1
2
3
4
5
6
7
8
9
10 package org.mule.transport.file;
11
12 import org.mule.api.MuleEventContext;
13 import org.mule.tck.functional.EventCallback;
14 import org.mule.tck.functional.FunctionalTestComponent;
15 import org.mule.tck.junit4.FunctionalTestCase;
16 import org.mule.util.FileUtils;
17
18 import java.io.File;
19 import java.util.concurrent.CountDownLatch;
20 import java.util.concurrent.TimeUnit;
21
22 import org.junit.Test;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertTrue;
26
27 public class FileComparatorTestCase extends FunctionalTestCase
28 {
29 public static final String PATH = "./.mule/in/";
30 public static final String FILE_CONNECTOR_NAME = "fileConnector";
31 public static final int TIMEOUT = 50000;
32 public static final String FILE_NAMES[] = {"first", "second"};
33 public static final String COMPONENT_NAME = "FolderTO";
34
35 @Override
36 protected String getConfigResources()
37 {
38 return "file-functional-config.xml";
39 }
40
41 @Test
42 public void testComparator() throws Exception
43 {
44 final CountDownLatch countDown = new CountDownLatch(2);
45 EventCallback callback = new EventCallback()
46 {
47 @Override
48 public void eventReceived(MuleEventContext context, Object component) throws Exception
49 {
50 int index = (int) countDown.getCount() - 1;
51 assertEquals(FILE_NAMES[index], context.getMessage().getOutboundProperty(FileConnector.PROPERTY_ORIGINAL_FILENAME));
52 countDown.countDown();
53 }
54 };
55
56 ((FunctionalTestComponent) getComponent(COMPONENT_NAME)).setEventCallback(callback);
57
58 muleContext.getRegistry().lookupConnector(FILE_CONNECTOR_NAME).stop();
59 File f1 = FileUtils.newFile(PATH + FILE_NAMES[0]);
60 assertTrue(f1.createNewFile());
61 Thread.sleep(1000);
62 File f2 = FileUtils.newFile(PATH + FILE_NAMES[1]);
63 assertTrue(f2.createNewFile());
64 Thread.sleep(1000);
65 muleContext.getRegistry().lookupConnector(FILE_CONNECTOR_NAME).start();
66 assertTrue(countDown.await(TIMEOUT, TimeUnit.MILLISECONDS));
67 }
68 }