View Javadoc

1   /**
2    * Copyright 2005-2013 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.kuali.rice.core.api.config.property.ConfigContext;
19  import org.kuali.rice.core.api.lifecycle.Lifecycle;
20  import org.kuali.rice.core.api.resourceloader.ResourceLoader;
21  import org.kuali.rice.core.framework.persistence.ojb.BaseOjbConfigurer;
22  import org.kuali.rice.core.framework.resourceloader.SpringResourceLoader;
23  import org.kuali.rice.ksb.api.KsbApiServiceLocator;
24  import org.kuali.rice.ksb.server.TestClient1;
25  import org.kuali.rice.ksb.server.TestClient2;
26  import org.kuali.rice.test.BaselineTestCase;
27  
28  import javax.xml.namespace.QName;
29  import java.util.List;
30  
31  @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.ROLLBACK)
32  public abstract class KSBTestCase extends BaselineTestCase {
33  
34      private static final String KSB_MODULE_NAME = "ksb";
35  
36      private TestClient1 testClient1;
37      private TestClient2 testClient2;
38      private ResourceLoader springContextResourceLoader;
39  
40      public KSBTestCase() {
41  		super(KSB_MODULE_NAME);
42  	}
43  
44      @Override
45      public void setUp() throws Exception {
46  
47      	// because we're stopping and starting so many times we need to clear
48          // the core before another set of RLs get put in the core. This is 
49          // because we are sometimes using the GRL to fetch a specific servers
50          // spring file out for testing purposes.
51          ConfigContext.destroy();
52          
53  		// Turn off http keep-alive. Repeated jetty start/stop using same port
54  		// results sockets held by client not to close properly, resulting in
55          // cxf test failures.
56  		System.setProperty("http.keepAlive", "false");
57  
58          super.setUp();
59          if (startClient1() || startClient2()) {
60              KsbApiServiceLocator.getServiceBus().synchronize();
61          }
62      }
63      
64      @Override
65      protected List<Lifecycle> getPerTestLifecycles() {
66          List<Lifecycle> lifecycles = super.getSuiteLifecycles();
67          if (this.disableJta()) {
68              System.setProperty(BaseOjbConfigurer.OJB_PROPERTIES_PROP, "RiceNoJtaOJB.properties");
69              this.springContextResourceLoader = new SpringResourceLoader(new QName("ksbtestharness"), "KSBTestHarnessNoJtaSpring.xml", null);
70          } else {
71              this.springContextResourceLoader = new SpringResourceLoader(new QName("ksbtestharness"), "KSBTestHarnessSpring.xml", null);
72          }
73  
74          lifecycles.add(this.springContextResourceLoader);
75          if (startClient1()) {
76              this.testClient1 = new TestClient1();
77              lifecycles.add(this.testClient1);
78          }
79          if (startClient2()) {
80              this.testClient2 = new TestClient2();
81              lifecycles.add(this.testClient2);
82          }
83          return lifecycles;
84      }
85  
86      public boolean startClient1() {
87          return false;
88      }
89  
90      public boolean startClient2() {
91          return false;
92      }
93  
94      public TestClient1 getTestClient1() {
95          return this.testClient1;
96      }
97  
98      public TestClient2 getTestClient2() {
99          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 }