1   /*
2    * $Id: FileComparatorTestCase.java 9311 2007-10-23 19:04:12Z akuzmin $
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.providers.file;
11  
12  import org.mule.MuleManager;
13  import org.mule.tck.FunctionalTestCase;
14  import org.mule.tck.functional.EventCallback;
15  import org.mule.tck.functional.FunctionalTestComponent;
16  import org.mule.umo.UMOEventContext;
17  import org.mule.util.FileUtils;
18  
19  import java.io.File;
20  
21  import edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch;
22  import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
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 MODEL_NAME = "ESTest";
32      public static final String COMPONENT_NAME = "FolderTO";
33  
34  
35      public void testComparator() throws Exception
36      {
37  
38          final CountDownLatch countDown = new CountDownLatch(2);
39          EventCallback callback = new EventCallback()
40          {
41              public void eventReceived(UMOEventContext context, Object component) throws Exception
42              {
43                  int index = (int) countDown.getCount() - 1;
44                  assertEquals(context.getMessage().getProperty(FileConnector.PROPERTY_ORIGINAL_FILENAME), FILE_NAMES[index]);
45                  countDown.countDown();
46              }
47          };
48  
49          ((FunctionalTestComponent) MuleManager.getInstance().lookupModel(MODEL_NAME).getComponent(COMPONENT_NAME).getDescriptor().getImplementation()).
50                  setEventCallback(callback);
51  
52          MuleManager.getInstance().lookupConnector(FILE_CONNECTOR_NAME).stopConnector();
53          File f1 = FileUtils.newFile(PATH + FILE_NAMES[0]);
54          f1.createNewFile();
55          Thread.sleep(1000);
56          File f2 = FileUtils.newFile(PATH + FILE_NAMES[1]);
57          f2.createNewFile();
58          Thread.sleep(1000);
59          MuleManager.getInstance().lookupConnector(FILE_CONNECTOR_NAME).startConnector();
60          assertTrue(countDown.await(TIMEOUT, TimeUnit.MILLISECONDS));
61      }
62  
63  
64      protected String getConfigResources()
65      {
66          return "file-functional-config.xml";
67      }
68  }