Author: bdelacretaz
Date: Wed Apr 29 15:37:11 2015
New Revision: 1676772

URL: http://svn.apache.org/r1676772
Log:
SLING-4681 - setReadinessContentType added

Modified:
    
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java

Modified: 
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java?rev=1676772&r1=1676771&r2=1676772&view=diff
==============================================================================
--- 
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java
 (original)
+++ 
sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java
 Wed Apr 29 15:37:11 2015
@@ -79,6 +79,9 @@ public class HttpTestBase extends TestCa
 
     public static final String SLING_POST_SERVLET_CREATE_SUFFIX = "/";
        public static final String DEFAULT_EXT = ".txt";
+       
+       private String readinessCheckExtension = ".txt";
+       private String readinessCheckContentTypePrefix = "text/plain";
 
        public static final String EXECUTE_RESOURCE_TYPE = "SlingTesting" + 
HttpTestBase.class.getSimpleName();
        private static int executeCounter;
@@ -272,7 +275,7 @@ public class HttpTestBase extends TestCa
         String urlOfNewNode = null; 
         try {
             urlOfNewNode = testClient.createNode(url, props, null, true);
-            final GetMethod get = new GetMethod(urlOfNewNode + DEFAULT_EXT);
+            final GetMethod get = new GetMethod(urlOfNewNode + 
readinessCheckExtension);
             final int status = httpClient.executeMethod(get);
             if(status!=200) {
                 throw new HttpStatusCodeException(200, status, "GET", 
urlOfNewNode);
@@ -280,8 +283,8 @@ public class HttpTestBase extends TestCa
 
             final Header h = get.getResponseHeader("Content-Type");
             final String contentType = h==null ? "" : h.getValue();
-            if(!contentType.startsWith("text/plain")) {
-                throw new IOException("Expected Content-Type=text/plain but 
got '" + contentType + "' for URL=" + urlOfNewNode);
+            if(!contentType.startsWith(readinessCheckContentTypePrefix)) {
+                throw new IOException("Expected Content-Type=" + 
readinessCheckContentTypePrefix + " but got '" + contentType + "' for URL=" + 
urlOfNewNode);
             }
 
             final String content = get.getResponseBodyAsString();
@@ -546,4 +549,10 @@ public class HttpTestBase extends TestCa
         }
         return content.toString();
     }
+
+    /** Set the extension and content-type prefix to use for GET requests that 
check Sling readiness */
+    public final void setReadinessContentType(String extension, String 
contentTypePrefix) {
+        readinessCheckExtension = extension;
+        readinessCheckContentTypePrefix = contentTypePrefix;
+    }
 }
\ No newline at end of file


Reply via email to