CerberusMetadataLookup { public ArrayList<Map<String, String>> getCerberusMetadata(String environment) { String cerberusUrl = String.format("https: OkHttpClient httpClient = createHttpClient(); String region = EnvUtils.getRequiredEnv("REGION"); DefaultCerberusCredentialsProviderChain chain = new DefaultCerberusCredentialsProviderChain(cerberusUrl, region); ArrayList<Map<String, String>> sdbMetadata = new ArrayList<>(); String offset = "0"; Boolean hasNext; do { HashMap result = executeRequest(httpClient, chain, cerberusUrl, offset); sdbMetadata.addAll((ArrayList<Map<String, String>>) result.get("safe_deposit_box_metadata")); offset = result.get("next_offset").toString(); hasNext = Boolean.valueOf(result.get("has_next").toString()); } while (hasNext); if (sdbMetadata.isEmpty()) { throw new NullPointerException("SDB Metadata is empty"); } return sdbMetadata; }  ArrayList<Map<String, String>> getCerberusMetadata(String environment); ArrayList<String> searchCerberusMetadata(ArrayList<Map<String, String>> sdbMetadata, String sdbName, String principalName);  }
@Test(expected = RuntimeException.class) public void test_get_metadata_bad_response() throws IOException { MockWebServer mockWebServer = new MockWebServer(); mockWebServer.start(); final String cerberusUrl = "http: mockWebServer.enqueue(new MockResponse().setResponseCode(400).setBody(ERROR_RESPONSE)); ArrayList<Map<String, String>> sdbMetadata = cerberusMetadataLookup.getCerberusMetadata(cerberusUrl); }
@Test(expected = RuntimeException.class) public void test_get_metadata_empty_response_body() throws IOException { MockWebServer mockWebServer = new MockWebServer(); mockWebServer.start(); final String cerberusUrl = "http: mockWebServer.enqueue(new MockResponse().setResponseCode(200)); ArrayList<Map<String, String>> sdbMetadata = cerberusMetadataLookup.getCerberusMetadata(cerberusUrl); }