Search in sources :

Example 6 with MetadataDataOutputParameter

use of com.adaptris.core.common.MetadataDataOutputParameter in project interlok by adaptris.

the class XPathServiceTest method testPayloadAttributeValueXPathIntoMetadata.

@Test
public void testPayloadAttributeValueXPathIntoMetadata() throws Exception {
    message.setContent(sampleXml, message.getContentEncoding());
    MetadataDataOutputParameter metadataDataDestination1 = new MetadataDataOutputParameter("targetMetadataKey");
    ConstantDataInputParameter constantDataDestination = new ConstantDataInputParameter("//some/random/xml/node1/@attr");
    Execution execution = new Execution(constantDataDestination, metadataDataDestination1);
    List<Execution> executions = new ArrayList<>();
    executions.add(execution);
    service.setXmlSource(new StringPayloadDataInputParameter());
    service.setExecutions(executions);
    execute(service, message);
    assertEquals("attribute value", message.getMetadataValue("targetMetadataKey"));
}
Also used : StringPayloadDataInputParameter(com.adaptris.core.common.StringPayloadDataInputParameter) Execution(com.adaptris.core.common.Execution) ConstantDataInputParameter(com.adaptris.core.common.ConstantDataInputParameter) ArrayList(java.util.ArrayList) MetadataDataOutputParameter(com.adaptris.core.common.MetadataDataOutputParameter) Test(org.junit.Test)

Example 7 with MetadataDataOutputParameter

use of com.adaptris.core.common.MetadataDataOutputParameter in project interlok by adaptris.

the class XPathServiceTest method testPayloadSimpleValueXPathIntoMultipleMetadataExecutions.

@Test
public void testPayloadSimpleValueXPathIntoMultipleMetadataExecutions() throws Exception {
    message.setContent(sampleXml, message.getContentEncoding());
    MetadataDataOutputParameter metadataDataDestination1 = new MetadataDataOutputParameter("targetMetadataKey1");
    ConstantDataInputParameter constantDataDestination1 = new ConstantDataInputParameter("//some/random/xml/node1/text()");
    MetadataDataOutputParameter metadataDataDestination2 = new MetadataDataOutputParameter("targetMetadataKey2");
    ConstantDataInputParameter constantDataDestination2 = new ConstantDataInputParameter("//some/random/xml/node2/text()");
    MetadataDataOutputParameter metadataDataDestination3 = new MetadataDataOutputParameter("targetMetadataKey3");
    ConstantDataInputParameter constantDataDestination3 = new ConstantDataInputParameter("//some/random/xml/node3/text()");
    Execution execution = new Execution(constantDataDestination1, metadataDataDestination1);
    Execution execution2 = new Execution(constantDataDestination2, metadataDataDestination2);
    Execution execution3 = new Execution(constantDataDestination3, metadataDataDestination3);
    List<Execution> executions = new ArrayList<>();
    executions.add(execution);
    executions.add(execution2);
    executions.add(execution3);
    service.setXmlSource(new StringPayloadDataInputParameter());
    service.setExecutions(executions);
    execute(service, message);
    assertEquals("value1", message.getMetadataValue("targetMetadataKey1"));
    assertEquals("value2", message.getMetadataValue("targetMetadataKey2"));
    assertEquals("value3", message.getMetadataValue("targetMetadataKey3"));
}
Also used : StringPayloadDataInputParameter(com.adaptris.core.common.StringPayloadDataInputParameter) Execution(com.adaptris.core.common.Execution) ConstantDataInputParameter(com.adaptris.core.common.ConstantDataInputParameter) ArrayList(java.util.ArrayList) MetadataDataOutputParameter(com.adaptris.core.common.MetadataDataOutputParameter) Test(org.junit.Test)

Example 8 with MetadataDataOutputParameter

use of com.adaptris.core.common.MetadataDataOutputParameter in project interlok by adaptris.

the class XPathServiceTest method testPayloadComplexValueXPathIntoMetadata.

