SLING-5348 - Make test servlet path configurable in ClientSideTeleporter, and use credentials to access it. Based on a patch by Sufyan Haroon, thanks!
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1718828 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/sling/testing/teleporter/client/ClientSideTeleporter.java b/src/main/java/org/apache/sling/testing/teleporter/client/ClientSideTeleporter.java
index acc144b..8f9cf06 100644
--- a/src/main/java/org/apache/sling/testing/teleporter/client/ClientSideTeleporter.java
+++ b/src/main/java/org/apache/sling/testing/teleporter/client/ClientSideTeleporter.java
@@ -44,10 +44,12 @@
*/
public class ClientSideTeleporter extends TeleporterRule {
+ public static final String DEFAULT_TEST_SERVLET_PATH = "system/sling/junit";
private DependencyAnalyzer dependencyAnalyzer;
private int testReadyTimeoutSeconds = 5;
private String baseUrl;
private String serverCredentials;
+ private String testServletPath = DEFAULT_TEST_SERVLET_PATH;
private final Set<Class<?>> embeddedClasses = new HashSet<Class<?>>();
private final Map<String, String> additionalBundleHeaders = new HashMap<String, String>();
@@ -107,7 +109,15 @@
serverCredentials = username + ":" + password;
}
- /** Define a prefix for class names that can be embedded
+ /**
+ * @param testServletPath relative path to the Sling JUnit test servlet.
+ * If null, defaults to DEFAULT_TEST_SERVLET_PATH.
+ */
+ public void setTestServletPath(String testServletPath) {
+ this.testServletPath = testServletPath == null ? DEFAULT_TEST_SERVLET_PATH : testServletPath;
+ }
+
+ /** Define a prefix for class names that can be embedded
* in the test bundle if the {@link DependencyAnalyzer} thinks
* they should. Overridden by {@link #excludeDependencyPrefix } if
* any conflicts arise.
@@ -168,7 +178,7 @@
embeddedClasses.add(c);
}
- final TeleporterHttpClient httpClient = new TeleporterHttpClient(baseUrl);
+ final TeleporterHttpClient httpClient = new TeleporterHttpClient(baseUrl, testServletPath);
httpClient.setCredentials(serverCredentials);
// As this is not a ClassRule (which wouldn't map the test results correctly in an IDE)
@@ -188,4 +198,4 @@
}
};
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/testing/teleporter/client/TeleporterHttpClient.java b/src/main/java/org/apache/sling/testing/teleporter/client/TeleporterHttpClient.java
index 482a6b7..bf43ba4 100644
--- a/src/main/java/org/apache/sling/testing/teleporter/client/TeleporterHttpClient.java
+++ b/src/main/java/org/apache/sling/testing/teleporter/client/TeleporterHttpClient.java
@@ -42,9 +42,14 @@
private final String CHARSET = "UTF-8";
private final String baseUrl;
private String credentials = null;
+ private final String testServletPath;
- TeleporterHttpClient(String baseUrl) {
+ TeleporterHttpClient(String baseUrl, String testServletPath) {
this.baseUrl = baseUrl;
+ if(!testServletPath.endsWith("/")) {
+ testServletPath += "/";
+ }
+ this.testServletPath = testServletPath;
}
void setCredentials(String cred) {
@@ -103,6 +108,7 @@
private int getHttpGetStatus(String url) throws MalformedURLException, IOException {
final HttpURLConnection c = (HttpURLConnection)new URL(url).openConnection();
+ setConnectionCredentials(c);
c.setUseCaches(false);
c.setDoOutput(true);
c.setDoInput(true);
@@ -115,7 +121,7 @@
}
void runTests(String testSelectionPath, int testReadyTimeoutSeconds) throws MalformedURLException, IOException, MultipleFailureException {
- final String testUrl = baseUrl + "/system/sling/junit/" + testSelectionPath + ".junit_result";
+ final String testUrl = baseUrl + "/" + testServletPath + testSelectionPath + ".junit_result";
// Wait for non-404 response that signals that test bundle is ready
final long timeout = System.currentTimeMillis() + (testReadyTimeoutSeconds * 1000L);
@@ -131,6 +137,7 @@
final HttpURLConnection c = (HttpURLConnection)new URL(testUrl).openConnection();
try {
+ setConnectionCredentials(c);
c.setRequestMethod("POST");
c.setUseCaches(false);
c.setDoOutput(true);