SysService { public ResponseEntity<String> checkVaultHealth() { log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Check Health"). put(LogMessage.MESSAGE, "Trying to get health of the Vault Server"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); Response response = reqProcessor.process("/health","{}",""); if(HttpStatus.OK.equals(response.getHttpstatus()) || HttpStatus.TOO_MANY_REQUESTS.equals(response.getHttpstatus())) { return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Healthy.All OK\"]}"); } else { response = reqProcessor.process("/v2/health","{}",""); if(HttpStatus.OK.equals(response.getHttpstatus()) || HttpStatus.TOO_MANY_REQUESTS.equals(response.getHttpstatus())) { log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Check Health"). put(LogMessage.MESSAGE, "Getting Vault Health information completed successfully"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Healthy.All OK\"]}"); } else { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Check Health"). put(LogMessage.MESSAGE, "Getting Vault Health information failed."). put(LogMessage.RESPONSE, response.getResponse()). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(response.getHttpstatus()).body("{\"messages\":[\"Not OK \"]}"); } } }  ResponseEntity<String> checkVaultHealth(); ResponseEntity<String> checkVaultSealStatus(); ResponseEntity<String> unseal(Unseal unseal); ResponseEntity<String> unsealProgress(String serverip);  }
@Test public void test_checkVaultHealth_successfully_https() { Response response = getMockResponse(HttpStatus.OK, true, "{ \"messages\": [ \"Healthy.All OK\" ]}"); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Healthy.All OK\"]}"); when( reqProcessor.process("/health","{}","")).thenReturn(response); ResponseEntity<String> responseEntity = sysService.checkVaultHealth(); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertEquals(responseEntityExpected, responseEntity); }
@Test public void test_checkVaultHealth_successfully_http() { Response responseNotFound = getMockResponse(HttpStatus.NOT_FOUND, true, ""); Response response = getMockResponse(HttpStatus.OK, true, "{ \"messages\": [ \"Healthy.All OK\" ]}"); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Healthy.All OK\"]}"); when( reqProcessor.process("/health","{}","")).thenReturn(responseNotFound); when(reqProcessor.process("/v2/health","{}","")).thenReturn(response); ResponseEntity<String> responseEntity = sysService.checkVaultHealth(); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertEquals(responseEntityExpected, responseEntity); }
@Test public void test_checkVaultHealth_failure() { Response responseNotFound = getMockResponse(HttpStatus.NOT_FOUND, true, ""); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.NOT_FOUND).body("{\"messages\":[\"Not OK \"]}"); when( reqProcessor.process("/health","{}","")).thenReturn(responseNotFound); when(reqProcessor.process("/v2/health","{}","")).thenReturn(responseNotFound); ResponseEntity<String> responseEntity = sysService.checkVaultHealth(); assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); assertEquals(responseEntityExpected, responseEntity); }