diff options
author | dims <dims@13f79535-47bb-0310-9956-ffa450edef68> | 2008-06-17 00:23:01 +0000 |
---|---|---|
committer | dims <dims@13f79535-47bb-0310-9956-ffa450edef68> | 2008-06-17 00:23:01 +0000 |
commit | bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a (patch) | |
tree | 38a92061c0793434c4be189f1d70c3458b6bc41d /sandbox/rfeng/minicore/src/test |
Move Tuscany from Incubator to top level.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
113 files changed, 7852 insertions, 0 deletions
diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/binding/local/AbstractLocalTargetInvokerTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/binding/local/AbstractLocalTargetInvokerTestCase.java new file mode 100644 index 0000000000..dfda132671 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/binding/local/AbstractLocalTargetInvokerTestCase.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.InvocationChain; +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.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); + InvocationChain chain = EasyMock.createMock(InvocationChain.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); + InvocationChain chain = EasyMock.createMock(InvocationChain.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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingBuilderTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingBuilderTestCase.java new file mode 100644 index 0000000000..e628df47e2 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingBuilderTestCase.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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 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.setUri(new URI("#foo")); + ServiceBinding binding = builder.build(def, null, null); + assertEquals(LocalServiceBinding.class, binding.getClass()); + } +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingLoaderTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingLoaderTestCase.java new file mode 100644 index 0000000000..0c35ae9a09 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/binding/local/LocalBindingLoaderTestCase.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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, 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, 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, reader, null); + fail(); + } catch (LoaderException e) { + // expected + } + EasyMock.verify(reader); + } + + protected void setUp() throws Exception { + super.setUp(); + loader = new LocalBindingLoader(null); + } +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerInvocationExceptionTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerInvocationExceptionTestCase.java new file mode 100644 index 0000000000..9b83d95918 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerInvocationExceptionTestCase.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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 org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.wire.Interceptor; +import org.apache.tuscany.spi.wire.InvocationChain; +import org.apache.tuscany.spi.wire.Message; +import org.apache.tuscany.spi.wire.MessageImpl; +import org.apache.tuscany.spi.wire.Wire; + +import junit.framework.TestCase; +import org.apache.tuscany.core.wire.InvocationChainImpl; +import org.apache.tuscany.core.wire.WireImpl; + +/** + * @version $Rev$ $Date$ + */ +public class LocalCallbackTargetInvokerInvocationExceptionTestCase extends TestCase { + + /** + * 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 { + Operation<Type> operation = new Operation<Type>("echo", null, null, null); + Interceptor head = new ErrorInterceptor(); + InvocationChain chain = new InvocationChainImpl(operation); + chain.addInterceptor(head); + Wire wire = new WireImpl(); + wire.addCallbackInvocationChain(operation, chain); + LocalCallbackTargetInvoker invoker = new LocalCallbackTargetInvoker(operation, wire); + Message msg = new MessageImpl(); + msg.setBody("foo"); + Message response = invoker.invoke(msg); + assertTrue(response.isFault()); + Object body = response.getBody(); + assertTrue(SomeException.class.equals(body.getClass())); + } + + 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerTestCase.java new file mode 100644 index 0000000000..d922ec8033 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerTestCase.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.net.URI; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.wire.Interceptor; +import org.apache.tuscany.spi.wire.InvocationChain; +import org.apache.tuscany.spi.wire.Message; +import org.apache.tuscany.spi.wire.MessageImpl; +import org.apache.tuscany.spi.wire.Wire; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class LocalCallbackTargetInvokerTestCase extends TestCase { + private Wire wire; + private Message message; + private InvocationChain 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(); + URI targetAddress = URI.create("from"); + message = new MessageImpl(); + message.pushCallbackUri(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(InvocationChain.class); + EasyMock.expect(chain.getTargetInvoker()).andReturn(null); + EasyMock.expect(chain.getHeadInterceptor()).andReturn(head); + EasyMock.replay(chain); + Map<Operation<?>, InvocationChain> chains = new HashMap<Operation<?>, InvocationChain>(); + chains.put(operation, chain); + wire = EasyMock.createMock(Wire.class); + EasyMock.expect(wire.getCallbackInvocationChains()).andReturn(chains); + EasyMock.replay(wire); + + invoker = new LocalCallbackTargetInvoker(operation, wire); + } + + +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerThrowableTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerThrowableTestCase.java new file mode 100644 index 0000000000..0c06842a60 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/binding/local/LocalCallbackTargetInvokerThrowableTestCase.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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 org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.wire.Interceptor; +import org.apache.tuscany.spi.wire.InvocationChain; +import org.apache.tuscany.spi.wire.Message; +import org.apache.tuscany.spi.wire.MessageImpl; +import org.apache.tuscany.spi.wire.Wire; + +import junit.framework.TestCase; +import org.apache.tuscany.core.wire.InvocationChainImpl; +import org.apache.tuscany.core.wire.WireImpl; + +/** + * @version $Rev$ $Date$ + */ +public class LocalCallbackTargetInvokerThrowableTestCase extends TestCase { + private LocalCallbackTargetInvoker invoker; + + /** + * Verfies an exception thrown in the target is propagated to the client correctly + */ + public void testThrowableTargetInvocation() throws Exception { + Message message = new MessageImpl(); + message.setBody("foo"); + Message response = invoker.invoke(message); + assertTrue(response.isFault()); + Object body = response.getBody(); + if (!(body instanceof InsidiousException)) { + fail(); + } + } + + @SuppressWarnings("unchecked") + protected void setUp() throws Exception { + super.setUp(); + Operation<Type> operation = new Operation<Type>("echo", null, null, null); + InvocationChain chain = new InvocationChainImpl(operation); + chain.addInterceptor(new InsidiuousInterceptor()); + Wire wire = new WireImpl(); + wire.addCallbackInvocationChain(operation, chain); + invoker = new LocalCallbackTargetInvoker(operation, wire); + } + + private class InsidiousException extends RuntimeException { + + } + + private class InsidiuousInterceptor implements Interceptor { + + public Message invoke(Message msg) throws InsidiousException { + throw new InsidiousException(); + } + + public void setNext(Interceptor next) { + + } + + public Interceptor getNext() { + return null; + } + + public boolean isOptimizable() { + return false; + } + } + + +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java new file mode 100644 index 0000000000..e49447164d --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/binding/local/LocalTargetInvokerTestCase.java @@ -0,0 +1,115 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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 org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.model.ServiceContract; +import org.apache.tuscany.spi.wire.InvocationChain; +import org.apache.tuscany.spi.wire.Message; +import org.apache.tuscany.spi.wire.MessageImpl; +import org.apache.tuscany.spi.wire.TargetInvoker; +import org.apache.tuscany.spi.wire.Wire; + +import junit.framework.TestCase; +import org.apache.tuscany.core.wire.InvocationChainImpl; +import org.apache.tuscany.core.wire.WireImpl; +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); + InvocationChain chain = new InvocationChainImpl(operation); + chain.setTargetInvoker(targetInvoker); + Wire wire = new WireImpl(); + wire.addInvocationChain(operation, chain); + wire.setSourceContract(serviceContract); + 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); + + InvocationChain chain = new InvocationChainImpl(operation); + chain.setTargetInvoker(targetInvoker); + InvocationChain callbackChain = new InvocationChainImpl(operation); + Wire wire = new WireImpl(); + wire.addInvocationChain(operation, chain); + wire.addCallbackInvocationChain(operation, callbackChain); + wire.setSourceContract(serviceContract); + URI uri = URI.create("foo"); + wire.setSourceUri(uri); + wire.addInvocationChain(operation, chain); + TargetInvoker invoker = new LocalTargetInvoker(operation, wire); + Message msg = EasyMock.createMock(Message.class); + msg.pushCallbackUri(EasyMock.eq(uri)); + 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); + + InvocationChain chain = new InvocationChainImpl(operation); + chain.setTargetInvoker(targetInvoker); + Wire wire = new WireImpl(); + wire.setSourceContract(serviceContract); + wire.addInvocationChain(operation, chain); + 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryNoBindingsTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryNoBindingsTestCase.java new file mode 100644 index 0000000000..f13ed3367d --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryNoBindingsTestCase.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.Component; +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.Multiplicity; +import org.apache.tuscany.spi.model.ReferenceDefinition; +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.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class BuilderRegistryNoBindingsTestCase extends TestCase { + private DeploymentContext deploymentContext; + private Component parent; + private BuilderRegistry registry; + + public void testNoServiceBindings() throws Exception { + ServiceBinding binding = EasyMock.createNiceMock(ServiceBinding.class); + EasyMock.replay(binding); + ServiceDefinition definition = new ServiceDefinition(URI.create("#foo"), null, false); + definition.setTarget(new URI("foo")); + EasyMock.replay(deploymentContext); + EasyMock.replay(parent); + + Service service = registry.build(definition, deploymentContext); + + assertEquals(1, service.getServiceBindings().size()); + assertTrue(service.getServiceBindings().get(0) instanceof LocalServiceBinding); + EasyMock.verify(deploymentContext); + EasyMock.verify(parent); + } + + public void testReferenceBindingBuilderDispatch() throws Exception { + ReferenceBinding binding = EasyMock.createNiceMock(ReferenceBinding.class); + EasyMock.replay(binding); + ReferenceDefinition definition = new ReferenceDefinition(URI.create("#foo"), null, Multiplicity.ONE_ONE); + EasyMock.replay(deploymentContext); + EasyMock.replay(parent); + + Reference reference = registry.build(definition, deploymentContext); + + assertEquals(1, reference.getReferenceBindings().size()); + assertTrue(reference.getReferenceBindings().get(0) instanceof LocalReferenceBinding); + EasyMock.verify(deploymentContext); + EasyMock.verify(parent); + } + + protected void setUp() throws Exception { + super.setUp(); + deploymentContext = EasyMock.createMock(DeploymentContext.class); + parent = EasyMock.createNiceMock(Component.class); + registry = new BuilderRegistryImpl(null); + registry.register(LocalBindingDefinition.class, new LocalBindingBuilder()); + } + + +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryTestCase.java new file mode 100644 index 0000000000..34173154b8 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/BuilderRegistryTestCase.java @@ -0,0 +1,190 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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 java.util.Map; + +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.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.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.ReferenceDefinition; +import org.apache.tuscany.spi.model.Scope; +import org.apache.tuscany.spi.model.ServiceDefinition; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class BuilderRegistryTestCase extends TestCase { + private DeploymentContext deploymentContext; + private ScopeContainer scopeContainer; + private Map<URI, Component> components; + + //private BuilderRegistryImpl registry; + private Component parent; + + @SuppressWarnings({"unchecked"}) + public void testRegistration() throws Exception { + URI componentId = URI.create("sca://localhost/component"); + CompositeImplementation implementation = new CompositeImplementation(); + ComponentDefinition<CompositeImplementation> componentDefinition = + new ComponentDefinition<CompositeImplementation>(implementation); + componentDefinition.getImplementation().setComponentType(new CompositeComponentType()); + + Component component = EasyMock.createMock(Component.class); + component.setDefaultPropertyValues(componentDefinition.getPropertyValues()); + component.setScopeContainer(scopeContainer); + EasyMock.expect(component.getUri()).andReturn(componentId); + EasyMock.replay(component); + + EasyMock.expect(deploymentContext.getCompositeScope()).andReturn(scopeContainer); + EasyMock.expect(deploymentContext.getComponents()).andReturn(components); + EasyMock.replay(deploymentContext); + + EasyMock.expect(components.put(componentId, component)).andReturn(null); + EasyMock.replay(components); + + ComponentBuilder builder = EasyMock.createMock(ComponentBuilder.class); + EasyMock.expect(builder.build(componentDefinition, deploymentContext)).andReturn(component); + EasyMock.replay(builder); + + BuilderRegistry registry = new BuilderRegistryImpl(null); + registry.register(CompositeImplementation.class, builder); + + assertSame(component, registry.build(componentDefinition, deploymentContext)); + EasyMock.verify(builder); + } + + @SuppressWarnings({"unchecked"}) + public void testServiceBindingBuilderDispatch() throws Exception { + BuilderRegistry registry = new BuilderRegistryImpl(null); + ServiceBinding binding = EasyMock.createNiceMock(ServiceBinding.class); + EasyMock.replay(binding); + BindingBuilder<MockBindingDefinition> builder = EasyMock.createMock(BindingBuilder.class); + EasyMock.expect(builder.build( + 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(URI.create("#foo"), null, false); + definition.addBinding(new MockBindingDefinition()); + definition.addBinding(new MockBindingDefinition()); + definition.setTarget(new URI("foo")); + Service service = registry.build(definition, deploymentContext); + assertEquals(2, service.getServiceBindings().size()); + } + + @SuppressWarnings({"unchecked"}) + public void testReferenceBindingBuilderDispatch() throws Exception { + BuilderRegistry registry = new BuilderRegistryImpl(null); + ReferenceBinding binding = EasyMock.createNiceMock(ReferenceBinding.class); + EasyMock.replay(binding); + BindingBuilder<MockBindingDefinition> builder = EasyMock.createMock(BindingBuilder.class); + EasyMock.expect(builder.build( + EasyMock.isA(ReferenceDefinition.class), + EasyMock.isA(MockBindingDefinition.class), + EasyMock.isA(DeploymentContext.class))).andReturn(binding).times(2); + EasyMock.replay(builder); + registry.register(MockBindingDefinition.class, builder); + ReferenceDefinition definition = new ReferenceDefinition(URI.create("#foo"), null, ONE_ONE); + definition.addBinding(new MockBindingDefinition()); + definition.addBinding(new MockBindingDefinition()); + Reference reference = registry.build(definition, deploymentContext); + assertEquals(2, reference.getReferenceBindings().size()); + } + + @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); + BuilderRegistry registry = new BuilderRegistryImpl(scopeRegistry); + + AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class); + EasyMock.replay(component); + ComponentBuilder<FooImplementation> builder = EasyMock.createMock(ComponentBuilder.class); + EasyMock.expect(builder.build( + 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); + URI uri = URI.create("foo"); + ComponentDefinition<FooImplementation> definition = new ComponentDefinition<FooImplementation>(uri, impl); + try { + registry.build(definition, deploymentContext); + fail("Should throw NoConversationalContractException"); + } catch (NoConversationalContractException e) { + // expected + } + } + + @SuppressWarnings({"unchecked"}) + protected void setUp() throws Exception { + super.setUp(); + deploymentContext = EasyMock.createMock(DeploymentContext.class); + parent = EasyMock.createNiceMock(Component.class); + scopeContainer = EasyMock.createMock(ScopeContainer.class); + components = EasyMock.createMock(Map.class); + } + + private class MockBuilder implements ComponentBuilder<CompositeImplementation> { + public Component build( + ComponentDefinition componentDefinition, + DeploymentContext deploymentContext) throws BuilderConfigException { + return null; + } + } + + private class MockBindingDefinition extends BindingDefinition { + + } + + private class FooImplementation extends Implementation<ComponentType> { + + } + + +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/ConnectorImplTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/ConnectorImplTestCase.java new file mode 100644 index 0000000000..4c4e1a32b0 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/ConnectorImplTestCase.java @@ -0,0 +1,320 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.net.URI; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import javax.xml.namespace.QName; + +import org.apache.tuscany.spi.component.AtomicComponent; +import org.apache.tuscany.spi.component.Component; +import org.apache.tuscany.spi.component.ComponentManager; +import org.apache.tuscany.spi.model.ComponentDefinition; +import org.apache.tuscany.spi.model.ComponentType; +import org.apache.tuscany.spi.model.Implementation; +import org.apache.tuscany.spi.model.Operation; +import org.apache.tuscany.spi.model.Property; +import org.apache.tuscany.spi.model.ReferenceDefinition; +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.Interceptor; +import org.apache.tuscany.spi.wire.InvocationChain; +import org.apache.tuscany.spi.wire.Wire; + +import junit.framework.TestCase; +import org.apache.tuscany.core.component.ComponentManagerImpl; +import org.apache.tuscany.core.wire.InvokerInterceptor; +import org.apache.tuscany.core.wire.NonBlockingInterceptor; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class ConnectorImplTestCase extends TestCase { + private TestConnector connector; + private ComponentManager manager; + + public void testConnectTargetNotFound() throws Exception { + Implementation<ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>> impl = + new Implementation<ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>>() { + }; + ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type = + new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>(); + URI refUri = URI.create("ref"); + ReferenceDefinition referenceDefinition = new ReferenceDefinition(refUri, null); + referenceDefinition.setRequired(true); + type.add(referenceDefinition); + impl.setComponentType(type); + + URI sourceUri = URI.create("source"); + ComponentDefinition<?> definition = + new ComponentDefinition<Implementation<ComponentType<ServiceDefinition, + ReferenceDefinition, Property<?>>>>(impl); + definition.setUri(sourceUri); + ReferenceTarget referenceTarget = new ReferenceTarget(); + referenceTarget.setReferenceName(refUri); + referenceTarget.addTarget(URI.create("NotThere")); + definition.add(referenceTarget); + Component component = EasyMock.createMock(Component.class); + EasyMock.expect(component.getUri()).andReturn(sourceUri); + EasyMock.replay(component); + manager.register(component); + try { + connector.connect(definition); + fail(); + } catch (ComponentNotFoundException e) { + // expected + } + } + + /** + * Verifies a non-existent target does not throw an error. + * <p/> + * TODO JFM when the allocator is in place it should optimize connecting to non-existent targets but keep it for + * now + */ + public void testConnectTargetNotFoundNonRequiredReference() throws Exception { + Implementation<ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>> impl = + new Implementation<ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>>() { + }; + ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type = + new ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>(); + URI refUri = URI.create("ref"); + ReferenceDefinition referenceDefinition = new ReferenceDefinition(refUri, null); + referenceDefinition.setRequired(false); + type.add(referenceDefinition); + impl.setComponentType(type); + + URI sourceUri = URI.create("source"); + ComponentDefinition<?> definition = + new ComponentDefinition<Implementation<ComponentType<ServiceDefinition, + ReferenceDefinition, Property<?>>>>(impl); + definition.setUri(sourceUri); + ReferenceTarget referenceTarget = new ReferenceTarget(); + referenceTarget.setReferenceName(refUri); + referenceTarget.addTarget(URI.create("NotThere")); + definition.add(referenceTarget); + Component component = EasyMock.createMock(Component.class); + EasyMock.expect(component.getUri()).andReturn(sourceUri); + EasyMock.replay(component); + manager.register(component); + connector.connect(definition); + } + + public void testNonOptimizableTargetComponent() throws Exception { + AtomicComponent source = EasyMock.createMock(AtomicComponent.class); + EasyMock.expect(source.getScope()).andReturn(Scope.COMPOSITE); + EasyMock.replay(source); + + AtomicComponent target = EasyMock.createMock(AtomicComponent.class); + EasyMock.expect(target.getScope()).andReturn(Scope.COMPOSITE); + EasyMock.expect(target.isOptimizable()).andReturn(false); + EasyMock.replay(target); + + Wire wire = EasyMock.createMock(Wire.class); + wire.setOptimizable(false); + EasyMock.replay(wire); + connector.optimize(source, target, wire); + EasyMock.verify(source); + EasyMock.verify(target); + EasyMock.verify(wire); + } + + public void testOptimizableTargetComponent() throws Exception { + AtomicComponent source = EasyMock.createMock(AtomicComponent.class); + EasyMock.expect(source.getScope()).andReturn(Scope.COMPOSITE); + EasyMock.replay(source); + + AtomicComponent target = EasyMock.createMock(AtomicComponent.class); + EasyMock.expect(target.getScope()).andReturn(Scope.COMPOSITE); + EasyMock.expect(target.isOptimizable()).andReturn(true); + EasyMock.replay(target); + + Wire wire = EasyMock.createMock(Wire.class); + wire.setOptimizable(true); + wire.setTarget(EasyMock.eq(target)); + wire.getInvocationChains(); + EasyMock.expectLastCall().andReturn(Collections.emptyMap()); + wire.getCallbackInvocationChains(); + EasyMock.expectLastCall().andReturn(Collections.emptyMap()); + EasyMock.replay(wire); + connector.optimize(source, target, wire); + EasyMock.verify(source); + EasyMock.verify(target); + } + + 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 testCreateSyncForwardWire() throws Exception { + ServiceContract<Type> contract = new ServiceContract<Type>() { + + }; + Operation<Type> operation = new Operation<Type>("operation", null, null, null); + Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>(); + operations.put("operation", operation); + contract.setOperations(operations); + Wire wire = connector.createWire(URI.create("target"), URI.create("#ref"), contract, Wire.LOCAL_BINDING); + assertEquals(1, wire.getInvocationChains().size()); + InvocationChain chain = wire.getInvocationChains().get(operation); + Interceptor head = chain.getHeadInterceptor(); + assertTrue(head instanceof InvokerInterceptor); + } + + public void testCreateSyncCallbackWire() throws Exception { + ServiceContract<Type> contract = new ServiceContract<Type>() { + + }; + + Operation<Type> operation = new Operation<Type>("operation", null, null, null); + Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>(); + operations.put("operation", operation); + contract.setOperations(operations); + + Operation<Type> callbackOperation = new Operation<Type>("operation", null, null, null); + Map<String, Operation<Type>> callbackOperations = new HashMap<String, Operation<Type>>(); + callbackOperations.put("operation", callbackOperation); + contract.setCallbackOperations(callbackOperations); + + Wire wire = connector.createWire(URI.create("target"), URI.create("#ref"), contract, Wire.LOCAL_BINDING); + assertEquals(1, wire.getCallbackInvocationChains().size()); + InvocationChain chain = wire.getCallbackInvocationChains().get(callbackOperation); + Interceptor head = chain.getHeadInterceptor(); + assertTrue(head instanceof InvokerInterceptor); + } + + public void testCreateNonBlockingForwardWire() throws Exception { + ServiceContract<Type> contract = new ServiceContract<Type>() { + + }; + Operation<Type> operation = new Operation<Type>("operation", null, null, null); + operation.setNonBlocking(true); + Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>(); + operations.put("operation", operation); + contract.setOperations(operations); + Wire wire = connector.createWire(URI.create("target"), URI.create("#ref"), contract, Wire.LOCAL_BINDING); + assertEquals(1, wire.getInvocationChains().size()); + InvocationChain chain = wire.getInvocationChains().get(operation); + Interceptor head = chain.getHeadInterceptor(); + assertTrue(head instanceof NonBlockingInterceptor); + assertTrue(head.getNext() instanceof InvokerInterceptor); + } + + public void testCreateNonBlockingCallbackWire() throws Exception { + ServiceContract<Type> contract = new ServiceContract<Type>() { + + }; + + Operation<Type> operation = new Operation<Type>("operation", null, null, null); + operation.setNonBlocking(true); + Map<String, Operation<Type>> operations = new HashMap<String, Operation<Type>>(); + operations.put("operation", operation); + contract.setOperations(operations); + + Operation<Type> callbackOperation = new Operation<Type>("operation", null, null, null); + callbackOperation.setNonBlocking(true); + Map<String, Operation<Type>> callbackOperations = new HashMap<String, Operation<Type>>(); + callbackOperations.put("operation", callbackOperation); + contract.setCallbackOperations(callbackOperations); + + Wire wire = connector.createWire(URI.create("target"), URI.create("#ref"), contract, Wire.LOCAL_BINDING); + assertEquals(1, wire.getCallbackInvocationChains().size()); + InvocationChain chain = wire.getCallbackInvocationChains().get(callbackOperation); + Interceptor head = chain.getHeadInterceptor(); + assertTrue(head instanceof NonBlockingInterceptor); + assertTrue(head.getNext() instanceof InvokerInterceptor); + } + + protected void setUp() throws Exception { + super.setUp(); + manager = new ComponentManagerImpl(); + connector = new TestConnector(manager); + } + + private class TestConnector extends ConnectorImpl { + + public TestConnector(ComponentManager componentManager) { + super(componentManager); + } + + protected Wire createWire(URI sourceURI, URI targetUri, ServiceContract<?> contract, QName bindingType) { + return super.createWire(sourceURI, targetUri, contract, bindingType); + } + + public boolean isOptimizable(Scope pReferrer, Scope pReferee) { + return super.isOptimizable(pReferrer, pReferee); + } + + } + +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/IllegalCallbackExceptionTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/IllegalCallbackExceptionTestCase.java new file mode 100644 index 0000000000..c6a9927db3 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/IllegalCallbackExceptionTestCase.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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 junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class IllegalCallbackExceptionTestCase extends TestCase { + + public void testInstantiation() throws Exception { + URI sourceUri = URI.create("source"); + URI targetUri = URI.create("target"); + IllegalCallbackException e = new IllegalCallbackException("message", "identifier", sourceUri, targetUri); + assertEquals("message", e.getMessage()); + assertEquals("identifier", e.getIdentifier()); + assertEquals(sourceUri, e.getSourceUri()); + assertEquals(targetUri, e.getTargetUri()); + + } +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/IncompatibleInterfacesExceptionTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/IncompatibleInterfacesExceptionTestCase.java new file mode 100644 index 0000000000..5d370fcfc5 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/IncompatibleInterfacesExceptionTestCase.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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 junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class IncompatibleInterfacesExceptionTestCase extends TestCase { + + public void testInstantiation() throws Exception { + URI sourceUri = URI.create("source"); + URI targetUri = URI.create("target"); + IncompatibleInterfacesException e = new IncompatibleInterfacesException(sourceUri, targetUri); + assertNotNull(e.getMessage()); + assertEquals("source", e.getSourceUri().toString()); + assertEquals("target", e.getTargetUri().toString()); + } +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/InvalidSourceTypeExceptionTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/InvalidSourceTypeExceptionTestCase.java new file mode 100644 index 0000000000..67ad003d58 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/InvalidSourceTypeExceptionTestCase.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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 junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class InvalidSourceTypeExceptionTestCase extends TestCase { + + public void testInstantiation() throws Exception { + URI sourceUri = URI.create("source"); + URI targetUri = URI.create("target"); + InvalidSourceTypeException e = new InvalidSourceTypeException("message", sourceUri, targetUri); + assertEquals("message", e.getMessage()); + assertEquals(sourceUri, e.getSourceUri()); + assertEquals(targetUri, e.getTargetUri()); + + } +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/InvalidTargetTypeExceptionTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/InvalidTargetTypeExceptionTestCase.java new file mode 100644 index 0000000000..61060293ce --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/InvalidTargetTypeExceptionTestCase.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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 junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class InvalidTargetTypeExceptionTestCase extends TestCase { + + public void testInstantiation() throws Exception { + URI sourceUri = URI.create("source"); + URI targetUri = URI.create("target"); + InvalidTargetTypeException e = new InvalidTargetTypeException("message", sourceUri, targetUri); + assertEquals("message", e.getMessage()); + assertEquals(sourceUri, e.getSourceUri()); + assertEquals(targetUri, e.getTargetUri()); + + } +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/TargetServiceNotFoundExceptionTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/TargetServiceNotFoundExceptionTestCase.java new file mode 100644 index 0000000000..2d056ac964 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/TargetServiceNotFoundExceptionTestCase.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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 junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class TargetServiceNotFoundExceptionTestCase extends TestCase { + + public void testInstantiation() throws Exception { + URI sourceUri = URI.create("source"); + URI targetUri = URI.create("target"); + TargetServiceNotFoundException e = new TargetServiceNotFoundException("message", sourceUri, targetUri); + assertEquals("message", e.getMessage()); + assertEquals(sourceUri, e.getSourceUri()); + assertEquals(targetUri, e.getTargetUri()); + } +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/WirePostProcessorRegistryImplTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/WirePostProcessorRegistryImplTestCase.java new file mode 100644 index 0000000000..fcd5f03189 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/WirePostProcessorRegistryImplTestCase.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.Wire; +import org.apache.tuscany.spi.wire.WirePostProcessor; +import org.apache.tuscany.spi.wire.WirePostProcessorRegistry; + +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(); + Wire wire = EasyMock.createMock(Wire.class); + WirePostProcessor processor = createMock(WirePostProcessor.class); + processor.process(EasyMock.eq(wire)); + EasyMock.replay(processor); + registry.register(processor); + registry.process(wire); + registry.unregister(processor); + registry.process(wire); + verify(processor); + } + +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/WiringExceptionFormatterTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/WiringExceptionFormatterTestCase.java new file mode 100644 index 0000000000..e05a162d7a --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder/WiringExceptionFormatterTestCase.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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 java.net.URI; + +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", URI.create("source"), URI.create("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("identifier") >= 0); + assertTrue(buffer.indexOf("source") >= 0); + assertTrue(buffer.indexOf("target") >= 0); + } + + + public void testFormatNulls() throws Exception { + WiringException e = new MockWiringException("message", + "identifier", + null, + 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); + } + + private class MockWiringException extends WiringException { + + public MockWiringException(String message, String identifier, URI source, URI reference) { + super(message, identifier, source, reference); + } + } +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/ComponentManagerImplTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/ComponentManagerImplTestCase.java new file mode 100644 index 0000000000..c1710e9b8e --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/ComponentManagerImplTestCase.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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 java.net.URI; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +import org.apache.tuscany.spi.component.Component; +import org.apache.tuscany.spi.component.DuplicateNameException; + +/** + * @version $Rev$ $Date$ + */ +public class ComponentManagerImplTestCase extends TestCase { + private static final URI DOMAIN = URI.create("sca://localhost/"); + private static final URI ROOT1 = DOMAIN.resolve("root1"); + private static final URI GRANDCHILD = DOMAIN.resolve("parent/child2/grandchild"); + + private ComponentManagerImpl manager; + + public void testRegister() throws Exception { + Component root = EasyMock.createMock(Component.class); + EasyMock.expect(root.getUri()).andReturn(ROOT1); + EasyMock.replay(root); + manager.register(root); + assertEquals(root, manager.getComponent(ROOT1)); + EasyMock.verify(root); + + EasyMock.reset(root); + EasyMock.expect(root.getUri()).andReturn(ROOT1); + EasyMock.replay(root); + manager.unregister(root); + EasyMock.verify(root); + assertEquals(null, manager.getComponent(ROOT1)); + } + + public void testRegisterGrandchild() throws Exception { + Component root = EasyMock.createMock(Component.class); + EasyMock.expect(root.getUri()).andReturn(GRANDCHILD); + EasyMock.replay(root); + manager.register(root); + assertEquals(root, manager.getComponent(GRANDCHILD)); + EasyMock.verify(root); + } + + public void testRegisterDuplicate() throws Exception { + Component root = EasyMock.createMock(Component.class); + EasyMock.expect(root.getUri()).andReturn(ROOT1); + EasyMock.replay(root); + + Component duplicate = EasyMock.createMock(Component.class); + EasyMock.expect(duplicate.getUri()).andReturn(ROOT1); + EasyMock.replay(duplicate); + + manager.register(root); + assertEquals(root, manager.getComponent(ROOT1)); + try { + manager.register(duplicate); + fail(); + } catch (DuplicateNameException e) { + // expected + } + assertEquals(root, manager.getComponent(ROOT1)); + EasyMock.verify(root); + EasyMock.verify(duplicate); + } + + protected void setUp() throws Exception { + super.setUp(); + manager = new ComponentManagerImpl(); + } +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/JavaObjectRegistrationTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/JavaObjectRegistrationTestCase.java new file mode 100644 index 0000000000..2d00a13716 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/JavaObjectRegistrationTestCase.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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 java.net.URI; + +import org.apache.tuscany.spi.component.AtomicComponent; +import org.apache.tuscany.spi.component.Component; +import org.apache.tuscany.spi.component.ComponentManager; +import org.apache.tuscany.spi.component.DuplicateNameException; +import org.apache.tuscany.spi.idl.java.JavaServiceContract; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class JavaObjectRegistrationTestCase extends TestCase { + private ComponentManager componentManager; + + public void testRegistration() throws Exception { + MockComponent instance = new MockComponent(); + URI uri = URI.create("foo"); + JavaServiceContract<MockComponent> contract = new JavaServiceContract<MockComponent>(MockComponent.class) { + }; + componentManager.registerJavaObject(uri, contract, instance); + Component component = componentManager.getComponent(URI.create("foo")); + assertTrue(component instanceof AtomicComponent); + MockComponent resolvedInstance = (MockComponent) ((AtomicComponent) component).getTargetInstance(); + assertSame(instance, resolvedInstance); + } + + public void testDuplicateRegistration() throws Exception { + MockComponent instance = new MockComponent(); + URI uri = URI.create("foo"); + JavaServiceContract<MockComponent> contract = new JavaServiceContract<MockComponent>(MockComponent.class) { + }; + componentManager.registerJavaObject(uri, contract, instance); + try { + componentManager.registerJavaObject(uri, contract, instance); + fail(); + } catch (DuplicateNameException e) { + // ok + } + } + + protected void setUp() throws Exception { + super.setUp(); + componentManager = new ComponentManagerImpl(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + private static class MockComponent { + public String hello(String message) { + return message; + } + } +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/SystemSingletonAtomicComponentTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/SystemSingletonAtomicComponentTestCase.java new file mode 100644 index 0000000000..fac45ebfb5 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/SystemSingletonAtomicComponentTestCase.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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 java.net.URI; +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.spi.component.TargetException; +import org.apache.tuscany.spi.idl.java.JavaServiceContract; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class SystemSingletonAtomicComponentTestCase extends TestCase { + + public void testGetInstance() throws TargetException { + JavaServiceContract<Foo> contract = new JavaServiceContract<Foo>(Foo.class) { + + }; + FooImpl foo = new FooImpl(); + SystemSingletonAtomicComponent<Foo, FooImpl> component = + new SystemSingletonAtomicComponent<Foo, FooImpl>(URI.create("foo"), contract, foo); + assertEquals(foo, component.getTargetInstance()); + } + + public void testGetInstanceMultipleServices() throws TargetException { + FooImpl foo = new FooImpl(); + List<JavaServiceContract<?>> services = new ArrayList<JavaServiceContract<?>>(); + services.add(new JavaServiceContract<Foo>(Foo.class) { + }); + services.add(new JavaServiceContract<Bar>(Bar.class) { + }); + SystemSingletonAtomicComponent<Foo, FooImpl> component = + new SystemSingletonAtomicComponent<Foo, FooImpl>(URI.create("foo"), services, foo); + assertEquals(foo, component.getTargetInstance()); + } + + public void testOptimizable() { + JavaServiceContract<Foo> contract = new JavaServiceContract<Foo>(Foo.class) { + }; + FooImpl foo = new FooImpl(); + SystemSingletonAtomicComponent<Foo, FooImpl> component = + new SystemSingletonAtomicComponent<Foo, FooImpl>(URI.create("foo"), contract, foo); + assertTrue(component.isOptimizable()); + } + + + protected void setUp() throws Exception { + super.setUp(); + } + + private interface Foo { + + } + + private interface Bar { + + } + + private class FooImpl implements Foo, Bar { + + } +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/event/EventTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/event/EventTestCase.java new file mode 100644 index 0000000000..93cb50ddcb --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/event/EventTestCase.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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 java.net.URI; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class EventTestCase extends TestCase { + private URI uri = URI.create("foo"); + + public void testCompositeStart() { + ComponentStart event = new ComponentStart(this, uri); + assertEquals(uri, event.getComponentUri()); + } + + public void testCompositeStop() { + ComponentStop event = new ComponentStop(this, uri); + assertEquals(uri, event.getComponentUri()); + } + + 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(); + } +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/AbstractScopeContainerTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/AbstractScopeContainerTestCase.java new file mode 100644 index 0000000000..a6e4de3c48 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/AbstractScopeContainerTestCase.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.net.URI; + +import junit.framework.TestCase; + +import org.apache.tuscany.spi.component.ScopeContainer; +import org.apache.tuscany.spi.component.AtomicComponent; +import org.apache.tuscany.spi.component.InstanceWrapper; + +import org.easymock.EasyMock; +import org.easymock.IMocksControl; + +/** + * @version $Rev$ $Date$ + */ +public abstract class AbstractScopeContainerTestCase<T, KEY> extends TestCase { + protected IMocksControl control; + protected ScopeContainer<KEY> scopeContainer; + protected URI groupId; + protected KEY contextId; + protected AtomicComponent<T> component; + protected InstanceWrapper<T> wrapper; + + @SuppressWarnings("unchecked") + protected void setUp() throws Exception { + super.setUp(); + control = EasyMock.createStrictControl(); + component = control.createMock(AtomicComponent.class); + wrapper = control.createMock(InstanceWrapper.class); + } + + protected void preRegisterComponent() throws Exception { + scopeContainer.start(); + scopeContainer.register(component, groupId); + EasyMock.expect(component.isEagerInit()).andStubReturn(false); + } + + protected void expectCreateWrapper() throws Exception { + EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper); + wrapper.start(); + } +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/BasicCompositeScopeTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/BasicCompositeScopeTestCase.java new file mode 100644 index 0000000000..cb66af27b0 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/BasicCompositeScopeTestCase.java @@ -0,0 +1,143 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.net.URI; + +import junit.framework.TestCase; +import org.easymock.EasyMock; +import org.easymock.IMocksControl; + +import org.apache.tuscany.spi.component.AtomicComponent; +import org.apache.tuscany.spi.component.InstanceWrapper; +import org.apache.tuscany.spi.component.ScopeContainer; +import org.apache.tuscany.spi.component.TargetResolutionException; +import org.apache.tuscany.spi.model.Scope; + +/** + * @version $$Rev$$ $$Date$$ + */ +public class BasicCompositeScopeTestCase<T> extends TestCase { + protected IMocksControl control; + protected ScopeContainer<URI> scopeContainer; + protected URI groupId; + protected URI contextId; + protected AtomicComponent<T> component; + protected InstanceWrapper<T> wrapper; + + public void testCorrectScope() { + assertEquals(Scope.COMPOSITE, scopeContainer.getScope()); + } + + public void testWrapperCreation() throws Exception { + EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper); + wrapper.start(); + control.replay(); + scopeContainer.register(component, groupId); + assertSame(wrapper, scopeContainer.getWrapper(component, contextId)); + assertSame(wrapper, scopeContainer.getWrapper(component, contextId)); + assertSame(wrapper, scopeContainer.getAssociatedWrapper(component, contextId)); + control.verify(); + } + + public void testGetAssociatedInstanceNonExistent() throws Exception { + URI uri = URI.create("oops"); + EasyMock.expect(component.getUri()).andReturn(uri); + control.replay(); + scopeContainer.register(component, groupId); + try { + scopeContainer.getAssociatedWrapper(component, contextId); + fail(); + } catch (TargetResolutionException e) { + assertEquals(uri.toString(), e.getMessage()); + } + control.verify(); + } + + /* + public void testLifecycleWithNoEagerInit() throws Exception { + EasyMock.expect(component.getInitLevel()).andReturn(0); + control.replay(); + scopeContainer.startContext(contextId, groupId); + scopeContainer.stopContext(contextId); + control.verify(); + } + + public void testLifecycleWithEagerInit() throws Exception { + EasyMock.expect(component.getInitLevel()).andReturn(1); + EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper); + wrapper.start(); + wrapper.stop(); + EasyMock.replay(component, wrapper); + scopeContainer.onEvent(new ComponentStart(this, null)); + scopeContainer.onEvent(new ComponentStop(this, null)); + EasyMock.verify(component, wrapper); + } + + public void testDestroyOrder() throws Exception { + scopeContainer = new CompositeScopeContainer(null); + scopeContainer.start(); + IMocksControl control = EasyMock.createStrictControl(); + InstanceWrapper wrapper1 = control.createMock(InstanceWrapper.class); + InstanceWrapper wrapper2 = control.createMock(InstanceWrapper.class); + InstanceWrapper wrapper3 = control.createMock(InstanceWrapper.class); + AtomicComponent component1 = control.createMock(AtomicComponent.class); + AtomicComponent component2 = control.createMock(AtomicComponent.class); + AtomicComponent component3 = control.createMock(AtomicComponent.class); + + EasyMock.expect(component1.getInitLevel()).andStubReturn(-1); + EasyMock.expect(component2.getInitLevel()).andStubReturn(1); + EasyMock.expect(component3.getInitLevel()).andStubReturn(-1); + + EasyMock.expect(component2.createInstanceWrapper()).andReturn(wrapper2); + wrapper2.start(); + EasyMock.expect(component1.createInstanceWrapper()).andReturn(wrapper1); + wrapper1.start(); + EasyMock.expect(component3.createInstanceWrapper()).andReturn(wrapper3); + wrapper3.start(); + wrapper3.stop(); + wrapper1.stop(); + wrapper2.stop(); + control.replay(); + + scopeContainer.register(component1, contextId); + scopeContainer.register(component2, contextId); + scopeContainer.register(component3, contextId); + scopeContainer.onEvent(new ComponentStart(this, null)); + assertSame(wrapper1, scopeContainer.getWrapper(component1)); + assertSame(wrapper2, scopeContainer.getWrapper(component2)); + assertSame(wrapper3, scopeContainer.getWrapper(component3)); + scopeContainer.onEvent(new ComponentStop(this, null)); + control.verify(); + } + */ + @SuppressWarnings("unchecked") + protected void setUp() throws Exception { + super.setUp(); + groupId = contextId = URI.create("compositeId"); + control = EasyMock.createStrictControl(); + component = control.createMock(AtomicComponent.class); + EasyMock.expect(component.isEagerInit()).andStubReturn(false); + wrapper = control.createMock(InstanceWrapper.class); + + scopeContainer = new CompositeScopeContainer<URI>(null); + scopeContainer.start(); + scopeContainer.startContext(contextId, groupId); + } +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/BasicConversationalScopeTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/BasicConversationalScopeTestCase.java new file mode 100644 index 0000000000..02f5540dea --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/BasicConversationalScopeTestCase.java @@ -0,0 +1,95 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * 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;
+
+import org.apache.tuscany.core.component.SimpleWorkContext;
+import org.apache.tuscany.core.services.store.memory.MemoryStore;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.InstanceWrapper;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.services.store.StoreMonitor;
+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 AtomicComponent component;
+ private InstanceWrapper wrapper;
+ private ScopeContainer scopeContainer;
+ private WorkContext workContext;
+
+/*
+ public void testLifecycleManagement() throws Exception {
+ // start the request
+ String conversation = "conv";
+ workContext.setIdentifier(Scope.CONVERSATION, conversation);
+
+ EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper);
+ wrapper.start();
+ // FIXME shouldn't stop be called when the component is removed?
+// wrapper.stop();
+ EasyMock.replay(component, wrapper);
+ assertSame(wrapper, scopeContainer.getWrapper(component));
+ assertSame(wrapper, scopeContainer.getWrapper(component));
+ scopeContainer.remove(component);
+ EasyMock.verify(component, wrapper);
+ }
+*/
+
+/*
+ public void testCoversationIsolation() throws Exception {
+ String conversation1 = "conv";
+ String conversation2 = "conv2";
+
+ InstanceWrapper wrapper2 = EasyMock.createStrictMock(InstanceWrapper.class);
+ EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper);
+ wrapper.start();
+ EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper2);
+ wrapper2.start();
+ EasyMock.replay(component, wrapper, wrapper2);
+ workContext.setIdentifier(Scope.CONVERSATION, conversation1);
+ assertSame(wrapper, scopeContainer.getWrapper(component));
+ workContext.setIdentifier(Scope.CONVERSATION, conversation2);
+ assertSame(wrapper2, scopeContainer.getWrapper(component));
+ EasyMock.verify(component, wrapper);
+ }
+*/
+ public void testX() {
+}
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ component = EasyMock.createStrictMock(AtomicComponent.class);
+ EasyMock.expect(component.getMaxAge()).andStubReturn(-1);
+ EasyMock.expect(component.getMaxIdleTime()).andStubReturn(-1);
+ wrapper = EasyMock.createStrictMock(InstanceWrapper.class);
+
+ StoreMonitor monitor = EasyMock.createMock(StoreMonitor.class);
+ monitor.start(EasyMock.isA(String.class));
+ monitor.stop(EasyMock.isA(String.class));
+ MemoryStore store = new MemoryStore(monitor);
+ workContext = new SimpleWorkContext();
+ scopeContainer = new ConversationalScopeContainer(store, workContext, null);
+ scopeContainer.start();
+ }
+}
diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/BasicHttpSessionScopeTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/BasicHttpSessionScopeTestCase.java new file mode 100644 index 0000000000..1f29c92c92 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/BasicHttpSessionScopeTestCase.java @@ -0,0 +1,220 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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; + +import org.apache.tuscany.core.component.SimpleWorkContext; +import org.apache.tuscany.spi.component.AtomicComponent; +import org.apache.tuscany.spi.component.InstanceWrapper; +import org.apache.tuscany.spi.component.ScopeContainer; +import org.apache.tuscany.spi.component.ScopeContainerMonitor; +import org.apache.tuscany.spi.component.WorkContext; +import org.easymock.EasyMock; + +/** + * @version $$Rev$$ $$Date$$ + */ +public abstract class BasicHttpSessionScopeTestCase extends TestCase { + private ScopeContainerMonitor monitor; + private ScopeContainer scopeContainer; + private AtomicComponent component; + private InstanceWrapper wrapper; + private WorkContext workContext; + + public void testLifecycleManagement() throws Exception { +/* + // start the request + Object session = new Object(); + workContext.setIdentifier(Scope.SESSION, session); + + EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper); + wrapper.start(); + wrapper.stop(); + EasyMock.replay(component, wrapper); + assertSame(wrapper, scopeContainer.getWrapper(component)); + assertSame(wrapper, scopeContainer.getWrapper(component)); + scopeContainer.onEvent(new HttpSessionEnd(this, session)); + EasyMock.verify(component, wrapper); +*/ + } + + public void testGetAssociatedInstance() throws Exception { +/* + // start the request + Object session = new Object(); + workContext.setIdentifier(Scope.SESSION, session); + + EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper); + wrapper.start(); + EasyMock.replay(component, wrapper); + assertSame(wrapper, scopeContainer.getWrapper(component)); + assertSame(wrapper, scopeContainer.getAssociatedWrapper(component)); + EasyMock.verify(component, wrapper); +*/ + } + + public void testGetAssociatedInstanceNonExistent() throws Exception { +/* + URI id = URI.create("oops"); + EasyMock.expect(component.getUri()).andReturn(id); + EasyMock.replay(component); + + // start the request + Object session = new Object(); + workContext.setIdentifier(Scope.SESSION, session); + try { + scopeContainer.getAssociatedWrapper(component); + fail(); + } catch (TargetNotFoundException e) { + assertEquals(id.toString(), e.getMessage()); + EasyMock.verify(component); + } +*/ + } + + public void testSessionIsolation() throws Exception { +/* + // start the request + Object session1 = new Object(); + Object session2 = new Object(); + + InstanceWrapper wrapper2 = EasyMock.createNiceMock(InstanceWrapper.class); + EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper); + wrapper.start(); + EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper2); + wrapper2.start(); + EasyMock.replay(component, wrapper); + workContext.setIdentifier(Scope.SESSION, session1); + assertSame(wrapper, scopeContainer.getWrapper(component)); + assertSame(wrapper, scopeContainer.getAssociatedWrapper(component)); + workContext.setIdentifier(Scope.SESSION, session2); + assertSame(wrapper2, scopeContainer.getWrapper(component)); + assertSame(wrapper2, scopeContainer.getAssociatedWrapper(component)); + workContext.setIdentifier(Scope.SESSION, session1); + assertSame(wrapper, scopeContainer.getWrapper(component)); + EasyMock.verify(component, wrapper); +*/ + } + + public void testDestroyErrorMonitor() throws Exception { +/* + TargetDestructionException ex = new TargetDestructionException("oops", "again"); + monitor.destructionError(ex); + EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper); + wrapper.start(); + wrapper.stop(); + EasyMock.expectLastCall().andThrow(ex); + EasyMock.replay(component, wrapper, monitor); + + Object id = new Object(); + scopeContainer.onEvent(new HttpSessionStart(this, id)); + workContext.setIdentifier(Scope.SESSION, id); + assertSame(wrapper, scopeContainer.getWrapper(component)); + scopeContainer.onEvent(new HttpSessionEnd(this, id)); + EasyMock.verify(component, wrapper, monitor); +*/ + } + + public void testDestroyOrder() throws Exception { +/* + Object session = new Object(); + workContext.setIdentifier(Scope.SESSION, session); + + IMocksControl control = EasyMock.createStrictControl(); + InstanceWrapper wrapper1 = control.createMock(InstanceWrapper.class); + InstanceWrapper wrapper2 = control.createMock(InstanceWrapper.class); + InstanceWrapper wrapper3 = control.createMock(InstanceWrapper.class); + AtomicComponent component1 = control.createMock(AtomicComponent.class); + AtomicComponent component2 = control.createMock(AtomicComponent.class); + AtomicComponent component3 = control.createMock(AtomicComponent.class); + + component1.addListener(scopeContainer); + component2.addListener(scopeContainer); + component3.addListener(scopeContainer); + EasyMock.expect(component1.createInstanceWrapper()).andReturn(wrapper1); + wrapper1.start(); + EasyMock.expect(component2.createInstanceWrapper()).andReturn(wrapper2); + wrapper2.start(); + EasyMock.expect(component3.createInstanceWrapper()).andReturn(wrapper3); + wrapper3.start(); + wrapper3.stop(); + wrapper2.stop(); + wrapper1.stop(); + control.replay(); + + scopeContainer.register(component1, null); + scopeContainer.register(component2, null); + scopeContainer.register(component3, null); + scopeContainer.onEvent(new HttpSessionStart(this, session)); + assertSame(wrapper1, scopeContainer.getWrapper(component1)); + assertSame(wrapper2, scopeContainer.getWrapper(component2)); + assertSame(wrapper3, scopeContainer.getWrapper(component3)); + scopeContainer.onEvent(new HttpSessionEnd(this, session)); + control.verify(); +*/ + } + + public void testReuseSession() throws Exception { +/* + Object session = new Object(); + workContext.setIdentifier(Scope.SESSION, session); + + IMocksControl control = EasyMock.createStrictControl(); + InstanceWrapper wrapper1 = control.createMock(InstanceWrapper.class); + InstanceWrapper wrapper2 = control.createMock(InstanceWrapper.class); + AtomicComponent component1 = control.createMock(AtomicComponent.class); + + component1.addListener(scopeContainer); + EasyMock.expect(component1.createInstanceWrapper()).andReturn(wrapper1); + wrapper1.start(); + wrapper1.stop(); + EasyMock.expect(component1.createInstanceWrapper()).andReturn(wrapper2); + wrapper2.start(); + wrapper2.stop(); + control.replay(); + + scopeContainer.register(component1, null); + scopeContainer.onEvent(new HttpSessionStart(this, session)); + assertSame(wrapper1, scopeContainer.getWrapper(component1)); + scopeContainer.onEvent(new HttpSessionEnd(this, session)); + + scopeContainer.onEvent(new HttpSessionStart(this, session)); + assertSame(wrapper2, scopeContainer.getWrapper(component1)); + scopeContainer.onEvent(new HttpSessionEnd(this, session)); + control.verify(); +*/ + } + + protected void setUp() throws Exception { + super.setUp(); + component = EasyMock.createStrictMock(AtomicComponent.class); + wrapper = EasyMock.createStrictMock(InstanceWrapper.class); + + workContext = new SimpleWorkContext(); + monitor = EasyMock.createStrictMock(ScopeContainerMonitor.class); + scopeContainer = new HttpSessionScopeContainer(workContext, monitor); + scopeContainer.start(); + + component.addListener(scopeContainer); + EasyMock.replay(component); + scopeContainer.register(component, null); + EasyMock.reset(component); + } +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/BasicRequestScopeTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/BasicRequestScopeTestCase.java new file mode 100644 index 0000000000..4aad2dc0c6 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/BasicRequestScopeTestCase.java @@ -0,0 +1,167 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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; +import org.easymock.EasyMock; + +import org.apache.tuscany.spi.component.AtomicComponent; +import org.apache.tuscany.spi.component.InstanceWrapper; +import org.apache.tuscany.spi.component.ScopeContainer; +import org.apache.tuscany.spi.component.ScopeContainerMonitor; + +/** + * @version $$Rev$$ $$Date$$ + */ +public abstract class BasicRequestScopeTestCase extends TestCase { + private ScopeContainerMonitor monitor; + private ScopeContainer scopeContainer; + private AtomicComponent component; + private InstanceWrapper wrapper; + + public void testLifecycleManagement() throws Exception { +/* + EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper); + wrapper.start(); + EasyMock.replay(component, wrapper); + assertSame(wrapper, scopeContainer.getWrapper(component)); + assertSame(wrapper, scopeContainer.getWrapper(component)); + EasyMock.verify(component, wrapper); +*/ + } + + public void testGetAssociatedInstance() throws Exception { +/* + EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper); + wrapper.start(); + EasyMock.replay(component, wrapper); + assertSame(wrapper, scopeContainer.getWrapper(component)); + assertSame(wrapper, scopeContainer.getAssociatedWrapper(component)); + EasyMock.verify(component, wrapper); +*/ + } + + public void testGetAssociatedInstanceNonExistent() throws Exception { +/* + URI id = URI.create("oops"); + EasyMock.expect(component.getUri()).andReturn(id); + EasyMock.replay(component); + + try { + scopeContainer.getAssociatedWrapper(component); + fail(); + } catch (TargetNotFoundException e) { + assertEquals(id.toString(), e.getMessage()); + EasyMock.verify(component); + } +*/ + } + + public void testRequestIsolation() throws Exception { +/* + IMocksControl control = EasyMock.createStrictControl(); + InstanceWrapper wrapper1 = control.createMock(InstanceWrapper.class); + InstanceWrapper wrapper2 = control.createMock(InstanceWrapper.class); + AtomicComponent component1 = control.createMock(AtomicComponent.class); + AtomicComponent component2 = control.createMock(AtomicComponent.class); + + EasyMock.expect(component1.createInstanceWrapper()).andReturn(wrapper1); + wrapper1.start(); + wrapper1.stop(); + EasyMock.expect(component2.createInstanceWrapper()).andReturn(wrapper2); + wrapper2.start(); + wrapper2.stop(); + control.replay(); + + scopeContainer.register(component1, null); + scopeContainer.register(component2, null); + scopeContainer.onEvent(new RequestStart(this)); + assertSame(wrapper1, scopeContainer.getWrapper(component1)); + scopeContainer.onEvent(new RequestEnd(this)); + scopeContainer.onEvent(new RequestStart(this)); + assertSame(wrapper2, scopeContainer.getWrapper(component2)); + scopeContainer.onEvent(new RequestEnd(this)); + control.verify(); +*/ + } + + public void testDestroyErrorMonitor() throws Exception { +/* + TargetDestructionException ex = new TargetDestructionException("oops", "again"); + monitor.destructionError(ex); + EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper); + wrapper.start(); + wrapper.stop(); + EasyMock.expectLastCall().andThrow(ex); + EasyMock.replay(component, wrapper, monitor); + + scopeContainer.onEvent(new RequestStart(this)); + assertSame(wrapper, scopeContainer.getWrapper(component)); + scopeContainer.onEvent(new RequestEnd(this)); + EasyMock.verify(component, wrapper, monitor); +*/ + } + + public void testDestroyOrder() throws Exception { +/* + IMocksControl control = EasyMock.createStrictControl(); + InstanceWrapper wrapper1 = control.createMock(InstanceWrapper.class); + InstanceWrapper wrapper2 = control.createMock(InstanceWrapper.class); + InstanceWrapper wrapper3 = control.createMock(InstanceWrapper.class); + AtomicComponent component1 = control.createMock(AtomicComponent.class); + AtomicComponent component2 = control.createMock(AtomicComponent.class); + AtomicComponent component3 = control.createMock(AtomicComponent.class); + + EasyMock.expect(component1.createInstanceWrapper()).andReturn(wrapper1); + wrapper1.start(); + EasyMock.expect(component2.createInstanceWrapper()).andReturn(wrapper2); + wrapper2.start(); + EasyMock.expect(component3.createInstanceWrapper()).andReturn(wrapper3); + wrapper3.start(); + wrapper3.stop(); + wrapper2.stop(); + wrapper1.stop(); + control.replay(); + + scopeContainer.register(component1, null); + scopeContainer.register(component2, null); + scopeContainer.register(component3, null); + scopeContainer.onEvent(new RequestStart(this)); + assertSame(wrapper1, scopeContainer.getWrapper(component1)); + assertSame(wrapper2, scopeContainer.getWrapper(component2)); + assertSame(wrapper3, scopeContainer.getWrapper(component3)); + scopeContainer.onEvent(new RequestEnd(this)); + control.verify(); +*/ + } + + protected void setUp() throws Exception { + super.setUp(); + component = EasyMock.createStrictMock(AtomicComponent.class); + wrapper = EasyMock.createStrictMock(InstanceWrapper.class); + monitor = EasyMock.createStrictMock(ScopeContainerMonitor.class); + scopeContainer = new RequestScopeContainer(monitor); + scopeContainer.start(); + + component.addListener(scopeContainer); + EasyMock.replay(component); + scopeContainer.register(component, null); + EasyMock.reset(component); + } +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/BasicStatelessScopeTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/BasicStatelessScopeTestCase.java new file mode 100644 index 0000000000..a7cab71ade --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/BasicStatelessScopeTestCase.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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; +import org.easymock.EasyMock; +import org.easymock.IMocksControl; + +import org.apache.tuscany.spi.component.AtomicComponent; +import org.apache.tuscany.spi.component.InstanceWrapper; +import org.apache.tuscany.spi.model.Scope; + +/** + * Unit tests for the composite scope container + * + * @version $Rev$ $Date$ + */ +public class BasicStatelessScopeTestCase<T> extends TestCase { + private StatelessScopeContainer<String> scopeContainer; + private String contextId; + private IMocksControl control; + private AtomicComponent<T> component; + private InstanceWrapper<T> wrapper; + + public void testCorrectScope() { + assertEquals(Scope.STATELESS, scopeContainer.getScope()); + } + + public void testInstanceCreation() throws Exception { + @SuppressWarnings("unchecked") + InstanceWrapper<T> wrapper2 = control.createMock(InstanceWrapper.class); + + EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper); + wrapper.start(); + EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper2); + wrapper2.start(); + control.replay(); + + assertSame(wrapper, scopeContainer.getWrapper(component, contextId)); + assertSame(wrapper2, scopeContainer.getWrapper(component, contextId)); + control.verify(); + } + + public void testGetAssociatedInstance() throws Exception { + control.replay(); + try { + // always throws an exception, which is the semantic for stateless implementations + scopeContainer.getAssociatedWrapper(component, contextId); + fail(); + } catch (UnsupportedOperationException e) { + // ok + } + control.verify(); + } + + public void testReturnWrapper() throws Exception { + wrapper.stop(); + control.replay(); + scopeContainer.returnWrapper(component, wrapper, contextId); + control.verify(); + } + + @SuppressWarnings("unchecked") + protected void setUp() throws Exception { + super.setUp(); + scopeContainer = new StatelessScopeContainer<String>(null); + contextId = "context"; + + control = EasyMock.createStrictControl(); + component = control.createMock(AtomicComponent.class); + wrapper = control.createMock(InstanceWrapper.class); + } +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInitDestroyErrorTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInitDestroyErrorTestCase.java new file mode 100644 index 0000000000..01c426e917 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/CompositeScopeInitDestroyErrorTestCase.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.net.URI; + +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 org.apache.tuscany.spi.component.InstanceWrapper; +import org.apache.tuscany.spi.component.TargetResolutionException; +import org.apache.tuscany.spi.component.GroupInitializationException; + +import junit.framework.TestCase; +import org.apache.tuscany.core.component.event.ComponentStart; +import org.apache.tuscany.core.component.event.ComponentStop; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class CompositeScopeInitDestroyErrorTestCase extends TestCase { + private URI groupId; + + public void testInitializeError() throws Exception { + CompositeScopeContainer scope = new CompositeScopeContainer(null); + scope.start(); + + ObjectCreationException ex = new ObjectCreationException(""); + AtomicComponent component = EasyMock.createMock(AtomicComponent.class); + EasyMock.expect(component.createInstanceWrapper()).andThrow(ex); + EasyMock.expect(component.isEagerInit()).andStubReturn(true); + EasyMock.expect(component.getInitLevel()).andStubReturn(1); + EasyMock.replay(component); + scope.register(component, groupId); + try { + scope.startContext(groupId, groupId); + } catch (GroupInitializationException e) { + assertSame(ex, e.getCauses().get(0)); + } + EasyMock.verify(component); + } + + public void testDestroyErrorMonitor() throws Exception { + InstanceWrapper wrapper = EasyMock.createMock(InstanceWrapper.class); + wrapper.start(); + wrapper.stop(); + EasyMock.expectLastCall().andThrow(new TargetDestructionException("", "")); + EasyMock.replay(wrapper); + + 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.createInstanceWrapper()).andReturn(wrapper); + EasyMock.expect(component.isEagerInit()).andStubReturn(true); + EasyMock.expect(component.getInitLevel()).andStubReturn(1); + EasyMock.replay(component); + scope.register(component, groupId); + scope.startContext(groupId, groupId); + scope.stopContext(groupId); + EasyMock.verify(monitor); + EasyMock.verify(component); + EasyMock.verify(wrapper); + } + + + protected void setUp() throws Exception { + super.setUp(); + groupId = URI.create("composite"); + } +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerDestroyOnExpirationTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerDestroyOnExpirationTestCase.java new file mode 100644 index 0000000000..caf0c0cc5e --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerDestroyOnExpirationTestCase.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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; + +import org.apache.tuscany.core.component.SimpleWorkContext; +import org.apache.tuscany.spi.component.AtomicComponent; +import org.apache.tuscany.spi.component.InstanceWrapper; +import org.apache.tuscany.spi.component.WorkContext; +import org.apache.tuscany.spi.event.RuntimeEventListener; +import org.apache.tuscany.spi.services.store.Store; +import org.apache.tuscany.spi.services.store.StoreExpirationEvent; +import org.easymock.EasyMock; +import org.easymock.IAnswer; + +/** + * @version $Rev$ $Date$ + */ +public class ConversationalScopeContainerDestroyOnExpirationTestCase extends TestCase { + private Store store; + private RuntimeEventListener listener; + private WorkContext context; + private InstanceWrapper wrapper; + 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.addListener(EasyMock.isA(RuntimeEventListener.class)); + EasyMock.expectLastCall().andStubAnswer(new IAnswer<Object>(){ + public Object answer() throws Throwable { + listener = (RuntimeEventListener) EasyMock.getCurrentArguments()[0]; + return null; + } + }); + wrapper.stop(); + EasyMock.replay(store); + EasyMock.replay(wrapper); + + new ConversationalScopeContainer(store, context, null); + listener.onEvent(new StoreExpirationEvent(this, component, wrapper)); + EasyMock.verify(store); + EasyMock.verify(wrapper); + } + + protected void setUp() throws Exception { + super.setUp(); + store = EasyMock.createMock(Store.class); + wrapper = EasyMock.createMock(InstanceWrapper.class); + component = EasyMock.createMock(AtomicComponent.class); + context = new SimpleWorkContext(); + } +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxAgeTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxAgeTestCase.java new file mode 100644 index 0000000000..e896b410d0 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxAgeTestCase.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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; + +import org.apache.tuscany.core.component.SimpleWorkContext; +import org.apache.tuscany.spi.component.AtomicComponent; +import org.apache.tuscany.spi.component.InstanceWrapper; +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 org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class ConversationalScopeContainerMaxAgeTestCase extends TestCase { + + private ScopeContainer container; + private WorkContext context; + private Store store; + private AtomicComponent component; + private InstanceWrapper wrapper; + + public void testMaxAgeUpdate() throws Exception { +/* + context.setIdentifier(Scope.CONVERSATION, "12345"); + assertSame(wrapper, container.getWrapper(component)); + EasyMock.verify(store); +*/ + } + + protected void setUp() throws Exception { + super.setUp(); + context = new SimpleWorkContext(); + component = EasyMock.createMock(AtomicComponent.class); + EasyMock.expect(component.getMaxIdleTime()).andReturn(-1L).atLeastOnce(); + EasyMock.expect(component.getMaxAge()).andReturn(600000L).atLeastOnce(); + EasyMock.replay(component); + + wrapper = EasyMock.createMock(InstanceWrapper.class); + + store = EasyMock.createMock(Store.class); + EasyMock.expect(store.readRecord(EasyMock.isA(SCAObject.class), EasyMock.isA(String.class))).andReturn(wrapper); + 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(); + } +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxIdleTimeTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxIdleTimeTestCase.java new file mode 100644 index 0000000000..9ac97bff32 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerMaxIdleTimeTestCase.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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; + +import org.apache.tuscany.core.component.SimpleWorkContext; +import org.apache.tuscany.spi.component.AtomicComponent; +import org.apache.tuscany.spi.component.InstanceWrapper; +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 org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class ConversationalScopeContainerMaxIdleTimeTestCase extends TestCase { + + private ScopeContainer container; + private WorkContext context; + private Store store; + private AtomicComponent component; + private InstanceWrapper wrapper; + + public void testMaxIdleTimeUpdate() throws Exception { +/* + context.setIdentifier(Scope.CONVERSATION, "12345"); + assertSame(wrapper, container.getWrapper(component)); + EasyMock.verify(store); +*/ + } + + protected void setUp() throws Exception { + super.setUp(); + wrapper = EasyMock.createMock(InstanceWrapper.class); + context = new SimpleWorkContext(); + component = EasyMock.createMock(AtomicComponent.class); + EasyMock.expect(component.getMaxIdleTime()).andStubReturn(600000L); + EasyMock.replay(component); + store = EasyMock.createMock(Store.class); + EasyMock.expect(store.readRecord(EasyMock.isA(SCAObject.class), EasyMock.isA(String.class))).andReturn(wrapper); + store.addListener(EasyMock.isA(RuntimeEventListener.class)); + store.updateRecord(EasyMock.isA(SCAObject.class), + EasyMock.isA(String.class), + EasyMock.eq(wrapper), + 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(); + } + +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerPersistenceTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerPersistenceTestCase.java new file mode 100644 index 0000000000..a8960c4575 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/ConversationalScopeContainerPersistenceTestCase.java @@ -0,0 +1,189 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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; + +import org.apache.tuscany.core.component.SimpleWorkContext; +import org.apache.tuscany.core.services.store.memory.MemoryStore; +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 org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public abstract class ConversationalScopeContainerPersistenceTestCase extends TestCase { + private ConversationalScopeContainer container; + private WorkContext context; + + public void testNotYetPersistedInMemory() throws Exception { +/* + InstanceWrapper wrapper = EasyMock.createMock(InstanceWrapper.class); + wrapper.start(); + EasyMock.replay(wrapper); + + String id = UUID.randomUUID().toString(); + context.setIdentifier(Scope.CONVERSATION, id); + AtomicComponent component = EasyMock.createMock(AtomicComponent.class); + component.addListener(EasyMock.eq(container)); + EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper); + EasyMock.expect(component.getMaxAge()).andReturn(600000L).atLeastOnce(); + EasyMock.replay(component); + + container.register(component, null); + assertSame(wrapper, container.getWrapper(component)); + EasyMock.verify(component); + EasyMock.verify(wrapper); +*/ + } + + 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, null); + InstanceWrapper fooWrapper = EasyMock.createMock(InstanceWrapper.class); + InstanceWrapper fooWrapper2 = EasyMock.createMock(InstanceWrapper.class); + container.persistNew(component, id, fooWrapper, System.currentTimeMillis() + 100000); + assertEquals(fooWrapper, container.getWrapper(component)); + container.persistNew(component, id2, fooWrapper2, System.currentTimeMillis() + 100000); + context.setIdentifier(Scope.CONVERSATION, id2); + assertEquals(fooWrapper2, container.getWrapper(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, null); + InstanceWrapper fooWrapper = EasyMock.createMock(InstanceWrapper.class); + container.persistNew(component, id, fooWrapper, System.currentTimeMillis() + 100000); + assertEquals(fooWrapper, container.getWrapper(component)); + container.persist(component, id, fooWrapper, System.currentTimeMillis() + 100000); + assertEquals(fooWrapper, container.getWrapper(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.getUri()).andReturn(URI.create("foo")).atLeastOnce(); + EasyMock.replay(component); + container.register(component, null); + InstanceWrapper fooWrapper = EasyMock.createMock(InstanceWrapper.class); + container.persistNew(component, id, fooWrapper, System.currentTimeMillis() + 100000); + assertEquals(fooWrapper, container.getWrapper(component)); + container.remove(component); + try { + container.getAssociatedWrapper(component); + fail(); + } catch (TargetNotFoundException e) { + //expected + } + EasyMock.verify(component); +*/ + } + + public void testRecreateAfterRemoveInMemory() throws Exception { +/* + InstanceWrapper wrapper = EasyMock.createMock(InstanceWrapper.class); + wrapper.start(); + EasyMock.replay(wrapper); + + 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(); + EasyMock.expect(component.getMaxIdleTime()).andReturn(-1L).atLeastOnce(); + EasyMock.expect(component.createInstanceWrapper()).andReturn(wrapper); + EasyMock.replay(component); + + container.register(component, null); + InstanceWrapper fooWrapper = EasyMock.createMock(InstanceWrapper.class); + container.persistNew(component, id, fooWrapper, System.currentTimeMillis() + 100000); + assertEquals(fooWrapper, container.getWrapper(component)); + container.remove(component); + assertSame(wrapper, container.getWrapper(component)); + 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.getUri()).andReturn(URI.create("foo")).atLeastOnce(); + EasyMock.expect(component.getMaxIdleTime()).andReturn(-1L).atLeastOnce(); + component.addListener(EasyMock.eq(container)); + EasyMock.replay(component); + container.register(component, null); + + InstanceWrapper fooWrapper = EasyMock.createMock(InstanceWrapper.class); + container.persistNew(component, id, fooWrapper, System.currentTimeMillis() + 100000); + assertEquals(fooWrapper, container.getAssociatedWrapper(component)); + assertEquals(fooWrapper, container.getAssociatedWrapper(component)); + context.setIdentifier(Scope.CONVERSATION, id2); + try { + container.getAssociatedWrapper(component); + fail(); + } catch (TargetNotFoundException e) { + //expected + } + EasyMock.verify(component); +*/ + } + + protected void setUp() throws Exception { + super.setUp(); + context = new SimpleWorkContext(); + 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(); + } +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperBaseTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperBaseTestCase.java new file mode 100644 index 0000000000..c583ff19c6 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/InstanceWrapperBaseTestCase.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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 InstanceWrapperBaseTestCase extends TestCase { + private static final Object INSTANCE = new Object(); + private InstanceWrapperBase<Object> wrapper; + + public void testLifecycle() throws Exception { + assertFalse(wrapper.isStarted()); + try { + wrapper.getInstance(); + fail(); + } catch (AssertionError e) { + // expected + } + wrapper.start(); + assertTrue(wrapper.isStarted()); + assertSame(INSTANCE, wrapper.getInstance()); + wrapper.stop(); + assertFalse(wrapper.isStarted()); + try { + wrapper.getInstance(); + fail(); + } catch (AssertionError e) { + // expected + } + } + + public void testNullCheck() { + try { + new InstanceWrapperBase<Object>(null); + fail(); + } catch (AssertionError e) { + // expected + } + } + + protected void setUp() throws Exception { + super.setUp(); + wrapper = new InstanceWrapperBase<Object>(INSTANCE); + } +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/WorkContextTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/WorkContextTestCase.java new file mode 100644 index 0000000000..94feca05be --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/component/scope/WorkContextTestCase.java @@ -0,0 +1,166 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.Component; +import org.apache.tuscany.spi.component.WorkContext; + +import junit.framework.TestCase; +import org.apache.tuscany.core.component.SimpleWorkContext; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class WorkContextTestCase extends TestCase { + + public void testSetCurrentAtomicComponent() throws Exception { + WorkContext ctx = new SimpleWorkContext(); + 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 SimpleWorkContext(); + assertNull(ctx.getCurrentAtomicComponent()); + } + + public void testIndentifier() throws Exception { + WorkContext ctx = new SimpleWorkContext(); + Object id = new Object(); + ctx.setIdentifier(this, id); + assertEquals(id, ctx.getIdentifier(this)); + } + + public void testClearIndentifier() throws Exception { + WorkContext ctx = new SimpleWorkContext(); + Object id = new Object(); + ctx.setIdentifier(this, id); + ctx.clearIdentifier(this); + assertNull(ctx.getIdentifier(this)); + } + + public void testClearIndentifiers() throws Exception { + WorkContext ctx = new SimpleWorkContext(); + 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 SimpleWorkContext(); + ctx.clearIdentifier(this); + } + + public void testNullIndentifier() throws Exception { + WorkContext ctx = new SimpleWorkContext(); + Object id = new Object(); + ctx.setIdentifier(this, id); + ctx.clearIdentifier(null); + assertEquals(id, ctx.getIdentifier(this)); + } + + public void testNoIndentifier() throws Exception { + WorkContext ctx = new SimpleWorkContext(); + assertNull(ctx.getIdentifier(this)); + } + + public void testSetGetCorrelationId() { + WorkContext context = new SimpleWorkContext(); + context.setCorrelationId("msg-005"); + assertEquals(context.getCorrelationId(), "msg-005"); + context.setCorrelationId(null); + assertNull(context.getCorrelationId()); + } + + public void testSetGetCorrelationIdInNewThread() throws InterruptedException { + WorkContext context = new SimpleWorkContext(); + context.setCorrelationId("msg-005"); + assertEquals(context.getCorrelationId(), "msg-005"); + context.setIdentifier("TX", "002"); + ChildThread t = new ChildThread(context); + t.start(); + t.join(); + assertTrue(t.passed); + context.setCorrelationId(null); + assertNull(context.getCorrelationId()); + } + + public void testCurrentAtomicComponentDoesNotPropagateToChildThread() throws InterruptedException { + // NOTE should behaviour be to propagate? + WorkContext context = new SimpleWorkContext(); + context.setCurrentAtomicComponent(EasyMock.createNiceMock(AtomicComponent.class)); + TestCurrentAtomicComponentChildThread t = new TestCurrentAtomicComponentChildThread(context); + t.start(); + t.join(); + assertTrue(t.passed); + context.setCurrentAtomicComponent(null); + assertNull(context.getCurrentAtomicComponent()); + } + + 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.getCorrelationId()); + 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; + } + } + + } + + +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplTestCase.java new file mode 100644 index 0000000000..a5574c7f78 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/implementation/composite/CompositeComponentImplTestCase.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.Component; +import org.apache.tuscany.spi.component.Reference; +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.model.Scope; + +import junit.framework.Assert; +import junit.framework.TestCase; +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.replay; + +/** + * @version $Rev$ $Date$ + */ +public class CompositeComponentImplTestCase extends TestCase { + + public void testGetScope() { + Component composite = new CompositeComponentImpl(URI.create("parent")); + Assert.assertEquals(Scope.SYSTEM, composite.getScope()); + } + + public void testRegisterService() throws Exception { + Component composite = new CompositeComponentImpl(URI.create("parent")); + Service service = new ServiceImpl(URI.create("foo#service"), null); + composite.register(service); + assertNotNull(composite.getService("service")); + } + + public void testRegisterReference() throws Exception { + Component composite = new CompositeComponentImpl(URI.create("parent")); + Reference reference = new ReferenceImpl(URI.create("foo#reference"), null); + composite.register(reference); + assertNotNull(composite.getReference("reference")); + } + + public void testOnEvent() { + CompositeComponentImpl composite = new CompositeComponentImpl(URI.create("parent")); + Event event = new Event() { + public Object getSource() { + return null; + } + }; + RuntimeEventListener listener = createMock(RuntimeEventListener.class); + listener.onEvent(eq(event)); + expectLastCall(); + replay(listener); + composite.addListener(listener); + composite.start(); + composite.onEvent(event); + EasyMock.verify(listener); + } + +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/implementation/composite/DuplicateRegistrationTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/implementation/composite/DuplicateRegistrationTestCase.java new file mode 100644 index 0000000000..c3394c1043 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/implementation/composite/DuplicateRegistrationTestCase.java @@ -0,0 +1,120 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.DuplicateNameException; +import org.apache.tuscany.spi.component.Service; +import org.apache.tuscany.spi.component.Reference; +import org.apache.tuscany.spi.component.Component; + +import junit.framework.TestCase; +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 testDuplicateServiceRegistration() throws Exception { + Component parent = new CompositeComponentImpl(URI.create("parent")); + parent.start(); + + Service service1 = EasyMock.createMock(Service.class); + EasyMock.expect(service1.getUri()).andReturn(URI.create("#service")).atLeastOnce(); + service1.stop(); + EasyMock.replay(service1); + + Service service2 = EasyMock.createMock(Service.class); + EasyMock.expect(service2.getUri()).andReturn(URI.create("#service")).atLeastOnce(); + service2.stop(); + EasyMock.replay(service2); + + parent.register(service2); + try { + parent.register(service1); + fail(); + } catch (DuplicateNameException e) { + // ok + } + parent.stop(); + } + + public void testDuplicateReferenceRegistration() throws Exception { + Component parent = new CompositeComponentImpl(URI.create("parent")); + parent.start(); + + Reference reference1 = EasyMock.createMock(Reference.class); + EasyMock.expect(reference1.getUri()).andReturn(URI.create("#reference")).atLeastOnce(); + reference1.stop(); + EasyMock.replay(reference1); + + Reference reference2 = EasyMock.createMock(Reference.class); + EasyMock.expect(reference2.getUri()).andReturn(URI.create("#reference")).atLeastOnce(); + reference2.stop(); + EasyMock.replay(reference2); + + parent.register(reference2); + try { + parent.register(reference1); + fail(); + } catch (DuplicateNameException e) { + // ok + } + parent.stop(); + + } + + public void testDuplicateServiceReferenceRegistration() throws Exception { + Component parent = new CompositeComponentImpl(URI.create("parent")); + parent.start(); + + Service service1 = EasyMock.createMock(Service.class); + EasyMock.expect(service1.getUri()).andReturn(URI.create("#child")).atLeastOnce(); + service1.stop(); + EasyMock.replay(service1); + + Reference service2 = EasyMock.createMock(Reference.class); + EasyMock.expect(service2.getUri()).andReturn(URI.create("#child")).atLeastOnce(); + service2.stop(); + EasyMock.replay(service2); + + parent.register(service2); + try { + parent.register(service1); + fail(); + } catch (DuplicateNameException e) { + // ok + } + parent.stop(); + + } + + protected void setUp() throws Exception { + super.setUp(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/implementation/composite/ManagedRequestContextTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/implementation/composite/ManagedRequestContextTestCase.java new file mode 100644 index 0000000000..12299e762b --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/implementation/composite/ManagedRequestContextTestCase.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/implementation/composite/ReferenceImplTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/implementation/composite/ReferenceImplTestCase.java new file mode 100644 index 0000000000..34d37469a7 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/implementation/composite/ReferenceImplTestCase.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.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.start(); + EasyMock.replay(binding); + Reference reference = new ReferenceImpl(URI.create("ref"), null); + reference.addReferenceBinding(binding); + reference.start(); + EasyMock.verify(binding); + + } + + public void testStop() { + ReferenceBinding binding = EasyMock.createMock(ReferenceBinding.class); + binding.stop(); + EasyMock.replay(binding); + Reference reference = new ReferenceImpl(URI.create("ref"), null); + reference.addReferenceBinding(binding); + reference.stop(); + EasyMock.verify(binding); + + } +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/implementation/composite/ServiceImplTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/implementation/composite/ServiceImplTestCase.java new file mode 100644 index 0000000000..bb8ed020e0 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/implementation/composite/ServiceImplTestCase.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.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.start(); + EasyMock.replay(binding); + Service service = new ServiceImpl(URI.create("foo#bar"), null, null); + service.addServiceBinding(binding); + service.start(); + EasyMock.verify(binding); + + } + + public void testStop() { + ServiceBinding binding = EasyMock.createMock(ServiceBinding.class); + binding.stop(); + EasyMock.replay(binding); + Service service = new ServiceImpl(URI.create("foo#bar"), null, null); + service.addServiceBinding(binding); + service.stop(); + EasyMock.verify(binding); + + } + +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/injection/SingletonObjectFactoryTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/injection/SingletonObjectFactoryTestCase.java new file mode 100644 index 0000000000..876e68d5b3 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/injection/SingletonObjectFactoryTestCase.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/AsyncTarget.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/AsyncTarget.java new file mode 100644 index 0000000000..653d5d7335 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/AsyncTarget.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/BadContextPojo.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/BadContextPojo.java new file mode 100644 index 0000000000..066acc346d --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/BadContextPojo.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/BadNamePojo.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/BadNamePojo.java new file mode 100644 index 0000000000..77ec37f9e4 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/BadNamePojo.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/BasicInterface.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/BasicInterface.java new file mode 100644 index 0000000000..b7921c248f --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/BasicInterface.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/BasicInterfaceImpl.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/BasicInterfaceImpl.java new file mode 100644 index 0000000000..f7d7bb38cf --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/BasicInterfaceImpl.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponent.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponent.java new file mode 100644 index 0000000000..88b97216cd --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponent.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponentImpl.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponentImpl.java new file mode 100644 index 0000000000..93ee1f707a --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeComponentImpl.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeDestroyOnlyComponent.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeDestroyOnlyComponent.java new file mode 100644 index 0000000000..16ce3b5569 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeDestroyOnlyComponent.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitDestroyComponent.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitDestroyComponent.java new file mode 100644 index 0000000000..05b938a87c --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitDestroyComponent.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitOnlyComponent.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitOnlyComponent.java new file mode 100644 index 0000000000..f9f80ca15c --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/CompositeScopeInitOnlyComponent.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponent.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponent.java new file mode 100644 index 0000000000..c71ac0586f --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponent.java @@ -0,0 +1,29 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponentImpl.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponentImpl.java new file mode 100644 index 0000000000..5ea7278e1f --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeComponentImpl.java @@ -0,0 +1,29 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeDestroyOnlyComponent.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeDestroyOnlyComponent.java new file mode 100644 index 0000000000..8cea9efa49 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeDestroyOnlyComponent.java @@ -0,0 +1,37 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitDestroyComponent.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitDestroyComponent.java new file mode 100644 index 0000000000..40dbfedf2c --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitDestroyComponent.java @@ -0,0 +1,38 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitOnlyComponent.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitOnlyComponent.java new file mode 100644 index 0000000000..caaa0c39e7 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/ConversationalScopeInitOnlyComponent.java @@ -0,0 +1,38 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/OrderException.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/OrderException.java new file mode 100644 index 0000000000..af257c226d --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/OrderException.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojo.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojo.java new file mode 100644 index 0000000000..2033f0eca5 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojo.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojoImpl.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojoImpl.java new file mode 100644 index 0000000000..439c3d143c --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/OrderedDependentPojoImpl.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/OrderedEagerInitPojo.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/OrderedEagerInitPojo.java new file mode 100644 index 0000000000..1986952747 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/OrderedEagerInitPojo.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojo.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojo.java new file mode 100644 index 0000000000..0b891cfa42 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojo.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojoImpl.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojoImpl.java new file mode 100644 index 0000000000..a7063f6353 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/OrderedInitPojoImpl.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/OtherTarget.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/OtherTarget.java new file mode 100644 index 0000000000..0b897daa40 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/OtherTarget.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/OtherTargetImpl.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/OtherTargetImpl.java new file mode 100644 index 0000000000..a3b2bbf098 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/OtherTargetImpl.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeComponent.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeComponent.java new file mode 100644 index 0000000000..8c7dc107ee --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeComponent.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeDestroyOnlyComponent.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeDestroyOnlyComponent.java new file mode 100644 index 0000000000..5224ceda5f --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeDestroyOnlyComponent.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitDestroyComponent.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitDestroyComponent.java new file mode 100644 index 0000000000..38b188a4b5 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitDestroyComponent.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitOnlyComponent.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitOnlyComponent.java new file mode 100644 index 0000000000..707f8ab50f --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/RequestScopeInitOnlyComponent.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponent.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponent.java new file mode 100644 index 0000000000..827ba804f2 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponent.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponentImpl.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponentImpl.java new file mode 100644 index 0000000000..e547bf6113 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeComponentImpl.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitDestroyComponent.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitDestroyComponent.java new file mode 100644 index 0000000000..c11bd1bd49 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitDestroyComponent.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitOnlyComponent.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitOnlyComponent.java new file mode 100644 index 0000000000..095cc916ec --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/SessionScopeInitOnlyComponent.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/SimpleTarget.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/SimpleTarget.java new file mode 100644 index 0000000000..c78ba00a7a --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/SimpleTarget.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/SimpleTargetImpl.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/SimpleTargetImpl.java new file mode 100644 index 0000000000..634a07a401 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/SimpleTargetImpl.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/Source.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/Source.java new file mode 100644 index 0000000000..f7969f748b --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/Source.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/SourceImpl.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/SourceImpl.java new file mode 100644 index 0000000000..187e33b2bd --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/SourceImpl.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponent.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponent.java new file mode 100644 index 0000000000..c16ac942a3 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponent.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponentImpl.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponentImpl.java new file mode 100644 index 0000000000..64a23c12c8 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/StatelessComponentImpl.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/Target.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/Target.java new file mode 100644 index 0000000000..778c14665d --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/Target.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/TargetImpl.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/TargetImpl.java new file mode 100644 index 0000000000..037dd3a37c --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/component/TargetImpl.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/wire/MockStaticInvoker.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/wire/MockStaticInvoker.java new file mode 100644 index 0000000000..98f5973f62 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/wire/MockStaticInvoker.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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; +import org.apache.tuscany.spi.component.WorkContext; + +/** + * 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, WorkContext workContext) 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, null); + 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/wire/MockSyncInterceptor.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/wire/MockSyncInterceptor.java new file mode 100644 index 0000000000..1fe2c027ab --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/wire/MockSyncInterceptor.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/wire/MockTargetInvoker.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/wire/MockTargetInvoker.java new file mode 100644 index 0000000000..3fcc75bdb4 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/mock/wire/MockTargetInvoker.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/monitor/DefaultExceptionFormatterTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/monitor/DefaultExceptionFormatterTestCase.java new file mode 100644 index 0000000000..437e718206 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/monitor/DefaultExceptionFormatterTestCase.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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") { + }; + formatter.write(pw, e); + assertTrue(writer.toString().indexOf("somemessage") >= 0); + } + + public void testTuscanyRuntimeExceptionFormat() throws Exception { + StringWriter writer = new StringWriter(); + PrintWriter pw = new PrintWriter(writer); + TuscanyRuntimeException e = new TuscanyRuntimeException("somemessage") { + }; + formatter.write(pw, e); + assertTrue(writer.toString().indexOf("somemessage") >= 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/monitor/JavaLoggingTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/monitor/JavaLoggingTestCase.java new file mode 100644 index 0000000000..5fdf035c7a --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/monitor/JavaLoggingTestCase.java @@ -0,0 +1,153 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/resolver/DefaultAutowireResolverTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/resolver/DefaultAutowireResolverTestCase.java new file mode 100644 index 0000000000..6d50489f18 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/resolver/DefaultAutowireResolverTestCase.java @@ -0,0 +1,177 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.core.resolver; + +import java.net.URI; + +import org.apache.tuscany.spi.model.AtomicImplementation; +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.CompositeImplementation; +import org.apache.tuscany.spi.model.Property; +import org.apache.tuscany.spi.model.ReferenceDefinition; +import org.apache.tuscany.spi.model.ReferenceTarget; +import org.apache.tuscany.spi.model.ServiceContract; +import org.apache.tuscany.spi.model.ServiceDefinition; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class DefaultAutowireResolverTestCase extends TestCase { + private static final URI REFERENCE_URI = URI.create("source#ref"); + private static final URI TARGET_URI = URI.create("target#service"); + private DefaultAutowireResolver resolver; + + public void testAutowireAtomicToAtomic() throws Exception { + ComponentDefinition<CompositeImplementation> composite = createComposite("composite"); + CompositeComponentType<?, ?, ?> type = composite.getImplementation().getComponentType(); + ComponentDefinition<MockAtomicImpl> source = createSourceAtomic(Foo.class); + type.add(source); + ComponentDefinition<MockAtomicImpl> target = createTargetAtomic(Foo.class); + type.add(target); + resolver.resolve(null, composite); + ReferenceTarget refTarget = source.getReferenceTargets().get(REFERENCE_URI.getFragment()); + assertEquals(TARGET_URI, refTarget.getTargets().get(0)); + } + + public void testAutowireAtomicToAtomicRequiresSuperInterface() throws Exception { + ComponentDefinition<CompositeImplementation> composite = createComposite("composite"); + CompositeComponentType<?, ?, ?> type = composite.getImplementation().getComponentType(); + ComponentDefinition<MockAtomicImpl> source = createSourceAtomic(SuperFoo.class); + type.add(source); + ComponentDefinition<MockAtomicImpl> target = createTargetAtomic(Foo.class); + type.add(target); + resolver.resolve(null, composite); + ReferenceTarget refTarget = source.getReferenceTargets().get(REFERENCE_URI.getFragment()); + assertEquals(TARGET_URI, refTarget.getTargets().get(0)); + } + + public void testAutowireAtomicToAtomicRequiresSubInterface() throws Exception { + ComponentDefinition<CompositeImplementation> composite = createComposite("composite"); + CompositeComponentType<?, ?, ?> type = composite.getImplementation().getComponentType(); + ComponentDefinition<MockAtomicImpl> source = createSourceAtomic(Foo.class); + type.add(source); + ComponentDefinition<MockAtomicImpl> target = createTargetAtomic(SuperFoo.class); + type.add(target); + try { + resolver.resolve(null, composite); + fail(); + } catch (AutowireTargetNotFoundException e) { + // expected + } + } + + public void testAutowireAtomicToAtomicIncompatibleInterfaces() throws Exception { + ComponentDefinition<CompositeImplementation> composite = createComposite("composite"); + CompositeComponentType<?, ?, ?> type = composite.getImplementation().getComponentType(); + ComponentDefinition<MockAtomicImpl> source = createSourceAtomic(Foo.class); + type.add(source); + ComponentDefinition<MockAtomicImpl> target = createTargetAtomic(String.class); + type.add(target); + try { + resolver.resolve(null, composite); + fail(); + } catch (AutowireTargetNotFoundException e) { + // expected + } + } + + public void testNestedAutowireAtomicToAtomic() throws Exception { + ComponentDefinition<CompositeImplementation> composite = createComposite("composite"); + CompositeComponentType<?, ?, ?> type = composite.getImplementation().getComponentType(); + ComponentDefinition<MockAtomicImpl> source = createSourceAtomic(Foo.class); + type.add(source); + ComponentDefinition<MockAtomicImpl> target = createTargetAtomic(Foo.class); + type.add(target); + ComponentDefinition<CompositeImplementation> parent = createComposite("parent"); + parent.getImplementation().getComponentType().add(composite); + resolver.resolve(null, parent); + ReferenceTarget refTarget = source.getReferenceTargets().get(REFERENCE_URI.getFragment()); + assertEquals(TARGET_URI, refTarget.getTargets().get(0)); + } + + + protected void setUp() throws Exception { + super.setUp(); + resolver = new DefaultAutowireResolver(); + } + + private ComponentDefinition<CompositeImplementation> createComposite(String uri) { + URI parentUri = URI.create(uri); + CompositeComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> type = + new CompositeComponentType<ServiceDefinition, ReferenceDefinition, Property<?>>(); + CompositeImplementation impl = new CompositeImplementation(); + impl.setComponentType(type); + return new ComponentDefinition<CompositeImplementation>(parentUri, impl); + } + + private ComponentDefinition<MockAtomicImpl> createSourceAtomic(Class<?> requiredInterface) { + URI uri = URI.create("source"); + ServiceContract contract = new ServiceContract() { + }; + contract.setInterfaceClass(requiredInterface); + ReferenceDefinition reference = new ReferenceDefinition(URI.create("#ref"), contract); + reference.setRequired(true); + MockComponentType type = new MockComponentType(); + type.add(reference); + MockAtomicImpl impl = new MockAtomicImpl(); + impl.setComponentType(type); + ComponentDefinition<MockAtomicImpl> definition = new ComponentDefinition<MockAtomicImpl>(uri, impl); + ReferenceTarget target = new ReferenceTarget(); + target.setReferenceName(REFERENCE_URI); + target.setAutowire(true); + definition.add(target); + return definition; + } + + private ComponentDefinition<MockAtomicImpl> createTargetAtomic(Class<?> serviceInterface) { + URI uri = URI.create("target"); + ServiceDefinition service = new ServiceDefinition(); + service.setUri(URI.create("#service")); + ServiceContract contract = new ServiceContract() { + }; + contract.setInterfaceClass(serviceInterface); + service.setServiceContract(contract); + MockComponentType type = new MockComponentType(); + type.add(service); + MockAtomicImpl impl = new MockAtomicImpl(); + impl.setComponentType(type); + return new ComponentDefinition<MockAtomicImpl>(uri, impl); + } + + private class MockAtomicImpl extends AtomicImplementation<MockComponentType> { + + } + + private class MockComponentType extends ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> { + + } + + private interface SuperFoo { + + } + + private interface Foo extends SuperFoo { + + } + +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/services/store/memory/MemoryStoreTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/services/store/memory/MemoryStoreTestCase.java new file mode 100644 index 0000000000..06ea7cf903 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/services/store/memory/MemoryStoreTestCase.java @@ -0,0 +1,166 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.net.URI; +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.createMock(AtomicComponent.class); + EasyMock.expect(component.getUri()).andReturn(URI.create("component")); + 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/util/Bean1.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/util/Bean1.java new file mode 100644 index 0000000000..79fad549aa --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/util/Bean1.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/util/Bean2.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/util/Bean2.java new file mode 100644 index 0000000000..7f7f03da9e --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/util/Bean2.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/util/JavaIntrospectionHelperTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/util/JavaIntrospectionHelperTestCase.java new file mode 100644 index 0000000000..797b147b54 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/util/JavaIntrospectionHelperTestCase.java @@ -0,0 +1,180 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/util/SuperBean.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/util/SuperBean.java new file mode 100644 index 0000000000..83aef7fb5e --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/util/SuperBean.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/CallbackInterfaceInterceptorTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/CallbackInterfaceInterceptorTestCase.java new file mode 100644 index 0000000000..6c50cb406f --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/CallbackInterfaceInterceptorTestCase.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java new file mode 100644 index 0000000000..c955faf7b1 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/ContractCompatibilityTestCase.java @@ -0,0 +1,390 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.ReferenceBinding; +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.ChainHolder; +import org.apache.tuscany.spi.wire.IncompatibleServiceContractException; +import org.apache.tuscany.spi.wire.ProxyCreationException; +import org.apache.tuscany.spi.wire.Wire; +import org.apache.tuscany.spi.wire.ProxyService; +import org.apache.tuscany.spi.wire.InvocationChain; + +import junit.framework.TestCase; +import org.osoa.sca.CallableReference; + +/** + * TODO some tests commented out due to DataType.equals() needing to be strict + * + * @version $Rev$ $Date$ + */ +public class ContractCompatibilityTestCase extends TestCase { + + private ProxyService proxyService = new MockProxyService(); + + public void testNoOperation() throws Exception { + ServiceContract source = new MockContract<Type>("FooContract"); + ServiceContract target = new MockContract<Type>("FooContract"); + proxyService.checkCompatibility(source, target, false, 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); + proxyService.checkCompatibility(source, target, false, 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 { + proxyService.checkCompatibility(source, target, false, 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); + proxyService.checkCompatibility(source, target, false, 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 { + proxyService.checkCompatibility(source, target, false, 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); + proxyService.checkCompatibility(source, target, false, 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 { + proxyService.checkCompatibility(source, target, false, 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); + proxyService.checkCompatibility(source, target, false, 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); + proxyService.checkCompatibility(source, target, false, 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 MockProxyService extends ProxyServiceExtension { + public MockProxyService() { + super(null); + } + + public <T> T createProxy(Class<T> interfaze, Wire wire) throws ProxyCreationException { + throw new UnsupportedOperationException(); + } + + public <T> T createProxy2(Class<T> interfaze, boolean conversational, Wire wire) throws ProxyCreationException { + throw new UnsupportedOperationException(); + } + + public <T> T createProxy2(Class<T> interfaze, Wire wire) throws ProxyCreationException { + throw new UnsupportedOperationException(); + } + + public <T> T createProxy(Class<T> interfaze, Wire wire, Map<Method, ChainHolder> mapping) + throws ProxyCreationException { + throw new UnsupportedOperationException(); + } + + public <T> T createProxy2(Class<T> interfaze, Wire wire, Map<Method, InvocationChain> mapping) + throws ProxyCreationException { + throw new UnsupportedOperationException(); + } + + public Object createCallbackProxy(Class<?> interfaze, List<Wire> wires) throws ProxyCreationException { + throw new UnsupportedOperationException(); + } + + public Object createCallbackProxy(Class<?> interfaze) throws ProxyCreationException { + throw new UnsupportedOperationException(); + } + + public void createWires(ReferenceBinding referenceBinding, ServiceContract<?> contract, + QualifiedName targetName) { + throw new UnsupportedOperationException(); + } + + public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException { + throw new UnsupportedOperationException(); + } + } + +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/IncompatibleServiceContractExceptionFormatterTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/IncompatibleServiceContractExceptionFormatterTestCase.java new file mode 100644 index 0000000000..a9f455bc62 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/IncompatibleServiceContractExceptionFormatterTestCase.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/InvocationChainImplTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/InvocationChainImplTestCase.java new file mode 100644 index 0000000000..9875058abb --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/InvocationChainImplTestCase.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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 org.apache.tuscany.spi.wire.InvocationChain; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class InvocationChainImplTestCase extends TestCase { + + public void testInsertAtPos() throws Exception { + InvocationChain chain = new InvocationChainImpl(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 { + InvocationChain chain = new InvocationChainImpl(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 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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/NonBlockingInterceptorBuilderTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/NonBlockingInterceptorBuilderTestCase.java new file mode 100644 index 0000000000..c563217306 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/NonBlockingInterceptorBuilderTestCase.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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 static org.apache.tuscany.core.wire.NonBlockingInterceptorBuilder.QNAME; + +import org.apache.tuscany.spi.model.physical.PhysicalInterceptorDefinition; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class NonBlockingInterceptorBuilderTestCase extends TestCase { + + public void testBuild() throws Exception { + NonBlockingInterceptorBuilder builder = new NonBlockingInterceptorBuilder(null, null); + PhysicalInterceptorDefinition definition = new PhysicalInterceptorDefinition(QNAME); + definition.setBuilder(QNAME); + assertTrue(builder.build(definition) instanceof NonBlockingInterceptor); + } +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/NonBlockingInterceptorTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/NonBlockingInterceptorTestCase.java new file mode 100644 index 0000000000..c08d1453db --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/NonBlockingInterceptorTestCase.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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 NonBlockingInterceptorTestCase 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.setCorrelationId(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 NonBlockingInterceptor(scheduler, context, next); + interceptor.invoke(msg); + verify(context); + verify(next); + } + + public void testOptimizable() { + NonBlockingInterceptor interceptor = new NonBlockingInterceptor(null, null); + assertFalse(interceptor.isOptimizable()); + } + +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactoryTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactoryTestCase.java new file mode 100644 index 0000000000..5293678d12 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/OptimizedWireObjectFactoryTestCase.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.Wire; + +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(); + Wire wire = EasyMock.createMock(Wire.class); + EasyMock.expect(wire.getTargetInstance()).andReturn(foo); + EasyMock.replay(wire); + OptimizedWireObjectFactory<Foo> factory = new OptimizedWireObjectFactory<Foo>(Foo.class, wire); + assertEquals(foo, factory.getInstance()); + EasyMock.verify(wire); + } + + private class Foo { + + } +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/WireImplTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/WireImplTestCase.java new file mode 100644 index 0000000000..e337133523 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/WireImplTestCase.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.AtomicComponent; +import org.apache.tuscany.spi.wire.Wire; + +import junit.framework.TestCase; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class WireImplTestCase extends TestCase { + + /** + * Tests that the target wire returns null if there is no connected wire. This behavior is needed for optional + * autowires. + */ + public void testGetNonExistentTarget() throws Exception { + Wire wire = new WireImpl(); + assertNull(wire.getTargetInstance()); + } + + public void testTargetInstance() throws Exception { + Wire wire = new WireImpl(); + AtomicComponent component = EasyMock.createMock(AtomicComponent.class); + EasyMock.expect(component.getTargetInstance()).andReturn(new Object()); + EasyMock.replay(component); + wire.setTarget(component); + assertNotNull(wire.getTargetInstance()); + } + +} diff --git a/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/WireObjectFactoryTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/WireObjectFactoryTestCase.java new file mode 100644 index 0000000000..9f21b9efdb --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/WireObjectFactoryTestCase.java @@ -0,0 +1,138 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.ProxyService; +import org.apache.tuscany.spi.wire.InvocationChain; +import org.apache.tuscany.spi.wire.Wire; + +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); + InvocationChain chain = new InvocationChainImpl(op); + Wire wire = EasyMock.createMock(Wire.class); + Map<Operation<?>, InvocationChain> chains = new HashMap<Operation<?>, InvocationChain>(); + chains.put(op, chain); + EasyMock.expect(wire.getInvocationChains()).andReturn(chains); + EasyMock.expect(wire.isOptimizable()).andReturn(false); + EasyMock.replay(wire); + ProxyService service = EasyMock.createMock(ProxyService.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); + Wire wire = EasyMock.createMock(Wire.class); + EasyMock.expect(wire.isOptimizable()).andReturn(true); + EasyMock.expect(wire.getSourceContract()).andReturn(contract).atLeastOnce(); + EasyMock.expect(wire.getInvocationChains()).andReturn((Map) Collections.emptyMap()); + EasyMock.expect(wire.getTargetInstance()).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); + Wire wire = EasyMock.createMock(Wire.class); + EasyMock.expect(wire.isOptimizable()).andReturn(true); + EasyMock.expect(wire.getSourceContract()).andReturn(contract).atLeastOnce(); + EasyMock.expect(wire.getInvocationChains()).andReturn((Map) Collections.emptyMap()); + EasyMock.replay(wire); + ProxyService service = EasyMock.createMock(ProxyService.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(); + Wire wire = EasyMock.createMock(Wire.class); + EasyMock.expect(wire.isOptimizable()).andReturn(true); + EasyMock.expect(wire.getSourceContract()).andReturn(contract).atLeastOnce(); + EasyMock.expect(wire.getInvocationChains()).andReturn((Map) Collections.emptyMap()); + EasyMock.replay(wire); + ProxyService service = EasyMock.createMock(ProxyService.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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/WireOptimizationTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/WireOptimizationTestCase.java new file mode 100644 index 0000000000..1db3892471 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/WireOptimizationTestCase.java @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.model.Operation; +import static org.apache.tuscany.spi.model.Operation.NO_CONVERSATION; +import org.apache.tuscany.spi.wire.Interceptor; +import org.apache.tuscany.spi.wire.InvocationChain; +import org.apache.tuscany.spi.wire.Message; +import org.apache.tuscany.spi.wire.Wire; + +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 testWireInterceptorOptimization() throws Exception { + AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class); + EasyMock.replay(component); + Wire wire = new WireImpl(); + InvocationChain chain = new InvocationChainImpl(operation); + chain.addInterceptor(new OptimizableInterceptor()); + wire.addInvocationChain(operation, chain); + assertTrue(WireUtils.isOptimizable(wire)); + } + + public void testWireNonInterceptorOptimization() throws Exception { + AtomicComponent component = EasyMock.createNiceMock(AtomicComponent.class); + EasyMock.replay(component); + Wire wire = new WireImpl(); + InvocationChain chain = new InvocationChainImpl(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/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.java b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.java new file mode 100644 index 0000000000..a9da65e0ba --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/wire/WireUtilsTestCase.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.ChainHolder; +import org.apache.tuscany.spi.wire.InvocationChain; +import org.apache.tuscany.spi.wire.Wire; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class WireUtilsTestCase extends TestCase { + private Method m; + + public void testCreateInterfaceToWireMapping() throws Exception { + Wire wire = new WireImpl(); + Operation<Type> op = new Operation<Type>("hello", null, null, null); + InvocationChain chain = new InvocationChainImpl(op); + wire.addInvocationChain(op, chain); + Map<Method, ChainHolder> chains = WireUtils.createInterfaceToWireMapping(Foo.class, wire); + assertEquals(1, chains.size()); + assertNotNull(chains.get(m)); + } + + public void testCreateInterfaceToWireMappingNoOperation() throws Exception { + Wire wire = new WireImpl(); + Operation<Type> op = new Operation<Type>("goodbye", null, null, null); + InvocationChain chain = new InvocationChainImpl(op); + wire.addInvocationChain(op, chain); + try { + WireUtils.createInterfaceToWireMapping(Foo.class, wire); + 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/sandbox/rfeng/minicore/src/test/resources/deployables/sample-calculator.jar b/sandbox/rfeng/minicore/src/test/resources/deployables/sample-calculator.jar Binary files differnew file mode 100644 index 0000000000..0ca3a1b781 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/resources/deployables/sample-calculator.jar diff --git a/sandbox/rfeng/minicore/src/test/resources/marshall/javaChangeSet.xml b/sandbox/rfeng/minicore/src/test/resources/marshall/javaChangeSet.xml new file mode 100644 index 0000000000..2ac4c6932e --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/resources/marshall/javaChangeSet.xml @@ -0,0 +1,72 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<core:changeSet xmlns:core="http://tuscany.apache.org/xmlns/marshaller/1.0-SNAPSHOT"> + + <!-- Component 1 --> + <java:component initLevel="0" groupId="xyz" xmlns:java="http://tuscany.apache.org/xmlns/marshaller/java/1.0-SNAPSHOT" componentId="cmp1" scope="STATELESS"> + <java:classLoaderId>#123</java:classLoaderId> + <bc:instanceFactoryProvider xmlns:bc="http://tuscany.apache.org/xmlns/marshaller/byteCode/1.0-SNAPSHOT"> + <bc:byteCode>AB12345</bc:byteCode> + </bc:instanceFactoryProvider> + </java:component> + + <!-- Component 2 --> + <java:component initLevel="0" groupId="xyz" xmlns:java="http://tuscany.apache.org/xmlns/marshaller/java/1.0-SNAPSHOT" componentId="cmp2" scope="STATELESS"> + <java:classLoaderId>#123</java:classLoaderId> + <reflect:instanceFactoryProvider xmlns:reflect="http://tuscany.apache.org/xmlns/marshaller/reflect/1.0-SNAPSHOT"> + <reflect:implementationClass>com.acme.Foo</reflect:implementationClass> + <reflect:initMethod>init</reflect:initMethod> + <reflect:destroyMethod>destroy</reflect:destroyMethod> + <reflect:constructorArgument>java.lang.String</reflect:constructorArgument> + <reflect:constructorArgument>java.lang.Long</reflect:constructorArgument> + <reflect:cdiSource type="REFERENCE" name="abc"/> + <reflect:injectionSite elementType="FIELD" type="PROPERTY" name="xyz" physicalName="xyz"/> + <reflect:injectionSite elementType="METHOD" type="CALLBACK" name="abc" physicalName="abc"/> + <reflect:property name="abc" value="123"/> + </reflect:instanceFactoryProvider> + </java:component> + + <!-- Wire 1 --> + <core:wire> + <java:wireSource uri="cmp1#rf1" callbackUri="a#b" optimizable="true" conversational="false" + xmlns:java="http://tuscany.apache.org/xmlns/marshaller/java/1.0-SNAPSHOT" /> + <java:wireTarget uri="cmp2#sv2" callbackUri="a#b" optimizable="true" + xmlns:java="http://tuscany.apache.org/xmlns/marshaller/java/1.0-SNAPSHOT" /> + <core:operation name="op2" conversationSequence="1"> + <core:parameter>java.lang.String</core:parameter> + <core:parameter>java.lang.Long</core:parameter> + <core:returnType>java.lang.Object</core:returnType> + </core:operation> + </core:wire> + + <!-- Wire 2 --> + <core:wire> + <java:wireSource uri="cmp2#rf2" callbackUri="a#b" optimizable="true" conversational="true" + xmlns:java="http://tuscany.apache.org/xmlns/marshaller/java/1.0-SNAPSHOT" /> + <java:wireTarget uri="cmp1#sv1" callbackUri="a#b" optimizable="true" + xmlns:java="http://tuscany.apache.org/xmlns/marshaller/java/1.0-SNAPSHOT" /> + <core:operation name="op1" conversationSequence="2"> + <core:parameter>java.lang.String</core:parameter> + <core:parameter>java.lang.Long</core:parameter> + <core:returnType>java.lang.Object</core:returnType> + </core:operation> + </core:wire> + +</core:changeSet>
\ No newline at end of file diff --git a/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/deployer/boot1-include.scdl b/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/deployer/boot1-include.scdl new file mode 100644 index 0000000000..838dbf6a9c --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/deployer/boot1-include.scdl @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" + xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha" + name="boot1-include"> + + <component name="component2"> + <system:implementation.system class="org.apache.tuscany.core.mock.component.BasicInterfaceImpl"/> + </component> + + <service name="service2" promote = "component2"> + <interface.java interface="org.apache.tuscany.core.mock.component.BasicInterface"/> + </service> + +</composite> diff --git a/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/deployer/boot1.scdl b/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/deployer/boot1.scdl new file mode 100644 index 0000000000..8a71aa5698 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/deployer/boot1.scdl @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" + xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha" + targetNamespace="http://example.com" name="boot1"> + <service name="service" promote = "component"> + <interface.java interface="org.apache.tuscany.core.mock.component.BasicInterface"/> + </service> + + <component name="component"> + <system:implementation.system class="org.apache.tuscany.core.mock.component.BasicInterfaceImpl"/> + <property name="publicProperty">propval</property> + <reference name="publicReference" target="component2"/> + </component> + + <include name="boot1-include" scdlLocation="boot1-include.scdl"/> +</composite> diff --git a/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/deployer/boot2.scdl b/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/deployer/boot2.scdl new file mode 100644 index 0000000000..a4f5ecf1e9 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/deployer/boot2.scdl @@ -0,0 +1,160 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<!-- + A more complex example closer to a typical bootstrap configuration + $Rev$ $Date$ +--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" + xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha" + name="boot2" + autowire="true"> + + + <!-- expose Deployer API as a service --> + <service name="deployer" promote="deployerImpl"> + <interface.java interface="org.apache.tuscany.spi.deployer.Deployer"/> + </service> + + <!-- Component that provides the Deployer service --> + <component name="deployerImpl"> + <system:implementation.system class="org.apache.tuscany.core.deployer.DeployerImpl"/> + </component> + + <!-- Component that provides the Autowire resolver service --> + <component name="autowireResolver"> + <system:implementation.system class="org.apache.tuscany.core.resolver.DefaultAutowireResolver"/> + </component> + + <!-- Work management --> + <component name="workContext"> + <system:implementation.system class="org.apache.tuscany.core.component.WorkContextImpl"/> + </component> + + <component name="workScheduler"> + <system:implementation.system class="org.apache.tuscany.core.services.work.jsr237.Jsr237WorkScheduler"/> + </component> + + <component name="workManager"> + <system:implementation.system + class="org.apache.tuscany.core.services.work.jsr237.workmanager.ThreadPoolWorkManager"/> + </component> + + <!-- Builder and BuilderRegistry --> + <component name="builder"> + <system:implementation.system class="org.apache.tuscany.core.builder.BuilderRegistryImpl"/> + </component> + + <!-- Loader and LoaderRegistry --> + <component name="loader"> + <system:implementation.system class="org.apache.tuscany.core.loader.LoaderRegistryImpl"/> + </component> + + <!-- Introspector and IntrospectionRegistry --> + <component name="interfaceProcessorRegistry"> + <system:implementation.system class="org.apache.tuscany.core.implementation.IntrospectionRegistryImpl"/> + </component> + + <!-- Connector infrastructure --> + <component name="connector"> + <system:implementation.system class="org.apache.tuscany.core.builder.ConnectorImpl"/> + </component> + + <component name="interceptorBuilderRegistry"> + <system:implementation.system + class="org.apache.tuscany.core.builder.interceptor.InterceptorBuilderRegistryImpl"/> + </component> + + <component name="wireAttacherRegistry"> + <system:implementation.system + class="org.apache.tuscany.core.builder.physical.WireAttacherRegistryImpl"/> + </component> + + <component name="wirePostProcess"> + <system:implementation.system class="org.apache.tuscany.core.builder.WirePostProcessorRegistryImpl"/> + </component> + + <!-- Resource host registry --> + <component name="resourceHostRegistry"> + <system:implementation.system class="org.apache.tuscany.core.services.host.DelegatingResourceHostRegistry"/> + </component> + + <!-- Foundation element loader implementations --> + <component name="elementLoader.component"> + <system:implementation.system class="org.apache.tuscany.core.loader.ComponentLoader"/> + </component> + <component name="elementLoader.componentType"> + <system:implementation.system class="org.apache.tuscany.core.loader.ComponentTypeElementLoader"/> + </component> + <component name="elementLoader.interface.java"> + <system:implementation.system class="org.apache.tuscany.core.idl.java.InterfaceJavaLoader"/> + </component> + <component name="elementLoader.property"> + <system:implementation.system class="org.apache.tuscany.core.loader.PropertyLoader"/> + </component> + <component name="elementLoader.reference"> + <system:implementation.system class="org.apache.tuscany.core.loader.ReferenceLoader"/> + </component> + <component name="elementLoader.service"> + <system:implementation.system class="org.apache.tuscany.core.loader.ServiceLoader"/> + </component> + + <component name="proxyService"> + <system:implementation.system class="org.apache.tuscany.core.wire.jdk.JDKProxyService"/> + </component> + + <!-- Composite implementation type --> + <component name="composite.loader"> + <system:implementation.system class="org.apache.tuscany.core.implementation.composite.CompositeLoader"/> + </component> + + <component name="interfaceJava.interfaceProcessorRegistry"> + <system:implementation.system class="org.apache.tuscany.core.idl.java.JavaInterfaceProcessorRegistryImpl"/> + </component> + + <component name="artifactRepository"> + <system:implementation.system class="org.apache.tuscany.core.services.artifact.LocalMavenRepository"/> + <property name="repository">.m2/repository</property> + </component> + + <!-- DataBinding registry --> + <component name="databinding.registry"> + <system:implementation.system class="org.apache.tuscany.databinding.impl.DataBindingRegistryImpl"/> + </component> + + <!-- DataBinding registry --> + <component name="databinding.mediator"> + <system:implementation.system class="org.apache.tuscany.databinding.impl.MediatorImpl"/> + </component> + + <!-- Transformer registry --> + <component name="databinding.transformerRegistry" initLevel="90"> + <system:implementation.system class="org.apache.tuscany.databinding.impl.TransformerRegistryImpl"/> + </component> + + <component name="propertyFactory"> + <system:implementation.system class="org.apache.tuscany.core.property.PropertyObjectFactoryImpl"/> + </component> + + <component name="policyBuilderRegistry"> + <system:implementation.system class="org.apache.tuscany.core.policy.PolicyBuilderRegistryImpl"/> + </component> + + +</composite> diff --git a/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/loader/TestPolicy.scdl b/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/loader/TestPolicy.scdl new file mode 100644 index 0000000000..ee75ea23f0 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/loader/TestPolicy.scdl @@ -0,0 +1,51 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<!-- + Default system configuration for the launcher environment. + + $Rev$ $Date$ +--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" + xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha" + xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" + name="org.apache.tuscany.core.policy.testCase"> + <policySet name="BasicAuthMsgProtSecurity" + provides="sec.confidentiality" appliesTo="binding.ws binding.jms" + xmlns="http://www.osoa.org/xmlns/sca/1.0"> + <wsp:PolicyAttachment/> + <intentMap provides="sec.confidentiality" default="transport"> + <qualifier name="transport"> + <wsp:PolicyAttachment/> + <wsp:PolicyAttachment/> + </qualifier> + <qualifier name="message"> + <intentMap provides="sec.confidentiality/message" + default="all"> + <qualifier name="all"> + <wsp:PolicyAttachment/> + </qualifier> + <qualifier name="body"> + <wsp:PolicyAttachment/> + </qualifier> + </intentMap> + </qualifier> + </intentMap> + </policySet> +</composite>
\ No newline at end of file diff --git a/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/loader/test-include.scdl b/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/loader/test-include.scdl new file mode 100644 index 0000000000..584846504b --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/loader/test-include.scdl @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<composite> + This file just needs to exist +</composite>
\ No newline at end of file diff --git a/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/policy/PolicySet.scdl b/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/policy/PolicySet.scdl new file mode 100644 index 0000000000..0860855d9d --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/policy/PolicySet.scdl @@ -0,0 +1,66 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<!-- + Default system configuration for the launcher environment. + + $Rev$ $Date$ +--> +<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" + xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha" + xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" + name="org.apache.tuscany.core.policy.testCase"> + <policySet name="BasicMsgProtSecurity" + provides="sec.confidentiality" appliesTo="binding.ws binding.jms" + xmlns="http://www.osoa.org/xmlns/sca/1.0"> + <wsp:PolicyAttachment/> + <intentMap provides="sec.confidentiality" default="transport"> + <qualifier name="transport"> + <wsp:PolicyAttachment/> + <wsp:PolicyAttachment/> + </qualifier> + <qualifier name="message"> + <intentMap provides="sec.confidentiality/message" + default="all"> + <qualifier name="all"> + <wsp:PolicyAttachment/> + </qualifier> + <qualifier name="body"> + <wsp:PolicyAttachment/> + </qualifier> + </intentMap> + </qualifier> + </intentMap> + </policySet> + + <policySet name="Authentication" + provides="sec.authentication" appliesTo="binding.ws binding.jms"> + <wsp:PolicyAttachment/> + <intentMap provides="authentication" default="cert"> + <qualifier name="cert"> + <wsp:PolicyAttachment/> + <wsp:PolicyAttachment/> + </qualifier> + <qualifier name="basic"> + <wsp:PolicyAttachment/> + </qualifier> + </intentMap> + </policySet> + +</composite>
\ No newline at end of file diff --git a/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/property/ipo.xml b/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/property/ipo.xml new file mode 100644 index 0000000000..5bef464cf7 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/property/ipo.xml @@ -0,0 +1,51 @@ +<?xml version="1.0"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<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> + diff --git a/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/services/deployment/test.ext b/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/services/deployment/test.ext new file mode 100644 index 0000000000..042f3ce1f3 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/services/deployment/test.ext @@ -0,0 +1,18 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ diff --git a/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/services/deployment/test.scdl b/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/services/deployment/test.scdl new file mode 100644 index 0000000000..1e09549194 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/resources/org/apache/tuscany/core/services/deployment/test.scdl @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<composite>
+ This file just needs to exist
+</composite>
\ No newline at end of file diff --git a/sandbox/rfeng/minicore/src/test/resources/repository/sample-calculator.jar b/sandbox/rfeng/minicore/src/test/resources/repository/sample-calculator.jar Binary files differnew file mode 100644 index 0000000000..0ca3a1b781 --- /dev/null +++ b/sandbox/rfeng/minicore/src/test/resources/repository/sample-calculator.jar |