Search in sources :

Example 11 with CacheConnection

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

the class BasicSchemaValidationTest method testBasicSchemaValidator.

@Test
public void testBasicSchemaValidator() throws Exception {
    String schemaUrl = PROPERTIES.getProperty(KEY_WILL_VALIDATE_SCHEMA);
    BasicXmlSchemaValidator validator = new BasicXmlSchemaValidator().withSchema(schemaUrl).withSchemaCache(new CacheConnection().withCacheInstance(new ExpiringMapCache()));
    XmlValidationService service = new XmlValidationService(validator);
    try {
        LifecycleHelper.initAndStart(service);
        AdaptrisMessage m1 = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_INPUT_FILE));
        AdaptrisMessage m2 = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_INPUT_FILE));
        service.doService(m1);
        service.doService(m2);
    } finally {
        LifecycleHelper.stopAndClose(service);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ExpiringMapCache(com.adaptris.core.cache.ExpiringMapCache) XmlValidationService(com.adaptris.core.transform.XmlValidationService) CacheConnection(com.adaptris.core.services.cache.CacheConnection) Test(org.junit.Test)

Example 12 with CacheConnection

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

the class GetAndCacheOauthTokenTest method testService_Expiry.

@Test
public void testService_Expiry() throws Exception {
    ExpiringMapCache cache = new ExpiringMapCache().withExpiration(new TimeInterval(5L, TimeUnit.SECONDS));
    AccessToken t = new AccessToken(getName());
    GetAndCacheOauthToken service = new GetAndCacheOauthToken().withCacheKey("OauthToken").withConnection(new CacheConnection(cache)).withAccessTokenBuilder(new ExpiringAccessToken(t, 1000));
    try {
        AdaptrisMessage m1 = new DefaultMessageFactory().newMessage(TEXT);
        LifecycleHelper.initAndStart(service);
        service.doService(m1);
        AccessToken t1 = (AccessToken) cache.get("OauthToken");
        assertNotNull(t1);
        await().atMost(Duration.ofSeconds(3)).with().pollInterval(Duration.ofMillis(100)).until(() -> cache.size() == 0);
        AdaptrisMessage m2 = new DefaultMessageFactory().newMessage(TEXT);
        service.doService(m2);
        AccessToken t2 = (AccessToken) cache.get("OauthToken");
        assertNotNull(t2);
        assertNotSame(t1, t2);
    } finally {
        LifecycleHelper.stopAndClose(service);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ExpiringMapCache(com.adaptris.core.cache.ExpiringMapCache) CacheConnection(com.adaptris.core.services.cache.CacheConnection) Test(org.junit.Test)

Example 13 with CacheConnection

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

the class GetAndCacheOauthTokenTest method testService.

@Test
public void testService() throws Exception {
    ExpiringMapCache cache = new ExpiringMapCache().withExpiration(new TimeInterval(5L, TimeUnit.SECONDS));
    AccessToken t = new AccessToken(getName());
    GetAndCacheOauthToken service = new GetAndCacheOauthToken().withCacheKey("OauthToken").withConnection(new CacheConnection(cache)).withAccessTokenBuilder(new DummyAccessTokenBuilder(t));
    try {
        AdaptrisMessage m1 = new DefaultMessageFactory().newMessage(TEXT);
        LifecycleHelper.initAndStart(service);
        service.doService(m1);
        assertTrue(m1.headersContainsKey("Authorization"));
        assertEquals("Bearer " + getName(), m1.getMetadataValue("Authorization"));
        AccessToken t1 = (AccessToken) cache.get("OauthToken");
        assertNotNull(t1);
        AdaptrisMessage m2 = new DefaultMessageFactory().newMessage(TEXT);
        service.doService(m2);
        assertTrue(m2.headersContainsKey("Authorization"));
        assertEquals("Bearer " + getName(), m1.getMetadataValue("Authorization"));
        AccessToken t2 = (AccessToken) cache.get("OauthToken");
        assertNotNull(t2);
        assertSame(t1, t2);
    } finally {
        LifecycleHelper.stopAndClose(service);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) TimeInterval(com.adaptris.util.TimeInterval) 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