Search in sources :

Example 21 with MetadataElement

use of com.adaptris.core.MetadataElement in project interlok by adaptris.

the class CheckCacheServiceTest method testDoService_InCache.

@Test
public void testDoService_InCache() throws Exception {
    AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(LOOKUP_VALUE, LOOKUP_VALUE) }));
    ExpiringMapCache cache = createCacheInstanceForTests();
    CheckCacheService service = createServiceForTests();
    try {
        service.setConnection(new CacheConnection(cache));
        service.setKeysFoundServiceId(FOUND);
        service.setKeysNotFoundServiceId(NOT_FOUND);
        start(service);
        cache.put(LOOKUP_VALUE, LOOKED_UP_VALUE);
        service.doService(msg);
        assertEquals(FOUND, msg.getNextServiceId());
    } finally {
        stop(service);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ExpiringMapCache(com.adaptris.core.cache.ExpiringMapCache) MetadataElement(com.adaptris.core.MetadataElement) Test(org.junit.Test)

Example 22 with MetadataElement

use of com.adaptris.core.MetadataElement in project interlok by adaptris.

the class CheckCacheServiceTest method testDoService_NotInCache.

@Test
public void testDoService_NotInCache() throws Exception {
    AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(LOOKUP_VALUE, LOOKUP_VALUE) }));
    ExpiringMapCache cache = createCacheInstanceForTests();
    CheckCacheService service = createServiceForTests();
    try {
        service.setConnection(new CacheConnection(cache));
        service.setKeysFoundServiceId(FOUND);
        service.setKeysNotFoundServiceId(NOT_FOUND);
        start(service);
        service.doService(msg);
        assertEquals(NOT_FOUND, msg.getNextServiceId());
    } finally {
        stop(service);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ExpiringMapCache(com.adaptris.core.cache.ExpiringMapCache) MetadataElement(com.adaptris.core.MetadataElement) Test(org.junit.Test)

Example 23 with MetadataElement

use of com.adaptris.core.MetadataElement in project interlok by adaptris.

the class RemoveFromCacheServiceTest method testDoService.

@Override
@Test
public void testDoService() throws Exception {
    AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(SRC_METADATA_KEY, LOOKUP_VALUE) }));
    Cache cache = createCacheInstanceForTests();
    CacheServiceBase service = createServiceForTests();
    try {
        service.setConnection(new CacheConnection(cache));
        start(service);
        // Now add the TARGET DATA to the cache.
        cache.put(LOOKUP_VALUE, LOOKED_UP_VALUE);
        service.doService(msg);
        assertTrue(msg.headersContainsKey(TARGET_METADATA_KEY));
        assertEquals(LOOKED_UP_VALUE, msg.getMetadataValue(TARGET_METADATA_KEY));
        // The service should have removed it.
        assertFalse(cache.getKeys().contains(LOOKUP_VALUE));
    } finally {
        stop(service);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) Cache(com.adaptris.core.cache.Cache) Test(org.junit.Test)

Example 24 with MetadataElement

use of com.adaptris.core.MetadataElement in project interlok by adaptris.

the class RetrieveFromCacheServiceTest method testDoService_KeyNotFound.

@Test
public void testDoService_KeyNotFound() throws Exception {
    AdaptrisMessage msg = createMessage("Hello World", new ArrayList<MetadataElement>());
    Cache cache = createCacheInstanceForTests();
    RetrieveFromCacheService service = createService();
    CacheEntryEvaluator eval = new CacheEntryEvaluator();
    eval.setErrorOnEmptyKey(false);
    service.addCacheEntryEvaluator(eval);
    try {
        service.setConnection(new CacheConnection(cache));
        start(service);
        service.doService(msg);
    } finally {
        stop(service);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) Cache(com.adaptris.core.cache.Cache) Test(org.junit.Test)

Example 25 with MetadataElement

use of com.adaptris.core.MetadataElement in project interlok by adaptris.

the class RetrieveFromCacheServiceTest method testDoService_NullValueTranslator.

@Test
public void testDoService_NullValueTranslator() throws Exception {
    AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(SRC_METADATA_KEY, LOOKUP_VALUE) }));
    Cache cache = createCacheInstanceForTests();
    RetrieveFromCacheService service = createServiceForTests();
    CacheEntryEvaluator eval = service.getCacheEntryEvaluators().get(0);
    // we know that StaticCacheValueTranslator should throw an exception if
    // we try to apply a value into the message.
    eval.setValueTranslator(new StaticCacheValueTranslator("dummy value"));
    try {
        service.setConnection(new CacheConnection(cache));
        start(service);
        // Now add the TARGET DATA to the cache.
        cache.put(LOOKUP_VALUE, LOOKED_UP_VALUE);
        service.doService(msg);
        fail("Expected a ServiceException");
    } catch (ServiceException expected) {
    } finally {
        stop(service);
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) StaticCacheValueTranslator(com.adaptris.core.services.cache.translators.StaticCacheValueTranslator) Cache(com.adaptris.core.cache.Cache) Test(org.junit.Test)

Aggregations

MetadataElement (com.adaptris.core.MetadataElement)151 Test (org.junit.Test)101 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)94 XPath (com.adaptris.util.text.xml.XPath)23 Document (org.w3c.dom.Document)19 MetadataCollection (com.adaptris.core.MetadataCollection)18 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)18 ServiceException (com.adaptris.core.ServiceException)17 ServiceList (com.adaptris.core.ServiceList)14 Cache (com.adaptris.core.cache.Cache)14 MetadataCacheValueTranslator (com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator)12 ArrayList (java.util.ArrayList)11 CoreException (com.adaptris.core.CoreException)10 Service (com.adaptris.core.Service)10 HashSet (java.util.HashSet)9 ExpiringMapCache (com.adaptris.core.cache.ExpiringMapCache)8 StandaloneProducer (com.adaptris.core.StandaloneProducer)7 StaticCacheValueTranslator (com.adaptris.core.services.cache.translators.StaticCacheValueTranslator)7 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)6 Session (javax.jms.Session)6