sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1070537 - in /sling/whiteboard/bdelacretaz/junit/remotejunit: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/sling/ src/main/java/org/apache/sling/junit/ src/main/java/org/apache/slin...
Date Mon, 14 Feb 2011 16:02:06 GMT
Author: bdelacretaz
Date: Mon Feb 14 16:02:05 2011
New Revision: 1070537

URL: http://svn.apache.org/viewvc?rev=1070537&view=rev
Log:
Experimenting with JUnit tests that would run on a remote Sling instance - all faked for now

Added:
    sling/whiteboard/bdelacretaz/junit/remotejunit/   (with props)
    sling/whiteboard/bdelacretaz/junit/remotejunit/pom.xml   (with props)
    sling/whiteboard/bdelacretaz/junit/remotejunit/src/
    sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/
    sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/
    sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/org/
    sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/org/apache/
    sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/org/apache/sling/
    sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/org/apache/sling/junit/
    sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/org/apache/sling/junit/remotejunit/
    sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/org/apache/sling/junit/remotejunit/RemoteTest.java
  (with props)
    sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/org/apache/sling/junit/remotejunit/RemoteTestConfig.java
  (with props)
    sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/org/apache/sling/junit/remotejunit/RemoteTestRunner.java
  (with props)
    sling/whiteboard/bdelacretaz/junit/remotejunit/src/test/
    sling/whiteboard/bdelacretaz/junit/remotejunit/src/test/java/
    sling/whiteboard/bdelacretaz/junit/remotejunit/src/test/java/org/
    sling/whiteboard/bdelacretaz/junit/remotejunit/src/test/java/org/apache/
    sling/whiteboard/bdelacretaz/junit/remotejunit/src/test/java/org/apache/sling/
    sling/whiteboard/bdelacretaz/junit/remotejunit/src/test/java/org/apache/sling/junit/
    sling/whiteboard/bdelacretaz/junit/remotejunit/src/test/java/org/apache/sling/junit/remotejunit/
    sling/whiteboard/bdelacretaz/junit/remotejunit/src/test/java/org/apache/sling/junit/remotejunit/test/
    sling/whiteboard/bdelacretaz/junit/remotejunit/src/test/java/org/apache/sling/junit/remotejunit/test/FirstRemoteTest.java
  (with props)
    sling/whiteboard/bdelacretaz/junit/remotejunit/src/test/java/org/apache/sling/junit/remotejunit/test/SecondRemoteTest.java
  (with props)

Propchange: sling/whiteboard/bdelacretaz/junit/remotejunit/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Feb 14 16:02:05 2011
@@ -0,0 +1,11 @@
+target
+bin
+*.iml
+*.ipr
+*.iws
+.settings
+.project
+.classpath
+.externalToolBuilders
+maven-eclipse.xml
+

Added: sling/whiteboard/bdelacretaz/junit/remotejunit/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/junit/remotejunit/pom.xml?rev=1070537&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/junit/remotejunit/pom.xml (added)
+++ sling/whiteboard/bdelacretaz/junit/remotejunit/pom.xml Mon Feb 14 16:02:05 2011
@@ -0,0 +1,36 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.sling</groupId>
+  <artifactId>org.apache.sling.junit.remotejunit</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <name>remotejunit</name>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <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>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.8.2</version>
+    </dependency>
+  </dependencies>
+</project>

