View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.test.construct;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.api.client.MuleClient;
11  import org.mule.lifecycle.LifecycleTrackerProcessor;
12  import org.mule.tck.junit4.FunctionalTestCase;
13  
14  import org.junit.Test;
15  
16  import static org.junit.Assert.assertEquals;
17  
18  public class SubFlowTestCase extends FunctionalTestCase
19  {
20  
21      @Override
22      protected String getConfigResources()
23      {
24          return "org/mule/test/construct/sub-flow.xml";
25      }
26  
27      @Test
28      public void testProcessorChainViaProcessorRef() throws Exception
29      {
30          MuleClient client = muleContext.getClient();
31          MuleMessage result = client.send("vm://ProcessorChainViaProcessorRef", "", null);
32          assertEquals("1xyz2", result.getPayloadAsString());
33  
34          assertEquals("[setMuleContext, initialise, setService, setMuleContext, initialise, start]",
35              result.getInboundProperty(LifecycleTrackerProcessor.LIFECYCLE_TRACKER_PROCESSOR_PROPERTY));
36          assertEquals(muleContext.getRegistry().lookupFlowConstruct("ProcessorChainViaProcessorRef"),
37              result.getInboundProperty(LifecycleTrackerProcessor.FLOW_CONSRUCT_PROPERTY));
38      }
39  
40      @Test
41      public void testProcessorChainViaFlowRef() throws Exception
42      {
43          MuleClient client = muleContext.getClient();
44          MuleMessage result = client.send("vm://ProcessorChainViaFlowRef", "", null);
45  
46          assertEquals("1xyz2", result.getPayloadAsString());
47  
48          assertEquals("[setMuleContext, initialise, setService, setMuleContext, initialise, start]",
49              result.getInboundProperty(LifecycleTrackerProcessor.LIFECYCLE_TRACKER_PROCESSOR_PROPERTY));
50          assertEquals(muleContext.getRegistry().lookupFlowConstruct("ProcessorChainViaFlowRef"),
51              result.getInboundProperty(LifecycleTrackerProcessor.FLOW_CONSRUCT_PROPERTY));
52      }
53  
54      @Test
55      public void testFlowviaFlowRef() throws Exception
56      {
57          MuleClient client = muleContext.getClient();
58          assertEquals("1xyz2", client.send("vm://FlowViaFlowRef", "", null).getPayloadAsString());
59      }
60  
61      @Test
62      public void testServiceviaFlowRef() throws Exception
63      {
64          MuleClient client = muleContext.getClient();
65          assertEquals("1xyz2", client.send("vm://ServiceViaFlowRef", "", null).getPayloadAsString());
66      }
67  
68      @Test
69      public void testFlowWithSubFlowWithComponent() throws Exception
70      {
71          MuleClient client = muleContext.getClient();
72          assertEquals("0", client.send("vm://flowWithsubFlowWithComponent", "0", null).getPayloadAsString());
73  
74      }
75  
76      @Test
77      public void testFlowWithSameGlobalChainTwice() throws Exception
78      {
79          MuleClient client = muleContext.getClient();
80          assertEquals("0xyzxyz", client.send("vm://flowWithSameGlobalChainTwice", "0", null).getPayloadAsString());
81      }
82  
83      @Test
84      public void testFlowWithSameGlobalChainSingletonTwice() throws Exception
85      {
86          MuleClient client = muleContext.getClient();
87          assertEquals("0xyzxyz", client.send("vm://flowWithSameGlobalChainSingletonTwice", "0", null).getPayloadAsString());
88      }
89  
90  }