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.
@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();
}
}
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;
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;