You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2007/02/24 16:09:52 UTC

svn commit: r511282 - in /incubator/tuscany/branches/sca-java-integration/sca/extensions/script: container.bsf/src/main/java/org/apache/tuscany/container/script/ container.bsf/src/test/java/org/apache/tuscany/container/script/ itests/src/main/resources...

Author: antelder
Date: Sat Feb 24 07:09:51 2007
New Revision: 511282

URL: http://svn.apache.org/viewvc?view=rev&rev=511282
Log:
Get properties working for script components and tests for ruby python and javascript

Added:
    incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/META-INF/sca/properties.composite
    incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/properties/
    incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/properties/helloworld.componentType   (with props)
    incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/properties/helloworld.js   (with props)
    incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/properties/helloworld.py   (with props)
    incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/properties/helloworld.rb
    incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/test/java/helloworld/PropertiesTestCase.java   (with props)
Modified:
    incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/src/main/java/org/apache/tuscany/container/script/ScriptComponent.java
    incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/src/main/java/org/apache/tuscany/container/script/ScriptInstanceFactory.java
    incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/src/test/java/org/apache/tuscany/container/script/ScriptInstanceFactoryTestCase.java

Modified: incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/src/main/java/org/apache/tuscany/container/script/ScriptComponent.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/src/main/java/org/apache/tuscany/container/script/ScriptComponent.java?view=diff&rev=511282&r1=511281&r2=511282
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/src/main/java/org/apache/tuscany/container/script/ScriptComponent.java (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/src/main/java/org/apache/tuscany/container/script/ScriptComponent.java Sat Feb 24 07:09:51 2007
@@ -75,7 +75,7 @@
     @SuppressWarnings({"unchecked"})
     protected void onReferenceWire(OutboundWire wire) {
         Class<?> clazz = wire.getServiceContract().getInterfaceClass();
-        factory.addContextObjectFactory(wire.getReferenceName(), new WireObjectFactory(clazz, wire, wireService));
+        factory.addContextObjectFactory(wire.getReferenceName(), clazz, new WireObjectFactory(clazz, wire, wireService));
     }
 
     public Object getTargetInstance() throws TargetResolutionException {

Modified: incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/src/main/java/org/apache/tuscany/container/script/ScriptInstanceFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/src/main/java/org/apache/tuscany/container/script/ScriptInstanceFactory.java?view=diff&rev=511282&r1=511281&r2=511282
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/src/main/java/org/apache/tuscany/container/script/ScriptInstanceFactory.java (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/src/main/java/org/apache/tuscany/container/script/ScriptInstanceFactory.java Sat Feb 24 07:09:51 2007
@@ -39,6 +39,7 @@
     private String className;
     private String scriptSource;
     private Map<String, ObjectFactory> contextObjects;
+    private Map<String, Class> contextTypes;
 
     public ScriptInstanceFactory(String resourceName,
                                  String className,
@@ -49,6 +50,7 @@
         this.className = className;
         this.scriptSource = scriptSource;
         this.contextObjects = new HashMap<String, ObjectFactory>();
+        this.contextTypes = new HashMap<String, Class>();
     }
 
     /**
@@ -73,7 +75,12 @@
 
             // register any context objects (SCA properties and references)
             for (Map.Entry<String, ObjectFactory> entry : contextObjects.entrySet()) {
-                bsfManager.declareBean(entry.getKey(), entry.getValue().getInstance(), Object.class);
+                Object value = entry.getValue().getInstance();
+                Class type = contextTypes.get(entry.getKey());
+                if (type == null) {
+                    type = value.getClass();
+                }
+                bsfManager.declareBean(entry.getKey(), value, type);
             }
 
             String scriptLanguage = BSFManager.getLangFromFilename(resourceName);
@@ -123,6 +130,11 @@
 
     public void addContextObjectFactory(String name, ObjectFactory<?> factory) {
         contextObjects.put(name, factory);
+    }
+
+    public void addContextObjectFactory(String name, Class type, ObjectFactory<?> factory) {
+        contextObjects.put(name, factory);
+        contextTypes.put(name, type);
     }
 
 }

Modified: incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/src/test/java/org/apache/tuscany/container/script/ScriptInstanceFactoryTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/src/test/java/org/apache/tuscany/container/script/ScriptInstanceFactoryTestCase.java?view=diff&rev=511282&r1=511281&r2=511282
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/src/test/java/org/apache/tuscany/container/script/ScriptInstanceFactoryTestCase.java (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/extensions/script/container.bsf/src/test/java/org/apache/tuscany/container/script/ScriptInstanceFactoryTestCase.java Sat Feb 24 07:09:51 2007
@@ -35,7 +35,7 @@
         BSFManager.registerScriptingEngine("mock", MockBSFEngine.class.getName(), new String[]{"mock"});
         ScriptInstanceFactory factory =
             new ScriptInstanceFactory("foo.mock", "bar", "baz", getClass().getClassLoader());
-        factory.addContextObjectFactory("foo", new SingletonObjectFactory("bar"));
+        factory.addContextObjectFactory("foo", String.class, new SingletonObjectFactory("bar"));
         ScriptInstanceImpl instance = (ScriptInstanceImpl) factory.getInstance();
         assertNotNull(instance);
         assertNotNull(instance.bsfEngine);
@@ -45,7 +45,7 @@
         BSFManager.registerScriptingEngine("mock", MockBSFEngine.class.getName(), new String[]{"mock"});
         ScriptInstanceFactory factory =
             new ScriptInstanceFactory("foo.mock", null, "baz", getClass().getClassLoader());
-        factory.addContextObjectFactory("foo", new SingletonObjectFactory("bar"));
+        factory.addContextObjectFactory("foo", String.class, new SingletonObjectFactory("bar"));
         ScriptInstanceImpl instance = (ScriptInstanceImpl) factory.getInstance();
         assertNotNull(instance);
         assertNotNull(instance.bsfEngine);
@@ -55,7 +55,7 @@
         BSFManager.registerScriptingEngine("ruby", MockBSFEngine.class.getName(), new String[]{"mock"});
         ScriptInstanceFactory factory =
             new ScriptInstanceFactory("foo.mock", "bar", "baz", getClass().getClassLoader());
-        factory.addContextObjectFactory("foo", new SingletonObjectFactory("bar"));
+        factory.addContextObjectFactory("foo", String.class, new SingletonObjectFactory("bar"));
         ScriptInstanceImpl instance = (ScriptInstanceImpl) factory.getInstance();
         assertNotNull(instance);
         assertNotNull(instance.bsfEngine);

Added: incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/META-INF/sca/properties.composite
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/META-INF/sca/properties.composite?view=auto&rev=511282
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/META-INF/sca/properties.composite (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/META-INF/sca/properties.composite Sat Feb 24 07:09:51 2007
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+
+           name="ScriptItests">
+    
+    <component name="HelloWorldJSDefaultComponent">
+        <implementation.script script="properties/helloworld.js"/>
+    </component>
+
+    <component name="HelloWorldJSOverrideComponent">
+        <implementation.script script="properties/helloworld.js"/>
+        <property name="GREETING">Namaskaar</property>
+    </component>
+
+    <component name="HelloWorldRubyDefaultComponent">
+        <implementation.script script="properties/helloworld.rb"/>
+    </component>
+
+    <component name="HelloWorldRubyOverrideComponent">
+        <implementation.script script="properties/helloworld.rb"/>
+        <property name="GREETING">Namaskaar</property>
+    </component>
+
+    <component name="HelloWorldPythonDefaultComponent">
+        <implementation.script script="properties/helloworld.py"/>
+    </component>
+
+    <component name="HelloWorldPythonOverrideComponent">
+        <implementation.script script="properties/helloworld.py"/>
+        <property name="GREETING">Namaskaar</property>
+    </component>
+
+</composite>

Added: incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/properties/helloworld.componentType
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/properties/helloworld.componentType?view=auto&rev=511282
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/properties/helloworld.componentType (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/properties/helloworld.componentType Sat Feb 24 07:09:51 2007
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="ASCII"?>
+<componentType xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:wsdli="http://www.w3.org/2006/01/wsdl-instance">
+
+  <service name="HelloWorldService">
+        <interface.java class="helloworld.HelloWorldService" />
+  </service>
+
+  <property name="GREETING" type="xsd:string">Kia Ora</property>
+
+</componentType>              
+       
\ No newline at end of file

Propchange: incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/properties/helloworld.componentType
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/properties/helloworld.componentType
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/properties/helloworld.componentType
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/properties/helloworld.js
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/properties/helloworld.js?view=auto&rev=511282
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/properties/helloworld.js (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/properties/helloworld.js Sat Feb 24 07:09:51 2007
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+ 
+function getGreetings(s) {
+   return "js" + GREETING + " " + s;
+}
\ No newline at end of file

Propchange: incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/properties/helloworld.js
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/properties/helloworld.py
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/properties/helloworld.py?view=auto&rev=511282
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/properties/helloworld.py (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/properties/helloworld.py Sat Feb 24 07:09:51 2007
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+def getGreetings(s):
+   return "py" + GREETING + " " + s
\ No newline at end of file

Propchange: incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/properties/helloworld.py
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/properties/helloworld.rb
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/properties/helloworld.rb?view=auto&rev=511282
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/properties/helloworld.rb (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/main/resources/properties/helloworld.rb Sat Feb 24 07:09:51 2007
@@ -0,0 +1,21 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+def getGreetings(s) 
+   return "rb" + $GREETING + " " + s
+end
+

Added: incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/test/java/helloworld/PropertiesTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/test/java/helloworld/PropertiesTestCase.java?view=auto&rev=511282
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/test/java/helloworld/PropertiesTestCase.java (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/test/java/helloworld/PropertiesTestCase.java Sat Feb 24 07:09:51 2007
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package helloworld;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.test.SCATestCase;
+import org.osoa.sca.CompositeContext;
+import org.osoa.sca.CurrentCompositeContext;
+
+/**
+ * Test case for using references in script components
+ */
+public class PropertiesTestCase extends SCATestCase {
+
+    private CompositeContext compositeContext;
+
+    public void testJavaScriptDefault() throws Exception {
+        HelloWorldService helloWorldService =
+            compositeContext.locateService(HelloWorldService.class, "HelloWorldJSDefaultComponent");
+        String msg = helloWorldService.getGreetings("Petra");
+        Assert.assertEquals("jsKia Ora Petra", msg);
+    }
+
+    public void testJavaScriptOverride() throws Exception {
+        HelloWorldService helloWorldService =
+            compositeContext.locateService(HelloWorldService.class, "HelloWorldJSOverrideComponent");
+        String msg = helloWorldService.getGreetings("Petra");
+        Assert.assertEquals("jsNamaskaar Petra", msg);
+    }
+
+    public void testPythonDefault() throws Exception {
+        HelloWorldService helloWorldService =
+            compositeContext.locateService(HelloWorldService.class, "HelloWorldPythonDefaultComponent");
+        String msg = helloWorldService.getGreetings("Petra");
+        Assert.assertEquals("pyKia Ora Petra", msg);
+    }
+    public void testPythonOverride() throws Exception {
+        HelloWorldService helloWorldService =
+            compositeContext.locateService(HelloWorldService.class, "HelloWorldPythonOverrideComponent");
+        String msg = helloWorldService.getGreetings("Petra");
+        Assert.assertEquals("pyNamaskaar Petra", msg);
+    }
+
+    public void testRubyDefault() throws Exception {
+        HelloWorldService helloWorldService =
+            compositeContext.locateService(HelloWorldService.class, "HelloWorldRubyDefaultComponent");
+        String msg = helloWorldService.getGreetings("Petra");
+        Assert.assertEquals("rbKia Ora Petra", msg);
+    }
+    public void testRubyOverride() throws Exception {
+        HelloWorldService helloWorldService =
+            compositeContext.locateService(HelloWorldService.class, "HelloWorldRubyOverrideComponent");
+        String msg = helloWorldService.getGreetings("Petra");
+        Assert.assertEquals("rbNamaskaar Petra", msg);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        setApplicationSCDL(getClass().getResource("/META-INF/sca/properties.composite"));
+        super.setUp();
+        this.compositeContext = CurrentCompositeContext.getContext();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+}

Propchange: incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/test/java/helloworld/PropertiesTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/branches/sca-java-integration/sca/extensions/script/itests/src/test/java/helloworld/PropertiesTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org