View Javadoc

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