Search in sources :

Example 71 with PipeLineSession

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

the class ParameterTest method testPutInSessionPipeWithDomdocParamsUsedMoreThanOnce.

@Test
public // Test for #2256 PutParametersInSession with xpathExpression with type=domdoc results in "Content is not allowed in prolog"
void testPutInSessionPipeWithDomdocParamsUsedMoreThanOnce() throws Exception {
    try (TestConfiguration configuration = new TestConfiguration()) {
        PipeLine pipeline = configuration.createBean(PipeLine.class);
        String firstPipe = "PutInSession under test";
        String secondPipe = "PutInSession next pipe";
        String testMessage = "<Test>\n" + "	<Child><name>X</name></Child>\n" + "	<Child><name>Y</name></Child>\n" + "	<Child><name>Z</name></Child>\n" + "</Test>";
        String testMessageChild1 = "<Child><name>X</name></Child>";
        PutInSession pipe = configuration.createBean(PutInSession.class);
        pipe.setName(firstPipe);
        pipe.setPipeLine(pipeline);
        Parameter p = new Parameter();
        p.setName("xmlMessageChild");
        p.setXpathExpression("Test/Child[1]");
        p.setType(ParameterType.DOMDOC);
        pipe.addParameter(p);
        pipeline.addPipe(pipe);
        PutInSession pipe2 = configuration.createBean(PutInSession.class);
        pipe2.setName(secondPipe);
        pipe2.setPipeLine(pipeline);
        Parameter p2 = new Parameter();
        p2.setName("xmlMessageChild2");
        p2.setSessionKey("xmlMessageChild");
        p2.setXpathExpression("Child/name/text()");
        pipe2.addParameter(p2);
        pipeline.addPipe(pipe2);
        PipeLineExit exit = new PipeLineExit();
        exit.setPath("exit");
        exit.setState(ExitState.SUCCESS);
        pipeline.registerPipeLineExit(exit);
        pipeline.configure();
        CorePipeLineProcessor cpp = configuration.createBean(CorePipeLineProcessor.class);
        CorePipeProcessor pipeProcessor = configuration.createBean(CorePipeProcessor.class);
        cpp.setPipeProcessor(pipeProcessor);
        PipeLineSession session = configuration.createBean(PipeLineSession.class);
        pipeline.setOwner(pipe);
        PipeLineResult pipeRunResult = cpp.processPipeLine(pipeline, "messageId", new Message(testMessage), session, firstPipe);
        assertEquals(ExitState.SUCCESS, pipeRunResult.getState());
        assertEquals(testMessage, pipeRunResult.getResult().asString());
        MatchUtils.assertXmlEquals(testMessageChild1, session.getMessage("xmlMessageChild").asString());
        assertEquals("X", session.getMessage("xmlMessageChild2").asString());
    }
}
Also used : Message(nl.nn.adapterframework.stream.Message) CorePipeProcessor(nl.nn.adapterframework.processors.CorePipeProcessor) PipeLineResult(nl.nn.adapterframework.core.PipeLineResult) TestConfiguration(nl.nn.adapterframework.testutil.TestConfiguration) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) PipeLine(nl.nn.adapterframework.core.PipeLine) PutInSession(nl.nn.adapterframework.pipes.PutInSession) CorePipeLineProcessor(nl.nn.adapterframework.processors.CorePipeLineProcessor) PipeLineExit(nl.nn.adapterframework.core.PipeLineExit) Test(org.junit.Test)

Example 72 with PipeLineSession

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

the class ParameterTest method testPatternSessionVariable.

@Test
public void testPatternSessionVariable() throws ConfigurationException, ParameterException {
    Parameter p = new Parameter();
    p.setName("dummy");
    p.setPattern("{sessionKey}");
    p.configure();
    PipeLineSession session = new PipeLineSession();
    session.put("sessionKey", "fakeSessionVariable");
    ParameterValueList alreadyResolvedParameters = new ParameterValueList();
    assertEquals("fakeSessionVariable", p.getValue(alreadyResolvedParameters, null, session, false));
}
Also used : PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) Test(org.junit.Test)

