1   /*
2    * $Id: FileComparatorTestCase.java 12017 2008-06-12 09:04:04Z rossmason $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  package org.mule.transport.file;
11  
12  import org.mule.api.MuleEventContext;
13  import org.mule.tck.FunctionalTestCase;
14  import org.mule.tck.functional.EventCallback;
15  import org.mule.tck.functional.FunctionalTestComponent;
16  import org.mule.util.FileUtils;
17  
18  import java.io.File;
19  
20  import edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch;
21  import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
22  
23  public class FileComparatorTestCase extends FunctionalTestCase
24  {
25  
26      public static final String PATH = "./.mule/in/";
27      public static final String FILE_CONNECTOR_NAME = "fileConnector";
28      public static final int TIMEOUT = 50000;
29      public static final String FILE_NAMES[] = {"first", "second"};
30      public static final String MODEL_NAME = "ESTest";
31      public static final String COMPONENT_NAME = "FolderTO";
32  
33  
34      public void testComparator() throws Exception
35      {
36  
37          final CountDownLatch countDown = new CountDownLatch(2);
38          EventCallback callback = new EventCallback()
39          {
40              public void eventReceived(MuleEventContext context, Object component) throws Exception
41              {
42                  int index = (int) countDown.getCount() - 1;
43                  assertEquals(context.getMessage().getProperty(FileConnector.PROPERTY_ORIGINAL_FILENAME), FILE_NAMES[index]);
44                  countDown.countDown();
45              }
46          };
47  
48          ((FunctionalTestComponent) getComponent(COMPONENT_NAME)).setEventCallback(callback);
49  
50          muleContext.getRegistry().lookupConnector(FILE_CONNECTOR_NAME).stop();
51          File f1 = FileUtils.newFile(PATH + FILE_NAMES[0]);
52          assertTrue(f1.createNewFile());
53          Thread.sleep(1000);
54          File f2 = FileUtils.newFile(PATH + FILE_NAMES[1]);
55          assertTrue(f2.createNewFile());
56          Thread.sleep(1000);
57          muleContext.getRegistry().lookupConnector(FILE_CONNECTOR_NAME).start();
58          assertTrue(countDown.await(TIMEOUT, TimeUnit.MILLISECONDS));
59      }
60  
61  
62      protected String getConfigResources()
63      {
64          return "file-functional-config.xml";
65      }
66  }