Search in sources :

Example 41 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class XpathMetadataServiceTest method testDoService_DisableDocType.

@Test
public void testDoService_DisableDocType() throws CoreException {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_WITH_DOCTYPE);
    XpathMetadataService service = new XpathMetadataService();
    // Shouldn't matter what the query actually is.
    service.setXpathQueries(new ArrayList<XpathQuery>(Arrays.asList(new ConfiguredXpathQuery("source", "//source-id"), new ConfiguredXpathQuery("destination", "//destination-id"))));
    DocumentBuilderFactoryBuilder builder = new DocumentBuilderFactoryBuilder();
    builder.getFeatures().add(new KeyValuePair("http://apache.org/xml/features/disallow-doctype-decl", "true"));
    service.setXmlDocumentFactoryConfig(builder);
    try {
        execute(service, msg);
        fail();
    } catch (ServiceException expected) {
        assertTrue(expected.getMessage().contains("DOCTYPE is disallowed"));
    }
}
Also used : XpathQuery(com.adaptris.core.services.metadata.xpath.XpathQuery) MultiItemConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.MultiItemConfiguredXpathQuery) MetadataXpathQuery(com.adaptris.core.services.metadata.xpath.MetadataXpathQuery) MultiItemMetadataXpathQuery(com.adaptris.core.services.metadata.xpath.MultiItemMetadataXpathQuery) ConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.ConfiguredXpathQuery) KeyValuePair(com.adaptris.util.KeyValuePair) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MultiItemConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.MultiItemConfiguredXpathQuery) ConfiguredXpathQuery(com.adaptris.core.services.metadata.xpath.ConfiguredXpathQuery) DocumentBuilderFactoryBuilder(com.adaptris.core.util.DocumentBuilderFactoryBuilder) Test(org.junit.Test)

Example 42 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class SimpleSequenceNumberTest method testDoService_FileIsDirectory.

@Test
public void testDoService_FileIsDirectory() throws Exception {
    SimpleSequenceNumberService service = new SimpleSequenceNumberService();
    service.setMetadataKey(DEFAULT_METADATA_KEY);
    File dir = new File(PROPERTIES.getProperty(KEY_BASEDIR), new GuidGenerator().getUUID());
    dir.mkdirs();
    service.setSequenceNumberFile(dir.getCanonicalPath());
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    try {
        execute(service, msg);
        fail();
    } catch (ServiceException expected) {
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) GuidGenerator(com.adaptris.util.GuidGenerator) File(java.io.File) Test(org.junit.Test)

Example 43 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class StringToHexServiceTest method testService_BadEncodingChoice.

@Test
public void testService_BadEncodingChoice() throws Exception {
    StringToHexService service = new StringToHexService();
    service.setCharset("RandomEncoding!");
    service.setMetadataKeyRegexp(HexToStringServiceTest.SOURCE_METADATA_KEY);
    AdaptrisMessage msg = createMessage();
    try {
        execute(service, msg);
        fail();
    } catch (ServiceException expected) {
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 44 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class MetadataBranchingServiceTest method testNoMetadataService.

@Test
public void testNoMetadataService() throws Exception {
    MetadataValueBranchingService service = createService();
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(DUMMY_PAYLOAD);
    try {
        execute(service, msg);
        fail("no Exc. for null Service ID");
    } catch (ServiceException e) {
    // expected behaviour
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 45 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class ReformatDateServiceTest method testServiceWithBadFormat.

@Test
public void testServiceWithBadFormat() throws Exception {
    ReformatDateService service = new ReformatDateService();
    service.setDestinationFormatBuilder(new DateFormatBuilder(DEST_DATE_FORMAT));
    service.setSourceFormatBuilder(new DateFormatBuilder(BAD_SOURCE_DATE_FORMAT));
    service.setMetadataKeyRegexp(DATE_METADATA_KEY);
    AdaptrisMessage msg = createMessage();
    try {
        execute(service, msg);
        fail();
    } catch (ServiceException expected) {
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Aggregations

ServiceException (com.adaptris.core.ServiceException)236 Test (org.junit.Test)172 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)161 CoreException (com.adaptris.core.CoreException)45 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)26 StandaloneProducer (com.adaptris.core.StandaloneProducer)18 MetadataElement (com.adaptris.core.MetadataElement)17 ValidationStage (com.adaptris.transform.validate.ValidationStage)16 Cache (com.adaptris.core.cache.Cache)15 DefectiveMessageFactory (com.adaptris.core.stubs.DefectiveMessageFactory)13 TimeInterval (com.adaptris.util.TimeInterval)13 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)11 Connection (java.sql.Connection)10 File (java.io.File)9 IOException (java.io.IOException)9 OutputStream (java.io.OutputStream)9 SQLException (java.sql.SQLException)9 InputStream (java.io.InputStream)8 Document (org.w3c.dom.Document)8 Channel (com.adaptris.core.Channel)7