use of org.apache.felix.cm.MockBundleContext in project felix by apache.
the class ConfigurationManagerTest method createConfigurationManager.
private static ConfigurationManager createConfigurationManager(final LogService logService) {
ConfigurationManager configMgr = new ConfigurationManager();
try {
Field field = configMgr.getClass().getDeclaredField("logTracker");
field.setAccessible(true);
field.set(configMgr, new ServiceTracker(new MockBundleContext(), "", null) {
@Override
public Object getService() {
return logService;
}
});
} catch (Throwable ignore) {
throw (IllegalArgumentException) new IllegalArgumentException("Cannot set logTracker field value").initCause(ignore);
}
return configMgr;
}
use of org.apache.felix.cm.MockBundleContext in project felix by apache.
the class ConfigurationManagerTest method setServiceTrackerField.
private static ServiceReference[] setServiceTrackerField(ConfigurationManager configMgr, String fieldName, Object... services) throws Exception {
final Map<ServiceReference, Object> refMap = new HashMap<>();
for (Object svc : services) {
ServiceReference sref = Mockito.mock(ServiceReference.class);
Mockito.when(sref.getProperty("objectClass")).thenReturn(new String[] { "TestService" });
refMap.put(sref, svc);
}
Field field = configMgr.getClass().getDeclaredField(fieldName);
field.setAccessible(true);
field.set(configMgr, new ServiceTracker(new MockBundleContext(), "", null) {
@Override
public ServiceReference[] getServiceReferences() {
return refMap.keySet().toArray(new ServiceReference[0]);
}
@Override
public Object getService(ServiceReference reference) {
return refMap.get(reference);
}
});
return refMap.keySet().toArray(new ServiceReference[0]);
}
use of org.apache.felix.cm.MockBundleContext in project felix by apache.
the class ConfigurationManagerTest method createConfigurationManagerAndLog.
private static ConfigurationManager createConfigurationManagerAndLog(final LogService logService) throws IOException {
final PersistenceManager pm = Mockito.mock(PersistenceManager.class);
ConfigurationManager configMgr = new ConfigurationManager(new CachingPersistenceManagerProxy(pm), null);
try {
Field field = Log.class.getDeclaredField("logTracker");
field.setAccessible(true);
field.set(Log.logger, new ServiceTracker(new MockBundleContext(), "", null) {
@Override
public Object getService() {
return logService;
}
});
} catch (Throwable ignore) {
throw (IllegalArgumentException) new IllegalArgumentException("Cannot set logTracker field value").initCause(ignore);
}
return configMgr;
}
use of org.apache.felix.cm.MockBundleContext in project felix by apache.
the class DynamicBindingsTest method test_no_bindings.
public void test_no_bindings() throws IOException {
// ensure there is no file
bindingsFile.delete();
final BundleContext ctx = new MockBundleContext();
final DynamicBindings dm = new DynamicBindings(ctx, persistenceManager);
final Dictionary bindings = getBindings(dm);
assertNotNull(bindings);
assertTrue(bindings.isEmpty());
}
use of org.apache.felix.cm.MockBundleContext in project felix by apache.
the class DynamicBindingsTest method test_store_and_load_bindings_with_cleanup.
public void test_store_and_load_bindings_with_cleanup() 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 DynamicBindings dm = new DynamicBindings(new MockBundleContext(), persistenceManager);
// API check
assertNull(dm.getLocation(PID1));
// low level check
final Dictionary bindings = getBindings(dm);
assertNotNull(bindings);
assertTrue(bindings.isEmpty());
}
Aggregations