Author: jboynes
Date: Wed Oct 18 22:23:25 2006
New Revision: 465498

URL: http://svn.apache.org/viewvc?view=rev&rev=465498
Log:
changes to support running tests from the itest plugin

Added:
    incubator/tuscany/sandbox/testing/core/src/main/java/testing/
    
incubator/tuscany/sandbox/testing/core/src/main/java/testing/HelloService.java  
 (with props)
    
incubator/tuscany/sandbox/testing/core/src/main/java/testing/HelloServiceImpl.java
   (with props)
    incubator/tuscany/sandbox/testing/core/src/main/resources/
    incubator/tuscany/sandbox/testing/core/src/main/resources/META-INF/
    incubator/tuscany/sandbox/testing/core/src/main/resources/META-INF/sca/
    
incubator/tuscany/sandbox/testing/core/src/main/resources/META-INF/sca/default.scdl
   (with props)
    
incubator/tuscany/sandbox/testing/itest/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyITestMojo.java
   (with props)
Modified:
    incubator/tuscany/sandbox/testing/core/pom.xml
    incubator/tuscany/sandbox/testing/core/src/test/java/testing/FooITest.java
    incubator/tuscany/sandbox/testing/itest/pom.xml
    
incubator/tuscany/sandbox/testing/itest/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java
    
incubator/tuscany/sandbox/testing/itest/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyStartMojo.java

Modified: incubator/tuscany/sandbox/testing/core/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/testing/core/pom.xml?view=diff&rev=465498&r1=465497&r2=465498
==============================================================================
--- incubator/tuscany/sandbox/testing/core/pom.xml (original)
+++ incubator/tuscany/sandbox/testing/core/pom.xml Wed Oct 18 22:23:25 2006
@@ -7,6 +7,11 @@
 
     <dependencies>
         <dependency>
+            <groupId>org.osoa</groupId>
+            <artifactId>sca-api-r0.95</artifactId>
+            <version>1.0-incubator-M2</version>
+        </dependency>
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <version>3.8.1</version>
@@ -17,25 +22,10 @@
         <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-surefire-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <id>itest</id>
-                        <phase>integration-test</phase>
-                        <goals>
-                            <goal>test</goal>
-                        </goals>
-                        <configuration>
-                            <includes>
-                                <include>**/*ITest.java</include>
-                            </includes>
-                        </configuration>
-                    </execution>
-                </executions>
+                <artifactId>maven-compiler-plugin</artifactId>
                 <configuration>
-                    <includes>
-                        <include>**/*TestCase.java</include>
-                    </includes>
+                    <source>1.5</source>
+                    <target>1.5</target>
                 </configuration>
             </plugin>
             <plugin>
@@ -49,12 +39,32 @@
                         </goals>
                     </execution>
                     <execution>
+                        <id>test</id>
+                        <goals>
+                            <goal>test</goal>
+                        </goals>
+                        <configuration>
+                            <includes>
+                                <include>**/*ITest.java</include>
+                            </includes>
+                        </configuration>
+                    </execution>
+                    <execution>
                         <id>stop</id>
                         <goals>
                             <goal>stop</goal>
                         </goals>
                     </execution>
                 </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <excludes>
+                        <exclude>**/*ITest.java</exclude>
+                    </excludes>
+                </configuration>
             </plugin>
         </plugins>
     </build>

Added: 
incubator/tuscany/sandbox/testing/core/src/main/java/testing/HelloService.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/testing/core/src/main/java/testing/HelloService.java?view=auto&rev=465498
==============================================================================
--- 
incubator/tuscany/sandbox/testing/core/src/main/java/testing/HelloService.java 
(added)
+++ 
incubator/tuscany/sandbox/testing/core/src/main/java/testing/HelloService.java 
Wed Oct 18 22:23:25 2006
@@ -0,0 +1,8 @@
+package testing;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface HelloService {
+    String getGreeting();
+}

Propchange: 
incubator/tuscany/sandbox/testing/core/src/main/java/testing/HelloService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/sandbox/testing/core/src/main/java/testing/HelloService.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
incubator/tuscany/sandbox/testing/core/src/main/java/testing/HelloServiceImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/testing/core/src/main/java/testing/HelloServiceImpl.java?view=auto&rev=465498
==============================================================================
--- 
incubator/tuscany/sandbox/testing/core/src/main/java/testing/HelloServiceImpl.java
 (added)
+++ 
incubator/tuscany/sandbox/testing/core/src/main/java/testing/HelloServiceImpl.java
 Wed Oct 18 22:23:25 2006
@@ -0,0 +1,11 @@
+package testing;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class HelloServiceImpl implements HelloService {
+
+    public String getGreeting() {
+        return "Hello World";
+    }
+}

Propchange: 
incubator/tuscany/sandbox/testing/core/src/main/java/testing/HelloServiceImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/sandbox/testing/core/src/main/java/testing/HelloServiceImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
incubator/tuscany/sandbox/testing/core/src/main/resources/META-INF/sca/default.scdl
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/testing/core/src/main/resources/META-INF/sca/default.scdl?view=auto&rev=465498
==============================================================================
--- 
incubator/tuscany/sandbox/testing/core/src/main/resources/META-INF/sca/default.scdl
 (added)
