This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag 
org.apache.sling.junit.healthcheck-1.0.4
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-junit-healthcheck.git

commit d0be351e71d120c8485a95d0e12cedcdc697598d
Author: Bertrand Delacretaz <[email protected]>
AuthorDate: Fri Feb 15 11:00:40 2013 +0000

    SLING-2419 - support non-default credential in test utilities - patch 
contributed by Mark Adamcin, thanks!
    
    git-svn-id: 
https://svn.apache.org/repos/asf/sling/trunk/testing/junit/remote@1446510 
13f79535-47bb-0310-9956-ffa450edef68
---
 .../remote/httpclient/RemoteTestHttpClient.java    | 24 ++++++++++++++++---
 .../junit/remote/ide/SlingRemoteExecutionRule.java | 11 ++++++---
 .../remote/testrunner/SlingRemoteTestRunner.java   | 27 ++++++++++++++++++----
 3 files changed, 52 insertions(+), 10 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/junit/remote/httpclient/RemoteTestHttpClient.java
 
b/src/main/java/org/apache/sling/junit/remote/httpclient/RemoteTestHttpClient.java
index d23c851..2091236 100644
--- 
a/src/main/java/org/apache/sling/junit/remote/httpclient/RemoteTestHttpClient.java
+++ 
b/src/main/java/org/apache/sling/junit/remote/httpclient/RemoteTestHttpClient.java
@@ -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);
 
diff --git 
a/src/main/java/org/apache/sling/junit/remote/ide/SlingRemoteExecutionRule.java 
b/src/main/java/org/apache/sling/junit/remote/ide/SlingRemoteExecutionRule.java
index e6551de..590ebd2 100644
--- 
a/src/main/java/org/apache/sling/junit/remote/ide/SlingRemoteExecutionRule.java
+++ 
b/src/main/java/org/apache/sling/junit/remote/ide/SlingRemoteExecutionRule.java
@@ -40,6 +40,8 @@ public class SlingRemoteExecutionRule implements MethodRule, 
RequestCustomizer {
 
    /** 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 implements 
MethodRule, RequestCustomizer {
     */
    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"
diff --git 
a/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestRunner.java
 
b/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestRunner.java
index 3f6e28a..a352436 100644
--- 
a/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestRunner.java
+++ 
b/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestRunner.java
@@ -25,6 +25,7 @@ import org.apache.sling.commons.json.JSONTokener;
 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 extends 
ParentRunner<SlingRemoteTest> {
     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 extends 
ParentRunner<SlingRemoteTest> {
             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 extends 
ParentRunner<SlingRemoteTest> {
             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 extends 
ParentRunner<SlingRemoteTest> {
             }
         }
         
-        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 extends 
ParentRunner<SlingRemoteTest> {
             eachNotifier.fireTestFinished();
         }
     }
-}
\ No newline at end of file
+}

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to