@Test public void testHandleRequest() { EjectHandler handler = new EjectHandler(); APIGatewayProxyRequestEvent input = new APIGatewayProxyRequestEvent(); input.setBody("invalid : json"); APIGatewayProxyResponseEvent output = handler.handleRequest(input, null); assertThat(output.getStatusCode(), is(400)); assertTrue(output.getBody().startsWith("Parameter must be a JSON object: ")); Scheduler scheduler = mock(Scheduler.class); doReturn(false).when(scheduler).unschedule(anyString()); Prodigy.container(new Container(scheduler, mock(Repository.class))); input = new APIGatewayProxyRequestEvent(); input.setBody("{\"id\" : \"fault-id-1\"}"); output = handler.handleRequest(input, null); assertThat(output.getStatusCode(), is(400)); assertThat(output.getBody(), is("Fault id [fault-id-1] not found")); scheduler = mock(Scheduler.class); doThrow(new IllegalStateException("hello")).when(scheduler).unschedule(anyString()); Prodigy.container(new Container(scheduler, mock(Repository.class))); input = new APIGatewayProxyRequestEvent(); input.setBody("{\"id\" : \"fault-id-1\"}"); output = handler.handleRequest(input, null); assertThat(output.getStatusCode(), is(500)); assertThat(output.getBody(), is("hello")); scheduler = mock(Scheduler.class); doReturn(true).when(scheduler).unschedule(anyString()); Prodigy.container(new Container(scheduler, mock(Repository.class))); input = new APIGatewayProxyRequestEvent(); input.setBody("{\"id\" : \"fault-id-2\"}"); output = handler.handleRequest(input, null); assertThat(output.getStatusCode(), is(200)); assertThat(output.getBody(), is("{}")); }
@Override public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) { APIGatewayProxyResponseEvent output = new APIGatewayProxyResponseEvent(); ObjectMapper mapper = new ObjectMapper(); try { Map<String, String> request = mapper.readValue(input.getBody(), new TypeReference<Map<String, String>>() { }); String id = request.get("id"); Prodigy.eject(id); return output.withStatusCode(200).withBody("{}"); } catch (JsonParseException e) { String message = "Parameter must be a JSON object: " + e.getMessage(); log.warn(message, e); return output.withStatusCode(400).withBody(message); } catch (IllegalArgumentException e) { log.warn(e.getMessage(), e); return output.withStatusCode(400).withBody(e.getMessage()); } catch (Exception e) { log.error(e.getMessage(), e); return output.withStatusCode(500).withBody(e.getMessage()); } }
EjectHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> { @Override public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) { APIGatewayProxyResponseEvent output = new APIGatewayProxyResponseEvent(); ObjectMapper mapper = new ObjectMapper(); try { Map<String, String> request = mapper.readValue(input.getBody(), new TypeReference<Map<String, String>>() { }); String id = request.get("id"); Prodigy.eject(id); return output.withStatusCode(200).withBody("{}"); } catch (JsonParseException e) { String message = "Parameter must be a JSON object: " + e.getMessage(); log.warn(message, e); return output.withStatusCode(400).withBody(message); } catch (IllegalArgumentException e) { log.warn(e.getMessage(), e); return output.withStatusCode(400).withBody(e.getMessage()); } catch (Exception e) { log.error(e.getMessage(), e); return output.withStatusCode(500).withBody(e.getMessage()); } } }
EjectHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> { @Override public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) { APIGatewayProxyResponseEvent output = new APIGatewayProxyResponseEvent(); ObjectMapper mapper = new ObjectMapper(); try { Map<String, String> request = mapper.readValue(input.getBody(), new TypeReference<Map<String, String>>() { }); String id = request.get("id"); Prodigy.eject(id); return output.withStatusCode(200).withBody("{}"); } catch (JsonParseException e) { String message = "Parameter must be a JSON object: " + e.getMessage(); log.warn(message, e); return output.withStatusCode(400).withBody(message); } catch (IllegalArgumentException e) { log.warn(e.getMessage(), e); return output.withStatusCode(400).withBody(e.getMessage()); } catch (Exception e) { log.error(e.getMessage(), e); return output.withStatusCode(500).withBody(e.getMessage()); } }  }
EjectHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> { @Override public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) { APIGatewayProxyResponseEvent output = new APIGatewayProxyResponseEvent(); ObjectMapper mapper = new ObjectMapper(); try { Map<String, String> request = mapper.readValue(input.getBody(), new TypeReference<Map<String, String>>() { }); String id = request.get("id"); Prodigy.eject(id); return output.withStatusCode(200).withBody("{}"); } catch (JsonParseException e) { String message = "Parameter must be a JSON object: " + e.getMessage(); log.warn(message, e); return output.withStatusCode(400).withBody(message); } catch (IllegalArgumentException e) { log.warn(e.getMessage(), e); return output.withStatusCode(400).withBody(e.getMessage()); } catch (Exception e) { log.error(e.getMessage(), e); return output.withStatusCode(500).withBody(e.getMessage()); } }  @Override APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context); }
EjectHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> { @Override public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) { APIGatewayProxyResponseEvent output = new APIGatewayProxyResponseEvent(); ObjectMapper mapper = new ObjectMapper(); try { Map<String, String> request = mapper.readValue(input.getBody(), new TypeReference<Map<String, String>>() { }); String id = request.get("id"); Prodigy.eject(id); return output.withStatusCode(200).withBody("{}"); } catch (JsonParseException e) { String message = "Parameter must be a JSON object: " + e.getMessage(); log.warn(message, e); return output.withStatusCode(400).withBody(message); } catch (IllegalArgumentException e) { log.warn(e.getMessage(), e); return output.withStatusCode(400).withBody(e.getMessage()); } catch (Exception e) { log.error(e.getMessage(), e); return output.withStatusCode(500).withBody(e.getMessage()); } }  @Override APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context);  }