Search in sources :

Example 96 with Message

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

the class FileSystemActorTest method fileSystemActorListActionTest.

public void fileSystemActorListActionTest(String inputFolder, int numberOfFiles, int expectedNumberOfFiles) throws Exception {
    for (int i = 0; i < numberOfFiles; i++) {
        String filename = "tobelisted" + i + FILE1;
        if (!_fileExists(filename)) {
            createFile(inputFolder, filename, "is not empty");
        }
    }
    actor.setAction(FileSystemAction.LIST);
    if (inputFolder != null) {
        actor.setInputFolder(inputFolder);
    }
    actor.configure(fileSystem, null, owner);
    actor.open();
    Message message = new Message("");
    PipeLineSession session = new PipeLineSession();
    ParameterValueList pvl = null;
    Object result = actor.doAction(message, pvl, session);
    String stringResult = (String) result;
    log.debug(result);
    // TODO test that the fileSystemSender has returned the an XML with the details of the file
    // Iterator<F> it = result;
    // int count = 0;
    // while (it.hasNext()) {
    // it.next();
    // count++;
    // }
    String anchor = " count=\"";
    int posCount = stringResult.indexOf(anchor);
    if (posCount < 0) {
        fail("result does not contain anchor [" + anchor + "]");
    }
    int posQuote = stringResult.indexOf('"', posCount + anchor.length());
    int resultCount = Integer.valueOf(stringResult.substring(posCount + anchor.length(), posQuote));
    // test
    assertEquals("count mismatch", expectedNumberOfFiles, resultCount);
    assertEquals("mismatch in number of files", expectedNumberOfFiles, resultCount);
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) Message(nl.nn.adapterframework.stream.Message) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession)

Example 97 with Message

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

the class FileSystemSenderTest method fileSystemSenderListActionTest.

public void fileSystemSenderListActionTest(String inputFolder, int numberOfFiles) throws Exception {
    for (int i = 0; i < numberOfFiles; i++) {
        String filename = "tobelisted" + i + FILE1;
        if (!_fileExists(filename)) {
            createFile(inputFolder, filename, "is not empty");
        }
    }
    fileSystemSender.setAction(FileSystemAction.LIST);
    if (inputFolder != null) {
        fileSystemSender.setInputFolder(inputFolder);
    }
    fileSystemSender.configure();
    fileSystemSender.open();
    PipeLineSession session = new PipeLineSession();
    Message message = new Message("");
    Message result = fileSystemSender.sendMessage(message, session);
    log.debug(result);
    // TODO test that the fileSystemSender has returned the an XML with the details of the file
    // Iterator<F> it = result;
    // int count = 0;
    // while (it.hasNext()) {
    // it.next();
    // count++;
    // }
    String anchor = " count=\"";
    int posCount = result.asString().indexOf(anchor);
    if (posCount < 0) {
        fail("result does not contain anchor [" + anchor + "]");
    }
    int posQuote = result.asString().indexOf('"', posCount + anchor.length());
    int resultCount = Integer.valueOf(result.asString().substring(posCount + anchor.length(), posQuote));
    // test
    assertEquals("count mismatch", numberOfFiles, resultCount);
    assertEquals("mismatch in number of files", numberOfFiles, resultCount);
}
Also used : Message(nl.nn.adapterframework.stream.Message) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession)

Example 98 with Message

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

the class FileSystemActorTest method fileSystemActorWriteWithNoCharsetUsed.

@Test
public void fileSystemActorWriteWithNoCharsetUsed() throws Exception {
    String filename = "senderwriteWithCharsetUseDefault" + FILE1;
    String contents = "€ $ & ^ % @ < é ë ó ú à è";
    PipeLineSession session = new PipeLineSession();
    session.put("senderwriteWithCharsetUseDefault", contents);
    ParameterList params = new ParameterList();
    params.add(ParameterBuilder.create().withName("contents").withSessionKey("senderwriteWithCharsetUseDefault"));
    params.configure();
    waitForActionToFinish();
    actor.setAction(FileSystemAction.WRITE);
    actor.setFilename(filename);
    actor.configure(fileSystem, null, owner);
    actor.open();
    Message message = new Message(contents);
    ParameterValueList pvl = params.getValues(message, session);
    actor.doAction(message, pvl, session);
    String actualContents = readFile(null, filename);
    assertEquals(contents, actualContents);
}
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 99 with Message

use of nl.nn.adapterframework.stream.Message 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 100 with Message

use of nl.nn.adapterframework.stream.Message 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)

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