1   /*
2    * Copyright (c) 2003 by Atlassian Software Systems Pty. Ltd.
3    * All rights reserved.
4    */
5   package com.atlassian.spring.container;
6   
7   import junit.framework.TestCase;
8   
9   /**
10   * @author Ross Mason
11   *
12   * Tests implementations of ContainerContext
13   */
14  public abstract class AbstractContainerContextTest extends TestCase
15  {
16      public void testContainer() throws Exception
17      {
18          ContainerContext container = getContainer();
19  
20          try
21          {
22              container.getComponent(null);
23              fail("Should get an exception with a null key");
24          }
25          catch (ComponentNotFoundException e)
26          {
27              // expected
28          }
29  
30          try
31          {
32              container.getComponent(getInvalidKey());
33              fail("Should get an exception with a invalid key");
34          }
35          catch (ComponentNotFoundException e1)
36          {
37              // expected
38          }
39  
40          assertNotNull(container.getComponent(getValidKey()));
41  
42          Object dupKey = getDuplicateKey();
43          //Only do this test if the container supports Duplicate keys
44          if(dupKey!=null)
45          {
46              try
47              {
48                  container.getComponent(dupKey);
49                  fail("Should get an exception with a duplicate key");
50              }
51              catch (ComponentNotFoundException e)
52              {
53                  // expected
54              }
55          }
56  
57          //Just call to make sure it doesn't fail.  How do we test if further??
58          container.refresh();
59      }
60  
61      public abstract ContainerContext getContainer() throws Exception;
62  
63      public abstract Object getValidKey();
64  
65      public Object getInvalidKey()
66      {
67          return "12345676890Invalid";
68      }
69  
70      public abstract Object getDuplicateKey();
71  
72  }