Skip to content

Commit

Permalink
Implemented unit tests for unrecognized snmp protocols in `RoadSideUn…
Browse files Browse the repository at this point in the history
…itTest.java` & `TimQueryControllerTest.java`
  • Loading branch information
dmccoystephenson committed Jul 10, 2023
1 parent e57cd28 commit 93f85ba
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ public void testDeserializationFromJson_ntcip1218RSU() {
assertEquals(SnmpProtocol.NTCIP1218, deserializedRSU.getSnmpProtocol());
}

// TODO: implement deserialization with unrecognized protocol so defaults to fourDot1
@Test
public void testDeserializationFromJson_unrecognizedProtocol_exception() {
String unrecognizedProtocolRSU = "{\"rsuTarget\":\"10.10.10.10\",\"rsuUsername\":\"user\",\"rsuPassword\":\"pass\",\"rsuRetries\":\"3\",\"rsuTimeout\":\"5000\",\"snmpProtocol\":\"banana\"}";

RSU deserializedRSU = null;
try {
deserializedRSU = (RSU) JsonUtils.fromJson(unrecognizedProtocolRSU, RSU.class);
}
catch(Exception e) {

}
assert(deserializedRSU == null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,16 @@ public synchronized ResponseEntity<String> bulkQuery(@RequestBody String jsonStr
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(JsonUtils.jsonKeyValue(ERRSTR, "Empty request."));
}

RSU queryTarget = (RSU) JsonUtils.fromJson(jsonString, RSU.class);
RSU queryTarget = null;
try {
queryTarget = (RSU) JsonUtils.fromJson(jsonString, RSU.class);
}
catch(Exception e) {

}
if (queryTarget == null) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(JsonUtils.jsonKeyValue(ERRSTR, "Unrecognized protocol"));
}

TimTransmogrifier.updateRsuCreds(queryTarget, odeProperties);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,13 @@ public void testSuccessfulPopulatedQuery_ntcip1218RSU() throws IOException {
assertTrue(actualResponse.getBody().contains("indicies_set"));
}

// TODO: implement test for unrecognized snmp protocol
@Test
public void testPopulatedQuery_unrecognizedProtocol() throws IOException {
String unrecognizedProtocolRSU = "{\"rsuTarget\":\"10.10.10.10\",\"rsuUsername\":\"user\",\"rsuPassword\":\"pass\",\"rsuRetries\":\"3\",\"rsuTimeout\":\"5000\",\"snmpProtocol\":\"banana\"}";

ResponseEntity<String> actualResponse = testTimQueryController.bulkQuery(unrecognizedProtocolRSU);
assertEquals(HttpStatus.BAD_REQUEST, actualResponse.getStatusCode());
assertTrue(actualResponse.getBody().contains("Unrecognized protocol"));
}

}

0 comments on commit 93f85ba

Please sign in to comment.