View Javadoc

1   /*
2    * $Id: AbstractContainerContextTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
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.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  public abstract class AbstractContainerContextTestCase extends AbstractMuleTestCase
22  {
23      public void testContainerContext() throws Exception
24      {
25          UMOContainerContext container = getContainerContext();
26          container.initialise();
27          assertNotNull(container);
28  
29          Object result = null;
30  
31          try
32          {
33              result = container.getComponent(null);
34              fail("Should throw ObjectNotFoundException for null key");
35          }
36          catch (ObjectNotFoundException e)
37          {
38              // expected
39          }
40  
41          try
42          {
43              result = container.getComponent("abcdefg123456!�$%^n");
44              fail("Should throw ObjectNotFoundException for a key that doesn't exist");
45          }
46          catch (ObjectNotFoundException e)
47          {
48              // expected
49          }
50  
51          try
52          {
53              result = container.getComponent(Apple.class);
54              assertNotNull("Component should exist in container", result);
55          }
56          catch (ObjectNotFoundException e)
57          {
58              fail("Component should exist in the container");
59          }
60      }
61  
62      /**
63       * Usage 2: the implementation reference on the descriptor is to a component in
64       * the container
65       * 
66       * @throws Exception
67       */
68      public void testExternalUMOReference() throws Exception
69      {
70          UMOContainerContext container = getContainerContext();
71          assertNotNull(container);
72          container.initialise();
73          UMODescriptor descriptor = getTestDescriptor("fruit Bowl", "org.mule.tck.testmodels.fruit.FruitBowl");
74          descriptor.setContainer("plexus");
75          descriptor.initialise();
76          FruitBowl fruitBowl = (FruitBowl) container.getComponent(getFruitBowlComponentName());
77  
78          assertNotNull(fruitBowl);
79          assertTrue(fruitBowl.hasApple());
80          assertTrue(fruitBowl.hasBanana());
81      }
82  
83      public abstract UMOContainerContext getContainerContext() throws ConfigurationException;
84  
85      protected String getFruitBowlComponentName()
86      {
87          return FruitBowl.class.getName();
88      }
89  }