From 6d0e93c68d3aeaeb4bb6d96ac0460eec40ef786e Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 11 Nov 2009 23:13:23 +0000 Subject: Moving 1.x branches git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835143 13f79535-47bb-0310-9956-ffa450edef68 --- .../tuscany/binding/rmi/BindingTestCase.java | 54 ++++++++++++++ .../rmi/NoRemoteMethodExceptionTestCase.java | 47 ++++++++++++ .../rmi/NoRemoteServiceExceptionTestCase.java | 47 ++++++++++++ .../binding/rmi/RMIBindingBuilderTestCase.java | 48 +++++++++++++ .../binding/rmi/RMIBindingLoaderTestCase.java | 74 +++++++++++++++++++ .../tuscany/binding/rmi/RMIBindingTestCase.java | 40 +++++++++++ .../tuscany/binding/rmi/RMIInvokerTestCase.java | 84 ++++++++++++++++++++++ .../tuscany/binding/rmi/RMIReferenceTestCase.java | 48 +++++++++++++ .../tuscany/binding/rmi/RMIServiceTestCase.java | 53 ++++++++++++++ .../binding/rmi/RemoteMethodHandlerTestCase.java | 42 +++++++++++ .../binding/rmi/host/RMIHostImplTestCase.java | 76 ++++++++++++++++++++ 11 files changed, 613 insertions(+) create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/BindingTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/NoRemoteMethodExceptionTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/NoRemoteServiceExceptionTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIBindingBuilderTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIBindingLoaderTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIBindingTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIInvokerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIReferenceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIServiceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RemoteMethodHandlerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/host/RMIHostImplTestCase.java (limited to 'sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi') diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/BindingTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/BindingTestCase.java new file mode 100644 index 0000000000..7ebee2af66 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/BindingTestCase.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.binding.rmi; + +import helloworld.HelloWorldRmiService; + +import org.apache.tuscany.test.SCATestCase; +import org.osoa.sca.CompositeContext; +import org.osoa.sca.CurrentCompositeContext; + +// TODO: renamed to XXX as it doesn't work for me +public class BindingTestCase extends SCATestCase { + private HelloWorldRmiService helloWorldRmiService; + + public void testRmiService() { + System.out.println(helloWorldRmiService.sayRmiHello("Tuscany World!")); + assertEquals("Hello from the RMI Service to - Tuscany World! thro the RMI Reference", + helloWorldRmiService.sayRmiHello("Tuscany World!")); + } + + protected void setUp() throws Exception { + addExtension("rmi.binding", + getClass().getClassLoader().getResource("META-INF/sca/rmi_extension.scdl")); + setApplicationSCDL(getClass().getClassLoader().getResource("META-INF/sca/default.scdl")); + + super.setUp(); + + CompositeContext context = CurrentCompositeContext.getContext(); + helloWorldRmiService = context.locateService(HelloWorldRmiService.class, + "HelloWorldRmiServiceComponent"); + } + + + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/NoRemoteMethodExceptionTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/NoRemoteMethodExceptionTestCase.java new file mode 100644 index 0000000000..cb4911a0a5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/NoRemoteMethodExceptionTestCase.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.binding.rmi; + +import junit.framework.TestCase; + +public class NoRemoteMethodExceptionTestCase extends TestCase { + + public void testNoArgs() { + assertNotNull(new NoRemoteMethodException()); + } + + public void testMsgArg() { + NoRemoteMethodException e = new NoRemoteMethodException("foo"); + assertEquals("foo", e.getMessage()); + } + + public void test2Args() { + Exception cause = new Exception(); + NoRemoteMethodException e = new NoRemoteMethodException("foo", cause); + assertEquals("foo", e.getMessage()); + assertEquals(cause, e.getCause()); + } + + public void testCauseArgs() { + Exception cause = new Exception(); + NoRemoteMethodException e = new NoRemoteMethodException(cause); + assertEquals(cause, e.getCause()); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/NoRemoteServiceExceptionTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/NoRemoteServiceExceptionTestCase.java new file mode 100644 index 0000000000..a5da001ad9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/NoRemoteServiceExceptionTestCase.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.binding.rmi; + +import junit.framework.TestCase; + +public class NoRemoteServiceExceptionTestCase extends TestCase { + + public void testNoArgs() { + assertNotNull(new NoRemoteServiceException()); + } + + public void testMsgArg() { + NoRemoteServiceException e = new NoRemoteServiceException("foo"); + assertEquals("foo", e.getMessage()); + } + + public void test2Args() { + Exception cause = new Exception(); + NoRemoteServiceException e = new NoRemoteServiceException("foo", cause); + assertEquals("foo", e.getMessage()); + assertEquals(cause, e.getCause()); + } + + public void testCauseArgs() { + Exception cause = new Exception(); + NoRemoteServiceException e = new NoRemoteServiceException(cause); + assertEquals(cause, e.getCause()); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIBindingBuilderTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIBindingBuilderTestCase.java new file mode 100644 index 0000000000..b74be6d78b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIBindingBuilderTestCase.java @@ -0,0 +1,48 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.binding.rmi; + +import static org.easymock.EasyMock.expect; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.replay; +import junit.framework.TestCase; + +import org.apache.tuscany.spi.model.BoundReferenceDefinition; +import org.apache.tuscany.spi.model.ServiceContract; + +public class RMIBindingBuilderTestCase extends TestCase { + + public void testGetBindingType() { + assertEquals(RMIBinding.class, new RMIBindingBuilder(null).getBindingType()); + } + + @SuppressWarnings("unchecked") + public void testBuildService() { + RMIBindingBuilder builder = new RMIBindingBuilder(null); + BoundReferenceDefinition def = createMock(BoundReferenceDefinition.class); + expect(def.getName()).andReturn("petra"); + RMIBinding binding = new RMIBinding(); + expect(def.getBinding()).andReturn(binding ); + expect(def.getBinding()).andReturn(binding ); + expect(def.getBinding()).andReturn(binding ); + ServiceContract sc = createMock(ServiceContract.class); + expect(def.getServiceContract()).andReturn(sc); + replay(def); + Object ref = builder.build(null, def, null); + assertTrue(ref instanceof RMIReference); + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIBindingLoaderTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIBindingLoaderTestCase.java new file mode 100644 index 0000000000..160ca19b8a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIBindingLoaderTestCase.java @@ -0,0 +1,74 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.binding.rmi; + +import static org.easymock.EasyMock.expect; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.replay; +import static org.easymock.classextension.EasyMock.verify; + +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.spi.component.CompositeComponent; +import org.apache.tuscany.spi.deployer.DeploymentContext; +import org.apache.tuscany.spi.loader.LoaderException; +import org.apache.tuscany.spi.loader.LoaderRegistry; + +public class RMIBindingLoaderTestCase extends TestCase { + private CompositeComponent parent; + + private XMLStreamReader reader; + + private DeploymentContext deploymentContext; + + private LoaderRegistry registry; + + private RMIBindingLoader loader; + + public void testLoad() throws LoaderException, XMLStreamException { + expect(reader.getAttributeValue(null, "host")).andReturn("host"); + expect(reader.getAttributeValue(null, "port")).andReturn("0"); + expect(reader.getAttributeValue(null, "serviceName")).andReturn("servicename"); + expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT); + + replay(reader); + replay(deploymentContext); + + RMIBindingLoader mockLoader = new RMIBindingLoader(registry); + mockLoader.load(parent, reader, deploymentContext); + verify(reader); + verify(deploymentContext); + } + + public void testGetXMLType() throws LoaderException { + assertEquals(RMIBindingLoader.BINDING_RMI, loader.getXMLType()); + } + + protected void setUp() throws Exception { + super.setUp(); + registry = createMock(LoaderRegistry.class); + loader = new RMIBindingLoader(registry); + + parent = createMock(CompositeComponent.class); + reader = createMock(XMLStreamReader.class); + deploymentContext = createMock(DeploymentContext.class); + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIBindingTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIBindingTestCase.java new file mode 100644 index 0000000000..6dbb81437f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIBindingTestCase.java @@ -0,0 +1,40 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.binding.rmi; + +import junit.framework.TestCase; + +public class RMIBindingTestCase extends TestCase { + + public void testHost() { + RMIBinding binding = new RMIBinding(); + binding.setHost("foo"); + assertEquals("foo", binding.getHost()); + } + + public void testPort() { + RMIBinding binding = new RMIBinding(); + binding.setPort("foo"); + assertEquals("foo", binding.getPort()); + } + + public void testServiceName() { + RMIBinding binding = new RMIBinding(); + binding.setServiceName("foo"); + assertEquals("foo", binding.getServiceName()); + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIInvokerTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIInvokerTestCase.java new file mode 100644 index 0000000000..72c0acacc4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIInvokerTestCase.java @@ -0,0 +1,84 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.binding.rmi; + +import static org.easymock.EasyMock.expect; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.replay; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.rmi.Remote; + +import junit.framework.TestCase; + +import org.apache.tuscany.host.rmi.RMIHost; +import org.apache.tuscany.host.rmi.RMIHostException; +import org.apache.tuscany.host.rmi.RMIHostRuntimeException; + +public class RMIInvokerTestCase extends TestCase { + + public void testInvokeTarget() throws InvocationTargetException, RMIHostRuntimeException, RMIHostException, IllegalArgumentException, + IllegalAccessException, SecurityException, NoSuchMethodException { + Method method = Object.class.getDeclaredMethod("toString", new Class[] {}); + RMIHost host = createMock(RMIHost.class); + expect(host.findService(null, null, null)).andReturn(new Remote() { + }); + replay(host); + RMIInvoker invoker = new RMIInvoker(host, null, null, null, method); + assertNotNull(invoker.invokeTarget(new Object[] {})); + } + +// TODO: these don't seem to work +// public void testInvokeTargetRMIHostException() throws InvocationTargetException, RMIHostRuntimeException, RMIHostException, +// IllegalArgumentException, IllegalAccessException, SecurityException, NoSuchMethodException { +// Method method = foo.class.getDeclaredMethod("bang", new Class[] {}); +// RMIHost host = createMock(RMIHost.class); +// expect(host.findService(null, null, null)).andReturn(new foo()); +// replay(host); +// try { +// new RMIInvoker(host, null, null, null, method).invokeTarget(new Object[] {}); +// fail(); +// } catch (InvocationTargetException e) { +// // expected +// } +// } +// +// public void testInvokeTargetIllegalAccessException() throws InvocationTargetException, RMIHostRuntimeException, RMIHostException, +// IllegalArgumentException, IllegalAccessException, SecurityException, NoSuchMethodException { +// Method method = foo.class.getDeclaredMethod("crash", new Class[] {}); +// RMIHost host = createMock(RMIHost.class); +// expect(host.findService(null, null, null)).andReturn(new foo()); +// replay(host); +// try { +// new RMIInvoker(host, null, null, null, method).invokeTarget(new Object[] {}); +// fail(); +// } catch (InvocationTargetException e) { +// // expected +// } +// } +// +// class foo implements Remote { +// void crash() throws IllegalAccessException { +// throw new IllegalAccessException(); +// } +// +// void bang() throws RMIHostException { +// throw new RMIHostException(); +// } +// } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIReferenceTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIReferenceTestCase.java new file mode 100644 index 0000000000..5c935ec38a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIReferenceTestCase.java @@ -0,0 +1,48 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.binding.rmi; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.tuscany.spi.idl.java.JavaServiceContract; +import org.apache.tuscany.spi.model.DataType; +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.model.ServiceContract; + +public class RMIReferenceTestCase extends TestCase { + + @SuppressWarnings("unchecked") + public void testCreateTargetInvoker() { + // TODO: this doesn't really test anything yet + RMIReference ref = new RMIReference(null, null, null, null, null, null, null, null); + ServiceContract contract = new JavaServiceContract(); + contract.setInterfaceClass(String.class); + List l = new ArrayList(); + l.add(new DataType(null, null)); + DataType in = new DataType(null, l); + Operation operation = new Operation(null, in, null, null); + try { + ref.createTargetInvoker(contract, operation); + } catch (Exception e) { + // expected + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIServiceTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIServiceTestCase.java new file mode 100644 index 0000000000..1386cf2c72 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RMIServiceTestCase.java @@ -0,0 +1,53 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.binding.rmi; + +import junit.framework.TestCase; + +import org.apache.tuscany.binding.rmi.host.RMIHostImpl; +import org.apache.tuscany.host.rmi.RMIHostRuntimeException; +import org.apache.tuscany.spi.wire.WireInvocationHandler; + +public class RMIServiceTestCase extends TestCase { + + @SuppressWarnings("unchecked") + public void testGetPort() { + RMIService s = new RMIService(null, null, null, null, null, null, null, null); + assertEquals(0, s.getPort("0")); + } + + @SuppressWarnings("unchecked") + public void testGenerateRemoteInterface() { + RMIService s = new RMIService("foo27", null, null, null, null, null, null, null); + s.generateRemoteInterface(Runnable.class); + } + + @SuppressWarnings("unchecked") + public void testCreateRmiService() { + RMIService s = new RMIService("bla023", null, null, new RMIHostImpl(), null, "9996", "bla", Runnable.class) { + public WireInvocationHandler getHandler() { + return null; + } + }; + s.start(); + try { + s.stop(); + } catch (RMIHostRuntimeException e) { + // expected + } + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RemoteMethodHandlerTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RemoteMethodHandlerTestCase.java new file mode 100644 index 0000000000..f5c9595aa3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/RemoteMethodHandlerTestCase.java @@ -0,0 +1,42 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.binding.rmi; + +import static org.easymock.EasyMock.expect; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.replay; + +import java.lang.reflect.Method; + +import junit.framework.TestCase; + +import org.apache.tuscany.spi.wire.WireInvocationHandler; + +public class RemoteMethodHandlerTestCase extends TestCase { + + public void testIntercept() throws SecurityException, NoSuchMethodException, Throwable { + WireInvocationHandler h2 = createMock(WireInvocationHandler.class); + Method method = Runnable.class.getDeclaredMethod("run", new Class[]{}); + Object[] noArgs = new Object[]{}; + expect(h2.invoke(method, noArgs)).andReturn("foo"); + replay(h2); + RemoteMethodHandler handler = new RemoteMethodHandler(h2, Runnable.class); + Object o = handler.intercept(null, method, noArgs, null); + assertEquals("foo", o); + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/host/RMIHostImplTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/host/RMIHostImplTestCase.java new file mode 100644 index 0000000000..08f6172f3d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.rmi/src/test/java/org/apache/tuscany/binding/rmi/host/RMIHostImplTestCase.java @@ -0,0 +1,76 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.binding.rmi.host; + +import java.rmi.Remote; + +import junit.framework.TestCase; + +import org.apache.tuscany.host.rmi.RMIHostException; +import org.apache.tuscany.host.rmi.RMIHostRuntimeException; + +public class RMIHostImplTestCase extends TestCase { + + public void testInit() { + new RMIHostImpl().init(); + } + + public void testFindServiceBadHost() throws RMIHostRuntimeException, RMIHostException { + try { + new RMIHostImpl().findService(null, "0", null); + fail(); + } catch (RMIHostRuntimeException e) { + // expected + } + } + + public void testRegisterService1() throws RMIHostRuntimeException, RMIHostException { + RMIHostImpl host = new RMIHostImpl(); + host.registerService("foo1", new MockRemote()); + host.unregisterService("foo1"); + } + + public void testRegisterService2() throws RMIHostRuntimeException, RMIHostException { + RMIHostImpl host = new RMIHostImpl(); + host.registerService("bar1", 9999, new MockRemote()); + host.unregisterService("bar1", 9999); + } + + public void testRegisterServiceAlreadyBound() throws RMIHostRuntimeException, RMIHostException { + RMIHostImpl host = new RMIHostImpl(); + host.registerService("bar2", 9997, new MockRemote()); + try { + host.registerService("bar2", 9997, new MockRemote()); + } catch (RMIHostException e) { + // expected + host.unregisterService("bar2", 9997); + } + } + + public void testUnRegisterService() throws RMIHostRuntimeException, RMIHostException { + RMIHostImpl host = new RMIHostImpl(); + try { + host.unregisterService("bar3", 9998); + fail(); + } catch (RMIHostException e) { + // expected + } + } + + private static class MockRemote implements Remote { + } +} -- cgit v1.2.3