View Javadoc

1   /*
2    * $Id: ObjectFactoryTestCase.java 22414 2011-07-14 13:24:46Z 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.test.components;
11  
12  import org.mule.api.registry.Registry;
13  import org.mule.tck.junit4.FunctionalTestCase;
14  import org.mule.tck.services.UniqueComponent;
15  
16  import org.junit.Test;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertFalse;
20  import static org.junit.Assert.assertNotNull;
21  
22  public class ObjectFactoryTestCase extends FunctionalTestCase
23  {
24  
25      @Override
26      protected String getConfigResources()
27      {
28          return "org/mule/test/components/object-factory-functional-test.xml";
29      }
30  
31      @Test
32      public void testDefaultScope() throws Exception
33      {
34          Registry registry = muleContext.getRegistry();
35          
36          Object bean1 = registry.lookupObject("default");
37          assertNotNull(bean1);
38          String id1 = ((UniqueComponent) bean1).getId();
39          
40          Object bean2 = registry.lookupObject("default");
41          assertNotNull(bean2);
42          String id2 = ((UniqueComponent) bean2).getId();
43          
44          assertEquals(id1, id2);
45      }
46  
47      @Test
48      public void testSingletonScope() throws Exception
49      {
50          Registry registry = muleContext.getRegistry();
51          
52          Object bean1 = registry.lookupObject("singleton");
53          assertNotNull(bean1);
54          String id1 = ((UniqueComponent) bean1).getId();
55          
56          Object bean2 = registry.lookupObject("singleton");
57          assertNotNull(bean2);
58          String id2 = ((UniqueComponent) bean2).getId();
59          
60          assertEquals(id1, id2);
61      }
62  
63      @Test
64      public void testPrototypeScope() throws Exception
65      {
66          Registry registry = muleContext.getRegistry();
67          
68          Object bean1 = registry.lookupObject("prototype");
69          assertNotNull(bean1);
70          String id1 = ((UniqueComponent) bean1).getId();
71          
72          Object bean2 = registry.lookupObject("prototype");
73          assertNotNull(bean2);
74          String id2 = ((UniqueComponent) bean2).getId();
75          
76          assertFalse("IDs " + id1 + " and " + id2 + " should be different", id1.equals(id2));
77      }
78  
79  }
80  
81