Propchange: sling/whiteboard/bdelacretaz/junit/remotejunit/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/org/apache/sling/junit/remotejunit/RemoteTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/org/apache/sling/junit/remotejunit/RemoteTest.java?rev=1070537&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/org/apache/sling/junit/remotejunit/RemoteTest.java
(added)
+++ sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/org/apache/sling/junit/remotejunit/RemoteTest.java
Mon Feb 14 16:02:05 2011
@@ -0,0 +1,64 @@
+/*
+ * 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.sling.junit.remotejunit;
+
+import org.junit.runner.Description;
+
+/** Fake remote test, used to experiment with JUnit tests that
+ *  would run on a remote Sling instance.
+ */
+class RemoteTest {
+    private String name;
+    private Throwable throwable;
+    private Class<?> testClass;
+    
+    static RemoteTest parse(Class<?> c, String str) {
+        final String [] cfg = str.split("/");
+        final RemoteTest result = new RemoteTest();
+        result.testClass = c;
+        
+        if(cfg.length < 1) {
+            result.name = "NONAME??";
+        } else {
+            result.name = cfg[0];
+        }
+        
+        if(cfg.length == 3) {
+            if("ASSERT".equals(cfg[1])) {
+                result.throwable = new AssertionError(cfg[2]);
+            } else {
+                result.throwable = new IllegalStateException(cfg[2]);
+            }
+        }
+        
+        return result;
+    }
+    
+    String getName() {
+        return name;
+    }
+    
+    Description getDescription() {
+        return Description.createTestDescription(testClass, name);
+    }
+
+    void run() throws Throwable {
+        if(throwable != null) {
+            throw throwable;
+        }
+    }
+}

Propchange: sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/org/apache/sling/junit/remotejunit/RemoteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/org/apache/sling/junit/remotejunit/RemoteTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/org/apache/sling/junit/remotejunit/RemoteTestConfig.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/org/apache/sling/junit/remotejunit/RemoteTestConfig.java?rev=1070537&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/org/apache/sling/junit/remotejunit/RemoteTestConfig.java
(added)
+++ sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/org/apache/sling/junit/remotejunit/RemoteTestConfig.java
Mon Feb 14 16:02:05 2011
@@ -0,0 +1,30 @@
+/*
+ * 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.sling.junit.remotejunit;
+
+/** Test classes implement this interface to provide the runner
+ *  with test parameters (mostly JUnitServlet paths that select
+ *  which tests to run).
+ *  
+ *  We could use annotations but this is (arguably) easier to write,
+ *  and more importantly an interface allows the test to query 
+ *  the Sling instance for tests that are available based on the
+ *  test's base path.
+ */
+public interface RemoteTestConfig {
+    String[] getTestURI();
+}

Propchange: sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/org/apache/sling/junit/remotejunit/RemoteTestConfig.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/org/apache/sling/junit/remotejunit/RemoteTestConfig.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/org/apache/sling/junit/remotejunit/RemoteTestRunner.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/org/apache/sling/junit/remotejunit/RemoteTestRunner.java?rev=1070537&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/org/apache/sling/junit/remotejunit/RemoteTestRunner.java
(added)
+++ sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/org/apache/sling/junit/remotejunit/RemoteTestRunner.java
Mon Feb 14 16:02:05 2011
@@ -0,0 +1,75 @@
+/*
+ * 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.sling.junit.remotejunit;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.internal.AssumptionViolatedException;
+import org.junit.internal.runners.model.EachTestNotifier;
+import org.junit.runner.Description;
+import org.junit.runner.notification.RunNotifier;
+import org.junit.runners.ParentRunner;
+import org.junit.runners.model.InitializationError;
+
+/** Fake remote test runner, used to experiment with JUnit tests 
+ *  that would run on a remote Sling instance.
+ */
+public class RemoteTestRunner extends ParentRunner<RemoteTest> {
+
+    private final List<RemoteTest> children = new ArrayList<RemoteTest>();
+    
+    public RemoteTestRunner(Class<?> testClass) throws InitializationError {
+        super(testClass);
+        
+        try {
+            final RemoteTestConfig cfg = (RemoteTestConfig)testClass.newInstance();
+            for(String str : cfg.getTestURI()) {
+                children.add(RemoteTest.parse(testClass, str));
+            }
+        } catch(Exception e) {
+            final Throwable [] t = { e };
+            throw new InitializationError(Arrays.asList(t));
+        }
+    }
+
+    @Override
+    protected Description describeChild(RemoteTest t) {
+        return t.getDescription();
+    }
+
+    @Override
+    protected List<RemoteTest> getChildren() {
+        return children;
+    }
+
+    @Override
+    protected void runChild(RemoteTest t, RunNotifier n) {
+        EachTestNotifier eachNotifier= new EachTestNotifier(n, t.getDescription());
+        eachNotifier.fireTestStarted();
+        try {
+            t.run();
+        } catch (AssumptionViolatedException e) {
+            eachNotifier.addFailedAssumption(e);
+        } catch (Throwable e) {
+            eachNotifier.addFailure(e);
+        } finally {
+            eachNotifier.fireTestFinished();
+        }
+    }
+}

