SafeUtils { public Safe getSafeMetaData(String token, String safeType, String safeName){ String _path = "metadata/" + safeType + "/" + safeName; log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Get Info"). put(LogMessage.MESSAGE, String.format ("Trying to get Info for [%s]", _path)). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); Response response = ControllerUtil.getReqProcessor().process("/sdb","{\"path\":\""+_path+"\"}",token); Safe safe = null; if(HttpStatus.OK.equals(response.getHttpstatus())){ try { ObjectMapper objMapper = new ObjectMapper(); JsonNode dataNode = objMapper.readTree(response.getResponse().toString()).get("data"); safe = getSafeInfo(dataNode); } catch (IOException e) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "getSafeMetaDataWithAppRoleElevation"). put(LogMessage.MESSAGE, "Error while trying to get details about the safe"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); } } log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER).toString()). put(LogMessage.ACTION, "Get Info"). put(LogMessage.MESSAGE, "Getting Info completed"). put(LogMessage.STATUS, response.getHttpstatus().toString()). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL).toString()). build())); return safe; } SafeUtils(); List<String> getPoliciesForManagedSafes(JsonNode policiesNode); String[] getManagedSafes(String[] policies, String safeType); boolean canAddOrRemoveUser(UserDetails userDetails, SafeUser safeUser, String action); Safe getSafeMetaData(String token, String safeType, String safeName); Safe getSafeInfo(JsonNode dataNode);  }
@Test public void test_getSafeMetaData_failure() { Response response = getMockResponse(HttpStatus.OK, true, ""); when(ControllerUtil.getSafeType("users/ert")).thenReturn("users"); when(ControllerUtil.getSafeName("users/ert")).thenReturn("ert"); when(ControllerUtil.getReqProcessor().process("/sdb", "{\"path\":\"metadata/users/ert\"}", "5PDrOhsy4ig8L3EpsJZSLAMg")).thenReturn(response); Safe safe = safeUtils.getSafeMetaData("5PDrOhsy4ig8L3EpsJZSLAMg", "users", "ert"); assertNull(safe); }