Search in sources :

Example 61 with PipeLineSession

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

the class ParameterTest method testParameterValueList.

@Test
public void testParameterValueList() throws Exception {
    String sessionKey = "mySessionKey";
    Parameter p = new Parameter();
    p.setName("myParameter");
    p.setSessionKey(sessionKey);
    p.setType(ParameterType.LIST);
    p.setXpathExpression("items/item");
    p.configure();
    PipeLineSession session = new PipeLineSession();
    session.put(sessionKey, Arrays.asList(new String[] { "fiets", "bel", "appel" }));
    ParameterValueList alreadyResolvedParameters = new ParameterValueList();
    Message message = new Message("fakeMessage");
    Object result = p.getValue(alreadyResolvedParameters, message, session, false);
    assertTrue(result instanceof String);
    String stringResult = Message.asMessage(result).asString();
    assertEquals("fiets bel appel", stringResult);
}
Also used : Message(nl.nn.adapterframework.stream.Message) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) Test(org.junit.Test)

Example 62 with PipeLineSession

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

the class ParameterTest method testPatternCombined.

@Test
public void testPatternCombined() throws ConfigurationException, ParameterException {
    Parameter p = new Parameter();
    p.setName("dummy");
    p.setPattern("param [{siblingParameter}] sessionKey [{sessionKey}] username [{username}] password [{password}]");
    p.setUsername("fakeUsername");
    p.setPassword("fakePassword");
    p.configure();
    PipeLineSession session = new PipeLineSession();
    session.put("sessionKey", "fakeSessionVariable");
    ParameterValueList alreadyResolvedParameters = new ParameterValueList();
    Parameter siblingParameter = new Parameter();
    siblingParameter.setName("siblingParameter");
    siblingParameter.setValue("fakeParameterValue");
    siblingParameter.configure();
    alreadyResolvedParameters.add(new ParameterValue(siblingParameter, siblingParameter.getValue(alreadyResolvedParameters, null, session, false)));
    assertEquals("param [fakeParameterValue] sessionKey [fakeSessionVariable] username [fakeUsername] password [fakePassword]", p.getValue(alreadyResolvedParameters, null, session, false));
}
Also used : PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) Test(org.junit.Test)

Example 63 with PipeLineSession

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

the class ParameterTest method testContextKeyWithSessionKeyAndXPath.

@Test
public void testContextKeyWithSessionKeyAndXPath() throws ConfigurationException, ParameterException {
    Parameter p = new Parameter();
    p.setName("dummy");
    p.setSessionKey("fakeSessionKey");
    p.setContextKey("fakeContextKey");
    p.setXpathExpression("count(root/a)");
    p.configure();
    Message input = new Message("fakeMessage1", new MessageContext().with("fakeContextKey", "<root><a/><a/></root>"));
    Message sessionValue = new Message("fakeMessage2", new MessageContext().with("fakeContextKey", "<root><a/><a/><a/></root>"));
    PipeLineSession session = new PipeLineSession();
    session.put("fakeSessionKey", sessionValue);
    ParameterValueList alreadyResolvedParameters = new ParameterValueList();
    assertEquals("3", p.getValue(alreadyResolvedParameters, input, session, false));
}
Also used : Message(nl.nn.adapterframework.stream.Message) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) MessageContext(nl.nn.adapterframework.stream.MessageContext) Test(org.junit.Test)

Example 64 with PipeLineSession

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

the class ParameterTest method testParameterFromURLToNodeWithXpath.

@Test
public void testParameterFromURLToNodeWithXpath() throws Exception {
    URL originalMessage = TestFileUtils.getTestFileURL("/Xslt/MultiNamespace/in.xml");
    String expectedResultContents = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><block><XDOC><REF_ID>0</REF_ID><XX>0</XX></XDOC><XDOC><REF_ID>1</REF_ID></XDOC><XDOC><REF_ID>2</REF_ID></XDOC></block>";
    PipeLineSession session = new PipeLineSession();
    session.put("originalMessage", Message.asMessage(originalMessage));
    Parameter parameter = new Parameter();
    parameter.setName("InputMessage");
    parameter.setSessionKey("originalMessage");
    parameter.setType(ParameterType.NODE);
    parameter.setRemoveNamespaces(true);
    parameter.setXpathExpression("*");
    parameter.configure();
    ParameterValueList alreadyResolvedParameters = new ParameterValueList();
    Message message = new Message("fakeMessage");
    Object result = parameter.getValue(alreadyResolvedParameters, message, session, true);
    assertThat(result, instanceOf(Node.class));
    assertThat(result, not(instanceOf(Document.class)));
    String contents = XmlUtils.transformXml(TransformerFactory.newInstance().newTransformer(), new DOMSource((Node) result));
    assertEquals(expectedResultContents, contents);
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Message(nl.nn.adapterframework.stream.Message) Node(org.w3c.dom.Node) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) URL(java.net.URL) Test(org.junit.Test)

Example 65 with PipeLineSession

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

the class ParameterTest method testDefaultValueMethodValue.

@Test
public void testDefaultValueMethodValue() throws Exception {
    Parameter p = new Parameter();
    p.setXpathExpression("*/*");
    p.setValue("<doc/>");
    p.setDefaultValue("fakeDefaultValue");
    p.setSessionKey("sessionKeyForDefaultValue");
    p.setPattern("{sessionKeyForPattern}");
    p.setDefaultValueMethods("value");
    p.configure();
    PipeLineSession session = new PipeLineSession();
    session.put("sessionKeyForDefaultValue", "fakeDefaultValueSessionKey");
    session.put("sessionKeyForPattern", "fakePatternSessionKey");
    ParameterValueList alreadyResolvedParameters = new ParameterValueList();
    Message message = new Message("fakeMessage");
    String result = (String) p.getValue(alreadyResolvedParameters, message, session, false);
    assertEquals("<doc/>", result);
}
Also used : Message(nl.nn.adapterframework.stream.Message) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) 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