Search in sources :

Example 16 with MetadataElement

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

the class AddToCacheServiceTest method testDoService_EnforceSerializable_NotSerializable.

@Test
public void testDoService_EnforceSerializable_NotSerializable() throws Exception {
    AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(JmsConstants.JMS_CORRELATION_ID, CORRELATION_ID) }));
    Cache cache = createCacheInstanceForTests();
    AddToCacheService service = createServiceForTests();
    try {
        service.setConnection(new CacheConnection(cache));
        service.setEnforceSerializable(true);
        start(service);
        service.doService(msg);
        fail();
    } catch (ServiceException expected) {
    } finally {
        stop(service);
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) Cache(com.adaptris.core.cache.Cache) Test(org.junit.Test)

Example 17 with MetadataElement

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

the class AddToCacheServiceTest method testDoService_NoErrorOnEmpty_NoKeyValue.

@Test
public void testDoService_NoErrorOnEmpty_NoKeyValue() throws Exception {
    AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(JmsConstants.JMS_CORRELATION_ID, CORRELATION_ID) }));
    Cache cache = createCacheInstanceForTests();
    AddToCacheService service = createServiceForTests();
    CacheEntryEvaluator eval = service.getCacheEntryEvaluators().get(0);
    eval.setErrorOnEmptyKey(false);
    eval.setKeyTranslator(new MetadataCacheValueTranslator(SRC_KEY));
    try {
        service.setConnection(new CacheConnection(cache));
        start(service);
        service.doService(msg);
        assertNull(cache.get(SRC_VALUE));
    } finally {
        stop(service);
    }
}
Also used : MetadataCacheValueTranslator(com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) Cache(com.adaptris.core.cache.Cache) Test(org.junit.Test)

Example 18 with MetadataElement

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

the class AddToCacheServiceTest method testDoService_ErrorOnEmpty.

@Test
public void testDoService_ErrorOnEmpty() throws Exception {
    AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(JmsConstants.JMS_CORRELATION_ID, CORRELATION_ID) }));
    Cache cache = createCacheInstanceForTests();
    AddToCacheService service = createServiceForTests();
    CacheEntryEvaluator eval = service.getCacheEntryEvaluators().get(0);
    eval.setValueTranslator(new MetadataCacheValueTranslator(SRC_KEY));
    eval.setKeyTranslator(new MetadataCacheValueTranslator(SRC_KEY));
    try {
        service.setConnection(new CacheConnection(cache));
        start(service);
        service.doService(msg);
        fail();
    } catch (ServiceException expected) {
    } finally {
        stop(service);
    }
}
Also used : MetadataCacheValueTranslator(com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) Cache(com.adaptris.core.cache.Cache) Test(org.junit.Test)

Example 19 with MetadataElement

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

the class AddToCacheServiceTest method testDoService_NoErrorOnEmpty_NoValue.

@Test
public void testDoService_NoErrorOnEmpty_NoValue() throws Exception {
    AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(JmsConstants.JMS_CORRELATION_ID, CORRELATION_ID) }));
    Cache cache = createCacheInstanceForTests();
    AddToCacheService service = createServiceForTests();
    CacheEntryEvaluator eval = service.getCacheEntryEvaluators().get(0);
    eval.setErrorOnEmptyValue(false);
    eval.setValueTranslator(new MetadataCacheValueTranslator(SRC_KEY));
    try {
        service.setConnection(new CacheConnection(cache));
        start(service);
        service.doService(msg);
        assertNull(cache.get(SRC_VALUE));
    } finally {
        stop(service);
    }
}
Also used : MetadataCacheValueTranslator(com.adaptris.core.services.cache.translators.MetadataCacheValueTranslator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataElement(com.adaptris.core.MetadataElement) Cache(com.adaptris.core.cache.Cache) Test(org.junit.Test)

Example 20 with MetadataElement

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

the class CheckCacheServiceTest method testDoService_Error.

@Test
public void testDoService_Error() throws Exception {
    AdaptrisMessage msg = createMessage("Hello World", Arrays.asList(new MetadataElement[] { new MetadataElement(LOOKUP_VALUE, LOOKUP_VALUE) }));
    ExpiringMapCache cache = new KeysSizeUnsupportedCache().withMaxEntries(10).withExpiration(new TimeInterval(10L, TimeUnit.SECONDS));
    CheckCacheService service = new CheckCacheService() {

        @Override
        protected boolean eval(AdaptrisMessage msg, FoundInCache callback) throws CoreException {
            throw new CoreException();
        }
    };
    try {
        service.withConnection(new CacheConnection().withCacheInstance(cache));
        service.setKeysFoundServiceId(FOUND);
        service.setKeysNotFoundServiceId(NOT_FOUND);
        start(service);
        cache.put(LOOKUP_VALUE, LOOKED_UP_VALUE);
        service.doService(msg);
        fail();
    } catch (ServiceException expected) {
    } finally {
        stop(service);
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) CoreException(com.adaptris.core.CoreException) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ExpiringMapCache(com.adaptris.core.cache.ExpiringMapCache) MetadataElement(com.adaptris.core.MetadataElement) 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