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