View Javadoc

1   /*
2    * $Id: FlowSyncAsyncProcessingStrategyTestCase.java 22653 2011-08-12 05:29:45Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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  
11  package org.mule.test.construct;
12  
13  import java.io.File;
14  
15  import junit.framework.Assert;
16  
17  import org.junit.Test;
18  import org.mule.api.client.MuleClient;
19  import org.mule.tck.junit4.FunctionalTestCase;
20  import org.mule.util.FileUtils;
21  
22  public class FlowSyncAsyncProcessingStrategyTestCase extends FunctionalTestCase
23  {
24  
25      public static final String SLEEP_TIME = "sleepTime";
26  
27      @Override
28      protected String getConfigResources()
29      {
30          return "org/mule/test/construct/flow-sync-async-processing-strategy-config.xml";
31  
32      }
33  
34      @Test
35      public void testSynchProcessingStrategy() throws Exception
36      {
37          sendMsgAndWait("vm://testSynch");
38  
39          File file = getFileTestWroteTo();
40          String str = FileUtils.readFileToString(file);
41  
42          Assert.assertEquals("Part 1Part 2", str);
43  
44          FileUtils.deleteQuietly(file);
45      }
46  
47      @Test
48      public void testAsynch() throws Exception
49      {
50          sendMsgAndWait("vm://testAsynch");
51  
52          File file = getFileTestWroteTo();
53          String str = FileUtils.readFileToString(file);
54  
55          Assert.assertEquals("Part 2Part 1", str);
56  
57          FileUtils.deleteQuietly(file);
58  
59      }
60  
61      private void sendMsgAndWait(String endpoint) throws Exception
62      {
63          MuleClient client = muleContext.getClient();
64  
65          client.dispatch(endpoint, "Part 1;Part 2", null);
66  
67          Thread.sleep(10000);
68  
69      }
70  
71      private File getFileTestWroteTo()
72      {
73          return new File("./test/testfile.txt");
74      }
75  
76  }