Example 73 with PipeLineSession

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

the class ParameterTest method testParameterTypeHelper.

public <T> void testParameterTypeHelper(ParameterType type, Class<T> c) throws Exception {
    Parameter p = new Parameter();
    p.setName("integer");
    p.setValue("8");
    p.setType(type);
    p.configure();
    ParameterValueList alreadyResolvedParameters = new ParameterValueList();
    Message message = new Message("fakeMessage");
    Object result = p.getValue(alreadyResolvedParameters, message, null, false);
    assertTrue(c + " is expected type but was: " + result.getClass(), c.isAssignableFrom(result.getClass()));
    PipeLineSession session = new PipeLineSession();
    session.put("sessionkey", 8);
    p = new Parameter();
    p.setName("integer");
    p.setSessionKey("sessionkey");
    p.setType(type);
    p.configure();
    result = p.getValue(alreadyResolvedParameters, message, session, false);
    assertTrue(c + " is expected type but was: " + result.getClass(), c.isAssignableFrom(result.getClass()));
    session = new PipeLineSession();
    session.put("sessionkey", "8");
    result = p.getValue(alreadyResolvedParameters, message, session, false);
    assertTrue(c + " is expected type but was: " + result.getClass(), c.isAssignableFrom(result.getClass()));
    session = new PipeLineSession();
    session.put("sessionkey", Message.asMessage(8));
    result = p.getValue(alreadyResolvedParameters, message, session, false);
    assertTrue(c + " is expected type but was: " + result.getClass(), c.isAssignableFrom(result.getClass()));
    session = new PipeLineSession();
    session.put("sessionkey", "8".getBytes());
    result = p.getValue(alreadyResolvedParameters, message, session, false);
    assertTrue(c + " is expected type but was: " + result.getClass(), c.isAssignableFrom(result.getClass()));
    session = new PipeLineSession();
    session.put("sessionkey", Message.asMessage("8".getBytes()));
    result = p.getValue(alreadyResolvedParameters, message, session, false);
    assertTrue(c + " is expected type but was: " + result.getClass(), c.isAssignableFrom(result.getClass()));
}
Also used : Message(nl.nn.adapterframework.stream.Message) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession)

Example 74 with PipeLineSession

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

the class ParameterTest method testEmptyPatternUsedAsSourceForTransformation.

@Test
public void testEmptyPatternUsedAsSourceForTransformation() throws ConfigurationException, ParameterException {
    Parameter p = new Parameter();
    p.setName("dummy");
    p.setPattern("{username}");
    p.setXpathExpression("root/username");
    p.setDefaultValue("fakeDefault");
    p.configure();
    PipeLineSession session = new PipeLineSession();
    ParameterValueList alreadyResolvedParameters = new ParameterValueList();
    assertEquals("fakeDefault", p.getValue(alreadyResolvedParameters, null, session, false));
}
Also used : PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) Test(org.junit.Test)

Example 75 with PipeLineSession

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

the class ParameterTest method testPatternNowWithStringType.

@Test
public void testPatternNowWithStringType() throws Exception {
    Parameter p = new Parameter();
    System.getProperties().setProperty(ConfigurationUtils.STUB4TESTTOOL_CONFIGURATION_KEY, "true");
    try {
        p.setName("date");
        p.setPattern("{now}");
        p.configure();
        PipeLineSession session = new PipeLineSession();
        ParameterValueList alreadyResolvedParameters = new ParameterValueList();
        Message message = new Message("fakeMessage");
        // Should return PutSystemDateInSession.FIXEDDATETIME
        Object result = p.getValue(alreadyResolvedParameters, message, session, false);
        assertTrue(result instanceof String);
        SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.FORMAT_FULL_GENERIC);
        // dit gaat echt meestal wel goed
        String expectedDate = sdf.format(new Date());
        assertEquals(expectedDate.substring(0, 10), ((String) result).substring(0, 10));
    } finally {
        System.getProperties().setProperty(ConfigurationUtils.STUB4TESTTOOL_CONFIGURATION_KEY, "false");
    }
}
Also used : Message(nl.nn.adapterframework.stream.Message) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) 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