1   /*
2    * $Id: VmNamespaceHandlerTestCase.java 12091 2008-06-18 10:02:26Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.transport.vm.VMConnector;
19  
20  
21  /**
22   * Tests the Spring XML namespace for the VM transport.
23   */
24  public class VmNamespaceHandlerTestCase extends FunctionalTestCase
25  {
26      protected String getConfigResources()
27      {
28          return "vm/vm-namespace-config.xml";
29      }
30  
31      public void testDefaults() throws Exception
32      {
33          VMConnector c = (VMConnector)muleContext.getRegistry().lookupConnector("vmConnectorDefaults");
34          assertNotNull(c);
35          
36          assertFalse(c.isQueueEvents());
37          assertEquals(1000, c.getQueueTimeout());
38          QueueProfile queueProfile = c.getQueueProfile();
39          assertNull(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          assertTrue(c.isQueueEvents());
51          assertEquals(1000, c.getQueueTimeout());
52          QueueProfile queueProfile = c.getQueueProfile();
53          assertNotNull(queueProfile);
54          assertFalse(queueProfile.isPersistent());
55          
56          assertTrue(c.isConnected());
57          assertTrue(c.isStarted());
58      }
59      
60      public void testConfig() throws Exception
61      {
62          VMConnector c = (VMConnector)muleContext.getRegistry().lookupConnector("vmConnector2");
63          assertNotNull(c);
64          
65          assertTrue(c.isQueueEvents());
66          assertEquals(5000, c.getQueueTimeout());
67          QueueProfile queueProfile = c.getQueueProfile();
68          assertNotNull(queueProfile);
69          assertTrue(queueProfile.isPersistent());
70          assertEquals(10, queueProfile.getMaxOutstandingMessages());
71  
72          assertTrue(c.isConnected());
73          assertTrue(c.isStarted());
74      }
75  
76      public void testGlobalEndpoint() throws Exception
77      {
78          ImmutableEndpoint endpoint = muleContext.getRegistry().lookupEndpointFactory().getInboundEndpoint("vmEndpoint");
79          assertNotNull(endpoint);
80          EndpointURI uri = endpoint.getEndpointURI();
81          assertNotNull(uri);
82          String address = uri.getAddress();
83          assertEquals(address, "queue");
84      }
85      
86      public void testVmTransaction() throws Exception
87      {
88          ImmutableEndpoint endpoint = muleContext.getRegistry().lookupEndpointFactory().getInboundEndpoint("globalWithTx");
89          assertNotNull(endpoint);
90          
91          TransactionConfig txConfig = endpoint.getTransactionConfig();
92          assertNotNull(txConfig);
93          assertEquals(TransactionConfig.ACTION_ALWAYS_BEGIN, txConfig.getAction());
94          assertEquals(42, txConfig.getTimeout());
95      }
96  
97      public void testCustomTransaction() throws Exception
98      {
99          ImmutableEndpoint endpoint = muleContext.getRegistry().lookupEndpointBuilder("customTx").buildInboundEndpoint();
100         assertNotNull(endpoint);
101         
102         TransactionConfig txConfig = endpoint.getTransactionConfig();
103         assertNotNull(txConfig);
104         assertEquals(TransactionConfig.ACTION_JOIN_IF_POSSIBLE, txConfig.getAction());
105         TestTransactionFactory factory = (TestTransactionFactory) endpoint.getTransactionConfig().getFactory();
106         assertNotNull(factory);
107         assertEquals("foo", factory.getValue());
108     }
109 
110 }