1   /*
2    * WebservicesWithHessianAndBurlap - Webservices with Hessian and Burlap
3    * Copyright (C) 2007 Christian Schenk
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or (at your option) any later version.
9    * 
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   * 
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18   */
19  package org.christianschenk.webserviceswithhessianandburlap;
20  
21  import java.net.MalformedURLException;
22  
23  import org.junit.BeforeClass;
24  import org.junit.Ignore;
25  import org.mortbay.jetty.servlet.ServletHolder;
26  import org.mortbay.jetty.testing.ServletTester;
27  
28  import com.caucho.burlap.client.BurlapProxyFactory;
29  import com.caucho.burlap.server.BurlapServlet;
30  import com.caucho.hessian.client.HessianProxyFactory;
31  import com.caucho.hessian.server.HessianServlet;
32  
33  @Ignore
34  public abstract class AbstractServiceTest {
35  
36  	private static ServletTester tester;
37  	protected static String url;
38  
39  	@BeforeClass
40  	public static void setUpClass() throws Exception {
41  		tester = new ServletTester();
42  		url = tester.createSocketConnector(true);
43  		tester.setContextPath("/");
44  		tester.start();
45  	}
46  
47  	@SuppressWarnings("unchecked")
48  	protected <A> A addServlet(final Class<?> servlet, final String path, final Class<?> service, final Class<A> api) throws MalformedURLException {
49  		final ServletHolder servletHolder = tester.addServlet(servlet, path);
50  		servletHolder.setInitParameter("service-class", service.getName());
51  		servletHolder.setInitParameter("api-class", api.getName());
52  		if (url.endsWith(path) == false) url += path;
53  
54  		if (servlet.isAssignableFrom(BurlapServlet.class)) {
55  			return (A) new BurlapProxyFactory().create(api, url);
56  		} else if (servlet.isAssignableFrom(HessianServlet.class)) {
57  			return (A) new HessianProxyFactory().create(api, url);
58  		} else {
59  			throw new RuntimeException("Servlet must be either BurlapServlet or HessianServlet and not " + servlet.getSimpleName());
60  		}
61  	}
62  }