SysService { public ResponseEntity<String> unsealProgress (String serverip){ log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Unseal Vault Progress"). put(LogMessage.MESSAGE, String.format("Unseal Vault Progress for [%s]", serverip)). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); Response response = reqProcessor.process("/unseal-progress","{\"serverip\":\""+serverip+"\",\"port\":\""+vaultPort+"\"}",""); log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Unseal Vault"). put(LogMessage.MESSAGE, String.format("Unsealing Vault server completed for [%s]", serverip)). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); if(HttpStatus.OK.equals(response.getHttpstatus())) { return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); } else { if(HttpStatus.INTERNAL_SERVER_ERROR.equals(response.getHttpstatus())) { response = reqProcessor.process("/v2/unseal-progress","{\"serverip\":\""+serverip+"\",\"port\":\""+vaultPort+"\"}",""); } return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); } }  ResponseEntity<String> checkVaultHealth(); ResponseEntity<String> checkVaultSealStatus(); ResponseEntity<String> unseal(Unseal unseal); ResponseEntity<String> unsealProgress(String serverip);  }
@Test public void test_unsealProgress_successfully_https() { Response response = getMockResponse(HttpStatus.OK, true, "{ \"sealed\": false, \"progress\": 0}"); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body("{ \"sealed\": false, \"progress\": 0}"); when(reqProcessor.process("/unseal-progress","{\"serverip\":\"localhost\",\"port\":\"null\"}","")).thenReturn(response); ResponseEntity<String> responseEntity = sysService.unsealProgress("localhost"); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertEquals(responseEntityExpected, responseEntity); }
@Test public void test_unsealProgress_successfully_http() { Response responseOk = getMockResponse(HttpStatus.OK, true, "{ \"sealed\": false, \"progress\": 0}"); Response response = getMockResponse(HttpStatus.INTERNAL_SERVER_ERROR, true, "{\"errors\": [ \"vault is unsealed\" ]}"); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body("{ \"sealed\": false, \"progress\": 0}"); when(reqProcessor.process("/unseal-progress","{\"serverip\":\"localhost\",\"port\":\"null\"}","")).thenReturn(response); when(reqProcessor.process("/v2/unseal-progress","{\"serverip\":\"localhost\",\"port\":\"null\"}","")).thenReturn(responseOk); ResponseEntity<String> responseEntity = sysService.unsealProgress("localhost"); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertEquals(responseEntityExpected, responseEntity); }