use of com.adaptris.core.Service in project interlok by adaptris.
the class DynamicServiceExecutorTest method testDoService_MimeServiceExtractor_NullSelector.
@Test
public void testDoService_MimeServiceExtractor_NullSelector() throws Exception {
AddMetadataService metadataService = new AddMetadataService();
metadataService.addMetadataElement(new MetadataElement(getName(), getName()));
DynamicServiceExecutor dynamicService = createService();
dynamicService.setServiceExtractor(new MimeServiceExtractor());
AdaptrisMessage msg = createMimeMessage(new ServiceList(new Service[] { metadataService }), ENCODING_BASE64);
try {
execute(dynamicService, msg);
fail();
} catch (ServiceException expected) {
}
}
use of com.adaptris.core.Service in project interlok by adaptris.
the class ExceptionHandlingServiceWrapperTest method retrieveObjectForSampleConfig.
@Override
protected Object retrieveObjectForSampleConfig() {
ExceptionHandlingServiceWrapper service = create();
service.setService(new ServiceList(new Service[] { new ThrowExceptionService(new ConfiguredException("Fail")), new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement("servicesComplete", "true") })) }));
return service;
}
use of com.adaptris.core.Service in project interlok by adaptris.
the class ExceptionHandlingServiceWrapperTest method testWithExceptionFromWrappedServices.
@Test
public void testWithExceptionFromWrappedServices() throws Exception {
ExceptionHandlingServiceWrapper service = create();
service.registerEventHandler(new DefaultEventHandler());
service.setService(new ServiceList(new Service[] { new ThrowExceptionService(new ConfiguredException("Fail")), new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement("servicesComplete", "true") })) }));
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
assertNotNull(service.wrappedServices());
// ExceptionService defaults to NullService
assertEquals(2, service.wrappedServices().length);
execute(service, msg);
assertEquals("true", msg.getMetadataValue("exceptionServiceTriggered"));
assertNull(msg.getMetadataValue("servicesComplete"));
}
use of com.adaptris.core.Service in project interlok by adaptris.
the class ExceptionReportServiceTest method testBug2356.
@Test
public void testBug2356() throws Exception {
ServiceImp failingService = new ThrowExceptionService(new ConfiguredException("Fail"));
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
ExceptionReportService service = new ExceptionReportService(new ExceptionAsXml().withExceptionGenerator(new SimpleExceptionReport()).withDocumentMerge(new InsertNode(XPATH_ROOT)));
MockMessageProducer mockProducer = new MockMessageProducer();
StandardProcessingExceptionHandler speh = new StandardProcessingExceptionHandler(new ServiceList(new Service[] { service, new StandaloneProducer(mockProducer) }));
MockChannel channel = new MockChannel();
MockMessageConsumer consumer = new MockMessageConsumer();
StandardWorkflow wf = new StandardWorkflow();
wf.getServiceCollection().add(failingService);
wf.setConsumer(consumer);
channel.setMessageErrorHandler(speh);
channel.getWorkflowList().add(wf);
try {
channel.prepare();
channel.requestStart();
consumer.submitMessage(msg);
assertEquals(1, mockProducer.getMessages().size());
AdaptrisMessage failedMessage = mockProducer.getMessages().get(0);
assertNotSame(XML_PAYLOAD, failedMessage.getContent());
XmlUtils xml = XmlHelper.createXmlUtils(failedMessage);
assertEquals(RAW_DATA, xml.getSingleTextItem(XPATH_ORIGINAL_NODE));
assertNotNull(xml.getSingleNode(XPATH_ROOT + "/Exception"));
String xmlElement = xml.getSingleTextItem(XPATH_ROOT + "/Exception");
assertTrue(xmlElement.contains("com.adaptris.core.services.exception.ThrowExceptionService.doService"));
} finally {
channel.requestClose();
}
}
use of com.adaptris.core.Service in project interlok by adaptris.
the class MetadataIdentitySequenceNumberServiceTest method testService_PooledConnection.
@Test
public void testService_PooledConnection() throws Exception {
int maxServices = 5;
final int iterations = 5;
int poolsize = maxServices - 1;
createDatabase();
List<Service> serviceList = new ArrayList<Service>();
String name = Thread.currentThread().getName();
Thread.currentThread().setName(getName());
JdbcPooledConnection conn = PooledConnectionHelper.createPooledConnection(PROPERTIES.getProperty(JDBC_SEQUENCENUMBER_DRIVER), PROPERTIES.getProperty(JDBC_SEQUENCENUMBER_URL), poolsize);
try {
for (int i = 0; i < maxServices; i++) {
MetadataIdentitySequenceNumberService service = configureForTests(createService(), false);
service.setConnection(conn);
serviceList.add(service);
start(service);
}
PooledConnectionHelper.executeTest(serviceList, iterations, new PooledConnectionHelper.MessageCreator() {
@Override
public AdaptrisMessage createMsgForPooledConnectionTest() throws Exception {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
msg.addMetadata(DEFAULT_IDENTITY_METADATA_KEY, new GuidGenerator().safeUUID());
return msg;
}
});
assertEquals(0, conn.currentBusyConnectionCount());
assertEquals(poolsize, conn.currentIdleConnectionCount());
assertEquals(poolsize, conn.currentConnectionCount());
} finally {
stop(serviceList.toArray(new ComponentLifecycle[0]));
Thread.currentThread().setName(name);
}
}
Aggregations