View Javadoc

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