ValidationResourceManager implements LoggableResource { public boolean handleValidationResource(final HttpServerRequest request) { if (request.uri().equals(validationUri) && HttpMethod.PUT == request.method()) { request.bodyHandler(validationResourceBuffer -> { try { extractValidationValues(validationResourceBuffer); } catch (ValidationException validationException) { updateValidationResource(); log.error("Could not parse validation resource: " + validationException.toString()); ResponseStatusCodeLogUtil.info(request, StatusCode.BAD_REQUEST, ValidationResourceManager.class); request.response().setStatusCode(StatusCode.BAD_REQUEST.getStatusCode()); request.response().setStatusMessage(StatusCode.BAD_REQUEST.getStatusMessage()); if(validationException.getValidationDetails() != null){ request.response().headers().add("content-type", "application/json"); request.response().end(validationException.getValidationDetails().encode()); } else { request.response().end(validationException.getMessage()); } return; } storage.put(validationUri, validationResourceBuffer, status -> { if (status == StatusCode.OK.getStatusCode()) { if(logConfigurationResourceChanges){ RequestLogger.logRequest(vertx.eventBus(), request, status, validationResourceBuffer); } vertx.eventBus().publish(UPDATE_ADDRESS, true); } else { request.response().setStatusCode(status); } ResponseStatusCodeLogUtil.info(request, StatusCode.fromCode(status), ValidationResourceManager.class); request.response().end(); }); }); return true; } if (request.uri().equals(validationUri) && HttpMethod.DELETE == request.method()) { getValidationResource().reset(); log.info("Reset ValidationResource"); } return false; } ValidationResourceManager(Vertx vertx, final ResourceStorage storage, String validationUri); ValidationResource getValidationResource(); @Override void enableResourceLogging(boolean resourceLoggingEnabled); boolean handleValidationResource(final HttpServerRequest request);  }
@Test public void testHandleValidationResourceWithGETRequests(TestContext context){ validationResourceManager = new ValidationResourceManager(vertx, new MockResourceStorage(ImmutableMap.of(VALIDATION_URI, VALIDATION_RESOURCE_VALID)), VALIDATION_URI); class GETValidationResourceRequest extends HttpServerRequestMock{ @Override public HttpMethod method() { return HttpMethod.GET; } @Override public String uri() { return VALIDATION_URI; } @Override public String path() { return VALIDATION_URI; } } boolean handled = validationResourceManager.handleValidationResource(new GETValidationResourceRequest()); context.assertFalse(handled, "GET Request to validationUri should not be handled"); class GETOtherResourceRequest extends HttpServerRequestMock{ @Override public HttpMethod method() { return HttpMethod.GET; } @Override public String uri() { return "/some/other/resource"; } @Override public String path() { return "/some/other/resource"; } } handled = validationResourceManager.handleValidationResource(new GETOtherResourceRequest()); context.assertFalse(handled, "GET Request to some other resource should not be handled"); }