You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2017/09/05 10:28:22 UTC

svn commit: r1807333 - in /sling/trunk/testing/junit/teleporter: pom.xml src/test/java/org/apache/sling/testing/teleporter/client/TeleporterHttpClientTest.java

Author: bdelacretaz
Date: Tue Sep  5 10:28:21 2017
New Revision: 1807333

URL: http://svn.apache.org/viewvc?rev=1807333&view=rev
Log:
SLING-7101 - adapt tests for wiremock 2.8.0, to be able to test with credentials

Modified:
    sling/trunk/testing/junit/teleporter/pom.xml
    sling/trunk/testing/junit/teleporter/src/test/java/org/apache/sling/testing/teleporter/client/TeleporterHttpClientTest.java

Modified: sling/trunk/testing/junit/teleporter/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/teleporter/pom.xml?rev=1807333&r1=1807332&r2=1807333&view=diff
==============================================================================
--- sling/trunk/testing/junit/teleporter/pom.xml (original)
+++ sling/trunk/testing/junit/teleporter/pom.xml Tue Sep  5 10:28:21 2017
@@ -122,7 +122,7 @@
     <dependency>
       <groupId>com.github.tomakehurst</groupId>
       <artifactId>wiremock</artifactId>
-      <version>1.57</version>
+      <version>2.8.0</version>
       <scope>test</scope>
     </dependency>
     <dependency>

Modified: sling/trunk/testing/junit/teleporter/src/test/java/org/apache/sling/testing/teleporter/client/TeleporterHttpClientTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/teleporter/src/test/java/org/apache/sling/testing/teleporter/client/TeleporterHttpClientTest.java?rev=1807333&r1=1807332&r2=1807333&view=diff
==============================================================================
--- sling/trunk/testing/junit/teleporter/src/test/java/org/apache/sling/testing/teleporter/client/TeleporterHttpClientTest.java (original)
+++ sling/trunk/testing/junit/teleporter/src/test/java/org/apache/sling/testing/teleporter/client/TeleporterHttpClientTest.java Tue Sep  5 10:28:21 2017
@@ -18,15 +18,12 @@ package org.apache.sling.testing.telepor
 
 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
 import static com.github.tomakehurst.wiremock.client.WireMock.get;
-import static com.github.tomakehurst.wiremock.client.WireMock.givenThat;
 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
-import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.InputStreamReader;
 import java.net.MalformedURLException;
 import java.nio.charset.StandardCharsets;
 import java.util.Timer;
@@ -48,10 +45,11 @@ public class TeleporterHttpClientTest {
     @Rule
     public WireMockRule http = new WireMockRule(PORT);
     
-    private void activateLater(final String path, long delayMsec) {
+    private void changeStatusLater(final String path, long delayMsec, final int newStatus) {
         TimerTask t = new TimerTask() {
             public void run() {
-                givenThat(get(urlEqualTo(path)).willReturn(aResponse().withStatus(200)));
+                http.resetAll();
+                http.givenThat(get(urlEqualTo(path)).willReturn(aResponse().withStatus(newStatus)));
             }
         };
         
@@ -63,8 +61,10 @@ public class TeleporterHttpClientTest {
         final TeleporterHttpClient client = new TeleporterHttpClient(baseUrl, TEST_PATH);
         final String testUrl = baseUrl + TEST_PATH;
         
-        assertEquals(404, client.getHttpGetStatus(baseUrl + TEST_PATH).getStatus());
-        activateLater(TEST_PATH, 1000);
+        http.givenThat(get(urlEqualTo(TEST_PATH)).willReturn(aResponse().withStatus(418)));
+        assertEquals(418, client.getHttpGetStatus(baseUrl + TEST_PATH).getStatus());
+        
+        changeStatusLater(TEST_PATH, 1000, 200);
         client.waitForStatus(testUrl, 200, TimeoutsProvider.getInstance().getTimeout(2000));
         assertEquals(200, client.getHttpGetStatus(baseUrl + TEST_PATH).getStatus());
     }
@@ -75,7 +75,7 @@ public class TeleporterHttpClientTest {
         final String testUrl = baseUrl + TEST_PATH;
         
         assertEquals(404, client.getHttpGetStatus(baseUrl + TEST_PATH).getStatus());
-        activateLater(TEST_PATH, 1000);
+        changeStatusLater(TEST_PATH, 1000, 200);
         
         try {
             client.waitForStatus(testUrl, 200, 100);
@@ -87,7 +87,7 @@ public class TeleporterHttpClientTest {
     @Test
     public void repeatedGetStatus() {
         final String path = TEST_PATH + "/" + UUID.randomUUID();
-        givenThat(get(urlEqualTo(path)).willReturn(aResponse().withStatus(200)));
+        http.givenThat(get(urlEqualTo(path)).willReturn(aResponse().withStatus(200)));
         
         final TeleporterHttpClient client = new TeleporterHttpClient(baseUrl, path);
         final String testUrl = baseUrl + path;
@@ -111,7 +111,7 @@ public class TeleporterHttpClientTest {
         // open resource
         try (InputStream inputStream = this.getClass().getResourceAsStream("/bundle-not-active.json")) {
             String body = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
-            givenThat(get(urlEqualTo("/system/console/bundles/" + bundleSymbolicName + ".json")).willReturn(aResponse().withStatus(200).withBody(body)));
+            http.givenThat(get(urlEqualTo("/system/console/bundles/" + bundleSymbolicName + ".json")).willReturn(aResponse().withStatus(200).withBody(body)));
         }
         client.verifyCorrectBundleState(bundleSymbolicName, 1);
     }
@@ -123,7 +123,7 @@ public class TeleporterHttpClientTest {
         // open resource
         try (InputStream inputStream = this.getClass().getResourceAsStream("/bundle-active.json")) {
             String body = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
-            givenThat(get(urlEqualTo("/system/console/bundles/" + bundleSymbolicName + ".json")).willReturn(aResponse().withStatus(200).withBody(body)));
+            http.givenThat(get(urlEqualTo("/system/console/bundles/" + bundleSymbolicName + ".json")).willReturn(aResponse().withStatus(200).withBody(body)));
         }
         client.verifyCorrectBundleState(bundleSymbolicName, 1);
     }