1   /*
2    * $Id: AbstractObjectFactoryTestCase.java 11376 2008-03-16 17:44:10Z dfeist $
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.object;
12  
13  import org.mule.api.lifecycle.InitialisationException;
14  import org.mule.api.object.ObjectFactory;
15  import org.mule.object.AbstractObjectFactory;
16  import org.mule.tck.AbstractMuleTestCase;
17  
18  public abstract class AbstractObjectFactoryTestCase extends AbstractMuleTestCase
19  {
20  
21      public void testInitialisationFailure() throws Exception
22      {
23          AbstractObjectFactory factory = (AbstractObjectFactory) getObjectFactory();
24  
25          try
26          {
27              factory.initialise();
28              fail("expected InitialisationException");
29          }
30          catch (InitialisationException iex)
31          {
32              // OK
33          }
34  
35          try
36          {
37              factory.getInstance();
38              fail("expected InitialisationException");
39          }
40          catch (InitialisationException iex)
41          {
42              // OK
43          }
44      }
45  
46      public void testInitialiseWithClass() throws Exception
47      {
48          AbstractObjectFactory factory = (AbstractObjectFactory) getObjectFactory();
49          factory.setObjectClass(Object.class);
50  
51          try
52          {
53              factory.initialise();
54          }
55          catch (InitialisationException iex)
56          {
57              fail(iex.getDetailedMessage());
58          }
59  
60          assertNotNull(factory.getInstance());
61      }
62  
63      public void testInitialiseWithClassName() throws Exception
64      {
65          AbstractObjectFactory factory = (AbstractObjectFactory) getObjectFactory();
66          factory.setObjectClassName(Object.class.getName());
67  
68          try
69          {
70              factory.initialise();
71          }
72          catch (InitialisationException iex)
73          {
74              fail(iex.getDetailedMessage());
75          }
76  
77          assertNotNull(factory.getInstance());
78      }
79  
80      public void testDispose() throws Exception
81      {
82          AbstractObjectFactory factory = (AbstractObjectFactory) getObjectFactory();
83          factory.setObjectClass(Object.class);
84  
85          factory.initialise();
86          factory.dispose();
87  
88          assertNull(factory.getObjectClass());
89  
90          try
91          {
92              factory.getInstance();
93              fail("expected InitialisationException");
94          }
95          catch (InitialisationException iex)
96          {
97              // OK
98          }
99      }
100 
101     public abstract ObjectFactory getObjectFactory();
102 
103     public abstract void testGetObjectClass() throws Exception;
104 
105     public abstract void testGet() throws Exception;
106 
107 }