summaryrefslogtreecommitdiffstats
path: root/tags/java-M1-final/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder
diff options
context:
space:
mode:
Diffstat (limited to 'tags/java-M1-final/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder')
-rw-r--r--tags/java-M1-final/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/JavaContextFactoryBuilderTestCase.java112
-rw-r--r--tags/java-M1-final/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/JavaTargetWireBuilderTestCase.java132
-rw-r--r--tags/java-M1-final/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/MockHandlerBuilder.java120
-rw-r--r--tags/java-M1-final/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/MockInterceptorBuilder.java66
4 files changed, 0 insertions, 430 deletions
diff --git a/tags/java-M1-final/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/JavaContextFactoryBuilderTestCase.java b/tags/java-M1-final/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/JavaContextFactoryBuilderTestCase.java
deleted file mode 100644
index fcfd320e0e..0000000000
--- a/tags/java-M1-final/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/JavaContextFactoryBuilderTestCase.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/**
- *
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tuscany.container.java.builder;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-import org.apache.tuscany.container.java.invocation.mock.MockSyncInterceptor;
-import org.apache.tuscany.container.java.mock.MockFactory;
-import org.apache.tuscany.container.java.mock.components.GenericComponent;
-import org.apache.tuscany.container.java.mock.components.ModuleScopeComponent;
-import org.apache.tuscany.core.builder.ContextFactory;
-import org.apache.tuscany.core.builder.system.PolicyBuilderRegistry;
-import org.apache.tuscany.core.builder.system.DefaultPolicyBuilderRegistry;
-import org.apache.tuscany.core.builder.impl.DefaultWireBuilder;
-import org.apache.tuscany.core.context.impl.EventContextImpl;
-import org.apache.tuscany.core.context.scope.DefaultScopeStrategy;
-import org.apache.tuscany.core.context.scope.ModuleScopeContext;
-import org.apache.tuscany.core.context.ScopeStrategy;
-import org.apache.tuscany.core.context.EventContext;
-import org.apache.tuscany.core.context.ScopeContext;
-import org.apache.tuscany.core.context.Context;
-import org.apache.tuscany.core.context.event.ModuleStart;
-import org.apache.tuscany.core.wire.WireConfiguration;
-import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory;
-import org.apache.tuscany.core.wire.SourceWireFactory;
-import org.apache.tuscany.core.wire.service.WireFactoryService;
-import org.apache.tuscany.core.wire.service.DefaultWireFactoryService;
-import org.apache.tuscany.core.message.impl.MessageFactoryImpl;
-import org.apache.tuscany.model.assembly.Component;
-import org.apache.tuscany.model.assembly.Module;
-
-public class JavaContextFactoryBuilderTestCase extends TestCase {
-
- public JavaContextFactoryBuilderTestCase() {
- }
-
- public void testBuilder() throws Exception {
- MockSyncInterceptor mockInterceptor = new MockSyncInterceptor();
- MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, true);
- PolicyBuilderRegistry policyRegistry = new DefaultPolicyBuilderRegistry();
- policyRegistry.registerSourceBuilder(interceptorBuilder);
- WireFactoryService wireService = new DefaultWireFactoryService(new MessageFactoryImpl(), new JDKWireFactoryFactory(), policyRegistry);
- JavaContextFactoryBuilder builder = new JavaContextFactoryBuilder(wireService);
-
- JavaTargetWireBuilder javaWireBuilder = new JavaTargetWireBuilder();
- ScopeStrategy strategy = new DefaultScopeStrategy();
- DefaultWireBuilder wireBuilder = new DefaultWireBuilder();
- wireBuilder.addWireBuilder(javaWireBuilder);
- Module module = MockFactory.createModule();
- EventContext eCtx = new EventContextImpl();
- ScopeContext scopeContext = new ModuleScopeContext(eCtx);
- scopeContext.start();
- scopeContext.onEvent(new ModuleStart(this));
- List<Component> components = module.getComponents();
- Map<String, Component> compMap = new HashMap<String, Component>(components.size());
-
- for (Component component : components) {
- compMap.put(component.getName(), component);
- builder.build(component);
- ContextFactory contextFactory = (ContextFactory) component.getContextFactory();
- Assert.assertNotNull(contextFactory);
- }
- for (Component component : components) {
- ContextFactory<Context> source = (ContextFactory<Context>) component.getContextFactory();
- Assert.assertNotNull(source);
- for (SourceWireFactory pFactory : source.getSourceWireFactories()) {
- WireConfiguration pConfig = pFactory.getConfiguration();
- Component target = compMap.get(pConfig.getTargetName().getPartName());
-
- if (target != null) {
- ContextFactory targetConfig = (ContextFactory) target.getContextFactory();
- boolean downScope = strategy.downScopeReference(source.getScope(), targetConfig.getScope());
- wireBuilder.connect(pFactory, targetConfig.getTargetWireFactory(pFactory.getConfiguration().getTargetName()
- .getPortName()), targetConfig.getClass(), downScope, scopeContext);
- }
- pFactory.initialize();
- }
- scopeContext.registerFactory(source);
- }
- for (Component component : components) {
- ContextFactory config = (ContextFactory) component.getContextFactory();
- Context context = config.createContext();
- if ("source".equals(component.getName())) {
- ModuleScopeComponent source = (ModuleScopeComponent) context.getInstance(null);
- Assert.assertNotNull(source);
- GenericComponent gComp = source.getGenericComponent();
- gComp.getString();
- }
- }
- }
-
-
-}
diff --git a/tags/java-M1-final/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/JavaTargetWireBuilderTestCase.java b/tags/java-M1-final/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/JavaTargetWireBuilderTestCase.java
deleted file mode 100644
index 5a0ee8e14c..0000000000
--- a/tags/java-M1-final/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/JavaTargetWireBuilderTestCase.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/**
- *
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.tuscany.container.java.builder;
-
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Map;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-import org.apache.tuscany.container.java.config.JavaContextFactory;
-import org.apache.tuscany.container.java.invocation.mock.MockHandler;
-import org.apache.tuscany.container.java.invocation.mock.MockSyncInterceptor;
-import org.apache.tuscany.container.java.invocation.mock.SimpleTarget;
-import org.apache.tuscany.container.java.invocation.mock.SimpleTargetImpl;
-import org.apache.tuscany.container.java.mock.MockScopeContext;
-import org.apache.tuscany.core.builder.impl.DefaultWireBuilder;
-import org.apache.tuscany.core.context.QualifiedName;
-import org.apache.tuscany.core.wire.MethodHashMap;
-import org.apache.tuscany.core.wire.impl.InvokerInterceptor;
-import org.apache.tuscany.core.wire.jdk.JDKWireFactoryFactory;
-import org.apache.tuscany.core.wire.WireSourceConfiguration;
-import org.apache.tuscany.core.wire.WireTargetConfiguration;
-import org.apache.tuscany.core.wire.SourceInvocationConfiguration;
-import org.apache.tuscany.core.wire.TargetInvocationConfiguration;
-import org.apache.tuscany.core.wire.TargetWireFactory;
-import org.apache.tuscany.core.wire.SourceWireFactory;
-import org.apache.tuscany.core.message.Message;
-import org.apache.tuscany.core.message.MessageFactory;
-import org.apache.tuscany.core.message.impl.MessageFactoryImpl;
-
-public class JavaTargetWireBuilderTestCase extends TestCase {
-
- private Method hello;
-
- public JavaTargetWireBuilderTestCase() {
- }
-
- public JavaTargetWireBuilderTestCase(String arg0) {
- super(arg0);
- }
-
- public void setUp() throws Exception {
- hello = SimpleTarget.class.getMethod("hello", String.class);
- }
-
-
- /**
- * Tests basic wiring of a source to a target, including handlers and interceptors
- */
- public void testInvocation() throws Exception {
- MessageFactory msgFactory = new MessageFactoryImpl();
-
- SourceInvocationConfiguration source = new SourceInvocationConfiguration(hello);
- MockHandler sourceRequestHandler = new MockHandler();
- MockHandler sourceResponseHandler = new MockHandler();
- MockSyncInterceptor sourceInterceptor = new MockSyncInterceptor();
- source.addRequestHandler(sourceRequestHandler);
- source.addResponseHandler(sourceResponseHandler);
- source.addInterceptor(sourceInterceptor);
-
- SourceWireFactory sourceFactory = new JDKWireFactoryFactory().createSourceWireFactory();
- Map<Method, SourceInvocationConfiguration> sourceInvocationConfigs = new MethodHashMap<SourceInvocationConfiguration>();
- sourceInvocationConfigs.put(hello, source);
- WireSourceConfiguration sourceConfig = new WireSourceConfiguration("foo",new QualifiedName("target/SimpleTarget"),
- sourceInvocationConfigs, Thread.currentThread().getContextClassLoader(), msgFactory);
- sourceFactory.setConfiguration(sourceConfig);
- sourceFactory.setBusinessInterface(SimpleTarget.class);
-
- TargetInvocationConfiguration target = new TargetInvocationConfiguration(hello);
- MockHandler targetRequestHandler = new MockHandler();
- MockHandler targetResponseHandler = new MockHandler();
- MockSyncInterceptor targetInterceptor = new MockSyncInterceptor();
- target.addRequestHandler(targetRequestHandler);
- target.addResponseHandler(targetResponseHandler);
- target.addInterceptor(targetInterceptor);
- target.addInterceptor(new InvokerInterceptor());
-
- TargetWireFactory targetFactory = new JDKWireFactoryFactory().createTargetWireFactory();
- Map<Method, TargetInvocationConfiguration> targetInvocationConfigs = new MethodHashMap<TargetInvocationConfiguration>();
- targetInvocationConfigs.put(hello, target);
- WireTargetConfiguration targetConfig = new WireTargetConfiguration(new QualifiedName("target/SimpleTarget"),
- targetInvocationConfigs, Thread.currentThread().getContextClassLoader(), msgFactory);
- targetFactory.setConfiguration(targetConfig);
- targetFactory.setBusinessInterface(SimpleTarget.class);
-
- // bootstrap a scope container with the target in it
- Map<String,Object> instances = new HashMap<String,Object>();
- SimpleTarget simpleTarget = new SimpleTargetImpl();
- instances.put("target",simpleTarget);
- MockScopeContext scopeCtx = new MockScopeContext(instances);
-
- // connect the source to the target
- DefaultWireBuilder builder = new DefaultWireBuilder();
- builder.addWireBuilder(new JavaTargetWireBuilder());
-
- builder.connect(sourceFactory, targetFactory, JavaContextFactory.class, true, scopeCtx);
- source.build();
- target.build();
- Assert.assertNotNull(source.getTargetInvoker());
-
- Message msg = msgFactory.createMessage();
- msg.setBody("foo");
- msg.setTargetInvoker(source.getTargetInvoker());
- Message response = source.getHeadInterceptor().invoke(msg);
- Assert.assertEquals("foo", response.getBody());
- Assert.assertEquals(1, sourceRequestHandler.getCount());
- Assert.assertEquals(1, sourceResponseHandler.getCount());
- Assert.assertEquals(1, sourceInterceptor.getCount());
- Assert.assertEquals(1, targetRequestHandler.getCount());
- Assert.assertEquals(1, targetResponseHandler.getCount());
- Assert.assertEquals(1, targetInterceptor.getCount());
- }
-
-
-}
-
diff --git a/tags/java-M1-final/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/MockHandlerBuilder.java b/tags/java-M1-final/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/MockHandlerBuilder.java
deleted file mode 100644
index bd1c13c4ac..0000000000
--- a/tags/java-M1-final/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/MockHandlerBuilder.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/**
- *
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
- * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations under the License.
- */
-package org.apache.tuscany.container.java.builder;
-
-import org.apache.tuscany.core.builder.BuilderException;
-import org.apache.tuscany.core.builder.SourcePolicyBuilder;
-import org.apache.tuscany.core.builder.TargetPolicyBuilder;
-import org.apache.tuscany.core.wire.InvocationConfiguration;
-import org.apache.tuscany.core.wire.MessageHandler;
-import org.apache.tuscany.core.wire.SourceInvocationConfiguration;
-import org.apache.tuscany.core.wire.SourceWireFactory;
-import org.apache.tuscany.core.wire.TargetInvocationConfiguration;
-import org.apache.tuscany.core.wire.TargetWireFactory;
-import org.apache.tuscany.core.wire.WireSourceConfiguration;
-import org.apache.tuscany.core.wire.WireTargetConfiguration;
-import org.apache.tuscany.model.assembly.AssemblyObject;
-import org.apache.tuscany.model.assembly.ConfiguredReference;
-import org.apache.tuscany.model.assembly.ConfiguredService;
-
-import java.util.List;
-
-/**
- * Adds a handler to a source or target proxy configuration
- *
- * @version $Rev$ $Date$
- */
-public class MockHandlerBuilder implements SourcePolicyBuilder, TargetPolicyBuilder {
-
-
- private MessageHandler handler;
-
- private boolean source;
-
- private boolean request;
-
- /**
- * Creates the builder.
- *
- * @param handler the handler to add to the source or target proxy configuration
- * @param source true if the handler should be added on the source side; false if the handler should be added to the target
- * side
- * @param request true if the handler is a request handler; false if the handler is a response handler
- */
- public MockHandlerBuilder(MessageHandler handler, boolean source, boolean request) {
- this.handler = handler;
- this.source = source;
- this.request = request;
- }
-
- public void build(AssemblyObject modelObject) throws BuilderException {
- if (source) {
- if (!(modelObject instanceof ConfiguredReference)) {
- return;
- } else {
- ConfiguredReference cref = (ConfiguredReference) modelObject;
- // /xcv WireFactory pFactory = (WireFactory) cref.getProxyFactory();
- for (ConfiguredService configuredService : cref.getTargetConfiguredServices()) {
- SourceWireFactory pFactory = (SourceWireFactory) configuredService.getProxyFactory();
- for (InvocationConfiguration config : pFactory.getConfiguration().getInvocationConfigurations().values()) {
- if (request) {
- config.addRequestHandler(handler);
- } else {
- config.addResponseHandler(handler);
- }
- }
- }
- }
- } else {
- if (!(modelObject instanceof ConfiguredService)) {
- return;
- } else {
- ConfiguredService cservice = (ConfiguredService) modelObject;
- TargetWireFactory pFactory = (TargetWireFactory) cservice.getProxyFactory();
- for (InvocationConfiguration config : pFactory.getConfiguration().getInvocationConfigurations().values()) {
- if (request) {
- config.addRequestHandler(handler);
- } else {
- config.addResponseHandler(handler);
- }
- }
- }
-
- }
- }
-
- public void build(ConfiguredReference reference, List<WireSourceConfiguration> configurations) throws BuilderException {
- for (WireSourceConfiguration wireSourceConfiguration : configurations) {
- for (SourceInvocationConfiguration configuration : wireSourceConfiguration.getInvocationConfigurations().values()) {
- if (request) {
- configuration.addRequestHandler(handler);
- } else {
- configuration.addResponseHandler(handler);
- }
-
- }
-
- }
- }
-
- public void build(ConfiguredService service, WireTargetConfiguration configuration) throws BuilderException {
- for (TargetInvocationConfiguration config : configuration.getInvocationConfigurations().values()) {
- if (request) {
- config.addRequestHandler(handler);
- } else {
- config.addResponseHandler(handler);
- }
- }
- }
-}
diff --git a/tags/java-M1-final/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/MockInterceptorBuilder.java b/tags/java-M1-final/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/MockInterceptorBuilder.java
deleted file mode 100644
index d3ad8a53b5..0000000000
--- a/tags/java-M1-final/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/builder/MockInterceptorBuilder.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- *
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
- * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations under the License.
- */
-package org.apache.tuscany.container.java.builder;
-
-import org.apache.tuscany.core.builder.BuilderException;
-import org.apache.tuscany.core.builder.SourcePolicyBuilder;
-import org.apache.tuscany.core.builder.TargetPolicyBuilder;
-import org.apache.tuscany.core.wire.Interceptor;
-import org.apache.tuscany.core.wire.SourceInvocationConfiguration;
-import org.apache.tuscany.core.wire.SourceWireFactory;
-import org.apache.tuscany.core.wire.TargetInvocationConfiguration;
-import org.apache.tuscany.core.wire.TargetWireFactory;
-import org.apache.tuscany.core.wire.WireFactory;
-import org.apache.tuscany.core.wire.WireSourceConfiguration;
-import org.apache.tuscany.core.wire.WireTargetConfiguration;
-import org.apache.tuscany.model.assembly.AssemblyObject;
-import org.apache.tuscany.model.assembly.ConfiguredReference;
-import org.apache.tuscany.model.assembly.ConfiguredService;
-
-import java.util.List;
-
-/**
- * Adds an interceptor to a source or target proxy configuration
- *
- * @version $Rev$ $Date$
- */
-public class MockInterceptorBuilder implements SourcePolicyBuilder, TargetPolicyBuilder {
-
- private Interceptor interceptor;
-
- /**
- * Creates the builder
- *
- * @param interceptor the interceptor ot add
- * @param source true if the interceptor should be added to the source side; false if the interceptor should be added to
- * the target side
- */
- public MockInterceptorBuilder(Interceptor interceptor, boolean source) {
- this.interceptor = interceptor;
- }
-
- public void build(ConfiguredReference reference, List<WireSourceConfiguration> configurations) throws BuilderException {
- for (WireSourceConfiguration wireSourceConfiguration : configurations) {
- for (SourceInvocationConfiguration configuration : wireSourceConfiguration.getInvocationConfigurations().values()) {
- configuration.addInterceptor(interceptor);
- }
- }
- }
-
- public void build(ConfiguredService service, WireTargetConfiguration configuration) throws BuilderException {
- for (TargetInvocationConfiguration config : configuration.getInvocationConfigurations().values()) {
- config.addInterceptor(interceptor);
- }
- }
-}