diff options
Diffstat (limited to 'tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes')
11 files changed, 0 insertions, 1473 deletions
diff --git a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/AggregateScopeTestCase.java b/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/AggregateScopeTestCase.java deleted file mode 100644 index 77130f6334..0000000000 --- a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/AggregateScopeTestCase.java +++ /dev/null @@ -1,178 +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.scopes; - -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.mock.MockFactory; -import org.apache.tuscany.container.java.mock.components.GenericComponent; -import org.apache.tuscany.container.java.mock.components.ModuleScopeComponentImpl; -import org.apache.tuscany.container.java.mock.components.SessionScopeComponentImpl; -import org.apache.tuscany.core.builder.BuilderException; -import org.apache.tuscany.core.context.AggregateContext; -import org.apache.tuscany.core.context.EventContext; -import org.apache.tuscany.core.context.QualifiedName; -import org.apache.tuscany.core.context.impl.AggregateContextImpl; -import org.apache.tuscany.core.context.impl.EventContextImpl; -import org.apache.tuscany.core.context.scope.AggregateScopeContext; -import org.apache.tuscany.model.assembly.Extensible; -import org.apache.tuscany.model.assembly.Scope; -import org.apache.tuscany.model.assembly.SimpleComponent; - -/** - * Tests component nesting. This test need to be in the container.java progject since it relies on Java POJOs for scope - * testing. - * - * @version $Rev$ $Date$ - */ -public class AggregateScopeTestCase extends TestCase { - - /** - * Ensures scope events are propagated in an aggregate scope - */ - public void testAggregateScopePropagation() throws Exception { - EventContext ctx = new EventContextImpl(); - AggregateContext moduleComponentCtx = new AggregateContextImpl(); - moduleComponentCtx.setName("testMC"); - AggregateScopeContext scopeContainer = new AggregateScopeContext(ctx); - scopeContainer.registerConfiguration(MockFactory.createAggregateConfiguration("AggregateComponent", moduleComponentCtx)); - scopeContainer.start(); - AggregateContext child = (AggregateContext) scopeContainer.getContext("AggregateComponent"); - List<Extensible> models = createAssembly(moduleComponentCtx); - for (Extensible model : models) { - child.registerModelObject(model); - } - - scopeContainer.onEvent(EventContext.MODULE_START, null); - Object session = new Object(); - scopeContainer.onEvent(EventContext.REQUEST_START, null); - scopeContainer.onEvent(EventContext.SESSION_NOTIFY, session); - AggregateContext componentCtx = (AggregateContext) scopeContainer.getContext("AggregateComponent"); - GenericComponent testService1 = (GenericComponent) componentCtx.locateInstance("TestService1"); - GenericComponent testService2 = (GenericComponent) componentCtx.locateInstance("TestService2"); - GenericComponent testService3 = (GenericComponent) componentCtx.locateInstance("TestService3"); - Assert.assertNotNull(testService1); - Assert.assertNotNull(testService2); - Assert.assertNotNull(testService3); - scopeContainer.onEvent(EventContext.REQUEST_END, null); - scopeContainer.onEvent(EventContext.REQUEST_START, null); - scopeContainer.onEvent(EventContext.SESSION_NOTIFY, session); - - GenericComponent testService2a = (GenericComponent) componentCtx.locateInstance("TestService2"); - Assert.assertNotNull(testService2a); - GenericComponent testService3a = (GenericComponent) componentCtx.locateInstance("TestService3"); - Assert.assertNotNull(testService3a); - Assert.assertEquals(testService2, testService2a); - Assert.assertNotSame(testService3, testService3a); - scopeContainer.onEvent(EventContext.REQUEST_END, null); - scopeContainer.onEvent(EventContext.SESSION_END, session); - - Object session2 = new Object(); - scopeContainer.onEvent(EventContext.REQUEST_START, null); - scopeContainer.onEvent(EventContext.SESSION_NOTIFY, session2); - GenericComponent testService2b = (GenericComponent) componentCtx.locateInstance("TestService2"); - Assert.assertNotNull(testService2b); - Assert.assertNotSame(testService2, testService2b); - - scopeContainer.onEvent(EventContext.REQUEST_END, null); - scopeContainer.onEvent(EventContext.SESSION_END, session2); - - } - - /** - * Ensures only child entry points (and not components) are accessible from parents - */ - public void testAggregateNoEntryPoint() throws Exception { - EventContext ctx = new EventContextImpl(); - AggregateContext moduleComponentCtx = new AggregateContextImpl(); - moduleComponentCtx.setName("testMC"); - AggregateScopeContext scopeContainer = new AggregateScopeContext(ctx); - scopeContainer.registerConfiguration(MockFactory.createAggregateConfiguration("AggregateComponent", moduleComponentCtx)); - scopeContainer.start(); - AggregateContext child = (AggregateContext) scopeContainer.getContext("AggregateComponent"); - List<Extensible> parts = createAssembly(moduleComponentCtx); - for (Extensible part : parts) { - child.registerModelObject(part); - } - - // aggregate.onEvent(EventContext.SYSTEM_START, null); - scopeContainer.onEvent(EventContext.MODULE_START, null); - QualifiedName name = new QualifiedName("AggregateComponent/TestService1"); - AggregateContext componentCtx = (AggregateContext) scopeContainer.getContext("AggregateComponent"); - } - - /** - * Tests adding a context before its parent has been started - */ - public void testRegisterContextBeforeStart() throws Exception { - EventContext ctx = new EventContextImpl(); - AggregateContext moduleComponentCtx = new AggregateContextImpl(); - moduleComponentCtx.setName("testMC"); - AggregateScopeContext scopeContainer = new AggregateScopeContext(ctx); - scopeContainer.registerConfiguration(MockFactory.createAggregateConfiguration("AggregateComponent", moduleComponentCtx)); - scopeContainer.start(); - scopeContainer.onEvent(EventContext.MODULE_START, null); - QualifiedName name = new QualifiedName("AggregateComponent/TestService1"); - AggregateContext componentCtx = (AggregateContext) scopeContainer.getContext("AggregateComponent"); - scopeContainer.onEvent(EventContext.MODULE_STOP, null); - scopeContainer.stop(); - } - - /** - * Tests adding a context after its parent has been started - */ - public void testRegisterContextAfterStart() throws Exception { - EventContext ctx = new EventContextImpl(); - AggregateContext moduleComponentCtx = new AggregateContextImpl(); - moduleComponentCtx.setName("testMC"); - AggregateScopeContext scopeContainer = new AggregateScopeContext(ctx); - scopeContainer.start(); - - scopeContainer.onEvent(EventContext.MODULE_START, null); - scopeContainer.registerConfiguration(MockFactory.createAggregateConfiguration("AggregateComponent", moduleComponentCtx)); - QualifiedName name = new QualifiedName("AggregateComponent/TestService1"); - AggregateContext componentCtx = (AggregateContext) scopeContainer.getContext("AggregateComponent"); - scopeContainer.onEvent(EventContext.MODULE_STOP, null); - scopeContainer.stop(); - } - - /** - * Creats an assembly containing a module-scoped component definition, a session-scoped component definition, and a - * request-scoped component definition - * - * @param ctx the parent module context - */ - private List<Extensible> createAssembly(AggregateContext ctx) throws BuilderException { - JavaComponentContextBuilder builder = new JavaComponentContextBuilder(); - SimpleComponent component = MockFactory.createComponent("TestService1", ModuleScopeComponentImpl.class, Scope.MODULE); - SimpleComponent sessionComponent = MockFactory.createComponent("TestService2", SessionScopeComponentImpl.class, - Scope.SESSION); - SimpleComponent requestComponent = MockFactory.createComponent("TestService3", SessionScopeComponentImpl.class, - Scope.REQUEST); - builder.build(component, ctx); - builder.build(sessionComponent, ctx); - builder.build(requestComponent, ctx); - List<Extensible> configs = new ArrayList(); - configs.add(component); - configs.add(sessionComponent); - configs.add(requestComponent); - return configs; - } - -} diff --git a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicHttpSessionScopeTestCase.java b/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicHttpSessionScopeTestCase.java deleted file mode 100644 index a56589c4d1..0000000000 --- a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicHttpSessionScopeTestCase.java +++ /dev/null @@ -1,223 +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.scopes; - -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.mock.MockFactory; -import org.apache.tuscany.container.java.mock.components.SessionScopeComponent; -import org.apache.tuscany.container.java.mock.components.SessionScopeComponentImpl; -import org.apache.tuscany.container.java.mock.components.SessionScopeInitDestroyComponent; -import org.apache.tuscany.core.builder.BuilderException; -import org.apache.tuscany.core.builder.RuntimeConfiguration; -import org.apache.tuscany.core.context.EventContext; -import org.apache.tuscany.core.context.InstanceContext; -import org.apache.tuscany.core.context.impl.EventContextImpl; -import org.apache.tuscany.core.context.scope.HttpSessionScopeContext; -import org.apache.tuscany.model.assembly.Scope; -import org.apache.tuscany.model.assembly.SimpleComponent; - -/** - * Unit tests for the Http session scope container - * - * @version $Rev$ $Date$ - */ -public class BasicHttpSessionScopeTestCase extends TestCase { - - /** - * Tests instance identity is properly maintained - */ - public void testInstanceManagement() throws Exception { - EventContext ctx = new EventContextImpl(); - HttpSessionScopeContext scope = new HttpSessionScopeContext(ctx); - scope.registerConfigurations(createConfigurations()); - scope.start(); - Object session = new Object(); - Object session2 = new Object(); - // first request - ctx.setIdentifier(EventContext.HTTP_SESSION, session); - SessionScopeComponent comp1 = (SessionScopeComponent) scope.getContext("TestService1").getInstance(null); - Assert.assertNotNull(comp1); - ctx.clearIdentifier(EventContext.HTTP_SESSION); - - // second request - ctx.setIdentifier(EventContext.HTTP_SESSION, session); - SessionScopeComponent comp2 = (SessionScopeComponent) scope.getContext("TestService1").getInstance(null); - Assert.assertNotNull(comp2); - Assert.assertSame(comp1, comp2); - ctx.clearIdentifier(EventContext.HTTP_SESSION); - - // third request, different session - ctx.setIdentifier(EventContext.HTTP_SESSION, session2); - SessionScopeComponent comp3 = (SessionScopeComponent) scope.getContext("TestService1").getInstance(null); - Assert.assertNotNull(comp3); - Assert.assertNotSame(comp1, comp3); // should be different instances - ctx.clearIdentifier(EventContext.HTTP_SESSION); - - scope.onEvent(EventContext.SESSION_END, session); - scope.onEvent(EventContext.SESSION_END, session2); - - scope.stop(); - } - - /** - * Tests setting no components in the scope - */ - public void testSetNullComponents() throws Exception { - EventContext ctx = new EventContextImpl(); - HttpSessionScopeContext scope = new HttpSessionScopeContext(ctx); - scope.registerConfigurations(new ArrayList<RuntimeConfiguration<InstanceContext>>()); - scope.start(); - scope.stop(); - } - - public void testGetContextByKey() throws Exception { - EventContext ctx = new EventContextImpl(); - HttpSessionScopeContext scope = new HttpSessionScopeContext(ctx); - scope.registerConfigurations(createConfigurations()); - scope.start(); - Object session = new Object(); - Object session2 = new Object(); - - // first request - ctx.setIdentifier(EventContext.HTTP_SESSION, session); - SessionScopeComponent comp1 = (SessionScopeComponent) scope.getContext("TestService1").getInstance(null); - Assert.assertNotNull(comp1); - ctx.clearIdentifier(EventContext.HTTP_SESSION); - - // second request, different session - ctx.setIdentifier(EventContext.HTTP_SESSION, session2); - SessionScopeComponent comp2 = (SessionScopeComponent) scope.getContextByKey("TestService1", session) - .getInstance(null); - SessionScopeComponent comp3 = (SessionScopeComponent) scope.getContextByKey("TestService1", session) - .getInstance(null); - Assert.assertNotNull(comp2); - scope.onEvent(EventContext.REQUEST_END, session2); - Assert.assertSame(comp1, comp2); // should be same instances - Assert.assertSame(comp2, comp3); // should not be same instances - ctx.clearIdentifier(EventContext.HTTP_SESSION); - - // shutdown sessions - scope.onEvent(EventContext.SESSION_END, session); - scope.onEvent(EventContext.SESSION_END, session2); - - scope.stop(); - } - - public void testRegisterContextBeforeSession() throws Exception { - EventContext ctx = new EventContextImpl(); - HttpSessionScopeContext scope = new HttpSessionScopeContext(ctx); - scope.registerConfigurations(createConfigurations()); - scope.start(); - Object session = new Object(); - scope.registerConfiguration(createConfiguration("NewTestService")); - - // first request - ctx.setIdentifier(EventContext.HTTP_SESSION, session); - - SessionScopeInitDestroyComponent comp2 = (SessionScopeInitDestroyComponent) scope.getContext("NewTestService") - .getInstance(null); - Assert.assertNotNull(comp2); - Assert.assertTrue(comp2.isInitialized()); - ctx.clearIdentifier(EventContext.HTTP_SESSION); - - // second request different session - Object session2 = new Object(); - ctx.setIdentifier(EventContext.HTTP_SESSION, session2); - SessionScopeInitDestroyComponent comp3 = (SessionScopeInitDestroyComponent) scope.getContext("NewTestService") - .getInstance(null); - Assert.assertNotNull(comp3); - Assert.assertNotSame(comp2, comp3); - Assert.assertTrue(comp3.isInitialized()); - ctx.clearIdentifier(EventContext.HTTP_SESSION); - - scope.onEvent(EventContext.SESSION_END, session); - Assert.assertTrue(comp2.isDestroyed()); - - scope.onEvent(EventContext.SESSION_END, session2); - Assert.assertTrue(comp3.isDestroyed()); - scope.stop(); - } - - /** - * Tests runtime context registration - */ - public void testRegisterContextAfterSession() throws Exception { - EventContext ctx = new EventContextImpl(); - HttpSessionScopeContext scope = new HttpSessionScopeContext(ctx); - scope.registerConfigurations(createConfigurations()); - scope.start(); - Object session = new Object(); - - // first request - ctx.setIdentifier(EventContext.HTTP_SESSION, session); - SessionScopeComponent comp1 = (SessionScopeComponent) scope.getContext("TestService1").getInstance(null); - Assert.assertNotNull(comp1); - ctx.clearIdentifier(EventContext.HTTP_SESSION); - - scope.registerConfiguration(createConfiguration("NewTestService")); - - // second request - ctx.setIdentifier(EventContext.HTTP_SESSION, session); - SessionScopeInitDestroyComponent comp2 = (SessionScopeInitDestroyComponent) scope.getContext("NewTestService") - .getInstance(null); - Assert.assertNotNull(comp2); - Assert.assertTrue(comp2.isInitialized()); - ctx.clearIdentifier(EventContext.HTTP_SESSION); - - // third request different session - Object session2 = new Object(); - ctx.setIdentifier(EventContext.HTTP_SESSION, session2); - SessionScopeInitDestroyComponent comp3 = (SessionScopeInitDestroyComponent) scope.getContext("NewTestService") - .getInstance(null); - Assert.assertNotNull(comp3); - Assert.assertNotSame(comp2, comp3); - Assert.assertTrue(comp3.isInitialized()); - ctx.clearIdentifier(EventContext.HTTP_SESSION); - - scope.onEvent(EventContext.SESSION_END, session); - Assert.assertTrue(comp2.isDestroyed()); - - scope.onEvent(EventContext.SESSION_END, session2); - Assert.assertTrue(comp3.isDestroyed()); - scope.stop(); - } - - // ---------------------------------- - // Private methods - // ---------------------------------- - JavaComponentContextBuilder builder = new JavaComponentContextBuilder(); - - private List<RuntimeConfiguration<InstanceContext>> createConfigurations() throws NoSuchMethodException, BuilderException { - SimpleComponent component = MockFactory.createComponent("TestService1", SessionScopeComponentImpl.class, Scope.SESSION); - builder.build(component, null); - List<RuntimeConfiguration<InstanceContext>> configs = new ArrayList(); - configs.add((RuntimeConfiguration<InstanceContext>) component.getComponentImplementation().getRuntimeConfiguration()); - return configs; - } - - private RuntimeConfiguration<InstanceContext> createConfiguration(String name) throws NoSuchMethodException, BuilderException { - SimpleComponent component = MockFactory.createComponent(name, SessionScopeInitDestroyComponent.class, Scope.SESSION); - builder.build(component, null); - return (RuntimeConfiguration<InstanceContext>) component.getComponentImplementation().getRuntimeConfiguration(); - } -} diff --git a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicModuleScopeTestCase.java b/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicModuleScopeTestCase.java deleted file mode 100644 index e1dab000ce..0000000000 --- a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicModuleScopeTestCase.java +++ /dev/null @@ -1,126 +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.scopes; - -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.mock.MockFactory; -import org.apache.tuscany.container.java.mock.components.ModuleScopeComponentImpl; -import org.apache.tuscany.container.java.mock.components.ModuleScopeInitDestroyComponent; -import org.apache.tuscany.core.builder.BuilderException; -import org.apache.tuscany.core.builder.RuntimeConfiguration; -import org.apache.tuscany.core.context.EventContext; -import org.apache.tuscany.core.context.InstanceContext; -import org.apache.tuscany.core.context.impl.EventContextImpl; -import org.apache.tuscany.core.context.scope.ModuleScopeContext; -import org.apache.tuscany.model.assembly.Scope; -import org.apache.tuscany.model.assembly.SimpleComponent; - -/** - * Unit tests for the module scope container - * - * @version $Rev$ $Date$ - */ -public class BasicModuleScopeTestCase extends TestCase { - - /** - * Tests instance identity is properly maintained - */ - public void testInstanceManagement() throws Exception { - EventContext ctx = new EventContextImpl(); - ModuleScopeContext scope = new ModuleScopeContext(ctx); - scope.registerConfigurations(createConfigurations()); - scope.start(); - // first request - scope.onEvent(EventContext.MODULE_START, null); - ModuleScopeComponentImpl comp1 = (ModuleScopeComponentImpl) scope.getContext("TestService1").getInstance(null); - Assert.assertNotNull(comp1); - // second request - ModuleScopeComponentImpl comp2 = (ModuleScopeComponentImpl) scope.getContext("TestService1").getInstance(null); - Assert.assertNotNull(comp2); - Assert.assertSame(comp1, comp2); - scope.onEvent(EventContext.MODULE_STOP, null); - scope.stop(); - } - - public void testSetNullComponents() throws Exception { - EventContext ctx = new EventContextImpl(); - ModuleScopeContext scope = new ModuleScopeContext(ctx); - scope.registerConfigurations(createConfigurations()); - scope.start(); - scope.onEvent(EventContext.MODULE_START, null); - scope.onEvent(EventContext.MODULE_STOP, null); - scope.stop(); - } - - public void testRegisterContextBeforeStart() throws Exception { - EventContext ctx = new EventContextImpl(); - ModuleScopeContext scope = new ModuleScopeContext(ctx); - scope.registerConfigurations(createConfigurations()); - scope.start(); - scope.registerConfiguration(createConfiguration("NewTestService")); - scope.onEvent(EventContext.MODULE_START,null); - ModuleScopeInitDestroyComponent comp2 = (ModuleScopeInitDestroyComponent) scope.getContext("NewTestService").getInstance(null); - Assert.assertNotNull(comp2); - Assert.assertTrue(comp2.isInitialized()); - scope.onEvent(EventContext.MODULE_STOP,null); - Assert.assertTrue(comp2.isDestroyed()); - scope.stop(); - } - - public void testRegisterContextAfterStart() throws Exception { - EventContext ctx = new EventContextImpl(); - ModuleScopeContext scope = new ModuleScopeContext(ctx); - scope.start(); - scope.registerConfiguration(createConfiguration("NewTestService")); - scope.onEvent(EventContext.MODULE_START,null); - scope.registerConfigurations(createConfigurations()); - ModuleScopeInitDestroyComponent comp2 = (ModuleScopeInitDestroyComponent) scope.getContext("NewTestService").getInstance(null); - Assert.assertNotNull(comp2); - Assert.assertTrue(comp2.isInitialized()); - scope.onEvent(EventContext.MODULE_STOP,null); - Assert.assertTrue(comp2.isDestroyed()); - scope.stop(); - } - - // ---------------------------------- - // Private methods - // ---------------------------------- - - JavaComponentContextBuilder builder = new JavaComponentContextBuilder(); - - private List<RuntimeConfiguration<InstanceContext>> createConfigurations() throws NoSuchMethodException, BuilderException { - SimpleComponent component = MockFactory.createComponent("TestService1", ModuleScopeComponentImpl.class, Scope.MODULE); - builder.build(component, null); - List<RuntimeConfiguration<InstanceContext>> configs = new ArrayList(); - configs.add((RuntimeConfiguration<InstanceContext>) component.getComponentImplementation().getRuntimeConfiguration()); - return configs; - } - - private RuntimeConfiguration<InstanceContext> createConfiguration(String name) - throws NoSuchMethodException, BuilderException { - SimpleComponent component = MockFactory.createComponent(name, ModuleScopeInitDestroyComponent.class, - Scope.MODULE); - builder.build(component, null); - return (RuntimeConfiguration<InstanceContext>) component.getComponentImplementation().getRuntimeConfiguration(); - } -} diff --git a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicRequestScopeTestCase.java b/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicRequestScopeTestCase.java deleted file mode 100644 index b3a6e5f64b..0000000000 --- a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicRequestScopeTestCase.java +++ /dev/null @@ -1,148 +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.scopes; - -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.mock.MockFactory; -import org.apache.tuscany.container.java.mock.components.RequestScopeComponent; -import org.apache.tuscany.container.java.mock.components.RequestScopeComponentImpl; -import org.apache.tuscany.core.builder.BuilderException; -import org.apache.tuscany.core.builder.RuntimeConfiguration; -import org.apache.tuscany.core.context.EventContext; -import org.apache.tuscany.core.context.InstanceContext; -import org.apache.tuscany.core.context.impl.EventContextImpl; -import org.apache.tuscany.core.context.scope.RequestScopeContext; -import org.apache.tuscany.model.assembly.Scope; -import org.apache.tuscany.model.assembly.SimpleComponent; - -/** - * Unit tests for the request scope container - * - * @version $Rev$ $Date$ - */ -public class BasicRequestScopeTestCase extends TestCase { - - /** - * Tests instance identity is properly maintained - */ - public void testInstanceManagement() throws Exception { - EventContext ctx = new EventContextImpl(); - RequestScopeContext scope = new RequestScopeContext(ctx); - scope.registerConfigurations(createConfigurations()); - scope.start(); - - // first request - RequestScopeComponentImpl comp1 = (RequestScopeComponentImpl) scope.getContext("TestService1").getInstance(null); - Assert.assertNotNull(comp1); - scope.onEvent(EventContext.REQUEST_END, null); - - // second request - RequestScopeComponentImpl comp2 = (RequestScopeComponentImpl) scope.getContext("TestService1").getInstance(null); - Assert.assertNotNull(comp2); - Assert.assertNotSame(comp1, comp2); - scope.onEvent(EventContext.REQUEST_END, null); - - scope.stop(); - } - - public void testRegisterContextBeforeRequest() throws Exception { - EventContext ctx = new EventContextImpl(); - RequestScopeContext scope = new RequestScopeContext(ctx); - scope.registerConfigurations(createConfigurations()); - scope.registerConfiguration(createConfiguration("NewTestService")); - scope.start(); - RequestScopeComponent comp1 = (RequestScopeComponent) scope.getContext("TestService1").getInstance(null); - Assert.assertNotNull(comp1); - RequestScopeComponent comp2 = (RequestScopeComponent) scope.getContext("NewTestService").getInstance(null); - Assert.assertNotNull(comp2); - scope.onEvent(EventContext.REQUEST_END, null); - scope.stop(); - } - - public void testRegisterContextAfterRequest() throws Exception { - EventContext ctx = new EventContextImpl(); - RequestScopeContext scope = new RequestScopeContext(ctx); - scope.registerConfigurations(createConfigurations()); - scope.start(); - RequestScopeComponent comp1 = (RequestScopeComponent) scope.getContext("TestService1").getInstance(null); - Assert.assertNotNull(comp1); - scope.registerConfiguration(createConfiguration("NewTestService")); - RequestScopeComponent comp2 = (RequestScopeComponent) scope.getContext("NewTestService").getInstance(null); - Assert.assertNotNull(comp2); - scope.onEvent(EventContext.REQUEST_END, null); - scope.stop(); - } - - /** - * Tests setting no components in the scope - */ - public void testSetNullComponents() throws Exception { - EventContext ctx = new EventContextImpl(); - RequestScopeContext scope = new RequestScopeContext(ctx); - scope.registerConfigurations(createConfigurations()); - scope.start(); - scope.stop(); - } - - public void testGetComponentByKey() throws Exception { - EventContext ctx = new EventContextImpl(); - RequestScopeContext scope = new RequestScopeContext(ctx); - scope.registerConfigurations(createConfigurations()); - scope.start(); - - RequestScopeComponentImpl comp1 = (RequestScopeComponentImpl) scope.getContext("TestService1").getInstance(null); - Assert.assertNotNull(comp1); - scope.onEvent(EventContext.REQUEST_END, null); - - // second request - // should be null since the other context (thread) expired w/ onEvent(..) - Assert.assertNull((RequestScopeComponentImpl) scope.getContextByKey("TestService1", Thread.currentThread())); - // Note should test better using concurrent threads to pull the instance - - scope.stop(); - } - - // ---------------------------------- - // Private methods - // ---------------------------------- - - JavaComponentContextBuilder builder = new JavaComponentContextBuilder(); - - private List<RuntimeConfiguration<InstanceContext>> createConfigurations() throws NoSuchMethodException, BuilderException { - SimpleComponent component = MockFactory.createComponent("TestService1", RequestScopeComponentImpl.class, - Scope.REQUEST); - builder.build(component, null); - List<RuntimeConfiguration<InstanceContext>> configs = new ArrayList(); - configs.add((RuntimeConfiguration<InstanceContext>) component.getComponentImplementation().getRuntimeConfiguration()); - return configs; - } - - private RuntimeConfiguration<InstanceContext> createConfiguration(String name) throws NoSuchMethodException, - BuilderException { - SimpleComponent component = MockFactory.createComponent(name, RequestScopeComponentImpl.class, - Scope.REQUEST); - builder.build(component, null); - return (RuntimeConfiguration<InstanceContext>) component.getComponentImplementation().getRuntimeConfiguration(); - } - -} diff --git a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicStatelessScopeTestCase.java b/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicStatelessScopeTestCase.java deleted file mode 100644 index 807a0901ce..0000000000 --- a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/BasicStatelessScopeTestCase.java +++ /dev/null @@ -1,125 +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.scopes; - -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.mock.MockFactory; -import org.apache.tuscany.container.java.mock.components.StatelessComponent; -import org.apache.tuscany.container.java.mock.components.StatelessComponentImpl; -import org.apache.tuscany.core.builder.BuilderException; -import org.apache.tuscany.core.builder.RuntimeConfiguration; -import org.apache.tuscany.core.context.EventContext; -import org.apache.tuscany.core.context.InstanceContext; -import org.apache.tuscany.core.context.impl.EventContextImpl; -import org.apache.tuscany.core.context.scope.StatelessScopeContext; -import org.apache.tuscany.model.assembly.Scope; -import org.apache.tuscany.model.assembly.SimpleComponent; - -/** - * Unit tests for the module scope container - * - * @version $Rev$ $Date$ - */ -public class BasicStatelessScopeTestCase extends TestCase { - - /** - * Tests instance identity is properly maintained - */ - public void testInstanceManagement() throws Exception { - EventContext ctx = new EventContextImpl(); - StatelessScopeContext scope = new StatelessScopeContext(ctx); - scope.registerConfigurations(createConfigurations()); - scope.start(); - // first request - StatelessComponentImpl comp1 = (StatelessComponentImpl) scope.getContext("TestService1").getInstance(null); - Assert.assertNotNull(comp1); - // second request - StatelessComponentImpl comp2 = (StatelessComponentImpl) scope.getContext("TestService1").getInstance(null); - Assert.assertNotNull(comp2); - Assert.assertNotSame(comp1, comp2); - scope.stop(); - } - - public void testRegisterContextBeforeRequest() throws Exception { - EventContext ctx = new EventContextImpl(); - StatelessScopeContext scope = new StatelessScopeContext(ctx); - scope.registerConfigurations(createConfigurations()); - scope.registerConfiguration(createConfiguration("NewTestService")); - scope.start(); - StatelessComponent comp1 = (StatelessComponent) scope.getContext("TestService1").getInstance(null); - Assert.assertNotNull(comp1); - StatelessComponent comp2 = (StatelessComponent) scope.getContext("NewTestService").getInstance(null); - Assert.assertNotNull(comp2); - scope.stop(); - } - - public void testRegisterContextAfterRequest() throws Exception { - EventContext ctx = new EventContextImpl(); - StatelessScopeContext scope = new StatelessScopeContext(ctx); - scope.registerConfigurations(createConfigurations()); - scope.start(); - StatelessComponent comp1 = (StatelessComponent) scope.getContext("TestService1").getInstance(null); - Assert.assertNotNull(comp1); - scope.registerConfiguration(createConfiguration("NewTestService")); - StatelessComponent comp2 = (StatelessComponent) scope.getContext("NewTestService").getInstance(null); - Assert.assertNotNull(comp2); - scope.stop(); - } - - - /** - * Tests setting no components in the scope - */ - public void testSetNullComponents() throws Exception { - EventContext ctx = new EventContextImpl(); - StatelessScopeContext scope = new StatelessScopeContext(ctx); - scope.registerConfigurations(createConfigurations()); - scope.start(); - scope.stop(); - } - - // ---------------------------------- - // Private methods - // ---------------------------------- - - JavaComponentContextBuilder builder = new JavaComponentContextBuilder(); - - private List<RuntimeConfiguration<InstanceContext>> createConfigurations() - throws NoSuchMethodException, BuilderException { - SimpleComponent component = MockFactory.createComponent("TestService1", StatelessComponentImpl.class, - Scope.INSTANCE); - builder.build(component, null); - List<RuntimeConfiguration<InstanceContext>> configs = new ArrayList(); - configs.add((RuntimeConfiguration<InstanceContext>) component.getComponentImplementation().getRuntimeConfiguration()); - return configs; - } - - private RuntimeConfiguration<InstanceContext> createConfiguration(String name) - throws NoSuchMethodException, BuilderException { - SimpleComponent component = MockFactory.createComponent(name, StatelessComponentImpl.class, - Scope.INSTANCE); - builder.build(component, null); - return (RuntimeConfiguration<InstanceContext>) component.getComponentImplementation().getRuntimeConfiguration(); - } - -} diff --git a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/HttpSessionScopeLifecycleTestCase.java b/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/HttpSessionScopeLifecycleTestCase.java deleted file mode 100644 index 1d5780dac4..0000000000 --- a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/HttpSessionScopeLifecycleTestCase.java +++ /dev/null @@ -1,157 +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.scopes; - -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.mock.MockFactory; -import org.apache.tuscany.container.java.mock.components.SessionScopeDestroyOnlyComponent; -import org.apache.tuscany.container.java.mock.components.SessionScopeInitDestroyComponent; -import org.apache.tuscany.container.java.mock.components.SessionScopeInitOnlyComponent; -import org.apache.tuscany.core.builder.BuilderException; -import org.apache.tuscany.core.builder.RuntimeConfiguration; -import org.apache.tuscany.core.context.EventContext; -import org.apache.tuscany.core.context.InstanceContext; -import org.apache.tuscany.core.context.impl.EventContextImpl; -import org.apache.tuscany.core.context.scope.HttpSessionScopeContext; -import org.apache.tuscany.model.assembly.Scope; -import org.apache.tuscany.model.assembly.SimpleComponent; - -/** - * Lifecycle unit tests for the Http session scope container - * - * @version $Rev$ $Date$ - */ -public class HttpSessionScopeLifecycleTestCase extends TestCase { - - /** - * Tests instance identity is properly maintained - */ - public void testInitDestroy() throws Exception { - EventContext ctx = new EventContextImpl(); - HttpSessionScopeContext scope = new HttpSessionScopeContext(ctx); - scope.registerConfigurations(createComponents()); - scope.start(); - Object session = new Object(); - Object session2 = new Object(); - // first request, no need to notify scope container since sessions are - // evaluated lazily - ctx.setIdentifier(EventContext.HTTP_SESSION, session); - SessionScopeInitDestroyComponent initDestroy = (SessionScopeInitDestroyComponent) scope.getContext( - "TestServiceInitDestroy").getInstance(null); - Assert.assertNotNull(initDestroy); - SessionScopeInitOnlyComponent initOnly = (SessionScopeInitOnlyComponent) scope.getContext("TestServiceInitOnly") - .getInstance(null); - Assert.assertNotNull(initOnly); - SessionScopeDestroyOnlyComponent destroyOnly = (SessionScopeDestroyOnlyComponent) scope.getContext( - "TestServiceDestroyOnly").getInstance(null); - Assert.assertNotNull(destroyOnly); - - Assert.assertTrue(initDestroy.isInitialized()); - Assert.assertTrue(initOnly.isInitialized()); - Assert.assertFalse(initDestroy.isDestroyed()); - Assert.assertFalse(destroyOnly.isDestroyed()); - // end request - ctx.clearIdentifier(EventContext.HTTP_SESSION); - // expire session - scope.onEvent(EventContext.SESSION_END, session); - Assert.assertTrue(initDestroy.isDestroyed()); - Assert.assertTrue(destroyOnly.isDestroyed()); - - scope.stop(); - } - - /** - * Test instances destroyed in proper (i.e. reverse) order - */ - public void testDestroyOrder() throws Exception { - EventContext ctx = new EventContextImpl(); - HttpSessionScopeContext scope = new HttpSessionScopeContext(ctx); - scope.registerConfigurations(createOrderedInitComponents()); - scope.start(); - Object session = new Object(); - Object session2 = new Object(); - // request start - ctx.setIdentifier(EventContext.HTTP_SESSION, session); - - OrderedInitPojo one = (OrderedInitPojo) scope.getContext("one").getInstance(null); - Assert.assertNotNull(one); - Assert.assertEquals(1, one.getNumberInstantiated()); - Assert.assertEquals(1, one.getInitOrder()); - - OrderedInitPojo two = (OrderedInitPojo) scope.getContext("two").getInstance(null); - Assert.assertNotNull(two); - Assert.assertEquals(2, two.getNumberInstantiated()); - Assert.assertEquals(2, two.getInitOrder()); - - OrderedInitPojo three = (OrderedInitPojo) scope.getContext("three").getInstance(null); - Assert.assertNotNull(three); - Assert.assertEquals(3, three.getNumberInstantiated()); - Assert.assertEquals(3, three.getInitOrder()); - - // end request - ctx.clearIdentifier(EventContext.HTTP_SESSION); - - // expire session - scope.onEvent(EventContext.SESSION_END, session); - Assert.assertEquals(0, one.getNumberInstantiated()); - scope.stop(); - } - - // ---------------------------------- - // Private methods - // ---------------------------------- - - JavaComponentContextBuilder builder = new JavaComponentContextBuilder(); - - private List<RuntimeConfiguration<InstanceContext>> createComponents() throws NoSuchMethodException, BuilderException { - SimpleComponent[] ca = new SimpleComponent[3]; - ca[0] = MockFactory.createComponent("TestServiceInitDestroy", SessionScopeInitDestroyComponent.class, - Scope.SESSION); - ca[1] = MockFactory.createComponent("TestServiceInitOnly", SessionScopeInitOnlyComponent.class, Scope.SESSION); - ca[2] = MockFactory.createComponent("TestServiceDestroyOnly", SessionScopeDestroyOnlyComponent.class, - Scope.SESSION); - List<RuntimeConfiguration<InstanceContext>> configs = new ArrayList(); - for (int i = 0; i < ca.length; i++) { - builder.build(ca[i], null); - configs.add((RuntimeConfiguration<InstanceContext>) ca[i].getComponentImplementation().getRuntimeConfiguration()); - - } - return configs; - } - - private List<RuntimeConfiguration<InstanceContext>> createOrderedInitComponents() throws NoSuchMethodException, - BuilderException { - SimpleComponent[] ca = new SimpleComponent[3]; - ca[0] = MockFactory.createComponent("one", OrderedInitPojo.class, Scope.SESSION); - ca[1] = MockFactory.createComponent("two", OrderedInitPojo.class, Scope.SESSION); - ca[2] = MockFactory.createComponent("three", OrderedInitPojo.class, Scope.SESSION); - List<RuntimeConfiguration<InstanceContext>> configs = new ArrayList(); - for (int i = 0; i < ca.length; i++) { - builder.build(ca[i], null); - configs.add((RuntimeConfiguration<InstanceContext>) ca[i].getComponentImplementation().getRuntimeConfiguration()); - - } - return configs; - } - -} diff --git a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/ModuleScopeLifecycleTestCase.java b/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/ModuleScopeLifecycleTestCase.java deleted file mode 100644 index 2c8a79de14..0000000000 --- a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/ModuleScopeLifecycleTestCase.java +++ /dev/null @@ -1,224 +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.scopes; - -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.mock.MockFactory; -import org.apache.tuscany.container.java.mock.components.ModuleScopeDestroyOnlyComponent; -import org.apache.tuscany.container.java.mock.components.ModuleScopeEagerInitComponent; -import org.apache.tuscany.container.java.mock.components.ModuleScopeEagerInitDestroyComponent; -import org.apache.tuscany.container.java.mock.components.ModuleScopeInitDestroyComponent; -import org.apache.tuscany.container.java.mock.components.ModuleScopeInitOnlyComponent; -import org.apache.tuscany.core.builder.BuilderException; -import org.apache.tuscany.core.builder.RuntimeConfiguration; -import org.apache.tuscany.core.context.EventContext; -import org.apache.tuscany.core.context.InstanceContext; -import org.apache.tuscany.core.context.impl.EventContextImpl; -import org.apache.tuscany.core.context.scope.ModuleScopeContext; -import org.apache.tuscany.model.assembly.Scope; -import org.apache.tuscany.model.assembly.SimpleComponent; - -/** - * Lifecycle unit tests for the Http session scope container - * - * @version $Rev$ $Date$ - */ -public class ModuleScopeLifecycleTestCase extends TestCase { - - public void testInitDestroy() throws Exception { - EventContext ctx = new EventContextImpl(); - ModuleScopeContext scope = new ModuleScopeContext(ctx); - scope.registerConfigurations(createComponents()); - scope.start(); - scope.onEvent(EventContext.MODULE_START, null); - ModuleScopeInitDestroyComponent initDestroy = (ModuleScopeInitDestroyComponent) scope.getContext( - "TestServiceInitDestroy").getInstance(null); - Assert.assertNotNull(initDestroy); - ModuleScopeInitOnlyComponent initOnly = (ModuleScopeInitOnlyComponent) scope.getContext("TestServiceInitOnly") - .getInstance(null); - Assert.assertNotNull(initOnly); - ModuleScopeDestroyOnlyComponent destroyOnly = (ModuleScopeDestroyOnlyComponent) scope.getContext( - "TestServiceDestroyOnly").getInstance(null); - Assert.assertNotNull(destroyOnly); - - Assert.assertTrue(initDestroy.isInitialized()); - Assert.assertTrue(initOnly.isInitialized()); - Assert.assertFalse(initDestroy.isDestroyed()); - Assert.assertFalse(destroyOnly.isDestroyed()); - - // expire module - scope.onEvent(EventContext.MODULE_STOP, null); - - Assert.assertTrue(initDestroy.isDestroyed()); - Assert.assertTrue(destroyOnly.isDestroyed()); - - scope.stop(); - } - - public void testEagerInit() throws Exception { - EventContext ctx = new EventContextImpl(); - ModuleScopeContext scope = new ModuleScopeContext(ctx); - scope.registerConfigurations(createEagerInitComponents()); - scope.start(); - scope.onEvent(EventContext.MODULE_START, null); - ModuleScopeEagerInitDestroyComponent initDestroy = (ModuleScopeEagerInitDestroyComponent) scope.getContext( - "TestServiceEagerInitDestroy").getInstance(null); - Assert.assertNotNull(initDestroy); - ModuleScopeEagerInitComponent initOnly = (ModuleScopeEagerInitComponent) scope - .getContext("TestServiceEagerInit").getInstance(null); - Assert.assertNotNull(initOnly); - - Assert.assertTrue(initDestroy.isInitialized()); - Assert.assertTrue(initOnly.isInitialized()); - Assert.assertFalse(initDestroy.isDestroyed()); - - // expire module - scope.onEvent(EventContext.MODULE_STOP, null); - - Assert.assertTrue(initDestroy.isDestroyed()); - - scope.stop(); - - } - - public void testDestroyOrder() throws Exception { - EventContext ctx = new EventContextImpl(); - ModuleScopeContext scope = new ModuleScopeContext(ctx); - scope.registerConfigurations(createOrderedInitComponents()); - scope.start(); - scope.onEvent(EventContext.MODULE_START, null); - OrderedInitPojo one = (OrderedInitPojo) scope.getContext("one").getInstance(null); - Assert.assertNotNull(one); - Assert.assertEquals(1, one.getNumberInstantiated()); - Assert.assertEquals(1, one.getInitOrder()); - - OrderedInitPojo two = (OrderedInitPojo) scope.getContext("two").getInstance(null); - Assert.assertNotNull(two); - Assert.assertEquals(2, two.getNumberInstantiated()); - Assert.assertEquals(2, two.getInitOrder()); - - OrderedInitPojo three = (OrderedInitPojo) scope.getContext("three").getInstance(null); - Assert.assertNotNull(three); - Assert.assertEquals(3, three.getNumberInstantiated()); - Assert.assertEquals(3, three.getInitOrder()); - - // expire module - scope.onEvent(EventContext.MODULE_STOP, null); - Assert.assertEquals(0, one.getNumberInstantiated()); - scope.stop(); - } - - public void testEagerInitDestroyOrder() throws Exception { - EventContext ctx = new EventContextImpl(); - ModuleScopeContext scope = new ModuleScopeContext(ctx); - scope.registerConfigurations(createOrderedEagerInitComponents()); - scope.start(); - scope.onEvent(EventContext.MODULE_START, null); - OrderedEagerInitPojo one = (OrderedEagerInitPojo) scope.getContext("one").getInstance(null); - Assert.assertNotNull(one); - - OrderedEagerInitPojo two = (OrderedEagerInitPojo) scope.getContext("two").getInstance(null); - Assert.assertNotNull(two); - - OrderedEagerInitPojo three = (OrderedEagerInitPojo) scope.getContext("three").getInstance(null); - Assert.assertNotNull(three); - - // expire module - scope.onEvent(EventContext.MODULE_STOP, null); - Assert.assertEquals(0, one.getNumberInstantiated()); - scope.stop(); - } - - // ---------------------------------- - // Private methods - // ---------------------------------- - - JavaComponentContextBuilder builder = new JavaComponentContextBuilder(); - - private List<RuntimeConfiguration<InstanceContext>> createComponents() throws NoSuchMethodException, BuilderException { - SimpleComponent[] ca = new SimpleComponent[3]; - ca[0] = MockFactory.createComponent("TestServiceInitDestroy", ModuleScopeInitDestroyComponent.class, - Scope.MODULE); - ca[1] = MockFactory.createComponent("TestServiceInitOnly", ModuleScopeInitOnlyComponent.class, - Scope.MODULE); - ca[2] = MockFactory.createComponent("TestServiceDestroyOnly", ModuleScopeDestroyOnlyComponent.class, - Scope.MODULE); - List<RuntimeConfiguration<InstanceContext>> configs = new ArrayList(); - for (int i = 0; i < ca.length; i++) { - builder.build(ca[i], null); - configs.add((RuntimeConfiguration<InstanceContext>) ca[i].getComponentImplementation() - .getRuntimeConfiguration()); - - } - return configs; - } - - private List<RuntimeConfiguration<InstanceContext>> createEagerInitComponents() throws NoSuchMethodException, - BuilderException { - SimpleComponent[] ca = new SimpleComponent[2]; - ca[0] = MockFactory.createComponent("TestServiceEagerInitDestroy", ModuleScopeEagerInitDestroyComponent.class, - Scope.MODULE); - ca[1] = MockFactory.createComponent("TestServiceEagerInit", ModuleScopeEagerInitComponent.class, - Scope.MODULE); - List<RuntimeConfiguration<InstanceContext>> configs = new ArrayList(); - for (int i = 0; i < ca.length; i++) { - builder.build(ca[i], null); - configs.add((RuntimeConfiguration<InstanceContext>) ca[i].getComponentImplementation() - .getRuntimeConfiguration()); - - } - return configs; - } - - private List<RuntimeConfiguration<InstanceContext>> createOrderedInitComponents() throws NoSuchMethodException, - BuilderException { - SimpleComponent[] ca = new SimpleComponent[3]; - ca[0] = MockFactory.createComponent("one", OrderedInitPojo.class, Scope.MODULE); - ca[1] = MockFactory.createComponent("two", OrderedInitPojo.class, Scope.MODULE); - ca[2] = MockFactory.createComponent("three", OrderedInitPojo.class, Scope.MODULE); - List<RuntimeConfiguration<InstanceContext>> configs = new ArrayList(); - for (int i = 0; i < ca.length; i++) { - builder.build(ca[i], null); - configs.add((RuntimeConfiguration<InstanceContext>) ca[i].getComponentImplementation() - .getRuntimeConfiguration()); - - } - return configs; - } - - private List<RuntimeConfiguration<InstanceContext>> createOrderedEagerInitComponents() throws NoSuchMethodException, - BuilderException { - SimpleComponent[] ca = new SimpleComponent[3]; - ca[0] = MockFactory.createComponent("one", OrderedEagerInitPojo.class, Scope.MODULE); - ca[1] = MockFactory.createComponent("two", OrderedEagerInitPojo.class, Scope.MODULE); - ca[2] = MockFactory.createComponent("three", OrderedEagerInitPojo.class, Scope.MODULE); - List<RuntimeConfiguration<InstanceContext>> configs = new ArrayList(); - for (int i = 0; i < ca.length; i++) { - builder.build(ca[i], null); - configs.add((RuntimeConfiguration<InstanceContext>) ca[i].getComponentImplementation() - .getRuntimeConfiguration()); - - } - return configs; - } -} diff --git a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderException.java b/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderException.java deleted file mode 100644 index fc5f7c8c58..0000000000 --- a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderException.java +++ /dev/null @@ -1,38 +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.scopes; - -public class OrderException extends Exception { - - public OrderException() { - super(); - } - - public OrderException(String message) { - super(message); - } - - public OrderException(String message, Throwable cause) { - super(message, cause); - } - - public OrderException(Throwable cause) { - super(cause); - } - -} - diff --git a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedEagerInitPojo.java b/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedEagerInitPojo.java deleted file mode 100644 index d439159550..0000000000 --- a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedEagerInitPojo.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.scopes; - -import org.osoa.sca.annotations.Destroy; -import org.osoa.sca.annotations.Init; - -public class OrderedEagerInitPojo { - - private static Object lock = new Object(); - private static int numberInstantied; - private int initOrder; - - @Init(eager = true) - public void init() { - synchronized (lock) { - ++numberInstantied; - initOrder = numberInstantied; - } - } - - @Destroy - public void destroy() throws OrderException { - synchronized (lock) { - if (initOrder != numberInstantied) { - throw new OrderException("Instance shutdown done out of order"); - } - --numberInstantied; - } - } - - public int getNumberInstantiated() { - return numberInstantied; - } - - public int getInitOrder() { - return initOrder; - } - -} diff --git a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedInitPojo.java b/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedInitPojo.java deleted file mode 100644 index ee5c5145c2..0000000000 --- a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/OrderedInitPojo.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.scopes; - -import org.osoa.sca.annotations.Destroy; -import org.osoa.sca.annotations.Init; - -public class OrderedInitPojo { - - private static Object lock = new Object(); - private static int numberInstantied; - private int initOrder; - - @Init - public void init() { - synchronized (lock) { - ++numberInstantied; - initOrder = numberInstantied; - } - } - - @Destroy - public void destroy() throws OrderException { - synchronized (lock) { - if (initOrder != numberInstantied) { - throw new OrderException("Instance shutdown done out of order"); - } - --numberInstantied; - } - } - - public int getNumberInstantiated() { - return numberInstantied; - } - - public int getInitOrder() { - return initOrder; - } - -} diff --git a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/RequestScopeLifecycleTestCase.java b/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/RequestScopeLifecycleTestCase.java deleted file mode 100644 index 1979d9b25c..0000000000 --- a/tags/java-stable-20060304/sca/container.java/src/test/java/org/apache/tuscany/container/java/scopes/RequestScopeLifecycleTestCase.java +++ /dev/null @@ -1,146 +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.scopes; - -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.mock.MockFactory; -import org.apache.tuscany.container.java.mock.components.SessionScopeDestroyOnlyComponent; -import org.apache.tuscany.container.java.mock.components.SessionScopeInitDestroyComponent; -import org.apache.tuscany.container.java.mock.components.SessionScopeInitOnlyComponent; -import org.apache.tuscany.core.builder.BuilderException; -import org.apache.tuscany.core.builder.RuntimeConfiguration; -import org.apache.tuscany.core.context.EventContext; -import org.apache.tuscany.core.context.InstanceContext; -import org.apache.tuscany.core.context.impl.EventContextImpl; -import org.apache.tuscany.core.context.scope.RequestScopeContext; -import org.apache.tuscany.model.assembly.Scope; -import org.apache.tuscany.model.assembly.SimpleComponent; - -/** - * Lifecycle unit tests for the Http session scope container - * - * @version $Rev$ $Date$ - */ -public class RequestScopeLifecycleTestCase extends TestCase { - - /** - * Tests instance identity is properly maintained - */ - public void testInitDestroy() throws Exception { - EventContext ctx = new EventContextImpl(); - RequestScopeContext scope = new RequestScopeContext(ctx); - scope.registerConfigurations(createComponents()); - scope.start(); - SessionScopeInitDestroyComponent initDestroy = (SessionScopeInitDestroyComponent) scope.getContext( - "TestServiceInitDestroy").getInstance(null); - Assert.assertNotNull(initDestroy); - SessionScopeInitOnlyComponent initOnly = (SessionScopeInitOnlyComponent) scope.getContext("TestServiceInitOnly") - .getInstance(null); - Assert.assertNotNull(initOnly); - SessionScopeDestroyOnlyComponent destroyOnly = (SessionScopeDestroyOnlyComponent) scope.getContext( - "TestServiceDestroyOnly").getInstance(null); - Assert.assertNotNull(destroyOnly); - - Assert.assertTrue(initDestroy.isInitialized()); - Assert.assertTrue(initOnly.isInitialized()); - Assert.assertFalse(initDestroy.isDestroyed()); - Assert.assertFalse(destroyOnly.isDestroyed()); - - // end request - scope.onEvent(EventContext.REQUEST_END, null); - Assert.assertTrue(initDestroy.isDestroyed()); - Assert.assertTrue(destroyOnly.isDestroyed()); - - scope.stop(); - } - - /** - * Test instances destroyed in proper (i.e. reverse) order - */ - public void testDestroyOrder() throws Exception { - EventContext ctx = new EventContextImpl(); - RequestScopeContext scope = new RequestScopeContext(ctx); - scope.registerConfigurations(createOrderedInitComponents()); - scope.start(); - // request start - OrderedInitPojo one = (OrderedInitPojo) scope.getContext("one").getInstance(null); - Assert.assertNotNull(one); - Assert.assertEquals(1, one.getNumberInstantiated()); - Assert.assertEquals(1, one.getInitOrder()); - - OrderedInitPojo two = (OrderedInitPojo) scope.getContext("two").getInstance(null); - Assert.assertNotNull(two); - Assert.assertEquals(2, two.getNumberInstantiated()); - Assert.assertEquals(2, two.getInitOrder()); - - OrderedInitPojo three = (OrderedInitPojo) scope.getContext("three").getInstance(null); - Assert.assertNotNull(three); - Assert.assertEquals(3, three.getNumberInstantiated()); - Assert.assertEquals(3, three.getInitOrder()); - - // end request - scope.onEvent(EventContext.REQUEST_END, null); - - Assert.assertEquals(0, one.getNumberInstantiated()); - scope.stop(); - } - - // ---------------------------------- - // Private methods - // ---------------------------------- - - JavaComponentContextBuilder builder = new JavaComponentContextBuilder(); - - private List<RuntimeConfiguration<InstanceContext>> createComponents() throws NoSuchMethodException, BuilderException { - SimpleComponent[] ca = new SimpleComponent[3]; - ca[0] = MockFactory.createComponent("TestServiceInitDestroy", SessionScopeInitDestroyComponent.class, - Scope.REQUEST); - ca[1] = MockFactory.createComponent("TestServiceInitOnly", SessionScopeInitOnlyComponent.class, - Scope.REQUEST); - ca[2] = MockFactory.createComponent("TestServiceDestroyOnly", SessionScopeDestroyOnlyComponent.class, - Scope.REQUEST); - List<RuntimeConfiguration<InstanceContext>> configs = new ArrayList(); - for (int i = 0; i < ca.length; i++) { - builder.build(ca[i], null); - configs.add((RuntimeConfiguration<InstanceContext>) ca[i].getComponentImplementation().getRuntimeConfiguration()); - - } - return configs; - } - - private List<RuntimeConfiguration<InstanceContext>> createOrderedInitComponents() throws NoSuchMethodException, - BuilderException { - SimpleComponent[] ca = new SimpleComponent[3]; - ca[0] = MockFactory.createComponent("one", OrderedInitPojo.class, Scope.REQUEST); - ca[1] = MockFactory.createComponent("two", OrderedInitPojo.class, Scope.REQUEST); - ca[2] = MockFactory.createComponent("three", OrderedInitPojo.class, Scope.REQUEST); - List<RuntimeConfiguration<InstanceContext>> configs = new ArrayList(); - for (int i = 0; i < ca.length; i++) { - builder.build(ca[i], null); - configs.add((RuntimeConfiguration<InstanceContext>) ca[i].getComponentImplementation().getRuntimeConfiguration()); - - } - return configs; - } - -} |