incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1073087 - in /sling/trunk/testing/samples/test-tools: ./ src/test/java/org/apache/sling/testing/samples/testtools/ src/test/java/org/apache/sling/testing/samples/testtools/serverside/
Date Mon, 21 Feb 2011 17:36:09 GMT
Author: bdelacretaz
Date: Mon Feb 21 17:36:09 2011
New Revision: 1073087

URL: http://svn.apache.org/viewvc?rev=1073087&view=rev
Log:
SLING-1981 - JSONResponseTest added (ignored for now, fails)

Added:
    sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/samples/testtools/serverside/JSONResponseTest.java
  (with props)
    sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/samples/testtools/serverside/ServerSideTestsBase.java
  (with props)
Modified:
    sling/trunk/testing/samples/test-tools/pom.xml
    sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/samples/testtools/SlingTestBase.java
    sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/samples/testtools/serverside/ServerSideTest.java

Modified: sling/trunk/testing/samples/test-tools/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/test-tools/pom.xml?rev=1073087&r1=1073086&r2=1073087&view=diff
==============================================================================
--- sling/trunk/testing/samples/test-tools/pom.xml (original)
+++ sling/trunk/testing/samples/test-tools/pom.xml Mon Feb 21 17:36:09 2011
@@ -106,7 +106,7 @@
                         <configuration>
                             <outputDirectory>${project.build.directory}/sling/additional-bundles</outputDirectory>
                             <includeArtifactIds>
-                                org.apache.sling.junit.core,org.apache.sling.testing.samples.testbundle
+                                org.apache.sling.junit.core,org.apache.sling.testing.samples.testbundle,org.apache.sling.junit.scriptable
                             </includeArtifactIds>
                             <excludeTransitive>true</excludeTransitive>
                             <overWriteReleases>false</overWriteReleases>
@@ -167,6 +167,12 @@
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.junit.scriptable</artifactId>
+            <version>0.1.1-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.testing.samples.testbundle</artifactId>
             <version>0.1.1-SNAPSHOT</version>
             <scope>provided</scope>
@@ -185,6 +191,11 @@
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.json</artifactId>
+            <version>2.0.6</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.launchpad</artifactId>
             <classifier>standalone</classifier>
             <version>6-SNAPSHOT</version>

