1   /*
2    * $Id: MuleBeanDefinitionReaderTestCase.java 9206 2007-10-18 15:38:38Z holger $
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      // @Override
43      public ConfigurationBuilder getBuilder()
44      {
45          return new SpringConfigurationBuilder();
46      }
47  
48      // Test spring bean configs
49  
50      public void testConnectorBean()
51      {
52          VMConnector c = (VMConnector) MuleManager.getInstance().lookupConnector("beanConnector");
53          assertNotNull(c);
54          assertTrue(c.isQueueEvents());
55      }
56  
57      public void testManagerIdIsSet()
58      {
59          // The id is the the mule-configuration id from the first config
60          assertEquals("Manager ID has not been properly transformed.", "Test_Mule_Properties_with_beans",
61              MuleManager.getInstance().getId());
62      }
63  
64      public void testEndpointPropertyBean()
65      {
66          UMODescriptor d = MuleManager.getInstance().lookupModel("main").getDescriptor("appleComponent3");
67          assertNotNull(d);
68          assertNotNull(d.getInboundRouter());
69          UMOEndpoint e = (UMOEndpoint) d.getInboundRouter().getEndpoints().get(0);
70          assertNotNull(e);
71          assertEquals("Prop2", e.getProperties().get("testEndpointBeanProperty"));
72  
73          d = MuleManager.getInstance().lookupModel("main").getDescriptor("orangeComponent");
74          assertNotNull(d);
75          UMORouterCatchAllStrategy strategy = d.getInboundRouter().getCatchAllStrategy();
76          assertTrue(strategy instanceof ForwardingCatchAllStrategy);
77          UMOConnector conn = strategy.getEndpoint().getConnector();
78          assertTrue(conn instanceof TestConnector);
79          assertEquals("dummyConnector", conn.getName());
80  
81          e = d.getInboundEndpoint();
82          assertNotNull(e);
83          assertEquals(e.getEndpointURI().toString(), MuleManager.getInstance().getEndpointIdentifiers().get(
84              "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          assertEquals("1.1", d.getVersion());
94      }
95  
96      public void testPropertyBeansInMaps()
97      {
98          UMODescriptor d = MuleManager.getInstance().lookupModel("main").getDescriptor("appleComponent3");
99          assertNotNull(d);
100         Map map = (Map) d.getProperties().get("springMap");
101         assertNotNull(map);
102         assertEquals(2, map.size());
103         List list = (List) d.getProperties().get("springList");
104         assertNotNull(list);
105         assertEquals(2, list.size());
106         Set set = (Set) d.getProperties().get("springSet");
107         assertNotNull(set);
108         assertEquals(2, set.size());
109         assertNotNull(d.getProperties().get("springBean"));
110     }
111 
112     public void testConvertedSpringBeans() throws UMOException
113     {
114         assertNotNull(MuleManager.getInstance().getContainerContext().getComponent("TestComponent"));
115     }
116 
117 }