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