Search in sources :

Example 96 with PipeLineSession

use of nl.nn.adapterframework.core.PipeLineSession in project iaf by ibissource.

the class XmlValidatorTest method testWrongRootElement.

@Test
public void testWrongRootElement() throws Exception {
    String schema = SCHEMA_LOCATION_BASIC_A_OK;
    String inputFile = INPUT_FILE_BASIC_A_OK;
    XmlValidator validator = new XmlValidator();
    validator.registerForward(createSuccessForward());
    validator.registerForward(createFailureForward());
    validator.setFullSchemaChecking(true);
    validator.setRoot("anotherElement");
    validator.setReasonSessionKey("reason");
    validator.setSchemaLocation(schema);
    validator.configure();
    validator.start();
    String testXml = inputFile != null ? getTestXml(inputFile + ".xml") : null;
    PipeLineSession session = new PipeLineSession();
    PipeRunResult result = validator.doPipe(new Message(testXml), session);
    PipeForward forward = result.getPipeForward();
    assertEquals("failure", forward.getName());
    assertThat((String) session.get("reason"), containsString("Illegal element 'A'. Element(s) 'anotherElement' expected."));
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) AbstractXmlValidator(nl.nn.adapterframework.validation.AbstractXmlValidator) XercesXmlValidator(nl.nn.adapterframework.validation.XercesXmlValidator) JavaxXmlValidator(nl.nn.adapterframework.validation.JavaxXmlValidator) Message(nl.nn.adapterframework.stream.Message) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) PipeForward(nl.nn.adapterframework.core.PipeForward) Test(org.junit.Test)

Example 97 with PipeLineSession

use of nl.nn.adapterframework.core.PipeLineSession in project iaf by ibissource.

the class XmlValidatorTest method testRuntimeRootElement.

@Test
public void testRuntimeRootElement() throws Exception {
    String schema = SCHEMA_LOCATION_BASIC_A_OK;
    String root = "A";
    String inputFile = INPUT_FILE_BASIC_A_OK;
    XmlValidator validator = new XmlValidator();
    validator.registerForward(createSuccessForward());
    validator.registerForward(createFailureForward());
    validator.setFullSchemaChecking(true);
    // if multiple root elements are specified, in a comma separated list, the validation succeeds if one of these root elements is found
    validator.setRoot("oneElement,anotherElement");
    validator.setSchemaLocation(schema);
    validator.configure();
    validator.start();
    String testXml = inputFile != null ? getTestXml(inputFile + ".xml") : null;
    PipeLineSession session = new PipeLineSession();
    PipeRunResult result = validator.validate(new Message(testXml), session, root);
    PipeForward forward = result.getPipeForward();
    assertEquals("success", forward.getName());
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) AbstractXmlValidator(nl.nn.adapterframework.validation.AbstractXmlValidator) XercesXmlValidator(nl.nn.adapterframework.validation.XercesXmlValidator) JavaxXmlValidator(nl.nn.adapterframework.validation.JavaxXmlValidator) Message(nl.nn.adapterframework.stream.Message) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) PipeForward(nl.nn.adapterframework.core.PipeForward) Test(org.junit.Test)

Example 98 with PipeLineSession

use of nl.nn.adapterframework.core.PipeLineSession in project iaf by ibissource.

the class InputOutputSenderWrapperProcessorTest method getSenderWrapper.

public SenderWrapperBase getSenderWrapper() {
    SenderSeries senderSeries = new SenderSeries();
    senderSeries.registerSender(new SenderBase() {

        @Override
        public Message sendMessage(Message message, PipeLineSession session) throws SenderException, TimeoutException {
            try {
                return new Message("Sender 1: [" + message.asString() + "]");
            } catch (IOException e) {
                throw new SenderException(e);
            }
        }
    });
    senderSeries.registerSender(new SenderBase() {

        @Override
        public Message sendMessage(Message message, PipeLineSession session) throws SenderException, TimeoutException {
            try {
                secondSenderOutput = "Sender 2: [" + message.asString() + "]";
                return new Message(secondSenderOutput);
            } catch (IOException e) {
                throw new SenderException(e);
            }
        }
    });
    return senderSeries;
}
Also used : Message(nl.nn.adapterframework.stream.Message) SenderBase(nl.nn.adapterframework.senders.SenderBase) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) IOException(java.io.IOException) SenderException(nl.nn.adapterframework.core.SenderException) SenderSeries(nl.nn.adapterframework.senders.SenderSeries) TimeoutException(nl.nn.adapterframework.core.TimeoutException)

