diff options
Diffstat (limited to 'tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire')
13 files changed, 0 insertions, 1067 deletions
diff --git a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationErrorTestCase.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationErrorTestCase.java deleted file mode 100644 index 5e4b3e2f9e..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationErrorTestCase.java +++ /dev/null @@ -1,155 +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.wire; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.core.wire.impl.InvokerInterceptor; -import org.apache.tuscany.core.wire.impl.MessageChannelImpl; -import org.apache.tuscany.core.wire.mock.MockHandler; -import org.apache.tuscany.core.wire.mock.SimpleTarget; -import org.apache.tuscany.core.wire.mock.MockSyncInterceptor; -import org.apache.tuscany.core.wire.mock.SimpleTargetImpl; -import org.apache.tuscany.core.wire.mock.MockStaticInvoker; -import org.apache.tuscany.core.message.Message; -import org.apache.tuscany.core.message.MessageFactory; -import org.apache.tuscany.core.message.impl.MessageFactoryImpl; - -import java.lang.reflect.Method; - -/** - * Tests error propagation through an innvocation - * - * @version $Rev$ $Date$ - */ -public class InvocationConfigurationErrorTestCase extends TestCase { - - - private Method hello; - - private MessageFactory factory = new MessageFactoryImpl(); - - public InvocationConfigurationErrorTestCase() { - super(); - } - - public InvocationConfigurationErrorTestCase(String arg0) { - super(arg0); - } - - public void setUp() throws Exception { - hello = SimpleTarget.class.getMethod("hello", String.class); - } - - public void testInvokeWithHandlers() throws Exception{ - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - MockHandler sourceRequestHandler = new MockHandler(); - MockHandler sourceResponseHandler = new MockHandler(); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addRequestHandler(sourceRequestHandler); - source.addResponseHandler(sourceResponseHandler); - source.addInterceptor(sourceInterceptor); - - TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello); - MockHandler targetRequestHandler = new MockHandler(); - MockHandler targetResponseHandler = new MockHandler(); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addRequestHandler(targetRequestHandler); - target.addResponseHandler(targetResponseHandler); - target.addInterceptor(targetInterceptor); - target.addInterceptor(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 = source.getHeadInterceptor().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{ - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - MockHandler sourceRequestHandler = new MockHandler(); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addRequestHandler(sourceRequestHandler); - source.addInterceptor(sourceInterceptor); - - TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello); - MockHandler targetRequestHandler = new MockHandler(); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addRequestHandler(targetRequestHandler); - target.addInterceptor(targetInterceptor); - target.addInterceptor(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 = source.getHeadInterceptor().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{ - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addInterceptor(sourceInterceptor); - - TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addInterceptor(targetInterceptor); - target.addInterceptor(new InvokerInterceptor()); - - // connect the source to the target - source.setTargetInterceptor(target.getHeadInterceptor()); - source.build(); - target.build(); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Message msg = factory.createMessage(); - msg.setTargetInvoker(invoker); - Message response = source.getHeadInterceptor().invoke(msg); - Assert.assertTrue(response.getBody() instanceof IllegalArgumentException); - Assert.assertEquals(1,sourceInterceptor.getCount()); - Assert.assertEquals(1,targetInterceptor.getCount()); - - } - -} - diff --git a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationTestCase.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationTestCase.java deleted file mode 100644 index 0519573439..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationTestCase.java +++ /dev/null @@ -1,153 +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.wire; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.core.wire.impl.InvokerInterceptor; -import org.apache.tuscany.core.wire.impl.MessageChannelImpl; -import org.apache.tuscany.core.wire.mock.SimpleTarget; -import org.apache.tuscany.core.wire.mock.MockHandler; -import org.apache.tuscany.core.wire.mock.MockSyncInterceptor; -import org.apache.tuscany.core.wire.mock.MockStaticInvoker; -import org.apache.tuscany.core.wire.mock.SimpleTargetImpl; -import org.apache.tuscany.core.message.Message; -import org.apache.tuscany.core.message.MessageFactory; -import org.apache.tuscany.core.message.impl.MessageFactoryImpl; - -import java.lang.reflect.Method; - -public class InvocationConfigurationTestCase extends TestCase { - - private Method hello; - - - private MessageFactory factory = new MessageFactoryImpl(); - - public InvocationConfigurationTestCase() { - super(); - } - - public InvocationConfigurationTestCase(String arg0) { - super(arg0); - } - - public void setUp() throws Exception { - hello = SimpleTarget.class.getMethod("hello", String.class); - } - - /** - * Tests basic wiring of a source to a target, including handlers and interceptors - */ - public void testInvokeWithHandlers() throws Exception { - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - MockHandler sourceRequestHandler = new MockHandler(); - MockHandler sourceResponseHandler = new MockHandler(); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addRequestHandler(sourceRequestHandler); - source.addResponseHandler(sourceResponseHandler); - source.addInterceptor(sourceInterceptor); - - TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello); - MockHandler targetRequestHandler = new MockHandler(); - MockHandler targetResponseHandler = new MockHandler(); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addRequestHandler(targetRequestHandler); - target.addResponseHandler(targetResponseHandler); - target.addInterceptor(targetInterceptor); - target.addInterceptor(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 = source.getHeadInterceptor().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 { - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - MockHandler sourceRequestHandler = new MockHandler(); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addRequestHandler(sourceRequestHandler); - source.addInterceptor(sourceInterceptor); - - TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello); - MockHandler targetRequestHandler = new MockHandler(); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addRequestHandler(targetRequestHandler); - target.addInterceptor(targetInterceptor); - target.addInterceptor(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 = source.getHeadInterceptor().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 { - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addInterceptor(sourceInterceptor); - - TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addInterceptor(targetInterceptor); - target.addInterceptor(new InvokerInterceptor()); - - // connect the source to the target - source.setTargetInterceptor(target.getHeadInterceptor()); - 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 = source.getHeadInterceptor().invoke(msg); - Assert.assertEquals("foo", response.getBody()); - Assert.assertEquals(1, sourceInterceptor.getCount()); - Assert.assertEquals(1, targetInterceptor.getCount()); - } -} diff --git a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/InvocationErrorTestCase.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/InvocationErrorTestCase.java deleted file mode 100644 index 1d04e18757..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/InvocationErrorTestCase.java +++ /dev/null @@ -1,122 +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.wire; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.core.wire.impl.InvokerInterceptor; -import org.apache.tuscany.core.wire.jdk.JDKInvocationHandler; -import org.apache.tuscany.core.wire.mock.MockHandler; -import org.apache.tuscany.core.wire.mock.MockStaticInvoker; -import org.apache.tuscany.core.wire.mock.MockSyncInterceptor; -import org.apache.tuscany.core.message.impl.MessageFactoryImpl; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.Map; - -/** - * Tests handling of exceptions thrown during an wire - * - * @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<InvocationConfiguration>(); - 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()); - SourceInvocationConfiguration invocationConfiguration=new SourceInvocationConfiguration(m); - invocationConfiguration.addInterceptor(new MockSyncInterceptor()); - invocationConfiguration.addRequestHandler(new MockHandler()); - invocationConfiguration.setTargetInvoker(invoker); - invocationConfiguration.setTargetInterceptor(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-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerTestCase.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerTestCase.java deleted file mode 100644 index 28a2da23b5..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInvocationHandlerTestCase.java +++ /dev/null @@ -1,126 +0,0 @@ -/** - * - * Copyright 2005 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.core.wire.jdk; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.core.wire.InvocationConfiguration; -import org.apache.tuscany.core.wire.MethodHashMap; -import org.apache.tuscany.core.wire.SourceInvocationConfiguration; -import org.apache.tuscany.core.wire.TargetInvocationConfiguration; -import org.apache.tuscany.core.wire.mock.SimpleTarget; -import org.apache.tuscany.core.wire.mock.SimpleTargetImpl; -import org.apache.tuscany.core.wire.mock.MockStaticInvoker; -import org.apache.tuscany.core.wire.mock.MockHandler; -import org.apache.tuscany.core.wire.mock.MockSyncInterceptor; -import org.apache.tuscany.core.wire.impl.InvokerInterceptor; -import org.apache.tuscany.core.wire.impl.MessageChannelImpl; -import org.apache.tuscany.core.message.impl.MessageFactoryImpl; - -import java.lang.reflect.Method; -import java.util.Map; - -public class JDKInvocationHandlerTestCase extends TestCase { - - private Method hello; - - public JDKInvocationHandlerTestCase() { - super(); - } - - public JDKInvocationHandlerTestCase(String arg0) { - super(arg0); - } - - public void setUp() throws Exception { - hello = SimpleTarget.class.getMethod("hello", String.class); - } - - public void testBasicInvoke() throws Throwable { - Map<Method, InvocationConfiguration> configs = new MethodHashMap<InvocationConfiguration>(); - 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<InvocationConfiguration>(); - 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 { - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Map<Method, InvocationConfiguration> configs = new MethodHashMap<InvocationConfiguration>(); - 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 { - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Map<Method, InvocationConfiguration> configs = new MethodHashMap<InvocationConfiguration>(); - 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) { - SourceInvocationConfiguration source = new SourceInvocationConfiguration(m); - MockHandler sourceRequestHandler = new MockHandler(); - MockHandler sourceResponseHandler = new MockHandler(); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addRequestHandler(sourceRequestHandler); - source.addResponseHandler(sourceResponseHandler); - source.addInterceptor(sourceInterceptor); - - TargetInvocationConfiguration target = new TargetInvocationConfiguration(m); - MockHandler targetRequestHandler = new MockHandler(); - MockHandler targetResponseHandler = new MockHandler(); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addRequestHandler(targetRequestHandler); - target.addResponseHandler(targetResponseHandler); - target.addInterceptor(targetInterceptor); - target.addInterceptor(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-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKWireFactoryFactoryTestCase.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKWireFactoryFactoryTestCase.java deleted file mode 100644 index 60f8cf837d..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKWireFactoryFactoryTestCase.java +++ /dev/null @@ -1,83 +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.wire.jdk; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.core.context.QualifiedName; -import org.apache.tuscany.core.wire.MethodHashMap; -import org.apache.tuscany.core.wire.WireSourceConfiguration; -import org.apache.tuscany.core.wire.SourceInvocationConfiguration; -import org.apache.tuscany.core.wire.TargetInvocationConfiguration; -import org.apache.tuscany.core.wire.WireTargetConfiguration; -import org.apache.tuscany.core.wire.impl.InvokerInterceptor; -import org.apache.tuscany.core.wire.mock.MockStaticInvoker; -import org.apache.tuscany.core.wire.mock.MockSyncInterceptor; -import org.apache.tuscany.core.wire.mock.SimpleTarget; -import org.apache.tuscany.core.wire.mock.SimpleTargetImpl; -import org.apache.tuscany.core.message.impl.MessageFactoryImpl; - -import java.lang.reflect.Method; -import java.util.Map; - -public class JDKWireFactoryFactoryTestCase extends TestCase { - - private Method hello; - - public JDKWireFactoryFactoryTestCase(String arg0) { - super(arg0); - } - - public void setUp() throws Exception { - hello = SimpleTarget.class.getMethod("hello", String.class); - } - - public void testSourceWireFactory() throws Exception { - SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addInterceptor(sourceInterceptor); - source.setTargetInterceptor(new InvokerInterceptor()); - source.setTargetInvoker(new MockStaticInvoker(hello, new SimpleTargetImpl())); - source.build(); - Map<Method, SourceInvocationConfiguration> configs = new MethodHashMap<SourceInvocationConfiguration>(); - configs.put(hello, source); - WireSourceConfiguration config = new WireSourceConfiguration("foo",new QualifiedName("foo"), configs, Thread.currentThread() - .getContextClassLoader(), new MessageFactoryImpl()); - JDKSourceWireFactory factory = new JDKSourceWireFactory(); - factory.setConfiguration(config); - factory.setBusinessInterface(SimpleTarget.class); - factory.initialize(); - SimpleTarget instance = (SimpleTarget) factory.createProxy(); - Assert.assertEquals("foo",instance.hello("foo")); - } - - public void testTargetWireFactory() throws Exception { - TargetInvocationConfiguration source = new TargetInvocationConfiguration(hello); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addInterceptor(sourceInterceptor); - source.addInterceptor(new InvokerInterceptor()); - source.setTargetInvoker(new MockStaticInvoker(hello, new SimpleTargetImpl())); - source.build(); - Map<Method, TargetInvocationConfiguration> configs = new MethodHashMap<TargetInvocationConfiguration>(); - configs.put(hello, source); - WireTargetConfiguration config = new WireTargetConfiguration(new QualifiedName("foo"), configs, Thread.currentThread() - .getContextClassLoader(), new MessageFactoryImpl()); - JDKTargetWireFactory factory = new JDKTargetWireFactory(); - factory.setConfiguration(config); - factory.setBusinessInterface(SimpleTarget.class); - factory.initialize(); - SimpleTarget instance = (SimpleTarget) factory.createProxy(); - Assert.assertEquals("foo",instance.hello("foo")); - } -} diff --git a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/MockHandler.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/MockHandler.java deleted file mode 100644 index 9def6b5b0e..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/MockHandler.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * - * Copyright 2005 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.core.wire.mock; - -import org.apache.tuscany.core.wire.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-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/MockScopeContext.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/MockScopeContext.java deleted file mode 100644 index 915885549a..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/MockScopeContext.java +++ /dev/null @@ -1,131 +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.wire.mock; - -import org.apache.tuscany.core.builder.ContextFactory; -import org.apache.tuscany.core.context.ScopeContext; -import org.apache.tuscany.core.context.RuntimeEventListener; -import org.apache.tuscany.core.context.ContextRuntimeException; -import org.apache.tuscany.core.context.AtomicContext; -import org.apache.tuscany.core.context.ScopeRuntimeException; -import org.apache.tuscany.core.context.QualifiedName; -import org.apache.tuscany.core.context.Context; -import org.apache.tuscany.core.context.EventFilter; -import org.apache.tuscany.core.context.event.Event; -import org.apache.tuscany.model.assembly.AtomicComponent; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class MockScopeContext implements ScopeContext { - - Map<String, Object> components; - - public MockScopeContext() { - components = new HashMap<String, Object>(); - 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 void publish(Event object) { - //To change body of implemented methods use File | Settings | File Templates. - } - - public void addListener(RuntimeEventListener listener) throws ContextRuntimeException { - } - - public void addListener(EventFilter filter, RuntimeEventListener listener) { - //To change body of implemented methods use File | Settings | File Templates. - } - - public void removeListener(RuntimeEventListener listener) throws ContextRuntimeException { - } - - public String getName() { - return "Mock Scope Container"; - } - - public boolean isCacheable() { - return false; - } - - public int[] getEventTypes() { - return null; - } - - public AtomicContext getContext(String name) { - return null; - } - - public Object getInstance(QualifiedName name) throws ScopeRuntimeException { - return components.get(name.getPartName()); - } - - public AtomicContext getContextByKey(String name, Object key) { - return null; - } - - public void setComponent(AtomicComponent component) throws ScopeRuntimeException { - } - - public void removeContext(String name) throws ScopeRuntimeException { - } - - public void removeContextByKey(String name, Object key) throws ScopeRuntimeException { - } - - public AtomicComponent[] getComponents() { - return null; - } - - - public void registerFactories(List<ContextFactory<Context>> configurations) { - } - - public void registerFactory(ContextFactory<Context> configuration) { - } - - public int getLifecycleState(){ - return RUNNING; - } - - - public void setLifecycleState(int state) { - } - - - public void setName(String name) { - } - - - public void onEvent(Event event) { - //To change body of implemented methods use File | Settings | File Templates. - } -} - diff --git a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/MockStaticInvoker.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/MockStaticInvoker.java deleted file mode 100644 index 66e8579cb4..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/MockStaticInvoker.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * - * Copyright 2005 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.core.wire.mock; - -import org.apache.tuscany.core.wire.Interceptor; -import org.apache.tuscany.core.wire.InvocationRuntimeException; -import org.apache.tuscany.core.wire.TargetInvoker; -import org.apache.tuscany.core.message.Message; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -/** - * Caches component instances that do not need to be resolved for every wire, e.g. an wire 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() throws CloneNotSupportedException { - 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-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/MockSyncInterceptor.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/MockSyncInterceptor.java deleted file mode 100644 index a64caed8eb..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/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.wire.mock; - -import org.apache.tuscany.core.wire.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-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/SimpleSource.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/SimpleSource.java deleted file mode 100644 index 8e8af9ec18..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/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.wire.mock; - -public interface SimpleSource { - - public void invokeHello() throws Exception; - - public void invokeGoodbye() throws Exception; -} - diff --git a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/SimpleSourceImpl.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/SimpleSourceImpl.java deleted file mode 100644 index 900fa9c324..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/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.wire.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-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/SimpleTarget.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/SimpleTarget.java deleted file mode 100644 index d63d3a0565..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/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.wire.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-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/SimpleTargetImpl.java b/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/mock/SimpleTargetImpl.java deleted file mode 100644 index 1b6fe93ac8..0000000000 --- a/tags/java-M1-20060522/java/sca/core/src/test/java/org/apache/tuscany/core/wire/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.wire.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; - } - - -} - |