You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jm...@apache.org on 2006/02/13 08:35:19 UTC
svn commit: r377318 - in /incubator/tuscany/java/sca:
container.java/src/test/java/org/apache/tuscany/container/java/invocation/jdk/
core/src/main/java/org/apache/tuscany/core/invocation/
core/src/test/java/org/apache/tuscany/core/invocation/ core/src/...
Author: jmarino
Date: Sun Feb 12 23:35:18 2006
New Revision: 377318
URL: http://svn.apache.org/viewcvs?rev=377318&view=rev
Log:
more unit tests for invocation framework
Added:
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/InvocationErrorTestCase.java
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/jdk/JDKProxyFactoryTestCase.java
Removed:
incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/invocation/jdk/InvocationHandlerErrorTestCase.java
incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/invocation/jdk/JDKInvocationHandlerTestCase.java
Modified:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/invocation/ProxyConfiguration.java
Modified: incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/invocation/ProxyConfiguration.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/invocation/ProxyConfiguration.java?rev=377318&r1=377317&r2=377318&view=diff
==============================================================================
--- incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/invocation/ProxyConfiguration.java (original)
+++ incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/invocation/ProxyConfiguration.java Sun Feb 12 23:35:18 2006
@@ -36,6 +36,7 @@
private MessageFactory messageFactory;
+ //FIXME Remove
private Map<Integer, ScopeContext> scopeContainers;
private QualifiedName targetName;
@@ -89,6 +90,7 @@
/**
* @return Returns the scopeContainers.
+ * @deprecated
*/
public Map<Integer, ScopeContext> getScopeContainers() {
return scopeContainers;
Added: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/InvocationErrorTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/InvocationErrorTestCase.java?rev=377318&view=auto
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/InvocationErrorTestCase.java (added)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/InvocationErrorTestCase.java Sun Feb 12 23:35:18 2006
@@ -0,0 +1,127 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.core.invocation;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.invocation.impl.InvokerInterceptor;
+import org.apache.tuscany.core.invocation.jdk.JDKInvocationHandler;
+import org.apache.tuscany.core.invocation.mock.MockHandler;
+import org.apache.tuscany.core.invocation.mock.MockJavaOperationType;
+import org.apache.tuscany.core.invocation.mock.MockStaticInvoker;
+import org.apache.tuscany.core.invocation.mock.MockSyncInterceptor;
+import org.apache.tuscany.core.message.impl.MessageFactoryImpl;
+import org.apache.tuscany.model.types.OperationType;
+
+/**
+ * Tests handling of exceptions thrown during an invocation
+ *
+ * @version $Rev: 377006 $ $Date: 2006-02-11 09:41:59 -0800 (Sat, 11 Feb 2006) $
+ */
+public class InvocationErrorTestCase extends TestCase {
+
+ private Method checkedMethod;
+ private Method runtimeMethod;
+
+ public InvocationErrorTestCase() {
+ super();
+ }
+
+ public InvocationErrorTestCase(String arg0) {
+ super(arg0);
+ }
+
+ public void setUp() throws Exception {
+ checkedMethod = TestBean.class.getDeclaredMethod("checkedException", (Class[]) null);
+ runtimeMethod = TestBean.class.getDeclaredMethod("runtimeException", (Class[]) null);
+ Assert.assertNotNull(checkedMethod);
+ Assert.assertNotNull(runtimeMethod);
+ }
+
+ public void testCheckedException() throws Exception {
+ Map<Method, InvocationConfiguration> config = new HashMap();
+ config.put(checkedMethod, getConfiguration(checkedMethod));
+ InvocationHandler handler = new JDKInvocationHandler(new MessageFactoryImpl(), config);
+ try {
+ TestBean proxy = (TestBean) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
+ new Class[]{TestBean.class}, handler);
+ proxy.checkedException();
+ } catch (TestException e) {
+ return;
+ }
+ Assert.fail(TestException.class.getName() + " should have been thrown");
+ }
+
+ public void testRuntimeException() throws Exception {
+ Map<Method, InvocationConfiguration> config = new HashMap();
+ config.put(runtimeMethod, getConfiguration(runtimeMethod));
+ InvocationHandler handler = new JDKInvocationHandler(new MessageFactoryImpl(), config);
+ try {
+ TestBean proxy = (TestBean) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
+ new Class[]{TestBean.class}, handler);
+ proxy.runtimeException();
+ } catch (TestRuntimeException e) {
+ return;
+ }
+ Assert.fail(TestException.class.getName() + " should have been thrown");
+ }
+
+ private InvocationConfiguration getConfiguration(Method m) {
+ OperationType operation = new MockJavaOperationType(m);
+ MockStaticInvoker invoker = new MockStaticInvoker(m, new TestBeanImpl());
+ InvocationConfiguration invocationConfiguration=new InvocationConfiguration(operation);
+ invocationConfiguration.addSourceInterceptor(new MockSyncInterceptor());
+ invocationConfiguration.addRequestHandler(new MockHandler());
+ invocationConfiguration.setTargetInvoker(invoker);
+ invocationConfiguration.addTargetInterceptor(new InvokerInterceptor());
+ invocationConfiguration.build();
+ return invocationConfiguration;
+ }
+
+ public interface TestBean {
+
+ public void checkedException() throws TestException;
+
+ public void runtimeException() throws TestRuntimeException;
+
+ }
+
+ public class TestBeanImpl implements TestBean {
+
+ public void checkedException() throws TestException {
+ throw new TestException();
+ }
+
+ public void runtimeException() throws TestRuntimeException {
+ throw new TestRuntimeException();
+ }
+ }
+
+ public class TestException extends Exception {
+ }
+
+ public class TestRuntimeException extends RuntimeException {
+ }
+
+}
Added: incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/jdk/JDKProxyFactoryTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/jdk/JDKProxyFactoryTestCase.java?rev=377318&view=auto
==============================================================================
--- incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/jdk/JDKProxyFactoryTestCase.java (added)
+++ incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/invocation/jdk/JDKProxyFactoryTestCase.java Sun Feb 12 23:35:18 2006
@@ -0,0 +1,70 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.core.invocation.jdk;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.core.context.QualifiedName;
+import org.apache.tuscany.core.invocation.InvocationConfiguration;
+import org.apache.tuscany.core.invocation.ProxyConfiguration;
+import org.apache.tuscany.core.invocation.impl.InvokerInterceptor;
+import org.apache.tuscany.core.invocation.mock.MockJavaOperationType;
+import org.apache.tuscany.core.invocation.mock.MockStaticInvoker;
+import org.apache.tuscany.core.invocation.mock.MockSyncInterceptor;
+import org.apache.tuscany.core.invocation.mock.SimpleTarget;
+import org.apache.tuscany.core.invocation.mock.SimpleTargetImpl;
+import org.apache.tuscany.core.message.impl.PojoMessageFactory;
+import org.apache.tuscany.model.types.OperationType;
+
+public class JDKProxyFactoryTestCase extends TestCase {
+
+ private Method hello;
+
+ private Method goodbye;
+
+ public JDKProxyFactoryTestCase(String arg0) {
+ super(arg0);
+ }
+
+ public void setUp() throws Exception {
+ hello = SimpleTarget.class.getMethod("hello", new Class[] { String.class });
+ goodbye = SimpleTarget.class.getMethod("goodbye", new Class[] { String.class });
+ }
+
+ public void testProxyFactory() throws Exception {
+
+ OperationType operation = new MockJavaOperationType(hello);
+ InvocationConfiguration source = new InvocationConfiguration(operation);
+ MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor();
+ source.addSourceInterceptor(sourceInterceptor);
+ source.addTargetInterceptor(new InvokerInterceptor());
+ source.setTargetInvoker(new MockStaticInvoker(hello, new SimpleTargetImpl()));
+ source.build();
+ Map<OperationType, InvocationConfiguration> configs = new HashMap();
+ configs.put(operation, source);
+ ProxyConfiguration config = new ProxyConfiguration(new QualifiedName("foo"), configs, Thread.currentThread()
+ .getContextClassLoader(), null, new PojoMessageFactory());
+ JDKProxyFactory factory = new JDKProxyFactory();
+ factory.setProxyConfiguration(config);
+ factory.setBusinessInterface(SimpleTarget.class);
+ factory.initialize();
+ SimpleTarget instance = (SimpleTarget) factory.createProxy();
+ Assert.assertEquals("foo",instance.hello("foo"));
+ }
+}