View Javadoc

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