01: /**
02: *
03: * Licensed to the Apache Software Foundation (ASF) under one or more
04: * contributor license agreements. See the NOTICE file distributed with
05: * this work for additional information regarding copyright ownership.
06: * The ASF licenses this file to You under the Apache License, Version 2.0
07: * (the "License"); you may not use this file except in compliance with
08: * the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */package org.apache.openejb.test.servlet;
18:
19: import java.io.IOException;
20: import java.io.PrintStream;
21: import java.lang.reflect.Method;
22: import javax.servlet.http.HttpServlet;
23: import javax.servlet.http.HttpServletRequest;
24: import javax.servlet.http.HttpServletResponse;
25: import javax.servlet.ServletException;
26: import javax.servlet.ServletOutputStream;
27: import javax.ejb.EJB;
28:
29: import org.apache.openejb.test.stateless.BasicStatelessBusinessLocal;
30: import junit.framework.Assert;
31:
32: public class EjbServlet extends HttpServlet {
33: @EJB
34: private BasicStatelessBusinessLocal statelessBusinessLocal;
35:
36: protected void service(HttpServletRequest request,
37: HttpServletResponse response) throws ServletException,
38: IOException {
39: response.setContentType("text/plain");
40: ServletOutputStream out = response.getOutputStream();
41: PrintStream printStream = new PrintStream(out);
42:
43: String methodName = request.getParameter("method");
44: if (methodName == null) {
45: testAll(printStream);
46: } else {
47: try {
48: Method method = getClass().getMethod(methodName);
49: method.invoke(this );
50: } catch (Throwable e) {
51: // response.setStatus(580);
52: printStream.println("FAILED");
53: e.printStackTrace(printStream);
54: }
55: }
56: printStream.flush();
57: }
58:
59: public void testAll(PrintStream printStream) {
60: for (Method method : EjbServlet.class.getMethods()) {
61: if (!method.getName().startsWith("invoke"))
62: continue;
63:
64: try {
65: method.invoke(this );
66: printStream.println(method.getName() + " PASSED");
67: } catch (Throwable e) {
68: printStream.println(method.getName() + " FAILED");
69: e.printStackTrace(printStream);
70: printStream.flush();
71: }
72: printStream.println();
73: }
74: }
75:
76: public void invokeBusinessMethod() {
77: Assert.assertEquals("oof", statelessBusinessLocal
78: .businessMethod("foo"));
79: }
80: }
|