View Javadoc

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