Author: antelder
Date: Mon Jul 31 08:25:54 2006
New Revision: 427139

URL: http://svn.apache.org/viewvc?rev=427139&view=rev
Log:
Add the JavaScriptTestCase and helloworld test that we're talking about right 
now on IRC.
Quite rough right now as it was done in a hurry, I'll tidy it up in a mo...


Added:
    
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/helloworld/
    
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/helloworld/HelloWorldService.java
    
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/functional/
    
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/functional/HelloWorld.componentType
    
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/functional/HelloWorld.js
    
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/functional/HelloWorldTestCase.java
    
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/functional/helloworld.scdl
    
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/utils/
    
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/utils/JavaScriptTestCase.java

Added: 
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/helloworld/HelloWorldService.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.javascript/src/test/java/helloworld/HelloWorldService.java?rev=427139&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/helloworld/HelloWorldService.java
 (added)
+++ 
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/helloworld/HelloWorldService.java
 Mon Jul 31 08:25:54 2006
@@ -0,0 +1,7 @@
+package helloworld;
+
+public interface HelloWorldService {
+
+       String sayHello(String s);
+
+}

Added: 
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/functional/HelloWorld.componentType
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/functional/HelloWorld.componentType?rev=427139&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/functional/HelloWorld.componentType
 (added)
+++ 
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/functional/HelloWorld.componentType
 Mon Jul 31 08:25:54 2006
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="ASCII"?>
+
+<componentType xmlns="http://www.osoa.org/xmlns/sca/1.0"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
+
+    <service name="HelloWorldService">
+        <interface.java interface="helloworld.HelloWorldService"/>
+    </service>
+
+</componentType>
\ No newline at end of file

Added: 
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/functional/HelloWorld.js
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/functional/HelloWorld.js?rev=427139&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/functional/HelloWorld.js
 (added)
+++ 
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/functional/HelloWorld.js
 Mon Jul 31 08:25:54 2006
@@ -0,0 +1,3 @@
+function sayHello(s) {
+       return "Hello " + s;
+}

Added: 
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/functional/HelloWorldTestCase.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/functional/HelloWorldTestCase.java?rev=427139&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/functional/HelloWorldTestCase.java
 (added)
+++ 
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/functional/HelloWorldTestCase.java
 Mon Jul 31 08:25:54 2006
@@ -0,0 +1,45 @@
+/**
+ *
+ *  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.javascript.functional;
+
+import helloworld.HelloWorldService;
+
+import org.apache.tuscany.container.javascript.utils.JavaScriptTestCase;
+import org.osoa.sca.CompositeContext;
+import org.osoa.sca.CurrentCompositeContext;
+
+/**
+ * This shows how to test the HelloWorld service component.
+ */
+public class HelloWorldTestCase extends JavaScriptTestCase {
+
+    private HelloWorldService helloWorldService;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        CompositeContext context = CurrentCompositeContext.getContext();
+        helloWorldService = context.locateService(HelloWorldService.class, 
"HelloWorldComponent");
+    }
+
+    protected void tearDown() throws Exception {
+    }
+
+    public void testHelloWorld() throws Exception {
+        assertEquals(helloWorldService.sayHello("petra"), "Hello petra");
+    }
+}

Added: 
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/functional/helloworld.scdl
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/functional/helloworld.scdl?rev=427139&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/functional/helloworld.scdl
 (added)
+++ 
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/functional/helloworld.scdl
 Mon Jul 31 08:25:54 2006
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ *  Copyright (c) 2006 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.
+ -->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0";
+           xmlns:js="http://tuscany.apache.org/xmlns/js/1.0";
+           name="HelloWorldComposite">
+
+    <component name="HelloWorldComponent">
+               <js:implementation.js 
script="org/apache/tuscany/container/javascript/functional/HelloWorld.js"/>
+    </component>
+
+</composite>
\ No newline at end of file

Added: 
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/utils/JavaScriptTestCase.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/utils/JavaScriptTestCase.java?rev=427139&view=auto
==============================================================================
--- 
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/utils/JavaScriptTestCase.java
 (added)
+++ 
incubator/tuscany/java/sca/containers/container.javascript/src/test/java/org/apache/tuscany/container/javascript/utils/JavaScriptTestCase.java
 Mon Jul 31 08:25:54 2006
@@ -0,0 +1,71 @@
+package org.apache.tuscany.container.javascript.utils;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import junit.framework.TestCase;
+
+import 
org.apache.tuscany.core.implementation.system.model.SystemCompositeImplementation;
+import org.apache.tuscany.core.launcher.CompositeContextImpl;
+import org.apache.tuscany.core.launcher.Launcher;
+import org.apache.tuscany.spi.TuscanyException;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.Deployer;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+
+public class JavaScriptTestCase extends TestCase {
+    private Launcher launcher;
+    private CompositeComponent<?> component;
+    private CompositeContextImpl context;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        ClassLoader cl = getClass().getClassLoader();
+        launcher = new Launcher();
+        launcher.setApplicationLoader(cl);
+        CompositeComponent<?> composite = 
launcher.bootRuntime(cl.getResource(Launcher.METAINF_SYSTEM_SCDL_PATH));
+        
+        addJavaScriptExtension(composite);
+        
+        component = 
launcher.bootApplication(cl.getResource("org/apache/tuscany/container/javascript/functional/helloworld.scdl"));
+        component.start();
+        context = new CompositeContextImpl(component);
+        context.start();
+    }
+
+    protected void addJavaScriptExtension(CompositeComponent<?> composite) {
+        Deployer deployer = (Deployer) 
composite.getChild("deployer").getServiceInstance();
+        
+        
+        URL scdlURL = 
getClass().getClassLoader().getResource("META-INF/sca/default.scdl");
+        URL extensionURL = scdlURL;
+
+        ClassLoader extensionCL = new URLClassLoader(new URL[]{extensionURL}, 
getClass().getClassLoader());
+
+        // create a ComponentDefinition to represent the component we are 
going to deploy
+        SystemCompositeImplementation implementation = new 
SystemCompositeImplementation();
+        implementation.setScdlLocation(scdlURL);
+        implementation.setClassLoader(extensionCL);
+        ComponentDefinition<SystemCompositeImplementation> definition =
+                new ComponentDefinition<SystemCompositeImplementation>("JS", 
implementation);
+
+        try {
+            CompositeComponent<?> parent = composite;
+            Component<?> component = deployer.deploy(parent, definition);
+            component.start();
+        } catch (LoaderException e) {
+            // FIXME handle the exception
+        } catch (TuscanyException e) {
+            // FIXME handle the exception
+        }
+        
+    }
+
+    protected void tearDown() throws Exception {
+        context.stop();
+        component.stop();
+        super.tearDown();
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to