Propchange: sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/org/apache/sling/junit/remotejunit/RemoteTestRunner.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/bdelacretaz/junit/remotejunit/src/main/java/org/apache/sling/junit/remotejunit/RemoteTestRunner.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: sling/whiteboard/bdelacretaz/junit/remotejunit/src/test/java/org/apache/sling/junit/remotejunit/test/FirstRemoteTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/junit/remotejunit/src/test/java/org/apache/sling/junit/remotejunit/test/FirstRemoteTest.java?rev=1070537&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/junit/remotejunit/src/test/java/org/apache/sling/junit/remotejunit/test/FirstRemoteTest.java
(added)
+++ sling/whiteboard/bdelacretaz/junit/remotejunit/src/test/java/org/apache/sling/junit/remotejunit/test/FirstRemoteTest.java
Mon Feb 14 16:02:05 2011
@@ -0,0 +1,40 @@
+/*
+ * 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.sling.junit.remotejunit.test;
+
+import org.apache.sling.junit.remotejunit.RemoteTestConfig;
+import org.apache.sling.junit.remotejunit.RemoteTestRunner;
+import org.junit.runner.RunWith;
+
+/** Remote tests would just define the paths of the JUnitServlet
+ *  tests to run. The RemoteTestRunner runs the corresponding tests
+ *  and outputs results as if the tests were local.
+ */
+@RunWith(RemoteTestRunner.class)
+public class FirstRemoteTest implements RemoteTestConfig {
+
+    /** This could call a remote Sling instance to find out
+     *  which tests are available at this test's base path.
+     */
+    public String[] getTestURI() {
+        return new String[] {
+            "Simulating a remote test that passes",
+            "Simulating a remote test where an assertion fails/ASSERT/Let's say some assertion
failed",
+            "Simulating a remote test that causes a failure/FAIL/Something went very wrong"
+        };
+    }
+}

Propchange: sling/whiteboard/bdelacretaz/junit/remotejunit/src/test/java/org/apache/sling/junit/remotejunit/test/FirstRemoteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/bdelacretaz/junit/remotejunit/src/test/java/org/apache/sling/junit/remotejunit/test/FirstRemoteTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: sling/whiteboard/bdelacretaz/junit/remotejunit/src/test/java/org/apache/sling/junit/remotejunit/test/SecondRemoteTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/junit/remotejunit/src/test/java/org/apache/sling/junit/remotejunit/test/SecondRemoteTest.java?rev=1070537&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/junit/remotejunit/src/test/java/org/apache/sling/junit/remotejunit/test/SecondRemoteTest.java
(added)
+++ sling/whiteboard/bdelacretaz/junit/remotejunit/src/test/java/org/apache/sling/junit/remotejunit/test/SecondRemoteTest.java
Mon Feb 14 16:02:05 2011
@@ -0,0 +1,37 @@
+/*
+ * 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.sling.junit.remotejunit.test;
+
+import java.util.Date;
+
+import org.apache.sling.junit.remotejunit.RemoteTestConfig;
+import org.apache.sling.junit.remotejunit.RemoteTestRunner;
+import org.junit.runner.RunWith;
+
+/** Another remote test example */
+@RunWith(RemoteTestRunner.class)
+public class SecondRemoteTest implements RemoteTestConfig {
+    
+    public String[] getTestURI() {
+        return new String[] {
+            "Fake remote test 1 that passes",
+            "Fake remote test 2 that passes",
+            "Fake remote test 3 that asserts/ASSERT/It's too late: " + new Date(),
+            "Fake remote test 4 that passes",
+        };
+    }
+}

Propchange: sling/whiteboard/bdelacretaz/junit/remotejunit/src/test/java/org/apache/sling/junit/remotejunit/test/SecondRemoteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/bdelacretaz/junit/remotejunit/src/test/java/org/apache/sling/junit/remotejunit/test/SecondRemoteTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message