View Javadoc
1   /**
2    * Copyright 2011-2013 The Kuali Foundation Licensed under the Educational
3    * Community License, Version 2.0 (the "License"); you may not use this file
4    * except in compliance with the License. You may obtain a copy of the License
5    * at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12   * License for the specific language governing permissions and limitations under
13   * the License.
14   */
15  package org.kuali.mobility.computerlabs.dao;
16  
17  import org.slf4j.Logger;
18  import org.slf4j.LoggerFactory;
19  import org.junit.Before;
20  import org.junit.Test;
21  import org.junit.runner.RunWith;
22  import org.kuali.mobility.computerlabs.entity.Lab;
23  import org.kuali.mobility.computerlabs.entity.LabGroup;
24  import org.kuali.mobility.computerlabs.entity.Location;
25  import org.springframework.test.context.ContextConfiguration;
26  import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
27  
28  import javax.annotation.Resource;
29  import java.util.List;
30  
31  import static org.junit.Assert.assertTrue;
32  
33  /**
34   *
35   * @author Kuali Mobility Team <mobility.collab@kuali.org>
36   */
37  @RunWith(SpringJUnit4ClassRunner.class)
38  @ContextConfiguration(value = "classpath:ComputerLabsSpringBeans.xml")
39  public class ComputerLabsDaoImplTest {
40  
41  	private static final Logger LOG = LoggerFactory.getLogger( ComputerLabsDaoImplTest.class );
42  
43      @Resource(name="computerLabInitBean")
44  	private ComputerLabsInitBean initBean;
45      @Resource(name="computerLabDao")
46  	private ComputerLabsDao dao;
47  
48      @Before
49      public void setUpTest() {
50          getInitBean().loadData();
51      }
52  
53  	@Test
54  	public void testGetLabGroups() {
55  		List<? extends LabGroup> labGroups = dao.getLabGroups();
56  		assertTrue("No lab groups found.", labGroups != null);
57  		for( LabGroup lg : labGroups ) {
58  			LOG.debug( "Loaded lab group for "+lg.getName() );
59  			LOG.debug( lg.getName()+" has "+lg.getLocations().size()+" locations." );
60  		}
61  		assertTrue("Lab groups count is not 7.", labGroups.size() == 7 );
62  		
63  		dao.setLabGroups(null);
64  		List<? extends LabGroup> nullLabGroups = dao.getLabGroups();
65  		assertTrue("Lab groups count is not 0.", nullLabGroups.size() == 0 );
66  		
67  	}
68  
69  	@Test
70  	public void testGetLabGroup() {
71  		LabGroup labGroup = dao.getLabGroup("BL");
72  		assertTrue( "Lab group not loaded for key BL.", labGroup != null );		
73  	}
74  
75  	@Test
76  	public void testGetLocations() {
77  		List<? extends Location> locations = dao.getLocations("BL");
78  		assertTrue( "No locations found for group id of BL", locations != null && locations.size() > 0 );
79  		
80  		List<? extends Location> nullLocations = dao.getLocations(null);
81  		assertTrue( "Locations group should not be NULL for group id NULL", nullLocations != null && nullLocations.size() > 0 );
82  	}
83  
84  	@Test
85  	public void testGetLabs() {
86  		List<? extends Location> locations = dao.getLocations("BL");
87  		Location testLocation = locations.get(0);
88  		List<? extends Lab> labs = dao.getLabs( testLocation.getName(), "IN088" );
89  		assertTrue( "Labs were not loaded for location IN, building code IN088", labs != null && labs.size() > 0 );
90  	}
91  
92  	@Test
93  	public void testGetLab() {
94  		List<? extends Location> locations = dao.getLocations("BL");
95  		Location testLocation = locations.get(0);
96  //		List<? extends Lab> labs = dao.getLabs( testLocation.getName(), "IN088" );
97  //		for( Lab lab : labs ) {
98  //			LOG.debug( "Lab UID = "+lab.getLabUID() );
99  //		}
100 		Lab lab = dao.getLab("328ebdda457861828eba6e9136f7d2867524b5e0");
101 		assertTrue( "Lab not loaded for UID XXXX", lab != null && lab.getLab() != null && !lab.getLab().isEmpty() );
102 		
103 		Lab fakeLab = dao.getLab("fakeLab");
104 		assertTrue( "Lab should not be loaded for UID XXXX", fakeLab == null);
105 	}
106 	
107 	@Test
108 	public void testGetDaoContext() {
109 		assertTrue("Failed to get dao context",initBean.getDao() == getDao());
110 	}
111 
112 	/**
113 	 * @return the initBean
114 	 */
115 	public ComputerLabsInitBean getInitBean() {
116 		return initBean;
117 	}
118 
119 	/**
120 	 * @param initBean the initBean to set
121 	 */
122 	public void setInitBean(ComputerLabsInitBean initBean) {
123 		this.initBean = initBean;
124 	}
125 
126 	/**
127 	 * @return the dao
128 	 */
129 	public ComputerLabsDao getDao() {
130 		return dao;
131 	}
132 
133 	/**
134 	 * @param dao the dao to set
135 	 */
136 	public void setDao(ComputerLabsDao dao) {
137 		this.dao = dao;
138 	}
139 }