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;
17  
18  import org.eclipse.jetty.server.Server;
19  import org.kuali.rice.core.api.lifecycle.Lifecycle;
20  import org.springframework.util.Log4jConfigurer;
21  
22  /**
23   * Abstract class to provide convenience methods for starting and stopping a
24   * Jetty Server instance.
25   * 
26   * @author Kuali Rice Team (rice.collab@kuali.org)
27   * @since 0.9
28   */
29  public abstract class BaseTestServer implements Lifecycle {
30  
31      private Server server;
32  
33      protected abstract Server createServer();
34  
35      public Server getServer() {
36          return this.server;
37      }
38  
39      public void start() throws Exception {
40          this.server = createServer();
41          if (this.server == null) {
42          	throw new RuntimeException("Server not successfully created for class: " + getClass().getName());
43          }
44          this.server.start();
45      }
46  
47      public void stop() throws Exception {
48          if (this.server != null) {
49          	this.server.stop();
50          }
51      }
52  
53      public boolean isStarted() {
54          if (this.server == null) {
55          	return false;
56          }
57      	return this.server.isStarted();
58      }
59  }