// Downloads large file in the remote directory specified in config
public void testIdentityFile() throws Exception
{
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference message = new AtomicReference();
final AtomicInteger loopCount = new AtomicInteger(0);
EventCallback callback = new EventCallback()
{
public synchronized void eventReceived(MuleEventContext context, Object component)
{
try
{
logger.info("called " + loopCount.incrementAndGet() + " times");
// without this we may have problems with the many repeats
if (1 == latch.getCount())
{
String o = IOUtils.toString((SftpInputStream) context.getMessage().getPayload());
message.set(o);
latch.countDown();
}
}
catch (Exception e)
{
logger.error(e.getMessage(), e);
}
}
};
MuleClient client = new MuleClient(muleContext);
// Ensure that no other files exists
// cleanupRemoteFtpDirectory(client, INBOUND_ENDPOINT_NAME);
Map properties = new HashMap();
// properties.put("filename", "foo.bar");
Object component = getComponent("testComponent");
assertTrue("FunctionalTestComponent expected", component instanceof FunctionalTestComponent);
FunctionalTestComponent ftc = (FunctionalTestComponent) component;
assertNotNull(ftc);
ftc.setEventCallback(callback);
logger.debug("before dispatch");
// Send an file to the SFTP server, which the inbound-endpoint then can pick
// up
client.dispatch(getAddressByEndpoint(client, INBOUND_ENDPOINT_NAME), TEST_MESSAGE, properties);
logger.debug("before retrieve");
latch.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
assertEquals(TEST_MESSAGE, message.get());
}