Author: jmarino
Date: Tue Feb 28 23:45:26 2006
New Revision: 381938
URL: http://svn.apache.org/viewcvs?rev=381938&view=rev
Log:
bug fix for down-scope references where target was being cached
Added:
incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaRuntimeBootstrapTestCase.java
incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/context/
incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/context/ScopeReferenceTestCase.java
Modified:
incubator/tuscany/java/sca/container.java/src/main/java/org/apache/tuscany/container/java/builder/JavaTargetWireBuilder.java
incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockFactory.java
Modified:
incubator/tuscany/java/sca/container.java/src/main/java/org/apache/tuscany/container/java/builder/JavaTargetWireBuilder.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/container.java/src/main/java/org/apache/tuscany/container/java/builder/JavaTargetWireBuilder.java?rev=381938&r1=381937&r2=381938&view=diff
==============================================================================
---
incubator/tuscany/java/sca/container.java/src/main/java/org/apache/tuscany/container/java/builder/JavaTargetWireBuilder.java
(original)
+++
incubator/tuscany/java/sca/container.java/src/main/java/org/apache/tuscany/container/java/builder/JavaTargetWireBuilder.java
Tue Feb 28 23:45:26 2006
@@ -59,9 +59,9 @@
.getTargetName(), sourceInvocationConfig.getMethod(),
targetScopeContext);
if (downScope) {
// the source scope is shorter than the target, so the invoker
can cache the target instance
- invoker.setCacheable(true);
- } else {
invoker.setCacheable(false);
+ } else {
+ invoker.setCacheable(true);
}
sourceInvocationConfig.setTargetInvoker(invoker);
}
Added:
incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaRuntimeBootstrapTestCase.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaRuntimeBootstrapTestCase.java?rev=381938&view=auto
==============================================================================
---
incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaRuntimeBootstrapTestCase.java
(added)
+++
incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/JavaRuntimeBootstrapTestCase.java
Tue Feb 28 23:45:26 2006
@@ -0,0 +1,54 @@
+/**
+ *
+ * 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("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();
+
+ }
+
+}
+
Added:
incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/context/ScopeReferenceTestCase.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/context/ScopeReferenceTestCase.java?rev=381938&view=auto
==============================================================================
---
incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/context/ScopeReferenceTestCase.java
(added)
+++
incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/integration/context/ScopeReferenceTestCase.java
Tue Feb 28 23:45:26 2006
@@ -0,0 +1,97 @@
+/**
+ *
+ * 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());
+ //testCtx.fireEvent(EventContext.SESSION_NOTIFY,session);
+
+
+ }
+
+
+
+}
+
Modified:
incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockFactory.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockFactory.java?rev=381938&r1=381937&r2=381938&view=diff
==============================================================================
---
incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockFactory.java
(original)
+++
incubator/tuscany/java/sca/container.java/src/test/java/org/apache/tuscany/container/java/mock/MockFactory.java
Tue Feb 28 23:45:26 2006
@@ -285,11 +285,18 @@
}
/**
- * Creates a module with a Java-based "target" component wired to a
"source"
+ * Creates a module with a Java-based "target" module-scoped component
wired to a module-scoped "source"
*/
public static Module createModule() {
- Component sourceComponent = createComponent("source",
ModuleScopeComponentImpl.class, Scope.MODULE);
- Component targetComponent = createComponent("target",
ModuleScopeComponentImpl.class, Scope.MODULE);
+ return createModule(Scope.MODULE,Scope.MODULE);
+ }
+
+ /**
+ * Creates a module with a Java-based "target" component wired to a
"source"
+ */
+ public static Module createModule(Scope sourceScope, Scope targetScope) {
+ Component sourceComponent = createComponent("source",
ModuleScopeComponentImpl.class, sourceScope);
+ Component targetComponent = createComponent("target",
ModuleScopeComponentImpl.class, targetScope);
Service targetService = factory.createService();
JavaServiceContract targetContract =
factory.createJavaServiceContract();
@@ -509,7 +516,7 @@
SystemAggregateContext ctx = (SystemAggregateContext)
runtime.getSystemContext().getContext("tuscany.system.child");
ctx.registerModelObject(createSystemComponent("java.runtime.builder",
JavaComponentContextBuilder.class, Scope.MODULE));
ctx.registerModelObject(createSystemComponent("java.wire.builder",
JavaTargetWireBuilder.class, Scope.MODULE));
- ctx.fireEvent(EventContext.MODULE_START,null);
+ ctx.fireEvent(EventContext.MODULE_START, null);
return runtime;
}
}