001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: TestEngineWebservicesHessian.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.engine;
009:
010: import com.caucho.hessian.client.HessianProxyFactory;
011: import com.meterware.httpunit.GetMethodWebRequest;
012: import com.meterware.httpunit.WebConversation;
013: import com.meterware.httpunit.WebForm;
014: import com.meterware.httpunit.WebRequest;
015: import com.meterware.httpunit.WebResponse;
016: import com.uwyn.rife.TestCaseServerside;
017: import com.uwyn.rife.engine.exceptions.InputUnknownException;
018: import com.uwyn.rife.engine.testwebservices.webservices.hessian.BasicApi;
019: import com.uwyn.rife.engine.testwebservices.webservices.hessian.EchoApi;
020: import com.uwyn.rife.engine.testwebservices.webservices.hessian.HessianElementServiceApi;
021: import com.uwyn.rife.tools.ExceptionUtils;
022: import java.util.logging.Level;
023: import java.util.logging.Logger;
024:
025: public class TestEngineWebservicesHessian extends TestCaseServerside {
026: public TestEngineWebservicesHessian(int siteType, String name) {
027: super (siteType, name);
028: }
029:
030: public void testBasic() throws Exception {
031: setupSite("site/webservices_hessian.xml");
032:
033: String url = "http://localhost:8181/basic";
034:
035: HessianProxyFactory factory = new HessianProxyFactory();
036: BasicApi basic = (BasicApi) factory.create(BasicApi.class, url);
037:
038: assertEquals("Hello, world", basic.hello());
039: }
040:
041: public void testEcho() throws Exception {
042: setupSite("site/webservices_hessian.xml");
043:
044: String url = "http://localhost:8181/echo";
045:
046: HessianProxyFactory factory = new HessianProxyFactory();
047: EchoApi echo = (EchoApi) factory.create(EchoApi.class, url);
048:
049: assertEquals("I got : 'Yooohoooo!'", echo.echo("Yooohoooo!"));
050: }
051:
052: public void testEchoAuth() throws Exception {
053: setupSite("site/webservices_hessian.xml");
054:
055: HessianProxyFactory factory = new HessianProxyFactory();
056:
057: String url_noauth = "http://localhost:8181/echoauth";
058: EchoApi echo_noauth = (EchoApi) factory.create(EchoApi.class,
059: url_noauth);
060: try {
061: echo_noauth.echo("Yooohoooo!");
062: } catch (Throwable e) {
063: assertTrue(
064: ExceptionUtils.getExceptionStackTrace(e),
065: e instanceof com.caucho.hessian.client.HessianRuntimeException);
066: }
067:
068: String url_auth = "http://localhost:8181/echoauth?login=gbevin&password=yeolpass&submission=credentials";
069: EchoApi echo_auth = (EchoApi) factory.create(EchoApi.class,
070: url_auth);
071: assertEquals("I got : 'Yooohoooo!'", echo_auth
072: .echo("Yooohoooo!"));
073:
074: WebConversation conversation = new WebConversation();
075: WebRequest request = null;
076: WebResponse response = null;
077: WebForm form = null;
078: String auth_id;
079: request = new GetMethodWebRequest("http://localhost:8181/auth");
080: response = conversation.getResponse(request);
081: form = response.getForms()[0];
082: form.setParameter("login", "guest");
083: form.setParameter("password", "guestpass");
084: response = form.submit();
085: assertEquals(0, response.getForms().length);
086: auth_id = response.getTitle();
087:
088: url_auth = "http://localhost:8181/echoauth?authid=" + auth_id;
089: echo_auth = (EchoApi) factory.create(EchoApi.class, url_auth);
090: assertEquals("I got : 'Yooohoooo!'", echo_auth
091: .echo("Yooohoooo!"));
092: }
093:
094: public void testElementService() throws Exception {
095: setupSite("site/webservices_hessian.xml");
096:
097: String url = "http://localhost:8181/elementservice?input1=value1&input2=value2";
098:
099: HessianProxyFactory factory = new HessianProxyFactory();
100: HessianElementServiceApi service = (HessianElementServiceApi) factory
101: .create(HessianElementServiceApi.class, url);
102:
103: assertEquals("value1", service.getElementInput("input1"));
104: assertEquals("value2", service.getElementInput("input2"));
105: assertNull(service.getElementInput("input3"));
106:
107: Level orig_level = Logger.getLogger(
108: "com.caucho.hessian.server.HessianSkeleton").getLevel();
109: try {
110: Logger.getLogger(
111: "com.caucho.hessian.server.HessianSkeleton")
112: .setLevel(Level.OFF);
113: service.getElementInput("unknown");
114: fail();
115: } catch (InputUnknownException e) {
116: assertEquals(e.getInputName(), "unknown");
117: } finally {
118: Logger.getLogger(
119: "com.caucho.hessian.server.HessianSkeleton")
120: .setLevel(orig_level);
121: }
122: }
123: }
|