1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.jetspeed.engine;
18  
19  import java.util.HashMap;
20  
21  import junit.framework.TestCase;
22  
23  import org.apache.jetspeed.components.ComponentManagement;
24  import org.apache.jetspeed.testhelpers.SpringEngineHelper;
25  
26  /***
27   * <p>
28   * AbstractEngineTest
29   * </p>
30   * 
31   * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
32   * @version $Id: AbstractEngineTest.java 516448 2007-03-09 16:25:47Z ate $
33   */
34  public abstract class AbstractEngineTest extends TestCase
35  {
36  
37      /***
38       * 
39       */
40      public AbstractEngineTest()
41      {
42          super();
43      }
44  
45      /***
46       * @param arg0
47       */
48      public AbstractEngineTest(String arg0)
49      {
50          super(arg0);
51      }
52  
53      protected Engine engine;
54  
55      protected Object[] keysToCheck;
56  
57      private SpringEngineHelper engineHelper;
58  
59      public void testEngine() throws Exception
60      {
61          assertNotNull(engine.getComponentManager());
62          assertNotNull(engine.getComponentManager().getRootContainer());
63          if (keysToCheck != null)
64          {
65              verifyComponents(keysToCheck);
66          }
67      }
68  
69      protected void setUp() throws Exception
70      {
71         HashMap context = new HashMap();
72         engineHelper = new SpringEngineHelper(context);
73         engineHelper.setUp();
74         engine = (Engine) context.get(SpringEngineHelper.ENGINE_ATTR);
75      }
76  
77      protected void tearDown() throws Exception
78      {
79          engineHelper.tearDown();
80          super.tearDown();        
81      }
82  
83      protected void verifyComponents(Object[] keys)
84      {
85          ComponentManagement cm = engine.getComponentManager();
86          for (int i = 0; i < keys.length; i++)
87          {
88              assertNotNull("Could not get component insatance " + keys[i], cm.getComponent(keys[i]));
89              System.out.println("Load componenet " + cm.getComponent(keys[i]).getClass() + " for key " + keys[i]);
90          }
91      }
92  
93  }