incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1446510 - in /sling/trunk/testing: junit/remote/src/main/java/org/apache/sling/junit/remote/httpclient/ junit/remote/src/main/java/org/apache/sling/junit/remote/ide/ junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/ samp...
Date Fri, 15 Feb 2013 11:00:41 GMT
Author: bdelacretaz
Date: Fri Feb 15 11:00:40 2013
New Revision: 1446510

URL: http://svn.apache.org/r1446510
Log:
SLING-2419 - support non-default credential in test utilities - patch contributed by Mark
Adamcin, thanks!

Modified:
    sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/httpclient/RemoteTestHttpClient.java
    sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/ide/SlingRemoteExecutionRule.java
    sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestRunner.java
    sling/trunk/testing/samples/integration-tests/pom.xml
    sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/http/OsgiConsoleTest.java
    sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/FailingTestsTest.java
    sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/JSONResponseTest.java
    sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/ServerSideTestsBase.java
    sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/scriptable/ScriptableTestsTest.java
    sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideTestsBase.java
    sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/http/RetryingContentChecker.java
    sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/sling/SlingTestBase.java

Modified: sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/httpclient/RemoteTestHttpClient.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/httpclient/RemoteTestHttpClient.java?rev=1446510&r1=1446509&r2=1446510&view=diff
==============================================================================
--- sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/httpclient/RemoteTestHttpClient.java
(original)
+++ sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/httpclient/RemoteTestHttpClient.java
Fri Feb 15 11:00:40 2013
@@ -34,18 +34,36 @@ public class RemoteTestHttpClient {
     private final Logger log = LoggerFactory.getLogger(getClass());
     
     private final String junitServletUrl;
+    private final String username;
+    private final String password;
     private StringBuilder subpath;
     private boolean consumeContent;
     private RequestCustomizer requestCustomizer;
     private static final String SLASH = "/";
     private static final String DOT = ".";
-    
+
     public RemoteTestHttpClient(String junitServletUrl, boolean consumeContent) {
+        this(junitServletUrl, null, null, consumeContent);
+    }
+    
+    public RemoteTestHttpClient(String junitServletUrl, String username, String password,
boolean consumeContent) {
         if(junitServletUrl == null) {
             throw new IllegalArgumentException("JUnit servlet URL is null, cannot run tests");
         }
         this.junitServletUrl = junitServletUrl;
         this.consumeContent = consumeContent;
+
+        if (username != null) {
+            this.username = username;
+        } else {
+            this.username = SlingTestBase.ADMIN;
+        }
+
+        if (password != null) {
+            this.password = password;
+        } else {
+            this.password = SlingTestBase.ADMIN;
+        }
     }
     
     public void setRequestCustomizer(RequestCustomizer c) {
@@ -87,11 +105,11 @@ public class RemoteTestHttpClient {
         }
         subpath.append(extension);
         
-        log.info("Executing test remotely, path={} JUnit servlet URL={}", 
+        log.info("Executing test remotely, path={} JUnit servlet URL={}",
                 subpath, junitServletUrl);
         final Request r = builder
         .buildPostRequest(subpath.toString())
-        .withCredentials(SlingTestBase.ADMIN, SlingTestBase.ADMIN)
+        .withCredentials(username, password)
         .withCustomizer(requestCustomizer);
         executor.execute(r).assertStatus(200);
 

Modified: sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/ide/SlingRemoteExecutionRule.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/ide/SlingRemoteExecutionRule.java?rev=1446510&r1=1446509&r2=1446510&view=diff
==============================================================================
--- sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/ide/SlingRemoteExecutionRule.java
(original)
+++ sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/ide/SlingRemoteExecutionRule.java
Fri Feb 15 11:00:40 2013
@@ -40,6 +40,8 @@ public class SlingRemoteExecutionRule im
 
    /** Name of the system property that activates remote test execution */
    public static final String SLING_REMOTE_TEST_URL = "sling.remote.test.url";
+   public static final String SLING_REMOTE_TEST_USERNAME = "sling.remote.test.username";
+   public static final String SLING_REMOTE_TEST_PASSWORD = "sling.remote.test.password";
    
    public Statement apply(final Statement base, final FrameworkMethod method, Object target)
{
        return new Statement() {
@@ -63,21 +65,24 @@ public class SlingRemoteExecutionRule im
     */
    private boolean tryRemoteEvaluation(FrameworkMethod method) throws Throwable {
        String remoteUrl = System.getProperty(SLING_REMOTE_TEST_URL);
+       String remoteUsername = System.getProperty(SLING_REMOTE_TEST_USERNAME);
+       String remotePassword = System.getProperty(SLING_REMOTE_TEST_PASSWORD);
+
        if(remoteUrl != null) {
            remoteUrl = remoteUrl.trim();
            if(remoteUrl.length() > 0) {
-               invokeRemote(remoteUrl, method);
+               invokeRemote(remoteUrl, remoteUsername, remotePassword, method);
                return true;
            }
        }
        return false;
    }
 
-   private void invokeRemote(String remoteUrl, FrameworkMethod method) throws Throwable {
+   private void invokeRemote(String remoteUrl, String remoteUsername, String remotePassword,
FrameworkMethod method) throws Throwable {
        final String testClassesSelector = method.getMethod().getDeclaringClass().getName();
        final String methodName = method.getMethod().getName();
        
-       final RemoteTestHttpClient testHttpClient = new RemoteTestHttpClient(remoteUrl, false);
+       final RemoteTestHttpClient testHttpClient = new RemoteTestHttpClient(remoteUrl, remoteUsername,
remotePassword, false);
        testHttpClient.setRequestCustomizer(this);
        final RequestExecutor executor = testHttpClient.runTests(
                testClassesSelector, methodName, "serialized"

Modified: sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestRunner.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestRunner.java?rev=1446510&r1=1446509&r2=1446510&view=diff
==============================================================================
--- sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestRunner.java
(original)
+++ sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestRunner.java
Fri Feb 15 11:00:40 2013
@@ -25,6 +25,7 @@ import org.apache.sling.commons.json.JSO
 import org.apache.sling.junit.remote.httpclient.RemoteTestHttpClient;
 import org.apache.sling.testing.tools.http.RequestCustomizer;
 import org.apache.sling.testing.tools.http.RequestExecutor;
+import org.apache.sling.testing.tools.sling.SlingTestBase;
 import org.junit.internal.AssumptionViolatedException;
 import org.junit.internal.runners.model.EachTestNotifier;
 import org.junit.runner.Description;
@@ -45,6 +46,8 @@ public class SlingRemoteTestRunner exten
     private static final Logger log = LoggerFactory.getLogger(SlingRemoteTestRunner.class);
     private final SlingRemoteTestParameters testParameters;
     private RemoteTestHttpClient testHttpClient;
+    private final String username;
+    private final String password;
     private final Class<?> testClass;
     
     private final List<SlingRemoteTest> children = new LinkedList<SlingRemoteTest>();
@@ -64,6 +67,22 @@ public class SlingRemoteTestRunner exten
             throw new InitializationError(e);
         }
         
+        // Set configured username using "admin" as default credential
+        final String configuredUsername = System.getProperty(SlingTestBase.TEST_SERVER_USERNAME);
+        if (configuredUsername != null && configuredUsername.trim().length() >
0) {
+            username = configuredUsername;
+        } else {
+            username = SlingTestBase.ADMIN;
+        }
+
+        // Set configured password using "admin" as default credential
+        final String configuredPassword = System.getProperty(SlingTestBase.TEST_SERVER_PASSWORD);
+        if (configuredPassword != null && configuredPassword.trim().length() >
0) {
+            password = configuredPassword;
+        } else {
+            password = SlingTestBase.ADMIN;
+        }
+        
         testParameters = (SlingRemoteTestParameters)o;
     }
     
@@ -73,7 +92,7 @@ public class SlingRemoteTestRunner exten
             return;
         }
         
-        testHttpClient = new RemoteTestHttpClient(testParameters.getJunitServletUrl(), true);
+        testHttpClient = new RemoteTestHttpClient(testParameters.getJunitServletUrl(), this.username,
this.password, true);
 
         // Let the parameters class customize the request if desired 
         if(testParameters instanceof RequestCustomizer) {
@@ -99,8 +118,8 @@ public class SlingRemoteTestRunner exten
             }
         }
         
-        log.info("Server-side tests executed at {} with path {}", 
-                testParameters.getJunitServletUrl(), testHttpClient.getTestExecutionPath());
+        log.info("Server-side tests executed as {} at {} with path {}",
+                new Object[]{this.username, testParameters.getJunitServletUrl(), testHttpClient.getTestExecutionPath()});
         
         // Optionally check that number of tests is as expected
         if(testParameters instanceof SlingTestsCountChecker) {
@@ -144,4 +163,4 @@ public class SlingRemoteTestRunner exten
             eachNotifier.fireTestFinished();
         }
     }
-}
\ No newline at end of file
+}

Modified: sling/trunk/testing/samples/integration-tests/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/pom.xml?rev=1446510&r1=1446509&r2=1446510&view=diff
==============================================================================
--- sling/trunk/testing/samples/integration-tests/pom.xml (original)
+++ sling/trunk/testing/samples/integration-tests/pom.xml Fri Feb 15 11:00:40 2013
@@ -65,6 +65,12 @@
         
          <!-- Set this to run tests against a specific hostname, if test.server.url is
not set-->
          <test.server.hostname />
+
+        <!-- Set this to use a different username for remote execution of sling junit
tests -->
+        <test.server.username />
+
+        <!-- Set this to use a different password for remote execution of sling junit
tests -->
+        <test.server.password />
         
         <!-- Options for the VM that executes our runnable jar -->
         <jar.executor.vm.options>-Xmx512m</jar.executor.vm.options>
@@ -199,6 +205,8 @@
                     <systemPropertyVariables>
                         <test.server.url>${test.server.url}</test.server.url>
                         <test.server.hostname>${test.server.hostname}</test.server.hostname>
+                        <test.server.username>${test.server.username}</test.server.username>
+                        <test.server.password>${test.server.password}</test.server.password>
                         <jar.executor.server.port>${http.port}</jar.executor.server.port>
                         <jar.executor.vm.options>${jar.executor.vm.options}</jar.executor.vm.options>
                         <jar.executor.jar.folder>${project.basedir}/target/dependency</jar.executor.jar.folder>

Modified: sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/http/OsgiConsoleTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/http/OsgiConsoleTest.java?rev=1446510&r1=1446509&r2=1446510&view=diff
==============================================================================
--- sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/http/OsgiConsoleTest.java
(original)
+++ sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/http/OsgiConsoleTest.java
Fri Feb 15 11:00:40 2013
@@ -43,7 +43,7 @@ public class OsgiConsoleTest extends Sli
             final String path = "/system/console/" + subpath;
             getRequestExecutor().execute(
                     getRequestBuilder().buildGetRequest(path)
-                    .withCredentials("admin", "admin")
+                    .withCredentials(getServerUsername(), getServerPassword())
             ).assertStatus(200);
         }
     }

