01: package org.jboss.seam.remoting.gwt;
02:
03: /*
04: * Copyright 2005 JBoss Inc
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * 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: */
18:
19: import junit.framework.TestCase;
20:
21: import org.jboss.seam.remoting.gwt.GWTToSeamAdapter.ReturnedObject;
22:
23: public class GWTToSeamAdapterTest extends TestCase {
24:
25: public void testAdapter() throws Exception {
26: MyServiceThingie service = new SubServiceThingie();
27: StubbedAdapter adapter = new StubbedAdapter(service);
28:
29: int startSize = StubbedAdapter.METHOD_CACHE.size();
30:
31: ReturnedObject obj = adapter.callWebRemoteMethod("x",
32: "doSomething", new Class[] { String.class },
33: new String[] { "yeah" });
34: assertEquals(startSize + 1, StubbedAdapter.METHOD_CACHE.size());
35: assertEquals("yeah", service.something);
36: assertNull(obj.returnedObject);
37: assertEquals("x", adapter.calledService);
38:
39: //check its still the same size, ie the cache is working.
40: obj = adapter.callWebRemoteMethod("x", "doSomething",
41: new Class[] { String.class }, new String[] { "yeah" });
42: assertEquals(startSize + 1, StubbedAdapter.METHOD_CACHE.size());
43:
44: assertEquals(void.class, obj.returnType);
45: adapter.callWebRemoteMethod("x", "doSomething",
46: new Class[] { String.class }, new String[] { "no" });
47: assertEquals("no", service.something);
48:
49: obj = adapter.callWebRemoteMethod("x", "yeahYeah", null, null);
50: assertEquals(String.class, obj.returnType);
51: assertEquals("whee", obj.returnedObject);
52:
53: try {
54: adapter.callWebRemoteMethod("x", "notMe", null, null);
55: fail("This should not be allowed");
56: } catch (SecurityException e) {
57: assertNotNull(e.getMessage());
58: }
59:
60: try {
61: adapter.callWebRemoteMethod("x", "abc", null, null);
62: fail("This should not be allowed");
63: } catch (SecurityException e) {
64: assertNotNull(e.getMessage());
65: }
66:
67: }
68:
69: public void testAnotherClass() throws Exception {
70: AnotherService b = new AnotherService();
71: GWTToSeamAdapter ad = new StubbedAdapter(b);
72: int oldSize = StubbedAdapter.METHOD_CACHE.size();
73: ad.callWebRemoteMethod("y", "doSomething", null, null);
74: assertTrue(b.called);
75: assertEquals(oldSize + 1, StubbedAdapter.METHOD_CACHE.size());
76: }
77:
78: static class StubbedAdapter extends GWTToSeamAdapter {
79: private Object target;
80:
81: public String calledService;
82:
83: public StubbedAdapter(Object target) {
84: this .target = target;
85: }
86:
87: @Override
88: protected Object getServiceComponent(String serviceIntfName) {
89: this.calledService = serviceIntfName;
90: return target;
91: }
92: }
93:
94: }
|