@Test public void deleteTestTimeout1() throws IOException { new Expectations() {{ capturingSnmpSession.set((PDU) any, (Snmp) any, (UserTarget) any, anyBoolean); result = null; }}; assertEquals(HttpStatus.REQUEST_TIMEOUT, testTimDeleteController.deleteTim("{\"rsuTarget\":\"127.0.0.1\",\"rsuRetries\":\"1\",\"rsuTimeout\":\"2000\"}", 42).getStatusCode()); }
@CrossOrigin @DeleteMapping(value = "/tim") public ResponseEntity<String> deleteTim(@RequestBody String jsonString, @RequestParam(value = "index", required = true) Integer index) { if (null == jsonString) { logger.error("Empty request"); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(JsonUtils.jsonKeyValue(ERRSTR, "Empty request")); } RSU queryTarget = (RSU) JsonUtils.fromJson(jsonString, RSU.class); TimTransmogrifier.updateRsuCreds(queryTarget, odeProperties); logger.info("TIM delete call, RSU info {}", queryTarget); SnmpSession ss = null; try { ss = new SnmpSession(queryTarget); } catch (IOException e) { logger.error("Error creating TIM delete SNMP session", e); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body(JsonUtils.jsonKeyValue(ERRSTR, e.getMessage())); } catch (NullPointerException e) { logger.error("TIM query error, malformed JSON", e); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(JsonUtils.jsonKeyValue(ERRSTR, "Malformed JSON")); } PDU pdu = new ScopedPDU(); pdu.add(new VariableBinding(new OID("1.0.15628.4.1.4.1.11.".concat(Integer.toString(index))), new Integer32(6))); pdu.setType(PDU.SET); ResponseEvent rsuResponse = null; try { rsuResponse = ss.set(pdu, ss.getSnmp(), ss.getTarget(), false); } catch (IOException e) { logger.error("Error sending TIM query PDU to RSU", e); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body(JsonUtils.jsonKeyValue(ERRSTR, e.getMessage())); } HttpStatus returnCode = null; String bodyMsg = ""; if (null == rsuResponse || null == rsuResponse.getResponse()) { returnCode = HttpStatus.REQUEST_TIMEOUT; bodyMsg = JsonUtils.jsonKeyValue(ERRSTR, "Timeout."); } else if (rsuResponse.getResponse().getErrorStatus() == 0) { returnCode = HttpStatus.OK; bodyMsg = JsonUtils.jsonKeyValue("deleted_msg", Integer.toString(index)); } else if (rsuResponse.getResponse().getErrorStatus() == 12) { returnCode = HttpStatus.BAD_REQUEST; bodyMsg = JsonUtils.jsonKeyValue(ERRSTR, "No message at index ".concat(Integer.toString(index))); } else if (rsuResponse.getResponse().getErrorStatus() == 10) { returnCode = HttpStatus.BAD_REQUEST; bodyMsg = JsonUtils.jsonKeyValue(ERRSTR, "Invalid index ".concat(Integer.toString(index))); } else { returnCode = HttpStatus.BAD_REQUEST; bodyMsg = JsonUtils.jsonKeyValue(ERRSTR, rsuResponse.getResponse().getErrorStatusText()); } logger.info("Delete call response code: {}, message: {}", returnCode, bodyMsg); return ResponseEntity.status(returnCode).body(bodyMsg); }
TimDeleteController { @CrossOrigin @DeleteMapping(value = "/tim") public ResponseEntity<String> deleteTim(@RequestBody String jsonString, @RequestParam(value = "index", required = true) Integer index) { if (null == jsonString) { logger.error("Empty request"); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(JsonUtils.jsonKeyValue(ERRSTR, "Empty request")); } RSU queryTarget = (RSU) JsonUtils.fromJson(jsonString, RSU.class); TimTransmogrifier.updateRsuCreds(queryTarget, odeProperties); logger.info("TIM delete call, RSU info {}", queryTarget); SnmpSession ss = null; try { ss = new SnmpSession(queryTarget); } catch (IOException e) { logger.error("Error creating TIM delete SNMP session", e); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body(JsonUtils.jsonKeyValue(ERRSTR, e.getMessage())); } catch (NullPointerException e) { logger.error("TIM query error, malformed JSON", e); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(JsonUtils.jsonKeyValue(ERRSTR, "Malformed JSON")); } PDU pdu = new ScopedPDU(); pdu.add(new VariableBinding(new OID("1.0.15628.4.1.4.1.11.".concat(Integer.toString(index))), new Integer32(6))); pdu.setType(PDU.SET); ResponseEvent rsuResponse = null; try { rsuResponse = ss.set(pdu, ss.getSnmp(), ss.getTarget(), false); } catch (IOException e) { logger.error("Error sending TIM query PDU to RSU", e); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body(JsonUtils.jsonKeyValue(ERRSTR, e.getMessage())); } HttpStatus returnCode = null; String bodyMsg = ""; if (null == rsuResponse || null == rsuResponse.getResponse()) { returnCode = HttpStatus.REQUEST_TIMEOUT; bodyMsg = JsonUtils.jsonKeyValue(ERRSTR, "Timeout."); } else if (rsuResponse.getResponse().getErrorStatus() == 0) { returnCode = HttpStatus.OK; bodyMsg = JsonUtils.jsonKeyValue("deleted_msg", Integer.toString(index)); } else if (rsuResponse.getResponse().getErrorStatus() == 12) { returnCode = HttpStatus.BAD_REQUEST; bodyMsg = JsonUtils.jsonKeyValue(ERRSTR, "No message at index ".concat(Integer.toString(index))); } else if (rsuResponse.getResponse().getErrorStatus() == 10) { returnCode = HttpStatus.BAD_REQUEST; bodyMsg = JsonUtils.jsonKeyValue(ERRSTR, "Invalid index ".concat(Integer.toString(index))); } else { returnCode = HttpStatus.BAD_REQUEST; bodyMsg = JsonUtils.jsonKeyValue(ERRSTR, rsuResponse.getResponse().getErrorStatusText()); } logger.info("Delete call response code: {}, message: {}", returnCode, bodyMsg); return ResponseEntity.status(returnCode).body(bodyMsg); } }
TimDeleteController { @CrossOrigin @DeleteMapping(value = "/tim") public ResponseEntity<String> deleteTim(@RequestBody String jsonString, @RequestParam(value = "index", required = true) Integer index) { if (null == jsonString) { logger.error("Empty request"); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(JsonUtils.jsonKeyValue(ERRSTR, "Empty request")); } RSU queryTarget = (RSU) JsonUtils.fromJson(jsonString, RSU.class); TimTransmogrifier.updateRsuCreds(queryTarget, odeProperties); logger.info("TIM delete call, RSU info {}", queryTarget); SnmpSession ss = null; try { ss = new SnmpSession(queryTarget); } catch (IOException e) { logger.error("Error creating TIM delete SNMP session", e); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body(JsonUtils.jsonKeyValue(ERRSTR, e.getMessage())); } catch (NullPointerException e) { logger.error("TIM query error, malformed JSON", e); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(JsonUtils.jsonKeyValue(ERRSTR, "Malformed JSON")); } PDU pdu = new ScopedPDU(); pdu.add(new VariableBinding(new OID("1.0.15628.4.1.4.1.11.".concat(Integer.toString(index))), new Integer32(6))); pdu.setType(PDU.SET); ResponseEvent rsuResponse = null; try { rsuResponse = ss.set(pdu, ss.getSnmp(), ss.getTarget(), false); } catch (IOException e) { logger.error("Error sending TIM query PDU to RSU", e); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body(JsonUtils.jsonKeyValue(ERRSTR, e.getMessage())); } HttpStatus returnCode = null; String bodyMsg = ""; if (null == rsuResponse || null == rsuResponse.getResponse()) { returnCode = HttpStatus.REQUEST_TIMEOUT; bodyMsg = JsonUtils.jsonKeyValue(ERRSTR, "Timeout."); } else if (rsuResponse.getResponse().getErrorStatus() == 0) { returnCode = HttpStatus.OK; bodyMsg = JsonUtils.jsonKeyValue("deleted_msg", Integer.toString(index)); } else if (rsuResponse.getResponse().getErrorStatus() == 12) { returnCode = HttpStatus.BAD_REQUEST; bodyMsg = JsonUtils.jsonKeyValue(ERRSTR, "No message at index ".concat(Integer.toString(index))); } else if (rsuResponse.getResponse().getErrorStatus() == 10) { returnCode = HttpStatus.BAD_REQUEST; bodyMsg = JsonUtils.jsonKeyValue(ERRSTR, "Invalid index ".concat(Integer.toString(index))); } else { returnCode = HttpStatus.BAD_REQUEST; bodyMsg = JsonUtils.jsonKeyValue(ERRSTR, rsuResponse.getResponse().getErrorStatusText()); } logger.info("Delete call response code: {}, message: {}", returnCode, bodyMsg); return ResponseEntity.status(returnCode).body(bodyMsg); } @Autowired  TimDeleteController(OdeProperties odeProperties); }
TimDeleteController { @CrossOrigin @DeleteMapping(value = "/tim") public ResponseEntity<String> deleteTim(@RequestBody String jsonString, @RequestParam(value = "index", required = true) Integer index) { if (null == jsonString) { logger.error("Empty request"); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(JsonUtils.jsonKeyValue(ERRSTR, "Empty request")); } RSU queryTarget = (RSU) JsonUtils.fromJson(jsonString, RSU.class); TimTransmogrifier.updateRsuCreds(queryTarget, odeProperties); logger.info("TIM delete call, RSU info {}", queryTarget); SnmpSession ss = null; try { ss = new SnmpSession(queryTarget); } catch (IOException e) { logger.error("Error creating TIM delete SNMP session", e); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body(JsonUtils.jsonKeyValue(ERRSTR, e.getMessage())); } catch (NullPointerException e) { logger.error("TIM query error, malformed JSON", e); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(JsonUtils.jsonKeyValue(ERRSTR, "Malformed JSON")); } PDU pdu = new ScopedPDU(); pdu.add(new VariableBinding(new OID("1.0.15628.4.1.4.1.11.".concat(Integer.toString(index))), new Integer32(6))); pdu.setType(PDU.SET); ResponseEvent rsuResponse = null; try { rsuResponse = ss.set(pdu, ss.getSnmp(), ss.getTarget(), false); } catch (IOException e) { logger.error("Error sending TIM query PDU to RSU", e); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body(JsonUtils.jsonKeyValue(ERRSTR, e.getMessage())); } HttpStatus returnCode = null; String bodyMsg = ""; if (null == rsuResponse || null == rsuResponse.getResponse()) { returnCode = HttpStatus.REQUEST_TIMEOUT; bodyMsg = JsonUtils.jsonKeyValue(ERRSTR, "Timeout."); } else if (rsuResponse.getResponse().getErrorStatus() == 0) { returnCode = HttpStatus.OK; bodyMsg = JsonUtils.jsonKeyValue("deleted_msg", Integer.toString(index)); } else if (rsuResponse.getResponse().getErrorStatus() == 12) { returnCode = HttpStatus.BAD_REQUEST; bodyMsg = JsonUtils.jsonKeyValue(ERRSTR, "No message at index ".concat(Integer.toString(index))); } else if (rsuResponse.getResponse().getErrorStatus() == 10) { returnCode = HttpStatus.BAD_REQUEST; bodyMsg = JsonUtils.jsonKeyValue(ERRSTR, "Invalid index ".concat(Integer.toString(index))); } else { returnCode = HttpStatus.BAD_REQUEST; bodyMsg = JsonUtils.jsonKeyValue(ERRSTR, rsuResponse.getResponse().getErrorStatusText()); } logger.info("Delete call response code: {}, message: {}", returnCode, bodyMsg); return ResponseEntity.status(returnCode).body(bodyMsg); } @Autowired  TimDeleteController(OdeProperties odeProperties); @CrossOrigin @DeleteMapping(value = "/tim") ResponseEntity<String> deleteTim(@RequestBody String jsonString,
         @RequestParam(value = "index", required = true) Integer index); }
