1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 * 9 * http://www.apache.org/licenses/LICENSE-2.010 * 11 * Unless required by applicable law or agreed to in writing, software12 * 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 and15 * limitations under the License.16 */17packageorg.apache.jetspeed.components.test;
1819import java.util.Properties;
2021import org.apache.jetspeed.engine.JetspeedEngineConstants;
22import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
23import org.springframework.context.ApplicationContext;
24import org.springframework.context.support.ClassPathXmlApplicationContext;
2526import junit.framework.TestCase;
2728/***29 * <p>30 * AbstractSpringTestCase31 * </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 */40publicabstractclassAbstractSpringTestCaseextends TestCase
41 {
42/***43 * Provides access to the Spring ApplicationContext.44 */45protected ClassPathXmlApplicationContext ctx;
4647/***48 * setup Spring context as part of test setup49 */50protectedvoid setUp() throws Exception
51 {
52super.setUp();
53if (ctx == null)
54 {
55 String [] bootConfigurations = getBootConfigurations();
56if (bootConfigurations != null)
57 {
58 ApplicationContext bootContext = new ClassPathXmlApplicationContext(bootConfigurations, true);
59 ctx = new ClassPathXmlApplicationContext(getConfigurations(), false, bootContext);
60 }
61else62 {
63 ctx = new ClassPathXmlApplicationContext(getConfigurations(), false);
64 }
65 PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
66 Properties p = getPostProcessProperties();
67 p.setProperty(JetspeedEngineConstants.APPLICATION_ROOT_KEY, "../../src/webapp");
68 ppc.setProperties(p);
69 ctx.addBeanFactoryPostProcessor(ppc);
70 ctx.refresh();
71 }
72 }
7374/***75 * close Spring context as part of test teardown76 */77protectedvoid tearDown() throws Exception
78 {
79super.tearDown();
80if (ctx != null)
81 {
82 ctx.close();
83 }
84 }
8586/***87 * required specification of spring configurations88 */89protectedabstract String[] getConfigurations();
9091/***92 * optional specification of boot spring configurations93 */94protected String[] getBootConfigurations()
95 {
96returnnull;
97 }
9899protected Properties getPostProcessProperties()
100 {
101returnnew Properties();
102 }
103 }