From 157e7b4758c6f2f24ed73fb0093268420026d2b7 Mon Sep 17 00:00:00 2001
From: Michael Vorburger <mike@vorburger.ch>
Date: Thu, 10 Jan 2019 04:14:00 +0100
Subject: [PATCH] replace TestHttpClient with upstream TestWebClient

requires https://git.opendaylight.org/gerrit/#/c/79382/

Signed-off-by: Michael Vorburger <mike@vorburger.ch>
---
 pom.xml                                       |  6 ++++
 .../infrautils/web/WebModule.java             |  2 ++
 .../infrautils/testutils/TestHttpClient.java  | 35 -------------------
 .../simple/test/NeutronModuleTest.java        |  6 ++--
 .../simple/test/OpenFlowPluginModuleTest.java |  4 +--
 .../simple/test/RestConfModuleTest.java       |  6 ++--
 6 files changed, 16 insertions(+), 43 deletions(-)
 delete mode 100644 src/test/java/org/opendaylight/infrautils/testutils/TestHttpClient.java

diff --git a/pom.xml b/pom.xml
index b76c3f5..ac7e025 100644
--- a/pom.xml
+++ b/pom.xml
@@ -285,6 +285,12 @@
     </dependency>
 
     <!-- Now <scope>test... -->
+    <dependency>
+      <groupId>org.opendaylight.aaa.web</groupId>
+      <artifactId>testutils</artifactId>
+      <version>0.9.0-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
     <dependency>
       <groupId>org.opendaylight.infrautils</groupId>
       <artifactId>infrautils-testutils</artifactId>
