01: /******************************************************************************
02: * JBoss, a division of Red Hat *
03: * Copyright 2006, Red Hat Middleware, LLC, and individual *
04: * contributors as indicated by the @authors tag. See the *
05: * copyright.txt in the distribution for a full listing of *
06: * individual contributors. *
07: * *
08: * This is free software; you can redistribute it and/or modify it *
09: * under the terms of the GNU Lesser General Public License as *
10: * published by the Free Software Foundation; either version 2.1 of *
11: * the License, or (at your option) any later version. *
12: * *
13: * This software is distributed in the hope that it will be useful, *
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16: * Lesser General Public License for more details. *
17: * *
18: * You should have received a copy of the GNU Lesser General Public *
19: * License along with this software; if not, write to the Free *
20: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
21: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
22: ******************************************************************************/package org.jboss.portal.test.cms;
23:
24: import junit.framework.TestCase;
25: import junit.framework.TestSuite;
26: import org.jboss.portal.test.framework.embedded.DataSourceSupport;
27: import org.jboss.portal.test.framework.embedded.HibernateSupport;
28: import org.jboss.portal.test.framework.junit.JUnitAdapter;
29: import org.jboss.portal.test.framework.junit.POJOJUnitTest;
30: import org.jboss.portal.test.framework.mc.TestRuntimeContext;
31:
32: import java.net.URL;
33: import java.util.HashMap;
34: import java.util.Map;
35:
36: /**
37: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
38: * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
39: * @version $Revision: 7954 $
40: */
41: public abstract class AbstractCMSTestCase extends TestCase {
42:
43: /** . */
44: protected DataSourceSupport.Config dataSourceConfigParameter;
45:
46: /** . */
47: protected TestRuntimeContext runtimeContext;
48:
49: /**
50: *
51: *
52: */
53: protected String configuration = "org/jboss/portal/cms/jboss-beans.xml";
54:
55: public AbstractCMSTestCase() {
56: }
57:
58: public DataSourceSupport.Config getDataSourceConfigParameter() {
59: return dataSourceConfigParameter;
60: }
61:
62: public void setDataSourceConfigParameter(
63: DataSourceSupport.Config dataSourceConfigParameter) {
64: this .dataSourceConfigParameter = dataSourceConfigParameter;
65: }
66:
67: public void setUp() throws Exception {
68: //Bootstrapping low-level services needed by PortalCMS
69: runtimeContext = new TestRuntimeContext(this .configuration);
70: runtimeContext.addBean("DataSourceConfig",
71: dataSourceConfigParameter);
72: runtimeContext.addBean("HibernateConfig", HibernateSupport
73: .getConfig(dataSourceConfigParameter.getName()));
74:
75: //Start the context
76: runtimeContext.start();
77: }
78:
79: public void tearDown() throws Exception {
80: runtimeContext.stop();
81: }
82:
83: public static TestSuite createTestSuite(Class clazz)
84: throws Exception {
85: URL configsURL = Thread.currentThread().getContextClassLoader()
86: .getResource("datasources.xml");
87: Map parameterMap = new HashMap();
88: parameterMap.put("DataSourceConfig", DataSourceSupport.Config
89: .fromXML2(configsURL));
90: POJOJUnitTest abc = new POJOJUnitTest(clazz);
91: JUnitAdapter adapter = new JUnitAdapter(abc, parameterMap);
92: TestSuite suite = new TestSuite();
93: suite.addTest(adapter);
94: return suite;
95: }
96: }
|