CerberusMetadataLookup { public ArrayList<String> searchCerberusMetadata(ArrayList<Map<String, String>> sdbMetadata, String sdbName, String principalName) { if (sdbMetadata == null) { throw new NullPointerException("SDB Metadata is empty"); } ArrayList<String> owner = new ArrayList<>(); for (Map<String, String> entry : sdbMetadata) { if (entry.get("path").contains(sdbName) && !sdbName.isEmpty()) { owner.add(entry.get("owner")); if (entry.get("created_by").contains(EMAIL_SYMBOL)) owner.add(entry.get("created_by")); if (entry.get("last_updated_by").contains(EMAIL_SYMBOL) && !entry.get("last_updated_by").equals(entry.get("created_by"))) { owner.add(entry.get("last_updated_by")); } return owner; } else { if (entry.containsValue(principalName)) { owner.add(entry.get("owner")); if (entry.get("created_by").contains(EMAIL_SYMBOL)) owner.add(entry.get("created_by")); if (entry.get("last_updated_by").contains(EMAIL_SYMBOL) && !entry.get("last_updated_by").equals(entry.get("created_by"))) { owner.add(entry.get("last_updated_by")); } return owner; } } } owner.add("No owner found"); return owner; }  ArrayList<Map<String, String>> getCerberusMetadata(String environment); ArrayList<String> searchCerberusMetadata(ArrayList<Map<String, String>> sdbMetadata, String sdbName, String principalName);  }
@Test public void test_search_cerberus_metadata_successful() throws IOException { HashMap responseMap = new ObjectMapper().readValue(mockResponseBodyString, HashMap.class); ArrayList<Map<String, String>> sdbMetadata = (ArrayList<Map<String, String>>) responseMap.get("safe_deposit_box_metadata"); String sdbName = "test sdb"; String principalName = "arn:aws:iam::111111111111:role/example/role"; ArrayList<String> results = cerberusMetadataLookup.searchCerberusMetadata(sdbMetadata, sdbName, principalName); assertTrue(results.contains("Test.Owner")); assertTrue(results.contains("test.user@nike.com")); assertFalse(results.contains("arn:aws:iam::111111111111:role/example/role")); }
@Test public void test_search_cerberus_metadata_successful_with_unknown_sdb_name() throws IOException { HashMap responseMap = new ObjectMapper().readValue(mockResponseBodyString, HashMap.class); ArrayList<Map<String, String>> sdbMetadata = (ArrayList<Map<String, String>>) responseMap.get("safe_deposit_box_metadata"); String sdbName = "_unknown"; String principalName = "arn:aws:iam::111111111111:role/example/role"; ArrayList<String> results = cerberusMetadataLookup.searchCerberusMetadata(sdbMetadata, sdbName, principalName); assertTrue(results.contains("Test.Owner")); assertTrue(results.contains("test.user@nike.com")); assertFalse(results.contains("arn:aws:iam::111111111111:role/example/role")); }
@Test(expected = NullPointerException.class) public void test_search_cerberus_metadata_parameter_null() throws IOException { String sdbName = "test sdb"; String principalName = "arn:aws:iam::111111111111:role/example/role"; ArrayList<String> results = cerberusMetadataLookup.searchCerberusMetadata(null, sdbName, principalName); assertNotNull(results); }
@Test public void test_search_cerberus_metadata_parameters_empty() throws IOException { HashMap result = new ObjectMapper().readValue(mockResponseBodyString, HashMap.class); ArrayList<Map<String, String>> sdbMetadata = (ArrayList<Map<String, String>>) result.get("safe_deposit_box_metadata"); ArrayList<String> results = cerberusMetadataLookup.searchCerberusMetadata(sdbMetadata, "", ""); assertTrue(results.contains("No owner found")); }
@Test public void test_search_cerberus_metadata_not_successful() throws IOException { HashMap responseMap = new ObjectMapper().readValue(mockResponseBodyString, HashMap.class); ArrayList<Map<String, String>> sdbMetadata = (ArrayList<Map<String, String>>) responseMap.get("safe_deposit_box_metadata"); String sdbName = "none"; String principalName = "arn:aws:iam::00000000000:role/example/role"; ArrayList<String> results = cerberusMetadataLookup.searchCerberusMetadata(sdbMetadata, sdbName, principalName); assertTrue(results.contains("No owner found")); }