SafesService { public ResponseEntity<String> createNestedfolder(String token, String path, UserDetails userDetails) { log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "createNestedfolder"). put(LogMessage.MESSAGE, String.format ("Trying to createNestedfolder [%s]", path)). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); path = (path != null) ? path.toLowerCase(): path; if(ControllerUtil.isPathValid(path) && isValidSafe(token, path, userDetails)){ String jsonStr ="{\"path\":\""+path +"\",\"data\":{\"default\":\"default\"}}"; Response response = reqProcessor.process("/sdb/createfolder",jsonStr,token); log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "createNestedfolder"). put(LogMessage.MESSAGE, "createNestedfolder completed"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); if(response.getHttpstatus().equals(HttpStatus.NO_CONTENT)) { return ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Folder created \"]}"); } return ResponseEntity.status(response.getHttpstatus()).body(response.getResponse()); }else{ log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "createNestedfolder"). put(LogMessage.MESSAGE, "createNestedfolder completed"). put(LogMessage.RESPONSE, "Invalid Path"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("{\"errors\":[\"Invalid path\"]}"); } }  ResponseEntity<String> getFolders( String token, String path); ResponseEntity<String> getInfo(String token, String path); ResponseEntity<String> createfolder(String token, String path); ResponseEntity<String> createSafe(String token, Safe safe); ResponseEntity<String> getSafe(String token, String path); ResponseEntity<String> deleteSafe(String token, Safe safe, UserDetails userDetails); ResponseEntity<String> updateSafe(String token, Safe safe); ResponseEntity<String> addUserToSafe(String token, SafeUser safeUser, UserDetails userDetails); ResponseEntity<String> addGroupToSafe(String token, SafeGroup safeGroup, UserDetails userDetails); ResponseEntity<String> removeUserFromSafe(String token, SafeUser safeUser, UserDetails userDetails); ResponseEntity<String> removeGroupFromSafe(String token, SafeGroup safeGroup, UserDetails userDetails); ResponseEntity<String> addAwsRoleToSafe(String token, AWSRole awsRole); ResponseEntity<String> removeAWSRoleFromSafe(String token, AWSRole awsRole, boolean detachOnly, UserDetails userDetails); ResponseEntity<String> deletefolder(String token, String path, UserDetails userDetails); ResponseEntity<String> getFoldersRecursively(String token, String path); ResponseEntity<String> createNestedfolder(String token, String path, UserDetails userDetails); ResponseEntity<String> associateApproletoSDB(String token, SafeAppRoleAccess safeAppRoleAccess); ResponseEntity<String> removeApproleFromSafe(String token, String jsonstr);  }
@Test public void test_createNestedfolder_successfully() { String responseJson = "{\"messages\":[\"Folder created \"]}"; String path = "shared/mysafe01"; String jsonStr = "{\"path\":\"" + path + "\",\"data\":{\"default\":\"default\"}}"; String token = "5PDrOhsy4ig8L3EpsJZSLAMg"; Response response = getMockResponse(HttpStatus.OK, true, responseJson); ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body(responseJson); when(ControllerUtil.isPathValid(path)).thenReturn(true); when(reqProcessor.process("/sdb/createfolder",jsonStr,token)).thenReturn(response); UserDetails userDetails = getMockUser(false); VaultTokenLookupDetails vaultTokenLookupDetails = new VaultTokenLookupDetails(); vaultTokenLookupDetails.setPolicies(new String[] {"w_shared_mysafe01"}); when(ControllerUtil.getSafeType(path)).thenReturn("shared"); when(ControllerUtil.getSafeName(path)).thenReturn("mysafe01"); try { when(tokenValidator.getVaultTokenLookupDetails(token)).thenReturn(vaultTokenLookupDetails); } catch (TVaultValidationException e) {} ResponseEntity<String> responseEntity = safesService.createNestedfolder(token, path, userDetails); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); }