View Javadoc

1   /**
2    * Copyright 2011 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
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   * @author Kuali Mobility Team (mobility.collab@kuali.org)
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  }