use of org.osgi.util.tracker.ServiceTracker 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.osgi.util.tracker.ServiceTracker in project felix by apache.
the class ConfigurationTestBase method setUp.
@Before
public void setUp() {
configAdminTracker = new ServiceTracker(bundleContext, ConfigurationAdmin.class.getName(), null);
configAdminTracker.open();
}
use of org.osgi.util.tracker.ServiceTracker in project felix by apache.
the class AgentContext method setTrackers.
// ////////////////////////////////////////////////////////////////////
// ////////////////PRIVATE////////////////////////////////////////////
private void setTrackers() {
try {
logTracker = new ServiceTracker(context, context.createFilter("(objectClass=" + LogService.class.getName() + ")"), null);
logReaderTracker = new ServiceTracker(context, context.createFilter("(objectClass=" + LogReaderService.class.getName() + ")"), null);
startLevelTracker = new ServiceTracker(context, context.createFilter("(objectClass=" + StartLevel.class.getName() + ")"), null);
packageAdminTracker = new ServiceTracker(context, context.createFilter("(objectClass=" + PackageAdmin.class.getName() + ")"), null);
permissionAdminTracker = new ServiceTracker(context, context.createFilter("(objectClass=" + PermissionAdmin.class.getName() + ")"), null);
userAdminTracker = new ServiceTracker(context, context.createFilter("(objectClass=" + UserAdmin.class.getName() + ")"), null);
configAdminTracker = new ServiceTracker(context, context.createFilter("(objectClass=" + ConfigurationAdmin.class.getName() + ")"), null);
} catch (InvalidSyntaxException e) {
warning("INVALID FILTER ");
}
logTracker.open();
logReaderTracker.open();
startLevelTracker.open();
packageAdminTracker.open();
permissionAdminTracker.open();
userAdminTracker.open();
configAdminTracker.open();
}
use of org.osgi.util.tracker.ServiceTracker 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.osgi.util.tracker.ServiceTracker 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;
}
Aggregations