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