Example 99 with PipeLineSession

use of nl.nn.adapterframework.core.PipeLineSession in project iaf by ibissource.

the class SoapWrapperTest method getBodyXmlAndStoreSoapNamespace.

@Test
public void getBodyXmlAndStoreSoapNamespace() throws ConfigurationException {
    SoapWrapper soapWrapper = SoapWrapper.getInstance();
    String soapMessage = xmlMessage;
    String expectedSoapBody = xmlMessage;
    String soapBody = null;
    PipeLineSession session = new PipeLineSession();
    String sessionKey = "SoapVersion";
    try {
        soapBody = soapWrapper.getBody(new Message(soapMessage), true, session, sessionKey).asString();
    } catch (Exception e) {
        soapBody = e.getMessage();
    }
    assertEquals(expectedSoapBody, soapBody);
    String soapVersion = (String) session.get(sessionKey);
    assertEquals(SoapVersion.NONE.namespace, soapVersion);
}
Also used : Message(nl.nn.adapterframework.stream.Message) SOAPMessage(javax.xml.soap.SOAPMessage) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) KeySelectorException(javax.xml.crypto.KeySelectorException) SAXException(org.xml.sax.SAXException) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Test(org.junit.Test)

Example 100 with PipeLineSession

use of nl.nn.adapterframework.core.PipeLineSession in project iaf by ibissource.

the class SoapWrapperTest method getBody11AndStoreSoapNamespace.

@Test
public void getBody11AndStoreSoapNamespace() throws ConfigurationException {
    SoapWrapper soapWrapper = SoapWrapper.getInstance();
    String soapMessage = soapMessageSoap11;
    String expectedSoapBody = expectedSoapBody11;
    String soapBody = null;
    PipeLineSession session = new PipeLineSession();
    String sessionKey = "SoapVersion";
    try {
        soapBody = soapWrapper.getBody(new Message(soapMessage), true, session, sessionKey).asString();
    } catch (Exception e) {
        soapBody = e.getMessage();
    }
    assertEquals(expectedSoapBody, soapBody);
    String soapVersion = (String) session.get(sessionKey);
    assertEquals(SoapVersion.SOAP11.namespace, soapVersion);
}
Also used : Message(nl.nn.adapterframework.stream.Message) SOAPMessage(javax.xml.soap.SOAPMessage) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) KeySelectorException(javax.xml.crypto.KeySelectorException) SAXException(org.xml.sax.SAXException) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Test(org.junit.Test)

Aggregations

PipeLineSession (nl.nn.adapterframework.core.PipeLineSession)270 Message (nl.nn.adapterframework.stream.Message)210 Test (org.junit.Test)202 SenderException (nl.nn.adapterframework.core.SenderException)43 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)33 UrlMessage (nl.nn.adapterframework.stream.UrlMessage)30 ByteArrayInputStream (java.io.ByteArrayInputStream)26 IOException (java.io.IOException)25 Parameter (nl.nn.adapterframework.parameters.Parameter)23 PipeForward (nl.nn.adapterframework.core.PipeForward)21 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)17 Date (java.util.Date)15 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)14 InputStream (java.io.InputStream)11 TimeoutException (nl.nn.adapterframework.core.TimeoutException)11 ParameterList (nl.nn.adapterframework.parameters.ParameterList)11 Map (java.util.Map)10 SimpleDateFormat (java.text.SimpleDateFormat)9 SOAPMessage (javax.xml.soap.SOAPMessage)9 URL (java.net.URL)8