use of java.util.Dictionary in project aries by apache.
the class DSLTest method testConfigurationsAndRegistrations.
@Test
public void testConfigurationsAndRegistrations() throws InvalidSyntaxException, IOException, InterruptedException {
ServiceReference<ConfigurationAdmin> serviceReference = bundleContext.getServiceReference(ConfigurationAdmin.class);
ConfigurationAdmin configurationAdmin = bundleContext.getService(serviceReference);
/* For each factory configuration register a service with the property
key set to the value of the property key that comes with the
configuration */
OSGi<ServiceRegistration<Service>> program = configurations("test.configuration").map(d -> d.get("key")).flatMap(key -> register(Service.class, new Service(), new HashMap<String, Object>() {
{
put("key", key);
}
}));
OSGiResult<ServiceRegistration<Service>> result = program.run(bundleContext);
assertEquals(0, bundleContext.getServiceReferences(Service.class, "(test.configuration=*)").size());
CountDownLatch addedLatch = new CountDownLatch(3);
ServiceRegistration<?> addedServiceRegistration = bundleContext.registerService(ManagedServiceFactory.class, new ManagedServiceFactory() {
@Override
public String getName() {
return "";
}
@Override
public void updated(String s, Dictionary<String, ?> dictionary) throws ConfigurationException {
addedLatch.countDown();
}
@Override
public void deleted(String s) {
}
}, new Hashtable<String, Object>() {
{
put("service.pid", "test.configuration");
}
});
CountDownLatch deletedLatch = new CountDownLatch(3);
ServiceRegistration<?> deletedServiceRegistration = bundleContext.registerService(ManagedServiceFactory.class, new ManagedServiceFactory() {
@Override
public String getName() {
return "";
}
@Override
public void updated(String s, Dictionary<String, ?> dictionary) throws ConfigurationException {
}
@Override
public void deleted(String s) {
deletedLatch.countDown();
}
}, new Hashtable<String, Object>() {
{
put("service.pid", "test.configuration");
}
});
Configuration configuration = configurationAdmin.createFactoryConfiguration("test.configuration");
configuration.update(new Hashtable<String, Object>() {
{
put("key", "service one");
}
});
Configuration configuration2 = configurationAdmin.createFactoryConfiguration("test.configuration");
configuration2.update(new Hashtable<String, Object>() {
{
put("key", "service two");
}
});
Configuration configuration3 = configurationAdmin.createFactoryConfiguration("test.configuration");
configuration3.update(new Hashtable<String, Object>() {
{
put("key", "service three");
}
});
assertTrue(addedLatch.await(10, TimeUnit.SECONDS));
assertEquals(1, bundleContext.getServiceReferences(Service.class, "(key=service one)").size());
assertEquals(1, bundleContext.getServiceReferences(Service.class, "(key=service two)").size());
assertEquals(1, bundleContext.getServiceReferences(Service.class, "(key=service three)").size());
configuration3.delete();
configuration2.delete();
configuration.delete();
assertTrue(deletedLatch.await(10, TimeUnit.SECONDS));
assertEquals(0, bundleContext.getServiceReferences(Service.class, "(test.configuration=*)").size());
addedServiceRegistration.unregister();
deletedServiceRegistration.unregister();
result.close();
bundleContext.ungetService(serviceReference);
}
use of java.util.Dictionary in project aries by apache.
the class DSLTest method testConfigurations.
@Test
public void testConfigurations() throws IOException, InterruptedException {
ServiceReference<ConfigurationAdmin> serviceReference = bundleContext.getServiceReference(ConfigurationAdmin.class);
ConfigurationAdmin configurationAdmin = bundleContext.getService(serviceReference);
AtomicReference<Dictionary<?, ?>> atomicReference = new AtomicReference<>(null);
CountDownLatch countDownLatch = new CountDownLatch(1);
Configuration configuration = null;
try (OSGiResult<Dictionary<String, ?>> result = configurations("test.configuration").run(bundleContext, x -> {
atomicReference.set(x);
countDownLatch.countDown();
})) {
assertNull(atomicReference.get());
configuration = configurationAdmin.createFactoryConfiguration("test.configuration");
configuration.update(new Hashtable<>());
countDownLatch.await(10, TimeUnit.SECONDS);
assertNotNull(atomicReference.get());
} finally {
bundleContext.ungetService(serviceReference);
if (configuration != null) {
configuration.delete();
}
}
}
use of java.util.Dictionary in project aries by apache.
the class FragmentUtilsTest method testFragmentCreation.
@Test
public void testFragmentCreation() throws Exception {
Bundle exportBundle = makeBundleWithExports("export.bundle", "1.2.3", "export.package;version=\"1.0.0\";uses:=\"foo.jar,bar.jar\";singleton:=true");
Dictionary fragmentHeaders = makeFragmentFromExportBundle(exportBundle).getHeaders();
assertNotNull("No headers in the fragment", fragmentHeaders);
assertEquals("Wrong symbolicName", "scooby.doo.test.fragment", fragmentHeaders.get(Constants.BUNDLE_SYMBOLICNAME));
assertEquals("Wrong version", "0.0.0", fragmentHeaders.get(Constants.BUNDLE_VERSION));
assertEquals("Wrong Bundle manifest version", "2", fragmentHeaders.get(Constants.BUNDLE_MANIFESTVERSION));
assertEquals("Wrong Fragment host", "scooby.doo;bundle-version=\"0.0.0\"", fragmentHeaders.get(Constants.FRAGMENT_HOST));
assertEquals("Wrong Bundle Name", "Test Fragment bundle", fragmentHeaders.get(Constants.BUNDLE_NAME));
assertEquals("Wrong Imports", "export.package;version=\"1.0.0\";bundle-symbolic-name=\"export.bundle\";bundle-version=\"[1.2.3,1.2.3]\"", fragmentHeaders.get(Constants.IMPORT_PACKAGE));
}
use of java.util.Dictionary in project ddf by codice.
the class ConfigureTestCommons method configureMetacardAttributeSecurityFiltering.
public static Dictionary<String, Object> configureMetacardAttributeSecurityFiltering(List<String> intersectAttributes, List<String> unionAttributes, AdminConfig configAdmin) throws IOException {
Dictionary properties = new Hashtable<>();
properties.put("intersectMetacardAttributes", intersectAttributes);
properties.put("unionMetacardAttributes", unionAttributes);
return configureMetacardAttributeSecurityFiltering(properties, configAdmin);
}
use of java.util.Dictionary in project ddf by codice.
the class ConfigureTestCommons method configureFilterInvalidMetacards.
public static void configureFilterInvalidMetacards(String filterErrors, String filterWarnings, AdminConfig configAdmin) throws IOException {
Configuration config = configAdmin.getConfiguration(METACARD_VALIDATITY_FILTER_PLUGIN_SERVICE_PID, null);
Dictionary properties = new Hashtable<>();
properties.put("filterErrors", filterErrors);
properties.put("filterWarnings", filterWarnings);
config.update(properties);
}
Aggregations