Search in sources :

Example 1 with BrandingRegistryImpl

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))));
}
Also used : BrandingRegistryImpl(org.codice.ddf.branding.BrandingRegistryImpl) BrandingPlugin(org.codice.ddf.branding.BrandingPlugin) JSONObject(net.minidev.json.JSONObject) JSONObject(net.minidev.json.JSONObject) Test(org.junit.Test)

Aggregations

JSONObject (net.minidev.json.JSONObject)1 BrandingPlugin (org.codice.ddf.branding.BrandingPlugin)1 BrandingRegistryImpl (org.codice.ddf.branding.BrandingRegistryImpl)1 Test (org.junit.Test)1