1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.kuali.mobility.campus.service;
16
17 import org.apache.log4j.Logger;
18 import org.junit.AfterClass;
19 import org.junit.BeforeClass;
20 import org.junit.Test;
21 import org.kuali.mobility.campus.entity.Campus;
22 import org.springframework.context.ApplicationContext;
23 import org.springframework.context.support.FileSystemXmlApplicationContext;
24
25 import java.util.ArrayList;
26 import java.util.List;
27
28 import static org.junit.Assert.assertTrue;
29
30
31
32
33 public class CampusServiceImplTest {
34 private static final Logger LOG = Logger.getLogger( CampusServiceImplTest.class );
35
36 private static ApplicationContext applicationContext;
37
38 private static String[] getConfigLocations() {
39 return new String[] { "classpath:/CampusSpringBeans.xml" };
40 }
41
42 @BeforeClass
43 public static void setUpClass() throws Exception {
44 CampusServiceImplTest.setApplicationContext(new FileSystemXmlApplicationContext(getConfigLocations()));
45 }
46
47 @AfterClass
48 public static void tearDownClass() throws Exception {
49 }
50
51 @Test
52 public void testFindCampusesByTool() {
53 CampusService service = (CampusService)getApplicationContext().getBean("campusService");
54
55 assertTrue( "Campus service failed to load.", service != null );
56
57 List<Campus> campuses = service.findCampusesByTool("news");
58 assertTrue( "No campus found for IUPUI.", campuses != null && campuses.size() > 1 );
59 }
60
61 @Test
62 public void testNeedToSelectDifferentCampusForTool() {
63 CampusService service = (CampusService)getApplicationContext().getBean("campusService");
64
65 assertTrue( "Campus service failed to load.", service != null );
66
67 boolean result = service.needToSelectDifferentCampusForTool("computerlabs","BL");
68 assertTrue( "Received wrong response for Tool: computerlabs, Campus: IU Bloomington", !result);
69
70 result = service.needToSelectDifferentCampusForTool("computerlabs","IU Kokomo");
71 assertTrue( "Received wrong response for Tool: computerlabs, Campus: IU Kokomo", result);
72
73 result = service.needToSelectDifferentCampusForTool("news","");
74 assertTrue("Received a response for empty string campus value and should not have.",result);
75 }
76
77 @Test
78 public void testEmptyCampusList() {
79 CampusService service = (CampusService)getApplicationContext().getBean("campusService");
80 List<Campus> cachedCampuses = service.getCampuses();
81 service.setCampuses(new ArrayList<Campus>());
82 boolean result = service.needToSelectDifferentCampusForTool("computerlabs","IU Kokomo");
83 assertTrue( "Empty campus list in service should result in true response and did not.", result );
84
85 List<Campus> foundCampuses = service.findCampusesByTool(null);
86 assertTrue("Campuses found when none should have existed.",foundCampuses == null || foundCampuses.isEmpty() );
87
88 service.setCampuses(cachedCampuses);
89 }
90
91 public static ApplicationContext getApplicationContext() {
92 return applicationContext;
93 }
94
95 public static void setApplicationContext(ApplicationContext applicationContext) {
96 CampusServiceImplTest.applicationContext = applicationContext;
97 }
98 }