SafeUtils { public String[] getManagedSafes(String[] policies, String safeType) { List<String> safes = new ArrayList<String>(); if (policies != null) { for (String policy: policies) { if (policy.startsWith("s_")) { String[] _policies = policy.split("_"); if (_policies[1].equals(safeType)) { String [] safeNameArray = Arrays.copyOfRange(_policies, 2, _policies.length); String safeName = StringUtils.arrayToDelimitedString(safeNameArray, "_"); safes.add(safeName); } } } } return safes.toArray(new String[safes.size()]); } 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_getManagedSafesFromPolicies_successfully() throws IOException { ObjectMapper objMapper = new ObjectMapper(); Response response = getMockResponse(HttpStatus.OK, true, "{\"client_token\":\"8zyIbj3i9hXJFuIPC5AzeUK3\",\"admin\":\"no\",\"access\":{},\"policies\":[\"approle_normal_user\",\"default\",\"s_users_ert\"],\"lease_duration\":1800000}"); JsonNode policiesJsonNode = objMapper.readTree(response.getResponse().toString()).get("policies"); String[] expectedList = {"ert"}; String[] policies = {"s_users_ert"}; String[] policiesRes = safeUtils.getManagedSafes(policies, "users"); assertEquals(expectedList, policiesRes); }