Search in sources :

Example 6 with CacheConnection

use of com.adaptris.core.services.cache.CacheConnection in project interlok by adaptris.

the class ServiceFromCacheTest method testNotFound.

@Test(expected = NullPointerException.class)
public void testNotFound() throws Exception {
    CacheConnection conn = createCache("actualCacheKey");
    ServiceFromCache extractor = new ServiceFromCache().withKey("%message{myKey}").withConnection(conn);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    msg.addMetadata("myKey", "nonExistentKey");
    try {
        LifecycleHelper.initAndStart(extractor);
        // NPE will be thrown by IOUtils.toInputStream() since it's not in the cache.
        InputStream in = extractor.getInputStream(msg);
    } finally {
        LifecycleHelper.stopAndClose(extractor);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) InputStream(java.io.InputStream) CacheConnection(com.adaptris.core.services.cache.CacheConnection) Test(org.junit.Test)

Example 7 with CacheConnection

use of com.adaptris.core.services.cache.CacheConnection in project interlok by adaptris.

the class ServiceFromCacheTest method testGetInputStream.

@Test
public void testGetInputStream() throws Exception {
    CacheConnection conn = createCache("actualCacheKey");
    ServiceFromCache extractor = new ServiceFromCache().withKey("%message{myKey}").withConnection(conn);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    msg.addMetadata("myKey", "actualCacheKey");
    try {
        LifecycleHelper.initAndStart(extractor);
        try (InputStream in = extractor.getInputStream(msg)) {
            assertNotNull(in);
            assertEquals(ServiceList.class, DefaultMarshaller.getDefaultMarshaller().unmarshal(in).getClass());
        }
    } finally {
        LifecycleHelper.stopAndClose(extractor);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) InputStream(java.io.InputStream) CacheConnection(com.adaptris.core.services.cache.CacheConnection) Test(org.junit.Test)

Example 8 with CacheConnection

use of com.adaptris.core.services.cache.CacheConnection in project interlok by adaptris.

the class CacheConditionTest method testExists.

@Test
public void testExists() throws Exception {
    CacheConnection conn = new CacheConnection().withCacheInstance(new ExpiringMapCache());
    ExistsInCache condition = new ExistsInCache().withConnection(conn).withKey("%message{key}");
    try {
        AdaptrisMessage message = DefaultMessageFactory.getDefaultInstance().newMessage();
        LifecycleHelper.initAndStart(condition);
        Cache cache = conn.retrieveCache();
        cache.put("key", "VALUE");
        message.addMessageHeader("key", "key");
        assertTrue(condition.evaluate(message));
    } finally {
        LifecycleHelper.stopAndClose(condition);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ExpiringMapCache(com.adaptris.core.cache.ExpiringMapCache) CacheConnection(com.adaptris.core.services.cache.CacheConnection) Cache(com.adaptris.core.cache.Cache) ExpiringMapCache(com.adaptris.core.cache.ExpiringMapCache) Test(org.junit.Test)

Example 9 with CacheConnection

use of com.adaptris.core.services.cache.CacheConnection in project interlok by adaptris.

the class CacheConditionTest method testDoesNotExist.

@Test
public void testDoesNotExist() throws Exception {
    CacheConnection conn = new CacheConnection().withCacheInstance(new ExpiringMapCache());
    ExistsInCache condition = new ExistsInCache().withConnection(conn).withKey("does-not-exist");
    try {
        AdaptrisMessage message = DefaultMessageFactory.getDefaultInstance().newMessage();
        LifecycleHelper.initAndStart(condition);
        Cache cache = conn.retrieveCache();
        cache.put("key", "VALUE");
        assertFalse(condition.evaluate(message));
    } finally {
        LifecycleHelper.stopAndClose(condition);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ExpiringMapCache(com.adaptris.core.cache.ExpiringMapCache) CacheConnection(com.adaptris.core.services.cache.CacheConnection) Cache(com.adaptris.core.cache.Cache) ExpiringMapCache(com.adaptris.core.cache.ExpiringMapCache) Test(org.junit.Test)

Example 10 with CacheConnection

use of com.adaptris.core.services.cache.CacheConnection in project interlok by adaptris.

the class XmlValidationServiceTest method testValidXmlSchema_Expression.

@Test
public void testValidXmlSchema_Expression() throws Exception {
    String schemaUrl = PROPERTIES.getProperty(KEY_WILL_VALIDATE_SCHEMA);
    // if (!ExternalResourcesHelper.isExternalServerAvailable(new URLString(schemaUrl))) {
    // log.debug(schemaUrl + " not available, ignoring testMetadataSchemaKeyIsEmpty test");
    // return;
    // }
    BasicXmlSchemaValidator validator = new BasicXmlSchemaValidator().withSchema("%message{schema-key}").withSchemaCache(new CacheConnection(new ExpiringMapCache().withMaxEntries(1)));
    AdaptrisMessage msg = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_INPUT_FILE));
    msg.addMetadata("schema-key", schemaUrl);
    XmlValidationService service = new XmlValidationService(validator);
    try {
        LifecycleHelper.initAndStart(service);
        service.doService(msg);
        // Hits the cache the 2nd time round
        service.doService(msg);
    } finally {
        LifecycleHelper.stopAndClose(service);
    }
}
Also used : BasicXmlSchemaValidator(com.adaptris.core.transform.schema.BasicXmlSchemaValidator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ExpiringMapCache(com.adaptris.core.cache.ExpiringMapCache) CacheConnection(com.adaptris.core.services.cache.CacheConnection) Test(org.junit.Test)

Aggregations

CacheConnection (com.adaptris.core.services.cache.CacheConnection)13 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)10 ExpiringMapCache (com.adaptris.core.cache.ExpiringMapCache)10 Test (org.junit.Test)10 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)3 TimeInterval (com.adaptris.util.TimeInterval)3 Cache (com.adaptris.core.cache.Cache)2 XmlValidationService (com.adaptris.core.transform.XmlValidationService)2 InputStream (java.io.InputStream)2 Service (com.adaptris.core.Service)1 ServiceList (com.adaptris.core.ServiceList)1 LogMessageService (com.adaptris.core.services.LogMessageService)1 DefectiveMessageFactory (com.adaptris.core.stubs.DefectiveMessageFactory)1 BasicXmlSchemaValidator (com.adaptris.core.transform.schema.BasicXmlSchemaValidator)1 ArrayList (java.util.ArrayList)1