TimDeleteController { @CrossOrigin @DeleteMapping(value = "/tim") public ResponseEntity<String> deleteTim(@RequestBody String jsonString, @RequestParam(value = "index", required = true) Integer index) { if (null == jsonString) { logger.error("Empty request"); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(JsonUtils.jsonKeyValue(ERRSTR, "Empty request")); } RSU queryTarget = (RSU) JsonUtils.fromJson(jsonString, RSU.class); TimTransmogrifier.updateRsuCreds(queryTarget, odeProperties); logger.info("TIM delete call, RSU info {}", queryTarget); SnmpSession ss = null; try { ss = new SnmpSession(queryTarget); } catch (IOException e) { logger.error("Error creating TIM delete SNMP session", e); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body(JsonUtils.jsonKeyValue(ERRSTR, e.getMessage())); } catch (NullPointerException e) { logger.error("TIM query error, malformed JSON", e); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(JsonUtils.jsonKeyValue(ERRSTR, "Malformed JSON")); } PDU pdu = new ScopedPDU(); pdu.add(new VariableBinding(new OID("1.0.15628.4.1.4.1.11.".concat(Integer.toString(index))), new Integer32(6))); pdu.setType(PDU.SET); ResponseEvent rsuResponse = null; try { rsuResponse = ss.set(pdu, ss.getSnmp(), ss.getTarget(), false); } catch (IOException e) { logger.error("Error sending TIM query PDU to RSU", e); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body(JsonUtils.jsonKeyValue(ERRSTR, e.getMessage())); } HttpStatus returnCode = null; String bodyMsg = ""; if (null == rsuResponse || null == rsuResponse.getResponse()) { returnCode = HttpStatus.REQUEST_TIMEOUT; bodyMsg = JsonUtils.jsonKeyValue(ERRSTR, "Timeout."); } else if (rsuResponse.getResponse().getErrorStatus() == 0) { returnCode = HttpStatus.OK; bodyMsg = JsonUtils.jsonKeyValue("deleted_msg", Integer.toString(index)); } else if (rsuResponse.getResponse().getErrorStatus() == 12) { returnCode = HttpStatus.BAD_REQUEST; bodyMsg = JsonUtils.jsonKeyValue(ERRSTR, "No message at index ".concat(Integer.toString(index))); } else if (rsuResponse.getResponse().getErrorStatus() == 10) { returnCode = HttpStatus.BAD_REQUEST; bodyMsg = JsonUtils.jsonKeyValue(ERRSTR, "Invalid index ".concat(Integer.toString(index))); } else { returnCode = HttpStatus.BAD_REQUEST; bodyMsg = JsonUtils.jsonKeyValue(ERRSTR, rsuResponse.getResponse().getErrorStatusText()); } logger.info("Delete call response code: {}, message: {}", returnCode, bodyMsg); return ResponseEntity.status(returnCode).body(bodyMsg); } @Autowired  TimDeleteController(OdeProperties odeProperties); @CrossOrigin @DeleteMapping(value = "/tim") ResponseEntity<String> deleteTim(@RequestBody String jsonString,
         @RequestParam(value = "index", required = true) Integer index);  }