use infrautils' TestHttpClient
authorMichael Vorburger <mike@vorburger.ch>
Wed, 9 Jan 2019 21:43:47 +0000 (22:43 +0100)
committerMichael Vorburger <mike@vorburger.ch>
Wed, 1 Jul 2020 23:38:22 +0000 (01:38 +0200)
introduced in https://git.opendaylight.org/gerrit/#/c/79382/

Signed-off-by: Michael Vorburger <mike@vorburger.ch>
src/test/java/org/opendaylight/infrautils/testutils/TestHttpClient.java
src/test/java/org/opendaylight/neutron/simple/test/NeutronModuleTest.java
src/test/java/org/opendaylight/restconf/simple/test/RestConfModuleTest.java

index f66f1a33990d7dd918bce15804dc9ac6c840e5de..f15dffbfe772da45880703ca72bd1c8c923847ef 100644 (file)
@@ -8,11 +8,11 @@
 package org.opendaylight.infrautils.testutils;
 
 import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.net.URL;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.aaa.web.WebServer;
+import org.opendaylight.infrautils.testutils.web.TestWebClient;
+import org.opendaylight.infrautils.testutils.web.TestWebClient.Method;
 
 /**
  * HTTP Client.
@@ -22,21 +22,14 @@ import org.opendaylight.aaa.web.WebServer;
 @Singleton
 public class TestHttpClient {
 
-    public enum Method {
-        GET, POST, HEAD, OPTIONS, PUT, DELETE, TRACE
-    }
-
-    private final WebServer webServer;
+    private final TestWebClient webClient;
 
     @Inject
     public TestHttpClient(WebServer webServer) {
-        this.webServer = webServer;
+        this.webClient = new TestWebClient(webServer.getBaseURL());
     }
 
     public int responseCode(Method httpMethod, String path) throws IOException {
-        URL url = new URL(webServer.getBaseURL() + path);
-        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
-        conn.setRequestMethod(httpMethod.name());
-        return conn.getResponseCode();
+        return webClient.request(httpMethod, path).getStatus();
     }
 }
index 74cfd5959f80b103290cdf3f277e38e03a2df51d..b5a032852d6ea23fc9efc03f755dda048b1e2fc1 100644 (file)
@@ -8,7 +8,7 @@
 package org.opendaylight.neutron.simple.test;
 
 import static com.google.common.truth.Truth.assertThat;
-import static org.opendaylight.infrautils.testutils.TestHttpClient.Method.GET;
+import static org.opendaylight.infrautils.testutils.web.TestWebClient.Method.GET;
 
 import java.io.IOException;
 import javax.inject.Inject;
index ed3286ad02c41d5572ceb934eff72169c28ea632..76b51ed6522d6e99e35a64e6507d3253c53ba2e2 100644 (file)
@@ -8,7 +8,7 @@
 package org.opendaylight.restconf.simple.test;
 
 import static com.google.common.truth.Truth.assertThat;
-import static org.opendaylight.infrautils.testutils.TestHttpClient.Method.GET;
+import static org.opendaylight.infrautils.testutils.web.TestWebClient.Method.GET;
 
 import java.io.IOException;
 import javax.inject.Inject;