01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: public static final String ENGINE_ATTR = "Engine";
37:
38: protected JetspeedTestJNDIComponent jndiDS;
39:
40: public SpringEngineHelper(Map context) {
41: super (context);
42: }
43:
44: private Engine engine;
45:
46: public void setUp() throws Exception {
47: jndiDS = new JetspeedTestJNDIComponent();
48: jndiDS.setup();
49:
50: PropertiesConfiguration config = new PropertiesConfiguration();
51: config.load(new FileInputStream(
52: PortalTestConstants.JETSPEED_PROPERTIES_PATH));
53:
54: String appRoot = PortalTestConstants.JETSPEED_APPLICATION_ROOT;
55:
56: MockServletConfig servletConfig = new MockServletConfig();
57: ResourceLocatingServletContext servletContent = new ResourceLocatingServletContext(
58: new File(appRoot));
59: servletConfig.setServletContext(servletContent);
60: ServletConfigFactoryBean.setServletConfig(servletConfig);
61:
62: SpringComponentManager scm = new SpringComponentManager(
63: new String[] { "/WEB-INF/assembly/boot/datasource.xml" },
64: new String[] { "/WEB-INF/assembly/*.xml" },
65: servletContent, appRoot);
66:
67: engine = new JetspeedEngine(config, appRoot, servletConfig, scm);
68: Jetspeed.setEngine(engine);
69: engine.start();
70: getContext().put(ENGINE_ATTR, engine);
71: }
72:
73: public void tearDown() throws Exception {
74: engine.shutdown();
75: jndiDS.tearDown();
76: }
77: }
|