+++ 
incubator/tuscany/sandbox/testing/core/src/main/resources/META-INF/sca/default.scdl
 Wed Oct 18 22:23:25 2006
@@ -0,0 +1,26 @@
+<?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="TestingComposite">
+
+    <component name="HelloComponent">
+               <implementation.java class="testing.HelloServiceImpl"/>
+    </component>
+</composite>

Propchange: 
incubator/tuscany/sandbox/testing/core/src/main/resources/META-INF/sca/default.scdl
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/sandbox/testing/core/src/main/resources/META-INF/sca/default.scdl
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: 
incubator/tuscany/sandbox/testing/core/src/test/java/testing/FooITest.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/testing/core/src/test/java/testing/FooITest.java?view=diff&rev=465498&r1=465497&r2=465498
==============================================================================
--- incubator/tuscany/sandbox/testing/core/src/test/java/testing/FooITest.java 
(original)
+++ incubator/tuscany/sandbox/testing/core/src/test/java/testing/FooITest.java 
Wed Oct 18 22:23:25 2006
@@ -1,12 +1,26 @@
 package testing;
 
 import junit.framework.TestCase;
+import org.osoa.sca.CurrentCompositeContext;
 
 /**
  * @version $Rev$ $Date$
  */
 public class FooITest extends TestCase {
+    private HelloService service;
+
     public void testFoo() {
         System.out.println("Hello World");
+    }
+
+    public void testHelloWorld() {
+        assertEquals("Hello World", service.getGreeting());
+    }
+
+
+    protected void setUp() throws Exception {
+        super.setUp();
+//        service = new HelloServiceImpl();
+        service = 
CurrentCompositeContext.getContext().locateService(HelloService.class, 
"HelloComponent");
     }
 }

Modified: incubator/tuscany/sandbox/testing/itest/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/testing/itest/pom.xml?view=diff&rev=465498&r1=465497&r2=465498
==============================================================================
--- incubator/tuscany/sandbox/testing/itest/pom.xml (original)
+++ incubator/tuscany/sandbox/testing/itest/pom.xml Wed Oct 18 22:23:25 2006
@@ -36,6 +36,17 @@
             <artifactId>maven-plugin-api</artifactId>
             <version>2.0</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.maven.surefire</groupId>
+            <artifactId>surefire-api</artifactId>
+            <version>2.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.maven.surefire</groupId>
+            <artifactId>surefire-junit</artifactId>
+            <version>2.0</version>
+            <scope>runtime</scope>
+        </dependency>
 
         <dependency>
             <groupId>org.apache.tuscany.sca.kernel</groupId>
@@ -43,4 +54,16 @@
             <version>1.0-incubator-M2-SNAPSHOT</version>
         </dependency>
     </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.5</source>
+                    <target>1.5</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
 </project>

Modified: 
incubator/tuscany/sandbox/testing/itest/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/testing/itest/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java?view=diff&rev=465498&r1=465497&r2=465498
==============================================================================
--- 
incubator/tuscany/sandbox/testing/itest/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java
 (original)
+++ 
incubator/tuscany/sandbox/testing/itest/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java
 Wed Oct 18 22:23:25 2006
@@ -82,7 +82,6 @@
             // switch to the system deployer
             deployer = (Deployer) 
tuscanySystem.getSystemChild("deployer").getServiceInstance();
 
