use of org.apache.felix.cm.MockPersistenceManager in project felix by apache.
the class CachingPersistenceManagerProxyTest method test_caching_is_applied.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void test_caching_is_applied() throws Exception {
String pid = "testDefaultPersistenceManager";
SimpleFilter filter = SimpleFilter.parse("(&(service.pid=" + pid + ")(property1=value1))");
PersistenceManager pm = new MockPersistenceManager();
CachingPersistenceManagerProxy cpm = new CachingPersistenceManagerProxy(pm);
Dictionary dictionary = new Hashtable();
dictionary.put("property1", "value1");
dictionary.put(Constants.SERVICE_PID, pid);
pm.store(pid, dictionary);
Enumeration dictionaries = cpm.getDictionaries(filter);
List list = Collections.list(dictionaries);
assertEquals(1, list.size());
dictionary = new Hashtable();
dictionary.put("property1", "value2");
pid = "testDefaultPersistenceManager";
dictionary.put(Constants.SERVICE_PID, pid);
pm.store(pid, dictionary);
dictionaries = cpm.getDictionaries(filter);
list = Collections.list(dictionaries);
assertEquals(1, list.size());
}
use of org.apache.felix.cm.MockPersistenceManager in project felix by apache.
the class ConfigurationManagerTest method test_listConfigurations_cached.
@Test
public void test_listConfigurations_cached() throws Exception {
String pid = "testDefaultPersistenceManager";
PersistenceManager pm = new MockPersistenceManager();
Dictionary<String, Object> dictionary = new Hashtable<>();
dictionary.put("property1", "value1");
dictionary.put(Constants.SERVICE_PID, pid);
pm.store(pid, dictionary);
ConfigurationManager configMgr = new ConfigurationManager(new CachingPersistenceManagerProxy(pm), null);
ConfigurationImpl[] conf = configMgr.listConfigurations(new ConfigurationAdminImpl(configMgr, null), null);
assertEquals(1, conf.length);
assertEquals(2, conf[0].getProperties(true).size());
dictionary = new Hashtable<>();
dictionary.put("property1", "value2");
pid = "testDefaultPersistenceManager";
dictionary.put(Constants.SERVICE_PID, pid);
pm.store(pid, dictionary);
conf = configMgr.listConfigurations(new ConfigurationAdminImpl(configMgr, null), null);
assertEquals(1, conf.length);
assertEquals(2, conf[0].getProperties(true).size());
// verify that the property in the configurations cache was used
assertEquals("value1", conf[0].getProperties(true).get("property1"));
}
use of org.apache.felix.cm.MockPersistenceManager in project felix by apache.
the class ConfigurationManagerTest method testEventsStartingBundle.
@Test
public void testEventsStartingBundle() throws Exception {
final Set<String> result = new HashSet<>();
SynchronousConfigurationListener syncListener1 = new SynchronousConfigurationListener() {
@Override
public void configurationEvent(ConfigurationEvent event) {
result.add("L1");
}
};
SynchronousConfigurationListener syncListener2 = new SynchronousConfigurationListener() {
@Override
public void configurationEvent(ConfigurationEvent event) {
result.add("L2");
}
};
SynchronousConfigurationListener syncListener3 = new SynchronousConfigurationListener() {
@Override
public void configurationEvent(ConfigurationEvent event) {
result.add("L3");
}
};
ServiceReference mockRef = Mockito.mock(ServiceReference.class);
ServiceRegistration mockReg = Mockito.mock(ServiceRegistration.class);
Mockito.when(mockReg.getReference()).thenReturn(mockRef);
ConfigurationManager configMgr = new ConfigurationManager(new PersistenceManagerProxy(new MockPersistenceManager()), null);
setServiceTrackerField(configMgr, "configurationListenerTracker");
ServiceReference[] refs = setServiceTrackerField(configMgr, "syncConfigurationListenerTracker", syncListener1, syncListener2, syncListener3);
for (int i = 0; i < refs.length; i++) {
Bundle mockBundle = Mockito.mock(Bundle.class);
switch(i) {
case 0:
Mockito.when(mockBundle.getState()).thenReturn(Bundle.ACTIVE);
break;
case 1:
Mockito.when(mockBundle.getState()).thenReturn(Bundle.STARTING);
break;
case 2:
Mockito.when(mockBundle.getState()).thenReturn(Bundle.STOPPING);
break;
}
Mockito.when(refs[i].getBundle()).thenReturn(mockBundle);
}
Field srField = configMgr.getClass().getDeclaredField("configurationAdminRegistration");
srField.setAccessible(true);
srField.set(configMgr, mockReg);
Field utField = configMgr.getClass().getDeclaredField("updateThread");
utField.setAccessible(true);
utField.set(configMgr, new UpdateThread(null, "Test updater"));
Dictionary<String, Object> props = new Hashtable<>();
props.put(Constants.SERVICE_PID, "org.acme.testpid");
ConfigurationImpl config = new ConfigurationImpl(configMgr, new MockPersistenceManager(), props);
configMgr.updated(config, true);
assertEquals("Both listeners should have been called, both in the STARTING and ACTIVE state, but not in the STOPPING state", 2, result.size());
}
use of org.apache.felix.cm.MockPersistenceManager in project felix by apache.
the class CachingPersistenceManagerProxyTest method createAndPopulatePersistenceManager.
private PersistenceManager createAndPopulatePersistenceManager() throws IOException {
final PersistenceManager pm = new MockPersistenceManager();
pm.store(PID_A, createConfiguration(PID_A, null));
pm.store(PID_B, createConfiguration(PID_B, null));
pm.store(PID_C, createConfiguration(PID_C, null));
pm.store(FA_PID_A, createConfiguration(FA_PID_A, FACTORY_PID_A));
pm.store(FA_PID_B, createConfiguration(FA_PID_B, FACTORY_PID_A));
pm.store(FA_PID_C, createConfiguration(FA_PID_C, FACTORY_PID_A));
pm.store(FB_PID_A, createConfiguration(FB_PID_A, FACTORY_PID_B));
pm.store(FB_PID_B, createConfiguration(FB_PID_B, FACTORY_PID_B));
return pm;
}
use of org.apache.felix.cm.MockPersistenceManager in project felix by apache.
the class CachingPersistenceManagerProxyTest method test_caching_is_applied.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void test_caching_is_applied() throws Exception {
String pid = "testDefaultPersistenceManager";
SimpleFilter filter = SimpleFilter.parse("(&(service.pid=" + pid + ")(property1=value1))");
PersistenceManager pm = new MockPersistenceManager();
CachingPersistenceManagerProxy cpm = new CachingPersistenceManagerProxy(pm);
Dictionary dictionary = new Hashtable();
dictionary.put("property1", "value1");
dictionary.put(Constants.SERVICE_PID, pid);
pm.store(pid, dictionary);
Collection<Dictionary> list = cpm.getDictionaries(filter);
assertEquals(1, list.size());
dictionary = new Hashtable();
dictionary.put("property1", "value2");
pid = "testDefaultPersistenceManager";
dictionary.put(Constants.SERVICE_PID, pid);
pm.store(pid, dictionary);
list = cpm.getDictionaries(filter);
assertEquals(1, list.size());
}
Aggregations