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.testhelpers;
18  
19  import java.io.File;
20  import java.io.FileInputStream;
21  import java.util.Map;
22  
23  import org.apache.commons.configuration.PropertiesConfiguration;
24  import org.apache.jetspeed.Jetspeed;
25  import org.apache.jetspeed.PortalTestConstants;
26  import org.apache.jetspeed.components.SpringComponentManager;
27  import org.apache.jetspeed.components.factorybeans.ServletConfigFactoryBean;
28  import org.apache.jetspeed.components.jndi.JetspeedTestJNDIComponent;
29  import org.apache.jetspeed.engine.Engine;
30  import org.apache.jetspeed.engine.JetspeedEngine;
31  import org.apache.jetspeed.mocks.ResourceLocatingServletContext;
32  
33  import com.mockrunner.mock.web.MockServletConfig;
34  
35  public class SpringEngineHelper extends AbstractTestHelper
36  {
37      public static final String ENGINE_ATTR = "Engine";     
38      
39      protected JetspeedTestJNDIComponent jndiDS;
40      
41      public SpringEngineHelper(Map context)
42      {
43          super(context);
44      }
45      
46      private Engine engine;
47  
48      public void setUp() throws Exception
49      {
50          jndiDS = new JetspeedTestJNDIComponent();
51          jndiDS.setup();
52  
53          PropertiesConfiguration config = new PropertiesConfiguration();
54          config.load(new FileInputStream(PortalTestConstants.JETSPEED_PROPERTIES_PATH));
55                  
56          String appRoot = PortalTestConstants.JETSPEED_APPLICATION_ROOT;
57          
58          MockServletConfig servletConfig = new MockServletConfig();        
59          ResourceLocatingServletContext servletContent = new ResourceLocatingServletContext(new File(appRoot));        
60          servletConfig.setServletContext(servletContent);
61          ServletConfigFactoryBean.setServletConfig(servletConfig);
62          
63          SpringComponentManager scm = new SpringComponentManager(new String[] {"/WEB-INF/assembly/boot/datasource.xml"}, new String[] {"/WEB-INF/assembly/*.xml"}, servletContent, appRoot );
64         
65          engine = new JetspeedEngine(config, appRoot, servletConfig, scm );
66          Jetspeed.setEngine(engine);
67          engine.start();
68          getContext().put(ENGINE_ATTR, engine );
69      }
70  
71      public void tearDown() throws Exception
72      {
73          engine.shutdown();
74          jndiDS.tearDown();
75      }
76  }