Demonstrate variables in provisioning model configs
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1774245 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/sling/crankstart/junit/CrankstartSetup.java b/src/main/java/org/apache/sling/crankstart/junit/CrankstartSetup.java
index ed78d38..e35ba31 100644
--- a/src/main/java/org/apache/sling/crankstart/junit/CrankstartSetup.java
+++ b/src/main/java/org/apache/sling/crankstart/junit/CrankstartSetup.java
@@ -148,6 +148,14 @@
log.info("Starting {}", this);
+ // Add system properties which have the expected prefix
+ for(Object o : System.getProperties().keySet()) {
+ final String key = o.toString();
+ if(key.startsWith(Launcher.VARIABLE_OVERRIDE_PREFIX)) {
+ replacementProps.setProperty(key, System.getProperty(key));
+ }
+ }
+
final HttpUriRequest get = new HttpGet(baseUrl);
replacementProps.setProperty("crankstart.model.http.port", String.valueOf(port));
replacementProps.setProperty("crankstart.model.osgi.storage.path", storagePath);
diff --git a/src/test/java/org/apache/sling/crankstart/launcher/BasicLauncherIT.java b/src/test/java/org/apache/sling/crankstart/launcher/BasicLauncherIT.java
index e81ccf9..b619472 100644
--- a/src/test/java/org/apache/sling/crankstart/launcher/BasicLauncherIT.java
+++ b/src/test/java/org/apache/sling/crankstart/launcher/BasicLauncherIT.java
@@ -5,6 +5,7 @@
import static org.junit.Assert.fail;
import java.io.IOException;
+import java.util.UUID;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
@@ -33,6 +34,17 @@
private DefaultHttpClient client;
private static WebconsoleClient osgiConsole;
+ private static final String uniqueText = "Unique text for tests run " + UUID.randomUUID();
+
+ // The Launcher.VARIABLE_OVERRIDE_PREFIX must be used for system properties that
+ // are meant to provide values for the provisioning model
+ private static final String PROP_UNIQUE_TEXT = Launcher.VARIABLE_OVERRIDE_PREFIX + "single.servlet.text";
+
+ static {
+ // BeforeClass would be too late for this as it's
+ // the CrankstartSetup rule that needs this.
+ System.setProperty(PROP_UNIQUE_TEXT, uniqueText);
+ }
@Rule
public final RetryRule retryRule = new RetryRule();
@@ -44,6 +56,7 @@
@Before
public void setup() throws IOException {
+ System.getProperties().remove(PROP_UNIQUE_TEXT);
client = new DefaultHttpClient();
}
@@ -68,6 +81,9 @@
try {
response = client.execute(get);
assertEquals("Expecting success for " + get.getURI(), 200, response.getStatusLine().getStatusCode());
+ final String content = U.getContent(response);
+ final String expected = "SingleConfigServlet:test content is " + uniqueText;
+ assertEquals(expected, content);
} finally {
U.closeConnection(response);
}
diff --git a/src/test/java/org/apache/sling/crankstart/launcher/U.java b/src/test/java/org/apache/sling/crankstart/launcher/U.java
index 57061ef..f13dfc7 100644
--- a/src/test/java/org/apache/sling/crankstart/launcher/U.java
+++ b/src/test/java/org/apache/sling/crankstart/launcher/U.java
@@ -6,6 +6,7 @@
import java.io.IOException;
import org.apache.commons.io.IOUtils;
+import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
@@ -62,6 +63,25 @@
.getContent());
}
+ public static String getContent(HttpResponse response) throws IOException{
+
+ final HttpEntity e = response.getEntity();
+ if(e == null) {
+ throw new IOException("Response does not provide an Entity");
+ }
+
+ String encoding = "UTF-8";
+ if(response.getEntity().getContentEncoding() != null) {
+ encoding = response.getEntity().getContentEncoding().getValue();
+ }
+
+ try {
+ return IOUtils.toString(e.getContent(), encoding);
+ } finally {
+ e.consumeContent();
+ }
+ }
+
public static void assertHttpGet(CrankstartSetup C, DefaultHttpClient client, String path, String expectedContent) throws Exception {
final HttpUriRequest get = new HttpGet(C.getBaseUrl() + path);
HttpResponse response = null;
@@ -69,11 +89,7 @@
response = client.execute(get);
assertEquals("Expecting 200 response at " + path, 200, response.getStatusLine().getStatusCode());
assertNotNull("Expecting response entity", response.getEntity());
- String encoding = "UTF-8";
- if(response.getEntity().getContentEncoding() != null) {
- encoding = response.getEntity().getContentEncoding().getValue();
- }
- final String content = IOUtils.toString(response.getEntity().getContent(), encoding);
+ final String content = getContent(response);
assertEquals(expectedContent, content);
} finally {
U.closeConnection(response);
diff --git a/src/test/resources/provisioning-model/crankstart-tests.txt b/src/test/resources/provisioning-model/crankstart-tests.txt
index 2c8396a..f579459 100644
--- a/src/test/resources/provisioning-model/crankstart-tests.txt
+++ b/src/test/resources/provisioning-model/crankstart-tests.txt
@@ -19,6 +19,9 @@
[feature name=crankstart.tests]
+[variables]
+single.servlet.text = this can be overridden, see BasicLauncherIT
+
[artifacts]
org.apache.sling/org.apache.sling.crankstart.test.services/1.9.9-SNAPSHOT
org.apache.sling/org.apache.sling.junit.core/1.0.10
@@ -44,9 +47,8 @@
[configurations]
org.apache.sling.crankstart.testservices.SingleConfigServlet
- # TODO should use a variable to verify that they work in configs
path="/single"
- message="doesn't matter"
+ message="test content is ${single.servlet.text}"
org.apache.sling.crankstart.testservices.ConfigFactoryServlet-foo
path="/foo"