Search in sources :

Example 1 with BrandingRegistryImpl

use of org.codice.ddf.branding.impl.BrandingRegistryImpl in project ddf by codice.

the class PlatformUiConfigurationTest method testConfig.

@Test
public void testConfig() throws IOException {
    int timeout = 1234;
    String wsOutput = configuration.getConfigAsJsonString();
    // 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()));
    when(branding.getBase64VendorImage()).thenReturn(Base64.getEncoder().encodeToString("vendorimage".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");
    configuration.setTimeout(timeout);
    wsOutput = configuration.getConfigAsJsonString();
    // 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_CONFIG_KEY));
    assertEquals("footer", jsonObject.get(PlatformUiConfiguration.FOOTER_CONFIG_KEY));
    assertEquals("background", jsonObject.get(PlatformUiConfiguration.BACKGROUND_CONFIG_KEY));
    assertEquals("color", jsonObject.get(PlatformUiConfiguration.COLOR_CONFIG_KEY));
    assertEquals("product", jsonObject.get(PlatformUiConfiguration.TITLE_CONFIG_KEY));
    assertEquals("image", new String(Base64.getMimeDecoder().decode((String) jsonObject.get(PlatformUiConfiguration.PRODUCT_IMAGE_CONFIG_KEY))));
    assertEquals("vendorimage", new String(Base64.getMimeDecoder().decode((String) jsonObject.get(PlatformUiConfiguration.VENDOR_IMAGE_CONFIG_KEY))));
    assertEquals("fav", new String(Base64.getMimeDecoder().decode((String) jsonObject.get(PlatformUiConfiguration.FAV_ICON_CONFIG_KEY))));
    assertEquals(timeout, jsonObject.get(PlatformUiConfiguration.TIMEOUT_CONFIG_KEY));
}
Also used : BrandingRegistryImpl(org.codice.ddf.branding.impl.BrandingRegistryImpl) BrandingPlugin(org.codice.ddf.branding.BrandingPlugin) JSONObject(net.minidev.json.JSONObject) JSONObject(net.minidev.json.JSONObject) Test(org.junit.Test)

Example 2 with BrandingRegistryImpl

use of org.codice.ddf.branding.impl.BrandingRegistryImpl in project ddf by codice.

the class BrandingRegistryTest method getBrandingRegistry.

private BrandingRegistry getBrandingRegistry() {
    BrandingPlugin plugin = mock(BrandingPlugin.class);
    when(plugin.getProductName()).thenReturn("DDF1 v1.0.0");
    return new BrandingRegistryImpl() {

        public BundleContext getContext() {
            BundleContext bundleContext = mock(BundleContext.class);
            ServiceReference<BrandingPlugin> serviceReference = mock(ServiceReference.class);
            when(bundleContext.getService(serviceReference)).thenReturn(plugin);
            try {
                when(bundleContext.getServiceReferences(BrandingPlugin.class, "")).thenReturn(Collections.singletonList(serviceReference));
            } catch (InvalidSyntaxException e) {
            // won't happen
            }
            return bundleContext;
        }
    };
}
Also used : BrandingRegistryImpl(org.codice.ddf.branding.impl.BrandingRegistryImpl) BrandingPlugin(org.codice.ddf.branding.BrandingPlugin) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) BundleContext(org.osgi.framework.BundleContext)

Example 3 with BrandingRegistryImpl

use of org.codice.ddf.branding.impl.BrandingRegistryImpl in project ddf by codice.

the class BrandingRegistryTest method getBrandingRegistryMultiplePlugins.

private BrandingRegistry getBrandingRegistryMultiplePlugins(String firstReturnValue, String secondReturnValue) {
    BrandingPlugin plugin = mock(BrandingPlugin.class);
    when(plugin.getProductName()).thenReturn(firstReturnValue);
    BrandingPlugin plugin2 = mock(BrandingPlugin.class);
    when(plugin2.getProductName()).thenReturn(secondReturnValue);
    return new BrandingRegistryImpl() {

        public BundleContext getContext() {
            BundleContext bundleContext = mock(BundleContext.class);
            ServiceReference<BrandingPlugin> serviceReference = mock(ServiceReference.class);
            when(bundleContext.getService(serviceReference)).thenReturn(plugin);
            ServiceReference<BrandingPlugin> serviceReference2 = mock(ServiceReference.class);
            when(bundleContext.getService(serviceReference2)).thenReturn(plugin2);
            when(serviceReference.compareTo(serviceReference2)).thenReturn(1);
            when(serviceReference2.compareTo(serviceReference)).thenReturn(-1);
            try {
                when(bundleContext.getServiceReferences(BrandingPlugin.class, "")).thenReturn(Arrays.asList(serviceReference, serviceReference2));
            } catch (InvalidSyntaxException e) {
            // won't happen
            }
            return bundleContext;
        }
    };
}
Also used : BrandingRegistryImpl(org.codice.ddf.branding.impl.BrandingRegistryImpl) BrandingPlugin(org.codice.ddf.branding.BrandingPlugin) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) BundleContext(org.osgi.framework.BundleContext)

Aggregations

BrandingPlugin (org.codice.ddf.branding.BrandingPlugin)3 BrandingRegistryImpl (org.codice.ddf.branding.impl.BrandingRegistryImpl)3 BundleContext (org.osgi.framework.BundleContext)2 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)2 JSONObject (net.minidev.json.JSONObject)1 Test (org.junit.Test)1