View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.config.spring;
8   
9   import static org.junit.Assert.assertTrue;
10  
11  import org.mule.api.component.JavaComponent;
12  import org.mule.api.object.ObjectFactory;
13  import org.mule.construct.SimpleFlowConstruct;
14  import org.mule.tck.junit4.FunctionalTestCase;
15  
16  import org.junit.Test;
17  
18  /**
19   * Test to ensure that Mule always uses the real
20   */
21  public class SpringAOPSpringBeanLookupTestCase extends FunctionalTestCase
22  {
23  
24      @Override
25      protected String getConfigResources()
26      {
27          return "org/mule/config/spring/spring-aop-springbeanlookup-config.xml";
28      }
29  
30      @Override
31      protected boolean isStartContext()
32      {
33          return false;
34      }
35  
36      @Override
37      protected boolean isDisposeContextPerClass()
38      {
39          return false;
40      }
41  
42      @Test
43      public void beanType() throws Exception
44      {
45          ObjectFactory prototype = getPrototypeSpringObjectFactory();
46          ObjectFactory singleton = getSingletonSpringObjectFactory();
47  
48          assertProxy(prototype.getObjectClass());
49          assertProxy(singleton.getObjectClass());
50      }
51  
52      @Test
53      public void beanTypeAfterInstantiation() throws Exception
54      {
55          ObjectFactory prototype = getPrototypeSpringObjectFactory();
56          ObjectFactory singleton = getSingletonSpringObjectFactory();
57          prototype.getInstance(muleContext);
58          singleton.getInstance(muleContext);
59  
60          assertProxy(prototype.getObjectClass());
61          assertProxy(singleton.getObjectClass());
62      }
63  
64      @Test
65      public void beanTypeContextStarted() throws Exception
66      {
67          muleContext.start();
68  
69          ObjectFactory prototype = getPrototypeSpringObjectFactory();
70          ObjectFactory singleton = getSingletonSpringObjectFactory();
71  
72          assertProxy(prototype.getObjectClass());
73          assertProxy(singleton.getObjectClass());
74      }
75  
76      @Test
77      public void beanTypeContextStartedAfterInstantiation() throws Exception
78      {
79          muleContext.start();
80  
81          ObjectFactory prototype = getPrototypeSpringObjectFactory();
82          ObjectFactory singleton = getSingletonSpringObjectFactory();
83          prototype.getInstance(muleContext);
84          singleton.getInstance(muleContext);
85  
86          assertProxy(prototype.getObjectClass());
87          assertProxy(singleton.getObjectClass());
88      }
89  
90      private void assertProxy(Class<?> clazz)
91      {
92          assertTrue(clazz.getName().contains("$Proxy"));
93      }
94  
95      private ObjectFactory getPrototypeSpringObjectFactory() throws Exception
96      {
97          return ((JavaComponent) ((SimpleFlowConstruct) getFlowConstruct("flow")).getMessageProcessors()
98              .get(0)).getObjectFactory();
99      }
100 
101     private ObjectFactory getSingletonSpringObjectFactory() throws Exception
102     {
103         return ((JavaComponent) ((SimpleFlowConstruct) getFlowConstruct("flow")).getMessageProcessors()
104             .get(1)).getObjectFactory();
105     }
106 
107 }