1   /*
2    * $Id: MuleBeanDefinitionReaderTestCase.java 7976 2007-08-21 14:26:13Z 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  
11  package org.mule.extras.spring.config;
12  
13  import org.mule.MuleManager;
14  import org.mule.config.ConfigurationBuilder;
15  import org.mule.impl.DefaultExceptionStrategy;
16  import org.mule.providers.vm.VMConnector;
17  import org.mule.routing.ForwardingCatchAllStrategy;
18  import org.mule.tck.AbstractConfigBuilderTestCase;
19  import org.mule.tck.testmodels.mule.TestConnector;
20  import org.mule.umo.UMODescriptor;
21  import org.mule.umo.UMOException;
22  import org.mule.umo.endpoint.UMOEndpoint;
23  import org.mule.umo.provider.UMOConnector;
24  import org.mule.umo.routing.UMORouterCatchAllStrategy;
25  
26  import java.util.List;
27  import java.util.Map;
28  import java.util.Set;
29  
30  /**
31   * Tests the Mule-to-Spring XSLT transformation.
32   */
33  public class MuleBeanDefinitionReaderTestCase extends AbstractConfigBuilderTestCase
34  {
35  
36      public String getConfigResources()
37      {
38          // A Mule Xml config file and a Spring context file
39          return "test-xml-mule-config-split-with-beans.xml,test-xml-mule-config.xml,test-application-context.xml,test-xml-mule-config-split.xml,test-mule-to-spring-with-xslt.xml";
40      }
41  
42      public ConfigurationBuilder getBuilder()
43      {
44          return new SpringConfigurationBuilder();
45      }
46  
47      // Test spring bean configs
48  
49      public void testConnectorBean()
50      {
51          VMConnector c = (VMConnector)MuleManager.getInstance().lookupConnector("beanConnector");
52          assertNotNull(c);
53          assertTrue(c.isQueueEvents());
54      }
55  
56      public void testManagerIdIsSet()
57      {
58          // The id is the the mule-configuration id from the first config
59          assertEquals("Manager ID has not been properly transformed.",
60                       "Test_Mule_Properties_with_beans", MuleManager.getInstance().getId());
61      }
62  
63      public void testEndpointPropertyBean()
64      {
65          UMODescriptor d = MuleManager.getInstance().lookupModel("main").getDescriptor("appleComponent3");
66          assertNotNull(d);
67          assertNotNull(d.getInboundRouter());
68          UMOEndpoint e = (UMOEndpoint)d.getInboundRouter().getEndpoints().get(0);
69          assertNotNull(e);
70          assertEquals("Prop2", e.getProperties().get("testEndpointBeanProperty"));
71  
72          d = MuleManager.getInstance().lookupModel("main").getDescriptor("orangeComponent");
73          assertNotNull(d);
74          UMORouterCatchAllStrategy strategy = d.getInboundRouter().getCatchAllStrategy();
75          assertTrue(strategy instanceof ForwardingCatchAllStrategy);
76          UMOConnector conn = strategy.getEndpoint().getConnector();
77          assertTrue(conn instanceof TestConnector);
78          assertEquals("dummyConnector", conn.getName());
79          
80          // e = d.getInboundEndpoint();
81          // assertNotNull(e);
82          // assertEquals(e.getEndpointURI().toString(), MuleManager.getInstance()
83          // .getEndpointIdentifiers()
84          // .get("Test Queue"));
85      }
86  
87      public void testPropertyBeansOnDescriptors()
88      {
89          UMODescriptor d = MuleManager.getInstance().lookupModel("main").getDescriptor("appleComponent3");
90          assertNotNull(d);
91  
92          assertTrue(d.getExceptionListener() instanceof DefaultExceptionStrategy);
93  
94          // assertEquals("1.1", d.getVersion());
95      }
96  
97      public void testPropertyBeansInMaps()
98      {
99          UMODescriptor d = MuleManager.getInstance().lookupModel("main").getDescriptor("appleComponent3");
100         assertNotNull(d);
101         Map map = (Map)d.getProperties().get("springMap");
102         assertNotNull(map);
103         assertEquals(2, map.size());
104         List list = (List)d.getProperties().get("springList");
105         assertNotNull(list);
106         assertEquals(2, list.size());
107         Set set = (Set)d.getProperties().get("springSet");
108         assertNotNull(set);
109         assertEquals(2, set.size());
110         assertNotNull(d.getProperties().get("springBean"));
111     }
112 
113     public void testConvertedSpringBeans() throws UMOException
114     {
115         assertNotNull(MuleManager.getInstance().getContainerContext().getComponent("TestComponent"));
116     }
117 }