@Test public void checkJsonResponse2RSUSuccess() { try { new Expectations() { { JsonUtils.fromJson(anyString, J2735PdmRequest.class); result = mockJ2735PdmRequest; mockJ2735PdmRequest.getRsuList(); result = new RSU[]{mockRSU, mockRSU}; mockRSU.getRsuTarget(); result = "127.0.0.1"; capturingSnmpSession.set((PDU) any, (Snmp) any, (UserTarget) any, anyBoolean); result = mockResponseEvent; mockResponseEvent.getResponse().getErrorStatus(); result = 0; } }; } catch (IOException e) { fail("Unexpected exception: " + e); } assertEquals("{\"rsu_responses\":[{\"127.0.0.1\":\"Deposit successful\"},{\"127.0.0.1\":\"Deposit successful\"}]}", testPdmController.pdmMessage("not a null string").getBody()); }
@PostMapping(value = "/pdm", produces = "application/json") public ResponseEntity<String> pdmMessage(@RequestBody String jsonString) { if (null == jsonString) { logger.error("PDM controller received empty request"); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Empty request"); } J2735PdmRequest pdmRequest = (J2735PdmRequest) JsonUtils.fromJson(jsonString, J2735PdmRequest.class); String jsonPdmRequest = pdmRequest.toJson(true); logger.debug("J2735PdmRequest: {}", jsonPdmRequest); String aggregateBodyMessage = "["; ScopedPDU pdu = PdmUtil.createPDU(pdmRequest.getPdm()); for (RSU curRsu : pdmRequest.getRsuList()) { String curRsuMessage = "Error"; ResponseEvent response = null; try { response = createAndSend(pdu, curRsu); if (null == response || null == response.getResponse()) { curRsuMessage = "Timeout"; } else if (0 == response.getResponse().getErrorStatus()) { curRsuMessage = "Deposit successful"; } else { curRsuMessage = "Deposit failed: " + response.getResponse().getErrorStatusText(); } } catch (IOException e) { logger.error("Exception sending PDM: ", e); curRsuMessage = "Exception occurred"; } if (!("[".equals(aggregateBodyMessage))) { aggregateBodyMessage = aggregateBodyMessage.concat(","); } aggregateBodyMessage = aggregateBodyMessage.concat("{\"" + curRsu.getRsuTarget() + "\":\"" + curRsuMessage + "\"}"); } aggregateBodyMessage = aggregateBodyMessage.concat("]"); aggregateBodyMessage = "{\"rsu_responses\":".concat(aggregateBodyMessage).concat("}"); return ResponseEntity.status(HttpStatus.OK).body(aggregateBodyMessage); }
PdmController { @PostMapping(value = "/pdm", produces = "application/json") public ResponseEntity<String> pdmMessage(@RequestBody String jsonString) { if (null == jsonString) { logger.error("PDM controller received empty request"); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Empty request"); } J2735PdmRequest pdmRequest = (J2735PdmRequest) JsonUtils.fromJson(jsonString, J2735PdmRequest.class); String jsonPdmRequest = pdmRequest.toJson(true); logger.debug("J2735PdmRequest: {}", jsonPdmRequest); String aggregateBodyMessage = "["; ScopedPDU pdu = PdmUtil.createPDU(pdmRequest.getPdm()); for (RSU curRsu : pdmRequest.getRsuList()) { String curRsuMessage = "Error"; ResponseEvent response = null; try { response = createAndSend(pdu, curRsu); if (null == response || null == response.getResponse()) { curRsuMessage = "Timeout"; } else if (0 == response.getResponse().getErrorStatus()) { curRsuMessage = "Deposit successful"; } else { curRsuMessage = "Deposit failed: " + response.getResponse().getErrorStatusText(); } } catch (IOException e) { logger.error("Exception sending PDM: ", e); curRsuMessage = "Exception occurred"; } if (!("[".equals(aggregateBodyMessage))) { aggregateBodyMessage = aggregateBodyMessage.concat(","); } aggregateBodyMessage = aggregateBodyMessage.concat("{\"" + curRsu.getRsuTarget() + "\":\"" + curRsuMessage + "\"}"); } aggregateBodyMessage = aggregateBodyMessage.concat("]"); aggregateBodyMessage = "{\"rsu_responses\":".concat(aggregateBodyMessage).concat("}"); return ResponseEntity.status(HttpStatus.OK).body(aggregateBodyMessage); } }
PdmController { @PostMapping(value = "/pdm", produces = "application/json") public ResponseEntity<String> pdmMessage(@RequestBody String jsonString) { if (null == jsonString) { logger.error("PDM controller received empty request"); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Empty request"); } J2735PdmRequest pdmRequest = (J2735PdmRequest) JsonUtils.fromJson(jsonString, J2735PdmRequest.class); String jsonPdmRequest = pdmRequest.toJson(true); logger.debug("J2735PdmRequest: {}", jsonPdmRequest); String aggregateBodyMessage = "["; ScopedPDU pdu = PdmUtil.createPDU(pdmRequest.getPdm()); for (RSU curRsu : pdmRequest.getRsuList()) { String curRsuMessage = "Error"; ResponseEvent response = null; try { response = createAndSend(pdu, curRsu); if (null == response || null == response.getResponse()) { curRsuMessage = "Timeout"; } else if (0 == response.getResponse().getErrorStatus()) { curRsuMessage = "Deposit successful"; } else { curRsuMessage = "Deposit failed: " + response.getResponse().getErrorStatusText(); } } catch (IOException e) { logger.error("Exception sending PDM: ", e); curRsuMessage = "Exception occurred"; } if (!("[".equals(aggregateBodyMessage))) { aggregateBodyMessage = aggregateBodyMessage.concat(","); } aggregateBodyMessage = aggregateBodyMessage.concat("{\"" + curRsu.getRsuTarget() + "\":\"" + curRsuMessage + "\"}"); } aggregateBodyMessage = aggregateBodyMessage.concat("]"); aggregateBodyMessage = "{\"rsu_responses\":".concat(aggregateBodyMessage).concat("}"); return ResponseEntity.status(HttpStatus.OK).body(aggregateBodyMessage); }  }
PdmController { @PostMapping(value = "/pdm", produces = "application/json") public ResponseEntity<String> pdmMessage(@RequestBody String jsonString) { if (null == jsonString) { logger.error("PDM controller received empty request"); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Empty request"); } J2735PdmRequest pdmRequest = (J2735PdmRequest) JsonUtils.fromJson(jsonString, J2735PdmRequest.class); String jsonPdmRequest = pdmRequest.toJson(true); logger.debug("J2735PdmRequest: {}", jsonPdmRequest); String aggregateBodyMessage = "["; ScopedPDU pdu = PdmUtil.createPDU(pdmRequest.getPdm()); for (RSU curRsu : pdmRequest.getRsuList()) { String curRsuMessage = "Error"; ResponseEvent response = null; try { response = createAndSend(pdu, curRsu); if (null == response || null == response.getResponse()) { curRsuMessage = "Timeout"; } else if (0 == response.getResponse().getErrorStatus()) { curRsuMessage = "Deposit successful"; } else { curRsuMessage = "Deposit failed: " + response.getResponse().getErrorStatusText(); } } catch (IOException e) { logger.error("Exception sending PDM: ", e); curRsuMessage = "Exception occurred"; } if (!("[".equals(aggregateBodyMessage))) { aggregateBodyMessage = aggregateBodyMessage.concat(","); } aggregateBodyMessage = aggregateBodyMessage.concat("{\"" + curRsu.getRsuTarget() + "\":\"" + curRsuMessage + "\"}"); } aggregateBodyMessage = aggregateBodyMessage.concat("]"); aggregateBodyMessage = "{\"rsu_responses\":".concat(aggregateBodyMessage).concat("}"); return ResponseEntity.status(HttpStatus.OK).body(aggregateBodyMessage); }  @PostMapping(value = "/pdm", produces = "application/json") ResponseEntity<String> pdmMessage(@RequestBody String jsonString); static ResponseEvent createAndSend(ScopedPDU pdu, RSU rsu); }
PdmController { @PostMapping(value = "/pdm", produces = "application/json") public ResponseEntity<String> pdmMessage(@RequestBody String jsonString) { if (null == jsonString) { logger.error("PDM controller received empty request"); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Empty request"); } J2735PdmRequest pdmRequest = (J2735PdmRequest) JsonUtils.fromJson(jsonString, J2735PdmRequest.class); String jsonPdmRequest = pdmRequest.toJson(true); logger.debug("J2735PdmRequest: {}", jsonPdmRequest); String aggregateBodyMessage = "["; ScopedPDU pdu = PdmUtil.createPDU(pdmRequest.getPdm()); for (RSU curRsu : pdmRequest.getRsuList()) { String curRsuMessage = "Error"; ResponseEvent response = null; try { response = createAndSend(pdu, curRsu); if (null == response || null == response.getResponse()) { curRsuMessage = "Timeout"; } else if (0 == response.getResponse().getErrorStatus()) { curRsuMessage = "Deposit successful"; } else { curRsuMessage = "Deposit failed: " + response.getResponse().getErrorStatusText(); } } catch (IOException e) { logger.error("Exception sending PDM: ", e); curRsuMessage = "Exception occurred"; } if (!("[".equals(aggregateBodyMessage))) { aggregateBodyMessage = aggregateBodyMessage.concat(","); } aggregateBodyMessage = aggregateBodyMessage.concat("{\"" + curRsu.getRsuTarget() + "\":\"" + curRsuMessage + "\"}"); } aggregateBodyMessage = aggregateBodyMessage.concat("]"); aggregateBodyMessage = "{\"rsu_responses\":".concat(aggregateBodyMessage).concat("}"); return ResponseEntity.status(HttpStatus.OK).body(aggregateBodyMessage); }  @PostMapping(value = "/pdm", produces = "application/json") ResponseEntity<String> pdmMessage(@RequestBody String jsonString); static ResponseEvent createAndSend(ScopedPDU pdu, RSU rsu);  }