diff options
Diffstat (limited to 'tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation')
13 files changed, 0 insertions, 1020 deletions
diff --git a/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/InvocationConfigurationErrorTestCase.java b/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/InvocationConfigurationErrorTestCase.java deleted file mode 100644 index 3d2fe482f1..0000000000 --- a/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/InvocationConfigurationErrorTestCase.java +++ /dev/null @@ -1,158 +0,0 @@ -/** - * - * 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.Method; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.core.invocation.impl.InvokerInterceptor; -import org.apache.tuscany.core.invocation.impl.MessageChannelImpl; -import org.apache.tuscany.core.invocation.mock.MockHandler; -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.Message; -import org.apache.tuscany.core.message.MessageFactory; -import org.apache.tuscany.core.message.impl.MessageFactoryImpl; - -/** - * Tests error propagation through an innvocation - * - * @version $Rev$ $Date$ - */ -public class InvocationConfigurationErrorTestCase extends TestCase { - - - private Method hello; - private Method goodbye; - - private MessageFactory factory = new MessageFactoryImpl(); - - public InvocationConfigurationErrorTestCase() { - super(); - } - - public InvocationConfigurationErrorTestCase(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 testInvokeWithHandlers() throws Exception{ - InvocationConfiguration source = new InvocationConfiguration(hello); - MockHandler sourceRequestHandler = new MockHandler(); - MockHandler sourceResponseHandler = new MockHandler(); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addRequestHandler(sourceRequestHandler); - source.addResponseHandler(sourceResponseHandler); - source.addSourceInterceptor(sourceInterceptor); - - InvocationConfiguration target = new InvocationConfiguration(hello); - MockHandler targetRequestHandler = new MockHandler(); - MockHandler targetResponseHandler = new MockHandler(); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addRequestHandler(targetRequestHandler); - target.addResponseHandler(targetResponseHandler); - target.addTargetInterceptor(targetInterceptor); - target.addTargetInterceptor(new InvokerInterceptor()); - - // connect the source to the target - source.setTargetRequestChannel(new MessageChannelImpl(target.getRequestHandlers())); - source.setTargetResponseChannel(new MessageChannelImpl(target.getResponseHandlers())); - source.build(); - target.build(); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Message msg = factory.createMessage(); - msg.setTargetInvoker(invoker); - Message response = (Message) source.getSourceInterceptor().invoke(msg); - Assert.assertTrue(response.getBody() instanceof IllegalArgumentException); - Assert.assertEquals(1,sourceRequestHandler.getCount()); - Assert.assertEquals(1,sourceResponseHandler.getCount()); - Assert.assertEquals(1,sourceInterceptor.getCount()); - Assert.assertEquals(1,targetRequestHandler.getCount()); - Assert.assertEquals(1,targetResponseHandler.getCount()); - Assert.assertEquals(1,targetInterceptor.getCount()); - } - - public void testInvokeWithRequestHandlers() throws Exception{ - InvocationConfiguration source = new InvocationConfiguration(hello); - MockHandler sourceRequestHandler = new MockHandler(); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addRequestHandler(sourceRequestHandler); - source.addSourceInterceptor(sourceInterceptor); - - InvocationConfiguration target = new InvocationConfiguration(hello); - MockHandler targetRequestHandler = new MockHandler(); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addRequestHandler(targetRequestHandler); - target.addTargetInterceptor(targetInterceptor); - target.addTargetInterceptor(new InvokerInterceptor()); - - // connect the source to the target - source.setTargetRequestChannel(new MessageChannelImpl(target.getRequestHandlers())); - source.setTargetResponseChannel(new MessageChannelImpl(target.getResponseHandlers())); - source.build(); - target.build(); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Message msg = factory.createMessage(); - msg.setTargetInvoker(invoker); - Message response = (Message) source.getSourceInterceptor().invoke(msg); - Assert.assertTrue(response.getBody() instanceof IllegalArgumentException); - Assert.assertEquals(1,sourceRequestHandler.getCount()); - Assert.assertEquals(1,sourceInterceptor.getCount()); - Assert.assertEquals(1,targetRequestHandler.getCount()); - Assert.assertEquals(1,targetInterceptor.getCount()); - } - - /** - * Tests basic wiring of a source to a target, including handlers and interceptors - */ - public void testInvokeWithInterceptorsOnly() throws Exception{ - InvocationConfiguration source = new InvocationConfiguration(hello); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addSourceInterceptor(sourceInterceptor); - - InvocationConfiguration target = new InvocationConfiguration(hello); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addTargetInterceptor(targetInterceptor); - target.addTargetInterceptor(new InvokerInterceptor()); - - // connect the source to the target - source.addTargetInterceptor(target.getTargetInterceptor()); - source.build(); - target.build(); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Message msg = factory.createMessage(); - msg.setTargetInvoker(invoker); - Message response = (Message) source.getSourceInterceptor().invoke(msg); - Assert.assertTrue(response.getBody() instanceof IllegalArgumentException); - Assert.assertEquals(1,sourceInterceptor.getCount()); - Assert.assertEquals(1,targetInterceptor.getCount()); - - } - -} - diff --git a/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/InvocationConfigurationTestCase.java b/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/InvocationConfigurationTestCase.java deleted file mode 100644 index 9e5fb80cad..0000000000 --- a/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/InvocationConfigurationTestCase.java +++ /dev/null @@ -1,156 +0,0 @@ -/** - * - * 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.Method; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.core.invocation.impl.InvokerInterceptor; -import org.apache.tuscany.core.invocation.impl.MessageChannelImpl; -import org.apache.tuscany.core.invocation.mock.MockHandler; -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.Message; -import org.apache.tuscany.core.message.MessageFactory; -import org.apache.tuscany.core.message.impl.MessageFactoryImpl; - -public class InvocationConfigurationTestCase extends TestCase { - - private Method hello; - - private Method goodbye; - - private MessageFactory factory = new MessageFactoryImpl(); - - public InvocationConfigurationTestCase() { - super(); - } - - public InvocationConfigurationTestCase(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 }); - } - - /** - * Tests basic wiring of a source to a target, including handlers and interceptors - */ - public void testInvokeWithHandlers() throws Exception { - InvocationConfiguration source = new InvocationConfiguration(hello); - MockHandler sourceRequestHandler = new MockHandler(); - MockHandler sourceResponseHandler = new MockHandler(); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addRequestHandler(sourceRequestHandler); - source.addResponseHandler(sourceResponseHandler); - source.addSourceInterceptor(sourceInterceptor); - - InvocationConfiguration target = new InvocationConfiguration(hello); - MockHandler targetRequestHandler = new MockHandler(); - MockHandler targetResponseHandler = new MockHandler(); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addRequestHandler(targetRequestHandler); - target.addResponseHandler(targetResponseHandler); - target.addTargetInterceptor(targetInterceptor); - target.addTargetInterceptor(new InvokerInterceptor()); - - // connect the source to the target - source.setTargetRequestChannel(new MessageChannelImpl(target.getRequestHandlers())); - source.setTargetResponseChannel(new MessageChannelImpl(target.getResponseHandlers())); - source.build(); - target.build(); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Message msg = factory.createMessage(); - msg.setBody("foo"); - msg.setTargetInvoker(invoker); - Message response = (Message) source.getSourceInterceptor().invoke(msg); - Assert.assertEquals("foo", response.getBody()); - Assert.assertEquals(1, sourceRequestHandler.getCount()); - Assert.assertEquals(1, sourceResponseHandler.getCount()); - Assert.assertEquals(1, sourceInterceptor.getCount()); - Assert.assertEquals(1, targetRequestHandler.getCount()); - Assert.assertEquals(1, targetResponseHandler.getCount()); - Assert.assertEquals(1, targetInterceptor.getCount()); - } - - public void testInvokeWithRequestHandlers() throws Exception { - InvocationConfiguration source = new InvocationConfiguration(hello); - MockHandler sourceRequestHandler = new MockHandler(); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addRequestHandler(sourceRequestHandler); - source.addSourceInterceptor(sourceInterceptor); - - InvocationConfiguration target = new InvocationConfiguration(hello); - MockHandler targetRequestHandler = new MockHandler(); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addRequestHandler(targetRequestHandler); - target.addTargetInterceptor(targetInterceptor); - target.addTargetInterceptor(new InvokerInterceptor()); - - // connect the source to the target - source.setTargetRequestChannel(new MessageChannelImpl(target.getRequestHandlers())); - source.setTargetResponseChannel(new MessageChannelImpl(target.getResponseHandlers())); - source.build(); - target.build(); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Message msg = factory.createMessage(); - msg.setBody("foo"); - msg.setTargetInvoker(invoker); - Message response = (Message) source.getSourceInterceptor().invoke(msg); - Assert.assertEquals("foo", response.getBody()); - Assert.assertEquals(1, sourceRequestHandler.getCount()); - Assert.assertEquals(1, sourceInterceptor.getCount()); - Assert.assertEquals(1, targetRequestHandler.getCount()); - Assert.assertEquals(1, targetInterceptor.getCount()); - } - - /** - * Tests basic wiring of a source to a target, including handlers and interceptors - */ - public void testInvokeWithInterceptorsOnly() throws Exception { - InvocationConfiguration source = new InvocationConfiguration(hello); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addSourceInterceptor(sourceInterceptor); - - InvocationConfiguration target = new InvocationConfiguration(hello); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addTargetInterceptor(targetInterceptor); - target.addTargetInterceptor(new InvokerInterceptor()); - - // connect the source to the target - source.addTargetInterceptor(target.getTargetInterceptor()); - source.build(); - target.build(); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Message msg = factory.createMessage(); - msg.setBody("foo"); - msg.setTargetInvoker(invoker); - Message response = (Message) source.getSourceInterceptor().invoke(msg); - Assert.assertEquals("foo", response.getBody()); - Assert.assertEquals(1, sourceInterceptor.getCount()); - Assert.assertEquals(1, targetInterceptor.getCount()); - } -} diff --git a/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/InvocationErrorTestCase.java b/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/InvocationErrorTestCase.java deleted file mode 100644 index 02929c9193..0000000000 --- a/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/InvocationErrorTestCase.java +++ /dev/null @@ -1,124 +0,0 @@ -/** - * - * 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.MockStaticInvoker; -import org.apache.tuscany.core.invocation.mock.MockSyncInterceptor; -import org.apache.tuscany.core.message.impl.MessageFactoryImpl; - -/** - * 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 MethodHashMap(); - 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 MethodHashMap(); - 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) { - MockStaticInvoker invoker = new MockStaticInvoker(m, new TestBeanImpl()); - InvocationConfiguration invocationConfiguration=new InvocationConfiguration(m); - 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 { - } - -} diff --git a/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/jdk/JDKInvocationHandlerTestCase.java b/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/jdk/JDKInvocationHandlerTestCase.java deleted file mode 100644 index 758134fbba..0000000000 --- a/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/jdk/JDKInvocationHandlerTestCase.java +++ /dev/null @@ -1,112 +0,0 @@ -package org.apache.tuscany.core.invocation.jdk; - -import java.lang.reflect.Method; -import java.util.Map; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.core.invocation.InvocationConfiguration; -import org.apache.tuscany.core.invocation.MethodHashMap; -import org.apache.tuscany.core.invocation.impl.InvokerInterceptor; -import org.apache.tuscany.core.invocation.impl.MessageChannelImpl; -import org.apache.tuscany.core.invocation.mock.MockHandler; -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.MessageFactoryImpl; - -public class JDKInvocationHandlerTestCase extends TestCase { - - private Method hello; - - private Method goodbye; - - public JDKInvocationHandlerTestCase() { - super(); - } - - public JDKInvocationHandlerTestCase(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 testBasicInvoke() throws Throwable { - Map<Method, InvocationConfiguration> configs = new MethodHashMap(); - configs.put(hello, getInvocationHandler(hello)); - JDKInvocationHandler handler = new JDKInvocationHandler(new MessageFactoryImpl(), configs); - Assert.assertEquals("foo", handler.invoke(null, hello, new Object[] { "foo" })); - } - - public void testErrorInvoke() throws Throwable { - Map<Method, InvocationConfiguration> configs = new MethodHashMap(); - configs.put(hello, getInvocationHandler(hello)); - JDKInvocationHandler handler = new JDKInvocationHandler(new MessageFactoryImpl(), configs); - try { - Assert.assertEquals("foo", handler.invoke(null, hello, new Object[] {})); - fail("Expected " + IllegalArgumentException.class.getName()); - } catch (IllegalArgumentException e) { - // should throw - } - } - - public void testDirectErrorInvoke() throws Throwable { - InvocationConfiguration source = new InvocationConfiguration(hello); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Map<Method, InvocationConfiguration> configs = new MethodHashMap(); - configs.put(hello, source); - JDKInvocationHandler handler = new JDKInvocationHandler(new MessageFactoryImpl(), configs); - try { - Assert.assertEquals("foo", handler.invoke(null, hello, new Object[] {})); - fail("Expected " + IllegalArgumentException.class.getName()); - } catch (IllegalArgumentException e) { - // should throw - } - } - - public void testDirectInvoke() throws Throwable { - InvocationConfiguration source = new InvocationConfiguration(hello); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Map<Method, InvocationConfiguration> configs = new MethodHashMap(); - configs.put(hello, source); - JDKInvocationHandler handler = new JDKInvocationHandler(new MessageFactoryImpl(), configs); - Assert.assertEquals("foo", handler.invoke(null, hello, new Object[] { "foo" })); - } - - private InvocationConfiguration getInvocationHandler(Method m) { - InvocationConfiguration source = new InvocationConfiguration(m); - MockHandler sourceRequestHandler = new MockHandler(); - MockHandler sourceResponseHandler = new MockHandler(); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addRequestHandler(sourceRequestHandler); - source.addResponseHandler(sourceResponseHandler); - source.addSourceInterceptor(sourceInterceptor); - - InvocationConfiguration target = new InvocationConfiguration(m); - MockHandler targetRequestHandler = new MockHandler(); - MockHandler targetResponseHandler = new MockHandler(); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addRequestHandler(targetRequestHandler); - target.addResponseHandler(targetResponseHandler); - target.addTargetInterceptor(targetInterceptor); - target.addTargetInterceptor(new InvokerInterceptor()); - - // connect the source to the target - source.setTargetRequestChannel(new MessageChannelImpl(target.getRequestHandlers())); - source.setTargetResponseChannel(new MessageChannelImpl(target.getResponseHandlers())); - source.build(); - target.build(); - MockStaticInvoker invoker = new MockStaticInvoker(m, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - return source; - } -} diff --git a/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/jdk/JDKProxyFactoryTestCase.java b/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/jdk/JDKProxyFactoryTestCase.java deleted file mode 100644 index 98853a1469..0000000000 --- a/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/jdk/JDKProxyFactoryTestCase.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * - * 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.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.MethodHashMap; -import org.apache.tuscany.core.invocation.ProxyConfiguration; -import org.apache.tuscany.core.invocation.impl.InvokerInterceptor; -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.MessageFactoryImpl; - -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 { - InvocationConfiguration source = new InvocationConfiguration(hello); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addSourceInterceptor(sourceInterceptor); - source.addTargetInterceptor(new InvokerInterceptor()); - source.setTargetInvoker(new MockStaticInvoker(hello, new SimpleTargetImpl())); - source.build(); - Map<Method, InvocationConfiguration> configs = new MethodHashMap(); - configs.put(hello, source); - ProxyConfiguration config = new ProxyConfiguration(new QualifiedName("foo"), configs, Thread.currentThread() - .getContextClassLoader(), new MessageFactoryImpl()); - JDKProxyFactory factory = new JDKProxyFactory(); - factory.setProxyConfiguration(config); - factory.setBusinessInterface(SimpleTarget.class); - factory.initialize(); - SimpleTarget instance = (SimpleTarget) factory.createProxy(); - Assert.assertEquals("foo",instance.hello("foo")); - } -} diff --git a/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/MockHandler.java b/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/MockHandler.java deleted file mode 100644 index ec52bee002..0000000000 --- a/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/MockHandler.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * - */ -package org.apache.tuscany.core.invocation.mock; - -import org.apache.tuscany.core.invocation.MessageHandler; -import org.apache.tuscany.core.message.Message; - -/** - * - */ -public class MockHandler implements MessageHandler { - - private int count =0; - - public boolean processMessage(Message message) { - //System.out.println("Invoking handler"); - count++; - return true; - } - - public int getCount(){ - return count; - } -} diff --git a/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/MockScopeContext.java b/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/MockScopeContext.java deleted file mode 100644 index ec8a95d4be..0000000000 --- a/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/MockScopeContext.java +++ /dev/null @@ -1,136 +0,0 @@ -/** - * - * 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.mock; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.tuscany.core.builder.RuntimeConfiguration; -import org.apache.tuscany.core.context.InstanceContext; -import org.apache.tuscany.core.context.EventException; -import org.apache.tuscany.core.context.QualifiedName; -import org.apache.tuscany.core.context.LifecycleEventListener; -import org.apache.tuscany.core.context.ScopeContext; -import org.apache.tuscany.core.context.ScopeRuntimeException; -import org.apache.tuscany.core.context.SimpleComponentContext; -import org.apache.tuscany.core.context.TargetException; -import org.apache.tuscany.model.assembly.SimpleComponent; - -public class MockScopeContext implements ScopeContext { - - Map<String, Object> components; - - public MockScopeContext() { - components = new HashMap(); - components.put("foo", new SimpleTargetImpl()); - components.put("bar", new SimpleTargetImpl()); - } - - public MockScopeContext(Map<String,Object> instances) { - components = instances; - } - - - public void start() { - } - - public void stop() { - } - - public String getName() { - return "Mock Scope Container"; - } - - public boolean isCacheable() { - return false; - } - - public int[] getEventTypes() { - return null; - } - - public SimpleComponentContext getContext(String name) { - return null; - } - - public Object getInstance(QualifiedName name) throws ScopeRuntimeException { - return components.get(name.getPartName()); - } - - public Object getInstance(QualifiedName componentName, boolean notify) throws TargetException { - return getInstance(componentName); - } - - public SimpleComponentContext getContextByKey(String name, Object key) { - return null; - } - - public void setComponent(SimpleComponent component) throws ScopeRuntimeException { - } - - public void removeContext(String name) throws ScopeRuntimeException { - } - - public void removeContextByKey(String name, Object key) throws ScopeRuntimeException { - } - - public SimpleComponent[] getComponents() { - return null; - } - - public void onEvent(int type, Object message) throws EventException { - } - - - public void registerConfigurations(List<RuntimeConfiguration<InstanceContext>> configurations) { - } - - public void registerConfiguration(RuntimeConfiguration<InstanceContext> configuration) { - } - - public int getLifecycleState(){ - return RUNNING; - } - - - public void setLifecycleState(int state) { - } - - - public void setName(String name) { - } - - - public void addContextListener(LifecycleEventListener listener) { - } - - - public void removeContextListener(LifecycleEventListener listener) { - } - - public Object getImplementationInstance() throws TargetException{ - return this; - } - - public Object getImplementationInstance(boolean notify) throws TargetException{ - return this; - } - - -} - diff --git a/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/MockStaticInvoker.java b/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/MockStaticInvoker.java deleted file mode 100644 index 27b3594ab7..0000000000 --- a/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/MockStaticInvoker.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.apache.tuscany.core.invocation.mock; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import org.apache.tuscany.core.invocation.Interceptor; -import org.apache.tuscany.core.invocation.InvocationRuntimeException; -import org.apache.tuscany.core.invocation.TargetInvoker; -import org.apache.tuscany.core.message.Message; - -/** - * Caches component instances that do not need to be resolved for every invocation, e.g. an invocation originating from - * a lesser scope intended for a target with a wider scope - * - * @version $Rev: 377006 $ $Date: 2006-02-11 09:41:59 -0800 (Sat, 11 Feb 2006) $ - */ -public class MockStaticInvoker implements TargetInvoker { - - private Object instance; - - private Method operation; - - public MockStaticInvoker(Method operation, Object instance) { - this.operation = operation; - this.instance = instance; - } - - public boolean isCacheable() { - return true; - } - - public Object invokeTarget(Object payload) throws InvocationTargetException { - try { - if (payload != null && !payload.getClass().isArray()) { - return operation.invoke(instance, payload); - } else { - return operation.invoke(instance, (Object[]) payload); - } - } catch (IllegalAccessException e) { - throw new InvocationRuntimeException(e); - } - } - - public Message invoke(Message msg) { - try { - Object resp = invokeTarget(msg.getBody()); - msg.setBody(resp); - } catch (InvocationTargetException e) { - msg.setBody(e.getCause()); - } catch (Throwable e) { - msg.setBody(e); - } - return msg; - } - - public void setNext(Interceptor next) { - throw new IllegalStateException("This interceptor must be the last interceptor in an interceptor chain"); - } - - public Object clone() { - try { - MockStaticInvoker invoker = (MockStaticInvoker) super.clone(); - invoker.instance = this.instance; - invoker.operation = this.operation; - return invoker; - } catch (CloneNotSupportedException e) { - return null; // will not happen - } - } -} diff --git a/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/MockSyncInterceptor.java b/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/MockSyncInterceptor.java deleted file mode 100644 index 120b7654cd..0000000000 --- a/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/MockSyncInterceptor.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * - * 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.mock; - -import org.apache.tuscany.core.invocation.Interceptor; -import org.apache.tuscany.core.message.Message; - -public class MockSyncInterceptor implements Interceptor { - - private int count; - - private Interceptor next; - - public MockSyncInterceptor() { - } - - public Message invoke(Message msg) { - ++count; - //System.out.println("Invoking interceptor"); - return next.invoke(msg); - } - - public int getCount() { - return count; - } - - public void setNext(Interceptor next) { - this.next=next; - } -} - diff --git a/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/SimpleSource.java b/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/SimpleSource.java deleted file mode 100644 index 5a68024f2a..0000000000 --- a/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/SimpleSource.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * - * 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.mock; - -public interface SimpleSource { - - public void invokeHello() throws Exception; - - public void invokeGoodbye() throws Exception; -} - diff --git a/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/SimpleSourceImpl.java b/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/SimpleSourceImpl.java deleted file mode 100644 index 51025ba3a0..0000000000 --- a/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/SimpleSourceImpl.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * - * 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.mock; - -public class SimpleSourceImpl implements SimpleSource { - - private SimpleTarget proxy; - - public SimpleSourceImpl(SimpleTarget proxy) { - this.proxy = proxy; - } - - public void invokeHello() throws Exception { - proxy.hello("hello"); - } - - public void invokeGoodbye() throws Exception { - proxy.goodbye("hello"); - } - -} - diff --git a/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/SimpleTarget.java b/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/SimpleTarget.java deleted file mode 100644 index e4aabd72a2..0000000000 --- a/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/SimpleTarget.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * - * 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.mock; - -public interface SimpleTarget { - - public String hello(String message) throws Exception; - - public String goodbye(String message) throws Exception; - - public String echo(String message) throws Exception; - -} - diff --git a/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/SimpleTargetImpl.java b/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/SimpleTargetImpl.java deleted file mode 100644 index 16f70c020f..0000000000 --- a/tags/java-stable-20060304/sca/core/src/test/java/org/apache/tuscany/core/invocation/mock/SimpleTargetImpl.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * - * 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.mock; - -public class SimpleTargetImpl implements SimpleTarget { - - public SimpleTargetImpl() { - super(); - } - - public String hello(String message) throws Exception { - return message; - } - - public String goodbye(String message) throws Exception { - return message; - } - - public String echo(String message) throws Exception { - return message; - } - - -} - |