-/*
             application = deployApplicationScdl(deployer,
                 runtime.getRootComponent(),
                 getApplicationName(),
@@ -91,7 +90,6 @@
             application.start();
 
             context = new CompositeContextImpl(application);
-*/
         } catch (LoaderException e) {
             // FIXME do something with this
             e.printStackTrace();

Added: 
incubator/tuscany/sandbox/testing/itest/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyITestMojo.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/testing/itest/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyITestMojo.java?view=auto&rev=465498
==============================================================================
--- 
incubator/tuscany/sandbox/testing/itest/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyITestMojo.java
 (added)
+++ 
incubator/tuscany/sandbox/testing/itest/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyITestMojo.java
 Wed Oct 18 22:23:25 2006
@@ -0,0 +1,100 @@
+/*
+ * 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 org.apache.tuscany.sca.plugin.itest;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.surefire.Surefire;
+import org.apache.maven.surefire.testset.TestSetFailedException;
+import org.apache.maven.surefire.report.BriefFileReporter;
+import org.apache.maven.surefire.report.ReporterException;
+
+/**
+ * @version $Rev$ $Date$
+ * @goal test
+ * @phase integration-test
+ */
+public class TuscanyITestMojo extends AbstractMojo {
+    /**
+     * @parameter expression="${project.build.directory}/surefire-reports"
+     */
+    private File reportsDirectory;
+
+    /**
+     * Whether to trim the stack trace in the reports to just the lines within 
the test, or show the full trace.
+     *
+     * @parameter expression="${trimStackTrace}" default-value="true"
+     */
+    private boolean trimStackTrace;
+
+    /**
+     * The directory containing generated test classes of the project being 
tested.
+     *
+     * @parameter expression="${project.build.testOutputDirectory}"
+     * @required
+     */
+    private File testClassesDirectory;
+
+    /**
+     * @parameter
+     */
+    private List includes = new ArrayList();
+
+    /**
+     * @parameter
+     */
+    private List excludes = new ArrayList();
+
+    public void execute() throws MojoExecutionException, MojoFailureException {
+        System.out.println("Executing tests");
+
+        boolean success = runSurefire();
+        if (!success) {
+            String msg = "There were test failures";
+            throw new MojoFailureException(msg);
+        }
+    }
+
+    public boolean runSurefire() throws MojoExecutionException {
+        Surefire surefire = new Surefire();
+        ClassLoader surefireClassLoader = surefire.getClass().getClassLoader();
+
+        List reports = new ArrayList();
+        reports.add(new Object[]{BriefFileReporter.class.getName(),
+            new Object[]{reportsDirectory, trimStackTrace}});
+
+        List testSuites = new ArrayList();
+        testSuites.add(new 
Object[]{"org.apache.maven.surefire.junit.JUnitDirectoryTestSuite",
+            new Object[]{testClassesDirectory, includes, excludes}});
+
+        ClassLoader testsClassLoader = TuscanyStartMojo.foo.get();
+        try {
+            return surefire.run(reports, testSuites, surefireClassLoader, 
testsClassLoader);
+        } catch (ReporterException e) {
+            throw new MojoExecutionException(e.getMessage(), e);
+        } catch (TestSetFailedException e) {
+            throw new MojoExecutionException(e.getMessage(), e);
+        }
+    }
+}

Propchange: 
incubator/tuscany/sandbox/testing/itest/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyITestMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/tuscany/sandbox/testing/itest/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyITestMojo.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: 
incubator/tuscany/sandbox/testing/itest/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyStartMojo.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/sandbox/testing/itest/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyStartMojo.java?view=diff&rev=465498&r1=465497&r2=465498
==============================================================================
--- 
incubator/tuscany/sandbox/testing/itest/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyStartMojo.java
 (original)
+++ 
incubator/tuscany/sandbox/testing/itest/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyStartMojo.java
 Wed Oct 18 22:23:25 2006
@@ -19,6 +19,13 @@
 package org.apache.tuscany.sca.plugin.itest;
 
 import java.net.URL;
+import java.net.MalformedURLException;
+import java.net.URLClassLoader;
+import java.util.List;
+import java.util.Iterator;
+import java.util.Enumeration;
+import java.io.File;
+import java.io.IOException;
 
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -43,6 +50,15 @@
      */
     private URL applicationScdl;
 
+    /**
+     * @parameter expression="${project.testClasspathElements}"
+     * @required
+     * @readonly
+     */
+    private List testClassPath;
+
+    static ThreadLocal<ClassLoader> foo = new ThreadLocal<ClassLoader>();
+
     public void execute() throws MojoExecutionException, MojoFailureException {
         System.out.println("Starting Tuscany!");
 
@@ -56,13 +72,55 @@
         runtime.setMonitorFactory(runtime.createDefaultMonitorFactory());
         runtime.setSystemScdl(systemScdl);
         runtime.setHostClassLoader(hostClassLoader);
-/*
+
+        ClassLoader applicationClassLoader = createApplicationClassLoader();
+        if (applicationScdl == null) {
+            Enumeration resources;
+            try {
+                resources = 
applicationClassLoader.getResources("META-INF/sca/default.scdl");
+            } catch (IOException e) {
+                throw new MojoExecutionException(e.getMessage(), e);
+            }
+            if (!resources.hasMoreElements()) {
+                throw new MojoExecutionException("No SCDL found on test 
classpath");
+            }
+            applicationScdl = (URL) resources.nextElement();
+            if (resources.hasMoreElements()) {
+                StringBuffer msg = new StringBuffer();
+                msg.append("Multiple SCDL files found on test classpath:\n");
+                msg.append("  ").append(applicationScdl).append('\n');
+                do {
+                    msg.append("  
").append(resources.nextElement()).append('\n');
+                } while (resources.hasMoreElements());
+                throw new MojoExecutionException(msg.toString());
+            }
+        }
         runtime.setApplicationName("application");
         runtime.setApplicationScdl(applicationScdl);
         runtime.setApplicationClassLoader(applicationClassLoader);
-*/
         runtime.setRuntimeInfo(runtimeInfo);
         runtime.initialize();
         SCA context = runtime.getContext();
+        context.start();
+
+        foo.set(applicationClassLoader);
+    }
+
+    public ClassLoader createApplicationClassLoader() {
+        URL[] urls = new URL[testClassPath.size()];
+        int idx = 0;
+        for (Iterator i = testClassPath.iterator(); i.hasNext();) {
+            File pathElement = new File((String) i.next());
+            try {
+                URL url = pathElement.toURI().toURL();
+                getLog().debug("Adding application URL: " + url);
+                urls[idx++] = url;
+            } catch (MalformedURLException e) {
+                // toURI should have encoded the URL
+                throw new AssertionError();
+            }
+
+        }
+        return new URLClassLoader(urls);
     }
 }



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

Reply via email to