diff options
Diffstat (limited to 'policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http')
4 files changed, 25 insertions, 22 deletions
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpClientTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpClientTest.java index d214d23b..f559b112 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpClientTest.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpClientTest.java @@ -25,7 +25,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import java.io.IOException; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.util.Collections; @@ -67,10 +66,9 @@ public class HttpClientTest { * Setup before class method. * * @throws InterruptedException can be interrupted - * @throws IOException can have an IO exception */ @BeforeClass - public static void setUpBeforeClass() throws InterruptedException, IOException { + public static void setUpBeforeClass() throws InterruptedException { /* echo server - http + no auth */ final HttpServletServer echoServerNoAuth = diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpServerTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpServerTest.java index 41ad2122..c6ff2f32 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpServerTest.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpServerTest.java @@ -20,6 +20,7 @@ package org.onap.policy.common.endpoints.http.server.test; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -75,7 +76,7 @@ public class HttpServerTest { */ @Before public void setUp() { - port += 10; + incrementPort(); portUrl = LOCALHOST_PREFIX + port; HttpServletServer.factory.destroy(); @@ -84,6 +85,10 @@ public class HttpServerTest { MyGsonProvider.resetSome(); } + private static void incrementPort() { + port += 10; + } + @AfterClass public static void tearDownAfterClass() { HttpServletServer.factory.destroy(); @@ -264,13 +269,7 @@ public class HttpServerTest { String response = http(portUrl + JUNIT_ECHO_HELLO); assertEquals(HELLO, response); - response = null; - try { - response = http(portUrl + SWAGGER_JSON); - } catch (IOException e) { - // Expected - } - assertTrue(response == null); + assertThatThrownBy(() -> http(portUrl + SWAGGER_JSON)).isInstanceOf(IOException.class); response = http(portUrl + "/junit/echo/hello?block=true"); assertEquals("FILTERED", response); @@ -311,13 +310,7 @@ public class HttpServerTest { response = http(LOCALHOST_PREFIX + port2 + JUNIT_ECHO_HELLO); assertTrue(HELLO.equals(response)); - response = null; - try { - response = http(LOCALHOST_PREFIX + port2 + SWAGGER_JSON); - } catch (IOException e) { - // Expected - } - assertTrue(response == null); + assertThatThrownBy(() -> http(LOCALHOST_PREFIX + port2 + SWAGGER_JSON)).isInstanceOf(IOException.class); HttpServletServer.factory.destroy(); assertTrue(HttpServletServer.factory.inventory().isEmpty()); diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/MyGsonProvider.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/MyGsonProvider.java index 286d73dc..8343d02d 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/MyGsonProvider.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/MyGsonProvider.java @@ -27,13 +27,19 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Type; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; +import lombok.AccessLevel; +import lombok.Setter; import org.onap.policy.common.gson.GsonMessageBodyHandler; /** * GsonMessageBodyHandler that tracks activities. */ public class MyGsonProvider extends GsonMessageBodyHandler { + + @Setter(AccessLevel.PRIVATE) private static boolean readSome = false; + + @Setter(AccessLevel.PRIVATE) private static boolean wroteSome = false; /** @@ -48,7 +54,7 @@ public class MyGsonProvider extends GsonMessageBodyHandler { public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { - readSome = true; + setReadSome(true); return super.readFrom(type, genericType, annotations, mediaType, httpHeaders, entityStream); } @@ -56,7 +62,7 @@ public class MyGsonProvider extends GsonMessageBodyHandler { public void writeTo(Object object, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { - wroteSome = true; + setWroteSome(true); super.writeTo(object, type, genericType, annotations, mediaType, httpHeaders, entityStream); } diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/MyJacksonProvider.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/MyJacksonProvider.java index 07062451..55efd8bb 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/MyJacksonProvider.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/MyJacksonProvider.java @@ -28,12 +28,18 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Type; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; +import lombok.AccessLevel; +import lombok.Setter; /** * JacksonJsonProvider that tracks activities. */ public class MyJacksonProvider extends JacksonJsonProvider { + + @Setter(AccessLevel.PRIVATE) private static boolean readSome = false; + + @Setter(AccessLevel.PRIVATE) private static boolean wroteSome = false; /** @@ -48,7 +54,7 @@ public class MyJacksonProvider extends JacksonJsonProvider { public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { - readSome = true; + setReadSome(true); return super.readFrom(type, genericType, annotations, mediaType, httpHeaders, entityStream); } @@ -56,7 +62,7 @@ public class MyJacksonProvider extends JacksonJsonProvider { public void writeTo(Object object, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { - wroteSome = true; + setWroteSome(true); super.writeTo(object, type, genericType, annotations, mediaType, httpHeaders, entityStream); } |