1 /*** 2 * 3 * Copyright 2005 LogicBlaze, Inc. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 **/ 18 package org.logicblaze.lingo; 19 20 import junit.framework.TestCase; 21 22 import java.lang.reflect.Method; 23 24 import org.logicblaze.lingo.example.ExampleService; 25 26 /*** 27 * @version $Revision: 1.1 $ 28 */ 29 public class SimpleMetadataStrategyTest extends TestCase { 30 protected MetadataStrategy strategy; 31 32 public void testExampleService_someOneWayMethod() throws Exception { 33 MethodMetadata metadata = strategy.getMethodMetadata(findMethod(ExampleService.class, "someOneWayMethod")); 34 assertEquals("oneway", true, metadata.isOneWay()); 35 assertEquals("param 0 remote", false, metadata.isRemoteParameter(0)); 36 assertEquals("param 1 remote", false, metadata.isRemoteParameter(1)); 37 } 38 39 public void testExampleService_regularRPC() throws Exception { 40 MethodMetadata metadata = strategy.getMethodMetadata(findMethod(ExampleService.class, "regularRPC")); 41 assertEquals("oneway", false, metadata.isOneWay()); 42 assertEquals("param 0 remote", false, metadata.isRemoteParameter(0)); 43 } 44 45 public void testExampleService_anotherRPC() throws Exception { 46 MethodMetadata metadata = strategy.getMethodMetadata(findMethod(ExampleService.class, "anotherRPC")); 47 assertEquals("oneway", false, metadata.isOneWay()); 48 } 49 50 public void testExampleService_asyncRequestResponse() throws Exception { 51 MethodMetadata metadata = strategy.getMethodMetadata(findMethod(ExampleService.class, "asyncRequestResponse")); 52 assertEquals("oneway", true, metadata.isOneWay()); 53 assertEquals("param 0 remote", false, metadata.isRemoteParameter(0)); 54 assertEquals("param 1 remote", true, metadata.isRemoteParameter(1)); 55 } 56 57 protected Method findMethod(Class type, String name) throws Exception { 58 Method[] methods = type.getMethods(); 59 for (int i = 0; i < methods.length; i++) { 60 Method method = methods[i]; 61 if (method.getName().equals(name)) { 62 return method; 63 } 64 } 65 fail("No such method called: " + name + " on type: " + type.getName()); 66 return null; 67 } 68 69 protected void setUp() throws Exception { 70 strategy = createMetadataStrategy(); 71 } 72 73 protected MetadataStrategy createMetadataStrategy() { 74 return new SimpleMetadataStrategy(true); 75 } 76 }