Search in sources :

Example 86 with Message

use of nl.nn.adapterframework.stream.Message in project iaf by ibissource.

the class FileSystemPipeTest method fileSystemPipeUploadActionTestWithInputStream.

@Test
public void fileSystemPipeUploadActionTestWithInputStream() 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);
    fileSystemPipe.addParameter(ParameterBuilder.create().withName("file").withSessionKey("uploadActionTarget"));
    fileSystemPipe.setAction(FileSystemAction.UPLOAD);
    fileSystemPipe.configure();
    fileSystemPipe.start();
    Message message = new Message(filename);
    PipeRunResult prr = fileSystemPipe.doPipe(message, session);
    String result = prr.getResult().asString();
    TestAssertions.assertXpathValueEquals(filename, result, "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 : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) Message(nl.nn.adapterframework.stream.Message) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) Test(org.junit.Test)

Example 87 with Message

use of nl.nn.adapterframework.stream.Message in project iaf by ibissource.

the class FileSystemPipeTest method fileSystemPipeDeleteActionTest.

@Test
public void fileSystemPipeDeleteActionTest() throws Exception {
    String filename = "tobedeleted" + FILE1;
    if (!_fileExists(filename)) {
        createFile(null, filename, "is not empty");
    }
    fileSystemPipe.setAction(FileSystemAction.DELETE);
    fileSystemPipe.configure();
    fileSystemPipe.start();
    Message message = new Message(filename);
    PipeRunResult prr = fileSystemPipe.doPipe(message, null);
    String result = prr.getResult().asString();
    waitForActionToFinish();
    boolean actual = _fileExists(filename);
    // test
    assertEquals("result of pipe should be name of deleted file", filename, result);
    assertFalse("Expected file [" + filename + "] " + "not to be present", actual);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) Message(nl.nn.adapterframework.stream.Message) Test(org.junit.Test)

Example 88 with Message

use of nl.nn.adapterframework.stream.Message in project iaf by ibissource.

the class FileSystemPipeTest method fileSystemPipeUploadActionTestWithByteArray.

@Test
public void fileSystemPipeUploadActionTestWithByteArray() 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());
    fileSystemPipe.addParameter(ParameterBuilder.create().withName("file").withSessionKey("uploadActionTargetwByteArray"));
    fileSystemPipe.setAction(FileSystemAction.UPLOAD);
    fileSystemPipe.configure();
    fileSystemPipe.start();
    Message message = new Message(filename);
    PipeRunResult prr = fileSystemPipe.doPipe(message, session);
    String result = prr.getResult().asString();
    TestAssertions.assertXpathValueEquals(filename, result, "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 : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) Message(nl.nn.adapterframework.stream.Message) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) Test(org.junit.Test)

Example 89 with Message

use of nl.nn.adapterframework.stream.Message in project iaf by ibissource.

the class FileSystemPipeTest method fileSystemPipeMoveActionTest.

public void fileSystemPipeMoveActionTest(String folder1, String folder2, boolean folderExists, boolean setCreateFolderAttribute) throws Exception {
    String filename = "sendermove" + FILE1;
    String contents = "Tekst om te lezen";
    if (folder1 != null) {
        _createFolder(folder1);
    }
    if (folderExists && folder2 != null) {
        _createFolder(folder2);
    }
    createFile(folder1, filename, contents);
    // deleteFile(folder2, filename);
    waitForActionToFinish();
    fileSystemPipe.setAction(FileSystemAction.MOVE);
    fileSystemPipe.addParameter(new Parameter("destination", folder2));
    if (setCreateFolderAttribute) {
        fileSystemPipe.setCreateFolder(true);
    }
    fileSystemPipe.configure();
    fileSystemPipe.start();
    Message message = new Message(filename);
    PipeRunResult prr = fileSystemPipe.doPipe(message, null);
    String result = prr.getResult().asString();
    // test
    // result should be name of the moved file
    assertNotNull(result);
    // TODO: result should point to new location of file
    // TODO: contents of result should be contents of original file
    // assertTrue("file should exist in destination folder ["+folder2+"]", _fileExists(folder2, filename)); // does not have to be this way. filename may have changed.
    assertFalse("file should not exist anymore in original folder [" + folder1 + "]", _fileExists(folder1, filename));
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) Message(nl.nn.adapterframework.stream.Message) Parameter(nl.nn.adapterframework.parameters.Parameter)

Example 90 with Message

use of nl.nn.adapterframework.stream.Message in project iaf by ibissource.

the class FileSystemPipeTest method fileSystemPipeListActionTestWithInputFolderAsParameter.

@Test
public void fileSystemPipeListActionTestWithInputFolderAsParameter() throws Exception {
    String filename = FILE1;
    String filename2 = FILE2;
    String inputFolder = "directory";
    if (_fileExists(inputFolder, filename)) {
        _deleteFile(inputFolder, filename);
    }
    if (_fileExists(inputFolder, filename2)) {
        _deleteFile(inputFolder, filename2);
    }
    _createFolder(inputFolder);
    fileSystemPipe.addParameter(new Parameter("inputFolder", inputFolder));
    fileSystemPipe.setAction(FileSystemAction.LIST);
    fileSystemPipe.configure();
    fileSystemPipe.start();
    OutputStream out = _createFile(inputFolder, filename);
    out.write("some content".getBytes());
    out.close();
    waitForActionToFinish();
    assertTrue("File [" + filename + "]expected to be present", _fileExists(inputFolder, filename));
    OutputStream out2 = _createFile(inputFolder, filename2);
    out2.write("some content of second file".getBytes());
    out2.close();
    waitForActionToFinish();
    assertTrue("File [" + filename2 + "]expected to be present", _fileExists(inputFolder, filename2));
    Message message = new Message(filename);
    PipeRunResult prr = fileSystemPipe.doPipe(message, null);
    String result = prr.getResult().asString();
    System.err.println(result);
    waitForActionToFinish();
    String anchor = " count=\"";
    int posCount = result.indexOf(anchor);
    if (posCount < 0) {
        fail("result does not contain anchor [" + anchor + "]");
    }
    int posQuote = result.indexOf('"', posCount + anchor.length());
    int resultCount = Integer.valueOf(result.substring(posCount + anchor.length(), posQuote));
    // test
    assertEquals("count mismatch", 2, resultCount);
    assertEquals("mismatch in number of files", 2, resultCount);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) Message(nl.nn.adapterframework.stream.Message) OutputStream(java.io.OutputStream) MessageOutputStream(nl.nn.adapterframework.stream.MessageOutputStream) Parameter(nl.nn.adapterframework.parameters.Parameter) Test(org.junit.Test)

Aggregations

Message (nl.nn.adapterframework.stream.Message)598 Test (org.junit.Test)385 PipeLineSession (nl.nn.adapterframework.core.PipeLineSession)220 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)114 IOException (java.io.IOException)112 SenderException (nl.nn.adapterframework.core.SenderException)97 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)54 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)54 Parameter (nl.nn.adapterframework.parameters.Parameter)52 PipeForward (nl.nn.adapterframework.core.PipeForward)41 Date (java.util.Date)37 TimeoutException (nl.nn.adapterframework.core.TimeoutException)31 UrlMessage (nl.nn.adapterframework.stream.UrlMessage)31 PipeRunException (nl.nn.adapterframework.core.PipeRunException)30 ByteArrayInputStream (java.io.ByteArrayInputStream)29 InputStream (java.io.InputStream)29 ParameterList (nl.nn.adapterframework.parameters.ParameterList)28 ListenerException (nl.nn.adapterframework.core.ListenerException)27 ParameterException (nl.nn.adapterframework.core.ParameterException)25 SAXException (org.xml.sax.SAXException)19