001 /** 002 * Copyright 2005-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.ksb; 017 018 import org.eclipse.jetty.server.Server; 019 import org.kuali.rice.core.api.lifecycle.Lifecycle; 020 021 /** 022 * Abstract class to provide convenience methods for starting and stopping a 023 * Jetty Server instance. 024 * 025 * @author Kuali Rice Team (rice.collab@kuali.org) 026 * @since 0.9 027 */ 028 public abstract class BaseTestServer implements Lifecycle { 029 030 private Server server; 031 032 protected abstract Server createServer(); 033 034 public Server getServer() { 035 return this.server; 036 } 037 038 public void start() throws Exception { 039 this.server = createServer(); 040 if (this.server == null) { 041 throw new RuntimeException("Server not successfully created for class: " + getClass().getName()); 042 } 043 this.server.start(); 044 } 045 046 public void stop() throws Exception { 047 if (this.server != null) { 048 this.server.stop(); 049 } 050 } 051 052 public boolean isStarted() { 053 if (this.server == null) { 054 return false; 055 } 056 return this.server.isStarted(); 057 } 058 }