View Javadoc
1   package fr.ifremer.dali.dao.system.rule;
2   
3   /*
4    * #%L
5    * Dali :: Core
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2014 - 2015 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
24   */
25  
26  import fr.ifremer.dali.dao.DaliDatabaseResource;
27  import fr.ifremer.dali.dto.configuration.control.RuleListDTO;
28  import fr.ifremer.dali.service.DaliServiceLocator;
29  import fr.ifremer.quadrige3.core.test.AbstractDaoTest;
30  import org.apache.commons.lang3.builder.ToStringBuilder;
31  import org.apache.commons.lang3.builder.ToStringStyle;
32  import org.apache.commons.logging.Log;
33  import org.apache.commons.logging.LogFactory;
34  import org.junit.Before;
35  import org.junit.ClassRule;
36  import org.junit.Test;
37  import org.springframework.dao.DataRetrievalFailureException;
38  
39  import java.util.List;
40  
41  import static org.junit.Assert.*;
42  
43  public class RuleListDaoReadTest extends AbstractDaoTest {
44  
45      private static final Log log = LogFactory.getLog(RuleListDaoReadTest.class);
46  
47      @ClassRule
48      public static final DaliDatabaseResource dbResource = DaliDatabaseResource.readDb();
49  
50      private DaliRuleListDao ruleListDao;
51  
52      @Before
53      @Override
54      public void setUp() throws Exception {
55          super.setUp();
56          ruleListDao = DaliServiceLocator.instance().getService("daliRuleListDao", DaliRuleListDao.class);
57      }
58  
59      @Test
60      public void getAllRuleList() {
61  
62          List<RuleListDTO> ruleLists = ruleListDao.getAllRuleLists();
63          assertNotNull(ruleLists);
64          assertEquals(3, ruleLists.size());
65          if (log.isDebugEnabled()) {
66              for (RuleListDTO dto : ruleLists) {
67                  log.debug(ToStringBuilder.reflectionToString(dto, ToStringStyle.SHORT_PREFIX_STYLE));
68              }
69          }
70  
71          // RULELIST1 comes from test dataset only
72          RuleListDTO ruleList = ruleListDao.getRuleList(dbResource.getFixtures().getRuleListCode(0));
73          assertNotNull(ruleList);
74          assertEquals("rule list 1", ruleList.getDescription());
75  
76          try {
77              ruleListDao.getRuleList("RULELISTxxx");
78              fail("should throw DataRetrievalFailureException");
79          } catch (DataRetrievalFailureException ex) {
80              assertNotNull(ex);
81          }
82      }
83  
84  }