Modified: sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/FailingTestsTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/FailingTestsTest.java?rev=1446510&r1=1446509&r2=1446510&view=diff
==============================================================================
--- sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/FailingTestsTest.java
(original)
+++ sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/FailingTestsTest.java
Fri Feb 15 11:00:40 2013
@@ -59,7 +59,7 @@ public class FailingTestsTest extends Se
         
         // Execute tests from the failingtests bundle and verify response
         final Request r = getRequestBuilder().buildPostRequest(JUNIT_SERVLET_PATH 
-                + "/org.apache.sling.testing.samples.failingtests.json");
+                + "/org.apache.sling.testing.samples.failingtests.json").withCredentials(getServerUsername(),
getServerPassword());
         getRequestExecutor().execute(r).assertStatus(200);
         
         final JSONArray json = new JSONArray(new JSONTokener((getRequestExecutor().getContent())));
@@ -89,4 +89,4 @@ public class FailingTestsTest extends Se
                 getFailure(json, "testAssertsEveryTime(org.apache.sling.testing.samples.failingtests.JUnit4FailingTest")
         );
     }
-}
\ No newline at end of file
+}

Modified: sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/JSONResponseTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/JSONResponseTest.java?rev=1446510&r1=1446509&r2=1446510&view=diff
==============================================================================
--- sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/JSONResponseTest.java
(original)
+++ sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/JSONResponseTest.java
Fri Feb 15 11:00:40 2013
@@ -80,7 +80,8 @@ public class JSONResponseTest extends Se
     }
 
     private void testJsonListOfTests() throws Exception {
-        Request r = getRequestBuilder().buildGetRequest(JUNIT_SERVLET_PATH + "/.json");
+        Request r = getRequestBuilder().buildGetRequest(JUNIT_SERVLET_PATH + "/.json")
+                .withCredentials(getServerUsername(), getServerPassword());
         
         // Get list of tests in JSON format
         getRequestExecutor().execute(r)
@@ -107,4 +108,4 @@ public class JSONResponseTest extends Se
                     findTestName(json, name));
         }
     }
