1 package org.kuali.mobility.bus.service;
2
3 import static org.junit.Assert.*;
4
5 import java.util.ArrayList;
6 import java.util.List;
7
8 import org.apache.log4j.Logger;
9 import org.junit.AfterClass;
10 import org.junit.BeforeClass;
11 import org.junit.Test;
12 import org.kuali.mobility.bus.entity.BusStop;
13 import org.kuali.mobility.bus.entity.BusStopImpl;
14 import org.kuali.mobility.bus.entity.ScheduledStopImpl;
15 import org.kuali.mobility.bus.service.util.BusStopDistanceUtil;
16 import org.springframework.context.ApplicationContext;
17 import org.springframework.context.support.FileSystemXmlApplicationContext;
18
19 public class BusServiceImplTest {
20
21 private static final Logger LOG = Logger.getLogger(BusServiceImplTest.class);
22 private static ApplicationContext applicationContext;
23
24
25
26
27 public static ApplicationContext getApplicationContext() {
28 return applicationContext;
29 }
30
31
32
33
34 public static void setApplicationContext(ApplicationContext aApplicationContext) {
35 applicationContext = aApplicationContext;
36 }
37
38 public BusServiceImplTest() {
39 }
40
41 @BeforeClass
42 public static void setUpClass() throws Exception {
43 BusServiceImplTest.setApplicationContext(new FileSystemXmlApplicationContext(getConfigLocations()));
44 }
45
46 private static String[] getConfigLocations() {
47 return new String[]{"classpath:/BusSpringBeans.xml"};
48 }
49
50 @AfterClass
51 public static void tearDownClass() throws Exception {
52 }
53
54 @Test
55 public void testGetNearbyStops() {
56 BusServiceImpl service = (BusServiceImpl) getApplicationContext().getBean("busService");
57 List<BusStopImpl> stopstest = new ArrayList<BusStopImpl>();
58
59
60
61
62 double lat1 = 42.2693773;
63 double lon1 = -83.7460591;
64 double radius = 0.9;
65 stopstest = service.getNearbyStops(lat1, lon1, radius);
66
67 for (BusStop s : stopstest) {
68 LOG.debug("BusStop ID: " + s.getId() + " ,name :" + s.getName() + ", distance: " + s.getDistance() );
69 }
70 assertTrue("Failed to find nearby bus stops.", stopstest != null);
71
72 }
73
74 @Test
75 public void testBusStopDistanceUtil() {
76 BusServiceImpl service = (BusServiceImpl) getApplicationContext().getBean("busService");
77
78 BusStop stop = null;
79
80 double lat1 = 42.2693773;
81 double lon1 = -83.7460591;
82 LOG.debug("Busstop 927605132");
83 stop = service.getStop("ALL", 927605132);
84
85 if (stop != null){
86 BusStopDistanceUtil bsu = new BusStopDistanceUtil();
87 double distance= bsu.calculateDistance(stop, lat1, lon1);
88 LOG.debug("BusStop ID: " + stop.getId() + " ,name :" + stop.getName() + ", calculated distance:" + distance);
89 }
90 assertTrue("Failed to find nearby bus stops.", stop != null);
91
92 }
93
94 @Test
95 public void testGetArrivalData() {
96 BusServiceImpl service = (BusServiceImpl) getApplicationContext().getBean("busService");
97 List<ScheduledStopImpl> arrivals = service.getArrivalData("1", "-249281262", "ALL");
98 assertNotNull( "No scheduled stops found.", arrivals );
99 }
100 }