FlagsHandler extends LoggingRequestHandler { @Override public HttpResponse handle(HttpRequest request) { try { switch (request.getMethod()) { case GET: return handleGET(request); case DELETE: return handleDELETE(request); case PUT: return handlePUT(request); default: return ErrorResponse.methodNotAllowed("Method '" + request.getMethod() + "' is not supported"); } } catch (IllegalArgumentException e) { return ErrorResponse.badRequest(Exceptions.toMessageString(e)); } catch (RuntimeException e) { log.log(Level.WARNING, "Unexpected error handling '" + request.getUri() + "'", e); return ErrorResponse.internalServerError(Exceptions.toMessageString(e)); } } @Inject  FlagsHandler(LoggingRequestHandler.Context context, FlagsDb flagsDb); @Override HttpResponse handle(HttpRequest request);  }
@Test public void testForcing() { assertThat(handle(Method.PUT, "/data/" + new FlagId("undef"), "", 400), containsString("There is no flag 'undef'")); assertThat(handle(Method.PUT, "/data/" + new FlagId("undef") + "?force=true", "", 400), containsString("No content to map due to end-of-input")); assertThat(handle(Method.PUT, "/data/" + FLAG1.id(), "{}", 400), containsString("Flag ID missing")); assertThat(handle(Method.PUT, "/data/" + FLAG1.id(), "{\"id\": \"id1\",\"rules\": [{\"value\":\"string\"}]}", 400), containsString("Wrong type of JsonNode: STRING")); assertThat(handle(Method.PUT, "/data/" + FLAG1.id() + "?force=true", "{\"id\": \"id1\",\"rules\": [{\"value\":\"string\"}]}", 200), is("")); }