use of org.wso2.carbon.inbound.endpoint.protocol.file.MockFile in project wso2-synapse by wso2.
the class VFSTransportListenerTest method testVFSTransportListenerBasics.
/**
* Testcase to test basic functionality of {@link VFSTransportListener}
* @throws Exception
*/
public void testVFSTransportListenerBasics() throws Exception {
MockFileHolder.getInstance().clear();
String fileUri = "test1:///foo/bar/test-" + System.currentTimeMillis() + "/DIR/IN/";
String moveAfterFailure = "test1:///foo/bar/test-" + System.currentTimeMillis() + "/DIR/FAIL/";
AxisService axisService = new AxisService("testVFSService");
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_FILE_URI, fileUri));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_CONTENT_TYPE, "text/xml"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_FILE_NAME_PATTERN, ".*\\.txt"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_ACTION_AFTER_PROCESS, VFSTransportListener.MOVE));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_ACTION_AFTER_FAILURE, VFSTransportListener.MOVE));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_MOVE_AFTER_FAILURE, moveAfterFailure));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_MOVE_AFTER_FAILED_MOVE, moveAfterFailure));
axisService.addParameter(new Parameter(VFSConstants.STREAMING, "false"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_LOCKING, VFSConstants.TRANSPORT_FILE_LOCKING_ENABLED));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_INTERVAL, "1000"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_COUNT, "1"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_AUTO_LOCK_RELEASE, "true"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_AUTO_LOCK_RELEASE_INTERVAL, "20000"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_AUTO_LOCK_RELEASE_SAME_NODE, "true"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_DISTRIBUTED_LOCK, "true"));
axisService.addParameter(new Parameter(VFSConstants.TRANSPORT_DISTRIBUTED_LOCK_TIMEOUT, "20000"));
axisService.addParameter(new Parameter(VFSConstants.FILE_SORT_PARAM, VFSConstants.FILE_SORT_VALUE_NAME));
axisService.addParameter(new Parameter(VFSConstants.FILE_SORT_ORDER, "true"));
TransportDescriptionFactory transportDescriptionFactory = new VFSTransportDescriptionFactory();
TransportInDescription transportInDescription = null;
try {
transportInDescription = transportDescriptionFactory.createTransportInDescription();
} catch (Exception e) {
Assert.fail("Error occurred while creating transport in description");
}
VFSTransportListener vfsTransportListener = getListener(transportInDescription);
// initialize listener
vfsTransportListener.init(new ConfigurationContext(new AxisConfiguration()), transportInDescription);
// Initialize VFSTransportListener
vfsTransportListener.doInit();
// Start listener
vfsTransportListener.start();
// Create poll entry
PollTableEntry pollTableEntry = vfsTransportListener.createEndpoint();
Assert.assertTrue("Global file locking not applied to created poll entry", pollTableEntry.isFileLockingEnabled());
// Load configuration of poll entry
pollTableEntry.loadConfiguration(axisService);
populatePollTableEntry(pollTableEntry, axisService, vfsTransportListener);
vfsTransportListener.poll(pollTableEntry);
MockFile targetDir = MockFileHolder.getInstance().getFile(fileUri);
Assert.assertNotNull("Failed target directory creation", targetDir);
Assert.assertEquals("Created target directory is not Folder type", targetDir.getName().getType(), FileType.FOLDER);
MockFile failDir = MockFileHolder.getInstance().getFile(moveAfterFailure);
Assert.assertNotNull("Fail to create expected directory to move files when failure", failDir);
MockFileHolder.getInstance().clear();
}
Aggregations