DelegatingConfigurationProvider implements ConfigurationProvider { @Override public List<String> getContentTypes() throws ConfigurationProviderException { try { HttpURLConnection httpURLConnection = httpConnector.get("/c2/config/contentTypes"); try { List<String> contentTypes = objectMapper.readValue(httpURLConnection.getInputStream(), List.class); if (logger.isDebugEnabled()) { logger.debug("Got content types: " + contentTypes); } return contentTypes; } finally { httpURLConnection.disconnect(); } } catch (IOException e) { throw new ConfigurationProviderException("Unable to get content types from delegate.", e); } } DelegatingConfigurationProvider(ConfigurationCache configurationCache, String delegateUrl);  DelegatingConfigurationProvider(ConfigurationCache configurationCache, HttpConnector httpConnector); @Override List<String> getContentTypes(); @Override Configuration getConfiguration(String contentType, Integer version, Map<String, List<String>> parameters); static final Pattern errorPattern; }
@Test(expected = ConfigurationProviderException.class) public void testGetContentTypesMalformed() throws ConfigurationProviderException, IOException { endpointPath = "/c2/config/contentTypes"; initMocks(); when(httpURLConnection.getInputStream()).thenReturn(new ByteArrayInputStream("[malformed".getBytes(StandardCharsets.UTF_8))); delegatingConfigurationProvider.getContentTypes(); }
@Test(expected = ConfigurationProviderException.class) public void testGetContentTypesIOE() throws ConfigurationProviderException, IOException { endpointPath = "/c2/config/contentTypes"; initMocks(); when(httpURLConnection.getInputStream()).thenThrow(new IOException()); delegatingConfigurationProvider.getContentTypes(); }
@Test public void testGetContentTypes() throws ConfigurationProviderException, IOException { endpointPath = "/c2/config/contentTypes"; initMocks(); List<String> contentTypes = Arrays.asList(contentType, "application/json"); when(httpURLConnection.getInputStream()).thenReturn(new ByteArrayInputStream(("[\"" + String.join("\", \"", contentTypes) + "\"]").getBytes(StandardCharsets.UTF_8))); assertEquals(contentTypes, delegatingConfigurationProvider.getContentTypes()); }