1   /*
2    * $Id: SpringContainerContextTestCase.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.extras.spring;
12  
13  import org.mule.tck.model.AbstractContainerContextTestCase;
14  import org.mule.tck.testmodels.fruit.FruitBowl;
15  import org.mule.umo.manager.ObjectNotFoundException;
16  import org.mule.umo.manager.UMOContainerContext;
17  
18  /**
19   * Tests the Spring container.
20   */
21  public class SpringContainerContextTestCase extends AbstractContainerContextTestCase
22  {
23      SpringContainerContext context;
24  
25      public UMOContainerContext getContainerContext()
26      {
27          return context;
28      }
29  
30      protected void doSetUp() throws Exception
31      {
32          context = new SpringContainerContext();
33          context.setConfigResources(getConfigResources());
34      }
35  
36      public String getConfigResources()
37      {
38          return "test-application-context.xml";
39      }
40  
41      public void testContainerContext() throws Exception
42      {
43          UMOContainerContext container = getContainerContext();
44          container.initialise();
45          assertNotNull(container);
46  
47          try
48          {
49              container.getComponent(null);
50              fail("Should throw ObjectNotFoundException for null key");
51          }
52          catch (ObjectNotFoundException e)
53          {
54              // expected
55          }
56  
57          try
58          {
59              container.getComponent("abcdefg123456!�$%^n");
60              fail("Should throw ObjectNotFoundException for a key that doesn't exist");
61          }
62          catch (ObjectNotFoundException e)
63          {
64              // expected
65          }
66  
67          try
68          {
69              Object result = container.getComponent("apple");
70              assertNotNull("Component should exist in container", result);
71          }
72          catch (ObjectNotFoundException e)
73          {
74              fail("Component should exist in the container");
75          }
76      }
77  
78      protected String getFruitBowlComponentName()
79      {
80          return "fruitBowl";
81      }
82  }