001 /**
002 * Copyright 2005-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.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/ecl2.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.ksb.test;
017
018 import org.kuali.rice.core.api.config.property.ConfigContext;
019 import org.kuali.rice.core.api.lifecycle.Lifecycle;
020 import org.kuali.rice.core.api.resourceloader.ResourceLoader;
021 import org.kuali.rice.core.framework.persistence.ojb.BaseOjbConfigurer;
022 import org.kuali.rice.core.framework.resourceloader.SpringResourceLoader;
023 import org.kuali.rice.ksb.api.KsbApiServiceLocator;
024 import org.kuali.rice.ksb.server.TestClient1;
025 import org.kuali.rice.ksb.server.TestClient2;
026 import org.kuali.rice.test.BaselineTestCase;
027
028 import javax.xml.namespace.QName;
029 import java.util.List;
030
031 @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.ROLLBACK)
032 public abstract class KSBTestCase extends BaselineTestCase {
033
034 private static final String KSB_MODULE_NAME = "ksb";
035
036 private TestClient1 testClient1;
037 private TestClient2 testClient2;
038 private ResourceLoader springContextResourceLoader;
039
040 public KSBTestCase() {
041 super(KSB_MODULE_NAME);
042 }
043
044 @Override
045 public void setUp() throws Exception {
046
047 // because we're stopping and starting so many times we need to clear
048 // the core before another set of RLs get put in the core. This is
049 // because we are sometimes using the GRL to fetch a specific servers
050 // spring file out for testing purposes.
051 ConfigContext.destroy();
052
053 // Turn off http keep-alive. Repeated jetty start/stop using same port
054 // results sockets held by client not to close properly, resulting in
055 // cxf test failures.
056 System.setProperty("http.keepAlive", "false");
057
058 super.setUp();
059 if (startClient1() || startClient2()) {
060 KsbApiServiceLocator.getServiceBus().synchronize();
061 }
062 }
063
064 @Override
065 protected List<Lifecycle> getPerTestLifecycles() {
066 List<Lifecycle> lifecycles = super.getSuiteLifecycles();
067 if (this.disableJta()) {
068 System.setProperty(BaseOjbConfigurer.OJB_PROPERTIES_PROP, "RiceNoJtaOJB.properties");
069 this.springContextResourceLoader = new SpringResourceLoader(new QName("ksbtestharness"), "KSBTestHarnessNoJtaSpring.xml", null);
070 } else {
071 this.springContextResourceLoader = new SpringResourceLoader(new QName("ksbtestharness"), "KSBTestHarnessSpring.xml", null);
072 }
073
074 lifecycles.add(this.springContextResourceLoader);
075 if (startClient1()) {
076 this.testClient1 = new TestClient1();
077 lifecycles.add(this.testClient1);
078 }
079 if (startClient2()) {
080 this.testClient2 = new TestClient2();
081 lifecycles.add(this.testClient2);
082 }
083 return lifecycles;
084 }
085
086 public boolean startClient1() {
087 return false;
088 }
089
090 public boolean startClient2() {
091 return false;
092 }
093
094 public TestClient1 getTestClient1() {
095 return this.testClient1;
096 }
097
098 public TestClient2 getTestClient2() {
099 return this.testClient2;
100 }
101
102 public ResourceLoader getSpringContextResourceLoader() {
103 return this.springContextResourceLoader;
104 }
105
106 public void setSpringContextResourceLoader(ResourceLoader testHarnessResourceLoader) {
107 this.springContextResourceLoader = testHarnessResourceLoader;
108 }
109
110 protected boolean disableJta() {
111 return false;
112 }
113 }