View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.ksb.test;
17  
18  import org.junit.Test;
19  import org.junit.runner.RunWith;
20  import org.kuali.rice.core.api.config.property.ConfigContext;
21  import org.kuali.rice.core.api.lifecycle.Lifecycle;
22  import org.kuali.rice.core.api.resourceloader.ResourceLoader;
23  import org.kuali.rice.core.framework.persistence.ojb.BaseOjbConfigurer;
24  import org.kuali.rice.core.framework.resourceloader.SpringResourceLoader;
25  import org.kuali.rice.ksb.api.KsbApiServiceLocator;
26  import org.kuali.rice.ksb.server.TestClient1;
27  import org.kuali.rice.ksb.server.TestClient2;
28  import org.kuali.rice.test.BaselineTestCase;
29  import org.kuali.rice.test.runners.BootstrapTest;
30  import org.kuali.rice.test.runners.LoadTimeWeavableTestRunner;
31  
32  import javax.xml.namespace.QName;
33  import java.util.List;
34  
35  @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.ROLLBACK)
36  @RunWith(LoadTimeWeavableTestRunner.class)
37  @BootstrapTest(KSBTestCase.BootstrapTest.class)
38  public abstract class KSBTestCase extends BaselineTestCase {
39  
40      private static final String KSB_MODULE_NAME = "ksb";
41  
42      private TestClient1 testClient1;
43      private TestClient2 testClient2;
44      private ResourceLoader springContextResourceLoader;
45  
46      public KSBTestCase() {
47  		super(KSB_MODULE_NAME);
48  	}
49  
50      @Override
51      public void setUp() throws Exception {
52  
53      	// because we're stopping and starting so many times we need to clear
54          // the core before another set of RLs get put in the core. This is 
55          // because we are sometimes using the GRL to fetch a specific servers
56          // spring file out for testing purposes.
57          ConfigContext.destroy();
58          
59  		// Turn off http keep-alive. Repeated jetty start/stop using same port
60  		// results sockets held by client not to close properly, resulting in
61          // cxf test failures.
62  		System.setProperty("http.keepAlive", "false");
63  
64          super.setUp();
65          if (startClient1() || startClient2()) {
66              KsbApiServiceLocator.getServiceBus().synchronize();
67          }
68      }
69      
70      @Override
71      protected List<Lifecycle> getPerTestLifecycles() {
72          List<Lifecycle> lifecycles = super.getSuiteLifecycles();
73          if (this.disableJta()) {
74              System.setProperty(BaseOjbConfigurer.OJB_PROPERTIES_PROP, "RiceNoJtaOJB.properties");
75              this.springContextResourceLoader = new SpringResourceLoader(new QName("ksbtestharness"), "KSBTestHarnessNoJtaSpring.xml", null);
76          } else {
77              this.springContextResourceLoader = new SpringResourceLoader(new QName("ksbtestharness"), "KSBTestHarnessSpring.xml", null);
78          }
79  
80          lifecycles.add(this.springContextResourceLoader);
81          if (startClient1()) {
82              this.testClient1 = new TestClient1();
83              lifecycles.add(this.testClient1);
84          }
85          if (startClient2()) {
86              this.testClient2 = new TestClient2();
87              lifecycles.add(this.testClient2);
88          }
89          return lifecycles;
90      }
91  
92      public boolean startClient1() {
93          return false;
94      }
95  
96      public boolean startClient2() {
97          return false;
98      }
99  
100     public TestClient1 getTestClient1() {
101         return this.testClient1;
102     }
103 
104     public TestClient2 getTestClient2() {
105         return this.testClient2;
106     }
107 
108     public ResourceLoader getSpringContextResourceLoader() {
109         return this.springContextResourceLoader;
110     }
111 
112     public void setSpringContextResourceLoader(ResourceLoader testHarnessResourceLoader) {
113         this.springContextResourceLoader = testHarnessResourceLoader;
114     }
115 
116     protected boolean disableJta() {
117         return false;
118     }
119 
120     public static final class BootstrapTest extends KSBTestCase {
121         @Test
122         public void bootstrapTest() {};
123     }
124 
125 }