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