tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r427514 - /incubator/tuscany/java/sca/test/src/main/java/org/apache/tuscany/test/SCATestCase.java
Date Tue, 01 Aug 2006 10:21:45 GMT
Author: antelder
Date: Tue Aug  1 03:21:43 2006
New Revision: 427514

URL: http://svn.apache.org/viewvc?rev=427514&view=rev
Log:
Add support for testcases customizing the SCA runtime environment for the testcase by add
extensions and to change the default location of the application SCDL 

Modified:
    incubator/tuscany/java/sca/test/src/main/java/org/apache/tuscany/test/SCATestCase.java

Modified: incubator/tuscany/java/sca/test/src/main/java/org/apache/tuscany/test/SCATestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/test/src/main/java/org/apache/tuscany/test/SCATestCase.java?rev=427514&r1=427513&r2=427514&view=diff
==============================================================================
--- incubator/tuscany/java/sca/test/src/main/java/org/apache/tuscany/test/SCATestCase.java
(original)
+++ incubator/tuscany/java/sca/test/src/main/java/org/apache/tuscany/test/SCATestCase.java
Tue Aug  1 03:21:43 2006
@@ -16,11 +16,21 @@
  */
 package org.apache.tuscany.test;
 
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.HashMap;
+import java.util.Map;
+
 import junit.framework.TestCase;
 
-import org.apache.tuscany.core.launcher.Launcher;
+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.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;
 
 /**
  * Base class for JUnit tests that want to run in an SCA client environment.
@@ -31,17 +41,57 @@
     private Launcher launcher;
     private CompositeComponent<?> component;
     private CompositeContextImpl context;
+    private Map<String, URL> extensions = new HashMap<String, URL>();
+    private String applicationSCDL = Launcher.METAINF_APPLICATION_SCDL_PATH;
 
     protected void setUp() throws Exception {
         super.setUp();
         ClassLoader cl = getClass().getClassLoader();
         launcher = new Launcher();
         launcher.setApplicationLoader(cl);
-        launcher.bootRuntime(cl.getResource(Launcher.METAINF_SYSTEM_SCDL_PATH));
-        component = launcher.bootApplication(cl.getResource(Launcher.METAINF_APPLICATION_SCDL_PATH));
+        CompositeComponent<?> composite = launcher.bootRuntime(cl.getResource(Launcher.METAINF_SYSTEM_SCDL_PATH));
+
+        for (String extensionName : extensions.keySet()) {
+            deployExtension(composite, extensionName, extensions.get(extensionName));
+        }
+        
+        URL applicationScdlURL = cl.getResource(applicationSCDL);
+        if (applicationScdlURL == null) {
+            throw new RuntimeException("application SCDL not found: " + applicationSCDL);
+        }
+        component = launcher.bootApplication(applicationScdlURL);
         component.start();
         context = new CompositeContextImpl(component);
         context.start();
+    }
+
+    /**
+     * A TestCase can use this to overide the default SCDL location of "META-INF/sca/default.scdl"
+     */
+    protected void setApplicationSCDL(String applicationSCDL) {
+        this.applicationSCDL = applicationSCDL;
+    }
+
+    /**
+     * A TestCase can use this to add the SCDL location of an extention to be deployed to
the runtime
+     */
+    protected void addExtension(String extensionName, URL extentionSCDL) {
+        extensions.put(extensionName, extentionSCDL);
+    }
+
+    @SuppressWarnings("unchecked")
+    protected void deployExtension(CompositeComponent<?> composite, String extensionName,
URL scdlURL) throws LoaderException {
+        SystemCompositeImplementation implementation = new SystemCompositeImplementation();
+        implementation.setScdlLocation(scdlURL);
+        implementation.setClassLoader(new URLClassLoader(new URL[] { scdlURL }, getClass().getClassLoader()));
+
+        ComponentDefinition<SystemCompositeImplementation> definition = new ComponentDefinition<SystemCompositeImplementation>(extensionName,
+                implementation);
+
+        Deployer deployer = (Deployer) composite.getChild("deployer").getServiceInstance();
+        Component<?> component = deployer.deploy(composite, definition);
+
+        component.start();
     }
 
     protected void tearDown() throws Exception {



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


Mime
View raw message