use of org.apache.felix.cm.MockBundleContext in project felix by apache.
the class DynamicBindingsTest method test_store_bindings.
public void test_store_bindings() throws IOException {
// ensure there is no file
bindingsFile.delete();
final BundleContext ctx = new MockBundleContext();
final DynamicBindings dm = new DynamicBindings(ctx, persistenceManager);
dm.putLocation(PID1, LOCATION1);
assertEquals(LOCATION1, dm.getLocation(PID1));
assertTrue(bindingsFile.exists());
final Dictionary bindings = persistenceManager.load(DynamicBindings.BINDINGS_FILE_NAME);
assertNotNull(bindings);
assertEquals(1, bindings.size());
assertEquals(LOCATION1, bindings.get(PID1));
}
use of org.apache.felix.cm.MockBundleContext in project felix by apache.
the class ConfigurationManagerTest method test_factoryConfigurationCleanup.
public void test_factoryConfigurationCleanup() throws Exception {
MockNotCachablePersistenceManager pm = new MockNotCachablePersistenceManager();
ConfigurationManager configMgr = new ConfigurationManager(new CachingPersistenceManagerProxy(pm), null);
final Field bcField = configMgr.getClass().getDeclaredField("bundleContext");
bcField.setAccessible(true);
bcField.set(configMgr, new MockBundleContext());
setServiceTrackerField(configMgr, "persistenceManagerTracker");
setServiceTrackerField(configMgr, "logTracker");
setServiceTrackerField(configMgr, "configurationListenerTracker");
setServiceTrackerField(configMgr, "syncConfigurationListenerTracker");
final Field mstField = configMgr.getClass().getDeclaredField("managedServiceFactoryTracker");
mstField.setAccessible(true);
mstField.set(configMgr, new ManagedServiceFactoryTracker(configMgr) {
@Override
public void open() {
}
});
final Field utField = configMgr.getClass().getDeclaredField("updateThread");
utField.setAccessible(true);
utField.set(configMgr, new UpdateThread(null, "Test updater") {
@Override
void schedule(Runnable update) {
update.run();
}
});
final String factoryPid = "my.factory";
final Dictionary<String, Object> props = new Hashtable<>();
props.put("hello", "world");
final ConfigurationImpl c1 = configMgr.createFactoryConfiguration(factoryPid, null);
c1.update(props);
final ConfigurationImpl c2 = configMgr.createFactoryConfiguration(factoryPid, null);
c2.update(props);
final ConfigurationImpl c3 = configMgr.createFactoryConfiguration(factoryPid, null);
c3.update(props);
assertEquals(4, pm.getStored().size());
c1.delete();
assertEquals(3, pm.getStored().size());
c2.delete();
assertEquals(2, pm.getStored().size());
c3.delete();
assertEquals(0, pm.getStored().size());
}
use of org.apache.felix.cm.MockBundleContext in project felix by apache.
the class ConfigurationManagerTest method testLogSetup.
@Test
public void testLogSetup() throws IOException {
final MockBundleContext bundleContext = new MockBundleContext();
createConfigurationManagerAndLog(null);
// ensure the configuration data goes to target
bundleContext.setProperty("felix.cm.dir", "target/config");
// default value is 2
bundleContext.setProperty("felix.cm.loglevel", null);
Log.logger.start(bundleContext);
assertEquals(2, getLogLevel());
Log.logger.stop();
// illegal number yields default value
bundleContext.setProperty("felix.cm.loglevel", "not-a-number");
Log.logger.start(bundleContext);
assertEquals(2, getLogLevel());
Log.logger.stop();
bundleContext.setProperty("felix.cm.loglevel", "-100");
Log.logger.start(bundleContext);
assertEquals(-100, getLogLevel());
Log.logger.stop();
bundleContext.setProperty("felix.cm.loglevel", "4");
Log.logger.start(bundleContext);
assertEquals(4, getLogLevel());
Log.logger.stop();
}
use of org.apache.felix.cm.MockBundleContext in project felix by apache.
the class DynamicBindingsTest method test_store_and_load_bindings.
public void test_store_and_load_bindings() throws IOException {
// ensure there is no file
bindingsFile.delete();
// preset bindings
final DynamicBindings dm0 = new DynamicBindings(new MockBundleContext(), persistenceManager);
dm0.putLocation(PID1, LOCATION1);
// check bindings
final BundleContext ctx = new DMTestMockBundleContext();
final DynamicBindings dm = new DynamicBindings(ctx, persistenceManager);
// API check
assertEquals(LOCATION1, dm.getLocation(PID1));
// low level check
final Dictionary bindings = getBindings(dm);
assertNotNull(bindings);
assertEquals(1, bindings.size());
assertEquals(LOCATION1, bindings.get(PID1));
}
Aggregations