summaryrefslogtreecommitdiffstats
path: root/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration
diff options
context:
space:
mode:
Diffstat (limited to 'tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration')
-rw-r--r--tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaBuilderContextIntegrationTestCase.java240
-rw-r--r--tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaIntegrationTestCase.java64
-rw-r--r--tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaRuntimeBootstrapTestCase.java54
-rw-r--r--tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/EntryPointToJavaTestCase.java248
-rw-r--r--tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/JavaToExternalServiceTestCase.java61
-rw-r--r--tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/context/ScopeReferenceTestCase.java709
6 files changed, 0 insertions, 1376 deletions
diff --git a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaBuilderContextIntegrationTestCase.java b/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaBuilderContextIntegrationTestCase.java
deleted file mode 100644
index b935f19214..0000000000
--- a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaBuilderContextIntegrationTestCase.java
+++ /dev/null
@@ -1,240 +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.integration;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-import org.apache.tuscany.container.java.builder.JavaComponentContextBuilder;
-import org.apache.tuscany.container.java.builder.JavaTargetWireBuilder;
-import org.apache.tuscany.container.java.builder.MockHandlerBuilder;
-import org.apache.tuscany.container.java.builder.MockInterceptorBuilder;
-import org.apache.tuscany.container.java.invocation.mock.MockHandler;
-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.core.builder.RuntimeConfigurationBuilder;
-import org.apache.tuscany.core.builder.impl.DefaultWireBuilder;
-import org.apache.tuscany.core.builder.impl.HierarchicalBuilder;
-import org.apache.tuscany.core.context.AggregateContext;
-import org.apache.tuscany.core.context.EventContext;
-import org.apache.tuscany.core.invocation.jdk.JDKProxyFactoryFactory;
-import org.apache.tuscany.core.invocation.spi.ProxyFactoryFactory;
-import org.apache.tuscany.core.message.MessageFactory;
-import org.apache.tuscany.core.message.impl.MessageFactoryImpl;
-import org.apache.tuscany.core.runtime.RuntimeContext;
-import org.apache.tuscany.core.runtime.RuntimeContextImpl;
-import org.apache.tuscany.core.system.builder.SystemComponentContextBuilder;
-import org.apache.tuscany.core.system.builder.SystemEntryPointBuilder;
-import org.apache.tuscany.core.system.builder.SystemExternalServiceBuilder;
-
-/**
- * Verifies that the aggregate context implementation and java component builders construct references properly
- *
- * @version $Rev$ $Date$
- */
-public class JavaBuilderContextIntegrationTestCase extends TestCase {
-
- public JavaBuilderContextIntegrationTestCase(String arg0) {
- super(arg0);
- }
-
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- public void testRefWithSourceInterceptor() throws Exception {
- MessageFactory msgFactory = new MessageFactoryImpl();
-
- List<RuntimeConfigurationBuilder> builders = new ArrayList();
- builders.add((new SystemComponentContextBuilder()));
- builders.add(new SystemEntryPointBuilder());
- builders.add(new SystemExternalServiceBuilder());
-
- ProxyFactoryFactory proxyFactoryFactory =new JDKProxyFactoryFactory();
-
- JavaComponentContextBuilder javaBuilder = new JavaComponentContextBuilder();
- javaBuilder.setMessageFactory(msgFactory);
- javaBuilder.setProxyFactoryFactory(proxyFactoryFactory);
-
- MockSyncInterceptor mockInterceptor = new MockSyncInterceptor();
- MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, true);
- //HierarchicalBuilder refBuilder = new HierarchicalBuilder();
- //refBuilder.addBuilder(interceptorBuilder);
- javaBuilder.addPolicyBuilder(interceptorBuilder);
- builders.add(javaBuilder);
-
- DefaultWireBuilder defaultWireBuilder = new DefaultWireBuilder();
-
- RuntimeContext runtime = new RuntimeContextImpl(null, null, builders, defaultWireBuilder);
- runtime.addBuilder(new JavaTargetWireBuilder());
- runtime.start();
- runtime.getRootContext().registerModelObject(
- MockFactory.createAggregateComponent("test.module"));
- AggregateContext child = (AggregateContext) runtime.getRootContext().getContext("test.module");
- child.registerModelObject(MockFactory.createModule());
- child.fireEvent(EventContext.MODULE_START, null);
- GenericComponent source = (GenericComponent) child.locateInstance("source");
- Assert.assertNotNull(source);
- source.getGenericComponent().getString();
- Assert.assertEquals(1, mockInterceptor.getCount());
- source.getGenericComponent().getString();
- Assert.assertEquals(2, mockInterceptor.getCount());
- child.fireEvent(EventContext.MODULE_STOP, null);
- runtime.stop();
- }
-
- public void testRefWithSourceInterceptorHandler() throws Exception {
- MessageFactory msgFactory = new MessageFactoryImpl();
-
- List<RuntimeConfigurationBuilder> builders = new ArrayList();
- builders.add((new SystemComponentContextBuilder()));
- builders.add(new SystemEntryPointBuilder());
- builders.add(new SystemExternalServiceBuilder());
-
- JavaComponentContextBuilder javaBuilder = new JavaComponentContextBuilder();
- javaBuilder.setMessageFactory(msgFactory);
- javaBuilder.setProxyFactoryFactory(new JDKProxyFactoryFactory());
-
- MockSyncInterceptor mockInterceptor = new MockSyncInterceptor();
- MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, true);
- //HierarchicalBuilder refBuilder = new HierarchicalBuilder();
- //refBuilder.addBuilder(interceptorBuilder);
- MockHandler mockHandler = new MockHandler();
- MockHandlerBuilder handlerBuilder = new MockHandlerBuilder(mockHandler, true, true);
- //refBuilder.addBuilder(handlerBuilder);
- javaBuilder.addPolicyBuilder(interceptorBuilder);
- javaBuilder.addPolicyBuilder(handlerBuilder);
-
- //javaBuilder.setPolicyBuilder(refBuilder);
- builders.add(javaBuilder);
-
- DefaultWireBuilder defaultWireBuilder = new DefaultWireBuilder();
- RuntimeContext runtime = new RuntimeContextImpl(null, null, builders, defaultWireBuilder);
- runtime.addBuilder(new JavaTargetWireBuilder());
- runtime.start();
- runtime.getRootContext().registerModelObject(
- MockFactory.createAggregateComponent("test.module"));
- AggregateContext child = (AggregateContext) runtime.getRootContext().getContext("test.module");
- child.registerModelObject(MockFactory.createModule());
- child.fireEvent(EventContext.MODULE_START, null);
- GenericComponent source = (GenericComponent) child.locateInstance("source");
- Assert.assertNotNull(source);
- source.getGenericComponent().getString();
- Assert.assertEquals(1, mockInterceptor.getCount());
- Assert.assertEquals(1, mockHandler.getCount());
- source.getGenericComponent().getString();
- Assert.assertEquals(2, mockInterceptor.getCount());
- Assert.assertEquals(2, mockHandler.getCount());
- child.fireEvent(EventContext.MODULE_STOP, null);
- runtime.stop();
- }
-
- public void testRefWithTargetInterceptorHandler() throws Exception {
- MessageFactory msgFactory = new MessageFactoryImpl();
-
- List<RuntimeConfigurationBuilder> builders = new ArrayList();
- builders.add((new SystemComponentContextBuilder()));
- builders.add(new SystemEntryPointBuilder());
- builders.add(new SystemExternalServiceBuilder());
-
- JavaComponentContextBuilder javaBuilder = new JavaComponentContextBuilder();
- javaBuilder.setMessageFactory(msgFactory);
- javaBuilder.setProxyFactoryFactory(new JDKProxyFactoryFactory());
-
- MockSyncInterceptor mockInterceptor = new MockSyncInterceptor();
- MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false);
- //HierarchicalBuilder refBuilder = new HierarchicalBuilder();
- //refBuilder.addBuilder(interceptorBuilder);
- MockHandler mockHandler = new MockHandler();
- MockHandlerBuilder handlerBuilder = new MockHandlerBuilder(mockHandler, false, true);
- //refBuilder.addBuilder(handlerBuilder);
- javaBuilder.addPolicyBuilder(interceptorBuilder);
- javaBuilder.addPolicyBuilder(handlerBuilder);
-
- // javaBuilder.setPolicyBuilder(refBuilder);
- builders.add(javaBuilder);
-
- DefaultWireBuilder defaultWireBuilder = new DefaultWireBuilder();
-
- RuntimeContext runtime = new RuntimeContextImpl(null, null, builders, defaultWireBuilder);
- runtime.addBuilder(new JavaTargetWireBuilder());
- runtime.start();
- runtime.getRootContext().registerModelObject(
- MockFactory.createAggregateComponent("test.module"));
- AggregateContext child = (AggregateContext) runtime.getRootContext().getContext("test.module");
- child.registerModelObject(MockFactory.createModule());
- child.fireEvent(EventContext.MODULE_START, null);
- GenericComponent source = (GenericComponent) child.locateInstance("source");
- Assert.assertNotNull(source);
- source.getGenericComponent().getString();
- Assert.assertEquals(1, mockInterceptor.getCount());
- Assert.assertEquals(1, mockHandler.getCount());
- source.getGenericComponent().getString();
- Assert.assertEquals(2, mockInterceptor.getCount());
- Assert.assertEquals(2, mockHandler.getCount());
- child.fireEvent(EventContext.MODULE_STOP, null);
- runtime.stop();
- }
-
- public void testRefWithTargetInterceptor() throws Exception {
- MessageFactory msgFactory = new MessageFactoryImpl();
-
- List<RuntimeConfigurationBuilder> builders = new ArrayList();
- builders.add((new SystemComponentContextBuilder()));
- builders.add(new SystemEntryPointBuilder());
- builders.add(new SystemExternalServiceBuilder());
-
- JavaComponentContextBuilder javaBuilder = new JavaComponentContextBuilder();
- javaBuilder.setMessageFactory(msgFactory);
- javaBuilder.setProxyFactoryFactory(new JDKProxyFactoryFactory());
-
- MockSyncInterceptor mockInterceptor = new MockSyncInterceptor();
- MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false);
- //HierarchicalBuilder refBuilder = new HierarchicalBuilder();
- //refBuilder.addBuilder(interceptorBuilder);
- javaBuilder.addPolicyBuilder(interceptorBuilder);
-
- //javaBuilder.setPolicyBuilder(refBuilder);
- builders.add(javaBuilder);
-
- DefaultWireBuilder defaultWireBuilder = new DefaultWireBuilder();
-
- RuntimeContext runtime = new RuntimeContextImpl(null, null, builders, defaultWireBuilder);
- runtime.addBuilder(new JavaTargetWireBuilder());
-
- runtime.start();
- runtime.getRootContext().registerModelObject(
- MockFactory.createAggregateComponent("test.module"));
- AggregateContext child = (AggregateContext) runtime.getRootContext().getContext("test.module");
- child.registerModelObject(MockFactory.createModule());
- child.fireEvent(EventContext.MODULE_START, null);
- GenericComponent source = (GenericComponent) child.locateInstance("source");
- Assert.assertNotNull(source);
- source.getGenericComponent().getString();
- Assert.assertEquals(1, mockInterceptor.getCount());
- source.getGenericComponent().getString();
- Assert.assertEquals(2, mockInterceptor.getCount());
- child.fireEvent(EventContext.MODULE_STOP, null);
- runtime.stop();
- }
-
-}
diff --git a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaIntegrationTestCase.java b/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaIntegrationTestCase.java
deleted file mode 100644
index 795a6fe908..0000000000
--- a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaIntegrationTestCase.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/**
- *
- * Copyright 2005 BEA Systems Inc.
- * Copyright 2005 International Business Machines Corporation
- *
- * 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.integration;
-
-import junit.framework.TestCase;
-
-import org.apache.tuscany.container.java.assembly.JavaAssemblyFactory;
-import org.apache.tuscany.container.java.assembly.impl.JavaAssemblyFactoryImpl;
-import org.apache.tuscany.core.runtime.RuntimeContext;
-import org.apache.tuscany.core.runtime.RuntimeContextImpl;
-import org.apache.tuscany.model.assembly.Module;
-import org.apache.tuscany.model.assembly.ModuleComponent;
-
-/**
- * Integration test that verifies container.java can be used to host components.
- *
- * @version $Rev$ $Date$
- */
-public class JavaIntegrationTestCase extends TestCase {
- private JavaAssemblyFactory factory;
- private RuntimeContext runtime;
-
- public void testModuleWithOneComponent() throws Exception {
- Module module = factory.createModule();
- ModuleComponent moduleComponent = factory.createModuleComponent();
- moduleComponent.setModuleImplementation(module);
-
-// runtime.registerModelObject(moduleComponent);
- }
-
- protected void setUp() throws Exception {
- super.setUp();
-
- // Create a factory for model objects
- factory = new JavaAssemblyFactoryImpl();
-
- // Create and bootstrap an empty Tuscany runtime
- this.runtime = new RuntimeContextImpl();
- this.runtime.start();
-
-// Component component = MockSystemAssemblyFactory.createComponent(RuntimeContext.SYSTEM, SystemAggregateContextImpl.class.getName(), ContextConstants.AGGREGATE_SCOPE_ENUM);
-// runtime.registerModelObject(component);
- }
-
- protected void tearDown() throws Exception {
- runtime.stop();
- super.tearDown();
- }
-}
diff --git a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaRuntimeBootstrapTestCase.java b/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaRuntimeBootstrapTestCase.java
deleted file mode 100644
index d474d9cb4f..0000000000
--- a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaRuntimeBootstrapTestCase.java
+++ /dev/null
@@ -1,54 +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.integration;
-
-import org.apache.tuscany.container.java.mock.MockFactory;
-import org.apache.tuscany.container.java.mock.components.GenericComponent;
-import org.apache.tuscany.core.context.AggregateContext;
-import org.apache.tuscany.core.context.EventContext;
-import org.apache.tuscany.core.context.InstanceContext;
-import org.apache.tuscany.core.runtime.RuntimeContext;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-/**
- * Ensures basic runtime with Java support boots properly
- *
- * @version $Rev$ $Date$
- */
-public class JavaRuntimeBootstrapTestCase extends TestCase {
-
- /**
- * Tests the runtime can be bootstrapped with Java builders and two module-scoped Java-based components can be wired
- */
- public void testRuntimeBoot() throws Exception{
- RuntimeContext runtime = MockFactory.createJavaRuntime();
- InstanceContext ctx = runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD);
- Assert.assertNotNull(ctx);
- runtime.getRootContext().registerModelObject(MockFactory.createAggregateComponent("test"));
- AggregateContext testCtx = (AggregateContext) runtime.getRootContext().getContext("test");
- Assert.assertNotNull(testCtx);
- testCtx.registerModelObject(MockFactory.createModule());
- testCtx.fireEvent(EventContext.MODULE_START,null);
- GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source);
- GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null);
- Assert.assertNotNull(target);
- source.getGenericComponent().getString();
-
- }
-
-}
-
diff --git a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/EntryPointToJavaTestCase.java b/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/EntryPointToJavaTestCase.java
deleted file mode 100644
index a9408ef9ee..0000000000
--- a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/EntryPointToJavaTestCase.java
+++ /dev/null
@@ -1,248 +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.integration.binding;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-import org.apache.tuscany.container.java.assembly.mock.HelloWorldService;
-import org.apache.tuscany.container.java.builder.MockInterceptorBuilder;
-import org.apache.tuscany.container.java.invocation.mock.MockSyncInterceptor;
-import org.apache.tuscany.container.java.mock.MockFactory;
-import org.apache.tuscany.container.java.mock.binding.foo.FooBindingBuilder;
-import org.apache.tuscany.core.context.AggregateContext;
-import org.apache.tuscany.core.context.EntryPointContext;
-import org.apache.tuscany.core.context.EventContext;
-import org.apache.tuscany.core.runtime.RuntimeContext;
-import org.apache.tuscany.model.assembly.Scope;
-
-/**
- * Tests basic entry point functionality with Java components
- *
- * @version $Rev$ $Date$
- */
-public class EntryPointToJavaTestCase extends TestCase {
-
- private Method hello;
-
- public void setUp() throws Exception {
- hello = HelloWorldService.class.getMethod("hello", new Class[] { String.class });
- }
-
- /**
- * Tests creation and invocation of an entry point wired to a module-scoped service offered by a Java component
- */
- public void testEPtoJavaModuleScopeInvoke() throws Throwable {
- RuntimeContext runtime = MockFactory.registerFooBinding(MockFactory.createJavaRuntime());
- FooBindingBuilder builder = (FooBindingBuilder) ((AggregateContext) runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD))
- .getContext(MockFactory.FOO_BUILDER).getInstance(null);
- MockSyncInterceptor mockInterceptor = new MockSyncInterceptor();
- MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false);
- builder.addPolicyBuilder(interceptorBuilder);
- runtime.getRootContext().registerModelObject(MockFactory.createAggregateComponent("test.module"));
- AggregateContext child = (AggregateContext) runtime.getRootContext().getContext("test.module");
- child.registerModelObject(MockFactory.createModuleWithEntryPoint(Scope.MODULE));
- child.fireEvent(EventContext.MODULE_START, null);
- child.fireEvent(EventContext.REQUEST_START, null);
- EntryPointContext ctx = (EntryPointContext) child.getContext("source");
- Assert.assertNotNull(ctx);
- InvocationHandler handler = (InvocationHandler) ctx.getImplementationInstance();
- Assert.assertEquals(0, mockInterceptor.getCount());
- Object response = handler.invoke(null, hello, new Object[] { "foo" });
- Assert.assertEquals("Hello foo", response);
- Assert.assertEquals(1, mockInterceptor.getCount());
- child.fireEvent(EventContext.REQUEST_END, null);
-
- // second request
- child.fireEvent(EventContext.REQUEST_START, null);
- ctx = (EntryPointContext) child.getContext("source");
- Assert.assertNotNull(ctx);
- handler = (InvocationHandler) ctx.getImplementationInstance();
- Assert.assertEquals(1, mockInterceptor.getCount());
- response = handler.invoke(null, hello, new Object[] { "foo" });
- Assert.assertEquals("Hello foo", response);
- Assert.assertEquals(2, mockInterceptor.getCount());
- HelloWorldService service1 = (HelloWorldService)child.getContext("target").getInstance(null);
- Assert.assertEquals(2, service1.count());
- child.fireEvent(EventContext.REQUEST_END, null);
-
- child.fireEvent(EventContext.MODULE_STOP, null);
- runtime.stop();
- }
-
- /**
- * Tests creation and invocation of an entry point wired to a session-scoped service offered by a Java component
- */
- public void testEPtoJavaSessionScopeInvoke() throws Throwable {
- RuntimeContext runtime = MockFactory.registerFooBinding(MockFactory.createJavaRuntime());
- FooBindingBuilder builder = (FooBindingBuilder) ((AggregateContext) runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD))
- .getContext(MockFactory.FOO_BUILDER).getInstance(null);
- MockSyncInterceptor mockInterceptor = new MockSyncInterceptor();
- MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false);
- builder.addPolicyBuilder(interceptorBuilder);
- runtime.getRootContext().registerModelObject(MockFactory.createAggregateComponent("test.module"));
- AggregateContext child = (AggregateContext) runtime.getRootContext().getContext("test.module");
- child.registerModelObject(MockFactory.createModuleWithEntryPoint(Scope.SESSION));
- child.fireEvent(EventContext.MODULE_START, null);
-
- // first session
- Object session = new Object();
- child.fireEvent(EventContext.REQUEST_START, null);
- child.fireEvent(EventContext.SESSION_NOTIFY, session);
-
- EntryPointContext ctx = (EntryPointContext) child.getContext("source");
- Assert.assertNotNull(ctx);
- InvocationHandler handler = (InvocationHandler) ctx.getImplementationInstance();
- Assert.assertEquals(0, mockInterceptor.getCount());
- Object response = handler.invoke(null, hello, new Object[] { "foo" });
- Assert.assertEquals("Hello foo", response);
- Assert.assertEquals(1, mockInterceptor.getCount());
- child.fireEvent(EventContext.REQUEST_END, session);
-
- child.fireEvent(EventContext.REQUEST_START, null);
- child.fireEvent(EventContext.SESSION_NOTIFY, session);
- EntryPointContext ctx2 = (EntryPointContext) child.getContext("source");
- Assert.assertNotNull(ctx2);
- response = handler.invoke(null, hello, new Object[] { "foo" });
- Assert.assertEquals("Hello foo", response);
- Assert.assertEquals(2, mockInterceptor.getCount());
- HelloWorldService service1 = (HelloWorldService)child.getContext("target").getInstance(null);
- Assert.assertEquals(2, service1.count());
- child.fireEvent(EventContext.REQUEST_END, session);
- child.fireEvent(EventContext.SESSION_END, session);
-
-
- // second session
- Object session2 = new Object();
- child.fireEvent(EventContext.REQUEST_START, null);
- child.fireEvent(EventContext.SESSION_NOTIFY, session2);
-
- ctx = (EntryPointContext) child.getContext("source");
- Assert.assertNotNull(ctx);
- Assert.assertEquals(2, mockInterceptor.getCount());
- response = handler.invoke(null, hello, new Object[] { "foo" });
- Assert.assertEquals("Hello foo", response);
- Assert.assertEquals(3, mockInterceptor.getCount());
- child.fireEvent(EventContext.REQUEST_END, session2);
-
- child.fireEvent(EventContext.REQUEST_START, null);
- child.fireEvent(EventContext.SESSION_NOTIFY, session2);
- ctx2 = (EntryPointContext) child.getContext("source");
- Assert.assertNotNull(ctx2);
- response = handler.invoke(null, hello, new Object[] { "foo" });
- Assert.assertEquals("Hello foo", response);
- Assert.assertEquals(4, mockInterceptor.getCount());
- HelloWorldService service2 = (HelloWorldService)child.getContext("target").getInstance(null);
- Assert.assertEquals(2, service2.count());
- Assert.assertEquals(2, service1.count()); //ensure sessions not crossed
- child.fireEvent(EventContext.REQUEST_END, session2);
- child.fireEvent(EventContext.SESSION_NOTIFY, session2);
-
-
- child.fireEvent(EventContext.MODULE_STOP, null);
- runtime.stop();
- }
-
-
- /**
- * Tests creation and invocation of an entry point wired to a module-scoped service offered by a Java component
- */
- public void testEPtoJavaStatelessInvoke() throws Throwable {
- RuntimeContext runtime = MockFactory.registerFooBinding(MockFactory.createJavaRuntime());
- FooBindingBuilder builder = (FooBindingBuilder) ((AggregateContext) runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD))
- .getContext(MockFactory.FOO_BUILDER).getInstance(null);
- MockSyncInterceptor mockInterceptor = new MockSyncInterceptor();
- MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false);
- builder.addPolicyBuilder(interceptorBuilder);
- runtime.getRootContext().registerModelObject(MockFactory.createAggregateComponent("test.module"));
- AggregateContext child = (AggregateContext) runtime.getRootContext().getContext("test.module");
- child.registerModelObject(MockFactory.createModuleWithEntryPoint(Scope.INSTANCE));
- child.fireEvent(EventContext.MODULE_START, null);
- child.fireEvent(EventContext.REQUEST_START, null);
- EntryPointContext ctx = (EntryPointContext) child.getContext("source");
- Assert.assertNotNull(ctx);
- InvocationHandler handler = (InvocationHandler) ctx.getImplementationInstance();
- Assert.assertEquals(0, mockInterceptor.getCount());
- Object response = handler.invoke(null, hello, new Object[] { "foo" });
- Assert.assertEquals("Hello foo", response);
- Assert.assertEquals(1, mockInterceptor.getCount());
- child.fireEvent(EventContext.REQUEST_END, null);
-
- // second request
- child.fireEvent(EventContext.REQUEST_START, null);
- ctx = (EntryPointContext) child.getContext("source");
- Assert.assertNotNull(ctx);
- handler = (InvocationHandler) ctx.getImplementationInstance();
- Assert.assertEquals(1, mockInterceptor.getCount());
- response = handler.invoke(null, hello, new Object[] { "foo" });
- Assert.assertEquals("Hello foo", response);
- Assert.assertEquals(2, mockInterceptor.getCount());
- HelloWorldService service1 = (HelloWorldService)child.getContext("target").getInstance(null);
- Assert.assertEquals(0, service1.count());
- child.fireEvent(EventContext.REQUEST_END, null);
-
- child.fireEvent(EventContext.MODULE_STOP, null);
- runtime.stop();
- }
-
- public void testEPtoJavaRequestInvoke() throws Throwable {
- RuntimeContext runtime = MockFactory.registerFooBinding(MockFactory.createJavaRuntime());
- FooBindingBuilder builder = (FooBindingBuilder) ((AggregateContext) runtime.getSystemContext().getContext(MockFactory.SYSTEM_CHILD))
- .getContext(MockFactory.FOO_BUILDER).getInstance(null);
- MockSyncInterceptor mockInterceptor = new MockSyncInterceptor();
- MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false);
- builder.addPolicyBuilder(interceptorBuilder);
- runtime.getRootContext().registerModelObject(MockFactory.createAggregateComponent("test.module"));
- AggregateContext child = (AggregateContext) runtime.getRootContext().getContext("test.module");
- child.registerModelObject(MockFactory.createModuleWithEntryPoint(Scope.REQUEST));
- child.fireEvent(EventContext.MODULE_START, null);
- child.fireEvent(EventContext.REQUEST_START, null);
- EntryPointContext ctx = (EntryPointContext) child.getContext("source");
- Assert.assertNotNull(ctx);
- InvocationHandler handler = (InvocationHandler) ctx.getImplementationInstance();
- Assert.assertEquals(0, mockInterceptor.getCount());
- Object response = handler.invoke(null, hello, new Object[] { "foo" });
- Assert.assertEquals("Hello foo", response);
- Assert.assertEquals(1, mockInterceptor.getCount());
-
- ctx = (EntryPointContext) child.getContext("source");
- Assert.assertNotNull(ctx);
- handler = (InvocationHandler) ctx.getImplementationInstance();
- response = handler.invoke(null, hello, new Object[] { "foo" });
- HelloWorldService service1 = (HelloWorldService)child.getContext("target").getInstance(null);
- Assert.assertEquals(2, service1.count());
-
- child.fireEvent(EventContext.REQUEST_END, null);
-
- // second request
- child.fireEvent(EventContext.REQUEST_START, null);
- ctx = (EntryPointContext) child.getContext("source");
- Assert.assertNotNull(ctx);
- handler = (InvocationHandler) ctx.getImplementationInstance();
- Assert.assertEquals(2, mockInterceptor.getCount());
- response = handler.invoke(null, hello, new Object[] { "foo" });
- Assert.assertEquals("Hello foo", response);
- Assert.assertEquals(3, mockInterceptor.getCount());
- HelloWorldService service2 = (HelloWorldService)child.getContext("target").getInstance(null);
- Assert.assertEquals(1, service2.count());
- child.fireEvent(EventContext.REQUEST_END, null);
-
- child.fireEvent(EventContext.MODULE_STOP, null);
- runtime.stop();
- }
-
-}
diff --git a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/JavaToExternalServiceTestCase.java b/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/JavaToExternalServiceTestCase.java
deleted file mode 100644
index a2c88e315a..0000000000
--- a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/binding/JavaToExternalServiceTestCase.java
+++ /dev/null
@@ -1,61 +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.integration.binding;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-import org.apache.tuscany.container.java.assembly.mock.HelloWorldService;
-import org.apache.tuscany.container.java.builder.MockInterceptorBuilder;
-import org.apache.tuscany.container.java.invocation.mock.MockSyncInterceptor;
-import org.apache.tuscany.container.java.mock.MockFactory;
-import org.apache.tuscany.container.java.mock.binding.foo.FooBindingBuilder;
-import org.apache.tuscany.core.context.AggregateContext;
-import org.apache.tuscany.core.context.EventContext;
-import org.apache.tuscany.core.runtime.RuntimeContext;
-
-/**
- * Tests basic Java to external service interaction
- *
- * @version $Rev$ $Date$
- */
-public class JavaToExternalServiceTestCase extends TestCase {
-
- /**
- * Tests an invocation of an external service configured with the
- * {@link org.apache.tuscany.container.java.mock.binding.foo.FooBinding} from a Java component
- *
- * @throws Exception
- */
- public void testJavaToESInvoke() throws Exception {
- RuntimeContext runtime = MockFactory.registerFooBinding(MockFactory.createJavaRuntime());
- FooBindingBuilder builder = (FooBindingBuilder) ((AggregateContext) runtime.getSystemContext().getContext(
- MockFactory.SYSTEM_CHILD)).getContext(MockFactory.FOO_BUILDER).getInstance(null);
- MockSyncInterceptor mockInterceptor = new MockSyncInterceptor();
- MockInterceptorBuilder interceptorBuilder = new MockInterceptorBuilder(mockInterceptor, false);
- builder.addPolicyBuilder(interceptorBuilder);
- runtime.getRootContext().registerModelObject(MockFactory.createAggregateComponent("test.module"));
- AggregateContext child = (AggregateContext) runtime.getRootContext().getContext("test.module");
- child.registerModelObject(MockFactory.createModuleWithExternalService());
- child.fireEvent(EventContext.MODULE_START, null);
- HelloWorldService source = (HelloWorldService) child.locateInstance("source");
- Assert.assertNotNull(source);
- Assert.assertEquals(0, mockInterceptor.getCount());
- Assert.assertEquals("foo", source.hello("foo"));
- Assert.assertEquals(1, mockInterceptor.getCount());
- child.fireEvent(EventContext.MODULE_STOP, null);
- runtime.stop();
- }
-
-}
diff --git a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/context/ScopeReferenceTestCase.java b/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/context/ScopeReferenceTestCase.java
deleted file mode 100644
index fc9bab4ca3..0000000000
--- a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/context/ScopeReferenceTestCase.java
+++ /dev/null
@@ -1,709 +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.integration.context;
-
-import org.apache.tuscany.container.java.mock.MockFactory;
-import org.apache.tuscany.container.java.mock.components.GenericComponent;
-import org.apache.tuscany.core.context.AggregateContext;
-import org.apache.tuscany.core.context.EventContext;
-import org.apache.tuscany.core.context.InstanceContext;
-import org.apache.tuscany.core.runtime.RuntimeContext;
-import org.apache.tuscany.model.assembly.Scope;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-/**
- * Tests scoping is properly handled for service references
- *
- * @version $Rev$ $Date$
- */
-public class ScopeReferenceTestCase extends TestCase {
-
- /**
- * Tests a module-to-module scoped wire is setup properly by the runtime
- */
- public void testModuleToModule() throws Exception{
- RuntimeContext runtime = MockFactory.createJavaRuntime();
- InstanceContext ctx = runtime.getSystemContext().getContext("tuscany.system.child");
- Assert.assertNotNull(ctx);
- runtime.getRootContext().registerModelObject(MockFactory.createAggregateComponent("test"));
- AggregateContext testCtx = (AggregateContext) runtime.getRootContext().getContext("test");
- Assert.assertNotNull(testCtx);
- testCtx.registerModelObject(MockFactory.createModule());
- testCtx.fireEvent(EventContext.MODULE_START,null);
- GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source);
- GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null);
- Assert.assertNotNull(target);
- source.getGenericComponent().getString();
- }
-
- /**
- * Tests a module-to-session scoped wire is setup properly by the runtime
- */
- public void testModuleToSession() throws Exception{
- RuntimeContext runtime = MockFactory.createJavaRuntime();
- InstanceContext ctx = runtime.getSystemContext().getContext("tuscany.system.child");
- Assert.assertNotNull(ctx);
- runtime.getRootContext().registerModelObject(MockFactory.createAggregateComponent("test"));
- AggregateContext testCtx = (AggregateContext) runtime.getRootContext().getContext("test");
- Assert.assertNotNull(testCtx);
- testCtx.registerModelObject(MockFactory.createModule(Scope.MODULE,Scope.SESSION));
- testCtx.fireEvent(EventContext.MODULE_START,null);
-
- // first session
- Object session = new Object();
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- testCtx.fireEvent(EventContext.SESSION_NOTIFY,session);
- GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source);
- GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null);
- Assert.assertNotNull(target);
- source.getGenericComponent().setString("foo");
- Assert.assertEquals("foo",target.getString());
- testCtx.fireEvent(EventContext.REQUEST_END,session);
-
- //second session
- Object session2 = new Object();
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- testCtx.fireEvent(EventContext.SESSION_NOTIFY,session2);
- GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null);
- Assert.assertNotNull(target2);
- Assert.assertTrue(!"foo".equals(target2.getString()));
-
- Assert.assertTrue(!"foo".equals(source.getGenericComponent().getString()));
- source.getGenericComponent().setString("bar");
- Assert.assertEquals("bar",target2.getString());
- Assert.assertEquals("bar",source.getGenericComponent().getString());
- //testCtx.fireEvent(EventContext.SESSION_NOTIFY,session);
-
- }
-
- /**
- * Tests a module-to-request scoped wire is setup properly by the runtime
- */
- public void testModuleToRequest() throws Exception{
- RuntimeContext runtime = MockFactory.createJavaRuntime();
- InstanceContext ctx = runtime.getSystemContext().getContext("tuscany.system.child");
- Assert.assertNotNull(ctx);
- runtime.getRootContext().registerModelObject(MockFactory.createAggregateComponent("test"));
- AggregateContext testCtx = (AggregateContext) runtime.getRootContext().getContext("test");
- Assert.assertNotNull(testCtx);
- testCtx.registerModelObject(MockFactory.createModule(Scope.MODULE,Scope.REQUEST));
- testCtx.fireEvent(EventContext.MODULE_START,null);
-
- // first request
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source);
- GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null);
- Assert.assertNotNull(target);
- source.getGenericComponent().setString("foo");
- Assert.assertEquals("foo",target.getString());
- testCtx.fireEvent(EventContext.REQUEST_END,null);
-
- //second request
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null);
- Assert.assertNotNull(target2);
- Assert.assertTrue(!"foo".equals(target2.getString()));
-
- Assert.assertTrue(!"foo".equals(source.getGenericComponent().getString()));
- source.getGenericComponent().setString("bar");
- Assert.assertEquals("bar",target2.getString());
- Assert.assertEquals("bar",source.getGenericComponent().getString());
-
- }
-
- /**
- * Tests a module-to-stateless scoped wire is setup properly by the runtime
- */
- public void testModuleToStateless() throws Exception{
- RuntimeContext runtime = MockFactory.createJavaRuntime();
- InstanceContext ctx = runtime.getSystemContext().getContext("tuscany.system.child");
- Assert.assertNotNull(ctx);
- runtime.getRootContext().registerModelObject(MockFactory.createAggregateComponent("test"));
- AggregateContext testCtx = (AggregateContext) runtime.getRootContext().getContext("test");
- Assert.assertNotNull(testCtx);
- testCtx.registerModelObject(MockFactory.createModule(Scope.MODULE,Scope.INSTANCE));
- testCtx.fireEvent(EventContext.MODULE_START,null);
-
- // first request
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source);
- GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null);
- Assert.assertNotNull(target);
- source.getGenericComponent().setString("foo");
- Assert.assertTrue(!"foo".equals(target.getString()));
- testCtx.fireEvent(EventContext.REQUEST_END,null);
-
- //second request
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null);
- Assert.assertNotNull(target2);
- Assert.assertTrue(!"foo".equals(target2.getString()));
-
- Assert.assertTrue(!"foo".equals(source.getGenericComponent().getString()));
- source.getGenericComponent().setString("bar");
- Assert.assertTrue(!"bar".equals(target2.getString()));
- }
-
- /**
- * Tests a session-to-session scoped wire is setup properly by the runtime
- */
- public void testSessionToSession() throws Exception{
- RuntimeContext runtime = MockFactory.createJavaRuntime();
- InstanceContext ctx = runtime.getSystemContext().getContext("tuscany.system.child");
- Assert.assertNotNull(ctx);
- runtime.getRootContext().registerModelObject(MockFactory.createAggregateComponent("test"));
- AggregateContext testCtx = (AggregateContext) runtime.getRootContext().getContext("test");
- Assert.assertNotNull(testCtx);
- testCtx.registerModelObject(MockFactory.createModule(Scope.SESSION,Scope.SESSION));
- testCtx.fireEvent(EventContext.MODULE_START,null);
-
- // first session
- Object session = new Object();
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- testCtx.fireEvent(EventContext.SESSION_NOTIFY,session);
- GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source);
- GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null);
- Assert.assertNotNull(target);
- source.getGenericComponent().setString("foo");
- source.getGenericComponent().setString("foo");
- Assert.assertEquals("foo",target.getString());
- testCtx.fireEvent(EventContext.REQUEST_END,session);
-
- //second session
- Object session2 = new Object();
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- testCtx.fireEvent(EventContext.SESSION_NOTIFY,session2);
- GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source2);
- GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null);
-
- Assert.assertNotNull(target2);
- Assert.assertEquals(null,target2.getString());
- Assert.assertEquals(null,source2.getGenericComponent().getString());
- source2.getGenericComponent().setString("baz");
- Assert.assertEquals("baz",source2.getGenericComponent().getString());
- Assert.assertEquals("baz",target2.getString());
-
- testCtx.fireEvent(EventContext.REQUEST_END,session2);
-
- }
-
-
- /**
- * Tests a session-to-module scoped wire is setup properly by the runtime
- */
- public void testSessionToModule() throws Exception{
- RuntimeContext runtime = MockFactory.createJavaRuntime();
- InstanceContext ctx = runtime.getSystemContext().getContext("tuscany.system.child");
- Assert.assertNotNull(ctx);
- runtime.getRootContext().registerModelObject(MockFactory.createAggregateComponent("test"));
- AggregateContext testCtx = (AggregateContext) runtime.getRootContext().getContext("test");
- Assert.assertNotNull(testCtx);
- testCtx.registerModelObject(MockFactory.createModule(Scope.SESSION,Scope.MODULE));
- testCtx.fireEvent(EventContext.MODULE_START,null);
-
- // first session
- Object session = new Object();
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- testCtx.fireEvent(EventContext.SESSION_NOTIFY,session);
- GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source);
- GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null);
- Assert.assertNotNull(target);
- source.getGenericComponent().setString("foo");
- source.getGenericComponent().setString("foo");
- Assert.assertEquals("foo",target.getString());
- testCtx.fireEvent(EventContext.REQUEST_END,session);
-
- //second session
- Object session2 = new Object();
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- testCtx.fireEvent(EventContext.SESSION_NOTIFY,session2);
- GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source2);
- GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null);
-
- Assert.assertNotNull(target2);
- Assert.assertEquals("foo",target2.getString());
- Assert.assertEquals("foo",source2.getGenericComponent().getString());
- source2.getGenericComponent().setString("baz");
- Assert.assertEquals("baz",source2.getGenericComponent().getString());
- Assert.assertEquals("baz",target2.getString());
- Assert.assertEquals("baz",target.getString());
-
- testCtx.fireEvent(EventContext.REQUEST_END,session2);
-
- }
-
- /**
- * Tests a session-to-request scoped wire is setup properly by the runtime
- */
- public void testSessionToRequest() throws Exception{
- RuntimeContext runtime = MockFactory.createJavaRuntime();
- InstanceContext ctx = runtime.getSystemContext().getContext("tuscany.system.child");
- Assert.assertNotNull(ctx);
- runtime.getRootContext().registerModelObject(MockFactory.createAggregateComponent("test"));
- AggregateContext testCtx = (AggregateContext) runtime.getRootContext().getContext("test");
- Assert.assertNotNull(testCtx);
- testCtx.registerModelObject(MockFactory.createModule(Scope.SESSION,Scope.REQUEST));
- testCtx.fireEvent(EventContext.MODULE_START,null);
-
- // first session
- Object session = new Object();
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- testCtx.fireEvent(EventContext.SESSION_NOTIFY,session);
- GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source);
- GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null);
- Assert.assertNotNull(target);
- source.getGenericComponent().setString("foo");
- Assert.assertEquals("foo",target.getString());
- testCtx.fireEvent(EventContext.REQUEST_END,session);
-
- //second session
- Object session2 = new Object();
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- testCtx.fireEvent(EventContext.SESSION_NOTIFY,session2);
- GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source);
- GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null);
-
- Assert.assertNotNull(target2);
- Assert.assertEquals(null,target2.getString());
- source2.getGenericComponent().setString("baz");
- Assert.assertEquals("baz",target2.getString());
- Assert.assertEquals("baz",source2.getGenericComponent().getString());
-
- Assert.assertEquals("foo",target.getString());
- testCtx.fireEvent(EventContext.REQUEST_END,session);
-
- }
-
-
- /**
- * Tests a session-to-stateless scoped wire is setup properly by the runtime
- */
- public void testSessionToStateless() throws Exception{
- RuntimeContext runtime = MockFactory.createJavaRuntime();
- InstanceContext ctx = runtime.getSystemContext().getContext("tuscany.system.child");
- Assert.assertNotNull(ctx);
- runtime.getRootContext().registerModelObject(MockFactory.createAggregateComponent("test"));
- AggregateContext testCtx = (AggregateContext) runtime.getRootContext().getContext("test");
- Assert.assertNotNull(testCtx);
- testCtx.registerModelObject(MockFactory.createModule(Scope.SESSION,Scope.INSTANCE));
- testCtx.fireEvent(EventContext.MODULE_START,null);
-
- // first session
- Object session = new Object();
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- testCtx.fireEvent(EventContext.SESSION_NOTIFY,session);
- GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source);
- GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null);
- Assert.assertNotNull(target);
- source.getGenericComponent().setString("foo");
- Assert.assertEquals(null,target.getString());
- testCtx.fireEvent(EventContext.REQUEST_END,session);
-
- //second session
- Object session2 = new Object();
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- testCtx.fireEvent(EventContext.SESSION_NOTIFY,session2);
- GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source);
- GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null);
-
- Assert.assertNotNull(target2);
- Assert.assertEquals(null,target2.getString());
- source2.getGenericComponent().setString("baz");
- Assert.assertEquals(null,target2.getString()); //Note assumes no pooling
- Assert.assertEquals(null,source2.getGenericComponent().getString());
-
- Assert.assertEquals(null,target.getString()); //Note assumes no pooling
- testCtx.fireEvent(EventContext.REQUEST_END,session);
-
- }
-
- /**
- * Tests a request-to-request scoped wire is setup properly by the runtime
- */
- public void testRequestToRequest() throws Exception{
- RuntimeContext runtime = MockFactory.createJavaRuntime();
- InstanceContext ctx = runtime.getSystemContext().getContext("tuscany.system.child");
- Assert.assertNotNull(ctx);
- runtime.getRootContext().registerModelObject(MockFactory.createAggregateComponent("test"));
- AggregateContext testCtx = (AggregateContext) runtime.getRootContext().getContext("test");
- Assert.assertNotNull(testCtx);
- testCtx.registerModelObject(MockFactory.createModule(Scope.REQUEST,Scope.REQUEST));
- testCtx.fireEvent(EventContext.MODULE_START,null);
-
- // first request
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source);
- GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null);
- Assert.assertNotNull(target);
- source.getGenericComponent().setString("foo");
- Assert.assertEquals("foo",target.getString());
- testCtx.fireEvent(EventContext.REQUEST_END,null);
-
- //second request
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source2);
- GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null);
-
- Assert.assertNotNull(target2);
- Assert.assertEquals(null,target2.getString());
- Assert.assertEquals(null,source2.getGenericComponent().getString());
- source2.getGenericComponent().setString("baz");
- Assert.assertEquals("baz",source2.getGenericComponent().getString());
- Assert.assertEquals("baz",target2.getString());
-
- testCtx.fireEvent(EventContext.REQUEST_END,null);
-
- }
-
- /**
- * Tests a request-to-module scoped wire is setup properly by the runtime
- */
- public void testRequestToModule() throws Exception{
- RuntimeContext runtime = MockFactory.createJavaRuntime();
- InstanceContext ctx = runtime.getSystemContext().getContext("tuscany.system.child");
- Assert.assertNotNull(ctx);
- runtime.getRootContext().registerModelObject(MockFactory.createAggregateComponent("test"));
- AggregateContext testCtx = (AggregateContext) runtime.getRootContext().getContext("test");
- Assert.assertNotNull(testCtx);
- testCtx.registerModelObject(MockFactory.createModule(Scope.REQUEST,Scope.MODULE));
- testCtx.fireEvent(EventContext.MODULE_START,null);
-
- // first request
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source);
- GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null);
- Assert.assertNotNull(target);
- source.getGenericComponent().setString("foo");
- Assert.assertEquals("foo",target.getString());
- testCtx.fireEvent(EventContext.REQUEST_END,null);
-
- //second request
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source2);
- GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null);
-
- Assert.assertNotNull(target2);
- Assert.assertEquals("foo",target2.getString());
- Assert.assertEquals("foo",source2.getGenericComponent().getString());
- source2.getGenericComponent().setString("baz");
- Assert.assertEquals("baz",source2.getGenericComponent().getString());
- Assert.assertEquals("baz",target2.getString());
- Assert.assertEquals("baz",target.getString());
-
- testCtx.fireEvent(EventContext.REQUEST_END,null);
-
- }
-
- /**
- * Tests a request-to-session scoped wire is setup properly by the runtime
- */
- public void testRequestToSession() throws Exception{
- RuntimeContext runtime = MockFactory.createJavaRuntime();
- InstanceContext ctx = runtime.getSystemContext().getContext("tuscany.system.child");
- Assert.assertNotNull(ctx);
- runtime.getRootContext().registerModelObject(MockFactory.createAggregateComponent("test"));
- AggregateContext testCtx = (AggregateContext) runtime.getRootContext().getContext("test");
- Assert.assertNotNull(testCtx);
- testCtx.registerModelObject(MockFactory.createModule(Scope.REQUEST,Scope.SESSION));
- testCtx.fireEvent(EventContext.MODULE_START,null);
-
- // first session
- Object session = new Object();
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- testCtx.fireEvent(EventContext.SESSION_NOTIFY,session);
- GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source);
- GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null);
- Assert.assertNotNull(target);
- source.getGenericComponent().setString("foo");
- Assert.assertEquals("foo",target.getString());
- testCtx.fireEvent(EventContext.REQUEST_END,session);
-
- //second request for session
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- testCtx.fireEvent(EventContext.SESSION_NOTIFY,session);
- GenericComponent targetR2 = (GenericComponent)testCtx.getContext("target").getInstance(null);
- Assert.assertEquals("foo",targetR2.getString());
- GenericComponent sourceR2 = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(sourceR2);
- Assert.assertEquals("foo",sourceR2.getGenericComponent().getString());
-
- testCtx.fireEvent(EventContext.REQUEST_END,session);
-
- //second session
- Object session2 = new Object();
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- testCtx.fireEvent(EventContext.SESSION_NOTIFY,session2);
- GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source2);
- GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null);
-
- Assert.assertNotNull(target2);
- Assert.assertEquals(null,target2.getString());
- Assert.assertEquals(null,source2.getGenericComponent().getString());
- source2.getGenericComponent().setString("baz");
- Assert.assertEquals("baz",source2.getGenericComponent().getString());
- Assert.assertEquals("baz",target2.getString());
-
- testCtx.fireEvent(EventContext.REQUEST_END,session2);
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- testCtx.fireEvent(EventContext.SESSION_NOTIFY,session);
- testCtx.fireEvent(EventContext.REQUEST_END,session);
-
- }
-
-
- /**
- * Tests a request-to-stateless scoped wire is setup properly by the runtime
- */
- public void testRequestToStateless() throws Exception{
- RuntimeContext runtime = MockFactory.createJavaRuntime();
- InstanceContext ctx = runtime.getSystemContext().getContext("tuscany.system.child");
- Assert.assertNotNull(ctx);
- runtime.getRootContext().registerModelObject(MockFactory.createAggregateComponent("test"));
- AggregateContext testCtx = (AggregateContext) runtime.getRootContext().getContext("test");
- Assert.assertNotNull(testCtx);
- testCtx.registerModelObject(MockFactory.createModule(Scope.REQUEST,Scope.INSTANCE));
- testCtx.fireEvent(EventContext.MODULE_START,null);
-
- // first request
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source);
- GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null);
- Assert.assertNotNull(target);
- source.getGenericComponent().setString("foo");
- Assert.assertEquals(null,target.getString());
- testCtx.fireEvent(EventContext.REQUEST_END,null);
-
- //second request
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source2);
- GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null);
-
- Assert.assertNotNull(target2);
- Assert.assertEquals(null,target2.getString());
- Assert.assertEquals(null,source2.getGenericComponent().getString());
- source2.getGenericComponent().setString("baz");
- Assert.assertEquals(null,source2.getGenericComponent().getString());
- Assert.assertEquals(null,target2.getString());
-
- testCtx.fireEvent(EventContext.REQUEST_END,null);
-
- }
-
-
- /**
- * Tests a stateless-to-stateless scoped wire is setup properly by the runtime
- */
- public void testStatelessToStateless() throws Exception{
- RuntimeContext runtime = MockFactory.createJavaRuntime();
- InstanceContext ctx = runtime.getSystemContext().getContext("tuscany.system.child");
- Assert.assertNotNull(ctx);
- runtime.getRootContext().registerModelObject(MockFactory.createAggregateComponent("test"));
- AggregateContext testCtx = (AggregateContext) runtime.getRootContext().getContext("test");
- Assert.assertNotNull(testCtx);
- testCtx.registerModelObject(MockFactory.createModule(Scope.INSTANCE,Scope.INSTANCE));
- testCtx.fireEvent(EventContext.MODULE_START,null);
-
- // first request
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source);
- GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null);
- Assert.assertNotNull(target);
- source.getGenericComponent().setString("foo");
- Assert.assertEquals(null,target.getString());
- testCtx.fireEvent(EventContext.REQUEST_END,null);
-
- //second request
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source2);
- GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null);
-
- Assert.assertNotNull(target2);
- Assert.assertEquals(null,target2.getString());
- Assert.assertEquals(null,source2.getGenericComponent().getString());
- source2.getGenericComponent().setString("baz");
- Assert.assertEquals(null,source2.getGenericComponent().getString());
- Assert.assertEquals(null,target2.getString());
-
- testCtx.fireEvent(EventContext.REQUEST_END,null);
-
- }
-
- /**
- * Tests a stateless-to-request scoped wire is setup properly by the runtime
- */
- public void testStatelessToRequest() throws Exception{
- RuntimeContext runtime = MockFactory.createJavaRuntime();
- InstanceContext ctx = runtime.getSystemContext().getContext("tuscany.system.child");
- Assert.assertNotNull(ctx);
- runtime.getRootContext().registerModelObject(MockFactory.createAggregateComponent("test"));
- AggregateContext testCtx = (AggregateContext) runtime.getRootContext().getContext("test");
- Assert.assertNotNull(testCtx);
- testCtx.registerModelObject(MockFactory.createModule(Scope.INSTANCE,Scope.REQUEST));
- testCtx.fireEvent(EventContext.MODULE_START,null);
-
- // first request
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source);
- GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null);
- Assert.assertNotNull(target);
- source.getGenericComponent().setString("foo");
- Assert.assertEquals("foo",target.getString());
- testCtx.fireEvent(EventContext.REQUEST_END,null);
-
- GenericComponent targetR1 = (GenericComponent)testCtx.getContext("target").getInstance(null);
- Assert.assertNotNull(targetR1);
- Assert.assertEquals("foo",target.getString());
-
- //second request
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source2);
- GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null);
-
- Assert.assertNotNull(target2);
- Assert.assertEquals(null,target2.getString());
- Assert.assertEquals(null,source2.getGenericComponent().getString());
- source2.getGenericComponent().setString("baz");
- Assert.assertEquals("baz",source2.getGenericComponent().getString());
- Assert.assertEquals("baz",target2.getString());
-
- testCtx.fireEvent(EventContext.REQUEST_END,null);
-
- }
-
- /**
- * Tests a stateless-to-session scoped wire is setup properly by the runtime
- */
- public void testStatelessToSession() throws Exception{
- RuntimeContext runtime = MockFactory.createJavaRuntime();
- InstanceContext ctx = runtime.getSystemContext().getContext("tuscany.system.child");
- Assert.assertNotNull(ctx);
- runtime.getRootContext().registerModelObject(MockFactory.createAggregateComponent("test"));
- AggregateContext testCtx = (AggregateContext) runtime.getRootContext().getContext("test");
- Assert.assertNotNull(testCtx);
- testCtx.registerModelObject(MockFactory.createModule(Scope.INSTANCE,Scope.SESSION));
- testCtx.fireEvent(EventContext.MODULE_START,null);
-
- // first session
- Object session = new Object();
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- testCtx.fireEvent(EventContext.SESSION_NOTIFY,session);
- GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source);
- GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null);
- Assert.assertNotNull(target);
- source.getGenericComponent().setString("foo");
- Assert.assertEquals("foo",target.getString());
- testCtx.fireEvent(EventContext.REQUEST_END,session);
-
- //second request for session
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- testCtx.fireEvent(EventContext.SESSION_NOTIFY,session);
- GenericComponent targetR2 = (GenericComponent)testCtx.getContext("target").getInstance(null);
- Assert.assertEquals("foo",targetR2.getString());
- GenericComponent sourceR2 = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(sourceR2);
- Assert.assertEquals("foo",sourceR2.getGenericComponent().getString());
-
- testCtx.fireEvent(EventContext.REQUEST_END,session);
-
- //second session
- Object session2 = new Object();
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- testCtx.fireEvent(EventContext.SESSION_NOTIFY,session2);
- GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source2);
- GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null);
-
- Assert.assertNotNull(target2);
- Assert.assertEquals(null,target2.getString());
- Assert.assertEquals(null,source2.getGenericComponent().getString());
- source2.getGenericComponent().setString("baz");
- Assert.assertEquals("baz",source2.getGenericComponent().getString());
- Assert.assertEquals("baz",target2.getString());
-
- testCtx.fireEvent(EventContext.REQUEST_END,session2);
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- testCtx.fireEvent(EventContext.SESSION_NOTIFY,session);
- testCtx.fireEvent(EventContext.REQUEST_END,session);
-
- }
-
-
- /**
- * Tests a stateless-to-module scoped wire is setup properly by the runtime
- */
- public void testStatelessToModule() throws Exception{
- RuntimeContext runtime = MockFactory.createJavaRuntime();
- InstanceContext ctx = runtime.getSystemContext().getContext("tuscany.system.child");
- Assert.assertNotNull(ctx);
- runtime.getRootContext().registerModelObject(MockFactory.createAggregateComponent("test"));
- AggregateContext testCtx = (AggregateContext) runtime.getRootContext().getContext("test");
- Assert.assertNotNull(testCtx);
- testCtx.registerModelObject(MockFactory.createModule(Scope.INSTANCE,Scope.MODULE));
- testCtx.fireEvent(EventContext.MODULE_START,null);
-
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- GenericComponent source = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source);
- GenericComponent target = (GenericComponent)testCtx.getContext("target").getInstance(null);
- Assert.assertNotNull(target);
- source.getGenericComponent().setString("foo");
- Assert.assertEquals("foo",target.getString());
- testCtx.fireEvent(EventContext.REQUEST_END,null);
-
- //second session
- testCtx.fireEvent(EventContext.REQUEST_START,null);
- GenericComponent source2 = (GenericComponent)testCtx.getContext("source").getInstance(null);
- Assert.assertNotNull(source2);
- GenericComponent target2 = (GenericComponent)testCtx.getContext("target").getInstance(null);
-
- Assert.assertNotNull(target2);
- Assert.assertEquals("foo",target2.getString());
- Assert.assertEquals("foo",source2.getGenericComponent().getString());
- source2.getGenericComponent().setString("baz");
- Assert.assertEquals("baz",source2.getGenericComponent().getString());
- Assert.assertEquals("baz",target2.getString());
-
- testCtx.fireEvent(EventContext.REQUEST_END,null);
-
- }
-
-}
-