diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:13:31 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:13:31 +0000 |
commit | 3caf8614f25d6b1962e20331fdf423c863bc02f3 (patch) | |
tree | 069fa30b63dd4804846385d8571928bdaa7b73ad /branches/sca-java-integration/sca/kernel/core/src/test/java/org | |
parent | 6d0e93c68d3aeaeb4bb6d96ac0460eec40ef786e (diff) |
Moving 1.x branches
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835144 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-integration/sca/kernel/core/src/test/java/org')
289 files changed, 0 insertions, 31694 deletions
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/AbstractLocalTargetInvokerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/AbstractLocalTargetInvokerTestCase.java deleted file mode 100644 index 8dc0023332..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/AbstractLocalTargetInvokerTestCase.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.binding.local; - -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.TargetInvoker; - -import junit.framework.TestCase; -import org.apache.tuscany.core.mock.wire.MockTargetInvoker; -import org.easymock.EasyMock; -import org.easymock.IAnswer; - -/** - * @version $Rev$ $Date$ - */ -public class AbstractLocalTargetInvokerTestCase extends TestCase { - - public void testInvokerWithInterceptor() throws Throwable { - AbstractLocalTargetInvoker invoker = new MockTargetInvoker(); - Interceptor interceptor = EasyMock.createMock(Interceptor.class); - interceptor.invoke(EasyMock.isA(Message.class)); - EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() { - public Object answer() throws Throwable { - Message msg = (Message) EasyMock.getCurrentArguments()[0]; - if (msg.getTargetInvoker() == null) { - fail("Target invoker not set"); - } - return null; - } - }); - EasyMock.replay(interceptor); - OutboundInvocationChain chain = EasyMock.createMock(OutboundInvocationChain.class); - EasyMock.expect(chain.getHeadInterceptor()).andReturn(interceptor); - EasyMock.replay(chain); - invoker.invoke(chain, EasyMock.createNiceMock(TargetInvoker.class), new MessageImpl()); - EasyMock.verify(chain); - EasyMock.verify(interceptor); - } - - public void testShortCircuitInvoke() throws Throwable { - AbstractLocalTargetInvoker invoker = new MockTargetInvoker(); - TargetInvoker targetInvoker = EasyMock.createMock(TargetInvoker.class); - EasyMock.expect(targetInvoker.invoke(EasyMock.isA(Message.class))).andReturn(new MessageImpl()); - EasyMock.replay(targetInvoker); - OutboundInvocationChain chain = EasyMock.createMock(OutboundInvocationChain.class); - EasyMock.expect(chain.getHeadInterceptor()).andReturn(null); - EasyMock.replay(chain); - invoker.invoke(chain, targetInvoker, new MessageImpl()); - EasyMock.verify(chain); - EasyMock.verify(targetInvoker); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingBuilderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingBuilderTestCase.java deleted file mode 100644 index 90f02e80a6..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingBuilderTestCase.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.binding.local; - -import org.apache.tuscany.spi.component.ServiceBinding; -import org.apache.tuscany.spi.model.ServiceDefinition; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class LocalBindingBuilderTestCase extends TestCase { - - public void testBuild() throws Exception { - LocalBindingBuilder builder = new LocalBindingBuilder(); - ServiceDefinition def = new ServiceDefinition(); - def.setName("foo"); - ServiceBinding binding = builder.build(null, def, null, null); - assertEquals(LocalServiceBinding.class, binding.getClass()); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingLoaderTestCase.java deleted file mode 100644 index 1633d5f8ea..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingLoaderTestCase.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.binding.local; - -import java.net.URI; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.spi.loader.LoaderException; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class LocalBindingLoaderTestCase extends TestCase { - private LocalBindingLoader loader; - - public void testParse() throws Exception { - XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class); - EasyMock.expect(reader.getAttributeValue(null, "uri")).andReturn("foo"); - EasyMock.replay(reader); - LocalBindingDefinition definition = loader.load(null, null, reader, null); - assertEquals(new URI("foo"), definition.getTargetUri()); - EasyMock.verify(reader); - } - - public void testNoUri() throws Exception { - XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class); - EasyMock.expect(reader.getAttributeValue(null, "uri")).andReturn(null); - EasyMock.replay(reader); - LocalBindingDefinition definition = loader.load(null, null, reader, null); - assertNull(definition.getTargetUri()); - EasyMock.verify(reader); - } - - public void testBadUri() throws Exception { - XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class); - EasyMock.expect(reader.getAttributeValue(null, "uri")).andReturn("foo foo"); - EasyMock.replay(reader); - try { - loader.load(null, null, reader, null); - fail(); - } catch (LoaderException e) { - // expected - } - EasyMock.verify(reader); - } - - protected void setUp() throws Exception { - super.setUp(); - loader = new LocalBindingLoader(null); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerInvocationExceptionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerInvocationExceptionTestCase.java deleted file mode 100644 index 1976170f54..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerInvocationExceptionTestCase.java +++ /dev/null @@ -1,86 +0,0 @@ -package org.apache.tuscany.core.binding.local; - -import java.lang.reflect.Type; -import java.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class LocalCallbackTargetInvokerInvocationExceptionTestCase extends TestCase { - private InboundWire wire; - private Message message; - private OutboundInvocationChain chain; - private LocalCallbackTargetInvoker invoker; - - /** - * Verfies an InvocationTargetException thrown when invoking the target is propagated to the client correctly and - * the originating error is unwrapped - */ - public void testThrowableTargetInvocation() throws Exception { - Message response = invoker.invoke(message); - assertTrue(response.isFault()); - Object body = response.getBody(); - assertTrue(SomeException.class.equals(body.getClass())); - EasyMock.verify(wire); - EasyMock.verify(chain); - } - - protected void setUp() throws Exception { - super.setUp(); - Object targetAddress = new Object(); - message = new MessageImpl(); - message.pushFromAddress(targetAddress); - message.setBody("foo"); - Message response = new MessageImpl(); - response.setBody("response"); - Operation<Type> operation = new Operation<Type>("echo", null, null, null); - Interceptor head = new ErrorInterceptor(); - chain = EasyMock.createMock(OutboundInvocationChain.class); - EasyMock.expect(chain.getTargetInvoker()).andReturn(null); - EasyMock.expect(chain.getHeadInterceptor()).andReturn(head); - EasyMock.replay(chain); - Map<Operation<?>, OutboundInvocationChain> chains = new HashMap<Operation<?>, OutboundInvocationChain>(); - chains.put(operation, chain); - wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getSourceCallbackInvocationChains(targetAddress)).andReturn(chains); - EasyMock.replay(wire); - invoker = new LocalCallbackTargetInvoker(operation, wire); - } - - private class SomeException extends Exception { - - } - - private class ErrorInterceptor implements Interceptor { - - public Message invoke(Message msg) { - msg.setBodyWithFault(new SomeException()); - return msg; - } - - public void setNext(Interceptor next) { - - } - - public Interceptor getNext() { - return null; - } - - public boolean isOptimizable() { - return false; - } - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerTestCase.java deleted file mode 100644 index 123f32d66a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerTestCase.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.binding.local; - -import java.lang.reflect.Type; -import java.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class LocalCallbackTargetInvokerTestCase extends TestCase { - private InboundWire wire; - private Message message; - private OutboundInvocationChain chain; - private Interceptor head; - private LocalCallbackTargetInvoker invoker; - - /** - * Verfies the normal execution path through a callback - */ - public void testNormalPathMessageInvocation() throws Exception { - Message response = invoker.invoke(message); - assertEquals("response", response.getBody()); - EasyMock.verify(wire); - EasyMock.verify(chain); - EasyMock.verify(head); - } - - protected void setUp() throws Exception { - super.setUp(); - Object targetAddress = new Object(); - message = new MessageImpl(); - message.pushFromAddress(targetAddress); - message.setBody("foo"); - Message response = new MessageImpl(); - response.setBody("response"); - Operation<Type> operation = new Operation<Type>("echo", null, null, null); - head = EasyMock.createMock(Interceptor.class); - EasyMock.expect(head.invoke(EasyMock.isA(Message.class))).andReturn(response); - EasyMock.replay(head); - chain = EasyMock.createMock(OutboundInvocationChain.class); - EasyMock.expect(chain.getTargetInvoker()).andReturn(null); - EasyMock.expect(chain.getHeadInterceptor()).andReturn(head); - EasyMock.replay(chain); - Map<Operation<?>, OutboundInvocationChain> chains = new HashMap<Operation<?>, OutboundInvocationChain>(); - chains.put(operation, chain); - wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getSourceCallbackInvocationChains(targetAddress)).andReturn(chains); - EasyMock.replay(wire); - - invoker = new LocalCallbackTargetInvoker(operation, wire); - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerThrowableTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerThrowableTestCase.java deleted file mode 100644 index 9c1bbc616e..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerThrowableTestCase.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.binding.local; - -import java.lang.reflect.Type; -import java.lang.reflect.UndeclaredThrowableException; -import java.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; - -import junit.framework.TestCase; -import org.easymock.EasyMock; -import org.easymock.IAnswer; - -/** - * @version $Rev$ $Date$ - */ -public class LocalCallbackTargetInvokerThrowableTestCase extends TestCase { - private InboundWire wire; - private Message message; - private OutboundInvocationChain chain; - private Interceptor head; - private LocalCallbackTargetInvoker invoker; - - /** - * Verfies an exception thrown in the target is propagated to the client correctly - */ - public void testThrowableTargetInvocation() throws Exception { - Message response = invoker.invoke(message); - assertTrue(response.isFault()); - Object body = response.getBody(); - if (!(body instanceof UndeclaredThrowableException)) { - fail(); // EasyMock wraps the Throwable in an UndeclaredThrowableException - } - UndeclaredThrowableException e = (UndeclaredThrowableException) body; - assertTrue(InsidiousException.class.equals(e.getUndeclaredThrowable().getClass())); - EasyMock.verify(wire); - EasyMock.verify(chain); - EasyMock.verify(head); - } - - @SuppressWarnings("unchecked") - protected void setUp() throws Exception { - super.setUp(); - Object targetAddress = new Object(); - message = new MessageImpl(); - message.pushFromAddress(targetAddress); - message.setBody("foo"); - Message response = new MessageImpl(); - response.setBody("response"); - Operation<Type> operation = new Operation<Type>("echo", null, null, null); - head = EasyMock.createMock(Interceptor.class); - EasyMock.expect(head.invoke(EasyMock.isA(Message.class))).andStubAnswer(new IAnswer() { - public Object answer() throws Throwable { - throw new InsidiousException(); // andThrow() does not seem to work here - } - }); - EasyMock.replay(head); - chain = EasyMock.createMock(OutboundInvocationChain.class); - EasyMock.expect(chain.getTargetInvoker()).andReturn(null); - EasyMock.expect(chain.getHeadInterceptor()).andReturn(head); - EasyMock.replay(chain); - Map<Operation<?>, OutboundInvocationChain> chains = new HashMap<Operation<?>, OutboundInvocationChain>(); - chains.put(operation, chain); - wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getSourceCallbackInvocationChains(targetAddress)).andReturn(chains); - EasyMock.replay(wire); - invoker = new LocalCallbackTargetInvoker(operation, wire); - } - - private class InsidiousException extends Throwable { - - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java deleted file mode 100644 index a313d341ed..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.binding.local; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.component.SCAObject; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.TargetInvoker; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class LocalTargetInvokerTestCase extends TestCase { - private ServiceContract<Object> serviceContract; - private Operation<Object> operation; - - public void testInvoke() { - TargetInvoker targetInvoker = EasyMock.createMock(TargetInvoker.class); - EasyMock.expect(targetInvoker.invoke(EasyMock.isA(Message.class))).andReturn(new MessageImpl()); - EasyMock.replay(targetInvoker); - OutboundInvocationChain chain = EasyMock.createNiceMock(OutboundInvocationChain.class); - EasyMock.expect(chain.getTargetInvoker()).andReturn(targetInvoker); - EasyMock.replay(chain); - Map<Operation<?>, OutboundInvocationChain> chains = new HashMap<Operation<?>, OutboundInvocationChain>(); - chains.put(operation, chain); - OutboundWire wire = EasyMock.createNiceMock(OutboundWire.class); - wire.getInvocationChains(); - EasyMock.expectLastCall().andReturn(chains); - EasyMock.expect(wire.getServiceContract()).andReturn(serviceContract); - EasyMock.replay(wire); - TargetInvoker invoker = new LocalTargetInvoker(operation, wire); - Message msg = invoker.invoke(new MessageImpl()); - assertFalse(msg.isFault()); - EasyMock.verify(targetInvoker); - } - - public void testCallbackSetInvoke() { - ServiceContract<?> contract = new ServiceContract<Object>() { - - }; - contract.setCallbackClass(Object.class); - TargetInvoker targetInvoker = EasyMock.createMock(TargetInvoker.class); - EasyMock.expect(targetInvoker.invoke(EasyMock.isA(Message.class))).andReturn(new MessageImpl()); - EasyMock.replay(targetInvoker); - OutboundInvocationChain chain = EasyMock.createNiceMock(OutboundInvocationChain.class); - EasyMock.expect(chain.getTargetInvoker()).andReturn(targetInvoker); - EasyMock.replay(chain); - Map<Operation<?>, OutboundInvocationChain> chains = new HashMap<Operation<?>, OutboundInvocationChain>(); - chains.put(operation, chain); - SCAObject container = EasyMock.createMock(SCAObject.class); - EasyMock.expect(container.getName()).andReturn("foo").atLeastOnce(); - EasyMock.replay(container); - OutboundWire wire = EasyMock.createNiceMock(OutboundWire.class); - EasyMock.expect(wire.getContainer()).andReturn(container).atLeastOnce(); - wire.getInvocationChains(); - EasyMock.expectLastCall().andReturn(chains); - EasyMock.expect(wire.getServiceContract()).andReturn(contract); - EasyMock.replay(wire); - TargetInvoker invoker = new LocalTargetInvoker(operation, wire); - Message msg = EasyMock.createMock(Message.class); - msg.pushFromAddress(EasyMock.eq("foo")); - EasyMock.replay(msg); - invoker.invoke(msg); - EasyMock.verify(msg); - EasyMock.verify(targetInvoker); - } - - public void testFaultInvoke() { - TargetInvoker targetInvoker = EasyMock.createMock(TargetInvoker.class); - EasyMock.expect(targetInvoker.invoke(EasyMock.isA(Message.class))).andThrow(new TestException()); - EasyMock.replay(targetInvoker); - OutboundInvocationChain chain = EasyMock.createNiceMock(OutboundInvocationChain.class); - EasyMock.expect(chain.getTargetInvoker()).andReturn(targetInvoker); - EasyMock.replay(chain); - Map<Operation<?>, OutboundInvocationChain> chains = new HashMap<Operation<?>, OutboundInvocationChain>(); - chains.put(operation, chain); - OutboundWire wire = EasyMock.createNiceMock(OutboundWire.class); - wire.getInvocationChains(); - EasyMock.expectLastCall().andReturn(chains); - EasyMock.expect(wire.getServiceContract()).andReturn(serviceContract); - EasyMock.replay(wire); - TargetInvoker invoker = new LocalTargetInvoker(operation, wire); - Message msg = invoker.invoke(new MessageImpl()); - assertTrue(msg.isFault()); - assertTrue(msg.getBody() instanceof TestException); - EasyMock.verify(targetInvoker); - } - - - protected void setUp() throws Exception { - super.setUp(); - serviceContract = new ServiceContract<Object>() { - }; - operation = new Operation<Object>("foo", null, null, null); - } - - - private class TestException extends RuntimeException { - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/bootstrap/BootstrapperTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/bootstrap/BootstrapperTestCase.java deleted file mode 100644 index 728902e82b..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/bootstrap/BootstrapperTestCase.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.bootstrap; - -import junit.framework.TestCase; - -import org.apache.tuscany.core.deployer.DeployerImpl; -import org.apache.tuscany.core.monitor.NullMonitorFactory; - -/** - * Verifies the default bootstrapper can be instantiated - * - * @version $Rev$ $Date$ - */ -public class BootstrapperTestCase extends TestCase { - private Bootstrapper bootstrapper; - - public void testDeployerBootstrap() { - DeployerImpl deployer = (DeployerImpl) bootstrapper.createDeployer(); - } - - protected void setUp() throws Exception { - super.setUp(); - bootstrapper = new DefaultBootstrapper(new NullMonitorFactory(), null, null); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractConnectorImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractConnectorImplTestCase.java deleted file mode 100644 index b828262d6e..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AbstractConnectorImplTestCase.java +++ /dev/null @@ -1,306 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.builder; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.xml.namespace.QName; - -import org.apache.tuscany.spi.QualifiedName; -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.ReferenceBinding; -import org.apache.tuscany.spi.component.Service; -import org.apache.tuscany.spi.component.ServiceBinding; -import org.apache.tuscany.spi.component.TargetInvokerCreationException; -import org.apache.tuscany.spi.idl.java.JavaServiceContract; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.InvocationRuntimeException; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.TargetInvoker; -import org.apache.tuscany.spi.wire.WireService; - -import junit.framework.TestCase; -import org.apache.tuscany.core.binding.local.LocalReferenceBinding; -import org.apache.tuscany.core.binding.local.LocalServiceBinding; -import org.apache.tuscany.core.implementation.composite.ServiceImpl; -import org.apache.tuscany.core.mock.binding.MockServiceBinding; -import org.apache.tuscany.core.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InboundWireImpl; -import org.apache.tuscany.core.wire.InvokerInterceptor; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; -import org.apache.tuscany.core.wire.SynchronousBridgingInterceptor; -import org.apache.tuscany.core.wire.jdk.JDKWireService; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public abstract class AbstractConnectorImplTestCase extends TestCase { - protected static final String TARGET = "target"; - protected static final QualifiedName TARGET_NAME = new QualifiedName(TARGET); - protected static final String TARGET_SERVICE = "FooService"; - protected static final QualifiedName TARGET_SERVICE_NAME = new QualifiedName("target/FooService"); - protected static final String RESPONSE = "response"; - - protected ConnectorImpl connector; - protected ServiceContract contract; - protected Operation<Type> operation; - - protected void setUp() throws Exception { - super.setUp(); - WireService wireService = new JDKWireService(null, null); - connector = new ConnectorImpl(wireService, null, null, null); - contract = new JavaServiceContract(Foo.class); - operation = new Operation<Type>("bar", null, null, null); - } - - protected AtomicComponent createAtomicTarget() throws Exception { - InboundInvocationChain chain = new InboundInvocationChainImpl(operation); - chain.addInterceptor(new InvokerInterceptor()); - InboundWire targetWire = new InboundWireImpl(); - targetWire.setServiceContract(contract); - targetWire.addInvocationChain(operation, chain); - - MockInvoker mockInvoker = new MockInvoker(); - - // create the target - AtomicComponent target = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(target.getName()).andReturn(TARGET).anyTimes(); - EasyMock.expect(target.isOptimizable()).andReturn(false).anyTimes(); - EasyMock.expect(target.getScope()).andReturn(Scope.COMPOSITE).atLeastOnce(); - EasyMock.expect(target.isSystem()).andReturn(false).atLeastOnce(); - target.getInboundWire(EasyMock.eq(TARGET_SERVICE)); - EasyMock.expectLastCall().andReturn(targetWire).atLeastOnce(); - target.createTargetInvoker(EasyMock.eq(TARGET_SERVICE), EasyMock.eq(operation), EasyMock.eq(targetWire)); - EasyMock.expectLastCall().andReturn(mockInvoker); - EasyMock.replay(target); - targetWire.setContainer(target); - return target; - } - - protected AtomicComponent createAtomicSource(CompositeComponent parent) throws Exception { - // create the outbound wire and chain from the source component - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - - OutboundWire outboundWire = new OutboundWireImpl(); - outboundWire.setTargetName(TARGET_SERVICE_NAME); - outboundWire.setServiceContract(contract); - outboundWire.addInvocationChain(operation, outboundChain); - - Map<String, List<OutboundWire>> outboundWires = new HashMap<String, List<OutboundWire>>(); - List<OutboundWire> list = new ArrayList<OutboundWire>(); - list.add(outboundWire); - outboundWires.put(TARGET_SERVICE, list); - - // create the source - AtomicComponent source = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(source.isSystem()).andReturn(false).atLeastOnce(); - EasyMock.expect(source.getScope()).andReturn(Scope.COMPOSITE); - EasyMock.expect(source.getParent()).andReturn(parent).atLeastOnce(); - EasyMock.expect(source.getOutboundWires()).andReturn(outboundWires).atLeastOnce(); - EasyMock.expect(source.getName()).andReturn("source").atLeastOnce(); - source.getInboundWires(); - EasyMock.expectLastCall().andReturn(Collections.emptyList()); - EasyMock.replay(source); - - outboundWire.setContainer(source); - return source; - } - - - protected Service createServiceNonLocalBinding() throws WireConnectException { - QName qName = new QName("foo", "bar"); - ServiceBinding serviceBinding = new MockServiceBinding(); - InboundInvocationChain targetInboundChain = new InboundInvocationChainImpl(operation); - targetInboundChain.addInterceptor(new SynchronousBridgingInterceptor()); - InboundWire serviceInboundWire = new InboundWireImpl(qName); - serviceInboundWire.setServiceContract(contract); - serviceInboundWire.addInvocationChain(operation, targetInboundChain); - serviceInboundWire.setContainer(serviceBinding); - - OutboundInvocationChain targetOutboundChain = new OutboundInvocationChainImpl(operation); - // place an invoker interceptor on the end - targetOutboundChain.addInterceptor(new InvokerInterceptor()); - OutboundWire targetOutboundWire = new OutboundWireImpl(qName); - targetOutboundWire.setServiceContract(contract); - targetOutboundWire.addInvocationChain(operation, targetOutboundChain); - targetOutboundWire.setContainer(serviceBinding); - - serviceBinding.setInboundWire(serviceInboundWire); - serviceBinding.setOutboundWire(targetOutboundWire); - // manually connect the service chains - connector.connect(targetInboundChain, targetOutboundChain); - Service service = new ServiceImpl(TARGET, null, contract); - service.addServiceBinding(serviceBinding); - return service; - } - - /** - * Creates a service configured with the local binding and places an invoker interceptor on the end of each outbound - * chain for invocation testing without needing to wire the service to a target - * - * @throws org.apache.tuscany.core.builder.WireConnectException - * - */ - protected Service createLocalService(CompositeComponent parent) throws WireConnectException { - LocalServiceBinding serviceBinding = new LocalServiceBinding(TARGET, parent); - InboundInvocationChain targetInboundChain = new InboundInvocationChainImpl(operation); - targetInboundChain.addInterceptor(new SynchronousBridgingInterceptor()); - InboundWire localServiceInboundWire = new InboundWireImpl(); - localServiceInboundWire.setServiceContract(contract); - localServiceInboundWire.addInvocationChain(operation, targetInboundChain); - localServiceInboundWire.setContainer(serviceBinding); - - OutboundInvocationChain targetOutboundChain = new OutboundInvocationChainImpl(operation); - // place an invoker interceptor on the end - targetOutboundChain.addInterceptor(new InvokerInterceptor()); - OutboundWire targetOutboundWire = new OutboundWireImpl(); - targetOutboundWire.setServiceContract(contract); - targetOutboundWire.addInvocationChain(operation, targetOutboundChain); - targetOutboundWire.setContainer(serviceBinding); - - serviceBinding.setInboundWire(localServiceInboundWire); - serviceBinding.setOutboundWire(targetOutboundWire); - // manually connect the service chains - connector.connect(targetInboundChain, targetOutboundChain); - Service service = new ServiceImpl(TARGET, null, contract); - service.addServiceBinding(serviceBinding); - return service; - } - - protected ReferenceBinding createLocalReferenceBinding(QualifiedName target) - throws TargetInvokerCreationException { - ReferenceBinding referenceBinding = new LocalReferenceBinding("local", null); - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - InboundWire referenceInboundWire = new InboundWireImpl(); - referenceInboundWire.setServiceContract(contract); - referenceInboundWire.setContainer(referenceBinding); - referenceInboundWire.addInvocationChain(operation, inboundChain); - - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - // Outbound chains always contains at least one interceptor - outboundChain.addInterceptor(new SynchronousBridgingInterceptor()); - OutboundWire outboundWire = new OutboundWireImpl(); - outboundWire.setServiceContract(contract); - outboundWire.setTargetName(target); - outboundWire.addInvocationChain(operation, outboundChain); - outboundWire.setContainer(referenceBinding); - - referenceBinding.setInboundWire(referenceInboundWire); - referenceBinding.setOutboundWire(outboundWire); - - return referenceBinding; - } - - protected InboundWire createLocalInboundWire(CompositeComponent parent) throws WireConnectException { - InboundInvocationChain chain = new InboundInvocationChainImpl(operation); - chain.addInterceptor(new SynchronousBridgingInterceptor()); - InboundWire wire = new InboundWireImpl(); - wire.setServiceContract(contract); - LocalReferenceBinding referenceBinding = new LocalReferenceBinding("", parent); - wire.setContainer(referenceBinding); - wire.addInvocationChain(operation, chain); - - OutboundInvocationChain targetOutboundChain = new OutboundInvocationChainImpl(operation); - // place an invoker interceptor on the end - targetOutboundChain.addInterceptor(new InvokerInterceptor()); - OutboundWire targetOutboundWire = new OutboundWireImpl(); - targetOutboundWire.setServiceContract(contract); - targetOutboundWire.addInvocationChain(operation, targetOutboundChain); - referenceBinding.setInboundWire(wire); - referenceBinding.setOutboundWire(targetOutboundWire); - // manually connect the service chains - connector.connect(chain, targetOutboundChain); - return wire; - } - - protected static class MockInvoker implements TargetInvoker { - public Object invokeTarget(final Object payload, final short sequence) throws InvocationTargetException { - return null; - } - - public Message invoke(Message msg) throws InvocationRuntimeException { - Message resp = new MessageImpl(); - resp.setBody(RESPONSE); - return resp; - } - - public boolean isCacheable() { - return false; - } - - public void setCacheable(boolean cacheable) { - - } - - public boolean isOptimizable() { - return false; - } - - public Object clone() throws CloneNotSupportedException { - return super.clone(); - } - } - - protected static class MockInterceptor implements Interceptor { - private Interceptor next; - private boolean invoked; - - public Message invoke(Message msg) { - invoked = true; - return next.invoke(msg); - } - - public void setNext(Interceptor next) { - this.next = next; - } - - public Interceptor getNext() { - return next; - } - - public boolean isInvoked() { - return invoked; - } - - public boolean isOptimizable() { - return false; - } - } - - protected interface Foo { - String echo(); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java deleted file mode 100644 index f89ba7ea8d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/AtomicConnectorTestCase.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.builder; - -import java.util.List; -import java.util.Map; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.Service; -import org.apache.tuscany.spi.component.ServiceBinding; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; - -import org.apache.tuscany.core.implementation.composite.ServiceImpl; -import org.apache.tuscany.core.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InboundWireImpl; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class AtomicConnectorTestCase extends AbstractConnectorImplTestCase { - - public void testConnectSynchronousServiceWiresToAtomicTarget() throws Exception { - AtomicComponent target = createAtomicTarget(); - - // create the parent composite - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(parent.getChild("target")).andReturn(target); - EasyMock.replay(parent); - - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.addInvocationChain(operation, inboundChain); - inboundWire.setServiceContract(contract); - - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - OutboundWire outboundWire = new OutboundWireImpl(); - outboundWire.setTargetName(TARGET_SERVICE_NAME); - outboundWire.addInvocationChain(operation, outboundChain); - outboundWire.setServiceContract(contract); - - // create the binding - ServiceBinding binding = EasyMock.createMock(ServiceBinding.class); - EasyMock.expect(binding.getName()).andReturn("source"); - binding.setService(EasyMock.isA(Service.class)); - EasyMock.expect(binding.isSystem()).andReturn(false).atLeastOnce(); - EasyMock.expect(binding.getInboundWire()).andReturn(inboundWire).atLeastOnce(); - EasyMock.expect(binding.getOutboundWire()).andReturn(outboundWire); - EasyMock.expect(binding.getScope()).andReturn(Scope.SYSTEM); - EasyMock.replay(binding); - - outboundWire.setContainer(binding); - inboundWire.setContainer(binding); - - Service service = new ServiceImpl("foo", parent, null); - service.addServiceBinding(binding); - - connector.connect(service); - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(inboundChain.getTargetInvoker()); - Message resp = inboundChain.getHeadInterceptor().invoke(msg); - assertEquals(RESPONSE, resp.getBody()); - EasyMock.verify(binding); - } - - public void testConnectNonBlockingServiceWiresToAtomicTarget() throws Exception { - // JFM FIXME - } - - public void testConnectCallbackServiceWiresToAtomicTarget() throws Exception { - // JFM FIXME - } - - /** - * Verifies connecting a wire from an atomic component to a target atomic component with one synchronous operation - */ - public void testConnectAtomicComponentToAtomicComponentSyncWire() throws Exception { - - AtomicComponent target = createAtomicTarget(); - // create the parent composite - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(parent.getChild("target")).andReturn(target); - EasyMock.replay(parent); - AtomicComponent source = createAtomicSource(parent); - connector.connect(source); - - MessageImpl msg = new MessageImpl(); - Map<String, List<OutboundWire>> wires = source.getOutboundWires(); - OutboundWire wire = wires.get(TARGET_SERVICE).get(0); - OutboundInvocationChain chain = wire.getInvocationChains().get(operation); - msg.setTargetInvoker(chain.getTargetInvoker()); - Message resp = chain.getHeadInterceptor().invoke(msg); - assertEquals(RESPONSE, resp.getBody()); - } - - protected void setUp() throws Exception { - super.setUp(); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryNoBindingsTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryNoBindingsTestCase.java deleted file mode 100644 index 16f2846921..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryNoBindingsTestCase.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.builder; - -import java.net.URI; - -import org.apache.tuscany.spi.builder.BuilderRegistry; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.Reference; -import org.apache.tuscany.spi.component.ReferenceBinding; -import org.apache.tuscany.spi.component.Service; -import org.apache.tuscany.spi.component.ServiceBinding; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.model.ComponentTypeReferenceDefinition; -import org.apache.tuscany.spi.model.Multiplicity; -import org.apache.tuscany.spi.model.AbstractReferenceDefinition; -import org.apache.tuscany.spi.model.ServiceDefinition; - -import junit.framework.TestCase; -import org.apache.tuscany.core.binding.local.LocalBindingBuilder; -import org.apache.tuscany.core.binding.local.LocalBindingDefinition; -import org.apache.tuscany.core.binding.local.LocalReferenceBinding; -import org.apache.tuscany.core.binding.local.LocalServiceBinding; -import org.apache.tuscany.core.deployer.RootDeploymentContext; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class BuilderRegistryNoBindingsTestCase extends TestCase { - private DeploymentContext deploymentContext; - private CompositeComponent parent; - private BuilderRegistry registry; - - public void testNoServiceBindings() throws Exception { - ServiceBinding binding = EasyMock.createNiceMock(ServiceBinding.class); - EasyMock.replay(binding); - ServiceDefinition definition = new ServiceDefinition("foo", null, false); - definition.setTarget(new URI("foo")); - Service service = registry.build(parent, definition, deploymentContext); - assertEquals(1, service.getServiceBindings().size()); - assertTrue(service.getServiceBindings().get(0) instanceof LocalServiceBinding); - } - - public void testReferenceBindingBuilderDispatch() throws Exception { - ReferenceBinding binding = EasyMock.createNiceMock(ReferenceBinding.class); - EasyMock.replay(binding); - AbstractReferenceDefinition definition = new ComponentTypeReferenceDefinition("foo", null, Multiplicity.ONE_ONE); - Reference reference = registry.build(parent, definition, deploymentContext); - assertEquals(1, reference.getReferenceBindings().size()); - assertTrue(reference.getReferenceBindings().get(0) instanceof LocalReferenceBinding); - } - - protected void setUp() throws Exception { - super.setUp(); - deploymentContext = new RootDeploymentContext(null, null, null, null); - parent = EasyMock.createNiceMock(CompositeComponent.class); - EasyMock.replay(parent); - registry = new BuilderRegistryImpl(null, null); - registry.register(LocalBindingDefinition.class, new LocalBindingBuilder()); - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryTestCase.java deleted file mode 100644 index 572babf817..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryTestCase.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.builder; - -import java.net.URI; - -import org.apache.tuscany.spi.QualifiedName; -import org.apache.tuscany.spi.builder.BindingBuilder; -import org.apache.tuscany.spi.builder.BuilderConfigException; -import org.apache.tuscany.spi.builder.BuilderRegistry; -import org.apache.tuscany.spi.builder.ComponentBuilder; -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.Component; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.Reference; -import org.apache.tuscany.spi.component.ReferenceBinding; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.component.ScopeRegistry; -import org.apache.tuscany.spi.component.Service; -import org.apache.tuscany.spi.component.ServiceBinding; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.model.BindingDefinition; -import org.apache.tuscany.spi.model.ComponentDefinition; -import org.apache.tuscany.spi.model.ComponentType; -import org.apache.tuscany.spi.model.ComponentTypeReferenceDefinition; -import org.apache.tuscany.spi.model.CompositeComponentType; -import org.apache.tuscany.spi.model.CompositeImplementation; -import org.apache.tuscany.spi.model.Implementation; -import static org.apache.tuscany.spi.model.Multiplicity.ONE_ONE; -import org.apache.tuscany.spi.model.AbstractReferenceDefinition; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.model.ServiceDefinition; -import org.apache.tuscany.spi.wire.WireService; - -import junit.framework.TestCase; -import org.apache.tuscany.core.deployer.RootDeploymentContext; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class BuilderRegistryTestCase extends TestCase { - private DeploymentContext deploymentContext; - //private BuilderRegistryImpl registry; - private CompositeComponent parent; - - public void testRegistration() throws Exception { - MockBuilder builder = new MockBuilder(); - BuilderRegistry registry = new BuilderRegistryImpl(null, null); - registry.register(CompositeImplementation.class, builder); - CompositeImplementation implementation = new CompositeImplementation(); - ComponentDefinition<CompositeImplementation> componentDefinition = - new ComponentDefinition<CompositeImplementation>(implementation); - componentDefinition.getImplementation().setComponentType(new CompositeComponentType()); - registry.build(parent, componentDefinition, deploymentContext); - } - - @SuppressWarnings({"unchecked"}) - public void testServiceBindingBuilderDispatch() throws Exception { - WireService wireService = EasyMock.createMock(WireService.class); - wireService.createWires(EasyMock.isA(ServiceBinding.class), - (ServiceContract) EasyMock.isNull(), EasyMock.isA(String.class) - ); - EasyMock.expectLastCall().times(2); - EasyMock.replay(wireService); - BuilderRegistry registry = new BuilderRegistryImpl(null, wireService); - ServiceBinding binding = EasyMock.createNiceMock(ServiceBinding.class); - EasyMock.replay(binding); - BindingBuilder<MockBindingDefinition> builder = EasyMock.createMock(BindingBuilder.class); - EasyMock.expect(builder.build(EasyMock.isA(CompositeComponent.class), - EasyMock.isA(ServiceDefinition.class), - EasyMock.isA(MockBindingDefinition.class), - EasyMock.isA(DeploymentContext.class))).andReturn(binding).times(2); - EasyMock.replay(builder); - registry.register(MockBindingDefinition.class, builder); - ServiceDefinition definition = new ServiceDefinition("foo", null, false); - definition.addBinding(new MockBindingDefinition()); - definition.addBinding(new MockBindingDefinition()); - definition.setTarget(new URI("foo")); - Service service = registry.build(parent, definition, deploymentContext); - assertEquals(2, service.getServiceBindings().size()); - EasyMock.verify(wireService); - } - - @SuppressWarnings({"unchecked"}) - public void testReferenceBindingBuilderDispatch() throws Exception { - WireService wireService = EasyMock.createMock(WireService.class); - wireService.createWires(EasyMock.isA(ReferenceBinding.class), - (ServiceContract) EasyMock.isNull(), (QualifiedName) EasyMock.isNull() - ); - EasyMock.expectLastCall().times(2); - EasyMock.replay(wireService); - BuilderRegistry registry = new BuilderRegistryImpl(null, wireService); - ReferenceBinding binding = EasyMock.createNiceMock(ReferenceBinding.class); - EasyMock.replay(binding); - BindingBuilder<MockBindingDefinition> builder = EasyMock.createMock(BindingBuilder.class); - EasyMock.expect(builder.build(EasyMock.isA(CompositeComponent.class), - EasyMock.isA(AbstractReferenceDefinition.class), - EasyMock.isA(MockBindingDefinition.class), - EasyMock.isA(DeploymentContext.class))).andReturn(binding).times(2); - EasyMock.replay(builder); - registry.register(MockBindingDefinition.class, builder); - AbstractReferenceDefinition definition = new ComponentTypeReferenceDefinition("foo", null, ONE_ONE); - definition.addBinding(new MockBindingDefinition()); - definition.addBinding(new MockBindingDefinition()); - Reference reference = registry.build(parent, definition, deploymentContext); - assertEquals(2, reference.getReferenceBindings().size()); - EasyMock.verify(wireService); - } - - @SuppressWarnings({"unchecked"}) - public void testComponentImplementationDispatch() throws Exception { - ScopeRegistry scopeRegistry = EasyMock.createMock(ScopeRegistry.class); - ScopeContainer scopeContainer = EasyMock.createNiceMock(ScopeContainer.class); - EasyMock.expect(scopeRegistry.getScopeContainer(EasyMock.isA(Scope.class))).andReturn(scopeContainer); - EasyMock.replay(scopeRegistry); - WireService wireService = EasyMock.createMock(WireService.class); - wireService.createWires(EasyMock.isA(AtomicComponent.class), - EasyMock.isA(ComponentDefinition.class)); - EasyMock.replay(wireService); - BuilderRegistry registry = new BuilderRegistryImpl(scopeRegistry, wireService); - - AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.replay(component); - ComponentBuilder<FooImplementation> builder = EasyMock.createMock(ComponentBuilder.class); - EasyMock.expect(builder.build(EasyMock.isA(CompositeComponent.class), - EasyMock.isA(ComponentDefinition.class), - EasyMock.isA(DeploymentContext.class))).andReturn(component); - EasyMock.replay(builder); - registry.register(FooImplementation.class, builder); - - FooImplementation impl = new FooImplementation(); - impl.setComponentType(new ComponentType()); - ComponentDefinition<FooImplementation> definition = new ComponentDefinition<FooImplementation>("foo", impl); - Component ret = registry.build(parent, definition, deploymentContext); - assertNotNull(ret); - EasyMock.verify(wireService); - } - - @SuppressWarnings({"unchecked"}) - public void testNoConversationalContract() throws Exception { - ScopeRegistry scopeRegistry = EasyMock.createMock(ScopeRegistry.class); - ScopeContainer scopeContainer = EasyMock.createNiceMock(ScopeContainer.class); - EasyMock.expect(scopeRegistry.getScopeContainer(EasyMock.isA(Scope.class))).andReturn(scopeContainer); - EasyMock.replay(scopeRegistry); - WireService wireService = EasyMock.createMock(WireService.class); - wireService.createWires(EasyMock.isA(AtomicComponent.class), - EasyMock.isA(ComponentDefinition.class)); - EasyMock.replay(wireService); - BuilderRegistry registry = new BuilderRegistryImpl(scopeRegistry, wireService); - - AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.replay(component); - ComponentBuilder<FooImplementation> builder = EasyMock.createMock(ComponentBuilder.class); - EasyMock.expect(builder.build(EasyMock.isA(CompositeComponent.class), - EasyMock.isA(ComponentDefinition.class), - EasyMock.isA(DeploymentContext.class))).andReturn(component); - EasyMock.replay(builder); - registry.register(FooImplementation.class, builder); - - FooImplementation impl = new FooImplementation(); - ComponentType componentType = new ComponentType(); - componentType.setImplementationScope(Scope.CONVERSATION); - impl.setComponentType(componentType); - ComponentDefinition<FooImplementation> definition = new ComponentDefinition<FooImplementation>("foo", impl); - try { - registry.build(parent, definition, deploymentContext); - fail("Should throw NoConversationalContractException"); - } catch (NoConversationalContractException e) { - // expected - } - } - - protected void setUp() throws Exception { - super.setUp(); - deploymentContext = new RootDeploymentContext(null, null, null, null); - parent = EasyMock.createNiceMock(CompositeComponent.class); - EasyMock.replay(parent); - } - - private class MockBuilder implements ComponentBuilder<CompositeImplementation> { - public Component build(CompositeComponent parent, - ComponentDefinition componentDefinition, - DeploymentContext deploymentContext) throws BuilderConfigException { - return null; - } - } - - private class MockBindingDefinition extends BindingDefinition { - public Object clone() { - MockBindingDefinition mockClone = new MockBindingDefinition(); - mockClone.setTargetUri(URI.create(this.getTargetUri().toString())); - return mockClone; - } - } - - private class FooImplementation extends Implementation<ComponentType> { - - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplTestCase.java deleted file mode 100644 index fc5daa6b12..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorImplTestCase.java +++ /dev/null @@ -1,322 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.builder; - -import java.lang.reflect.Type; -import java.util.Collections; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.ReferenceBinding; -import org.apache.tuscany.spi.component.SCAObject; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.TargetInvoker; - -import org.apache.tuscany.core.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InboundWireImpl; -import org.apache.tuscany.core.wire.InvokerInterceptor; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; -import org.apache.tuscany.core.wire.SynchronousBridgingInterceptor; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class ConnectorImplTestCase extends AbstractConnectorImplTestCase { - - public void testConnectTargetNotFound() throws Exception { - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(parent.getName()).andReturn("parent"); - parent.getChild(EasyMock.isA(String.class)); - EasyMock.expectLastCall().andReturn(null); - EasyMock.replay(parent); - try { - AtomicComponent source = createAtomicSource(parent); - connector.connect(source); - fail(); - } catch (TargetServiceNotFoundException e) { - // expected - } - } - - public void testOutboundToInboundOptimization() throws Exception { - AtomicComponent container = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.expect(container.isSystem()).andReturn(true); - EasyMock.replay(container); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setContainer(container); - OutboundWire outboundWire = EasyMock.createMock(OutboundWire.class); - outboundWire.setTargetWire(EasyMock.eq(inboundWire)); - EasyMock.expect(outboundWire.getContainer()).andReturn(container).atLeastOnce(); - EasyMock.replay(outboundWire); - - connector.connect(outboundWire, inboundWire, true); - EasyMock.verify(outboundWire); - } - - /** - * Verifies that stateless targets with a destructor are not optimized as the destructor callback event must be - * issued by the TargetInvoker after it dispatches to the target - */ - public void testOutboundToInboundNoOptimizationBecauseStatelessDestructor() throws Exception { - AtomicComponent container = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.expect(container.isSystem()).andReturn(false); - EasyMock.expect(container.getScope()).andReturn(Scope.STATELESS); - EasyMock.expect(container.isDestroyable()).andReturn(true); - EasyMock.replay(container); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setContainer(container); - OutboundWire outboundWire = EasyMock.createMock(OutboundWire.class); - outboundWire.getInvocationChains(); - EasyMock.expectLastCall().andReturn(Collections.emptyMap()).atLeastOnce(); - outboundWire.getTargetCallbackInvocationChains(); - EasyMock.expectLastCall().andReturn(Collections.emptyMap()).atLeastOnce(); - EasyMock.expect(outboundWire.getContainer()).andReturn(container).atLeastOnce(); - EasyMock.replay(outboundWire); - - connector.connect(outboundWire, inboundWire, true); - EasyMock.verify(outboundWire); - } - - public void testOutboundToInboundNoOptimizationAtomic() throws Exception { - AtomicComponent container = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.expect(container.isSystem()).andReturn(false); - EasyMock.expect(container.getScope()).andReturn(Scope.STATELESS); - EasyMock.expect(container.isOptimizable()).andReturn(false); - EasyMock.replay(container); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setContainer(container); - OutboundWire outboundWire = EasyMock.createMock(OutboundWire.class); - EasyMock.expect(outboundWire.getContainer()).andReturn(container).atLeastOnce(); - outboundWire.getInvocationChains(); - EasyMock.expectLastCall().andReturn(Collections.emptyMap()).atLeastOnce(); - outboundWire.getTargetCallbackInvocationChains(); - EasyMock.expectLastCall().andReturn(Collections.emptyMap()).atLeastOnce(); - EasyMock.replay(outboundWire); - - connector.connect(outboundWire, inboundWire, true); - EasyMock.verify(outboundWire); - } - - public void testOutboundToInboundNoOptimizationNonAtomicTarget() throws Exception { - ReferenceBinding container = EasyMock.createNiceMock(ReferenceBinding.class); - EasyMock.expect(container.isSystem()).andReturn(false); - EasyMock.replay(container); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setContainer(container); - OutboundWire outboundWire = EasyMock.createMock(OutboundWire.class); - outboundWire.getInvocationChains(); - EasyMock.expectLastCall().andReturn(Collections.emptyMap()).atLeastOnce(); - outboundWire.getTargetCallbackInvocationChains(); - EasyMock.expectLastCall().andReturn(Collections.emptyMap()).atLeastOnce(); - EasyMock.expect(outboundWire.getContainer()).andReturn(container).atLeastOnce(); - EasyMock.replay(outboundWire); - - connector.connect(outboundWire, inboundWire, true); - EasyMock.verify(outboundWire); - } - - public void testOutboundToInboundChainConnect() throws Exception { - TargetInvoker invoker = new MockInvoker(); - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - inboundChain.addInterceptor(new InvokerInterceptor()); - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - connector.connect(outboundChain, inboundChain, invoker, false); - Interceptor interceptor = outboundChain.getHeadInterceptor(); - assertTrue(interceptor instanceof SynchronousBridgingInterceptor); - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(new MockInvoker()); - Message resp = interceptor.invoke(msg); - assertEquals(RESPONSE, resp.getBody()); - } - - public void testOutboundToInboundChainConnectNoInboundInterceptor() { - TargetInvoker invoker = new MockInvoker(); - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - try { - connector.connect(outboundChain, inboundChain, invoker, false); - fail(); - } catch (WireConnectException e) { - // expected - } - } - - public void testInboundToOutboundChainConnect() throws Exception { - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - outboundChain.addInterceptor(new InvokerInterceptor()); - connector.connect(inboundChain, outboundChain); - Interceptor interceptor = inboundChain.getHeadInterceptor(); - assertTrue(interceptor instanceof SynchronousBridgingInterceptor); - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(new MockInvoker()); - Message resp = interceptor.invoke(msg); - assertEquals(RESPONSE, resp.getBody()); - } - - public void testInboundToOutboundChainConnectNoOutboundInterceptors() throws Exception { - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - try { - connector.connect(inboundChain, outboundChain); - fail(); - } catch (WireConnectException e) { - // expected - } - } - - public void testInboundOutboundSystemWireOptimization() throws Exception { - SCAObject container = EasyMock.createMock(SCAObject.class); - EasyMock.expect(container.isSystem()).andReturn(true); - EasyMock.replay(container); - InboundWire inboundWire = EasyMock.createMock(InboundWire.class); - inboundWire.setTargetWire(EasyMock.isA(OutboundWire.class)); - EasyMock.expect(inboundWire.getContainer()).andReturn(container).atLeastOnce(); - EasyMock.replay(inboundWire); - OutboundWire outboundWire = new OutboundWireImpl(); - outboundWire.setContainer(container); - connector.connect(inboundWire, outboundWire, true); - EasyMock.verify(inboundWire); - EasyMock.verify(container); - } - - public void testOutboundInboundSystemWireOptimization() throws Exception { - SCAObject container = EasyMock.createMock(SCAObject.class); - EasyMock.expect(container.isSystem()).andReturn(true); - EasyMock.replay(container); - OutboundWire outboundWire = EasyMock.createMock(OutboundWire.class); - outboundWire.setTargetWire(EasyMock.isA(InboundWire.class)); - EasyMock.expect(outboundWire.getContainer()).andReturn(container).atLeastOnce(); - EasyMock.replay(outboundWire); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setContainer(container); - connector.connect(outboundWire, inboundWire, true); - EasyMock.verify(outboundWire); - EasyMock.verify(container); - } - - public void testIncompatibleInboundOutboundWiresConnect() throws Exception { - Operation<Type> operation = new Operation<Type>("bar", null, null, null); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.addInvocationChain(operation, new InboundInvocationChainImpl(operation)); - OutboundWire outboundWire = new OutboundWireImpl(); - try { - connector.connect(inboundWire, outboundWire, false); - fail(); - } catch (IncompatibleInterfacesException e) { - // expected - } - - } - - public void testIncompatibleOutboundInboundWiresConnect() throws Exception { - SCAObject container = EasyMock.createNiceMock(SCAObject.class); - EasyMock.expect(container.isSystem()).andReturn(false); - EasyMock.replay(container); - Operation<Type> operation = new Operation<Type>("bar", null, null, null); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setContainer(container); - OutboundWire outboundWire = new OutboundWireImpl(); - outboundWire.setContainer(container); - outboundWire.addInvocationChain(operation, new OutboundInvocationChainImpl(operation)); - try { - connector.connect(outboundWire, inboundWire, false); - fail(); - } catch (IncompatibleInterfacesException e) { - // expected - } - - } - - public void testIsOptimizable() { - assertTrue(connector.isOptimizable(Scope.STATELESS, Scope.STATELESS)); - assertTrue(connector.isOptimizable(Scope.STATELESS, Scope.COMPOSITE)); - assertFalse(connector.isOptimizable(Scope.STATELESS, Scope.CONVERSATION)); - assertTrue(connector.isOptimizable(Scope.STATELESS, Scope.REQUEST)); - assertTrue(connector.isOptimizable(Scope.STATELESS, Scope.SESSION)); - assertTrue(connector.isOptimizable(Scope.STATELESS, Scope.SYSTEM)); - - assertTrue(connector.isOptimizable(Scope.COMPOSITE, Scope.COMPOSITE)); - assertFalse(connector.isOptimizable(Scope.COMPOSITE, Scope.CONVERSATION)); - assertFalse(connector.isOptimizable(Scope.COMPOSITE, Scope.REQUEST)); - assertFalse(connector.isOptimizable(Scope.COMPOSITE, Scope.SESSION)); - assertFalse(connector.isOptimizable(Scope.COMPOSITE, Scope.STATELESS)); - assertTrue(connector.isOptimizable(Scope.COMPOSITE, Scope.SYSTEM)); - - assertFalse(connector.isOptimizable(Scope.CONVERSATION, Scope.COMPOSITE)); - assertFalse(connector.isOptimizable(Scope.CONVERSATION, Scope.CONVERSATION)); - assertFalse(connector.isOptimizable(Scope.CONVERSATION, Scope.REQUEST)); - assertFalse(connector.isOptimizable(Scope.CONVERSATION, Scope.SESSION)); - assertFalse(connector.isOptimizable(Scope.CONVERSATION, Scope.STATELESS)); - assertFalse(connector.isOptimizable(Scope.CONVERSATION, Scope.SYSTEM)); - - assertTrue(connector.isOptimizable(Scope.REQUEST, Scope.COMPOSITE)); - assertFalse(connector.isOptimizable(Scope.REQUEST, Scope.CONVERSATION)); - assertTrue(connector.isOptimizable(Scope.REQUEST, Scope.REQUEST)); - assertTrue(connector.isOptimizable(Scope.REQUEST, Scope.SESSION)); - assertFalse(connector.isOptimizable(Scope.REQUEST, Scope.STATELESS)); - assertTrue(connector.isOptimizable(Scope.REQUEST, Scope.SYSTEM)); - - assertTrue(connector.isOptimizable(Scope.SESSION, Scope.COMPOSITE)); - assertFalse(connector.isOptimizable(Scope.SESSION, Scope.CONVERSATION)); - assertFalse(connector.isOptimizable(Scope.SESSION, Scope.REQUEST)); - assertTrue(connector.isOptimizable(Scope.SESSION, Scope.SESSION)); - assertFalse(connector.isOptimizable(Scope.SESSION, Scope.STATELESS)); - assertTrue(connector.isOptimizable(Scope.SESSION, Scope.SYSTEM)); - - assertTrue(connector.isOptimizable(Scope.SYSTEM, Scope.COMPOSITE)); - assertFalse(connector.isOptimizable(Scope.SYSTEM, Scope.CONVERSATION)); - assertFalse(connector.isOptimizable(Scope.SYSTEM, Scope.REQUEST)); - assertFalse(connector.isOptimizable(Scope.SYSTEM, Scope.SESSION)); - assertFalse(connector.isOptimizable(Scope.SYSTEM, Scope.STATELESS)); - assertTrue(connector.isOptimizable(Scope.SYSTEM, Scope.SYSTEM)); - - assertFalse(connector.isOptimizable(Scope.UNDEFINED, Scope.COMPOSITE)); - assertFalse(connector.isOptimizable(Scope.UNDEFINED, Scope.CONVERSATION)); - assertFalse(connector.isOptimizable(Scope.UNDEFINED, Scope.REQUEST)); - assertFalse(connector.isOptimizable(Scope.UNDEFINED, Scope.SESSION)); - assertFalse(connector.isOptimizable(Scope.UNDEFINED, Scope.STATELESS)); - assertFalse(connector.isOptimizable(Scope.UNDEFINED, Scope.SYSTEM)); - - } - - public void testInvalidConnectObject() throws Exception { - try { - connector.connect(EasyMock.createNiceMock(SCAObject.class)); - fail(); - } catch (AssertionError e) { - // expected - } - } - - protected void setUp() throws Exception { - super.setUp(); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorPostProcessTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorPostProcessTestCase.java deleted file mode 100644 index 857b17eff5..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ConnectorPostProcessTestCase.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.builder; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.WirePostProcessorRegistry; -import org.apache.tuscany.spi.wire.WireService; - -import junit.framework.TestCase; -import org.easymock.EasyMock; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.createNiceMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.expectLastCall; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; - -/** - * @version $Rev$ $Date$ - */ -public class ConnectorPostProcessTestCase extends TestCase { - - public void testInboundToOutboundPostProcessCalled() throws Exception { - OutboundWire owire = createNiceMock(OutboundWire.class); - replay(owire); - InboundWire iwire = createNiceMock(InboundWire.class); - Map<Operation<?>, InboundInvocationChain> chains = new HashMap<Operation<?>, InboundInvocationChain>(); - expect(iwire.getInvocationChains()).andReturn(chains); - replay(iwire); - WirePostProcessorRegistry registry = createMock(WirePostProcessorRegistry.class); - registry.process(EasyMock.eq(iwire), EasyMock.eq(owire)); - replay(registry); - WireService wireService = createMock(WireService.class); - wireService.checkCompatibility((ServiceContract<?>) EasyMock.anyObject(), - (ServiceContract<?>) EasyMock.anyObject(), EasyMock.eq(false)); - expectLastCall().anyTimes(); - replay(wireService); - ConnectorImpl connector = new ConnectorImpl(wireService, registry, null, null); - connector.connect(iwire, owire, false); - verify(registry); - } - - public void testOutboundToInboundPostProcessCalled() throws Exception { - AtomicComponent source = createNiceMock(AtomicComponent.class); - expect(source.getName()).andReturn("Component"); - replay(source); - - AtomicComponent target = createNiceMock(AtomicComponent.class); - expect(target.getName()).andReturn("Component"); - replay(target); - - OutboundWire owire = createNiceMock(OutboundWire.class); - EasyMock.expect(owire.getContainer()).andReturn(source); - - Map<Operation<?>, OutboundInvocationChain> chains = new HashMap<Operation<?>, OutboundInvocationChain>(); - expect(owire.getInvocationChains()).andReturn(chains); - Map<Operation<?>, InboundInvocationChain> ichains = new HashMap<Operation<?>, InboundInvocationChain>(); - expect(owire.getTargetCallbackInvocationChains()).andReturn(ichains); - replay(owire); - InboundWire iwire = createNiceMock(InboundWire.class); - expect(iwire.getSourceCallbackInvocationChains("Component")).andReturn(chains); - EasyMock.expect(iwire.getContainer()).andReturn(target); - replay(iwire); - WirePostProcessorRegistry registry = createMock(WirePostProcessorRegistry.class); - registry.process(EasyMock.eq(owire), EasyMock.eq(iwire)); - replay(registry); - WireService wireService = createMock(WireService.class); - wireService.checkCompatibility((ServiceContract<?>) EasyMock.anyObject(), - (ServiceContract<?>) EasyMock.anyObject(), EasyMock.eq(false)); - expectLastCall().anyTimes(); - replay(wireService); - ConnectorImpl connector = new ConnectorImpl(wireService, registry, null, null); - - connector.connect(owire, iwire, false); - verify(registry); - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/IllegalCallbackExceptionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/IllegalCallbackExceptionTestCase.java deleted file mode 100644 index 40ddc837c7..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/IllegalCallbackExceptionTestCase.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.builder; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class IllegalCallbackExceptionTestCase extends TestCase { - - public void testInstantiation() throws Exception { - IllegalCallbackException e = new IllegalCallbackException("message", - "identifier", - "source name", - "ref name", - "target name", - "service name"); - assertEquals("message", e.getMessage()); - assertEquals("identifier", e.getIdentifier()); - assertEquals("source name", e.getSourceName()); - assertEquals("ref name", e.getReferenceName()); - assertEquals("target name", e.getTargetName()); - assertEquals("service name", e.getTargetServiceName()); - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/InboundtoOutboundConnectTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/InboundtoOutboundConnectTestCase.java deleted file mode 100644 index 4676dbb7cc..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/InboundtoOutboundConnectTestCase.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.builder; - -import org.apache.tuscany.spi.idl.InvalidServiceContractException; -import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.TargetInvoker; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -import org.apache.tuscany.core.mock.component.SimpleTarget; -import org.apache.tuscany.core.mock.wire.MockSyncInterceptor; -import org.apache.tuscany.core.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InvokerInterceptor; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.easymock.EasyMock; - -/** - * Verifies connection strategies between {@link org.apache.tuscany.spi.wire.OutboundInvocationChain}s and {@link - * org.apache.tuscany.spi.wire.InboundInvocationChain}s - * - * @version $$Rev$$ $$Date$$ - */ -public class InboundtoOutboundConnectTestCase extends TestCase { - private Operation operation; - private ConnectorImpl connector; - - public void testNoInterceptors() throws Exception { - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - outboundChain.addInterceptor(new InvokerInterceptor()); - TargetInvoker invoker = EasyMock.createNiceMock(TargetInvoker.class); - EasyMock.expect(invoker.invoke(EasyMock.isA(Message.class))).andReturn(new MessageImpl()); - EasyMock.replay(invoker); - connector.connect(inboundChain, outboundChain); - inboundChain.setTargetInvoker(invoker); - inboundChain.prepare(); - Message msg = new MessageImpl(); - msg.setTargetInvoker(invoker); - inboundChain.getHeadInterceptor().invoke(msg); - EasyMock.verify(invoker); - } - - - /** - * Verifies an invocation with a single source interceptor - */ - public void testSourceInterceptor() throws Exception { - MockSyncInterceptor interceptor = new MockSyncInterceptor(); - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - inboundChain.addInterceptor(interceptor); - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - outboundChain.addInterceptor(new InvokerInterceptor()); - Message msg = new MessageImpl(); - TargetInvoker invoker = EasyMock.createNiceMock(TargetInvoker.class); - EasyMock.expect(invoker.invoke(EasyMock.eq(msg))).andReturn(msg); - EasyMock.replay(invoker); - assertEquals(0, interceptor.getCount()); - connector.connect(inboundChain, outboundChain); - inboundChain.setTargetInvoker(invoker); - inboundChain.prepare(); - msg.setTargetInvoker(inboundChain.getTargetInvoker()); - assertEquals(msg, inboundChain.getHeadInterceptor().invoke(msg)); - assertEquals(1, interceptor.getCount()); - EasyMock.verify(invoker); - } - - /** - * Verifies an invocation with a single target interceptor - */ - public void testTargetInterceptor() throws Exception { - MockSyncInterceptor interceptor = new MockSyncInterceptor(); - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - inboundChain.addInterceptor(interceptor); - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - outboundChain.addInterceptor(new InvokerInterceptor()); - Message msg = new MessageImpl(); - TargetInvoker invoker = EasyMock.createNiceMock(TargetInvoker.class); - EasyMock.expect(invoker.invoke(EasyMock.eq(msg))).andReturn(msg); - EasyMock.replay(invoker); - assertEquals(0, interceptor.getCount()); - connector.connect(inboundChain, outboundChain); - inboundChain.setTargetInvoker(invoker); - inboundChain.prepare(); - msg.setTargetInvoker(inboundChain.getTargetInvoker()); - assertEquals(msg, inboundChain.getHeadInterceptor().invoke(msg)); - assertEquals(1, interceptor.getCount()); - EasyMock.verify(invoker); - } - - /** - * Verifies an invocation with a source and target interceptor - */ - public void testSourceTargetInterceptor() throws Exception { - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - outboundChain.addInterceptor(sourceInterceptor); - outboundChain.addInterceptor(new InvokerInterceptor()); - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - inboundChain.addInterceptor(targetInterceptor); - Message msg = new MessageImpl(); - TargetInvoker invoker = EasyMock.createNiceMock(TargetInvoker.class); - EasyMock.expect(invoker.invoke(EasyMock.eq(msg))).andReturn(msg); - EasyMock.replay(invoker); - assertEquals(0, sourceInterceptor.getCount()); - assertEquals(0, targetInterceptor.getCount()); - connector.connect(inboundChain, outboundChain); - inboundChain.setTargetInvoker(invoker); - inboundChain.prepare(); - msg.setTargetInvoker(inboundChain.getTargetInvoker()); - assertEquals(msg, inboundChain.getHeadInterceptor().invoke(msg)); - assertEquals(1, sourceInterceptor.getCount()); - assertEquals(1, targetInterceptor.getCount()); - EasyMock.verify(invoker); - } - - public void testOptimizeSet() throws Exception { - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - outboundChain.addInterceptor(new InvokerInterceptor()); - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - Message msg = new MessageImpl(); - TargetInvoker invoker = EasyMock.createNiceMock(TargetInvoker.class); - EasyMock.expect(invoker.invoke(EasyMock.eq(msg))).andReturn(msg); - EasyMock.replay(invoker); - connector.connect(inboundChain, outboundChain); - inboundChain.setTargetInvoker(invoker); - inboundChain.prepare(); - msg.setTargetInvoker(inboundChain.getTargetInvoker()); - assertEquals(msg, inboundChain.getHeadInterceptor().invoke(msg)); - EasyMock.verify(invoker); - } - - protected void setUp() throws Exception { - super.setUp(); - connector = new ConnectorImpl(); - JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - ServiceContract<?> contract; - try { - contract = registry.introspect(SimpleTarget.class); - } catch (InvalidServiceContractException e) { - throw new AssertionError(); - } - operation = contract.getOperations().get("echo"); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/IncompatibleInterfacesExceptionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/IncompatibleInterfacesExceptionTestCase.java deleted file mode 100644 index 7fa6633258..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/IncompatibleInterfacesExceptionTestCase.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.builder; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class IncompatibleInterfacesExceptionTestCase extends TestCase { - - public void testInstantiation() throws Exception { - IncompatibleInterfacesException e = new IncompatibleInterfacesException("message", - "source name", - "ref name", - "target name", - "service name"); - assertEquals("message", e.getMessage()); - assertEquals("source name", e.getSourceName()); - assertEquals("ref name", e.getReferenceName()); - assertEquals("target name", e.getTargetName()); - assertEquals("service name", e.getTargetServiceName()); - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/InvalidTargetTypeExceptionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/InvalidTargetTypeExceptionTestCase.java deleted file mode 100644 index c34be84745..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/InvalidTargetTypeExceptionTestCase.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.builder; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class InvalidTargetTypeExceptionTestCase extends TestCase { - - public void testInstantiation() throws Exception { - InvalidTargetTypeException e = new InvalidTargetTypeException("message", - "source name", - "ref name", - "target name", - "service name"); - assertEquals("message", e.getMessage()); - assertEquals("source name", e.getSourceName()); - assertEquals("ref name", e.getReferenceName()); - assertEquals("target name", e.getTargetName()); - assertEquals("service name", e.getTargetServiceName()); - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/LocalReferenceWiringTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/LocalReferenceWiringTestCase.java deleted file mode 100644 index 0806708056..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/LocalReferenceWiringTestCase.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.builder; - -import java.util.Collections; - -import org.apache.tuscany.spi.QualifiedName; -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.Reference; -import org.apache.tuscany.spi.component.ReferenceBinding; -import org.apache.tuscany.spi.component.Service; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; - -import org.apache.tuscany.core.implementation.composite.CompositeComponentImpl; -import org.apache.tuscany.core.implementation.composite.ReferenceImpl; -import org.easymock.EasyMock; -import org.easymock.IAnswer; - -/** - * Verifies various wiring "scenarios" or paths through the connector - * - * @version $Rev$ $Date$ - */ -public class LocalReferenceWiringTestCase extends AbstractConnectorImplTestCase { - protected ReferenceBinding referenceBinding; - private Reference reference; - - /** - * Verifies the case where the outbound reference wire is connected to a target atomic component that is a sibling - * to the reference's parent composite. This wiring scenario occurs when a reference is configured with the local - * binding. - */ - public void testConnectLocalReferenceBindingToAtomicComponentService() throws Exception { - final AtomicComponent atomicComponent = createAtomicTarget(); - CompositeComponent topComposite = EasyMock.createMock(CompositeComponent.class); - topComposite.getChild(TARGET); - EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() { - public Object answer() throws Throwable { - return atomicComponent; - } - }); - EasyMock.replay(topComposite); - CompositeComponent parent = new CompositeComponentImpl("parent", topComposite, connector, null); - reference = createLocalReference(parent, TARGET_SERVICE_NAME); - parent.register(reference); - // connect to the target - connector.connect(parent); - // connect the internal reference chains - connector.connect(reference); - InboundInvocationChain chain = referenceBinding.getInboundWire().getInvocationChains().get(operation); - Interceptor interceptor = chain.getHeadInterceptor(); - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(new MockInvoker()); - Message resp = interceptor.invoke(msg); - assertEquals(RESPONSE, resp.getBody()); - } - - /** - * Verifies the case where the outbound reference wire is connected to a target composite service that is a sibling - * to the reference's parent composite. This wiring scenario occurs when a reference is configured with the local - * binding. - */ - public void testConnectLocalReferenceBindingToCompositeService() throws Exception { - final CompositeComponent topComposite = EasyMock.createMock(CompositeComponent.class); - - topComposite.getInboundWire(TARGET); - EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() { - public Object answer() throws Throwable { - return createLocalInboundWire(topComposite); - } - }); - final Service service = createLocalService(topComposite); - topComposite.getChild(TARGET); - EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() { - public Object answer() throws Throwable { - return service; - } - }); - EasyMock.replay(topComposite); - - CompositeComponent parent = new CompositeComponentImpl("parent", topComposite, connector, null); - reference = createLocalReference(parent, TARGET_NAME); - parent.register(reference); - connector.connect(parent); - connector.connect(reference); - InboundInvocationChain chain = referenceBinding.getInboundWire().getInvocationChains().get(operation); - Interceptor interceptor = chain.getHeadInterceptor(); - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(new MockInvoker()); - Message resp = interceptor.invoke(msg); - assertEquals(RESPONSE, resp.getBody()); - } - - /** - * Verfies an exception if the target composite service (a sibling to the reference's parent) does not have a local - * binding - */ - public void testConnectLocalReferenceBindingToCompositeServiceNoMatchingBinding() throws Exception { - final Service service = createServiceNonLocalBinding(); - CompositeComponent topComposite = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(topComposite.getName()).andReturn("foo"); - topComposite.getChild(TARGET); - EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() { - public Object answer() throws Throwable { - return service; - } - }); - EasyMock.replay(topComposite); - - CompositeComponent parent = new CompositeComponentImpl("parent", topComposite, connector, null); - reference = createLocalReference(parent, TARGET_NAME); - parent.register(reference); - try { - connector.connect(parent); - fail(); - } catch (NoCompatibleBindingsException e) { - // expected - } - } - - /** - * Verifies a connection to a service offered by a sibling composite of the reference's parent - * - * @throws Exception - */ - public void testConnectLocalReferenceBindingToSiblingCompositeService() throws Exception { - final CompositeComponent sibling = EasyMock.createMock(CompositeComponent.class); - final InboundWire localServiceInboundWire = createLocalInboundWire(sibling); - EasyMock.expect(sibling.getName()).andReturn("sibling").atLeastOnce(); - sibling.getInboundWires(); - EasyMock.expectLastCall().andReturn(Collections.emptyList()).atLeastOnce(); - EasyMock.expect(sibling.isSystem()).andReturn(false).atLeastOnce(); - sibling.getInboundWire(TARGET_SERVICE); - EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() { - public Object answer() throws Throwable { - return localServiceInboundWire; - } - }); - EasyMock.expect(sibling.getScope()).andReturn(Scope.SYSTEM).anyTimes(); - EasyMock.replay(sibling); - - CompositeComponent topComposite = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(topComposite.getName()).andReturn("foo").atLeastOnce(); - topComposite.getChild(TARGET); - EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() { - public Object answer() throws Throwable { - return sibling; - } - }); - EasyMock.replay(topComposite); - - CompositeComponent parent = new CompositeComponentImpl("parent", topComposite, connector, null); - reference = createLocalReference(parent, TARGET_SERVICE_NAME); - parent.register(reference); - parent.register(sibling); - connector.connect(parent); - connector.connect(reference); - InboundInvocationChain chain = referenceBinding.getInboundWire().getInvocationChains().get(operation); - Interceptor interceptor = chain.getHeadInterceptor(); - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(new MockInvoker()); - Message resp = interceptor.invoke(msg); - assertEquals(RESPONSE, resp.getBody()); - } - - public void testConnectLocalReferenceBindingToSiblingCompositeServiceNoMatchingBinding() throws Exception { - try { - final CompositeComponent sibling = EasyMock.createMock(CompositeComponent.class); - sibling.getInboundWire(TARGET_SERVICE); - EasyMock.expectLastCall().andReturn(null); - EasyMock.expect(sibling.getName()).andReturn("sibling").atLeastOnce(); - EasyMock.expect(sibling.getScope()).andReturn(Scope.SYSTEM).atLeastOnce(); - EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() { - public Object answer() throws Throwable { - return null; - } - }); - EasyMock.replay(sibling); - - CompositeComponent topComposite = EasyMock.createMock(CompositeComponent.class); - topComposite.getChild(TARGET); - EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() { - public Object answer() throws Throwable { - return sibling; - } - }); - EasyMock.expect(topComposite.getName()).andReturn("top").atLeastOnce(); - EasyMock.replay(topComposite); - - CompositeComponent parent = new CompositeComponentImpl("parent", topComposite, connector, null); - - reference = createLocalReference(parent, TARGET_SERVICE_NAME); - parent.register(reference); - connector.connect(parent); - fail(); - } catch (TargetServiceNotFoundException e) { - // expected - } - } - - protected void setUp() throws Exception { - super.setUp(); - } - - - private Reference createLocalReference(CompositeComponent parent, QualifiedName target) throws Exception { - referenceBinding = createLocalReferenceBinding(target); - Reference reference = new ReferenceImpl("foo", parent, contract); - reference.addReferenceBinding(referenceBinding); - return reference; - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/NonBlockingForwardNonBlockingCallbackConnectionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/NonBlockingForwardNonBlockingCallbackConnectionTestCase.java deleted file mode 100644 index 896a98b773..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/NonBlockingForwardNonBlockingCallbackConnectionTestCase.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.builder; - -import java.lang.reflect.Type; -import java.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.QualifiedName; -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.idl.java.JavaServiceContract; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.services.work.NotificationListener; -import org.apache.tuscany.spi.services.work.WorkScheduler; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.TargetInvoker; -import org.apache.tuscany.spi.wire.WireService; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InboundWireImpl; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; -import org.apache.tuscany.core.wire.jdk.JDKWireService; -import org.easymock.EasyMock; - -/** - * Verifies connections with non-blocking forward and callback invocations - * - * @version $Rev$ $Date$ - */ -public class NonBlockingForwardNonBlockingCallbackConnectionTestCase extends TestCase { - private Operation<Type> operation; - private Operation<Type> callbackOperation; - private ServiceContract<Type> contract; - private ConnectorImpl connector; - - public void testNonBlockingForwardAndNonBlockingCallbackAtomicToAtomic() throws Exception { - AtomicComponent target = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(target.isSystem()).andReturn(false).anyTimes(); - EasyMock.expect(target.getName()).andReturn("target").anyTimes(); - EasyMock.expect(target.createTargetInvoker(EasyMock.eq("service"), - EasyMock.isA(Operation.class), - EasyMock.isA(InboundWire.class))).andReturn(EasyMock.createNiceMock(TargetInvoker.class)); - EasyMock.replay(target); - - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setContainer(target); - inboundWire.setServiceContract(contract); - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - inboundChain.addInterceptor(new NonBlockingForwardNonBlockingCallbackConnectionTestCase.MockInterceptor()); - inboundWire.addInvocationChain(operation, inboundChain); - - AtomicComponent source = createSource(); - OutboundWire outboundWire = new OutboundWireImpl(); - outboundWire.setContainer(source); - outboundWire.setServiceContract(contract); - outboundWire.setTargetName(new QualifiedName("target/service")); - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - outboundWire.addInvocationChain(operation, outboundChain); - - InboundInvocationChain callbackInboundChain = new InboundInvocationChainImpl(callbackOperation); - callbackInboundChain - .addInterceptor(new NonBlockingForwardNonBlockingCallbackConnectionTestCase.MockInterceptor()); - Map<Operation<?>, InboundInvocationChain> chains = new HashMap<Operation<?>, InboundInvocationChain>(); - chains.put(callbackOperation, callbackInboundChain); - outboundWire.addTargetCallbackInvocationChains(chains); - - connector.connect(outboundWire, inboundWire, true); - - // test the forward request - Message msg = new MessageImpl(); - msg.setBody("foo"); - Message ret = outboundChain.getHeadInterceptor().invoke(msg); - assertEquals(null, ret.getBody()); - - // test the callback - msg = new MessageImpl(); - msg.setBody("callback"); - Map<Operation<?>, OutboundInvocationChain> callbackChains = - inboundWire.getSourceCallbackInvocationChains("source"); - OutboundInvocationChain callbackInvocationChain = callbackChains.get(callbackOperation); - ret = callbackInvocationChain.getHeadInterceptor().invoke(msg); - assertEquals(null, ret.getBody()); - - EasyMock.verify(source); - EasyMock.verify(target); - } - - protected void setUp() throws Exception { - super.setUp(); - WorkContext context = new WorkContextImpl(); - WireService wireService = new JDKWireService(null, null); - WorkScheduler scheduler = new MockWorkScheduler(); - connector = new ConnectorImpl(wireService, null, scheduler, context); - operation = new Operation<Type>("bar", null, null, null); - operation.setNonBlocking(true); - callbackOperation = new Operation<Type>("callback", null, null, null); - callbackOperation.setNonBlocking(true); - contract = new JavaServiceContract(); - Map<String, Operation<Type>> ops = new HashMap<String, Operation<Type>>(); - ops.put("callback", callbackOperation); - contract.setCallbackOperations(ops); - } - - private AtomicComponent createSource() throws Exception { - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(false).anyTimes(); - EasyMock.expect(component.createTargetInvoker(EasyMock.eq("callback"), - EasyMock.isA(Operation.class), - (InboundWire) EasyMock.isNull())).andReturn(EasyMock.createNiceMock(TargetInvoker.class)); - EasyMock.replay(component); - return component; - } - - private class MockInterceptor implements Interceptor { - - public Message invoke(Message msg) { - return msg; - } - - public void setNext(Interceptor next) { - - } - - public Interceptor getNext() { - return null; - } - - public boolean isOptimizable() { - return false; - } - } - - private class MockWorkScheduler implements WorkScheduler { - - public <T extends Runnable> void scheduleWork(T work, NotificationListener<T> listener) { - throw new UnsupportedOperationException(); - } - - public <T extends Runnable> void scheduleWork(T work) { - work.run(); - } - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/NonBlockingForwardSyncCallbackConnectionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/NonBlockingForwardSyncCallbackConnectionTestCase.java deleted file mode 100644 index 0e425b73bf..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/NonBlockingForwardSyncCallbackConnectionTestCase.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.builder; - -import java.lang.reflect.Type; -import java.util.Map; -import java.util.HashMap; - -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.TargetInvoker; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.WireService; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.QualifiedName; -import org.apache.tuscany.spi.idl.java.JavaServiceContract; -import org.apache.tuscany.spi.services.work.WorkScheduler; -import org.apache.tuscany.spi.services.work.NotificationListener; - -import junit.framework.TestCase; -import org.easymock.EasyMock; -import org.apache.tuscany.core.wire.InboundWireImpl; -import org.apache.tuscany.core.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.apache.tuscany.core.wire.jdk.JDKWireService; -import org.apache.tuscany.core.component.WorkContextImpl; - -/** - * Verifies connections with non-blocking forward and synchronous callback invocations - * - * @version $Rev$ $Date$ - */ -public class NonBlockingForwardSyncCallbackConnectionTestCase extends TestCase { - private Operation<Type> operation; - private Operation<Type> callbackOperation; - private ServiceContract<Type> contract; - private ConnectorImpl connector; - - public void testNonBlockingForwardAndSyncCallbackAtomicToAtomic() throws Exception { - AtomicComponent target = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(target.isSystem()).andReturn(false).anyTimes(); - EasyMock.expect(target.getName()).andReturn("target").anyTimes(); - EasyMock.expect(target.createTargetInvoker(EasyMock.eq("service"), - EasyMock.isA(Operation.class), - EasyMock.isA(InboundWire.class))).andReturn(EasyMock.createNiceMock(TargetInvoker.class)); - EasyMock.replay(target); - - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setContainer(target); - inboundWire.setServiceContract(contract); - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - inboundChain.addInterceptor(new NonBlockingForwardSyncCallbackConnectionTestCase.MockInterceptor()); - inboundWire.addInvocationChain(operation, inboundChain); - - AtomicComponent source = createSource(); - OutboundWire outboundWire = new OutboundWireImpl(); - outboundWire.setContainer(source); - outboundWire.setServiceContract(contract); - outboundWire.setTargetName(new QualifiedName("target/service")); - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - outboundWire.addInvocationChain(operation, outboundChain); - - InboundInvocationChain callbackInboundChain = new InboundInvocationChainImpl(callbackOperation); - callbackInboundChain.addInterceptor(new NonBlockingForwardSyncCallbackConnectionTestCase.MockInterceptor()); - Map<Operation<?>, InboundInvocationChain> chains = new HashMap<Operation<?>, InboundInvocationChain>(); - chains.put(callbackOperation, callbackInboundChain); - outboundWire.addTargetCallbackInvocationChains(chains); - - connector.connect(outboundWire, inboundWire, true); - - // test the forward request - Message msg = new MessageImpl(); - msg.setBody("foo"); - Message ret = outboundChain.getHeadInterceptor().invoke(msg); - assertEquals(null, ret.getBody()); - - // test the callback - msg = new MessageImpl(); - msg.setBody("callback"); - Map<Operation<?>, OutboundInvocationChain> callbackChains = - inboundWire.getSourceCallbackInvocationChains("source"); - OutboundInvocationChain callbackInvocationChain = callbackChains.get(callbackOperation); - ret = callbackInvocationChain.getHeadInterceptor().invoke(msg); - assertEquals("callback", ret.getBody()); - - EasyMock.verify(source); - EasyMock.verify(target); - } - - - protected void setUp() throws Exception { - super.setUp(); - WorkContext context = new WorkContextImpl(); - WireService wireService = new JDKWireService(null, null); - WorkScheduler scheduler = new NonBlockingForwardSyncCallbackConnectionTestCase.MockWorkScheduler(); - connector = new ConnectorImpl(wireService, null, scheduler, context); - operation = new Operation<Type>("bar", null, null, null); - operation.setNonBlocking(true); - callbackOperation = new Operation<Type>("callback", null, null, null); - contract = new JavaServiceContract(); - Map<String, Operation<Type>> ops = new HashMap<String, Operation<Type>>(); - ops.put("callback", callbackOperation); - contract.setCallbackOperations(ops); - } - - private AtomicComponent createSource() throws Exception { - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(false).anyTimes(); - EasyMock.expect(component.createTargetInvoker(EasyMock.eq("callback"), - EasyMock.isA(Operation.class), - (InboundWire) EasyMock.isNull())).andReturn(EasyMock.createNiceMock(TargetInvoker.class)); - EasyMock.replay(component); - return component; - } - - private class MockInterceptor implements Interceptor { - - public Message invoke(Message msg) { - return msg; - } - - public void setNext(Interceptor next) { - - } - - public Interceptor getNext() { - return null; - } - - public boolean isOptimizable() { - return false; - } - } - - private class MockWorkScheduler implements WorkScheduler { - - public <T extends Runnable> void scheduleWork(T work, NotificationListener<T> listener) { - throw new UnsupportedOperationException(); - } - - public <T extends Runnable> void scheduleWork(T work) { - work.run(); - } - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/OutboundToInboundConnectTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/OutboundToInboundConnectTestCase.java deleted file mode 100644 index 2c8e2c3fa8..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/OutboundToInboundConnectTestCase.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.builder; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.spi.idl.InvalidServiceContractException; -import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.TargetInvoker; -import static org.apache.tuscany.spi.wire.TargetInvoker.NONE; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -import org.apache.tuscany.core.mock.component.SimpleTarget; -import org.apache.tuscany.core.mock.wire.MockSyncInterceptor; -import org.apache.tuscany.core.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InvokerInterceptor; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.easymock.EasyMock; -import static org.easymock.EasyMock.createNiceMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; - -/** - * Verifies connection strategies between {@link org.apache.tuscany.spi.wire.OutboundInvocationChain}s and {@link - * org.apache.tuscany.spi.wire.InboundInvocationChain}s - * - * @version $$Rev$$ $$Date$$ - */ -public class OutboundToInboundConnectTestCase extends TestCase { - - public void testNoInterceptorsNoHandlers() throws Exception { - ConnectorImpl connector = new ConnectorImpl(); - InboundInvocationChain inboundChain = setupTarget(null); - OutboundInvocationChain outboundChain = setupSource(null); - String[] val = new String[]{"foo"}; - TargetInvoker invoker = createNiceMock(TargetInvoker.class); - expect(invoker.invokeTarget(EasyMock.eq(val), EasyMock.eq(NONE))).andReturn(val); - replay(invoker); - connector.connect(outboundChain, inboundChain, invoker, false); - inboundChain.prepare(); - assertEquals(val, outboundChain.getTargetInvoker().invokeTarget(val, NONE)); - verify(invoker); - } - - - /** - * Verifies an invocation with a single source interceptor - */ - public void testSourceInterceptor() throws Exception { - ConnectorImpl connector = new ConnectorImpl(); - MockSyncInterceptor interceptor = new MockSyncInterceptor(); - List<Interceptor> interceptors = new ArrayList<Interceptor>(); - interceptors.add(interceptor); - OutboundInvocationChain outboundChain = setupSource(interceptors); - InboundInvocationChain inboundChain = setupTarget(null); - Message msg = new MessageImpl(); - TargetInvoker invoker = createNiceMock(TargetInvoker.class); - expect(invoker.invoke(EasyMock.eq(msg))).andReturn(msg); - replay(invoker); - assertEquals(0, interceptor.getCount()); - connector.connect(outboundChain, inboundChain, invoker, false); - inboundChain.prepare(); - msg.setTargetInvoker(outboundChain.getTargetInvoker()); - assertEquals(msg, outboundChain.getHeadInterceptor().invoke(msg)); - assertEquals(1, interceptor.getCount()); - verify(invoker); - } - - /** - * Verifies an invocation with a single target interceptor - */ - public void testTargetInterceptor() throws Exception { - ConnectorImpl connector = new ConnectorImpl(); - MockSyncInterceptor interceptor = new MockSyncInterceptor(); - List<Interceptor> interceptors = new ArrayList<Interceptor>(); - interceptors.add(interceptor); - OutboundInvocationChain outboundChain = setupSource(null); - InboundInvocationChain inboundChain = setupTarget(interceptors); - Message msg = new MessageImpl(); - TargetInvoker invoker = createNiceMock(TargetInvoker.class); - expect(invoker.invoke(EasyMock.eq(msg))).andReturn(msg); - replay(invoker); - assertEquals(0, interceptor.getCount()); - connector.connect(outboundChain, inboundChain, invoker, false); - inboundChain.prepare(); - msg.setTargetInvoker(outboundChain.getTargetInvoker()); - assertEquals(msg, outboundChain.getHeadInterceptor().invoke(msg)); - assertEquals(1, interceptor.getCount()); - verify(invoker); - } - - /** - * Verifies an invocation with a source and target interceptor - */ - public void testSourceTargetInterceptor() throws Exception { - ConnectorImpl connector = new ConnectorImpl(); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - List<Interceptor> sourceInterceptors = new ArrayList<Interceptor>(); - sourceInterceptors.add(sourceInterceptor); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - List<Interceptor> targetInterceptors = new ArrayList<Interceptor>(); - targetInterceptors.add(targetInterceptor); - OutboundInvocationChain outboundChain = setupSource(sourceInterceptors); - InboundInvocationChain inboundChain = setupTarget(targetInterceptors); - Message msg = new MessageImpl(); - TargetInvoker invoker = createNiceMock(TargetInvoker.class); - expect(invoker.invoke(EasyMock.eq(msg))).andReturn(msg); - replay(invoker); - assertEquals(0, sourceInterceptor.getCount()); - assertEquals(0, targetInterceptor.getCount()); - connector.connect(outboundChain, inboundChain, invoker, false); - inboundChain.prepare(); - msg.setTargetInvoker(outboundChain.getTargetInvoker()); - assertEquals(msg, outboundChain.getHeadInterceptor().invoke(msg)); - assertEquals(1, sourceInterceptor.getCount()); - assertEquals(1, targetInterceptor.getCount()); - verify(invoker); - } - - - public InboundInvocationChain setupTarget(List<Interceptor> interceptors) { - JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - ServiceContract<?> contract; - try { - contract = registry.introspect(SimpleTarget.class); - } catch (InvalidServiceContractException e) { - throw new AssertionError(); - } - Operation operation = contract.getOperations().get("echo"); - InboundInvocationChainImpl chain = new InboundInvocationChainImpl(operation); - if (interceptors != null) { - for (Interceptor interceptor : interceptors) { - chain.addInterceptor(interceptor); - } - } - chain.addInterceptor(new InvokerInterceptor()); // add tail interceptor - return chain; - } - - public OutboundInvocationChain setupSource(List<Interceptor> interceptors) { - JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - ServiceContract<?> contract; - try { - contract = registry.introspect(SimpleTarget.class); - } catch (InvalidServiceContractException e) { - throw new AssertionError(); - } - Operation operation = contract.getOperations().get("echo"); - OutboundInvocationChainImpl chain = new OutboundInvocationChainImpl(operation); - if (interceptors != null) { - for (Interceptor interceptor : interceptors) { - chain.addInterceptor(interceptor); - } - } - return chain; - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ReferenceConnectorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ReferenceConnectorTestCase.java deleted file mode 100644 index d3e7263045..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ReferenceConnectorTestCase.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.builder; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.Reference; -import org.apache.tuscany.spi.component.ReferenceBinding; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; - -import org.apache.tuscany.core.implementation.composite.ReferenceImpl; -import org.apache.tuscany.core.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InboundWireImpl; -import org.apache.tuscany.core.wire.InvokerInterceptor; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class ReferenceConnectorTestCase extends AbstractConnectorImplTestCase { - private AtomicComponent source; - private CompositeComponent parent; - - public void testConnectReferenceWiresNoInboundInterceptors() throws Exception { - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setServiceContract(contract); - inboundWire.addInvocationChain(operation, inboundChain); - - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - // Outbound chains always contains at least one interceptor - outboundChain.addInterceptor(new InvokerInterceptor()); - OutboundWire outboundWire = new OutboundWireImpl(); - outboundWire.setServiceContract(contract); - outboundWire.setTargetName(TARGET_SERVICE_NAME); - outboundWire.addInvocationChain(operation, outboundChain); - - ReferenceBinding referenceBinding = EasyMock.createMock(ReferenceBinding.class); - referenceBinding.setReference(EasyMock.isA(Reference.class)); - EasyMock.expect(referenceBinding.createTargetInvoker(contract, operation)).andReturn(null); - EasyMock.expect(referenceBinding.getInboundWire()).andReturn(inboundWire); - EasyMock.expect(referenceBinding.getOutboundWire()).andReturn(outboundWire); - EasyMock.expect(referenceBinding.isSystem()).andReturn(false).atLeastOnce(); - EasyMock.replay(referenceBinding); - inboundWire.setContainer(referenceBinding); - outboundWire.setContainer(referenceBinding); - - Reference reference = new ReferenceImpl("foo", parent, contract); - reference.addReferenceBinding(referenceBinding); - - connector.connect(reference); - - EasyMock.verify(referenceBinding); - Interceptor interceptor = inboundChain.getHeadInterceptor(); - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(new MockInvoker()); - Message resp = interceptor.invoke(msg); - assertEquals(RESPONSE, resp.getBody()); - } - - public void testConnectReferenceWiresWithInboundInterceptors() throws Exception { - MockInterceptor inboundInterceptor = new MockInterceptor(); - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - inboundChain.addInterceptor(inboundInterceptor); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setServiceContract(contract); - inboundWire.addInvocationChain(operation, inboundChain); - - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - // Outbound always contains at lease one interceptor - outboundChain.addInterceptor(new InvokerInterceptor()); - OutboundWire outboundWire = new OutboundWireImpl(); - outboundWire.setServiceContract(contract); - outboundWire.setTargetName(TARGET_SERVICE_NAME); - outboundWire.addInvocationChain(operation, outboundChain); - - ReferenceBinding referenceBinding = EasyMock.createMock(ReferenceBinding.class); - referenceBinding.setReference(EasyMock.isA(Reference.class)); - EasyMock.expect(referenceBinding.createTargetInvoker(contract, operation)).andReturn(null); - EasyMock.expect(referenceBinding.getInboundWire()).andReturn(inboundWire); - EasyMock.expect(referenceBinding.getOutboundWire()).andReturn(outboundWire); - EasyMock.expect(referenceBinding.isSystem()).andReturn(false); - EasyMock.replay(referenceBinding); - inboundWire.setContainer(referenceBinding); - outboundWire.setContainer(referenceBinding); - - Reference reference = new ReferenceImpl("foo", parent, contract); - reference.addReferenceBinding(referenceBinding); - - connector.connect(reference); - - EasyMock.verify(referenceBinding); - Interceptor interceptor = inboundChain.getHeadInterceptor(); - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(new MockInvoker()); - Message resp = interceptor.invoke(msg); - assertEquals(RESPONSE, resp.getBody()); - assertTrue(inboundInterceptor.isInvoked()); - } - - public void testOutboundWireToInboundReferenceTarget() throws Exception { - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("foo"); - EasyMock.replay(component); - - ReferenceBinding target = EasyMock.createMock(ReferenceBinding.class); - EasyMock.expect(target.isSystem()).andReturn(false); - EasyMock.expect(target.createTargetInvoker(EasyMock.isA(ServiceContract.class), EasyMock.isA(Operation.class))) - .andReturn(new MockInvoker()); - EasyMock.replay(target); - - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - inboundChain.addInterceptor(new InvokerInterceptor()); - InboundWire targetWire = new InboundWireImpl(); - targetWire.setServiceContract(contract); - targetWire.addInvocationChain(operation, inboundChain); - targetWire.setContainer(target); - - // create the outbound wire and chain from the source component - OutboundInvocationChain sourceChain = new OutboundInvocationChainImpl(operation); - OutboundWire sourceWire = new OutboundWireImpl(); - sourceWire.setServiceContract(contract); - sourceWire.setTargetName(TARGET_SERVICE_NAME); - sourceWire.addInvocationChain(operation, sourceChain); - sourceWire.setContainer(component); - sourceWire.setContainer(source); - - connector.connect(sourceWire, targetWire, false); - Interceptor interceptor = sourceChain.getHeadInterceptor(); - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(new MockInvoker()); - Message resp = interceptor.invoke(msg); - assertEquals(RESPONSE, resp.getBody()); - } - - protected void setUp() throws Exception { - super.setUp(); - parent = EasyMock.createNiceMock(CompositeComponent.class); - source = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.replay(source); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ServiceConnectorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ServiceConnectorTestCase.java deleted file mode 100644 index 0ccab5bfea..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/ServiceConnectorTestCase.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.builder; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.Reference; -import org.apache.tuscany.spi.component.ReferenceBinding; -import org.apache.tuscany.spi.component.Service; -import org.apache.tuscany.spi.component.ServiceBinding; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; - -import org.apache.tuscany.core.implementation.composite.ReferenceImpl; -import org.apache.tuscany.core.implementation.composite.ServiceImpl; -import org.apache.tuscany.core.mock.binding.MockServiceBinding; -import org.apache.tuscany.core.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InboundWireImpl; -import org.apache.tuscany.core.wire.InvokerInterceptor; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; -import org.apache.tuscany.core.wire.SynchronousBridgingInterceptor; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class ServiceConnectorTestCase extends AbstractConnectorImplTestCase { - private CompositeComponent parent; - private InboundInvocationChain inboundChain; - private ServiceBinding sourceServiceBinding; - - public void testConnectServiceToAtomicComponent() throws Exception { - configureAtomicTarget(); - Service sourceService = new ServiceImpl("foo", parent, contract); - sourceService.addServiceBinding(sourceServiceBinding); - connector.connect(sourceService); - Interceptor interceptor = inboundChain.getHeadInterceptor(); - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(new MockInvoker()); - Message resp = interceptor.invoke(msg); - assertEquals(RESPONSE, resp.getBody()); - } - - public void testConnectServiceToChildCompositeService() throws Exception { - configureChildCompositeServiceTarget(); - Service sourceService = new ServiceImpl("foo", parent, contract); - sourceService.addServiceBinding(sourceServiceBinding); - connector.connect(sourceService); - Interceptor interceptor = inboundChain.getHeadInterceptor(); - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(new MockInvoker()); - Message resp = interceptor.invoke(msg); - assertEquals(RESPONSE, resp.getBody()); - } - - public void testConnectServiceToReference() throws Exception { - configureReferenceTarget(); - Service sourceService = new ServiceImpl("foo", parent, contract); - sourceService.addServiceBinding(sourceServiceBinding); - connector.connect(sourceService); - Interceptor interceptor = inboundChain.getHeadInterceptor(); - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(new MockInvoker()); - Message resp = interceptor.invoke(msg); - assertEquals(RESPONSE, resp.getBody()); - } - - protected void setUp() throws Exception { - super.setUp(); - inboundChain = new InboundInvocationChainImpl(operation); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setServiceContract(contract); - inboundWire.addInvocationChain(operation, inboundChain); - - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - // Outbound chains always contains at least one interceptor - outboundChain.addInterceptor(new SynchronousBridgingInterceptor()); - OutboundWire outboundWire = new OutboundWireImpl(); - outboundWire.setServiceContract(contract); - outboundWire.setTargetName(TARGET_SERVICE_NAME); - outboundWire.addInvocationChain(operation, outboundChain); - - sourceServiceBinding = new MockServiceBinding(); - sourceServiceBinding.setInboundWire(inboundWire); - sourceServiceBinding.setOutboundWire(outboundWire); - inboundWire.setContainer(sourceServiceBinding); - outboundWire.setContainer(sourceServiceBinding); - - } - - private void configureAtomicTarget() throws Exception { - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - inboundChain.addInterceptor(new InvokerInterceptor()); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setServiceContract(contract); - inboundWire.addInvocationChain(operation, inboundChain); - - AtomicComponent atomicTarget = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(atomicTarget.getInboundWire(EasyMock.isA(String.class))).andReturn(inboundWire).atLeastOnce(); - EasyMock.expect(atomicTarget.getScope()).andReturn(Scope.COMPOSITE); - EasyMock.expect(atomicTarget.isSystem()).andReturn(false); - EasyMock.expect(atomicTarget.createTargetInvoker(EasyMock.isA(String.class), - EasyMock.isA(Operation.class), - EasyMock.isA(InboundWire.class))).andReturn(new MockInvoker()); - EasyMock.replay(atomicTarget); - - inboundWire.setContainer(atomicTarget); - - parent = EasyMock.createNiceMock(CompositeComponent.class); - EasyMock.expect(parent.getChild(TARGET)).andReturn(atomicTarget); - EasyMock.replay(parent); - } - - private void configureChildCompositeServiceTarget() throws Exception { - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - inboundChain.addInterceptor(new InvokerInterceptor()); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setServiceContract(contract); - inboundWire.addInvocationChain(operation, inboundChain); - - CompositeComponent compositeTarget = EasyMock.createMock(CompositeComponent.class); - Service service = createLocalService(compositeTarget); - ServiceBinding binding = service.getServiceBindings().get(0); - EasyMock.expect(compositeTarget.getInboundWire(TARGET_SERVICE)).andReturn(binding.getInboundWire()); - EasyMock.expect(compositeTarget.getScope()).andReturn(Scope.SYSTEM).anyTimes(); - EasyMock.replay(compositeTarget); - - inboundWire.setContainer(compositeTarget); - - parent = EasyMock.createNiceMock(CompositeComponent.class); - EasyMock.expect(parent.getChild(TARGET)).andReturn(compositeTarget); - EasyMock.replay(parent); - } - - - private void configureReferenceTarget() throws Exception { - ReferenceBinding binding = createLocalReferenceBinding(TARGET_NAME); - Reference referenceTarget = new ReferenceImpl(TARGET, parent, contract); - referenceTarget.addReferenceBinding(binding); - // put a terminating interceptor on the outbound wire of the reference for testing an invocation - binding.getOutboundWire().getInvocationChains().get(operation).addInterceptor(new InvokerInterceptor()); - connector.connect(binding.getInboundWire(), binding.getOutboundWire(), true); - parent = EasyMock.createNiceMock(CompositeComponent.class); - EasyMock.expect(parent.getChild(TARGET)).andReturn(referenceTarget); - EasyMock.replay(parent); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/SynchronousForwardCallbackConnectionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/SynchronousForwardCallbackConnectionTestCase.java deleted file mode 100644 index 9beca64444..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/SynchronousForwardCallbackConnectionTestCase.java +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.builder; - -import java.lang.reflect.Type; -import java.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.QualifiedName; -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.ReferenceBinding; -import org.apache.tuscany.spi.component.ServiceBinding; -import org.apache.tuscany.spi.idl.java.JavaServiceContract; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.TargetInvoker; -import org.apache.tuscany.spi.wire.WireService; - -import junit.framework.TestCase; -import org.apache.tuscany.core.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InboundWireImpl; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; -import org.apache.tuscany.core.wire.jdk.JDKWireService; -import org.easymock.EasyMock; - -/** - * Verifies connections with synchronous forward and callback invocations - * - * @version $Rev$ $Date$ - */ -public class SynchronousForwardCallbackConnectionTestCase extends TestCase { - private Operation<Type> operation; - private Operation<Type> callbackOperation; - private ServiceContract<Type> contract; - private ConnectorImpl connector; - - public void testSyncForwardAndCallbackAtomicToAtomic() throws Exception { - AtomicComponent target = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(target.isSystem()).andReturn(false).anyTimes(); - EasyMock.expect(target.getName()).andReturn("target").anyTimes(); - EasyMock.expect(target.createTargetInvoker(EasyMock.eq("service"), - EasyMock.isA(Operation.class), - EasyMock.isA(InboundWire.class))).andReturn(EasyMock.createNiceMock(TargetInvoker.class)); - EasyMock.replay(target); - - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setContainer(target); - inboundWire.setServiceContract(contract); - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - inboundChain.addInterceptor(new MockInterceptor()); - inboundWire.addInvocationChain(operation, inboundChain); - - AtomicComponent source = createSource(); - OutboundWire outboundWire = new OutboundWireImpl(); - outboundWire.setContainer(source); - outboundWire.setServiceContract(contract); - outboundWire.setTargetName(new QualifiedName("target/service")); - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - outboundWire.addInvocationChain(operation, outboundChain); - - InboundInvocationChain callbackInboundChain = new InboundInvocationChainImpl(callbackOperation); - callbackInboundChain.addInterceptor(new MockInterceptor()); - Map<Operation<?>, InboundInvocationChain> chains = new HashMap<Operation<?>, InboundInvocationChain>(); - chains.put(callbackOperation, callbackInboundChain); - outboundWire.addTargetCallbackInvocationChains(chains); - - connector.connect(outboundWire, inboundWire, true); - - // test the forward request - Message msg = new MessageImpl(); - msg.setBody("foo"); - Message ret = outboundChain.getHeadInterceptor().invoke(msg); - assertEquals("foo", ret.getBody()); - - // test the callback - msg = new MessageImpl(); - msg.setBody("callback"); - Map<Operation<?>, OutboundInvocationChain> callbackChains = - inboundWire.getSourceCallbackInvocationChains("source"); - OutboundInvocationChain callbackInvocationChain = callbackChains.get(callbackOperation); - ret = callbackInvocationChain.getHeadInterceptor().invoke(msg); - assertEquals("callback", ret.getBody()); - - EasyMock.verify(source); - EasyMock.verify(target); - } - - public void testSyncForwardAndCallbackAtomicToReferenceBinding() throws Exception { - ReferenceBinding target = EasyMock.createMock(ReferenceBinding.class); - EasyMock.expect(target.isSystem()).andReturn(false).anyTimes(); - EasyMock.expect(target.createTargetInvoker(EasyMock.isA(ServiceContract.class), - EasyMock.isA(Operation.class))).andReturn(EasyMock.createNiceMock(TargetInvoker.class)); - EasyMock.replay(target); - - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setContainer(target); - inboundWire.setServiceContract(contract); - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - inboundChain.addInterceptor(new MockInterceptor()); - inboundWire.addInvocationChain(operation, inboundChain); - - AtomicComponent source = createSource(); - OutboundWire outboundWire = new OutboundWireImpl(); - outboundWire.setContainer(source); - outboundWire.setServiceContract(contract); - outboundWire.setTargetName(new QualifiedName("target/service")); - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - outboundWire.addInvocationChain(operation, outboundChain); - - InboundInvocationChain callbackInboundChain = new InboundInvocationChainImpl(callbackOperation); - callbackInboundChain.addInterceptor(new MockInterceptor()); - Map<Operation<?>, InboundInvocationChain> chains = new HashMap<Operation<?>, InboundInvocationChain>(); - chains.put(callbackOperation, callbackInboundChain); - outboundWire.addTargetCallbackInvocationChains(chains); - - connector.connect(outboundWire, inboundWire, true); - // test the forward request - Message msg = new MessageImpl(); - msg.setBody("foo"); - Message ret = outboundChain.getHeadInterceptor().invoke(msg); - assertEquals("foo", ret.getBody()); - - // test the callback - msg = new MessageImpl(); - msg.setBody("callback"); - Map<Operation<?>, OutboundInvocationChain> callbackChains = - inboundWire.getSourceCallbackInvocationChains("source"); - OutboundInvocationChain callbackInvocationChain = callbackChains.get(callbackOperation); - ret = callbackInvocationChain.getHeadInterceptor().invoke(msg); - assertEquals("callback", ret.getBody()); - - EasyMock.verify(target); - EasyMock.verify(source); - } - - public void testSyncForwardAndCallbackReferenceBindingToServiceBinding() throws Exception { - ReferenceBinding source = EasyMock.createMock(ReferenceBinding.class); - EasyMock.expect(source.isSystem()).andReturn(false).anyTimes(); - EasyMock.expect(source.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(source.createTargetInvoker(EasyMock.isA(ServiceContract.class), - EasyMock.isA(Operation.class))).andReturn(EasyMock.createNiceMock(TargetInvoker.class)); - EasyMock.replay(source); - - ServiceBinding target = EasyMock.createMock(ServiceBinding.class); - EasyMock.expect(target.isSystem()).andReturn(false).anyTimes(); - EasyMock.expect(target.createTargetInvoker(EasyMock.isA(ServiceContract.class), - EasyMock.isA(Operation.class))).andReturn(EasyMock.createNiceMock(TargetInvoker.class)); - EasyMock.replay(target); - - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setContainer(target); - inboundWire.setServiceContract(contract); - InboundInvocationChain inboundChain = new InboundInvocationChainImpl(operation); - inboundChain.addInterceptor(new MockInterceptor()); - inboundWire.addInvocationChain(operation, inboundChain); - - OutboundWire outboundWire = new OutboundWireImpl(); - outboundWire.setContainer(source); - outboundWire.setServiceContract(contract); - outboundWire.setTargetName(new QualifiedName("target/service")); - OutboundInvocationChain outboundChain = new OutboundInvocationChainImpl(operation); - outboundWire.addInvocationChain(operation, outboundChain); - - InboundInvocationChain callbackInboundChain = new InboundInvocationChainImpl(callbackOperation); - callbackInboundChain.addInterceptor(new MockInterceptor()); - Map<Operation<?>, InboundInvocationChain> chains = new HashMap<Operation<?>, InboundInvocationChain>(); - chains.put(callbackOperation, callbackInboundChain); - outboundWire.addTargetCallbackInvocationChains(chains); - - connector.connect(outboundWire, inboundWire, true); - // test the forward request - Message msg = new MessageImpl(); - msg.setBody("foo"); - Message ret = outboundChain.getHeadInterceptor().invoke(msg); - assertEquals("foo", ret.getBody()); - - // test the callback - msg = new MessageImpl(); - msg.setBody("callback"); - Map<Operation<?>, OutboundInvocationChain> callbackChains = - inboundWire.getSourceCallbackInvocationChains("source"); - OutboundInvocationChain callbackInvocationChain = callbackChains.get(callbackOperation); - ret = callbackInvocationChain.getHeadInterceptor().invoke(msg); - assertEquals("callback", ret.getBody()); - - EasyMock.verify(source); - EasyMock.verify(target); - } - - protected void setUp() throws Exception { - super.setUp(); - WireService wireService = new JDKWireService(null, null); - connector = new ConnectorImpl(wireService, null, null, null); - operation = new Operation<Type>("bar", null, null, null); - callbackOperation = new Operation<Type>("callback", null, null, null); - contract = new JavaServiceContract(); - Map<String, Operation<Type>> ops = new HashMap<String, Operation<Type>>(); - ops.put("callback", callbackOperation); - contract.setCallbackOperations(ops); - } - - private AtomicComponent createSource() throws Exception { - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(false).anyTimes(); - EasyMock.expect(component.createTargetInvoker(EasyMock.eq("callback"), - EasyMock.isA(Operation.class), - (InboundWire) EasyMock.isNull())).andReturn(EasyMock.createNiceMock(TargetInvoker.class)); - EasyMock.replay(component); - return component; - } - - private class MockInterceptor implements Interceptor { - - public Message invoke(Message msg) { - return msg; - } - - public void setNext(Interceptor next) { - - } - - public Interceptor getNext() { - return null; - } - - public boolean isOptimizable() { - return false; - } - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/TargetServiceNotFoundExceptionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/TargetServiceNotFoundExceptionTestCase.java deleted file mode 100644 index b6ecd952e3..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/TargetServiceNotFoundExceptionTestCase.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.builder; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class TargetServiceNotFoundExceptionTestCase extends TestCase { - - public void testInstantiation() throws Exception { - TargetServiceNotFoundException e = new TargetServiceNotFoundException("message", - "source name", - "ref name", - "target name", - "service name"); - assertEquals("message", e.getMessage()); - assertEquals("source name", e.getSourceName()); - assertEquals("ref name", e.getReferenceName()); - assertEquals("target name", e.getTargetName()); - assertEquals("service name", e.getTargetServiceName()); - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/WirePostProcessorRegistryImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/WirePostProcessorRegistryImplTestCase.java deleted file mode 100644 index 359733a4fc..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/WirePostProcessorRegistryImplTestCase.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.builder; - -import org.apache.tuscany.spi.wire.WirePostProcessor; -import org.apache.tuscany.spi.wire.WirePostProcessorRegistry; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.OutboundWire; - -import junit.framework.TestCase; -import org.easymock.EasyMock; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.verify; - -/** - * @version $Rev$ $Date$ - */ -public class WirePostProcessorRegistryImplTestCase extends TestCase { - - public void testRegisterUnregister() throws Exception { - WirePostProcessorRegistry registry = new WirePostProcessorRegistryImpl(); - OutboundWire owire = EasyMock.createMock(OutboundWire.class); - InboundWire iwire = EasyMock.createMock(InboundWire.class); - WirePostProcessor processor = createMock(WirePostProcessor.class); - processor.process(EasyMock.eq(owire), EasyMock.eq(iwire)); - EasyMock.replay(processor); - registry.register(processor); - registry.process(owire, iwire); - registry.unregister(processor); - registry.process(owire, iwire); - verify(processor); - } - - public void testProcessInboundToOutbound() throws Exception { - WirePostProcessorRegistry registry = new WirePostProcessorRegistryImpl(); - OutboundWire owire = EasyMock.createMock(OutboundWire.class); - InboundWire iwire = EasyMock.createMock(InboundWire.class); - WirePostProcessor processor = createMock(WirePostProcessor.class); - processor.process(EasyMock.eq(iwire), EasyMock.eq(owire)); - EasyMock.replay(processor); - registry.register(processor); - registry.process(iwire, owire); - verify(processor); - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/WiringExceptionFormatterTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/WiringExceptionFormatterTestCase.java deleted file mode 100644 index 0269fd07e1..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/builder/WiringExceptionFormatterTestCase.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.builder; - -import java.io.PrintWriter; -import java.io.StringWriter; - -import org.apache.tuscany.spi.builder.WiringException; - -import junit.framework.TestCase; -import org.apache.tuscany.host.monitor.FormatterRegistry; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class WiringExceptionFormatterTestCase extends TestCase { - WiringExceptionFormatter formatter = new WiringExceptionFormatter(EasyMock.createNiceMock(FormatterRegistry.class)); - - public void testFormat() throws Exception { - WiringException e = new MockWiringException("message", - "identifier", - "source name", - "ref name", - "target name", - "service name"); - StringWriter writer = new StringWriter(); - PrintWriter pw = new PrintWriter(writer); - formatter.write(pw, e); - String buffer = writer.toString(); - assertTrue(buffer.indexOf("message") >= 0); - assertTrue(buffer.indexOf("identifier") >= 0); - assertTrue(buffer.indexOf("source name") >= 0); - assertTrue(buffer.indexOf("ref name") >= 0); - assertTrue(buffer.indexOf("target name") >= 0); - assertTrue(buffer.indexOf("service name") >= 0); - } - - - public void testFormatNulls() throws Exception { - WiringException e = new MockWiringException("message", - "identifier", - "source name", - null, - "target name", - null); - StringWriter writer = new StringWriter(); - PrintWriter pw = new PrintWriter(writer); - formatter.write(pw, e); - String buffer = writer.toString(); - assertTrue(buffer.indexOf("message") >= 0); - assertTrue(buffer.indexOf("identifier") >= 0); - assertTrue(buffer.indexOf("source name") >= 0); - assertTrue(buffer.indexOf("target name") >= 0); - } - - private class MockWiringException extends WiringException { - - public MockWiringException(String message, String - identifier, - String sourceName, - String referenceName, - String targetName, - String serviceName) { - super(message, identifier); - setSourceName(sourceName); - setReferenceName(referenceName); - setTargetName(targetName); - setTargetServiceName(serviceName); - } - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/WorkContextImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/WorkContextImplTestCase.java deleted file mode 100644 index aee910ddaf..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/WorkContextImplTestCase.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component; - -import org.apache.tuscany.spi.component.WorkContext; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class WorkContextImplTestCase extends TestCase { - - public void testPushPopServiceNames() throws Exception { - WorkContext context = new WorkContextImpl(); - context.pushServiceName("foo"); - context.pushServiceName("bar"); - assertEquals("bar", context.getCurrentServiceName()); - assertEquals("bar", context.popServiceName()); - assertEquals("foo", context.getCurrentServiceName()); - assertEquals("foo", context.popServiceName()); - assertNull(context.getCurrentServiceName()); - } - - public void testGetCurrentServiceNamesNull() throws Exception { - WorkContext context = new WorkContextImpl(); - assertNull(context.getCurrentServiceName()); - } - - public void testPopCurrentServiceNamesNull() throws Exception { - WorkContext context = new WorkContextImpl(); - assertNull(context.popServiceName()); - } - - public void testClearServiceNames() throws Exception { - WorkContext context = new WorkContextImpl(); - context.pushServiceName("foo"); - context.pushServiceName("bar"); - context.clearServiceNames(); - assertNull(context.getCurrentServiceName()); - } - - public void testClearServiceNamesNull() throws Exception { - WorkContext context = new WorkContextImpl(); - context.clearServiceNames(); - assertNull(context.getCurrentServiceName()); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/event/EventTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/event/EventTestCase.java deleted file mode 100644 index 79b9757c2c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/event/EventTestCase.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.event; - -import org.apache.tuscany.spi.component.CompositeComponent; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class EventTestCase extends TestCase { - - private CompositeComponent component; - - public void testCompositeStart() { - CompositeStart event = new CompositeStart(this, component); - assertEquals(component, event.getComposite()); - } - - public void testCompositeStop() { - CompositeStop event = new CompositeStop(this, component); - assertEquals(component, event.getComposite()); - } - - public void testHttpSessionStart() { - Object id = new Object(); - HttpSessionEvent event = new HttpSessionStart(this, id); - assertEquals(this, event.getSource()); - assertEquals(id, event.getId()); - } - - public void testHttpSessionEnd() { - Object id = new Object(); - HttpSessionEvent event = new HttpSessionEnd(this, id); - assertEquals(this, event.getSource()); - assertEquals(id, event.getId()); - } - - public void testRequestStart() { - RequestStart event = new RequestStart(this); - assertEquals(this, event.getSource()); - } - - public void testReequestEnd() { - RequestEnd event = new RequestEnd(this); - assertEquals(this, event.getSource()); - } - - - protected void setUp() throws Exception { - super.setUp(); - component = EasyMock.createNiceMock(CompositeComponent.class); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/AbstractScopeContainerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/AbstractScopeContainerTestCase.java deleted file mode 100644 index f8f8dd5f60..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/AbstractScopeContainerTestCase.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.scope; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.event.Event; -import org.apache.tuscany.spi.event.EventFilter; -import org.apache.tuscany.spi.event.RuntimeEventListener; -import org.apache.tuscany.spi.event.TrueFilter; -import org.apache.tuscany.spi.model.Scope; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class AbstractScopeContainerTestCase extends TestCase { - - public void testFireListener() { - TestContainer container = new TestContainer("foo"); - RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); - Event event = new TestEvent(); - listener.onEvent(EasyMock.eq(event)); - EasyMock.replay(listener); - container.addListener(listener); - container.publish(event); - EasyMock.verify(listener); - } - - public void testRemoveListener() { - TestContainer container = new TestContainer("foo"); - RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); - EasyMock.replay(listener); - Event event = new TestEvent(); - container.addListener(listener); - container.removeListener(listener); - container.publish(event); - EasyMock.verify(listener); - } - - public void testFalseFilterListener() { - TestContainer container = new TestContainer("foo"); - RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); - Event event = new TestEvent(); - EasyMock.replay(listener); - container.addListener(new FalseFilter(), listener); - container.publish(event); - EasyMock.verify(listener); - } - - public void testTrueFilterListener() { - TestContainer container = new TestContainer("foo"); - RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); - Event event = new TestEvent(); - listener.onEvent(EasyMock.eq(event)); - EasyMock.replay(listener); - container.addListener(new TrueFilter(), listener); - container.publish(event); - EasyMock.verify(listener); - } - - public void testToString() { - TestContainer container = new TestContainer("foo"); - assertNotNull(container.toString()); - } - - private class TestContainer extends AbstractScopeContainer { - - public TestContainer(String name) { - super(null, null); - } - - protected InstanceWrapper getInstanceWrapper(AtomicComponent component, boolean create) { - return null; - } - - public Scope getScope() { - return null; - } - - public void register(AtomicComponent component) { - - } - - public void onEvent(Event event) { - - } - - public WorkContext getWorkContext() { - return super.getWorkContext(); - } - } - - private class TestEvent implements Event { - public Object getSource() { - return null; - } - } - - private class FalseFilter implements EventFilter { - - public boolean match(Event event) { - return false; - } - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicCompositeScopeTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicCompositeScopeTestCase.java deleted file mode 100644 index cd68b46541..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicCompositeScopeTestCase.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.scope; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.component.TargetNotFoundException; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.event.CompositeStop; -import org.apache.tuscany.core.implementation.PojoConfiguration; -import org.apache.tuscany.core.implementation.system.component.SystemAtomicComponentImpl; -import org.apache.tuscany.core.injection.EventInvoker; -import org.apache.tuscany.core.injection.MethodEventInvoker; -import org.apache.tuscany.core.injection.PojoObjectFactory; -import org.apache.tuscany.core.mock.component.CompositeScopeInitDestroyComponent; - -/** - * @version $$Rev$$ $$Date$$ - */ -public class BasicCompositeScopeTestCase extends TestCase { - - private EventInvoker<Object> initInvoker; - private EventInvoker<Object> destroyInvoker; - private PojoObjectFactory<?> factory; - - public void testLifecycleManagement() throws Exception { - CompositeScopeContainer scopeContext = new CompositeScopeContainer(null); - scopeContext.start(); - AtomicComponent component = createComponent(scopeContext); - // start the request - CompositeScopeInitDestroyComponent o1 = - (CompositeScopeInitDestroyComponent) scopeContext.getInstance(component); - assertTrue(o1.isInitialized()); - assertFalse(o1.isDestroyed()); - CompositeScopeInitDestroyComponent o2 = - (CompositeScopeInitDestroyComponent) scopeContext.getInstance(component); - assertEquals(o1, o2); - scopeContext.onEvent(new CompositeStop(this, null)); - assertTrue(o1.isDestroyed()); - scopeContext.stop(); - } - - - public void testGetAssociatedInstance() throws Exception { - CompositeScopeContainer scopeContext = new CompositeScopeContainer(null); - scopeContext.start(); - AtomicComponent component = createComponent(scopeContext); - // start the request - scopeContext.getInstance(component); - scopeContext.getAssociatedInstance(component); - } - - public void testGetAssociatedInstanceNonExistent() throws Exception { - CompositeScopeContainer scopeContext = new CompositeScopeContainer(null); - scopeContext.start(); - AtomicComponent component = createComponent(scopeContext); - // start the request - try { - scopeContext.getAssociatedInstance(component); - fail(); - } catch (TargetNotFoundException e) { - // expected - } - } - - public void testCompositeIsolation() throws Exception { - CompositeScopeContainer scopeContext = new CompositeScopeContainer(null); - scopeContext.start(); - - AtomicComponent component = createComponent(scopeContext); - - CompositeScopeInitDestroyComponent o1 = - (CompositeScopeInitDestroyComponent) scopeContext.getInstance(component); - assertTrue(o1.isInitialized()); - assertFalse(o1.isDestroyed()); - - CompositeScopeInitDestroyComponent o2 = - (CompositeScopeInitDestroyComponent) scopeContext.getInstance(component); - assertSame(o1, o2); - scopeContext.onEvent(new CompositeStop(this, null)); - assertTrue(o1.isDestroyed()); - scopeContext.stop(); - } - - protected void setUp() throws Exception { - super.setUp(); - factory = new PojoObjectFactory<CompositeScopeInitDestroyComponent>( - CompositeScopeInitDestroyComponent.class.getConstructor((Class[]) null)); - initInvoker = new MethodEventInvoker<Object>(CompositeScopeInitDestroyComponent.class.getMethod( - "init", (Class[]) null)); - destroyInvoker = new MethodEventInvoker<Object>(CompositeScopeInitDestroyComponent.class.getMethod( - "destroy", (Class[]) null)); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - - private AtomicComponent createComponent(ScopeContainer scopeContainer) { - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setInstanceFactory(factory); - configuration.setInitInvoker(initInvoker); - configuration.setDestroyInvoker(destroyInvoker); - configuration.setName("foo"); - SystemAtomicComponentImpl component = new SystemAtomicComponentImpl(configuration); - component.setScopeContainer(scopeContainer); - component.start(); - return component; - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicConversationalScopeTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicConversationalScopeTestCase.java deleted file mode 100644 index c97f3cb96f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicConversationalScopeTestCase.java +++ /dev/null @@ -1,129 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tuscany.core.component.scope;
-
-import org.apache.tuscany.spi.component.AtomicComponent;
-import org.apache.tuscany.spi.component.ScopeContainer;
-import org.apache.tuscany.spi.component.WorkContext;
-import org.apache.tuscany.spi.model.Scope;
-import org.apache.tuscany.spi.services.store.StoreMonitor;
-
-import junit.framework.TestCase;
-import org.apache.tuscany.core.component.WorkContextImpl;
-import org.apache.tuscany.core.component.event.ConversationEnd;
-import org.apache.tuscany.core.implementation.PojoConfiguration;
-import org.apache.tuscany.core.implementation.system.component.SystemAtomicComponentImpl;
-import org.apache.tuscany.core.injection.EventInvoker;
-import org.apache.tuscany.core.injection.MethodEventInvoker;
-import org.apache.tuscany.core.injection.PojoObjectFactory;
-import org.apache.tuscany.core.mock.component.ConversationalScopeInitDestroyComponent;
-import org.apache.tuscany.core.services.store.memory.MemoryStore;
-import org.easymock.EasyMock;
-
-/**
- * @version $$Rev: 471111 $$ $$Date: 2006-11-03 23:06:48 -0500 (Fri, 03 Nov 2006) $$
- */
-public class BasicConversationalScopeTestCase extends TestCase {
-
- private EventInvoker<Object> initInvoker;
- private EventInvoker<Object> destroyInvoker;
- private PojoObjectFactory<?> factory;
-
- public void testLifecycleManagement() throws Exception {
- StoreMonitor monitor = EasyMock.createMock(StoreMonitor.class);
- monitor.start(EasyMock.isA(String.class));
- monitor.stop(EasyMock.isA(String.class));
- MemoryStore store = new MemoryStore(monitor);
- WorkContext workContext = new WorkContextImpl();
- ConversationalScopeContainer scopeContext = new ConversationalScopeContainer(store, workContext, null);
- scopeContext.start();
- AtomicComponent atomicContext = createContext(scopeContext);
- // start the request
- String conversation = "conv";
- workContext.setIdentifier(Scope.CONVERSATION, conversation);
- ConversationalScopeInitDestroyComponent o1 =
- (ConversationalScopeInitDestroyComponent) scopeContext.getInstance(atomicContext);
- //assertTrue(o1.isInitialized());
- assertFalse(o1.isDestroyed());
- ConversationalScopeInitDestroyComponent o2 =
- (ConversationalScopeInitDestroyComponent) scopeContext.getInstance(atomicContext);
- assertSame(o1, o2);
- scopeContext.onEvent(new ConversationEnd(this, conversation));
- //assertTrue(o1.isDestroyed());
- scopeContext.stop();
- }
-
- public void testCompositeIsolation() throws Exception {
- StoreMonitor monitor = EasyMock.createMock(StoreMonitor.class);
- monitor.start(EasyMock.isA(String.class));
- monitor.stop(EasyMock.isA(String.class));
- MemoryStore store = new MemoryStore(monitor);
- WorkContext workContext = new WorkContextImpl();
- ConversationalScopeContainer scopeContext = new ConversationalScopeContainer(store, workContext, null);
- scopeContext.start();
-
- AtomicComponent atomicContext = createContext(scopeContext);
-
- String conversation1 = "conv";
- workContext.setIdentifier(Scope.CONVERSATION, conversation1);
- ConversationalScopeInitDestroyComponent o1 =
- (ConversationalScopeInitDestroyComponent) scopeContext.getInstance(atomicContext);
- //assertTrue(o1.isInitialized());
- assertFalse(o1.isDestroyed());
-
- String conversation2 = "conv2";
- workContext.setIdentifier(Scope.CONVERSATION, conversation2);
- ConversationalScopeInitDestroyComponent o2 =
- (ConversationalScopeInitDestroyComponent) scopeContext.getInstance(atomicContext);
- assertNotSame(o1, o2);
-
- scopeContext.onEvent(new ConversationEnd(this, conversation1));
- //assertTrue(o1.isDestroyed());
- assertFalse(o2.isDestroyed());
- scopeContext.onEvent(new ConversationEnd(this, conversation2));
- //assertTrue(o2.isDestroyed());
- scopeContext.stop();
- }
-
- protected void setUp() throws Exception {
- super.setUp();
- factory = new PojoObjectFactory<ConversationalScopeInitDestroyComponent>(
- ConversationalScopeInitDestroyComponent.class.getConstructor((Class[]) null));
- initInvoker = new MethodEventInvoker<Object>(
- ConversationalScopeInitDestroyComponent.class.getMethod("init", (Class[]) null));
- destroyInvoker = new MethodEventInvoker<Object>(
- ConversationalScopeInitDestroyComponent.class.getMethod("destroy", (Class[]) null));
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- private AtomicComponent createContext(ScopeContainer scopeContainer) {
- PojoConfiguration configuration = new PojoConfiguration();
- configuration.setInstanceFactory(factory);
- configuration.setInitInvoker(initInvoker);
- configuration.setDestroyInvoker(destroyInvoker);
- configuration.setName("foo");
- SystemAtomicComponentImpl component = new SystemAtomicComponentImpl(configuration);
- component.setScopeContainer(scopeContainer);
- component.start();
- return component;
- }
-}
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicHttpSessionScopeTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicHttpSessionScopeTestCase.java deleted file mode 100644 index 44e9bbc1d6..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicHttpSessionScopeTestCase.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.scope; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.component.TargetNotFoundException; -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.model.Scope; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.component.event.HttpSessionEnd; -import org.apache.tuscany.core.implementation.PojoConfiguration; -import org.apache.tuscany.core.implementation.system.component.SystemAtomicComponentImpl; -import org.apache.tuscany.core.injection.EventInvoker; -import org.apache.tuscany.core.injection.MethodEventInvoker; -import org.apache.tuscany.core.injection.PojoObjectFactory; -import org.apache.tuscany.core.mock.component.SessionScopeInitDestroyComponent; - -/** - * @version $$Rev$$ $$Date$$ - */ -public class BasicHttpSessionScopeTestCase extends TestCase { - private EventInvoker<Object> initInvoker; - private EventInvoker<Object> destroyInvoker; - private PojoObjectFactory<?> factory; - - public void testLifecycleManagement() throws Exception { - WorkContext workContext = new WorkContextImpl(); - HttpSessionScopeContainer scopeContext = new HttpSessionScopeContainer(workContext, null); - scopeContext.start(); - AtomicComponent component = createComponent(scopeContext); - // start the request - Object session = new Object(); - workContext.setIdentifier(Scope.SESSION, session); - SessionScopeInitDestroyComponent o1 = - (SessionScopeInitDestroyComponent) scopeContext.getInstance(component); - assertTrue(o1.isInitialized()); - assertFalse(o1.isDestroyed()); - SessionScopeInitDestroyComponent o2 = - (SessionScopeInitDestroyComponent) scopeContext.getInstance(component); - assertSame(o1, o2); - scopeContext.onEvent(new HttpSessionEnd(this, session)); - assertTrue(o1.isDestroyed()); - scopeContext.stop(); - } - - public void testGetAssociatedInstance() throws Exception { - WorkContext workContext = new WorkContextImpl(); - HttpSessionScopeContainer scopeContext = new HttpSessionScopeContainer(workContext, null); - scopeContext.start(); - AtomicComponent component = createComponent(scopeContext); - // start the request - Object session = new Object(); - workContext.setIdentifier(Scope.SESSION, session); - scopeContext.getInstance(component); - scopeContext.getAssociatedInstance(component); - } - - public void testGetAssociatedInstanceNonExistent() throws Exception { - WorkContext workContext = new WorkContextImpl(); - HttpSessionScopeContainer scopeContext = new HttpSessionScopeContainer(workContext, null); - scopeContext.start(); - AtomicComponent component = createComponent(scopeContext); - // start the request - Object session = new Object(); - workContext.setIdentifier(Scope.SESSION, session); - try { - scopeContext.getAssociatedInstance(component); - fail(); - } catch (TargetNotFoundException e) { - // expected - } - } - - public void testSessionIsolation() throws Exception { - WorkContext workContext = new WorkContextImpl(); - HttpSessionScopeContainer scopeContext = new HttpSessionScopeContainer(workContext, null); - scopeContext.start(); - - AtomicComponent component = createComponent(scopeContext); - - Object session1 = new Object(); - workContext.setIdentifier(Scope.SESSION, session1); - SessionScopeInitDestroyComponent o1 = - (SessionScopeInitDestroyComponent) scopeContext.getInstance(component); - assertTrue(o1.isInitialized()); - - Object session2 = new Object(); - workContext.setIdentifier(Scope.SESSION, session2); - SessionScopeInitDestroyComponent o2 = - (SessionScopeInitDestroyComponent) scopeContext.getInstance(component); - assertNotSame(o1, o2); - - scopeContext.onEvent(new HttpSessionEnd(this, session1)); - assertTrue(o1.isDestroyed()); - assertFalse(o2.isDestroyed()); - scopeContext.onEvent(new HttpSessionEnd(this, session2)); - assertTrue(o2.isDestroyed()); - scopeContext.stop(); - } - - protected void setUp() throws Exception { - super.setUp(); - factory = new PojoObjectFactory<SessionScopeInitDestroyComponent>( - SessionScopeInitDestroyComponent.class.getConstructor((Class[]) null)); - initInvoker = new MethodEventInvoker<Object>( - SessionScopeInitDestroyComponent.class.getMethod("init", (Class[]) null)); - destroyInvoker = new MethodEventInvoker<Object>( - SessionScopeInitDestroyComponent.class.getMethod("destroy", (Class[]) null)); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - - private AtomicComponent createComponent(ScopeContainer scopeContainer) { - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setInstanceFactory(factory); - configuration.setInitInvoker(initInvoker); - configuration.setDestroyInvoker(destroyInvoker); - configuration.setName("foo"); - SystemAtomicComponentImpl component = new SystemAtomicComponentImpl(configuration); - component.setScopeContainer(scopeContainer); - component.start(); - return component; - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicRequestScopeTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicRequestScopeTestCase.java deleted file mode 100644 index 435e7d29b7..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicRequestScopeTestCase.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.scope; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.component.TargetNotFoundException; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.event.RequestEnd; -import org.apache.tuscany.core.implementation.PojoConfiguration; -import org.apache.tuscany.core.implementation.system.component.SystemAtomicComponentImpl; -import org.apache.tuscany.core.injection.EventInvoker; -import org.apache.tuscany.core.injection.MethodEventInvoker; -import org.apache.tuscany.core.injection.PojoObjectFactory; -import org.apache.tuscany.core.mock.component.RequestScopeInitDestroyComponent; - -/** - * @version $$Rev$$ $$Date$$ - */ -public class BasicRequestScopeTestCase extends TestCase { - private EventInvoker<Object> initInvoker; - private EventInvoker<Object> destroyInvoker; - private PojoObjectFactory<?> factory; - - public void testLifecycleManagement() throws Exception { - RequestScopeContainer scopeContainer = new RequestScopeContainer(null, null); - scopeContainer.start(); - AtomicComponent component = createComponent(scopeContainer); - // start the request - RequestScopeInitDestroyComponent o1 = - (RequestScopeInitDestroyComponent) scopeContainer.getInstance(component); - assertTrue(o1.isInitialized()); - assertFalse(o1.isDestroyed()); - RequestScopeInitDestroyComponent o2 = - (RequestScopeInitDestroyComponent) scopeContainer.getInstance(component); - assertSame(o1, o2); - scopeContainer.onEvent(new RequestEnd(this)); - assertTrue(o1.isDestroyed()); - scopeContainer.stop(); - } - - public void testGetAssociatedInstance() throws Exception { - RequestScopeContainer scopeContainer = new RequestScopeContainer(null, null); - scopeContainer.start(); - AtomicComponent component = createComponent(scopeContainer); - // start the request - scopeContainer.getInstance(component); - scopeContainer.getAssociatedInstance(component); - scopeContainer.stop(); - } - - public void testGetAssociatedInstanceNonExistent() throws Exception { - RequestScopeContainer scopeContainer = new RequestScopeContainer(null, null); - scopeContainer.start(); - AtomicComponent component = createComponent(scopeContainer); - // start the request - try { - scopeContainer.getAssociatedInstance(component); - fail(); - } catch (TargetNotFoundException e) { - // expected - } - scopeContainer.stop(); - } - - public void testRequestIsolation() throws Exception { - RequestScopeContainer scopeContainer = new RequestScopeContainer(null, null); - scopeContainer.start(); - - AtomicComponent component = createComponent(scopeContainer); - - RequestScopeInitDestroyComponent o1 = - (RequestScopeInitDestroyComponent) scopeContainer.getInstance(component); - assertTrue(o1.isInitialized()); - scopeContainer.onEvent(new RequestEnd(this)); - assertTrue(o1.isDestroyed()); - - RequestScopeInitDestroyComponent o2 = - (RequestScopeInitDestroyComponent) scopeContainer.getInstance(component); - assertNotSame(o1, o2); - scopeContainer.onEvent(new RequestEnd(this)); - assertTrue(o2.isDestroyed()); - scopeContainer.stop(); - } - - protected void setUp() throws Exception { - super.setUp(); - factory = new PojoObjectFactory<RequestScopeInitDestroyComponent>( - RequestScopeInitDestroyComponent.class.getConstructor((Class[]) null)); - initInvoker = new MethodEventInvoker<Object>( - RequestScopeInitDestroyComponent.class.getMethod("init", (Class[]) null)); - destroyInvoker = new MethodEventInvoker<Object>( - RequestScopeInitDestroyComponent.class.getMethod("destroy", (Class[]) null)); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - - private AtomicComponent createComponent(ScopeContainer scopeContainer) { - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setInstanceFactory(factory); - configuration.setInitInvoker(initInvoker); - configuration.setDestroyInvoker(destroyInvoker); - configuration.setName("foo"); - SystemAtomicComponentImpl component = new SystemAtomicComponentImpl(configuration); - component.setScopeContainer(scopeContainer); - component.start(); - return component; - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicStatelessScopeTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicStatelessScopeTestCase.java deleted file mode 100644 index 9ca9230e5b..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/BasicStatelessScopeTestCase.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.scope; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.component.TargetNotFoundException; -import org.apache.tuscany.spi.component.WorkContext; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.implementation.PojoConfiguration; -import org.apache.tuscany.core.implementation.system.component.SystemAtomicComponentImpl; -import org.apache.tuscany.core.injection.PojoObjectFactory; -import org.apache.tuscany.core.mock.component.StatelessComponent; -import org.apache.tuscany.core.mock.component.StatelessComponentImpl; - -/** - * Unit tests for the composite scope container - * - * @version $Rev$ $Date$ - */ -public class BasicStatelessScopeTestCase extends TestCase { - private PojoObjectFactory<StatelessComponentImpl> factory; - - /** - * Verfies instance identity is properly maintained - */ - public void testInstanceManagement() throws Exception { - WorkContext ctx = new WorkContextImpl(); - StatelessScopeContainer scope = new StatelessScopeContainer(ctx, null); - scope.start(); - AtomicComponent component1 = createComponent(scope); - scope.register(component1); - AtomicComponent component2 = createComponent(scope); - scope.register(component2); - StatelessComponentImpl comp1 = (StatelessComponentImpl) scope.getInstance(component1); - Assert.assertNotNull(comp1); - StatelessComponentImpl comp2 = (StatelessComponentImpl) scope.getInstance(component2); - Assert.assertNotNull(comp2); - Assert.assertNotSame(comp1, comp2); - scope.stop(); - } - - public void testGetAssociatedInstance() throws Exception { - WorkContext ctx = new WorkContextImpl(); - StatelessScopeContainer scope = new StatelessScopeContainer(ctx, null); - scope.start(); - AtomicComponent component1 = createComponent(scope); - scope.register(component1); - try { - // always throws an exception, which is the semantic for stateless implementations - scope.getAssociatedInstance(component1); - fail(); - } catch (TargetNotFoundException e) { - // expected - } - scope.stop(); - } - - public void testRegisterContextAfterRequest() throws Exception { - WorkContext ctx = new WorkContextImpl(); - StatelessScopeContainer scope = new StatelessScopeContainer(ctx, null); - - scope.start(); - AtomicComponent component1 = createComponent(scope); - scope.register(component1); - StatelessComponent comp1 = (StatelessComponentImpl) scope.getInstance(component1); - Assert.assertNotNull(comp1); - AtomicComponent component2 = createComponent(scope); - scope.register(component2); - StatelessComponentImpl comp2 = (StatelessComponentImpl) scope.getInstance(component2); - Assert.assertNotNull(comp2); - scope.stop(); - } - - - /** - * Tests setting no components in the scope - */ - public void testSetNullComponents() throws Exception { - WorkContext ctx = new WorkContextImpl(); - StatelessScopeContainer scope = new StatelessScopeContainer(ctx, null); - scope.start(); - scope.stop(); - } - - protected void setUp() throws Exception { - super.setUp(); - factory = - new PojoObjectFactory<StatelessComponentImpl>(StatelessComponentImpl.class.getConstructor((Class[]) null)); - - } - - private AtomicComponent createComponent(ScopeContainer scopeContainer) { - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setInstanceFactory(factory); - configuration.setName("foo"); - AtomicComponent component = new SystemAtomicComponentImpl(configuration); - component.setScopeContainer(scopeContainer); - return component; - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInitDestroyErrorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInitDestroyErrorTestCase.java deleted file mode 100644 index 8ac4ce46a4..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInitDestroyErrorTestCase.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.scope; - -import org.apache.tuscany.spi.ObjectCreationException; -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.ScopeContainerMonitor; -import org.apache.tuscany.spi.component.TargetDestructionException; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.event.CompositeStart; -import org.apache.tuscany.core.component.event.CompositeStop; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class CompositeScopeInitDestroyErrorTestCase extends TestCase { - - public void testInitializeErrorMonitor() throws Exception { - ScopeContainerMonitor monitor; - monitor = EasyMock.createMock(ScopeContainerMonitor.class); - monitor.eagerInitializationError(EasyMock.isA(ObjectCreationException.class)); - EasyMock.replay(monitor); - CompositeScopeContainer scope = new CompositeScopeContainer(monitor); - scope.start(); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("foo").atLeastOnce(); - EasyMock.expect(component.createInstance()).andThrow(new ObjectCreationException("")); - EasyMock.expect(component.getInitLevel()).andReturn(1); - EasyMock.replay(component); - scope.register(component); - scope.onEvent(new CompositeStart(this, null)); - EasyMock.verify(monitor); - } - - public void testDestroyErrorMonitor() throws Exception { - ScopeContainerMonitor monitor; - monitor = EasyMock.createMock(ScopeContainerMonitor.class); - monitor.destructionError(EasyMock.isA(TargetDestructionException.class)); - EasyMock.replay(monitor); - CompositeScopeContainer scope = new CompositeScopeContainer(monitor); - scope.start(); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("foo").atLeastOnce(); - EasyMock.expect(component.createInstance()).andReturn(new Object()); - EasyMock.expect(component.getInitLevel()).andReturn(1); - component.init(EasyMock.isA(Object.class)); - component.destroy(EasyMock.isA(Object.class)); - EasyMock.expectLastCall().andThrow(new TargetDestructionException("", "")); - EasyMock.replay(component); - scope.register(component); - scope.onEvent(new CompositeStart(this, null)); - scope.onEvent(new CompositeStop(this, null)); - EasyMock.verify(monitor); - } - - - protected void setUp() throws Exception { - super.setUp(); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInstanceLifecycleTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInstanceLifecycleTestCase.java deleted file mode 100644 index 0d70bcf252..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInstanceLifecycleTestCase.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.scope; - - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.TargetException; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.event.CompositeStart; -import org.apache.tuscany.core.component.event.CompositeStop; -import org.apache.tuscany.core.mock.component.OrderedInitPojo; -import org.apache.tuscany.core.mock.component.OrderedInitPojoImpl; -import org.easymock.EasyMock; -import org.easymock.IAnswer; - -/** - * Lifecycle unit tests for the composite scope container - * - * @version $Rev$ $Date$ - */ -public class CompositeScopeInstanceLifecycleTestCase extends TestCase { - - /** - * Verify init and stop by scope container on an atomic component - * - * @throws Exception - */ - public void testInitDestroy() throws Exception { - CompositeScopeContainer scope = new CompositeScopeContainer(null); - scope.start(); - Foo comp = new Foo(); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.createInstance()).andReturn(comp); - EasyMock.expect(component.getInitLevel()).andReturn(1).atLeastOnce(); - component.init(EasyMock.eq(comp)); - component.destroy(EasyMock.eq(comp)); - EasyMock.replay(component); - scope.register(component); - scope.onEvent(new CompositeStart(this, null)); - assertNotNull(scope.getInstance(component)); - // expire composite - scope.onEvent(new CompositeStop(this, null)); - scope.stop(); - EasyMock.verify(component); - } - - /** - * Verify init and stop by scope container on an atomic component when set to eager initialize - * - * @throws Exception - */ - public void testEagerInitDestroy() throws Exception { - CompositeScopeContainer scope = new CompositeScopeContainer(null); - scope.start(); - Foo comp = new Foo(); - AtomicComponent initDestroyComponent = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(initDestroyComponent.createInstance()).andReturn(comp); - EasyMock.expect(initDestroyComponent.getInitLevel()).andReturn(1).atLeastOnce(); - initDestroyComponent.init(EasyMock.eq(comp)); - initDestroyComponent.destroy(EasyMock.eq(comp)); - EasyMock.replay(initDestroyComponent); - scope.register(initDestroyComponent); - scope.onEvent(new CompositeStart(this, null)); - // expire composite - scope.onEvent(new CompositeStop(this, null)); - scope.stop(); - EasyMock.verify(initDestroyComponent); - } - - - public void testDestroyOrder() throws Exception { - CompositeScopeContainer scope = new CompositeScopeContainer(null); - scope.start(); - - AtomicComponent oneComponent = createComponent(0); - scope.register(oneComponent); - AtomicComponent twoComponent = createComponent(0); - scope.register(twoComponent); - AtomicComponent threeComponent = createComponent(0); - scope.register(threeComponent); - - scope.onEvent(new CompositeStart(this, null)); - OrderedInitPojo one = (OrderedInitPojo) scope.getInstance(oneComponent); - assertNotNull(one); - assertEquals(1, one.getNumberInstantiated()); - assertEquals(1, one.getInitOrder()); - - OrderedInitPojo two = (OrderedInitPojo) scope.getInstance(twoComponent); - assertNotNull(two); - assertEquals(2, two.getNumberInstantiated()); - assertEquals(2, two.getInitOrder()); - - OrderedInitPojo three = (OrderedInitPojo) scope.getInstance(threeComponent); - assertNotNull(three); - assertEquals(3, three.getNumberInstantiated()); - assertEquals(3, three.getInitOrder()); - - // expire composite - scope.onEvent(new CompositeStop(this, null)); - assertEquals(0, one.getNumberInstantiated()); - scope.stop(); - EasyMock.verify(oneComponent); - EasyMock.verify(twoComponent); - EasyMock.verify(threeComponent); - } - - public void testEagerInitDestroyOrder() throws Exception { - CompositeScopeContainer scope = new CompositeScopeContainer(null); - scope.start(); - - AtomicComponent oneComponent = createComponent(1); - scope.register(oneComponent); - AtomicComponent twoComponent = createComponent(1); - scope.register(twoComponent); - AtomicComponent threeComponent = createComponent(1); - scope.register(threeComponent); - - scope.onEvent(new CompositeStart(this, null)); - OrderedInitPojo one = (OrderedInitPojo) scope.getInstance(oneComponent); - assertNotNull(one); - - OrderedInitPojo two = (OrderedInitPojo) scope.getInstance(twoComponent); - assertNotNull(two); - - OrderedInitPojo three = (OrderedInitPojo) scope.getInstance(threeComponent); - assertNotNull(three); - - // expire composite - scope.onEvent(new CompositeStop(this, null)); - assertEquals(0, one.getNumberInstantiated()); - scope.stop(); - EasyMock.verify(oneComponent); - EasyMock.verify(twoComponent); - EasyMock.verify(threeComponent); - } - - @SuppressWarnings("unchecked") - private AtomicComponent createComponent(int init) throws TargetException { - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.createInstance()).andStubAnswer(new IAnswer() { - public Object answer() throws Throwable { - return new OrderedInitPojoImpl(); - } - }); - EasyMock.expect(component.getInitLevel()).andReturn(init).atLeastOnce(); - component.init(EasyMock.isA(OrderedInitPojoImpl.class)); - EasyMock.expectLastCall().andAnswer(new IAnswer() { - public Object answer() throws Throwable { - OrderedInitPojoImpl pojo = (OrderedInitPojoImpl) EasyMock.getCurrentArguments()[0]; - pojo.init(); - return null; - } - }); - component.destroy(EasyMock.isA(OrderedInitPojoImpl.class)); - EasyMock.expectLastCall().andAnswer(new IAnswer() { - public Object answer() throws Throwable { - OrderedInitPojoImpl pojo = (OrderedInitPojoImpl) EasyMock.getCurrentArguments()[0]; - pojo.destroy(); - return null; - } - }); - EasyMock.replay(component); - return component; - } - - private class Foo { - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeObjectFactoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeObjectFactoryTestCase.java deleted file mode 100644 index 611fbfc13f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeObjectFactoryTestCase.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.scope; - -import org.apache.tuscany.spi.component.ScopeRegistry; -import org.apache.tuscany.spi.model.Scope; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class CompositeScopeObjectFactoryTestCase extends TestCase { - - public void testCreation() { - ScopeRegistry registry = EasyMock.createMock(ScopeRegistry.class); - registry.registerFactory(EasyMock.isA(Scope.class), EasyMock.isA(CompositeScopeObjectFactory.class)); - - assertNotNull(new CompositeScopeObjectFactory(registry, null).getInstance()); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeRestartTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeRestartTestCase.java deleted file mode 100644 index 1fdaeed48c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeRestartTestCase.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.scope; - -import java.lang.reflect.Constructor; - -import org.apache.tuscany.spi.component.AtomicComponent; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.event.CompositeStart; -import org.apache.tuscany.core.component.event.CompositeStop; -import org.apache.tuscany.core.implementation.PojoConfiguration; -import org.apache.tuscany.core.implementation.system.component.SystemAtomicComponentImpl; -import org.apache.tuscany.core.injection.MethodEventInvoker; -import org.apache.tuscany.core.injection.PojoObjectFactory; - -/** - * Verifies the scope container properly disposes resources and canbe restarted - * - * @version $$Rev$$ $$Date$$ - */ -public class CompositeScopeRestartTestCase extends TestCase { - - public void testRestart() throws Exception { - CompositeScopeContainer scope = new CompositeScopeContainer(null); - scope.start(); - MethodEventInvoker<Object> initInvoker = - new MethodEventInvoker<Object>(InitDestroyOnce.class.getMethod("init")); - MethodEventInvoker<Object> destroyInvoker = - new MethodEventInvoker<Object>(InitDestroyOnce.class.getMethod("destroy")); - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setInitInvoker(initInvoker); - configuration.setDestroyInvoker(destroyInvoker); - Constructor<InitDestroyOnce> ctr = InitDestroyOnce.class.getConstructor((Class<?>[]) null); - configuration.setInstanceFactory(new PojoObjectFactory<InitDestroyOnce>(ctr)); - configuration.setName("InitDestroy"); - AtomicComponent component = new SystemAtomicComponentImpl(configuration); - component.setScopeContainer(scope); - component.start(); - - scope.onEvent(new CompositeStart(this, null)); - Object instance = component.getTargetInstance(); - assertSame(instance, component.getTargetInstance()); - - scope.onEvent(new CompositeStop(this, null)); - scope.stop(); - component.stop(); - - scope.start(); - scope.onEvent(new CompositeStart(this, null)); - component.start(); - assertNotSame(instance, component.getTargetInstance()); - scope.onEvent(new CompositeStop(this, null)); - scope.stop(); - component.stop(); - } - - public static class InitDestroyOnce { - - private boolean initialized; - private boolean destroyed; - - public InitDestroyOnce() { - } - - public void init() { - if (!initialized) { - initialized = true; - } else { - fail("Scope did not clean up properly - Init called more than once"); - } - } - - public void destroy() { - if (!destroyed) { - destroyed = true; - } else { - fail("Scope did not clean up properly - Destroyed called more than once"); - } - } - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerDestroyOnExpirationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerDestroyOnExpirationTestCase.java deleted file mode 100644 index a1a3616d0a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerDestroyOnExpirationTestCase.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.scope; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.SCAObject; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.event.Event; -import org.apache.tuscany.spi.event.EventFilter; -import org.apache.tuscany.spi.event.RuntimeEventListener; -import org.apache.tuscany.spi.services.store.RecoveryListener; -import org.apache.tuscany.spi.services.store.Store; -import org.apache.tuscany.spi.services.store.StoreExpirationEvent; -import org.apache.tuscany.spi.services.store.StoreReadException; -import org.apache.tuscany.spi.services.store.StoreWriteException; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class ConversationalScopeContainerDestroyOnExpirationTestCase extends TestCase { - private ScopeContainer container; - private TestStore store; - private AtomicComponent component; - - /** - * Verifies the scope container registers a callback listener for component instance destroy events when a - * conversational instance expires - */ - public void testDestroyNotification() throws Exception { - store.getListener().onEvent(new StoreExpirationEvent(this, component, new Object())); - EasyMock.verify(component); - } - - protected void setUp() throws Exception { - super.setUp(); - component = EasyMock.createMock(AtomicComponent.class); - component.destroy(EasyMock.isA(Object.class)); - EasyMock.replay(component); - store = new TestStore(); - WorkContext context = new WorkContextImpl(); - container = new ConversationalScopeContainer(store, context, null); - container.start(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - container.stop(); - } - - private class TestStore implements Store { - private RuntimeEventListener listener; - - public RuntimeEventListener getListener() { - return listener; - } - - public void insertRecord(SCAObject owner, String id, Object object, long expiration) - throws StoreWriteException { - - } - - public void updateRecord(SCAObject owner, String id, Object object, long expiration) - throws StoreWriteException { - - } - - public Object readRecord(SCAObject owner, String id) throws StoreReadException { - return null; - } - - public void removeRecord(SCAObject owner, String id) throws StoreWriteException { - - } - - public void removeRecords() throws StoreWriteException { - - } - - public void recover(RecoveryListener listener) throws StoreReadException { - - } - - public void publish(Event object) { - - } - - public void addListener(RuntimeEventListener listener) { - this.listener = listener; - } - - public void addListener(EventFilter filter, RuntimeEventListener listener) { - - } - - public void removeListener(RuntimeEventListener listener) { - - } - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxAgeTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxAgeTestCase.java deleted file mode 100644 index 79ea057652..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxAgeTestCase.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.scope; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.SCAObject; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.event.RuntimeEventListener; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.services.store.Store; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class ConversationalScopeContainerMaxAgeTestCase extends TestCase { - - private ScopeContainer container; - private WorkContext context; - private Store store; - private AtomicComponent component; - - public void testMaxAgeUpdate() throws Exception { - context.setIdentifier(Scope.CONVERSATION, "12345"); - container.getInstance(component); - EasyMock.verify(store); - } - - protected void setUp() throws Exception { - super.setUp(); - ConversationalScopeContainerMaxAgeTestCase.Foo foo = new ConversationalScopeContainerMaxAgeTestCase.Foo(); - context = new WorkContextImpl(); - component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("foo").atLeastOnce(); - EasyMock.expect(component.getMaxIdleTime()).andReturn(-1L).atLeastOnce(); - EasyMock.expect(component.getMaxAge()).andReturn(600000L).atLeastOnce(); - EasyMock.replay(component); - store = EasyMock.createMock(Store.class); - EasyMock.expect(store.readRecord(EasyMock.isA(SCAObject.class), EasyMock.isA(String.class))).andReturn(foo); - store.addListener(EasyMock.isA(RuntimeEventListener.class)); - EasyMock.replay(store); - container = new ConversationalScopeContainer(store, context, null); - container.start(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - context.clearIdentifier(Scope.CONVERSATION); - container.stop(); - } - - private class Foo { - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxIdleTimeTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxIdleTimeTestCase.java deleted file mode 100644 index 2ba152d223..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxIdleTimeTestCase.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.scope; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.SCAObject; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.event.RuntimeEventListener; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.services.store.Store; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class ConversationalScopeContainerMaxIdleTimeTestCase extends TestCase { - - private ScopeContainer container; - private WorkContext context; - private Store store; - private AtomicComponent component; - - public void testMaxIdleTimeUpdate() throws Exception { - context.setIdentifier(Scope.CONVERSATION, "12345"); - container.getInstance(component); - EasyMock.verify(store); - } - - protected void setUp() throws Exception { - super.setUp(); - Foo foo = new Foo(); - context = new WorkContextImpl(); - component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("foo").atLeastOnce(); - EasyMock.expect(component.getMaxIdleTime()).andReturn(600000L).atLeastOnce(); - EasyMock.replay(component); - store = EasyMock.createMock(Store.class); - EasyMock.expect(store.readRecord(EasyMock.isA(SCAObject.class), EasyMock.isA(String.class))).andReturn(foo); - store.addListener(EasyMock.isA(RuntimeEventListener.class)); - store.updateRecord(EasyMock.isA(SCAObject.class), - EasyMock.isA(String.class), - EasyMock.eq(foo), - EasyMock.anyLong()); - EasyMock.replay(store); - container = new ConversationalScopeContainer(store, context, null); - container.start(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - context.clearIdentifier(Scope.CONVERSATION); - container.stop(); - } - - private class Foo { - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerPersistenceTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerPersistenceTestCase.java deleted file mode 100644 index ae7e91a59a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerPersistenceTestCase.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.scope; - -import java.util.UUID; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.component.TargetNotFoundException; -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.services.store.Store; -import org.apache.tuscany.spi.services.store.StoreMonitor; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.services.store.memory.MemoryStore; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class ConversationalScopeContainerPersistenceTestCase extends TestCase { - private ScopeContainer container; - private WorkContext context; - - /** - * Verifies the scope container properly creates an instance - */ - public void testNotYetPersistedInMemory() throws Exception { - String id = UUID.randomUUID().toString(); - context.setIdentifier(Scope.CONVERSATION, id); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - component.addListener(EasyMock.eq(container)); - EasyMock.expect(component.createInstance()).andReturn(new Foo()); - EasyMock.expect(component.getMaxAge()).andReturn(600000L).atLeastOnce(); - component.init(EasyMock.isA(Object.class)); - EasyMock.replay(component); - container.register(component); - assertTrue(container.getInstance(component) instanceof Foo); - EasyMock.verify(component); - } - - public void testPersistNewInMemory() throws Exception { - String id = UUID.randomUUID().toString(); - String id2 = UUID.randomUUID().toString(); - context.setIdentifier(Scope.CONVERSATION, id); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - component.addListener(EasyMock.eq(container)); - EasyMock.expect(component.getMaxIdleTime()).andReturn(-1L).atLeastOnce(); - EasyMock.replay(component); - container.register(component); - Foo foo = new Foo(); - Foo foo2 = new Foo(); - container.persistNew(component, id, foo, System.currentTimeMillis() + 100000); - assertEquals(foo, container.getInstance(component)); - container.persistNew(component, id2, foo2, System.currentTimeMillis() + 100000); - context.setIdentifier(Scope.CONVERSATION, id2); - assertEquals(foo2, container.getInstance(component)); - EasyMock.verify(component); - } - - public void testPersistInMemory() throws Exception { - String id = UUID.randomUUID().toString(); - context.setIdentifier(Scope.CONVERSATION, id); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - component.addListener(EasyMock.eq(container)); - EasyMock.expect(component.getMaxIdleTime()).andReturn(-1L).atLeastOnce(); - EasyMock.replay(component); - container.register(component); - Foo foo = new Foo(); - container.persistNew(component, id, foo, System.currentTimeMillis() + 100000); - assertEquals(foo, container.getInstance(component)); - container.persist(component, id, foo, System.currentTimeMillis() + 100000); - assertEquals(foo, container.getInstance(component)); - EasyMock.verify(component); - } - - public void testRemoveInMemory() throws Exception { - String id = UUID.randomUUID().toString(); - context.setIdentifier(Scope.CONVERSATION, id); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - component.addListener(EasyMock.eq(container)); - EasyMock.expect(component.getMaxIdleTime()).andReturn(-1L).atLeastOnce(); - EasyMock.expect(component.getName()).andReturn("foo").atLeastOnce(); - EasyMock.replay(component); - container.register(component); - Foo foo = new Foo(); - container.persistNew(component, id, foo, System.currentTimeMillis() + 100000); - assertEquals(foo, container.getInstance(component)); - container.remove(component); - try { - container.getAssociatedInstance(component); - fail(); - } catch (TargetNotFoundException e) { - //expected - } - EasyMock.verify(component); - } - - public void testRecreateAfterRemoveInMemory() throws Exception { - String id = UUID.randomUUID().toString(); - context.setIdentifier(Scope.CONVERSATION, id); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - component.addListener(EasyMock.eq(container)); - EasyMock.expect(component.getMaxAge()).andReturn(600000L).atLeastOnce(); - component.init(EasyMock.isA(Object.class)); - EasyMock.expect(component.getMaxIdleTime()).andReturn(-1L).atLeastOnce(); - EasyMock.expect(component.createInstance()).andReturn(new Foo()); - EasyMock.replay(component); - container.register(component); - Foo foo = new Foo(); - container.persistNew(component, id, foo, System.currentTimeMillis() + 100000); - assertEquals(foo, container.getInstance(component)); - container.remove(component); - Foo foo2 = (Foo) container.getInstance(component); - assertNotNull(foo2); - assertNotSame(foo, foo2); - EasyMock.verify(component); - } - - public void testGetPersistedInstance() throws Exception { - String id = UUID.randomUUID().toString(); - String id2 = UUID.randomUUID().toString(); - context.setIdentifier(Scope.CONVERSATION, id); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("foo").atLeastOnce(); - EasyMock.expect(component.getMaxIdleTime()).andReturn(-1L).atLeastOnce(); - component.addListener(EasyMock.eq(container)); - EasyMock.replay(component); - container.register(component); - Foo foo = new Foo(); - container.persistNew(component, id, foo, System.currentTimeMillis() + 100000); - assertEquals(foo, container.getAssociatedInstance(component)); - assertEquals(foo, container.getAssociatedInstance(component)); - context.setIdentifier(Scope.CONVERSATION, id2); - try { - container.getAssociatedInstance(component); - fail(); - } catch (TargetNotFoundException e) { - //expected - } - EasyMock.verify(component); - } - - protected void setUp() throws Exception { - super.setUp(); - context = new WorkContextImpl(); - StoreMonitor mock = EasyMock.createNiceMock(StoreMonitor.class); - EasyMock.replay(mock); - Store store = new MemoryStore(mock); - container = new ConversationalScopeContainer(store, context, null); - container.start(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - context.clearIdentifier(Scope.CONVERSATION); - container.stop(); - } - - private class Foo { - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeInstanceLifecycleTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeInstanceLifecycleTestCase.java deleted file mode 100644 index 782b175b47..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeInstanceLifecycleTestCase.java +++ /dev/null @@ -1,70 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tuscany.core.component.scope;
-
-import org.apache.tuscany.spi.component.AtomicComponent;
-import org.apache.tuscany.spi.component.WorkContext;
-import org.apache.tuscany.spi.event.RuntimeEventListener;
-import org.apache.tuscany.spi.model.Scope;
-import org.apache.tuscany.spi.services.store.StoreMonitor;
-
-import junit.framework.TestCase;
-import org.apache.tuscany.core.component.WorkContextImpl;
-import org.apache.tuscany.core.services.store.memory.MemoryStore;
-import org.easymock.EasyMock;
-
-/**
- * Lifecycle unit tests for the conversational scope container
- *
- * @version $Rev: 451895 $ $Date: 2006-10-02 02:58:18 -0400 (Mon, 02 Oct 2006) $
- */
-public class ConversationalScopeInstanceLifecycleTestCase extends TestCase {
-
- public void testInitRemove() throws Exception {
- StoreMonitor monitor = EasyMock.createMock(StoreMonitor.class);
- monitor.start(EasyMock.isA(String.class));
- monitor.stop(EasyMock.isA(String.class));
- MemoryStore store = new MemoryStore(monitor);
- WorkContext ctx = new WorkContextImpl();
- ConversationalScopeContainer scope = new ConversationalScopeContainer(store, ctx, null);
- scope.start();
-
- Foo comp = new Foo();
- AtomicComponent component = EasyMock.createMock(AtomicComponent.class);
- EasyMock.expect(component.createInstance()).andReturn(comp);
- component.init(EasyMock.eq(comp));
- EasyMock.expect(component.getMaxAge()).andReturn(1L).anyTimes();
- component.addListener(EasyMock.isA(RuntimeEventListener.class));
- EasyMock.replay(component);
- scope.register(component);
- String convID = "ConvID";
- ctx.setIdentifier(Scope.CONVERSATION, convID);
- assertNotNull(scope.getInstance(component));
- // expire
- scope.remove(component);
- scope.stop();
- EasyMock.verify(component);
- scope.stop();
- }
-
- private class Foo {
-
- }
-
-}
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeRestartTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeRestartTestCase.java deleted file mode 100644 index bc5ddc7c2c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeRestartTestCase.java +++ /dev/null @@ -1,112 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tuscany.core.component.scope;
-
-import java.lang.reflect.Constructor;
-
-import org.apache.tuscany.spi.component.AtomicComponent;
-import org.apache.tuscany.spi.component.WorkContext;
-import org.apache.tuscany.spi.model.Scope;
-import org.apache.tuscany.spi.services.store.StoreMonitor;
-
-import junit.framework.TestCase;
-import org.apache.tuscany.core.component.WorkContextImpl;
-import org.apache.tuscany.core.component.event.ConversationEnd;
-import org.apache.tuscany.core.component.event.ConversationStart;
-import org.apache.tuscany.core.implementation.PojoConfiguration;
-import org.apache.tuscany.core.implementation.system.component.SystemAtomicComponentImpl;
-import org.apache.tuscany.core.injection.MethodEventInvoker;
-import org.apache.tuscany.core.injection.PojoObjectFactory;
-import org.apache.tuscany.core.services.store.memory.MemoryStore;
-import org.easymock.EasyMock;
-
-/**
- * Verifies the scope container properly disposes resources and can be restarted
- *
- * @version $$Rev: 471111 $$ $$Date: 2006-11-03 23:06:48 -0500 (Fri, 03 Nov 2006) $$
- */
-public class ConversationalScopeRestartTestCase extends TestCase {
-
- public void testRestart() throws Exception {
- StoreMonitor monitor = EasyMock.createMock(StoreMonitor.class);
- monitor.start(EasyMock.isA(String.class));
- monitor.stop(EasyMock.isA(String.class));
- MemoryStore store = new MemoryStore(monitor);
- WorkContext ctx = new WorkContextImpl();
- ConversationalScopeContainer scope = new ConversationalScopeContainer(store, ctx, null);
- scope.start();
- MethodEventInvoker<Object> initInvoker = new MethodEventInvoker<Object>(
- ConversationalScopeRestartTestCase.InitDestroyOnce.class.getMethod("init"));
- MethodEventInvoker<Object> destroyInvoker =
- new MethodEventInvoker<Object>(InitDestroyOnce.class.getMethod("destroy"));
- PojoConfiguration configuration = new PojoConfiguration();
- configuration.setInitInvoker(initInvoker);
- configuration.setDestroyInvoker(destroyInvoker);
- Constructor<InitDestroyOnce> ctr = InitDestroyOnce.class.getConstructor((Class<?>[]) null);
- configuration.setInstanceFactory(new PojoObjectFactory<InitDestroyOnce>(ctr));
- configuration.setName("InitDestroy");
- AtomicComponent component = new SystemAtomicComponentImpl(configuration);
- component.setScopeContainer(scope);
- component.start();
-
- String conversation = "conv";
- ctx.setIdentifier(Scope.CONVERSATION, conversation);
- scope.onEvent(new ConversationStart(this, conversation));
- Object instance = component.getTargetInstance();
- assertSame(instance, component.getTargetInstance());
-
- scope.onEvent(new ConversationEnd(this, conversation));
- scope.stop();
- component.stop();
-
- scope.start();
- scope.onEvent(new ConversationStart(this, conversation));
- component.start();
- //assertNotSame(instance, context.getServiceInstance());
- scope.onEvent(new ConversationEnd(this, conversation));
- scope.stop();
- component.stop();
- }
-
- public static class InitDestroyOnce {
-
- private boolean initialized;
- private boolean destroyed;
-
- public InitDestroyOnce() {
- }
-
- public void init() {
- if (!initialized) {
- initialized = true;
- } else {
- fail("Scope did not clean up properly - Init called more than once");
- }
- }
-
- public void destroy() {
- if (!destroyed) {
- destroyed = true;
- } else {
- fail("Scope did not clean up properly - Destroyed called more than once");
- }
- }
-
- }
-}
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/DependencyLifecycleTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/DependencyLifecycleTestCase.java deleted file mode 100644 index 4a2497a725..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/DependencyLifecycleTestCase.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.scope; - -import java.util.Map; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.model.Scope; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.component.event.CompositeStart; -import org.apache.tuscany.core.component.event.CompositeStop; -import org.apache.tuscany.core.component.event.HttpSessionEnd; -import org.apache.tuscany.core.component.event.RequestEnd; -import org.apache.tuscany.core.component.event.RequestStart; -import org.apache.tuscany.core.mock.component.OrderedDependentPojo; -import org.apache.tuscany.core.mock.component.OrderedDependentPojoImpl; -import org.apache.tuscany.core.mock.component.OrderedInitPojo; -import org.apache.tuscany.core.mock.component.OrderedInitPojoImpl; - -/** - * Tests dependencies are initalized and destroyed in the proper order (i.e. LIFO) - * - * @version $Rev$ $Date$ - */ -public class DependencyLifecycleTestCase extends TestCase { - - public void testInitDestroyOrderCompositeScope() throws Exception { - CompositeScopeContainer scopeCtx = new CompositeScopeContainer(null); - scopeCtx.start(); - Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", - OrderedDependentPojoImpl.class, - scopeCtx, - "target", - OrderedInitPojoImpl.class, - scopeCtx); - for (AtomicComponent component : contexts.values()) { - scopeCtx.register(component); - } - AtomicComponent sourceComponent = contexts.get("source"); - AtomicComponent targetComponent = contexts.get("target"); - scopeCtx.register(sourceComponent); - scopeCtx.register(targetComponent); - scopeCtx.onEvent(new CompositeStart(this, null)); - OrderedDependentPojo source = (OrderedDependentPojo) scopeCtx.getInstance(sourceComponent); - OrderedInitPojo target = (OrderedInitPojo) scopeCtx.getInstance(targetComponent); - assertNotNull(source.getPojo()); - assertNotNull(target); - assertEquals(2, source.getNumberInstantiated()); - scopeCtx.onEvent(new CompositeStop(this, null)); - assertEquals(0, source.getNumberInstantiated()); - scopeCtx.stop(); - } - - public void testInitDestroyOrderAfterStartCompositeScope() throws Exception { - CompositeScopeContainer scopeCtx = new CompositeScopeContainer(null); - scopeCtx.start(); - Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", - OrderedDependentPojoImpl.class, - scopeCtx, - "target", - OrderedInitPojoImpl.class, - scopeCtx); - AtomicComponent sourceComponent = contexts.get("source"); - AtomicComponent targetComponent = contexts.get("target"); - scopeCtx.onEvent(new CompositeStart(this, null)); - scopeCtx.register(sourceComponent); - scopeCtx.register(targetComponent); - OrderedDependentPojo source = (OrderedDependentPojo) scopeCtx.getInstance(sourceComponent); - OrderedInitPojo target = (OrderedInitPojo) scopeCtx.getInstance(targetComponent); - assertNotNull(source.getPojo()); - assertNotNull(target); - assertEquals(2, source.getNumberInstantiated()); - scopeCtx.onEvent(new CompositeStop(this, null)); - assertEquals(0, source.getNumberInstantiated()); - scopeCtx.stop(); - } - - - public void testInitDestroyOrderSessionScope() throws Exception { - WorkContext ctx = new WorkContextImpl(); - HttpSessionScopeContainer scopeCtx = new HttpSessionScopeContainer(ctx, null); - scopeCtx.start(); - Object session = new Object(); - Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", - OrderedDependentPojoImpl.class, - scopeCtx, - "target", - OrderedInitPojoImpl.class, - scopeCtx); - AtomicComponent sourceComponent = contexts.get("source"); - AtomicComponent targetComponent = contexts.get("target"); - scopeCtx.register(sourceComponent); - scopeCtx.register(targetComponent); - ctx.setIdentifier(Scope.SESSION, session); - OrderedDependentPojo source = (OrderedDependentPojo) scopeCtx.getInstance(sourceComponent); - assertNotNull(source.getPojo()); - assertEquals(2, source.getNumberInstantiated()); - scopeCtx.onEvent(new HttpSessionEnd(this, session)); - assertEquals(0, source.getNumberInstantiated()); - scopeCtx.stop(); - } - - - public void testInitDestroyOrderAfterStartSessionScope() throws Exception { - WorkContext ctx = new WorkContextImpl(); - HttpSessionScopeContainer scopeCtx = new HttpSessionScopeContainer(ctx, null); - scopeCtx.start(); - Object session = new Object(); - Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", - OrderedDependentPojoImpl.class, - scopeCtx, - "target", - OrderedInitPojoImpl.class, - scopeCtx); - AtomicComponent sourceComponent = contexts.get("source"); - AtomicComponent targetComponent = contexts.get("target"); - ctx.setIdentifier(Scope.SESSION, session); - scopeCtx.register(sourceComponent); - scopeCtx.register(targetComponent); - OrderedDependentPojo source = (OrderedDependentPojo) scopeCtx.getInstance(sourceComponent); - assertNotNull(source.getPojo()); - assertEquals(2, source.getNumberInstantiated()); - scopeCtx.onEvent(new HttpSessionEnd(this, session)); - assertEquals(0, source.getNumberInstantiated()); - scopeCtx.stop(); - } - - public void testInitDestroyOrderRequestScope() throws Exception { - WorkContext ctx = new WorkContextImpl(); - RequestScopeContainer scopeCtx = new RequestScopeContainer(ctx, null); - scopeCtx.start(); - scopeCtx.onEvent(new RequestStart(this)); - Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", - OrderedDependentPojoImpl.class, - scopeCtx, - "target", - OrderedInitPojoImpl.class, - scopeCtx); - AtomicComponent sourceComponent = contexts.get("source"); - AtomicComponent targetComponent = contexts.get("target"); - scopeCtx.register(sourceComponent); - scopeCtx.register(targetComponent); - OrderedDependentPojo source = (OrderedDependentPojo) scopeCtx.getInstance(sourceComponent); - assertNotNull(source.getPojo()); - assertEquals(2, source.getNumberInstantiated()); - scopeCtx.onEvent(new RequestEnd(this)); - assertEquals(0, source.getNumberInstantiated()); - scopeCtx.stop(); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeInitDestroyErrorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeInitDestroyErrorTestCase.java deleted file mode 100644 index 7aa2f9a120..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeInitDestroyErrorTestCase.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.scope; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.ScopeContainerMonitor; -import org.apache.tuscany.spi.component.TargetDestructionException; -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.event.RuntimeEventListener; -import org.apache.tuscany.spi.model.Scope; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.component.event.HttpSessionEnd; -import org.apache.tuscany.core.component.event.HttpSessionStart; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class HttpSessionScopeInitDestroyErrorTestCase extends TestCase { - - public void testDestroyErrorMonitor() throws Exception { - ScopeContainerMonitor monitor; - monitor = EasyMock.createMock(ScopeContainerMonitor.class); - monitor.destructionError(EasyMock.isA(TargetDestructionException.class)); - EasyMock.replay(monitor); - WorkContext workContext = new WorkContextImpl(); - HttpSessionScopeContainer scope = new HttpSessionScopeContainer(workContext, monitor); - scope.start(); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - component.addListener(EasyMock.isA(RuntimeEventListener.class)); - EasyMock.expect(component.getName()).andReturn("foo").atLeastOnce(); - EasyMock.expect(component.createInstance()).andReturn(new Object()); - EasyMock.expect(component.isEagerInit()).andReturn(true); - component.init(EasyMock.isA(Object.class)); - component.destroy(EasyMock.isA(Object.class)); - EasyMock.expectLastCall().andThrow(new TargetDestructionException("", "")); - EasyMock.replay(component); - scope.register(component); - Object id = new Object(); - scope.onEvent(new HttpSessionStart(this, id)); - workContext.setIdentifier(Scope.SESSION, id); - scope.getInstance(component); - scope.onEvent(new HttpSessionEnd(this, id)); - EasyMock.verify(monitor); - } - - - protected void setUp() throws Exception { - super.setUp(); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeInstanceLifecycleTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeInstanceLifecycleTestCase.java deleted file mode 100644 index 29d6d54450..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeInstanceLifecycleTestCase.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.scope; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.TargetException; -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.event.RuntimeEventListener; -import org.apache.tuscany.spi.model.Scope; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.component.event.HttpSessionEnd; -import org.apache.tuscany.core.component.event.HttpSessionStart; -import org.apache.tuscany.core.mock.component.OrderedInitPojo; -import org.apache.tuscany.core.mock.component.OrderedInitPojoImpl; -import org.easymock.EasyMock; -import org.easymock.IAnswer; - -/** - * Lifecycle unit tests for the composite scope container - * - * @version $Rev$ $Date$ - */ -public class HttpSessionScopeInstanceLifecycleTestCase extends TestCase { - - public void testInitDestroy() throws Exception { - WorkContext ctx = new WorkContextImpl(); - HttpSessionScopeContainer scope = new HttpSessionScopeContainer(ctx, null); - scope.start(); - Foo comp = new Foo(); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.createInstance()).andReturn(comp); - component.addListener(EasyMock.isA(RuntimeEventListener.class)); - component.init(EasyMock.eq(comp)); - component.destroy(EasyMock.eq(comp)); - EasyMock.replay(component); - scope.register(component); - Object session = new Object(); - ctx.setIdentifier(Scope.SESSION, session); - scope.onEvent(new HttpSessionStart(this, session)); - assertNotNull(scope.getInstance(component)); - // expire - scope.onEvent(new HttpSessionEnd(this, session)); - scope.stop(); - EasyMock.verify(component); - scope.stop(); - } - - public void testDestroyOrder() throws Exception { - WorkContext ctx = new WorkContextImpl(); - HttpSessionScopeContainer scope = new HttpSessionScopeContainer(ctx, null); - scope.start(); - - AtomicComponent oneComponent = createComponent(); - scope.register(oneComponent); - AtomicComponent twoComponent = createComponent(); - scope.register(twoComponent); - AtomicComponent threeComponent = createComponent(); - scope.register(threeComponent); - - Object session = new Object(); - ctx.setIdentifier(Scope.SESSION, session); - scope.onEvent(new HttpSessionStart(this, session)); - OrderedInitPojo one = (OrderedInitPojo) scope.getInstance(oneComponent); - assertNotNull(one); - assertEquals(1, one.getNumberInstantiated()); - assertEquals(1, one.getInitOrder()); - - OrderedInitPojo two = (OrderedInitPojo) scope.getInstance(twoComponent); - assertNotNull(two); - assertEquals(2, two.getNumberInstantiated()); - assertEquals(2, two.getInitOrder()); - - OrderedInitPojo three = (OrderedInitPojo) scope.getInstance(threeComponent); - assertNotNull(three); - assertEquals(3, three.getNumberInstantiated()); - assertEquals(3, three.getInitOrder()); - - scope.onEvent(new HttpSessionEnd(this, session)); - assertEquals(0, one.getNumberInstantiated()); - scope.stop(); - EasyMock.verify(oneComponent); - EasyMock.verify(twoComponent); - EasyMock.verify(threeComponent); - } - - @SuppressWarnings("unchecked") - private AtomicComponent createComponent() throws TargetException { - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.createInstance()).andStubAnswer(new IAnswer() { - public Object answer() throws Throwable { - return new OrderedInitPojoImpl(); - } - }); - component.addListener(EasyMock.isA(RuntimeEventListener.class)); - component.init(EasyMock.isA(OrderedInitPojoImpl.class)); - EasyMock.expectLastCall().andAnswer(new IAnswer() { - public Object answer() throws Throwable { - OrderedInitPojoImpl pojo = (OrderedInitPojoImpl) EasyMock.getCurrentArguments()[0]; - pojo.init(); - return null; - } - }); - component.destroy(EasyMock.isA(OrderedInitPojoImpl.class)); - EasyMock.expectLastCall().andAnswer(new IAnswer() { - public Object answer() throws Throwable { - OrderedInitPojoImpl pojo = (OrderedInitPojoImpl) EasyMock.getCurrentArguments()[0]; - pojo.destroy(); - return null; - } - }); - EasyMock.replay(component); - return component; - } - - private class Foo { - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeRestartTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeRestartTestCase.java deleted file mode 100644 index eff0eb6d3a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/HttpSessionScopeRestartTestCase.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.scope; - -import java.lang.reflect.Constructor; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.model.Scope; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.component.event.HttpSessionEnd; -import org.apache.tuscany.core.component.event.HttpSessionStart; -import org.apache.tuscany.core.implementation.PojoConfiguration; -import org.apache.tuscany.core.implementation.system.component.SystemAtomicComponentImpl; -import org.apache.tuscany.core.injection.MethodEventInvoker; -import org.apache.tuscany.core.injection.PojoObjectFactory; - -/** - * Verifies the scope container properly disposes resources and canbe restarted - * - * @version $$Rev$$ $$Date$$ - */ -public class HttpSessionScopeRestartTestCase extends TestCase { - - public void testRestart() throws Exception { - WorkContext ctx = new WorkContextImpl(); - HttpSessionScopeContainer scope = new HttpSessionScopeContainer(ctx, null); - scope.start(); - MethodEventInvoker<Object> initInvoker = new MethodEventInvoker<Object>( - HttpSessionScopeRestartTestCase.InitDestroyOnce.class.getMethod("init")); - MethodEventInvoker<Object> destroyInvoker = - new MethodEventInvoker<Object>(InitDestroyOnce.class.getMethod("destroy")); - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setInitInvoker(initInvoker); - configuration.setDestroyInvoker(destroyInvoker); - Constructor<InitDestroyOnce> ctr = InitDestroyOnce.class.getConstructor((Class<?>[]) null); - configuration.setInstanceFactory(new PojoObjectFactory<InitDestroyOnce>(ctr)); - configuration.setName("InitDestroy"); - AtomicComponent component = new SystemAtomicComponentImpl(configuration); - component.setScopeContainer(scope); - component.start(); - - Object session = new Object(); - ctx.setIdentifier(Scope.SESSION, session); - scope.onEvent(new HttpSessionStart(this, session)); - Object instance = component.getTargetInstance(); - assertSame(instance, component.getTargetInstance()); - - scope.onEvent(new HttpSessionEnd(this, session)); - scope.stop(); - component.stop(); - - scope.start(); - scope.onEvent(new HttpSessionStart(this, session)); - component.start(); - assertNotSame(instance, component.getTargetInstance()); - scope.onEvent(new HttpSessionEnd(this, session)); - scope.stop(); - component.stop(); - } - - public static class InitDestroyOnce { - - private boolean initialized; - private boolean destroyed; - - public InitDestroyOnce() { - } - - public void init() { - if (!initialized) { - initialized = true; - } else { - fail("Scope did not clean up properly - Init called more than once"); - } - } - - public void destroy() { - if (!destroyed) { - destroyed = true; - } else { - fail("Scope did not clean up properly - Destroyed called more than once"); - } - } - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperTestCase.java deleted file mode 100644 index 5600987d8b..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperTestCase.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.scope; - -import org.apache.tuscany.spi.component.AtomicComponent; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class InstanceWrapperTestCase extends TestCase { - - public void testExceptionInit() throws Exception { - AtomicComponent component = getComponent(); - InstanceWrapper wrapper = new InstanceWrapperImpl(component, new Object()); - try { - wrapper.start(); - fail(); - } catch (SomeException e) { - // expected - } - assertFalse(wrapper.isStarted()); - EasyMock.verify(component); - } - - public void testNonStart() throws Exception { - AtomicComponent comp = EasyMock.createNiceMock(AtomicComponent.class); // class-level one has an expects - InstanceWrapper wrapper = new InstanceWrapperImpl(comp, new Object()); - try { - wrapper.getInstance(); - fail(); - } catch (IllegalStateException e) { - // expected - } - } - - private AtomicComponent getComponent() throws Exception { - // do not use setUp() since we do not need this in all testcases - AtomicComponent comp = EasyMock.createMock(AtomicComponent.class); - comp.init(EasyMock.isA(Object.class)); - EasyMock.expectLastCall().andThrow(new SomeException()); - EasyMock.replay(comp); - return comp; - } - - private class SomeException extends RuntimeException { - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/MockFactory.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/MockFactory.java deleted file mode 100644 index db947e0d66..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/MockFactory.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.scope; - -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; - -import org.osoa.sca.annotations.Destroy; -import org.osoa.sca.annotations.EagerInit; -import org.osoa.sca.annotations.Init; - -import org.apache.tuscany.spi.QualifiedName; -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.idl.java.JavaServiceContract; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.OutboundWire; - -import org.apache.tuscany.core.implementation.PojoConfiguration; -import org.apache.tuscany.core.implementation.system.component.SystemAtomicComponentImpl; -import org.apache.tuscany.core.injection.MethodEventInvoker; -import org.apache.tuscany.core.injection.PojoObjectFactory; -import org.apache.tuscany.core.wire.InboundWireImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; - -/** - * @version $$Rev$$ $$Date$$ - */ -public final class MockFactory { - - private MockFactory() { - } - - @SuppressWarnings("unchecked") - public static Map<String, AtomicComponent> createWiredComponents(String source, - Class<?> sourceClass, - ScopeContainer sourceScopeContainer, - String target, - Class<?> targetClass, - ScopeContainer targetScopeContainer) - throws NoSuchMethodException { - - Map<String, AtomicComponent> components = new HashMap<String, AtomicComponent>(); - AtomicComponent targetComponent = createAtomicComponent(target, targetScopeContainer, targetClass); - PojoConfiguration sourceConfig = new PojoConfiguration(); - sourceConfig.setInstanceFactory(new PojoObjectFactory(sourceClass.getConstructor())); - - //create target wire - Method[] sourceMethods = sourceClass.getMethods(); - Class[] interfaces = targetClass.getInterfaces(); - EagerInit eager = targetClass.getAnnotation(EagerInit.class); - if (eager != null) { - sourceConfig.setInitLevel(50); - } - - Method setter = null; - for (Class interfaze : interfaces) { - - for (Method method : sourceMethods) { - if (method.getParameterTypes().length == 1) { - if (interfaze.isAssignableFrom(method.getParameterTypes()[0])) { - setter = method; - } - } - if (method.getAnnotation(Init.class) != null) { - sourceConfig.setInitInvoker(new MethodEventInvoker<Object>(method)); - - } else if (method.getAnnotation(Destroy.class) != null) { - sourceConfig.setDestroyInvoker(new MethodEventInvoker<Object>(method)); - } - } - - } - if (setter == null) { - throw new IllegalArgumentException("No setter found on source for target"); - } - - sourceConfig.addReferenceSite(setter.getName(), setter); - sourceConfig.setName(source); - AtomicComponent sourceComponent = new SystemAtomicComponentImpl(sourceConfig); - sourceComponent.setScopeContainer(sourceScopeContainer); - QualifiedName targetName = new QualifiedName(target); - OutboundWire wire = new OutboundWireImpl(); - wire.setReferenceName(setter.getName()); - wire.setServiceContract(new JavaServiceContract(targetClass)); - InboundWire inboundWire = new InboundWireImpl(); - inboundWire.setContainer(targetComponent); - inboundWire.setServiceContract(new JavaServiceContract(targetClass)); - inboundWire.setServiceName(targetName.getPortName()); - wire.setTargetWire(inboundWire); - sourceComponent.addOutboundWire(wire); - components.put(source, sourceComponent); - components.put(target, targetComponent); - return components; - } - - @SuppressWarnings("unchecked") - public static AtomicComponent createAtomicComponent(String name, ScopeContainer container, Class<?> clazz) - throws NoSuchMethodException { - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setInstanceFactory(new PojoObjectFactory(clazz.getConstructor())); - EagerInit eager = clazz.getAnnotation(EagerInit.class); - if (eager != null) { - configuration.setInitLevel(50); - } - Method[] methods = clazz.getMethods(); - for (Method method : methods) { - if (method.getAnnotation(Init.class) != null) { - configuration.setInitInvoker(new MethodEventInvoker<Object>(method)); - } else if (method.getAnnotation(Destroy.class) != null) { - configuration.setDestroyInvoker(new MethodEventInvoker<Object>(method)); - } - } - configuration.setName(name); - AtomicComponent component = new SystemAtomicComponentImpl(configuration); - component.setScopeContainer(container); - return component; - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeInitDestroyErrorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeInitDestroyErrorTestCase.java deleted file mode 100644 index 3f562c9b61..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeInitDestroyErrorTestCase.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.scope; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.ScopeContainerMonitor; -import org.apache.tuscany.spi.component.TargetDestructionException; -import org.apache.tuscany.spi.event.RuntimeEventListener; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.component.event.RequestEnd; -import org.apache.tuscany.core.component.event.RequestStart; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class RequestScopeInitDestroyErrorTestCase extends TestCase { - - public void testDestroyErrorMonitor() throws Exception { - ScopeContainerMonitor monitor; - monitor = EasyMock.createMock(ScopeContainerMonitor.class); - monitor.destructionError(EasyMock.isA(TargetDestructionException.class)); - EasyMock.replay(monitor); - RequestScopeContainer scope = new RequestScopeContainer(new WorkContextImpl(), monitor); - scope.start(); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - component.addListener(EasyMock.isA(RuntimeEventListener.class)); - EasyMock.expect(component.getName()).andReturn("foo").atLeastOnce(); - EasyMock.expect(component.createInstance()).andReturn(new Object()); - component.init(EasyMock.isA(Object.class)); - component.destroy(EasyMock.isA(Object.class)); - EasyMock.expectLastCall().andThrow(new TargetDestructionException("", "")); - EasyMock.replay(component); - scope.register(component); - scope.onEvent(new RequestStart(this)); - scope.getInstance(component); - scope.onEvent(new RequestEnd(this)); - EasyMock.verify(monitor); - } - - - protected void setUp() throws Exception { - super.setUp(); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeInstanceLifecycleTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeInstanceLifecycleTestCase.java deleted file mode 100644 index 6601640c3b..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeInstanceLifecycleTestCase.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.scope; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.TargetException; -import org.apache.tuscany.spi.component.WorkContext; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.component.event.RequestEnd; -import org.apache.tuscany.core.component.event.RequestStart; -import org.apache.tuscany.core.mock.component.OrderedInitPojo; -import org.apache.tuscany.core.mock.component.OrderedInitPojoImpl; -import org.easymock.EasyMock; -import org.easymock.IAnswer; - -/** - * Lifecycle unit tests for the request scope container - * - * @version $Rev$ $Date$ - */ -public class RequestScopeInstanceLifecycleTestCase extends TestCase { - - public void testInitDestroy() throws Exception { - WorkContext ctx = new WorkContextImpl(); - RequestScopeContainer scope = new RequestScopeContainer(ctx, null); - scope.start(); - Foo comp = new Foo(); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.createInstance()).andReturn(comp); - component.init(EasyMock.eq(comp)); - component.destroy(EasyMock.eq(comp)); - EasyMock.replay(component); - scope.register(component); - scope.onEvent(new RequestStart(this)); - assertNotNull(scope.getInstance(component)); - // expire - scope.onEvent(new RequestEnd(this)); - scope.stop(); - EasyMock.verify(component); - scope.stop(); - } - - public void testDestroyOrder() throws Exception { - WorkContext ctx = new WorkContextImpl(); - RequestScopeContainer scope = new RequestScopeContainer(ctx, null); - scope.start(); - - AtomicComponent oneComponent = createComponent(); - scope.register(oneComponent); - AtomicComponent twoComponent = createComponent(); - scope.register(twoComponent); - AtomicComponent threeComponent = createComponent(); - scope.register(threeComponent); - - scope.onEvent(new RequestStart(this)); - OrderedInitPojo one = (OrderedInitPojo) scope.getInstance(oneComponent); - assertNotNull(one); - assertEquals(1, one.getNumberInstantiated()); - assertEquals(1, one.getInitOrder()); - - OrderedInitPojo two = (OrderedInitPojo) scope.getInstance(twoComponent); - assertNotNull(two); - assertEquals(2, two.getNumberInstantiated()); - assertEquals(2, two.getInitOrder()); - - OrderedInitPojo three = (OrderedInitPojo) scope.getInstance(threeComponent); - assertNotNull(three); - assertEquals(3, three.getNumberInstantiated()); - assertEquals(3, three.getInitOrder()); - - scope.onEvent(new RequestEnd(this)); - assertEquals(0, one.getNumberInstantiated()); - scope.stop(); - EasyMock.verify(oneComponent); - EasyMock.verify(twoComponent); - EasyMock.verify(threeComponent); - } - - @SuppressWarnings("unchecked") - private AtomicComponent createComponent() throws TargetException { - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.createInstance()).andStubAnswer(new IAnswer() { - public Object answer() throws Throwable { - return new OrderedInitPojoImpl(); - } - }); - component.init(EasyMock.isA(OrderedInitPojoImpl.class)); - EasyMock.expectLastCall().andAnswer(new IAnswer() { - public Object answer() throws Throwable { - OrderedInitPojoImpl pojo = (OrderedInitPojoImpl) EasyMock.getCurrentArguments()[0]; - pojo.init(); - return null; - } - }); - component.destroy(EasyMock.isA(OrderedInitPojoImpl.class)); - EasyMock.expectLastCall().andAnswer(new IAnswer() { - public Object answer() throws Throwable { - OrderedInitPojoImpl pojo = (OrderedInitPojoImpl) EasyMock.getCurrentArguments()[0]; - pojo.destroy(); - return null; - } - }); - EasyMock.replay(component); - return component; - } - - private class Foo { - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeRestartTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeRestartTestCase.java deleted file mode 100644 index 335d8c621d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/RequestScopeRestartTestCase.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.scope; - -import java.lang.reflect.Constructor; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.WorkContext; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.component.event.RequestEnd; -import org.apache.tuscany.core.implementation.PojoConfiguration; -import org.apache.tuscany.core.implementation.system.component.SystemAtomicComponentImpl; -import org.apache.tuscany.core.injection.MethodEventInvoker; -import org.apache.tuscany.core.injection.PojoObjectFactory; - -/** - * Verifies the scope container properly disposes resources and canbe restarted - * - * @version $$Rev$$ $$Date$$ - */ -public class RequestScopeRestartTestCase extends TestCase { - - public void testRestart() throws Exception { - WorkContext ctx = new WorkContextImpl(); - RequestScopeContainer scope = new RequestScopeContainer(ctx, null); - scope.start(); - MethodEventInvoker<Object> initInvoker = - new MethodEventInvoker<Object>(InitDestroyOnce.class.getMethod("init")); - MethodEventInvoker<Object> destroyInvoker = - new MethodEventInvoker<Object>(InitDestroyOnce.class.getMethod("destroy")); - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setInitInvoker(initInvoker); - configuration.setDestroyInvoker(destroyInvoker); - Constructor<InitDestroyOnce> ctr = InitDestroyOnce.class.getConstructor((Class<?>[]) null); - configuration.setInstanceFactory(new PojoObjectFactory<InitDestroyOnce>(ctr)); - configuration.setName("InitDestroy"); - AtomicComponent component = new SystemAtomicComponentImpl(configuration); - component.setScopeContainer(scope); - component.start(); - - Object instance = component.getTargetInstance(); - assertSame(instance, component.getTargetInstance()); - - scope.onEvent(new RequestEnd(this)); - scope.stop(); - component.stop(); - - scope.start(); - component.start(); - assertNotSame(instance, component.getTargetInstance()); - scope.onEvent(new RequestEnd(this)); - scope.stop(); - component.stop(); - } - - public static class InitDestroyOnce { - - private boolean initialized; - private boolean destroyed; - - public InitDestroyOnce() { - } - - public void init() { - if (!initialized) { - initialized = true; - } else { - fail("Scope did not clean up properly - Init called more than once"); - } - } - - public void destroy() { - if (!destroyed) { - destroyed = true; - } else { - fail("Scope did not clean up properly - Destroyed called more than once"); - } - } - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ScopeRegistryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ScopeRegistryTestCase.java deleted file mode 100644 index e1380eb4c0..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/ScopeRegistryTestCase.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.scope; - -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.component.ScopeRegistry; -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.model.Scope; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; - -/** - * Verifies retrieval of standard scope contexts from the default scope registry - * - * @version $$Rev$$ $$Date$$ - */ -public class ScopeRegistryTestCase extends TestCase { - public void testScopeContextCreation() throws Exception { - WorkContext context = new WorkContextImpl(); - ScopeRegistry scopeRegistry = new ScopeRegistryImpl(); - scopeRegistry.registerFactory(Scope.REQUEST, new RequestScopeObjectFactory(context, null)); - HttpSessionScopeObjectFactory sessionFactory = new HttpSessionScopeObjectFactory(scopeRegistry, context, null); - scopeRegistry.registerFactory(Scope.SESSION, sessionFactory); - scopeRegistry.registerFactory(Scope.CONVERSATION, - new ConversationalScopeObjectFactory(scopeRegistry, context, null, null)); - ScopeContainer request = scopeRegistry.getScopeContainer(Scope.REQUEST); - assertTrue(request instanceof RequestScopeContainer); - assertSame(request, scopeRegistry.getScopeContainer(Scope.REQUEST)); - ScopeContainer session = scopeRegistry.getScopeContainer(Scope.SESSION); - assertTrue(session instanceof HttpSessionScopeContainer); - assertSame(session, scopeRegistry.getScopeContainer(Scope.SESSION)); - assertNotSame(request, session); - ScopeContainer conversation = scopeRegistry.getScopeContainer(Scope.CONVERSATION); - assertTrue(conversation instanceof ConversationalScopeContainer); - assertSame(conversation, scopeRegistry.getScopeContainer(Scope.CONVERSATION)); - assertNotSame(session, conversation); - } - - public void testDeregisterFactory() throws Exception { - WorkContext context = new WorkContextImpl(); - ScopeRegistry scopeRegistry = new ScopeRegistryImpl(); - RequestScopeObjectFactory factory = new RequestScopeObjectFactory(context, null); - scopeRegistry.registerFactory(Scope.REQUEST, factory); - scopeRegistry.deregisterFactory(Scope.REQUEST); - assertNull(scopeRegistry.getScopeContainer(Scope.REQUEST)); - ConversationalScopeObjectFactory convFactory = - new ConversationalScopeObjectFactory(scopeRegistry, context, null, null); - scopeRegistry.registerFactory(Scope.CONVERSATION, convFactory); - scopeRegistry.deregisterFactory(Scope.CONVERSATION); - assertNull(scopeRegistry.getScopeContainer(Scope.CONVERSATION)); - } - - public void testScopeNotRegistered() throws Exception { - WorkContext workContext = new WorkContextImpl(); - ScopeRegistry scopeRegistry = new ScopeRegistryImpl(); - assertNull(scopeRegistry.getScopeContainer(Scope.REQUEST)); - assertNull(scopeRegistry.getScopeContainer(Scope.SESSION)); - assertNull(scopeRegistry.getScopeContainer(Scope.CONVERSATION)); - assertNull(scopeRegistry.getScopeContainer(Scope.STATELESS)); - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeContainerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeContainerTestCase.java deleted file mode 100644 index 89cd9b51d7..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeContainerTestCase.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.scope; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class StatelessScopeContainerTestCase extends TestCase { - - public void testBadStopWithoutStart() throws Exception { - StatelessScopeContainer container = new StatelessScopeContainer(null, null); - try { - container.stop(); - fail(); - } catch (IllegalStateException e) { - //expected - } - } - - public void testBadDoubleStart() throws Exception { - StatelessScopeContainer container = new StatelessScopeContainer(null, null); - try { - container.start(); - container.start(); - fail(); - } catch (IllegalStateException e) { - //expected - } - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeObjectFactoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeObjectFactoryTestCase.java deleted file mode 100644 index 0902b9d78c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/StatelessScopeObjectFactoryTestCase.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.scope; - -import org.apache.tuscany.spi.component.ScopeRegistry; -import org.apache.tuscany.spi.model.Scope; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class StatelessScopeObjectFactoryTestCase extends TestCase { - - public void testCreation() { - ScopeRegistry registry = EasyMock.createMock(ScopeRegistry.class); - registry.registerFactory(EasyMock.isA(Scope.class), EasyMock.isA(StatelessScopeObjectFactory.class)); - assertNotNull(new StatelessScopeObjectFactory(registry, null, null).getInstance()); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/WorkContextTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/WorkContextTestCase.java deleted file mode 100644 index 8a9fdf4ac4..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/component/scope/WorkContextTestCase.java +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.component.scope; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.WorkContext; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class WorkContextTestCase extends TestCase { - - public void testRemoteComponent() throws Exception { - WorkContext ctx = new WorkContextImpl(); - CompositeComponent component = EasyMock.createNiceMock(CompositeComponent.class); - CompositeComponent component2 = EasyMock.createNiceMock(CompositeComponent.class); - ctx.setRemoteComponent(component); - assertEquals(component, ctx.getRemoteComponent()); - ctx.setRemoteComponent(component2); - assertEquals(component2, ctx.getRemoteComponent()); - } - - public void testNonSetRemoteComponent() throws Exception { - WorkContext ctx = new WorkContextImpl(); - assertNull(ctx.getRemoteComponent()); - } - - public void testSetCurrentAtomicComponent() throws Exception { - WorkContext ctx = new WorkContextImpl(); - AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class); - AtomicComponent component2 = EasyMock.createNiceMock(AtomicComponent.class); - ctx.setCurrentAtomicComponent(component); - assertEquals(component, ctx.getCurrentAtomicComponent()); - ctx.setCurrentAtomicComponent(component2); - assertEquals(component2, ctx.getCurrentAtomicComponent()); - } - - public void testNonSetCurrentAtomicComponent() throws Exception { - WorkContext ctx = new WorkContextImpl(); - assertNull(ctx.getCurrentAtomicComponent()); - } - - public void testIndentifier() throws Exception { - WorkContext ctx = new WorkContextImpl(); - Object id = new Object(); - ctx.setIdentifier(this, id); - assertEquals(id, ctx.getIdentifier(this)); - } - - public void testClearIndentifier() throws Exception { - WorkContext ctx = new WorkContextImpl(); - Object id = new Object(); - ctx.setIdentifier(this, id); - ctx.clearIdentifier(this); - assertNull(ctx.getIdentifier(this)); - } - - public void testClearIndentifiers() throws Exception { - WorkContext ctx = new WorkContextImpl(); - Object id = new Object(); - Object id2 = new Object(); - ctx.setIdentifier(id, id); - ctx.setIdentifier(id2, id2); - ctx.clearIdentifiers(); - assertNull(ctx.getIdentifier(id)); - assertNull(ctx.getIdentifier(id2)); - } - - public void testClearNonExistentIndentifier() throws Exception { - WorkContext ctx = new WorkContextImpl(); - ctx.clearIdentifier(this); - } - - public void testNullIndentifier() throws Exception { - WorkContext ctx = new WorkContextImpl(); - Object id = new Object(); - ctx.setIdentifier(this, id); - ctx.clearIdentifier(null); - assertEquals(id, ctx.getIdentifier(this)); - } - - public void testNoIndentifier() throws Exception { - WorkContext ctx = new WorkContextImpl(); - assertNull(ctx.getIdentifier(this)); - } - - public void testSetGetCorrelationId() { - WorkContext context = new WorkContextImpl(); - context.setCurrentCorrelationId("msg-005"); - assertEquals(context.getCurrentCorrelationId(), "msg-005"); - context.setCurrentCorrelationId(null); - assertNull(context.getCurrentCorrelationId()); - } - - public void testSetGetCorrelationIdInNewThread() throws InterruptedException { - WorkContext context = new WorkContextImpl(); - context.setCurrentCorrelationId("msg-005"); - assertEquals(context.getCurrentCorrelationId(), "msg-005"); - context.setIdentifier("TX", "002"); - ChildThread t = new ChildThread(context); - t.start(); - t.join(); - assertTrue(t.passed); - context.setCurrentCorrelationId(null); - assertNull(context.getCurrentCorrelationId()); - } - - public void testCurrentAtomicComponentDoesNotPropagateToChildThread() throws InterruptedException { - // NOTE should behaviour be to propagate? - WorkContext context = new WorkContextImpl(); - context.setCurrentAtomicComponent(EasyMock.createNiceMock(AtomicComponent.class)); - TestCurrentAtomicComponentChildThread t = new TestCurrentAtomicComponentChildThread(context); - t.start(); - t.join(); - assertTrue(t.passed); - context.setCurrentAtomicComponent(null); - assertNull(context.getCurrentAtomicComponent()); - } - - public void testCurrentRemoteComponentDoesNotPropagateToChildThread() throws InterruptedException { - // NOTE should behaviour be to propagate? - WorkContext context = new WorkContextImpl(); - context.setRemoteComponent(EasyMock.createNiceMock(CompositeComponent.class)); - TestCurrentRemoteComponentChildThread t = new TestCurrentRemoteComponentChildThread(context); - t.start(); - t.join(); - assertTrue(t.passed); - context.setRemoteComponent(null); - assertNull(context.getRemoteComponent()); - } - - private static final class ChildThread extends Thread { - private WorkContext context; - private boolean passed = true; - - private ChildThread(WorkContext context) { - this.context = context; - } - - @Override - public void run() { - try { - assertNull(context.getCurrentCorrelationId()); - assertEquals("002", context.getIdentifier("TX")); - } catch (AssertionError e) { - passed = false; - } - } - - } - - private static final class TestCurrentAtomicComponentChildThread extends Thread { - private WorkContext context; - private boolean passed = true; - - private TestCurrentAtomicComponentChildThread(WorkContext context) { - this.context = context; - } - - @Override - public void run() { - try { - assertNull(context.getCurrentAtomicComponent()); - } catch (AssertionError e) { - passed = false; - } - } - - } - - private static final class TestCurrentRemoteComponentChildThread extends Thread { - private WorkContext context; - private boolean passed = true; - - private TestCurrentRemoteComponentChildThread(WorkContext context) { - this.context = context; - } - - @Override - public void run() { - try { - assertNull(context.getRemoteComponent()); - } catch (AssertionError e) { - passed = false; - } - } - - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingInterceptorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingInterceptorTestCase.java deleted file mode 100644 index ddfb75568d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingInterceptorTestCase.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.core.databinding.impl; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.apache.tuscany.spi.component.Component; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.databinding.DataBinding; -import org.apache.tuscany.spi.databinding.Mediator; -import org.apache.tuscany.spi.model.DataType; -import org.apache.tuscany.spi.model.Operation; -import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.OutboundWire; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.easymock.EasyMock; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.expectLastCall; -import static org.easymock.EasyMock.replay; - -/** - * @version $Rev$ $Date$ - */ -public class DataBindingInterceptorTestCase extends TestCase { - - @SuppressWarnings("unchecked") - public final void testInvoke() { - DataType<Class> type1 = new DataType<Class>("xml:string", String.class, String.class); - List<DataType<Class>> types1 = new ArrayList<DataType<Class>>(); - types1.add(type1); - DataType<List<DataType<Class>>> inputType1 = - new DataType<List<DataType<Class>>>("xml:string", Object[].class, types1); - - DataType<Class> type2 = new DataType<Class>("foo", Foo.class, Foo.class); - List<DataType<Class>> types2 = new ArrayList<DataType<Class>>(); - types2.add(type2); - DataType<List<DataType<Class>>> inputType2 = - new DataType<List<DataType<Class>>>("foo", Object[].class, types2); - - Operation<Class> operation1 = - new Operation<Class>("call", inputType1, type1, null, false, "xml:string", NO_CONVERSATION); - Operation<Class> operation2 = - new Operation<Class>("call", inputType2, type2, null, false, "org.w3c.dom.Node", NO_CONVERSATION); - - DataType<DataType> outputType1 = - new DataType<DataType>(DataBinding.IDL_OUTPUT, Object.class, operation1.getOutputType()); - DataType<DataType> outputType2 = - new DataType<DataType>(DataBinding.IDL_OUTPUT, Object.class, operation2.getOutputType()); - - OutboundWire outboundWire = EasyMock.createMock(OutboundWire.class); - InboundWire inboundWire = EasyMock.createMock(InboundWire.class); - CompositeComponent composite = EasyMock.createMock(CompositeComponent.class); - Component component = EasyMock.createMock(Component.class); - EasyMock.expect(component.getParent()).andReturn(composite).once(); - EasyMock.expect(outboundWire.getContainer()).andReturn(component); - EasyMock.replay(outboundWire, inboundWire, composite, component); - - DataBindingInteceptor interceptor = new DataBindingInteceptor(outboundWire, operation1, operation2); - Mediator mediator = createMock(Mediator.class); - Object[] source = new Object[]{"<foo>bar</foo>"}; - Foo foo = new Foo(); - foo.bar = "bar"; - Object[] target = new Object[]{foo}; - expect(mediator.mediate(EasyMock.same(source), - EasyMock.same(inputType1), - EasyMock.same(inputType2), - EasyMock.isA(Map.class))).andReturn(target); - // expect(mediator.mediate(target[0], type2, - // type1)).andReturn(source[0]); - expect(mediator.mediate(EasyMock.same(target[0]), - EasyMock.eq(outputType2), - EasyMock.eq(outputType1), - EasyMock.isA(Map.class))).andReturn(source[0]); - replay(mediator); - interceptor.setMediator(mediator); - Message msg = createMock(Message.class); - msg.setBody(EasyMock.anyObject()); - expectLastCall().anyTimes(); - expect(msg.getBody()).andReturn(source).once().andReturn(target[0]).once().andReturn(source[0]); - expect(msg.isFault()).andReturn(false).once(); - replay(msg); - Interceptor next = createMock(Interceptor.class); - expect(next.invoke(msg)).andReturn(msg); - replay(next); - interceptor.setNext(next); - interceptor.invoke(msg); - String result = (String) msg.getBody(); - Assert.assertEquals(source[0], result); - EasyMock.verify(mediator, msg, next); - } - - protected void setUp() throws Exception { - super.setUp(); - } - - private static class Foo { - private String bar; - - public String getBar() { - return bar; - } - - public void setBar(String bar) { - this.bar = bar; - } - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingJavaInterfaceProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingJavaInterfaceProcessorTestCase.java deleted file mode 100644 index 9e181960b4..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingJavaInterfaceProcessorTestCase.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.core.databinding.impl; - -import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION; - -import java.lang.reflect.Type; -import java.util.HashMap; -import java.util.Map; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.api.annotation.DataType; -import org.apache.tuscany.spi.databinding.DataBindingRegistry; -import org.apache.tuscany.spi.idl.InvalidServiceContractException; -import org.apache.tuscany.spi.idl.java.JavaServiceContract; -import org.apache.tuscany.spi.model.Operation; -import org.osoa.sca.annotations.Remotable; -import org.w3c.dom.Node; - -/** - * - */ -public class DataBindingJavaInterfaceProcessorTestCase extends TestCase { - - /** - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - } - - /** - * @throws InvalidServiceContractException - */ - public final void testVisitInterface() throws InvalidServiceContractException { - DataBindingRegistry registry = new DataBindingRegistryImpl(); - DataBindingJavaInterfaceProcessor processor = new DataBindingJavaInterfaceProcessor(registry); - JavaServiceContract contract = new JavaServiceContract(MockInterface.class); - Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>(); - Operation<Type> operation = new Operation<Type>("call", null, null, null, false, null, NO_CONVERSATION); - Operation<Type> operation1 = new Operation<Type>("call1", null, null, null, false, null, NO_CONVERSATION); - operations.put("call", operation); - operations.put("call1", operation1); - contract.setOperations(operations); - contract.setRemotable(true); - processor.visitInterface(MockInterface.class, null, contract); - Assert.assertEquals("org.w3c.dom.Node", contract.getDataBinding()); - Assert.assertEquals("org.w3c.dom.Node", contract.getOperations().get("call").getDataBinding()); - Assert.assertEquals("xml:string", contract.getOperations().get("call1").getDataBinding()); - } - - @DataType(name = "org.w3c.dom.Node") - @Remotable - public static interface MockInterface { - Node call(Node msg); - - @DataType(name = "xml:string") - String call1(String msg); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingLoaderTestCase.java deleted file mode 100644 index 02dd10ee97..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingLoaderTestCase.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.core.databinding.impl; - -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.spi.loader.InvalidValueException; -import org.apache.tuscany.spi.loader.LoaderException; -import org.apache.tuscany.spi.model.DataType; -import org.apache.tuscany.spi.model.ModelObject; -import org.easymock.EasyMock; - -/** - * Testcase for DataBindingLoader - */ -public class DataBindingLoaderTestCase extends TestCase { - private XMLStreamReader reader; - - /** - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - } - - public final void testLoad() throws LoaderException, XMLStreamException { - reader = EasyMock.createMock(XMLStreamReader.class); - // EasyMock.expect(reader.getEventType()).andReturn(XMLStreamConstants.START_ELEMENT); - EasyMock.expect(reader.hasNext()).andReturn(true).anyTimes(); - EasyMock.expect(reader.getName()).andReturn(DataTypeLoader.DATA_BINDING); - EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn("ABC"); - EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT); - EasyMock.replay(reader); - - ModelObject mo = new DataTypeLoader(null).load(null, null, reader, null); - Assert.assertTrue(mo instanceof DataType); - Assert.assertEquals("ABC", ((DataType<?>)mo).getDataBinding()); - EasyMock.verify(reader); - - EasyMock.reset(reader); - - // EasyMock.expect(reader.getEventType()).andReturn(XMLStreamConstants.START_ELEMENT); - EasyMock.expect(reader.hasNext()).andReturn(true).anyTimes(); - EasyMock.expect(reader.getName()).andReturn(DataTypeLoader.DATA_BINDING); - EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn(null); - EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT); - EasyMock.replay(reader); - try { - mo = new DataTypeLoader(null).load(null, null, reader, null); - Assert.fail("InvalidValueException should have been thrown"); - } catch (InvalidValueException e) { - Assert.assertTrue(true); - } - EasyMock.verify(reader); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingRegistryImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingRegistryImplTestCase.java deleted file mode 100644 index 3ee5460ac3..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingRegistryImplTestCase.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.databinding.impl; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; - -import java.lang.annotation.Annotation; - -import javax.xml.stream.XMLStreamReader; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.spi.databinding.DataBinding; -import org.apache.tuscany.spi.databinding.DataBindingRegistry; -import org.apache.tuscany.spi.model.DataType; -import org.easymock.EasyMock; -import org.xml.sax.ContentHandler; - -/** - * - */ -public class DataBindingRegistryImplTestCase extends TestCase { - private DataBindingRegistry registry; - - /** - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - registry = new DataBindingRegistryImpl(); - } - - public void testRegistry() { - DataBinding db1 = createMock(DataBinding.class); - expect(db1.getAliases()).andReturn(new String[] {"db1"}).anyTimes(); - expect(db1.getName()).andReturn(ContentHandler.class.getName()).anyTimes(); - DataType<Class> dataType1 = new DataType<Class>(ContentHandler.class, ContentHandler.class); - expect(db1.introspect(dataType1, null)).andReturn(true); - expect(db1.introspect(EasyMock.not(EasyMock.same(dataType1)), (Annotation[])EasyMock.isNull())) - .andReturn(false).anyTimes(); - replay(db1); - - registry.register(db1); - - DataBinding db2 = createMock(DataBinding.class); - expect(db2.getAliases()).andReturn(new String[] {"db2"}).anyTimes(); - expect(db2.getName()).andReturn(XMLStreamReader.class.getName()).anyTimes(); - DataType<Class> dataType2 = new DataType<Class>(XMLStreamReader.class, XMLStreamReader.class); - expect(db2.introspect(dataType2, null)).andReturn(true); - expect(db2.introspect(EasyMock.not(EasyMock.same(dataType2)), (Annotation[])EasyMock.isNull())) - .andReturn(false).anyTimes(); - replay(db2); - - registry.register(db2); - - // Lookup by name - String name = db1.getName(); - DataBinding db3 = registry.getDataBinding(name); - assertSame(db1, db3); - - // Look up by alias - DataBinding db5 = registry.getDataBinding("db1"); - assertSame(db1, db5); - - DataType dt = new DataType(ContentHandler.class, null); - registry.introspectType(dt, null); - assertEquals(dataType1.getLogical(), ContentHandler.class); - assertTrue(dt.getDataBinding().equalsIgnoreCase("java.lang.Object")); - - registry.unregister(name); - DataBinding db4 = registry.getDataBinding(name); - assertNull(db4); - - dt = new DataType(null, String.class, null); - registry.introspectType(dt, null); - assertEquals("java.lang.Object", dt.getDataBinding()); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingTestCase.java deleted file mode 100644 index 5abb520b80..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingTestCase.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.databinding.impl; - -import java.lang.reflect.Method; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.api.annotation.DataType; - -public class DataBindingTestCase extends TestCase { - @SuppressWarnings("unused") - public void testDataType() throws Exception { - Class<Test> testClass = Test.class; - DataType d = testClass.getAnnotation(DataType.class); - Assert.assertEquals(d.name(), "sdo"); - - Method method = testClass.getMethod("test", new Class[] {Object.class}); - DataType d2 = method.getAnnotation(DataType.class); - Assert.assertEquals(d2.name(), "jaxb"); - } - - @DataType(name = "sdo") - private static interface Test { - @DataType(name = "jaxb") - Object test(Object object); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorOptimizationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorOptimizationTestCase.java deleted file mode 100644 index d871978cb4..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorOptimizationTestCase.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.databinding.impl; - -import java.lang.reflect.Type; -import java.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.component.SCAObject; -import org.apache.tuscany.spi.databinding.Mediator; -import org.apache.tuscany.spi.idl.java.JavaServiceContract; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * Verifies that data binding interceptor is not added to invocation chains when the data binding types are not set on - * service contracts - * - * @version $Rev$ $Date$ - */ -public class DataBindingWirePostProcessorOptimizationTestCase extends TestCase { - private DataBindingWirePostProcessor processor; - private OutboundInvocationChain outboundChain; - private OutboundWire outboundWire; - private InboundInvocationChain inboundChain; - private InboundWire inboundWire; - - public void testNoInterceptorInterposedOutboundToInbound() { - processor.process(outboundWire, inboundWire); - EasyMock.verify(outboundChain); - EasyMock.verify(inboundChain); - EasyMock.verify(outboundWire); - EasyMock.verify(inboundWire); - } - - public void testNoInterceptorInterposedInboundToOutbound() { - processor.process(inboundWire, outboundWire); - EasyMock.verify(outboundChain); - EasyMock.verify(inboundChain); - EasyMock.verify(outboundWire); - EasyMock.verify(inboundWire); - } - - - protected void setUp() throws Exception { - super.setUp(); - SCAObject container = EasyMock.createMock(SCAObject.class); - EasyMock.expect(container.getName()).andReturn("foo"); - EasyMock.replay(container); - - Mediator mediator = new MediatorImpl(); - processor = new DataBindingWirePostProcessor(mediator); - - ServiceContract<Type> contract = new JavaServiceContract(null); - Operation<Type> operation = new Operation<Type>("test", null, null, null); - operation.setServiceContract(contract); - Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>(); - operations.put("test", operation); - contract.setOperations(operations); - contract.setCallbackOperations(operations); - - inboundChain = EasyMock.createMock(InboundInvocationChain.class); - EasyMock.replay(inboundChain); - Map<Operation<?>, InboundInvocationChain> inboundChains = new HashMap<Operation<?>, InboundInvocationChain>(); - inboundChains.put(operation, inboundChain); - - outboundChain = EasyMock.createMock(OutboundInvocationChain.class); - EasyMock.replay(outboundChain); - Map<Operation<?>, OutboundInvocationChain> outboundChains = - new HashMap<Operation<?>, OutboundInvocationChain>(); - outboundChains.put(operation, outboundChain); - - outboundWire = EasyMock.createMock(OutboundWire.class); - EasyMock.expect(outboundWire.getInvocationChains()).andReturn(outboundChains); - EasyMock.expect(outboundWire.getServiceContract()).andReturn(contract).anyTimes(); - EasyMock.expect(outboundWire.getContainer()).andReturn(container).anyTimes(); - EasyMock.expect(outboundWire.getTargetCallbackInvocationChains()).andReturn(inboundChains).anyTimes(); - EasyMock.replay(outboundWire); - - inboundWire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(inboundWire.getInvocationChains()).andReturn(inboundChains); - EasyMock.expect(inboundWire.getContainer()).andReturn(container).anyTimes(); - EasyMock.expect(inboundWire.getSourceCallbackInvocationChains(EasyMock.eq("foo"))).andReturn(outboundChains) - .anyTimes(); - EasyMock.replay(inboundWire); - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorTestCase.java deleted file mode 100644 index 29bf91f2c7..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DataBindingWirePostProcessorTestCase.java +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.core.databinding.impl; - -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.w3c.dom.Node; - -import org.apache.tuscany.spi.component.Component; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.ReferenceBinding; -import org.apache.tuscany.spi.component.ServiceBinding; -import org.apache.tuscany.spi.databinding.Mediator; -import org.apache.tuscany.spi.idl.java.JavaServiceContract; -import org.apache.tuscany.spi.model.DataType; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; - -import junit.framework.TestCase; -import org.easymock.EasyMock; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; - -/** - * @version $Rev$ $Date$ - */ -public class DataBindingWirePostProcessorTestCase extends TestCase { - private DataBindingWirePostProcessor processor; - - /** - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - Mediator mediator = new MediatorImpl(); - this.processor = new DataBindingWirePostProcessor(mediator); - } - - public void testProcess1() { - InboundWire inboundWire = createMock(InboundWire.class); - OutboundWire outboundWire = createMock(OutboundWire.class); - - Component component = createMock(Component.class); - CompositeComponent composite = createMock(CompositeComponent.class); - expect(component.getParent()).andReturn(composite); - expect(inboundWire.getContainer()).andReturn(component); - expect(outboundWire.getContainer()).andReturn(component); - - Map<Operation<?>, OutboundInvocationChain> outboundChains = - new HashMap<Operation<?>, OutboundInvocationChain>(); - DataType<Type> type1 = new DataType<Type>(String.class, String.class); - List<DataType<Type>> types = new ArrayList<DataType<Type>>(); - types.add(type1); - DataType<List<DataType<Type>>> inputType1 = new DataType<List<DataType<Type>>>(Object[].class, types); - DataType<Type> outputType1 = new DataType<Type>(String.class, String.class); - Operation<Type> op1 = new Operation<Type>("test", inputType1, outputType1, null); - ServiceContract<Type> outboundContract = new JavaServiceContract(null); - outboundContract.setDataBinding(String.class.getName()); - op1.setServiceContract(outboundContract); - - OutboundInvocationChain outboundChain = createMock(OutboundInvocationChain.class); - outboundChains.put(op1, outboundChain); - expect(outboundWire.getInvocationChains()).andReturn(outboundChains); - outboundChain.addInterceptor(EasyMock.anyInt(), (Interceptor) EasyMock.anyObject()); - - Map<Operation<?>, InboundInvocationChain> inboundChains = - new HashMap<Operation<?>, InboundInvocationChain>(); - DataType<Type> type2 = new DataType<Type>(Node.class, Node.class); - List<DataType<Type>> types2 = new ArrayList<DataType<Type>>(); - types2.add(type2); - DataType<List<DataType<Type>>> inputType2 = - new DataType<List<DataType<Type>>>(Object[].class, types2); - DataType<Type> outputType2 = new DataType<Type>(String.class, String.class); - Operation<Type> op2 = new Operation<Type>("test", inputType2, outputType2, null); - ServiceContract<Type> inboundContract = new JavaServiceContract(null); - inboundContract.setDataBinding(Node.class.getName()); - op2.setServiceContract(inboundContract); - - InboundInvocationChain inboundChain = createMock(InboundInvocationChain.class); - inboundChains.put(op2, inboundChain); - expect(inboundWire.getInvocationChains()).andReturn(inboundChains); - - ServiceContract<Type> contract = new JavaServiceContract(); - Map<String, Operation<Type>> operations = Collections.emptyMap(); - contract.setCallbackOperations(operations); - expect(outboundWire.getServiceContract()).andReturn(contract); - - EasyMock.replay(composite, component, inboundWire, outboundWire, inboundChain, outboundChain); - - processor.process(outboundWire, inboundWire); - } - - public void testProcess2() { - InboundWire inboundWire = createMock(InboundWire.class); - OutboundWire outboundWire = createMock(OutboundWire.class); - - ReferenceBinding referenceBinding = createMock(ReferenceBinding.class); - CompositeComponent composite = createMock(CompositeComponent.class); - expect(referenceBinding.getParent()).andReturn(composite); - expect(inboundWire.getContainer()).andReturn(referenceBinding).anyTimes(); - expect(outboundWire.getContainer()).andReturn(referenceBinding).anyTimes(); - - Map<Operation<?>, OutboundInvocationChain> outboundChains = - new HashMap<Operation<?>, OutboundInvocationChain>(); - DataType<Type> type1 = new DataType<Type>(String.class, String.class); - List<DataType<Type>> types = new ArrayList<DataType<Type>>(); - types.add(type1); - DataType<List<DataType<Type>>> inputType1 = new DataType<List<DataType<Type>>>(Object[].class, types); - DataType<Type> outputType1 = new DataType<Type>(String.class, String.class); - Operation<Type> op1 = new Operation<Type>("test", inputType1, outputType1, null); - ServiceContract<Type> outboundContract = new JavaServiceContract(null); - outboundContract.setDataBinding(String.class.getName()); - op1.setServiceContract(outboundContract); - - OutboundInvocationChain outboundChain = createMock(OutboundInvocationChain.class); - outboundChains.put(op1, outboundChain); - expect(outboundWire.getInvocationChains()).andReturn(outboundChains).anyTimes(); - outboundChain.addInterceptor(EasyMock.anyInt(), (Interceptor) EasyMock.anyObject()); - - Map<Operation<?>, InboundInvocationChain> inboundChains = - new HashMap<Operation<?>, InboundInvocationChain>(); - DataType<Type> type2 = new DataType<Type>(Node.class, Node.class); - List<DataType<Type>> types2 = new ArrayList<DataType<Type>>(); - types2.add(type2); - DataType<List<DataType<Type>>> inputType2 = - new DataType<List<DataType<Type>>>(Object[].class, types2); - DataType<Type> outputType2 = new DataType<Type>(String.class, String.class); - Operation<Type> op2 = new Operation<Type>("test", inputType2, outputType2, null); - ServiceContract<Type> inboundContract = new JavaServiceContract(null); - inboundContract.setDataBinding(Node.class.getName()); - op2.setServiceContract(inboundContract); - - InboundInvocationChain inboundChain = createMock(InboundInvocationChain.class); - inboundChains.put(op2, inboundChain); - expect(inboundWire.getInvocationChains()).andReturn(inboundChains).anyTimes(); - - ServiceContract<Type> contract = new JavaServiceContract(); - Map<String, Operation<Type>> operations = Collections.emptyMap(); - contract.setCallbackOperations(operations); - expect(inboundWire.getServiceContract()).andReturn(contract); - expect(inboundChain.getTailInterceptor()).andReturn(null); - - EasyMock.replay(composite, referenceBinding, inboundWire, outboundWire, inboundChain, outboundChain); - - processor.process(inboundWire, outboundWire); - } - - public void testProcess3() { - InboundWire inboundWire = createMock(InboundWire.class); - OutboundWire outboundWire = createMock(OutboundWire.class); - - ServiceBinding serviceBinding = createMock(ServiceBinding.class); - CompositeComponent composite = createMock(CompositeComponent.class); - expect(serviceBinding.getParent()).andReturn(composite); - expect(inboundWire.getContainer()).andReturn(serviceBinding).anyTimes(); - expect(outboundWire.getContainer()).andReturn(serviceBinding).anyTimes(); - - Map<Operation<?>, OutboundInvocationChain> outboundChains = - new HashMap<Operation<?>, OutboundInvocationChain>(); - DataType<Type> type1 = new DataType<Type>(String.class, String.class); - List<DataType<Type>> types = new ArrayList<DataType<Type>>(); - types.add(type1); - DataType<List<DataType<Type>>> inputType1 = new DataType<List<DataType<Type>>>(Object[].class, types); - DataType<Type> outputType1 = new DataType<Type>(String.class, String.class); - Operation<Type> op1 = new Operation<Type>("test", inputType1, outputType1, null); - ServiceContract<Type> outboundContract = new JavaServiceContract(null); - outboundContract.setDataBinding(String.class.getName()); - op1.setServiceContract(outboundContract); - - OutboundInvocationChain outboundChain = createMock(OutboundInvocationChain.class); - outboundChains.put(op1, outboundChain); - expect(outboundWire.getInvocationChains()).andReturn(outboundChains).anyTimes(); - // outboundChain.addInterceptor(EasyMock.anyInt(), (Interceptor) - // EasyMock.anyObject()); - - Map<Operation<?>, InboundInvocationChain> inboundChains = - new HashMap<Operation<?>, InboundInvocationChain>(); - DataType<Type> type2 = new DataType<Type>(Node.class, Node.class); - List<DataType<Type>> types2 = new ArrayList<DataType<Type>>(); - types2.add(type2); - DataType<List<DataType<Type>>> inputType2 = - new DataType<List<DataType<Type>>>(Object[].class, types2); - DataType<Type> outputType2 = new DataType<Type>(String.class, String.class); - Operation<Type> op2 = new Operation<Type>("test", inputType2, outputType2, null); - ServiceContract<Type> inboundContract = new JavaServiceContract(null); - inboundContract.setDataBinding(Node.class.getName()); - op2.setServiceContract(inboundContract); - - InboundInvocationChain inboundChain = createMock(InboundInvocationChain.class); - inboundChains.put(op2, inboundChain); - expect(inboundWire.getInvocationChains()).andReturn(inboundChains).anyTimes(); - inboundChain.addInterceptor(EasyMock.anyInt(), (Interceptor) EasyMock.anyObject()); - - ServiceContract<Type> contract = new JavaServiceContract(); - Map<String, Operation<Type>> operations = Collections.emptyMap(); - contract.setCallbackOperations(operations); - expect(inboundWire.getServiceContract()).andReturn(contract); - - EasyMock.replay(composite, serviceBinding, inboundWire, outboundWire, inboundChain, outboundChain); - - processor.process(inboundWire, outboundWire); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DirectedGraphTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DirectedGraphTestCase.java deleted file mode 100755 index 70244df8e2..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/DirectedGraphTestCase.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.databinding.impl; - -import java.util.List; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.core.databinding.impl.DirectedGraph.Edge; -import org.apache.tuscany.core.databinding.impl.DirectedGraph.Vertex; - -public class DirectedGraphTestCase extends TestCase { - private DirectedGraph<String, Object> graph; - - protected void setUp() throws Exception { - super.setUp(); - graph = new DirectedGraph<String, Object>(); - graph.addEdge("a", "b", null, 3); - graph.addEdge("b", "c", null, 1); - graph.addEdge("a", "c", null, 8); - graph.addEdge("a", "d", null, 3); - graph.addEdge("b", "d", null, 2); - graph.addEdge("c", "b", null, 1); - graph.addEdge("c", "d", null, 2); - graph.addEdge("d", "b", null, 1); - graph.addEdge("a", "e", null, 8); - graph.addEdge("c", "c", null, 2); - } - - public void testGraph() { - // System.out.println(graph); - - Vertex vertex = graph.getVertex("a"); - Assert.assertNotNull(vertex); - Assert.assertEquals(vertex.getValue(), "a"); - - Assert.assertNull(graph.getVertex("1")); - - Edge edge = graph.getEdge("a", "b"); - Assert.assertNotNull(edge); - Assert.assertEquals(edge.getWeight(), 3); - - edge = graph.getEdge("b", "a"); - Assert.assertNull(edge); - - DirectedGraph<String, Object>.Path path = graph.getShortestPath("a", "c"); - - List<DirectedGraph<String, Object>.Edge> edges = path.getEdges(); - Assert.assertEquals(edges.size(), 2); - Assert.assertEquals(edges.get(0), graph.getEdge("a", "b")); - Assert.assertEquals(edges.get(1), graph.getEdge("b", "c")); - - Assert.assertEquals(path.getWeight(), 4); - - DirectedGraph<String, Object>.Path path2 = graph.getShortestPath("b", "e"); - Assert.assertNull(path2); - - DirectedGraph<String, Object>.Path path3 = graph.getShortestPath("a", "a"); - Assert.assertTrue(path3.getWeight() == 0 && path3.getEdges().isEmpty()); - - DirectedGraph<String, Object>.Path path4 = graph.getShortestPath("c", "c"); - Assert.assertTrue(path4.getWeight() == 2 && path4.getEdges().size() == 1); - - // System.out.println(path); - - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/IDLTransformerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/IDLTransformerTestCase.java deleted file mode 100644 index 7981080f82..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/IDLTransformerTestCase.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.databinding.impl; - -import static org.apache.tuscany.spi.databinding.DataBinding.IDL_INPUT; -import static org.apache.tuscany.spi.databinding.DataBinding.IDL_OUTPUT; - -import java.util.ArrayList; -import java.util.List; - -import javax.xml.namespace.QName; - -import junit.framework.TestCase; - -import org.apache.tuscany.core.databinding.javabeans.DOMNode2JavaBeanTransformer; -import org.apache.tuscany.core.databinding.javabeans.JavaBean2DOMNodeTransformer; -import org.apache.tuscany.core.databinding.xml.DOMDataBinding; -import org.apache.tuscany.core.databinding.xml.Node2String; -import org.apache.tuscany.core.databinding.xml.String2Node; -import org.apache.tuscany.spi.databinding.DataBindingRegistry; -import org.apache.tuscany.spi.databinding.TransformationContext; -import org.apache.tuscany.spi.databinding.extension.DOMHelper; -import org.apache.tuscany.spi.databinding.extension.SimpleTypeMapperExtension; -import org.apache.tuscany.spi.idl.ElementInfo; -import org.apache.tuscany.spi.idl.TypeInfo; -import org.apache.tuscany.spi.idl.XMLType; -import org.apache.tuscany.spi.model.DataType; -import org.apache.tuscany.spi.model.WrapperInfo; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -public class IDLTransformerTestCase extends TestCase { - private static final String IPO_XML = - "<?xml version=\"1.0\"?>" + "<order1" - + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" - + " xmlns:ipo=\"http://www.example.com/IPO\"" - + " xsi:schemaLocation=\"http://www.example.com/IPO ipo.xsd\"" - + " orderDate=\"1999-12-01\">" - + " <shipTo exportCode=\"1\" xsi:type=\"ipo:UKAddress\">" - + " <name>Helen Zoe</name>" - + " <street>47 Eden Street</street>" - + " <city>Cambridge</city>" - + " <postcode>CB1 1JR</postcode>" - + " </shipTo>" - + " <billTo xsi:type=\"ipo:USAddress\">" - + " <name>Robert Smith</name>" - + " <street>8 Oak Avenue</street>" - + " <city>Old Town</city>" - + " <state>PA</state>" - + " <zip>95819</zip>" - + " </billTo>" - + " <items>" - + " <item partNum=\"833-AA\">" - + " <productName>Lapis necklace</productName>" - + " <quantity>1</quantity>" - + " <USPrice>99.95</USPrice>" - + " <ipo:comment>Want this for the holidays</ipo:comment>" - + " <shipDate>1999-12-05</shipDate>" - + " </item>" - + " </items>" - + "</order1>"; - - private static final String URI_ORDER_XSD = "http://example.com/order.xsd"; - - /** - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - } - - public void testTransform() throws Exception { - List<DataType<XMLType>> types0 = new ArrayList<DataType<XMLType>>(); - DataType<XMLType> wrapperType = - new DataType<XMLType>(null, Object.class, new XMLType(new QName(URI_ORDER_XSD, "checkOrderStatus"), null)); - types0.add(wrapperType); - DataType<List<DataType<XMLType>>> inputType0 = - new DataType<List<DataType<XMLType>>>(IDL_INPUT, Object[].class, types0); - - List<DataType<XMLType>> types1 = new ArrayList<DataType<XMLType>>(); - DataType<XMLType> customerIdType = - new DataType<XMLType>(null, Object.class, new XMLType(new QName(URI_ORDER_XSD, "customerId"), null)); - DataType<XMLType> orderType = - new DataType<XMLType>(null, Object.class, new XMLType(new QName(URI_ORDER_XSD, "order"), null)); - DataType<XMLType> flagType = - new DataType<XMLType>(null, Object.class, new XMLType(new QName(URI_ORDER_XSD, "flag"), null)); - types1.add(customerIdType); - types1.add(orderType); - types1.add(flagType); - - DataType<XMLType> statusType = - new DataType<XMLType>(null, Object.class, new XMLType(new QName(URI_ORDER_XSD, "status"), null)); - DataType<XMLType> responseType = - new DataType<XMLType>(null, Object.class, new XMLType(new QName(URI_ORDER_XSD, "checkOrderStatusResponse"), - null)); - - org.apache.tuscany.spi.model.Operation<XMLType> op = - new org.apache.tuscany.spi.model.Operation<XMLType>("checkOrderStatus", inputType0, responseType, null); - op.setDataBinding(DOMDataBinding.NAME); - - inputType0.setOperation(op); - op.setWrapperStyle(true); - ElementInfo inputElement = - new ElementInfo(new QName(URI_ORDER_XSD, "checkOrderStatus"), new TypeInfo(null, false, null)); - wrapperType.setMetadata(ElementInfo.class.getName(), inputElement); - - ElementInfo customerId = - new ElementInfo(new QName("", "customerId"), SimpleTypeMapperExtension.XSD_SIMPLE_TYPES.get("string")); - ElementInfo order = - new ElementInfo(new QName("", "order"), new TypeInfo(new QName(URI_ORDER_XSD), false, null)); - ElementInfo flag = - new ElementInfo(new QName("", "flag"), SimpleTypeMapperExtension.XSD_SIMPLE_TYPES.get("int")); - - customerIdType.setMetadata(ElementInfo.class.getName(), customerId); - orderType.setMetadata(ElementInfo.class.getName(), order); - flagType.setMetadata(ElementInfo.class.getName(), flag); - - customerIdType.setOperation(op); - orderType.setOperation(op); - flagType.setOperation(op); - - List<ElementInfo> inputElements = new ArrayList<ElementInfo>(); - inputElements.add(customerId); - inputElements.add(order); - inputElements.add(flag); - - ElementInfo statusElement = - new ElementInfo(new QName("", "status"), SimpleTypeMapperExtension.XSD_SIMPLE_TYPES.get("string")); - - statusType.setMetadata(ElementInfo.class.getName(), statusElement); - statusType.setOperation(op); - - List<ElementInfo> outputElements = new ArrayList<ElementInfo>(); - outputElements.add(statusElement); - - ElementInfo outputElement = - new ElementInfo(new QName(URI_ORDER_XSD, "checkOrderStatusResponse"), new TypeInfo(null, false, null)); - - responseType.setMetadata(ElementInfo.class.getName(), inputElement); - responseType.setOperation(op); - - WrapperInfo wrapperInfo = - new WrapperInfo(DOMDataBinding.NAME, inputElement, outputElement, inputElements, outputElements); - op.setWrapper(wrapperInfo); - op.setDataBinding(DOMDataBinding.NAME); - - MediatorImpl m = new MediatorImpl(); - TransformerRegistryImpl tr = new TransformerRegistryImpl(); - tr.registerTransformer(new String2Node()); - tr.registerTransformer(new Node2String()); - tr.registerTransformer(new DOMNode2JavaBeanTransformer()); - tr.registerTransformer(new JavaBean2DOMNodeTransformer()); - m.setTransformerRegistry(tr); - DataBindingRegistry dataBindingRegistry = new DataBindingRegistryImpl(); - dataBindingRegistry.register(new DOMDataBinding()); - m.setDataBindingRegistry(dataBindingRegistry); - - Object[] source = new Object[] {"cust001", IPO_XML, Integer.valueOf(1)}; - Input2InputTransformer t = new Input2InputTransformer(); - t.setMediator(m); - - TransformationContext context = new TransformationContextImpl(); - List<DataType<Class>> types = new ArrayList<DataType<Class>>(); - types.add(new DataType<Class>(Object.class.getName(), String.class, String.class)); - types.add(new DataType<Class>("java.lang.String", String.class, String.class)); - types.add(new DataType<Class>(Object.class.getName(), int.class, int.class)); - DataType<List<DataType<Class>>> inputType1 = - new DataType<List<DataType<Class>>>(IDL_INPUT, Object[].class, types); - context.setSourceDataType(inputType1); - context.setTargetDataType(op.getInputType()); - Object[] results = t.transform(source, context); - assertEquals(1, results.length); - assertTrue(results[0] instanceof Element); - Element element = (Element)results[0]; - assertEquals("http://example.com/order.xsd", element.getNamespaceURI()); - assertEquals("checkOrderStatus", element.getLocalName()); - - TransformationContext context1 = new TransformationContextImpl(); - DataType<DataType> sourceType = new DataType<DataType>(IDL_OUTPUT, Object.class, op.getOutputType()); - sourceType.setOperation(op.getOutputType().getOperation()); - - context1.setSourceDataType(sourceType); - DataType<DataType> targetType = - new DataType<DataType>(IDL_OUTPUT, Object.class, new DataType<Class>("java.lang.Object", String.class, - String.class)); - context1.setTargetDataType(targetType); - - Document factory = DOMHelper.newDocument(); - Element responseElement = - factory.createElementNS("http://example.com/order.wsdl", "p:checkOrderStatusResponse"); - Element status = factory.createElement("status"); - responseElement.appendChild(status); - status.appendChild(factory.createTextNode("shipped")); - Output2OutputTransformer t2 = new Output2OutputTransformer(); - t2.setMediator(m); - Object st = t2.transform(responseElement, context1); - assertEquals("shipped", st); - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/MediatorImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/MediatorImplTestCase.java deleted file mode 100644 index 3cb7f243a9..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/MediatorImplTestCase.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.databinding.impl; - -import java.io.StringWriter; -import java.io.Writer; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.core.databinding.xml.Node2String; -import org.apache.tuscany.core.databinding.xml.Node2Writer; -import org.apache.tuscany.core.databinding.xml.SAX2DOMPipe; -import org.apache.tuscany.core.databinding.xml.String2SAX; -import org.apache.tuscany.spi.databinding.DataBindingRegistry; -import org.apache.tuscany.spi.databinding.TransformationContext; -import org.apache.tuscany.spi.databinding.TransformerRegistry; -import org.apache.tuscany.spi.model.DataType; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - * Test case for MediatorImpl - */ -public class MediatorImplTestCase extends TestCase { - private static final String IPO_XML = - "<?xml version=\"1.0\"?>" + "<ipo:purchaseOrder" - + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" - + " xmlns:ipo=\"http://www.example.com/IPO\"" - + " xsi:schemaLocation=\"http://www.example.com/IPO ipo.xsd\"" - + " orderDate=\"1999-12-01\">" - + " <shipTo exportCode=\"1\" xsi:type=\"ipo:UKAddress\">" - + " <name>Helen Zoe</name>" - + " <street>47 Eden Street</street>" - + " <city>Cambridge</city>" - + " <postcode>CB1 1JR</postcode>" - + " </shipTo>" - + " <billTo xsi:type=\"ipo:USAddress\">" - + " <name>Robert Smith</name>" - + " <street>8 Oak Avenue</street>" - + " <city>Old Town</city>" - + "<state>PA</state>" - + " <zip>95819</zip>" - + " </billTo>" - + " <items>" - + " <item partNum=\"833-AA\">" - + " <productName>Lapis necklace</productName>" - + " <quantity>1</quantity>" - + "<USPrice>99.95</USPrice>" - + " <ipo:comment>Want this for the holidays</ipo:comment>" - + " <shipDate>1999-12-05</shipDate>" - + " </item>" - + " </items>" - + "</ipo:purchaseOrder>"; - - private MediatorImpl mediator; - - protected void setUp() throws Exception { - super.setUp(); - - TransformerRegistry registry = new TransformerRegistryImpl(); - registry.registerTransformer(new String2SAX()); - registry.registerTransformer(new SAX2DOMPipe()); - registry.registerTransformer(new Node2String()); - registry.registerTransformer(new Node2Writer()); - - mediator = new MediatorImpl(); - mediator.setTransformerRegistry(registry); - - DataBindingRegistry dataBindingRegistry = new DataBindingRegistryImpl(); - mediator.setDataBindingRegistry(dataBindingRegistry); - } - - private TransformationContext createTransformationContext(Class sourceType, Class targetType) { - TransformationContext context = new TransformationContextImpl(); - DataType sourceDataType = new DataType<Class>(sourceType, sourceType); - DataType targetDataType = new DataType<Class>(targetType, targetType); - context.setSourceDataType(sourceDataType); - context.setTargetDataType(targetDataType); - return context; - } - - public void testTransform1() { - TransformationContext context = createTransformationContext(String.class, Node.class); - Object node = - mediator.mediate(IPO_XML, context.getSourceDataType(), context.getTargetDataType(), null); - Assert.assertTrue(node instanceof Document); - Element root = ((Document)node).getDocumentElement(); - Assert.assertEquals(root.getNamespaceURI(), "http://www.example.com/IPO"); - Assert.assertEquals(root.getLocalName(), "purchaseOrder"); - } - - public void testTransform2() { - TransformationContext context = createTransformationContext(String.class, Writer.class); - Writer writer = new StringWriter(); - mediator.mediate(IPO_XML, writer, context.getSourceDataType(), context.getTargetDataType(), null); - String str = writer.toString(); - Assert.assertTrue(str != null && str.indexOf("<shipDate>1999-12-05</shipDate>") != -1); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueInterceptorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueInterceptorTestCase.java deleted file mode 100644 index 3e839bdae1..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueInterceptorTestCase.java +++ /dev/null @@ -1,75 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.tuscany.core.databinding.impl;
-
-import java.io.Serializable;
-
-import org.apache.tuscany.core.databinding.javabeans.JavaBeansDataBinding;
-import org.apache.tuscany.spi.databinding.DataBinding;
-
-import junit.framework.TestCase;
-
-/**
- * Test case for ByValueInterceptor
- */
-public class PassByValueInterceptorTestCase extends TestCase {
- private MySerialiable serialiable = new MySerialiable();
- private String str = "ABC";
- private Integer i = new Integer(1);
- private String[] array = new String[] {"1", "2"};
- private Object[] values;
-
- /**
- * @see junit.framework.TestCase#setUp()
- */
- protected void setUp() throws Exception {
- super.setUp();
- values = new Object[] {serialiable, str, i, serialiable, array};
- }
-
- private static class MySerialiable implements Serializable {
- private static final long serialVersionUID = 7827201707529055310L;
- private final String name = "Serializable";
- private final int age = 100;
-
- public int getAge() {
- return age;
- }
-
- public String getName() {
- return name;
- }
- }
-
- public void testCopy() {
- PassByValueInterceptor interceptor = new PassByValueInterceptor(null);
- DataBinding db = new JavaBeansDataBinding();
- interceptor.setParameterDatabindings(new DataBinding[] {db, db, db, db, db});
- Object[] copy = interceptor.copy(values);
- assertTrue(copy[0] instanceof MySerialiable);
- MySerialiable copied = (MySerialiable)copy[0];
- assertNotSame(serialiable, copy[0]);
- assertEquals(serialiable.getName(), copied.getName());
- assertEquals(serialiable.getAge(), copied.getAge());
- assertSame(copy[1], str);
- assertSame(copy[2], i);
- assertSame(copy[0], copy[3]);
- }
-}
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessorTestCase.java deleted file mode 100644 index 1839aa4044..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/PassByValueWirePostProcessorTestCase.java +++ /dev/null @@ -1,266 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.tuscany.core.databinding.impl;
-
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.Map;
-
-import org.apache.tuscany.spi.ObjectCreationException;
-import org.apache.tuscany.spi.component.ServiceBinding;
-import org.apache.tuscany.spi.component.TargetResolutionException;
-import org.apache.tuscany.spi.databinding.DataBindingRegistry;
-import org.apache.tuscany.spi.extension.AtomicComponentExtension;
-import org.apache.tuscany.spi.idl.java.JavaServiceContract;
-import org.apache.tuscany.spi.model.Operation;
-import org.apache.tuscany.spi.model.ServiceContract;
-import org.apache.tuscany.spi.wire.InboundInvocationChain;
-import org.apache.tuscany.spi.wire.InboundWire;
-import org.apache.tuscany.spi.wire.Interceptor;
-import org.apache.tuscany.spi.wire.OutboundInvocationChain;
-import org.apache.tuscany.spi.wire.OutboundWire;
-import org.apache.tuscany.spi.wire.TargetInvoker;
-
-import junit.framework.TestCase;
-import org.apache.tuscany.core.wire.InboundInvocationChainImpl;
-import org.apache.tuscany.core.wire.OutboundInvocationChainImpl;
-import org.apache.tuscany.core.wire.SynchronousBridgingInterceptor;
-import org.easymock.EasyMock;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-
-/**
- * Testcase for testing if the PassByValueWireProcessor adds the PassByValueInterceptor to the invocation chains and
- * also ensure that the outbound and inbound chain of interceptors are linked after this insertion
- *
- * @version $Rev$ $Date$
- */
-public class PassByValueWirePostProcessorTestCase extends TestCase {
- private PassByValueWirePostProcessor processor;
-
- /**
- * @see junit.framework.TestCase#setUp()
- */
- protected void setUp() throws Exception {
- super.setUp();
- this.processor = new PassByValueWirePostProcessor();
- DataBindingRegistry dataBindingRegistry = createMock(DataBindingRegistry.class);
- processor.setDataBindingRegistry(dataBindingRegistry);
- }
-
- public void testProcessInclusionOfInterceptor() {
-
- InboundWire inboundWire = createMock(InboundWire.class);
- OutboundWire outboundWire = createMock(OutboundWire.class);
-
- ServiceContract<Type> serviceContract = new JavaServiceContract(null);
- serviceContract.setRemotable(true);
- Map<Operation<?>, InboundInvocationChain> inChainsMap =
- new Hashtable<Operation<?>, InboundInvocationChain>();
-
- Operation<Type> operation1 = new Operation<Type>("testMethod", null, null, null);
- operation1.setServiceContract(serviceContract);
- InboundInvocationChainImpl inChain = new InboundInvocationChainImpl(operation1);
- inChainsMap.put(operation1, inChain);
-
- AtomicComponentExtension componentExtn = new FooComponent();
- componentExtn.setPassByReferenceMethods(new ArrayList<String>());
-
- Map<Operation<?>, OutboundInvocationChain> outChainsMap =
- new Hashtable<Operation<?>, OutboundInvocationChain>();
- OutboundInvocationChainImpl outChain = new OutboundInvocationChainImpl(operation1);
- outChainsMap.put(operation1, outChain);
-
- expect(inboundWire.getServiceContract()).andReturn(serviceContract);
- expect(inboundWire.getContainer()).andReturn(componentExtn).anyTimes();
- expect(outboundWire.getContainer()).andReturn(componentExtn).anyTimes();
- expect(inboundWire.getServiceContract()).andReturn(serviceContract);
- expect(inboundWire.getInvocationChains()).andReturn(inChainsMap);
- expect(outboundWire.getServiceContract()).andReturn(serviceContract).times(2);
- expect(outboundWire.getInvocationChains()).andReturn(outChainsMap).times(2);
-
- Interceptor inInterceptor = createMock(Interceptor.class);
- Interceptor outInterceptor = createMock(Interceptor.class);
- inChain.addInterceptor(0, inInterceptor);
- outChain.addInterceptor(0, outInterceptor);
- outChain.addInterceptor(new SynchronousBridgingInterceptor(inChain.getHeadInterceptor()));
-
- EasyMock.replay(inboundWire, outboundWire);
- processor.process(outboundWire, inboundWire);
-
- assertEquals(true, outChain.getHeadInterceptor() instanceof PassByValueInterceptor);
- assertEquals(true, outChain.getTailInterceptor().getNext().equals(
- inChain.getHeadInterceptor()));
-
- }
-
- public void testProcessExclusionOfInterceptorWhenAllowsPassByReference() {
- InboundWire inboundWire = createMock(InboundWire.class);
- OutboundWire outboundWire = createMock(OutboundWire.class);
-
- ServiceContract<Type> serviceContract = new JavaServiceContract(null);
- serviceContract.setRemotable(true);
- Map<Operation<?>, InboundInvocationChain> inChainsMap =
- new Hashtable<Operation<?>, InboundInvocationChain>();
-
- Operation<?> operation1 = new Operation<Type>("testMethod", null, null, null);
- InboundInvocationChainImpl inChain = new InboundInvocationChainImpl(operation1);
- inChainsMap.put(operation1, inChain);
-
- AtomicComponentExtension componentExtn = new FooComponent();
- componentExtn.setAllowsPassByReference(true);
- componentExtn.setPassByReferenceMethods(new ArrayList<String>());
-
-
- Map<Operation<?>, OutboundInvocationChain> outChainsMap =
- new Hashtable<Operation<?>, OutboundInvocationChain>();
- OutboundInvocationChainImpl outChain = new OutboundInvocationChainImpl(operation1);
- outChainsMap.put(operation1, outChain);
-
- expect(inboundWire.getServiceContract()).andReturn(serviceContract);
- expect(inboundWire.getContainer()).andReturn(componentExtn).anyTimes();
- expect(outboundWire.getContainer()).andReturn(componentExtn).anyTimes();
- expect(inboundWire.getServiceContract()).andReturn(serviceContract);
- expect(inboundWire.getInvocationChains()).andReturn(inChainsMap);
- expect(outboundWire.getServiceContract()).andReturn(serviceContract).anyTimes();
- expect(outboundWire.getInvocationChains()).andReturn(outChainsMap).times(2);
-
- Interceptor inInterceptor = createMock(Interceptor.class);
- Interceptor outInterceptor = createMock(Interceptor.class);
- inChain.addInterceptor(0, inInterceptor);
- outChain.addInterceptor(0, outInterceptor);
- outChain.addInterceptor(new SynchronousBridgingInterceptor(inChain.getHeadInterceptor()));
-
- EasyMock.replay(inboundWire, outboundWire);
- processor.process(outboundWire, inboundWire);
-
- assertEquals(false, inChain.getHeadInterceptor() instanceof PassByValueInterceptor);
- assertEquals(false,
- outChain.getTailInterceptor().getNext() instanceof PassByValueInterceptor);
- assertEquals(true, outChain.getTailInterceptor().getNext().equals(
- inChain.getHeadInterceptor()));
- }
-
- public void testProcessExclusionOfInterceptorWhenAllowsPassByReferenceAtMethod() {
- InboundWire inboundWire = createMock(InboundWire.class);
- OutboundWire outboundWire = createMock(OutboundWire.class);
-
- ServiceContract<Type> serviceContract = new JavaServiceContract(null);
- serviceContract.setRemotable(true);
- Map<Operation<?>, InboundInvocationChain> inChainsMap =
- new Hashtable<Operation<?>, InboundInvocationChain>();
-
- Operation<?> operation1 = new Operation<Type>("testMethod", null, null, null);
- InboundInvocationChainImpl inChain = new InboundInvocationChainImpl(operation1);
- inChainsMap.put(operation1, inChain);
-
- AtomicComponentExtension componentExtn = new FooComponent();
- componentExtn.setPassByReferenceMethods(new ArrayList<String>());
- componentExtn.getPassByReferenceMethods().add("testMethod");
-
-
- Map<Operation<?>, OutboundInvocationChain> outChainsMap =
- new Hashtable<Operation<?>, OutboundInvocationChain>();
- OutboundInvocationChainImpl outChain = new OutboundInvocationChainImpl(operation1);
- outChainsMap.put(operation1, outChain);
-
- expect(inboundWire.getServiceContract()).andReturn(serviceContract);
- expect(inboundWire.getContainer()).andReturn(componentExtn).anyTimes();
- expect(outboundWire.getContainer()).andReturn(componentExtn).anyTimes();
- expect(inboundWire.getServiceContract()).andReturn(serviceContract);
- expect(inboundWire.getInvocationChains()).andReturn(inChainsMap);
- expect(outboundWire.getServiceContract()).andReturn(serviceContract).anyTimes();
- expect(outboundWire.getInvocationChains()).andReturn(outChainsMap).times(2);
-
- Interceptor inInterceptor = createMock(Interceptor.class);
- Interceptor outInterceptor = createMock(Interceptor.class);
- inChain.addInterceptor(0, inInterceptor);
- outChain.addInterceptor(0, outInterceptor);
- outChain.addInterceptor(new SynchronousBridgingInterceptor(inChain.getHeadInterceptor()));
-
- EasyMock.replay(inboundWire, outboundWire);
- processor.process(outboundWire, inboundWire);
-
- assertEquals(false, inChain.getHeadInterceptor() instanceof PassByValueInterceptor);
- assertEquals(false,
- outChain.getTailInterceptor().getNext() instanceof PassByValueInterceptor);
- assertEquals(true, outChain.getTailInterceptor().getNext().equals(
- inChain.getHeadInterceptor()));
- }
-
- public void testProcessExclusionOfInterceptorForBinding() {
- InboundWire inboundWire = createMock(InboundWire.class);
- OutboundWire outboundWire = createMock(OutboundWire.class);
-
- ServiceBinding serviceBinding = createMock(ServiceBinding.class);
- expect(outboundWire.getContainer()).andReturn(serviceBinding).anyTimes();
- expect(inboundWire.getContainer()).andReturn(null).anyTimes();
-
- ServiceContract<Type> serviceContract = new JavaServiceContract(null);
- serviceContract.setRemotable(true);
- Map<Operation<?>, InboundInvocationChain> inChainsMap =
- new Hashtable<Operation<?>, InboundInvocationChain>();
-
- Operation<?> operation1 = new Operation<Type>("testMethod", null, null, null);
- InboundInvocationChainImpl inChain = new InboundInvocationChainImpl(operation1);
- inChainsMap.put(operation1, inChain);
-
- Map<Operation<?>, OutboundInvocationChain> outChainsMap =
- new Hashtable<Operation<?>, OutboundInvocationChain>();
- OutboundInvocationChainImpl outChain = new OutboundInvocationChainImpl(operation1);
- outChainsMap.put(operation1, outChain);
-
- Interceptor inInterceptor = createMock(Interceptor.class);
- Interceptor outInterceptor = createMock(Interceptor.class);
- inChain.addInterceptor(0, inInterceptor);
- outChain.addInterceptor(0, outInterceptor);
- outChain.addInterceptor(new SynchronousBridgingInterceptor(inChain.getHeadInterceptor()));
-
- EasyMock.replay(inboundWire, outboundWire);
- processor.process(outboundWire, inboundWire);
-
- assertEquals(false, inChain.getHeadInterceptor() instanceof PassByValueInterceptor);
- assertEquals(false,
- outChain.getTailInterceptor().getNext() instanceof PassByValueInterceptor);
- assertEquals(true, outChain.getTailInterceptor().getNext().equals(
- inChain.getHeadInterceptor()));
- }
-
- private class FooComponent extends AtomicComponentExtension {
-
- public FooComponent() {
- super(null, null, null, null, null, null, 0);
- }
-
- public Object createInstance() throws ObjectCreationException {
- return null;
- }
-
- public Object getTargetInstance() throws TargetResolutionException {
- return null;
- }
-
- public TargetInvoker createTargetInvoker(String targetName, Operation operation, InboundWire callbackWire) {
- return null;
- }
-
- }
-}
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/TransformerRegistryImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/TransformerRegistryImplTestCase.java deleted file mode 100644 index 6250efd897..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/impl/TransformerRegistryImplTestCase.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.core.databinding.impl; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; - -import java.util.List; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.spi.databinding.Transformer; -import org.apache.tuscany.spi.databinding.TransformerRegistry; - -/** - * - */ -public class TransformerRegistryImplTestCase extends TestCase { - private TransformerRegistry registry; - - /** - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - registry = new TransformerRegistryImpl(); - } - - public void testRegisterTransformer1() { - Transformer transformer = createMock(Transformer.class); - registry.registerTransformer("a", "b", 10, transformer); - Transformer t = registry.getTransformer("a", "b"); - Assert.assertSame(t, transformer); - } - - public void testRegisterTransformerTransformer() { - Transformer transformer = createMock(Transformer.class); - expect(transformer.getSourceDataBinding()).andReturn("a"); - expect(transformer.getTargetDataBinding()).andReturn("b"); - expect(transformer.getWeight()).andReturn(10); - replay(transformer); - registry.registerTransformer(transformer); - Transformer t = registry.getTransformer("a", "b"); - Assert.assertSame(t, transformer); - } - - public void testUnregisterTransformer() { - Transformer transformer = createMock(Transformer.class); - registry.registerTransformer("a", "b", 10, transformer); - boolean result = registry.unregisterTransformer("a", "b"); - Assert.assertTrue(result); - Transformer t = registry.getTransformer("a", "b"); - Assert.assertNull(t); - } - - public void testGetTransformerChain() { - Transformer t1 = createMock(Transformer.class); - expect(t1.getSourceDataBinding()).andReturn("a"); - expect(t1.getTargetDataBinding()).andReturn("b"); - expect(t1.getWeight()).andReturn(10); - replay(t1); - Transformer t2 = createMock(Transformer.class); - expect(t2.getSourceDataBinding()).andReturn("b"); - expect(t2.getTargetDataBinding()).andReturn("c"); - expect(t2.getWeight()).andReturn(20); - replay(t2); - - Transformer t3 = createMock(Transformer.class); - expect(t3.getSourceDataBinding()).andReturn("a"); - expect(t3.getTargetDataBinding()).andReturn("c"); - expect(t3.getWeight()).andReturn(120); - replay(t3); - - registry.registerTransformer(t1); - registry.registerTransformer(t2); - registry.registerTransformer(t3); - - List<Transformer> l1 = registry.getTransformerChain("a", "b"); - Assert.assertTrue(l1.size() == 1 && l1.get(0) == t1); - List<Transformer> l2 = registry.getTransformerChain("a", "c"); - Assert.assertTrue(l2.size() == 2 && l2.get(0) == t1 && l2.get(1) == t2); - List<Transformer> l3 = registry.getTransformerChain("a", "d"); - Assert.assertNull(l3); - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformerTestCase.java deleted file mode 100644 index e654fe3ec9..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/DOMNode2JavaBeanTransformerTestCase.java +++ /dev/null @@ -1,187 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.tuscany.core.databinding.javabeans;
-
-import java.io.StringReader;
-import java.io.StringWriter;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
-import junit.framework.TestCase;
-
-import org.apache.tuscany.core.databinding.javabeans.DOMNode2JavaBeanTransformer;
-import org.apache.tuscany.core.databinding.javabeans.JavaBean2DOMNodeTransformer;
-import org.apache.tuscany.spi.databinding.TransformationContext;
-import org.apache.tuscany.spi.databinding.extension.DOMHelper;
-import org.apache.tuscany.spi.idl.ElementInfo;
-import org.apache.tuscany.spi.idl.TypeInfo;
-import org.apache.tuscany.spi.idl.XMLType;
-import org.apache.tuscany.spi.model.DataType;
-import org.easymock.EasyMock;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.xml.sax.InputSource;
-
-/**
- * Testcase to test the XMLTypeMapperExtension which is the back bone for all transformations supported by the JavaBeans
- * Databinding.
- *
- * @version $Rev$ $Date$
- */
-public class DOMNode2JavaBeanTransformerTestCase extends TestCase {
-
- private DOMNode2JavaBeanTransformer dom2JavaTransformer = new DOMNode2JavaBeanTransformer();
-
- /**
- * @see junit.framework.TestCase#setUp()
- */
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- public void testFieldSettings() throws Exception {
- String samplePropertyXML =
- "<property name=\"prop2\" >" + "<integerNumber>27</integerNumber>"
- + "<floatNumber>79.34</floatNumber>"
- + "<doubleNumber>184.52</doubleNumber>" + "<innerProperty>"
- + "<integerNumber>54</integerNumber>" + "<floatNumber>158.68</floatNumber>"
- + "<doubleNumber>369.04</doubleNumber>" + "</innerProperty>"
- + "<stringArray>TestString_1</stringArray>"
- + "<stringArray>TestString_2</stringArray>" + "<boolArray>true</boolArray>"
- + "<boolArray>false</boolArray>" + "</property>";
-
- DocumentBuilder builder = DOMHelper.newDocumentBuilder();
- InputSource inputSource = new InputSource(new StringReader(samplePropertyXML));
- Node samplePropertyNode = builder.parse(inputSource);
- TypeInfo typeInfo = new TypeInfo(null, false, null);
-
- TransformationContext context = EasyMock.createMock(TransformationContext.class);
- DataType<Class> targetDataType = new DataType<Class>(SamplePropertyBean.class, SamplePropertyBean.class);
- EasyMock.expect(context.getTargetDataType()).andReturn(targetDataType).anyTimes();
-
- DataType<XMLType> sourceDataType = new DataType<XMLType>(null, new XMLType(typeInfo));
- // ElementInfo eleInfo = new ElementInfo(null, typeInfo);
- // sourceDataType.setMetadata(ElementInfo.class.getName(), eleInfo);
- EasyMock.expect(context.getSourceDataType()).andReturn(sourceDataType).anyTimes();
- EasyMock.replay(context);
-
- Object javaObject =
- dom2JavaTransformer.transform(((Document) samplePropertyNode).getDocumentElement(), context);
-
- assertTrue(javaObject instanceof SamplePropertyBean);
- SamplePropertyBean samplePropBean = (SamplePropertyBean) javaObject;
- assertEquals(samplePropBean.getIntegerNumber(), 27);
- assertEquals((float) 79.34, samplePropBean.getFloatNumber());
- assertEquals(samplePropBean.getInnerProperty().getDoubleNumber(), 369.04);
-
- assertEquals(samplePropBean.getStringArray()[0], "TestString_1");
- assertEquals(samplePropBean.boolArray[0], true);
-
- /** testing for object to node * */
- javax.xml.transform.Transformer transformer =
- TransformerFactory.newInstance().newTransformer();
- JavaBean2DOMNodeTransformer java2DomTransformer = new JavaBean2DOMNodeTransformer();
- Node aNode = java2DomTransformer.transform(javaObject, context);
- StringWriter sw = new StringWriter();
- transformer.transform(new DOMSource(aNode), new StreamResult(sw));
- String nodeString = sw.toString();
- //System.out.println(nodeString);
-
- // testing the case when field and getter method do not have public access
- assertTrue(nodeString.indexOf("<doubleNumber>184.52</doubleNumber>") == -1);
- // test the case for fields that are of array type
- assertTrue(nodeString.indexOf("<stringArray>TestString_1</stringArray>"
- + "<stringArray>TestString_2</stringArray>") != -1);
- // testing the case for non-public field with public getter method
- assertTrue(nodeString.indexOf("<integerNumber>27</integerNumber>") != -1);
- // test the case for public field that is a another java bean .i.e. embeded javabean
- int startIndex = nodeString.indexOf("<innerProperty>");
- int endIndex = nodeString.indexOf("</innerProperty>");
- String fragment = nodeString.substring(startIndex, endIndex);
- assertTrue(fragment.indexOf("<integerNumber>54</integerNumber>") != -1);
-
- // System.out.println(sw.toString());
-
- }
-
-
- public static class SamplePropertyBean {
-
- private float floatNumber = 50;
- private SamplePropertyBean innerProperty;
- public boolean[] boolArray;
- private double doubleNumber = 75;
- private int integerNumber = 25;
- private String[] stringArray;
-
- public SamplePropertyBean() {
-
- }
-
- double getDoubleNumber() {
- return doubleNumber;
- }
-
- public void setDoubleNumber(double doubleNumber) {
- this.doubleNumber = doubleNumber;
- }
-
- public float getFloatNumber() {
- return floatNumber;
- }
-
- public void setFloatNumber(float floatNumber) {
- this.floatNumber = floatNumber;
- }
-
- public int getIntegerNumber() {
- return integerNumber;
- }
-
- public void setIntegerNumber(int integerNumber) {
- this.integerNumber = integerNumber;
- }
-
- public SamplePropertyBean getInnerProperty() {
- return innerProperty;
- }
-
- public void setInnerProperty(SamplePropertyBean prop) {
- this.innerProperty = prop;
- }
-
- public String toString() {
- return Double.toString(integerNumber + floatNumber + doubleNumber) + " & "
- + ((innerProperty == null) ? "" : innerProperty.toString());
- }
-
- public String[] getStringArray() {
- return stringArray;
- }
-
- public void setStringArray(String[] stringArray) {
- this.stringArray = stringArray;
- }
-
- }
-}
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2DOMNodeTransformerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2DOMNodeTransformerTestCase.java deleted file mode 100644 index 95701cc0fb..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/javabeans/JavaBean2DOMNodeTransformerTestCase.java +++ /dev/null @@ -1,127 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.tuscany.core.databinding.javabeans;
-
-import java.io.StringWriter;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
-import org.w3c.dom.Node;
-
-import org.apache.tuscany.spi.databinding.TransformationContext;
-import org.apache.tuscany.spi.model.DataType;
-
-import junit.framework.TestCase;
-import org.easymock.EasyMock;
-
-/**
- * Testcase to test the XMLTypeMapperExtension which is the back bone for all transformations supported by the JavaBeans
- * Databinding.
- *
- * @version $Rev$ $Date$
- */
-public class JavaBean2DOMNodeTransformerTestCase extends TestCase {
- private JavaBean2DOMNodeTransformer aTransformer = new JavaBean2DOMNodeTransformer();
-
- /**
- * @see junit.framework.TestCase#setUp()
- */
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- public void testTranformation() throws Exception {
- TransformationContext context = EasyMock.createMock(TransformationContext.class);
- DataType<Class> dataType = new DataType<Class>(null, SamplePropertyBean.class);
- EasyMock.expect(context.getTargetDataType()).andReturn(dataType).anyTimes();
- EasyMock.replay(context);
-
- javax.xml.transform.Transformer transformer =
- TransformerFactory.newInstance().newTransformer();
- Object data = new int[]{10, 20, 30, 40};
- Node aNode = aTransformer.transform(data, context);
- StringWriter sw = new StringWriter();
- transformer.transform(new DOMSource(aNode), new StreamResult(sw));
-
- System.out.println(sw.toString());
- assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><int_collection><int>10</int><int>20</int>"
- + "<int>30</int><int>40</int></int_collection>",
- sw.toString());
- }
-
- public static class SamplePropertyBean {
- private float floatNumber = 50;
- private SamplePropertyBean innerProperty;
- private double doubleNumber = 75;
- private int integerNumber = 25;
- private String[] stringArray;
-
- public SamplePropertyBean() {
-
- }
-
- double getDoubleNumber() {
- return doubleNumber;
- }
-
- public void setDoubleNumber(double doubleNumber) {
- this.doubleNumber = doubleNumber;
- }
-
- public float getFloatNumber() {
- return floatNumber;
- }
-
- public void setFloatNumber(float floatNumber) {
- this.floatNumber = floatNumber;
- }
-
- public int getIntegerNumber() {
- return integerNumber;
- }
-
- public void setIntegerNumber(int integerNumber) {
- this.integerNumber = integerNumber;
- }
-
- public SamplePropertyBean getInnerProperty() {
- return innerProperty;
- }
-
- public void setInnerProperty(SamplePropertyBean prop) {
- this.innerProperty = prop;
- }
-
- public String toString() {
- return Double.toString(integerNumber + floatNumber + doubleNumber) + " & "
- + ((innerProperty == null) ? "" : innerProperty.toString());
- }
-
- public String[] getStringArray() {
- return stringArray;
- }
-
- public void setStringArray(String[] stringArray) {
- this.stringArray = stringArray;
- }
-
- }
-}
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/DOM2StAXTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/DOM2StAXTestCase.java deleted file mode 100644 index bc9ecb2713..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/DOM2StAXTestCase.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.databinding.xml; - -import javax.xml.stream.XMLStreamReader; - -import junit.framework.TestCase; - -import org.w3c.dom.Node; - -public class DOM2StAXTestCase extends TestCase { - private static final String IPO_XML = - "<?xml version=\"1.0\"?>" + "<ipo:purchaseOrder" - + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" - + " xmlns:ipo=\"http://www.example.com/IPO\"" - + " xsi:schemaLocation=\"http://www.example.com/IPO ipo.xsd\"" - + " orderDate=\"1999-12-01\">" - + " <shipTo exportCode=\"1\" xsi:type=\"ipo:UKAddress\">" - + " <name>Helen Zoe</name>" - + " <street>47 Eden Street</street>" - + " <city>Cambridge</city>" - + " <postcode>CB1 1JR</postcode>" - + " </shipTo>" - + " <billTo xsi:type=\"ipo:USAddress\">" - + " <name>Robert Smith</name>" - + " <street>8 Oak Avenue</street>" - + " <city>Old Town</city>" - + " <state>PA</state>" - + " <zip>95819</zip>" - + " </billTo>" - + " <items>" - + " <item partNum=\"833-AA\">" - + " <productName>Lapis necklace</productName>" - + " <quantity>1</quantity>" - + " <USPrice>99.95</USPrice>" - + " <ipo:comment>Want this for the holidays</ipo:comment>" - + " <shipDate>1999-12-05</shipDate>" - + " </item>" - + " </items>" - + "</ipo:purchaseOrder>"; - - private static final String CRAZY_XML = - "<p:e1 xmlns=\"http://ns0\" xmlns:p=\"http://p1\">" - + "<p:e2 xmlns:p=\"http://p2\"/><e3/><e4 xmlns=\"\">E4</e4></p:e1>"; - - /** - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - } - - public void testTransformation() { - String2Node t1 = new String2Node(); - Node node = t1.transform(IPO_XML, null); - Node2XMLStreamReader t2 = new Node2XMLStreamReader(); - XMLStreamReader reader = t2.transform(node, null); - XMLStreamReader2String t3 = new XMLStreamReader2String(); - String xml = t3.transform(reader, null); - assertTrue(xml != null && xml.indexOf("<shipDate>1999-12-05</shipDate>") != -1); - } - - public void testTransformation2() { - String2Node t1 = new String2Node(); - Node node = t1.transform(CRAZY_XML, null); - Node2XMLStreamReader t2 = new Node2XMLStreamReader(); - XMLStreamReader reader = t2.transform(node, null); - XMLStreamReader2String t3 = new XMLStreamReader2String(); - String xml = t3.transform(reader, null); - System.out.println(xml); - assertTrue(xml.contains("<p:e2 xmlns:p=\"http://p2\"")); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/DataPipeTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/DataPipeTestCase.java deleted file mode 100644 index d4eaf9b2a9..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/DataPipeTestCase.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.core.databinding.xml; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.Reader; -import java.io.Writer; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.core.databinding.impl.PipedTransformer; -import org.apache.tuscany.spi.databinding.extension.DOMHelper; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - * Test case for DataPipe - */ -public class DataPipeTestCase extends TestCase { - - public final void testStreamPipe() throws IOException { - byte[] bytes = new byte[] {1, 2, 3}; - StreamDataPipe pipe = new StreamDataPipe(); - Assert.assertSame(OutputStream.class, pipe.getSourceType()); - Assert.assertSame(InputStream.class, pipe.getTargetType()); - OutputStream os = pipe.getSink(); - os.write(bytes); - byte[] newBytes = new byte[16]; - int count = pipe.getResult().read(newBytes); - Assert.assertEquals(3, count); - for (int i = 0; i < bytes.length; i++) { - Assert.assertEquals(bytes[i], newBytes[i]); - } - } - - public final void testWriter2ReaderPipe() throws IOException { - String str = "ABC"; - Writer2ReaderDataPipe pipe = new Writer2ReaderDataPipe(); - Assert.assertSame(Writer.class, pipe.getSourceType()); - Assert.assertSame(Reader.class, pipe.getTargetType()); - pipe.getSink().write(str); - char[] buf = new char[16]; - int count = pipe.getResult().read(buf); - Assert.assertEquals(3, count); - for (int i = 0; i < str.length(); i++) { - Assert.assertEquals(str.charAt(i), buf[i]); - } - } - - public final void testPiped() throws Exception { - Node2Writer node2Writer = new Node2Writer(); - Writer2ReaderDataPipe pipe = new Writer2ReaderDataPipe(); - PipedTransformer<Node, Writer, Reader> transformer = - new PipedTransformer<Node, Writer, Reader>(node2Writer, pipe); - Document document = DOMHelper.newDocument(); - Element element = document.createElementNS("http://ns1", "root"); - document.appendChild(element); - Reader reader = transformer.transform(document, null); - Assert.assertEquals(transformer.getWeight(), node2Writer.getWeight() + pipe.getWeight()); - Assert.assertEquals(transformer.getSourceDataBinding(), node2Writer.getSourceDataBinding()); - Assert.assertEquals(transformer.getTargetDataBinding(), pipe.getTargetDataBinding()); - char[] buf = new char[120]; - int count = reader.read(buf); - String xml = new String(buf, 0, count); - Assert.assertTrue(xml.contains("<root xmlns=\"http://ns1\"/>")); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/JavaBean2XMLStreamReaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/JavaBean2XMLStreamReaderTestCase.java deleted file mode 100644 index 6eb2c101df..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/JavaBean2XMLStreamReaderTestCase.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.databinding.xml; - -import javax.xml.stream.XMLStreamReader; - -import junit.framework.TestCase; - -import org.apache.tuscany.core.databinding.javabeans.JavaBean2XMLStreamReader; - -public class JavaBean2XMLStreamReaderTestCase extends TestCase { - /** - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - } - - public void testTransformation() { - JavaBean2XMLStreamReader t2 = new JavaBean2XMLStreamReader(); - MyBean bean = new MyBean(); - bean.str = "ABC"; - bean.i = 1; - bean.arr = new long[] {1, 2, 3}; - bean.bean = new AnotherBean(); - bean.bean.setName("Name"); - XMLStreamReader reader = t2.transform(bean, null); - XMLStreamReader2String t3 = new XMLStreamReader2String(); - String xml = t3.transform(reader, null); - assertTrue(xml.contains("<JavaBean2XMLStreamReaderTestCase$MyBean>" - + "<arr>1</arr><arr>2</arr><arr>3</arr><bean><name>Name</name></bean>" - + "<i>1</i><str>ABC</str></JavaBean2XMLStreamReaderTestCase$MyBean>")); - } - - private static class MyBean { - private String str; - private int i; - private long arr[]; - private AnotherBean bean; - - /** - * @return the arr - */ - public long[] getArr() { - return arr; - } - - /** - * @param arr the arr to set - */ - public void setArr(long[] arr) { - this.arr = arr; - } - - /** - * @return the i - */ - public int getI() { - return i; - } - - /** - * @param i the i to set - */ - public void setI(int i) { - this.i = i; - } - - /** - * @return the str - */ - public String getStr() { - return str; - } - - /** - * @param str the str to set - */ - public void setStr(String str) { - this.str = str; - } - - /** - * @return the bean - */ - public AnotherBean getBean() { - return bean; - } - - /** - * @param bean the bean to set - */ - public void setBean(AnotherBean bean) { - this.bean = bean; - } - - } - - private static class AnotherBean { - private String name; - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param name the name to set - */ - public void setName(String name) { - this.name = name; - } - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/Node2StringTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/Node2StringTestCase.java deleted file mode 100755 index 9b9aa3b893..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/Node2StringTestCase.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.databinding.xml; - -import junit.framework.TestCase; - -import org.apache.tuscany.spi.databinding.extension.DOMHelper; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -public class Node2StringTestCase extends TestCase { - public void testTransformation() throws Exception { - Document document = DOMHelper.newDocument(); - Element element = document.createElementNS("http://ns1", "test"); - document.appendChild(element); - - new Node2String().transform(document, null); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/PushTransformationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/PushTransformationTestCase.java deleted file mode 100644 index a2318b2faa..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/PushTransformationTestCase.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.databinding.xml; - -import javax.xml.stream.XMLStreamReader; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.apache.tuscany.core.databinding.impl.PipedTransformer; -import org.w3c.dom.Node; -import org.xml.sax.ContentHandler; - -public class PushTransformationTestCase extends TestCase { - private static final String IPO_XML = - "<?xml version=\"1.0\"?>" + "<ipo:purchaseOrder" - + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" - + " xmlns:ipo=\"http://www.example.com/IPO\"" - + " xsi:schemaLocation=\"http://www.example.com/IPO ipo.xsd\"" - + " orderDate=\"1999-12-01\">" - + " <shipTo exportCode=\"1\" xsi:type=\"ipo:UKAddress\">" - + " <name>Helen Zoe</name>" - + " <street>47 Eden Street</street>" - + " <city>Cambridge</city>" - + " <postcode>CB1 1JR</postcode>" - + " </shipTo>" - + " <billTo xsi:type=\"ipo:USAddress\">" - + " <name>Robert Smith</name>" - + " <street>8 Oak Avenue</street>" - + " <city>Old Town</city>" - + " <state>PA</state>" - + " <zip>95819</zip>" - + " </billTo>" - + " <items>" - + " <item partNum=\"833-AA\">" - + " <productName>Lapis necklace</productName>" - + " <quantity>1</quantity>" - + " <USPrice>99.95</USPrice>" - + " <ipo:comment>Want this for the holidays</ipo:comment>" - + " <shipDate>1999-12-05</shipDate>" - + " </item>" - + " </items>" - + "</ipo:purchaseOrder>"; - - /** - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - } - - public void testTransformation() { - String2XMLStreamReader t1 = new String2XMLStreamReader(); - XMLStreamReader reader = t1.transform(IPO_XML, null); - XMLStreamReader2SAX t2 = new XMLStreamReader2SAX(); - PipedTransformer<XMLStreamReader, ContentHandler, Node> t3 = - new PipedTransformer<XMLStreamReader, ContentHandler, Node>(t2, new SAX2DOMPipe()); - Node node = t3.transform(reader, null); - Assert.assertNotNull(node); - Node2String t4 = new Node2String(); - String xml = t4.transform(node, null); - Assert.assertTrue(xml != null && xml.indexOf("<shipDate>1999-12-05</shipDate>") != -1); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/StAXHelperTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/StAXHelperTestCase.java deleted file mode 100644 index 7d18e83ac6..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/StAXHelperTestCase.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.core.databinding.xml; - -import javax.xml.stream.XMLStreamReader; - -import junit.framework.TestCase; - -/** - * Test Case for StAXHelper - */ -public class StAXHelperTestCase extends TestCase { - private static final String XML = - "<a:foo xmlns:a='http://a' name='foo'><bar name='bar'>" + "<doo a:name='doo' xmlns:a='http://doo'/>" - + "</bar></a:foo>"; - - /** - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - } - - public void testHelper() throws Exception { - XMLStreamReader reader = StAXHelper.createXMLStreamReader(XML); - String xml = StAXHelper.save(reader); - reader = StAXHelper.createXMLStreamReader(xml); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/TraxTransformerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/TraxTransformerTestCase.java deleted file mode 100644 index 7e9494d423..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/databinding/xml/TraxTransformerTestCase.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.core.databinding.xml; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.StringReader; -import java.io.StringWriter; -import java.io.Writer; -import java.net.URL; - -import junit.framework.TestCase; - -import org.w3c.dom.Node; -import org.xml.sax.Attributes; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -/** - * - */ -public class TraxTransformerTestCase extends TestCase { - private URL url; - - /** - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - url = getClass().getResource("foo.xml"); - } - - public void testTransformDOM() throws IOException { - InputStream is = url.openStream(); - InputStream2Node t1 = new InputStream2Node(); - Node node = t1.transform(is, null); - is.close(); - Writer writer = new StringWriter(); - Node2Writer t2 = new Node2Writer(); - t2.transform(node, writer, null); - String str = writer.toString(); - StringReader reader = new StringReader(str); - Reader2Node t3 = new Reader2Node(); - node = t3.transform(reader, null); - ByteArrayOutputStream os = new ByteArrayOutputStream(); - Node2OutputStream t4 = new Node2OutputStream(); - t4.transform(node, os, null); - InputSource inputSource = new InputSource(new ByteArrayInputStream(os.toByteArray())); - InputSource2Node t5 = new InputSource2Node(); - node = t5.transform(inputSource, null); - } - - public void testTransformSAX() throws IOException { - MyContentHandler handler = new MyContentHandler(); - InputStream is = url.openStream(); - InputStream2SAX t1 = new InputStream2SAX(); - t1.transform(is, handler, null); - is.close(); - - String xml = "<foo xmlns=\"http://foo\">bar</foo>"; - - InputSource inputSource = new InputSource(new StringReader(xml)); - InputSource2SAX t2 = new InputSource2SAX(); - MyContentHandler handler2 = new MyContentHandler(); - t2.transform(inputSource, handler2, null); - - } - - private static class MyContentHandler extends DefaultHandler { - - @Override - public void startElement(String namespaceURI, String localName, String qName, Attributes atts) - throws SAXException { - super.startElement(namespaceURI, localName, qName, atts); - } - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/deployer/BootstrapDeployerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/deployer/BootstrapDeployerTestCase.java deleted file mode 100644 index 20ae7eecb8..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/deployer/BootstrapDeployerTestCase.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.deployer; - -import java.net.URL; -import java.util.Collection; -import java.util.Map; -import javax.xml.stream.XMLInputFactory; - -import org.apache.tuscany.spi.bootstrap.ComponentNames; -import org.apache.tuscany.spi.component.Component; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.SCAObject; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.loader.LoaderException; -import org.apache.tuscany.spi.model.BindingDefinition; -import org.apache.tuscany.spi.model.ComponentDefinition; -import org.apache.tuscany.spi.model.ComponentType; -import org.apache.tuscany.spi.model.CompositeComponentType; -import org.apache.tuscany.spi.model.CompositeReferenceDefinition; -import org.apache.tuscany.spi.model.Implementation; -import org.apache.tuscany.spi.model.Include; -import org.apache.tuscany.spi.model.Property; -import org.apache.tuscany.spi.model.PropertyValue; -import org.apache.tuscany.spi.model.AbstractReferenceDefinition; -import org.apache.tuscany.spi.model.ServiceDefinition; - -import junit.framework.TestCase; -import org.apache.tuscany.core.bootstrap.Bootstrapper; -import org.apache.tuscany.core.bootstrap.DefaultBootstrapper; -import org.apache.tuscany.core.implementation.system.model.SystemCompositeImplementation; -import org.apache.tuscany.core.mock.component.BasicInterface; -import org.apache.tuscany.core.monitor.NullMonitorFactory; -import static org.easymock.EasyMock.createNiceMock; -import static org.easymock.EasyMock.isA; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; - -/** - * Verifies the default boostrap deployer - * - * @version $Rev$ $Date$ - */ -public class BootstrapDeployerTestCase extends TestCase { - private DeployerImpl deployer; - private DeploymentContext deploymentContext; - private ComponentDefinition<SystemCompositeImplementation> componentDefinition; - private SystemCompositeImplementation implementation; - - @SuppressWarnings("unchecked") - public void testBoot1Load() throws LoaderException { - CompositeComponent parent = createNiceMock(CompositeComponent.class); - URL scdl = BootstrapDeployerTestCase.class.getResource("boot1.scdl"); - implementation.setScdlLocation(scdl); - deployer.load(parent, componentDefinition, deploymentContext); - CompositeComponentType<ServiceDefinition, CompositeReferenceDefinition, Property<?>> composite = - implementation.getComponentType(); - assertNotNull(composite); - assertEquals("boot1", composite.getName()); - - // check parse of <service> - Map<String, ServiceDefinition> services = composite.getDeclaredServices(); - assertEquals(1, services.size()); // included doesn't count - services = composite.getServices(); - assertEquals(2, services.size()); // included counts - ServiceDefinition serviceDefinition = services.get("service"); - assertNotNull(serviceDefinition); - assertEquals("service", serviceDefinition.getName()); - assertEquals(BasicInterface.class, serviceDefinition.getServiceContract().getInterfaceClass()); - Collection<BindingDefinition> bindings = serviceDefinition.getBindings(); - assertTrue(bindings.isEmpty()); - - // check parse of <component> - Map<String, ComponentDefinition<? extends Implementation<?>>> components = composite.getDeclaredComponents(); - assertEquals(1, components.size()); // included doesn't count - components = composite.getComponents(); - assertEquals(2, components.size()); // included counts - ComponentDefinition<? extends Implementation<?>> component = components.get("component"); - assertNotNull(component); - PropertyValue<?> propVal = component.getPropertyValues().get("publicProperty"); - assertEquals("propval", propVal.getValueFactory().getInstance()); - - // check introspection of implementation - ComponentType<?, ?, ?> componentType = component.getImplementation().getComponentType(); - assertNotNull(componentType); // details checked in SystemComponentTypeLoaderTestCase - - // check included component - Map<String, Include> includes = composite.getIncludes(); - assertEquals(1, includes.size()); - Include include = includes.get("boot1-include"); - assertNotNull(include); - CompositeComponentType included = include.getIncluded(); - assertNotNull(included); - assertEquals(1, included.getComponents().size()); - } - - public void testBoot1Deployment() throws Exception { - URL scdl = BootstrapDeployerTestCase.class.getResource("boot1.scdl"); - implementation.setScdlLocation(scdl); - CompositeComponent parent = createNiceMock(CompositeComponent.class); - parent.register(isA(SCAObject.class)); - replay(parent); - // load the boot1 file using the bootstrap deployer - componentDefinition.setName("simple"); - Component component = deployer.deploy(parent, componentDefinition); - assertNotNull(component); - verify(parent); - } - - public void testBoot2Deployment() throws Exception { - URL scdl = BootstrapDeployerTestCase.class.getResource("boot2.scdl"); - implementation.setScdlLocation(scdl); - CompositeComponent parent = createNiceMock(CompositeComponent.class); - parent.register(isA(SCAObject.class)); - replay(parent); - - // load the boot2 file using the bootstrap deployer - componentDefinition.setName("newDeployer"); - CompositeComponent component = (CompositeComponent) deployer.deploy(parent, componentDefinition); - assertNotNull(component); - verify(parent); - component.start(); - SCAObject newDeployer = component.getSystemChild(ComponentNames.TUSCANY_DEPLOYER); - assertNotNull(newDeployer); - SCAObject wireService = component.getSystemChild(ComponentNames.TUSCANY_WIRE_SERVICE); - assertNotNull(wireService); - -/* // FIXME - // load the boot2 file using the newly loaded deployer - parent.reset(); - parent.expects(once()).method("register").withAnyArguments(); - componentDefinition.setName("newDeployer2"); - component = newDeployer.deploy((CompositeComponent) parent.proxy(), componentDefinition); - assertNotNull(component); - parent.verify(); - component.start(); - Deployer newDeployer2 = (Deployer) component.getServiceInstance("deployer"); - assertNotNull(newDeployer2); -*/ - } - - protected void setUp() throws Exception { - super.setUp(); - XMLInputFactory xmlFactory = XMLInputFactory.newInstance(); - Bootstrapper bootstrapper = new DefaultBootstrapper(new NullMonitorFactory(), xmlFactory, null); - deployer = (DeployerImpl) bootstrapper.createDeployer(); - deploymentContext = new RootDeploymentContext(null, xmlFactory, null, null); - implementation = new SystemCompositeImplementation(); - implementation.setClassLoader(getClass().getClassLoader()); - componentDefinition = new ComponentDefinition<SystemCompositeImplementation>(implementation); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/idl/java/ConversationalIntrospectionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/idl/java/ConversationalIntrospectionTestCase.java deleted file mode 100644 index 5b0fe34705..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/idl/java/ConversationalIntrospectionTestCase.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.idl.java; - -import org.osoa.sca.annotations.EndsConversation; -import org.osoa.sca.annotations.Scope; - -import org.apache.tuscany.spi.idl.InvalidConversationalOperationException; -import org.apache.tuscany.spi.idl.java.JavaServiceContract; -import static org.apache.tuscany.spi.model.InteractionScope.CONVERSATIONAL; -import static org.apache.tuscany.spi.model.InteractionScope.NONCONVERSATIONAL; -import org.apache.tuscany.spi.model.Operation; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class ConversationalIntrospectionTestCase extends TestCase { - private JavaInterfaceProcessorRegistryImpl registry = new JavaInterfaceProcessorRegistryImpl(); - - public void testServiceContractConversationalInformationIntrospection() throws Exception { - JavaServiceContract contract = registry.introspect(Foo.class); - assertEquals(CONVERSATIONAL, contract.getInteractionScope()); - int seq = contract.getOperations().get("operation").getConversationSequence(); - assertEquals(Operation.CONVERSATION_CONTINUE, seq); - seq = contract.getOperations().get("endOperation").getConversationSequence(); - assertEquals(Operation.CONVERSATION_END, seq); - } - - public void testBadServiceContract() throws Exception { - try { - registry.introspect(BadFoo.class); - fail(); - } catch (InvalidConversationalOperationException e) { - //expected - } - } - - public void testNonConversationalInformationIntrospection() throws Exception { - JavaServiceContract contract = registry.introspect(NonConversationalFoo.class); - assertEquals(NONCONVERSATIONAL, contract.getInteractionScope()); - int seq = contract.getOperations().get("operation").getConversationSequence(); - assertEquals(Operation.NO_CONVERSATION, seq); - } - - @Scope("CONVERSATION") - private interface Foo { - void operation(); - - @EndsConversation - void endOperation(); - } - - private interface BadFoo { - void operation(); - - @EndsConversation - void endOperation(); - } - - private interface NonConversationalFoo { - void operation(); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/idl/java/JavaInterfaceProcessorRegistryImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/idl/java/JavaInterfaceProcessorRegistryImplTestCase.java deleted file mode 100644 index e3a7deb10a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/idl/java/JavaInterfaceProcessorRegistryImplTestCase.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.idl.java; - -import java.lang.reflect.Type; -import java.util.List; -import java.util.Map; - -import org.apache.tuscany.spi.idl.InvalidServiceContractException; -import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessor; -import org.apache.tuscany.spi.idl.java.JavaServiceContract; -import org.apache.tuscany.spi.model.DataType; -import org.apache.tuscany.spi.model.Operation; - -import junit.framework.TestCase; -import org.apache.tuscany.core.util.JavaIntrospectionHelper; -import org.easymock.EasyMock; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.eq; -import static org.easymock.EasyMock.expectLastCall; -import static org.easymock.EasyMock.isA; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; - -/** - * @version $Rev$ $Date$ - */ -public class JavaInterfaceProcessorRegistryImplTestCase extends TestCase { - private JavaInterfaceProcessorRegistryImpl impl; - - public void testSimpleInterface() throws InvalidServiceContractException { - JavaServiceContract contract = impl.introspect(Simple.class); - // TODO spec to clairfy interface name - assertEquals(JavaIntrospectionHelper.getBaseName(Simple.class), contract.getInterfaceName()); - assertEquals(Simple.class, contract.getInterfaceClass()); - Map<String, Operation<Type>> operations = contract.getOperations(); - assertEquals(1, operations.size()); - Operation<Type> baseInt = operations.get("baseInt"); - assertNotNull(baseInt); - - DataType<Type> returnType = baseInt.getOutputType(); - assertEquals(Integer.TYPE, returnType.getPhysical()); - assertEquals(Integer.TYPE, returnType.getLogical()); - - List<DataType<Type>> parameterTypes = baseInt.getInputType().getLogical(); - assertEquals(1, parameterTypes.size()); - DataType<Type> arg0 = parameterTypes.get(0); - assertEquals(Integer.TYPE, arg0.getPhysical()); - assertEquals(Integer.TYPE, arg0.getLogical()); - - List<DataType<Type>> faultTypes = baseInt.getFaultTypes(); - assertEquals(1, faultTypes.size()); - DataType<Type> fault0 = faultTypes.get(0); - assertEquals(IllegalArgumentException.class, fault0.getPhysical()); - assertEquals(IllegalArgumentException.class, fault0.getLogical()); - } - - public void testUnregister() throws Exception { - JavaInterfaceProcessor processor = createMock(JavaInterfaceProcessor.class); - processor.visitInterface(eq(Base.class), EasyMock.same((Class)null), isA(JavaServiceContract.class)); - expectLastCall().once(); - replay(processor); - impl.registerProcessor(processor); - impl.introspect(Base.class); - impl.unregisterProcessor(processor); - impl.introspect(Base.class); - verify(processor); - } - - protected void setUp() throws Exception { - super.setUp(); - impl = new JavaInterfaceProcessorRegistryImpl(); - - } - - private static interface Base { - int baseInt(int param) throws IllegalArgumentException; - } - - private static interface Simple extends Base { - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/IntrospectionRegistryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/IntrospectionRegistryTestCase.java deleted file mode 100644 index fb5e7fbb1f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/IntrospectionRegistryTestCase.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation; - -import java.lang.reflect.Method; -import java.lang.reflect.Field; -import java.lang.reflect.Constructor; - -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.implementation.java.ImplementationProcessor; -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; - -import junit.framework.TestCase; -import org.apache.tuscany.core.implementation.IntrospectionRegistryImpl.Monitor; -import org.apache.tuscany.core.monitor.NullMonitorFactory; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class IntrospectionRegistryTestCase extends TestCase { - - private Monitor monitor; - - public void testRegister() throws Exception { - IntrospectionRegistryImpl registry = new IntrospectionRegistryImpl(monitor); - ImplementationProcessor processor = EasyMock.createNiceMock(ImplementationProcessor.class); - registry.registerProcessor(processor); - } - - public void testUnegister() throws Exception { - IntrospectionRegistryImpl registry = new IntrospectionRegistryImpl(monitor); - ImplementationProcessor processor = EasyMock.createNiceMock(ImplementationProcessor.class); - registry.registerProcessor(processor); - registry.unregisterProcessor(processor); - } - - @SuppressWarnings("unchecked") - public void testWalk() throws Exception { - IntrospectionRegistryImpl registry = new IntrospectionRegistryImpl(monitor); - ImplementationProcessor processor = EasyMock.createMock(ImplementationProcessor.class); - processor.visitClass(EasyMock.isA(CompositeComponent.class), - EasyMock.eq(Bar.class), - EasyMock.isA(PojoComponentType.class), - EasyMock.isA(DeploymentContext.class)); - processor.visitConstructor(EasyMock.isA(CompositeComponent.class), - EasyMock.isA(Constructor.class), - EasyMock.isA(PojoComponentType.class), - EasyMock.isA(DeploymentContext.class)); - processor.visitMethod(EasyMock.isA(CompositeComponent.class), - EasyMock.isA(Method.class), - EasyMock.isA(PojoComponentType.class), - EasyMock.isA(DeploymentContext.class)); - processor.visitField(EasyMock.isA(CompositeComponent.class), - EasyMock.isA(Field.class), - EasyMock.isA(PojoComponentType.class), - EasyMock.isA(DeploymentContext.class)); - processor.visitSuperClass(EasyMock.isA(CompositeComponent.class), - EasyMock.isA(Class.class), - EasyMock.isA(PojoComponentType.class), - EasyMock.isA(DeploymentContext.class)); - processor.visitEnd(EasyMock.isA(CompositeComponent.class), - EasyMock.isA(Class.class), - EasyMock.isA(PojoComponentType.class), - EasyMock.isA(DeploymentContext.class)); - - // mock.expects(once()).method("visitClass"); -// mock.expects(once()).method("visitMethod"); -// mock.expects(once()).method("visitField"); -// mock.expects(once()).method("visitConstructor"); -// mock.expects(once()).method("visitSuperClass"); -// mock.expects(once()).method("visitEnd"); - EasyMock.replay(processor); - registry.registerProcessor(processor); - registry.introspect(EasyMock.createNiceMock(CompositeComponent.class), - Bar.class, - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(), - EasyMock.createNiceMock(DeploymentContext.class)); - EasyMock.verify(processor); - } - - - protected void setUp() throws Exception { - super.setUp(); - monitor = new NullMonitorFactory().getMonitor(Monitor.class); - } - - private class Baz { - - } - - private class Bar extends Baz { - - protected String bar; - - public Bar() { - } - - public void bar() { - } - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/PojoAtomicComponentTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/PojoAtomicComponentTestCase.java deleted file mode 100644 index 6fcef3622e..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/PojoAtomicComponentTestCase.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation; - -import org.apache.tuscany.spi.ObjectFactory; -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.TargetInvokerCreationException; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.TargetInvoker; - -import junit.framework.TestCase; -import org.apache.tuscany.core.injection.EventInvoker; -import org.apache.tuscany.core.injection.PojoObjectFactory; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class PojoAtomicComponentTestCase extends TestCase { - private PojoObjectFactory<Foo> factory; - - @SuppressWarnings({"unchecked"}) - public void testDestroy() throws Exception { - PojoConfiguration config = new PojoConfiguration(); - config.setInstanceFactory(factory); - EventInvoker<Object> invoker = EasyMock.createMock(EventInvoker.class); - invoker.invokeEvent(EasyMock.notNull()); - EasyMock.replay(invoker); - config.setDestroyInvoker(invoker); - AtomicComponent component = new TestAtomicComponent(config); - assertTrue(component.isDestroyable()); - component.destroy(new Object()); - EasyMock.verify(invoker); - } - - @SuppressWarnings({"unchecked"}) - public void testInit() throws Exception { - PojoConfiguration config = new PojoConfiguration(); - config.setInstanceFactory(factory); - EventInvoker<Object> invoker = EasyMock.createMock(EventInvoker.class); - invoker.invokeEvent(EasyMock.notNull()); - EasyMock.replay(invoker); - config.setInitInvoker(invoker); - AtomicComponent component = new TestAtomicComponent(config); - component.init(new Object()); - EasyMock.verify(invoker); - } - - public void testOptimizable() throws Exception { - PojoConfiguration config = new PojoConfiguration(); - config.setInstanceFactory(factory); - TestAtomicComponent component = new TestAtomicComponent(config); - assertTrue(component.isOptimizable()); - } - - @SuppressWarnings({"unchecked"}) - public void testDestroyableButOptimizable() throws Exception { - PojoConfiguration config = new PojoConfiguration(); - config.setInstanceFactory(factory); - EventInvoker<Object> invoker = EasyMock.createMock(EventInvoker.class); - invoker.invokeEvent(EasyMock.notNull()); - EasyMock.replay(invoker); - config.setDestroyInvoker(invoker); - TestAtomicComponent component = new TestAtomicComponent(config); - assertTrue(component.isOptimizable()); - } - - @SuppressWarnings({"unchecked"}) - public void testStatelessOptimizable() throws Exception { - PojoConfiguration config = new PojoConfiguration(); - config.setInstanceFactory(factory); - TestStatelessAtomicComponent component = new TestStatelessAtomicComponent(config); - assertTrue(component.isOptimizable()); - } - - @SuppressWarnings({"unchecked"}) - public void testNotOptimizable() throws Exception { - PojoConfiguration config = new PojoConfiguration(); - config.setInstanceFactory(factory); - EventInvoker<Object> invoker = EasyMock.createMock(EventInvoker.class); - invoker.invokeEvent(EasyMock.notNull()); - EasyMock.replay(invoker); - config.setDestroyInvoker(invoker); - TestStatelessAtomicComponent component = new TestStatelessAtomicComponent(config); - assertFalse(component.isOptimizable()); - } - - protected void setUp() throws Exception { - super.setUp(); - factory = new PojoObjectFactory<Foo>(Foo.class.getConstructor()); - } - - private class TestAtomicComponent extends PojoAtomicComponent { - - public TestAtomicComponent(PojoConfiguration configuration) { - super(configuration); - } - - public Scope getScope() { - return Scope.COMPOSITE; - } - - protected ObjectFactory<?> createWireFactory(Class<?> interfaze, OutboundWire wire) { - return null; - } - - public TargetInvoker createTargetInvoker(String targetName, Operation operation, InboundWire callbackWire) - throws TargetInvokerCreationException { - return null; - } - } - - private class TestStatelessAtomicComponent extends PojoAtomicComponent { - - public TestStatelessAtomicComponent(PojoConfiguration configuration) { - super(configuration); - } - - public Scope getScope() { - return Scope.STATELESS; - } - - protected ObjectFactory<?> createWireFactory(Class<?> interfaze, OutboundWire wire) { - return null; - } - - public TargetInvoker createTargetInvoker(String targetName, Operation operation, InboundWire callbackWire) - throws TargetInvokerCreationException { - return null; - } - } - - private static class Foo { - public Foo() { - } - } - -} - - diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/TestUtils.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/TestUtils.java deleted file mode 100644 index e18fc99861..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/TestUtils.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.idl.InvalidServiceContractException; -import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry; -import org.apache.tuscany.spi.idl.java.JavaServiceContract; -import org.apache.tuscany.spi.wire.InboundWire; - -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -import org.apache.tuscany.core.wire.InboundWireImpl; - -/** - * @version $Rev$ $Date$ - */ -public final class TestUtils { - private static final JavaInterfaceProcessorRegistry REGISTRY = new JavaInterfaceProcessorRegistryImpl(); - - private TestUtils() { - } - - public static List<InboundWire> populateInboundWires(AtomicComponent component, List<InboundWire> wires) - throws InvalidServiceContractException { - for (InboundWire wire : wires) { - wire.setContainer(component); - } - return wires; - } - - public static List<InboundWire> createInboundWires(List<Class<?>> interfazes) - throws InvalidServiceContractException { - List<InboundWire> wires = new ArrayList<InboundWire>(interfazes.size()); - for (Class<?> interfaze : interfazes) { - InboundWire wire = createInboundWire(interfaze); - wires.add(wire); - } - return wires; - } - - public static InboundWire createInboundWire(Class<?> interfaze) throws InvalidServiceContractException { - InboundWire wire = new InboundWireImpl(); - JavaServiceContract contract = REGISTRY.introspect(interfaze); - wire.setServiceContract(contract); - return wire; - } - - public static InboundWire createInboundWire(Class<?> interfaze, CompositeComponent parent) - throws InvalidServiceContractException { - InboundWire wire = createInboundWire(interfaze); - wire.setContainer(parent); - return wire; - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/AutowireResolutionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/AutowireResolutionTestCase.java deleted file mode 100644 index c644c3d7c4..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/AutowireResolutionTestCase.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.composite; - -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.wire.InboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.implementation.TestUtils; -import org.easymock.EasyMock; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.eq; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; - -/** - * Verfies specific autowire resolution scenarios - * - * @version $Rev$ $Date$ - */ -public class AutowireResolutionTestCase extends TestCase { - - public void testConstruction() { - CompositeComponent parent = createMock(CompositeComponent.class); - replay(parent); - CompositeComponent component = new CompositeComponentImpl("test", parent, null, null); - assertEquals("test", component.getName()); - assertSame(parent, component.getParent()); - verify(parent); - } - - public void testResolvedByAutowire() throws Exception { - CompositeComponent parent = createMock(CompositeComponent.class); - InboundWire wire = TestUtils.createInboundWire(Foo.class, parent); - EasyMock.expect(parent.resolveAutowire(eq(Foo.class))).andReturn(wire); - EasyMock.expect(parent.resolveSystemAutowire(eq(Foo.class))).andReturn(null); - replay(parent); - CompositeComponent component = new CompositeComponentImpl("test", parent, null, null); - assertSame(wire, component.resolveAutowire(Foo.class)); - verify(parent); - } - - public void testSystemResolvedByAutowire() throws Exception { - CompositeComponent parent = createMock(CompositeComponent.class); - InboundWire wire = TestUtils.createInboundWire(Foo.class, parent); - EasyMock.expect(parent.resolveSystemAutowire(eq(Foo.class))).andReturn(wire); - replay(parent); - CompositeComponent component = new CompositeComponentImpl("test", parent, null, null); - assertSame(wire, component.resolveSystemAutowire(Foo.class)); - verify(parent); - } - - /** - * Verify parent resolution strategy for application serviceBindings - */ - public void testNamespaceIsolationAutowire() throws Exception { - Foo foo = new Foo() { - }; - CompositeComponent parent = new CompositeComponentImpl("parent", null, null, null); - parent.registerJavaObject("foo", Foo.class, foo); - CompositeComponent component = new CompositeComponentImpl("test", parent, null, null); - assertNotNull(component.resolveAutowire(Foo.class)); - } - - protected void setUp() throws Exception { - super.setUp(); - } - - public static interface Foo { - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/AutowireTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/AutowireTestCase.java deleted file mode 100644 index 341efcd09c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/AutowireTestCase.java +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.composite; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.Reference; -import org.apache.tuscany.spi.component.ReferenceBinding; -import org.apache.tuscany.spi.component.Service; -import org.apache.tuscany.spi.component.ServiceBinding; -import org.apache.tuscany.spi.wire.InboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.implementation.TestUtils; -import org.easymock.EasyMock; - -/** - * Performs basic autowiring tests to composite artifacts - * - * @version $$Rev$$ $$Date$$ - */ -public class AutowireTestCase extends TestCase { - - /** - * Tests autowiring to an system atomic component - */ - public void testSystemAtomicAutowire() throws Exception { - CompositeComponent parent = new CompositeComponentImpl("parent", null, null, true); - parent.start(); - List<Class<?>> interfaces = new ArrayList<Class<?>>(); - interfaces.add(Source.class); - interfaces.add(Source2.class); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(true).atLeastOnce(); - List<InboundWire> wires = TestUtils.createInboundWires(interfaces); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - TestUtils.populateInboundWires(component, wires); - EasyMock.replay(component); - parent.register(component); - InboundWire source = parent.resolveSystemAutowire(Source.class); - assertNotNull(source); - InboundWire sourceBase = parent.resolveSystemAutowire(SourceBase.class); - assertSame(source, sourceBase); - InboundWire source2 = parent.resolveSystemAutowire(Source2.class); - assertSame(source.getContainer(), source2.getContainer()); - assertNull(parent.resolveSystemExternalAutowire(Source.class)); - EasyMock.verify(component); - } - - /** - * Tests autowiring to an system atomic component - */ - public void testAtomicAutowire() throws Exception { - CompositeComponent parent = new CompositeComponentImpl("parent", null, null, null); - parent.start(); - - List<Class<?>> interfaces = new ArrayList<Class<?>>(); - interfaces.add(Source.class); - interfaces.add(Source2.class); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(false).atLeastOnce(); - List<InboundWire> wires = TestUtils.createInboundWires(interfaces); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - TestUtils.populateInboundWires(component, wires); - - EasyMock.replay(component); - parent.register(component); - - InboundWire source = parent.resolveAutowire(Source.class); - assertNotNull(source); - InboundWire sourceBase = parent.resolveAutowire(SourceBase.class); - assertSame(source, sourceBase); - InboundWire source2 = parent.resolveAutowire(Source2.class); - assertSame(source.getContainer(), source2.getContainer()); - assertNull(parent.resolveExternalAutowire(Source.class)); - EasyMock.verify(component); - } - - /** - * Tests autowiring to a system service - */ - public void testSystemServiceAutowire() throws Exception { - CompositeComponent parent = new CompositeComponentImpl("parent", null, null, true); - parent.start(); - - ServiceBinding serviceBinding = EasyMock.createMock(ServiceBinding.class); - InboundWire wire = TestUtils.createInboundWire(Source.class); - wire.setContainer(serviceBinding); - EasyMock.expect(serviceBinding.getInboundWire()).andReturn(wire).atLeastOnce(); - EasyMock.replay(serviceBinding); - - List<ServiceBinding> bindings = new ArrayList<ServiceBinding>(); - bindings.add(serviceBinding); - Service service = EasyMock.createMock(Service.class); - EasyMock.expect(service.getName()).andReturn("service").atLeastOnce(); - EasyMock.expect(service.isSystem()).andReturn(true).atLeastOnce(); - - EasyMock.expect(service.getServiceBindings()).andReturn(bindings).atLeastOnce(); - EasyMock.replay(service); - parent.register(service); - - InboundWire source = parent.resolveSystemExternalAutowire(Source.class); - assertSame(serviceBinding, source.getContainer()); - InboundWire sourceBase = parent.resolveSystemExternalAutowire(SourceBase.class); - assertSame(source, sourceBase); - InboundWire source2 = parent.resolveSystemExternalAutowire(Source2.class); - assertNull(source2); - EasyMock.verify(serviceBinding); - } - - /** - * Tests autowiring to a service - */ - public void testServiceAutowire() throws Exception { - CompositeComponent parent = new CompositeComponentImpl("parent", null, null, true); - parent.start(); - - ServiceBinding serviceBinding = EasyMock.createMock(ServiceBinding.class); - InboundWire wire = TestUtils.createInboundWire(Source.class); - wire.setContainer(serviceBinding); - EasyMock.expect(serviceBinding.getInboundWire()).andReturn(wire).atLeastOnce(); - EasyMock.replay(serviceBinding); - - List<ServiceBinding> bindings = new ArrayList<ServiceBinding>(); - bindings.add(serviceBinding); - Service service = EasyMock.createMock(Service.class); - EasyMock.expect(service.getName()).andReturn("service").atLeastOnce(); - EasyMock.expect(service.isSystem()).andReturn(false).atLeastOnce(); - - EasyMock.expect(service.getServiceBindings()).andReturn(bindings).atLeastOnce(); - EasyMock.replay(service); - parent.register(service); - - InboundWire source = parent.resolveExternalAutowire(Source.class); - assertSame(serviceBinding, source.getContainer()); - InboundWire sourceBase = parent.resolveExternalAutowire(SourceBase.class); - assertSame(source, sourceBase); - InboundWire source2 = parent.resolveExternalAutowire(Source2.class); - assertNull(source2); - EasyMock.verify(serviceBinding); - } - - - /** - * Tests autowiring to a system reference - */ - public void testSystemReferenceAutowire() throws Exception { - CompositeComponent parent = new CompositeComponentImpl("parent", null, null, true); - parent.start(); - - ReferenceBinding binding = EasyMock.createMock(ReferenceBinding.class); - binding.setReference(EasyMock.isA(Reference.class)); - InboundWire wire = TestUtils.createInboundWire(Source.class); - wire.setContainer(binding); - EasyMock.expect(binding.getInboundWire()).andReturn(wire).atLeastOnce(); - EasyMock.replay(binding); - - Reference reference = new ReferenceImpl("foo", null, wire.getServiceContract(), true); - reference.addReferenceBinding(binding); - parent.register(reference); - - InboundWire source = parent.resolveSystemAutowire(Source.class); - assertNotNull(source); - InboundWire sourceBase = parent.resolveSystemAutowire(SourceBase.class); - assertSame(source, sourceBase); - EasyMock.verify(binding); - } - - /** - * Tests autowiring to a reference - */ - public void testReferenceAutowire() throws Exception { - CompositeComponent parent = new CompositeComponentImpl("parent", null, null, true); - parent.start(); - - ReferenceBinding binding = EasyMock.createMock(ReferenceBinding.class); - binding.setReference(EasyMock.isA(Reference.class)); - InboundWire wire = TestUtils.createInboundWire(Source.class); - wire.setContainer(binding); - EasyMock.expect(binding.getInboundWire()).andReturn(wire).atLeastOnce(); - EasyMock.replay(binding); - - Reference reference = new ReferenceImpl("foo", null, wire.getServiceContract(), false); - reference.addReferenceBinding(binding); - parent.register(reference); - - InboundWire source = parent.resolveAutowire(Source.class); - assertNotNull(source); - InboundWire sourceBase = parent.resolveAutowire(SourceBase.class); - assertSame(source, sourceBase); - EasyMock.verify(binding); - } - - - public static class SourceImpl implements Source, Source2 { - public SourceImpl() { - } - } - - public static interface SourceBase { - } - - public static interface Source extends SourceBase { - } - - public static interface Source2 { - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeBuilderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeBuilderTestCase.java deleted file mode 100644 index 2c47eab4ba..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeBuilderTestCase.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.composite; - -import java.net.URI; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.ScopeContainerMonitor; -import org.apache.tuscany.spi.component.Service; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry; -import org.apache.tuscany.spi.idl.java.JavaServiceContract; -import org.apache.tuscany.spi.implementation.java.ConstructorDefinition; -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.model.ComponentDefinition; -import org.apache.tuscany.spi.model.ComponentReferenceDefinition; -import org.apache.tuscany.spi.model.ComponentTypeReferenceDefinition; -import org.apache.tuscany.spi.model.CompositeComponentType; -import org.apache.tuscany.spi.model.CompositeImplementation; -import org.apache.tuscany.spi.model.AbstractReferenceDefinition; -import org.apache.tuscany.spi.model.CompositeReferenceDefinition; -import org.apache.tuscany.spi.model.ReferenceTarget; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.model.ServiceDefinition; -import org.apache.tuscany.spi.wire.WireService; - -import junit.framework.TestCase; -import org.apache.tuscany.core.binding.local.LocalBindingBuilder; -import org.apache.tuscany.core.binding.local.LocalBindingDefinition; -import org.apache.tuscany.core.builder.BuilderRegistryImpl; -import org.apache.tuscany.core.component.scope.CompositeScopeContainer; -import org.apache.tuscany.core.deployer.RootDeploymentContext; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -import org.apache.tuscany.core.implementation.java.JavaComponentBuilder; -import org.apache.tuscany.core.implementation.java.JavaImplementation; -import org.apache.tuscany.core.mock.component.OtherTarget; -import org.apache.tuscany.core.mock.component.Source; -import org.apache.tuscany.core.mock.component.SourceImpl; -import org.apache.tuscany.core.mock.component.Target; -import org.apache.tuscany.core.mock.component.TargetImpl; -import org.apache.tuscany.core.wire.jdk.JDKWireService; -import org.easymock.EasyMock; - -/** - * @version $$Rev$$ $$Date$$ - */ -public class CompositeBuilderTestCase extends TestCase { - private DeploymentContext deploymentContext; - - @SuppressWarnings("unchecked") - public void testBuild() throws Exception { - CompositeComponent parent = new CompositeComponentImpl(null, null, null, null); - - CompositeBuilder builder = new CompositeBuilder(); - WireService wireService = new JDKWireService(); - builder.setWireService(wireService); - BuilderRegistryImpl builderRegistry = new BuilderRegistryImpl(null, wireService); - JavaComponentBuilder jBuilder = new JavaComponentBuilder(); - jBuilder.setWireService(wireService); - builderRegistry.register(JavaImplementation.class, jBuilder); - builderRegistry.register(CompositeImplementation.class, builder); - builderRegistry.register(LocalBindingDefinition.class, new LocalBindingBuilder()); - builder.setBuilderRegistry(builderRegistry); - CompositeComponent component = - (CompositeComponent) builder.build(parent, createTopComponentDef(), deploymentContext); - - component.start(); - CompositeComponent sourceComponent = (CompositeComponent) component.getChild("SourceComponent"); - assertTrue(sourceComponent.getChild("InnerSourceService") instanceof Service); - AtomicComponent innerSourceComponent = (AtomicComponent) sourceComponent.getChild("InnerSourceComponent"); - Source innerSourceInstance = (Source) deploymentContext.getCompositeScope().getInstance(innerSourceComponent); - assertNotNull(innerSourceInstance); - component.stop(); - } - - private ComponentDefinition createTopComponentDef() throws Exception { - - CompositeComponentType<JavaMappedService, CompositeReferenceDefinition, JavaMappedProperty<?>> outerType = - new CompositeComponentType<JavaMappedService, CompositeReferenceDefinition, JavaMappedProperty<?>>(); - outerType.add(createSourceComponentDef()); - outerType.add(createTargetComponentDef()); - - CompositeImplementation outerImpl = new CompositeImplementation(); - outerImpl.setComponentType(outerType); - - return new ComponentDefinition<CompositeImplementation>(outerImpl); - } - - private ComponentDefinition<CompositeImplementation> createSourceComponentDef() throws Exception { - - CompositeComponentType<ServiceDefinition, CompositeReferenceDefinition, JavaMappedProperty<?>> innerType = - new CompositeComponentType<ServiceDefinition, CompositeReferenceDefinition, JavaMappedProperty<?>>(); - innerType.add(createInnerSourceComponentDef()); - CompositeReferenceDefinition reference = new CompositeReferenceDefinition(); - reference.setName("TargetComponentRef"); - JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - JavaServiceContract targetContract = registry.introspect(Target.class); - reference.setServiceContract(targetContract); - innerType.add(reference); - ServiceDefinition service = new ServiceDefinition(); - service.setName("InnerSourceService"); - JavaServiceContract sourceContract = registry.introspect(Source.class); - service.setServiceContract(sourceContract); - service.setTarget(new URI("InnerSourceComponent")); - innerType.add(service); - - CompositeImplementation innerImpl = new CompositeImplementation(); - innerImpl.setComponentType(innerType); - - ComponentDefinition<CompositeImplementation> sourceComponentDefinition = - new ComponentDefinition<CompositeImplementation>("SourceComponent", innerImpl); - - /*ReferenceTarget refTarget = new ReferenceTarget(); - refTarget.setReferenceName("TargetComponentRef"); - refTarget.addTarget(new URI("TargetComponent")); - sourceComponentDefinition.add(refTarget);*/ - ComponentReferenceDefinition compRef = new ComponentReferenceDefinition(innerType.getReferences().get("TargetComponentRef")); - compRef.setName("TargetComponentRef"); - compRef.addTarget(new URI("TargetComponent")); - sourceComponentDefinition.add(compRef); - - return sourceComponentDefinition; - } - - private ComponentDefinition<JavaImplementation> createInnerSourceComponentDef() throws Exception { - - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> sourceType = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - sourceType.setImplementationScope(Scope.COMPOSITE); - JavaMappedReference reference = new JavaMappedReference(); - reference.setName("targetReference"); - JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - ServiceContract<?> targetContract = registry.introspect(Target.class); - targetContract.setCallbackClass(OtherTarget.class); - targetContract.setCallbackName("OtherTarget"); - reference.setServiceContract(targetContract); - reference.setMember(SourceImpl.class.getMethod("setTarget", Target.class)); - sourceType.add(reference); - - ServiceContract<?> sourceContract = registry.introspect(Source.class); - - JavaMappedService sourceServiceDefinition = new JavaMappedService(); - sourceServiceDefinition.setName("Source"); - sourceServiceDefinition.setServiceContract(sourceContract); - - sourceType.add(sourceServiceDefinition); - sourceType.setConstructorDefinition(new ConstructorDefinition<SourceImpl>(SourceImpl.class.getConstructor())); - JavaImplementation sourceImpl = new JavaImplementation(SourceImpl.class, sourceType); - ComponentDefinition<JavaImplementation> innerSourceComponentDefinition = - new ComponentDefinition<JavaImplementation>("InnerSourceComponent", sourceImpl); - - ComponentReferenceDefinition compRef = new ComponentReferenceDefinition(sourceType.getReferences().get("targetReference")); - compRef.setName("targetReference"); - compRef.addTarget(new URI("TargetComponentRef")); - innerSourceComponentDefinition.add(compRef); - /*ReferenceTarget refTarget = new ReferenceTarget(); - refTarget.setReferenceName("targetReference"); - refTarget.addTarget(new URI("TargetComponentRef")); - innerSourceComponentDefinition.add(refTarget); - */ - return innerSourceComponentDefinition; - } - - private ComponentDefinition<JavaImplementation> createTargetComponentDef() throws Exception { - - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> targetType = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - targetType.setImplementationScope(Scope.COMPOSITE); - - JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - ServiceContract<?> targetContract = registry.introspect(Target.class); - targetContract.setCallbackClass(OtherTarget.class); - targetContract.setCallbackName("OtherTarget"); - - JavaMappedService serviceDefinition = new JavaMappedService(); - serviceDefinition.setName("Target"); - serviceDefinition.setServiceContract(targetContract); - serviceDefinition.setCallbackReferenceName("otherTarget"); - - targetType.add(serviceDefinition); - targetType.setConstructorDefinition(new ConstructorDefinition<TargetImpl>(TargetImpl.class.getConstructor())); - JavaImplementation targetImpl = new JavaImplementation(TargetImpl.class, targetType); - return new ComponentDefinition<JavaImplementation>("TargetComponent", targetImpl); - } - - protected void setUp() throws Exception { - super.setUp(); - ScopeContainerMonitor monitor = EasyMock.createNiceMock(ScopeContainerMonitor.class); - CompositeScopeContainer container = new CompositeScopeContainer(monitor); - container.start(); - deploymentContext = new RootDeploymentContext(null, null, container, null); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplBasicTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplBasicTestCase.java deleted file mode 100644 index 1f7c8618d2..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplBasicTestCase.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.composite; - -import java.util.Collections; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.Reference; -import org.apache.tuscany.spi.component.ReferenceBinding; -import org.apache.tuscany.spi.component.Service; -import org.apache.tuscany.spi.event.Event; -import org.apache.tuscany.spi.event.RuntimeEventListener; -import org.apache.tuscany.spi.idl.InvalidServiceContractException; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.wire.InboundWire; - -import junit.framework.Assert; -import junit.framework.TestCase; -import org.apache.tuscany.core.component.event.CompositeStart; -import org.apache.tuscany.core.implementation.TestUtils; -import org.easymock.EasyMock; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.eq; -import static org.easymock.EasyMock.expectLastCall; -import static org.easymock.EasyMock.isA; -import static org.easymock.EasyMock.replay; - -/** - * @version $Rev$ $Date$ - */ -public class CompositeComponentImplBasicTestCase extends TestCase { - private AtomicComponent component; - - public void testGetScope() { - CompositeComponent composite = new CompositeComponentImpl("parent", null, null, null); - Assert.assertEquals(Scope.SYSTEM, composite.getScope()); - } - - public void testReferencesServices() throws Exception { - CompositeComponent composite = new CompositeComponentImpl("parent", null, null, null); - Service service = EasyMock.createMock(Service.class); - EasyMock.expect(service.getName()).andReturn("foo").atLeastOnce(); - EasyMock.expect(service.isSystem()).andReturn(false).atLeastOnce(); - service.getServiceBindings(); - EasyMock.expectLastCall().andReturn(Collections.emptyList()).atLeastOnce(); - EasyMock.replay(service); - composite.register(service); - composite.register(getReference("bar")); - } - - public void testOnEvent() { - CompositeComponent composite = new CompositeComponentImpl("parent", null, null, null); - Event event = new Event() { - public Object getSource() { - return null; - } - }; - RuntimeEventListener listener = createMock(RuntimeEventListener.class); - listener.onEvent(isA(CompositeStart.class)); - listener.onEvent(eq(event)); - expectLastCall(); - replay(listener); - composite.addListener(listener); - composite.start(); - composite.onEvent(event); - } - - public void testPrepare() throws Exception { - CompositeComponent composite = new CompositeComponentImpl("parent", null, null, null); - composite.prepare(); - } - - private Reference getReference(String name) throws InvalidServiceContractException { - ReferenceBinding binding = EasyMock.createNiceMock(ReferenceBinding.class); - EasyMock.expect(binding.isSystem()).andReturn(false).atLeastOnce(); - InboundWire wire = TestUtils.createInboundWire(Bar.class); - wire.setContainer(binding); - EasyMock.expect(binding.getInboundWire()).andReturn(wire).atLeastOnce(); - - binding.getName(); - expectLastCall().andReturn(name).anyTimes(); - replay(binding); - - Reference reference = new ReferenceImpl(name, null, wire.getServiceContract()); - reference.addReferenceBinding(binding); - return reference; - } - - protected void setUp() throws Exception { - super.setUp(); - component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("foo").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(false).atLeastOnce(); - component.getInboundWires(); - EasyMock.expectLastCall().andReturn(Collections.emptyList()).atLeastOnce(); - EasyMock.replay(component); - } - - private interface Bar { - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplSystemWireTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplSystemWireTestCase.java deleted file mode 100644 index 018e068120..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplSystemWireTestCase.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.composite; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.tuscany.spi.QualifiedName; -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.PrepareException; -import org.apache.tuscany.spi.component.SCAObject; -import org.apache.tuscany.spi.idl.java.JavaServiceContract; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.OutboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.builder.ConnectorImpl; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class CompositeComponentImplSystemWireTestCase extends TestCase { - - /** - * Verifies system services in a CompositeComponentImpl are wired during the parent composite's prepare callback - */ - public void testSystemServiceWire() throws Exception { - InboundWire inbound = EasyMock.createMock(InboundWire.class); - EasyMock.expect(inbound.getServiceContract()).andReturn(new JavaServiceContract(Foo.class)).atLeastOnce(); - inbound.getInvocationChains(); - EasyMock.expectLastCall().andReturn(Collections.emptyMap()).atLeastOnce(); - - QualifiedName qName = new QualifiedName("target/bar"); - OutboundWire outbound = EasyMock.createMock(OutboundWire.class); - EasyMock.expect(outbound.getTargetName()).andReturn(qName).atLeastOnce(); - EasyMock.expect(outbound.isAutowire()).andReturn(false); - - outbound.setTargetWire(EasyMock.eq(inbound)); - EasyMock.expect(outbound.getServiceContract()).andReturn(new JavaServiceContract(Foo.class)).atLeastOnce(); - List<OutboundWire> wires = new ArrayList<OutboundWire>(); - wires.add(outbound); - Map<String, List<OutboundWire>> wireMap = new HashMap<String, List<OutboundWire>>(); - wireMap.put("ref", wires); - CompositeComponent parent = new CompositeComponentImpl("foo", "foo", null, new ConnectorImpl(), null); - AtomicComponent source = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(source.getScope()).andReturn(Scope.COMPOSITE).atLeastOnce(); - EasyMock.expect(source.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(source.getOutboundWires()).andReturn(wireMap); - source.getInboundWires(); - EasyMock.expectLastCall().andReturn(Collections.emptyList()).atLeastOnce(); - EasyMock.expect(source.isSystem()).andReturn(true).atLeastOnce(); - EasyMock.expect(source.getParent()).andReturn(parent).atLeastOnce(); - - source.prepare(); - EasyMock.replay(source); - - EasyMock.expect(outbound.getContainer()).andReturn(source).atLeastOnce(); - EasyMock.replay(outbound); - - parent.register(source); - - AtomicComponent target = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(target.getName()).andReturn("target").atLeastOnce(); - EasyMock.expect(target.getInboundWire("bar")).andReturn(inbound).atLeastOnce(); - List<InboundWire> inboundWires = new ArrayList<InboundWire>(); - inboundWires.add(inbound); - EasyMock.expect(target.getInboundWires()).andReturn(inboundWires).atLeastOnce(); - EasyMock.expect(target.getScope()).andReturn(Scope.COMPOSITE).atLeastOnce(); - EasyMock.expect(target.getParent()).andReturn(parent).atLeastOnce(); - - target.prepare(); - target.getOutboundWires(); - EasyMock.expectLastCall().andReturn(Collections.emptyMap()); - EasyMock.expect(target.isSystem()).andReturn(true).atLeastOnce(); - EasyMock.replay(target); - - EasyMock.expect(inbound.getContainer()).andReturn(target); - EasyMock.replay(inbound); - - parent.register(target); - parent.prepare(); - EasyMock.verify(source); - EasyMock.verify(target); - EasyMock.verify(inbound); - EasyMock.verify(outbound); - } - - - /** - * Verifies an application component cannot be wired to a system service in the same composite - */ - public void testSystemServiceIsolationWire() throws Exception { - InboundWire inbound = EasyMock.createMock(InboundWire.class); - EasyMock.expect(inbound.getServiceContract()).andReturn(new JavaServiceContract(Foo.class)).atLeastOnce(); - EasyMock.replay(inbound); - - QualifiedName qName = new QualifiedName("target/bar"); - OutboundWire outbound = EasyMock.createMock(OutboundWire.class); - EasyMock.expect(outbound.isAutowire()).andReturn(false); - EasyMock.expect(outbound.getContainer()).andReturn(EasyMock.createNiceMock(SCAObject.class)); - EasyMock.expect(outbound.getReferenceName()).andReturn("foo"); - EasyMock.expect(outbound.getTargetName()).andReturn(qName).atLeastOnce(); - EasyMock.replay(outbound); - - List<OutboundWire> wires = new ArrayList<OutboundWire>(); - wires.add(outbound); - Map<String, List<OutboundWire>> wireMap = new HashMap<String, List<OutboundWire>>(); - wireMap.put("ref", wires); - CompositeComponent parent = new CompositeComponentImpl("foo", "foo", null, new ConnectorImpl(), null); - AtomicComponent source = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(source.getName()).andReturn("source").atLeastOnce(); - List<InboundWire> inboundWires = new ArrayList<InboundWire>(); - inboundWires.add(inbound); - source.getInboundWires(); - EasyMock.expectLastCall().andReturn(inboundWires).atLeastOnce(); - EasyMock.expect(source.getOutboundWires()).andReturn(wireMap); - EasyMock.expect(source.isSystem()).andReturn(true).atLeastOnce(); - EasyMock.expect(source.getParent()).andReturn(parent).atLeastOnce(); - EasyMock.replay(source); - - parent.register(source); - - AtomicComponent target = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(target.getName()).andReturn("target").atLeastOnce(); - inboundWires.add(inbound); - EasyMock.expect(target.getInboundWires()).andReturn(inboundWires).atLeastOnce(); - EasyMock.expect(target.isSystem()).andReturn(false).atLeastOnce(); - EasyMock.replay(target); - - parent.register(target); - try { - parent.prepare(); - fail(); - } catch (PrepareException e) { - //expected - } - EasyMock.verify(source); - EasyMock.verify(target); - EasyMock.verify(inbound); - EasyMock.verify(outbound); - } - - - private class Foo { - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplTestCase.java deleted file mode 100644 index eb57c6733d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplTestCase.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.composite; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.wire.InboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.implementation.TestUtils; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class CompositeComponentImplTestCase extends TestCase { - - public void testSetUri() throws Exception { - CompositeComponentImpl component = new CompositeComponentImpl("foo", "foo/bar", null, null, null); - assertEquals("foo/bar", component.getURI()); - } - - public void testRegisterSystemService() throws Exception { - List<Class<?>> services = new ArrayList<Class<?>>(); - services.add(Foo.class); - CompositeComponent parent = new CompositeComponentImpl("foo", "foo", null, null, null); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("bar").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(true).atLeastOnce(); - List<InboundWire> wires = TestUtils.createInboundWires(services); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - EasyMock.replay(component); - parent.register(component); - assertNull(parent.getChild("bar")); - assertNotNull(parent.getSystemChild("bar")); - EasyMock.verify(component); - } - - public void testRegister() throws Exception { - List<Class<?>> services = new ArrayList<Class<?>>(); - services.add(Foo.class); - CompositeComponent parent = new CompositeComponentImpl("foo", "foo", null, null, null); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("bar").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(false).atLeastOnce(); - List<InboundWire> wires = TestUtils.createInboundWires(services); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - EasyMock.replay(component); - parent.register(component); - assertNull(parent.getSystemChild("bar")); - assertNotNull(parent.getChild("bar")); - EasyMock.verify(component); - } - - /** - * Verifies a system service and application component can be registered with the same name in a composite - */ - public void testSystemServiceApplicationNamespaceIsolation() throws Exception { - List<Class<?>> services = new ArrayList<Class<?>>(); - services.add(Foo.class); - CompositeComponent parent = new CompositeComponentImpl("foo", "foo", null, null, null); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("bar").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(true).atLeastOnce(); - List<InboundWire> wires = TestUtils.createInboundWires(services); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - EasyMock.replay(component); - parent.register(component); - AtomicComponent component2 = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component2.getName()).andReturn("bar").atLeastOnce(); - EasyMock.expect(component2.isSystem()).andReturn(false).atLeastOnce(); - EasyMock.expect(component2.getInboundWires()).andReturn(wires).atLeastOnce(); - EasyMock.replay(component2); - parent.register(component2); - EasyMock.verify(component); - EasyMock.verify(component2); - } - - public void testSystemServiceLifecycle() throws Exception { - List<Class<?>> services = new ArrayList<Class<?>>(); - services.add(Foo.class); - CompositeComponent parent = new CompositeComponentImpl("foo", "foo", null, null, null); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - component.start(); - EasyMock.expect(component.getName()).andReturn("bar").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(true).atLeastOnce(); - component.stop(); - List<InboundWire> wires = TestUtils.createInboundWires(services); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - EasyMock.replay(component); - parent.register(component); - parent.start(); - parent.stop(); - EasyMock.verify(component); - } - - public void testComponentLifecycle() throws Exception { - List<Class<?>> services = new ArrayList<Class<?>>(); - services.add(Foo.class); - CompositeComponent parent = new CompositeComponentImpl("foo", "foo", null, null, null); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - component.start(); - EasyMock.expect(component.getName()).andReturn("bar").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(false).atLeastOnce(); - List<InboundWire> wires = TestUtils.createInboundWires(services); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - component.stop(); - EasyMock.replay(component); - parent.register(component); - parent.start(); - parent.stop(); - EasyMock.verify(component); - } - - public void testSystemAutowire() throws Exception { - List<Class<?>> services = new ArrayList<Class<?>>(); - services.add(Foo.class); - CompositeComponent parent = new CompositeComponentImpl("foo", "foo", null, null, null); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - component.start(); - EasyMock.expect(component.getName()).andReturn("bar").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(true).atLeastOnce(); - List<InboundWire> wires = TestUtils.createInboundWires(services); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - component.stop(); - EasyMock.replay(component); - parent.register(component); - parent.start(); - assertNull(parent.resolveSystemExternalAutowire(Foo.class)); - assertNotNull(parent.resolveSystemAutowire(Foo.class)); - parent.stop(); - EasyMock.verify(component); - } - - - public void testAutowire() throws Exception { - List<Class<?>> services = new ArrayList<Class<?>>(); - services.add(Foo.class); - CompositeComponent parent = new CompositeComponentImpl("foo", "foo", null, null, null); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - component.start(); - EasyMock.expect(component.getName()).andReturn("bar").atLeastOnce(); - List<InboundWire> wires = TestUtils.createInboundWires(services); - TestUtils.populateInboundWires(component, wires); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(false).atLeastOnce(); - component.stop(); - EasyMock.replay(component); - parent.register(component); - parent.start(); - assertNull(parent.resolveExternalAutowire(Foo.class)); - assertNotNull(parent.resolveAutowire(Foo.class)); - parent.stop(); - EasyMock.verify(component); - } - - private class Foo { - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentResolutionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentResolutionTestCase.java deleted file mode 100644 index f24e1f8e94..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentResolutionTestCase.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.composite; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.wire.InboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.implementation.TestUtils; -import org.apache.tuscany.core.mock.component.Source; -import org.easymock.EasyMock; - -/** - * Verifies an atomic component can be resolved from its parent - * - * @version $$Rev$$ $$Date$$ - */ -public class CompositeComponentResolutionTestCase extends TestCase { - - public void testSystemComponentResolution() throws Exception { - CompositeComponent parent = new CompositeComponentImpl("foo", null, null, true); - parent.start(); - List<Class<?>> interfaces = new ArrayList<Class<?>>(); - interfaces.add(Source.class); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(true).atLeastOnce(); - List<InboundWire> wires = TestUtils.createInboundWires(interfaces); - TestUtils.populateInboundWires(component, wires); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - EasyMock.replay(component); - parent.register(component); - assertNull(parent.getChild("source")); - assertTrue(parent.getSystemChild("source") instanceof AtomicComponent); - EasyMock.verify(component); - } - - public void testComponentResolution() throws Exception { - CompositeComponent parent = new CompositeComponentImpl("foo", null, null, null); - parent.start(); - List<Class<?>> interfaces = new ArrayList<Class<?>>(); - interfaces.add(Source.class); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(false).atLeastOnce(); - List<InboundWire> wires = TestUtils.createInboundWires(interfaces); - TestUtils.populateInboundWires(component, wires); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - EasyMock.replay(component); - parent.register(component); - assertNull(parent.getSystemChild("source")); - assertTrue(parent.getChild("source") instanceof AtomicComponent); - EasyMock.verify(component); - } - - - protected void setUp() throws Exception { - super.setUp(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLifecycleTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLifecycleTestCase.java deleted file mode 100644 index f5d209fe4c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLifecycleTestCase.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.composite; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.wire.InboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.implementation.TestUtils; -import org.apache.tuscany.core.mock.component.Source; -import org.easymock.EasyMock; - -/** - * @version $$Rev$$ $$Date$$ - */ -public class CompositeLifecycleTestCase extends TestCase { - - public void testLifecycle() throws Exception { - CompositeComponent composite = new CompositeComponentImpl("foo", null, null, null); - composite.start(); - assertNull(composite.getChild("nothtere")); - composite.stop(); - composite.start(); - assertNull(composite.getChild("nothtere")); - composite.stop(); - } - - public void testSystemRestart() throws Exception { - List<Class<?>> interfaces = new ArrayList<Class<?>>(); - interfaces.add(Source.class); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - component.start(); - component.stop(); - EasyMock.expectLastCall().times(2); - EasyMock.expect(component.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(true).atLeastOnce(); - - List<InboundWire> wires = TestUtils.createInboundWires(interfaces); - TestUtils.populateInboundWires(component, wires); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - - EasyMock.replay(component); - - CompositeComponent composite = new CompositeComponentImpl("foo", null, null, null); - composite.start(); - composite.register(component); - - assertTrue(composite.getSystemChild("source") instanceof AtomicComponent); - composite.stop(); - composite.start(); - assertTrue(composite.getSystemChild("source") instanceof AtomicComponent); - composite.stop(); - EasyMock.verify(component); - } - - public void testRestart() throws Exception { - List<Class<?>> interfaces = new ArrayList<Class<?>>(); - interfaces.add(Source.class); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - component.start(); - component.stop(); - EasyMock.expectLastCall().times(2); - EasyMock.expect(component.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(false).atLeastOnce(); - - List<InboundWire> wires = TestUtils.createInboundWires(interfaces); - TestUtils.populateInboundWires(component, wires); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - - EasyMock.replay(component); - - CompositeComponent composite = new CompositeComponentImpl("foo", null, null, null); - composite.start(); - composite.register(component); - - assertTrue(composite.getChild("source") instanceof AtomicComponent); - composite.stop(); - composite.start(); - assertTrue(composite.getChild("source") instanceof AtomicComponent); - composite.stop(); - EasyMock.verify(component); - } - - public void testChildStoppedBeforeParent() throws Exception { - CompositeComponent parent = new CompositeComponentImpl("parent", null, null, null); - CompositeComponent child = new CompositeComponentImpl("child", null, null, null); - parent.register(child); - parent.start(); - child.stop(); - parent.stop(); - } - - protected void setUp() throws Exception { - super.setUp(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLoaderWireResolutionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLoaderWireResolutionTestCase.java deleted file mode 100644 index 9906528a84..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeLoaderWireResolutionTestCase.java +++ /dev/null @@ -1,232 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.tuscany.core.implementation.composite;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import org.apache.tuscany.spi.implementation.java.PojoComponentType;
-import org.apache.tuscany.spi.loader.InvalidPromotedReferenceException;
-import org.apache.tuscany.spi.loader.InvalidWireException;
-import org.apache.tuscany.spi.model.ComponentDefinition;
-import org.apache.tuscany.spi.model.ComponentReferenceDefinition;
-import org.apache.tuscany.spi.model.ComponentTypeReferenceDefinition;
-import org.apache.tuscany.spi.model.CompositeComponentType;
-import org.apache.tuscany.spi.model.CompositeReferenceDefinition;
-import org.apache.tuscany.spi.model.Property;
-import org.apache.tuscany.spi.model.AbstractReferenceDefinition;
-import org.apache.tuscany.spi.model.ServiceDefinition;
-import org.apache.tuscany.spi.model.WireDefinition;
-
-import junit.framework.TestCase;
-import org.apache.tuscany.core.implementation.java.JavaImplementation;
-
-/**
- * This class tests the wire resolution function of the composite loader
- *
- * @version $Rev$ $Date$
- */
-public class CompositeLoaderWireResolutionTestCase extends TestCase {
- private CompositeComponentType<ServiceDefinition, CompositeReferenceDefinition, Property<?>> componentType;
- private CompositeLoader compositeLoader = new CompositeLoader(null, null);
-
- public void setUp() throws Exception {
- componentType = new CompositeComponentType<ServiceDefinition, CompositeReferenceDefinition, Property<?>>();
- componentType.setName("TestComposite");
- //add a service to the composite
- ServiceDefinition serviceDefn = new ServiceDefinition("compositeService1", null, true);
- ServiceDefinition boundSvcDefn = new ServiceDefinition("boundSvc", null, true, null);
- ServiceDefinition boundSvcDefnWithTarget =
- new ServiceDefinition("boundSvcWithTarget", null, true);
- boundSvcDefnWithTarget.setTarget(new URI("orgTarget"));
- componentType.add(serviceDefn);
- componentType.add(boundSvcDefn);
- componentType.add(boundSvcDefnWithTarget);
-
- CompositeReferenceDefinition compositeReference = new CompositeReferenceDefinition("compositeReference", null);
- componentType.add(compositeReference);
-
- PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>> pojoComponentType1 =
- new PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>>();
- ServiceDefinition pojoSvc1 = new ServiceDefinition("pojoSvc1", null, false);
- pojoComponentType1.add(pojoSvc1);
- ComponentTypeReferenceDefinition pojoRef1 = new ComponentTypeReferenceDefinition("pojoRef1", null);
- pojoComponentType1.add(pojoRef1);
- JavaImplementation pojoImpl1 = new JavaImplementation(null, pojoComponentType1);
-
- ComponentDefinition<JavaImplementation> component1 =
- new ComponentDefinition<JavaImplementation>("Component1", pojoImpl1);
- component1.add(new ComponentReferenceDefinition(pojoRef1));
- componentType.add(component1);
-
- PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>> pojoComponentType2 =
- new PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>>();
- ServiceDefinition pojoSvc2 = new ServiceDefinition("pojoSvc2", null, false);
- pojoComponentType2.add(pojoSvc2);
- ServiceDefinition pojoSvc3 = new ServiceDefinition("pojoSvc3", null, false);
- pojoComponentType2.add(pojoSvc3);
- ComponentTypeReferenceDefinition pojoRef2 = new ComponentTypeReferenceDefinition("pojoRef2", null);
- pojoComponentType2.add(pojoRef2);
- ComponentTypeReferenceDefinition pojoRef3 = new ComponentTypeReferenceDefinition("pojoRef3", null);
- pojoComponentType2.add(pojoRef3);
- JavaImplementation pojoImpl2 = new JavaImplementation(null, pojoComponentType2);
-
- ComponentDefinition<JavaImplementation> component2 =
- new ComponentDefinition<JavaImplementation>("Component2", pojoImpl2);
- component2.add(new ComponentReferenceDefinition(pojoRef2));
- component2.add(new ComponentReferenceDefinition(pojoRef3));
- componentType.add(component2);
- }
-
- public void testCompositeSvc2CompositeReferenceWire() throws Exception {
- WireDefinition wireDefn = new WireDefinition();
- wireDefn.setSource(new URI("compositeService1"));
- wireDefn.setTarget(new URI("compositeReference"));
- componentType.add(wireDefn);
- compositeLoader.resolveWires(componentType);
- }
-
- public void testCompositeSvc2ComponentValid() throws Exception {
- //undefined source and targets
- WireDefinition wireDefn = new WireDefinition();
- wireDefn.setSource(new URI("compositeService1"));
- wireDefn.setTarget(new URI("Component1"));
- componentType.add(wireDefn);
- compositeLoader.resolveWires(componentType);
- }
-
- public void testCompositeSvc2ComponentQualifiedValid() throws Exception {
- //undefined source and targets
- WireDefinition wireDefn = new WireDefinition();
- wireDefn.setSource(new URI("compositeService1"));
- wireDefn.setTarget(new URI("Component2/pojoSvc3"));
- componentType.add(wireDefn);
- compositeLoader.resolveWires(componentType);
- }
-
- public void testCompositeSvc2ComponentQualifiedInvalid() throws URISyntaxException, InvalidPromotedReferenceException {
- //undefined source and targets
- WireDefinition wireDefn = new WireDefinition();
- wireDefn.setSource(new URI("compositeService1"));
- wireDefn.setTarget(new URI("Component2/pojoSvc5"));
- componentType.add(wireDefn);
- try {
- compositeLoader.resolveWires(componentType);
- fail();
- } catch (InvalidWireException e) {
- // expected
- }
- }
-
- public void testCompositeSvc2ComponentUnQualifiedInvalid() throws URISyntaxException, InvalidPromotedReferenceException {
- //undefined source and targets
- WireDefinition wireDefn = new WireDefinition();
- wireDefn.setSource(new URI("compositeService1"));
- wireDefn.setTarget(new URI("Component2"));
- componentType.add(wireDefn);
- try {
- compositeLoader.resolveWires(componentType);
- fail();
- } catch (InvalidWireException e) {
- // expected
- }
- }
-
- public void testComponent2CompositeReferenceValid() throws Exception {
- //undefined source and targets
- WireDefinition wireDefn = new WireDefinition();
- wireDefn.setSource(new URI("Component1"));
- wireDefn.setTarget(new URI("compositeReference"));
- componentType.add(wireDefn);
- compositeLoader.resolveWires(componentType);
- }
-
- public void testComponent2CompositeReferenceQualifiedValid() throws Exception {
- //undefined source and targets
- WireDefinition wireDefn = new WireDefinition();
- wireDefn.setSource(new URI("Component2/pojoRef3"));
- wireDefn.setTarget(new URI("compositeReference"));
- componentType.add(wireDefn);
- compositeLoader.resolveWires(componentType);
- }
-
- public void testComponent2CompositeReferenceUnQualifiedInvalid() throws URISyntaxException, InvalidPromotedReferenceException {
- //undefined source and targets
- WireDefinition wireDefn = new WireDefinition();
- wireDefn.setSource(new URI("Component2"));
- wireDefn.setTarget(new URI("compositeReference"));
- componentType.add(wireDefn);
-
- try {
- compositeLoader.resolveWires(componentType);
- fail();
- } catch (InvalidWireException e) {
- // expected
- }
- }
-
- public void testComponent2ComponentQualifedValid() throws Exception {
- //undefined source and targets
- WireDefinition wireDefn = new WireDefinition();
- wireDefn.setSource(new URI("Component1"));
- wireDefn.setTarget(new URI("Component2/pojoSvc3"));
- componentType.add(wireDefn);
- compositeLoader.resolveWires(componentType);
- }
-
- public void testComponent2ComponentUnQualifedInvalid() throws URISyntaxException, InvalidPromotedReferenceException {
- //undefined source and targets
- WireDefinition wireDefn = new WireDefinition();
- wireDefn.setSource(new URI("Component1"));
- wireDefn.setTarget(new URI("Component2"));
- componentType.add(wireDefn);
- try {
- compositeLoader.resolveWires(componentType);
- fail();
- } catch (InvalidWireException e) {
- // expected
- }
- }
-
- public void testInvalidWireDefinitions() throws URISyntaxException, InvalidPromotedReferenceException {
- //undefined source and targets
- WireDefinition wireDefn = new WireDefinition();
- wireDefn.setSource(new URI("undefinedSource"));
- wireDefn.setTarget(new URI("compositeReference"));
- componentType.add(wireDefn);
-
- try {
- compositeLoader.resolveWires(componentType);
- fail();
- } catch (InvalidWireException e) {
- // expected
- }
-
- try {
- wireDefn.setSource(new URI("compositeService1"));
- wireDefn.setTarget(new URI("undefinedTarget"));
- componentType.add(wireDefn);
- compositeLoader.resolveWires(componentType);
- fail();
- } catch (InvalidWireException e) {
- // expected
- }
- }
-}
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositePropagationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositePropagationTestCase.java deleted file mode 100644 index 36e6e98809..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/CompositePropagationTestCase.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.composite; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.wire.InboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.implementation.TestUtils; -import org.apache.tuscany.core.mock.component.Source; -import org.easymock.EasyMock; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; - -/** - * @version $Rev$ $Date$ - */ -public class CompositePropagationTestCase extends TestCase { - - private CompositeComponent parent; - private CompositeComponent child2; - - public void testSystemLifecyclePropagation() throws Exception { - parent.start(); - List<Class<?>> interfaces = new ArrayList<Class<?>>(); - interfaces.add(Source.class); - AtomicComponent component = createMock(AtomicComponent.class); - expect(component.getName()).andReturn("source").anyTimes(); - component.stop(); - EasyMock.expect(component.isSystem()).andReturn(true).atLeastOnce(); - List<InboundWire> wires = TestUtils.createInboundWires(interfaces); - TestUtils.populateInboundWires(component, wires); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - - replay(component); - child2.register(component); - parent.stop(); - verify(component); - } - - public void testLifecyclePropagation() throws Exception { - parent.start(); - List<Class<?>> interfaces = new ArrayList<Class<?>>(); - interfaces.add(Source.class); - AtomicComponent component = createMock(AtomicComponent.class); - expect(component.getName()).andReturn("source").anyTimes(); - component.stop(); - EasyMock.expect(component.isSystem()).andReturn(false).atLeastOnce(); - List<InboundWire> wires = TestUtils.createInboundWires(interfaces); - TestUtils.populateInboundWires(component, wires); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - replay(component); - child2.register(component); - parent.stop(); - verify(component); - } - - - protected void setUp() throws Exception { - super.setUp(); - parent = new CompositeComponentImpl("parent", null, null, null); - CompositeComponent child1 = new CompositeComponentImpl("child1", parent, null, null); - child2 = new CompositeComponentImpl("child2", child1, null, null); - child1.register(child2); - parent.register(child1); - } - - protected void tearDown() throws Exception { - parent.stop(); - super.tearDown(); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/DuplicateRegistrationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/DuplicateRegistrationTestCase.java deleted file mode 100644 index 72c2ffd827..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/DuplicateRegistrationTestCase.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.composite; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.DuplicateNameException; -import org.apache.tuscany.spi.wire.InboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.implementation.TestUtils; -import org.apache.tuscany.core.mock.component.Source; -import org.easymock.EasyMock; - -/** - * Verfies children with the same name cannot be registered in the same composite - * - * @version $Rev$ $Date$ - */ -public class DuplicateRegistrationTestCase extends TestCase { - - public void testDuplicateRegistration() throws Exception { - CompositeComponent parent = new CompositeComponentImpl(null, null, null, null); - parent.start(); - - List<Class<?>> interfaces = new ArrayList<Class<?>>(); - interfaces.add(Source.class); - AtomicComponent component1 = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component1.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(component1.isSystem()).andReturn(true).atLeastOnce(); - component1.stop(); - List<InboundWire> wires = TestUtils.createInboundWires(interfaces); - TestUtils.populateInboundWires(component1, wires); - EasyMock.expect(component1.getInboundWires()).andReturn(wires).atLeastOnce(); - EasyMock.replay(component1); - - AtomicComponent component2 = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component2.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(component2.isSystem()).andReturn(true).atLeastOnce(); - component2.stop(); - EasyMock.replay(component2); - - parent.register(component1); - try { - parent.register(component2); - fail(); - } catch (DuplicateNameException e) { - // ok - } - parent.stop(); - } - - public void testDuplicateNameSystemService() throws Exception { - List<Class<?>> services = new ArrayList<Class<?>>(); - services.add(Source.class); - CompositeComponent parent = new CompositeComponentImpl("foo", "foo", null, null, null); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getName()).andReturn("bar").atLeastOnce(); - EasyMock.expect(component.isSystem()).andReturn(true).atLeastOnce(); - List<InboundWire> wires = TestUtils.createInboundWires(services); - TestUtils.populateInboundWires(component, wires); - EasyMock.expect(component.getInboundWires()).andReturn(wires).atLeastOnce(); - EasyMock.replay(component); - parent.register(component); - AtomicComponent component2 = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component2.getName()).andReturn("bar").atLeastOnce(); - EasyMock.expect(component2.isSystem()).andReturn(true).atLeastOnce(); - EasyMock.replay(component2); - try { - parent.register(component2); - fail(); - } catch (DuplicateNameException e) { - // expected - } - } - - - protected void setUp() throws Exception { - super.setUp(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ImplementationCompositeLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ImplementationCompositeLoaderTestCase.java deleted file mode 100644 index 7d4ebc1ac3..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ImplementationCompositeLoaderTestCase.java +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.composite; - -import java.net.MalformedURLException; -import java.net.URL; -import javax.xml.namespace.QName; -import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import static org.osoa.sca.Constants.SCA_NS; - -import org.apache.tuscany.spi.deployer.CompositeClassLoader; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.loader.LoaderException; -import org.apache.tuscany.spi.model.CompositeImplementation; -import org.apache.tuscany.spi.services.artifact.Artifact; -import org.apache.tuscany.spi.services.artifact.ArtifactRepository; - -import junit.framework.TestCase; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.reportMatcher; -import static org.easymock.EasyMock.verify; -import org.easymock.IArgumentMatcher; - -/** - * @version $Rev$ $Date$ - */ -public class ImplementationCompositeLoaderTestCase extends TestCase { - private static final QName IMPLEMENTATION_COMPOSITE = new QName(SCA_NS, "implementation.composite"); - - private ClassLoader cl; - private ImplementationCompositeLoader loader; - private XMLStreamReader reader; - private DeploymentContext context; - private ArtifactRepository artifactRepository; - - public void testName() throws LoaderException, XMLStreamException, MalformedURLException { - String name = "foo"; - expect(reader.getName()).andReturn(IMPLEMENTATION_COMPOSITE); - expect(reader.getAttributeValue(null, "name")).andReturn(name); - expect(reader.getAttributeValue(null, "group")).andReturn(null); - expect(reader.getAttributeValue(null, "version")).andReturn(null); - expect(reader.getAttributeValue(null, "scdlLocation")).andReturn(null); - expect(reader.getAttributeValue(null, "jarLocation")).andReturn(null); - expect(reader.next()).andReturn(END_ELEMENT); - replay(reader); - - replay(context); - replay(artifactRepository); - - CompositeImplementation impl = loader.load(null, null, reader, context); - verify(reader); - verify(context); - verify(artifactRepository); - assertEquals(name, impl.getName()); - assertNull(impl.getScdlLocation()); - assertNull(impl.getClassLoader()); - } - - public void testWithArtifact() throws LoaderException, XMLStreamException, MalformedURLException { - String name = "foo"; - expect(reader.getName()).andReturn(IMPLEMENTATION_COMPOSITE); - expect(reader.getAttributeValue(null, "name")).andReturn(name); - expect(reader.getAttributeValue(null, "group")).andReturn("com.example"); - expect(reader.getAttributeValue(null, "version")).andReturn("1.0"); - expect(reader.getAttributeValue(null, "scdlLocation")).andReturn(null); - expect(reader.getAttributeValue(null, "jarLocation")).andReturn(null); - expect(reader.next()).andReturn(END_ELEMENT); - replay(reader); - - expect(context.getClassLoader()).andReturn(cl); - replay(context); - URL url = new URL("http://www.example.com/sca/base.jar"); - artifactRepository.resolve(artifactMatcher(url, "com.example", name, "1.0")); - replay(artifactRepository); - - CompositeImplementation impl = loader.load(null, null, reader, context); - verify(reader); - verify(context); - verify(artifactRepository); - assertEquals(name, impl.getName()); - assertEquals(new URL("jar:http://www.example.com/sca/base.jar!/META-INF/sca/default.scdl"), - impl.getScdlLocation()); - assertTrue(impl.getClassLoader() instanceof CompositeClassLoader); - } - - public void testWithScdlLocation() throws LoaderException, XMLStreamException, MalformedURLException { - String name = "foo"; - expect(reader.getName()).andReturn(IMPLEMENTATION_COMPOSITE); - expect(reader.getAttributeValue(null, "name")).andReturn(name); - expect(reader.getAttributeValue(null, "group")).andReturn(null); - expect(reader.getAttributeValue(null, "version")).andReturn(null); - expect(reader.getAttributeValue(null, "scdlLocation")).andReturn("bar.scdl"); - expect(reader.getAttributeValue(null, "jarLocation")).andReturn(null); - expect(reader.next()).andReturn(END_ELEMENT); - replay(reader); - - expect(context.getScdlLocation()).andReturn(new URL("http://www.example.com/sca/base.scdl")); - expect(context.getClassLoader()).andReturn(cl); - replay(context); - replay(artifactRepository); - - CompositeImplementation impl = loader.load(null, null, reader, context); - verify(reader); - verify(context); - verify(artifactRepository); - assertEquals(name, impl.getName()); - assertEquals(new URL("http://www.example.com/sca/bar.scdl"), impl.getScdlLocation()); - assertSame(cl, impl.getClassLoader()); - } - - public void testWithJarLocation() throws LoaderException, XMLStreamException, MalformedURLException { - String name = "foo"; - expect(reader.getName()).andReturn(IMPLEMENTATION_COMPOSITE); - expect(reader.getAttributeValue(null, "name")).andReturn(name); - expect(reader.getAttributeValue(null, "group")).andReturn(null); - expect(reader.getAttributeValue(null, "version")).andReturn(null); - expect(reader.getAttributeValue(null, "scdlLocation")).andReturn(null); - expect(reader.getAttributeValue(null, "jarLocation")).andReturn("bar.jar"); - expect(reader.next()).andReturn(END_ELEMENT); - replay(reader); - - expect(context.getScdlLocation()).andReturn(new URL("http://www.example.com/sca/base.scdl")); - expect(context.getClassLoader()).andReturn(cl); - replay(context); - replay(artifactRepository); - - CompositeImplementation impl = loader.load(null, null, reader, context); - verify(reader); - verify(context); - verify(artifactRepository); - assertEquals(name, impl.getName()); - assertEquals(new URL("jar:http://www.example.com/sca/bar.jar!/META-INF/sca/default.scdl"), - impl.getScdlLocation()); - } - - protected void setUp() throws Exception { - super.setUp(); - artifactRepository = createMock(ArtifactRepository.class); - reader = createMock(XMLStreamReader.class); - context = createMock(DeploymentContext.class); - cl = getClass().getClassLoader(); - loader = new ImplementationCompositeLoader(null, artifactRepository); - } - - protected static Artifact artifactMatcher(final URL url, - final String group, - final String name, - final String version) { - reportMatcher(new IArgumentMatcher() { - - public boolean matches(Object object) { - if (!(object instanceof Artifact)) { - return false; - } - - Artifact artifact = (Artifact) object; - boolean match = group.equals(artifact.getGroup()) - && name.equals(artifact.getName()) - && version.equals(artifact.getVersion()) - && "jar".equals(artifact.getType()); - if (match) { - artifact.setUrl(url); - } - return match; - } - - public void appendTo(StringBuffer stringBuffer) { - stringBuffer.append(group).append(':').append(name).append(':').append(version); - } - }); - return null; - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/JavaObjectRegistrationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/JavaObjectRegistrationTestCase.java deleted file mode 100644 index f0fdd8b704..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/JavaObjectRegistrationTestCase.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.composite; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.DuplicateNameException; -import org.apache.tuscany.spi.component.SCAObject; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.event.CompositeStart; -import org.apache.tuscany.core.component.event.CompositeStop; - -/** - * @version $Rev$ $Date$ - */ -public class JavaObjectRegistrationTestCase extends TestCase { - private CompositeComponent composite; - - public void testRegistration() throws Exception { - MockComponent instance = new MockComponent(); - composite.registerJavaObject("foo", MockComponent.class, instance); - SCAObject child = composite.getSystemChild("foo"); - assertTrue(child instanceof AtomicComponent); - MockComponent resolvedInstance = (MockComponent) ((AtomicComponent) child).getTargetInstance(); - assertSame(instance, resolvedInstance); - } - - public void testDuplicateRegistration() throws Exception { - MockComponent instance = new MockComponent(); - composite.registerJavaObject("foo", MockComponent.class, instance); - try { - composite.registerJavaObject("foo", MockComponent.class, instance); - fail(); - } catch (DuplicateNameException e) { - // ok - } - } - - public void testSystemAutowireToObject() throws Exception { - MockComponent instance = new MockComponent(); - composite.registerJavaObject("foo", MockComponent.class, instance); - assertSame(instance, composite.resolveSystemAutowire(MockComponent.class).getTargetService()); - assertNull(composite.resolveSystemExternalAutowire(MockComponent.class)); - } - - public void testApplicationAutowireToObject() throws Exception { - MockComponent instance = new MockComponent(); - composite.registerJavaObject("foo", MockComponent.class, instance); - assertNotNull(composite.resolveAutowire(MockComponent.class)); - assertNull(composite.resolveExternalAutowire(MockComponent.class)); - } - - protected void setUp() throws Exception { - super.setUp(); - composite = new CompositeComponentImpl(null, null, null, null); - composite.start(); - composite.publish(new CompositeStart(this, null)); - } - - protected void tearDown() throws Exception { - composite.publish(new CompositeStop(this, null)); - composite.stop(); - super.tearDown(); - } - - private static class MockComponent { - public String hello(String message) { - return message; - } - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ManagedRequestContextTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ManagedRequestContextTestCase.java deleted file mode 100644 index 12299e762b..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ManagedRequestContextTestCase.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.composite; - -import org.osoa.sca.RequestContext; - -import org.apache.tuscany.spi.component.WorkContext; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class ManagedRequestContextTestCase extends TestCase { - - public void testGetServiceName() { - WorkContext workContext = EasyMock.createMock(WorkContext.class); - EasyMock.expect(workContext.getCurrentServiceName()).andReturn("foo"); - EasyMock.replay(workContext); - RequestContext context = new ManagedRequestContext(workContext); - assertEquals("foo", context.getServiceName()); - EasyMock.verify(workContext); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ReferenceImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ReferenceImplTestCase.java deleted file mode 100644 index 251833a554..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ReferenceImplTestCase.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.composite; - -import org.apache.tuscany.spi.component.Reference; -import org.apache.tuscany.spi.component.ReferenceBinding; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class ReferenceImplTestCase extends TestCase { - - public void testStart() { - ReferenceBinding binding = EasyMock.createMock(ReferenceBinding.class); - binding.setReference(EasyMock.isA(Reference.class)); - binding.start(); - EasyMock.replay(binding); - Reference reference = new ReferenceImpl(null, null, null); - reference.addReferenceBinding(binding); - reference.start(); - EasyMock.verify(binding); - - } - - public void testStop() { - ReferenceBinding binding = EasyMock.createMock(ReferenceBinding.class); - binding.setReference(EasyMock.isA(Reference.class)); - binding.stop(); - EasyMock.replay(binding); - Reference reference = new ReferenceImpl(null, null, null); - reference.addReferenceBinding(binding); - reference.stop(); - EasyMock.verify(binding); - - } - - public void testIsSystem() { - Reference service = new ReferenceImpl(null, null, null, true); - assertTrue(service.isSystem()); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ServiceImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ServiceImplTestCase.java deleted file mode 100644 index 88d40a50eb..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/ServiceImplTestCase.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.composite; - -import org.apache.tuscany.spi.component.Service; -import org.apache.tuscany.spi.component.ServiceBinding; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class ServiceImplTestCase extends TestCase { - - public void testStart() { - ServiceBinding binding = EasyMock.createMock(ServiceBinding.class); - binding.setService(EasyMock.isA(Service.class)); - binding.start(); - EasyMock.replay(binding); - Service service = new ServiceImpl(null, null, null); - service.addServiceBinding(binding); - service.start(); - EasyMock.verify(binding); - - } - - public void testStop() { - ServiceBinding binding = EasyMock.createMock(ServiceBinding.class); - binding.setService(EasyMock.isA(Service.class)); - binding.stop(); - EasyMock.replay(binding); - Service service = new ServiceImpl(null, null, null); - service.addServiceBinding(binding); - service.stop(); - EasyMock.verify(binding); - - } - - public void testIsSystem() { - Service service = new ServiceImpl(null, null, null, null, true); - assertTrue(service.isSystem()); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/SystemComponentBuilderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/SystemComponentBuilderTestCase.java deleted file mode 100644 index 4645075a7a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/SystemComponentBuilderTestCase.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.composite; - -import java.lang.reflect.Method; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.implementation.java.ConstructorDefinition; -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.model.ComponentDefinition; -import org.apache.tuscany.spi.model.PropertyValue; -import org.apache.tuscany.spi.model.Scope; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.event.CompositeStart; -import org.apache.tuscany.core.component.event.CompositeStop; -import org.apache.tuscany.core.component.scope.CompositeScopeContainer; -import org.apache.tuscany.core.implementation.system.builder.SystemComponentBuilder; -import org.apache.tuscany.core.implementation.system.model.SystemImplementation; -import org.apache.tuscany.core.injection.SingletonObjectFactory; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class SystemComponentBuilderTestCase extends TestCase { - - CompositeComponent parent; - DeploymentContext deploymentContext; - SystemComponentBuilder builder = new SystemComponentBuilder(); - CompositeScopeContainer container; - - /** - * Verifies lifecycle callbacks are made - */ - public void testLifecycleBuild() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - type.setInitLevel(50); - Method initMethod = FooImpl.class.getMethod("init"); - initMethod.setAccessible(true); - type.setInitMethod(initMethod); - Method destroyMethod = FooImpl.class.getMethod("destroy"); - destroyMethod.setAccessible(true); - type.setDestroyMethod(destroyMethod); - type.setImplementationScope(Scope.COMPOSITE); - ConstructorDefinition<FooImpl> ctorDef = new ConstructorDefinition<FooImpl>(FooImpl.class.getConstructor()); - type.setConstructorDefinition(ctorDef); - SystemImplementation impl = new SystemImplementation(); - impl.setComponentType(type); - impl.setImplementationClass(FooImpl.class); - ComponentDefinition<SystemImplementation> definition = new ComponentDefinition<SystemImplementation>(impl); - AtomicComponent component = builder.build(parent, definition, deploymentContext); - component.setScopeContainer(container); - component.start(); - container.onEvent(new CompositeStart(this, null)); - FooImpl foo = (FooImpl) component.getTargetInstance(); - assertTrue(foo.initialized); - container.onEvent(new CompositeStop(this, null)); - assertTrue(foo.destroyed); - } - - /** - * Verifies properties are built properly - */ - public void testPropertyBuild() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - type.setInitLevel(50); - Method initMethod = FooImpl.class.getMethod("init"); - initMethod.setAccessible(true); - type.setInitMethod(initMethod); - Method destroyMethod = FooImpl.class.getMethod("destroy"); - destroyMethod.setAccessible(true); - type.setDestroyMethod(destroyMethod); - type.setImplementationScope(Scope.COMPOSITE); - JavaMappedProperty mappedProp = new JavaMappedProperty(); - mappedProp.setName("prop"); - Method propMethod = FooImpl.class.getMethod("setProp", String.class); - propMethod.setAccessible(true); - mappedProp.setMember(propMethod); - type.add(mappedProp); - ConstructorDefinition<FooImpl> ctorDef = new ConstructorDefinition<FooImpl>(FooImpl.class.getConstructor()); - type.setConstructorDefinition(ctorDef); - SystemImplementation impl = new SystemImplementation(); - impl.setComponentType(type); - impl.setImplementationClass(FooImpl.class); - ComponentDefinition<SystemImplementation> definition = new ComponentDefinition<SystemImplementation>(impl); - PropertyValue<String> propVal = new PropertyValue<String>(); - propVal.setName("prop"); - propVal.setValueFactory(new SingletonObjectFactory<String>("value")); - definition.add(propVal); - AtomicComponent component = builder.build(parent, definition, deploymentContext); - component.setScopeContainer(container); - component.start(); - FooImpl foo = (FooImpl) component.getTargetInstance(); - assertEquals("value", foo.prop); - container.onEvent(new CompositeStop(this, null)); - } - - protected void setUp() throws Exception { - super.setUp(); - parent = EasyMock.createNiceMock(CompositeComponent.class); - container = new CompositeScopeContainer(null); - container.start(); - deploymentContext = EasyMock.createMock(DeploymentContext.class); - EasyMock.expect(deploymentContext.getCompositeScope()).andReturn(container).atLeastOnce(); - EasyMock.replay(deploymentContext); - } - - private static interface Foo { - - } - - private static class FooImpl implements Foo { - private boolean initialized; - private boolean destroyed; - private String prop; - private Foo ref; - - public FooImpl() { - } - - public void init() { - if (initialized) { - fail(); - } - initialized = true; - } - - public void destroy() { - if (destroyed) { - fail(); - } - destroyed = true; - } - - public boolean isInitialized() { - return initialized; - } - - public String getProp() { - return prop; - } - - public void setProp(String prop) { - this.prop = prop; - } - - public Foo getRef() { - return ref; - } - - public void setRef(Foo ref) { - this.ref = ref; - } - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/SystemSingletonAtomicComponentTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/SystemSingletonAtomicComponentTestCase.java deleted file mode 100644 index 9c482b994f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/composite/SystemSingletonAtomicComponentTestCase.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.composite; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.spi.component.TargetException; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class SystemSingletonAtomicComponentTestCase extends TestCase { - - public void testGetInstance() throws TargetException { - FooImpl foo = new FooImpl(); - SystemSingletonAtomicComponent<Foo, FooImpl> component = - new SystemSingletonAtomicComponent<Foo, FooImpl>("foo", null, Foo.class, foo); - assertEquals(foo, component.getTargetInstance()); - } - - public void testGetInstanceMultipleServices() throws TargetException { - FooImpl foo = new FooImpl(); - List<Class<?>> services = new ArrayList<Class<?>>(); - services.add(Foo.class); - services.add(Bar.class); - SystemSingletonAtomicComponent<Foo, FooImpl> component = - new SystemSingletonAtomicComponent<Foo, FooImpl>("foo", null, services, foo); - assertEquals(foo, component.getTargetInstance()); - } - - private interface Foo { - - } - - private interface Bar { - - } - - private class FooImpl implements Foo, Bar { - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentMetadataInjectionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentMetadataInjectionTestCase.java deleted file mode 100644 index 5186119345..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentMetadataInjectionTestCase.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.java; - -import junit.framework.TestCase; - -/** - * Tests SCA metadata such as <code>@ComponentName</code> and <code>@SCAObject</code> are handled properly - * - * @version $Rev$ $Date$ - */ -public class JavaAtomicComponentMetadataInjectionTestCase extends TestCase { - - public void testComponentNameSet() throws Exception { - // TODO implement - } - - public void testCompositeContextSet() throws Exception { - // TODO implement - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentNegativeMetadataTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentNegativeMetadataTestCase.java deleted file mode 100644 index dfd62c8c53..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaAtomicComponentNegativeMetadataTestCase.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.java; - -import junit.framework.TestCase; - - -/** - * Performs rudimentary negative testing by using malformed metadata on a POJO - * - * @version $Rev $Date - */ -public class JavaAtomicComponentNegativeMetadataTestCase extends TestCase { - - /** - * Tests that a pojo with <code>@ComponentName</code> specified on a non-String type generates an error. - * <p/> - * <strong>NB:</strong> the test assumes an error with a message containing "@ComponentName" is generated - */ - public void testBadNameType() throws Exception { - // TODO implement - } - - /** - * Tests that a pojo with <code>@Context</code> specified on a non-CompositeContext type generates an error. - * <p/> - * <strong>NB:</strong> the test assumes an error with a message containing "@Context" is generated - */ - public void testContextType() throws Exception { - // TODO implement - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaBuilderPropertyTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaBuilderPropertyTestCase.java deleted file mode 100644 index d484a5d944..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaBuilderPropertyTestCase.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.java; - -import org.apache.tuscany.spi.ObjectFactory; -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.component.ScopeRegistry; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.implementation.java.ConstructorDefinition; -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.model.ComponentDefinition; -import org.apache.tuscany.spi.model.ComponentTypeReferenceDefinition; -import org.apache.tuscany.spi.model.PropertyValue; -import org.apache.tuscany.spi.model.AbstractReferenceDefinition; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.model.ServiceDefinition; - -import junit.framework.TestCase; -import org.apache.tuscany.core.injection.SingletonObjectFactory; -import org.easymock.EasyMock; - -/** - * Verifies that the java component builder handles configured properties correctly - * - * @version $Rev$ $Date$ - */ -public class JavaBuilderPropertyTestCase extends TestCase { - private DeploymentContext deploymentContext; - private CompositeComponent parent; - private ScopeRegistry registry; - - @SuppressWarnings("unchecked") - public void testPropertyHandling() throws Exception { - JavaComponentBuilder builder = new JavaComponentBuilder(); - builder.setScopeRegistry(registry); - PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, JavaMappedProperty<?>> type = - new PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, JavaMappedProperty<?>>(); - JavaMappedProperty<String> property = new JavaMappedProperty<String>(); - property.setName("test"); - property.setDefaultValueFactory(new SingletonObjectFactory<String>("foo")); - property.setMember(JavaBuilderPropertyTestCase.Foo.class.getMethod("setTest", String.class)); - type.add(property); - type.setConstructorDefinition(new ConstructorDefinition<Foo>(Foo.class.getConstructor((Class[]) null))); - type.setImplementationScope(Scope.STATELESS); - JavaImplementation impl = new JavaImplementation(Foo.class, type); - ComponentDefinition<JavaImplementation> definition = new ComponentDefinition<JavaImplementation>(impl); - PropertyValue propertyValue = new PropertyValue(property.getName(), property.getDefaultValueFactory()); - definition.getPropertyValues().put(property.getName(), propertyValue); - AtomicComponent component = builder.build(parent, definition, deploymentContext); - JavaBuilderPropertyTestCase.Foo foo = (JavaBuilderPropertyTestCase.Foo) component.createInstance(); - assertEquals("foo", foo.getTest()); - } - - public void testIntPropertyHandling() throws Exception { - JavaComponentBuilder builder = new JavaComponentBuilder(); - builder.setScopeRegistry(registry); - PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, JavaMappedProperty<?>> type = - new PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, JavaMappedProperty<?>>(); - JavaMappedProperty<Integer> property = new JavaMappedProperty<Integer>(); - property.setName("test"); - property.setDefaultValueFactory(new SingletonObjectFactory<Integer>(1)); - property.setMember(JavaBuilderPropertyTestCase.FooInt.class.getMethod("setTest", Integer.TYPE)); - type.add(property); - type.setConstructorDefinition(new ConstructorDefinition<FooInt>(FooInt.class.getConstructor((Class[]) null))); - type.setImplementationScope(Scope.STATELESS); - JavaImplementation impl = new JavaImplementation(Foo.class, type); - ComponentDefinition<JavaImplementation> definition = new ComponentDefinition<JavaImplementation>(impl); - ObjectFactory<?> defaultValueFactory = property.getDefaultValueFactory(); - PropertyValue<Integer> propertyValue = - new PropertyValue<Integer>(property.getName(), defaultValueFactory); - definition.getPropertyValues().put(property.getName(), propertyValue); - AtomicComponent component = builder.build(parent, definition, deploymentContext); - FooInt foo = (FooInt) component.createInstance(); - assertEquals(1, foo.getTest()); - } - - protected void setUp() throws Exception { - super.setUp(); - deploymentContext = EasyMock.createMock(DeploymentContext.class); - EasyMock.replay(deploymentContext); - parent = EasyMock.createNiceMock(CompositeComponent.class); - ScopeContainer mockContainer = EasyMock.createNiceMock(ScopeContainer.class); - EasyMock.replay(mockContainer); - registry = EasyMock.createMock(ScopeRegistry.class); - EasyMock.expect(registry.getScopeContainer(EasyMock.isA(Scope.class))).andReturn(mockContainer); - EasyMock.replay(registry); - } - - private static class Foo { - private String test; - - public Foo() { - } - - public String getTest() { - return test; - } - - public void setTest(String test) { - this.test = test; - } - } - - private static class FooInt { - private int test; - - public FooInt() { - } - - public int getTest() { - return test; - } - - public void setTest(int test) { - this.test = test; - } - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderConversationIDTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderConversationIDTestCase.java deleted file mode 100644 index 5c83af0e7d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderConversationIDTestCase.java +++ /dev/null @@ -1,80 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tuscany.core.implementation.java;
-
-import java.lang.reflect.Field;
-
-import org.apache.tuscany.core.component.WorkContextImpl;
-import org.apache.tuscany.spi.component.CompositeComponent;
-import org.apache.tuscany.spi.component.ScopeContainer;
-import org.apache.tuscany.spi.component.ScopeRegistry;
-import org.apache.tuscany.spi.component.WorkContext;
-import org.apache.tuscany.spi.implementation.java.ConstructorDefinition;
-import org.apache.tuscany.spi.implementation.java.PojoComponentType;
-import org.apache.tuscany.spi.model.ComponentDefinition;
-import org.apache.tuscany.spi.model.Scope;
-
-import junit.framework.TestCase;
-import org.easymock.EasyMock;
-import org.osoa.sca.annotations.ConversationID;
-
-/**
- * @version $Rev: 473859 $ $Date: 2006-11-11 22:31:55 -0500 (Sat, 11 Nov 2006) $
- */
-public class JavaComponentBuilderConversationIDTestCase extends TestCase {
-
- @SuppressWarnings("unchecked")
- public void testResourceInjection() throws Exception {
- ScopeContainer container = EasyMock.createNiceMock(ScopeContainer.class);
- ScopeRegistry registry = EasyMock.createMock(ScopeRegistry.class);
- EasyMock.expect(registry.getScopeContainer(Scope.STATELESS)).andReturn(container);
- EasyMock.replay(registry);
- JavaComponentBuilder builder = new JavaComponentBuilder();
- builder.setScopeRegistry(registry);
- WorkContext workContext = new WorkContextImpl();
- workContext.setIdentifier(Scope.CONVERSATION, "convID");
- builder.setWorkContext(workContext);
-
- ConstructorDefinition<Foo> ctorDef = new ConstructorDefinition<Foo>(Foo.class.getConstructor());
- PojoComponentType type = new PojoComponentType();
- Field field = Foo.class.getDeclaredField("conversationID");
- type.setConversationIDMember(field);
- type.setImplementationScope(Scope.STATELESS);
- type.setConstructorDefinition(ctorDef);
-
- JavaImplementation impl = new JavaImplementation(Foo.class, type);
- ComponentDefinition<JavaImplementation> definition = new ComponentDefinition<JavaImplementation>("foo", impl);
- CompositeComponent parent = EasyMock.createMock(CompositeComponent.class);
- JavaAtomicComponent component = (JavaAtomicComponent) builder.build(parent, definition, null);
- Foo foo = (Foo) component.createInstance();
- assertEquals("convID", foo.conversationID);
- }
-
- private static class Foo {
-
- @ConversationID
- protected String conversationID;
-
- public Foo() {
- }
-
- }
-}
-
-
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderMetadataTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderMetadataTestCase.java deleted file mode 100644 index e4adae73d3..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderMetadataTestCase.java +++ /dev/null @@ -1,112 +0,0 @@ -package org.apache.tuscany.core.implementation.java; - -import java.lang.reflect.Constructor; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.idl.java.JavaServiceContract; -import org.apache.tuscany.spi.implementation.java.ConstructorDefinition; -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.model.ComponentDefinition; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.model.ServiceContract; - -import junit.framework.TestCase; -import org.apache.tuscany.core.implementation.composite.CompositeComponentImpl; -import org.apache.tuscany.core.mock.component.Source; -import org.apache.tuscany.core.mock.component.SourceImpl; -import org.apache.tuscany.core.mock.component.Target; -import org.easymock.EasyMock; - -/** - * Verifies component type metadata is properly applied to the component - * - * @version $$Rev$$ $$Date$$ - */ -public class JavaComponentBuilderMetadataTestCase extends TestCase { - private DeploymentContext deploymentContext; - private Constructor<SourceImpl> constructor; - private CompositeComponent parent; - private PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type; - private ComponentDefinition<JavaImplementation> definition; - private ScopeContainer scopeContainer; - - public void testInitLevel() throws Exception { - type.setInitLevel(1); - JavaComponentBuilder builder = new JavaComponentBuilder(); - JavaAtomicComponent component = (JavaAtomicComponent) builder.build(parent, definition, deploymentContext); - assertEquals(1, component.getInitLevel()); - } - - public void testMaxAge() throws Exception { - type.setMaxAge(100); - JavaComponentBuilder builder = new JavaComponentBuilder(); - JavaAtomicComponent component = (JavaAtomicComponent) builder.build(parent, definition, deploymentContext); - assertEquals(100, component.getMaxAge()); - } - - public void testMaxIdleTime() throws Exception { - type.setMaxIdleTime(100); - JavaComponentBuilder builder = new JavaComponentBuilder(); - JavaAtomicComponent component = (JavaAtomicComponent) builder.build(parent, definition, deploymentContext); - assertEquals(100, component.getMaxIdleTime()); - } - - public void testNoMaxAgeNoMaxIdleTime() throws Exception { - JavaComponentBuilder builder = new JavaComponentBuilder(); - JavaAtomicComponent component = (JavaAtomicComponent) builder.build(parent, definition, deploymentContext); - assertEquals(-1, component.getMaxAge()); - assertEquals(-1, component.getMaxIdleTime()); - } - - public void testScope() throws Exception { - JavaComponentBuilder builder = new JavaComponentBuilder(); - JavaAtomicComponent component = (JavaAtomicComponent) builder.build(parent, definition, deploymentContext); - component.setScopeContainer(scopeContainer); - assertEquals(Scope.COMPOSITE, component.getScope()); - } - - protected void setUp() throws Exception { - super.setUp(); - parent = new CompositeComponentImpl(null, null, null, null); - constructor = SourceImpl.class.getConstructor((Class[]) null); - createDeploymentContext(); - createComponentDefinitionAndType(); - } - - - private void createDeploymentContext() { - scopeContainer = EasyMock.createMock(ScopeContainer.class); - scopeContainer.start(); - scopeContainer.stop(); - scopeContainer.register(EasyMock.isA(AtomicComponent.class)); - EasyMock.expectLastCall().atLeastOnce(); - EasyMock.expect(scopeContainer.getScope()).andReturn(Scope.COMPOSITE).atLeastOnce(); - EasyMock.replay(scopeContainer); - deploymentContext = EasyMock.createMock(DeploymentContext.class); - EasyMock.replay(deploymentContext); - } - - private void createComponentDefinitionAndType() throws Exception { - type = new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - type.setImplementationScope(Scope.COMPOSITE); - JavaMappedReference reference = new JavaMappedReference(); - reference.setName("target"); - reference.setMember(SourceImpl.class.getMethod("setTarget", Target.class)); - type.add(reference); - ServiceContract<?> contract = new JavaServiceContract(Source.class); - JavaMappedService serviceDefinition = new JavaMappedService(); - serviceDefinition.setName("Source"); - serviceDefinition.setServiceContract(contract); - type.add(serviceDefinition); - type.setConstructorDefinition(new ConstructorDefinition<SourceImpl>(constructor)); - JavaImplementation sourceImpl = new JavaImplementation(SourceImpl.class, type); - definition = new ComponentDefinition<JavaImplementation>(sourceImpl); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderReferenceTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderReferenceTestCase.java deleted file mode 100644 index c9d1f93a57..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderReferenceTestCase.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.java; - -import java.lang.reflect.Constructor; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.SCAObject; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.idl.java.JavaServiceContract; -import org.apache.tuscany.spi.implementation.java.ConstructorDefinition; -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.model.ComponentDefinition; -import org.apache.tuscany.spi.model.InteractionScope; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.WireService; - -import junit.framework.TestCase; -import org.apache.tuscany.core.implementation.composite.CompositeComponentImpl; -import org.apache.tuscany.core.mock.component.Source; -import org.apache.tuscany.core.mock.component.SourceImpl; -import org.apache.tuscany.core.mock.component.Target; -import org.apache.tuscany.core.wire.jdk.JDKWireService; -import org.easymock.EasyMock; -import org.easymock.IAnswer; - -/** - * @version $$Rev$$ $$Date$$ - */ -public class JavaComponentBuilderReferenceTestCase extends TestCase { - private DeploymentContext deploymentContext; - private WireService wireService; - private Constructor<SourceImpl> constructor; - private CompositeComponent parent; - private OutboundWire wire; - private ScopeContainer scopeContainer; - - public void testBuildReference() throws Exception { - - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> sourceType = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - sourceType.setImplementationScope(Scope.COMPOSITE); - JavaMappedReference reference = new JavaMappedReference(); - reference.setName("target"); - reference.setMember(SourceImpl.class.getMethod("setTarget", Target.class)); - sourceType.add(reference); - ServiceContract<?> contract = new JavaServiceContract(Source.class); - JavaMappedService serviceDefinition = new JavaMappedService(); - serviceDefinition.setName("Source"); - serviceDefinition.setServiceContract(contract); - sourceType.add(serviceDefinition); - sourceType.setConstructorDefinition(new ConstructorDefinition<SourceImpl>(constructor)); - JavaImplementation sourceImpl = new JavaImplementation(SourceImpl.class, sourceType); - ComponentDefinition<JavaImplementation> definition = new ComponentDefinition<JavaImplementation>(sourceImpl); - - JavaComponentBuilder builder = new JavaComponentBuilder(); - builder.setWireService(wireService); - JavaAtomicComponent component = (JavaAtomicComponent) builder.build(parent, definition, deploymentContext); - component.setScopeContainer(scopeContainer); - component.addOutboundWire(wire); - deploymentContext.getCompositeScope().start(); - component.start(); - - Source source = (Source) component.getTargetInstance(); - assertNotNull(source.getTarget()); - component.stop(); - } - - protected void setUp() throws Exception { - super.setUp(); - wireService = new JDKWireService(); - parent = new CompositeComponentImpl(null, null, null, null); - constructor = SourceImpl.class.getConstructor((Class[]) null); - createDeploymentContext(); - createWire(); - } - - - private void createDeploymentContext() throws Exception { - scopeContainer = EasyMock.createMock(ScopeContainer.class); - scopeContainer.start(); - scopeContainer.stop(); - scopeContainer.register(EasyMock.isA(AtomicComponent.class)); - EasyMock.expectLastCall().atLeastOnce(); - EasyMock.expect(scopeContainer.getScope()).andReturn(Scope.COMPOSITE).atLeastOnce(); - scopeContainer.getInstance(EasyMock.isA(AtomicComponent.class)); - EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() { - private Map<AtomicComponent, Object> cache = new HashMap<AtomicComponent, Object>(); - - public Object answer() throws Throwable { - AtomicComponent component = (AtomicComponent) EasyMock.getCurrentArguments()[0]; - Object instance = cache.get(component); - if (instance == null) { - instance = component.createInstance(); - cache.put(component, instance); - } - return instance; - } - }).anyTimes(); - EasyMock.replay(scopeContainer); - deploymentContext = EasyMock.createMock(DeploymentContext.class); - EasyMock.expect(deploymentContext.getCompositeScope()).andReturn(scopeContainer).atLeastOnce(); - EasyMock.replay(deploymentContext); - } - - private void createWire() { - SCAObject scaObject = EasyMock.createNiceMock(SCAObject.class); - Map<Operation<?>, OutboundInvocationChain> chains = Collections.emptyMap(); - wire = EasyMock.createMock(OutboundWire.class); - EasyMock.expect(wire.getReferenceName()).andReturn("target").atLeastOnce(); - EasyMock.expect(wire.getInvocationChains()).andReturn(chains).atLeastOnce(); - EasyMock.expect(wire.isOptimizable()).andReturn(false); - JavaServiceContract targetContract = new JavaServiceContract(Target.class); - targetContract.setInteractionScope(InteractionScope.NONCONVERSATIONAL); - EasyMock.expect(wire.getServiceContract()).andReturn(targetContract).atLeastOnce(); - EasyMock.expect(wire.getContainer()).andReturn(scaObject).atLeastOnce(); - EasyMock.replay(wire); - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderResourceTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderResourceTestCase.java deleted file mode 100644 index f5ee684e0b..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentBuilderResourceTestCase.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.java; - -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.component.ScopeRegistry; -import org.apache.tuscany.spi.implementation.java.ConstructorDefinition; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.implementation.java.Resource; -import org.apache.tuscany.spi.model.ComponentDefinition; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.wire.InboundWire; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class JavaComponentBuilderResourceTestCase extends TestCase { - - @SuppressWarnings("unchecked") - public void testResourceInjection() throws Exception { - ScopeContainer container = EasyMock.createNiceMock(ScopeContainer.class); - ScopeRegistry registry = EasyMock.createMock(ScopeRegistry.class); - EasyMock.expect(registry.getScopeContainer(Scope.STATELESS)).andReturn(container); - EasyMock.replay(registry); - JavaComponentBuilder builder = new JavaComponentBuilder(); - builder.setScopeRegistry(registry); - ConstructorDefinition<Foo> ctorDef = new ConstructorDefinition<Foo>(Foo.class.getConstructor()); - PojoComponentType type = new PojoComponentType(); - Resource resource = new Resource(); - resource.setType(String.class); - resource.setName("resource"); - resource.setMember(Foo.class.getDeclaredField("resource")); - type.add(resource); - type.setImplementationScope(Scope.STATELESS); - type.setConstructorDefinition(ctorDef); - JavaImplementation impl = new JavaImplementation(Foo.class, type); - ComponentDefinition<JavaImplementation> definition = new ComponentDefinition<JavaImplementation>("foo", impl); - InboundWire resourceWire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(resourceWire.getTargetService()).andReturn("result"); - EasyMock.replay(resourceWire); - - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(parent.resolveSystemAutowire(String.class)).andReturn(resourceWire); - EasyMock.replay(parent); - JavaAtomicComponent component = (JavaAtomicComponent) builder.build(parent, definition, null); - Foo foo = (Foo) component.createInstance(); - assertEquals("result", foo.resource); - EasyMock.verify(parent); - } - - private static class Foo { - - protected String resource; - - public Foo() { - } - - } -} - - diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentTypeLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentTypeLoaderTestCase.java deleted file mode 100644 index ef74c86d2e..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaComponentTypeLoaderTestCase.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.java; - -import java.net.URL; - -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.implementation.java.IntrospectionRegistry; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.loader.LoaderRegistry; - -import junit.framework.TestCase; -import org.easymock.EasyMock; -import org.easymock.IAnswer; - -/** - * @version $Rev$ $Date$ - */ -public class JavaComponentTypeLoaderTestCase extends TestCase { - - @SuppressWarnings("unchecked") - public void testPojoComponentTypeCreatedForIntrospection() throws Exception { - IntrospectionRegistry registry = EasyMock.createMock(IntrospectionRegistry.class); - registry.introspect( - (CompositeComponent) EasyMock.isNull(), - (Class) EasyMock.isNull(), - EasyMock.isA(PojoComponentType.class), - (DeploymentContext) EasyMock.isNull()); - EasyMock.expectLastCall().andStubAnswer(new IAnswer() { - public Object answer() throws Throwable { - return EasyMock.getCurrentArguments()[2]; - } - }); - EasyMock.replay(registry); - JavaComponentTypeLoader loader = new JavaComponentTypeLoader(null, registry); - loader.loadByIntrospection(null, new JavaImplementation(), null); - EasyMock.verify(registry); - } - - @SuppressWarnings("unchecked") - public void testPojoComponentTypeCreatedForSideFileLoadAndReturned() throws Exception { - LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class); - registry.load( - (CompositeComponent) EasyMock.isNull(), - EasyMock.isA(PojoComponentType.class), - (URL) EasyMock.isNull(), - EasyMock.eq(PojoComponentType.class), - (DeploymentContext) EasyMock.isNull()); - EasyMock.expectLastCall().andStubAnswer(new IAnswer() { - public Object answer() throws Throwable { - return EasyMock.getCurrentArguments()[1]; - } - }); - EasyMock.replay(registry); - JavaComponentTypeLoader loader = new JavaComponentTypeLoader(registry, null); - assertEquals(PojoComponentType.class, loader.loadFromSidefile(null, null, null).getClass()); - EasyMock.verify(registry); - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaReferenceWireTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaReferenceWireTestCase.java deleted file mode 100644 index 0fe6df8b6b..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaReferenceWireTestCase.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.java; - -import java.lang.reflect.Constructor; -import java.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.component.TargetException; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.WireService; - -import junit.framework.TestCase; -import org.apache.tuscany.core.implementation.PojoConfiguration; -import org.apache.tuscany.core.injection.PojoObjectFactory; -import org.easymock.EasyMock; -import org.easymock.IAnswer; - -/** - * Validates wiring from a Java atomic context - * - * @version $$Rev$$ $$Date$$ - */ -public class JavaReferenceWireTestCase extends TestCase { - - @SuppressWarnings({"unchecked"}) - public void testReferenceSet() throws Exception { - ScopeContainer scope = createMock(); - scope.start(); - final Target target = new TargetImpl(); - PojoConfiguration configuration = new PojoConfiguration(); - configuration.addReferenceSite("target", SourceImpl.class.getMethod("setTarget", Target.class)); - Constructor<SourceImpl> ctr = SourceImpl.class.getConstructor(); - configuration.setInstanceFactory(new PojoObjectFactory<SourceImpl>(ctr)); - OutboundWire wire = EasyMock.createMock(OutboundWire.class); - wire.getInvocationChains(); - EasyMock.expectLastCall().andReturn(new HashMap<Operation<?>, OutboundInvocationChain>()).atLeastOnce(); - EasyMock.expect(wire.getReferenceName()).andReturn("target").atLeastOnce(); - EasyMock.expect(wire.isOptimizable()).andReturn(false); - EasyMock.replay(wire); - WireService service = EasyMock.createMock(WireService.class); - EasyMock.expect(service.createProxy(EasyMock.eq(Target.class), EasyMock.eq(wire), EasyMock.isA(Map.class))) - .andAnswer(new IAnswer<Target>() { - public Target answer() throws Throwable { - OutboundWire wire = (OutboundWire) EasyMock.getCurrentArguments()[1]; - wire.getInvocationChains(); - return target; - } - - }).atLeastOnce(); - EasyMock.replay(service); - configuration.setWireService(service); - configuration.setName("source"); - JavaAtomicComponent component = new JavaAtomicComponent(configuration); - component.setScopeContainer(scope); - component.addOutboundWire(wire); - component.start(); - Source source = (Source) component.getTargetInstance(); - assertSame(target, source.getTarget()); - scope.stop(); - EasyMock.verify(wire); - EasyMock.verify(scope); - EasyMock.verify(service); - } - - private ScopeContainer createMock() throws TargetException { - ScopeContainer scope = EasyMock.createMock(ScopeContainer.class); - scope.start(); - scope.stop(); - scope.register(EasyMock.isA(AtomicComponent.class)); - EasyMock.expectLastCall().atLeastOnce(); - EasyMock.expect(scope.getScope()).andReturn(Scope.COMPOSITE).atLeastOnce(); - scope.getInstance(EasyMock.isA(AtomicComponent.class)); - EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() { - private Map<AtomicComponent, Object> cache = new HashMap<AtomicComponent, Object>(); - - public Object answer() throws Throwable { - AtomicComponent component = (AtomicComponent) EasyMock.getCurrentArguments()[0]; - Object instance = cache.get(component); - if (instance == null) { - instance = component.createInstance(); - cache.put(component, instance); - } - return instance; - } - }).anyTimes(); - EasyMock.replay(scope); - return scope; - } - - private interface Source { - Target getTarget(); - } - - private static class SourceImpl implements Source { - private Target target; - - public SourceImpl() { - } - - public Target getTarget() { - return target; - } - - public void setTarget(Target target) { - this.target = target; - } - } - - private interface Target { - - String getString(); - - void setString(String val); - } - - private static class TargetImpl implements Target { - private String string; - - public TargetImpl() { - } - - public String getString() { - return string; - } - - public void setString(String string) { - this.string = string; - } - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerBasicInvocationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerBasicInvocationTestCase.java deleted file mode 100644 index 30f7948673..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerBasicInvocationTestCase.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.java; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.extension.ExecutionMonitor; -import org.apache.tuscany.spi.wire.InboundWire; -import static org.apache.tuscany.spi.wire.TargetInvoker.NONE; -import org.apache.tuscany.spi.model.Scope; - -import junit.framework.TestCase; -import org.easymock.classextension.EasyMock; - -public class JavaTargetInvokerBasicInvocationTestCase extends TestCase { - private Method echoMethod; - private Method arrayMethod; - private Method nullParamMethod; - private Method primitiveMethod; - private Method checkedMethod; - private Method runtimeMethod; - private InboundWire wire; - private WorkContext context; - private ExecutionMonitor monitor; - - public JavaTargetInvokerBasicInvocationTestCase(String arg0) { - super(arg0); - } - - public void setUp() throws Exception { - echoMethod = TestBean.class.getDeclaredMethod("echo", String.class); - arrayMethod = TestBean.class.getDeclaredMethod("arrayEcho", String[].class); - nullParamMethod = TestBean.class.getDeclaredMethod("nullParam", (Class[]) null); - primitiveMethod = TestBean.class.getDeclaredMethod("primitiveEcho", Integer.TYPE); - checkedMethod = TestBean.class.getDeclaredMethod("checkedException", (Class[]) null); - runtimeMethod = TestBean.class.getDeclaredMethod("runtimeException", (Class[]) null); - wire = EasyMock.createNiceMock(InboundWire.class); - context = EasyMock.createNiceMock(WorkContext.class); - monitor = EasyMock.createNiceMock(ExecutionMonitor.class); - assertNotNull(echoMethod); - assertNotNull(checkedMethod); - assertNotNull(runtimeMethod); - } - - public void testObjectInvoke() throws Throwable { - TestBean bean = new TestBean(); - JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(component.getTargetInstance()).andReturn(bean); - EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE); - EasyMock.replay(component); - JavaTargetInvoker invoker = new JavaTargetInvoker(echoMethod, component, wire, context, monitor); - Object ret = invoker.invokeTarget("foo", NONE); - assertEquals("foo", ret); - } - - public void testArrayInvoke() throws Throwable { - TestBean bean = new TestBean(); - JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(component.getTargetInstance()).andReturn(bean); - EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE); - EasyMock.replay(component); - JavaTargetInvoker invoker = new JavaTargetInvoker(arrayMethod, component, wire, context, monitor); - - String[] args = new String[]{"foo", "bar"}; - Object ret = invoker.invokeTarget(new Object[]{args}, NONE); - String[] retA = (String[]) ret; - assertNotNull(retA); - assertEquals(2, retA.length); - assertEquals("foo", retA[0]); - assertEquals("bar", retA[1]); - } - - public void testNullInvoke() throws Throwable { - TestBean bean = new TestBean(); - JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(component.getTargetInstance()).andReturn(bean); - EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE); - EasyMock.replay(component); - JavaTargetInvoker invoker = new JavaTargetInvoker(nullParamMethod, component, wire, context, monitor); - Object ret = invoker.invokeTarget(null, NONE); - String retS = (String) ret; - assertEquals("foo", retS); - } - - public void testPrimitiveInvoke() throws Throwable { - TestBean bean = new TestBean(); - JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(component.getTargetInstance()).andReturn(bean); - EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE); - EasyMock.replay(component); - JavaTargetInvoker invoker = new JavaTargetInvoker(primitiveMethod, component, wire, context, monitor); - Object ret = invoker.invokeTarget(new Integer[]{1}, NONE); - Integer retI = (Integer) ret; - assertEquals(1, retI.intValue()); - } - - public void testInvokeCheckedException() throws Throwable { - TestBean bean = new TestBean(); - JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(component.getTargetInstance()).andReturn(bean); - EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE); - EasyMock.replay(component); - JavaTargetInvoker invoker = new JavaTargetInvoker(checkedMethod, component, wire, context, monitor); - try { - invoker.invokeTarget(null, NONE); - } catch (InvocationTargetException e) { - if (e.getCause() != null && TestException.class.equals(e.getCause().getClass())) { - return; - } - } catch (Throwable e) { - //ok - } - fail(TestException.class.getName() + " should have been thrown"); - } - - public void testInvokeRuntimeException() throws Throwable { - TestBean bean = new TestBean(); - JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(component.getTargetInstance()).andReturn(bean); - EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE); - EasyMock.replay(component); - JavaTargetInvoker invoker = new JavaTargetInvoker(runtimeMethod, component, wire, context, monitor); - try { - invoker.invokeTarget(null, NONE); - } catch (InvocationTargetException e) { - if (e.getCause() != null && e.getCause() instanceof TestRuntimeException) { - return; - } - } - fail(TestException.class.getName() + " should have been thrown"); - } - - private class TestBean { - - public String echo(String msg) throws Exception { - assertEquals("foo", msg); - return msg; - } - - public String[] arrayEcho(String[] msg) throws Exception { - assertNotNull(msg); - assertEquals(2, msg.length); - assertEquals("foo", msg[0]); - assertEquals("bar", msg[1]); - return msg; - } - - public String nullParam() throws Exception { - return "foo"; - } - - public int primitiveEcho(int i) throws Exception { - return i; - } - - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerMediationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerMediationTestCase.java deleted file mode 100644 index 936673d0a6..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerMediationTestCase.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.java; - -import java.lang.reflect.Method; - -import static org.apache.tuscany.spi.wire.TargetInvoker.NONE; -import org.apache.tuscany.spi.model.Scope; - -import junit.framework.TestCase; -import org.easymock.classextension.EasyMock; - -/** - * Tests invoking on a different interface from the one actually implemented by the target - * - * @version $Rev$ $Date$ - */ -public class JavaTargetInvokerMediationTestCase extends TestCase { - - private Method hello; - - public void setUp() throws Exception { - hello = Hello.class.getMethod("hello", String.class); - } - - public void testMediation() throws Exception { - Target target = EasyMock.createMock(Target.class); - EasyMock.expect(target.hello("foo")).andReturn("foo"); - EasyMock.replay(target); - JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(component.getTargetInstance()).andReturn(target); - EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE); - EasyMock.replay(component); - JavaTargetInvoker invoker = new JavaTargetInvoker(hello, component, null, null, null); - assertEquals("foo", invoker.invokeTarget("foo", NONE)); - } - - public interface Hello { - String hello(String message) throws Exception; - } - - private interface Target { - String hello(String message); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerNonBlockingInvocationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerNonBlockingInvocationTestCase.java deleted file mode 100644 index 25466a01ff..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerNonBlockingInvocationTestCase.java +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.java; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.extension.ExecutionMonitor; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import static org.apache.tuscany.spi.wire.TargetInvoker.NONE; - -import junit.framework.TestCase; -import org.easymock.classextension.EasyMock; - -/** - * Verifies dispatching invocations to a Java implementation instance - * - * @version $Rev$ $Date$ - */ -public class JavaTargetInvokerNonBlockingInvocationTestCase extends TestCase { - - private Method echoMethod; - private Method arrayMethod; - private Method nullParamMethod; - private Method primitiveMethod; - private Method checkedMethod; - private Method runtimeMethod; - private InboundWire wire; - private WorkContext context; - private ExecutionMonitor monitor; - - public JavaTargetInvokerNonBlockingInvocationTestCase(String arg0) { - super(arg0); - } - - public void testInvoke() throws Exception { - AsyncTarget target = EasyMock.createMock(AsyncTarget.class); - target.invoke(); - EasyMock.expectLastCall().once(); - EasyMock.replay(target); - JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(component.getTargetInstance()).andReturn(target); - EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE); - EasyMock.replay(component); - ExecutionMonitor monitor = EasyMock.createMock(ExecutionMonitor.class); - EasyMock.replay(monitor); - - Message msg = new MessageImpl(); - Object id = new Object(); - msg.setMessageId(id); - - WorkContext context = EasyMock.createMock(WorkContext.class); - context.setCurrentCorrelationId(id); - EasyMock.replay(context); - Method method = AsyncTarget.class.getMethod("invoke"); - method.setAccessible(true); - InboundWire wire = EasyMock.createMock(InboundWire.class); - JavaTargetInvoker invoker = new JavaTargetInvoker(method, component, wire, context, monitor); - invoker.invoke(msg); - EasyMock.verify(target); - EasyMock.verify(component); - } - - public void setUp() throws Exception { - echoMethod = TestBean.class.getDeclaredMethod("echo", String.class); - arrayMethod = TestBean.class.getDeclaredMethod("arrayEcho", String[].class); - nullParamMethod = TestBean.class.getDeclaredMethod("nullParam", (Class[]) null); - primitiveMethod = TestBean.class.getDeclaredMethod("primitiveEcho", Integer.TYPE); - checkedMethod = TestBean.class.getDeclaredMethod("checkedException", (Class[]) null); - runtimeMethod = TestBean.class.getDeclaredMethod("runtimeException", (Class[]) null); - wire = EasyMock.createNiceMock(InboundWire.class); - context = EasyMock.createNiceMock(WorkContext.class); - monitor = EasyMock.createNiceMock(ExecutionMonitor.class); - assertNotNull(echoMethod); - assertNotNull(checkedMethod); - assertNotNull(runtimeMethod); - } - - public void testObjectInvoke() throws Throwable { - TestBean bean = new TestBean(); - JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(component.getTargetInstance()).andReturn(bean); - EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE); - EasyMock.replay(component); - JavaTargetInvoker invoker = new JavaTargetInvoker(echoMethod, component, wire, context, monitor); - Object ret = invoker.invokeTarget("foo", NONE); - assertEquals("foo", ret); - } - - public void testArrayInvoke() throws Throwable { - TestBean bean = new TestBean(); - JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(component.getTargetInstance()).andReturn(bean); - EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE); - EasyMock.replay(component); - JavaTargetInvoker invoker = new JavaTargetInvoker(arrayMethod, component, wire, context, monitor); - - String[] args = new String[]{"foo", "bar"}; - Object ret = invoker.invokeTarget(new Object[]{args}, NONE); - String[] retA = (String[]) ret; - assertNotNull(retA); - assertEquals(2, retA.length); - assertEquals("foo", retA[0]); - assertEquals("bar", retA[1]); - } - - public void testNullInvoke() throws Throwable { - TestBean bean = new TestBean(); - JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(component.getTargetInstance()).andReturn(bean); - EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE); - EasyMock.replay(component); - JavaTargetInvoker invoker = new JavaTargetInvoker(nullParamMethod, component, wire, context, monitor); - Object ret = invoker.invokeTarget(null, NONE); - String retS = (String) ret; - assertEquals("foo", retS); - } - - public void testPrimitiveInvoke() throws Throwable { - TestBean bean = new TestBean(); - JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(component.getTargetInstance()).andReturn(bean); - EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE); - EasyMock.replay(component); - JavaTargetInvoker invoker = new JavaTargetInvoker(primitiveMethod, component, wire, context, monitor); - Object ret = invoker.invokeTarget(new Integer[]{1}, NONE); - Integer retI = (Integer) ret; - assertEquals(1, retI.intValue()); - } - - public void testInvokeCheckedException() throws Throwable { - TestBean bean = new TestBean(); - JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(component.getTargetInstance()).andReturn(bean); - EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE); - EasyMock.replay(component); - JavaTargetInvoker invoker = new JavaTargetInvoker(checkedMethod, component, wire, context, monitor); - try { - invoker.invokeTarget(null, NONE); - } catch (InvocationTargetException e) { - if (e.getCause() != null && TestException.class.equals(e.getCause().getClass())) { - return; - } - } catch (Throwable e) { - //ok - } - fail(TestException.class.getName() + " should have been thrown"); - } - - public void testInvokeRuntimeException() throws Throwable { - TestBean bean = new TestBean(); - JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(component.getTargetInstance()).andReturn(bean); - EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE); - EasyMock.replay(component); - JavaTargetInvoker invoker = new JavaTargetInvoker(runtimeMethod, component, wire, context, monitor); - try { - invoker.invokeTarget(null, NONE); - } catch (InvocationTargetException e) { - if (e.getCause() != null && e.getCause() instanceof TestRuntimeException) { - return; - } - } - fail(TestException.class.getName() + " should have been thrown"); - } - - private class TestBean { - - public String echo(String msg) throws Exception { - assertEquals("foo", msg); - return msg; - } - - public String[] arrayEcho(String[] msg) throws Exception { - assertNotNull(msg); - assertEquals(2, msg.length); - assertEquals("foo", msg[0]); - assertEquals("bar", msg[1]); - return msg; - } - - public String nullParam() throws Exception { - return "foo"; - } - - public int primitiveEcho(int i) throws Exception { - return i; - } - - 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 { - } - - public interface AsyncTarget { - void invoke(); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerSequenceTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerSequenceTestCase.java deleted file mode 100644 index acb2ed5e14..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerSequenceTestCase.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.java; - -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.TargetInvoker; - -import junit.framework.TestCase; -import org.easymock.classextension.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class JavaTargetInvokerSequenceTestCase extends TestCase { - - /** - * Verifies an invocation marked as non-conversational has an existing or new instance returned - */ - public void testNoSequence() throws Exception { - Foo foo = EasyMock.createMock(Foo.class); - foo.invoke(); - EasyMock.replay(foo); - JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(component.getTargetInstance()).andReturn(foo); - EasyMock.expect(component.getScope()).andReturn(Scope.CONVERSATION); - EasyMock.replay(component); - JavaTargetInvoker invoker = new JavaTargetInvoker(Foo.class.getMethod("invoke"), component, null, null, null); - Message msg = new MessageImpl(); - msg.setConversationSequence(TargetInvoker.NONE); - invoker.invoke(msg); - EasyMock.verify(foo); - EasyMock.verify(component); - } - - /** - * Verifies that an invocation marked as starting a conversation has a new instance returned - */ - public void testStartSequence() throws Exception { - Foo foo = EasyMock.createMock(Foo.class); - foo.invoke(); - EasyMock.replay(foo); - JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(component.getTargetInstance()).andReturn(foo); - EasyMock.expect(component.getScope()).andReturn(Scope.CONVERSATION); - EasyMock.replay(component); - JavaTargetInvoker invoker = new JavaTargetInvoker(Foo.class.getMethod("invoke"), component, null, null, null); - Message msg = new MessageImpl(); - msg.setConversationSequence(TargetInvoker.START); - invoker.invoke(msg); - EasyMock.verify(foo); - EasyMock.verify(component); - } - - /** - * Verifies that an invocation marked as continuing a conversation has an associated instance returned - */ - public void testContinueSequence() throws Exception { - Foo foo = EasyMock.createMock(Foo.class); - foo.invoke(); - EasyMock.replay(foo); - JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(component.getAssociatedTargetInstance()).andReturn(foo); - EasyMock.expect(component.getScope()).andReturn(Scope.CONVERSATION); - EasyMock.replay(component); - JavaTargetInvoker invoker = new JavaTargetInvoker(Foo.class.getMethod("invoke"), component, null, null, null); - Message msg = new MessageImpl(); - msg.setConversationSequence(TargetInvoker.CONTINUE); - invoker.invoke(msg); - EasyMock.verify(foo); - EasyMock.verify(component); - } - - /** - * Verifies that an invocation marked as ending a conversation has an associated instance returned and it is removed - * following the dispatch to the instance - */ - public void testEndSequence() throws Exception { - Foo foo = EasyMock.createMock(Foo.class); - foo.invoke(); - EasyMock.replay(foo); - JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(component.getAssociatedTargetInstance()).andReturn(foo); - EasyMock.expect(component.getScope()).andReturn(Scope.CONVERSATION); - component.removeInstance(); - component.destroy(EasyMock.eq(foo)); - EasyMock.replay(component); - JavaTargetInvoker invoker = new JavaTargetInvoker(Foo.class.getMethod("invoke"), component, null, null, null); - Message msg = new MessageImpl(); - msg.setConversationSequence(TargetInvoker.END); - invoker.invoke(msg); - EasyMock.verify(foo); - EasyMock.verify(component); - } - - - private interface Foo { - void invoke(); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerStatelessDestroyTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerStatelessDestroyTestCase.java deleted file mode 100644 index c87649f99e..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerStatelessDestroyTestCase.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.java; - -import java.lang.reflect.Method; - -import org.apache.tuscany.spi.model.Scope; - -import junit.framework.TestCase; -import org.easymock.classextension.EasyMock; - -public class JavaTargetInvokerStatelessDestroyTestCase extends TestCase { - - public JavaTargetInvokerStatelessDestroyTestCase(String arg0) { - super(arg0); - } - - public void testDestroy() throws Exception { - Method echoMethod = Echo.class.getDeclaredMethod("echo", String.class); - JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(component.getTargetInstance()).andReturn(new JavaTargetInvokerStatelessDestroyTestCase.Echo()); - EasyMock.expect(component.getScope()).andReturn(Scope.STATELESS); - component.destroy(EasyMock.isA(Echo.class)); - EasyMock.replay(component); - JavaTargetInvoker invoker = new JavaTargetInvoker(echoMethod, component, null, null, null); - invoker.setCacheable(false); - assertEquals("foo", invoker.invokeTarget("foo", JavaTargetInvoker.NONE)); - EasyMock.verify(component); - } - - public static class Echo { - public String echo(String message) throws Exception { - return message; - } - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerTestCase.java deleted file mode 100644 index 043af2d891..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/JavaTargetInvokerTestCase.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.java; - -import java.lang.reflect.Method; - -import org.apache.tuscany.spi.model.Scope; - -import junit.framework.TestCase; -import org.easymock.classextension.EasyMock; - -public class JavaTargetInvokerTestCase extends TestCase { - - public JavaTargetInvokerTestCase(String arg0) { - super(arg0); - } - - public void testInvoke() throws Exception { - Method echoMethod = Echo.class.getDeclaredMethod("echo", String.class); - JavaAtomicComponent component = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(component.getTargetInstance()).andReturn(new Echo()); - EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE); - EasyMock.replay(component); - JavaTargetInvoker invoker = new JavaTargetInvoker(echoMethod, component, null, null, null); - invoker.setCacheable(false); - assertEquals("foo", invoker.invokeTarget("foo", JavaTargetInvoker.NONE)); - EasyMock.verify(component); - } - - public static class Echo { - public String echo(String message) throws Exception { - return message; - } - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/MultiplicityTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/MultiplicityTestCase.java deleted file mode 100644 index ba478c9634..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/MultiplicityTestCase.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.java; - -import junit.framework.TestCase; - - -/** - * Tests wires that are configured with a multiplicity - * - * @version $Rev$ $Date$ - */ -public class MultiplicityTestCase extends TestCase { - - public void testMultiplicity() throws Exception { - // TODO implement - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/ResourceInjectionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/ResourceInjectionTestCase.java deleted file mode 100644 index f4cc56f158..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/ResourceInjectionTestCase.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.java; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.wire.InboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.implementation.PojoConfiguration; -import org.apache.tuscany.core.injection.PojoObjectFactory; -import org.apache.tuscany.core.injection.ResourceObjectFactory; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class ResourceInjectionTestCase extends TestCase { - - public void testResourceMemberInjection() throws Exception { - ScopeContainer containter = EasyMock.createNiceMock(ScopeContainer.class); - Constructor<Foo> ctor = Foo.class.getConstructor(); - Field field = Foo.class.getDeclaredField("resource"); - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setName("component"); - configuration.setInstanceFactory(new PojoObjectFactory<Foo>(ctor)); - configuration.addResourceSite("bar", field); - JavaAtomicComponent component = new JavaAtomicComponent(configuration); - component.setScopeContainer(containter); - - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getTargetService()).andReturn("result"); - EasyMock.replay(wire); - - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(parent.resolveSystemAutowire(EasyMock.eq(String.class))).andReturn(wire); - EasyMock.replay(parent); - ResourceObjectFactory<String> factory = new ResourceObjectFactory<String>(String.class, false, parent, null); - component.addResourceFactory("bar", factory); - - Foo foo = (Foo) component.createInstance(); - assertEquals("result", foo.resource); - EasyMock.verify(parent); - } - - - public void testResourceConstructorInjection() throws Exception { - ScopeContainer containter = EasyMock.createNiceMock(ScopeContainer.class); - Constructor<FooConstructor> ctor = FooConstructor.class.getConstructor(String.class); - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setName("component"); - configuration.setInstanceFactory(new PojoObjectFactory<FooConstructor>(ctor)); - List<String> ctorNames = new ArrayList<String>(); - ctorNames.add("bar"); - configuration.setConstructorParamNames(ctorNames); - JavaAtomicComponent component = new JavaAtomicComponent(configuration); - component.setScopeContainer(containter); - - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getTargetService()).andReturn("result"); - EasyMock.replay(wire); - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - - EasyMock.expect(parent.resolveSystemAutowire(EasyMock.eq(String.class))).andReturn(wire); - EasyMock.replay(parent); - ResourceObjectFactory<String> factory = new ResourceObjectFactory<String>(String.class, false, parent, null); - component.addResourceFactory("bar", factory); - - FooConstructor foo = (FooConstructor) component.createInstance(); - assertEquals("result", foo.resource); - EasyMock.verify(parent); - } - - public static class Foo { - protected String resource; - - public Foo() { - } - - } - - public static class FooConstructor { - protected String resource; - - public FooConstructor(String resource) { - this.resource = resource; - } - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/CallbackInvocationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/CallbackInvocationTestCase.java deleted file mode 100644 index 898f89383a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/CallbackInvocationTestCase.java +++ /dev/null @@ -1,395 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.java.integration; - -import java.lang.reflect.Method; -import java.net.URI; -import java.net.URISyntaxException; - -import org.osoa.sca.NoRegisteredCallbackException; -import org.osoa.sca.annotations.Callback; - -import org.apache.tuscany.spi.builder.Connector; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.idl.InvalidServiceContractException; -import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry; -import org.apache.tuscany.spi.implementation.java.ConstructorDefinition; -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.model.ComponentDefinition; -import org.apache.tuscany.spi.model.ComponentReferenceDefinition; -import org.apache.tuscany.spi.model.ReferenceTarget; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.services.work.WorkScheduler; -import org.apache.tuscany.spi.wire.WireService; - -import junit.framework.TestCase; -import org.apache.tuscany.core.builder.ConnectorImpl; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.component.scope.CompositeScopeContainer; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -import org.apache.tuscany.core.implementation.java.JavaAtomicComponent; -import org.apache.tuscany.core.implementation.java.JavaComponentBuilder; -import org.apache.tuscany.core.implementation.java.JavaImplementation; -import org.apache.tuscany.core.wire.jdk.JDKWireService; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expectLastCall; -import static org.easymock.EasyMock.getCurrentArguments; -import static org.easymock.EasyMock.isA; -import static org.easymock.EasyMock.replay; -import org.easymock.IAnswer; - -/** - * Verifies callback integration scenarios with Java components. - * - * @version $Rev$ $Date$ - */ -public class CallbackInvocationTestCase extends TestCase { - private ScopeContainer container; - private DeploymentContext context; - private JavaComponentBuilder builder; - private WireService wireService; - private WorkScheduler scheduler; - private WorkContext workContext; - - /** - * Verifies callback wires are built and callback invocations are handled properly - */ - public void testComponentToComponentCallback() throws Exception { - ComponentDefinition<JavaImplementation> targetDefinition = createTarget(); - JavaAtomicComponent fooComponent = - (JavaAtomicComponent) builder.build(null, targetDefinition, context); - fooComponent.setScopeContainer(container); - wireService.createWires(fooComponent, targetDefinition); - container.register(fooComponent); - - CompositeComponent parent = createMock(CompositeComponent.class); - parent.getChild(isA(String.class)); - expectLastCall().andReturn(fooComponent).anyTimes(); - replay(parent); - - ComponentDefinition<JavaImplementation> sourceDefinition = createSource("fooClient"); - JavaAtomicComponent clientComponent = - (JavaAtomicComponent) builder.build(parent, sourceDefinition, context); - clientComponent.setScopeContainer(container); - wireService.createWires(clientComponent, sourceDefinition); - container.register(clientComponent); - - Connector connector = new ConnectorImpl(new JDKWireService(), null, scheduler, workContext); - - connector.connect(clientComponent); - FooClient client = (FooClient) clientComponent.getTargetInstance(); - client.invoke(); - assertTrue(client.invoked); - client.invokeMultiCallback(); - assertTrue(client.count == 2); - } - - /** - * Verifies exception is thrown when callback is not implemented - */ - public void testCallbackNotRegistered() throws Exception { - ComponentDefinition<JavaImplementation> targetDefinition = createTarget(); - JavaAtomicComponent fooComponent = - (JavaAtomicComponent) builder.build(null, targetDefinition, context); - fooComponent.setScopeContainer(container); - wireService.createWires(fooComponent, targetDefinition); - container.register(fooComponent); - - CompositeComponent parent = createMock(CompositeComponent.class); - parent.getChild(isA(String.class)); - expectLastCall().andReturn(fooComponent).anyTimes(); - replay(parent); - - ComponentDefinition<JavaImplementation> sourceDefinition = createPlainSource("fooPlainClient"); - JavaAtomicComponent clientComponent = - (JavaAtomicComponent) builder.build(parent, sourceDefinition, context); - clientComponent.setScopeContainer(container); - wireService.createWires(clientComponent, sourceDefinition); - container.register(clientComponent); - - Connector connector = new ConnectorImpl(new JDKWireService(), null, scheduler, workContext); - - connector.connect(clientComponent); - FooPlainClient client = (FooPlainClient) clientComponent.getTargetInstance(); - try { - client.invoke(); - fail(); - } catch (NoRegisteredCallbackException e) { - // expected - } - } - - /** - * Verifies a callback in response to an invocation from two different client components is routed back to the - * appropriate client. - */ - public void testTwoSourceComponentToComponentCallback() throws Exception { - ComponentDefinition<JavaImplementation> targetDefinition = createTarget(); - JavaAtomicComponent fooComponent = - (JavaAtomicComponent) builder.build(null, targetDefinition, context); - fooComponent.setScopeContainer(container); - wireService.createWires(fooComponent, targetDefinition); - container.register(fooComponent); - - CompositeComponent parent = createMock(CompositeComponent.class); - parent.getChild(isA(String.class)); - expectLastCall().andReturn(fooComponent).anyTimes(); - replay(parent); - - ComponentDefinition<JavaImplementation> sourceDefinition1 = createSource("fooCleint1"); - ComponentDefinition<JavaImplementation> sourceDefinition2 = createSource("fooCleint2"); - JavaAtomicComponent clientComponent1 = - (JavaAtomicComponent) builder.build(parent, sourceDefinition1, context); - clientComponent1.setScopeContainer(container); - wireService.createWires(clientComponent1, sourceDefinition1); - container.register(clientComponent1); - JavaAtomicComponent clientComponent2 = - (JavaAtomicComponent) builder.build(parent, sourceDefinition2, context); - clientComponent2.setScopeContainer(container); - wireService.createWires(clientComponent2, sourceDefinition2); - container.register(clientComponent2); - - Connector connector = new ConnectorImpl(new JDKWireService(), null, scheduler, workContext); - connector.connect(clientComponent1); - connector.connect(clientComponent2); - FooClient client1 = (FooClient) clientComponent1.getTargetInstance(); - client1.invoke(); - assertTrue(client1.invoked); - FooClient client2 = (FooClient) clientComponent2.getTargetInstance(); - client2.invoke(); - assertTrue(client2.invoked); - } - - - private ComponentDefinition<JavaImplementation> createTarget() throws NoSuchMethodException, - InvalidServiceContractException { - ConstructorDefinition<FooImpl> ctorDef = new ConstructorDefinition<FooImpl>(FooImpl.class.getConstructor()); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - type.setConstructorDefinition(ctorDef); - type.setImplementationScope(Scope.COMPOSITE); - Method method = FooImpl.class.getMethod("setCallback", FooCallback.class); - JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - ServiceContract<?> contract = registry.introspect(Foo.class); - contract.setCallbackClass(FooCallback.class); - contract.setCallbackName("callback"); - JavaMappedService mappedService = new JavaMappedService("Foo", contract, false, "callback", method); - type.getServices().put("Foo", mappedService); - - JavaImplementation impl = new JavaImplementation(FooImpl.class, type); - impl.setComponentType(type); - impl.setImplementationClass(FooImpl.class); - return new ComponentDefinition<JavaImplementation>("foo", impl); - } - - private ComponentDefinition<JavaImplementation> createSource(String name) - throws NoSuchMethodException, URISyntaxException, InvalidServiceContractException { - ConstructorDefinition<FooClient> ctorDef = - new ConstructorDefinition<FooClient>(FooClient.class.getConstructor()); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - type.setConstructorDefinition(ctorDef); - type.setImplementationScope(Scope.COMPOSITE); - Method method = FooClient.class.getMethod("setFoo", Foo.class); - JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - ServiceContract<?> contract = registry.introspect(Foo.class); - contract.setCallbackClass(FooCallback.class); - contract.setCallbackName("callback"); - JavaMappedReference mappedReference = new JavaMappedReference("foo", contract, method); - type.getReferences().put("foo", mappedReference); - ReferenceTarget refTarget = new ReferenceTarget(); - refTarget.setReferenceName("foo"); - refTarget.getTargets().add(new URI("foo")); - JavaImplementation impl = new JavaImplementation(FooClient.class, type); - impl.setComponentType(type); - impl.setImplementationClass(FooClient.class); - ComponentDefinition<JavaImplementation> def = new ComponentDefinition<JavaImplementation>(name, impl); - ComponentReferenceDefinition compRef = new ComponentReferenceDefinition(type.getReferences().get("foo")); - compRef.addTarget(new URI("foo")); - def.add(compRef); - //def.getReferenceTargets().put("foo", refTarget); - return def; - } - - private ComponentDefinition<JavaImplementation> createPlainSource(String name) - throws NoSuchMethodException, URISyntaxException, InvalidServiceContractException { - ConstructorDefinition<FooPlainClient> ctorDef = - new ConstructorDefinition<FooPlainClient>(FooPlainClient.class.getConstructor()); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - type.setConstructorDefinition(ctorDef); - type.setImplementationScope(Scope.COMPOSITE); - Method method = FooPlainClient.class.getMethod("setFoo", Foo.class); - JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - ServiceContract<?> contract = registry.introspect(Foo.class); - contract.setCallbackClass(FooCallback.class); - contract.setCallbackName("callback"); - JavaMappedReference mappedReference = new JavaMappedReference("foo", contract, method); - type.getReferences().put("foo", mappedReference); - ReferenceTarget refTarget = new ReferenceTarget(); - refTarget.setReferenceName("foo"); - refTarget.getTargets().add(new URI("foo")); - JavaImplementation impl = new JavaImplementation(FooPlainClient.class, type); - ComponentDefinition<JavaImplementation> def = new ComponentDefinition<JavaImplementation>(name, impl); - ComponentReferenceDefinition compRef = new ComponentReferenceDefinition(type.getReferences().get("foo")); - compRef.addTarget(new URI("foo")); - def.add(compRef); - //def.getReferenceTargets().put("foo", refTarget); - return def; - } - - @Callback(FooCallback.class) - public static interface Foo { - void call(); - - void callMultiCallback(); - - void callFromPlain(); - } - - public static class FooImpl implements Foo { - private FooCallback callback; - - public FooImpl() { - } - - @Callback - public void setCallback(FooCallback callback) { - this.callback = callback; - } - - public void call() { - callback.callback(); - } - - public void callMultiCallback() { - callback.multiCallback(); - callback.multiCallback(); - } - - public void callFromPlain() { - try { - callback.callback(); - fail(); - } catch (NoRegisteredCallbackException e) { - // expected - } catch (Throwable e) { - e.printStackTrace(); - } - } - } - - public static class FooClient implements FooCallback { - - private Foo foo; - private boolean invoked; - private int count; - - public FooClient() { - } - - public void setFoo(Foo foo) { - this.foo = foo; - } - - public void callback() { - if (invoked) { - fail(); - } - invoked = true; - } - - public void multiCallback() { - count++; - } - - public void invoke() { - foo.call(); - } - - public void invokeMultiCallback() { - foo.callMultiCallback(); - } - } - - public interface FooCallback { - void callback(); - - void multiCallback(); - } - - public static class FooPlainClient /* implements FooCallback */ { // do NOT implement the callback - - private Foo foo; - - public FooPlainClient() { - } - - public void setFoo(Foo foo) { - this.foo = foo; - } - - public void invoke() { - foo.callFromPlain(); - } - - public void callback() { - - } - - public void multiCallback() { - - } - } - - protected void setUp() throws Exception { - super.setUp(); - wireService = new JDKWireService(); - container = new CompositeScopeContainer(null); - container.start(); - context = createMock(DeploymentContext.class); - context.getCompositeScope(); - expectLastCall().andReturn(container).anyTimes(); - replay(context); - - scheduler = createMock(WorkScheduler.class); - scheduler.scheduleWork(isA(Runnable.class)); - expectLastCall().andStubAnswer(new IAnswer<Object>() { - public Object answer() throws Throwable { - Runnable runnable = (Runnable) getCurrentArguments()[0]; - runnable.run(); - return null; - } - }); - replay(scheduler); - - builder = new JavaComponentBuilder(); - workContext = new WorkContextImpl(); - builder.setWorkContext(workContext); - builder.setWireService(new JDKWireService(workContext, null)); - builder.setWorkScheduler(scheduler); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/OutboundWireToJavaTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/OutboundWireToJavaTestCase.java deleted file mode 100644 index f2d88955e4..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/java/integration/OutboundWireToJavaTestCase.java +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.java.integration; - -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.Executor; -import java.util.concurrent.Executors; -import java.util.concurrent.FutureTask; - -import org.apache.tuscany.spi.QualifiedName; -import org.apache.tuscany.spi.builder.WiringException; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.idl.InvalidServiceContractException; -import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry; -import org.apache.tuscany.spi.idl.java.JavaServiceContract; -import org.apache.tuscany.spi.model.InteractionScope; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.WireService; - -import junit.framework.TestCase; -import org.apache.tuscany.core.builder.ConnectorImpl; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.component.event.CompositeStart; -import org.apache.tuscany.core.component.event.CompositeStop; -import org.apache.tuscany.core.component.event.HttpSessionEnd; -import org.apache.tuscany.core.component.event.HttpSessionStart; -import org.apache.tuscany.core.component.event.RequestEnd; -import org.apache.tuscany.core.component.event.RequestStart; -import org.apache.tuscany.core.component.scope.CompositeScopeContainer; -import org.apache.tuscany.core.component.scope.HttpSessionScopeContainer; -import org.apache.tuscany.core.component.scope.RequestScopeContainer; -import org.apache.tuscany.core.component.scope.StatelessScopeContainer; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -import org.apache.tuscany.core.implementation.PojoConfiguration; -import org.apache.tuscany.core.implementation.java.JavaAtomicComponent; -import org.apache.tuscany.core.injection.PojoObjectFactory; -import org.apache.tuscany.core.integration.mock.MockFactory; -import org.apache.tuscany.core.mock.component.Target; -import org.apache.tuscany.core.mock.component.TargetImpl; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; -import org.apache.tuscany.core.wire.jdk.JDKWireService; -import org.easymock.EasyMock; - -/** - * Validates wiring from a wire to Java atomic component by scope - * - * @version $$Rev$$ $$Date$$ - */ -public class OutboundWireToJavaTestCase extends TestCase { - private WorkContext workContext = new WorkContextImpl(); - private WireService wireService = new JDKWireService(new WorkContextImpl(), null); - - public void testToStatelessScope() throws Exception { - StatelessScopeContainer scope = new StatelessScopeContainer(workContext, null); - scope.start(); - final OutboundWire wire = getWire(scope); - Target service = wireService.createProxy(Target.class, wire); - assertNotNull(service); - service.setString("foo"); - assertEquals(null, service.getString()); - scope.stop(); - } - - public void testToRequestScope() throws Exception { - final RequestScopeContainer scope = new RequestScopeContainer(workContext, null); - scope.start(); - - scope.onEvent(new RequestStart(this)); - - final OutboundWire wire = getWire(scope); - Target service = wireService.createProxy(Target.class, wire); - assertNotNull(service); - service.setString("foo"); - - // another request - Executor executor = Executors.newSingleThreadExecutor(); - FutureTask<Void> future = new FutureTask<Void>(new Runnable() { - public void run() { - scope.onEvent(new RequestStart(this)); - Target service2 = wireService.createProxy(Target.class, wire); - Target target2 = wireService.createProxy(Target.class, wire); - assertEquals(null, service2.getString()); - service2.setString("bar"); - assertEquals("bar", service2.getString()); - assertEquals("bar", target2.getString()); - scope.onEvent(new RequestEnd(this)); - } - }, null); - executor.execute(future); - future.get(); - - assertEquals("foo", service.getString()); - scope.onEvent(new RequestEnd(this)); - scope.stop(); - } - - public void testToSessionScope() throws Exception { - HttpSessionScopeContainer scope = new HttpSessionScopeContainer(workContext, null); - scope.start(); - Object session1 = new Object(); - workContext.setIdentifier(Scope.SESSION, session1); - scope.onEvent(new HttpSessionStart(this, session1)); - - final OutboundWire wire = getWire(scope); - Target service = wireService.createProxy(Target.class, wire); - Target target = wireService.createProxy(Target.class, wire); - assertNotNull(service); - service.setString("foo"); - assertEquals("foo", service.getString()); - assertEquals("foo", target.getString()); - - workContext.clearIdentifier(Scope.SESSION); - - //second session - Object session2 = new Object(); - workContext.setIdentifier(Scope.SESSION, session2); - scope.onEvent(new HttpSessionStart(this, session2)); - - Target service2 = wireService.createProxy(Target.class, wire); - assertNotNull(service2); - assertNull(service2.getString()); - Target target2 = wireService.createProxy(Target.class, wire); - service2.setString("bar"); - assertEquals("bar", service2.getString()); - assertEquals("bar", target2.getString()); - - scope.onEvent(new HttpSessionEnd(this, session2)); - workContext.clearIdentifier(Scope.SESSION); - - workContext.setIdentifier(Scope.SESSION, session1); - assertEquals("foo", service.getString()); - - scope.onEvent(new HttpSessionEnd(this, session1)); - - scope.stop(); - } - - public void testToCompositeScope() throws Exception { - CompositeScopeContainer scope = new CompositeScopeContainer(null); - scope.start(); - scope.onEvent(new CompositeStart(this, null)); - final OutboundWire wire = getWire(scope); - Target service = wireService.createProxy(Target.class, wire); - Target target = wireService.createProxy(Target.class, wire); - assertNotNull(service); - service.setString("foo"); - assertEquals("foo", service.getString()); - assertEquals("foo", target.getString()); - scope.onEvent(new CompositeStop(this, null)); - scope.stop(); - } - - private OutboundWire getWire(ScopeContainer scope) throws NoSuchMethodException, - InvalidServiceContractException, WiringException { - ConnectorImpl connector = new ConnectorImpl(); - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setInstanceFactory(new PojoObjectFactory<TargetImpl>(TargetImpl.class.getConstructor())); - configuration.setParent(parent); - configuration.setWorkContext(workContext); - configuration.setName("source"); - - JavaAtomicComponent source = new JavaAtomicComponent(configuration); - source.setScopeContainer(scope); - OutboundWire outboundWire = createOutboundWire(new QualifiedName("target/Target"), Target.class); - outboundWire.setContainer(source); - source.addOutboundWire(outboundWire); - configuration.setName("target"); - JavaAtomicComponent target = new JavaAtomicComponent(configuration); - target.setScopeContainer(scope); - InboundWire targetWire = MockFactory.createInboundWire("Target", Target.class); - targetWire.setContainer(target); - target.addInboundWire(targetWire); - InboundWire inboundWire = target.getInboundWire("Target"); - inboundWire.setContainer(target); - - EasyMock.expect(parent.getChild("target")).andReturn(target); - EasyMock.replay(parent); - - connector.connect(source); - target.start(); - return outboundWire; - } - - private static <T> OutboundWire createOutboundWire(QualifiedName targetName, Class<T> interfaze) - throws InvalidServiceContractException { - OutboundWire wire = new OutboundWireImpl(); - JavaServiceContract contract = new JavaServiceContract(interfaze); - contract.setInteractionScope(InteractionScope.NONCONVERSATIONAL); - wire.setServiceContract(contract); - wire.setTargetName(targetName); - wire.addInvocationChains(createInvocationChains(interfaze)); - return wire; - } - - private static Map<Operation<?>, OutboundInvocationChain> createInvocationChains(Class<?> interfaze) - throws InvalidServiceContractException { - Map<Operation<?>, OutboundInvocationChain> invocations = new HashMap<Operation<?>, OutboundInvocationChain>(); - JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - ServiceContract<?> contract = registry.introspect(interfaze); - for (Operation operation : contract.getOperations().values()) { - OutboundInvocationChain chain = new OutboundInvocationChainImpl(operation); - invocations.put(operation, chain); - } - return invocations; - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessorTestCase.java deleted file mode 100644 index 9fd3fbfc9d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/AllowsPassByReferenceProcessorTestCase.java +++ /dev/null @@ -1,59 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tuscany.core.implementation.processor;
-
-import org.osoa.sca.annotations.AllowsPassByReference;
-
-import org.apache.tuscany.spi.implementation.java.JavaMappedProperty;
-import org.apache.tuscany.spi.implementation.java.JavaMappedReference;
-import org.apache.tuscany.spi.implementation.java.JavaMappedService;
-import org.apache.tuscany.spi.implementation.java.PojoComponentType;
-
-import junit.framework.TestCase;
-
-/**
- * @version $Rev: 452761 $ $Date: 2006-10-04 12:03:20 +0530 (Wed, 04 Oct 2006) $
- */
-public class AllowsPassByReferenceProcessorTestCase extends TestCase {
-
- PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type;
- AllowsPassByReferenceProcessor processor;
-
- public void testClassAnnotation() throws Exception {
- processor.visitClass(null, Foo.class, type, null);
- assertEquals(true, type.isAllowsPassByReference());
-
- processor.visitClass(null, Bar.class, type, null);
- assertEquals(false, type.isAllowsPassByReference());
- }
-
- protected void setUp() throws Exception {
- super.setUp();
- type = new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>();
- processor = new AllowsPassByReferenceProcessor();
- }
-
- @AllowsPassByReference
- private class Foo {
- }
-
- //no annotation
- private class Bar {
- }
-}
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorAutowireTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorAutowireTestCase.java deleted file mode 100644 index c67d226b41..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorAutowireTestCase.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.processor; - -import java.lang.reflect.Constructor; -import java.util.List; - -import org.osoa.sca.annotations.Property; - -import org.apache.tuscany.spi.annotation.Autowire; -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; - -/** - * @version $Rev$ $Date$ - */ -public class ConstructorAutowireTestCase extends TestCase { - - ConstructorProcessor processor = - new ConstructorProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl())); - - public void testAutowire() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<Foo> ctor = Foo.class.getConstructor(Bar.class); - processor.visitConstructor(null, ctor, type, null); - assertNotNull(type.getReferences().get("myRef")); - } - - public void testNamesOnConstructor() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<Foo> ctor = Foo.class.getConstructor(Bar.class, Bar.class); - processor.visitConstructor(null, ctor, type, null); - assertEquals(2, type.getConstructorDefinition().getInjectionNames().size()); - assertNotNull(type.getReferences().get("myRef1")); - assertNotNull(type.getReferences().get("myRef2")); - } - - public void testNoName() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<Foo2> ctor = Foo2.class.getConstructor(Bar.class); - processor.visitConstructor(null, ctor, type, null); - assertNotNull(type.getReferences().get(Bar.class.getName() + "0")); - } - - public void testInvalidNumberOfNames() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<BadFoo> ctor = BadFoo.class.getConstructor(Bar.class, Bar.class); - try { - processor.visitConstructor(null, ctor, type, null); - fail(); - } catch (InvalidAutowireException e) { - // expected - } - } - - public void testNoMatchingNames() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<BadFoo> ctor = BadFoo.class.getConstructor(List.class, List.class); - try { - processor.visitConstructor(null, ctor, type, null); - fail(); - } catch (InvalidConstructorException e) { - // expected - } - } - - /** - * Verifies processing executes with additional extension annotations - */ - public void testRandomAnnotation() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<Foo3> ctor = Foo3.class.getConstructor(String.class, String.class); - processor.visitConstructor(null, ctor, type, null); - assertEquals(1, type.getProperties().size()); - assertNotNull(type.getProperties().get("prop1")); - } - - private static interface Bar { - - } - - private static class Foo { - - @org.osoa.sca.annotations.Constructor() - public Foo(@Autowire(name = "myRef") Bar ref) { - - } - - @org.osoa.sca.annotations.Constructor({"myRef1", "myRef2"}) - public Foo(@Autowire Bar ref1, @Autowire Bar ref2) { - - } - - } - - private static class Foo2 { - @org.osoa.sca.annotations.Constructor() - public Foo2(@Autowire Bar ref) { - - } - } - - private static class BadFoo { - - @org.osoa.sca.annotations.Constructor({"ref1"}) - public BadFoo(@Autowire Bar ref1, @Autowire Bar ref2) { - - } - - @org.osoa.sca.annotations.Constructor({"myRef", "myRef2"}) - public BadFoo(@Autowire List ref, @Autowire(name = "myOtherRef") List ref2) { - - } - - } - - public static class Foo3 { - - @org.osoa.sca.annotations.Constructor - public Foo3(@Property(name = "prop1") String prop, @Baz String baz) { - } - } - - public @interface Baz { - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorExtensibilityTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorExtensibilityTestCase.java deleted file mode 100644 index 25a8ab9a1a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorExtensibilityTestCase.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.processor; - -import java.lang.reflect.Constructor; - -import org.osoa.sca.annotations.Property; - -import org.apache.tuscany.spi.implementation.java.ConstructorDefinition; -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; - -/** - * Verifies the constructor processor works when parameters are marked with custom extension annotations - * - * @version $Rev$ $Date$ - */ -public class ConstructorProcessorExtensibilityTestCase extends TestCase { - private ConstructorProcessor processor = - new ConstructorProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl())); - - public void testProcessFirst() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<Foo> ctor1 = Foo.class.getConstructor(String.class, String.class); - processor.visitConstructor(null, ctor1, type, null); - assertEquals("foo", type.getConstructorDefinition().getInjectionNames().get(0)); - } - - /** - * Verifies the constructor processor can be called after another processor has evaluated the constructor and found - * an annotation - * - * @throws Exception - */ - public void testProcessLast() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<Foo> ctor1 = Foo.class.getConstructor(String.class, String.class); - ConstructorDefinition<Foo> definition = new ConstructorDefinition<Foo>(ctor1); - definition.getInjectionNames().add(""); - definition.getInjectionNames().add("mybar"); - type.setConstructorDefinition(definition); - processor.visitConstructor(null, ctor1, type, null); - assertEquals("foo", type.getConstructorDefinition().getInjectionNames().get(0)); - } - - - private @interface Bar { - - } - - private static class Foo { - @org.osoa.sca.annotations.Constructor - public Foo(@Property(name = "foo") String foo, @Bar String bar) { - - } - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorTestCase.java deleted file mode 100644 index 4e48523e8c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorProcessorTestCase.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.processor; - -import java.lang.reflect.Constructor; -import java.util.Collection; -import java.util.List; -import java.util.Set; - -import org.osoa.sca.annotations.Property; -import org.osoa.sca.annotations.Reference; - -import org.apache.tuscany.spi.annotation.Autowire; -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.model.Multiplicity; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; - -/** - * @version $Rev$ $Date$ - */ -public class ConstructorProcessorTestCase extends TestCase { - private ConstructorProcessor processor = - new ConstructorProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl())); - - public void testDuplicateConstructor() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - try { - processor.visitClass(null, BadFoo.class, type, null); - fail(); - } catch (DuplicateConstructorException e) { - // expected - } - } - - public void testConstructorAnnotation() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<Foo> ctor1 = Foo.class.getConstructor(String.class); - processor.visitConstructor(null, ctor1, type, null); - assertEquals("foo", type.getConstructorDefinition().getInjectionNames().get(0)); - } - - public void testNoAnnotation() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<NoAnnotation> ctor1 = NoAnnotation.class.getConstructor(); - processor.visitConstructor(null, ctor1, type, null); - assertNull(type.getConstructorDefinition()); - } - - public void testBadAnnotation() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<BadAnnotation> ctor1 = BadAnnotation.class.getConstructor(String.class, Foo.class); - try { - processor.visitConstructor(null, ctor1, type, null); - fail(); - } catch (InvalidConstructorException e) { - // expected - } - } - - public void testMixedParameters() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<Mixed> ctor1 = Mixed.class.getConstructor(String.class, String.class, String.class); - processor.visitConstructor(null, ctor1, type, null); - assertEquals("java.lang.String0", type.getConstructorDefinition().getInjectionNames().get(0)); - assertEquals("foo", type.getConstructorDefinition().getInjectionNames().get(1)); - assertEquals("bar", type.getConstructorDefinition().getInjectionNames().get(2)); - } - - public void testAllAutowireWithNoNames() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<AllAutowireNoName> ctor1 = - AllAutowireNoName.class.getConstructor(String.class, String.class, String.class); - processor.visitConstructor(null, ctor1, type, null); - assertEquals("java.lang.String0", type.getConstructorDefinition().getInjectionNames().get(0)); - assertEquals("java.lang.String1", type.getConstructorDefinition().getInjectionNames().get(1)); - assertEquals("java.lang.String2", type.getConstructorDefinition().getInjectionNames().get(2)); - } - - private static class BadFoo { - - @org.osoa.sca.annotations.Constructor("foo") - public BadFoo(String foo) { - - } - - @org.osoa.sca.annotations.Constructor({"foo", "bar"}) - public BadFoo(String foo, String bar) { - - } - } - - private static class Foo { - @org.osoa.sca.annotations.Constructor("foo") - public Foo(String foo) { - - } - } - - private static class NoAnnotation { - public NoAnnotation() { - } - } - - private static class BadAnnotation { - @org.osoa.sca.annotations.Constructor("foo") - public BadAnnotation(String foo, Foo ref) { - } - } - - - public static final class Mixed { - @org.osoa.sca.annotations.Constructor - public Mixed(@Autowire String param1, - @Property(name = "foo")String param2, - @Reference(name = "bar")String param3) { - } - } - - public static final class AllAutowireNoName { - @org.osoa.sca.annotations.Constructor - public AllAutowireNoName(@Autowire String param1, @Autowire String param2, @Autowire String param3) { - } - } - - public static final class Multiple { - @org.osoa.sca.annotations.Constructor - public Multiple(@Autowire Collection<String> param1, - @Property(name = "foo")String[] param2, - @Reference(name = "bar", required = true)List<String> param3, - @Property(name = "abc")Set<String> param4, - @Reference(name = "xyz")String[] param5) { - } - } - - public void testMultiplicity() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<Multiple> ctor1 = - Multiple.class.getConstructor(Collection.class, String[].class, List.class, Set.class, String[].class); - processor.visitConstructor(null, ctor1, type, null); - JavaMappedReference ref0 = type.getReferences().get("java.util.Collection0"); - assertNotNull(ref0); - assertEquals(Multiplicity.ONE_N, ref0.getMultiplicity()); - JavaMappedReference ref1 = type.getReferences().get("bar"); - assertNotNull(ref1); - assertEquals(Multiplicity.ONE_N, ref1.getMultiplicity()); - JavaMappedReference ref2 = type.getReferences().get("xyz"); - assertNotNull(ref2); - assertEquals(Multiplicity.ZERO_N, ref2.getMultiplicity()); - JavaMappedProperty prop1 = type.getProperties().get("foo"); - assertNotNull(prop1); - assertTrue(prop1.isMany()); - JavaMappedProperty prop2 = type.getProperties().get("abc"); - assertNotNull(prop2); - assertTrue(prop2.isMany()); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorPropertyTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorPropertyTestCase.java deleted file mode 100644 index fb125ca0f4..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorPropertyTestCase.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.processor; - -import java.lang.reflect.Constructor; -import java.util.List; - -import junit.framework.TestCase; - -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -import org.apache.tuscany.spi.implementation.java.DuplicatePropertyException; -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.osoa.sca.annotations.Property; - -/** - * @version $Rev$ $Date$ - */ -public class ConstructorPropertyTestCase extends TestCase { - - ConstructorProcessor processor = - new ConstructorProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl())); - - public void testProperty() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<Foo> ctor = Foo.class.getConstructor(String.class); - processor.visitConstructor(null, ctor, type, null); - JavaMappedProperty<?> property = type.getProperties().get("myProp"); - assertEquals(property.isMustSupply(), true); - assertEquals("myProp", property.getName()); - } - - public void testTwoPropertiesSameType() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class); - processor.visitConstructor(null, ctor, type, null); - assertNotNull(type.getProperties().get("myProp1")); - assertNotNull(type.getProperties().get("myProp2")); - } - - public void testDuplicateProperty() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class, String.class); - try { - processor.visitConstructor(null, ctor, type, null); - fail(); - } catch (DuplicatePropertyException e) { - // expected - } - } - - public void testNoName() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class); - try { - processor.visitConstructor(null, ctor, type, null); - fail(); - } catch (InvalidPropertyException e) { - // expected - } - } - - public void testNamesOnConstructor() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<Foo> ctor = Foo.class.getConstructor(Integer.class); - processor.visitConstructor(null, ctor, type, null); - assertNotNull(type.getProperties().get("myProp")); - } - - public void testInvalidNumberOfNames() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<BadFoo> ctor = BadFoo.class.getConstructor(Integer.class, Integer.class); - try { - processor.visitConstructor(null, ctor, type, null); - fail(); - } catch (InvalidPropertyException e) { - // expected - } - } - - public void testNoMatchingNames() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<BadFoo> ctor = BadFoo.class.getConstructor(List.class, List.class); - try { - processor.visitConstructor(null, ctor, type, null); - fail(); - } catch (InvalidConstructorException e) { - // expected - } - } - -// public void testMultiplicityRequired() throws Exception { - // TODO multiplicity -// } - - private static class Foo { - - @org.osoa.sca.annotations.Constructor() - public Foo(@Property(name = "myProp", required = true) String prop) { - - } - - @org.osoa.sca.annotations.Constructor("myProp") - public Foo(@Property Integer prop) { - - } - - @org.osoa.sca.annotations.Constructor() - public Foo(@Property(name = "myProp1") String prop1, @Property(name = "myProp2") String prop2) { - - } - - @org.osoa.sca.annotations.Constructor() - public Foo(@Property List prop) { - - } - } - - private static class BadFoo { - - @org.osoa.sca.annotations.Constructor() - public BadFoo(@Property(name = "myProp") String prop1, @Property(name = "myProp") String prop2) { - - } - - @org.osoa.sca.annotations.Constructor() - public BadFoo(@Property String prop) { - - } - - @org.osoa.sca.annotations.Constructor("myProp") - public BadFoo(@Property Integer prop, @Property Integer prop2) { - - } - - @org.osoa.sca.annotations.Constructor({"myRef", "myRef2"}) - public BadFoo(@Property List ref, @Property(name = "myOtherRef") List ref2) { - - } - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorReferenceTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorReferenceTestCase.java deleted file mode 100644 index 152f3b63d1..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorReferenceTestCase.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.processor; - -import java.lang.reflect.Constructor; -import java.util.List; - -import org.osoa.sca.annotations.Reference; - -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; - -/** - * @version $Rev$ $Date$ - */ -public class ConstructorReferenceTestCase extends TestCase { - - ConstructorProcessor processor; - - public void testReference() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<Foo> ctor = Foo.class.getConstructor(String.class); - processor.visitConstructor(null, ctor, type, null); - JavaMappedReference reference = type.getReferences().get("myRef"); - assertEquals("myRef", reference.getName()); - } - - public void testTwoReferencesSameType() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class); - processor.visitConstructor(null, ctor, type, null); - assertNotNull(type.getReferences().get("myRef1")); - assertNotNull(type.getReferences().get("myRef2")); - } - - public void testDuplicateProperty() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class, String.class); - try { - processor.visitConstructor(null, ctor, type, null); - fail(); - } catch (DuplicateReferenceException e) { - // expected - } - } - - public void testNoName() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class); - try { - processor.visitConstructor(null, ctor, type, null); - fail(); - } catch (InvalidReferenceException e) { - // expected - } - } - - public void testNamesOnConstructor() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<Foo> ctor = Foo.class.getConstructor(Integer.class); - processor.visitConstructor(null, ctor, type, null); - assertNotNull(type.getReferences().get("myRef")); - } - - public void testInvalidNumberOfNames() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<BadFoo> ctor = BadFoo.class.getConstructor(Integer.class, Integer.class); - try { - processor.visitConstructor(null, ctor, type, null); - fail(); - } catch (InvalidReferenceException e) { - // expected - } - } - - public void testNoMatchingNames() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<BadFoo> ctor = BadFoo.class.getConstructor(List.class, List.class); - try { - processor.visitConstructor(null, ctor, type, null); - fail(); - } catch (InvalidConstructorException e) { - // expected - } - } - - protected void setUp() throws Exception { - super.setUp(); - processor = - new ConstructorProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl())); - } - -// public void testMultiplicityRequired() throws Exception { - // TODO multiplicity -// } - - private static class Foo { - - @org.osoa.sca.annotations.Constructor() - public Foo(@Reference(name = "myRef", required = true) String prop) { - - } - - @org.osoa.sca.annotations.Constructor() - public Foo(@Reference(name = "myRef1") String prop1, @Reference(name = "myRef2") String prop2) { - - } - - @org.osoa.sca.annotations.Constructor("myRef") - public Foo(@Reference Integer prop) { - - } - - @org.osoa.sca.annotations.Constructor() - public Foo(@Reference List prop) { - - } - } - - private static class BadFoo { - - @org.osoa.sca.annotations.Constructor - public BadFoo(@Reference(name = "myRef") String prop1, @Reference(name = "myRef") String prop2) { - - } - - @org.osoa.sca.annotations.Constructor - public BadFoo(@Reference String prop) { - - } - - @org.osoa.sca.annotations.Constructor("myRef") - public BadFoo(@Reference Integer ref, @Reference Integer ref2) { - - } - - @org.osoa.sca.annotations.Constructor({"myRef", "myRef2"}) - public BadFoo(@Reference List ref, @Reference(name = "myOtherRef") List ref2) { - - } - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorResourceTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorResourceTestCase.java deleted file mode 100644 index c691a4d6bc..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConstructorResourceTestCase.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.processor; - -import java.lang.reflect.Constructor; -import java.util.List; - -import org.apache.tuscany.api.annotation.Resource; - -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; - -/** - * @version $Rev$ $Date$ - */ -public class ConstructorResourceTestCase extends TestCase { - - ConstructorProcessor processor = - new ConstructorProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl())); - - public void testResource() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<Foo> ctor = Foo.class.getConstructor(String.class); - processor.visitConstructor(null, ctor, type, null); - org.apache.tuscany.spi.implementation.java.Resource resource = type.getResources().get("myResource"); - assertFalse(resource.isOptional()); - } - - public void testTwoResourcesSameType() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class); - processor.visitConstructor(null, ctor, type, null); - assertNotNull(type.getResources().get("myResource1")); - assertNotNull(type.getResources().get("myResource2")); - } - - public void testDuplicateResource() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class, String.class); - try { - processor.visitConstructor(null, ctor, type, null); - fail(); - } catch (DuplicateResourceException e) { - // expected - } - } - - public void testNoName() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<ConstructorResourceTestCase.BadFoo> ctor = - ConstructorResourceTestCase.BadFoo.class.getConstructor(String.class); - try { - processor.visitConstructor(null, ctor, type, null); - fail(); - } catch (InvalidResourceException e) { - // expected - } - } - - public void testNamesOnConstructor() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<Foo> ctor = Foo.class.getConstructor(Integer.class); - processor.visitConstructor(null, ctor, type, null); - assertNotNull(type.getResources().get("myResource")); - } - - public void testInvalidNumberOfNames() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<ConstructorResourceTestCase.BadFoo> ctor = - ConstructorResourceTestCase.BadFoo.class.getConstructor(Integer.class, Integer.class); - try { - processor.visitConstructor(null, ctor, type, null); - fail(); - } catch (InvalidResourceException e) { - // expected - } - } - - public void testNoMatchingNames() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<ConstructorResourceTestCase.BadFoo> ctor = - ConstructorResourceTestCase.BadFoo.class.getConstructor(List.class, List.class); - try { - processor.visitConstructor(null, ctor, type, null); - fail(); - } catch (InvalidConstructorException e) { - // expected - } - } - - private static class Foo { - - @org.osoa.sca.annotations.Constructor - public Foo(@Resource(name = "myResource") String resource) { - - } - - @org.osoa.sca.annotations.Constructor("myResource") - public Foo(@Resource Integer resource) { - - } - - @org.osoa.sca.annotations.Constructor - public Foo(@Resource(name = "myResource1") String res1, @Resource(name = "myResource2") String res2) { - - } - - @org.osoa.sca.annotations.Constructor - public Foo(@Resource List res) { - - } - } - - private static class BadFoo { - - @org.osoa.sca.annotations.Constructor - public BadFoo(@Resource(name = "myResource") String res1, @Resource(name = "myResource") String res2) { - - } - - @org.osoa.sca.annotations.Constructor - public BadFoo(@Resource String res) { - - } - - @org.osoa.sca.annotations.Constructor("myProp") - public BadFoo(@Resource Integer res, @Resource Integer res2) { - - } - - @org.osoa.sca.annotations.Constructor({"myRes", "myRes2"}) - public BadFoo(@Resource List res, @Resource(name = "myOtherRes") List res2) { - - } - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java deleted file mode 100644 index 1ad92bfee9..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ContextProcessorTestCase.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.processor; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -import junit.framework.TestCase; -import org.easymock.EasyMock; -import org.osoa.sca.ComponentContext; -import org.osoa.sca.RequestContext; -import org.osoa.sca.annotations.Context; - -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.wire.WireService; - -/** - * @version $Rev$ $Date$ - */ -public class ContextProcessorTestCase extends TestCase { - private ContextProcessor processor; - private CompositeComponent composite; - - // FIXME: resurrect to test ComponentContext injection -/* - public void testCompositeContextMethod() throws Exception { - Method method = Foo.class.getMethod("setContext", ComponentContext.class); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitMethod(composite, method, type, null); - assertNotNull(type.getResources().get("context")); - } -*/ - - // FIXME: resurrect to test ComponentContext injection -/* - public void testCompositeContextField() throws Exception { - Field field = Foo.class.getDeclaredField("context"); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitField(composite, field, type, null); - assertNotNull(type.getResources().get("context")); - } -*/ - - public void testRequestContextMethod() throws Exception { - Method method = Foo.class.getMethod("setRequestContext", RequestContext.class); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitMethod(composite, method, type, null); - assertNotNull(type.getResources().get("requestContext")); - } - - public void testRequestContextField() throws Exception { - Field field = Foo.class.getDeclaredField("requestContext"); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitField(composite, field, type, null); - assertNotNull(type.getResources().get("requestContext")); - } - - public void testInvalidParamType() throws Exception { - Method method = Foo.class.getMethod("setContext", String.class); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - try { - processor.visitMethod(composite, method, type, null); - fail(); - } catch (UnknownContextTypeException e) { - // expected - } - } - - public void testInvalidParamTypeField() throws Exception { - Field field = Foo.class.getDeclaredField("badContext"); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - try { - processor.visitField(composite, field, type, null); - fail(); - } catch (UnknownContextTypeException e) { - // expected - } - } - - - public void testInvalidParamNum() throws Exception { - Method method = Foo.class.getMethod("setContext", ComponentContext.class, String.class); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - try { - processor.visitMethod(composite, method, type, null); - fail(); - } catch (IllegalContextException e) { - // expected - } - } - - public void testInvalidNoParams() throws Exception { - Method method = Foo.class.getMethod("setContext"); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - try { - processor.visitMethod(composite, method, type, null); - fail(); - } catch (IllegalContextException e) { - // expected - } - } - - public void testNoContext() throws Exception { - Method method = Foo.class.getMethod("noContext", ComponentContext.class); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitMethod(composite, method, type, null); - assertEquals(0, type.getResources().size()); - } - - public void testNoContextField() throws Exception { - Field field = Foo.class.getDeclaredField("noContext"); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitField(composite, field, type, null); - assertEquals(0, type.getResources().size()); - } - - protected void setUp() throws Exception { - super.setUp(); - processor = new ContextProcessor(); - processor.setWireService(EasyMock.createNiceMock(WireService.class)); - processor.setWorkContext(EasyMock.createNiceMock(WorkContext.class)); - composite = EasyMock.createNiceMock(CompositeComponent.class); - } - - private class Foo { - @Context - protected ComponentContext context; - - @Context - protected Object badContext; - - protected ComponentContext noContext; - - @Context - protected RequestContext requestContext; - - @Context - public void setContext(ComponentContext context) { - - } - - @Context - public void setContext(String context) { - - } - - @Context - public void setContext(ComponentContext context, String string) { - - } - - @Context - public void setContext() { - - } - - public void noContext(ComponentContext context) { - - } - - @Context - public void setRequestContext(RequestContext requestContext) { - this.requestContext = requestContext; - } - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConversationProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConversationProcessorTestCase.java deleted file mode 100644 index 0433fed3a6..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConversationProcessorTestCase.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.processor; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -import junit.framework.TestCase; - -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.osoa.sca.annotations.ConversationAttributes; -import org.osoa.sca.annotations.ConversationID; -import org.osoa.sca.annotations.Scope; - -/** - * @version $Rev$ $Date$ - */ -public class ConversationProcessorTestCase extends TestCase { - private ConversationProcessor processor = new ConversationProcessor(); - - public void testMaxIdleTime() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitClass(null, FooMaxIdle.class, type, null); - assertEquals(10000L, type.getMaxIdleTime()); - assertEquals(-1, type.getMaxAge()); - } - - public void testMaxAge() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitClass(null, FooMaxAge.class, type, null); - assertEquals(10000L, type.getMaxAge()); - assertEquals(-1, type.getMaxIdleTime()); - } - - public void testBadFooBoth() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - try { - processor.visitClass(null, BadFooBoth.class, type, null); - fail(); - } catch (InvalidConversationalImplementation e) { - // expected - } - } - - public void testImplicitScope() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitClass(null, ImplicitFooScope.class, type, null); - assertEquals(org.apache.tuscany.spi.model.Scope.CONVERSATION, type.getImplementationScope()); - } - - public void testBadFooScope() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - try { - processor.visitClass(null, BadFooScope.class, type, null); - fail(); - } catch (InvalidConversationalImplementation e) { - // expected - } - } - - public void testJustConversation() throws Exception { - // TODO do we want these semantics - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitClass(null, FooJustConversation.class, type, null); - assertEquals(org.apache.tuscany.spi.model.Scope.CONVERSATION, type.getImplementationScope()); - assertEquals(-1, type.getMaxAge()); - assertEquals(-1, type.getMaxIdleTime()); - } - - public void testSetConversationIDField() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Field field = FooWithConversationIDField.class.getDeclaredField("conversationID"); - processor.visitField(null, field, type, null); - assertNotNull(type.getConversationIDMember()); - assertEquals(field, type.getConversationIDMember()); - } - - public void testSetConversationIDMethod() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Method method = FooWithConversationIDMethod.class.getDeclaredMethods()[0]; - processor.visitMethod(null, method, type, null); - assertNotNull(type.getConversationIDMember()); - assertEquals(method, type.getConversationIDMember()); - } - - @Scope("CONVERSATION") - @ConversationAttributes(maxIdleTime = "10 seconds") - private class FooMaxIdle { - } - - @Scope("CONVERSATION") - @ConversationAttributes(maxAge = "10 seconds") - private class FooMaxAge { - } - - @Scope("CONVERSATION") - @ConversationAttributes(maxAge = "10 seconds", maxIdleTime = "10 seconds") - private class BadFooBoth { - } - - @ConversationAttributes(maxAge = "10 seconds") - private class ImplicitFooScope { - } - - @Scope("STATELESS") - @ConversationAttributes(maxAge = "10 seconds") - private class BadFooScope { - } - - @ConversationAttributes - private class FooJustConversation { - } - - private class FooWithConversationIDField { - @ConversationID - private String conversationID; - } - - private class FooWithConversationIDMethod { - @ConversationID - void setConversationID(String conversationID) { - } - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConvertTimeMillisTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConvertTimeMillisTestCase.java deleted file mode 100644 index 556416a797..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ConvertTimeMillisTestCase.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.processor; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class ConvertTimeMillisTestCase extends TestCase { - private MockProcessor registy; - - public void testConvertSeconds() throws Exception { - assertEquals(10000L, registy.convertTimeMillis("10 seconds")); - assertEquals(10000L, registy.convertTimeMillis("10 SECONDS")); - try { - registy.convertTimeMillis("10seconds"); - fail(); - } catch (NumberFormatException e) { - // expected - } - } - - public void testConvertMinutes() throws Exception { - assertEquals(600000L, registy.convertTimeMillis("10 minutes")); - assertEquals(600000L, registy.convertTimeMillis("10 MINUTES")); - try { - registy.convertTimeMillis("10minutes"); - fail(); - } catch (NumberFormatException e) { - // expected - } - } - - public void testConvertHours() throws Exception { - assertEquals(36000000L, registy.convertTimeMillis("10 hours")); - assertEquals(36000000L, registy.convertTimeMillis("10 HOURS")); - try { - registy.convertTimeMillis("10hours"); - fail(); - } catch (NumberFormatException e) { - // expected - } - } - - public void testConvertDays() throws Exception { - assertEquals(864000000L, registy.convertTimeMillis("10 days")); - assertEquals(864000000L, registy.convertTimeMillis("10 DAYS")); - try { - registy.convertTimeMillis("10days"); - fail(); - } catch (NumberFormatException e) { - // expected - } - } - - public void testConvertYears() throws Exception { - assertEquals(315569260000L, registy.convertTimeMillis("10 years")); - assertEquals(315569260000L, registy.convertTimeMillis("10 YEARS")); - try { - registy.convertTimeMillis("10years"); - fail(); - } catch (NumberFormatException e) { - // expected - } - } - - public void testConvertDefault() throws Exception { - assertEquals(10000L, registy.convertTimeMillis("10 ")); - assertEquals(10000L, registy.convertTimeMillis("10")); - } - - public void testInvalid() throws Exception { - try { - registy.convertTimeMillis("foo"); - fail(); - } catch (NumberFormatException e) { - // expected - } - } - - protected void setUp() throws Exception { - super.setUp(); - registy = new MockProcessor(); - } - - private class MockProcessor extends ConversationProcessor { - - @Override - protected long convertTimeMillis(String expr) throws NumberFormatException { - return super.convertTimeMillis(expr); - } - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/DestroyProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/DestroyProcessorTestCase.java deleted file mode 100644 index 6929250298..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/DestroyProcessorTestCase.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.processor; - -import java.lang.reflect.Method; - -import org.osoa.sca.annotations.Destroy; - -import org.apache.tuscany.spi.implementation.java.JavaMappedService; - -import junit.framework.TestCase; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; - -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; - -/** - * @version $Rev$ $Date$ - */ -public class DestroyProcessorTestCase extends TestCase { - - public void testDestroy() throws Exception { - DestroyProcessor processor = new DestroyProcessor(); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Method method = Foo.class.getMethod("destroy"); - processor.visitMethod(null, method, type, null); - assertNotNull(type.getDestroyMethod()); - } - - public void testBadDestroy() throws Exception { - DestroyProcessor processor = new DestroyProcessor(); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Method method = Bar.class.getMethod("badDestroy", String.class); - try { - processor.visitMethod(null, method, type, null); - fail(); - } catch (IllegalDestructorException e) { - // expected - } - } - - public void testTwoDestroy() throws Exception { - DestroyProcessor processor = new DestroyProcessor(); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Method method = Bar.class.getMethod("destroy"); - Method method2 = Bar.class.getMethod("destroy2"); - processor.visitMethod(null, method, type, null); - try { - processor.visitMethod(null, method2, type, null); - fail(); - } catch (DuplicateDestructorException e) { - // expected - } - } - - - private class Foo { - - @Destroy - public void destroy() { - } - } - - - private class Bar { - - @Destroy - public void destroy() { - } - - @Destroy - public void destroy2() { - } - - @Destroy - public void badDestroy(String foo) { - } - - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/EagerInitProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/EagerInitProcessorTestCase.java deleted file mode 100644 index 22770cbfce..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/EagerInitProcessorTestCase.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.apache.tuscany.core.implementation.processor; - -import org.osoa.sca.annotations.EagerInit; - -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.implementation.java.ProcessingException; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class EagerInitProcessorTestCase extends TestCase { - - public void testNoLevel() throws ProcessingException { - EagerInitProcessor processor = new EagerInitProcessor(); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitClass(null, NoLevel.class, type, null); - assertEquals(50, type.getInitLevel()); - } - - public void testLevel() throws ProcessingException { - EagerInitProcessor processor = new EagerInitProcessor(); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitClass(null, Level.class, type, null); - assertEquals(50, type.getInitLevel()); - } - - public void testSubclass() throws ProcessingException { - EagerInitProcessor processor = new EagerInitProcessor(); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitClass(null, SubClass.class, type, null); - assertEquals(50, type.getInitLevel()); - } - - @EagerInit - private class NoLevel { - } - - @EagerInit - private class Level { - } - - private class SubClass extends Level { - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicAndPropertyTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicAndPropertyTestCase.java deleted file mode 100644 index 93de605e33..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicAndPropertyTestCase.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.processor; - -import java.lang.reflect.Constructor; - -import org.osoa.sca.annotations.Property; - -import org.apache.tuscany.spi.implementation.java.ConstructorDefinition; -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; - -/** - * @version $Rev$ $Date$ - */ -public class HeuristicAndPropertyTestCase extends TestCase { - - private PropertyProcessor propertyProcessor; - private HeuristicPojoProcessor heuristicProcessor; - - /** - * Verifies the property and heuristic processors don't collide - */ - @SuppressWarnings("unchecked") - public void testPropertyProcessorWithHeuristicProcessor() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor ctor = Foo.class.getConstructor(String.class); - type.setConstructorDefinition(new ConstructorDefinition(ctor)); - propertyProcessor.visitConstructor(null, ctor, type, null); - heuristicProcessor.visitEnd(null, Foo.class, type, null); - assertEquals(1, type.getProperties().size()); - assertNotNull(type.getProperties().get("foo")); - } - - protected void setUp() throws Exception { - super.setUp(); - ImplementationProcessorServiceImpl service = - new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl()); - propertyProcessor = new PropertyProcessor(service); - heuristicProcessor = new HeuristicPojoProcessor(service); - } - - public static class Foo { - public Foo(@Property(name = "foo") String prop) { - } - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java deleted file mode 100644 index 92f6d54366..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicConstructorTestCase.java +++ /dev/null @@ -1,330 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.processor; - -import org.osoa.sca.annotations.Property; -import org.osoa.sca.annotations.Reference; -import org.osoa.sca.annotations.Remotable; - -import org.apache.tuscany.spi.annotation.Autowire; -import org.apache.tuscany.spi.idl.java.JavaServiceContract; -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.model.ServiceContract; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; - -/** - * @version $Rev$ $Date$ - */ -public class HeuristicConstructorTestCase extends TestCase { - - private HeuristicPojoProcessor processor = - new HeuristicPojoProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl())); - - /** - * Verifies a single constructor is chosen with a parameter as the type - */ - public void testSingleConstructorWithParam() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - JavaMappedProperty<String> prop = new JavaMappedProperty<String>(); - prop.setName("foo"); - prop.setJavaType(String.class); - type.getProperties().put("foo", prop); - processor.visitEnd(null, Foo1.class, type, null); - assertNotNull(type.getConstructorDefinition().getConstructor()); - assertEquals("foo", type.getConstructorDefinition().getInjectionNames().get(0)); - } - - /** - * Verifies a single constructor is chosen with a reference as the type - */ - public void testSingleConstructorWithRef() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - JavaMappedReference ref = new JavaMappedReference(); - ref.setName("foo"); - ServiceContract contract = new JavaServiceContract(String.class); - ref.setServiceContract(contract); - type.getReferences().put("foo", ref); - processor.visitEnd(null, Foo1.class, type, null); - assertNotNull(type.getConstructorDefinition().getConstructor()); - assertEquals("foo", type.getConstructorDefinition().getInjectionNames().get(0)); - } - - /** - * Verifies a single constructor is chosen with a property and a reference as the type - */ - public void testSingleConstructorWithPropRef() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - - JavaMappedProperty<String> prop = new JavaMappedProperty<String>(); - prop.setName("foo"); - prop.setJavaType(String.class); - type.getProperties().put("foo", prop); - - JavaMappedReference ref = new JavaMappedReference(); - ref.setName("ref"); - ServiceContract contract = new JavaServiceContract(Foo1.class); - ref.setServiceContract(contract); - type.getReferences().put("ref", ref); - processor.visitEnd(null, Foo2.class, type, null); - assertNotNull(type.getConstructorDefinition().getConstructor()); - assertEquals(2, type.getConstructorDefinition().getInjectionNames().size()); - } - - - public void testSingleConstructorResolvableParam() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitEnd(null, Foo5.class, type, null); - assertEquals(String.class, type.getProperties().get("string").getJavaType()); - } - - public void testSingleConstructorResolvableRef() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitEnd(null, Foo6.class, type, null); - assertEquals(Ref.class, - type.getReferences().get("heuristicconstructortestcase$ref").getServiceContract().getInterfaceClass()); - } - - public void testSingleConstructorAmbiguousRef() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - JavaMappedReference ref = new JavaMappedReference(); - ref.setName("ref"); - ServiceContract contract = new JavaServiceContract(Foo1.class); - ref.setServiceContract(contract); - type.getReferences().put("ref", ref); - JavaMappedReference ref2 = new JavaMappedReference(); - ref2.setName("ref2"); - ref2.setServiceContract(contract); - type.getReferences().put("ref2", ref2); - try { - processor.visitEnd(null, Foo4.class, type, null); - fail(); - } catch (AmbiguousConstructorException e) { - // expected - } - } - - public void testConstructorPropertyAnnotatedParamsOnly() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitEnd(null, Foo7.class, type, null); - assertNotNull(type.getProperties().get("myProp")); - } - - public void testConstructorReferenceAnnotatedParamsOnly() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitEnd(null, Foo8.class, type, null); - assertNotNull(type.getReferences().get("myRef")); - } - - public void testConstructorAutowireAnnotatedParamsOnly() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitEnd(null, Foo9.class, type, null); - assertNotNull(type.getReferences().get("myAutowire")); - } - - @SuppressWarnings("unchecked") - public void testDefaultConstructor() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitEnd(null, Foo3.class, type, null); - assertNotNull(type.getConstructorDefinition().getConstructor()); - } - - public void testSameTypesButAnnotated() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitEnd(null, Foo12.class, type, null); - assertEquals(2, type.getProperties().size()); - assertNotNull(type.getProperties().get("prop1")); - assertNotNull(type.getProperties().get("prop2")); - } - - /** - * Verifies processing executes with additional extension annotations - */ - public void testRandomAnnotation() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitEnd(null, Foo11.class, type, null); - assertEquals(1, type.getProperties().size()); - assertNotNull(type.getProperties().get("prop1")); - } - - public void testAutowire() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitEnd(null, Foo13.class, type, null); - assertEquals(1, type.getReferences().size()); - assertNotNull(type.getReferences().get(String.class.getName() + "0")); - } - - public void testMultipleAutowire() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitEnd(null, Foo15.class, type, null); - assertEquals(2, type.getReferences().size()); - assertNotNull(type.getReferences().get(String.class.getName() + "0")); - assertNotNull(type.getReferences().get(String.class.getName() + "1")); - } - - public void testNoAutowireNameInConstructor() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitEnd(null, Foo16.class, type, null); - assertEquals(2, type.getReferences().size()); - assertNotNull(type.getReferences().get(String.class.getName() + "0")); - assertNotNull(type.getReferences().get("bar")); - assertNotNull(type.getProperties().get("foo")); - } - - public void testPrivateConstructor() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - try { - processor.visitEnd(null, Foo14.class, type, null); - fail(); - } catch (NoConstructorException e) { - // expected - } - } - - - public void testMultipleConstructors() throws Exception { - // throw new UnsupportedOperationException("Finish heuristic multiple constructors - Foo10"); - } - - - public static class Foo1 { - public Foo1(String val) { - } - } - - public static class Foo2 { - public Foo2(String val, Foo1 ref) { - } - } - - public static class Foo3 { - } - - public static class Foo4 { - public Foo4(Foo1 ref) { - } - } - - public static class Prop { - - } - - @Remotable - public static interface Ref { - - } - - public static class Foo5 { - public Foo5(String val) { - } - } - - public static class Foo6 { - public Foo6(Ref ref) { - } - } - - public static class Foo7 { - public Foo7(@Property(name = "myProp") String prop) { - } - } - - - public static class Foo8 { - public Foo8(@Reference(name = "myRef") String ref) { - } - } - - public static class Foo9 { - public Foo9(@Autowire(name = "myAutowire") String autowire) { - } - } - - public static class Foo10 { - - public Foo10() { - } - - public Foo10(String prop) { - } - - public Foo10(@Property(name = "prop1") String prop1, @Property(name = "prop2") String prop2) { - - } - } - - public static class Foo11 { - - public Foo11(@Property(name = "prop1") String prop, @Baz String baz) { - } - } - - public static class Foo12 { - - public Foo12(@Property(name = "prop1") String prop, @Property(name = "prop2") String baz) { - } - } - - public @interface Baz { - - } - - public static class Foo13 { - public Foo13(@Autowire String foo) { - } - } - - public static final class Foo14 { - private Foo14() { - } - } - - public static final class Foo15 { - public Foo15(@Autowire String param1, @Autowire String param2) { - } - } - - public static final class Foo16 { - public Foo16(@Autowire String param1, - @Property(name = "foo") String param2, - @Reference(name = "bar") String param3) { - } - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessorTestCase.java deleted file mode 100644 index 2b3c12a3aa..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeuristicPojoProcessorTestCase.java +++ /dev/null @@ -1,395 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.processor; - -import java.lang.reflect.Constructor; -import java.util.Collection; -import java.util.List; - -import org.osoa.sca.annotations.Property; -import org.osoa.sca.annotations.Reference; -import org.osoa.sca.annotations.Remotable; -import org.osoa.sca.annotations.Service; - -import org.apache.tuscany.spi.databinding.extension.SimpleTypeMapperExtension; -import org.apache.tuscany.spi.implementation.java.ConstructorDefinition; -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.implementation.java.ProcessingException; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; - -/** - * Verfies component type information is properly introspected from an unadorned POJO according to the SCA Java Client - * and Implementation Model Specification - * - * @version $Rev$ $Date$ - */ -public class HeuristicPojoProcessorTestCase extends TestCase { - - private HeuristicPojoProcessor processor = - new HeuristicPojoProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl())); - - /** - * Verifies a single service interface is computed when only one interface is implemented - */ - public void testSingleInterface() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<SingleInterfaceImpl> ctor = SingleInterfaceImpl.class.getConstructor(); - type.setConstructorDefinition(new ConstructorDefinition<SingleInterfaceImpl>(ctor)); - processor.visitEnd(null, SingleInterfaceImpl.class, type, null); - assertEquals(1, type.getServices().size()); - assertEquals(PropertyInterface.class, - type.getServices().get(PropertyInterface.class.getSimpleName()) - .getServiceContract().getInterfaceClass()); - assertTrue(type.getProperties().isEmpty()); - assertTrue(type.getReferences().isEmpty()); - } - - /** - * Verifies property and reference setters are computed - */ - public void testPropertyReference() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<SingleInterfaceWithPropertyReferenceImpl> ctor = - SingleInterfaceWithPropertyReferenceImpl.class.getConstructor(); - type.setConstructorDefinition(new ConstructorDefinition<SingleInterfaceWithPropertyReferenceImpl>(ctor)); - processor.visitEnd(null, SingleInterfaceWithPropertyReferenceImpl.class, type, null); - assertEquals(1, type.getServices().size()); - assertEquals(Interface1.class, - type.getServices().get(Interface1.class.getSimpleName()) - .getServiceContract().getInterfaceClass()); - assertEquals(1, type.getProperties().size()); - assertEquals(ComplexProperty.class, type.getProperties().get("property").getJavaType()); - assertEquals(1, type.getReferences().size()); - assertEquals(Ref.class, type.getReferences().get("reference").getServiceContract().getInterfaceClass()); - } - - /** - * Verifies that a property setter is not introspected if an analogous operation is in the service interface - */ - public void testPropertySetterInInterface() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<SingleInterfaceImpl> ctor = SingleInterfaceImpl.class.getConstructor(); - type.setConstructorDefinition(new ConstructorDefinition<SingleInterfaceImpl>(ctor)); - processor.visitEnd(null, SingleInterfaceImpl.class, type, null); - assertEquals(0, type.getProperties().size()); - } - - /** - * Verifies that a reference setter is not introspected if an analogous operation is in the service interface - */ - public void testReferenceSetterInInterface() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<RefInterfaceImpl> ctor = RefInterfaceImpl.class.getConstructor(); - type.setConstructorDefinition(new ConstructorDefinition<RefInterfaceImpl>(ctor)); - processor.visitEnd(null, RefInterfaceImpl.class, type, null); - assertEquals(0, type.getReferences().size()); - } - - /** - * Verifies collection generic types or array types are introspected as references according to spec rules - */ - public void testReferenceCollectionType() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<ReferenceCollectionImpl> ctor = ReferenceCollectionImpl.class.getConstructor(); - type.setConstructorDefinition(new ConstructorDefinition<ReferenceCollectionImpl>(ctor)); - processor.visitEnd(null, ReferenceCollectionImpl.class, type, null); - assertEquals(0, type.getProperties().size()); - assertEquals(4, type.getReferences().size()); - } - - /** - * Verifies collection generic types or array types are introspected as properties according to spec rules - */ - public void testPropertyCollectionType() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<PropertyCollectionImpl> ctor = PropertyCollectionImpl.class.getConstructor(); - type.setConstructorDefinition(new ConstructorDefinition<PropertyCollectionImpl>(ctor)); - processor.visitEnd(null, PropertyCollectionImpl.class, type, null); - assertEquals(0, type.getReferences().size()); - assertEquals(4, type.getProperties().size()); - } - - /** - * Verifies references are calculated when the type marked with is @Remotable - */ - public void testRemotableRef() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<RemotableRefImpl> ctor = RemotableRefImpl.class.getConstructor(); - type.setConstructorDefinition(new ConstructorDefinition<RemotableRefImpl>(ctor)); - processor.visitEnd(null, RemotableRefImpl.class, type, null); - assertEquals(2, type.getReferences().size()); - assertEquals(0, type.getProperties().size()); - } - - public void testParentInterface() throws ProcessingException, NoSuchMethodException { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<Child> ctor = Child.class.getConstructor(); - type.setConstructorDefinition(new ConstructorDefinition<Child>(ctor)); - processor.visitEnd(null, Child.class, type, null); - assertTrue(type.getServices().containsKey(Interface1.class.getSimpleName())); - } - - /** - * Verifies a service inteface is calculated when only props and refs are given - */ - public void testExcludedPropertyAndReference() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - JavaMappedReference ref = new JavaMappedReference(); - ref.setName("reference"); - type.add(ref); - JavaMappedReference ref2 = new JavaMappedReference(); - ref2.setName("reference2"); - type.add(ref2); - JavaMappedProperty<?> prop1 = new JavaMappedProperty(); - prop1.setName("string1"); - type.add(prop1); - JavaMappedProperty<?> prop2 = new JavaMappedProperty(); - prop2.setName("string2"); - type.add(prop2); - processor.visitEnd(null, MockService.class, type, null); - assertEquals(1, type.getServices().size()); - } - - public void testProtectedRemotableRefField() throws ProcessingException, NoSuchMethodException { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<ProtectedRemotableRefFieldImpl> ctor = ProtectedRemotableRefFieldImpl.class.getConstructor(); - type.setConstructorDefinition(new ConstructorDefinition<ProtectedRemotableRefFieldImpl>(ctor)); - processor.visitEnd(null, ProtectedRemotableRefFieldImpl.class, type, null); - assertNotNull(type.getReferences().get("otherRef")); - } - - public void testProtectedRemotableRefMethod() throws ProcessingException, NoSuchMethodException { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<ProtectedRemotableRefMethodImpl> ctor = ProtectedRemotableRefMethodImpl.class.getConstructor(); - type.setConstructorDefinition(new ConstructorDefinition<ProtectedRemotableRefMethodImpl>(ctor)); - processor.visitEnd(null, ProtectedRemotableRefMethodImpl.class, type, null); - assertNotNull(type.getReferences().get("otherRef")); - } - - public void testSetDataTypes() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<PropertyIntTypeOnConstructor> ctor = PropertyIntTypeOnConstructor.class.getConstructor(int.class); - type.setConstructorDefinition(new ConstructorDefinition<PropertyIntTypeOnConstructor>(ctor)); - processor.visitEnd(null, ProtectedRemotableRefMethodImpl.class, type, null); - org.apache.tuscany.spi.model.Property<?> foo = type.getProperties().get("foo"); - assertEquals(int.class, foo.getJavaType()); - assertEquals(SimpleTypeMapperExtension.XSD_INT, foo.getXmlType()); - } - - private static class PropertyIntTypeOnConstructor { - private int foo; - - public PropertyIntTypeOnConstructor(@Property(name = "foo")int foo) { - this.foo = foo; - } - - public int getFoo() { - return foo; - } - } - - private interface PropertyInterface { - void setString1(String val); - } - - private interface Interface1 { - } - - private static class Parent implements Interface1 { - - } - - private static class Child extends Parent { - public Child() { - } - - } - - private static class SingleInterfaceImpl implements PropertyInterface { - public SingleInterfaceImpl() { - } - - public void setString1(String val) { - } - - } - - private interface HeuristicServiceInterface { - void fooOperation(String ref); - - void setInvalid1(); // No parameter - - void setInvalid2(String str, int i); // More than one parameter - - String setInvalid3(String str); // return should be void - } - - public static class MockService implements PropertyInterface, RefInterface, HeuristicServiceInterface { - - @Property - public void setString1(String val) { - } - - @Property - public void setString2(String val) { - } - - @Reference - public void setReference(Ref ref) { - } - - @Reference - public void setReference2(Ref ref) { - } - - public void fooOperation(String ref) { - - } - - public void setInvalid1() { - } - - public void setInvalid2(String str, int i) { - } - - public String setInvalid3(String str) { - return null; - } - - } - - @Service - private interface Ref { - } - - private class ComplexProperty { - } - - private interface RefInterface { - void setReference(Ref ref); - } - - private static class RefInterfaceImpl implements RefInterface { - public RefInterfaceImpl() { - } - - public void setReference(Ref ref) { - } - } - - private static class SingleInterfaceWithPropertyReferenceImpl implements Interface1 { - public SingleInterfaceWithPropertyReferenceImpl() { - } - - public void setReference(Ref ref) { - } - - public void setProperty(ComplexProperty prop) { - } - } - - private static class ReferenceCollectionImpl implements Interface1 { - public ReferenceCollectionImpl() { - } - - public void setCollectionReference(Collection<Ref> ref) { - } - - public void setNonGenericCollectionReference(Collection ref) { - } - - public void setListReference(List<Ref> ref) { - } - - public void setArrayReference(Ref[] ref) { - } - } - - private static class PropertyCollectionImpl implements Interface1 { - public PropertyCollectionImpl() { - } - - public void setCollectionProperty(Collection<ComplexProperty> prop) { - } - - public void setCollectionProperty2(Collection<String> prop) { - } - - public void setArrayProperty(ComplexProperty[] prop) { - } - - public void setArrayProperty2(String[] prop) { - } - } - - @Remotable - private interface RemotableRef { - } - - private static class RemotableRefImpl implements Interface1 { - protected RemotableRef otherRef; - - public RemotableRefImpl() { - } - - public void setRef(RemotableRef ref) { - - } - } - - private static class ProtectedRemotableRefFieldImpl implements Interface1 { - protected RemotableRef otherRef; - - public ProtectedRemotableRefFieldImpl() { - } - - public ProtectedRemotableRefFieldImpl(RemotableRef otherRef) { - this.otherRef = otherRef; - } - - } - - private static class ProtectedRemotableRefMethodImpl implements Interface1 { - public ProtectedRemotableRefMethodImpl() { - } - - protected void setOtherRef(RemotableRef otherRef) { - } - - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java deleted file mode 100644 index 4e6c1063d8..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/HeutisticExtensibleConstructorTestCase.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.processor; - -import java.lang.reflect.Constructor; -import java.util.List; - -import org.apache.tuscany.spi.implementation.java.ConstructorDefinition; -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; - -/** - * Verifies constructors that have extensible annotation types, i.e. that have parameters marked by annotations which - * are themselves processed by some other implementation processor - * - * @version $Rev$ $Date$ - */ -public class HeutisticExtensibleConstructorTestCase extends TestCase { - - private HeuristicPojoProcessor processor = - new HeuristicPojoProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl())); - - /** - * Verifies heuristic processing can be called priot to an extension annotation processors being called. - */ - public void testBarAnnotationProcessedFirst() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class); - ConstructorDefinition<Foo> definition = new ConstructorDefinition<Foo>(ctor); - type.setConstructorDefinition(definition); - JavaMappedProperty property = new JavaMappedProperty(); - property.setName("myBar"); - definition.getInjectionNames().add("myBar"); - type.getProperties().put("myBar", property); - processor.visitEnd(null, Foo.class, type, null); - assertEquals(2, type.getProperties().size()); - } - - /** - * Verifies heuristic processing can be called before an extension annotation processors is called. - * <p/> - * For example, given: - * <pre> Foo(@Bar String prop, @org.osoa.sca.annotations.Property(name = "foo") String prop2)</pre> - * <p/> - * Heuristic evaluation of @Property can occur prior to another implementation processor evaluating @Bar - * - * @throws Exception - */ - public void testBarAnnotationProcessedLast() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitEnd(null, Foo.class, type, null); - - // now simulate process the bar impl - ConstructorDefinition<?> definition = type.getConstructorDefinition(); - List<String> injectionNames = definition.getInjectionNames(); - injectionNames.remove(0); - injectionNames.add(0, "mybar"); - type.getProperties().put("mybar", new JavaMappedProperty<String>()); - - assertEquals(2, type.getProperties().size()); - assertEquals("foo", definition.getInjectionNames().get(1)); - } - - /** - * Verifies heuristic processing can be called before an extension annotation processors is called with the - * extension parameter in a middle position. Specifically, verifies that the heuristic processor updates injection - * names and preserves their ordering. - */ - public void testBarAnnotationProcessedFirstInMiddle() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<Foo2> ctor = Foo2.class.getConstructor(String.class, String.class, String.class); - ConstructorDefinition<Foo2> definition = new ConstructorDefinition<Foo2>(ctor); - type.setConstructorDefinition(definition); - // insert placeholder for first param, which would be done by a processor - definition.getInjectionNames().add(""); - JavaMappedProperty property = new JavaMappedProperty(); - property.setName("myBar"); - definition.getInjectionNames().add("myBar"); - type.getProperties().put("myBar", property); - processor.visitEnd(null, Foo2.class, type, null); - assertEquals("baz", definition.getInjectionNames().get(0)); - assertEquals(2, type.getProperties().size()); - assertEquals(1, type.getReferences().size()); - } - - public @interface Bar { - - } - - public static class Foo { - public Foo(@Bar String prop, @org.osoa.sca.annotations.Property(name = "foo") String prop2) { - } - } - - public static class Foo2 { - public Foo2(@org.osoa.sca.annotations.Reference(name = "baz") String prop1, - @Bar String prop2, - @org.osoa.sca.annotations.Property(name = "foo") String prop3) { - } - } - - -} - - diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceTestCase.java deleted file mode 100644 index e843467866..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceTestCase.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.processor; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Constructor; -import java.util.ArrayList; -import java.util.List; - -import org.osoa.sca.annotations.Callback; -import org.osoa.sca.annotations.Property; -import org.osoa.sca.annotations.Remotable; -import org.osoa.sca.annotations.Scope; - -import org.apache.tuscany.spi.databinding.extension.SimpleTypeMapperExtension; -import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry; -import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService; -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.model.InteractionScope; -import org.apache.tuscany.spi.model.ServiceContract; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; - -/** - * @version $Rev$ $Date$ - */ -public class ImplementationProcessorServiceTestCase extends TestCase { - private JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - private ImplementationProcessorService implService = new ImplementationProcessorServiceImpl(registry); - - - public void testCreateConversationalService() throws Exception { - JavaMappedService service = implService.createService(Foo.class); - service.setServiceContract(registry.introspect(Foo.class, true)); - assertTrue(Foo.class.equals(service.getServiceContract().getInterfaceClass())); - assertTrue(service.isRemotable()); - assertEquals(InteractionScope.CONVERSATIONAL, service.getServiceContract().getInteractionScope()); - ServiceContract serviceContract = service.getServiceContract(); - assertTrue(Bar.class.equals(serviceContract.getCallbackClass())); - assertTrue("ImplementationProcessorServiceTestCase$Bar".equals(serviceContract.getCallbackName())); - } - - public void testCreateDefaultService() throws Exception { - JavaMappedService service = implService.createService(Baz.class); - service.setServiceContract(registry.introspect(Baz.class, true)); - assertTrue(Baz.class.equals(service.getServiceContract().getInterfaceClass())); - assertTrue(!service.isRemotable()); - assertEquals(InteractionScope.NONCONVERSATIONAL, service.getServiceContract().getInteractionScope()); - } - - public void testProcessParamProperty() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<PropertyClass> ctor = PropertyClass.class.getConstructor(int.class); - Annotation[] paramAnnotations = ctor.getParameterAnnotations()[0]; - List<String> injectionNames = new ArrayList<String>(); - String[] names = new String[]{"foo"}; - implService.processParam(int.class, - ctor.getGenericParameterTypes()[0], - paramAnnotations, - names, - 0, - type, - injectionNames); - org.apache.tuscany.spi.model.Property<?> property = type.getProperties().get("foo"); - assertEquals(int.class, property.getJavaType()); - assertEquals(SimpleTypeMapperExtension.XSD_INT, property.getXmlType()); - } - - - @Callback(Bar.class) - @Remotable - @Scope("CONVERSATION") - public interface Foo { - - } - - public interface Bar { - - } - - public interface Baz { - - } - - public static class PropertyClass { - private int foo; - - public PropertyClass(@Property(name = "foo") int foo) { - this.foo = foo; - } - - public int getFoo() { - return foo; - } - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceUniqueTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceUniqueTestCase.java deleted file mode 100644 index da45ed2d46..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ImplementationProcessorServiceUniqueTestCase.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.processor; - -import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; - -/** - * @version $Rev$ $Date$ - */ -public class ImplementationProcessorServiceUniqueTestCase extends TestCase { - - private ImplementationProcessorService service = - new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl()); - - public void testUniquess1() throws Exception { - Class[] classes = new Class[2]; - classes[0] = String.class; - classes[1] = Integer.class; - assertTrue(service.areUnique(classes)); - } - - public void testUniquess2() throws Exception { - Class[] classes = new Class[2]; - classes[0] = String.class; - classes[1] = String.class; - assertFalse(service.areUnique(classes)); - } - - public void testUniquess3() throws Exception { - Class[] classes = new Class[1]; - classes[0] = String.class; - assertTrue(service.areUnique(classes)); - } - - public void testUniquess4() throws Exception { - Class[] classes = new Class[3]; - classes[0] = String.class; - classes[1] = Integer.class; - classes[2] = String.class; - assertFalse(service.areUnique(classes)); - } - - public void testUniquess5() throws Exception { - Class[] classes = new Class[0]; - assertTrue(service.areUnique(classes)); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/InitProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/InitProcessorTestCase.java deleted file mode 100644 index 13fe7d003a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/InitProcessorTestCase.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.processor; - -import java.lang.reflect.Method; - -import org.osoa.sca.annotations.Init; - -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class InitProcessorTestCase extends TestCase { - - public void testInit() throws Exception { - InitProcessor processor = new InitProcessor(); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Method method = InitProcessorTestCase.Foo.class.getMethod("init"); - processor.visitMethod(null, method, type, null); - assertNotNull(type.getInitMethod()); - assertEquals(0, type.getInitLevel()); - } - - public void testBadInit() throws Exception { - InitProcessor processor = new InitProcessor(); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Method method = InitProcessorTestCase.Bar.class.getMethod("badInit", String.class); - try { - processor.visitMethod(null, method, type, null); - fail(); - } catch (IllegalInitException e) { - // expected - } - } - - public void testTwoInit() throws Exception { - InitProcessor processor = new InitProcessor(); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Method method = InitProcessorTestCase.Bar.class.getMethod("init"); - Method method2 = InitProcessorTestCase.Bar.class.getMethod("init2"); - processor.visitMethod(null, method, type, null); - try { - processor.visitMethod(null, method2, type, null); - fail(); - } catch (DuplicateInitException e) { - // expected - } - } - - - private class Foo { - @Init - public void init() { - } - } - - - private class Bar { - @Init - public void init() { - } - - @Init - public void init2() { - } - - @Init - public void badInit(String foo) { - } - - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/MonitorProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/MonitorProcessorTestCase.java deleted file mode 100644 index 8982fa3991..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/MonitorProcessorTestCase.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.processor; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.Map; - -import org.apache.tuscany.spi.implementation.java.ConstructorDefinition; -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.implementation.java.IllegalPropertyException; - -import junit.framework.TestCase; -import org.apache.tuscany.api.annotation.Monitor; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -import org.apache.tuscany.core.injection.SingletonObjectFactory; -import org.apache.tuscany.host.MonitorFactory; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class MonitorProcessorTestCase extends TestCase { - - private MonitorProcessor processor; - private MonitorFactory monitorFactory; - - public void testSetter() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Method method = Foo.class.getMethod("setMonitor", Foo.class); - EasyMock.expect(monitorFactory.getMonitor(EasyMock.eq(Foo.class))).andReturn(null); - EasyMock.replay(monitorFactory); - processor.visitMethod(null, method, type, null); - Map<String, JavaMappedProperty<?>> properties = type.getProperties(); - assertTrue(properties.get("monitor").getDefaultValueFactory() instanceof SingletonObjectFactory); - EasyMock.verify(monitorFactory); - } - - - public void testBadSetter() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Method method = BadMonitor.class.getMethod("setMonitor"); - try { - processor.visitMethod(null, method, type, null); - fail(); - } catch (IllegalPropertyException e) { - // expected - } - } - - public void testField() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Field field = Foo.class.getDeclaredField("bar"); - EasyMock.expect(monitorFactory.getMonitor(EasyMock.eq(Foo.class))).andReturn(null); - EasyMock.replay(monitorFactory); - processor.visitField(null, field, type, null); - Map<String, JavaMappedProperty<?>> properties = type.getProperties(); - assertTrue(properties.get("bar").getDefaultValueFactory() instanceof SingletonObjectFactory); - EasyMock.verify(monitorFactory); - } - - public void testConstructor() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<Bar> ctor = Bar.class.getConstructor(BazMonitor.class); - EasyMock.expect(monitorFactory.getMonitor(EasyMock.eq(BazMonitor.class))).andReturn(null); - EasyMock.replay(monitorFactory); - processor.visitConstructor(null, ctor, type, null); - Map<String, JavaMappedProperty<?>> properties = type.getProperties(); - assertTrue( - properties.get(BazMonitor.class.getName()).getDefaultValueFactory() instanceof SingletonObjectFactory); - EasyMock.verify(monitorFactory); - } - - /** - * Verifies calling the monitor processor to evaluate a constructor can be done after a property parameter is - * processed - */ - public void testConstructorAfterProperty() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<Bar> ctor = Bar.class.getConstructor(String.class, BazMonitor.class); - EasyMock.expect(monitorFactory.getMonitor(EasyMock.eq(BazMonitor.class))).andReturn(null); - EasyMock.replay(monitorFactory); - ConstructorDefinition<Bar> definition = new ConstructorDefinition<Bar>(ctor); - JavaMappedProperty prop = new JavaMappedProperty(); - definition.getInjectionNames().add("prop"); - type.setConstructorDefinition(definition); - type.getProperties().put("prop", prop); - processor.visitConstructor(null, ctor, type, null); - Map<String, JavaMappedProperty<?>> properties = type.getProperties(); - assertEquals(BazMonitor.class.getName(), definition.getInjectionNames().get(1)); - assertEquals(2, type.getProperties().size()); - String name = BazMonitor.class.getName(); - assertTrue(properties.get(name).getDefaultValueFactory() instanceof SingletonObjectFactory); - EasyMock.verify(monitorFactory); - } - - /** - * Verifies calling the monitor processor to evaluate a constructor can be done before a property parameter is - * processed - */ - public void testConstructorBeforeProperty() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - Constructor<Bar> ctor = Bar.class.getConstructor(String.class, BazMonitor.class); - EasyMock.expect(monitorFactory.getMonitor(EasyMock.eq(BazMonitor.class))).andReturn(null); - EasyMock.replay(monitorFactory); - processor.visitConstructor(null, ctor, type, null); - Map<String, JavaMappedProperty<?>> properties = type.getProperties(); - ConstructorDefinition definition = type.getConstructorDefinition(); - assertEquals(2, definition.getInjectionNames().size()); - assertEquals(BazMonitor.class.getName(), definition.getInjectionNames().get(1)); - String name = BazMonitor.class.getName(); - assertTrue(properties.get(name).getDefaultValueFactory() instanceof SingletonObjectFactory); - EasyMock.verify(monitorFactory); - } - - protected void setUp() throws Exception { - super.setUp(); - monitorFactory = EasyMock.createMock(MonitorFactory.class); - JavaInterfaceProcessorRegistryImpl registry = new JavaInterfaceProcessorRegistryImpl(); - ImplementationProcessorServiceImpl processor = new ImplementationProcessorServiceImpl(registry); - this.processor = new MonitorProcessor(monitorFactory, processor); - } - - private class Foo { - - @Monitor - protected Foo bar; - - @Monitor - public void setMonitor(Foo foo) { - } - } - - - private class BadMonitor { - - @Monitor - public void setMonitor() { - } - } - - private interface BazMonitor { - - } - - private static class Bar { - - public Bar(@Monitor BazMonitor monitor) { - } - - public Bar(String prop, @Monitor BazMonitor monitor) { - } - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/PropertyProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/PropertyProcessorTestCase.java deleted file mode 100644 index a4a60f13a0..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/PropertyProcessorTestCase.java +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.processor; - -import java.util.Collection; -import java.util.List; - -import junit.framework.TestCase; - -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -import org.apache.tuscany.spi.implementation.java.DuplicatePropertyException; -import org.apache.tuscany.spi.implementation.java.IllegalPropertyException; -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.osoa.sca.annotations.Property; - -/** - * @version $Rev$ $Date$ - */ -public class PropertyProcessorTestCase extends TestCase { - - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type; - PropertyProcessor processor; - - public void testMethodAnnotation() throws Exception { - processor.visitMethod(null, Foo.class.getMethod("setFoo", String.class), type, null); - assertNotNull(type.getProperties().get("foo")); - } - - public void testMethodRequired() throws Exception { - processor.visitMethod(null, Foo.class.getMethod("setFooRequired", String.class), type, null); - JavaMappedProperty prop = type.getProperties().get("fooRequired"); - assertNotNull(prop); - } - - public void testMethodName() throws Exception { - processor.visitMethod(null, Foo.class.getMethod("setBarMethod", String.class), type, null); - assertNotNull(type.getProperties().get("bar")); - } - - public void testFieldAnnotation() throws Exception { - processor.visitField(null, Foo.class.getDeclaredField("baz"), type, null); - assertNotNull(type.getProperties().get("baz")); - } - - public void testFieldRequired() throws Exception { - processor.visitField(null, Foo.class.getDeclaredField("bazRequired"), type, null); - JavaMappedProperty prop = type.getProperties().get("bazRequired"); - assertNotNull(prop); - } - - public void testFieldName() throws Exception { - processor.visitField(null, Foo.class.getDeclaredField("bazField"), type, null); - assertNotNull(type.getProperties().get("theBaz")); - } - - public void testDuplicateFields() throws Exception { - processor.visitField(null, Bar.class.getDeclaredField("dup"), type, null); - try { - processor.visitField(null, Bar.class.getDeclaredField("baz"), type, null); - fail(); - } catch (DuplicatePropertyException e) { - // expected - } - } - - public void testDuplicateMethods() throws Exception { - processor.visitMethod(null, Bar.class.getMethod("dupMethod", String.class), type, null); - try { - processor.visitMethod(null, Bar.class.getMethod("dupSomeMethod", String.class), type, null); - fail(); - } catch (DuplicatePropertyException e) { - // expected - } - } - - public void testInvalidProperty() throws Exception { - try { - processor.visitMethod(null, Bar.class.getMethod("badMethod"), type, null); - fail(); - } catch (IllegalPropertyException e) { - // expected - } - } - - protected void setUp() throws Exception { - super.setUp(); - type = new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - JavaInterfaceProcessorRegistryImpl registry = new JavaInterfaceProcessorRegistryImpl(); - processor = new PropertyProcessor(new ImplementationProcessorServiceImpl(registry)); - } - - private class Foo { - - @Property - protected String baz; - @Property(required = true) - protected String bazRequired; - @Property(name = "theBaz") - protected String bazField; - - @Property - public void setFoo(String string) { - } - - @Property(required = true) - public void setFooRequired(String string) { - } - - @Property(name = "bar") - public void setBarMethod(String string) { - } - - } - - private class Bar { - - @Property - protected String dup; - - @Property(name = "dup") - protected String baz; - - @Property - public void dupMethod(String s) { - } - - @Property(name = "dupMethod") - public void dupSomeMethod(String s) { - } - - @Property - public void badMethod() { - } - - } - - private class Multiple { - @Property - protected List<String> refs1; - - @Property - protected String[] refs2; - - @Property - public void setRefs3(String[] refs) { - } - - @Property - public void setRefs4(Collection<String> refs) { - } - - } - - public void testMultiplicityCollection() throws Exception { - processor.visitField(null, Multiple.class.getDeclaredField("refs1"), type, null); - JavaMappedProperty prop = type.getProperties().get("refs1"); - assertNotNull(prop); - assertSame(String.class, prop.getJavaType()); - assertTrue(prop.isMany()); - } - - public void testMultiplicityArray() throws Exception { - processor.visitField(null, Multiple.class.getDeclaredField("refs2"), type, null); - JavaMappedProperty prop = type.getProperties().get("refs2"); - assertNotNull(prop); - assertSame(String.class, prop.getJavaType()); - assertTrue(prop.isMany()); - } - - public void testMultiplicityArrayMethod() throws Exception { - processor.visitMethod(null, Multiple.class.getMethod("setRefs3", String[].class), type, null); - JavaMappedProperty prop = type.getProperties().get("refs3"); - assertNotNull(prop); - assertSame(String.class, prop.getJavaType()); - assertTrue(prop.isMany()); - } - - public void testMultiplicityCollectionMethod() throws Exception { - processor.visitMethod(null, Multiple.class.getMethod("setRefs4", Collection.class), type, null); - JavaMappedProperty prop = type.getProperties().get("refs4"); - assertNotNull(prop); - assertSame(String.class, prop.getJavaType()); - assertTrue(prop.isMany()); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessorTestCase.java deleted file mode 100644 index 80d3687170..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ReferenceProcessorTestCase.java +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.processor; - -import java.util.Collection; -import java.util.List; - -import org.osoa.sca.annotations.Reference; - -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.model.Multiplicity; -import org.apache.tuscany.spi.model.ServiceContract; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; - -/** - * @version $Rev$ $Date$ - */ -public class ReferenceProcessorTestCase extends TestCase { - - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - ReferenceProcessor processor = new ReferenceProcessor(new JavaInterfaceProcessorRegistryImpl()); - - public void testMethodAnnotation() throws Exception { - processor.visitMethod(null, ReferenceProcessorTestCase.Foo.class.getMethod("setFoo", Ref.class), type, null); - JavaMappedReference reference = type.getReferences().get("foo"); - assertNotNull(reference); - ServiceContract contract = reference.getServiceContract(); - assertEquals(Ref.class, contract.getInterfaceClass()); - assertEquals("ReferenceProcessorTestCase$Ref", contract.getInterfaceName()); - } - - public void testMethodRequired() throws Exception { - processor.visitMethod(null, - ReferenceProcessorTestCase.Foo.class.getMethod("setFooRequired", Ref.class), - type, - null); - JavaMappedReference prop = type.getReferences().get("fooRequired"); - assertNotNull(prop); - } - - public void testMethodName() throws Exception { - processor.visitMethod(null, - ReferenceProcessorTestCase.Foo.class.getMethod("setBarMethod", Ref.class), - type, - null); - assertNotNull(type.getReferences().get("bar")); - } - - public void testFieldAnnotation() throws Exception { - processor.visitField(null, ReferenceProcessorTestCase.Foo.class.getDeclaredField("baz"), type, null); - JavaMappedReference reference = type.getReferences().get("baz"); - assertNotNull(reference); - ServiceContract contract = reference.getServiceContract(); - assertEquals(Ref.class, contract.getInterfaceClass()); - assertEquals("ReferenceProcessorTestCase$Ref", contract.getInterfaceName()); - } - - public void testFieldRequired() throws Exception { - processor.visitField(null, ReferenceProcessorTestCase.Foo.class.getDeclaredField("bazRequired"), type, null); - JavaMappedReference prop = type.getReferences().get("bazRequired"); - assertNotNull(prop); - } - - public void testFieldName() throws Exception { - processor.visitField(null, ReferenceProcessorTestCase.Foo.class.getDeclaredField("bazField"), type, null); - assertNotNull(type.getReferences().get("theBaz")); - } - - public void testDuplicateFields() throws Exception { - processor.visitField(null, ReferenceProcessorTestCase.Bar.class.getDeclaredField("dup"), type, null); - try { - processor.visitField(null, ReferenceProcessorTestCase.Bar.class.getDeclaredField("baz"), type, null); - fail(); - } catch (DuplicateReferenceException e) { - // expected - } - } - - public void testDuplicateMethods() throws Exception { - processor.visitMethod(null, ReferenceProcessorTestCase.Bar.class.getMethod("dupMethod", Ref.class), type, null); - try { - processor.visitMethod(null, - ReferenceProcessorTestCase.Bar.class.getMethod("dupSomeMethod", Ref.class), - type, - null); - fail(); - } catch (DuplicateReferenceException e) { - // expected - } - } - - public void testInvalidProperty() throws Exception { - try { - processor.visitMethod(null, ReferenceProcessorTestCase.Bar.class.getMethod("badMethod"), type, null); - fail(); - } catch (IllegalReferenceException e) { - // expected - } - } - - protected void setUp() throws Exception { - super.setUp(); - type = new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor = new ReferenceProcessor(new JavaInterfaceProcessorRegistryImpl()); - } - - private interface Ref { - } - - private class Foo { - - @Reference - protected Ref baz; - @Reference(required = true) - protected Ref bazRequired; - @Reference(name = "theBaz") - protected Ref bazField; - - @Reference - public void setFoo(Ref ref) { - } - - @Reference(required = true) - public void setFooRequired(Ref ref) { - } - - @Reference(name = "bar") - public void setBarMethod(Ref ref) { - } - - } - - private class Bar { - - @Reference - protected Ref dup; - - @Reference(name = "dup") - protected Ref baz; - - @Reference - public void dupMethod(Ref s) { - } - - @Reference(name = "dupMethod") - public void dupSomeMethod(Ref s) { - } - - @Reference - public void badMethod() { - } - - } - - private class Multiple { - @Reference(required = true) - protected List<Ref> refs1; - - @Reference(required = false) - protected Ref[] refs2; - - @Reference(required = true) - public void setRefs3(Ref[] refs) { - } - - @Reference(required = false) - public void setRefs4(Collection<Ref> refs) { - } - - } - - public void testMultiplicity1ToN() throws Exception { - processor.visitField(null, Multiple.class.getDeclaredField("refs1"), type, null); - JavaMappedReference prop = type.getReferences().get("refs1"); - assertNotNull(prop); - assertSame(Ref.class, prop.getServiceContract().getInterfaceClass()); - assertEquals(Multiplicity.ONE_N, prop.getMultiplicity()); - } - - public void testMultiplicityTo0ToN() throws Exception { - processor.visitField(null, Multiple.class.getDeclaredField("refs2"), type, null); - JavaMappedReference prop = type.getReferences().get("refs2"); - assertNotNull(prop); - assertSame(Ref.class, prop.getServiceContract().getInterfaceClass()); - assertEquals(Multiplicity.ZERO_N, prop.getMultiplicity()); - } - - public void testMultiplicity1ToNMethod() throws Exception { - processor.visitMethod(null, Multiple.class.getMethod("setRefs3", Ref[].class), type, null); - JavaMappedReference prop = type.getReferences().get("refs3"); - assertNotNull(prop); - assertSame(Ref.class, prop.getServiceContract().getInterfaceClass()); - assertEquals(Multiplicity.ONE_N, prop.getMultiplicity()); - } - - public void testMultiplicity0ToNMethod() throws Exception { - processor.visitMethod(null, Multiple.class.getMethod("setRefs4", Collection.class), type, null); - JavaMappedReference prop = type.getReferences().get("refs4"); - assertNotNull(prop); - assertSame(Ref.class, prop.getServiceContract().getInterfaceClass()); - assertEquals(Multiplicity.ZERO_N, prop.getMultiplicity()); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ResourceProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ResourceProcessorTestCase.java deleted file mode 100644 index 96bf4a3ed3..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ResourceProcessorTestCase.java +++ /dev/null @@ -1,99 +0,0 @@ -package org.apache.tuscany.core.implementation.processor; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.implementation.java.Resource; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class ResourceProcessorTestCase extends TestCase { - - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type; - ResourceProcessor processor = new ResourceProcessor(); - - public void testVisitField() throws Exception { - Field field = Foo.class.getDeclaredField("bar"); - processor.visitField(null, field, type, null); - Resource resource = type.getResources().get("bar"); - assertFalse(resource.isOptional()); - assertNull(resource.getMappedName()); - assertEquals(field.getType(), resource.getType()); - } - - public void testVisitMethod() throws Exception { - Method method = Foo.class.getMethod("setBar", Bar.class); - processor.visitMethod(null, method, type, null); - Resource resource = type.getResources().get("bar"); - assertFalse(resource.isOptional()); - assertNull(resource.getMappedName()); - assertEquals(method.getParameterTypes()[0], resource.getType()); - } - - public void testVisitNamedMethod() throws Exception { - Method method = Foo.class.getMethod("setBar2", Bar.class); - processor.visitMethod(null, method, type, null); - Resource resource = type.getResources().get("someName"); - assertFalse(resource.isOptional()); - assertEquals("mapped", resource.getMappedName()); - } - - public void testVisitBadMethod() throws Exception { - Method method = Foo.class.getMethod("setBad"); - try { - processor.visitMethod(null, method, type, null); - fail(); - } catch (IllegalResourceException e) { - // expected - } - } - - public void testDuplicateResources() throws Exception { - Field field = Foo.class.getDeclaredField("bar"); - processor.visitField(null, field, type, null); - try { - processor.visitField(null, field, type, null); - fail(); - } catch (DuplicateResourceException e) { - //expected - } - } - - protected void setUp() throws Exception { - super.setUp(); - type = new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - } - - private class Foo { - - @org.apache.tuscany.api.annotation.Resource - protected Bar bar; - - @org.apache.tuscany.api.annotation.Resource(optional = true) - protected Bar barNotRequired; - - @org.apache.tuscany.api.annotation.Resource - public void setBar(Bar bar) { - } - - @org.apache.tuscany.api.annotation.Resource(name = "someName", mappedName = "mapped") - public void setBar2(Bar bar) { - } - - @org.apache.tuscany.api.annotation.Resource - public void setBad() { - } - - } - - private interface Bar { - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ScopeProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ScopeProcessorTestCase.java deleted file mode 100644 index dc65dc44f4..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ScopeProcessorTestCase.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.processor; - -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.implementation.java.ProcessingException; -import org.apache.tuscany.spi.model.Scope; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class ScopeProcessorTestCase extends TestCase { - - CompositeComponent parent; - - public void testCompositeScope() throws ProcessingException { - ScopeProcessor processor = new ScopeProcessor(); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - - processor.visitClass(parent, Composite.class, type, null); - assertEquals(Scope.COMPOSITE, type.getImplementationScope()); - } - - public void testSessionScope() throws ProcessingException { - ScopeProcessor processor = new ScopeProcessor(); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitClass(parent, Session.class, type, null); - assertEquals(Scope.SESSION, type.getImplementationScope()); - } - - public void testConversationalScope() throws ProcessingException { - ScopeProcessor processor = new ScopeProcessor(); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitClass(parent, Conversation.class, type, null); - assertEquals(Scope.CONVERSATION, type.getImplementationScope()); - } - - public void testRequestScope() throws ProcessingException { - ScopeProcessor processor = new ScopeProcessor(); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitClass(parent, Request.class, type, null); - assertEquals(Scope.REQUEST, type.getImplementationScope()); - } - - public void testSystemScope() throws ProcessingException { - ScopeProcessor processor = new ScopeProcessor(); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitClass(parent, System.class, type, null); - assertEquals(Scope.SYSTEM, type.getImplementationScope()); - } - - public void testStatelessScope() throws ProcessingException { - ScopeProcessor processor = new ScopeProcessor(); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitClass(parent, Stateless.class, type, null); - assertEquals(Scope.STATELESS, type.getImplementationScope()); - } - - public void testNoScope() throws ProcessingException { - ScopeProcessor processor = new ScopeProcessor(); - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitClass(parent, None.class, type, null); - assertEquals(Scope.STATELESS, type.getImplementationScope()); - } - - protected void setUp() throws Exception { - super.setUp(); - parent = EasyMock.createNiceMock(CompositeComponent.class); - } - - @org.osoa.sca.annotations.Scope("COMPOSITE") - private class Composite { - } - - @org.osoa.sca.annotations.Scope("SESSION") - private class Session { - } - - @org.osoa.sca.annotations.Scope("CONVERSATION") - private class Conversation { - } - - @org.osoa.sca.annotations.Scope("REQUEST") - private class Request { - } - - @org.osoa.sca.annotations.Scope("SYSTEM") - private class System { - } - - @org.osoa.sca.annotations.Scope("STATELESS") - private class Stateless { - } - - private class None { - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceCallbackTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceCallbackTestCase.java deleted file mode 100644 index 29cae3beae..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceCallbackTestCase.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.processor; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -import org.osoa.sca.annotations.Callback; -import org.osoa.sca.annotations.Service; - -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.implementation.java.ProcessingException; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -import org.apache.tuscany.core.idl.java.IllegalCallbackException; - -/** - * @version $Rev$ $Date$ - */ -public class ServiceCallbackTestCase extends TestCase { - - ServiceProcessor processor = - new ServiceProcessor(new ImplementationProcessorServiceImpl(new JavaInterfaceProcessorRegistryImpl())); - - public void testMethodCallbackInterface() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitClass(null, FooImpl.class, type, null); - JavaMappedService service = type.getServices().get(Foo.class.getSimpleName()); - assertNotNull(service); - Method method = FooImpl.class.getMethod("setCallback", FooCallback.class); - processor.visitMethod(null, method, type, null); - assertEquals(method, service.getCallbackMember()); - } - - public void testFieldCallbackInterface() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitClass(null, FooImpl.class, type, null); - JavaMappedService service = type.getServices().get(Foo.class.getSimpleName()); - assertNotNull(service); - Field field = FooImpl.class.getDeclaredField("callback"); - processor.visitField(null, field, type, null); - assertEquals(field, service.getCallbackMember()); - } - - public void testMethodDoesNotMatchCallback() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitClass(null, BadBarImpl.class, type, null); - Method method = BadBarImpl.class.getMethod("setWrongInterfaceCallback", String.class); - try { - processor.visitMethod(null, method, type, null); - fail(); - } catch (IllegalCallbackReferenceException e) { - // expected - } - } - - public void testNoParamCallback() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitClass(null, BadBarImpl.class, type, null); - Method method = BadBarImpl.class.getMethod("setNoParamCallback"); - try { - processor.visitMethod(null, method, type, null); - fail(); - } catch (IllegalCallbackReferenceException e) { - // expected - } - } - - public void testFieldDoesNotMatchCallback() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - processor.visitClass(null, BadBarImpl.class, type, null); - Field field = BadBarImpl.class.getDeclaredField("wrongInterfaceCallback"); - try { - processor.visitField(null, field, type, null); - fail(); - } catch (IllegalCallbackReferenceException e) { - // expected - } - } - - public void testBadCallbackInterfaceAnnotation() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - try { - processor.visitClass(null, BadFooImpl.class, type, null); - fail(); - } catch (ProcessingException e) { - // expected - assertTrue(e.getCause() instanceof IllegalCallbackException); - } - } - - @Callback(FooCallback.class) - private interface Foo { - - } - - private interface FooCallback { - - } - - @Service(Foo.class) - private static class FooImpl implements Foo { - - @Callback - protected FooCallback callback; - - @Callback - public void setCallback(FooCallback cb) { - - } - } - - private static class BadBarImpl implements Foo { - @Callback - protected String wrongInterfaceCallback; - - @Callback - public void setWrongInterfaceCallback(String cb) { - - } - - @Callback - public void setNoParamCallback() { - - } - - } - - @Callback - private interface BadFoo { - - } - - @Service(BadFoo.class) - private static class BadFooImpl implements BadFoo { - - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceProcessorTestCase.java deleted file mode 100644 index ed7cc6b8e6..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/processor/ServiceProcessorTestCase.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.processor; - -import org.osoa.sca.annotations.Callback; -import org.osoa.sca.annotations.Remotable; -import org.osoa.sca.annotations.Service; - -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.model.ServiceContract; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; - -/** - * @version $Rev$ $Date$ - */ -public class ServiceProcessorTestCase extends TestCase { - private ServiceProcessor processor; - private PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type; - - public void testMultipleInterfaces() throws Exception { - processor.visitClass(null, FooMultiple.class, type, null); - assertEquals(2, type.getServices().size()); - JavaMappedService service = type.getServices().get(Baz.class.getSimpleName()); - ServiceContract contract = service.getServiceContract(); - assertEquals(Baz.class, contract.getInterfaceClass()); - assertEquals(Bar.class, contract.getCallbackClass()); - assertEquals("ServiceProcessorTestCase$Bar", contract.getCallbackName()); - assertNotNull(type.getServices().get(Bar.class.getSimpleName())); - } - - public void testSingleInterfaces() throws Exception { - processor.visitClass(null, FooSingle.class, type, null); - assertEquals(1, type.getServices().size()); - assertNotNull(type.getServices().get(Baz.class.getSimpleName())); - } - - public void testMultipleNoService() throws Exception { - processor.visitClass(null, FooMultipleNoService.class, type, null); - assertEquals(0, type.getServices().size()); - } - - public void testRemotableNoService() throws Exception { - processor.visitClass(null, FooRemotableNoService.class, type, null); - assertEquals(1, type.getServices().size()); - JavaMappedService service = type.getServices().get(BazRemotable.class.getSimpleName()); - ServiceContract contract = service.getServiceContract(); - assertEquals(BazRemotable.class, contract.getInterfaceClass()); - } - - public void testNonInterface() throws Exception { - try { - processor.visitClass(null, BadImpl.class, type, null); - fail(); - } catch (InvalidServiceType e) { - //expected - } - } - - public void testNoInterfaces() throws Exception { - try { - processor.visitClass(null, BadDefinition.class, type, null); - fail(); - } catch (IllegalServiceDefinitionException e) { - //expected - } - } - - protected void setUp() throws Exception { - super.setUp(); - JavaInterfaceProcessorRegistryImpl registry = new JavaInterfaceProcessorRegistryImpl(); - processor = new ServiceProcessor(new ImplementationProcessorServiceImpl(registry)); - type = new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - } - - @Callback(Bar.class) - private interface Baz { - } - - private interface Bar { - } - - @Remotable - private interface BazRemotable { - } - - @Service(interfaces = {Baz.class, Bar.class}) - private class FooMultiple implements Baz, Bar { - - } - - @Service(Baz.class) - private class FooSingle implements Baz, Bar { - - } - - private class FooMultipleNoService implements Baz, Bar { - - } - - private class FooRemotableNoService implements BazRemotable, Bar { - - } - - @Service(FooSingle.class) - private class BadImpl extends FooSingle { - - } - - - @Service() - private class BadDefinition extends FooSingle { - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/builder/SystemComponentBuilderResourceTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/builder/SystemComponentBuilderResourceTestCase.java deleted file mode 100644 index 091f231f37..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/builder/SystemComponentBuilderResourceTestCase.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.apache.tuscany.core.implementation.system.builder; - -import junit.framework.TestCase; - -import org.apache.tuscany.core.implementation.system.model.SystemImplementation; -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.component.ScopeRegistry; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.implementation.java.ConstructorDefinition; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.implementation.java.Resource; -import org.apache.tuscany.spi.model.ComponentDefinition; -import org.apache.tuscany.spi.model.ComponentTypeReferenceDefinition; -import org.apache.tuscany.spi.model.Property; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.model.ServiceDefinition; -import org.apache.tuscany.spi.wire.InboundWire; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class SystemComponentBuilderResourceTestCase extends TestCase { - - @SuppressWarnings("unchecked") - public void testResourceInjection() throws Exception { - ScopeContainer container = EasyMock.createNiceMock(ScopeContainer.class); - DeploymentContext ctx = EasyMock.createNiceMock(DeploymentContext.class); - ScopeRegistry registry = EasyMock.createMock(ScopeRegistry.class); - EasyMock.expect(registry.getScopeContainer(Scope.STATELESS)).andReturn(container); - EasyMock.replay(registry); - SystemComponentBuilder builder = new SystemComponentBuilder(); - builder.setScopeRegistry(registry); - ConstructorDefinition<Foo> ctorDef = new ConstructorDefinition<SystemComponentBuilderResourceTestCase.Foo>( - SystemComponentBuilderResourceTestCase.Foo.class.getConstructor()); - PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>> type = - new PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>>(); - Resource resource = new Resource(); - resource.setType(String.class); - resource.setName("resource"); - resource.setMember(SystemComponentBuilderResourceTestCase.Foo.class.getDeclaredField("resource")); - type.add(resource); - type.setImplementationScope(Scope.STATELESS); - type.setConstructorDefinition(ctorDef); - SystemImplementation impl = new SystemImplementation(); - impl.setImplementationClass(SystemComponentBuilderResourceTestCase.Foo.class); - impl.setComponentType(type); - ComponentDefinition<SystemImplementation> definition = - new ComponentDefinition<SystemImplementation>("foo", impl); - - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getTargetService()).andReturn("result"); - EasyMock.replay(wire); - - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(parent.resolveSystemAutowire(String.class)).andReturn(wire); - EasyMock.replay(parent); - AtomicComponent component = builder.build(parent, definition, ctx); - SystemComponentBuilderResourceTestCase.Foo foo = - (SystemComponentBuilderResourceTestCase.Foo) component.createInstance(); - assertEquals("result", foo.resource); - EasyMock.verify(parent); - } - - private static class Foo { - - protected String resource; - - public Foo() { - } - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentTestCase.java deleted file mode 100644 index b8789cb8b4..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentTestCase.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.system.component; - -import org.apache.tuscany.spi.wire.OutboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.implementation.PojoConfiguration; -import org.apache.tuscany.core.injection.EventInvoker; -import org.apache.tuscany.core.injection.MethodEventInvoker; -import org.apache.tuscany.core.injection.PojoObjectFactory; -import org.apache.tuscany.core.injection.SingletonObjectFactory; -import org.easymock.EasyMock; - -/** - * Verifies a system atomic component can be started and initialized - * - * @version $$Rev$$ $$Date$$ - */ -public class SystemAtomicComponentTestCase extends TestCase { - - private EventInvoker<Object> initInvoker; - private EventInvoker<Object> destroyInvoker; - - public void testDefaultCreationAndInit() throws Exception { - PojoObjectFactory<Foo> factory = new PojoObjectFactory<Foo>(Foo.class.getConstructor((Class[]) null)); - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setInstanceFactory(factory); - configuration.setInitInvoker(initInvoker); - configuration.setName("foo"); - SystemAtomicComponentImpl component = new SystemAtomicComponentImpl(configuration); - Foo foo = (Foo) component.createInstance(); - component.init(foo); - assertTrue(foo.initialized); - } - - public void testDestroy() throws Exception { - PojoObjectFactory<Foo> factory = new PojoObjectFactory<Foo>(Foo.class.getConstructor((Class[]) null)); - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setInstanceFactory(factory); - configuration.setDestroyInvoker(destroyInvoker); - configuration.setName("foo"); - SystemAtomicComponentImpl component = new SystemAtomicComponentImpl(configuration); - Foo foo = (Foo) component.createInstance(); - component.destroy(foo); - assertTrue(foo.destroyed); - } - - public void testReferenceAndPropertyConstructor() throws Exception { - PojoObjectFactory<Bar> factory = new PojoObjectFactory<Bar>(Bar.class.getConstructor(String.class, Foo.class)); - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setInstanceFactory(factory); - configuration.setInitInvoker(initInvoker); - configuration.addConstructorParamName("foo"); - configuration.addConstructorParamType(String.class); - configuration.addConstructorParamName("ref"); - configuration.addConstructorParamType(Foo.class); - configuration.setName("foo"); - SystemAtomicComponentImpl component = new SystemAtomicComponentImpl(configuration); - component.addPropertyFactory("foo", new SingletonObjectFactory<String>("baz")); - Foo target = new Foo(); - OutboundWire wire = EasyMock.createMock(OutboundWire.class); - EasyMock.expect(wire.getTargetService()).andReturn(target); - EasyMock.expect(wire.getReferenceName()).andReturn("ref").anyTimes(); - EasyMock.replay(wire); - component.addOutboundWire(wire); - Bar bar = (Bar) component.createInstance(); - assertEquals("baz", bar.foo); - assertEquals(target, bar.ref); - EasyMock.verify(wire); - } - - protected void setUp() throws Exception { - super.setUp(); - initInvoker = new MethodEventInvoker<Object>(Foo.class.getMethod("init")); - destroyInvoker = new MethodEventInvoker<Object>(Foo.class.getMethod("destroy")); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - - public static class Foo { - private boolean initialized; - private boolean destroyed; - - public void init() { - initialized = true; - } - - public void destroy() { - destroyed = true; - } - } - - public static class Bar { - - private String foo; - private Foo ref; - - public Bar(String foo, Foo ref) { - this.foo = foo; - this.ref = ref; - } - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentWireInvocationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentWireInvocationTestCase.java deleted file mode 100644 index c4a2664228..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/component/SystemAtomicComponentWireInvocationTestCase.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.system.component; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.wire.OutboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.scope.CompositeScopeContainer; -import org.apache.tuscany.core.implementation.PojoConfiguration; -import org.apache.tuscany.core.injection.PojoObjectFactory; -import org.apache.tuscany.core.mock.component.Source; -import org.apache.tuscany.core.mock.component.SourceImpl; -import org.apache.tuscany.core.mock.component.Target; -import org.apache.tuscany.core.mock.component.TargetImpl; -import org.easymock.EasyMock; - -/** - * Tests reference wires are injected properly into system component instances - * - * @version $$Rev$$ $$Date$$ - */ -public class SystemAtomicComponentWireInvocationTestCase extends TestCase { - - public void testWireResolution() throws Exception { - CompositeScopeContainer scope = new CompositeScopeContainer(null); - scope.start(); - Target target = new TargetImpl(); - PojoConfiguration configuration = new PojoConfiguration(); - configuration.addReferenceSite("setTarget", SourceImpl.class.getMethod("setTarget", Target.class)); - configuration.setInstanceFactory(new PojoObjectFactory<SourceImpl>(SourceImpl.class.getConstructor())); - configuration.setName("source"); - AtomicComponent component = new SystemAtomicComponentImpl(configuration); - component.setScopeContainer(scope); - OutboundWire outboundWire = EasyMock.createMock(OutboundWire.class); - EasyMock.expect(outboundWire.getReferenceName()).andReturn("setTarget").atLeastOnce(); - EasyMock.expect(outboundWire.getTargetService()).andReturn(target); - EasyMock.replay(outboundWire); - component.addOutboundWire(outboundWire); - component.start(); - assertSame(((Source) component.getTargetInstance()).getTarget(), target); - EasyMock.verify(outboundWire); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemComponentTypeLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemComponentTypeLoaderTestCase.java deleted file mode 100644 index bc86d82f34..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemComponentTypeLoaderTestCase.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.system.loader; - -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.implementation.java.ProcessingException; -import org.apache.tuscany.spi.model.Property; -import org.apache.tuscany.spi.model.AbstractReferenceDefinition; -import org.apache.tuscany.spi.model.ServiceDefinition; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -import org.apache.tuscany.core.implementation.IntrospectionRegistryImpl; -import org.apache.tuscany.core.implementation.processor.ConstructorProcessor; -import org.apache.tuscany.core.implementation.processor.DestroyProcessor; -import org.apache.tuscany.core.implementation.processor.HeuristicPojoProcessor; -import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService; -import org.apache.tuscany.core.implementation.processor.ImplementationProcessorServiceImpl; -import org.apache.tuscany.core.implementation.processor.InitProcessor; -import org.apache.tuscany.core.implementation.processor.PropertyProcessor; -import org.apache.tuscany.core.implementation.processor.ReferenceProcessor; -import org.apache.tuscany.core.implementation.processor.ScopeProcessor; -import org.apache.tuscany.core.implementation.processor.ServiceProcessor; -import org.apache.tuscany.core.implementation.system.model.SystemImplementation; -import org.apache.tuscany.core.mock.component.BasicInterface; -import org.apache.tuscany.core.mock.component.BasicInterfaceImpl; -import org.apache.tuscany.core.monitor.NullMonitorFactory; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class SystemComponentTypeLoaderTestCase extends TestCase { - private SystemComponentTypeLoader loader; - - public void testIntrospectUnannotatedClass() throws ProcessingException { - CompositeComponent parent = EasyMock.createNiceMock(CompositeComponent.class); - SystemImplementation impl = new SystemImplementation(BasicInterfaceImpl.class); - PojoComponentType<?, ?, ?> componentType = loader.loadByIntrospection(parent, impl, null); - ServiceDefinition service = componentType.getServices().get(BasicInterface.class.getSimpleName()); - assertEquals(BasicInterface.class, service.getServiceContract().getInterfaceClass()); - Property<?> property = componentType.getProperties().get("publicProperty"); - assertEquals(String.class, property.getJavaType()); - AbstractReferenceDefinition referenceDefinition = componentType.getReferences().get("protectedReference"); - assertEquals(BasicInterface.class, referenceDefinition.getServiceContract().getInterfaceClass()); - } - - protected void setUp() throws Exception { - super.setUp(); - JavaInterfaceProcessorRegistryImpl interfaceProcessorRegistry = new JavaInterfaceProcessorRegistryImpl(); - ImplementationProcessorService service = - new ImplementationProcessorServiceImpl(interfaceProcessorRegistry); - IntrospectionRegistryImpl registry = new IntrospectionRegistryImpl(); - registry.setMonitor(new NullMonitorFactory().getMonitor(IntrospectionRegistryImpl.Monitor.class)); - registry.registerProcessor(new ConstructorProcessor(service)); - registry.registerProcessor(new DestroyProcessor()); - registry.registerProcessor(new InitProcessor()); - registry.registerProcessor(new ScopeProcessor()); - registry.registerProcessor(new PropertyProcessor(service)); - registry.registerProcessor(new ReferenceProcessor(interfaceProcessorRegistry)); - registry.registerProcessor(new ServiceProcessor(service)); - registry.registerProcessor(new HeuristicPojoProcessor(service)); - loader = new SystemComponentTypeLoader(registry); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemImplementationLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemImplementationLoaderTestCase.java deleted file mode 100644 index 6cb059d629..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/implementation/system/loader/SystemImplementationLoaderTestCase.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.implementation.system.loader; - -import javax.xml.namespace.QName; -import javax.xml.stream.Location; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.loader.LoaderRegistry; -import org.apache.tuscany.spi.loader.UnrecognizedElementException; - -import junit.framework.TestCase; -import org.apache.tuscany.core.implementation.system.model.SystemImplementation; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class SystemImplementationLoaderTestCase extends TestCase { - - public static final QName SYSTEM_IMPLEMENTATION = - new QName("http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT", "implementation.system"); - - public void testLoad() throws Exception { - LoaderRegistry registry = EasyMock.createNiceMock(LoaderRegistry.class); - EasyMock.replay(registry); - DeploymentContext context = EasyMock.createMock(DeploymentContext.class); - EasyMock.expect(context.getClassLoader()).andReturn(getClass().getClassLoader()); - EasyMock.replay(context); - XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class); - EasyMock.expect(reader.getName()).andReturn(SYSTEM_IMPLEMENTATION); - EasyMock.expect(reader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("class"))) - .andReturn(getClass().getName()); - EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT); - EasyMock.replay(reader); - SystemImplementationLoader loader = new SystemImplementationLoader(registry); - SystemImplementation impl = loader.load(null, null, reader, context); - assertEquals(getClass(), impl.getImplementationClass()); - EasyMock.verify(reader); - EasyMock.verify(context); - } - - public void testUnrecognizedElement() throws Exception { - LoaderRegistry registry = EasyMock.createNiceMock(LoaderRegistry.class); - EasyMock.replay(registry); - DeploymentContext context = EasyMock.createMock(DeploymentContext.class); - EasyMock.expect(context.getClassLoader()).andReturn(getClass().getClassLoader()); - EasyMock.replay(context); - XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class); - EasyMock.expect(reader.getName()).andReturn(SYSTEM_IMPLEMENTATION).atLeastOnce(); - EasyMock.expect(reader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("class"))) - .andReturn(getClass().getName()); - EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.START_ELEMENT); - EasyMock.expect(reader.getLocation()).andReturn(new MockLocation()); - EasyMock.replay(reader); - SystemImplementationLoader loader = new SystemImplementationLoader(registry); - try { - loader.load(null, null, reader, context); - fail(); - } catch (UnrecognizedElementException e) { - // expected - } - } - - private class MockLocation implements Location { - - public int getLineNumber() { - return 0; - } - - public int getColumnNumber() { - return 0; - } - - public int getCharacterOffset() { - return 0; - } - - public String getPublicId() { - return null; - } - - public String getSystemId() { - return null; - } - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactoryTestCase.java deleted file mode 100644 index 0a3a052024..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/CallbackWireObjectFactoryTestCase.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.injection; - -import org.apache.tuscany.spi.wire.WireService; - -import junit.framework.TestCase; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expectLastCall; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; - -/** - * @version $Rev$ $Date$ - */ -public class CallbackWireObjectFactoryTestCase extends TestCase { - - public void testCreateInstance() throws Exception { - WireService service = createMock(WireService.class); - service.createCallbackProxy(Foo.class, null); - expectLastCall().andReturn(null); - replay(service); - CallbackWireObjectFactory factory = new CallbackWireObjectFactory(Foo.class, service, null); - factory.getInstance(); - verify(service); - } - - private interface Foo { - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/FieldInjectorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/FieldInjectorTestCase.java deleted file mode 100644 index d31347f7e6..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/FieldInjectorTestCase.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.injection; - -import java.lang.reflect.Field; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class FieldInjectorTestCase extends TestCase { - - protected Field protectedField; - - public void testIllegalAccess() throws Exception { - FieldInjector<Foo> injector = new FieldInjector<Foo>(protectedField, new SingletonObjectFactory<String>("foo")); - Foo foo = new Foo(); - injector.inject(foo); - assertEquals("foo", foo.hidden); - } - - - protected void setUp() throws Exception { - super.setUp(); - protectedField = Foo.class.getDeclaredField("hidden"); - } - - private class Foo { - private String hidden; - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/JNDIObjectFactoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/JNDIObjectFactoryTestCase.java deleted file mode 100644 index 91214fd02d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/JNDIObjectFactoryTestCase.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.injection; - -import javax.naming.Context; -import javax.naming.NamingException; - -import org.apache.tuscany.spi.ObjectCreationException; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class JNDIObjectFactoryTestCase extends TestCase { - - public void testGetInstance() throws Exception { - Context ctx = EasyMock.createMock(Context.class); - EasyMock.expect(ctx.lookup(EasyMock.eq("foo"))).andReturn(new Foo()); - EasyMock.replay(ctx); - JNDIObjectFactory<Foo> factory = new JNDIObjectFactory<Foo>(ctx, "foo"); - assertTrue(factory.getInstance() instanceof Foo); // must do an instanceof b/c of type erasure - EasyMock.verify(ctx); - } - - public void testGetInstanceError() throws Exception { - Context ctx = EasyMock.createMock(Context.class); - EasyMock.expect(ctx.lookup(EasyMock.eq("foo"))).andThrow(new NamingException()); - EasyMock.replay(ctx); - JNDIObjectFactory<Foo> factory = new JNDIObjectFactory<Foo>(ctx, "foo"); - try { - factory.getInstance(); - fail(); - } catch (ObjectCreationException e) { - //expected - } - EasyMock.verify(ctx); - } - - - private class Foo { - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/MethodEventInvokerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/MethodEventInvokerTestCase.java deleted file mode 100644 index 3bb882da2d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/MethodEventInvokerTestCase.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.injection; - -import java.lang.reflect.Method; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class MethodEventInvokerTestCase extends TestCase { - private Method privateMethod; - private Method exceptionMethod; - - public void testIllegalAccess() throws Exception { - MethodEventInvoker<MethodEventInvokerTestCase.Foo> injector = new MethodEventInvoker<Foo>(privateMethod); - try { - injector.invokeEvent(new Foo()); - fail(); - } catch (AssertionError e) { - // expected - } - } - - public void testException() throws Exception { - MethodEventInvoker<MethodEventInvokerTestCase.Foo> injector = new MethodEventInvoker<Foo>(exceptionMethod); - try { - injector.invokeEvent(new Foo()); - fail(); - } catch (RuntimeException e) { - // expected - } - } - - protected void setUp() throws Exception { - super.setUp(); - privateMethod = MethodEventInvokerTestCase.Foo.class.getDeclaredMethod("hidden"); - exceptionMethod = MethodEventInvokerTestCase.Foo.class.getDeclaredMethod("exception"); - - } - - private class Foo { - - public void foo() { - } - - private void hidden() { - } - - public void exception() { - throw new RuntimeException(); - } - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/MethodInjectorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/MethodInjectorTestCase.java deleted file mode 100644 index b21ba4ccfa..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/MethodInjectorTestCase.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.injection; - -import java.lang.reflect.Method; - -import org.apache.tuscany.spi.ObjectCreationException; -import org.apache.tuscany.spi.ObjectFactory; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class MethodInjectorTestCase extends TestCase { - private Method fooMethod; - private Method privateMethod; - private Method exceptionMethod; - - public void testIllegalArgument() throws Exception { - ObjectFactory<Object> factory = new SingletonObjectFactory<Object>(new Object()); - MethodInjector<Foo> injector = new MethodInjector<Foo>(fooMethod, factory); - try { - injector.inject(new Foo()); - fail(); - } catch (ObjectCreationException e) { - // expected - } - } - - public void testException() throws Exception { - ObjectFactory<Object> factory = new SingletonObjectFactory<Object>("foo"); - MethodInjector<Foo> injector = new MethodInjector<Foo>(exceptionMethod, factory); - try { - injector.inject(new Foo()); - fail(); - } catch (RuntimeException e) { - // expected - } - } - - protected void setUp() throws Exception { - super.setUp(); - fooMethod = Foo.class.getMethod("foo", String.class); - privateMethod = Foo.class.getDeclaredMethod("hidden", String.class); - exceptionMethod = Foo.class.getDeclaredMethod("exception", String.class); - - } - - private class Foo { - - public void foo(String bar) { - } - - private void hidden(String bar) { - } - - public void exception(String bar) { - throw new RuntimeException(); - } - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/PojoObjectFactoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/PojoObjectFactoryTestCase.java deleted file mode 100644 index 7aba6dbab3..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/PojoObjectFactoryTestCase.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.injection; - -import java.lang.reflect.Constructor; -import java.util.List; -import java.util.ArrayList; - -import org.apache.tuscany.spi.ObjectFactory; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class PojoObjectFactoryTestCase extends TestCase { - - private Constructor<Foo> ctor; - - public void testConstructorInjection() throws Exception { - List<ObjectFactory> initializers = new ArrayList<ObjectFactory>(); - initializers.add(new SingletonObjectFactory<String>("foo")); - PojoObjectFactory<Foo> factory = new PojoObjectFactory<Foo>(ctor, initializers); - Foo foo = factory.getInstance(); - assertEquals("foo", foo.foo); - } - - public void testConstructorInitializerInjection() throws Exception { - PojoObjectFactory<Foo> factory = new PojoObjectFactory<Foo>(ctor); - factory.setInitializerFactory(0, new SingletonObjectFactory<String>("foo")); - Foo foo = factory.getInstance(); - assertEquals("foo", foo.foo); - } - - protected void setUp() throws Exception { - super.setUp(); - ctor = Foo.class.getConstructor(String.class); - } - - private static class Foo { - - private String foo; - - public Foo(String foo) { - this.foo = foo; - } - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/RequestContextObjectFactoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/RequestContextObjectFactoryTestCase.java deleted file mode 100644 index a1a41bbada..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/RequestContextObjectFactoryTestCase.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.injection; - -import org.apache.tuscany.spi.component.WorkContext; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class RequestContextObjectFactoryTestCase extends TestCase { - - public void testInstanceCreate() { - WorkContext workContext = EasyMock.createNiceMock(WorkContext.class); - RequestContextObjectFactory factory = new RequestContextObjectFactory(workContext); - assertNotNull(factory.getInstance()); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/ResourceObjectFactoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/ResourceObjectFactoryTestCase.java deleted file mode 100644 index 073bda1458..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/ResourceObjectFactoryTestCase.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.injection; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.host.ResourceHost; -import org.apache.tuscany.spi.wire.InboundWire; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class ResourceObjectFactoryTestCase extends TestCase { - - public void testResolveFromHostByType() throws Exception { - ResourceHost host = EasyMock.createMock(ResourceHost.class); - EasyMock.expect(host.resolveResource(EasyMock.eq(String.class))).andReturn("foo"); - EasyMock.replay(host); - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(parent.resolveSystemAutowire(EasyMock.eq(String.class))).andReturn(null); - EasyMock.replay(parent); - ResourceObjectFactory<String> factory = new ResourceObjectFactory<String>(String.class, false, parent, host); - assertEquals("foo", factory.getInstance()); - EasyMock.verify(host); - EasyMock.verify(parent); - } - - public void testResolveFromHostByName() throws Exception { - ResourceHost host = EasyMock.createMock(ResourceHost.class); - EasyMock.expect(host.resolveResource(EasyMock.eq(String.class), - EasyMock.eq("sca://localhost/bar"))).andReturn("foo"); - EasyMock.replay(host); - ResourceObjectFactory<String> factory = - new ResourceObjectFactory<String>(String.class, "sca://localhost/bar", false, null, host); - assertEquals("foo", factory.getInstance()); - EasyMock.verify(host); - } - - public void testResolveFromParentByType() throws Exception { - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getTargetService()).andReturn("foo"); - EasyMock.replay(wire); - - EasyMock.expect(parent.resolveSystemAutowire(EasyMock.eq(String.class))).andReturn(wire); - EasyMock.replay(parent); - ResourceObjectFactory<String> factory = new ResourceObjectFactory<String>(String.class, false, parent, null); - assertEquals("foo", factory.getInstance()); - EasyMock.verify(parent); - } - - public void testResolveFromParentByName() throws Exception { - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getTargetInstance()).andReturn("foo"); - EasyMock.replay(component); - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(parent.getSystemChild(EasyMock.eq("bar"))).andReturn(component); - EasyMock.replay(parent); - ResourceObjectFactory<String> factory = - new ResourceObjectFactory<String>(String.class, "bar", false, parent, null); - assertEquals("foo", factory.getInstance()); - EasyMock.verify(parent); - EasyMock.verify(component); - } - - /** - * Verifies if a resource is not found as a child of the parent, the host namespace will be searched - */ - public void testResolveFromParentThenResolveFromHost() throws Exception { - ResourceHost host = EasyMock.createMock(ResourceHost.class); - EasyMock.expect(host.resolveResource(EasyMock.eq(String.class))).andReturn("foo"); - EasyMock.replay(host); - - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(parent.resolveSystemAutowire(EasyMock.eq(String.class))).andReturn(null); - EasyMock.replay(parent); - ResourceObjectFactory<String> factory = new ResourceObjectFactory<String>(String.class, false, parent, host); - assertEquals("foo", factory.getInstance()); - EasyMock.verify(parent); - EasyMock.verify(host); - } - - public void testResolveFromParentThenResolveFromHostNotFound() throws Exception { - ResourceHost host = EasyMock.createMock(ResourceHost.class); - EasyMock.expect(host.resolveResource(EasyMock.eq(String.class))).andReturn(null); - EasyMock.replay(host); - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(parent.resolveSystemAutowire(EasyMock.eq(String.class))).andReturn(null); - EasyMock.replay(parent); - ResourceObjectFactory<String> factory = new ResourceObjectFactory<String>(String.class, true, parent, host); - assertNull(factory.getInstance()); - EasyMock.verify(parent); - EasyMock.verify(host); - } - - public void testResolveByTypeNotFound() throws Exception { - ResourceHost host = EasyMock.createMock(ResourceHost.class); - EasyMock.expect(host.resolveResource(EasyMock.eq(String.class))).andReturn(null); - EasyMock.replay(host); - - InboundWire wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getTargetService()).andReturn(null); - EasyMock.replay(wire); - - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(parent.resolveSystemAutowire(EasyMock.eq(String.class))).andReturn(null); - EasyMock.replay(parent); - ResourceObjectFactory<String> factory = new ResourceObjectFactory<String>(String.class, false, parent, host); - try { - factory.getInstance(); - fail(); - } catch (ResourceNotFoundException e) { - //expected - } - EasyMock.verify(parent); - EasyMock.verify(host); - } - - public void testResolveByTypeNotFoundOptional() throws Exception { - ResourceHost host = EasyMock.createMock(ResourceHost.class); - EasyMock.expect(host.resolveResource(EasyMock.eq(String.class))).andReturn(null); - EasyMock.replay(host); - CompositeComponent parent = EasyMock.createMock(CompositeComponent.class); - EasyMock.expect(parent.resolveSystemAutowire(EasyMock.eq(String.class))).andReturn(null); - EasyMock.replay(parent); - ResourceObjectFactory<String> factory = new ResourceObjectFactory<String>(String.class, true, parent, host); - assertNull(factory.getInstance()); - EasyMock.verify(parent); - EasyMock.verify(host); - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/SingletonObjectFactoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/SingletonObjectFactoryTestCase.java deleted file mode 100644 index 876e68d5b3..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/injection/SingletonObjectFactoryTestCase.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.injection; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class SingletonObjectFactoryTestCase extends TestCase { - - public void testSingleton() throws Exception { - Object o = new Object(); - SingletonObjectFactory<Object> factory = new SingletonObjectFactory<Object>(o); - assertEquals(o, factory.getInstance()); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/AbstractConversationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/AbstractConversationTestCase.java deleted file mode 100644 index f9135e2eb9..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/AbstractConversationTestCase.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.integration.conversation; - -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.services.store.StoreMonitor; -import org.apache.tuscany.spi.wire.WirePostProcessorRegistry; - -import junit.framework.TestCase; -import org.apache.tuscany.core.builder.ConnectorImpl; -import org.apache.tuscany.core.builder.WirePostProcessorRegistryImpl; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.component.scope.ConversationalScopeContainer; -import org.apache.tuscany.core.implementation.java.JavaAtomicComponent; -import org.apache.tuscany.core.services.store.memory.MemoryStore; -import org.easymock.classextension.EasyMock; - -/** - * Provides helper methods for setting up a partial runtime for conversational test cases. - * - * @version $Rev$ $Date$ - */ -public abstract class AbstractConversationTestCase extends TestCase { - protected ScopeContainer container; - protected MemoryStore store; - protected WorkContext workContext; - protected ConnectorImpl connector; - protected JavaAtomicComponent target; - - - protected void createRuntime() { - workContext = new WorkContextImpl(); - WirePostProcessorRegistry processorRegistry = new WirePostProcessorRegistryImpl(); - connector = new ConnectorImpl(null, processorRegistry, null, workContext); - store = new MemoryStore(EasyMock.createNiceMock(StoreMonitor.class)); - container = new ConversationalScopeContainer(store, workContext, null); - - } - - protected void initializeRuntime() { - store.init(); - container.start(); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationIdleExpireTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationIdleExpireTestCase.java deleted file mode 100644 index 4aec333cad..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationIdleExpireTestCase.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.integration.conversation; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; - -import org.apache.tuscany.core.implementation.PojoConfiguration; -import org.apache.tuscany.core.implementation.java.JavaAtomicComponent; -import org.apache.tuscany.core.injection.PojoObjectFactory; -import org.apache.tuscany.core.integration.mock.MockFactory; -import org.apache.tuscany.core.wire.jdk.JDKOutboundInvocationHandler; -import org.apache.tuscany.spi.ObjectCreationException; -import org.apache.tuscany.spi.QualifiedName; -import org.apache.tuscany.spi.component.TargetNotFoundException; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.easymock.classextension.EasyMock; -import org.osoa.sca.annotations.EndsConversation; -import org.osoa.sca.annotations.Scope; - -/** - * Verifies conversational resources are cleaned up if the maximum idle time is exceeded - * - * @version $Rev$ $Date$ - */ -public class ConversationIdleExpireTestCase extends AbstractConversationTestCase { - private JDKOutboundInvocationHandler handler; - private OutboundWire owire; - private Foo targetInstance; - private Method operation1; - private Method operation2; - private final Object mutex = new Object(); - - public void testConversationExpire() throws Throwable { - workContext.setIdentifier(org.apache.tuscany.spi.model.Scope.CONVERSATION, "12345A"); - // start the conversation - handler.invoke(operation1, null); - // verify the instance was persisted - assertEquals(targetInstance, store.readRecord(target, "12345A")); - synchronized (mutex) { - mutex.wait(100); - } - // verify the instance was expired - assertNull(store.readRecord(target, "12345A")); - // continue the conversation - should throw an error - try { - handler.invoke(operation2, null); - fail(); - } catch (TargetNotFoundException e) { - // expected - } - } - - - protected void setUp() throws Exception { - super.setUp(); - createRuntime(); - store.setReaperInterval(10); - initializeRuntime(); - - targetInstance = EasyMock.createMock(Foo.class); - targetInstance.operation1(); - targetInstance.operation2(); - targetInstance.end(); - EasyMock.replay(targetInstance); - target = createMaxIdleTimeAtomicComponent(); - // create source component mock - JavaAtomicComponent source = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(source.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(source.isSystem()).andReturn(false).atLeastOnce(); - EasyMock.replay(source); - - owire = MockFactory.createOutboundWire("foo", Foo.class); - owire.setContainer(source); - owire.setTargetName(new QualifiedName("foo/bar")); - InboundWire iwire = MockFactory.createInboundWire("foo", Foo.class); - iwire.setContainer(target); - connector.connect(owire, iwire, false); - handler = new JDKOutboundInvocationHandler(Foo.class, owire, workContext); - operation1 = Foo.class.getMethod("operation1"); - operation2 = Foo.class.getMethod("operation2"); - } - - protected void tearDown() throws Exception { - super.tearDown(); - container.stop(); - store.destroy(); - } - - private JavaAtomicComponent createMaxIdleTimeAtomicComponent() throws Exception { - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setName("target"); - configuration.setMaxIdleTime(50); - configuration.setInstanceFactory(new MockPojoFactory(Object.class.getConstructor())); - JavaAtomicComponent component = new JavaAtomicComponent(configuration); - component.setScopeContainer(container); - component.start(); - return component; - } - - private class MockPojoFactory extends PojoObjectFactory<Object> { - public MockPojoFactory(Constructor<Object> ctr) { - super(ctr); - } - - public Foo getInstance() throws ObjectCreationException { - return targetInstance; - } - } - - @Scope("CONVERSATION") - public static interface Foo { - - void operation1(); - - void operation2(); - - @EndsConversation - void end(); - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationMaxAgeExpireTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationMaxAgeExpireTestCase.java deleted file mode 100644 index 1c9bc4a290..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationMaxAgeExpireTestCase.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.integration.conversation; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; - -import org.apache.tuscany.core.implementation.PojoConfiguration; -import org.apache.tuscany.core.implementation.java.JavaAtomicComponent; -import org.apache.tuscany.core.injection.PojoObjectFactory; -import org.apache.tuscany.core.integration.mock.MockFactory; -import org.apache.tuscany.core.wire.jdk.JDKOutboundInvocationHandler; -import org.apache.tuscany.spi.ObjectCreationException; -import org.apache.tuscany.spi.QualifiedName; -import org.apache.tuscany.spi.component.TargetNotFoundException; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.easymock.classextension.EasyMock; -import org.osoa.sca.annotations.EndsConversation; -import org.osoa.sca.annotations.Scope; - -/** - * Verifies conversational resources are cleaned up if the maximum age is exceeded - * - * @version $Rev$ $Date$ - */ -public class ConversationMaxAgeExpireTestCase extends AbstractConversationTestCase { - private JDKOutboundInvocationHandler handler; - private OutboundWire owire; - private Foo targetInstance; - private Method operation1; - private Method operation2; - private final Object mutex = new Object(); - - public void testConversationExpire() throws Throwable { - workContext.setIdentifier(org.apache.tuscany.spi.model.Scope.CONVERSATION, "12345A"); - // start the conversation - handler.invoke(operation1, null); - // verify the instance was persisted - assertEquals(targetInstance, store.readRecord(target, "12345A")); - synchronized (mutex) { - mutex.wait(100); - } - // verify the instance was expired - assertNull(store.readRecord(target, "12345A")); - // continue the conversation - should throw an error - try { - handler.invoke(operation2, null); - fail(); - } catch (TargetNotFoundException e) { - // expected - } - } - - - protected void setUp() throws Exception { - super.setUp(); - createRuntime(); - store.setReaperInterval(10); - initializeRuntime(); - - targetInstance = EasyMock.createMock(ConversationMaxAgeExpireTestCase.Foo.class); - targetInstance.operation1(); - targetInstance.operation2(); - targetInstance.end(); - EasyMock.replay(targetInstance); - target = createMaxIdleTimeAtomicComponent(); - // create source component mock - JavaAtomicComponent source = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(source.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(source.isSystem()).andReturn(false).atLeastOnce(); - EasyMock.replay(source); - - owire = MockFactory.createOutboundWire("foo", Foo.class); - owire.setContainer(source); - owire.setTargetName(new QualifiedName("foo/bar")); - InboundWire iwire = MockFactory.createInboundWire("foo", Foo.class); - iwire.setContainer(target); - connector.connect(owire, iwire, false); - handler = new JDKOutboundInvocationHandler(Foo.class, owire, workContext); - operation1 = Foo.class.getMethod("operation1"); - operation2 = Foo.class.getMethod("operation2"); - } - - protected void tearDown() throws Exception { - super.tearDown(); - container.stop(); - store.destroy(); - } - - private JavaAtomicComponent createMaxIdleTimeAtomicComponent() throws Exception { - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setName("target"); - configuration.setMaxAge(50); - Constructor<Object> ctor = Object.class.getConstructor(); - configuration.setInstanceFactory(new ConversationMaxAgeExpireTestCase.MockPojoFactory(ctor)); - JavaAtomicComponent component = new JavaAtomicComponent(configuration); - component.setScopeContainer(container); - component.start(); - return component; - } - - private class MockPojoFactory extends PojoObjectFactory<Object> { - public MockPojoFactory(Constructor<Object> ctr) { - super(ctr); - } - - public ConversationMaxAgeExpireTestCase.Foo getInstance() throws ObjectCreationException { - return targetInstance; - } - } - - @Scope("CONVERSATION") - public static interface Foo { - - void operation1(); - - void operation2(); - - @EndsConversation - void end(); - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationStartStopEndTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationStartStopEndTestCase.java deleted file mode 100644 index e7a0bc3cfc..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/conversation/ConversationStartStopEndTestCase.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.integration.conversation; - -import static org.apache.tuscany.spi.model.Scope.CONVERSATION; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; - -import org.apache.tuscany.core.implementation.PojoConfiguration; -import org.apache.tuscany.core.implementation.java.JavaAtomicComponent; -import org.apache.tuscany.core.injection.PojoObjectFactory; -import org.apache.tuscany.core.integration.mock.MockFactory; -import org.apache.tuscany.core.wire.jdk.JDKOutboundInvocationHandler; -import org.apache.tuscany.spi.ObjectCreationException; -import org.apache.tuscany.spi.QualifiedName; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.easymock.classextension.EasyMock; -import org.osoa.sca.annotations.EndsConversation; -import org.osoa.sca.annotations.Scope; - -/** - * Verifies start, continue and end conversation invocations are processed properly. Checks that a target instance is - * properly instantiated and persisted in the store. Additionally verifies that invocations are dispatched to a target - * instance, and that start, continue, and end operations are performed correctly. Finally, verfies that the target - * instance is removed from the store when the conversation ends. - * - * @version $Rev$ $Date$ - */ -public class ConversationStartStopEndTestCase extends AbstractConversationTestCase { - private OutboundWire owire; - private Foo targetInstance; - private JDKOutboundInvocationHandler handler; - private Method operation1; - private Method operation2; - private Method endOperation; - - public void testConversationStartContinueEnd() throws Throwable { - workContext.setIdentifier(CONVERSATION, "12345A"); - // start the conversation - handler.invoke(operation1, null); - // verify the instance was persisted - assertEquals(targetInstance, store.readRecord(target, "12345A")); - // continue the conversation - handler.invoke(operation2, null); - // verify the instance was persisted - assertEquals(targetInstance, store.readRecord(target, "12345A")); - // end the conversation - handler.invoke(endOperation, null); - workContext.clearIdentifier(CONVERSATION); - EasyMock.verify(targetInstance); - // verify the store has removed the instance - assertNull(store.readRecord(target, "12345A")); - } - - - protected void setUp() throws Exception { - super.setUp(); - createRuntime(); - initializeRuntime(); - targetInstance = EasyMock.createMock(Foo.class); - targetInstance.operation1(); - targetInstance.operation2(); - targetInstance.end(); - EasyMock.replay(targetInstance); - // create target component mock - target = createAtomicComponent(); - // create source component mock - JavaAtomicComponent source = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(source.getName()).andReturn("source").atLeastOnce(); - EasyMock.expect(source.isSystem()).andReturn(false).atLeastOnce(); - EasyMock.replay(source); - - owire = MockFactory.createOutboundWire("foo", Foo.class); - owire.setContainer(source); - owire.setTargetName(new QualifiedName("foo/bar")); - InboundWire iwire = MockFactory.createInboundWire("foo", Foo.class); - iwire.setContainer(target); - connector.connect(owire, iwire, false); - handler = new JDKOutboundInvocationHandler(Foo.class, owire, workContext); - operation1 = Foo.class.getMethod("operation1"); - operation2 = Foo.class.getMethod("operation2"); - endOperation = Foo.class.getMethod("end"); - } - - protected void tearDown() throws Exception { - super.tearDown(); - container.stop(); - store.destroy(); - } - - private JavaAtomicComponent createAtomicComponent() throws Exception { - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setName("target"); - configuration.setInstanceFactory(new MockPojoFactory(Object.class.getConstructor())); - JavaAtomicComponent component = new JavaAtomicComponent(configuration); - component.setScopeContainer(container); - component.start(); - return component; - } - - private class MockPojoFactory extends PojoObjectFactory<Object> { - public MockPojoFactory(Constructor<Object> ctr) { - super(ctr); - } - - public Foo getInstance() throws ObjectCreationException { - return targetInstance; - } - } - - @Scope("CONVERSATION") - public static interface Foo { - - void operation1(); - - void operation2(); - - @EndsConversation - void end(); - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/IntrospectionRegistryIntegrationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/IntrospectionRegistryIntegrationTestCase.java deleted file mode 100644 index f551aa3e98..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/IntrospectionRegistryIntegrationTestCase.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.integration.implementation; - -import org.osoa.sca.annotations.Destroy; -import org.osoa.sca.annotations.Init; -import org.osoa.sca.annotations.Property; -import org.osoa.sca.annotations.Reference; -import org.osoa.sca.annotations.Scope; -import org.apache.tuscany.api.annotation.Resource; - -import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService; -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.JavaMappedReference; -import org.apache.tuscany.spi.implementation.java.JavaMappedService; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import static org.apache.tuscany.spi.model.Scope.COMPOSITE; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -import org.apache.tuscany.core.implementation.IntrospectionRegistryImpl; -import org.apache.tuscany.core.implementation.processor.DestroyProcessor; -import org.apache.tuscany.core.implementation.processor.ImplementationProcessorServiceImpl; -import org.apache.tuscany.core.implementation.processor.InitProcessor; -import org.apache.tuscany.core.implementation.processor.PropertyProcessor; -import org.apache.tuscany.core.implementation.processor.ReferenceProcessor; -import org.apache.tuscany.core.implementation.processor.ResourceProcessor; -import org.apache.tuscany.core.implementation.processor.ScopeProcessor; -import org.apache.tuscany.core.monitor.NullMonitorFactory; - -/** - * Sanity check of the <code>IntegrationRegistry</code> to verify operation with processors - * - * @version $Rev$ $Date$ - */ -public class IntrospectionRegistryIntegrationTestCase extends TestCase { - - private IntrospectionRegistryImpl registry; - - public void testSimpleComponentTypeParsing() throws Exception { - PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>> type = - new PojoComponentType<JavaMappedService, JavaMappedReference, JavaMappedProperty<?>>(); - registry.introspect(null, Foo.class, type, null); - assertEquals(Foo.class.getMethod("init"), type.getInitMethod()); - assertEquals(Foo.class.getMethod("destroy"), type.getDestroyMethod()); - assertEquals(COMPOSITE, type.getImplementationScope()); - assertEquals(Foo.class.getMethod("setBar", String.class), type.getProperties().get("bar").getMember()); - assertEquals(Foo.class.getMethod("setTarget", Foo.class), type.getReferences().get("target").getMember()); - assertEquals(Foo.class.getMethod("setResource", Foo.class), type.getResources().get("resource").getMember()); - } - - protected void setUp() throws Exception { - super.setUp(); - registry = new IntrospectionRegistryImpl(); - registry.setMonitor(new NullMonitorFactory().getMonitor(IntrospectionRegistryImpl.Monitor.class)); - registry.registerProcessor(new DestroyProcessor()); - registry.registerProcessor(new InitProcessor()); - registry.registerProcessor(new ScopeProcessor()); - JavaInterfaceProcessorRegistryImpl interfaceProcessorRegistry = new JavaInterfaceProcessorRegistryImpl(); - ImplementationProcessorService service = new ImplementationProcessorServiceImpl(interfaceProcessorRegistry); - registry.registerProcessor(new PropertyProcessor(service)); - registry.registerProcessor(new ReferenceProcessor(interfaceProcessorRegistry)); - registry.registerProcessor(new ResourceProcessor()); - } - - @Scope("COMPOSITE") - private static class Foo { - protected Foo target; - protected String bar; - protected Foo resource; - private boolean initialized; - private boolean destroyed; - - - @Init - public void init() { - if (initialized) { - fail(); - } - initialized = true; - } - - @Destroy - public void destroy() { - if (destroyed) { - fail(); - } - destroyed = true; - } - - public Foo getTarget() { - return target; - } - - @Reference - public void setTarget(Foo target) { - this.target = target; - } - - public String getBar() { - return bar; - } - - @Property - public void setBar(String bar) { - this.bar = bar; - } - - @Resource - public void setResource(Foo resource) { - this.resource = resource; - } - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/system/builder/SystemBuilderPropertyTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/system/builder/SystemBuilderPropertyTestCase.java deleted file mode 100644 index 4a4939b495..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/implementation/system/builder/SystemBuilderPropertyTestCase.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.integration.implementation.system.builder; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.implementation.java.ConstructorDefinition; -import org.apache.tuscany.spi.implementation.java.JavaMappedProperty; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.model.ComponentDefinition; -import org.apache.tuscany.spi.model.AbstractReferenceDefinition; -import org.apache.tuscany.spi.model.ComponentTypeReferenceDefinition; -import org.apache.tuscany.spi.model.ServiceDefinition; - -import junit.framework.TestCase; -import org.apache.tuscany.core.deployer.RootDeploymentContext; -import org.apache.tuscany.core.implementation.system.builder.SystemComponentBuilder; -import org.apache.tuscany.core.implementation.system.model.SystemImplementation; -import org.apache.tuscany.core.injection.SingletonObjectFactory; -import org.easymock.EasyMock; - -/** - * Verifies that the system builder handles configured properties correctly - * - * @version $Rev$ $Date$ - */ -public class SystemBuilderPropertyTestCase extends TestCase { - - DeploymentContext deploymentContext; - CompositeComponent parent; - - @SuppressWarnings("unchecked") - public void testPropertyHandling() throws Exception { - SystemComponentBuilder builder = new SystemComponentBuilder(); - PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, JavaMappedProperty<?>> type = - new PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, JavaMappedProperty<?>>(); - type.setConstructorDefinition(new ConstructorDefinition<Foo>(Foo.class.getConstructor((Class[]) null))); - JavaMappedProperty<String> property = new JavaMappedProperty<String>(); - property.setName("test"); - property.setDefaultValueFactory(new SingletonObjectFactory<String>("foo")); - property.setMember(Foo.class.getMethod("setTest", String.class)); - type.add(property); - SystemImplementation impl = new SystemImplementation(); - impl.setComponentType(type); - impl.setImplementationClass(Foo.class); - ComponentDefinition<SystemImplementation> definition = new ComponentDefinition<SystemImplementation>(impl); - AtomicComponent component = builder.build(parent, definition, deploymentContext); - Foo foo = (Foo) component.createInstance(); - assertEquals("foo", foo.getTest()); - } - - protected void setUp() throws Exception { - super.setUp(); - deploymentContext = new RootDeploymentContext(null, null, null, null); - parent = EasyMock.createNiceMock(CompositeComponent.class); - } - - private static class Foo { - private String test; - - public Foo() { - } - - public String getTest() { - return test; - } - - public void setTest(String test) { - this.test = test; - } - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/mock/MockFactory.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/mock/MockFactory.java deleted file mode 100644 index 0c331ae7d7..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/mock/MockFactory.java +++ /dev/null @@ -1,278 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.integration.mock; - -import java.lang.reflect.Member; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.tuscany.spi.QualifiedName; -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.idl.InvalidServiceContractException; -import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.WireService; - -import org.apache.tuscany.core.builder.ConnectorImpl; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -import org.apache.tuscany.core.implementation.PojoConfiguration; -import org.apache.tuscany.core.implementation.java.JavaAtomicComponent; -import org.apache.tuscany.core.injection.PojoObjectFactory; -import org.apache.tuscany.core.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InboundWireImpl; -import org.apache.tuscany.core.wire.InvokerInterceptor; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; -import org.apache.tuscany.core.wire.jdk.JDKWireService; - -/** - * @version $$Rev$$ $$Date$$ - */ -public final class MockFactory { - - private static final WireService WIRE_SERVICE = new JDKWireService(new WorkContextImpl(), null); - private static final JavaInterfaceProcessorRegistry REGISTRY = new JavaInterfaceProcessorRegistryImpl(); - private static final ConnectorImpl CONNECTOR = new ConnectorImpl(); - - private MockFactory() { - } - - /** - * Wires two components together where the reference interface is the same as target service - * - * @param sourceName - * @param sourceClass - * @param sourceScope - * @param members - * @param targetName - * @param targetService - * @param targetClass - * @param targetScope - * @return - * @throws Exception - */ - public static Map<String, AtomicComponent> createWiredComponents(String sourceName, - Class<?> sourceClass, - ScopeContainer sourceScope, - Map<String, Member> members, - String targetName, - Class<?> targetService, - Class<?> targetClass, - ScopeContainer targetScope) throws Exception { - return createWiredComponents(sourceName, - sourceClass, - targetService, - sourceScope, - null, - members, - targetName, - targetService, - targetClass, - targetScope, - null); - - } - - @SuppressWarnings("unchecked") - public static Map<String, AtomicComponent> createWiredComponents(String sourceName, Class<?> sourceClass, - Class<?> sourceReferenceClass, - ScopeContainer sourceScope, - Interceptor sourceHeadInterceptor, - Map<String, Member> members, - String targetName, Class<?> targetService, - Class<?> targetClass, - ScopeContainer targetScope, - Interceptor targetHeadInterceptor) - throws Exception { - - JavaAtomicComponent targetComponent = - createJavaComponent(targetName, targetScope, targetClass); - String serviceName = targetService.getName().substring(targetService.getName().lastIndexOf('.') + 1); - InboundWire inboundWire = createInboundWire(serviceName, targetService, targetHeadInterceptor); - targetComponent.addInboundWire(inboundWire); - inboundWire.setContainer(targetComponent); - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setInstanceFactory(new PojoObjectFactory(sourceClass.getConstructor())); - configuration.setWireService(WIRE_SERVICE); - for (Map.Entry<String, Member> entry : members.entrySet()) { - configuration.addReferenceSite(entry.getKey(), entry.getValue()); - } - configuration.setWorkContext(new WorkContextImpl()); - configuration.setName(sourceName); - JavaAtomicComponent sourceComponent = new JavaAtomicComponent(configuration); - sourceComponent.setScopeContainer(sourceScope); - OutboundWire outboundWire = createOutboundWire(targetName, sourceReferenceClass, sourceHeadInterceptor); - sourceComponent.addOutboundWire(outboundWire); - outboundWire.setContainer(sourceComponent); - outboundWire.setTargetName(new QualifiedName(targetName + "/" + serviceName)); - targetScope.register(targetComponent); - sourceScope.register(sourceComponent); - CONNECTOR.connect(outboundWire, inboundWire, false); - Map<String, AtomicComponent> contexts = new HashMap<String, AtomicComponent>(); - contexts.put(sourceName, sourceComponent); - contexts.put(targetName, targetComponent); - return contexts; - } - - - /** - * Wires two contexts using a multiplicity reference - * - * @param sourceName - * @param sourceClass - * @param sourceReferenceClass - * @param sourceScope - * @param targetName - * @param targetService - * @param targetClass - * @param members - * @param targetScope - * @return - * @throws Exception - */ - @SuppressWarnings("unchecked") - public static Map<String, AtomicComponent> createWiredMultiplicity(String sourceName, Class<?> sourceClass, - Class<?> sourceReferenceClass, - ScopeContainer sourceScope, - String targetName, Class<?> targetService, - Class<?> targetClass, - Map<String, Member> members, - ScopeContainer targetScope) throws Exception { - JavaAtomicComponent targetComponent = - createJavaComponent(targetName, targetScope, targetClass); - String serviceName = targetService.getName().substring(targetService.getName().lastIndexOf('.') + 1); - InboundWire inboundWire = createInboundWire(serviceName, targetService, null); - targetComponent.addInboundWire(inboundWire); - inboundWire.setContainer(targetComponent); - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setInstanceFactory(new PojoObjectFactory(sourceClass.getConstructor())); - configuration.setWireService(WIRE_SERVICE); - for (Map.Entry<String, Member> entry : members.entrySet()) { - configuration.addReferenceSite(entry.getKey(), entry.getValue()); - } - configuration.setWorkContext(new WorkContextImpl()); - configuration.setName(sourceName); - - JavaAtomicComponent sourceComponent = new JavaAtomicComponent(configuration); - sourceComponent.setScopeContainer(sourceScope); - OutboundWire outboundWire = createOutboundWire(targetName, sourceReferenceClass, null); - outboundWire.setContainer(sourceComponent); - outboundWire.setTargetName(new QualifiedName(targetName + "/" + serviceName)); - List<OutboundWire> factories = new ArrayList<OutboundWire>(); - factories.add(outboundWire); - sourceComponent.addOutboundWires(factories); - targetScope.register(targetComponent); - sourceScope.register(sourceComponent); - CONNECTOR.connect(outboundWire, inboundWire, false); - Map<String, AtomicComponent> components = new HashMap<String, AtomicComponent>(); - components.put(sourceName, sourceComponent); - components.put(targetName, targetComponent); - return components; - } - - public static <T> InboundWire createInboundWire(String serviceName, Class<T> interfaze) - throws InvalidServiceContractException { - return createInboundWire(serviceName, interfaze, null); - } - - public static <T> InboundWire createInboundWire(String serviceName, Class<T> interfaze, Interceptor interceptor) - throws InvalidServiceContractException { - InboundWire wire = new InboundWireImpl(); - ServiceContract<?> contract = REGISTRY.introspect(interfaze); - wire.setServiceContract(contract); - wire.setServiceName(serviceName); - wire.addInvocationChains(createInboundChains(interfaze, interceptor)); - return wire; - } - - public static <T> OutboundWire createOutboundWire(String refName, Class<T> interfaze) - throws InvalidServiceContractException { - return createOutboundWire(refName, interfaze, null); - } - - public static <T> OutboundWire createOutboundWire(String refName, Class<T> interfaze, Interceptor interceptor) - throws InvalidServiceContractException { - - OutboundWire wire = new OutboundWireImpl(); - wire.setReferenceName(refName); - Map<Operation<?>, OutboundInvocationChain> outboundChains = createOutboundChains(interfaze, interceptor); - wire.addInvocationChains(outboundChains); - ServiceContract<?> contract = REGISTRY.introspect(interfaze); - wire.setServiceContract(contract); - return wire; - } - - - @SuppressWarnings("unchecked") - private static <T> JavaAtomicComponent createJavaComponent(String name, ScopeContainer scope, Class<T> clazz) - throws NoSuchMethodException { - PojoConfiguration configuration = new PojoConfiguration(); - configuration.setInstanceFactory(new PojoObjectFactory(clazz.getConstructor())); - configuration.setWireService(WIRE_SERVICE); - configuration.setWorkContext(new WorkContextImpl()); - configuration.setName(name); - JavaAtomicComponent component = new JavaAtomicComponent(configuration); - component.setScopeContainer(scope); - return component; - } - - private static Map<Operation<?>, OutboundInvocationChain> createOutboundChains(Class<?> interfaze, - Interceptor interceptor) - throws InvalidServiceContractException { - Map<Operation<?>, OutboundInvocationChain> invocations = new HashMap<Operation<?>, OutboundInvocationChain>(); - ServiceContract<?> contract = REGISTRY.introspect(interfaze); - for (Operation<?> operation : contract.getOperations().values()) { - OutboundInvocationChain chain = new OutboundInvocationChainImpl(operation); - if (interceptor != null) { - chain.addInterceptor(interceptor); - } - invocations.put(operation, chain); - } - return invocations; - } - - private static Map<Operation<?>, InboundInvocationChain> createInboundChains(Class<?> interfaze, - Interceptor interceptor) - throws InvalidServiceContractException { - - Map<Operation<?>, InboundInvocationChain> invocations = new HashMap<Operation<?>, InboundInvocationChain>(); - ServiceContract<?> contract = REGISTRY.introspect(interfaze); - for (Operation<?> method : contract.getOperations().values()) { - InboundInvocationChain chain = new InboundInvocationChainImpl(method); - if (interceptor != null) { - chain.addInterceptor(interceptor); - } - // add tail interceptor - chain.addInterceptor(new InvokerInterceptor()); - invocations.put(method, chain); - } - return invocations; - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/scope/ScopeReferenceTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/scope/ScopeReferenceTestCase.java deleted file mode 100644 index 4cd5ac8d9b..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/scope/ScopeReferenceTestCase.java +++ /dev/null @@ -1,781 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.integration.scope; - -import java.lang.reflect.Member; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.Executor; -import java.util.concurrent.Executors; -import java.util.concurrent.FutureTask; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.component.TargetException; -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.model.Scope; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.component.event.CompositeStart; -import org.apache.tuscany.core.component.event.CompositeStop; -import org.apache.tuscany.core.component.event.HttpSessionEnd; -import org.apache.tuscany.core.component.event.HttpSessionStart; -import org.apache.tuscany.core.component.event.RequestEnd; -import org.apache.tuscany.core.component.event.RequestStart; -import org.apache.tuscany.core.component.scope.CompositeScopeContainer; -import org.apache.tuscany.core.component.scope.HttpSessionScopeContainer; -import org.apache.tuscany.core.component.scope.RequestScopeContainer; -import org.apache.tuscany.core.component.scope.StatelessScopeContainer; -import org.apache.tuscany.core.integration.mock.MockFactory; -import org.apache.tuscany.core.mock.component.Source; -import org.apache.tuscany.core.mock.component.SourceImpl; -import org.apache.tuscany.core.mock.component.Target; -import org.apache.tuscany.core.mock.component.TargetImpl; -import org.apache.tuscany.core.util.JavaIntrospectionHelper; - -/** - * Tests scoping is properly handled for service references - * - * @version $Rev$ $Date$ - */ -public class ScopeReferenceTestCase extends TestCase { - - private Map<String, Member> members; - - /** - * Tests a composite-to-composite scoped wire - */ - public void testCompositeToComposite() throws Exception { - ScopeContainer scope = new CompositeScopeContainer(null); - scope.start(); - - Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class, - scope, members, "target", Target.class, TargetImpl.class, scope); - scope.onEvent(new CompositeStart(this, null)); - AtomicComponent sourceComponent = contexts.get("source"); - AtomicComponent targetComponent = contexts.get("target"); - Source source = (Source) sourceComponent.getTargetInstance(); - Target target = (Target) targetComponent.getTargetInstance(); - assertNull(source.getTarget().getString()); - assertNull(target.getString()); - target.setString("foo"); - assertTrue(Proxy.isProxyClass(source.getTarget().getClass())); - assertEquals("foo", source.getTarget().getString()); - scope.onEvent(new CompositeStop(this, null)); - scope.stop(); - } - - /** - * Tests a composite-to-session scoped wire is setup properly by the runtime - */ - public void testCompositeToSession() throws Exception { - WorkContext ctx = new WorkContextImpl(); - ScopeContainer compositeScope = new CompositeScopeContainer(null); - compositeScope.start(); - ScopeContainer sessionScope = new HttpSessionScopeContainer(ctx, null); - sessionScope.start(); - - Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class, - compositeScope, members, "target", Target.class, TargetImpl.class, sessionScope); - compositeScope.onEvent(new CompositeStart(this, null)); - Object session1 = new Object(); - ctx.setIdentifier(Scope.SESSION, session1); - sessionScope.onEvent(new HttpSessionStart(this, session1)); - AtomicComponent sourceComponent = contexts.get("source"); - AtomicComponent targetComponent = contexts.get("target"); - Source source = (Source) sourceComponent.getTargetInstance(); - Target target = (Target) targetComponent.getTargetInstance(); - assertNull(source.getTarget().getString()); - assertNull(target.getString()); - target.setString("foo"); - assertTrue(Proxy.isProxyClass(source.getTarget().getClass())); - assertEquals("foo", source.getTarget().getString()); - ctx.clearIdentifier(Scope.SESSION); - sessionScope.onEvent(new HttpSessionEnd(this, session1)); - - //second session - Object session2 = new Object(); - ctx.setIdentifier(Scope.SESSION, session2); - sessionScope.onEvent(new HttpSessionStart(this, session2)); - - Target target2 = (Target) targetComponent.getTargetInstance(); - assertFalse("foo".equals(target2.getString())); - - assertFalse("foo".equals(source.getTarget().getString())); - source.getTarget().setString("bar"); - assertEquals("bar", target2.getString()); - assertEquals("bar", source.getTarget().getString()); - sessionScope.onEvent(new HttpSessionEnd(this, session2)); - - ctx.clearIdentifier(Scope.SESSION); - compositeScope.onEvent(new CompositeStop(this, null)); - sessionScope.stop(); - compositeScope.stop(); - } - - /** - * Tests a composite-to-request scoped wire - */ - public void testCompositeToRequest() throws Exception { - WorkContext ctx = new WorkContextImpl(); - ScopeContainer compositeScope = new CompositeScopeContainer(null); - compositeScope.start(); - final ScopeContainer requestScope = new RequestScopeContainer(ctx, null); - requestScope.start(); - - Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class, - compositeScope, members, "target", Target.class, TargetImpl.class, requestScope); - compositeScope.onEvent(new CompositeStart(this, null)); - requestScope.onEvent(new RequestStart(this)); - - AtomicComponent sourceComponent = contexts.get("source"); - final AtomicComponent targetComponent = contexts.get("target"); - final Source source = (Source) sourceComponent.getTargetInstance(); - Target target = (Target) targetComponent.getTargetInstance(); - assertNull(source.getTarget().getString()); - assertNull(target.getString()); - target.setString("foo"); - assertTrue(Proxy.isProxyClass(source.getTarget().getClass())); - assertEquals("foo", source.getTarget().getString()); - - // spin off another request - Executor executor = Executors.newSingleThreadExecutor(); - FutureTask<Void> future = new FutureTask<Void>(new Runnable() { - public void run() { - requestScope.onEvent(new RequestStart(this)); - Target target2 = null; - try { - target2 = (Target) targetComponent.getTargetInstance(); - } catch (TargetException e) { - fail(e.getMessage()); - } - assertFalse("foo".equals(target2.getString())); - assertFalse("foo".equals(source.getTarget().getString())); - source.getTarget().setString("bar"); - assertEquals("bar", target2.getString()); - assertEquals("bar", source.getTarget().getString()); - requestScope.onEvent(new RequestEnd(this)); - } - }, null); - executor.execute(future); - future.get(); - assertEquals("foo", source.getTarget().getString()); - requestScope.onEvent(new RequestEnd(this)); - compositeScope.onEvent(new CompositeStop(this, null)); - requestScope.stop(); - compositeScope.stop(); - } - - /** - * Tests a composite-to-stateless scoped wire is setup properly by the runtime - */ - public void testCompositeToStateless() throws Exception { - WorkContext ctx = new WorkContextImpl(); - ScopeContainer compositeScope = new CompositeScopeContainer(null); - compositeScope.start(); - ScopeContainer statelessScope = new StatelessScopeContainer(ctx, null); - statelessScope.start(); - - Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class, - compositeScope, members, "target", Target.class, TargetImpl.class, statelessScope); - compositeScope.onEvent(new CompositeStart(this, null)); - - AtomicComponent sourceComponent = contexts.get("source"); - AtomicComponent targetComponent = contexts.get("target"); - Source source = (Source) sourceComponent.getTargetInstance(); - Target target = (Target) targetComponent.getTargetInstance(); - assertTrue(Proxy.isProxyClass(source.getTarget().getClass())); - assertNull(source.getTarget().getString()); - assertNull(target.getString()); - target.setString("foo"); - assertFalse("foo".equals(source.getTarget().getString())); - Target target2 = (Target) targetComponent.getTargetInstance(); - assertFalse("foo".equals(target2.getString())); - source.getTarget().setString("bar"); - assertFalse("bar".equals(source.getTarget().getString())); - compositeScope.onEvent(new CompositeStop(this, null)); - compositeScope.stop(); - statelessScope.stop(); - } - - - /** - * Tests a session-to-session scoped wire - */ - public void testSessionToSession() throws Exception { - WorkContext ctx = new WorkContextImpl(); - ScopeContainer sessionScope = new HttpSessionScopeContainer(ctx, null); - sessionScope.start(); - - Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class, - sessionScope, members, "target", Target.class, TargetImpl.class, sessionScope); - - Object session1 = new Object(); - ctx.setIdentifier(Scope.SESSION, session1); - sessionScope.onEvent(new HttpSessionStart(this, session1)); - AtomicComponent sourceComponent = contexts.get("source"); - AtomicComponent targetComponent = contexts.get("target"); - Source source = (Source) sourceComponent.getTargetInstance(); - Target target = (Target) targetComponent.getTargetInstance(); - source.getTarget().setString("foo"); - source.getTarget().setString("foo"); - assertEquals("foo", target.getString()); - - ctx.clearIdentifier(Scope.SESSION); - sessionScope.onEvent(new HttpSessionEnd(this, session1)); - - //second session - Object session2 = new Object(); - ctx.setIdentifier(Scope.SESSION, session2); - sessionScope.onEvent(new HttpSessionStart(this, session2)); - - Source source2 = (Source) sourceComponent.getTargetInstance(); - assertNotNull(source2); - Target target2 = (Target) targetComponent.getTargetInstance(); - - assertNotNull(target2); - assertNull(target2.getString()); - assertEquals(null, source2.getTarget().getString()); - source2.getTarget().setString("baz"); - assertEquals("baz", source2.getTarget().getString()); - assertEquals("baz", target2.getString()); - ctx.clearIdentifier(Scope.SESSION); - sessionScope.onEvent(new HttpSessionEnd(this, session2)); - sessionScope.stop(); - } - - - /** - * Tests a session-to-composite scoped wire - */ - public void testSessionToComposite() throws Exception { - WorkContext ctx = new WorkContextImpl(); - ScopeContainer compositeScope = new CompositeScopeContainer(null); - compositeScope.start(); - ScopeContainer sessionScope = new HttpSessionScopeContainer(ctx, null); - sessionScope.start(); - - Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class, - sessionScope, members, "target", Target.class, TargetImpl.class, compositeScope); - compositeScope.onEvent(new CompositeStart(this, null)); - Object session1 = new Object(); - ctx.setIdentifier(Scope.SESSION, session1); - sessionScope.onEvent(new HttpSessionStart(this, session1)); - AtomicComponent sourceComponent = contexts.get("source"); - AtomicComponent targetComponent = contexts.get("target"); - Source source = (Source) sourceComponent.getTargetInstance(); - Target target = (Target) targetComponent.getTargetInstance(); - assertNull(source.getTarget().getString()); - assertNull(target.getString()); - target.setString("foo"); - assertTrue(Proxy.isProxyClass(source.getTarget().getClass())); - assertEquals("foo", source.getTarget().getString()); - ctx.clearIdentifier(Scope.SESSION); - sessionScope.onEvent(new HttpSessionEnd(this, session1)); - - //second session - Object session2 = new Object(); - ctx.setIdentifier(Scope.SESSION, session2); - sessionScope.onEvent(new HttpSessionStart(this, session2)); - - Target target2 = (Target) targetComponent.getTargetInstance(); - Source source2 = (Source) sourceComponent.getTargetInstance(); - assertEquals("foo", target2.getString()); - assertEquals("foo", source2.getTarget().getString()); - source2.getTarget().setString("baz"); - assertEquals("baz", source2.getTarget().getString()); - assertEquals("baz", target2.getString()); - assertEquals("baz", target.getString()); - ctx.clearIdentifier(Scope.SESSION); - sessionScope.onEvent(new HttpSessionEnd(this, session2)); - compositeScope.stop(); - sessionScope.stop(); - } - - /** - * Tests a session-to-request scoped wire is setup properly by the runtime - */ - public void testSessionToRequest() throws Exception { - WorkContext ctx = new WorkContextImpl(); - final ScopeContainer requestScope = new RequestScopeContainer(ctx, null); - requestScope.start(); - ScopeContainer sessionScope = new HttpSessionScopeContainer(ctx, null); - sessionScope.start(); - - Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class, - sessionScope, members, "target", Target.class, TargetImpl.class, requestScope); - Object session1 = new Object(); - ctx.setIdentifier(Scope.SESSION, session1); - sessionScope.onEvent(new HttpSessionStart(this, session1)); - requestScope.onEvent(new RequestStart(this)); - AtomicComponent sourceComponent = contexts.get("source"); - final AtomicComponent targetComponent = contexts.get("target"); - final Source source = (Source) sourceComponent.getTargetInstance(); - Target target = (Target) targetComponent.getTargetInstance(); - assertNull(source.getTarget().getString()); - assertNull(target.getString()); - target.setString("foo"); - assertTrue(Proxy.isProxyClass(source.getTarget().getClass())); - assertEquals("foo", source.getTarget().getString()); - - // spin off another request - Executor executor = Executors.newSingleThreadExecutor(); - FutureTask<Void> future = new FutureTask<Void>(new Runnable() { - public void run() { - requestScope.onEvent(new RequestStart(this)); - Target target2 = null; - try { - target2 = (Target) targetComponent.getTargetInstance(); - } catch (TargetException e) { - fail(e.getMessage()); - } - assertFalse("foo".equals(target2.getString())); - assertFalse("foo".equals(source.getTarget().getString())); - source.getTarget().setString("bar"); - assertEquals("bar", target2.getString()); - assertEquals("bar", source.getTarget().getString()); - requestScope.onEvent(new RequestEnd(this)); - } - }, null); - executor.execute(future); - future.get(); - assertEquals("foo", source.getTarget().getString()); - requestScope.onEvent(new RequestEnd(this)); - ctx.clearIdentifier(Scope.SESSION); - sessionScope.onEvent(new HttpSessionEnd(this, session1)); - requestScope.stop(); - sessionScope.stop(); - } - - - /** - * Tests a session-to-stateless scoped wire is setup properly by the runtime - */ - public void testSessionToStateless() throws Exception { - WorkContext ctx = new WorkContextImpl(); - ScopeContainer sessionScope = new HttpSessionScopeContainer(ctx, null); - sessionScope.start(); - ScopeContainer statelessScope = new StatelessScopeContainer(ctx, null); - statelessScope.start(); - - Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class, - sessionScope, members, "target", Target.class, TargetImpl.class, statelessScope); - - Object session1 = new Object(); - ctx.setIdentifier(Scope.SESSION, session1); - sessionScope.onEvent(new HttpSessionStart(this, session1)); - - AtomicComponent sourceComponent = contexts.get("source"); - AtomicComponent targetComponent = contexts.get("target"); - Source source = (Source) sourceComponent.getTargetInstance(); - Target target = (Target) targetComponent.getTargetInstance(); - assertTrue(Proxy.isProxyClass(source.getTarget().getClass())); - assertNull(source.getTarget().getString()); - assertNull(target.getString()); - target.setString("foo"); - assertFalse("foo".equals(source.getTarget().getString())); - Target target2 = (Target) targetComponent.getTargetInstance(); - assertFalse("foo".equals(target2.getString())); - source.getTarget().setString("bar"); - assertFalse("bar".equals(source.getTarget().getString())); - - ctx.clearIdentifier(Scope.SESSION); - sessionScope.onEvent(new HttpSessionEnd(this, session1)); - sessionScope.stop(); - statelessScope.stop(); - } - - /** - * Tests a request-to-request scoped wire is setup properly by the runtime - */ - public void testRequestToRequest() throws Exception { - WorkContext ctx = new WorkContextImpl(); - final ScopeContainer requestScope = new RequestScopeContainer(ctx, null); - requestScope.start(); - - Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class, - requestScope, members, "target", Target.class, TargetImpl.class, requestScope); - requestScope.onEvent(new RequestStart(this)); - - final AtomicComponent sourceComponent = contexts.get("source"); - final AtomicComponent targetComponent = contexts.get("target"); - Source source = (Source) sourceComponent.getTargetInstance(); - Target target = (Target) targetComponent.getTargetInstance(); - assertNull(source.getTarget().getString()); - assertNull(target.getString()); - target.setString("foo"); - assertTrue(Proxy.isProxyClass(source.getTarget().getClass())); - assertEquals("foo", source.getTarget().getString()); - - // spin off another request - Executor executor = Executors.newSingleThreadExecutor(); - FutureTask<Void> future = new FutureTask<Void>(new Runnable() { - public void run() { - requestScope.onEvent(new RequestStart(this)); - Source source2 = null; - Target target2 = null; - try { - source2 = (Source) sourceComponent.getTargetInstance(); - target2 = (Target) targetComponent.getTargetInstance(); - } catch (TargetException e) { - fail(e.getMessage()); - } - assertFalse("foo".equals(target2.getString())); - assertFalse("foo".equals(source2.getTarget().getString())); - source2.getTarget().setString("bar"); - assertEquals("bar", target2.getString()); - assertEquals("bar", source2.getTarget().getString()); - requestScope.onEvent(new RequestEnd(this)); - } - }, null); - executor.execute(future); - future.get(); - requestScope.onEvent(new RequestEnd(this)); - requestScope.stop(); - } - - /** - * Tests a request-to-composite scoped wire - */ - public void testRequestToComposite() throws Exception { - WorkContext ctx = new WorkContextImpl(); - final ScopeContainer requestScope = new RequestScopeContainer(ctx, null); - final ScopeContainer compositeScope = new CompositeScopeContainer(null); - requestScope.start(); - compositeScope.start(); - compositeScope.onEvent(new CompositeStart(this, null)); - - Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class, - requestScope, members, "target", Target.class, TargetImpl.class, compositeScope); - requestScope.onEvent(new RequestStart(this)); - - final AtomicComponent sourceComponent = contexts.get("source"); - final AtomicComponent targetComponent = contexts.get("target"); - Source source = (Source) sourceComponent.getTargetInstance(); - Target target = (Target) targetComponent.getTargetInstance(); - assertNull(source.getTarget().getString()); - assertNull(target.getString()); - target.setString("foo"); - assertTrue(Proxy.isProxyClass(source.getTarget().getClass())); - assertEquals("foo", source.getTarget().getString()); - - // spin off another request - Executor executor = Executors.newSingleThreadExecutor(); - FutureTask<Void> future = new FutureTask<Void>(new Runnable() { - public void run() { - requestScope.onEvent(new RequestStart(this)); - Source source2 = null; - Target target2 = null; - try { - source2 = (Source) sourceComponent.getTargetInstance(); - target2 = (Target) targetComponent.getTargetInstance(); - } catch (TargetException e) { - fail(e.getMessage()); - } - assertEquals("foo", target2.getString()); - assertEquals("foo", source2.getTarget().getString()); - source2.getTarget().setString("bar"); - assertEquals("bar", target2.getString()); - assertEquals("bar", source2.getTarget().getString()); - requestScope.onEvent(new RequestEnd(this)); - } - }, null); - executor.execute(future); - future.get(); - assertEquals("bar", target.getString()); - - requestScope.onEvent(new RequestEnd(this)); - requestScope.stop(); - compositeScope.onEvent(new CompositeStop(this, null)); - compositeScope.stop(); - } - - /** - * Tests a request-to-session scoped wire is setup properly by the runtime - */ - public void testRequestToSession() throws Exception { - WorkContext ctx = new WorkContextImpl(); - final ScopeContainer requestScope = new RequestScopeContainer(ctx, null); - final ScopeContainer sessionScope = new HttpSessionScopeContainer(ctx, null); - requestScope.start(); - sessionScope.start(); - - Object session1 = new Object(); - ctx.setIdentifier(Scope.SESSION, session1); - sessionScope.onEvent(new HttpSessionStart(this, session1)); - Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class, - requestScope, members, "target", Target.class, TargetImpl.class, sessionScope); - - final AtomicComponent sourceComponent = contexts.get("source"); - final AtomicComponent targetComponent = contexts.get("target"); - requestScope.onEvent(new RequestStart(this)); - Source source = (Source) sourceComponent.getTargetInstance(); - Target target = (Target) targetComponent.getTargetInstance(); - assertNull(source.getTarget().getString()); - assertNull(target.getString()); - target.setString("foo"); - assertTrue(Proxy.isProxyClass(source.getTarget().getClass())); - assertEquals("foo", source.getTarget().getString()); - - // spin off another request - Executor executor = Executors.newSingleThreadExecutor(); - FutureTask<Void> future = new FutureTask<Void>(new Runnable() { - public void run() { - requestScope.onEvent(new RequestStart(this)); - Source source2 = null; - Target target2 = null; - try { - source2 = (Source) sourceComponent.getTargetInstance(); - target2 = (Target) targetComponent.getTargetInstance(); - } catch (TargetException e) { - fail(e.getMessage()); - } - assertEquals("foo", target2.getString()); - assertEquals("foo", source2.getTarget().getString()); - source2.getTarget().setString("bar"); - assertEquals("bar", target2.getString()); - assertEquals("bar", source2.getTarget().getString()); - requestScope.onEvent(new RequestEnd(this)); - } - }, null); - executor.execute(future); - future.get(); - assertEquals("bar", target.getString()); - - requestScope.onEvent(new RequestEnd(this)); - requestScope.stop(); - ctx.clearIdentifier(Scope.SESSION); - sessionScope.onEvent(new HttpSessionEnd(this, session1)); - sessionScope.stop(); - } - - - /** - * Tests a request-to-stateless scoped wire is setup properly by the runtime - */ - public void testRequestToStateless() throws Exception { - WorkContext ctx = new WorkContextImpl(); - ScopeContainer requestScope = new RequestScopeContainer(ctx, null); - requestScope.start(); - ScopeContainer statelessScope = new StatelessScopeContainer(ctx, null); - statelessScope.start(); - - Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class, - requestScope, members, "target", Target.class, TargetImpl.class, statelessScope); - - AtomicComponent sourceComponent = contexts.get("source"); - AtomicComponent targetComponent = contexts.get("target"); - requestScope.onEvent(new RequestStart(this)); - Source source = (Source) sourceComponent.getTargetInstance(); - Target target = (Target) targetComponent.getTargetInstance(); - assertTrue(Proxy.isProxyClass(source.getTarget().getClass())); - assertNull(source.getTarget().getString()); - assertNull(target.getString()); - target.setString("foo"); - assertFalse("foo".equals(source.getTarget().getString())); - Target target2 = (Target) targetComponent.getTargetInstance(); - assertFalse("foo".equals(target2.getString())); - source.getTarget().setString("bar"); - assertFalse("bar".equals(source.getTarget().getString())); - requestScope.onEvent(new RequestEnd(this)); - requestScope.stop(); - statelessScope.stop(); - } - - - /** - * Tests a stateless-to-stateless scoped wire is setup properly by the runtime - */ - public void testStatelessToStateless() throws Exception { - WorkContext ctx = new WorkContextImpl(); - ScopeContainer statelessScope = new StatelessScopeContainer(ctx, null); - statelessScope.start(); - - Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class, - statelessScope, members, "target", Target.class, TargetImpl.class, statelessScope); - - AtomicComponent sourceComponent = contexts.get("source"); - AtomicComponent targetComponent = contexts.get("target"); - Source source = (Source) sourceComponent.getTargetInstance(); - Target target = (Target) targetComponent.getTargetInstance(); - assertTrue(Proxy.isProxyClass(source.getTarget().getClass())); - assertNull(source.getTarget().getString()); - assertNull(target.getString()); - target.setString("foo"); - assertFalse("foo".equals(source.getTarget().getString())); - Target target2 = (Target) targetComponent.getTargetInstance(); - assertFalse("foo".equals(target2.getString())); - source.getTarget().setString("bar"); - assertFalse("bar".equals(source.getTarget().getString())); - statelessScope.stop(); - } - - /** - * Tests a stateless-to-request scoped wire is setup properly by the runtime - */ - public void testStatelessToRequest() throws Exception { - WorkContext ctx = new WorkContextImpl(); - final ScopeContainer requestScope = new RequestScopeContainer(ctx, null); - requestScope.start(); - ScopeContainer statelessScope = new StatelessScopeContainer(ctx, null); - statelessScope.start(); - - Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class, - statelessScope, members, "target", Target.class, TargetImpl.class, requestScope); - requestScope.onEvent(new RequestStart(this)); - AtomicComponent sourceComponent = contexts.get("source"); - final AtomicComponent targetComponent = contexts.get("target"); - final Source source = (Source) sourceComponent.getTargetInstance(); - Target target = (Target) targetComponent.getTargetInstance(); - assertNull(source.getTarget().getString()); - assertNull(target.getString()); - target.setString("foo"); - assertTrue(Proxy.isProxyClass(source.getTarget().getClass())); - assertEquals("foo", source.getTarget().getString()); - - // spin off another request - Executor executor = Executors.newSingleThreadExecutor(); - FutureTask<Void> future = new FutureTask<Void>(new Runnable() { - public void run() { - requestScope.onEvent(new RequestStart(this)); - Target target2 = null; - try { - target2 = (Target) targetComponent.getTargetInstance(); - } catch (TargetException e) { - fail(e.getMessage()); - } - assertFalse("foo".equals(target2.getString())); - assertFalse("foo".equals(source.getTarget().getString())); - source.getTarget().setString("bar"); - assertEquals("bar", target2.getString()); - assertEquals("bar", source.getTarget().getString()); - requestScope.onEvent(new RequestEnd(this)); - } - }, null); - executor.execute(future); - future.get(); - requestScope.stop(); - statelessScope.stop(); - } - - /** - * Tests a stateless-to-session scoped wire is setup properly by the runtime - */ - public void testStatelessToSession() throws Exception { - WorkContext ctx = new WorkContextImpl(); - ScopeContainer statelessScope = new StatelessScopeContainer(ctx, null); - statelessScope.start(); - ScopeContainer sessionScope = new HttpSessionScopeContainer(ctx, null); - sessionScope.start(); - - Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class, - statelessScope, members, "target", Target.class, TargetImpl.class, sessionScope); - Object session1 = new Object(); - ctx.setIdentifier(Scope.SESSION, session1); - sessionScope.onEvent(new HttpSessionStart(this, session1)); - AtomicComponent sourceComponent = contexts.get("source"); - AtomicComponent targetComponent = contexts.get("target"); - Source source = (Source) sourceComponent.getTargetInstance(); - Target target = (Target) targetComponent.getTargetInstance(); - assertNull(source.getTarget().getString()); - assertNull(target.getString()); - target.setString("foo"); - assertTrue(Proxy.isProxyClass(source.getTarget().getClass())); - assertEquals("foo", source.getTarget().getString()); - ctx.clearIdentifier(Scope.SESSION); - sessionScope.onEvent(new HttpSessionEnd(this, session1)); - - //second session - Object session2 = new Object(); - ctx.setIdentifier(Scope.SESSION, session2); - sessionScope.onEvent(new HttpSessionStart(this, session2)); - - Target target2 = (Target) targetComponent.getTargetInstance(); - assertFalse("foo".equals(target2.getString())); - - assertFalse("foo".equals(source.getTarget().getString())); - source.getTarget().setString("bar"); - assertEquals("bar", target2.getString()); - assertEquals("bar", source.getTarget().getString()); - sessionScope.onEvent(new HttpSessionEnd(this, session2)); - - ctx.clearIdentifier(Scope.SESSION); - sessionScope.stop(); - statelessScope.stop(); - } - - - /** - * Tests a stateless-to-composite scoped wire is setup properly by the runtime - */ - public void testStatelessToComposite() throws Exception { - WorkContext ctx = new WorkContextImpl(); - ScopeContainer statelessScope = new StatelessScopeContainer(ctx, null); - statelessScope.start(); - ScopeContainer compositeScope = new CompositeScopeContainer(null); - compositeScope.start(); - - Map<String, AtomicComponent> contexts = MockFactory.createWiredComponents("source", SourceImpl.class, - statelessScope, members, "target", Target.class, TargetImpl.class, compositeScope); - compositeScope.onEvent(new CompositeStart(this, null)); - AtomicComponent sourceComponent = contexts.get("source"); - AtomicComponent targetComponent = contexts.get("target"); - Source source = (Source) sourceComponent.getTargetInstance(); - Target target = (Target) targetComponent.getTargetInstance(); - assertNull(source.getTarget().getString()); - assertNull(target.getString()); - target.setString("foo"); - assertTrue(Proxy.isProxyClass(source.getTarget().getClass())); - assertEquals("foo", source.getTarget().getString()); - - //second session - Object session2 = new Object(); - ctx.setIdentifier(Scope.SESSION, session2); - compositeScope.onEvent(new HttpSessionStart(this, session2)); - - Target target2 = (Target) targetComponent.getTargetInstance(); - assertEquals("foo", target2.getString()); - - assertEquals("foo", source.getTarget().getString()); - source.getTarget().setString("bar"); - assertEquals("bar", target2.getString()); - assertEquals("bar", source.getTarget().getString()); - - compositeScope.onEvent(new CompositeStop(this, null)); - compositeScope.stop(); - statelessScope.stop(); - } - - protected void setUp() throws Exception { - super.setUp(); - members = new HashMap<String, Member>(); - Method[] methods = SourceImpl.class.getMethods(); - for (Method method : methods) { - if (method.getName().startsWith("set")) { - members.put(JavaIntrospectionHelper.toPropertyName(method.getName()), method); - } - } - } - - -} - diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/wire/DifferentInterfaceWireTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/wire/DifferentInterfaceWireTestCase.java deleted file mode 100644 index 431f47b5bf..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/wire/DifferentInterfaceWireTestCase.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.integration.wire; - -import java.lang.reflect.Member; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.ScopeContainer; -import org.apache.tuscany.spi.component.TargetException; -import org.apache.tuscany.spi.model.Scope; - -import junit.framework.TestCase; -import org.apache.tuscany.core.integration.mock.MockFactory; -import org.apache.tuscany.core.mock.component.OtherTarget; -import org.apache.tuscany.core.mock.component.OtherTargetImpl; -import org.apache.tuscany.core.mock.component.Target; -import org.apache.tuscany.core.mock.component.SourceImpl; -import org.apache.tuscany.core.mock.component.Source; -import org.easymock.EasyMock; -import org.easymock.IAnswer; - - -/** - * Tests wires that have different interfaces on the source and target side - * - * @version $Rev$ $Date$ - */ -public class DifferentInterfaceWireTestCase extends TestCase { - - public void testDifferentInterfaceInjection() throws Exception { - Map<String, Member> members = new HashMap<String, Member>(); - Method m = SourceImpl.class.getMethod("setTarget", Target.class); - members.put("target", m); - ScopeContainer scope = createMock(); - scope.start(); - Map<String, AtomicComponent> contexts = - MockFactory.createWiredComponents("source", - SourceImpl.class, - Target.class, - scope, - null, - members, - "target", - OtherTarget.class, - OtherTargetImpl.class, - scope, - null); - AtomicComponent sourceComponent = contexts.get("source"); - Source source = (Source) sourceComponent.getTargetInstance(); - Target target = source.getTarget(); - assertTrue(Proxy.isProxyClass(target.getClass())); - assertNotNull(target); - scope.stop(); - EasyMock.verify(scope); - } - - public void testDifferentInterfaceMultiplicityInjection() throws Exception { - Map<String, Member> members = new HashMap<String, Member>(); - Method m = SourceImpl.class.getMethod("setTargets", List.class); - members.put("target", m); - ScopeContainer scope = createMock(); - scope.start(); - Map<String, AtomicComponent> components = MockFactory.createWiredMultiplicity("source", - SourceImpl.class, - Target.class, - scope, - "target", - OtherTarget.class, - OtherTargetImpl.class, - members, - scope); - AtomicComponent sourceComponent = components.get("source"); - Source source = (Source) sourceComponent.getTargetInstance(); - List<Target> targets = source.getTargets(); - assertEquals(1, targets.size()); - Target target = targets.get(0); - target.setString("foo"); - assertEquals("foo", target.getString()); - assertTrue(Proxy.isProxyClass(target.getClass())); - scope.stop(); - EasyMock.verify(scope); - } - - protected void setUp() throws Exception { - super.setUp(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - - private ScopeContainer createMock() throws TargetException { - ScopeContainer scope = EasyMock.createMock(ScopeContainer.class); - scope.start(); - scope.stop(); - scope.register(EasyMock.isA(AtomicComponent.class)); - EasyMock.expectLastCall().atLeastOnce(); - EasyMock.expect(scope.getScope()).andReturn(Scope.COMPOSITE).atLeastOnce(); - scope.getInstance(EasyMock.isA(AtomicComponent.class)); - EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() { - private Map<AtomicComponent, Object> cache = new HashMap<AtomicComponent, Object>(); - - public Object answer() throws Throwable { - AtomicComponent component = (AtomicComponent) EasyMock.getCurrentArguments()[0]; - Object instance = cache.get(component); - if (instance == null) { - instance = component.createInstance(); - cache.put(component, instance); - } - return instance; - } - }).anyTimes(); - EasyMock.replay(scope); - return scope; - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/wire/ReferenceInjectionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/wire/ReferenceInjectionTestCase.java deleted file mode 100644 index 603e334fe9..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/wire/ReferenceInjectionTestCase.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.integration.wire; - -import java.lang.reflect.Member; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.ScopeContainer; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.scope.CompositeScopeContainer; -import org.apache.tuscany.core.integration.mock.MockFactory; -import org.apache.tuscany.core.mock.component.Source; -import org.apache.tuscany.core.mock.component.SourceImpl; -import org.apache.tuscany.core.mock.component.TargetImpl; -import org.apache.tuscany.core.mock.component.Target; - -/** - * @version $$Rev$$ $$Date$$ - */ -public class ReferenceInjectionTestCase extends TestCase { - - private Map<String, Member> members; - - public void testProxiedReferenceInjection() throws Exception { - ScopeContainer scope = new CompositeScopeContainer(null); - scope.start(); - Map<String, AtomicComponent> components = - MockFactory.createWiredComponents("source", SourceImpl.class, scope, - members, "target", Target.class, TargetImpl.class, scope); - AtomicComponent sourceComponent = components.get("source"); - Source source = (Source) sourceComponent.getTargetInstance(); - Target target = source.getTarget(); - assertTrue(Proxy.isProxyClass(target.getClass())); - - assertNotNull(target); - scope.stop(); - } - - protected void setUp() throws Exception { - super.setUp(); - members = new HashMap<String, Member>(); - Method m = SourceImpl.class.getMethod("setTarget", Target.class); - members.put("target", m); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/wire/oneway/OneWayWireToJavaInvocationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/wire/oneway/OneWayWireToJavaInvocationTestCase.java deleted file mode 100644 index 78e349b788..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/integration/wire/oneway/OneWayWireToJavaInvocationTestCase.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.integration.wire.oneway; - -import java.lang.reflect.Method; -import java.lang.reflect.Type; -import java.util.concurrent.CountDownLatch; - -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.extension.ExecutionMonitor; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.services.work.WorkScheduler; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.TargetInvoker; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.implementation.java.JavaAtomicComponent; -import org.apache.tuscany.core.implementation.java.JavaTargetInvoker; -import org.apache.tuscany.core.services.work.jsr237.Jsr237WorkScheduler; -import org.apache.tuscany.core.services.work.jsr237.workmanager.ThreadPoolWorkManager; -import org.apache.tuscany.core.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InvokerInterceptor; -import org.apache.tuscany.core.wire.NonBlockingBridgingInterceptor; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.easymock.classextension.EasyMock; - -/** - * Verifies non-blocking invocations are properly made through a wire to a Java component - * - * @version $Rev$ $Date$ - */ -public class OneWayWireToJavaInvocationTestCase extends TestCase { - private WorkScheduler scheduler; - private WorkContext context; - private CountDownLatch latch; - private OutboundInvocationChain ochain; - private JavaTargetInvoker invoker; - private JavaAtomicComponent component; - private AsyncTarget target; - - public void testOneWay() throws Exception { - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(invoker); - ochain.getHeadInterceptor().invoke(msg); - latch.await(); - EasyMock.verify(target); - EasyMock.verify(component); - } - - protected void setUp() throws Exception { - super.setUp(); - latch = new CountDownLatch(1); - context = new WorkContextImpl(); - scheduler = new Jsr237WorkScheduler(new ThreadPoolWorkManager(1)); - target = EasyMock.createMock(AsyncTarget.class); - target.invoke(); - EasyMock.expectLastCall().once(); - EasyMock.replay(target); - component = EasyMock.createMock(JavaAtomicComponent.class); - EasyMock.expect(component.getScope()).andReturn(Scope.COMPOSITE); - EasyMock.expect(component.getTargetInstance()).andReturn(target); - EasyMock.replay(component); - Method method = AsyncTarget.class.getMethod("invoke"); - method.setAccessible(true); - InboundWire inboundWire = EasyMock.createMock(InboundWire.class); - ExecutionMonitor monitor = EasyMock.createNiceMock(ExecutionMonitor.class); - invoker = new JavaTargetInvoker(method, component, inboundWire, context, monitor); - Operation<Type> operation = new Operation<Type>("invoke", null, null, null, false, null, TargetInvoker.NONE); - ochain = new OutboundInvocationChainImpl(operation); - NonBlockingBridgingInterceptor bridgeInterceptor = new NonBlockingBridgingInterceptor(scheduler, context); - ochain.addInterceptor(bridgeInterceptor); - InboundInvocationChain ichain = new InboundInvocationChainImpl(operation); - WaitInterceptor waitInterceptor = new WaitInterceptor(); - InvokerInterceptor invokerInterceptor = new InvokerInterceptor(); - ichain.addInterceptor(waitInterceptor); - ichain.addInterceptor(invokerInterceptor); - bridgeInterceptor.setNext(waitInterceptor); - ochain.setTargetInvoker(invoker); - } - - public interface AsyncTarget { - void invoke(); - } - - - private class WaitInterceptor implements Interceptor { - private Interceptor next; - - public Message invoke(Message msg) { - msg = next.invoke(msg); - latch.countDown(); - return msg; - } - - public Interceptor getNext() { - return next; - } - - public void setNext(Interceptor next) { - this.next = next; - } - - public boolean isOptimizable() { - return false; - } - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderNoBindingTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderNoBindingTestCase.java deleted file mode 100644 index 3f6df22677..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderNoBindingTestCase.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.loader; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamReader; - -import static org.osoa.sca.Constants.SCA_NS; - -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.loader.LoaderRegistry; -import org.apache.tuscany.spi.model.ComponentTypeReferenceDefinition; -import org.apache.tuscany.spi.model.Implementation; -import org.apache.tuscany.spi.model.ModelObject; -import org.apache.tuscany.spi.model.Property; -import org.apache.tuscany.spi.model.AbstractReferenceDefinition; -import org.apache.tuscany.spi.model.ServiceDefinition; - -import junit.framework.TestCase; -import org.apache.tuscany.core.implementation.java.JavaImplementation; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class ComponentLoaderNoBindingTestCase extends TestCase { - private static final QName COMPONENT = new QName(SCA_NS, "component"); - private ComponentLoader loader; - private XMLStreamReader reader; - private ServiceDefinition service; - private ComponentTypeReferenceDefinition reference; - - public void testNoServiceBinding() throws Exception { - loader.load(null, null, reader, null); - assert service.getBindings().isEmpty(); - } - - public void testNoReferenceBinding() throws Exception { - loader.load(null, null, reader, null); - assert reference.getBindings().isEmpty(); - } - - protected void setUp() throws Exception { - super.setUp(); - service = new ServiceDefinition(); - reference = new ComponentTypeReferenceDefinition(); - PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>> type = - new PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>>(); - type.add(service); - type.add(reference); - JavaImplementation impl = new JavaImplementation(null, type); - LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class); - EasyMock.expect(registry.load((CompositeComponent) EasyMock.isNull(), - (ModelObject) EasyMock.isNull(), - EasyMock.isA(XMLStreamReader.class), - (DeploymentContext) EasyMock.isNull())).andReturn(impl); - registry.loadComponentType((CompositeComponent) EasyMock.isNull(), - EasyMock.isA(Implementation.class), - (DeploymentContext) EasyMock.isNull()); - EasyMock.replay(registry); - loader = new ComponentLoader(registry, null); - reader = EasyMock.createMock(XMLStreamReader.class); - EasyMock.expect(reader.getName()).andReturn(COMPONENT).atLeastOnce(); - EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT); - EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn("foo"); - EasyMock.expect(reader.getAttributeValue(null, "autowire")).andReturn("false"); - EasyMock.expect(reader.getAttributeValue(null, "initLevel")).andReturn("0"); - EasyMock.expect(reader.nextTag()).andReturn(1); - EasyMock.replay(reader); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderPropertyTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderPropertyTestCase.java deleted file mode 100644 index 5034e5114a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderPropertyTestCase.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.loader; - -import javax.xml.stream.XMLStreamException; - -import junit.framework.TestCase; - -import org.apache.tuscany.core.implementation.java.JavaImplementation; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.loader.LoaderException; -import org.apache.tuscany.spi.loader.LoaderRegistry; -import org.apache.tuscany.spi.loader.MissingPropertyValueException; -import org.apache.tuscany.spi.loader.PropertyObjectFactory; -import org.apache.tuscany.spi.model.ComponentDefinition; -import org.apache.tuscany.spi.model.ComponentTypeReferenceDefinition; -import org.apache.tuscany.spi.model.Implementation; -import org.apache.tuscany.spi.model.Property; -import org.apache.tuscany.spi.model.AbstractReferenceDefinition; -import org.apache.tuscany.spi.model.ServiceDefinition; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class ComponentLoaderPropertyTestCase extends TestCase { - - private TestLoader loader; - - /** - * Verifies that an optional property not cofigured in an assembly will avoid having a PropertyValue created for it - * so that the runtime does not erroneously inject null values - */ - public void testMissingPropertyValueException() throws LoaderException, XMLStreamException { - PojoComponentType<?, ?, Property<?>> type = - new PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>>(); - Property property = new Property(); - property.setName("name"); - property.setMustSupply(true); - type.add(property); - - JavaImplementation impl = new JavaImplementation(null, type); - impl.setComponentType(type); - ComponentDefinition<Implementation<?>> defn = new ComponentDefinition<Implementation<?>>(impl); - assertTrue(defn.getPropertyValues().isEmpty()); - try { - loader.populatePropertyValues(defn); - fail(); - } catch (Exception e) { - assertTrue(e instanceof MissingPropertyValueException); - } - - } - - protected void setUp() throws Exception { - super.setUp(); - LoaderRegistry mockRegistry = EasyMock.createMock(LoaderRegistry.class); - PropertyObjectFactory mockPropertyFactory = EasyMock.createMock(PropertyObjectFactory.class); - loader = new TestLoader(mockRegistry, mockPropertyFactory); - } - - private class TestLoader extends ComponentLoader { - - public TestLoader(LoaderRegistry registry, PropertyObjectFactory propertyFactory) { - super(registry, propertyFactory); - } - - @Override - public void populatePropertyValues(ComponentDefinition<Implementation<?>> componentDefinition) - throws MissingPropertyValueException, LoaderException { - super.populatePropertyValues(componentDefinition); - } - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderReferenceTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderReferenceTestCase.java deleted file mode 100644 index 3d73e53883..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderReferenceTestCase.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.apache.tuscany.core.loader; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import static org.osoa.sca.Constants.SCA_NS; - -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.loader.LoaderException; -import org.apache.tuscany.spi.loader.LoaderRegistry; -import org.apache.tuscany.spi.loader.UndefinedReferenceException; -import org.apache.tuscany.spi.model.ComponentTypeReferenceDefinition; -import org.apache.tuscany.spi.model.Implementation; -import org.apache.tuscany.spi.model.ModelObject; -import org.apache.tuscany.spi.model.Property; -import org.apache.tuscany.spi.model.AbstractReferenceDefinition; -import org.apache.tuscany.spi.model.ServiceDefinition; - -import junit.framework.TestCase; -import org.apache.tuscany.core.implementation.java.JavaImplementation; -import org.easymock.EasyMock; -import static org.easymock.EasyMock.isNull; - -/** - * @version $Rev$ $Date$ - */ -public class ComponentLoaderReferenceTestCase extends TestCase { - private static final QName COMPONENT = new QName(SCA_NS, "component"); - private static final QName REFERENCE = new QName(SCA_NS, "reference"); - private static final String NAME = "testComponent"; - private ComponentLoader loader; - private XMLStreamReader reader; - - /** - * Verifies an error is thrown when an attempt to configure a non-existent reference in SCDL is made - */ - public void testNoReferenceOnComponentType() throws LoaderException, XMLStreamException { - try { - loader.load(null, null, reader, null); - fail(); - } catch (UndefinedReferenceException e) { - // expected - } - } - - protected void setUp() throws Exception { - super.setUp(); - PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>> type = - new PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>>(); - JavaImplementation impl = new JavaImplementation(null, type); - reader = EasyMock.createMock(XMLStreamReader.class); - EasyMock.expect(reader.getName()).andReturn(COMPONENT); - EasyMock.expect(reader.getAttributeValue((String) EasyMock.isNull(), EasyMock.isA(String.class))) - .andReturn(NAME); - EasyMock.expect(reader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("initLevel"))) - .andReturn(null); - EasyMock.expect(reader.getAttributeValue((String) isNull(), EasyMock.eq("autowire"))) - .andReturn("false"); - EasyMock.expect(reader.getAttributeValue(EasyMock.isA(String.class), EasyMock.isA(String.class))) - .andReturn(null); - EasyMock.expect(reader.nextTag()).andReturn(0); - EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.START_ELEMENT); - EasyMock.expect(reader.getName()).andReturn(REFERENCE); - EasyMock.expect(reader.getAttributeValue((String) isNull(), EasyMock.eq("name"))) - .andReturn("noreference"); - EasyMock.expect(reader.getElementText()).andReturn("text"); - - EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT); - EasyMock.replay(reader); - LoaderRegistry mockRegistry = EasyMock.createMock(LoaderRegistry.class); - mockRegistry.loadComponentType((CompositeComponent) isNull(), - EasyMock.isA(Implementation.class), - (DeploymentContext) isNull()); - EasyMock.expect(mockRegistry.load((CompositeComponent) isNull(), - (ModelObject) isNull(), - EasyMock.isA(XMLStreamReader.class), - (DeploymentContext) isNull())).andReturn(impl); - EasyMock.replay(mockRegistry); - loader = new ComponentLoader(mockRegistry, null); - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderTestCase.java deleted file mode 100644 index f4421941fa..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderTestCase.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.loader; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import static org.osoa.sca.Constants.SCA_NS; - -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.loader.LoaderException; -import org.apache.tuscany.spi.loader.LoaderRegistry; -import org.apache.tuscany.spi.loader.PropertyObjectFactory; -import org.apache.tuscany.spi.loader.UnrecognizedElementException; -import org.apache.tuscany.spi.model.ComponentDefinition; -import org.apache.tuscany.spi.model.ComponentTypeReferenceDefinition; -import org.apache.tuscany.spi.model.Implementation; -import org.apache.tuscany.spi.model.ModelObject; -import org.apache.tuscany.spi.model.Property; -import org.apache.tuscany.spi.model.AbstractReferenceDefinition; -import org.apache.tuscany.spi.model.ServiceDefinition; - -import junit.framework.TestCase; -import org.apache.tuscany.core.implementation.java.JavaImplementation; -import org.easymock.EasyMock; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.isNull; -import static org.easymock.EasyMock.replay; -import org.easymock.IAnswer; - -/** - * @version $Rev$ $Date$ - */ -public class ComponentLoaderTestCase extends TestCase { - private static final QName COMPONENT = new QName(SCA_NS, "component"); - private static final String NAME = "testComponent"; - private JavaImplementation impl; - - private XMLStreamReader mockReader; - private LoaderRegistry mockRegistry; - private PropertyObjectFactory mockPropertyFactory; - private ComponentLoader loader; - - public void testEmptyComponent() throws LoaderException, XMLStreamException { - EasyMock.expect(mockReader.getName()).andReturn(COMPONENT).atLeastOnce(); - EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.isA(String.class))) - .andReturn(NAME); - EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("initLevel"))) - .andReturn(null); - EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("autowire"))) - .andReturn("false"); - EasyMock.expect(mockReader.getAttributeValue(EasyMock.isA(String.class), EasyMock.isA(String.class))) - .andReturn(null); - EasyMock.expect(mockReader.nextTag()).andReturn(0); - EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT); - EasyMock.replay(mockReader); - mockRegistry.loadComponentType(EasyMock.isA(CompositeComponent.class), - EasyMock.isA(Implementation.class), - EasyMock.isA(DeploymentContext.class)); - EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() { - @SuppressWarnings("unchecked") - public Object answer() throws Throwable { - Implementation impl = (Implementation) EasyMock.getCurrentArguments()[1]; - impl.setComponentType(new PojoComponentType()); - return impl; - } - }); - - EasyMock.expect(mockRegistry.load(EasyMock.isA(CompositeComponent.class), - (ModelObject) isNull(), - EasyMock.eq(mockReader), - EasyMock.isA(DeploymentContext.class))).andReturn(impl); - EasyMock.replay(mockRegistry); - ComponentDefinition component = loader.load(EasyMock.createNiceMock(CompositeComponent.class), - null, mockReader, - EasyMock.createNiceMock(DeploymentContext.class)); - assertEquals(NAME, component.getName()); - assertNull(component.getInitLevel()); - } - - public void testInitValue20() throws LoaderException, XMLStreamException { - EasyMock.expect(mockReader.getName()).andReturn(COMPONENT).atLeastOnce(); - EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.isA(String.class))) - .andReturn(NAME); - EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("initLevel"))) - .andReturn("20"); - EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("autowire"))) - .andReturn("false"); - EasyMock.expect(mockReader.nextTag()).andReturn(0); - EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT); - EasyMock.replay(mockReader); - - mockRegistry.loadComponentType(EasyMock.isA(CompositeComponent.class), - EasyMock.isA(Implementation.class), - EasyMock.isA(DeploymentContext.class)); - - EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() { - @SuppressWarnings("unchecked") - public Object answer() throws Throwable { - Implementation impl = (Implementation) EasyMock.getCurrentArguments()[1]; - impl.setComponentType(new PojoComponentType()); - return impl; - } - }); - EasyMock.expect(mockRegistry.load(EasyMock.isA(CompositeComponent.class), - (ModelObject) isNull(), - EasyMock.eq(mockReader), - EasyMock.isA(DeploymentContext.class))).andReturn(impl); - EasyMock.replay(mockRegistry); - ComponentDefinition component = loader.load(EasyMock.createNiceMock(CompositeComponent.class), - null, mockReader, - EasyMock.createNiceMock(DeploymentContext.class)); - assertEquals(NAME, component.getName()); - assertEquals(Integer.valueOf(20), component.getInitLevel()); - } - - public void testLoadPropertyWithSource() throws LoaderException, XMLStreamException { - PojoComponentType<?, ?, Property<?>> type = - new PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>>(); - Property property = new Property(); - property.setName("name"); - type.add(property); - JavaImplementation impl = new JavaImplementation(); - impl.setComponentType(type); - ComponentDefinition<?> defn = new ComponentDefinition<JavaImplementation>(impl); - XMLStreamReader reader = createMock(XMLStreamReader.class); - expect(reader.getAttributeValue(null, "name")).andReturn("name"); - expect(reader.getAttributeValue(null, "source")).andReturn("$source"); - expect(reader.getAttributeValue(null, "type")).andReturn(null).anyTimes(); - expect(reader.getAttributeValue(null, "element")).andReturn(null).anyTimes(); - expect(reader.getAttributeValue(null, "file")).andReturn(null); - expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT); - replay(reader); - loader.loadProperty(reader, null, defn); - assertEquals("$source", defn.getPropertyValues().get("name").getSource()); - EasyMock.verify(reader); - } - - public void testUnrecognizedElement() throws LoaderException, XMLStreamException { - EasyMock.expect(mockReader.getName()).andReturn(COMPONENT); - EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.isA(String.class))) - .andReturn(NAME); - EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("initLevel"))) - .andReturn(null); - EasyMock.expect(mockReader.getAttributeValue((String) EasyMock.isNull(), EasyMock.eq("autowire"))) - .andReturn("false"); - EasyMock.expect(mockReader.getAttributeValue(EasyMock.isA(String.class), EasyMock.isA(String.class))) - .andReturn(null); - EasyMock.expect(mockReader.nextTag()).andReturn(0); - EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.START_ELEMENT); - EasyMock.expect(mockReader.getName()).andReturn(new QName("foo", "bar")); - EasyMock.replay(mockReader); - mockRegistry.loadComponentType(EasyMock.isA(CompositeComponent.class), - EasyMock.isA(Implementation.class), - EasyMock.isA(DeploymentContext.class)); - - EasyMock.expect(mockRegistry.load(EasyMock.isA(CompositeComponent.class), - (ModelObject) isNull(), - EasyMock.eq(mockReader), - EasyMock.isA(DeploymentContext.class))).andReturn(impl); - EasyMock.replay(mockRegistry); - try { - loader.load(EasyMock.createNiceMock(CompositeComponent.class), - null, mockReader, - EasyMock.createNiceMock(DeploymentContext.class)); - fail(); - } catch (UnrecognizedElementException e) { - // expected - } - } - - protected void setUp() throws Exception { - super.setUp(); - impl = new JavaImplementation(); - mockReader = EasyMock.createMock(XMLStreamReader.class); - mockRegistry = EasyMock.createMock(LoaderRegistry.class); - mockPropertyFactory = EasyMock.createMock(PropertyObjectFactory.class); - loader = new ComponentLoader(mockRegistry, mockPropertyFactory); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderValidationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderValidationTestCase.java deleted file mode 100644 index 9c5ce0655c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentLoaderValidationTestCase.java +++ /dev/null @@ -1,170 +0,0 @@ -package org.apache.tuscany.core.loader; - -import java.net.URI; - -import javax.xml.stream.XMLStreamException; - -import org.apache.tuscany.spi.implementation.java.PojoComponentType; -import org.apache.tuscany.spi.loader.ReferenceMultiplicityViolationException; -import org.apache.tuscany.spi.loader.LoaderException; -import org.apache.tuscany.spi.loader.LoaderRegistry; -import org.apache.tuscany.spi.loader.MissingReferenceException; -import org.apache.tuscany.spi.loader.PropertyObjectFactory; -import org.apache.tuscany.spi.model.ComponentDefinition; -import org.apache.tuscany.spi.model.ComponentReferenceDefinition; -import org.apache.tuscany.spi.model.ComponentTypeReferenceDefinition; -import org.apache.tuscany.spi.model.Implementation; -import org.apache.tuscany.spi.model.Multiplicity; -import org.apache.tuscany.spi.model.Property; -import org.apache.tuscany.spi.model.AbstractReferenceDefinition; -import org.apache.tuscany.spi.model.ServiceDefinition; -import org.apache.tuscany.spi.model.ReferenceTarget; - -import junit.framework.TestCase; -import org.apache.tuscany.core.implementation.java.JavaImplementation; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class ComponentLoaderValidationTestCase extends TestCase { - - private ComponentLoaderValidationTestCase.TestLoader loader; - - public void testValidation() throws LoaderException, XMLStreamException { - PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>> type = - new PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>>(); - ComponentTypeReferenceDefinition refDefinition = new ComponentTypeReferenceDefinition(); - refDefinition.setName("name"); - type.add(refDefinition); - JavaImplementation impl = new JavaImplementation(null, type); - ComponentDefinition<Implementation<?>> defn = new ComponentDefinition<Implementation<?>>(impl); - ComponentReferenceDefinition compRef = new ComponentReferenceDefinition(refDefinition); - compRef.addTarget(URI.create("uri")); - defn.add(compRef); - /*ReferenceTarget target = new ReferenceTarget(); - target.setReferenceName("name"); - defn.add(target);*/ - loader.validate(defn); - } - - /*public void testReferenceNotSet() throws LoaderException, XMLStreamException { - PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>> type = - new PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>>(); - ComponentTypeReferenceDefinition refDefinition = new ComponentTypeReferenceDefinition(); - refDefinition.setName("name"); - type.add(refDefinition); - JavaImplementation impl = new JavaImplementation(null, type); - ComponentDefinition<Implementation<?>> defn = new ComponentDefinition<Implementation<?>>(impl); - try { - loader.validate(defn); - fail(); - } catch (MissingReferenceException e) { - // expected - } - }*/ - - public void testNotRequiredReference() throws LoaderException, XMLStreamException { - PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>> type = - new PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>>(); - ComponentTypeReferenceDefinition refDefinition = new ComponentTypeReferenceDefinition(); - refDefinition.setName("name"); - type.add(refDefinition); - JavaImplementation impl = new JavaImplementation(null, type); - ComponentDefinition<Implementation<?>> defn = new ComponentDefinition<Implementation<?>>(impl); - loader.validate(defn); - } - - public void testReferenceMultiplicity() throws LoaderException, XMLStreamException { - PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>> type = - new PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>>(); - ComponentTypeReferenceDefinition refDefinition = new ComponentTypeReferenceDefinition(); - refDefinition.setName("r1"); - refDefinition.setMultiplicity(Multiplicity.ONE_N); - type.add(refDefinition); - JavaImplementation impl = new JavaImplementation(null, type); - ComponentDefinition<Implementation<?>> defn = new ComponentDefinition<Implementation<?>>(impl); - ComponentReferenceDefinition compRef = new ComponentReferenceDefinition(type.getReferences().get("r1")); - compRef.addTarget(URI.create("c1")); - compRef.addTarget(URI.create("c2")); - defn.add(compRef); - /*ReferenceTarget target = new ReferenceTarget(); - target.setReferenceName("r1"); - target.addTarget(URI.create("c1")); - target.addTarget(URI.create("c2")); - defn.add(target);*/ - loader.validate(defn); - - refDefinition.setMultiplicity(Multiplicity.ZERO_ONE); - try { - loader.validate(defn); - fail(); - } catch (ReferenceMultiplicityViolationException e) { - // Expected - } - - refDefinition.setMultiplicity(Multiplicity.ZERO_N); - loader.validate(defn); - - refDefinition.setMultiplicity(Multiplicity.ONE_ONE); - try { - loader.validate(defn); - fail(); - } catch (ReferenceMultiplicityViolationException e) { - // Expected - } - - defn = new ComponentDefinition<Implementation<?>>(impl); - compRef = new ComponentReferenceDefinition(type.getReferences().get("r1")); - defn.add(compRef); - refDefinition.setMultiplicity(Multiplicity.ONE_ONE); - try { - loader.validate(defn); - fail(); - } catch (ReferenceMultiplicityViolationException e) { - // Expected - } - refDefinition.setMultiplicity(Multiplicity.ONE_N); - try { - loader.validate(defn); - fail(); - } catch (ReferenceMultiplicityViolationException e) { - // Expected - } - refDefinition.setMultiplicity(Multiplicity.ZERO_N); - loader.validate(defn); - refDefinition.setMultiplicity(Multiplicity.ZERO_ONE); - loader.validate(defn); - - } - public void testAutowire() throws LoaderException, XMLStreamException { - PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>> type = - new PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>>(); - ComponentTypeReferenceDefinition refDefinition = new ComponentTypeReferenceDefinition(); - refDefinition.setName("name"); - refDefinition.setAutowire(true); - type.add(refDefinition); - JavaImplementation impl = new JavaImplementation(null, type); - ComponentDefinition<Implementation<?>> defn = new ComponentDefinition<Implementation<?>>(impl); - loader.validate(defn); - } - - protected void setUp() throws Exception { - super.setUp(); - LoaderRegistry mockRegistry = EasyMock.createMock(LoaderRegistry.class); - PropertyObjectFactory mockPropertyFactory = EasyMock.createMock(PropertyObjectFactory.class); - loader = new ComponentLoaderValidationTestCase.TestLoader(mockRegistry, mockPropertyFactory); - } - - private class TestLoader extends ComponentLoader { - - public TestLoader(LoaderRegistry registry, PropertyObjectFactory propertyFactory) { - super(registry, propertyFactory); - } - - @Override - protected void validate(ComponentDefinition<Implementation<?>> definition) throws LoaderException { - super.validate(definition); - } - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentReferenceOverridingTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentReferenceOverridingTestCase.java deleted file mode 100644 index ffc6ee7a03..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentReferenceOverridingTestCase.java +++ /dev/null @@ -1,178 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tuscany.core.loader;
-
-import java.io.StringReader;
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
-import junit.framework.Assert;
-
-import org.apache.tuscany.core.binding.local.LocalBindingDefinition;
-import org.apache.tuscany.core.implementation.java.JavaImplementation;
-import org.apache.tuscany.spi.component.CompositeComponent;
-import org.apache.tuscany.spi.deployer.DeploymentContext;
-import org.apache.tuscany.spi.idl.java.JavaServiceContract;
-import org.apache.tuscany.spi.implementation.java.PojoComponentType;
-import org.apache.tuscany.spi.loader.LoaderException;
-import org.apache.tuscany.spi.loader.LoaderRegistry;
-import org.apache.tuscany.spi.loader.ReferenceMultiplicityOverridingException;
-import org.apache.tuscany.spi.model.BindingDefinition;
-import org.apache.tuscany.spi.model.ComponentDefinition;
-import org.apache.tuscany.spi.model.ComponentTypeReferenceDefinition;
-import org.apache.tuscany.spi.model.Implementation;
-import org.apache.tuscany.spi.model.Multiplicity;
-import org.apache.tuscany.spi.model.Property;
-import org.apache.tuscany.spi.model.ServiceDefinition;
-import org.easymock.EasyMock;
-import org.junit.Test;
-
-/**
- * Tests to verify overriding of aspects of componenttype reference defintions
- * by component definitions
- */
-public class ComponentReferenceOverridingTestCase {
- private static XMLInputFactory xmlFactory = XMLInputFactory.newInstance();;
- private static LoaderRegistryImpl loaderRegistry;
-
- public XMLStreamReader getReader(String xml) throws XMLStreamException {
- XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(xml));
- reader.next();
- return reader;
- }
-
-
- @Test
- public void testRefDefNoOverriding() throws LoaderException,
- XMLStreamException,
- URISyntaxException {
- String compDefXml =
- "<tus:component name='TestComponent' xmlns:tus='http://www.osoa.org/xmlns/sca/1.0'>"
- + "<tus:implementation.java class='mockedup'/>"
- + "</tus:component>";
-
- TestComponentLoader compLoader = new TestComponentLoader(EasyMock.createMock(LoaderRegistry.class));
- ComponentDefinition<?> compDef = compLoader.load(null, null, getReader(compDefXml), null);
-
- //verify if component inherits referece definitions from componentType
- Assert.assertNotNull(compDef.getReferences().get("CTRefDef1"));
- Assert.assertEquals(Multiplicity.ZERO_N.name(), compDef.getReferences().get("CTRefDef1").getMultiplicity().name());
- Assert.assertEquals("TestComponent1/testService1",
- compDef.getReferences().get("CTRefDef1").getTargets().get(1).toString());
- Assert.assertTrue(
- TestIfc1.class.isAssignableFrom(compDef.getReferences().get("CTRefDef1").getServiceContract().getInterfaceClass()));
- Assert.assertTrue(compDef.getReferences().get("CTRefDef1").getBindings().get(0) instanceof LocalBindingDefinition);
- }
-
- @Test
- public void testRefDefValidOverriding() throws LoaderException,
- XMLStreamException,
- URISyntaxException {
- String overridenRef =
- "<tus:component name='TestComponent' xmlns:tus='http://www.osoa.org/xmlns/sca/1.0'>"
- + "<tus:implementation.java class='mockedup'/>"
- + "<tus:reference name='CTRefDef1' target='OverridingTarget' multiplicity='0..1'>"
- + "</tus:reference>"
- + "</tus:component>";
-
- TestComponentLoader compLoader = new TestComponentLoader(EasyMock.createMock(LoaderRegistry.class));
-
- ComponentDefinition<?> compDef = compLoader.load(null, null, getReader(overridenRef), null);
-
- //verify if component inherits referece definitions from componentType
- Assert.assertNotNull(compDef.getReferences().get("CTRefDef1"));
- Assert.assertEquals(Multiplicity.ZERO_ONE.name(),
- compDef.getReferences().get("CTRefDef1").getMultiplicity().name());
- Assert.assertEquals("OverridingTarget",
- compDef.getReferences().get("CTRefDef1").getTargets().get(0).toString());
- Assert.assertTrue(
- TestIfc1.class.isAssignableFrom(compDef.getReferences().get("CTRefDef1").getServiceContract().getInterfaceClass()));
- Assert.assertTrue(compDef.getReferences().get("CTRefDef1").getBindings().get(0) instanceof LocalBindingDefinition);
- }
-
- @Test
- public void testRefDefInValidOverriding() throws LoaderException,
- XMLStreamException,
- URISyntaxException {
- String overridenRef =
- "<tus:component name='TestComponent' xmlns:tus='http://www.osoa.org/xmlns/sca/1.0'>"
- + "<tus:implementation.java class='mockedup'/>"
- + "<tus:reference name='CTRefDef1' target='OverridingTarget' multiplicity='1..1'/>"
- + "</tus:component>";
-
- TestComponentLoader compLoader = new TestComponentLoader(EasyMock.createMock(LoaderRegistry.class));
-
- try {
- ComponentDefinition<?> compDef = compLoader.load(null, null, getReader(overridenRef), null);
- Assert.fail();
- } catch ( ReferenceMultiplicityOverridingException e) {
- //expected behaviour
- }
- }
-
-
- public static interface TestIfc1 {
- public String testMethod1();
- }
-
- public class TestComponentLoader extends ComponentLoader {
-
- public TestComponentLoader(LoaderRegistry registry) {
- super(registry, null);
- }
-
- @Override
- protected Implementation<?> loadImplementation(CompositeComponent parent,
- XMLStreamReader reader,
- DeploymentContext deploymentContext) throws XMLStreamException,
- LoaderException {
- ComponentTypeReferenceDefinition ctRefDef = new ComponentTypeReferenceDefinition();
-
- ctRefDef.setName("CTRefDef1");
- try {
- ctRefDef.addTarget(new URI("TestComponent1"));
- ctRefDef.addTarget(new URI("TestComponent1/testService1"));
-
- ctRefDef.setMultiplicity(Multiplicity.ZERO_N);
-
- JavaServiceContract svcContract = new JavaServiceContract(TestIfc1.class);
- ctRefDef.setServiceContract(svcContract);
-
- BindingDefinition binding1 = new LocalBindingDefinition(new URI("localBindingUri"));
- ctRefDef.addBinding(binding1);
- } catch (URISyntaxException e) {
- //do nothing... unlikely to happen
- }
-
- PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>> ct =
- new PojoComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>>();
- ct.add(ctRefDef);
-
- JavaImplementation javaImpl = new JavaImplementation();
- javaImpl.setComponentType(ct);
- reader.next();
- reader.next();
- return javaImpl;
- }
- }
-}
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentTypeElementLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentTypeElementLoaderTestCase.java deleted file mode 100644 index 08272d98bc..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ComponentTypeElementLoaderTestCase.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.loader; - -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamReader; -import javax.xml.namespace.QName; - -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.loader.LoaderRegistry; -import org.apache.tuscany.spi.model.ComponentType; -import org.apache.tuscany.spi.model.ComponentTypeReferenceDefinition; -import org.apache.tuscany.spi.model.ModelObject; -import org.apache.tuscany.spi.model.Property; -import org.apache.tuscany.spi.model.AbstractReferenceDefinition; -import org.apache.tuscany.spi.model.ServiceDefinition; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class ComponentTypeElementLoaderTestCase extends TestCase { - - public void testSpecializedComponentTypePassedIn() throws Exception { - ComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>> type = - new ComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>>(); - ComponentTypeElementLoader loader = new ComponentTypeElementLoader(null); - XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class); - EasyMock.expect(reader.getName()).andReturn(ComponentTypeElementLoader.COMPONENT_TYPE); - EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT); - EasyMock.replay(reader); - // verify that the exact component type instance is returned. Some StAXElementLoader implementations may chose - // to copy the original instance but ComponentTypeElementLoader does not since it has no knowledge of the - // specialized instance - ModelObject object = loader.load(null, type, reader, null); - assertEquals(object, type); - } - - public void testComponentTypePassedAsContext() throws Exception { - ComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>> type = - new ComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>>(); - LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class); - EasyMock.expect(registry.load((CompositeComponent) EasyMock.isNull(), - EasyMock.isA(ComponentType.class), - EasyMock.isA(XMLStreamReader.class), - (DeploymentContext) EasyMock.isNull())).andReturn(type); - EasyMock.replay(registry); - ComponentTypeElementLoader loader = new ComponentTypeElementLoader(registry); - XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class); - EasyMock.expect(reader.getName()).andReturn(ComponentTypeElementLoader.COMPONENT_TYPE); - EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.START_ELEMENT); - EasyMock.expect(reader.getName()).andReturn(new QName("foo", "foo")); - EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT); - EasyMock.replay(reader); - - loader.load(null, type, reader, null); - EasyMock.verify(registry); - } - - public void testNonSpecializedComponentTypePassedIn() throws Exception { - ComponentTypeElementLoader loader = new ComponentTypeElementLoader(null); - XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class); - EasyMock.expect(reader.getName()).andReturn(ComponentTypeElementLoader.COMPONENT_TYPE); - EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT); - EasyMock.replay(reader); - ModelObject object = loader.load(null, null, reader, null); - assertEquals(ComponentType.class, object.getClass()); - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/DependencyLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/DependencyLoaderTestCase.java deleted file mode 100644 index 753289f4a6..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/DependencyLoaderTestCase.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.loader; - -import javax.xml.namespace.QName; -import javax.xml.stream.Location; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.spi.loader.LoaderRegistry; -import org.apache.tuscany.spi.loader.UnrecognizedElementException; - -import junit.framework.TestCase; -import org.easymock.EasyMock; -import org.apache.tuscany.core.implementation.composite.Dependency; - -/** - * @version $Rev$ $Date$ - */ -public class DependencyLoaderTestCase extends TestCase { - private static final String NS = "http://tuscany.apache.org/xmlns/1.0-SNAPSHOT"; - private static final QName DEPENDENCY = new QName(NS, "dependency"); - private static final QName GROUP = new QName(NS, "group"); - private static final QName NAME = new QName(NS, "name"); - private static final QName VERSION = new QName(NS, "version"); - private static final QName CLASSIFIER = new QName(NS, "classifier"); - private static final QName TYPE = new QName(NS, "type"); - - public void testLoad() throws Exception { - LoaderRegistry registry = EasyMock.createNiceMock(LoaderRegistry.class); - EasyMock.replay(registry); - XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class); - EasyMock.expect(reader.nextTag()).andReturn(XMLStreamConstants.START_ELEMENT); - EasyMock.expect(reader.getName()).andReturn(GROUP); - EasyMock.expect(reader.getElementText()).andReturn("group"); - EasyMock.expect(reader.nextTag()).andReturn(XMLStreamConstants.START_ELEMENT); - EasyMock.expect(reader.getName()).andReturn(NAME); - EasyMock.expect(reader.getElementText()).andReturn("name"); - EasyMock.expect(reader.nextTag()).andReturn(XMLStreamConstants.START_ELEMENT); - EasyMock.expect(reader.getName()).andReturn(VERSION); - EasyMock.expect(reader.getElementText()).andReturn("1"); - EasyMock.expect(reader.nextTag()).andReturn(XMLStreamConstants.START_ELEMENT); - EasyMock.expect(reader.getName()).andReturn(CLASSIFIER); - EasyMock.expect(reader.getElementText()).andReturn("classifier"); - EasyMock.expect(reader.nextTag()).andReturn(XMLStreamConstants.START_ELEMENT); - EasyMock.expect(reader.getName()).andReturn(TYPE); - EasyMock.expect(reader.getElementText()).andReturn("type"); - EasyMock.expect(reader.nextTag()).andReturn(XMLStreamConstants.END_ELEMENT); - EasyMock.replay(reader); - DependencyLoader loader = new DependencyLoader(registry); - Dependency dependency = loader.load(null, null, reader, null); - assertEquals("group", dependency.getArtifact().getGroup()); - assertEquals("name", dependency.getArtifact().getName()); - assertEquals("1", dependency.getArtifact().getVersion()); - assertEquals("classifier", dependency.getArtifact().getClassifier()); - assertEquals("type", dependency.getArtifact().getType()); - } - - public void testLoaderRegister() { - LoaderRegistry registry = EasyMock.createMock(LoaderRegistry.class); - registry.registerLoader(EasyMock.eq(DEPENDENCY), EasyMock.isA(DependencyLoader.class)); - EasyMock.replay(registry); - DependencyLoader loader = new DependencyLoader(registry); - loader.start(); - EasyMock.verify(registry); - } - - public void testUnrecognizedElement() throws Exception { - LoaderRegistry registry = EasyMock.createNiceMock(LoaderRegistry.class); - EasyMock.replay(registry); - XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class); - EasyMock.expect(reader.nextTag()).andReturn(XMLStreamConstants.START_ELEMENT); - EasyMock.expect(reader.getName()).andReturn(new QName("foo", "bar")); - EasyMock.expect(reader.getElementText()).andReturn("foo"); - EasyMock.expect(reader.getLocation()).andReturn(new MockLocation()); - EasyMock.replay(reader); - DependencyLoader loader = new DependencyLoader(registry); - try { - loader.load(null, null, reader, null); - fail(); - } catch (UnrecognizedElementException e) { - // expected - } - } - - private class MockLocation implements Location { - - public int getLineNumber() { - return 0; - } - - public int getColumnNumber() { - return 0; - } - - public int getCharacterOffset() { - return 0; - } - - public String getPublicId() { - return null; - } - - public String getSystemId() { - return null; - } - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/IncludeLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/IncludeLoaderTestCase.java deleted file mode 100644 index ed2fde80d3..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/IncludeLoaderTestCase.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.loader; - -import java.net.URL; -import javax.xml.namespace.QName; -import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import org.osoa.sca.Constants; - -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.loader.LoaderException; -import org.apache.tuscany.spi.loader.LoaderRegistry; -import org.apache.tuscany.spi.loader.MissingIncludeException; -import org.apache.tuscany.spi.model.CompositeComponentType; -import org.apache.tuscany.spi.model.Include; -import org.apache.tuscany.spi.model.ModelObject; - -import junit.framework.TestCase; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.eq; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.isA; -import static org.easymock.EasyMock.isNull; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; - -/** - * @version $Rev$ $Date$ - */ -public class IncludeLoaderTestCase extends TestCase { - private static final QName INCLUDE = new QName(Constants.SCA_NS, "include"); - - private LoaderRegistry registry; - private IncludeLoader loader; - private XMLStreamReader reader; - private DeploymentContext context; - private URL base; - private URL includeURL; - private ClassLoader cl; - - public void testNoLocation() throws LoaderException, XMLStreamException { - String name = "foo"; - expect(reader.getName()).andReturn(INCLUDE); - expect(reader.getAttributeValue(null, "name")).andReturn(name); - expect(reader.getAttributeValue(null, "scdlLocation")).andReturn(null); - expect(reader.getAttributeValue(null, "scdlResource")).andReturn(null); - expect(reader.next()).andReturn(END_ELEMENT); - - expect(context.getClassLoader()).andReturn(cl); - replay(registry, reader, context); - - try { - loader.load(null, null, reader, context); - fail(); - } catch (MissingIncludeException e) { - // OK expected - } - verify(registry, reader, context); - } - - public void testWithAbsoluteScdlLocation() throws LoaderException, XMLStreamException { - String name = "foo"; - expect(reader.getName()).andReturn(INCLUDE); - expect(reader.getAttributeValue(null, "name")).andReturn(name); - expect(reader.getAttributeValue(null, "scdlLocation")).andReturn("http://example.com/include.scdl"); - expect(reader.getAttributeValue(null, "scdlResource")).andReturn(null); - expect(reader.next()).andReturn(END_ELEMENT); - - expect(context.getScdlLocation()).andReturn(base); - expect(context.getClassLoader()).andReturn(cl); - - expect(registry.load((CompositeComponent) isNull(), - (ModelObject) isNull(), - eq(includeURL), - eq(CompositeComponentType.class), - isA(DeploymentContext.class))) - .andReturn(null); - replay(registry, reader, context); - - Include include = loader.load(null, null, reader, context); - assertEquals(name, include.getName()); - assertEquals(includeURL, include.getScdlLocation()); - verify(registry, reader, context); - } - - public void testWithRelativeScdlLocation() throws LoaderException, XMLStreamException { - String name = "foo"; - expect(reader.getName()).andReturn(INCLUDE); - expect(reader.getAttributeValue(null, "name")).andReturn(name); - expect(reader.getAttributeValue(null, "scdlLocation")).andReturn("include.scdl"); - expect(reader.getAttributeValue(null, "scdlResource")).andReturn(null); - expect(reader.next()).andReturn(END_ELEMENT); - - expect(context.getScdlLocation()).andReturn(base); - expect(context.getClassLoader()).andReturn(cl); - - expect(registry.load((CompositeComponent) isNull(), - (ModelObject) isNull(), - eq(includeURL), - eq(CompositeComponentType.class), - isA(DeploymentContext.class))) - .andReturn(null); - replay(registry, reader, context); - - Include include = loader.load(null, null, reader, context); - assertEquals(name, include.getName()); - assertEquals(includeURL, include.getScdlLocation()); - verify(registry, reader, context); - } - - public void testWithScdlResource() throws LoaderException, XMLStreamException { - String name = "foo"; - String resource = "org/apache/tuscany/core/loader/test-include.scdl"; - includeURL = cl.getResource(resource); - assertNotNull(includeURL); - - expect(reader.getName()).andReturn(INCLUDE); - expect(reader.getAttributeValue(null, "name")).andReturn(name); - expect(reader.getAttributeValue(null, "scdlLocation")).andReturn(null); - expect(reader.getAttributeValue(null, "scdlResource")).andReturn(resource); - expect(reader.next()).andReturn(END_ELEMENT); - - expect(context.getClassLoader()).andReturn(cl); - - expect(registry.load((CompositeComponent) isNull(), - (ModelObject) isNull(), - eq(includeURL), - eq(CompositeComponentType.class), - isA(DeploymentContext.class))) - .andReturn(null); - replay(registry, reader, context); - - Include include = loader.load(null, null, reader, context); - assertEquals(name, include.getName()); - assertEquals(includeURL, include.getScdlLocation()); - verify(registry, reader, context); - } - - protected void setUp() throws Exception { - super.setUp(); - registry = createMock(LoaderRegistry.class); - reader = createMock(XMLStreamReader.class); - context = createMock(DeploymentContext.class); - cl = getClass().getClassLoader(); - base = new URL("http://example.com/test.scdl"); - includeURL = new URL("http://example.com/include.scdl"); - loader = new IncludeLoader(registry); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/JNDIPropertyFactoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/JNDIPropertyFactoryTestCase.java deleted file mode 100644 index 1c65ed42cc..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/JNDIPropertyFactoryTestCase.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.apache.tuscany.core.loader; - -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.List; - -import javax.naming.Context; -import javax.naming.NamingException; -import javax.naming.spi.InitialContextFactory; - -import junit.framework.TestCase; - -import org.apache.tuscany.core.injection.JNDIObjectFactory; -import org.apache.tuscany.spi.model.PropertyValue; -import org.easymock.EasyMock; -import org.w3c.dom.Element; - -/** - * @version $Rev$ $Date$ - */ -public class JNDIPropertyFactoryTestCase extends TestCase { - - public void testCreate() throws Exception { - String old = System.getProperty(Context.INITIAL_CONTEXT_FACTORY); - try { - System.setProperty(Context.INITIAL_CONTEXT_FACTORY, MockInitialContextFactory.class.getName()); - JNDIPropertyFactory factory = new JNDIPropertyFactory(); - Element element = EasyMock.createMock(Element.class); - EasyMock.expect(element.getTextContent()).andReturn("foo"); - EasyMock.replay(element); - //Document doc = EasyMock.createMock(Document.class); - //EasyMock.expect(doc.getDocumentElement()).andReturn(element); - //EasyMock.replay(doc); - PropertyValue<?> value = new MockPropertyValue<Type>(); - List<Element> docList = new ArrayList<Element>(); - docList.add(element); - value.setValue(docList); - JNDIObjectFactory<?> jndiFactory = (JNDIObjectFactory<?>) factory.createObjectFactory(null, value); - assertEquals("bar", jndiFactory.getInstance()); - } finally { - System.clearProperty(Context.INITIAL_CONTEXT_FACTORY); - if (old != null) { - System.setProperty(Context.INITIAL_CONTEXT_FACTORY, old); - } - } - - } - - private class MockPropertyValue<T> extends PropertyValue<T> { - - } - - public static class MockInitialContextFactory implements InitialContextFactory { - public MockInitialContextFactory() { - } - - public Context getInitialContext(Hashtable<?, ?> environment) throws NamingException { - Context context = EasyMock.createMock(Context.class); - EasyMock.expect(context.lookup("foo")).andReturn("bar"); - EasyMock.replay(context); - return context; - } - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/LoaderExceptionFormatterTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/LoaderExceptionFormatterTestCase.java deleted file mode 100644 index 49c53935dc..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/LoaderExceptionFormatterTestCase.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.loader; - -import java.io.PrintWriter; -import java.io.StringWriter; - -import org.apache.tuscany.spi.loader.LoaderException; - -import junit.framework.TestCase; -import org.easymock.EasyMock; -import org.apache.tuscany.host.monitor.FormatterRegistry; - -/** - * @version $Rev$ $Date$ - */ -public class LoaderExceptionFormatterTestCase extends TestCase { - - public void testLog() { - FormatterRegistry registry = EasyMock.createNiceMock(FormatterRegistry.class); - LoaderExceptionFormatter formatter = new LoaderExceptionFormatter(registry); - LoaderException e = new LoaderException("test"); - StringWriter writer = new StringWriter(); - PrintWriter pw = new PrintWriter(writer); - formatter.write(pw, e); - pw.close(); - assertTrue(!"message".equals(writer.toString())); - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/MultivaluePropertyLoadingTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/MultivaluePropertyLoadingTestCase.java deleted file mode 100644 index a39ca52fd4..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/MultivaluePropertyLoadingTestCase.java +++ /dev/null @@ -1,204 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tuscany.core.loader;
-
-import java.io.StringReader;
-import java.io.StringWriter;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
-import junit.framework.TestCase;
-
-import org.apache.tuscany.core.databinding.javabeans.JavaBean2DOMNodeTransformer;
-import org.apache.tuscany.spi.loader.LoaderRegistry;
-import org.apache.tuscany.spi.model.Property;
-import org.easymock.EasyMock;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Text;
-
-/**
- * @version $Rev: 502055 $ $Date: 2007-02-01 05:37:32 +0530 (Thu, 01 Feb 2007) $
- */
-public class MultivaluePropertyLoadingTestCase extends TestCase {
- private PropertyLoader propertyLoader;
- private XMLInputFactory xmlFactory;
-
-
- public void testPropertyLoading_SimpleType() throws Exception {
- String xml = "<tus:property xmlns:foo='http://foo.com' "
- + "xmlns:tus='http://www.osoa.org/xmlns/sca/1.0' "
- + "xmlns:xs='http://www.w3.org/2001/XMLSchema' "
- + " name='TestProperty' type='xs:string' many='true'>"
- + "<value>"
- + "TestPropertyValue1"
- + "</value>"
- + "<value>"
- + "TestPropertyValue2"
- + "</value>"
- + "</tus:property>";
-
- XMLStreamReader reader = getReader(xml);
- Property<?> aProperty = propertyLoader.load(null, null, reader, null);
-
- assertEquals("TestProperty", aProperty.getName());
- assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "string", "xs"), aProperty.getXmlType());
- assertEquals(false, aProperty.isMustSupply());
- assertEquals(true, aProperty.isMany());
-
- Element secondValue = aProperty.getDefaultValues().get(1);
-
- NodeList childNodes = secondValue.getChildNodes();
- assertEquals(1, childNodes.getLength());
-
- Text t = (Text) childNodes.item(0);
- assertEquals("TestPropertyValue2", t.getTextContent());
- }
-
- public void testPropertyLoading_Type() throws Exception {
- String xml = "<tus:property xmlns:foo='http://foo.com' "
- + "xmlns:tus='http://www.osoa.org/xmlns/sca/1.0' "
- + "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' "
- + " name='complexFoo' many='true' type='foo:MyComplexType'>"
- + "<MyComplexPropertyValue1 xsi:type='foo:MyComplexType' attr='bar'>"
- + "<foo:a>AValue</foo:a>"
- + "<foo:b>InterestingURI</foo:b>"
- + "</MyComplexPropertyValue1>"
- + "<MyComplexPropertyValue2 xsi:type='foo:MyComplexType' attr='zing'>"
- + "<foo:a>BValue</foo:a>"
- + "<foo:b>BoringURI</foo:b>"
- + "</MyComplexPropertyValue2>"
- + "</tus:property>";
-
-
-
- XMLStreamReader reader = getReader(xml);
- Property<?> aProperty = propertyLoader.load(null, null, reader, null);
-
- assertEquals("complexFoo", aProperty.getName());
- assertEquals(new QName("http://foo.com", "MyComplexType", "foo"), aProperty.getXmlType());
- assertEquals(false, aProperty.isMustSupply());
- assertEquals(true, aProperty.isMany());
-
- Element secondValue = aProperty.getDefaultValues().get(1);
-
- NodeList childNodes = secondValue.getChildNodes();
- assertEquals(2, childNodes.getLength());
-
- Element e = (Element) childNodes.item(0);
- assertEquals("http://foo.com", e.getNamespaceURI());
- assertEquals("a", e.getLocalName());
- assertEquals("BValue", e.getTextContent());
- e = (Element) childNodes.item(1);
- assertEquals("http://foo.com", e.getNamespaceURI());
- assertEquals("b", e.getLocalName());
- assertEquals("BoringURI", e.getTextContent());
- }
-
- public void testPropertyLoading_Element() throws Exception {
- String xml =
- "<tus:property xmlns:foo='http://foo.com' "
- + "xmlns:tus='http://www.osoa.org/xmlns/sca/1.0'"
- + " name='TestProperty' many='true' element='foo:TestElement'>\n"
- + "<foo:TestElement>"
- + "<foo:a>aValue1</foo:a>"
- + "<foo:b>InterestingURI1</foo:b>"
- + "</foo:TestElement>"
- + "<foo:TestElement>"
- + "<foo:a>aValue2</foo:a>"
- + "<foo:b>InterestingURI2</foo:b>"
- + "</foo:TestElement>"
- + "</tus:property>";
- XMLStreamReader reader = getReader(xml);
- Property<?> aProperty = propertyLoader.load(null, null, reader, null);
-
- Element secondElement = aProperty.getDefaultValues().get(1);
-
- assertEquals(2, aProperty.getDefaultValues().size());
- assertEquals("TestProperty", aProperty.getName());
- assertEquals(new QName("http://foo.com", "TestElement", "foo"), aProperty.getXmlElement());
- assertEquals(false, aProperty.isMustSupply());
- assertEquals(true, aProperty.isMany());
-
- NodeList childNodes = secondElement.getChildNodes();
- assertEquals(2, childNodes.getLength());
-
- Element e = (Element) childNodes.item(0);
- assertEquals("http://foo.com", e.getNamespaceURI());
- assertEquals("a", e.getLocalName());
- assertEquals("aValue2", e.getTextContent());
- e = (Element) childNodes.item(1);
- assertEquals("http://foo.com", e.getNamespaceURI());
- assertEquals("b", e.getLocalName());
- assertEquals("InterestingURI2", e.getTextContent());
- }
-
- public void testManyValueException() throws Exception {
- String xml =
- "<tus:property xmlns:foo='http://foo.com' "
- + "xmlns:tus='http://www.osoa.org/xmlns/sca/1.0'"
- + " name='TestProperty' element='foo:TestElement'>\n"
- + "<foo:TestElement>"
- + "<foo:a>aValue1</foo:a>"
- + "<foo:b>InterestingURI1</foo:b>"
- + "</foo:TestElement>"
- + "<foo:TestElement>"
- + "<foo:a>aValue2</foo:a>"
- + "<foo:b>InterestingURI2</foo:b>"
- + "</foo:TestElement>"
- + "</tus:property>";
-
- XMLStreamReader reader = getReader(xml);
-
- try {
- propertyLoader.load(null, null, reader, null);
- } catch (Exception e) {
- assertTrue(e instanceof ManyPropertyValueLoaderException);
- }
- }
-
- public XMLStreamReader getReader(String xml) throws XMLStreamException {
- XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(xml));
- reader.next();
- return reader;
- }
-
- protected void setUp() throws Exception {
- super.setUp();
- xmlFactory = XMLInputFactory.newInstance();
- propertyLoader = new PropertyLoader(EasyMock.createMock(LoaderRegistry.class));
- }
-
- private void printNode(Node node) throws Exception {
- javax.xml.transform.Transformer transformer =
- TransformerFactory.newInstance().newTransformer();
- JavaBean2DOMNodeTransformer java2DomTransformer = new JavaBean2DOMNodeTransformer();
- StringWriter sw = new StringWriter();
- transformer.transform(new DOMSource(node), new StreamResult(sw));
-
- System.out.println(sw.toString());
- }
-}
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PolicySetLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PolicySetLoaderTestCase.java deleted file mode 100644 index 8e18c2ff0f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PolicySetLoaderTestCase.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.loader; - -import java.util.Collection; -import java.util.Iterator; -import javax.xml.namespace.QName; -import javax.xml.stream.XMLInputFactory; -import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; -import javax.xml.stream.XMLStreamReader; - -import static org.osoa.sca.Constants.SCA_NS; - -import org.apache.tuscany.spi.model.IntentMap; -import org.apache.tuscany.spi.model.PolicySet; -import org.apache.tuscany.spi.model.Qualifier; - -import junit.framework.TestCase; - -public class PolicySetLoaderTestCase extends TestCase { - private static final QName POLICYSET = new QName(SCA_NS, "policySet"); - - public void testLoader() throws Exception { - PolicySetLoader loader = new PolicySetLoader(null); - XMLInputFactory factory = XMLInputFactory.newInstance(); - XMLStreamReader reader = factory.createXMLStreamReader(this.getClass().getResourceAsStream("TestPolicy.scdl")); - while (true) { - int state = reader.next(); - if (START_ELEMENT == state && reader.getName().equals(POLICYSET)) { - break; - } - } - PolicySet policySet = loader.load(null, null, reader, null); - assertNotNull(policySet); - assertEquals(2, policySet.getAppliedArtifacts().size()); - assertTrue(policySet.getAppliedArtifacts().contains(new QName(SCA_NS, "binding.ws"))); - assertTrue(policySet.getAppliedArtifacts().contains(new QName(SCA_NS, "binding.jms"))); - Collection<IntentMap> intentMaps = policySet.getIntentMaps(); - assertEquals(1, intentMaps.size()); - IntentMap intentMap = intentMaps.iterator().next(); - assertEquals("transport", intentMap.getDefaultProvideIntent()); - assertTrue(intentMap.getProvideIntents().contains("sec.confidentiality")); - Collection<Qualifier> qualifiers = intentMap.getQualifiers(); - assertEquals(2, qualifiers.size()); - Iterator qit = qualifiers.iterator(); - Qualifier qualifier1 = (Qualifier) qit.next(); - assertEquals(2, qualifier1.getWsPolicyAttachments().size()); - assertEquals("transport", qualifier1.getName()); - Qualifier qualifier2 = (Qualifier) qit.next(); - assertEquals("message", qualifier2.getName()); - IntentMap messageMap = qualifier2.getIntentMap(); - assertEquals(2, messageMap.getQualifiers().size()); - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PropertyLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PropertyLoaderTestCase.java deleted file mode 100644 index c357d9bc0a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PropertyLoaderTestCase.java +++ /dev/null @@ -1,180 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tuscany.core.loader;
-
-import java.io.StringReader;
-import java.io.StringWriter;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
-import junit.framework.TestCase;
-
-import org.apache.tuscany.core.databinding.javabeans.JavaBean2DOMNodeTransformer;
-import org.apache.tuscany.spi.loader.LoaderRegistry;
-import org.apache.tuscany.spi.model.Property;
-import org.easymock.EasyMock;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Text;
-
-/**
- * @version $Rev: 502055 $ $Date: 2007-02-01 05:37:32 +0530 (Thu, 01 Feb 2007) $
- */
-public class PropertyLoaderTestCase extends TestCase {
- private PropertyLoader propertyLoader;
- private XMLInputFactory xmlFactory;
-
-
- public void testPropertyLoading_SimpleType() throws Exception {
- String xml = "<tus:property xmlns:foo='http://foo.com' "
- + "xmlns:tus='http://www.osoa.org/xmlns/sca/1.0' "
- + "xmlns:xs='http://www.w3.org/2001/XMLSchema' "
- + " name='TestProperty' type='xs:string'>"
- + "TestPropertyValue"
- + "</tus:property>";
-
- XMLStreamReader reader = getReader(xml);
- Property<?> aProperty = propertyLoader.load(null, null, reader, null);
-
- assertEquals("TestProperty", aProperty.getName());
- assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "string", "xs"), aProperty.getXmlType());
- assertEquals(false, aProperty.isMustSupply());
- assertEquals(false, aProperty.isMany());
-
- Element root = aProperty.getDefaultValues().get(0);
-
- NodeList childNodes = root.getChildNodes();
- assertEquals(1, childNodes.getLength());
-
- Text t = (Text) childNodes.item(0);
- assertEquals("TestPropertyValue", t.getTextContent());
- }
-
-
- public void testPropertyLoading_Type() throws Exception {
- String xml = "<tus:property xmlns:foo='http://foo.com' "
- + "xmlns:tus='http://www.osoa.org/xmlns/sca/1.0' "
- + "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' "
- + " name='complexFoo' type='foo:MyComplexType'>"
- + "<MyComplexPropertyValue1 xsi:type='foo:MyComplexType' attr='bar'>"
- + "<foo:a>AValue</foo:a>"
- + "<foo:b>InterestingURI</foo:b>"
- + "</MyComplexPropertyValue1>"
- + "</tus:property>";
-
- XMLStreamReader reader = getReader(xml);
- Property<?> aProperty = propertyLoader.load(null, null, reader, null);
- assertEquals("complexFoo", aProperty.getName());
- assertEquals(new QName("http://foo.com", "MyComplexType", "foo"), aProperty.getXmlType());
- assertEquals(false, aProperty.isMustSupply());
- assertEquals(false, aProperty.isMany());
-
- Element root = aProperty.getDefaultValues().get(0);
-
- NodeList childNodes = root.getChildNodes();
- assertEquals(2, childNodes.getLength());
-
- Element e = (Element) childNodes.item(0);
- assertEquals("http://foo.com", e.getNamespaceURI());
- assertEquals("a", e.getLocalName());
- assertEquals("AValue", e.getTextContent());
- e = (Element) childNodes.item(1);
- assertEquals("http://foo.com", e.getNamespaceURI());
- assertEquals("b", e.getLocalName());
- assertEquals("InterestingURI", e.getTextContent());
- }
-
- public void testPropertyLoading_Element() throws Exception {
- String xml = "<tus:property xmlns:foo='http://foo.com' "
- + "xmlns:tus='http://www.osoa.org/xmlns/sca/1.0'"
- + " name='TestProperty' element='foo:TestElement'>\n"
- + "<foo:TestElement>"
- + "<foo:a>aValue</foo:a>"
- + "<foo:b>InterestingURI</foo:b>"
- + "</foo:TestElement>"
- + "</tus:property>";
- XMLStreamReader reader = getReader(xml);
- Property<?> aProperty = propertyLoader.load(null, null, reader, null);
-
- Element root = aProperty.getDefaultValues().get(0);
-
- assertEquals("TestProperty", aProperty.getName());
- assertEquals(new QName("http://foo.com", "TestElement", "foo"), aProperty.getXmlElement());
- assertEquals(false, aProperty.isMustSupply());
- assertEquals(false, aProperty.isMany());
-
- NodeList childNodes = root.getChildNodes();
- assertEquals(2, childNodes.getLength());
-
- Element e = (Element) childNodes.item(0);
- assertEquals("http://foo.com", e.getNamespaceURI());
- assertEquals("a", e.getLocalName());
- assertEquals("aValue", e.getTextContent());
- e = (Element) childNodes.item(1);
- assertEquals("http://foo.com", e.getNamespaceURI());
- assertEquals("b", e.getLocalName());
- assertEquals("InterestingURI", e.getTextContent());
- }
-
- public void testPropertyLoadingNoDefault() throws Exception {
- String xml = "<tus:property xmlns:foo='http://foo.com' "
- + "xmlns:tus='http://www.osoa.org/xmlns/sca/1.0'"
- + " name='TestProperty' type='foo:TestType' mustSupply='true'>"
- + "<foo:a>aValue</foo:a>"
- + "<foo:b>InterestingURI</foo:b>"
- + "</tus:property>";
-
- XMLStreamReader reader = getReader(xml);
-
- try {
- propertyLoader.load(null, null, reader, null);
- } catch (Exception e) {
- assertTrue(e instanceof DefaultPropertyValueLoaderException);
- }
- }
-
- public XMLStreamReader getReader(String xml) throws XMLStreamException {
- XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(xml));
- reader.next();
- return reader;
- }
-
- protected void setUp() throws Exception {
- super.setUp();
- xmlFactory = XMLInputFactory.newInstance();
- propertyLoader = new PropertyLoader(EasyMock.createMock(LoaderRegistry.class));
- }
-
- private void printNode(Node node) throws Exception {
- javax.xml.transform.Transformer transformer =
- TransformerFactory.newInstance().newTransformer();
- JavaBean2DOMNodeTransformer java2DomTransformer = new JavaBean2DOMNodeTransformer();
- StringWriter sw = new StringWriter();
- transformer.transform(new DOMSource(node), new StreamResult(sw));
-
- System.out.println(sw.toString());
- }
-}
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PropertyParsingTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PropertyParsingTestCase.java deleted file mode 100644 index a82e5f6b72..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/PropertyParsingTestCase.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.loader; - -import java.io.StringReader; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamException; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.DocumentBuilder; - -import junit.framework.TestCase; - -import org.apache.tuscany.spi.util.stax.StaxUtil; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -/** - * @version $Rev$ $Date$ - */ -public class PropertyParsingTestCase extends TestCase { - private XMLInputFactory xmlFactory; - private DocumentBuilder docBuilder; - private Element root; - - public void testComplexProperty() throws XMLStreamException { - String xml = "<property xmlns:foo='http://foo.com'>" - + "<foo:a>aValue</foo:a>" - + "<foo:b>InterestingURI</foo:b>" - + "</property>"; - - XMLStreamReader reader = getReader(xml); - StaxUtil.loadPropertyValue(reader, root, root.getOwnerDocument()); - NodeList childNodes = root.getChildNodes(); - assertEquals(2, childNodes.getLength()); - - Element e = (Element) childNodes.item(0); - assertEquals("http://foo.com", e.getNamespaceURI()); - assertEquals("a", e.getLocalName()); - assertEquals("aValue", e.getTextContent()); - e = (Element) childNodes.item(1); - assertEquals("http://foo.com", e.getNamespaceURI()); - assertEquals("b", e.getLocalName()); - assertEquals("InterestingURI", e.getTextContent()); - } - - public XMLStreamReader getReader(String xml) throws XMLStreamException { - XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(xml)); - reader.next(); - return reader; - } - - protected void setUp() throws Exception { - super.setUp(); - xmlFactory = XMLInputFactory.newInstance(); - DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); - docBuilder = docFactory.newDocumentBuilder(); - Document doc = docBuilder.newDocument(); - root = doc.createElement("value"); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ReferenceLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ReferenceLoaderTestCase.java deleted file mode 100644 index 6254835f13..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ReferenceLoaderTestCase.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.loader; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import junit.framework.TestCase; - -import org.apache.tuscany.core.deployer.RootDeploymentContext; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.loader.LoaderException; -import org.apache.tuscany.spi.loader.LoaderRegistry; -import org.apache.tuscany.spi.model.BindingDefinition; -import org.apache.tuscany.spi.model.ComponentType; -import org.apache.tuscany.spi.model.ComponentTypeReferenceDefinition; -import org.apache.tuscany.spi.model.Property; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.model.ServiceDefinition; -import org.easymock.EasyMock; -import org.osoa.sca.Constants; - -/** - * Verifies loading of a reference definition from an XML-based assembly - * - * @version $Rev$ $Date$ - */ -public class ReferenceLoaderTestCase extends TestCase { - private static final QName REFERENCE = new QName(Constants.SCA_NS, "reference"); - - private ReferenceLoader loader; - private DeploymentContext deploymentContext; - private XMLStreamReader mockReader; - private LoaderRegistry mockRegistry; - - public void testWithNoInterface() throws LoaderException, XMLStreamException { - String name = "referenceDefinition"; - EasyMock.expect(mockReader.getName()).andReturn(REFERENCE).anyTimes(); - EasyMock.expect(mockReader.getAttributeValue(null, "name")).andReturn(name); - EasyMock.expect(mockReader.getAttributeValue(null, "multiplicity")).andReturn("0..1"); - EasyMock.expect(mockReader.getAttributeValue(null, "wiredByImpl")).andReturn("false"); - EasyMock.expect(mockReader.getAttributeValue(null, "target")).andReturn(null); - EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT); - EasyMock.expect(mockReader.getName()).andReturn(REFERENCE).anyTimes(); - EasyMock.replay(mockReader); - ComponentTypeReferenceDefinition referenceDefinition = - loader.load(null, new ComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>>(), mockReader, null); - assertNotNull(referenceDefinition); - assertEquals(name, referenceDefinition.getName()); - } - - public void testComponentTypeService() throws LoaderException, XMLStreamException { - String name = "reference"; - EasyMock.expect(mockReader.getName()).andReturn(REFERENCE).anyTimes(); - EasyMock.expect(mockReader.getAttributeValue(null, "name")).andReturn(name); - EasyMock.expect(mockReader.getAttributeValue(null, "multiplicity")).andReturn("0..1"); - EasyMock.expect(mockReader.getAttributeValue(null, "wiredByImpl")).andReturn("false"); - EasyMock.expect(mockReader.getAttributeValue(null, "target")).andReturn(null); - EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT); - EasyMock.expect(mockReader.getName()).andReturn(REFERENCE).anyTimes(); - EasyMock.replay(mockReader); - ComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>> type = - new ComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>>(); - ComponentTypeReferenceDefinition referenceDefinition = loader.load(null, type, mockReader, null); - assertTrue(ComponentTypeReferenceDefinition.class.equals(referenceDefinition.getClass())); - } - - public void testMultipleBindings() throws LoaderException, XMLStreamException { - String name = "referenceDefinition"; - EasyMock.expect(mockReader.getName()).andReturn(REFERENCE).anyTimes(); - EasyMock.expect(mockReader.getAttributeValue(null, "name")).andReturn(name); - EasyMock.expect(mockReader.getAttributeValue(null, "multiplicity")).andReturn("0..1"); - EasyMock.expect(mockReader.getAttributeValue(null, "wiredByImpl")).andReturn("false"); - EasyMock.expect(mockReader.getAttributeValue(null, "target")).andReturn(null); - EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.START_ELEMENT).times(2); - EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT); - EasyMock.expect(mockReader.getName()).andReturn(REFERENCE).anyTimes(); - EasyMock.replay(mockReader); - - BindingDefinition binding = new BindingDefinition() { - public Object clone() { - return null; - } - }; - EasyMock.expect(mockRegistry.load(null, null, mockReader, null)).andReturn(binding).times(2); - EasyMock.replay(mockRegistry); - - ComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>> type = - new ComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>>(); - ComponentTypeReferenceDefinition referenceDefinition = loader.load(null, type, mockReader, null); - assertEquals(2, referenceDefinition.getBindings().size()); - } - - public void testWithInterface() throws LoaderException, XMLStreamException { - String name = "referenceDefinition"; - ServiceContract sc = new ServiceContract() { - }; - EasyMock.expect(mockReader.getName()).andReturn(REFERENCE).anyTimes(); - EasyMock.expect(mockReader.getAttributeValue(null, "name")).andReturn(name); - EasyMock.expect(mockReader.getAttributeValue(null, "multiplicity")).andReturn("0..1"); - EasyMock.expect(mockReader.getAttributeValue(null, "wiredByImpl")).andReturn("false"); - EasyMock.expect(mockReader.getAttributeValue(null, "target")).andReturn(null); - EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.START_ELEMENT); - EasyMock.expect(mockRegistry.load(null, null, mockReader, deploymentContext)).andReturn(sc); - EasyMock.expect(mockReader.next()).andReturn(XMLStreamConstants.END_ELEMENT); - - EasyMock.replay(mockReader); - EasyMock.replay(mockRegistry); - - ComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>> type = - new ComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>>(); - ComponentTypeReferenceDefinition referenceDefinition = loader.load(null, type, mockReader, deploymentContext); - assertNotNull(referenceDefinition); - assertEquals(name, referenceDefinition.getName()); - assertSame(sc, referenceDefinition.getServiceContract()); - } - - protected void setUp() throws Exception { - super.setUp(); - mockReader = EasyMock.createStrictMock(XMLStreamReader.class); - mockRegistry = EasyMock.createMock(LoaderRegistry.class); - loader = new ReferenceLoader(mockRegistry); - deploymentContext = new RootDeploymentContext(null, null, null, null); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderTestCase.java deleted file mode 100644 index 6e13256440..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/ServiceLoaderTestCase.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.loader; - -import javax.xml.namespace.QName; -import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; -import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import static org.osoa.sca.Constants.SCA_NS; - -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.loader.LoaderException; -import org.apache.tuscany.spi.loader.LoaderRegistry; -import org.apache.tuscany.spi.model.BindingDefinition; -import org.apache.tuscany.spi.model.ComponentType; -import org.apache.tuscany.spi.model.ComponentTypeReferenceDefinition; -import org.apache.tuscany.spi.model.Property; -import org.apache.tuscany.spi.model.AbstractReferenceDefinition; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.model.ServiceDefinition; - -import junit.framework.TestCase; -import org.apache.tuscany.core.deployer.RootDeploymentContext; -import org.easymock.EasyMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; - -/** - * Verifies loading of a service definition from an XML-based assembly - * - * @version $Rev$ $Date$ - */ -public class ServiceLoaderTestCase extends TestCase { - private static final QName SERVICE = new QName(SCA_NS, "service"); - private static final QName BINDING = new QName(SCA_NS, "binding.foo"); - private static final QName REFERENCE = new QName(SCA_NS, "reference"); - private static final QName INTERFACE_JAVA = new QName(SCA_NS, "interface.java"); - - private ServiceLoader loader; - private DeploymentContext deploymentContext; - private XMLStreamReader mockReader; - private LoaderRegistry mockRegistry; - - public void testWithNoInterface() throws LoaderException, XMLStreamException { - String name = "serviceDefinition"; - expect(mockReader.getName()).andReturn(SERVICE).anyTimes(); - expect(mockReader.getAttributeValue(null, "name")).andReturn(name); - expect(mockReader.next()).andReturn(END_ELEMENT); - expect(mockReader.getName()).andReturn(SERVICE).anyTimes(); - replay(mockReader); - ServiceDefinition serviceDefinition = loader.load(null, null, mockReader, null); - assertNotNull(serviceDefinition); - assertEquals(name, serviceDefinition.getName()); - } - - public void testComponentTypeService() throws LoaderException, XMLStreamException { - String name = "service"; - expect(mockReader.getName()).andReturn(SERVICE).anyTimes(); - expect(mockReader.getAttributeValue(null, "name")).andReturn(name); - expect(mockReader.next()).andReturn(END_ELEMENT); - expect(mockReader.getName()).andReturn(SERVICE).anyTimes(); - replay(mockReader); - ComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>> type = - new ComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>>(); - ServiceDefinition serviceDefinition = loader.load(null, type, mockReader, null); - assertTrue(ServiceDefinition.class.equals(serviceDefinition.getClass())); - } - - public void testMultipleBindings() throws LoaderException, XMLStreamException { - String name = "serviceDefinition"; - expect(mockReader.getName()).andReturn(SERVICE).anyTimes(); - expect(mockReader.getAttributeValue(null, "name")).andReturn(name); - expect(mockReader.next()).andReturn(START_ELEMENT); - expect(mockReader.getName()).andReturn(BINDING); - expect(mockReader.next()).andReturn(START_ELEMENT); - expect(mockReader.getName()).andReturn(BINDING); - expect(mockReader.next()).andReturn(END_ELEMENT); - expect(mockReader.getName()).andReturn(SERVICE).anyTimes(); - replay(mockReader); - - BindingDefinition binding = new BindingDefinition() { - public Object clone() { - return null; - } - }; - expect(mockRegistry.load(null, null, mockReader, null)).andReturn(binding).times(2); - replay(mockRegistry); - - ServiceDefinition serviceDefinition = loader.load(null, null, mockReader, null); - assertEquals(2, serviceDefinition.getBindings().size()); - } - - public void testWithInterface() throws LoaderException, XMLStreamException { - String name = "serviceDefinition"; - String target = "target"; - ServiceContract sc = new ServiceContract() { - }; - expect(mockReader.getName()).andReturn(SERVICE).anyTimes(); - expect(mockReader.getAttributeValue(null, "name")).andReturn(name); - expect(mockReader.next()).andReturn(START_ELEMENT); - expect(mockReader.getName()).andReturn(INTERFACE_JAVA); - expect(mockRegistry.load(null, null, mockReader, deploymentContext)).andReturn(sc); - expect(mockReader.next()).andReturn(START_ELEMENT); - expect(mockReader.getName()).andReturn(REFERENCE); - expect(mockReader.getElementText()).andReturn(target); - expect(mockReader.next()).andReturn(END_ELEMENT); - expect(mockReader.getName()).andReturn(REFERENCE); - expect(mockReader.next()).andReturn(END_ELEMENT); - expect(mockReader.getName()).andReturn(SERVICE); - - replay(mockReader); - replay(mockRegistry); - - ServiceDefinition serviceDefinition = loader.load(null, null, mockReader, deploymentContext); - assertNotNull(serviceDefinition); - assertEquals(name, serviceDefinition.getName()); - assertSame(sc, serviceDefinition.getServiceContract()); - } - - public void testWithNoReference() throws LoaderException, XMLStreamException { - String name = "serviceDefinition"; - ServiceContract sc = new ServiceContract() { - }; - expect(mockReader.getName()).andReturn(SERVICE).anyTimes(); - expect(mockReader.getAttributeValue(null, "name")).andReturn(name); - expect(mockReader.next()).andReturn(START_ELEMENT); - expect(mockReader.getName()).andReturn(INTERFACE_JAVA); - expect(mockRegistry.load(null, null, mockReader, deploymentContext)).andReturn(sc); - expect(mockReader.next()).andReturn(END_ELEMENT); - expect(mockReader.getName()).andReturn(SERVICE); - - replay(mockReader); - replay(mockRegistry); - - ServiceDefinition serviceDefinition = loader.load(null, null, mockReader, deploymentContext); - assertNotNull(serviceDefinition); - assertEquals(name, serviceDefinition.getName()); - assertSame(sc, serviceDefinition.getServiceContract()); - } - - protected void setUp() throws Exception { - super.setUp(); - mockReader = EasyMock.createStrictMock(XMLStreamReader.class); - mockRegistry = EasyMock.createMock(LoaderRegistry.class); - loader = new ServiceLoader(mockRegistry); - deploymentContext = new RootDeploymentContext(null, null, null, null); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/StAXLoaderRegistryImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/StAXLoaderRegistryImplTestCase.java deleted file mode 100644 index 74a40c80a9..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/StAXLoaderRegistryImplTestCase.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.loader; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.spi.component.CompositeComponent; -import org.apache.tuscany.spi.deployer.DeploymentContext; -import org.apache.tuscany.spi.loader.LoaderException; -import org.apache.tuscany.spi.loader.StAXElementLoader; -import org.apache.tuscany.spi.loader.UnrecognizedElementException; -import org.apache.tuscany.spi.model.ModelObject; - -import junit.framework.TestCase; -import org.apache.tuscany.core.deployer.RootDeploymentContext; -import static org.easymock.EasyMock.isNull; -import org.easymock.classextension.EasyMock; - -/** - * Verifies the default loader registry - * - * @version $Rev$ $Date$ - */ -public class StAXLoaderRegistryImplTestCase extends TestCase { - private LoaderRegistryImpl registry; - private QName name; - private LoaderRegistryImpl.Monitor mockMonitor; - private StAXElementLoader<ModelObject> mockLoader; - private XMLStreamReader mockReader; - private DeploymentContext deploymentContext; - private ModelObject modelObject; - - public void testLoaderRegistration() { - mockMonitor.registeringLoader(EasyMock.eq(name)); - EasyMock.replay(mockMonitor); - registry.registerLoader(name, mockLoader); - EasyMock.verify(mockMonitor); - } - - public void testLoaderUnregistration() { - mockMonitor.unregisteringLoader(EasyMock.eq(name)); - EasyMock.replay(mockMonitor); - registry.unregisterLoader(name, (StAXElementLoader<ModelObject>) mockLoader); - EasyMock.verify(mockMonitor); - } - - public void testSuccessfulDispatch() throws LoaderException, XMLStreamException { - EasyMock.expect(mockReader.getName()).andReturn(name); - EasyMock.replay(mockReader); - mockMonitor.registeringLoader(EasyMock.eq(name)); - mockMonitor.elementLoad(EasyMock.eq(name)); - EasyMock.replay(mockMonitor); - EasyMock.expect(mockLoader.load(EasyMock.isA(CompositeComponent.class), - (ModelObject) isNull(), - EasyMock.eq(mockReader), - EasyMock.eq(deploymentContext))).andReturn(modelObject); - EasyMock.replay(mockLoader); - registry.registerLoader(name, (StAXElementLoader<ModelObject>) mockLoader); - CompositeComponent parent = EasyMock.createNiceMock(CompositeComponent.class); - assertSame(modelObject, registry.load(parent, null, mockReader, deploymentContext)); - EasyMock.verify(mockLoader); - EasyMock.verify(mockMonitor); - EasyMock.verify(mockReader); - - } - - public void testUnsuccessfulDispatch() throws LoaderException, XMLStreamException { - EasyMock.expect(mockReader.getName()).andReturn(name); - EasyMock.replay(mockReader); - mockMonitor.elementLoad(EasyMock.eq(name)); - EasyMock.replay(mockMonitor); - try { - registry.load(null, null, mockReader, deploymentContext); - fail(); - } catch (UnrecognizedElementException e) { - assertSame(name, e.getElement()); - } - EasyMock.verify(mockReader); - EasyMock.verify(mockMonitor); - } - - public void testPregivenModelObject() throws Exception { - EasyMock.expect(mockReader.getName()).andReturn(name); - EasyMock.replay(mockReader); - mockMonitor.registeringLoader(EasyMock.eq(name)); - mockMonitor.elementLoad(EasyMock.eq(name)); - EasyMock.replay(mockMonitor); - EasyMock.expect(mockLoader.load(EasyMock.isA(CompositeComponent.class), - EasyMock.eq(modelObject), - EasyMock.eq(mockReader), - EasyMock.eq(deploymentContext))).andReturn(modelObject); - EasyMock.replay(mockLoader); - registry.registerLoader(name, (StAXElementLoader<ModelObject>) mockLoader); - CompositeComponent parent = EasyMock.createNiceMock(CompositeComponent.class); - assertSame(modelObject, registry.load(parent, modelObject, mockReader, deploymentContext)); - EasyMock.verify(mockLoader); - } - - @SuppressWarnings("unchecked") - protected void setUp() throws Exception { - super.setUp(); - name = new QName("http://mock", "test"); - deploymentContext = new RootDeploymentContext(null, null, null, null); - mockMonitor = EasyMock.createMock(LoaderRegistryImpl.Monitor.class); - registry = new LoaderRegistryImpl(mockMonitor); - - mockLoader = EasyMock.createMock(StAXElementLoader.class); - mockReader = EasyMock.createMock(XMLStreamReader.class); - modelObject = new ModelObject() { - }; - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/StringParserPropertyFactoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/StringParserPropertyFactoryTestCase.java deleted file mode 100644 index 002eb6646e..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/StringParserPropertyFactoryTestCase.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.loader; - -import java.util.ArrayList; -import java.util.List; - -import junit.framework.TestCase; - -import org.apache.tuscany.spi.ObjectFactory; -import org.apache.tuscany.spi.model.Property; -import org.apache.tuscany.spi.model.PropertyValue; -import org.easymock.EasyMock; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -/** - * @version $Rev$ $Date$ - */ -public class StringParserPropertyFactoryTestCase extends TestCase { - - private <T> PropertyValue<T> mock(String value) { - Document document = EasyMock.createMock(Document.class); - Element element = EasyMock.createMock(Element.class); - //EasyMock.expect(document.getDocumentElement()).andReturn(element); - EasyMock.expect(element.getTextContent()).andReturn(value); - EasyMock.replay(document, element); - - List<Element> valueList = new ArrayList<Element>(); - valueList.add(element); - return new PropertyValue<T>(null, valueList); - } - - public void testInteger() throws Exception { - - StringParserPropertyFactory factory = new StringParserPropertyFactory(); - Property<Integer> property = new Property<Integer>(); - property.setJavaType(Integer.class); - PropertyValue<Integer> propertyValue = mock("1"); - ObjectFactory<Integer> oFactory = factory.createObjectFactory(property, propertyValue); - assertEquals(1, oFactory.getInstance().intValue()); - } - - public void testPrimitiveInt() throws Exception { - StringParserPropertyFactory factory = new StringParserPropertyFactory(); - Property<Integer> property = new Property<Integer>(); - property.setJavaType(Integer.TYPE); - PropertyValue<Integer> propertyValue = mock("1"); - ObjectFactory<Integer> oFactory = factory.createObjectFactory(property, propertyValue); - assertEquals(1, oFactory.getInstance().intValue()); - } - - public void testString() throws Exception { - StringParserPropertyFactory factory = new StringParserPropertyFactory(); - Property<String> property = new Property<String>(); - property.setJavaType(String.class); - PropertyValue<String> propertyValue = mock("1"); - ObjectFactory<String> oFactory = factory.createObjectFactory(property, propertyValue); - assertEquals("1", oFactory.getInstance()); - } - - public void testByteArray() throws Exception { - StringParserPropertyFactory factory = new StringParserPropertyFactory(); - Property<byte[]> property = new Property<byte[]>(); - property.setJavaType(byte[].class); - PropertyValue<byte[]> propertyValue = mock("1"); - ObjectFactory<byte[]> oFactory = factory.createObjectFactory(property, propertyValue); - byte[] result = oFactory.getInstance(); - byte[] expected = "1".getBytes(); - for (int i = 0; i < result.length; i++) { - byte b = result[i]; - if (b != expected[i]) { - fail(); - } - } - } - - public void testBoolean() throws Exception { - StringParserPropertyFactory factory = new StringParserPropertyFactory(); - Property<Boolean> property = new Property<Boolean>(); - property.setJavaType(Boolean.class); - PropertyValue<Boolean> propertyValue = mock("true"); - ObjectFactory<Boolean> oFactory = factory.createObjectFactory(property, propertyValue); - assertTrue(oFactory.getInstance()); - } - - public void testPrimitiveBoolean() throws Exception { - StringParserPropertyFactory factory = new StringParserPropertyFactory(); - Property<Boolean> property = new Property<Boolean>(); - property.setJavaType(Boolean.TYPE); - PropertyValue<Boolean> propertyValue = mock("true"); - ObjectFactory<Boolean> oFactory = factory.createObjectFactory(property, propertyValue); - assertTrue(oFactory.getInstance()); - } - - public void testStringConstructor() throws Exception { - StringParserPropertyFactory factory = new StringParserPropertyFactory(); - Property<Foo> property = new Property<Foo>(); - property.setJavaType(Foo.class); - PropertyValue<Foo> propertyValue = mock("test"); - ObjectFactory<Foo> oFactory = factory.createObjectFactory(property, propertyValue); - assertEquals("test", oFactory.getInstance().getFoo()); - } - - private static class Foo { - private String foo; - - public Foo(String foo) { - this.foo = foo; - } - - public String getFoo() { - return foo; - } - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/WireLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/WireLoaderTestCase.java deleted file mode 100644 index 2e42c0e70d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/loader/WireLoaderTestCase.java +++ /dev/null @@ -1,159 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tuscany.core.loader;
-
-import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
-import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-import org.easymock.EasyMock;
-
-import static org.osoa.sca.Constants.SCA_NS;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.Location;
-
-import junit.framework.TestCase;
-
-import org.apache.tuscany.spi.component.CompositeComponent;
-import org.apache.tuscany.spi.deployer.DeploymentContext;
-import org.apache.tuscany.spi.loader.InvalidWireException;
-import org.apache.tuscany.spi.loader.LoaderException;
-import org.apache.tuscany.spi.loader.LoaderRegistry;
-import org.apache.tuscany.spi.model.WireDefinition;
-
-/**
- * @version $Rev: 471504 $ $Date: 2006-11-06 01:10:40 +0530 (Mon, 06 Nov 2006) $
- */
-public class WireLoaderTestCase extends TestCase {
- private static final QName WIRE = new QName(SCA_NS, "wire");
- private static final QName SOURCE_URI = new QName(SCA_NS, "source.uri");
- private static final QName TARGET_URI = new QName(SCA_NS, "target.uri");
-
- private LoaderRegistry registry;
- private WireLoader loader;
- private XMLStreamReader reader;
- private DeploymentContext context;
- private CompositeComponent composite;
-
- public void testValidWire() throws LoaderException, XMLStreamException {
- expect(reader.getName()).andReturn(WIRE);
- expect(reader.next()).andReturn(START_ELEMENT);
- expect(reader.getName()).andReturn(SOURCE_URI).times(1);
- expect(reader.getElementText()).andReturn("source").times(1);
- expect(reader.next()).andReturn(END_ELEMENT);
- expect(reader.next()).andReturn(START_ELEMENT);
- expect(reader.getName()).andReturn(TARGET_URI).times(2);
- expect(reader.getElementText()).andReturn("target").times(1);
- expect(reader.next()).andReturn(END_ELEMENT);
- expect(reader.next()).andReturn(END_ELEMENT);
- expect(reader.getName()).andReturn(WIRE).anyTimes();
- replay(registry, reader, context);
- WireDefinition wireDef = loader.load(composite, null, reader, context);
- assertNotNull(wireDef);
- verify(registry, reader, context);
- }
-
- public void testInValidWireNoSourceElement() throws LoaderException, XMLStreamException {
- expect(reader.getName()).andReturn(WIRE).times(1);
- expect(reader.next()).andReturn(START_ELEMENT);
- expect(reader.getName()).andReturn(TARGET_URI).times(2);
- expect(reader.getElementText()).andReturn("target").times(1);
- expect(reader.next()).andReturn(END_ELEMENT);
- expect(reader.next()).andReturn(END_ELEMENT);
- expect(reader.getName()).andReturn(WIRE).anyTimes();
- replay(registry, reader, context);
- try {
- loader.load(composite, null, reader, context);
- fail();
- } catch (InvalidWireException e) {
- //expected behaviour
- }
- verify(registry, reader, context);
- }
-
- public void testInValidWireNoTargetElement() throws LoaderException, XMLStreamException {
- expect(reader.getName()).andReturn(WIRE).times(1);
- expect(reader.next()).andReturn(START_ELEMENT);
- expect(reader.getName()).andReturn(SOURCE_URI).times(1);
- expect(reader.getElementText()).andReturn("source").times(1);
- expect(reader.next()).andReturn(END_ELEMENT);
- expect(reader.next()).andReturn(END_ELEMENT);
- expect(reader.getName()).andReturn(WIRE).anyTimes();
- replay(registry, reader, context);
- try {
- loader.load(composite, null, reader, context);
- fail();
- } catch (InvalidWireException e) {
- //expected behaviour
- }
- verify(registry, reader, context);
- }
-
- public void testInValidWireNoSourceSpecified() throws LoaderException, XMLStreamException {
- expect(reader.getName()).andReturn(WIRE).times(1);
- expect(reader.next()).andReturn(START_ELEMENT);
- expect(reader.getName()).andReturn(SOURCE_URI).times(1);
- expect(reader.getElementText()).andReturn("").times(1);
- replay(registry, reader, context);
- try {
- loader.load(composite, null, reader, context);
- fail();
- } catch (InvalidWireException e) {
- //expected behaviour
- }
- verify(registry, reader, context);
- }
-
- public void testInValidWireNoTargetSpecified() throws LoaderException, XMLStreamException {
- expect(reader.getName()).andReturn(WIRE).times(1);
- expect(reader.next()).andReturn(START_ELEMENT);
- expect(reader.getName()).andReturn(SOURCE_URI).times(1);
- expect(reader.getElementText()).andReturn("source").times(1);
- expect(reader.next()).andReturn(END_ELEMENT);
- expect(reader.next()).andReturn(START_ELEMENT);
- expect(reader.getName()).andReturn(TARGET_URI).times(2);
- expect(reader.getElementText()).andReturn("").times(1);
- expect(reader.getName()).andReturn(WIRE).anyTimes();
- replay(registry, reader, context);
- try {
- loader.load(composite, null, reader, context);
- fail();
- } catch (InvalidWireException e) {
- //expected behaviour
- }
- verify(registry, reader, context);
- }
-
- protected void setUp() throws Exception {
- super.setUp();
- registry = createMock(LoaderRegistry.class);
- reader = createMock(XMLStreamReader.class);
- Location location = EasyMock.createNiceMock(Location.class);
- EasyMock.replay(location);
- EasyMock.expect(reader.getLocation()).andReturn(location).anyTimes();
- context = createMock(DeploymentContext.class);
- composite = createMock(CompositeComponent.class);
- loader = new WireLoader(registry);
- }
-}
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/binding/MockServiceBinding.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/binding/MockServiceBinding.java deleted file mode 100644 index 8a38665584..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/binding/MockServiceBinding.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.binding; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.spi.component.AbstractSCAObject; -import org.apache.tuscany.spi.component.Service; -import org.apache.tuscany.spi.component.ServiceBinding; -import org.apache.tuscany.spi.component.TargetInvokerCreationException; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.TargetInvoker; - -/** - * @version $Rev$ $Date$ - */ -public class MockServiceBinding extends AbstractSCAObject implements ServiceBinding { - private InboundWire inboundWire; - private OutboundWire outboundWire; - private ServiceContract<?> bindingServiceContract; - - - public MockServiceBinding() { - super("foo", null); - } - - public QName getBindingType() { - return null; - } - - public void setService(Service service) { - } - - public ServiceContract<?> getBindingServiceContract() { - return bindingServiceContract; - } - - public InboundWire getInboundWire() { - return inboundWire; - } - - public void setInboundWire(InboundWire inboundWire) { - this.inboundWire = inboundWire; - } - - public OutboundWire getOutboundWire() { - return outboundWire; - } - - public void setOutboundWire(OutboundWire outboundWire) { - this.outboundWire = outboundWire; - } - - public TargetInvoker createTargetInvoker(ServiceContract contract, Operation operation) - throws TargetInvokerCreationException { - return null; - } - - public Scope getScope() { - return null; - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/AsyncTarget.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/AsyncTarget.java deleted file mode 100644 index 653d5d7335..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/AsyncTarget.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -import org.osoa.sca.annotations.OneWay; - -/** - * @version $Rev$ $Date$ - */ -public interface AsyncTarget { - @OneWay - void invoke(); - - int getCount(); -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BadContextPojo.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BadContextPojo.java deleted file mode 100644 index 066acc346d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BadContextPojo.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -import org.osoa.sca.annotations.Context; - -public class BadContextPojo { - - @Context - String context; - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BadNamePojo.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BadNamePojo.java deleted file mode 100644 index 77ec37f9e4..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BadNamePojo.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -import org.osoa.sca.annotations.ComponentName; - -public class BadNamePojo { - @ComponentName - private int name; -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterface.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterface.java deleted file mode 100644 index b7921c248f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterface.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -/** - * @version $Rev$ $Date$ - */ -public interface BasicInterface { - String returnsProperty(); - - BasicInterface returnsReference(); - - int returnsInt(); -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterfaceImpl.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterfaceImpl.java deleted file mode 100644 index f7d7bb38cf..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/BasicInterfaceImpl.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -import org.osoa.sca.annotations.Property; -import org.osoa.sca.annotations.Reference; - -/** - * @version $Rev$ $Date$ - */ -public class BasicInterfaceImpl implements BasicInterface { - - @Property - public String publicProperty; - - @Reference (required = false) - public BasicInterface publicReference; - - @Property - protected String protectedProperty; - - @Reference (required = false) - protected BasicInterface protectedReference; - - private String privateProperty; - - private BasicInterface privateReference; - - @Property - public void setPrivateProperty(String privateProperty) { - this.privateProperty = privateProperty; - } - - @Reference (required = false) - public void setPrivateReference(BasicInterface privateReference) { - this.privateReference = privateReference; - } - - public String returnsProperty() { - return privateProperty; - } - - public BasicInterface returnsReference() { - return privateReference; - } - - public int returnsInt() { - return 0; - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponent.java deleted file mode 100644 index 88b97216cd..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponent.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -import org.osoa.sca.annotations.Scope; - -/** - * @version $Rev$ $Date$ - */ -@Scope("COMPOSITE") -public interface CompositeScopeComponent { - - //public boolean isInit(); -} - diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponentImpl.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponentImpl.java deleted file mode 100644 index 93ee1f707a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponentImpl.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -import org.osoa.sca.annotations.Scope; - - -/** - * @version $Rev$ $Date$ - */ -@Scope("COMPOSITE") -public class CompositeScopeComponentImpl implements - CompositeScopeComponent { - - private String foo; - - public void setFoo(String foo) { - this.foo = foo; - } - - public String getFoo() { - return foo; - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeDestroyOnlyComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeDestroyOnlyComponent.java deleted file mode 100644 index 16ce3b5569..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeDestroyOnlyComponent.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -import org.osoa.sca.annotations.Destroy; - -public class CompositeScopeDestroyOnlyComponent extends CompositeScopeComponentImpl { - - boolean destroyed; - - public boolean isDestroyed() { - return destroyed; - } - - @Destroy - public void destroy() { - destroyed = true; - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitDestroyComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitDestroyComponent.java deleted file mode 100644 index 05b938a87c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitDestroyComponent.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -import org.osoa.sca.annotations.Destroy; - -public class CompositeScopeInitDestroyComponent extends CompositeScopeInitOnlyComponent { - - boolean destroyed; - - public boolean isDestroyed() { - return destroyed; - } - - @Destroy - public void destroy() { - if (destroyed) { - throw new AssertionError("Destroy called more than once"); - } - destroyed = true; - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitOnlyComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitOnlyComponent.java deleted file mode 100644 index f9f80ca15c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitOnlyComponent.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -import org.osoa.sca.annotations.Init; - -public class CompositeScopeInitOnlyComponent extends CompositeScopeComponentImpl { - - private boolean initialized; - // this value tests to ensure introspection can find the init() method even - // if a field is named the same. Ultimately, this should be in the introspection tests - private boolean init; - - public boolean isInitialized() { - return initialized; - } - - @Init - public void init() { - if (initialized) { - throw new AssertionError("Init called more than once"); - } - initialized = true; - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponent.java deleted file mode 100644 index c71ac0586f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponent.java +++ /dev/null @@ -1,29 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tuscany.core.mock.component;
-
-import org.osoa.sca.annotations.Scope;
-
-/**
- * @version $Rev: 430937 $ $Date: 2006-08-11 21:17:56 -0400 (Fri, 11 Aug 2006) $
- */
-@Scope("CONVERSATION")
-public interface ConversationalScopeComponent {
-
-}
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponentImpl.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponentImpl.java deleted file mode 100644 index 5ea7278e1f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponentImpl.java +++ /dev/null @@ -1,29 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tuscany.core.mock.component;
-
-import org.osoa.sca.annotations.Scope;
-
-/**
- * @version $Rev: 430937 $ $Date: 2006-08-11 21:17:56 -0400 (Fri, 11 Aug 2006) $
- */
-@Scope("CONVERSATION")
-public class ConversationalScopeComponentImpl implements ConversationalScopeComponent {
-
-}
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeDestroyOnlyComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeDestroyOnlyComponent.java deleted file mode 100644 index 8cea9efa49..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeDestroyOnlyComponent.java +++ /dev/null @@ -1,37 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tuscany.core.mock.component;
-
-import org.osoa.sca.annotations.Destroy;
-import org.osoa.sca.annotations.Scope;
-
-@Scope("CONVERSATION")
-public class ConversationalScopeDestroyOnlyComponent extends ConversationalScopeComponentImpl {
-
- boolean destroyed;
-
- public boolean isDestroyed() {
- return destroyed;
- }
-
- @Destroy
- public void destroy() {
- destroyed = true;
- }
-}
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitDestroyComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitDestroyComponent.java deleted file mode 100644 index 40dbfedf2c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitDestroyComponent.java +++ /dev/null @@ -1,38 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tuscany.core.mock.component;
-
-import org.osoa.sca.annotations.Destroy;
-import org.osoa.sca.annotations.Scope;
-
-@Scope("CONVERSATION")
-public class ConversationalScopeInitDestroyComponent
- extends ConversationalScopeInitOnlyComponent {
-
- private boolean destroyed;
-
- public boolean isDestroyed() {
- return destroyed;
- }
-
- @Destroy
- public void destroy() {
- destroyed = true;
- }
-}
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitOnlyComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitOnlyComponent.java deleted file mode 100644 index caaa0c39e7..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitOnlyComponent.java +++ /dev/null @@ -1,38 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tuscany.core.mock.component;
-
-import org.osoa.sca.annotations.Init;
-import org.osoa.sca.annotations.Scope;
-
-@Scope("CONVERSATION")
-public class ConversationalScopeInitOnlyComponent
- extends ConversationalScopeComponentImpl {
-
- private boolean initialized;
-
- public boolean isInitialized() {
- return initialized;
- }
-
- @Init
- public void init() {
- initialized = true;
- }
-}
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderException.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderException.java deleted file mode 100644 index af257c226d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderException.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -public class OrderException extends Exception { - - public OrderException() { - super(); - } - - public OrderException(String message) { - super(message); - } - - public OrderException(String message, Throwable cause) { - super(message, cause); - } - - public OrderException(Throwable cause) { - super(cause); - } - -} - diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojo.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojo.java deleted file mode 100644 index 2033f0eca5..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojo.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -/** - * @version $$Rev$$ $$Date$$ - */ -public interface OrderedDependentPojo extends OrderedInitPojo { - - OrderedInitPojo getPojo(); - - void setPojo(OrderedInitPojo pojo); -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojoImpl.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojoImpl.java deleted file mode 100644 index 439c3d143c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojoImpl.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -/** - * @version $$Rev$$ $$Date$$ - */ -public class OrderedDependentPojoImpl extends OrderedInitPojoImpl implements OrderedDependentPojo { - - private OrderedInitPojo pojo; - - public OrderedInitPojo getPojo() { - return pojo; - } - - public void setPojo(OrderedInitPojo pojo) { - this.pojo = pojo; - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedEagerInitPojo.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedEagerInitPojo.java deleted file mode 100644 index 1986952747..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedEagerInitPojo.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -import org.osoa.sca.annotations.Destroy; -import org.osoa.sca.annotations.Init; -import org.osoa.sca.annotations.Scope; -import org.osoa.sca.annotations.EagerInit; - -@Scope("COMPOSITE") -@EagerInit -public class OrderedEagerInitPojo { - - private static final Object LOCK = new Object(); - private static int numberInstantied; - private int initOrder; - - @Init - public void init() { - synchronized (LOCK) { - ++numberInstantied; - initOrder = numberInstantied; - } - } - - @Destroy - public void destroy() throws OrderException { - synchronized (LOCK) { - if (initOrder != numberInstantied) { - throw new OrderException("Instance shutdown done out of order"); - } - --numberInstantied; - } - } - - public int getNumberInstantiated() { - return numberInstantied; - } - - public int getInitOrder() { - return initOrder; - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojo.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojo.java deleted file mode 100644 index 0b891cfa42..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojo.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -/** - * @version $$Rev$$ $$Date$$ - */ -public interface OrderedInitPojo { - int getNumberInstantiated(); - - int getInitOrder(); -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojoImpl.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojoImpl.java deleted file mode 100644 index a7063f6353..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojoImpl.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -import org.osoa.sca.annotations.Destroy; -import org.osoa.sca.annotations.Init; -import org.osoa.sca.annotations.Scope; - -@Scope("COMPOSITE") -public class OrderedInitPojoImpl implements OrderedInitPojo { - - private static final Object LOCK = new Object(); - private static int numberInstantied; - private int initOrder; - - public OrderedInitPojoImpl() { - } - - @Init - public void init() { - synchronized (LOCK) { - ++numberInstantied; - initOrder = numberInstantied; - } - } - - @Destroy - public void destroy() throws OrderException { - synchronized (LOCK) { - if (initOrder != numberInstantied) { - throw new OrderException("Instance shutdown done out of order"); - } - --numberInstantied; - } - } - - public int getNumberInstantiated() { - return numberInstantied; - } - - public int getInitOrder() { - return initOrder; - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTarget.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTarget.java deleted file mode 100644 index 0b897daa40..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTarget.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -/** - * Implementations are used in wiring tests - * - * @version $Rev$ $Date$ - */ -public interface OtherTarget { - - String getString(); - - void setString(String val); -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTargetImpl.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTargetImpl.java deleted file mode 100644 index a3b2bbf098..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/OtherTargetImpl.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -/** - * A target used for testing wires with a different source and target interface - * - * @version $Rev$ $Date$ - */ -public class OtherTargetImpl implements OtherTarget { - - private String theString; - - public String getString() { - return theString; - } - - public void setString(String val) { - theString = val; - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeComponent.java deleted file mode 100644 index 8c7dc107ee..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeComponent.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -import org.osoa.sca.annotations.Scope; - -/** - * @version $Rev$ $Date$ - */ -@Scope("REQUEST") -public interface RequestScopeComponent { - -} - diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeDestroyOnlyComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeDestroyOnlyComponent.java deleted file mode 100644 index 5224ceda5f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeDestroyOnlyComponent.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -import org.osoa.sca.annotations.Destroy; -import org.osoa.sca.annotations.Scope; - -@Scope("REQUEST") -public class RequestScopeDestroyOnlyComponent extends SessionScopeComponentImpl { - - boolean destroyed; - - public boolean isDestroyed() { - return destroyed; - } - - @Destroy - public void destroy() { - destroyed = true; - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitDestroyComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitDestroyComponent.java deleted file mode 100644 index 38b188a4b5..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitDestroyComponent.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -import org.osoa.sca.annotations.Destroy; -import org.osoa.sca.annotations.Scope; - -@Scope("REQUEST") -public class RequestScopeInitDestroyComponent extends SessionScopeInitOnlyComponent { - - boolean destroyed; - - public boolean isDestroyed() { - return destroyed; - } - - @Destroy - public void destroy() { - destroyed = true; - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitOnlyComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitOnlyComponent.java deleted file mode 100644 index 707f8ab50f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitOnlyComponent.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -import org.osoa.sca.annotations.Init; -import org.osoa.sca.annotations.Scope; - -@Scope("REQUEST") -public class RequestScopeInitOnlyComponent extends SessionScopeComponentImpl { - - private boolean initialized; - - public boolean isInitialized() { - return initialized; - } - - @Init - public void init() { - initialized = true; - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponent.java deleted file mode 100644 index 827ba804f2..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponent.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -import org.osoa.sca.annotations.Scope; - -/** - * @version $Rev$ $Date$ - */ -@Scope("SESSION") -public interface SessionScopeComponent { - -} - diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponentImpl.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponentImpl.java deleted file mode 100644 index e547bf6113..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponentImpl.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -import org.osoa.sca.annotations.Scope; - -/** - * @version $Rev$ $Date$ - */ -@Scope("SESSION") -public class SessionScopeComponentImpl implements - SessionScopeComponent { - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitDestroyComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitDestroyComponent.java deleted file mode 100644 index c11bd1bd49..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitDestroyComponent.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -import org.osoa.sca.annotations.Destroy; - -public class SessionScopeInitDestroyComponent extends SessionScopeInitOnlyComponent { - - private boolean destroyed; - - public boolean isDestroyed() { - return destroyed; - } - - @Destroy - public void destroy() { - destroyed = true; - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitOnlyComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitOnlyComponent.java deleted file mode 100644 index 095cc916ec..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitOnlyComponent.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -import org.osoa.sca.annotations.Init; - -public class SessionScopeInitOnlyComponent extends SessionScopeComponentImpl { - - private boolean initialized; - - public boolean isInitialized() { - return initialized; - } - - @Init - public void init() { - initialized = true; - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTarget.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTarget.java deleted file mode 100644 index c78ba00a7a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTarget.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -public interface SimpleTarget { - - String hello(String message) throws Exception; - - String goodbye(String message) throws Exception; - - String echo(String message) throws Exception; - -} - diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTargetImpl.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTargetImpl.java deleted file mode 100644 index 634a07a401..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SimpleTargetImpl.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -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; - } - - -} - diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/Source.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/Source.java deleted file mode 100644 index f7969f748b..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/Source.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -import java.util.List; - -/** - * Implementations are used in wiring tests - * - * @version $Rev$ $Date$ - */ -public interface Source { - - Target getTarget(); - - List<Target> getTargets(); - - List<Target> getTargetsThroughField(); - -} - diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SourceImpl.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SourceImpl.java deleted file mode 100644 index 187e33b2bd..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/SourceImpl.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -import java.util.List; - -/** - * Mock system component implementation used in wiring tests - * - * @version $Rev$ $Date$ - */ -public class SourceImpl implements Source { - - private Target target; - private List<Target> targets; - private List<Target> targetsThroughField; - private Target[] targetsArray; - - public void setTarget(Target target) { - this.target = target; - } - - public Target getTarget() { - return target; - } - - public List<Target> getTargets() { - return targets; - } - - public void setTargets(List<Target> targets) { - this.targets = targets; - } - - public List<Target> getTargetsThroughField() { - return targetsThroughField; - } - - public Target[] getArrayOfTargets() { - return targetsArray; - } - - public void setArrayOfTargets(Target[] targets) { - targetsArray = targets; - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponent.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponent.java deleted file mode 100644 index c16ac942a3..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponent.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -import org.osoa.sca.annotations.Scope; - -/** - * @version $Rev$ $Date$ - */ -@Scope("STATELESS") -public interface StatelessComponent { - -} - diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponentImpl.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponentImpl.java deleted file mode 100644 index 64a23c12c8..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponentImpl.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -/** - * @version $Rev$ $Date$ - */ -public class StatelessComponentImpl implements - StatelessComponent { - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/Target.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/Target.java deleted file mode 100644 index 778c14665d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/Target.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -/** - * Implementations are used in wiring tests - * - * @version $Rev$ $Date$ - */ -public interface Target { - - String getString(); - - void setString(String val); -} - diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/TargetImpl.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/TargetImpl.java deleted file mode 100644 index 037dd3a37c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/component/TargetImpl.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.component; - -/** - * Mock system component implementation used in wiring tests - * - * @version $Rev$ $Date$ - */ -public class TargetImpl implements Target { - - private String theString; - - public String getString() { - return theString; - } - - public void setString(String val) { - theString = val; - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockStaticInvoker.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockStaticInvoker.java deleted file mode 100644 index cdd0de7a6d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockStaticInvoker.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.wire; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.InvocationRuntimeException; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.TargetInvoker; - -/** - * 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$ $Date$ - */ -public class MockStaticInvoker implements TargetInvoker { - - private Object instance; - private Method operation; - private boolean cacheable; - - - public MockStaticInvoker(Method operation, Object instance) { - this.operation = operation; - this.instance = instance; - } - - public boolean isCacheable() { - return cacheable; - } - - public void setCacheable(boolean cacheable) { - this.cacheable = cacheable; - } - - public boolean isOptimizable() { - return isCacheable(); - } - - public Object invokeTarget(final Object payload, final short sequence) 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) throws InvocationRuntimeException { - try { - Object resp = invokeTarget(msg.getBody(), TargetInvoker.NONE); - msg.setBody(resp); - } catch (InvocationTargetException e) { - msg.setBodyWithFault(e.getCause()); - } catch (Throwable e) { - msg.setBodyWithFault(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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockSyncInterceptor.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockSyncInterceptor.java deleted file mode 100644 index 1fe2c027ab..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockSyncInterceptor.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.wire; - -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; - -public class MockSyncInterceptor implements Interceptor { - - private int count; - - private Interceptor next; - - public MockSyncInterceptor() { - } - - public Message invoke(Message msg) { - ++count; - return next.invoke(msg); - } - - public int getCount() { - return count; - } - - public void setNext(Interceptor next) { - this.next = next; - } - - public Interceptor getNext() { - return next; - } - - public boolean isOptimizable() { - return false; - } - -} - diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockTargetInvoker.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockTargetInvoker.java deleted file mode 100644 index 3fcc75bdb4..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/mock/wire/MockTargetInvoker.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.mock.wire; - -import org.apache.tuscany.spi.wire.InvocationRuntimeException; -import org.apache.tuscany.spi.wire.Message; - -import org.apache.tuscany.core.binding.local.AbstractLocalTargetInvoker; - -/** - * @version $Rev$ $Date$ - */ -public class MockTargetInvoker extends AbstractLocalTargetInvoker { - public Message invoke(Message msg) throws InvocationRuntimeException { - return null; - } -}
\ No newline at end of file diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/monitor/DefaultExceptionFormatterTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/monitor/DefaultExceptionFormatterTestCase.java deleted file mode 100644 index 2d3f01422d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/monitor/DefaultExceptionFormatterTestCase.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.monitor; - -import java.io.PrintWriter; -import java.io.StringWriter; - -import junit.framework.TestCase; -import org.apache.tuscany.api.TuscanyException; -import org.apache.tuscany.api.TuscanyRuntimeException; - -/** - * @version $Rev$ $Date$ - */ -public class DefaultExceptionFormatterTestCase extends TestCase { - private DefaultExceptionFormatter formatter = new DefaultExceptionFormatter(); - - public void testTuscanyExceptionFormat() throws Exception { - StringWriter writer = new StringWriter(); - PrintWriter pw = new PrintWriter(writer); - TuscanyException e = new TuscanyException("somemessage") { - }; - e.addContextName("somecontext"); - formatter.write(pw, e); - assertTrue(writer.toString().indexOf("somemessage") >= 0); - assertTrue(writer.toString().indexOf("somecontext") >= 0); - } - - public void testTuscanyRuntimeExceptionFormat() throws Exception { - StringWriter writer = new StringWriter(); - PrintWriter pw = new PrintWriter(writer); - TuscanyRuntimeException e = new TuscanyRuntimeException("somemessage") { - }; - e.addContextName("somecontext"); - formatter.write(pw, e); - assertTrue(writer.toString().indexOf("somemessage") >= 0); - assertTrue(writer.toString().indexOf("somecontext") >= 0); - } - - public void testNormalExceptionFormat() throws Exception { - StringWriter writer = new StringWriter(); - PrintWriter pw = new PrintWriter(writer); - Exception e = new Exception(); - formatter.write(pw, e); // just verify there are no errors since no formatting needs to be doen - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/monitor/JavaLoggingTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/monitor/JavaLoggingTestCase.java deleted file mode 100644 index 5fdf035c7a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/monitor/JavaLoggingTestCase.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.monitor; - -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; -import java.util.logging.Handler; -import java.util.logging.Level; -import java.util.logging.LogRecord; -import java.util.logging.Logger; - -import org.apache.tuscany.api.annotation.LogLevel; -import org.apache.tuscany.host.MonitorFactory; - -import junit.framework.TestCase; - -/** - * Test case for the JavaLoggingMonitorFactory. - * - * @version $Rev$ $Date$ - */ -public class JavaLoggingTestCase extends TestCase { - private static final Logger LOGGER = Logger.getLogger(Monitor.class.getName()); - private static final MockHandler HANDLER = new MockHandler(); - - private MonitorFactory factory; - - /** - * Smoke test to ensure the LOGGER is working. - */ - public void testLogger() { - LOGGER.info("test"); - assertEquals(1, HANDLER.logs.size()); - } - - /** - * Test that no record is logged. - */ - public void testUnloggedEvent() { - Monitor mon = factory.getMonitor(Monitor.class); - mon.eventNotToLog(); - assertEquals(0, HANDLER.logs.size()); - } - - /** - * Test the correct record is written for an event with no arguments. - */ - public void testEventWithNoArgs() { - Monitor mon = factory.getMonitor(Monitor.class); - mon.eventWithNoArgs(); - assertEquals(1, HANDLER.logs.size()); - LogRecord record = HANDLER.logs.get(0); - assertEquals(Level.INFO, record.getLevel()); - assertEquals(LOGGER.getName(), record.getLoggerName()); - assertEquals(Monitor.class.getName() + "#eventWithNoArgs", record.getMessage()); - } - - /** - * Test the correct record is written for an event defined by annotation. - */ - public void testEventWithAnnotation() { - Monitor mon = factory.getMonitor(Monitor.class); - mon.eventWithAnnotation(); - assertEquals(1, HANDLER.logs.size()); - LogRecord record = HANDLER.logs.get(0); - assertEquals(Level.INFO, record.getLevel()); - assertEquals(LOGGER.getName(), record.getLoggerName()); - assertEquals(Monitor.class.getName() + "#eventWithAnnotation", record.getMessage()); - } - - /** - * Test the argument is logged. - */ - public void testEventWithOneArg() { - Monitor mon = factory.getMonitor(Monitor.class); - mon.eventWithOneArg("ARG"); - assertEquals(1, HANDLER.logs.size()); - LogRecord record = HANDLER.logs.get(0); - assertEquals(Monitor.class.getName() + "#eventWithOneArg", record.getMessage()); - } - - protected void setUp() throws Exception { - super.setUp(); - LOGGER.setUseParentHandlers(false); - LOGGER.addHandler(HANDLER); - HANDLER.flush(); - - String sourceClass = Monitor.class.getName(); - Properties levels = new Properties(); - levels.setProperty(sourceClass + "#eventWithNoArgs", "INFO"); - levels.setProperty(sourceClass + "#eventWithOneArg", "INFO"); - levels.setProperty(sourceClass + "#eventWithThrowable", "WARNING"); - factory = new JavaLoggingMonitorFactory(levels, Level.FINE, "TestMessages"); - } - - protected void tearDown() throws Exception { - LOGGER.removeHandler(HANDLER); - HANDLER.flush(); - super.tearDown(); - } - - /** - * Mock log HANDLER to capture records. - */ - public static class MockHandler extends Handler { - List<LogRecord> logs = new ArrayList<LogRecord>(); - - public void publish(LogRecord record) { - logs.add(record); - } - - public void flush() { - logs.clear(); - } - - public void close() throws SecurityException { - } - } - - @SuppressWarnings({"JavaDoc"}) - public static interface Monitor { - void eventNotToLog(); - - @LogLevel("INFO") - void eventWithNoArgs(); - - @LogLevel("INFO") - void eventWithOneArg(String msg); - - @LogLevel("WARNING") - void eventWithThrowable(Exception e); - - @LogLevel("INFO") - void eventWithAnnotation(); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/IntentRegistryImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/IntentRegistryImplTestCase.java deleted file mode 100644 index de1c91b741..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/IntentRegistryImplTestCase.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.policy; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import javax.xml.namespace.QName; - -import static org.osoa.sca.Constants.SCA_NS; - -import org.apache.tuscany.spi.model.Intent; -import org.apache.tuscany.spi.model.IntentName; -import org.apache.tuscany.spi.policy.IntentRegistry; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class IntentRegistryImplTestCase extends TestCase { - private static final QName WS_BINDING = new QName(SCA_NS, "binding.ws"); - private static final QName JMS_BINDING = new QName(SCA_NS, "binding.jms"); - private IntentRegistry intentReg; - - @Override - protected void setUp() throws Exception { - intentReg = new IntentRegistryImpl(); - - Intent bodyintent = new Intent(new IntentName("sec.confidentiality/message/body"), "test"); - bodyintent.addAppliedArtifacts(WS_BINDING); - bodyintent.addAppliedArtifacts(JMS_BINDING); - intentReg.register(bodyintent); - - Intent headintent = new Intent(new IntentName("sec.confidentiality/message/head"), "test"); - headintent.addAppliedArtifacts(WS_BINDING); - headintent.addAppliedArtifacts(JMS_BINDING); - intentReg.register(headintent); - - Intent confidentialityintent = new Intent(new IntentName("sec.confidentiality"), "test"); - confidentialityintent.addAppliedArtifacts(WS_BINDING); - confidentialityintent.addAppliedArtifacts(JMS_BINDING); - intentReg.register(confidentialityintent); - - Intent messageintent = new Intent(new IntentName("sec.confidentiality/message"), null); - messageintent.addAppliedArtifacts(WS_BINDING); - messageintent.addAppliedArtifacts(JMS_BINDING); - intentReg.register(messageintent); - } - - @Override - protected void tearDown() throws Exception { - intentReg = null; - } - -// public void testGetQualifiedIntent() { -// List<IntentName> intentNameList = new ArrayList<IntentName>(); -// intentReg.get -// //intentReg.getConcretIntents(intentNameList, artifact) -// } - - public void testGetConcretIntents() { - Intent messageintent = new Intent(new IntentName("sec.confidentiality/transport"), null); - messageintent.addAppliedArtifacts(WS_BINDING); - messageintent.addAppliedArtifacts(JMS_BINDING); - intentReg.register(messageintent); - - Intent allintent = new Intent(new IntentName("sec.confidentiality/all"), null); - allintent.addAppliedArtifacts(WS_BINDING); - allintent.addRequriedIntents(new IntentName("sec.confidentiality/message")); - allintent.addRequriedIntents(new IntentName("sec.confidentiality/transport")); - - - intentReg.register(allintent); - List<IntentName> intents = new ArrayList<IntentName>(); - intents.add(new IntentName("sec.confidentiality/all")); - Collection<IntentName> concreteIntents = intentReg.inlineProfileIntent(intents, WS_BINDING); - assertEquals(2, concreteIntents.size()); - assertTrue(concreteIntents.contains(new IntentName("sec.confidentiality/message"))); - assertTrue(concreteIntents.contains(new IntentName("sec.confidentiality/transport"))); - //fail("Not yet implemented"); - } - - public void testGetQualifiedIntents() { - IntentName message = new IntentName("sec.confidentiality/message"); - Collection<IntentName> qualifiedIntents = intentReg.getQualifiedIntents(message, JMS_BINDING); - assertEquals(2, qualifiedIntents.size()); - assertTrue(qualifiedIntents.contains(new IntentName("sec.confidentiality/message/body"))); - assertTrue(qualifiedIntents.contains(new IntentName("sec.confidentiality/message/head"))); - assertFalse(qualifiedIntents.contains(new IntentName("sec.confidentiality/message"))); - assertFalse(qualifiedIntents.contains(new IntentName("sec.confidentiality"))); - } - - public void testIsApplicable() { - assertTrue(intentReg.isApplicable(new IntentName("sec.confidentiality/message"), WS_BINDING)); - assertFalse(intentReg.isApplicable(new IntentName("sec.confidentiality/transport"), WS_BINDING)); - assertFalse(intentReg.isApplicable(new IntentName("test.confidentiality/transport"), WS_BINDING)); - } - - public void testRegister() { - Intent messageintent = new Intent(new IntentName("sec.confidentiality/transport"), null); - messageintent.addAppliedArtifacts(WS_BINDING); - messageintent.addAppliedArtifacts(JMS_BINDING); - intentReg.register(messageintent); - assertTrue(intentReg.isApplicable(new IntentName("sec.confidentiality/transport"), WS_BINDING)); - assertTrue(intentReg.isApplicable(new IntentName("sec.confidentiality/transport"), JMS_BINDING)); - - } - - public void testIsQualifiedIntent() { - Intent messageintent = new Intent(new IntentName("sec.confidentiality/transport"), null); - messageintent.addAppliedArtifacts(WS_BINDING); - messageintent.addAppliedArtifacts(JMS_BINDING); - intentReg.register(messageintent); - Intent allintent = new Intent(new IntentName("sec.confidentiality/all"), null); - allintent.addAppliedArtifacts(WS_BINDING); - - assertTrue(intentReg.isQualifiedIntent(new IntentName("sec.confidentiality/transport"))); - assertTrue(intentReg.isQualifiedIntent(new IntentName("sec.confidentiality/message/body"))); - assertTrue(intentReg.isQualifiedIntent(new IntentName("sec.confidentiality/message/body"))); - assertFalse(intentReg.isQualifiedIntent(new IntentName("sec.confidentiality/message"))); - assertFalse(intentReg.isQualifiedIntent(new IntentName("sec.confidentiality"))); - } - - public void testUnRegister() { - Intent messageintent = new Intent(new IntentName("sec.confidentiality/transport"), null); - messageintent.addAppliedArtifacts(WS_BINDING); - messageintent.addAppliedArtifacts(JMS_BINDING); - intentReg.register(messageintent); - intentReg.unRegister(messageintent); - assertFalse(intentReg.isApplicable(new IntentName("sec.confidentiality/transport"), WS_BINDING)); - assertFalse(intentReg.isApplicable(new IntentName("sec.confidentiality/transport"), JMS_BINDING)); - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/PolicyEngineImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/PolicyEngineImplTestCase.java deleted file mode 100644 index afb8981951..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/policy/PolicyEngineImplTestCase.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.policy; - -import java.io.InputStream; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import javax.xml.namespace.QName; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamReader; - -import static org.osoa.sca.Constants.SCA_NS; - -import org.apache.tuscany.spi.model.Intent; -import org.apache.tuscany.spi.model.IntentName; -import org.apache.tuscany.spi.model.PolicyModel; -import org.apache.tuscany.spi.model.PolicySet; -import org.apache.tuscany.spi.policy.IntentRegistry; -import org.apache.tuscany.spi.policy.PolicyEngine; -import org.apache.tuscany.spi.policy.PolicySetContainer; -import org.apache.tuscany.spi.policy.SCATypeManager; - -import junit.framework.TestCase; -import org.apache.tuscany.core.loader.PolicySetLoader; - -public class PolicyEngineImplTestCase extends TestCase { - private static final QName POLICYSET = new QName(SCA_NS, "policySet"); - private static final QName WS_BINDING = new QName(SCA_NS, "binding.ws"); - private IntentRegistry intentReg; - private PolicyEngine policyEngine; - - - public void testgetPolicy() throws Exception { - Collection<PolicyModel> policies = - policyEngine.getPolicy(new IntentName[]{new IntentName("sec.authentication/cert")}, null, WS_BINDING); - assertEquals(2, policies.size()); - policies = - policyEngine.getPolicy(new IntentName[]{new IntentName("sec.authentication/basic")}, null, WS_BINDING); - assertEquals(1, policies.size()); - - //test for unqualified intent with default value on intentMap - policies = policyEngine.getPolicy(new IntentName[]{new IntentName("sec.authentication")}, null, WS_BINDING); - assertEquals(2, policies.size()); - } - - @Override - protected void setUp() throws Exception { - PolicySetLoader loader = new PolicySetLoader(null); - XMLInputFactory factory = XMLInputFactory.newInstance(); - InputStream resourceAsStream = this.getClass().getResourceAsStream("PolicySet.scdl"); - XMLStreamReader reader = factory.createXMLStreamReader(resourceAsStream); - PolicySetContainerImpl psc = new PolicySetContainerImpl(); - while (true) { - int state = reader.next(); - if (state == XMLStreamConstants.END_DOCUMENT) { - break; - } - if (XMLStreamConstants.START_ELEMENT == state && reader.getName().equals(POLICYSET)) { - psc.addPolicySet(loader.load(null, null, reader, null)); - } - - } - resourceAsStream.close(); - intentReg = new IntentRegistryImpl(); - policyEngine = new PolicyEngineImpl(intentReg, psc, new SCATypeManagerImpl()); - - Intent bodyintent = new Intent(new IntentName("sec.confidentiality/message/body"), "test"); - bodyintent.addAppliedArtifacts(WS_BINDING); - intentReg.register(bodyintent); - - Intent allintent = new Intent(new IntentName("sec.confidentiality/message/all"), "test"); - allintent.addAppliedArtifacts(WS_BINDING); - intentReg.register(allintent); - - Intent confidentialityintent = new Intent(new IntentName("sec.confidentiality"), "test"); - confidentialityintent.addAppliedArtifacts(WS_BINDING); - intentReg.register(confidentialityintent); - - Intent messageintent = new Intent(new IntentName("sec.confidentiality/message"), null); - messageintent.addAppliedArtifacts(WS_BINDING); - intentReg.register(messageintent); - - Intent authintent = new Intent(new IntentName("sec.authentication"), null); - authintent.addAppliedArtifacts(WS_BINDING); - intentReg.register(authintent); - - Intent certintent = new Intent(new IntentName("sec.authentication/cert"), null); - certintent.addAppliedArtifacts(WS_BINDING); - intentReg.register(certintent); - - Intent basicintent = new Intent(new IntentName("sec.authentication/basic"), null); - basicintent.addAppliedArtifacts(WS_BINDING); - intentReg.register(basicintent); - - } - - private class PolicySetContainerImpl implements PolicySetContainer { - - private Map<QName, PolicySet> sets = new HashMap<QName, PolicySet>(); - - public Collection<PolicySet> getAllPolicySet() { - return sets.values(); - } - - public PolicySet getPolicySet(QName name) { - return sets.get(name); - } - - public void addPolicySet(PolicySet pset) { - sets.put(pset.getName(), pset); - } - - } - - private class SCATypeManagerImpl implements SCATypeManager { - - public boolean isTypeOf(QName subType, QName type) { - return subType.equals(type); - } - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/property/PropertyHelperTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/property/PropertyHelperTestCase.java deleted file mode 100644 index 5ddd0b32ce..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/property/PropertyHelperTestCase.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.core.property; - -import java.net.URL; -import javax.xml.namespace.NamespaceContext; - -import org.w3c.dom.Document; -import org.w3c.dom.Node; - -import org.apache.tuscany.spi.deployer.DeploymentContext; - -import junit.framework.TestCase; -import org.apache.tuscany.core.databinding.xml.String2Node; -import org.easymock.EasyMock; - -/** - * - */ -public class PropertyHelperTestCase extends TestCase { - private static final String IPO_XML = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<ipo:purchaseOrder" - + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" - + " xmlns:ipo=\"http://www.example.com/IPO\"" - + " xsi:schemaLocation=\"http://www.example.com/IPO ipo.xsd\"" - + " orderDate=\"1999-12-01\">" - + " <shipTo exportCode=\"1\" xsi:type=\"ipo:UKAddress\">" - + " <name>Helen Zoe</name>" - + " <street>47 Eden Street</street>" - + " <city>Cambridge</city>" - + " <postcode>CB1 1JR</postcode>" - + " </shipTo>" - + " <billTo xsi:type=\"ipo:USAddress\">" - + " <name>Robert Smith</name>" - + " <street>8 Oak Avenue</street>" - + " <city>Old Town</city>" - + " <state>PA</state>" - + " <zip>95819</zip>" - + " </billTo>" - + " <items>" - + " <item partNum=\"833-AA\">" - + " <productName>Lapis necklace</productName>" - + " <quantity>1</quantity>" - + " <USPrice>99.95</USPrice>" - + " <ipo:comment>Want this for the holidays</ipo:comment>" - + " <shipDate>1999-12-05</shipDate>" - + " </item>" - + " </items>" - + "</ipo:purchaseOrder>"; - - /** - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - } - - public void testXPath() throws Exception { - String2Node t = new String2Node(); - Node node = t.transform(IPO_XML, null); - - Document doc = PropertyHelper.evaluate(null, node, "/ipo:purchaseOrder/billTo"); - assertNotNull(doc); - - NamespaceContext context = EasyMock.createMock(NamespaceContext.class); - EasyMock.expect(context.getNamespaceURI("ipo")).andReturn("http://www.example.com/IPO").anyTimes(); - EasyMock.replay(context); - doc = PropertyHelper.evaluate(context, node, "/ipo:purchaseOrder/items"); - assertNotNull(doc); - doc = PropertyHelper.evaluate(context, node, "/ipo:purchaseOrder/billTo"); - assertNotNull(doc); - doc = PropertyHelper.evaluate(context, node, "/"); - assertNotNull(doc); - doc = PropertyHelper.evaluate(context, node, "/ipo:purchaseOrder/billTo1"); - assertNull(doc); - } - - public void testFile() throws Exception { - URL url = getClass().getResource("ipo.xml"); - Document doc = PropertyHelper.loadFromFile(url.toExternalForm(), null); - assertNotNull(doc); - - DeploymentContext context = EasyMock.createMock(DeploymentContext.class); - EasyMock.expect(context.getClassLoader()).andReturn(getClass().getClassLoader()); - EasyMock.replay(context); - doc = PropertyHelper.loadFromFile("org/apache/tuscany/core/property/ipo.xml", context); - assertNotNull(doc); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/property/SimplePropertyObjectFactoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/property/SimplePropertyObjectFactoryTestCase.java deleted file mode 100644 index ef67533a0a..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/property/SimplePropertyObjectFactoryTestCase.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.property; - -import java.util.ArrayList; -import java.util.List; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import org.apache.tuscany.spi.ObjectFactory; -import org.apache.tuscany.spi.model.Property; -import org.apache.tuscany.spi.model.PropertyValue; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class SimplePropertyObjectFactoryTestCase extends TestCase { - - private <T> PropertyValue<T> mock(String value) { - Document document = EasyMock.createMock(Document.class); - Element element = EasyMock.createMock(Element.class); - //EasyMock.expect(document.getDocumentElement()).andReturn(element); - EasyMock.expect(element.getTextContent()).andReturn(value); - EasyMock.replay(document, element); - - List<Element> valueList = new ArrayList<Element>(); - valueList.add(element); - return new PropertyValue<T>(null, valueList); - } - - public void testInteger() throws Exception { - - PropertyObjectFactoryImpl factory = new PropertyObjectFactoryImpl(); - Property<Integer> property = new Property<Integer>(); - property.setJavaType(Integer.class); - PropertyValue<Integer> propertyValue = mock("1"); - ObjectFactory<Integer> oFactory = factory.createObjectFactory(property, propertyValue); - assertEquals(1, oFactory.getInstance().intValue()); - } - - public void testPrimitiveInt() throws Exception { - PropertyObjectFactoryImpl factory = new PropertyObjectFactoryImpl(); - Property<Integer> property = new Property<Integer>(); - property.setJavaType(Integer.TYPE); - PropertyValue<Integer> propertyValue = mock("1"); - ObjectFactory<Integer> oFactory = factory.createObjectFactory(property, propertyValue); - assertEquals(1, oFactory.getInstance().intValue()); - } - - public void testString() throws Exception { - PropertyObjectFactoryImpl factory = new PropertyObjectFactoryImpl(); - Property<String> property = new Property<String>(); - property.setJavaType(String.class); - PropertyValue<String> propertyValue = mock("1"); - ObjectFactory<String> oFactory = factory.createObjectFactory(property, propertyValue); - assertEquals("1", oFactory.getInstance()); - } - - public void testByteArray() throws Exception { - PropertyObjectFactoryImpl factory = new PropertyObjectFactoryImpl(); - Property<byte[]> property = new Property<byte[]>(); - property.setJavaType(byte[].class); - PropertyValue<byte[]> propertyValue = mock("TWFu"); // BASE64 for "Man" - ObjectFactory<byte[]> oFactory = factory.createObjectFactory(property, propertyValue); - byte[] result = oFactory.getInstance(); - byte[] expected = "Man".getBytes(); - for (int i = 0; i < result.length; i++) { - byte b = result[i]; - if (b != expected[i]) { - fail(); - } - } - } - - public void testBoolean() throws Exception { - PropertyObjectFactoryImpl factory = new PropertyObjectFactoryImpl(); - Property<Boolean> property = new Property<Boolean>(); - property.setJavaType(Boolean.class); - PropertyValue<Boolean> propertyValue = mock("true"); - ObjectFactory<Boolean> oFactory = factory.createObjectFactory(property, propertyValue); - assertTrue(oFactory.getInstance()); - } - - public void testPrimitiveBoolean() throws Exception { - PropertyObjectFactoryImpl factory = new PropertyObjectFactoryImpl(); - Property<Boolean> property = new Property<Boolean>(); - property.setJavaType(Boolean.TYPE); - PropertyValue<Boolean> propertyValue = mock("true"); - ObjectFactory<Boolean> oFactory = factory.createObjectFactory(property, propertyValue); - assertTrue(oFactory.getInstance()); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/artifact/LocalMavenRepositoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/artifact/LocalMavenRepositoryTestCase.java deleted file mode 100644 index 0efecb9302..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/artifact/LocalMavenRepositoryTestCase.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.services.artifact; - -import java.io.File; -import java.io.UnsupportedEncodingException; -import java.net.MalformedURLException; -import java.net.URL; - -import junit.framework.TestCase; - -import org.apache.tuscany.spi.services.artifact.Artifact; - -/** - * This testcase assumes that there is a maven repo in the default location. - * - * @version $Rev$ $Date$ - */ -public class LocalMavenRepositoryTestCase extends TestCase { - private static final String VERSION = "3.8.1"; - private LocalMavenRepository repo; - private Artifact artifact; - private String path; - - public void testPathWithNoClassifier() { - assertEquals(path, repo.getPath(artifact)); - } - - public void testPathWithClassifier() { - artifact.setClassifier("x86"); - path = "junit/junit/" + VERSION + "/junit-" + VERSION + "-x86.jar"; - assertEquals(path, repo.getPath(artifact)); - } - - public void testArtifactFoundInRepo() throws MalformedURLException, UnsupportedEncodingException { - String home = System.getProperty("user.home"); - File file = new File(home + "/.m2/repository", path); - repo.resolve(artifact); - assertEquals(file.toURI().toURL(), artifact.getUrl()); - } - - public void testArtifactNotFoundInRepo() throws MalformedURLException { - artifact.setClassifier("x86"); - repo.resolve(artifact); - assertNull(artifact.getUrl()); - } - - public void testNonNullURLIsUnmodified() throws MalformedURLException { - URL url = new URL("http://www.apache.org"); - artifact.setUrl(url); - repo.resolve(artifact); - assertSame(url, artifact.getUrl()); - } - - protected void setUp() throws Exception { - super.setUp(); - repo = new LocalMavenRepository(".m2/repository"); - - artifact = new Artifact(); - artifact.setGroup("junit"); - artifact.setName("junit"); - artifact.setVersion(VERSION); - artifact.setType("jar"); - path = "junit/junit/" + VERSION + "/junit-" + VERSION + ".jar"; - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/AssemblyServiceImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/AssemblyServiceImplTestCase.java deleted file mode 100644 index fb1daf7e5f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/AssemblyServiceImplTestCase.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.services.deployment; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.net.URLConnection; -import java.net.URLStreamHandler; - -import junit.framework.TestCase; -import org.easymock.classextension.EasyMock; - -import org.apache.tuscany.host.deployment.UnsupportedContentTypeException; - -/** - * @version $Rev$ $Date$ - */ -public class AssemblyServiceImplTestCase extends TestCase { - private AssemblyServiceImpl service; - - public void testApplyChangesWithNullURL() { - try { - service.applyChanges(null); - fail(); - } catch (IllegalArgumentException e) { - //ok - } catch (Throwable t) { - fail(); - } - } - - public void testApplyChangesWhenURLContentTypeIsNull() throws Exception { - final URLConnection urlConnection = EasyMock.createMock(URLConnection.class); - EasyMock.expect(urlConnection.getContentType()).andReturn(null); - EasyMock.replay(urlConnection); - URLStreamHandler handler = new MockURLStreamHandler(urlConnection); - - URL url = new URL(null, "file:/tmp/foo.xml", handler); - try { - service.applyChanges(url); - } catch (UnsupportedContentTypeException e) { - assertNull(e.getMessage()); - assertEquals(url.toString(), e.getIdentifier()); - EasyMock.verify(urlConnection); - } catch (Throwable t) { - fail(); - } - } - - public void testApplyChangesWithNullStream() { - try { - service.applyChanges(null, "xxx/xxx"); - fail(); - } catch (IllegalArgumentException e) { - //ok - } catch (Throwable t) { - fail(); - } - } - - public void testApplyChangesWithNullContentType() { - InputStream is = EasyMock.createMock(InputStream.class); - EasyMock.replay(is); - try { - service.applyChanges(is, null); - fail(); - } catch (IllegalArgumentException e) { - EasyMock.verify(is); - } catch (Throwable t) { - fail(); - } - } - - protected void setUp() throws Exception { - super.setUp(); - service = new AssemblyServiceImpl(null, null); - } - - private static class MockURLStreamHandler extends URLStreamHandler { - private final URLConnection urlConnection; - - public MockURLStreamHandler(URLConnection urlConnection) { - this.urlConnection = urlConnection; - } - - protected URLConnection openConnection(URL url) throws IOException { - return urlConnection; - } - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContentTypeDescriberImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContentTypeDescriberImplTestCase.java deleted file mode 100644 index 8bb800962f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContentTypeDescriberImplTestCase.java +++ /dev/null @@ -1,52 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tuscany.core.services.deployment;
-
-import java.net.URL;
-
-import junit.framework.TestCase;
-
-import org.apache.tuscany.spi.deployer.ContentType;
-
-public class ContentTypeDescriberImplTestCase extends TestCase {
- private ContentTypeDescriberImpl contentTypeBuilder;
-
- public void testResolveContentType() throws Exception {
- URL artifactURL = getClass().getResource("test.scdl");
- assertEquals(ContentType.COMPOSITE, contentTypeBuilder.getContentType(artifactURL, null));
- }
-
-
- public void testUnknownResolveContentType() throws Exception {
- URL artifactURL = getClass().getResource("test.ext");
- assertNull(contentTypeBuilder.getContentType(artifactURL, null));
- }
-
- public void testDefaultContentType() throws Exception {
- URL artifactURL = getClass().getResource("test.ext");
- assertEquals("application/vnd.tuscany.ext",
- contentTypeBuilder.getContentType(artifactURL, "application/vnd.tuscany.ext"));
- }
-
- protected void setUp() throws Exception {
- super.setUp();
- contentTypeBuilder = new ContentTypeDescriberImpl();
- }
-
-}
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionLoaderTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionLoaderTestCase.java deleted file mode 100644 index 85e959cb87..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionLoaderTestCase.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.core.services.deployment; - -import java.io.StringReader; - -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.spi.loader.InvalidValueException; -import org.apache.tuscany.spi.model.Contribution; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class ContributionLoaderTestCase extends TestCase { - - private static final String VALID_XML = - "<?xml version=\"1.0\" encoding=\"ASCII\"?>" - + "<contribution xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns=\"http://ns\">" - + "<deployable composite=\"ns:Composite1\"/>" - + "<deployable composite=\"ns:Composite2\"/>" - + "<import namespace=\"http://ns2\" location=\"sca://contributions/002/\"/>" - + "<export namespace=\"http://ns1\"/>" - + "</contribution>"; - - private static final String INVALID_XML = - "<?xml version=\"1.0\" encoding=\"ASCII\"?>" - + "<contribution xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns=\"http://ns\">" - + "<deployable composite=\"ns:Composite1\"/>" - + "<deployable composite=\"ns3:Composite1\"/>" - + "<import namespace=\"http://ns2\" location=\"sca://contributions/002/\"/>" - + "<export namespace=\"http://ns1\"/>" - + "</contribution>"; - - private XMLInputFactory factory; - - protected void setUp() throws Exception { - super.setUp(); - factory = XMLInputFactory.newInstance(); - } - - public void testLoad() throws Exception { - XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(VALID_XML)); - ContributionLoader loader = new ContributionLoader(null); - Contribution contribution = loader.load(null, null, reader, null); - assertNotNull(contribution); - assertEquals(1, contribution.getImports().size()); - assertEquals(1, contribution.getExports().size()); - assertEquals(2, contribution.getDeployables().size()); - } - - public void testLoadInvalid() throws Exception { - XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(INVALID_XML)); - ContributionLoader loader = new ContributionLoader(null); - try { - loader.load(null, null, reader, null); - fail("InvalidException should have been thrown"); - } catch (InvalidValueException e) { - assertTrue(true); - } - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryTestCase.java deleted file mode 100644 index 0641520b3c..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionRepositoryTestCase.java +++ /dev/null @@ -1,76 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.tuscany.core.services.deployment;
-
-import java.io.File;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URL;
-
-import org.apache.tuscany.core.util.FileHelper;
-
-import junit.framework.TestCase;
-
-public class ContributionRepositoryTestCase extends TestCase {
- private ContributionRepositoryImpl repository;
-
- protected void setUp() throws Exception {
- super.setUp();
- // create repository (this should re-create the root directory)
- this.repository = new ContributionRepositoryImpl("target/repository/");
- repository.init();
- }
-
- public void testStore() throws Exception {
- String resourceLocation = "/repository/sample-calculator.jar";
- URI contribution = URI.create("sample-calculator.jar");
- InputStream contributionStream = getClass().getResourceAsStream(resourceLocation);
- repository.store(contribution, contributionStream);
-
- URL contributionURL = repository.find(contribution);
- assertNotNull(contributionURL);
- }
-
- public void testRemove() throws Exception {
- String resourceLocation = "/repository/sample-calculator.jar";
- URI contribution = URI.create("sample-calculator.jar");
- InputStream contributionStream = getClass().getResourceAsStream(resourceLocation);
- repository.store(contribution, contributionStream);
-
- repository.remove(contribution);
- URL contributionURL = repository.find(contribution);
- assertNull(contributionURL);
- }
-
- public void testList() throws Exception {
- String resourceLocation = "/repository/sample-calculator.jar";
- URI contribution = URI.create("sample-calculator.jar");
- InputStream contributionStream = getClass().getResourceAsStream(resourceLocation);
- repository.store(contribution, contributionStream);
-
- assertEquals(1, repository.list().size());
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- FileHelper.deleteDirectory(new File("target/repository"));
- }
-}
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionServiceImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionServiceImplTestCase.java deleted file mode 100644 index 12c629f8a2..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/ContributionServiceImplTestCase.java +++ /dev/null @@ -1,72 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.tuscany.core.services.deployment;
-
-import java.net.URI;
-import java.net.URL;
-
-import junit.framework.TestCase;
-
-import org.apache.tuscany.core.services.deployment.contribution.JarContributionProcessor;
-import org.apache.tuscany.core.services.deployment.contribution.JavaContributionProcessor;
-import org.apache.tuscany.host.deployment.ContributionService;
-import org.apache.tuscany.spi.deployer.ContentTypeDescriber;
-import org.apache.tuscany.spi.deployer.ContributionProcessorRegistry;
-import org.apache.tuscany.spi.deployer.ContributionRepository;
-
-/**
- * This is more intended to be a integration test then a unit test. *
- */
-public class ContributionServiceImplTestCase extends TestCase {
- private static final String JAR_CONTRIBUTION = "/repository/sample-calculator.jar";
- private ContributionRepository repository;
- private ContentTypeDescriber contentTypeDescriber;
- private ContributionProcessorRegistry registry;
- private ContributionService contributionService;
-
- protected void setUp() throws Exception {
- super.setUp();
-
-// this.repository = new ContributionRepositoryImpl("target/repository");
-//
-// this.contentTypeDescriber = new ContentTypeDescriberImpl();
-//
-// this.registry = new ContributionProcessorRegistryImpl(contentTypeDescriber);
-//
-// JarContributionProcessor jarProcessor = new JarContributionProcessor();
-// jarProcessor.setContributionProcessorRegistry(this.registry);
-// this.registry.register(JarContributionProcessor.CONTENT_TYPE, jarProcessor);
-//
-// JavaContributionProcessor javaProcessor = new JavaContributionProcessor(null);
-// javaProcessor.setContributionProcessorRegistry(this.registry);
-// this.registry.register(JavaContributionProcessor.CONTENT_TYPE, javaProcessor);
-//
-//
-// contributionService = new ContributionServiceImpl(repository, registry);
- }
-
- public void testContributeURL() throws Exception {
-// URL contribution = getClass().getResource(JAR_CONTRIBUTION);
-//
-// URI contributionURI = contributionService.contribute(contribution);
-// assertNotNull(contributionURI);
- }
-
-}
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/CompositeContributionProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/CompositeContributionProcessorTestCase.java deleted file mode 100644 index 5d0b3227e8..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/CompositeContributionProcessorTestCase.java +++ /dev/null @@ -1,84 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tuscany.core.services.deployment.contribution;
-
-import java.net.URL;
-import java.util.jar.JarEntry;
-import java.util.jar.JarInputStream;
-
-import junit.framework.TestCase;
-
-import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
-import org.apache.tuscany.core.implementation.IntrospectionRegistryImpl;
-import org.apache.tuscany.core.implementation.processor.DestroyProcessor;
-import org.apache.tuscany.core.implementation.processor.ImplementationProcessorServiceImpl;
-import org.apache.tuscany.core.implementation.processor.InitProcessor;
-import org.apache.tuscany.core.implementation.processor.PropertyProcessor;
-import org.apache.tuscany.core.implementation.processor.ReferenceProcessor;
-import org.apache.tuscany.core.implementation.processor.ResourceProcessor;
-import org.apache.tuscany.core.implementation.processor.ScopeProcessor;
-import org.apache.tuscany.core.monitor.NullMonitorFactory;
-import org.apache.tuscany.spi.deployer.ContributionProcessor;
-import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService;
-
-public class CompositeContributionProcessorTestCase extends TestCase {
- private static final String CONTRIBUTION = "/repository/sample-calculator.jar";
- private static final String ARTIFACT_URL = "/META-INF/sca/default.scdl";
- private IntrospectionRegistryImpl registry;
-
- protected void setUp() throws Exception {
- super.setUp();
- registry = new IntrospectionRegistryImpl();
- registry.setMonitor(new NullMonitorFactory().getMonitor(IntrospectionRegistryImpl.Monitor.class));
- registry.registerProcessor(new DestroyProcessor());
- registry.registerProcessor(new InitProcessor());
- registry.registerProcessor(new ScopeProcessor());
- JavaInterfaceProcessorRegistryImpl interfaceProcessorRegistry = new JavaInterfaceProcessorRegistryImpl();
- ImplementationProcessorService service = new ImplementationProcessorServiceImpl(interfaceProcessorRegistry);
- registry.registerProcessor(new PropertyProcessor(service));
- registry.registerProcessor(new ReferenceProcessor(interfaceProcessorRegistry));
- registry.registerProcessor(new ResourceProcessor());
- }
-
- protected URL getArtifactURL() throws Exception {
- URL jarURL = getClass().getResource(CONTRIBUTION);
- JarInputStream jar = new JarInputStream(getClass().getResourceAsStream(CONTRIBUTION));
- URL rootURL = new URL("jar:" + jarURL.toString() + "!/");
- URL classURL = null;
-
- try {
- while (true) {
- JarEntry entry = jar.getNextJarEntry();
- if (entry.getName().endsWith(".class")) {
- classURL = new URL(rootURL, entry.getName());
- break;
- }
- }
- } finally {
- jar.close();
- }
- return classURL;
- }
-
- public final void testProcessScdl() throws Exception {
- //ContributionProcessor scdlContributionProcessor = new scdlContributionProcessor(registry);
- //URL jarURL = this.getClassURL();
- //javaContributionProcessor.processContent(null, jarURL, jarURL.openStream());
- }
-}
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/FolderContributionProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/FolderContributionProcessorTestCase.java deleted file mode 100644 index f6db2e8b7e..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/FolderContributionProcessorTestCase.java +++ /dev/null @@ -1,56 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tuscany.core.services.deployment.contribution;
-
-import java.io.File;
-import java.net.URI;
-import java.net.URL;
-
-import junit.framework.TestCase;
-
-import org.apache.tuscany.spi.deployer.ContributionProcessorRegistry;
-import org.apache.tuscany.spi.model.Contribution;
-import org.easymock.EasyMock;
-
-public class FolderContributionProcessorTestCase extends TestCase {
- private static final String DIRECTORY_CONTRIBUTION = "//D:/DEV/Projects/Tuscany/source/java-sca-integration/samples/sca/calculator";
-
- private File contributionRoot;
-
-
- protected void setUp() throws Exception {
- super.setUp();
- this.contributionRoot = new File(DIRECTORY_CONTRIBUTION);
- }
-
- public final void testProcessJarArtifacts() throws Exception {
-// FolderContributionProcessor folderContribution = new FolderContributionProcessor();
-// ContributionProcessorRegistry mockRegistry = EasyMock.createMock(ContributionProcessorRegistry.class);
-// mockRegistry.register(FolderContributionProcessor.CONTENT_TYPE, folderContribution);
-// EasyMock.expectLastCall().anyTimes();
-// EasyMock.replay(mockRegistry);
-// folderContribution.setContributionProcessorRegistry(mockRegistry);
-// folderContribution.start();
-// EasyMock.verify(mockRegistry);
-//
-// Contribution contribution = new Contribution(URI.create("sca://contributions/001"));
-// contribution.setLocation(this.contributionRoot.toURL());
-// folderContribution.processContent(contribution, contribution.getUri(), null);
- }
-}
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JarContributionProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JarContributionProcessorTestCase.java deleted file mode 100644 index 06ccd6c3da..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JarContributionProcessorTestCase.java +++ /dev/null @@ -1,53 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tuscany.core.services.deployment.contribution;
-
-import java.net.URI;
-import java.net.URL;
-
-import junit.framework.TestCase;
-
-import org.apache.tuscany.spi.deployer.ContributionProcessorRegistry;
-import org.apache.tuscany.spi.model.Contribution;
-import org.easymock.EasyMock;
-
-public class JarContributionProcessorTestCase extends TestCase {
- private static final String JAR_CONTRIBUTION = "/repository/sample-calculator.jar";
-
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- public final void testProcessJarArtifacts() throws Exception {
- /*
- JarContributionProcessor jarContribution = new JarContributionProcessor();
- ContributionProcessorRegistry mockRegistry = EasyMock.createMock(ContributionProcessorRegistry.class);
- mockRegistry.register(JarContributionProcessor.CONTENT_TYPE, jarContribution);
- EasyMock.expectLastCall().once();
- EasyMock.replay(mockRegistry);
- jarContribution.setContributionProcessorRegistry(mockRegistry);
- jarContribution.start();
- EasyMock.verify(mockRegistry);
- URL jarURL = getClass().getResource(JarContributionProcessorTestCase.JAR_CONTRIBUTION);
- Contribution contribution = new Contribution(URI.create("sca://contributions/001"));
- contribution.setLocation(jarURL);
- jarContribution.processContent(contribution, contribution.getUri(), jarURL.openStream());
- */
- }
-}
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JavaContributionProcessorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JavaContributionProcessorTestCase.java deleted file mode 100644 index 269e2e6feb..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/deployment/contribution/JavaContributionProcessorTestCase.java +++ /dev/null @@ -1,79 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tuscany.core.services.deployment.contribution;
-
-import java.net.URI;
-import java.net.URL;
-
-import junit.framework.TestCase;
-
-import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl;
-import org.apache.tuscany.core.implementation.IntrospectionRegistryImpl;
-import org.apache.tuscany.core.implementation.processor.DestroyProcessor;
-import org.apache.tuscany.core.implementation.processor.ImplementationProcessorServiceImpl;
-import org.apache.tuscany.core.implementation.processor.InitProcessor;
-import org.apache.tuscany.core.implementation.processor.PropertyProcessor;
-import org.apache.tuscany.core.implementation.processor.ReferenceProcessor;
-import org.apache.tuscany.core.implementation.processor.ResourceProcessor;
-import org.apache.tuscany.core.implementation.processor.ScopeProcessor;
-import org.apache.tuscany.core.monitor.NullMonitorFactory;
-import org.apache.tuscany.spi.deployer.ContributionProcessor;
-import org.apache.tuscany.spi.implementation.java.ImplementationProcessorService;
-import org.apache.tuscany.spi.model.Contribution;
-import org.apache.tuscany.spi.model.DeployedArtifact;
-
-public class JavaContributionProcessorTestCase extends TestCase {
- private static final String CONTRIBUTION = "/repository/sample-calculator.jar";
- private static final String JAVA_ARTIFACT = "calculator/AddService.class";
- private IntrospectionRegistryImpl registry;
- private URI contributionId;
- private Contribution contribution;
-
- protected void setUp() throws Exception {
- super.setUp();
- registry = new IntrospectionRegistryImpl();
- registry.setMonitor(new NullMonitorFactory().getMonitor(IntrospectionRegistryImpl.Monitor.class));
- registry.registerProcessor(new DestroyProcessor());
- registry.registerProcessor(new InitProcessor());
- registry.registerProcessor(new ScopeProcessor());
- JavaInterfaceProcessorRegistryImpl interfaceProcessorRegistry = new JavaInterfaceProcessorRegistryImpl();
- ImplementationProcessorService service = new ImplementationProcessorServiceImpl(interfaceProcessorRegistry);
- registry.registerProcessor(new PropertyProcessor(service));
- registry.registerProcessor(new ReferenceProcessor(interfaceProcessorRegistry));
- registry.registerProcessor(new ResourceProcessor());
-
- contributionId = new URI("sca://contribution/001");
- contribution = new Contribution(contributionId);
- contribution.setLocation(getClass().getResource(CONTRIBUTION));
-
- DeployedArtifact classArtifact = new DeployedArtifact(contributionId);
- classArtifact.setLocation(this.getArtifactURL());
- }
-
- protected URL getArtifactURL() throws Exception {
- URL jarURL = getClass().getResource(CONTRIBUTION);
- return new URL("jar:" + jarURL.toString() + "!/" + JAVA_ARTIFACT);
- }
-
- public final void testProcessJavaArtifact() throws Exception {
- //ContributionProcessor javaContributionProcessor = new JavaContributionProcessor(registry);
- //URL artifactURL = this.getArtifactURL();
- //javaContributionProcessor.processContent(contribution, artifactURL.toURI(), artifactURL.openStream());
- }
-}
diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistryTestCase.java deleted file mode 100644 index c3eb2fa1bf..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/host/DelegatingResourceHostRegistryTestCase.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.services.host; - -import org.apache.tuscany.spi.host.ResourceHost; -import org.apache.tuscany.spi.host.ResourceResolutionException; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class DelegatingResourceHostRegistryTestCase extends TestCase { - - public void testResolveByType() throws Exception { - Object ret = new Object(); - DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry(); - registry.registerResource(Object.class, ret); - assertEquals(ret, registry.resolveResource(Object.class)); - } - - public void testResolveByUri() throws Exception { - ResourceHost host = EasyMock.createMock(ResourceHost.class); - EasyMock.expect(host.resolveResource(String.class, "Foo://foo")).andReturn("result"); - EasyMock.replay(host); - DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry(); - registry.registerResourceHost("Foo://", host); - assertEquals("result", registry.resolveResource(String.class, "Foo://foo")); - EasyMock.verify(host); - } - - public void testResolveBySCAUri() throws Exception { - ResourceHost host = EasyMock.createMock(ResourceHost.class); - EasyMock.replay(host); - DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry(); - registry.registerResourceHost("Foo://", host); - Object ret = new Object(); - registry.registerResource(Object.class, "foo", ret); - assertEquals(ret, registry.resolveResource(Object.class, "SCA://foo")); - EasyMock.verify(host); - } - - public void testResolveByUriNotFound() throws Exception { - ResourceHost host = EasyMock.createMock(ResourceHost.class); - EasyMock.replay(host); - DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry(); - registry.registerResourceHost("Foo://", host); - try { - assertEquals("result", registry.resolveResource(String.class, "Bar://bar")); - fail(); - } catch (ResourceResolutionException e) { - //expected - } - EasyMock.verify(host); - } - - public void testUnregisterHost() throws Exception { - ResourceHost host = EasyMock.createMock(ResourceHost.class); - EasyMock.replay(host); - DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry(); - registry.registerResourceHost("Foo://", host); - registry.unregisterResourceHost("Foo://"); - try { - registry.resolveResource(String.class, "Foo://foo"); - fail(); - } catch (ResourceResolutionException e) { - //expected - } - EasyMock.verify(host); - } - - public void testUnregisterResource() throws Exception { - DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry(); - registry.registerResource(Object.class, new Object()); - registry.unregisterResource(Object.class); - assertNull(registry.resolveResource(Object.class)); - } - - public void testUnregisterMappedResource() throws Exception { - DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry(); - registry.registerResource(Object.class, "foo", new Object()); - registry.registerResource(Object.class, new Object()); - registry.unregisterResource(Object.class); - assertNull(registry.resolveResource(Object.class)); - assertNotNull(registry.resolveResource(Object.class, "foo")); - registry.unregisterResource(Object.class, "foo"); - assertNull(registry.resolveResource(Object.class)); - } - - public void testReolvedByTypeToMappedResource() throws Exception { - DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry(); - registry.registerResource(Object.class, "foo", new Object()); - assertNull(registry.resolveResource(Object.class)); - } - - public void testDelegatingResolveResource() throws Exception { - Object ret = new Object(); - ResourceHost host = EasyMock.createMock(ResourceHost.class); - EasyMock.expect(host.resolveResource(Object.class)).andReturn(ret); - EasyMock.replay(host); - DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry(); - registry.registerResourceHost("Foo://", host); - assertEquals(ret, registry.resolveResource(Object.class)); - EasyMock.verify(host); - } - - public void testDelegatingResolveResourceByTypeandName() throws Exception { - Object ret = new Object(); - ResourceHost host = EasyMock.createMock(ResourceHost.class); - EasyMock.expect(host.resolveResource(EasyMock.eq(Object.class), EasyMock.eq("Foo://bar"))).andReturn(ret); - EasyMock.replay(host); - DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry(); - registry.registerResourceHost("Foo://", host); - assertEquals(ret, registry.resolveResource(Object.class, "Foo://bar")); - EasyMock.verify(host); - } - - public void testResolveLocalResourceFirst() throws Exception { - Object local = new Object(); - ResourceHost host = EasyMock.createMock(ResourceHost.class); - EasyMock.replay(host); - DelegatingResourceHostRegistry registry = new DelegatingResourceHostRegistry(); - registry.registerResourceHost("Foo://", host); - registry.registerResource(Object.class, local); - assertEquals(local, registry.resolveResource(Object.class)); - EasyMock.verify(host); - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/store/memory/MemoryStoreTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/store/memory/MemoryStoreTestCase.java deleted file mode 100644 index 5ec1643b47..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/store/memory/MemoryStoreTestCase.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.services.store.memory; - -import java.util.UUID; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.event.RuntimeEventListener; -import org.apache.tuscany.spi.services.store.DuplicateRecordException; -import org.apache.tuscany.spi.services.store.Store; -import org.apache.tuscany.spi.services.store.StoreExpirationEvent; -import org.apache.tuscany.spi.services.store.StoreMonitor; - -import junit.framework.TestCase; -import org.easymock.EasyMock; -import org.easymock.IAnswer; - -/** - * @version $Rev$ $Date$ - */ -public class MemoryStoreTestCase extends TestCase { - private StoreMonitor monitor; - - public void testEviction() throws Exception { - MemoryStore store = new MemoryStore(monitor); - store.setReaperInterval(10); - store.init(); - AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.replay(component); - String id = UUID.randomUUID().toString(); - Object value = new Object(); - store.insertRecord(component, id, value, 1); - Thread.sleep(100); - assertNull(store.readRecord(component, id)); - store.destroy(); - } - - public void testNotifyOnEviction() throws Exception { - final CountDownLatch latch = new CountDownLatch(1); - RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); - listener.onEvent(EasyMock.isA(StoreExpirationEvent.class)); - org.easymock.classextension.EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>() { - public Object answer() throws Throwable { - latch.countDown(); - return null; - } - }); - EasyMock.replay(listener); - MemoryStore store = new MemoryStore(monitor); - store.addListener(listener); - store.setReaperInterval(10); - store.init(); - AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.replay(component); - String id = UUID.randomUUID().toString(); - Object value = new Object(); - store.insertRecord(component, id, value, 1); - if (!latch.await(1000, TimeUnit.MILLISECONDS)) { - // failed to notify listener - fail(); - } - EasyMock.verify(listener); - } - - public void testNoEviction() throws Exception { - MemoryStore store = new MemoryStore(monitor); - store.setReaperInterval(10); - store.init(); - AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.replay(component); - String id = UUID.randomUUID().toString(); - Object value = new Object(); - store.insertRecord(component, id, value, Store.NEVER); - Thread.sleep(100); - assertNotNull(store.readRecord(component, id)); - store.destroy(); - } - - public void testInsertRecord() throws Exception { - MemoryStore store = new MemoryStore(monitor); - store.setReaperInterval(10); - store.init(); - AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.replay(component); - String id = UUID.randomUUID().toString(); - Object value = new Object(); - store.insertRecord(component, id, value, Store.NEVER); - store.destroy(); - } - - public void testInsertAlreadyExists() throws Exception { - MemoryStore store = new MemoryStore(monitor); - store.setReaperInterval(10); - store.init(); - AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.replay(component); - String id = UUID.randomUUID().toString(); - Object value = new Object(); - store.insertRecord(component, id, value, Store.NEVER); - try { - store.insertRecord(component, id, value, Store.NEVER); - fail(); - } catch (DuplicateRecordException e) { - //expected - } - store.destroy(); - } - - public void testUpdateRecord() throws Exception { - MemoryStore store = new MemoryStore(monitor); - store.setReaperInterval(10); - store.init(); - AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.replay(component); - String id = UUID.randomUUID().toString(); - Object value = new Object(); - Object newValue = new Object(); - - store.insertRecord(component, id, value, Store.NEVER); - store.updateRecord(component, id, newValue, 1L); - assertEquals(newValue, store.readRecord(component, id)); - store.destroy(); - } - - public void testDeleteRecord() throws Exception { - MemoryStore store = new MemoryStore(monitor); - store.setReaperInterval(10); - store.init(); - AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.replay(component); - String id = UUID.randomUUID().toString(); - Object value = new Object(); - - store.insertRecord(component, id, value, Store.NEVER); - store.removeRecord(component, id); - assertNull(store.readRecord(component, id)); - store.destroy(); - } - - protected void setUp() throws Exception { - super.setUp(); - monitor = EasyMock.createNiceMock(StoreMonitor.class); - EasyMock.replay(monitor); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTest.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTest.java deleted file mode 100644 index 1a5cb4ebe1..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.services.work.jsr237; - -import org.apache.tuscany.spi.services.work.NotificationListener; -import org.apache.tuscany.spi.services.work.WorkScheduler; - -import commonj.work.WorkManager; -import junit.framework.TestCase; -import org.apache.tuscany.core.services.work.jsr237.workmanager.ThreadPoolWorkManager; - -public class Jsr237WorkSchedulerTest extends TestCase { - - /* - * Test method for 'org.apache.tuscany.core.services.work.jsr237.Jsr237WorkScheduler.scheduleWork(T) <T>' - */ - public void testScheduleWorkT() { - - - WorkManager workManager = new ThreadPoolWorkManager(1); - WorkScheduler workScheduler = new Jsr237WorkScheduler(workManager); - - workScheduler.scheduleWork(new MyRunnable(), new MyNotificationListener()); - - } - - /* - * Test method for 'org.apache.tuscany.core.services.work.jsr237.Jsr237WorkScheduler.scheduleWork(T, - * NotificationListener<T>) <T>' - */ - public void testScheduleWorkTNotificationListenerOfT() { - - } - - private class MyRunnable implements Runnable { - public void run() { - System.err.println("Test executed"); - } - } - - private class MyNotificationListener implements NotificationListener<MyRunnable> { - - public void workAccepted(MyRunnable work) { - System.err.println("Work accepted"); - } - - public void workCompleted(MyRunnable work) { - System.err.println("Work completed"); - } - - public void workStarted(MyRunnable work) { - System.err.println("Work started"); - } - - public void workRejected(MyRunnable work) { - System.err.println("Work rejected"); - } - - public void workFailed(MyRunnable work, Throwable error) { - System.err.println("Work failed"); - } - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTestCase.java deleted file mode 100644 index 3966f65683..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/Jsr237WorkSchedulerTestCase.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.services.work.jsr237; - -import org.apache.tuscany.spi.services.work.NotificationListener; -import org.apache.tuscany.spi.services.work.WorkSchedulerException; - -import commonj.work.Work; -import commonj.work.WorkItem; -import commonj.work.WorkListener; -import commonj.work.WorkManager; -import commonj.work.WorkRejectedException; -import junit.framework.TestCase; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expectLastCall; -import static org.easymock.EasyMock.isA; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; - -/** - * @version $Rev$ $Date$ - */ -public class Jsr237WorkSchedulerTestCase extends TestCase { - - public void testSchedule() throws Exception { - WorkItem item = createMock(WorkItem.class); - WorkManager mgr = createMock(WorkManager.class); - mgr.schedule(isA(Work.class)); - expectLastCall().andReturn(item); - replay(mgr); - Jsr237WorkScheduler scheduler = new Jsr237WorkScheduler(mgr); - Work work = createMock(Work.class); - scheduler.scheduleWork(work); - verify(mgr); - } - - @SuppressWarnings("unchecked") - public void testListener() throws Exception { - WorkItem item = createMock(WorkItem.class); - WorkManager mgr = createMock(WorkManager.class); - mgr.schedule(isA(Work.class), isA(WorkListener.class)); - expectLastCall().andReturn(item); - replay(mgr); - Jsr237WorkScheduler scheduler = new Jsr237WorkScheduler(mgr); - Work work = createMock(Work.class); - NotificationListener<Runnable> listener = createMock(NotificationListener.class); - scheduler.scheduleWork(work, listener); - verify(mgr); - } - - @SuppressWarnings("unchecked") - public void testWorkRejectedListener() throws Exception { - WorkManager mgr = createMock(WorkManager.class); - mgr.schedule(isA(Work.class), isA(WorkListener.class)); - expectLastCall().andThrow(new WorkRejectedException()); - replay(mgr); - Jsr237WorkScheduler scheduler = new Jsr237WorkScheduler(mgr); - Work work = createMock(Work.class); - NotificationListener<Runnable> listener = createMock(NotificationListener.class); - listener.workRejected(isA(Runnable.class)); - expectLastCall(); - replay(listener); - scheduler.scheduleWork(work, listener); - verify(mgr); - } - - @SuppressWarnings("unchecked") - public void testWorkRejectedNoListener() throws Exception { - WorkManager mgr = createMock(WorkManager.class); - mgr.schedule(isA(Work.class)); - expectLastCall().andThrow(new WorkRejectedException()); - replay(mgr); - Jsr237WorkScheduler scheduler = new Jsr237WorkScheduler(mgr); - Work work = createMock(Work.class); - try { - scheduler.scheduleWork(work); - fail(); - } catch (WorkSchedulerException e) { - // expected - } - verify(mgr); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/workmanager/ThreadPoolWorkManagerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/workmanager/ThreadPoolWorkManagerTestCase.java deleted file mode 100644 index 33ecd66fdc..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/services/work/jsr237/workmanager/ThreadPoolWorkManagerTestCase.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.services.work.jsr237.workmanager; - -import java.util.concurrent.CountDownLatch; - -import commonj.work.Work; -import commonj.work.WorkEvent; -import commonj.work.WorkListener; -import junit.framework.TestCase; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.createStrictMock; -import static org.easymock.EasyMock.expectLastCall; -import static org.easymock.EasyMock.isA; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import org.easymock.IAnswer; - -/** - * @version $Rev$ $Date$ - */ -public class ThreadPoolWorkManagerTestCase extends TestCase { - - public void testSchedule() throws Exception { - final CountDownLatch latch = new CountDownLatch(1); - Work work = createMock(Work.class); - work.run(); - expectLastCall().andStubAnswer(new IAnswer<Object>() { - public Object answer() throws Throwable { - latch.countDown(); - return null; - } - }); - replay(work); - ThreadPoolWorkManager mgr = new ThreadPoolWorkManager(1); - mgr.schedule(work); - latch.await(); - verify(work); - } - - public void testListener() throws Exception { - final CountDownLatch latch = new CountDownLatch(1); - WorkListener listener = createStrictMock(WorkListener.class); - listener.workAccepted(isA(WorkEvent.class)); - listener.workStarted(isA(WorkEvent.class)); - listener.workCompleted(isA(WorkEvent.class)); - expectLastCall(); - replay(listener); - Work work = createMock(Work.class); - work.run(); - expectLastCall().andStubAnswer(new IAnswer<Object>() { - public Object answer() throws Throwable { - latch.countDown(); - return null; - } - }); - replay(work); - ThreadPoolWorkManager mgr = new ThreadPoolWorkManager(1); - mgr.schedule(work, listener); - latch.await(); - verify(work); - } - - public void testDelayListener() throws Exception { - final CountDownLatch latch = new CountDownLatch(1); - final CountDownLatch latch2 = new CountDownLatch(1); - WorkListener listener = createStrictMock(WorkListener.class); - listener.workAccepted(isA(WorkEvent.class)); - listener.workStarted(isA(WorkEvent.class)); - listener.workCompleted(isA(WorkEvent.class)); - expectLastCall().andStubAnswer(new IAnswer<Object>() { - public Object answer() throws Throwable { - latch2.countDown(); - return null; - } - }); - replay(listener); - Work work = createMock(Work.class); - work.run(); - expectLastCall().andStubAnswer(new IAnswer<Object>() { - public Object answer() throws Throwable { - latch.await(); - return null; - } - }); - replay(work); - ThreadPoolWorkManager mgr = new ThreadPoolWorkManager(1); - mgr.schedule(work, listener); - latch.countDown(); - verify(work); - } - - public void testErrorListener() throws Exception { - final CountDownLatch latch = new CountDownLatch(1); - WorkListener listener = createStrictMock(WorkListener.class); - listener.workAccepted(isA(WorkEvent.class)); - listener.workStarted(isA(WorkEvent.class)); - listener.workCompleted(isA(WorkEvent.class)); - replay(listener); - Work work = createMock(Work.class); - work.run(); - expectLastCall().andStubAnswer(new IAnswer<Object>() { - public Object answer() throws Throwable { - latch.countDown(); - throw new RuntimeException(); - } - }); - replay(work); - ThreadPoolWorkManager mgr = new ThreadPoolWorkManager(1); - mgr.schedule(work, listener); - latch.await(); - verify(work); - } - -} - diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/Bean1.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/Bean1.java deleted file mode 100644 index 79fad549aa..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/Bean1.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.util; - - -public class Bean1 extends SuperBean { - - public static final int ALL_BEAN1_FIELDS = 6 + ALL_SUPER_FIELDS; - public static final int ALL_BEAN1_PUBLIC_PROTECTED_FIELDS = 5 + ALL_SUPER_PUBLIC_PROTECTED_FIELDS; - public static final int ALL_BEAN1_METHODS = 4 + ALL_SUPER_METHODS - 1; - public String field3; - protected String field2; - private String field1; - - public void setMethod1(String param) { - } - - public void setMethod1(int param) { - } - - public void override(String param) throws Exception { - } - - - public void noOverride(String param) throws Exception { - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/Bean2.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/Bean2.java deleted file mode 100644 index 7f7f03da9e..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/Bean2.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.util; - -import java.util.List; - -import junit.framework.AssertionFailedError; - -public class Bean2 { - - private List methodList; - private List fieldList; - - public List getMethodList() { - return methodList; - } - - public void setMethodList(List list) { - methodList = list; - } - - public List getfieldList() { - return fieldList; - } - - public void setfieldList(List list) { - throw new AssertionFailedError("setter inadvertantly called"); - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/JavaIntrospectionHelperTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/JavaIntrospectionHelperTestCase.java deleted file mode 100644 index 797b147b54..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/JavaIntrospectionHelperTestCase.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.util; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import junit.framework.TestCase; -import org.apache.tuscany.core.mock.component.Target; - -public class JavaIntrospectionHelperTestCase extends TestCase { - - private List testNoGenericsList; - private List<String> testList; - private Map<String, Bean1> testMap; - private Target[] testArray; - private String[] testStringArray; - - public JavaIntrospectionHelperTestCase() { - super(); - } - - public JavaIntrospectionHelperTestCase(String arg0) { - super(arg0); - } - - public void testBean1AllPublicProtectedFields() throws Exception { - Set<Field> beanFields = JavaIntrospectionHelper.getAllPublicAndProtectedFields(Bean1.class); - assertEquals(4, beanFields.size()); //Bean1.ALL_BEAN1_PUBLIC_PROTECTED_FIELDS - } - - public void testGetSuperAllMethods() throws Exception { - Set<Method> superBeanMethods = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(SuperBean.class); - assertEquals(SuperBean.ALL_SUPER_METHODS, superBeanMethods.size()); - } - - public void testGetBean1AllMethods() throws Exception { - Set<Method> beanMethods = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(Bean1.class); - assertEquals(Bean1.ALL_BEAN1_METHODS, beanMethods.size()); - } - - public void testOverrideMethod() throws Exception { - Set<Method> beanFields = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(Bean1.class); - boolean invoked = false; - for (Method method : beanFields) { - if (method.getName().equals("override")) { - method.invoke(new Bean1(), "foo"); - invoked = true; - } - } - if (!invoked) { - throw new Exception("Override never invoked"); - } - } - - public void testNoOverrideMethod() throws Exception { - Set<Method> beanFields = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(Bean1.class); - boolean found = false; - for (Method method : beanFields) { - if (method.getName().equals("noOverride") && method.getParameterTypes().length == 0) { - found = true; - } - } - if (!found) { - throw new Exception("No override not found"); - } - } - - public void testDefaultConstructor() throws Exception { - Constructor ctr = JavaIntrospectionHelper.getDefaultConstructor(Bean2.class); - assertEquals(ctr, Bean2.class.getConstructor()); - assertTrue(Bean2.class == ctr.newInstance((Object[]) null).getClass()); - } - - - public void testGetAllInterfaces() { - Set<Class> interfaces = JavaIntrospectionHelper.getAllInterfaces(Z.class); - assertEquals(2, interfaces.size()); - assertTrue(interfaces.contains(W.class)); - assertTrue(interfaces.contains(W2.class)); - } - - - public void testGetAllInterfacesObject() { - Set<Class> interfaces = JavaIntrospectionHelper.getAllInterfaces(Object.class); - assertEquals(0, interfaces.size()); - } - - public void testGetAllInterfacesNoInterfaces() { - Set<Class> interfaces = JavaIntrospectionHelper.getAllInterfaces(NoInterface.class); - assertEquals(0, interfaces.size()); - } - - /** - * Tests generics introspection capabilities - */ - public void testGenerics() throws Exception { - - List classes = JavaIntrospectionHelper.getGenerics(getClass().getDeclaredField("testList").getGenericType()); - assertEquals(1, classes.size()); - assertEquals(String.class, classes.get(0)); - - classes = - JavaIntrospectionHelper.getGenerics(getClass().getDeclaredField("testNoGenericsList").getGenericType()); - assertEquals(0, classes.size()); - - classes = JavaIntrospectionHelper.getGenerics(getClass().getDeclaredField("testMap").getGenericType()); - assertEquals(2, classes.size()); - assertEquals(String.class, classes.get(0)); - assertEquals(Bean1.class, classes.get(1)); - - classes = JavaIntrospectionHelper - .getGenerics(getClass().getDeclaredMethod("fooMethod", Map.class).getGenericParameterTypes()[0]); - assertEquals(2, classes.size()); - assertEquals(String.class, classes.get(0)); - assertEquals(Bean1.class, classes.get(1)); - - classes = JavaIntrospectionHelper - .getGenerics(getClass().getDeclaredMethod("fooMethod", List.class).getGenericParameterTypes()[0]); - assertEquals(1, classes.size()); - assertEquals(String.class, classes.get(0)); - - } - - private void fooMethod(List<String> foo) { - - } - - private void fooMethod(Map<String, Bean1> foo) { - - } - - public void setTestArray(Target[] array) { - } - - private interface W { - - } - - private interface W2 { - - } - - private class X implements W { - - } - - private class Y extends X implements W, W2 { - - } - - private class Z extends Y { - - } - - private class NoInterface { - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/SuperBean.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/SuperBean.java deleted file mode 100644 index 83aef7fb5e..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/util/SuperBean.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.util; - -/** - * @version $Rev$ $Date$ - */ -public class SuperBean { - - public static final int ALL_SUPER_FIELDS = 6; - public static final int ALL_SUPER_PUBLIC_PROTECTED_FIELDS = 5; - public static final int ALL_SUPER_METHODS = 4; - public String superField2; - - protected String superField3; - - private String superField1; - - public void setSuperMethod1(String param) { - } - - public void setSuperMethod1(int param) { - } - - public void override(String param) throws Exception { - throw new Exception("Override not handled"); - } - - public void noOverride() throws Exception { - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/BasicReferenceInvocationHandlerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/BasicReferenceInvocationHandlerTestCase.java deleted file mode 100644 index b62741a7e7..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/BasicReferenceInvocationHandlerTestCase.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.wire; - -import java.lang.reflect.Method; - -import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -import org.apache.tuscany.core.mock.component.SimpleTarget; -import org.apache.tuscany.core.mock.component.SimpleTargetImpl; -import org.apache.tuscany.core.mock.wire.MockStaticInvoker; -import org.apache.tuscany.core.mock.wire.MockSyncInterceptor; -import org.apache.tuscany.core.wire.jdk.JDKOutboundInvocationHandler; - -/** - * @version $$Rev$$ $$Date$$ - */ -public class BasicReferenceInvocationHandlerTestCase extends TestCase { - - private Method echo; - - public void testInterceptorInvoke() throws Throwable { - JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - ServiceContract<?> contract = registry.introspect(SimpleTarget.class); - Operation<?> operation = contract.getOperations().get("echo"); - MockStaticInvoker invoker = new MockStaticInvoker(echo, new SimpleTargetImpl()); - OutboundInvocationChain chain = new OutboundInvocationChainImpl(operation); - MockSyncInterceptor interceptor = new MockSyncInterceptor(); - chain.addInterceptor(interceptor); - chain.setTargetInterceptor(new InvokerInterceptor()); - chain.setTargetInvoker(invoker); - chain.prepare(); - //chains.put(echo, chain); - OutboundWire wire = new OutboundWireImpl(); - wire.addInvocationChain(operation, chain); - wire.setServiceContract(contract); - JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(SimpleTarget.class, wire, null); - assertEquals("foo", handler.invoke(null, echo, new String[]{"foo"})); - assertEquals(1, interceptor.getCount()); - } - - public void setUp() throws Exception { - super.setUp(); - echo = SimpleTarget.class.getMethod("echo", String.class); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/CallbackInterfaceInterceptorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/CallbackInterfaceInterceptorTestCase.java deleted file mode 100644 index 6c50cb406f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/CallbackInterfaceInterceptorTestCase.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.wire; - -import org.osoa.sca.NoRegisteredCallbackException; - -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class CallbackInterfaceInterceptorTestCase extends TestCase { - - public void testOptimize() throws Exception { - CallbackInterfaceInterceptor interceptor = new CallbackInterfaceInterceptor(true); - assertFalse(interceptor.isOptimizable()); - } - - public void testImplements() { - CallbackInterfaceInterceptor interceptor = new CallbackInterfaceInterceptor(true); - Interceptor next = EasyMock.createMock(Interceptor.class); - EasyMock.expect(next.invoke(EasyMock.isA(Message.class))).andReturn(null); - EasyMock.replay(next); - interceptor.setNext(next); - interceptor.invoke(new MessageImpl()); - EasyMock.verify(next); - } - - public void testDoesNotImplement() { - CallbackInterfaceInterceptor interceptor = new CallbackInterfaceInterceptor(false); - try { - interceptor.invoke(new MessageImpl()); - fail(); - } catch (NoRegisteredCallbackException e) { - // expected - } - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java deleted file mode 100644 index d200b983b3..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java +++ /dev/null @@ -1,401 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.wire; - -import java.lang.reflect.Method; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.tuscany.spi.QualifiedName; -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.ReferenceBinding; -import org.apache.tuscany.spi.component.ServiceBinding; -import org.apache.tuscany.spi.model.ComponentDefinition; -import org.apache.tuscany.spi.model.DataType; -import org.apache.tuscany.spi.model.Operation; -import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.model.ServiceDefinition; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.IncompatibleServiceContractException; -import org.apache.tuscany.spi.wire.OutboundChainHolder; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.ProxyCreationException; -import org.apache.tuscany.spi.wire.Wire; -import org.apache.tuscany.spi.wire.WireInvocationHandler; -import org.apache.tuscany.spi.wire.WireService; - -import junit.framework.TestCase; - -/** - * TODO some tests commented out due to DataType.equals() needing to be strict - * - * @version $Rev$ $Date$ - */ -public class ContractCompatibilityTestCase extends TestCase { - - private WireService wireService = new MockWireService(); - - public void testNoOperation() throws Exception { - ServiceContract source = new MockContract<Type>("FooContract"); - ServiceContract target = new MockContract<Type>("FooContract"); - wireService.checkCompatibility(source, target, false); - } - - public void testBasic() throws Exception { - ServiceContract<Type> source = new MockContract<Type>("FooContract"); - Operation<Type> opSource1 = new Operation<Type>("op1", null, null, null, false, null, NO_CONVERSATION); - Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>(); - sourceOperations.put("op1", opSource1); - source.setOperations(sourceOperations); - ServiceContract<Type> target = new MockContract<Type>("FooContract"); - Operation<Type> opSource2 = new Operation<Type>("op1", null, null, null, false, null, NO_CONVERSATION); - Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>(); - targetOperations.put("op1", opSource2); - target.setOperations(targetOperations); - wireService.checkCompatibility(source, target, false); - } - - public void testBasicIncompatibleOperationNames() throws Exception { - ServiceContract<Type> source = new MockContract<Type>("FooContract"); - Operation<Type> opSource1 = new Operation<Type>("op1", null, null, null, false, null, NO_CONVERSATION); - Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>(); - sourceOperations.put("op1", opSource1); - source.setOperations(sourceOperations); - ServiceContract<Type> target = new MockContract<Type>("FooContract"); - Operation<Type> opSource2 = new Operation<Type>("op2", null, null, null, false, null, NO_CONVERSATION); - Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>(); - targetOperations.put("op2", opSource2); - target.setOperations(targetOperations); - try { - wireService.checkCompatibility(source, target, false); - fail(); - } catch (IncompatibleServiceContractException e) { - //expected - } - } - - public void testInputTypes() throws Exception { - ServiceContract<Type> source = new MockContract<Type>("FooContract"); - List<DataType<Type>> sourceInputTypes = new ArrayList<DataType<Type>>(); - sourceInputTypes.add(new DataType<Type>(Object.class, Object.class)); - DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(String.class, sourceInputTypes); - Operation<Type> opSource1 = new Operation<Type>("op1", inputType, null, null, false, null, NO_CONVERSATION); - Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>(); - sourceOperations.put("op1", opSource1); - source.setOperations(sourceOperations); - - ServiceContract<Type> target = new MockContract<Type>("FooContract"); - List<DataType<Type>> targetInputTypes = new ArrayList<DataType<Type>>(); - targetInputTypes.add(new DataType<Type>(Object.class, Object.class)); - DataType<List<DataType<Type>>> targetInputType = - new DataType<List<DataType<Type>>>(String.class, targetInputTypes); - - Operation<Type> opTarget = - new Operation<Type>("op1", targetInputType, null, null, false, null, NO_CONVERSATION); - Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>(); - targetOperations.put("op1", opTarget); - target.setOperations(targetOperations); - wireService.checkCompatibility(source, target, false); - } - - - public void testIncompatibleInputTypes() throws Exception { - ServiceContract<Type> source = new MockContract<Type>("FooContract"); - List<DataType<Type>> sourceInputTypes = new ArrayList<DataType<Type>>(); - sourceInputTypes.add(new DataType<Type>(Integer.class, Integer.class)); - DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(String.class, sourceInputTypes); - Operation<Type> opSource1 = new Operation<Type>("op1", inputType, null, null, false, null, NO_CONVERSATION); - Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>(); - sourceOperations.put("op1", opSource1); - source.setOperations(sourceOperations); - - ServiceContract<Type> target = new MockContract<Type>("FooContract"); - List<DataType<Type>> targetInputTypes = new ArrayList<DataType<Type>>(); - targetInputTypes.add(new DataType<Type>(String.class, String.class)); - DataType<List<DataType<Type>>> targetInputType = - new DataType<List<DataType<Type>>>(String.class, targetInputTypes); - - Operation<Type> opTarget = - new Operation<Type>("op1", targetInputType, null, null, false, null, NO_CONVERSATION); - Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>(); - targetOperations.put("op1", opTarget); - target.setOperations(targetOperations); - try { - wireService.checkCompatibility(source, target, false); - fail(); - } catch (IncompatibleServiceContractException e) { - //expected - } - } - - /** - * Verfies source input types can be super types of the target - */ - public void testSourceSuperTypeInputCompatibility() throws Exception { -// ServiceContract<Type> source = new MockContract<Type>("FooContract"); -// List<DataType<Type>> sourceInputTypes = new ArrayList<DataType<Type>>(); -// sourceInputTypes.add(new DataType<Type>(Object.class, Object.class)); -// DataType<List<DataType<Type>>> inputType = new DataType<List<DataType<Type>>>(String.class, sourceInputTypes); -// Operation<Type> opSource1 = new Operation<Type>("op1", inputType, null, null, false, null); -// Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>(); -// sourceOperations.put("op1", opSource1); -// source.setOperations(sourceOperations); -// -// ServiceContract<Type> target = new MockContract<Type>("FooContract"); -// List<DataType<Type>> targetInputTypes = new ArrayList<DataType<Type>>(); -// targetInputTypes.add(new DataType<Type>(String.class, String.class)); -// DataType<List<DataType<Type>>> targetInputType = -// new DataType<List<DataType<Type>>>(String.class, targetInputTypes); -// -// Operation<Type> opTarget = new Operation<Type>("op1", targetInputType, null, null, false, null); -// Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>(); -// targetOperations.put("op1", opTarget); -// target.setOperations(targetOperations); -// wireService.checkCompatibility(source, target, false); - } - - public void testOutputTypes() throws Exception { - ServiceContract<Type> source = new MockContract<Type>("FooContract"); - DataType<Type> sourceOutputType = new DataType<Type>(String.class, String.class); - Operation<Type> opSource1 = - new Operation<Type>("op1", null, sourceOutputType, null, false, null, NO_CONVERSATION); - Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>(); - sourceOperations.put("op1", opSource1); - source.setOperations(sourceOperations); - - ServiceContract<Type> target = new MockContract<Type>("FooContract"); - DataType<Type> targetOutputType = new DataType<Type>(String.class, String.class); - Operation<Type> opTarget = - new Operation<Type>("op1", null, targetOutputType, null, false, null, NO_CONVERSATION); - Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>(); - targetOperations.put("op1", opTarget); - target.setOperations(targetOperations); - wireService.checkCompatibility(source, target, false); - } - - /** - * Verfies a return type that is a supertype of of the target is compatible - */ - public void testSupertypeOutputTypes() throws Exception { -// ServiceContract<Type> source = new MockContract<Type>("FooContract"); -// DataType<Type> sourceOutputType = new DataType<Type>(Object.class, Object.class); -// Operation<Type> opSource1 = new Operation<Type>("op1", null, sourceOutputType, null, false, null); -// Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>(); -// sourceOperations.put("op1", opSource1); -// source.setOperations(sourceOperations); -// -// ServiceContract<Type> target = new MockContract<Type>("FooContract"); -// DataType<Type> targetOutputType = new DataType<Type>(String.class, String.class); -// Operation<Type> opTarget = new Operation<Type>("op1", null, targetOutputType, null, false, null); -// Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>(); -// targetOperations.put("op1", opTarget); -// target.setOperations(targetOperations); -// wireService.checkCompatibility(source, target, false); - } - - public void testIncompatibleOutputTypes() throws Exception { - ServiceContract<Type> source = new MockContract<Type>("FooContract"); - DataType<Type> sourceOutputType = new DataType<Type>(String.class, String.class); - Operation<Type> opSource1 = - new Operation<Type>("op1", null, sourceOutputType, null, false, null, NO_CONVERSATION); - Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>(); - sourceOperations.put("op1", opSource1); - source.setOperations(sourceOperations); - - ServiceContract<Type> target = new MockContract<Type>("FooContract"); - DataType<Type> targetOutputType = new DataType<Type>(Integer.class, Integer.class); - Operation<Type> opTarget = - new Operation<Type>("op1", null, targetOutputType, null, false, null, NO_CONVERSATION); - Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>(); - targetOperations.put("op1", opTarget); - target.setOperations(targetOperations); - try { - wireService.checkCompatibility(source, target, false); - fail(); - } catch (IncompatibleServiceContractException e) { - //expected - } - } - - public void testFaultTypes() throws Exception { - ServiceContract<Type> source = new MockContract<Type>("FooContract"); - DataType<Type> sourceFaultType = new DataType<Type>(String.class, String.class); - List<DataType<Type>> sourceFaultTypes = new ArrayList<DataType<Type>>(); - sourceFaultTypes.add(0, sourceFaultType); - Operation<Type> opSource1 = - new Operation<Type>("op1", null, null, sourceFaultTypes, false, null, NO_CONVERSATION); - Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>(); - sourceOperations.put("op1", opSource1); - source.setOperations(sourceOperations); - - ServiceContract<Type> target = new MockContract<Type>("FooContract"); - DataType<Type> targetFaultType = new DataType<Type>(String.class, String.class); - List<DataType<Type>> targetFaultTypes = new ArrayList<DataType<Type>>(); - targetFaultTypes.add(0, targetFaultType); - - Operation<Type> opTarget = - new Operation<Type>("op1", null, null, targetFaultTypes, false, null, NO_CONVERSATION); - Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>(); - targetOperations.put("op1", opTarget); - target.setOperations(targetOperations); - wireService.checkCompatibility(source, target, false); - } - - public void testSourceFaultTargetNoFaultCompatibility() throws Exception { - ServiceContract<Type> source = new MockContract<Type>("FooContract"); - DataType<Type> sourceFaultType = new DataType<Type>(String.class, String.class); - List<DataType<Type>> sourceFaultTypes = new ArrayList<DataType<Type>>(); - sourceFaultTypes.add(0, sourceFaultType); - Operation<Type> opSource1 = - new Operation<Type>("op1", null, null, sourceFaultTypes, false, null, NO_CONVERSATION); - Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>(); - sourceOperations.put("op1", opSource1); - source.setOperations(sourceOperations); - - ServiceContract<Type> target = new MockContract<Type>("FooContract"); - Operation<Type> opTarget = new Operation<Type>("op1", null, null, null, false, null, NO_CONVERSATION); - Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>(); - targetOperations.put("op1", opTarget); - target.setOperations(targetOperations); - wireService.checkCompatibility(source, target, false); - } - - /** - * Verifies a source's fault which is a supertype of the target's fault are compatibile - * - * @throws Exception - */ - public void testFaultSuperTypes() throws Exception { -// ServiceContract<Type> source = new MockContract<Type>("FooContract"); -// DataType<Type> sourceFaultType = new DataType<Type>(Exception.class, Exception.class); -// List<DataType<Type>> sourceFaultTypes = new ArrayList<DataType<Type>>(); -// sourceFaultTypes.add(0, sourceFaultType); -// Operation<Type> opSource1 = new Operation<Type>("op1", null, null, sourceFaultTypes, false, null); -// Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>(); -// sourceOperations.put("op1", opSource1); -// source.setOperations(sourceOperations); -// -// ServiceContract<Type> target = new MockContract<Type>("FooContract"); -// DataType<Type> targetFaultType = new DataType<Type>(TuscanyException.class, TuscanyException.class); -// List<DataType<Type>> targetFaultTypes = new ArrayList<DataType<Type>>(); -// targetFaultTypes.add(0, targetFaultType); -// -// Operation<Type> opTarget = new Operation<Type>("op1", null, null, targetFaultTypes, false, null); -// Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>(); -// targetOperations.put("op1", opTarget); -// target.setOperations(targetOperations); -// wireService.checkCompatibility(source, target, false); - } - - /** - * Verifies a source's faults which are supertypes and a superset of the target's faults are compatibile - */ - public void testFaultSuperTypesAndSuperset() throws Exception { -// ServiceContract<Type> source = new MockContract<Type>("FooContract"); -// DataType<Type> sourceFaultType = new DataType<Type>(Exception.class, Exception.class); -// DataType<Type> sourceFaultType2 = new DataType<Type>(RuntimeException.class, RuntimeException.class); -// List<DataType<Type>> sourceFaultTypes = new ArrayList<DataType<Type>>(); -// sourceFaultTypes.add(0, sourceFaultType); -// sourceFaultTypes.add(1, sourceFaultType2); -// Operation<Type> opSource1 = new Operation<Type>("op1", null, null, sourceFaultTypes, false, null); -// Map<String, Operation<Type>> sourceOperations = new HashMap<String, Operation<Type>>(); -// sourceOperations.put("op1", opSource1); -// source.setOperations(sourceOperations); -// -// ServiceContract<Type> target = new MockContract<Type>("FooContract"); -// DataType<Type> targetFaultType = new DataType<Type>(TuscanyException.class, TuscanyException.class); -// List<DataType<Type>> targetFaultTypes = new ArrayList<DataType<Type>>(); -// targetFaultTypes.add(0, targetFaultType); -// -// Operation<Type> opTarget = new Operation<Type>("op1", null, null, targetFaultTypes, false, null); -// Map<String, Operation<Type>> targetOperations = new HashMap<String, Operation<Type>>(); -// targetOperations.put("op1", opTarget); -// target.setOperations(targetOperations); -// wireService.checkCompatibility(source, target, false); - } - - private class MockContract<T> extends ServiceContract<T> { - public MockContract() { - } - - public MockContract(Class interfaceClass) { - super(interfaceClass); - } - - public MockContract(String interfaceName) { - super(interfaceName); - } - } - - private class MockWireService extends WireServiceExtension { - public MockWireService() { - super(null, null); - } - - public <T> T createProxy(Class<T> interfaze, Wire wire) throws ProxyCreationException { - throw new UnsupportedOperationException(); - } - - public <T> T createProxy(Class<T> interfaze, Wire wire, Map<Method, OutboundChainHolder> mapping) - throws ProxyCreationException { - throw new UnsupportedOperationException(); - } - - public Object createCallbackProxy(Class<?> interfaze, InboundWire wire) throws ProxyCreationException { - throw new UnsupportedOperationException(); - } - - - public WireInvocationHandler createHandler(Class<?> interfaze, Wire wire) { - throw new UnsupportedOperationException(); - } - - public OutboundInvocationChain createOutboundChain(Operation<?> operation) { - throw new UnsupportedOperationException(); - } - - public InboundInvocationChain createInboundChain(Operation<?> operation) { - throw new UnsupportedOperationException(); - } - - public InboundWire createWire(ServiceDefinition service) { - throw new UnsupportedOperationException(); - } - - public void createWires(AtomicComponent component, ComponentDefinition<?> definition) { - throw new UnsupportedOperationException(); - } - - public void createWires(ReferenceBinding referenceBinding, ServiceContract<?> contract, - QualifiedName targetName) { - throw new UnsupportedOperationException(); - } - - public void createWires(ServiceBinding serviceBinding, ServiceContract<?> contract, String targetName) { - throw new UnsupportedOperationException(); - } - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InboundInvocationErrorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InboundInvocationErrorTestCase.java deleted file mode 100644 index 39e1bf0b46..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InboundInvocationErrorTestCase.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.wire; - -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.lang.reflect.Type; -import java.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.idl.InvalidServiceContractException; -import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry; -import org.apache.tuscany.spi.model.Operation; -import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -import org.apache.tuscany.core.mock.wire.MockStaticInvoker; -import org.apache.tuscany.core.mock.wire.MockSyncInterceptor; -import org.apache.tuscany.core.wire.jdk.JDKInboundInvocationHandler; -import org.easymock.classextension.EasyMock; - -/** - * Tests handling of exceptions thrown during an inbound wire invocation - * - * @version $Rev$ $Date$ - */ -public class InboundInvocationErrorTestCase extends TestCase { - private Method checkedMethod; - private Method runtimeMethod; - private Operation checkedOperation; - private Operation runtimeOperation; - - public InboundInvocationErrorTestCase() { - super(); - } - - public InboundInvocationErrorTestCase(String arg0) { - super(arg0); - } - - public void setUp() throws Exception { - super.setUp(); - checkedMethod = - TestBean.class.getDeclaredMethod("checkedException", (Class[]) null); - runtimeMethod = - TestBean.class.getDeclaredMethod("runtimeException", (Class[]) null); - assertNotNull(checkedMethod); - assertNotNull(runtimeMethod); - JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - ServiceContract<?> contract; - try { - contract = registry.introspect(TestBean.class); - } catch (InvalidServiceContractException e) { - throw new AssertionError(); - } - - checkedOperation = contract.getOperations().get("checkedException"); - runtimeOperation = contract.getOperations().get("runtimeException"); - } - - public void testCheckedException() throws Exception { - WorkContext workContext = EasyMock.createNiceMock(WorkContext.class); - EasyMock.replay(workContext); - - Operation<Type> operation = - new Operation<Type>("checkedException", null, null, null, false, null, NO_CONVERSATION); - Map<Operation<?>, InboundInvocationChain> chains = new HashMap<Operation<?>, InboundInvocationChain>(); - chains.put(operation, createChain(checkedMethod, checkedOperation)); - InboundWire wire = new InboundWireImpl(); - wire.addInvocationChains(chains); - wire.setServiceContract(new ServiceContract<TestBean>(TestBean.class) { - }); - - JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(TestBean.class, wire, workContext); - try { - ClassLoader ccl = Thread.currentThread().getContextClassLoader(); - TestBean proxy = (TestBean) Proxy.newProxyInstance(ccl, new Class[]{TestBean.class}, handler); - proxy.checkedException(); - } catch (InboundInvocationErrorTestCase.TestException e) { - return; - } - fail(InboundInvocationErrorTestCase.TestException.class.getName() + " should have been thrown"); - } - - public void testRuntimeException() throws Exception { - WorkContext workContext = EasyMock.createNiceMock(WorkContext.class); - EasyMock.replay(workContext); - - Operation<Type> operation = - new Operation<Type>("runtimeException", null, null, null, false, null, NO_CONVERSATION); - Map<Operation<?>, InboundInvocationChain> chains = new HashMap<Operation<?>, InboundInvocationChain>(); - chains.put(operation, createChain(runtimeMethod, runtimeOperation)); - InboundWire wire = new InboundWireImpl(); - wire.addInvocationChains(chains); - wire.setServiceContract(new ServiceContract<TestBean>(TestBean.class) { - }); - - JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(TestBean.class, wire, workContext); - try { - InboundInvocationErrorTestCase.TestBean proxy = (InboundInvocationErrorTestCase.TestBean) Proxy - .newProxyInstance(Thread.currentThread().getContextClassLoader(), - new Class[]{InboundInvocationErrorTestCase.TestBean.class}, handler); - proxy.runtimeException(); - } catch (InboundInvocationErrorTestCase.TestRuntimeException e) { - return; - } - fail(InboundInvocationErrorTestCase.TestException.class.getName() + " should have been thrown"); - } - - private InboundInvocationChain createChain(Method m, Operation operation) { - MockStaticInvoker invoker = new MockStaticInvoker(m, new TestBeanImpl()); - InboundInvocationChain chain = new InboundInvocationChainImpl(operation); - chain.addInterceptor(new MockSyncInterceptor()); - chain.setTargetInvoker(invoker); - chain.addInterceptor(new InvokerInterceptor()); - chain.prepare(); - return chain; - } - - public interface TestBean { - - void checkedException() throws TestException; - - void runtimeException() throws TestRuntimeException; - - } - - public class TestBeanImpl implements TestBean { - - public void checkedException() throws InboundInvocationErrorTestCase.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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/IncompatibleServiceContractExceptionFormatterTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/IncompatibleServiceContractExceptionFormatterTestCase.java deleted file mode 100644 index a9f455bc62..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/IncompatibleServiceContractExceptionFormatterTestCase.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.wire; - -import java.io.PrintWriter; -import java.io.StringWriter; - -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.IncompatibleServiceContractException; - -import junit.framework.TestCase; -import org.apache.tuscany.host.monitor.FormatterRegistry; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class IncompatibleServiceContractExceptionFormatterTestCase extends TestCase { - FormatterRegistry registry = EasyMock.createNiceMock(FormatterRegistry.class); - IncompatibleServiceContractExceptionFormatter formatter = - new IncompatibleServiceContractExceptionFormatter(registry); - - public void testFormat() throws Exception { - ServiceContract<Object> source = new ServiceContract<Object>() { - }; - source.setInterfaceName("sourceInterface"); - ServiceContract<Object> target = new ServiceContract<Object>() { - }; - target.setInterfaceName("targetInterface"); - Operation<Object> sourceOp = new Operation<Object>("sourceOp", null, null, null); - Operation<Object> targetOp = new Operation<Object>("targetOp", null, null, null); - - IncompatibleServiceContractException e = - new IncompatibleServiceContractException("message", source, target, sourceOp, targetOp); - StringWriter writer = new StringWriter(); - PrintWriter pw = new PrintWriter(writer); - formatter.write(pw, e); - String buffer = writer.toString(); - assertTrue(buffer.indexOf("message") >= 0); - assertTrue(buffer.indexOf("sourceInterface") >= 0); - assertTrue(buffer.indexOf("targetInterface") >= 0); - assertTrue(buffer.indexOf("sourceOp") >= 0); - assertTrue(buffer.indexOf("targetOp") >= 0); - } - - - public void testFormatNulls() throws Exception { - ServiceContract<Object> source = new ServiceContract<Object>() { - }; - source.setInterfaceName("sourceInterface"); - ServiceContract<Object> target = new ServiceContract<Object>() { - }; - target.setInterfaceName("targetInterface"); - - IncompatibleServiceContractException e = - new IncompatibleServiceContractException("message", source, target); - StringWriter writer = new StringWriter(); - PrintWriter pw = new PrintWriter(writer); - formatter.write(pw, e); - String buffer = writer.toString(); - assertTrue(buffer.indexOf("message") >= 0); - assertTrue(buffer.indexOf("sourceInterface") >= 0); - assertTrue(buffer.indexOf("targetInterface") >= 0); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationChainImplTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationChainImplTestCase.java deleted file mode 100644 index 294e98997f..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationChainImplTestCase.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.wire; - -import java.lang.reflect.Type; - -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class InvocationChainImplTestCase extends TestCase { - - public void testInsertAtPos() throws Exception { - MockChain chain = new MockChain(new Operation<Type>("foo", null, null, null)); - Interceptor inter3 = new MockInterceptor(); - Interceptor inter2 = new MockInterceptor(); - Interceptor inter1 = new MockInterceptor(); - chain.addInterceptor(inter3); - chain.addInterceptor(0, inter1); - chain.addInterceptor(1, inter2); - Interceptor head = chain.getHeadInterceptor(); - assertEquals(inter1, head); - assertEquals(inter2, head.getNext()); - assertEquals(inter3, head.getNext().getNext()); - } - - public void testInsertAtEnd() throws Exception { - MockChain chain = new MockChain(new Operation<Type>("foo", null, null, null)); - Interceptor inter2 = new MockInterceptor(); - Interceptor inter1 = new MockInterceptor(); - chain.addInterceptor(0, inter1); - chain.addInterceptor(1, inter2); - Interceptor head = chain.getHeadInterceptor(); - assertEquals(inter1, head); - assertEquals(inter2, head.getNext()); - assertEquals(inter2, chain.getTailInterceptor()); - - } - - private class MockChain extends InvocationChainImpl { - - public MockChain(Operation operation) { - super(operation); - } - - public void prepare() { - - } - } - - private class MockInterceptor implements Interceptor { - - private Interceptor next; - - public Message invoke(Message msg) { - return null; - } - - public void setNext(Interceptor next) { - this.next = next; - } - - public Interceptor getNext() { - return next; - } - - public boolean isOptimizable() { - return false; - } - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationErrorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationErrorTestCase.java deleted file mode 100644 index aca68a0f25..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationErrorTestCase.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.wire; - -import java.lang.reflect.Method; - -import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -import org.apache.tuscany.core.mock.component.SimpleTarget; -import org.apache.tuscany.core.mock.component.SimpleTargetImpl; -import org.apache.tuscany.core.mock.wire.MockStaticInvoker; -import org.apache.tuscany.core.mock.wire.MockSyncInterceptor; - -/** - * Tests error propagation through an innvocation - * - * @version $Rev$ $Date$ - */ -public class InvocationConfigurationErrorTestCase extends TestCase { - - private ServiceContract<?> contract; - private Method hello; - - public InvocationConfigurationErrorTestCase() { - super(); - } - - public InvocationConfigurationErrorTestCase(String arg0) { - super(arg0); - } - - public void setUp() throws Exception { - super.setUp(); - JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - contract = registry.introspect(SimpleTarget.class); - hello = SimpleTarget.class.getMethod("hello", String.class); - } - - /** - * Tests basic wiring of a source to a target, including handlers and interceptors - */ - public void testInvokeWithInterceptors() throws Exception { - Operation operation = contract.getOperations().get("hello"); - OutboundInvocationChain source = new OutboundInvocationChainImpl(operation); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addInterceptor(sourceInterceptor); - - InboundInvocationChain target = new InboundInvocationChainImpl(operation); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addInterceptor(targetInterceptor); - target.addInterceptor(new InvokerInterceptor()); - - // connect the source to the target - source.setTargetInterceptor(target.getHeadInterceptor()); - source.prepare(); - target.prepare(); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Message msg = new MessageImpl(); - msg.setTargetInvoker(invoker); - Message response = source.getHeadInterceptor().invoke(msg); - assertTrue(response.isFault()); - assertTrue(response.getBody() instanceof IllegalArgumentException); - assertEquals(1, sourceInterceptor.getCount()); - assertEquals(1, targetInterceptor.getCount()); - - } - -} - diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationTestCase.java deleted file mode 100644 index 62df732a9e..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/InvocationConfigurationTestCase.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.wire; - -import java.lang.reflect.Method; - -import org.apache.tuscany.spi.idl.InvalidServiceContractException; -import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -import org.apache.tuscany.core.mock.component.SimpleTarget; -import org.apache.tuscany.core.mock.component.SimpleTargetImpl; -import org.apache.tuscany.core.mock.wire.MockStaticInvoker; -import org.apache.tuscany.core.mock.wire.MockSyncInterceptor; - -public class InvocationConfigurationTestCase extends TestCase { - - private Method hello; - private Operation operation; - - - public InvocationConfigurationTestCase() { - super(); - } - - public InvocationConfigurationTestCase(String arg0) { - super(arg0); - } - - public void setUp() throws Exception { - super.setUp(); - JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - ServiceContract<?> contract; - try { - contract = registry.introspect(SimpleTarget.class); - } catch (InvalidServiceContractException e) { - throw new AssertionError(); - } - - operation = contract.getOperations().get("echo"); - hello = SimpleTarget.class.getMethod("hello", String.class); - } - - /** - * Tests basic wiring of a source to a target, including handlers and interceptors - */ - public void testInvokeWithInterceptors() throws Exception { - OutboundInvocationChain source = new OutboundInvocationChainImpl(operation); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addInterceptor(sourceInterceptor); - - InboundInvocationChain target = new InboundInvocationChainImpl(operation); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addInterceptor(targetInterceptor); - target.addInterceptor(new InvokerInterceptor()); - - // connect the source to the target - source.setTargetInterceptor(target.getHeadInterceptor()); - source.prepare(); - target.prepare(); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - Message msg = new MessageImpl(); - msg.setBody("foo"); - msg.setTargetInvoker(invoker); - Message response = source.getHeadInterceptor().invoke(msg); - assertEquals("foo", response.getBody()); - assertEquals(1, sourceInterceptor.getCount()); - assertEquals(1, targetInterceptor.getCount()); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/NonBlockingBridgingInterceptorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/NonBlockingBridgingInterceptorTestCase.java deleted file mode 100644 index 1755fe9d15..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/NonBlockingBridgingInterceptorTestCase.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.wire; - -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.services.work.WorkScheduler; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; - -import junit.framework.TestCase; -import org.easymock.EasyMock; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expectLastCall; -import static org.easymock.EasyMock.getCurrentArguments; -import static org.easymock.EasyMock.isA; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import org.easymock.IAnswer; - -/** - * @version $Rev$ $Date$ - */ -public class NonBlockingBridgingInterceptorTestCase extends TestCase { - - public void testInvoke() throws Exception { - WorkScheduler scheduler = createMock(WorkScheduler.class); - scheduler.scheduleWork(isA(Runnable.class)); - expectLastCall().andStubAnswer(new IAnswer<Object>() { - public Object answer() throws Throwable { - Runnable runnable = (Runnable) getCurrentArguments()[0]; - runnable.run(); - return null; - } - }); - replay(scheduler); - WorkContext context = createMock(WorkContext.class); - String convID = "convID"; - EasyMock.expect(context.getIdentifier(Scope.CONVERSATION)).andReturn(convID); - context.setCurrentCorrelationId(null); - context.setIdentifier(Scope.CONVERSATION, convID); - EasyMock.replay(context); - Message msg = new MessageImpl(); - Interceptor next = EasyMock.createMock(Interceptor.class); - EasyMock.expect(next.invoke(EasyMock.eq(msg))).andReturn(msg); - EasyMock.replay(next); - Interceptor interceptor = new NonBlockingBridgingInterceptor(scheduler, context, next); - interceptor.invoke(msg); - verify(context); - verify(next); - } - - public void testOptimizable() { - NonBlockingBridgingInterceptor interceptor = new NonBlockingBridgingInterceptor(null, null); - assertFalse(interceptor.isOptimizable()); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactoryTestCase.java deleted file mode 100644 index e0f094a83e..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactoryTestCase.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.wire; - -import org.apache.tuscany.spi.wire.OutboundWire; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class OptimizedWireObjectFactoryTestCase extends TestCase { - - public void testGetInstance() throws Exception { - Foo foo = new Foo(); - OutboundWire wire = EasyMock.createMock(OutboundWire.class); - EasyMock.expect(wire.getTargetService()).andReturn(foo); - EasyMock.replay(wire); - OptimizedWireObjectFactory factory = new OptimizedWireObjectFactory(wire); - assertEquals(foo, factory.getInstance()); - EasyMock.verify(wire); - } - - private class Foo { - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationErrorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationErrorTestCase.java deleted file mode 100644 index 42caa6eed7..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationErrorTestCase.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.wire; - -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; - -import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -import org.apache.tuscany.core.mock.wire.MockStaticInvoker; -import org.apache.tuscany.core.mock.wire.MockSyncInterceptor; -import org.apache.tuscany.core.wire.jdk.JDKOutboundInvocationHandler; - -/** - * Tests handling of exceptions thrown during an outbound wire invocation - * - * @version $Rev$ $Date$ - */ -public class OutboundInvocationErrorTestCase extends TestCase { - - private Method checkedMethod; - private Method runtimeMethod; - private JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - - public OutboundInvocationErrorTestCase() { - super(); - } - - public OutboundInvocationErrorTestCase(String arg0) { - super(arg0); - } - - public void setUp() throws Exception { - super.setUp(); - checkedMethod = TestBean.class.getDeclaredMethod("checkedException", (Class[]) null); - runtimeMethod = TestBean.class.getDeclaredMethod("runtimeException", (Class[]) null); - assertNotNull(checkedMethod); - assertNotNull(runtimeMethod); - } - - public void testCheckedException() throws Exception { - OutboundWire wire = new OutboundWireImpl(); - ServiceContract<?> contract = registry.introspect(TestBean.class); - wire.setServiceContract(contract); - Operation operation = contract.getOperations().get("checkedException"); - wire.addInvocationChain(operation, createChain(checkedMethod, operation)); - JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(TestBean.class, wire, null); - try { - TestBean proxy = (TestBean) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), - new Class[]{TestBean.class}, handler); - proxy.checkedException(); - } catch (TestException e) { - return; - } - fail(TestException.class.getName() + " should have been thrown"); - } - - public void testRuntimeException() throws Exception { - OutboundWire wire = new OutboundWireImpl(); - ServiceContract<?> contract = registry.introspect(TestBean.class); - wire.setServiceContract(contract); - Operation operation = contract.getOperations().get("runtimeException"); - OutboundInvocationChain chain = createChain(runtimeMethod, operation); - wire.addInvocationChain(operation, chain); - JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(TestBean.class, wire, null); - try { - TestBean proxy = (TestBean) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), - new Class[]{TestBean.class}, handler); - proxy.runtimeException(); - } catch (TestRuntimeException e) { - return; - } - fail(TestException.class.getName() + " should have been thrown"); - } - - private OutboundInvocationChain createChain(Method m, Operation operation) { - MockStaticInvoker invoker = new MockStaticInvoker(m, new TestBeanImpl()); - OutboundInvocationChain chain = new OutboundInvocationChainImpl(operation); - chain.addInterceptor(new MockSyncInterceptor()); - chain.setTargetInvoker(invoker); - chain.setTargetInterceptor(new InvokerInterceptor()); - chain.prepare(); - return chain; - } - - public interface TestBean { - - void checkedException() throws TestException; - - 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/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationHandlerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationHandlerTestCase.java deleted file mode 100644 index 70d85445ed..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OutboundInvocationHandlerTestCase.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.wire; - -import java.lang.reflect.Method; - -import org.apache.tuscany.spi.idl.java.JavaIDLUtils; -import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -import org.apache.tuscany.core.mock.component.SimpleTarget; -import org.apache.tuscany.core.mock.component.SimpleTargetImpl; -import org.apache.tuscany.core.mock.wire.MockStaticInvoker; -import org.apache.tuscany.core.mock.wire.MockSyncInterceptor; -import org.apache.tuscany.core.wire.jdk.JDKOutboundInvocationHandler; - -public class OutboundInvocationHandlerTestCase extends TestCase { - - private Method hello; - private ServiceContract<?> contract; - - public OutboundInvocationHandlerTestCase() { - super(); - } - - public OutboundInvocationHandlerTestCase(String arg0) { - super(arg0); - } - - public void setUp() throws Exception { - super.setUp(); - JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - contract = registry.introspect(SimpleTarget.class); - hello = SimpleTarget.class.getMethod("hello", String.class); - } - - public void testBasicInvoke() throws Throwable { - OutboundWire wire = new OutboundWireImpl(); - Operation operation = contract.getOperations().get("hello"); - wire.addInvocationChain(operation, createChain(operation)); - wire.setServiceContract(contract); - JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(SimpleTarget.class, wire, null); - assertEquals("foo", handler.invoke(hello, new Object[]{"foo"})); - } - - public void testErrorInvoke() throws Throwable { - OutboundWire wire = new OutboundWireImpl(); - Operation operation = contract.getOperations().get("hello"); - wire.addInvocationChain(operation, createChain(operation)); - wire.setServiceContract(contract); - JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(SimpleTarget.class, wire, null); - try { - handler.invoke(hello, new Object[]{}); - fail("Expected " + IllegalArgumentException.class.getName()); - } catch (IllegalArgumentException e) { - // should throw - } - } - - public void testDirectErrorInvoke() throws Throwable { - Operation operation = contract.getOperations().get("hello"); - OutboundInvocationChain source = new OutboundInvocationChainImpl(operation); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - OutboundWire wire = new OutboundWireImpl(); - wire.setServiceContract(contract); - wire.addInvocationChain(operation, source); - JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(SimpleTarget.class, wire, null); - try { - assertEquals("foo", handler.invoke(hello, new Object[]{})); - fail("Expected " + IllegalArgumentException.class.getName()); - } catch (IllegalArgumentException e) { - // should throw - } - } - - public void testDirectInvoke() throws Throwable { - Operation operation = contract.getOperations().get("hello"); - OutboundInvocationChain source = new OutboundInvocationChainImpl(operation); - MockStaticInvoker invoker = new MockStaticInvoker(hello, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - - OutboundWire wire = new OutboundWireImpl(); - wire.setServiceContract(contract); - wire.addInvocationChain(operation, source); - JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(SimpleTarget.class, wire, null); - assertEquals("foo", handler.invoke(hello, new Object[]{"foo"})); - } - - private OutboundInvocationChain createChain(Operation operation) { - OutboundInvocationChain source = new OutboundInvocationChainImpl(operation); - MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor(); - source.addInterceptor(sourceInterceptor); - - InboundInvocationChain target = new InboundInvocationChainImpl(operation); - MockSyncInterceptor targetInterceptor = new MockSyncInterceptor(); - target.addInterceptor(targetInterceptor); - target.addInterceptor(new InvokerInterceptor()); - - // connect the source to the target - source.setTargetInterceptor(targetInterceptor); - source.prepare(); - target.prepare(); - Method method = JavaIDLUtils.findMethod(operation, SimpleTarget.class.getMethods()); - MockStaticInvoker invoker = new MockStaticInvoker(method, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - return source; - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OutboundWireTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OutboundWireTestCase.java deleted file mode 100644 index 9d0de99ed2..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/OutboundWireTestCase.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.wire; - -import org.apache.tuscany.spi.wire.OutboundWire; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class OutboundWireTestCase extends TestCase { - - /** - * Tests that the target wire returns null if there is no connected wire. This behavior is needed for optional - * autowires. - */ - public void testGetNonExistentTargetService() throws Exception { - OutboundWire wire = new OutboundWireImpl(); - assertNull(wire.getTargetService()); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/SynchronousBridgingInterceptorTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/SynchronousBridgingInterceptorTestCase.java deleted file mode 100644 index f1631fc555..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/SynchronousBridgingInterceptorTestCase.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.wire; - -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; - -import org.easymock.EasyMock; -import static org.easymock.EasyMock.verify; -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class SynchronousBridgingInterceptorTestCase extends TestCase { - - public void testInvoke() throws Exception { - Message msg = new MessageImpl(); - Interceptor next = EasyMock.createMock(Interceptor.class); - EasyMock.expect(next.invoke(EasyMock.eq(msg))).andReturn(msg); - EasyMock.replay(next); - Interceptor interceptor = new SynchronousBridgingInterceptor(next); - interceptor.invoke(msg); - verify(next); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireObjectFactoryTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireObjectFactoryTestCase.java deleted file mode 100644 index 537ca21656..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireObjectFactoryTestCase.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.wire; - -import java.lang.reflect.Type; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.idl.java.JavaServiceContract; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.WireService; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class WireObjectFactoryTestCase extends TestCase { - - @SuppressWarnings({"unchecked"}) - public void testCreateInstance() throws Exception { - Operation<Type> op = new Operation<Type>("hello", null, null, null); - OutboundInvocationChain chain = new OutboundInvocationChainImpl(op); - OutboundWire wire = EasyMock.createMock(OutboundWire.class); - Map<Operation<?>, OutboundInvocationChain> chains = new HashMap<Operation<?>, OutboundInvocationChain>(); - chains.put(op, chain); - EasyMock.expect(wire.getInvocationChains()).andReturn(chains); - EasyMock.expect(wire.isOptimizable()).andReturn(false); - EasyMock.replay(wire); - WireService service = EasyMock.createMock(WireService.class); - service.createProxy(EasyMock.eq(Foo.class), EasyMock.eq(wire), EasyMock.isA(Map.class)); - EasyMock.expectLastCall().andReturn(new Foo() { - public void hello() { - - } - }); - EasyMock.replay(service); - - WireObjectFactory<Foo> factory = new WireObjectFactory<Foo>(Foo.class, wire, service); - factory.getInstance(); - EasyMock.verify(service); - EasyMock.verify(wire); - } - - @SuppressWarnings("unchecked") - public void testOptimizedCreateInstance() throws Exception { - ServiceContract<?> contract = new JavaServiceContract(Foo.class); - OutboundWire wire = EasyMock.createMock(OutboundWire.class); - EasyMock.expect(wire.isOptimizable()).andReturn(true); - EasyMock.expect(wire.getServiceContract()).andReturn(contract).atLeastOnce(); - EasyMock.expect(wire.getInvocationChains()).andReturn((Map) Collections.emptyMap()); - EasyMock.expect(wire.getTargetService()).andReturn(new Foo() { - public void hello() { - } - }); - EasyMock.replay(wire); - WireObjectFactory<Foo> factory = new WireObjectFactory<Foo>(Foo.class, wire, null); - factory.getInstance(); - EasyMock.verify(wire); - - } - - /** - * Verifies that a proxy is created when the required client contract is different than the wire contract - */ - @SuppressWarnings("unchecked") - public void testCannotOptimizeDifferentContractsCreateInstance() throws Exception { - ServiceContract<?> contract = new JavaServiceContract(Object.class); - OutboundWire wire = EasyMock.createMock(OutboundWire.class); - EasyMock.expect(wire.isOptimizable()).andReturn(true); - EasyMock.expect(wire.getServiceContract()).andReturn(contract).atLeastOnce(); - EasyMock.expect(wire.getInvocationChains()).andReturn((Map) Collections.emptyMap()); - EasyMock.replay(wire); - WireService service = EasyMock.createMock(WireService.class); - service.createProxy(EasyMock.eq(Foo.class), EasyMock.eq(wire), EasyMock.isA(Map.class)); - EasyMock.expectLastCall().andReturn(new Foo() { - public void hello() { - - } - }); - EasyMock.replay(service); - - WireObjectFactory<Foo> factory = new WireObjectFactory<Foo>(Foo.class, wire, service); - factory.getInstance(); - EasyMock.verify(service); - EasyMock.verify(wire); - } - - @SuppressWarnings("unchecked") - public void testNoJavaInterfaceCreateInstance() throws Exception { - ServiceContract<?> contract = new JavaServiceContract(); - OutboundWire wire = EasyMock.createMock(OutboundWire.class); - EasyMock.expect(wire.isOptimizable()).andReturn(true); - EasyMock.expect(wire.getServiceContract()).andReturn(contract).atLeastOnce(); - EasyMock.expect(wire.getInvocationChains()).andReturn((Map) Collections.emptyMap()); - EasyMock.replay(wire); - WireService service = EasyMock.createMock(WireService.class); - service.createProxy(EasyMock.eq(Foo.class), EasyMock.eq(wire), EasyMock.isA(Map.class)); - EasyMock.expectLastCall().andReturn(new Foo() { - public void hello() { - - } - }); - EasyMock.replay(service); - - WireObjectFactory<Foo> factory = new WireObjectFactory<Foo>(Foo.class, wire, service); - factory.getInstance(); - EasyMock.verify(service); - EasyMock.verify(wire); - } - - private interface Foo { - void hello(); - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireOptimizationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireOptimizationTestCase.java deleted file mode 100644 index c0d40c6369..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireOptimizationTestCase.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.wire; - -import java.lang.reflect.Type; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.Component; -import org.apache.tuscany.spi.model.Operation; -import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Interceptor; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * Verifies wire optimization analysis - * - * @version $$Rev$$ $$Date$$ - */ -public class WireOptimizationTestCase extends TestCase { - private Operation operation; - - public void foo() { - } - - public void testSourceWireInterceptorOptimization() throws Exception { - AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.replay(component); - OutboundWire wire = new OutboundWireImpl(); - wire.setContainer(component); - OutboundInvocationChain chain = new OutboundInvocationChainImpl(operation); - chain.addInterceptor(new OptimizableInterceptor()); - wire.addInvocationChain(operation, chain); - assertTrue(WireUtils.isOptimizable(wire)); - } - - public void testSourceWireNonInterceptorOptimization() throws Exception { - AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.replay(component); - OutboundWire wire = new OutboundWireImpl(); - wire.setContainer(component); - OutboundInvocationChain chain = new OutboundInvocationChainImpl(operation); - chain.addInterceptor(new NonOptimizableInterceptor()); - wire.addInvocationChain(operation, chain); - assertFalse(WireUtils.isOptimizable(wire)); - } - - public void testTargetWireInterceptorOptimization() throws Exception { - AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.expect(component.isOptimizable()).andReturn(true); - EasyMock.replay(component); - InboundWire wire = new InboundWireImpl(); - wire.setContainer(component); - InboundInvocationChain chain = new InboundInvocationChainImpl(operation); - chain.addInterceptor(new OptimizableInterceptor()); - wire.addInvocationChain(operation, chain); - assertTrue(WireUtils.isOptimizable(wire)); - - } - - public void testTargetWireNoOptimizationNonAtomicContainer() throws Exception { - Component component = EasyMock.createNiceMock(Component.class); - EasyMock.expect(component.isOptimizable()).andReturn(true); - EasyMock.replay(component); - InboundWire wire = new InboundWireImpl(); - wire.setContainer(component); - InboundInvocationChain chain = new InboundInvocationChainImpl(operation); - chain.addInterceptor(new OptimizableInterceptor()); - wire.addInvocationChain(operation, chain); - assertTrue(WireUtils.isOptimizable(wire)); - } - - public void testTargetWireNonInterceptorOptimization() throws Exception { - AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class); - EasyMock.replay(component); - InboundWire wire = new InboundWireImpl(); - wire.setContainer(component); - InboundInvocationChain chain = new InboundInvocationChainImpl(operation); - chain.addInterceptor(new NonOptimizableInterceptor()); - wire.addInvocationChain(operation, chain); - assertFalse(WireUtils.isOptimizable(wire)); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - - protected void setUp() throws Exception { - super.setUp(); - operation = new Operation<Type>("foo", null, null, null, false, null, NO_CONVERSATION); - - } - - private class OptimizableInterceptor implements Interceptor { - - public Message invoke(Message msg) { - return null; - } - - public void setNext(Interceptor next) { - - } - - public Interceptor getNext() { - return null; - } - - public boolean isOptimizable() { - return true; - } - } - - private class NonOptimizableInterceptor implements Interceptor { - - public Message invoke(Message msg) { - return null; - } - - public void setNext(Interceptor next) { - - } - - public Interceptor getNext() { - return null; - } - - public boolean isOptimizable() { - return false; - } - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireServiceExtensionTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireServiceExtensionTestCase.java deleted file mode 100644 index 1838fd35bd..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireServiceExtensionTestCase.java +++ /dev/null @@ -1,333 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.wire; - -import java.lang.reflect.Method; -import java.lang.reflect.Type; -import java.net.URI; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.spi.QualifiedName; -import org.apache.tuscany.spi.component.AbstractSCAObject; -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.Reference; -import org.apache.tuscany.spi.component.ReferenceBinding; -import org.apache.tuscany.spi.component.ServiceBinding; -import org.apache.tuscany.spi.component.TargetInvokerCreationException; -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.model.ComponentDefinition; -import org.apache.tuscany.spi.model.ComponentReferenceDefinition; -import org.apache.tuscany.spi.model.ComponentType; -import org.apache.tuscany.spi.model.ComponentTypeReferenceDefinition; -import org.apache.tuscany.spi.model.Implementation; -import org.apache.tuscany.spi.model.Multiplicity; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.Property; -import org.apache.tuscany.spi.model.AbstractReferenceDefinition; -import org.apache.tuscany.spi.model.ReferenceTarget; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.model.ServiceDefinition; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundChainHolder; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.ProxyCreationException; -import org.apache.tuscany.spi.wire.TargetInvoker; -import org.apache.tuscany.spi.wire.Wire; -import org.apache.tuscany.spi.wire.WireInvocationHandler; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.mock.binding.MockServiceBinding; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class WireServiceExtensionTestCase extends TestCase { - private TestWireService wireService; - private Operation<Type> operation; - private ServiceContract<Type> contract; - private Operation<Type> callbackOperation; - - public void testCreateInboundChain() throws Exception { - InboundInvocationChain chain = wireService.createInboundChain(operation); - assertEquals(operation, chain.getOperation()); - } - - public void testCreateOutboundChain() throws Exception { - OutboundInvocationChain chain = wireService.createOutboundChain(operation); - assertEquals(operation, chain.getOperation()); - } - - public void testCreateServiceWire() throws Exception { - ServiceDefinition definition = new ServiceDefinition("foo", contract, false); - TargetInvoker invoker = EasyMock.createMock(TargetInvoker.class); - MessageImpl resp = new MessageImpl(); - EasyMock.expect(invoker.invoke(EasyMock.isA(Message.class))).andReturn(resp); - EasyMock.replay(invoker); - InboundWire wire = wireService.createWire(definition); - assertEquals("foo", wire.getServiceName()); - assertEquals(1, wire.getInvocationChains().size()); - assertEquals(contract, wire.getServiceContract()); - InboundInvocationChain chain = wire.getInvocationChains().get(operation); - assertEquals(operation, chain.getOperation()); - // verify the chain is invokable - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(invoker); - assertNotNull(chain.getHeadInterceptor().invoke(msg)); - EasyMock.verify(invoker); - } - - /*public void testCreateReferenceWire() throws Exception { - AbstractReferenceDefinition definition = new AbstractReferenceDefinition("foo", contract); - ReferenceTarget target = new ReferenceTarget(); - target.addTarget(new URI("bar")); - target.setReferenceName("refName"); - - OutboundWire wire = wireService.createWire(target, definition).get(0); - assertEquals("refName", wire.getReferenceName()); - assertEquals("bar", wire.getTargetName().toString()); - assertFalse(wire.isAutowire()); - assertEquals(1, wire.getInvocationChains().size()); - assertEquals(contract, wire.getServiceContract()); - OutboundInvocationChain chain = wire.getInvocationChains().get(operation); - assertEquals(operation, chain.getOperation()); - assertNull(chain.getHeadInterceptor()); - assertEquals(Callback.class, wire.getCallbackInterface()); - assertEquals(1, wire.getTargetCallbackInvocationChains().size()); - InboundInvocationChain callbackChain = wire.getTargetCallbackInvocationChains().get(callbackOperation); - assertEquals(callbackOperation, callbackChain.getOperation()); - - TargetInvoker invoker = EasyMock.createMock(TargetInvoker.class); - MessageImpl resp = new MessageImpl(); - EasyMock.expect(invoker.invoke(EasyMock.isA(Message.class))).andReturn(resp); - EasyMock.replay(invoker); - // verify the callback chain is invokable - MessageImpl msg = new MessageImpl(); - msg.setTargetInvoker(invoker); - assertNotNull(callbackChain.getHeadInterceptor().invoke(msg)); - EasyMock.verify(invoker); - }*/ - - public void testCreateAutowireReferenceWire() throws Exception { - ComponentTypeReferenceDefinition definition = new ComponentTypeReferenceDefinition("foo", contract); - definition.setAutowire(true); - ComponentReferenceDefinition compRef = new ComponentReferenceDefinition(definition); - //ReferenceTarget target = new ReferenceTarget(); - //target.setReferenceName("refName"); - OutboundWire wire = wireService.createWire(new ArrayList<URI>(), compRef).get(0); - assertTrue(wire.isAutowire()); - assertEquals("foo", wire.getReferenceName()); - assertEquals(contract, wire.getServiceContract()); - assertEquals(Callback.class, wire.getCallbackInterface()); - } - - public void testCreateReferenceMultipleWire() throws Exception { - ComponentTypeReferenceDefinition ctRefDef = new ComponentTypeReferenceDefinition("foo", contract); - ComponentReferenceDefinition definition = new ComponentReferenceDefinition(ctRefDef); - definition.setMultiplicity(Multiplicity.ONE_N); - - //ReferenceTarget target = new ReferenceTarget(); - List<URI> target = new ArrayList<URI>(); - target.add(new URI("bar")); - target.add(new URI("bar2")); - //target.setReferenceName("refName"); - - List<OutboundWire> wires = wireService.createWire(target, definition); - assertEquals(2, wires.size()); - } - - public void testCreateComponentWires() throws Exception { - ComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>> type = - new ComponentType<ServiceDefinition, ComponentTypeReferenceDefinition, Property<?>>(); - ComponentTypeReferenceDefinition referenceDefinition = new ComponentTypeReferenceDefinition("refName", contract); - type.add(referenceDefinition); - ServiceDefinition serviceDefinition = new ServiceDefinition("foo", contract, false); - type.add(serviceDefinition); - - Implementation<ComponentType> impl = new Implementation<ComponentType>() { - }; - impl.setComponentType(type); - - ComponentDefinition<Implementation<ComponentType>> definition = - new ComponentDefinition<Implementation<ComponentType>>("Foo", impl); - ComponentReferenceDefinition compRef = - new ComponentReferenceDefinition(type.getReferences().get("refName")); - compRef.addTarget(new URI("bar")); - definition.add(compRef); - - /*ReferenceTarget target = new ReferenceTarget(); - target.addTarget(new URI("bar")); - target.setReferenceName("refName"); - definition.add(target); - */ - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - component.addInboundWire(EasyMock.isA(InboundWire.class)); - component.addOutboundWire(EasyMock.isA(OutboundWire.class)); - EasyMock.replay(component); - - wireService.createWires(component, definition); - EasyMock.verify(component); - } - - public void testCreateReferenceBindingWire() throws Exception { - ReferenceBinding binding = new MockReferenceBinding(); - QualifiedName qName = new QualifiedName("target"); - - wireService.createWires(binding, contract, qName); - - InboundWire inboundWire = binding.getInboundWire(); - assertEquals(1, inboundWire.getInvocationChains().size()); - assertEquals(contract, inboundWire.getServiceContract()); - assertEquals(binding, inboundWire.getContainer()); - - OutboundWire outboundWire = binding.getOutboundWire(); - assertEquals("target", outboundWire.getTargetName().toString()); - assertEquals(1, outboundWire.getInvocationChains().size()); - assertEquals(contract, outboundWire.getServiceContract()); - assertEquals(binding, outboundWire.getContainer()); - } - - public void testCreateServiceBindingWire() throws Exception { - ServiceBinding binding = new MockServiceBinding(); - - wireService.createWires(binding, contract, "target"); - - InboundWire inboundWire = binding.getInboundWire(); - assertEquals(1, inboundWire.getInvocationChains().size()); - assertEquals(contract, inboundWire.getServiceContract()); - assertEquals(binding, inboundWire.getContainer()); - - OutboundWire outboundWire = binding.getOutboundWire(); - assertEquals("target", outboundWire.getTargetName().toString()); - assertEquals(1, outboundWire.getInvocationChains().size()); - assertEquals(contract, outboundWire.getServiceContract()); - assertEquals(binding, outboundWire.getContainer()); - assertEquals(1, outboundWire.getTargetCallbackInvocationChains().size()); - } - - protected void setUp() throws Exception { - super.setUp(); - wireService = new TestWireService(new WorkContextImpl()); - - operation = new Operation<Type>("foo", null, null, null); - callbackOperation = new Operation<Type>("foo", null, null, null); - Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>(); - operations.put("foo", operation); - Map<String, Operation<Type>> callbackOperations = new HashMap<String, Operation<Type>>(); - callbackOperations.put("foo", callbackOperation); - contract = new ServiceContract<Type>() { - }; - contract.setOperations(operations); - contract.setCallbackClass(Callback.class); - contract.setCallbackName(Callback.class.getName()); - contract.setCallbackOperations(callbackOperations); - } - - private interface Callback { - - } - - private class TestWireService extends WireServiceExtension { - protected TestWireService(WorkContext context) { - super(context, null); - } - - public <T> T createProxy(Class<T> interfaze, Wire wire) throws ProxyCreationException { - return null; - } - - public <T> T createProxy(Class<T> interfaze, Wire wire, Map<Method, OutboundChainHolder> mapping) - throws ProxyCreationException { - return null; - } - - public Object createCallbackProxy(Class<?> interfaze, InboundWire wire) throws ProxyCreationException { - return null; - } - - public WireInvocationHandler createHandler(Class<?> interfaze, Wire wire) { - return null; - } - - - public List<OutboundWire> createWire(List<URI> refTargetURIs, ComponentReferenceDefinition def) { - return super.createWire(refTargetURIs, def); - } - } - - private class MockReferenceBinding extends AbstractSCAObject implements ReferenceBinding { - private ServiceContract<?> bindingServiceContract; - private InboundWire inboundWire; - private OutboundWire outboundWire; - - public MockReferenceBinding() { - super("foo", null); - } - - public ServiceContract<?> getBindingServiceContract() { - return bindingServiceContract; - } - - public QName getBindingType() { - return null; - } - - public void setReference(Reference reference) { - - } - - public InboundWire getInboundWire() { - return inboundWire; - } - - public void setInboundWire(InboundWire inboundWire) { - this.inboundWire = inboundWire; - } - - public OutboundWire getOutboundWire() { - return outboundWire; - } - - public void setOutboundWire(OutboundWire outboundWire) { - this.outboundWire = outboundWire; - } - - public TargetInvoker createTargetInvoker(ServiceContract contract, Operation operation) - throws TargetInvokerCreationException { - return null; - } - - public Scope getScope() { - return null; - } - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.java deleted file mode 100644 index 331c0760d9..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.wire; - -import java.lang.reflect.Method; -import java.lang.reflect.Type; -import java.util.Map; - -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.OutboundChainHolder; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; - -import junit.framework.TestCase; - -/** - * @version $Rev$ $Date$ - */ -public class WireUtilsTestCase extends TestCase { - private Method m; - - public void testCreateInterfaceToWireMapping() throws Exception { - OutboundWire wire = new OutboundWireImpl(); - Operation<Type> op = new Operation<Type>("hello", null, null, null); - OutboundInvocationChain chain = new OutboundInvocationChainImpl(op); - wire.addInvocationChain(op, chain); - Map<Method, OutboundChainHolder> chains = WireUtils.createInterfaceToWireMapping(Foo.class, wire); - assertEquals(1, chains.size()); - assertNotNull(chains.get(m)); - } - - public void testCreateInterfaceToWireMappingNoOperation() throws Exception { - OutboundWire wire = new OutboundWireImpl(); - Operation<Type> op = new Operation<Type>("goodbye", null, null, null); - OutboundInvocationChain chain = new OutboundInvocationChainImpl(op); - wire.addInvocationChain(op, chain); - try { - WireUtils.createInterfaceToWireMapping(Foo.class, wire); - fail(); - } catch (NoMethodForOperationException e) { - // expected - } - } - - public void testCreateInboundMapping() throws Exception { - InboundWire wire = new InboundWireImpl(); - Operation<Type> op = new Operation<Type>("hello", null, null, null); - InboundInvocationChain chain = new InboundInvocationChainImpl(op); - wire.addInvocationChain(op, chain); - Map<Method, InboundInvocationChain> chains = WireUtils.createInboundMapping(wire, new Method[]{m}); - assertEquals(1, chains.size()); - assertNotNull(chains.get(m)); - } - - public void testCreateInboundMappingNoOperation() throws Exception { - InboundWire wire = new InboundWireImpl(); - Operation<Type> op = new Operation<Type>("goodbye", null, null, null); - InboundInvocationChain chain = new InboundInvocationChainImpl(op); - wire.addInvocationChain(op, chain); - try { - WireUtils.createInboundMapping(wire, new Method[]{m}); - fail(); - } catch (NoMethodForOperationException e) { - // expected - } - } - - protected void setUp() throws Exception { - super.setUp(); - m = Foo.class.getMethod("hello"); - } - - private interface Foo { - void hello(); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerSerializationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerSerializationTestCase.java deleted file mode 100644 index df4dc63ea4..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerSerializationTestCase.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.apache.tuscany.core.wire.jdk; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.SCAExternalizable; -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.wire.InboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class JDKCallbackInvocationHandlerSerializationTestCase extends TestCase { - private InboundWire wire; - private WorkContext workContext; - - public void testSerializeDeserialize() throws Exception { - JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(wire, workContext); - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - ObjectOutputStream ostream = new ObjectOutputStream(stream); - ostream.writeObject(handler); - - ObjectInputStream istream = new ObjectInputStream(new ByteArrayInputStream(stream.toByteArray())); - SCAExternalizable externalizable = (SCAExternalizable) istream.readObject(); - - externalizable.setWorkContext(workContext); - externalizable.reactivate(); - EasyMock.verify(wire); - } - - protected void setUp() throws Exception { - super.setUp(); - wire = EasyMock.createMock(InboundWire.class); - EasyMock.expect(wire.getServiceName()).andReturn("foo").atLeastOnce(); - EasyMock.replay(wire); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getInboundWire(EasyMock.eq("foo"))).andReturn(wire); - EasyMock.replay(component); - workContext = new WorkContextImpl(); - workContext.setCurrentAtomicComponent(component); - } - - protected void tearDown() throws Exception { - super.tearDown(); - workContext.setCurrentAtomicComponent(null); - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerTestCase.java deleted file mode 100644 index b8cbde687d..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKCallbackInvocationHandlerTestCase.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.wire.jdk; - -import java.lang.reflect.Proxy; - -import org.apache.tuscany.spi.idl.java.JavaServiceContract; - -import junit.framework.TestCase; - -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.wire.InboundWireImpl; - -/** - * @version $Rev$ $Date$ - */ -public class JDKCallbackInvocationHandlerTestCase extends TestCase { - - public void testToString() { - InboundWireImpl wire = new InboundWireImpl(); - wire.setServiceContract(new JavaServiceContract(Foo.class)); - JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(wire, new WorkContextImpl()); - Foo foo = (Foo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, handler); - assertNotNull(foo.toString()); - } - - public void testHashCode() { - InboundWireImpl wire = new InboundWireImpl(); - wire.setServiceContract(new JavaServiceContract(Foo.class)); - JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(wire, new WorkContextImpl()); - Foo foo = (Foo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, handler); - assertNotNull(foo.hashCode()); - } - - private interface Foo { - - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerSerializationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerSerializationTestCase.java deleted file mode 100644 index a631982958..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerSerializationTestCase.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.wire.jdk; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.model.Operation; -import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.TargetInvoker; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InvokerInterceptor; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class JDKInboundInvocationHandlerSerializationTestCase extends TestCase { - private InboundWire wire; - private WorkContext workContext; - private TargetInvoker invoker; - - public void testSerializeDeserialize() throws Throwable { - JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(Foo.class, wire, workContext); - handler.invoke(Foo.class.getMethod("invoke"), null); - - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - ObjectOutputStream ostream = new ObjectOutputStream(stream); - ostream.writeObject(handler); - - ObjectInputStream istream = new ObjectInputStream(new ByteArrayInputStream(stream.toByteArray())); - JDKInboundInvocationHandler externalizable = (JDKInboundInvocationHandler) istream.readObject(); - - externalizable.setWorkContext(workContext); - externalizable.reactivate(); - externalizable.invoke(Foo.class.getMethod("invoke"), null); - EasyMock.verify(wire); - EasyMock.verify(invoker); - } - - protected void setUp() throws Exception { - super.setUp(); - wire = EasyMock.createMock(InboundWire.class); - Map<Operation<?>, InboundInvocationChain> map = new HashMap<Operation<?>, InboundInvocationChain>(); - Operation<Object> operation = new Operation<Object>("invoke", null, null, null, false, null, NO_CONVERSATION); - map.put(operation, createChain(operation)); - - EasyMock.expect(wire.getServiceName()).andReturn("foo").atLeastOnce(); - EasyMock.expect(wire.getInvocationChains()).andReturn(map).times(2); - EasyMock.replay(wire); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getInboundWire(EasyMock.eq("foo"))).andReturn(wire); - EasyMock.replay(component); - workContext = new WorkContextImpl(); - workContext.setCurrentAtomicComponent(component); - } - - protected void tearDown() throws Exception { - super.tearDown(); - workContext.setCurrentAtomicComponent(null); - } - - private InboundInvocationChain createChain(Operation operation) { - invoker = EasyMock.createMock(TargetInvoker.class); - EasyMock.expect(invoker.invoke(EasyMock.isA(Message.class))).andReturn(new MessageImpl()).times(2); - EasyMock.expect(invoker.isCacheable()).andReturn(false).atLeastOnce(); - EasyMock.replay(invoker); - InboundInvocationChain chain = new InboundInvocationChainImpl(operation); - chain.setTargetInvoker(invoker); - chain.addInterceptor(new InvokerInterceptor()); - chain.prepare(); - return chain; - } - - public class Foo { - public void invoke() { - } - } - - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerTestCase.java deleted file mode 100644 index 1a4238c589..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKInboundInvocationHandlerTestCase.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.wire.jdk; - -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.idl.InvalidServiceContractException; -import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry; -import org.apache.tuscany.spi.model.DataType; -import org.apache.tuscany.spi.model.Operation; -import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -import org.apache.tuscany.core.mock.component.SimpleTarget; -import org.apache.tuscany.core.mock.component.SimpleTargetImpl; -import org.apache.tuscany.core.mock.wire.MockStaticInvoker; -import org.apache.tuscany.core.mock.wire.MockSyncInterceptor; -import org.apache.tuscany.core.wire.InboundInvocationChainImpl; -import org.apache.tuscany.core.wire.InboundWireImpl; -import org.apache.tuscany.core.wire.InvokerInterceptor; -import org.easymock.classextension.EasyMock; - -/** - * Verifies invocations on inbound wires - * - * @version $$Rev$$ $$Date$$ - */ -public class JDKInboundInvocationHandlerTestCase extends TestCase { - - private Method echo; - private Operation operation; - - public void testInterceptorInvoke() throws Throwable { - MockStaticInvoker invoker = new MockStaticInvoker(echo, new SimpleTargetImpl()); - InboundInvocationChain chain = new InboundInvocationChainImpl(operation); - MockSyncInterceptor interceptor = new MockSyncInterceptor(); - chain.addInterceptor(interceptor); - chain.addInterceptor(new InvokerInterceptor()); - chain.setTargetInvoker(invoker); - chain.prepare(); - InboundWire wire = createWire(chain); - - WorkContext workContext = EasyMock.createNiceMock(WorkContext.class); - EasyMock.replay(workContext); - JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(SimpleTarget.class, wire, workContext); - assertEquals("foo", handler.invoke(echo, new String[]{"foo"})); - assertEquals(1, interceptor.getCount()); - } - - public void testDirectErrorInvoke() throws Throwable { - InboundInvocationChain source = new InboundInvocationChainImpl(operation); - MockStaticInvoker invoker = new MockStaticInvoker(echo, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - InboundWire wire = createWire(source); - - WorkContext workContext = EasyMock.createNiceMock(WorkContext.class); - EasyMock.replay(workContext); - JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(SimpleTarget.class, wire, workContext); - try { - assertEquals("foo", handler.invoke(echo, new Object[]{})); - fail("Expected " + IllegalArgumentException.class.getName()); - } catch (IllegalArgumentException e) { - // should throw - } - } - - public void testDirectInvoke() throws Throwable { - InboundInvocationChain source = new InboundInvocationChainImpl(operation); - MockStaticInvoker invoker = new MockStaticInvoker(echo, new SimpleTargetImpl()); - source.setTargetInvoker(invoker); - InboundWire wire = createWire(source); - - WorkContext workContext = EasyMock.createNiceMock(WorkContext.class); - EasyMock.replay(workContext); - JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(SimpleTarget.class, wire, workContext); - assertEquals("foo", handler.invoke(echo, new Object[]{"foo"})); - } - - public void testToString() { - WorkContext workContext = EasyMock.createNiceMock(WorkContext.class); - EasyMock.replay(workContext); - InboundWireImpl wire = new InboundWireImpl(); - wire.setServiceContract(new ServiceContract<Foo>(Foo.class) { - }); - JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(SimpleTarget.class, wire, workContext); - Foo foo = (Foo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, handler); - assertNotNull(foo.toString()); - } - - public void testHashCode() { - WorkContext workContext = EasyMock.createNiceMock(WorkContext.class); - EasyMock.replay(workContext); - InboundWireImpl wire = new InboundWireImpl(); - wire.setServiceContract(new ServiceContract<Foo>(Foo.class) { - }); - JDKInboundInvocationHandler handler = new JDKInboundInvocationHandler(SimpleTarget.class, wire, workContext); - Foo foo = (Foo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, handler); - assertNotNull(foo.hashCode()); - } - - public void setUp() throws Exception { - super.setUp(); - JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - ServiceContract<?> contract; - try { - contract = registry.introspect(SimpleTarget.class); - } catch (InvalidServiceContractException e) { - throw new AssertionError(); - } - operation = contract.getOperations().get("echo"); - echo = SimpleTarget.class.getMethod("echo", String.class); - } - - - private InboundWire createWire(InboundInvocationChain chain) { - DataType<Type> type = new DataType<Type>(String.class, String.class); - List<DataType<Type>> types = new ArrayList<DataType<Type>>(); - types.add(type); - DataType<List<DataType<Type>>> inputType = - new DataType<List<DataType<Type>>>(Object[].class, types); - Operation<Type> operation = new Operation<Type>("echo", inputType, null, null, false, null, NO_CONVERSATION); - Map<Operation<?>, InboundInvocationChain> chains = new HashMap<Operation<?>, InboundInvocationChain>(); - chains.put(operation, chain); - InboundWire wire = new InboundWireImpl(); - wire.addInvocationChains(chains); - wire.setServiceContract(new ServiceContract<SimpleTarget>(SimpleTarget.class) { - }); - return wire; - } - - private interface Foo { - - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerProxyTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerProxyTestCase.java deleted file mode 100644 index 39d8113584..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerProxyTestCase.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.wire.jdk; - -import java.lang.reflect.Method; - -import org.apache.tuscany.spi.idl.java.JavaInterfaceProcessorRegistry; -import org.apache.tuscany.spi.idl.java.JavaServiceContract; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.TargetInvoker; - -import junit.framework.TestCase; -import org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class JDKOutboundInvocationHandlerProxyTestCase extends TestCase { - - private JavaInterfaceProcessorRegistry registry = new JavaInterfaceProcessorRegistryImpl(); - private OutboundWire wire; - private Method clientHello; - private TargetInvoker targetInvoker; - - public void testDifferentInterface() throws Throwable { - JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(Client.class, wire, null); - handler.invoke(null, clientHello, null); - EasyMock.verify(targetInvoker); - } - - protected void setUp() throws Exception { - super.setUp(); - wire = new OutboundWireImpl(); - JavaServiceContract contract = registry.introspect(Target.class); - for (Operation<?> operation : contract.getOperations().values()) { - OutboundInvocationChain chain = new OutboundInvocationChainImpl(operation); - wire.addInvocationChain(operation, chain); - targetInvoker = EasyMock.createMock(TargetInvoker.class); - EasyMock.expect(targetInvoker.invokeTarget(EasyMock.isNull(), EasyMock.eq(TargetInvoker.NONE))) - .andReturn(new MessageImpl()); - EasyMock.expect(targetInvoker.isCacheable()).andReturn(false); - EasyMock.replay(targetInvoker); - chain.setTargetInvoker(targetInvoker); - } - wire.setServiceContract(contract); - clientHello = Client.class.getMethod("hello"); - - } - - private interface Target { - String hello(); - } - - private interface Client { - String hello(); - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerSerializationTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerSerializationTestCase.java deleted file mode 100644 index c6e449d291..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerSerializationTestCase.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.wire.jdk; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.tuscany.spi.component.AtomicComponent; -import org.apache.tuscany.spi.component.SCAObject; -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.model.InteractionScope; -import org.apache.tuscany.spi.model.Operation; -import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.MessageImpl; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.TargetInvoker; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.wire.InvokerInterceptor; -import org.apache.tuscany.core.wire.OutboundInvocationChainImpl; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class JDKOutboundInvocationHandlerSerializationTestCase extends TestCase { - private OutboundWire wire; - private WorkContext workContext; - private TargetInvoker invoker; - - public void testSerializeDeserialize() throws Throwable { - JDKOutboundInvocationHandler handler = - new JDKOutboundInvocationHandler(Foo.class, wire, workContext); - handler.invoke(Foo.class.getMethod("invoke"), null); - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - ObjectOutputStream ostream = new ObjectOutputStream(stream); - ostream.writeObject(handler); - - ObjectInputStream istream = new ObjectInputStream(new ByteArrayInputStream(stream.toByteArray())); - JDKOutboundInvocationHandler externalizable = (JDKOutboundInvocationHandler) istream.readObject(); - - externalizable.setWorkContext(workContext); - externalizable.reactivate(); - externalizable.invoke(Foo.class.getMethod("invoke"), null); - EasyMock.verify(invoker); - EasyMock.verify(wire); - } - - protected void setUp() throws Exception { - super.setUp(); - SCAObject container = EasyMock.createMock(SCAObject.class); - ServiceContract<Foo> contract = new ServiceContract<Foo>() { - }; - contract.setInterfaceClass(Foo.class); - contract.setInteractionScope(InteractionScope.NONCONVERSATIONAL); - EasyMock.expect(container.getName()).andReturn("bar").atLeastOnce(); - EasyMock.replay(container); - wire = EasyMock.createMock(OutboundWire.class); - Map<Operation<?>, OutboundInvocationChain> map = new HashMap<Operation<?>, OutboundInvocationChain>(); - Operation<Object> operation = new Operation<Object>("invoke", null, null, null, false, null, NO_CONVERSATION); - ServiceContract<Object> opContract = new ServiceContract<Object>() { - }; - contract.setInterfaceClass(Foo.class); - contract.setInteractionScope(InteractionScope.NONCONVERSATIONAL); - operation.setServiceContract(opContract); - map.put(operation, createChain(operation)); - EasyMock.expect(wire.getContainer()).andReturn(container).atLeastOnce(); - EasyMock.expect(wire.getServiceContract()).andReturn(contract).atLeastOnce(); - EasyMock.expect(wire.getReferenceName()).andReturn("foo").atLeastOnce(); - EasyMock.expect(wire.getInvocationChains()).andReturn(map).times(2); - EasyMock.replay(wire); - Map<String, List<OutboundWire>> wires = new HashMap<String, List<OutboundWire>>(); - List<OutboundWire> list = new ArrayList<OutboundWire>(); - list.add(wire); - wires.put("foo", list); - AtomicComponent component = EasyMock.createMock(AtomicComponent.class); - EasyMock.expect(component.getOutboundWires()).andReturn(wires); - EasyMock.replay(component); - workContext = new WorkContextImpl(); - workContext.setCurrentAtomicComponent(component); - } - - protected void tearDown() throws Exception { - super.tearDown(); - workContext.setCurrentAtomicComponent(null); - } - - private OutboundInvocationChain createChain(Operation operation) { - invoker = EasyMock.createMock(TargetInvoker.class); - EasyMock.expect(invoker.invoke(EasyMock.isA(Message.class))).andReturn(new MessageImpl()).times(2); - EasyMock.expect(invoker.isCacheable()).andReturn(false).atLeastOnce(); - EasyMock.replay(invoker); - OutboundInvocationChain chain = new OutboundInvocationChainImpl(operation); - chain.setTargetInvoker(invoker); - chain.addInterceptor(new InvokerInterceptor()); - chain.prepare(); - return chain; - } - - public class Foo { - - public void invoke() { - } - } - -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerTestCase.java deleted file mode 100644 index 4d2af8acf9..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKOutboundInvocationHandlerTestCase.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.wire.jdk; - -import java.lang.reflect.Array; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Proxy; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.apache.tuscany.spi.component.WorkContext; -import org.apache.tuscany.spi.idl.java.JavaServiceContract; -import org.apache.tuscany.spi.model.DataType; -import org.apache.tuscany.spi.model.InteractionScope; -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.model.Scope; -import org.apache.tuscany.spi.model.ServiceContract; -import org.apache.tuscany.spi.wire.InvocationRuntimeException; -import org.apache.tuscany.spi.wire.Message; -import org.apache.tuscany.spi.wire.OutboundInvocationChain; -import org.apache.tuscany.spi.wire.OutboundWire; -import org.apache.tuscany.spi.wire.TargetInvoker; - -import junit.framework.TestCase; -import org.apache.tuscany.core.component.WorkContextImpl; -import org.apache.tuscany.core.wire.OutboundWireImpl; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; - -/** - * @version $Rev$ $Date$ - */ -public class JDKOutboundInvocationHandlerTestCase extends TestCase { - - public void testToString() { - OutboundWireImpl wire = new OutboundWireImpl(); - ServiceContract contract = new JavaServiceContract(Foo.class); - contract.setInteractionScope(InteractionScope.NONCONVERSATIONAL); - wire.setServiceContract(contract); - JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(Foo.class, wire, null); - Foo foo = (Foo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, handler); - assertNotNull(foo.toString()); - } - - public void testHashCode() { - OutboundWireImpl wire = new OutboundWireImpl(); - ServiceContract contract = new JavaServiceContract(Foo.class); - contract.setInteractionScope(InteractionScope.NONCONVERSATIONAL); - wire.setServiceContract(contract); - JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(Foo.class, wire, null); - Foo foo = (Foo) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Foo.class}, handler); - assertNotNull(foo.hashCode()); - } - - public void testConversational() throws Throwable { - OutboundWire outboundWire = createMock(OutboundWire.class); - Map<Operation<?>, OutboundInvocationChain> outboundChains = - new HashMap<Operation<?>, OutboundInvocationChain>(); - DataType<Type> type1 = new DataType<Type>(String.class, String.class); - List<DataType<Type>> types = new ArrayList<DataType<Type>>(); - types.add(type1); - DataType<List<DataType<Type>>> inputType1 = new DataType<List<DataType<Type>>>(Object[].class, types); - DataType<Type> outputType1 = new DataType<Type>(String.class, String.class); - Operation<Type> op1 = new Operation<Type>("test", inputType1, outputType1, null); - ServiceContract<Type> outboundContract = new JavaServiceContract(Foo.class); - outboundContract.setInteractionScope(InteractionScope.CONVERSATIONAL); - op1.setServiceContract(outboundContract); - - WorkContext wc = new WorkContextImpl(); - MockInvoker invoker = new MockInvoker(wc); - OutboundInvocationChain outboundChain = createMock(OutboundInvocationChain.class); - expect(outboundChain.getTargetInvoker()).andReturn(invoker).anyTimes(); - expect(outboundChain.getHeadInterceptor()).andReturn(null).anyTimes(); - replay(outboundChain); - outboundChains.put(op1, outboundChain); - expect(outboundWire.getInvocationChains()).andReturn(outboundChains).anyTimes(); - expect(outboundWire.getReferenceName()).andReturn("fooRef").atLeastOnce(); - expect(outboundWire.getContainer()).andReturn(null).anyTimes(); - expect(outboundWire.getServiceContract()).andReturn(outboundContract).anyTimes(); - replay(outboundWire); - - String convID = UUID.randomUUID().toString(); - wc.setIdentifier(Scope.CONVERSATION, convID); - invoker.setCurrentConversationID(convID); - - outboundContract.setRemotable(true); - invoker.setRemotableTest(true); - JDKOutboundInvocationHandler handler = new JDKOutboundInvocationHandler(Foo.class, outboundWire, wc); - handler.invoke(Foo.class.getMethod("test", String.class), new Object[]{"bar"}); - String currentConvID = (String) wc.getIdentifier(Scope.CONVERSATION); - assertSame(convID, currentConvID); - - outboundContract.setRemotable(false); - invoker.setRemotableTest(false); - JDKOutboundInvocationHandler handler2 = new JDKOutboundInvocationHandler(Foo.class, outboundWire, wc); - handler2.invoke(Foo.class.getMethod("test", String.class), new Object[]{"bar"}); - currentConvID = (String) wc.getIdentifier(Scope.CONVERSATION); - assertSame(convID, currentConvID); - } - - private interface Foo { - String test(String s); - } - - private class MockInvoker implements TargetInvoker { - - private WorkContext wc; - private String currentConversationID; - private boolean remotableTest; - - public MockInvoker(WorkContext wc) { - this.wc = wc; - } - - public void setCurrentConversationID(String id) { - currentConversationID = id; - } - - public void setRemotableTest(boolean remotableTest) { - this.remotableTest = remotableTest; - } - - public Object invokeTarget(final Object payload, final short sequence) throws InvocationTargetException { - assertEquals("bar", Array.get(payload, 0)); - String convID = (String) wc.getIdentifier(Scope.CONVERSATION); - if (remotableTest) { - assertNotSame(convID, currentConversationID); - } else { - assertSame(convID, currentConversationID); - } - return "response"; - } - - public Message invoke(Message msg) throws InvocationRuntimeException { - fail(); - return null; - } - - public boolean isCacheable() { - return false; - } - - public void setCacheable(boolean cacheable) { - - } - - public boolean isOptimizable() { - return false; - } - - public Object clone() throws CloneNotSupportedException { - return super.clone(); - } - } -} diff --git a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKProxyTestCase.java b/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKProxyTestCase.java deleted file mode 100644 index 994d944d98..0000000000 --- a/branches/sca-java-integration/sca/kernel/core/src/test/java/org/apache/tuscany/core/wire/jdk/JDKProxyTestCase.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.core.wire.jdk; - -import java.lang.reflect.Proxy; -import java.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.spi.model.Operation; -import org.apache.tuscany.spi.wire.InboundInvocationChain; -import org.apache.tuscany.spi.wire.InboundWire; - -import junit.framework.TestCase; -import org.easymock.EasyMock; - -/** - * @version $Rev$ $Date$ - */ -public class JDKProxyTestCase extends TestCase { - private JDKWireService wireService; - private InboundWire inboundWire; - private Map<Operation<?>, InboundInvocationChain> chains; - - public void testCreateProxy() { - EasyMock.expect(inboundWire.getServiceName()).andReturn("service"); - EasyMock.expect(inboundWire.getInvocationChains()).andReturn(chains); - EasyMock.replay(inboundWire); - TestInterface intf = wireService.createProxy(TestInterface.class, inboundWire); - assertTrue(Proxy.isProxyClass(intf.getClass())); - EasyMock.verify(inboundWire); - } - - protected void setUp() throws Exception { - super.setUp(); - wireService = new JDKWireService(); - inboundWire = EasyMock.createMock(InboundWire.class); - chains = new HashMap<Operation<?>, InboundInvocationChain>(); - } - - public static interface TestInterface { - int primitives(int i); - - String objects(String object); - } -} |