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);
}
}
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);
}
}
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);
}
}
Aggregations