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