KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > tck > model > AbstractContainerContextTestCase


1 /*
2  * $Id: AbstractContainerContextTestCase.java 3798 2006-11-04 04:07:14Z aperepel $
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 MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.tck.model;
12
13 import org.mule.config.ConfigurationException;
14 import org.mule.tck.AbstractMuleTestCase;
15 import org.mule.tck.testmodels.fruit.Apple;
16 import org.mule.tck.testmodels.fruit.FruitBowl;
17 import org.mule.umo.UMODescriptor;
18 import org.mule.umo.manager.ObjectNotFoundException;
19 import org.mule.umo.manager.UMOContainerContext;
20
21 /**
22  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
23  * @version $Revision: 3798 $
24  */

25 public abstract class AbstractContainerContextTestCase extends AbstractMuleTestCase
26 {
27     public void testContainerContext() throws Exception JavaDoc
28     {
29         UMOContainerContext container = getContainerContext();
30         container.initialise();
31         assertNotNull(container);
32
33         Object JavaDoc result = null;
34
35         try
36         {
37             result = container.getComponent(null);
38             fail("Should throw ObjectNotFoundException for null key");
39         }
40         catch (ObjectNotFoundException e)
41         {
42             // expected
43
}
44
45         try
46         {
47             result = container.getComponent("abcdefg123456!£$%^n");
48             fail("Should throw ObjectNotFoundException for a key that doesn't exist");
49         }
50         catch (ObjectNotFoundException e)
51         {
52             // expected
53
}
54
55         try
56         {
57             result = container.getComponent(Apple.class);
58             assertNotNull("Component should exist in container", result);
59         }
60         catch (ObjectNotFoundException e)
61         {
62             fail("Component should exist in the container");
63         }
64     }
65
66     /**
67      * Usage 2: the implementation reference on the descriptor is to a component in
68      * the container
69      *
70      * @throws Exception
71      */

72     public void testExternalUMOReference() throws Exception JavaDoc
73     {
74         UMOContainerContext container = getContainerContext();
75         assertNotNull(container);
76         container.initialise();
77         UMODescriptor descriptor = getTestDescriptor("fruit Bowl", "org.mule.tck.testmodels.fruit.FruitBowl");
78         descriptor.setContainer("plexus");
79         descriptor.initialise();
80         FruitBowl fruitBowl = (FruitBowl)container.getComponent(descriptor.getImplementation());
81
82         assertNotNull(fruitBowl);
83         assertTrue(fruitBowl.hasApple());
84         assertTrue(fruitBowl.hasBanana());
85     }
86
87     public abstract UMOContainerContext getContainerContext() throws ConfigurationException;
88
89 }
90
Popular Tags