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.components.test;
18:
19: import java.util.Properties;
20:
21: import org.apache.jetspeed.engine.JetspeedEngineConstants;
22: import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
23: import org.springframework.context.ApplicationContext;
24: import org.springframework.context.support.ClassPathXmlApplicationContext;
25:
26: import junit.framework.TestCase;
27:
28: /**
29: * <p>
30: * AbstractSpringTestCase
31: * </p>
32: * <p>
33: *
34: * </p>
35: *
36: * @author <a href="mailto:weaver@apache.org">Scott T. Weaver </a>
37: * @version $Id: AbstractSpringTestCase.java 598474 2007-11-27 00:37:16Z ate $
38: *
39: */
40: public abstract class AbstractSpringTestCase extends TestCase {
41: /**
42: * Provides access to the Spring ApplicationContext.
43: */
44: protected ClassPathXmlApplicationContext ctx;
45:
46: /**
47: * setup Spring context as part of test setup
48: */
49: protected void setUp() throws Exception {
50: super .setUp();
51: if (ctx == null) {
52: String[] bootConfigurations = getBootConfigurations();
53: if (bootConfigurations != null) {
54: ApplicationContext bootContext = new ClassPathXmlApplicationContext(
55: bootConfigurations, true);
56: ctx = new ClassPathXmlApplicationContext(
57: getConfigurations(), false, bootContext);
58: } else {
59: ctx = new ClassPathXmlApplicationContext(
60: getConfigurations(), false);
61: }
62: PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
63: Properties p = getPostProcessProperties();
64: p.setProperty(JetspeedEngineConstants.APPLICATION_ROOT_KEY,
65: "../../src/webapp");
66: ppc.setProperties(p);
67: ctx.addBeanFactoryPostProcessor(ppc);
68: ctx.refresh();
69: }
70: }
71:
72: /**
73: * close Spring context as part of test teardown
74: */
75: protected void tearDown() throws Exception {
76: super .tearDown();
77: if (ctx != null) {
78: ctx.close();
79: }
80: }
81:
82: /**
83: * required specification of spring configurations
84: */
85: protected abstract String[] getConfigurations();
86:
87: /**
88: * optional specification of boot spring configurations
89: */
90: protected String[] getBootConfigurations() {
91: return null;
92: }
93:
94: protected Properties getPostProcessProperties() {
95: return new Properties();
96: }
97: }
|