1
2
3
4
5
6
7 package org.mule.transport.sftp;
8
9 import org.mule.api.endpoint.ImmutableEndpoint;
10 import org.mule.module.client.MuleClient;
11 import org.mule.transport.sftp.dataintegrity.AbstractSftpDataIntegrityTestCase;
12
13 import java.util.HashMap;
14
15 import org.junit.Test;
16
17 import static org.junit.Assert.assertFalse;
18 import static org.junit.Assert.assertTrue;
19
20
21
22
23
24 public class SftpFilterTestCase extends AbstractSftpDataIntegrityTestCase
25 {
26
27 private static String INBOUND_ENDPOINT_NAME = "inboundEndpoint";
28 private static String OUTBOUND_ENDPOINT_NAME = "outboundEndpoint";
29
30 @Override
31 protected String getConfigResources()
32 {
33 return "mule-sftp-filter-config.xml";
34 }
35
36 @Override
37 protected void doSetUp() throws Exception
38 {
39 super.doSetUp();
40
41 initEndpointDirectory(INBOUND_ENDPOINT_NAME);
42 initEndpointDirectory(OUTBOUND_ENDPOINT_NAME);
43 }
44
45 @Test
46 public void testFilter() throws Exception
47 {
48 MuleClient muleClient = new MuleClient(muleContext);
49
50
51
52
53 HashMap<String, String> txtProps = new HashMap<String, String>(1);
54 txtProps.put(SftpConnector.PROPERTY_FILENAME, FILE_NAME);
55 muleClient.dispatch(getAddressByEndpoint(muleClient, INBOUND_ENDPOINT_NAME), TEST_MESSAGE, txtProps);
56
57
58 DispatchParameters dp = new DispatchParameters(INBOUND_ENDPOINT_NAME, OUTBOUND_ENDPOINT_NAME);
59 dp.setFilename("file.xml");
60 dispatchAndWaitForDelivery(dp);
61
62 SftpClient outboundSftpClient = getSftpClient(muleClient, OUTBOUND_ENDPOINT_NAME);
63 ImmutableEndpoint outboundEndpoint = (ImmutableEndpoint) muleClient.getProperty(OUTBOUND_ENDPOINT_NAME);
64
65 SftpClient inboundSftpClient = getSftpClient(muleClient, INBOUND_ENDPOINT_NAME);
66 ImmutableEndpoint inboundEndpoint = (ImmutableEndpoint) muleClient.getProperty(INBOUND_ENDPOINT_NAME);
67
68 assertFalse("The xml file should not be left in the inbound directory", verifyFileExists(
69 inboundSftpClient, inboundEndpoint.getEndpointURI().getPath(), "file.xml"));
70 assertTrue("The xml file should be in the outbound directory", verifyFileExists(outboundSftpClient,
71 outboundEndpoint.getEndpointURI().getPath(), "file.xml"));
72
73 assertTrue("The txt file should be left in the inbound directory", verifyFileExists(
74 inboundSftpClient, inboundEndpoint.getEndpointURI().getPath(), FILE_NAME));
75 assertFalse("The txt file should not be in the outbound directory", verifyFileExists(
76 outboundSftpClient, outboundEndpoint.getEndpointURI().getPath(), FILE_NAME));
77 }
78 }