1
2
3
4
5
6
7
8
9
10
11
12
13
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
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
97
98
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
114
115 public ComputerLabsInitBean getInitBean() {
116 return initBean;
117 }
118
119
120
121
122 public void setInitBean(ComputerLabsInitBean initBean) {
123 this.initBean = initBean;
124 }
125
126
127
128
129 public ComputerLabsDao getDao() {
130 return dao;
131 }
132
133
134
135
136 public void setDao(ComputerLabsDao dao) {
137 this.dao = dao;
138 }
139 }