View Javadoc

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