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());
}
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);
}
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());
}
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));
}
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);
}
Aggregations