diff options
Diffstat (limited to 'sandbox/rfeng/minicore/src/test/java/org/apache/tuscany/core/builder')
10 files changed, 911 insertions, 0 deletions
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); + } + } +} |