Skip to content

Commit

Permalink
Added very simple logging and fixed a formating bug introduced into t…
Browse files Browse the repository at this point in the history
…he json sample files when some heavy-handed auto formatting was performed in Eclipse.
  • Loading branch information
smithlamar committed Apr 6, 2017
1 parent 18ad933 commit 318ae0e
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 44 deletions.
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.net.URISyntaxException;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
Expand All @@ -19,18 +21,25 @@

@RestController
public class BustimeRequestController {
@Autowired
private final Logger log = LoggerFactory.getLogger(this.getClass());
BustimeAPIRequest requestService;

@Autowired
public BustimeRequestController(BustimeAPIRequest requestService) {
this.requestService = requestService;
}

@RequestMapping(value = "/getbuslines", method = RequestMethod.GET)
public List<BusLine> getBusLines() {

List<BusLine> busLines = null;

try {
busLines = requestService.requestRoutes();

} catch (RestClientException | MalformedURLException | BusTimeErrorReceivedException | URISyntaxException e) {
// TODO Auto-generated catch block
log.error("[getBusLines()] - Exception thrown on requestRoutes() call: " + e.getMessage());
e.printStackTrace();
}

Expand All @@ -39,6 +48,8 @@ public List<BusLine> getBusLines() {
line.initialize(requestService);
} catch (BusTimeErrorReceivedException | IOException e) {
// TODO Auto-generated catch block
log.error("[getBusLines()] - Exception thrown on intialize() call for BusLine: " + line + ". "
+ e.getMessage());
e.printStackTrace();
}
}
Expand All @@ -58,6 +69,8 @@ public List<Prediction> getPredictions(@RequestParam(value = "stpids", required
predictions = requestService.requestPredictions(stpids, rts, top);
} catch (MalformedURLException | BusTimeErrorReceivedException e) {
// TODO Auto-generated catch block
log.error("[getPredictions()] - Exception thrown on requestPredictions() call for stops: " + stpids + ". "
+ e.getMessage());
e.printStackTrace();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ public BustimeAPIRequest setRequestURL(URL requestURL) {
* @param responseBody
* the responseBody to set
*/
public void setResponseBody(String responseBody) {
public void setResponseBody(Object responseBody) {
this.responseBody = responseBody;
}
}
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
logging.file=route_tracker_api.log
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class BustimeAPIRequestTest extends junit.framework.TestSuite {
static HashMap<String, HashMap<String, String>> sampleFiles;
BusLine referenceBusLine;

@Autowired
Configuration jsonPathConfig;
@Autowired
BustimeAPIRequest request;

Expand Down Expand Up @@ -133,14 +135,13 @@ public void get_bustime_error_returns_null_given_json_with_no_error()
}

@Test
public void get_bustime_error_returns_error_string_when_given_json_with_error()
public void get_bustime_error_returns_error_string_when_given_parsed_json_with_error()
throws RestClientException, MalformedURLException, URISyntaxException {
String actual = null;
String expected = "Invalid API access key supplied";
Object responseBody = Configuration.defaultConfiguration().jsonProvider()
.parse(sampleFiles.get("json").get("errorInvalidKey"));

actual = request.getBustimeError(responseBody);
String sampleRawResponseEntity = sampleFiles.get("json").get("errorInvalidKey");
Object parsedResponseBody = jsonPathConfig.jsonProvider().parse(sampleRawResponseEntity);
actual = request.getBustimeError(parsedResponseBody);

assertTrue(actual.equals(expected));
}
Expand Down
16 changes: 8 additions & 8 deletions src/test/resources/sample_json_responses/error_bad_param.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"bustime-response": {
"error": [
{
"rt": "100000",
"msg": "No data found for parameter"
}
]
}
"bustime-response": {
"error": [
{
"rt": "1000",
"msg": "No data found for parameter"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

{"bustime-response": {"error": [ {
"msg": "rt parameter missing"
} ] }}
"msg": "Invalid API access key supplied"
} ] }}
42 changes: 21 additions & 21 deletions src/test/resources/sample_json_responses/predictions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,57 @@
"bustime-response": {
"prd": [
{
"tmstmp": "20170314 11:25",
"tmstmp": "20170406 16:53",
"typ": "A",
"stpnm": "Michigan \u0026 Balbo",
"stpid": "1584",
"vid": "1315",
"dstp": 4833,
"vid": "1364",
"dstp": 4360,
"rt": "4",
"rtdd": "4",
"rtdir": "Northbound",
"des": "Illinois Center",
"prdtm": "20170314 11:32",
"tablockid": "4 -716",
"tatripid": "10001019",
"prdtm": "20170406 17:00",
"tablockid": "4 -707",
"tatripid": "10001141",
"dly": false,
"prdctdn": "7",
"prdctdn": "6",
"zone": ""
},
{
"tmstmp": "20170314 11:25",
"tmstmp": "20170406 16:53",
"typ": "A",
"stpnm": "Michigan \u0026 Balbo",
"stpid": "1584",
"vid": "1298",
"dstp": 5475,
"vid": "7903",
"dstp": 7979,
"rt": "4",
"rtdd": "4",
"rtdir": "Northbound",
"des": "Illinois Center",
"prdtm": "20170314 11:33",
"tablockid": "4 -720",
"tatripid": "10001006",
"prdtm": "20170406 17:04",
"tablockid": "4 -708",
"tatripid": "10001098",
"dly": false,
"prdctdn": "7",
"prdctdn": "11",
"zone": ""
},
{
"tmstmp": "20170314 11:24",
"tmstmp": "20170406 16:53",
"typ": "A",
"stpnm": "Michigan \u0026 Balbo",
"stpid": "1584",
"vid": "1358",
"dstp": 16129,
"vid": "1213",
"dstp": 10728,
"rt": "4",
"rtdd": "4",
"rtdir": "Northbound",
"des": "Illinois Center",
"prdtm": "20170314 11:44",
"tablockid": "4 -718",
"tatripid": "10001021",
"prdtm": "20170406 17:08",
"tablockid": "4 -756",
"tatripid": "10001099",
"dly": false,
"prdctdn": "19",
"prdctdn": "14",
"zone": ""
}
]
Expand Down
12 changes: 12 additions & 0 deletions src/test/resources/sample_json_responses/stops.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
"lat": 41.692663130765,
"lon": -87.612318992615
},
{
"stpid": "18241",
"stpnm": "115th Street Metra Station",
"lat": 41.685670738112,
"lon": -87.612446397502
},
{
"stpid": "1577",
"stpnm": "1509 S Michigan",
Expand Down Expand Up @@ -577,6 +583,12 @@
"lat": 41.690845782451,
"lon": -87.61328458786
},
{
"stpid": "14050",
"stpnm": "King Drive \u0026 113th Street",
"lat": 41.688977747838,
"lon": -87.613236308098
},
{
"stpid": "2527",
"stpnm": "Lake Meadows Shopping Center",
Expand Down
15 changes: 14 additions & 1 deletion src/test/resources/sample_json_responses/unwrapped_routes.json
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
[{"rt":"1","rtnm":"Bronzeville/Union Station","rtclr":"#336633","rtdd":"1"},{"rt":"2","rtnm":"Hyde Park Express","rtclr":"#993366","rtdd":"2"}]
[
{
"rt": "1",
"rtnm": "Bronzeville/Union Station",
"rtclr": "#336633",
"rtdd": "1"
},
{
"rt": "2",
"rtnm": "Hyde Park Express",
"rtclr": "#993366",
"rtdd": "2"
}
]

0 comments on commit 318ae0e

Please sign in to comment.