View Javadoc
1   /*
2    * To change this license header, choose License Headers in Project Properties.
3    * To change this template file, choose Tools | Templates
4    * and open the template in the editor.
5    */
6   
7   package fr.ifremer.dali.dao.system.filter;
8   
9   /*
10   * #%L
11   * Dali :: Core
12   * $Id:$
13   * $HeadURL:$
14   * %%
15   * Copyright (C) 2014 - 2015 Ifremer
16   * %%
17   * This program is free software: you can redistribute it and/or modify
18   * it under the terms of the GNU Affero General Public License as published by
19   * the Free Software Foundation, either version 3 of the License, or
20   * (at your option) any later version.
21   * 
22   * This program is distributed in the hope that it will be useful,
23   * but WITHOUT ANY WARRANTY; without even the implied warranty of
24   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25   * GNU General Public License for more details.
26   * 
27   * You should have received a copy of the GNU Affero General Public License
28   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
29   * #L%
30   */
31  
32  import fr.ifremer.dali.dao.DaliDatabaseResource;
33  import fr.ifremer.dali.dto.configuration.filter.FilterDTO;
34  import fr.ifremer.dali.dto.enums.FilterTypeValues;
35  import fr.ifremer.dali.service.DaliServiceLocator;
36  import fr.ifremer.quadrige3.core.test.AbstractDaoTest;
37  import org.junit.Assert;
38  import org.junit.Before;
39  import org.junit.ClassRule;
40  import org.junit.Test;
41  
42  import java.util.List;
43  
44  import static org.junit.Assert.assertEquals;
45  import static org.junit.Assert.assertNotNull;
46  
47  /**
48   *
49   * @author Lionel Touseau <lionel.touseau@e-is.pro>
50   */
51  public class FilterDaoReadTest extends AbstractDaoTest {
52      
53      @ClassRule
54      public static final DaliDatabaseResource dbResource = DaliDatabaseResource.readDb();
55  
56      private DaliFilterDao filterDao;
57      
58      @Before
59      @Override
60      public void setUp() throws Exception {
61          super.setUp();
62          filterDao = DaliServiceLocator.instance().getService("daliFilterDao", DaliFilterDao.class);
63      }
64      
65      @Test
66      public void getAllFilter() {
67          List<FilterDTO> locFilters = filterDao.getAllContextFilters(1001, FilterTypeValues.LOCATION.getFilterTypeId()); // context 1
68          assertNotNull(locFilters);
69          assertEquals(1, locFilters.size());
70          
71          locFilters = filterDao.getAllContextFilters(1002, FilterTypeValues.LOCATION.getFilterTypeId()); // context 2
72          Assert.assertTrue(locFilters == null || locFilters.isEmpty());
73          
74          List<FilterDTO> progFilters = filterDao.getAllContextFilters(null, FilterTypeValues.PROGRAM.getFilterTypeId());
75          
76          assertEquals(1, progFilters.size());
77          assertEquals("Program Filter", progFilters.get(0).getName());
78          
79      }
80      
81      @Test
82      public void getFilterById() {
83          FilterDTO f = filterDao.getFilterById(1001); // filter 1000
84          Assert.assertNotNull(f);
85          Assert.assertEquals(FilterTypeValues.LOCATION.getFilterTypeId(), f.getFilterTypeId());
86  
87          FilterDTO fp = filterDao.getFilterById(1002);
88          Assert.assertNotNull(fp);
89          Assert.assertEquals(FilterTypeValues.PROGRAM.getFilterTypeId(), fp.getFilterTypeId());
90  
91      }
92      
93  }