@Test
public void testPayloadComplexValueXPathIntoMetadata() throws Exception {
    message.setContent(sampleXml, message.getContentEncoding());
    MetadataDataOutputParameter metadataDataDestination1 = new MetadataDataOutputParameter("targetMetadataKey");
    ConstantDataInputParameter constantDataDestination = new ConstantDataInputParameter("//some/random/xml/node1");
    Execution execution = new Execution(constantDataDestination, metadataDataDestination1);
    List<Execution> executions = new ArrayList<>();
    executions.add(execution);
    service.setXmlSource(new StringPayloadDataInputParameter());
    service.setExecutions(executions);
    execute(service, message);
    assertEquals("<node1 attr=\"attribute value\">value1</node1>", message.getMetadataValue("targetMetadataKey"));
}
Also used : StringPayloadDataInputParameter(com.adaptris.core.common.StringPayloadDataInputParameter) Execution(com.adaptris.core.common.Execution) ConstantDataInputParameter(com.adaptris.core.common.ConstantDataInputParameter) ArrayList(java.util.ArrayList) MetadataDataOutputParameter(com.adaptris.core.common.MetadataDataOutputParameter) Test(org.junit.Test)

Example 9 with MetadataDataOutputParameter

use of com.adaptris.core.common.MetadataDataOutputParameter in project interlok by adaptris.

the class XPathServiceTest method testForCoveragePurposesInvalidXml.

@Test
public void testForCoveragePurposesInvalidXml() throws Exception {
    message.setContent("not valid xml!", message.getContentEncoding());
    MetadataDataOutputParameter metadataDataDestination1 = new MetadataDataOutputParameter("targetMetadataKey");
    ConstantDataInputParameter constantDataDestination = new ConstantDataInputParameter("//some/random/xml/node1/text()");
    Execution execution = new Execution(constantDataDestination, metadataDataDestination1);
    List<Execution> executions = new ArrayList<>();
    executions.add(execution);
    service.setXmlSource(new StringPayloadDataInputParameter());
    service.setExecutions(executions);
    try {
        execute(service, message);
    } catch (ServiceException ex) {
    // expected
    }
}
Also used : StringPayloadDataInputParameter(com.adaptris.core.common.StringPayloadDataInputParameter) Execution(com.adaptris.core.common.Execution) ServiceException(com.adaptris.core.ServiceException) ConstantDataInputParameter(com.adaptris.core.common.ConstantDataInputParameter) ArrayList(java.util.ArrayList) MetadataDataOutputParameter(com.adaptris.core.common.MetadataDataOutputParameter) Test(org.junit.Test)

Example 10 with MetadataDataOutputParameter

use of com.adaptris.core.common.MetadataDataOutputParameter in project interlok by adaptris.

the class ExceptionAsStringReportTest method testDoService_Metadata.

@Test
public void testDoService_Metadata() throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    msg.addObjectHeader(CoreConstants.OBJ_METADATA_EXCEPTION, new Exception("This is the exception"));
    ExceptionReportService service = new ExceptionReportService(new ExceptionAsString().withTarget(new MetadataDataOutputParameter("exceptionKey")).withIncludeStackTrace(false));
    execute(service, msg);
    assertTrue(msg.getMetadataValue("exceptionKey").contains("This is the exception"));
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MetadataDataOutputParameter(com.adaptris.core.common.MetadataDataOutputParameter) CoreException(com.adaptris.core.CoreException) ServiceException(com.adaptris.core.ServiceException) InterlokException(com.adaptris.interlok.InterlokException) Test(org.junit.Test)

Aggregations

MetadataDataOutputParameter (com.adaptris.core.common.MetadataDataOutputParameter)10 Execution (com.adaptris.core.common.Execution)9 Test (org.junit.Test)8 ConstantDataInputParameter (com.adaptris.core.common.ConstantDataInputParameter)7 StringPayloadDataInputParameter (com.adaptris.core.common.StringPayloadDataInputParameter)6 ArrayList (java.util.ArrayList)6 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)3 ServiceException (com.adaptris.core.ServiceException)3 MetadataDataInputParameter (com.adaptris.core.common.MetadataDataInputParameter)2 CoreException (com.adaptris.core.CoreException)1 MetadataElement (com.adaptris.core.MetadataElement)1 InterlokException (com.adaptris.interlok.InterlokException)1 KeyValuePair (com.adaptris.util.KeyValuePair)1 KeyValuePairSet (com.adaptris.util.KeyValuePairSet)1