use of org.codice.ddf.branding.BrandingRegistryImpl in project ddf by codice.
the class PlatformUiConfigurationTest method testConfig.
@Test
public void testConfig() throws IOException {
PlatformUiConfiguration configuration = new PlatformUiConfiguration();
String wsOutput = configuration.getConfig();
// throws JSON Parse exception if not valid json.
Object obj = JSONValue.parse(wsOutput);
if (!(obj instanceof JSONObject)) {
fail("PlatformUiConfiguration is not a JSON Object.");
}
BrandingPlugin branding = mock(BrandingPlugin.class);
when(branding.getBase64FavIcon()).thenReturn(Base64.getEncoder().encodeToString("fav".getBytes()));
when(branding.getBase64ProductImage()).thenReturn(Base64.getEncoder().encodeToString("image".getBytes()));
BrandingRegistryImpl brandingPlugin = mock(BrandingRegistryImpl.class);
when(brandingPlugin.getProductName()).thenReturn("product");
when(brandingPlugin.getBrandingPlugins()).thenReturn(Collections.singletonList(branding));
when(brandingPlugin.getAttributeFromBranding(any())).thenCallRealMethod();
configuration.setBranding(brandingPlugin);
configuration.setHeader("header");
configuration.setFooter("footer");
configuration.setBackground("background");
configuration.setColor("color");
wsOutput = configuration.getConfig();
// throws JSON Parse exception if not valid json.
obj = JSONValue.parse(wsOutput);
if (!(obj instanceof JSONObject)) {
fail("PlatformUiConfiguration is not a JSON Object.");
}
JSONObject jsonObject = (JSONObject) obj;
assertEquals("header", jsonObject.get(PlatformUiConfiguration.HEADER));
assertEquals("footer", jsonObject.get(PlatformUiConfiguration.FOOTER));
assertEquals("background", jsonObject.get(PlatformUiConfiguration.BACKGROUND));
assertEquals("color", jsonObject.get(PlatformUiConfiguration.COLOR));
assertEquals("product", jsonObject.get(PlatformUiConfiguration.TITLE));
assertEquals("image", new String(Base64.getMimeDecoder().decode((String) jsonObject.get(PlatformUiConfiguration.PRODUCT_IMAGE))));
assertEquals("fav", new String(Base64.getMimeDecoder().decode((String) jsonObject.get(PlatformUiConfiguration.FAV_ICON))));
}
Aggregations