@Test public void testHandleRequest() { FaultsHandler handler = new FaultsHandler(); Repository repository = mock(Repository.class); doThrow(new IllegalStateException("hello")).when(repository).load(); Prodigy.container(new Container(mock(Scheduler.class), repository)); APIGatewayProxyResponseEvent output = handler.handleRequest(null, null); assertThat(output.getStatusCode(), is(500)); assertThat(output.getBody(), is("hello")); repository = mock(Repository.class); Map<String, Class<? extends Fault>> faults = new LinkedHashMap<>(); faults.put("fault-1", Fault1.class); faults.put("fault-2", Fault2.class); doReturn(faults).when(repository).load(); Prodigy.container(new Container(mock(Scheduler.class), repository)); output = handler.handleRequest(null, null); assertThat(output.getStatusCode(), is(200)); assertThat(output.getBody(), is("{\"fault-1\":\"io.eiichiro.prodigy.Fault1\",\"fault-2\":\"io.eiichiro.prodigy.Fault2\"}")); }
@Override public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) { APIGatewayProxyResponseEvent output = new APIGatewayProxyResponseEvent(); ObjectMapper mapper = new ObjectMapper(); try { Map<String, Class<? extends Fault>> faults = Prodigy.faults(); return output.withStatusCode(200).withBody(mapper.writeValueAsString(faults)); } catch (Exception e) { log.error(e.getMessage(), e); return output.withStatusCode(500).withBody(e.getMessage()); } }
FaultsHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> { @Override public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) { APIGatewayProxyResponseEvent output = new APIGatewayProxyResponseEvent(); ObjectMapper mapper = new ObjectMapper(); try { Map<String, Class<? extends Fault>> faults = Prodigy.faults(); return output.withStatusCode(200).withBody(mapper.writeValueAsString(faults)); } catch (Exception e) { log.error(e.getMessage(), e); return output.withStatusCode(500).withBody(e.getMessage()); } } }
FaultsHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> { @Override public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) { APIGatewayProxyResponseEvent output = new APIGatewayProxyResponseEvent(); ObjectMapper mapper = new ObjectMapper(); try { Map<String, Class<? extends Fault>> faults = Prodigy.faults(); return output.withStatusCode(200).withBody(mapper.writeValueAsString(faults)); } catch (Exception e) { log.error(e.getMessage(), e); return output.withStatusCode(500).withBody(e.getMessage()); } }  }
FaultsHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> { @Override public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) { APIGatewayProxyResponseEvent output = new APIGatewayProxyResponseEvent(); ObjectMapper mapper = new ObjectMapper(); try { Map<String, Class<? extends Fault>> faults = Prodigy.faults(); return output.withStatusCode(200).withBody(mapper.writeValueAsString(faults)); } catch (Exception e) { log.error(e.getMessage(), e); return output.withStatusCode(500).withBody(e.getMessage()); } }  @Override APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context); }
FaultsHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> { @Override public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) { APIGatewayProxyResponseEvent output = new APIGatewayProxyResponseEvent(); ObjectMapper mapper = new ObjectMapper(); try { Map<String, Class<? extends Fault>> faults = Prodigy.faults(); return output.withStatusCode(200).withBody(mapper.writeValueAsString(faults)); } catch (Exception e) { log.error(e.getMessage(), e); return output.withStatusCode(500).withBody(e.getMessage()); } }  @Override APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context);  }