### Question:
AutoRecoveryStatusService implements HttpEndpointService { @Override public HttpServiceResponse handle(HttpServiceRequest request) throws Exception { return MetadataDrivers.runFunctionWithLedgerManagerFactory(conf, ledgerManagerFactory -> { try (LedgerUnderreplicationManager ledgerUnderreplicationManager = ledgerManagerFactory .newLedgerUnderreplicationManager()) { switch (request.getMethod()) { case GET: return handleGetStatus(ledgerUnderreplicationManager); case PUT: return handlePutStatus(request, ledgerUnderreplicationManager); default: return new HttpServiceResponse("Not found method. Should be GET or PUT method", HttpServer.StatusCode.NOT_FOUND); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new UncheckedExecutionException(e); } catch (Exception e) { throw new UncheckedExecutionException(e); } }); } AutoRecoveryStatusService(ServerConfiguration conf); @Override HttpServiceResponse handle(HttpServiceRequest request);  }### Answer:
@Test public void testGetStatus() throws Exception { HttpServiceRequest request = new HttpServiceRequest(null, HttpServer.Method.GET, null); HttpServiceResponse response = autoRecoveryStatusService.handle(request); assertEquals(HttpServer.StatusCode.OK.getValue(), response.getStatusCode()); JsonNode json = mapper.readTree(response.getBody()); assertEquals(Boolean.TRUE, json.get("enabled").asBoolean()); }
@Test public void testEnableStatus() throws Exception { Map<String, String> params = ImmutableMap.of("enabled", "true"); HttpServiceRequest request = new HttpServiceRequest(null, HttpServer.Method.PUT, params); HttpServiceResponse response = autoRecoveryStatusService.handle(request); assertEquals(HttpServer.StatusCode.OK.getValue(), response.getStatusCode()); JsonNode json = mapper.readTree(response.getBody()); assertEquals(Boolean.TRUE, json.get("enabled").asBoolean()); request = new HttpServiceRequest(null, HttpServer.Method.GET, params); response = autoRecoveryStatusService.handle(request); assertEquals(HttpServer.StatusCode.OK.getValue(), response.getStatusCode()); json = mapper.readTree(response.getBody()); assertEquals(Boolean.TRUE, json.get("enabled").asBoolean()); }
@Test public void testDisableStatus() throws Exception { Map<String, String> params = ImmutableMap.of("enabled", "false"); HttpServiceRequest request = new HttpServiceRequest(null, HttpServer.Method.PUT, params); HttpServiceResponse response = autoRecoveryStatusService.handle(request); assertEquals(HttpServer.StatusCode.OK.getValue(), response.getStatusCode()); JsonNode json = mapper.readTree(response.getBody()); assertEquals(Boolean.FALSE, json.get("enabled").asBoolean()); request = new HttpServiceRequest(null, HttpServer.Method.GET, params); response = autoRecoveryStatusService.handle(request); assertEquals(HttpServer.StatusCode.OK.getValue(), response.getStatusCode()); json = mapper.readTree(response.getBody()); assertEquals(Boolean.FALSE, json.get("enabled").asBoolean()); }
@Test public void testInvalidParams() throws Exception { Map<String, String> params = ImmutableMap.of("enable", "false"); HttpServiceRequest request = new HttpServiceRequest(null, HttpServer.Method.PUT, params); HttpServiceResponse response = autoRecoveryStatusService.handle(request); assertEquals(HttpServer.StatusCode.BAD_REQUEST.getValue(), response.getStatusCode()); }
@Test public void testInvalidMethod() throws Exception { HttpServiceRequest request = new HttpServiceRequest(null, HttpServer.Method.POST, null); HttpServiceResponse response = autoRecoveryStatusService.handle(request); assertEquals(HttpServer.StatusCode.NOT_FOUND.getValue(), response.getStatusCode()); }