View Javadoc

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