Search in sources :

Example 31 with PipeLineSession

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

the class FileSystemActorTest method fileSystemActorWriteActionTestWithInputStream.

@Test
public void fileSystemActorWriteActionTestWithInputStream() throws Exception {
    String filename = "uploadedwithInputStream" + FILE1;
    String contents = "Some text content to test upload action\n";
    if (_fileExists(filename)) {
        _deleteFile(null, filename);
    }
    InputStream stream = new ByteArrayInputStream(contents.getBytes("UTF-8"));
    PipeLineSession session = new PipeLineSession();
    session.put("uploadActionTarget", stream);
    ParameterList params = new ParameterList();
    params.add(ParameterBuilder.create().withName("file").withSessionKey("uploadActionTarget"));
    params.configure();
    actor.setAction(FileSystemAction.WRITE);
    actor.configure(fileSystem, params, owner);
    actor.open();
    Message message = new Message(filename);
    ParameterValueList pvl = params.getValues(message, session);
    Object result = actor.doAction(message, pvl, session);
    String stringResult = (String) result;
    TestAssertions.assertXpathValueEquals(filename, stringResult, "file/@name");
    waitForActionToFinish();
    String actual = readFile(null, filename);
    // test
    // TODO: evaluate 'result'
    // assertEquals("result of sender should be input message",result,message);
    assertEquals(contents.trim(), actual.trim());
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) Message(nl.nn.adapterframework.stream.Message) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) ParameterList(nl.nn.adapterframework.parameters.ParameterList) Test(org.junit.Test)

Example 32 with PipeLineSession

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

the class FileSystemActorTest method fileSystemActorAppendActionWithRolloverBySize.

@Test
public void fileSystemActorAppendActionWithRolloverBySize() throws Exception {
    String filename = "rolloverBySize" + FILE1;
    String contents = "thanos car ";
    int numOfBackups = 3;
    int numOfWrites = 5;
    int rotateSize = 10;
    if (_fileExists(filename)) {
        _deleteFile(null, filename);
    }
    createFile(null, filename, contents);
    PipeLineSession session = new PipeLineSession();
    ParameterList params = new ParameterList();
    params.add(ParameterBuilder.create().withName("contents").withSessionKey("appendActionwString"));
    params.configure();
    actor.setAction(FileSystemAction.APPEND);
    actor.setRotateSize(rotateSize);
    actor.setNumberOfBackups(numOfBackups);
    actor.configure(fileSystem, params, owner);
    actor.open();
    Message message = new Message(filename);
    for (int i = 0; i < numOfWrites; i++) {
        session.put("appendActionwString", contents + i);
        ParameterValueList pvl = params.getValues(message, session);
        String result = (String) actor.doAction(message, pvl, null);
        TestAssertions.assertXpathValueEquals(filename, result, "file/@name");
    }
    int lastSavedBackup = numOfWrites < numOfBackups ? numOfWrites : numOfBackups;
    assertTrue("last backup with no " + lastSavedBackup + " does not exist", fileSystem.exists(fileSystem.toFile(filename + "." + lastSavedBackup)));
    for (int i = 1; i <= numOfBackups; i++) {
        String actualContentsi = readFile(null, filename + "." + i);
        assertEquals("contents of backup no " + i + " is not correct", (contents + (numOfWrites - 1 - i)).trim(), actualContentsi.trim());
    }
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) Message(nl.nn.adapterframework.stream.Message) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) ParameterList(nl.nn.adapterframework.parameters.ParameterList) Test(org.junit.Test)

Example 33 with PipeLineSession

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

the class FileSystemActorTest method fileSystemActorWriteActionTestWithByteArrayAndContentsViaAlternativeParameter.

@Test
public void fileSystemActorWriteActionTestWithByteArrayAndContentsViaAlternativeParameter() throws Exception {
    String filename = "uploadedwithByteArray" + FILE1;
    String contents = "Some text content to test upload action\n";
    if (_fileExists(filename)) {
        _deleteFile(null, filename);
    }
    PipeLineSession session = new PipeLineSession();
    session.put("uploadActionTargetwByteArray", contents.getBytes());
    ParameterList params = new ParameterList();
    params.add(ParameterBuilder.create().withName("file").withSessionKey("uploadActionTargetwByteArray"));
    actor.setAction(FileSystemAction.WRITE);
    params.configure();
    actor.configure(fileSystem, params, owner);
    actor.open();
    Message message = new Message(filename);
    ParameterValueList pvl = params.getValues(message, session);
    Object result = actor.doAction(message, pvl, session);
    String stringResult = (String) result;
    TestAssertions.assertXpathValueEquals(filename, stringResult, "file/@name");
    waitForActionToFinish();
    String actual = readFile(null, filename);
    // test
    // TODO: evaluate 'result'
    // assertEquals("result of sender should be input message",result,message);
    assertEquals(contents.trim(), actual.trim());
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) Message(nl.nn.adapterframework.stream.Message) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) ParameterList(nl.nn.adapterframework.parameters.ParameterList) Test(org.junit.Test)

Example 34 with PipeLineSession

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

the class FileSystemActorTest method migrated_localFileSystemTestListIncludeExcludeWildcard.

@Test
public void migrated_localFileSystemTestListIncludeExcludeWildcard() throws Exception {
    String filename = "create" + FILE1;
    String filename1 = filename + ".oud.xml";
    String filename2 = filename + ".xml";
    String contents = "regeltje tekst";
    actor.setWildCard("*.xml");
    actor.setExcludeWildcard("*.oud.xml");
    actor.setAction(FileSystemAction.LIST);
    actor.configure(fileSystem, null, owner);
    actor.open();
    createFile(null, filename1, contents);
    createFile(null, filename2, contents);
    waitForActionToFinish();
    Message message = new Message("");
    PipeLineSession session = new PipeLineSession();
    ParameterValueList pvl = null;
    Object result = actor.doAction(message, pvl, session);
    String stringResult = (String) result;
    assertTrue(stringResult.contains(filename2));
    assertFalse(stringResult.contains(filename1));
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) Message(nl.nn.adapterframework.stream.Message) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) Test(org.junit.Test)

Example 35 with PipeLineSession

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

the class MultipartHttpSenderTest method simpleMockedMultipartHttp3.

@Test
public void simpleMockedMultipartHttp3() throws Throwable {
    MultipartHttpSender sender = getSender();
    Message input = new Message("<xml>input</xml>");
    try {
        PipeLineSession pls = new PipeLineSession(session);
        String xmlMultipart = "<parts><part name=\"dummy\" " + "value=\"{json:true}\" size=\"72833\" " + "mimeType=\"application/json\"/></parts>";
        pls.put("multipartXml", xmlMultipart);
        pls.put("part_file", new ByteArrayInputStream("<dummy xml file/>".getBytes()));
        sender.setMultipartXmlSessionKey("multipartXml");
        sender.configure();
        sender.open();
        String result = sender.sendMessage(input, pls).asString();
        assertEqualsIgnoreCRLF(getFile("simpleMockedMultipartHttp3.txt"), result.trim());
    } catch (SenderException e) {
        throw e.getCause();
    } finally {
        if (sender != null) {
            sender.close();
        }
    }
}
Also used : Message(nl.nn.adapterframework.stream.Message) ByteArrayInputStream(java.io.ByteArrayInputStream) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) SenderException(nl.nn.adapterframework.core.SenderException) 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