001: /*
002: * Copyright 2007 The Kuali Foundation
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.rice.testharness;
017:
018: import java.util.ArrayList;
019: import java.util.Arrays;
020: import java.util.List;
021:
022: import org.kuali.rice.config.spring.ConfigFactoryBean;
023: import org.kuali.rice.lifecycle.Lifecycle;
024: import org.kuali.rice.test.RiceTestCase;
025: import org.kuali.rice.test.lifecycles.JettyServerLifecycle;
026: import org.kuali.rice.test.lifecycles.KEWXmlDataLoaderLifecycle;
027: import org.kuali.rice.test.lifecycles.SQLDataLoaderLifecycle;
028:
029: /**
030: * Default test base for a full KNS enabled unit test.
031: *
032: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
033: */
034: public class KNSTestCase extends RiceTestCase {
035:
036: private String contextName = "/SampleRiceClient";
037: private String relativeWebappRoot = "/src/test/webapp";
038: private String sqlFilename = "classpath:DefaultTestData.sql";
039: private String sqlDelimiter = ";";
040: private String xmlFilename = "classpath:DefaultTestData.xml";
041: private String testConfigFilename = "classpath:META-INF/sample-app-test-config.xml";
042:
043: @Override
044: public List<Lifecycle> getPerTestLifecycles() {
045: return new ArrayList<Lifecycle>();
046: }
047:
048: @Override
049: protected List<Lifecycle> getSuiteLifecycles() {
050: List<Lifecycle> lifeCycles = super .getPerTestLifecycles();
051: lifeCycles.add(new Lifecycle() {
052:
053: boolean started = false;
054:
055: public boolean isStarted() {
056: return this .started;
057: }
058:
059: public void start() throws Exception {
060: ConfigFactoryBean.CONFIG_OVERRIDE_LOCATION = getTestConfigFilename();
061: new SQLDataLoaderLifecycle(getSqlFilename(),
062: getSqlDelimiter()).start();
063: new JettyServerLifecycle(getPort(), getContextName(),
064: getRelativeWebappRoot()).start();
065: new KEWXmlDataLoaderLifecycle(getXmlFilename()).start();
066:
067: this .started = true;
068: }
069:
070: public void stop() throws Exception {
071: this .started = false;
072: }
073:
074: });
075: return lifeCycles;
076: }
077:
078: @Override
079: protected List<String> getConfigLocations() {
080: return Arrays.asList(new String[] { getTestConfigFilename() });
081: }
082:
083: @Override
084: protected String getDerbySQLFileLocation() {
085: return "classpath:db/derby/kns.sql";
086: }
087:
088: @Override
089: protected String getModuleName() {
090: return "kns";
091: }
092:
093: protected String getTestConfigFilename() {
094: return testConfigFilename;
095: }
096:
097: protected void setTestConfigFilename(String testConfigFilename) {
098: this .testConfigFilename = testConfigFilename;
099: }
100:
101: protected String getContextName() {
102: return contextName;
103: }
104:
105: protected void setContextName(String contextName) {
106: this .contextName = contextName;
107: }
108:
109: protected int getPort() {
110: return HtmlUnitUtil.getPort();
111: }
112:
113: protected String getRelativeWebappRoot() {
114: return relativeWebappRoot;
115: }
116:
117: protected void setRelativeWebappRoot(String relativeWebappRoot) {
118: this .relativeWebappRoot = relativeWebappRoot;
119: }
120:
121: protected String getSqlFilename() {
122: return sqlFilename;
123: }
124:
125: protected void setSqlFilename(String sqlFilename) {
126: this .sqlFilename = sqlFilename;
127: }
128:
129: protected String getXmlFilename() {
130: return xmlFilename;
131: }
132:
133: protected void setXmlFilename(String xmlFilename) {
134: this .xmlFilename = xmlFilename;
135: }
136:
137: protected String getSqlDelimiter() {
138: return sqlDelimiter;
139: }
140:
141: protected void setSqlDelimiter(String sqlDelimiter) {
142: this.sqlDelimiter = sqlDelimiter;
143: }
144:
145: }
|