diff --git a/src/main/java/org/opendaylight/infrautils/web/WebModule.java b/src/main/java/org/opendaylight/infrautils/web/WebModule.java
index 1885228..32ad205 100644
--- a/src/main/java/org/opendaylight/infrautils/web/WebModule.java
+++ b/src/main/java/org/opendaylight/infrautils/web/WebModule.java
@@ -21,6 +21,8 @@ import org.opendaylight.aaa.web.servlet.jersey2.JerseyServletSupport;
  */
 public class WebModule extends AbstractModule {
 
+    // TODO note (new) org.opendaylight.aaa.web.testutils.WebTestModule .. integrate?
+
     @Override
     protected void configure() {
         // TODO read port from a -D parameter or configuration file instead of hard-coding
diff --git a/src/test/java/org/opendaylight/infrautils/testutils/TestHttpClient.java b/src/test/java/org/opendaylight/infrautils/testutils/TestHttpClient.java
deleted file mode 100644
index f15dffb..0000000
--- a/src/test/java/org/opendaylight/infrautils/testutils/TestHttpClient.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 2018 Red Hat, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.infrautils.testutils;
-
-import java.io.IOException;
-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.
- *
- * @author Michael Vorburger.ch
- */
-@Singleton
-public class TestHttpClient {
-
-    private final TestWebClient webClient;
-
-    @Inject
-    public TestHttpClient(WebServer webServer) {
-        this.webClient = new TestWebClient(webServer.getBaseURL());
-    }
-
-    public int responseCode(Method httpMethod, String path) throws IOException {
-        return webClient.request(httpMethod, path).getStatus();
-    }
-}
diff --git a/src/test/java/org/opendaylight/neutron/simple/test/NeutronModuleTest.java b/src/test/java/org/opendaylight/neutron/simple/test/NeutronModuleTest.java
index b5a0328..74f4ab9 100644
--- a/src/test/java/org/opendaylight/neutron/simple/test/NeutronModuleTest.java
+++ b/src/test/java/org/opendaylight/neutron/simple/test/NeutronModuleTest.java
@@ -15,11 +15,11 @@ import javax.inject.Inject;
 import org.junit.Rule;
 import org.junit.Test;
 import org.opendaylight.aaa.web.WebServer;
+import org.opendaylight.aaa.web.testutils.TestWebClient;
 import org.opendaylight.controller.simple.InMemoryControllerModule;
 import org.opendaylight.infrautils.inject.guice.testutils.AnnotationsModule;
 import org.opendaylight.infrautils.inject.guice.testutils.GuiceRule;
 import org.opendaylight.infrautils.simple.testutils.AbstractSimpleDistributionTest;
-import org.opendaylight.infrautils.testutils.TestHttpClient;
 import org.opendaylight.infrautils.web.WebModule;
 import org.opendaylight.neutron.simple.NeutronModule;
 
@@ -34,9 +34,9 @@ public class NeutronModuleTest extends AbstractSimpleDistributionTest {
             NeutronModule.class, InMemoryControllerModule.class, WebModule.class, AnnotationsModule.class);
 
     @Inject WebServer webServer;
-    @Inject TestHttpClient http;
+    @Inject TestWebClient http;
 
     @Test public void testNeutron() throws IOException {
-        assertThat(http.responseCode(GET, "/controller/nb/v2/neutron/networks")).isEqualTo(200);
+        assertThat(http.request(GET, "/controller/nb/v2/neutron/networks").getStatus()).isEqualTo(200);
     }
 }
diff --git a/src/test/java/org/opendaylight/openflowplugin/simple/test/OpenFlowPluginModuleTest.java b/src/test/java/org/opendaylight/openflowplugin/simple/test/OpenFlowPluginModuleTest.java
index 58a0902..221da56 100644
--- a/src/test/java/org/opendaylight/openflowplugin/simple/test/OpenFlowPluginModuleTest.java
+++ b/src/test/java/org/opendaylight/openflowplugin/simple/test/OpenFlowPluginModuleTest.java
@@ -12,6 +12,7 @@ import static com.google.common.truth.Truth.assertThat;
 import javax.inject.Inject;
 import org.junit.Rule;
 import org.junit.Test;
+import org.opendaylight.aaa.web.testutils.WebTestModule;
 import org.opendaylight.controller.simple.InMemoryControllerModule;
 import org.opendaylight.infrautils.inject.guice.GuiceClassPathBinder;
 import org.opendaylight.infrautils.inject.guice.testutils.AnnotationsModule;
@@ -19,7 +20,6 @@ import org.opendaylight.infrautils.inject.guice.testutils.GuiceRule;
 import org.opendaylight.infrautils.ready.guice.ReadyModule;
 import org.opendaylight.infrautils.simple.DiagStatusModule;
 import org.opendaylight.infrautils.simple.testutils.AbstractSimpleDistributionTest;
-import org.opendaylight.infrautils.web.WebModule;
 import org.opendaylight.openflowplugin.api.openflow.OpenFlowPluginProvider;
 import org.opendaylight.openflowplugin.simple.OpenFlowPluginModule;
 import org.opendaylight.serviceutils.simple.ServiceUtilsModule;
@@ -31,7 +31,7 @@ public class OpenFlowPluginModuleTest extends AbstractSimpleDistributionTest {
     private static final GuiceClassPathBinder CLASS_PATH_BINDER = new GuiceClassPathBinder("org.opendaylight");
 
     public @Rule GuiceRule guice = new GuiceRule(new OpenFlowPluginModule(CLASS_PATH_BINDER),
-            new ServiceUtilsModule(), new InMemoryControllerModule(), new DiagStatusModule(), new WebModule(),
+            new ServiceUtilsModule(), new InMemoryControllerModule(), new DiagStatusModule(), new WebTestModule(),
             new ReadyModule(), new AnnotationsModule());
 
     @Inject OpenFlowPluginProvider ofpProvider;
diff --git a/src/test/java/org/opendaylight/restconf/simple/test/RestConfModuleTest.java b/src/test/java/org/opendaylight/restconf/simple/test/RestConfModuleTest.java
index 76b51ed..b03a38a 100644
--- a/src/test/java/org/opendaylight/restconf/simple/test/RestConfModuleTest.java
+++ b/src/test/java/org/opendaylight/restconf/simple/test/RestConfModuleTest.java
@@ -15,11 +15,11 @@ import javax.inject.Inject;
 import org.junit.Rule;
 import org.junit.Test;
 import org.opendaylight.aaa.web.WebServer;
+import org.opendaylight.aaa.web.testutils.TestWebClient;
 import org.opendaylight.controller.simple.InMemoryControllerModule;
 import org.opendaylight.infrautils.inject.guice.testutils.AnnotationsModule;
 import org.opendaylight.infrautils.inject.guice.testutils.GuiceRule;
 import org.opendaylight.infrautils.simple.testutils.AbstractSimpleDistributionTest;
-import org.opendaylight.infrautils.testutils.TestHttpClient;
 import org.opendaylight.infrautils.web.WebModule;
 import org.opendaylight.restconf.simple.RestConfModule;
 
@@ -34,10 +34,10 @@ public class RestConfModuleTest extends AbstractSimpleDistributionTest {
             RestConfModule.class, InMemoryControllerModule.class, WebModule.class, AnnotationsModule.class);
 
     @Inject WebServer webServer;
-    @Inject TestHttpClient http;
+    @Inject TestWebClient http;
 
     @Test public void testRestConf() throws IOException {
-        assertThat(http.responseCode(GET, "/restconf/modules/")).isEqualTo(200);
+        assertThat(http.request(GET, "/restconf/modules/").getStatus()).isEqualTo(200);
 
         // TODO test security; add auth support to TestHttpClient, check that w.o. auth it's 401
     }
-- 
2.36.6