-}
\ No newline at end of file
+}

Modified: sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/ServerSideTestsBase.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/ServerSideTestsBase.java?rev=1446510&r1=1446509&r2=1446510&view=diff
==============================================================================
--- sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/ServerSideTestsBase.java
(original)
+++ sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/ServerSideTestsBase.java
Fri Feb 15 11:00:40 2013
@@ -46,7 +46,7 @@ public class ServerSideTestsBase extends
             if(!junitServletOk) {
                 if(junitServletChecker == null) {
                     junitServletChecker = 
-                        new RetryingContentChecker(getRequestExecutor(), getRequestBuilder())
{
+                        new RetryingContentChecker(getRequestExecutor(), getRequestBuilder(),
getServerUsername(), getServerPassword()) {
                         @Override
                         public void onTimeout() {
                             junitServletCheckFailed = true;

Modified: sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/scriptable/ScriptableTestsTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/scriptable/ScriptableTestsTest.java?rev=1446510&r1=1446509&r2=1446510&view=diff
==============================================================================
--- sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/scriptable/ScriptableTestsTest.java
(original)
+++ sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/scriptable/ScriptableTestsTest.java
Fri Feb 15 11:00:40 2013
@@ -58,8 +58,8 @@ public class ScriptableTestsTest extends
     
     @Before
     public void setupContent() throws Exception {
-        slingClient = new SlingClient(getServerBaseUrl(), ADMIN, ADMIN);
-        testClient = new RemoteTestHttpClient(getServerBaseUrl() + JUNIT_SERVLET_PATH, true);
+        slingClient = new SlingClient(getServerBaseUrl(), getServerUsername(), getServerPassword());
+        testClient = new RemoteTestHttpClient(getServerBaseUrl() + JUNIT_SERVLET_PATH, getServerUsername(),
getServerPassword(), true);
         
         cleanupContent();
 
@@ -121,4 +121,4 @@ public class ScriptableTestsTest extends
         data.add(new Object[] { "TEST_FAILED", 1});
         return data;
     }
-}
\ No newline at end of file
+}

Modified: sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideTestsBase.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideTestsBase.java?rev=1446510&r1=1446509&r2=1446510&view=diff
==============================================================================
--- sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideTestsBase.java
(original)
+++ sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideTestsBase.java
Fri Feb 15 11:00:40 2013
@@ -45,7 +45,7 @@ public class SlingServerSideTestsBase ex
      *  and check (with timeout) that the servlet is ready */
     public SlingServerSideTestsBase() {
         if(!servletNodeCreated) {
-            final SlingClient slingClient = new SlingClient(getServerBaseUrl(), ADMIN, ADMIN);
+            final SlingClient slingClient = new SlingClient(getServerBaseUrl(), getServerUsername(),
getServerPassword());
             try {
                 slingClient.createNode(SERVLET_NODE_PATH, "sling:resourceType", "sling/junit/testing");
                 servletNodeCreated = true;
@@ -59,7 +59,8 @@ public class SlingServerSideTestsBase ex
         }
         
         if(!servletOk) {
-            final RetryingContentChecker servletChecker = new RetryingContentChecker(getRequestExecutor(),
getRequestBuilder()) 
+            final RetryingContentChecker servletChecker = new RetryingContentChecker(getRequestExecutor(),
getRequestBuilder(),
+                    getServerUsername(), getServerPassword())
             {
                 @Override
                 public void onTimeout() {
@@ -84,4 +85,4 @@ public class SlingServerSideTestsBase ex
             log.info("{} is ready, returns expected content", path);
         }
     }
-}
\ No newline at end of file
+}

Modified: sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/http/RetryingContentChecker.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/http/RetryingContentChecker.java?rev=1446510&r1=1446509&r2=1446510&view=diff
==============================================================================
--- sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/http/RetryingContentChecker.java
(original)
+++ sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/http/RetryingContentChecker.java
Fri Feb 15 11:00:40 2013
@@ -25,10 +25,27 @@ import org.apache.sling.testing.tools.sl
 public class RetryingContentChecker {
     private final RequestExecutor executor;
     private final RequestBuilder builder;
+    private final String username;
+    private final String password;
     
     public RetryingContentChecker(RequestExecutor executor, RequestBuilder builder) {
+        this(executor, builder, null, SlingTestBase.ADMIN);
+    }
+
+    public RetryingContentChecker(RequestExecutor executor, RequestBuilder builder, String
username, String password) {
         this.executor = executor;
         this.builder = builder;
+        if (username != null) {
+            this.username = username;
+        } else {
+            this.username = SlingTestBase.ADMIN;
+        }
+
+        if (password != null) {
+            this.password = password;
+        } else {
+            this.password = SlingTestBase.ADMIN;
+        }
     }
 
     /** Check specified path for expected status, or timeout */
@@ -40,7 +57,7 @@ public class RetryingContentChecker {
 
             public boolean isTrue() throws Exception {
                 executor.execute(builder.buildGetRequest(path)
-                        .withCredentials(SlingTestBase.ADMIN, SlingTestBase.ADMIN))
+                        .withCredentials(username, password))
                     .assertStatus(expectedStatus);
                 return assertMore(executor);
             }

Modified: sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/sling/SlingTestBase.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/sling/SlingTestBase.java?rev=1446510&r1=1446509&r2=1446510&view=diff
==============================================================================
--- sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/sling/SlingTestBase.java
(original)
+++ sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/sling/SlingTestBase.java
Fri Feb 15 11:00:40 2013
@@ -39,6 +39,8 @@ import org.slf4j.LoggerFactory;
  */
 public class SlingTestBase {
     public static final String TEST_SERVER_URL_PROP = "test.server.url";
+    public static final String TEST_SERVER_USERNAME = "test.server.username";
+    public static final String TEST_SERVER_PASSWORD = "test.server.password";
     public static final String SERVER_READY_TIMEOUT_PROP = "server.ready.timeout.seconds";
     public static final String SERVER_READY_PROP_PREFIX = "server.ready.path";
     public static final String KEEP_JAR_RUNNING_PROP = "keepJarRunning";
@@ -51,6 +53,8 @@ public class SlingTestBase {
 
     private static final boolean keepJarRunning = "true".equals(System.getProperty(KEEP_JAR_RUNNING_PROP));
     private final String serverBaseUrl;
+    private final String serverUsername;
+    private final String serverPassword;
     private RequestBuilder builder;
     private DefaultHttpClient httpClient = new DefaultHttpClient();
     private RequestExecutor executor = new RequestExecutor(httpClient);
@@ -93,8 +97,24 @@ public class SlingTestBase {
             serverBaseUrl = "http://" + serverHost + ":" + jarExecutor.getServerPort();
         }
 
+        // Set configured username using "admin" as default credential
+        final String configuredUsername = System.getProperty(TEST_SERVER_USERNAME);
+        if (configuredUsername != null && configuredUsername.trim().length() >
0) {
+            serverUsername = configuredUsername;
+        } else {
+            serverUsername = ADMIN;
+        }
+
+        // Set configured password using "admin" as default credential
+        final String configuredPassword = System.getProperty(TEST_SERVER_PASSWORD);
+        if (configuredPassword != null && configuredPassword.trim().length() >
0) {
+            serverPassword = configuredPassword;
+        } else {
+            serverPassword = ADMIN;
+        }
+
         builder = new RequestBuilder(serverBaseUrl);
-        webconsoleClient = new WebconsoleClient(serverBaseUrl, ADMIN, ADMIN);
+        webconsoleClient = new WebconsoleClient(serverBaseUrl, serverUsername, serverPassword);
         builder = new RequestBuilder(serverBaseUrl);
         bundlesInstaller = new BundlesInstaller(webconsoleClient);
 
@@ -180,6 +200,16 @@ public class SlingTestBase {
         return serverBaseUrl;
     }
 
+    /** Return username configured for execution of HTTP requests */
+    protected String getServerUsername() {
+        return serverUsername;
+    }
+
+    /** Return password configured for execution of HTTP requests */
+    protected String getServerPassword() {
+        return serverPassword;
+    }
+
     /** Optionally block here so that the runnable jar stays up - we can
      *  then run tests against it from another VM.
      */
@@ -235,17 +265,17 @@ public class SlingTestBase {
                 final String path = s[0];
                 final String pattern = (s.length > 0 ? s[1] : "");
                 try {
-                    executor.execute(builder.buildGetRequest(path))
+                    executor.execute(builder.buildGetRequest(path).withCredentials(serverUsername,
serverPassword))
                     .assertStatus(200)
                     .assertContentContains(pattern);
                 } catch(AssertionError ae) {
                     errors = true;
-                    log.debug("Request to {}{} failed, will retry ({})",
-                            new Object[] { serverBaseUrl, path, ae});
+                    log.debug("Request to {}@{}{} failed, will retry ({})",
+                            new Object[] { serverUsername, serverBaseUrl, path, ae});
                 } catch(Exception e) {
                     errors = true;
-                    log.debug("Request to {}{} failed, will retry ({})",
-                            new Object[] { serverBaseUrl, path, pattern, e });
+                    log.debug("Request to {}@{}{} failed, will retry ({})",
+                            new Object[] { serverUsername, serverBaseUrl, path, pattern,
e });
                 }
             }
 
@@ -326,4 +356,4 @@ public class SlingTestBase {
         startServerIfNeeded();
         return webconsoleClient;
     }
-}
\ No newline at end of file
+}



Mime
View raw message