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.transport.vm.config;
8   
9   import org.mule.api.endpoint.EndpointURI;
10  import org.mule.api.endpoint.ImmutableEndpoint;
11  import org.mule.api.transaction.TransactionConfig;
12  import org.mule.config.QueueProfile;
13  import org.mule.tck.junit4.FunctionalTestCase;
14  import org.mule.tck.testmodels.mule.TestTransactionFactory;
15  import org.mule.transaction.XaTransactionFactory;
16  import org.mule.transport.vm.VMConnector;
17  
18  import org.junit.Test;
19  
20  import static org.junit.Assert.assertEquals;
21  import static org.junit.Assert.assertFalse;
22  import static org.junit.Assert.assertNotNull;
23  import static org.junit.Assert.assertTrue;
24  
25  
26  /**
27   * Tests the Spring XML namespace for the VM transport.
28   */
29  public class VmNamespaceHandlerTestCase extends FunctionalTestCase
30  {
31  
32      @Override
33      protected String getConfigResources()
34      {
35          return "vm/vm-namespace-config.xml";
36      }
37  
38      @Test
39      public void testDefaults() throws Exception
40      {
41          VMConnector c = (VMConnector)muleContext.getRegistry().lookupConnector("vmConnectorDefaults");
42          assertNotNull(c);
43          
44          assertEquals(muleContext.getConfiguration().getDefaultQueueTimeout(), c.getQueueTimeout());
45          QueueProfile queueProfile = c.getQueueProfile();
46          assertNotNull(queueProfile);
47          
48          assertTrue(c.isConnected());
49          assertTrue(c.isStarted());
50      }
51      
52      @Test
53      public void testDefaultQueueProfile() throws Exception
54      {
55          VMConnector c = (VMConnector)muleContext.getRegistry().lookupConnector("vmConnector1");
56          assertNotNull(c);
57          
58          assertEquals(muleContext.getConfiguration().getDefaultQueueTimeout(), c.getQueueTimeout());
59          QueueProfile queueProfile = c.getQueueProfile();
60          assertNotNull(queueProfile);
61          assertFalse(queueProfile.isPersistent());
62          
63          assertTrue(c.isConnected());
64          assertTrue(c.isStarted());
65      }
66      
67      @Test
68      public void testConfig() throws Exception
69      {
70          VMConnector c = (VMConnector)muleContext.getRegistry().lookupConnector("vmConnector2");
71          assertNotNull(c);
72          
73          assertEquals(5000, c.getQueueTimeout());
74          QueueProfile queueProfile = c.getQueueProfile();
75          assertNotNull(queueProfile);
76          assertTrue(queueProfile.isPersistent());
77          assertEquals(10, queueProfile.getMaxOutstandingMessages());
78  
79          assertTrue(c.isConnected());
80          assertTrue(c.isStarted());
81      }
82  
83      @Test
84      public void testGlobalEndpoint() throws Exception
85      {
86          ImmutableEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint("vmEndpoint");
87          assertNotNull(endpoint);
88          EndpointURI uri = endpoint.getEndpointURI();
89          assertNotNull(uri);
90          String address = uri.getAddress();
91          assertEquals(address, "queue");
92      }
93      
94      @Test
95      public void testVmTransaction() throws Exception
96      {
97          ImmutableEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint("globalWithTx");
98          assertNotNull(endpoint);
99          
100         TransactionConfig txConfig = endpoint.getTransactionConfig();
101         assertNotNull(txConfig);
102         assertEquals(TransactionConfig.ACTION_ALWAYS_BEGIN, txConfig.getAction());
103         assertEquals(42, txConfig.getTimeout());
104     }
105 
106     @Test
107     public void testCustomTransaction() throws Exception
108     {
109         ImmutableEndpoint endpoint = muleContext.getRegistry().lookupEndpointBuilder("customTx").buildInboundEndpoint();
110         assertNotNull(endpoint);
111         
112         TransactionConfig txConfig = endpoint.getTransactionConfig();
113         assertNotNull(txConfig);
114         assertEquals(TransactionConfig.ACTION_JOIN_IF_POSSIBLE, txConfig.getAction());
115         TestTransactionFactory factory = (TestTransactionFactory) endpoint.getTransactionConfig().getFactory();
116         assertNotNull(factory);
117         assertEquals("foo", factory.getValue());
118     }
119 
120     @Test
121     public void testXaTransaction() throws Exception
122     {
123         ImmutableEndpoint endpoint = muleContext.getRegistry().lookupEndpointBuilder("xaTx").buildInboundEndpoint();
124         assertNotNull(endpoint);
125         
126         TransactionConfig txConfig = endpoint.getTransactionConfig();
127         assertNotNull(txConfig);
128         assertEquals(TransactionConfig.ACTION_ALWAYS_JOIN, txConfig.getAction());
129         assertEquals(XaTransactionFactory.class, txConfig.getFactory().getClass());
130     }
131 
132 }