Search in sources :

Example 1 with SimpleFilter

use of org.apache.felix.cm.impl.SimpleFilter 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());
}
Also used : Dictionary(java.util.Dictionary) MockPersistenceManager(org.apache.felix.cm.MockPersistenceManager) PersistenceManager(org.apache.felix.cm.PersistenceManager) Hashtable(java.util.Hashtable) SimpleFilter(org.apache.felix.cm.impl.SimpleFilter) MockPersistenceManager(org.apache.felix.cm.MockPersistenceManager) Test(org.junit.Test)

Example 2 with SimpleFilter

use of org.apache.felix.cm.impl.SimpleFilter in project felix by apache.

the class PersistenceManagerProxyTest method test_caching_is_avoided.

@SuppressWarnings({ "rawtypes", "unchecked" })
public void test_caching_is_avoided() throws Exception {
    String pid = "testDefaultPersistenceManager";
    SimpleFilter filter = SimpleFilter.parse("(&(service.pid=" + pid + ")(property1=value1))");
    PersistenceManager pm = new MockNotCachablePersistenceManager();
    PersistenceManagerProxy cpm = new PersistenceManagerProxy(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(0, list.size());
}
Also used : Dictionary(java.util.Dictionary) MockNotCachablePersistenceManager(org.apache.felix.cm.MockNotCachablePersistenceManager) PersistenceManager(org.apache.felix.cm.PersistenceManager) Hashtable(java.util.Hashtable) SimpleFilter(org.apache.felix.cm.impl.SimpleFilter) MockNotCachablePersistenceManager(org.apache.felix.cm.MockNotCachablePersistenceManager)

Aggregations

Dictionary (java.util.Dictionary)2 Hashtable (java.util.Hashtable)2 PersistenceManager (org.apache.felix.cm.PersistenceManager)2 SimpleFilter (org.apache.felix.cm.impl.SimpleFilter)2 MockNotCachablePersistenceManager (org.apache.felix.cm.MockNotCachablePersistenceManager)1 MockPersistenceManager (org.apache.felix.cm.MockPersistenceManager)1 Test (org.junit.Test)1