Search in sources :

Example 1 with BrandingPlugin

use of org.codice.ddf.branding.BrandingPlugin in project ddf by codice.

the class TestLandingPage method setupLandingPage.

@BeforeClass
public static void setupLandingPage() throws IOException {
    BrandingPlugin brandingPlugin = mock(BrandingPlugin.class);
    when(brandingPlugin.getBase64FavIcon()).thenReturn("");
    when(brandingPlugin.getBase64ProductImage()).thenReturn(Base64.getEncoder().encodeToString(fakeImg.getBytes()));
    landingPage = new LandingPage();
    BrandingRegistry branding = mock(BrandingRegistryImpl.class);
    when(branding.getProductName()).thenReturn(productName);
    when(branding.getProductVersion()).thenReturn(version);
    when(branding.getBrandingPlugins()).thenReturn(Collections.singletonList(brandingPlugin));
    when(branding.getAttributeFromBranding(any())).thenCallRealMethod();
    landingPage.setBranding(branding);
    String firstDateLeadingZeroes = "05/07/20 stuff happened";
    String secondDateNoLeadingZeroes = "4/3/20 old stuff happened";
    String noDate = "something happened";
    List<String> unsorted = Arrays.asList(secondDateNoLeadingZeroes, noDate, firstDateLeadingZeroes);
    sorted = Arrays.asList(firstDateLeadingZeroes, secondDateNoLeadingZeroes, noDate);
    landingPage.setAnnouncements(unsorted);
}
Also used : BrandingPlugin(org.codice.ddf.branding.BrandingPlugin) Matchers.containsString(org.hamcrest.Matchers.containsString) BrandingRegistry(org.codice.ddf.branding.BrandingRegistry) BeforeClass(org.junit.BeforeClass)

Example 2 with BrandingPlugin

use of org.codice.ddf.branding.BrandingPlugin 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

BrandingPlugin (org.codice.ddf.branding.BrandingPlugin)2 JSONObject (net.minidev.json.JSONObject)1 BrandingRegistry (org.codice.ddf.branding.BrandingRegistry)1 BrandingRegistryImpl (org.codice.ddf.branding.BrandingRegistryImpl)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1