Modified: sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/samples/testtools/SlingTestBase.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/samples/testtools/SlingTestBase.java?rev=1073087&r1=1073086&r2=1073087&view=diff
==============================================================================
--- sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/samples/testtools/SlingTestBase.java
(original)
+++ sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/samples/testtools/SlingTestBase.java
Mon Feb 21 17:36:09 2011
@@ -63,6 +63,7 @@ public class SlingTestBase {
             log.info(TEST_SERVER_URL_PROP + " is set: not starting server jar (" + serverBaseUrl
+ ")");
         } else {
             final JarExecutor j = JarExecutor.getInstance(System.getProperties());
+            log.info(TEST_SERVER_URL_PROP + " not set, starting server jar {}", j);
             j.start();
             serverBaseUrl = "http://localhost:" + j.getServerPort();
             

Added: sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/samples/testtools/serverside/JSONResponseTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/samples/testtools/serverside/JSONResponseTest.java?rev=1073087&view=auto
==============================================================================
--- sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/samples/testtools/serverside/JSONResponseTest.java
(added)
+++ sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/samples/testtools/serverside/JSONResponseTest.java
Mon Feb 21 17:36:09 2011
@@ -0,0 +1,113 @@
+/*
+ * 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.testing.samples.testtools.serverside;
+
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.sling.commons.json.JSONArray;
+import org.apache.sling.commons.json.JSONObject;
+import org.apache.sling.commons.json.JSONTokener;
+import org.apache.stanbol.commons.testing.http.Request;
+import org.apache.stanbol.commons.testing.http.RetryLoop;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Test the JSON list of tests returned by the JUnit servlet, as an
+ *  example of testing JSON responses.
+ */
+public class JSONResponseTest extends ServerSideTestsBase {
+    
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    
+    // TODO compute those timeouts based on a configured factor
+    // to cope with slower testing systems??
+    public static final int TEST_LIST_TIMEOUT_SECONDS = 30;
+    
+    @Test
+    @Ignore // TODO: fails in mvn build, why??
+    public void testWithRetries() {
+        // Need a retry loop as the tests might still be registering
+        // when this test runs...we'd need to make the readyness detection
+        // more extensive to avoid this
+        final RetryLoop.Condition c = new RetryLoop.Condition() {
+
+            public String getDescription() {
+                return "Checking JSON list of server-side tests";
+            }
+
+            public boolean isTrue() throws Exception {
+                testJsonListOfTests();
+                return true;
+            }
+        };
+
+        log.info("{} (timeout={} seconds)", c.getDescription(), TEST_LIST_TIMEOUT_SECONDS);
+        new RetryLoop(c, TEST_LIST_TIMEOUT_SECONDS, 500);
+    }
+
+    private void testJsonListOfTests() throws Exception {
+        Request r = builder.buildGetRequest(JUNIT_SERVLET_PATH + "/.json");
+        
+        // Get list of tests in JSON format
+        executor.execute(r)
+        .assertStatus(200)
+        .assertContentType("application/json");
+        
+        // Parse JSON response for more precise testing
+        final JSONArray json = new JSONArray(new JSONTokener((executor.getContent())));
+        
+        // Verify that all our test names are in the response
+        final List<String> expectedTestNames = Arrays.asList(new String []{
+                "org.apache.sling.junit.scriptable.ScriptableTestsProvider",
+                "org.apache.sling.junit.testbundle.tests.JUnit3Test",
+                "org.apache.sling.junit.testbundle.tests.JUnit4Test",
+                "org.apache.sling.junit.testbundle.tests.MissingTest",
+                "org.apache.sling.junit.testbundle.tests.OsgiAwareTest"
+        });
+
+        // Response contains an array of objects identified by 
+        // their INFO_TYPE and INFO_SUBTYPE: check the one
+        // that has type=list and subtype=testNames
+        boolean dataFound = false;
+        for(int i = 0 ; i < json.length(); i++) {
+            final JSONObject obj = json.getJSONObject(i);
+            if("list".equals(obj.getString("INFO_TYPE")) && "testNames".equals(obj.getString("INFO_SUBTYPE")))
{
+                dataFound = true;
+                final JSONArray data = obj.getJSONArray("data");
+                assertEquals("Expecting correct number of tests", expectedTestNames.size(),
data.length());
+                
+                int matched = 0;
+                for(int j=0; j < data.length(); j++) {
+                    if(expectedTestNames.contains(data.getString(j))) {
+                        matched++;
+                    }
+                }
+                assertEquals("Expecting to find all test names in data array", expectedTestNames.size(),
matched);
+            }
+        }
+        
+        if(!dataFound) {
+            fail("Test names object not found in response");
+        }
+    }
+}
\ No newline at end of file

Propchange: sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/samples/testtools/serverside/JSONResponseTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/samples/testtools/serverside/JSONResponseTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/samples/testtools/serverside/ServerSideTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/samples/testtools/serverside/ServerSideTest.java?rev=1073087&r1=1073086&r2=1073087&view=diff
==============================================================================
--- sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/samples/testtools/serverside/ServerSideTest.java
(original)
+++ sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/samples/testtools/serverside/ServerSideTest.java
Mon Feb 21 17:36:09 2011
@@ -16,49 +16,14 @@
  */
 package org.apache.sling.testing.samples.testtools.serverside;
 
-import org.apache.sling.testing.samples.testtools.SlingTestBase;
-import org.apache.stanbol.commons.testing.http.RetryLoop;
-import org.junit.Before;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /** Run all server-side tests */ 
-public class ServerSideTest extends SlingTestBase {
-    public static final String JUNIT_SERVLET_PATH = "/system/sling/junit";
-    private static boolean junitServletOk;
+public class ServerSideTest extends ServerSideTestsBase {
     private final Logger log = LoggerFactory.getLogger(getClass());
     
-    // TODO compute those timeouts based on a configured factor
-    // to cope with slower testing systems??
-    public static final int JUNIT_SERVLET_TIMEOUT_SECONDS = 60;
-    
-    @Before
-    public void checkJunitServletPresent() throws Exception {
-        if(junitServletOk) {
-            return;
-        }
-    
-        // Retry accessing the junit servlet until it responds or timeout
-        // (as we might just have installed the required bundles)
-        final RetryLoop.Condition c = new RetryLoop.Condition() {
-            public String getDescription() {
-                return "Checking that " + JUNIT_SERVLET_PATH + " returns 200";
-            }
-
-            public boolean isTrue() throws Exception {
-                executor.execute(
-                        builder.buildGetRequest(JUNIT_SERVLET_PATH))
-                .assertStatus(200);
-                return true;
-            }
-                
-        };
-        
-        new RetryLoop(c, JUNIT_SERVLET_TIMEOUT_SECONDS, 500); 
-        junitServletOk = true;
-    }
-    
     @Test
     public void testNothing() {
         // TODO run the actual tests via junit servlet

Added: sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/samples/testtools/serverside/ServerSideTestsBase.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/samples/testtools/serverside/ServerSideTestsBase.java?rev=1073087&view=auto
==============================================================================
--- sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/samples/testtools/serverside/ServerSideTestsBase.java
(added)
+++ sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/samples/testtools/serverside/ServerSideTestsBase.java
Mon Feb 21 17:36:09 2011
@@ -0,0 +1,65 @@
+/*
+ * 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.testing.samples.testtools.serverside;
+
+import org.apache.sling.testing.samples.testtools.SlingTestBase;
+import org.apache.stanbol.commons.testing.http.RetryLoop;
+import org.junit.Before;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Base class for tests that require the server-side test bundles
+ *  to be active.
+ */
+public class ServerSideTestsBase extends SlingTestBase {
+    public static final String JUNIT_SERVLET_PATH = "/system/sling/junit";
+    
+    private static boolean junitServletOk;
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    
+    // TODO compute those timeouts based on a configured factor
+    // to cope with slower testing systems??
+    public static final int JUNIT_SERVLET_TIMEOUT_SECONDS = 60;
+    
+    @Before
+    public void checkJunitServletPresent() throws Exception {
+        if(junitServletOk) {
+            return;
+        }
+
+        // Retry accessing the junit servlet until it responds or timeout
+        // (as we might just have installed the required bundles)
+        final int expectedStatus = 200;
+        final RetryLoop.Condition c = new RetryLoop.Condition() {
+            public String getDescription() {
+                return "Checking that " + JUNIT_SERVLET_PATH + " returns " + expectedStatus;
+            }
+
+            public boolean isTrue() throws Exception {
+                executor.execute(
+                        builder.buildGetRequest(JUNIT_SERVLET_PATH))
+                .assertStatus(expectedStatus);
+                return true;
+            }
+                
+        };
+        
+        log.info(c.getDescription());
+        new RetryLoop(c, JUNIT_SERVLET_TIMEOUT_SECONDS, 500); 
+        junitServletOk = true;
+    }
+}

Propchange: sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/samples/testtools/serverside/ServerSideTestsBase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/samples/testtools/serverside/ServerSideTestsBase.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message