diff options
author | Einat Vinouze <einat.vinouze@intl.att.com> | 2019-09-12 15:29:11 +0300 |
---|---|---|
committer | Eylon Malin <eylon.malin@intl.att.com> | 2019-09-12 13:33:16 +0000 |
commit | d4838465bd008b85ab3214b6431e6daa7d059589 (patch) | |
tree | 6bba8d26ce1a845c670381647e21ba2fc574ae69 /vid-app-common/src/test | |
parent | ca6f40516028602d3551856301cd9d7cda65f812 (diff) |
logging requests and responses in SyncRestClient
Issue-ID: VID-611
Signed-off-by: Einat Vinouze <einat.vinouze@intl.att.com>
Change-Id: I0e64e9520e566f9317f3fcbf0495b67349993ce4
Diffstat (limited to 'vid-app-common/src/test')
-rw-r--r-- | vid-app-common/src/test/java/org/onap/vid/client/SyncRestClientForHttpServerTest.java | 26 | ||||
-rw-r--r-- | vid-app-common/src/test/java/org/onap/vid/client/SyncRestClientForHttpsServerTest.java | 10 |
2 files changed, 36 insertions, 0 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/client/SyncRestClientForHttpServerTest.java b/vid-app-common/src/test/java/org/onap/vid/client/SyncRestClientForHttpServerTest.java index b30cf5f32..5a2eb59d2 100644 --- a/vid-app-common/src/test/java/org/onap/vid/client/SyncRestClientForHttpServerTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/client/SyncRestClientForHttpServerTest.java @@ -3,6 +3,7 @@ * VID * ================================================================================ * Copyright (C) 2018 - 2019 Nokia. All rights reserved. + * Modifications Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,9 +27,13 @@ import static com.xebialabs.restito.semantics.Action.contentType; import static com.xebialabs.restito.semantics.Action.ok; import static com.xebialabs.restito.semantics.Action.status; import static com.xebialabs.restito.semantics.Action.stringContent; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import static org.testng.Assert.assertEquals; +import com.att.eelf.configuration.EELFLogger; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableMap; @@ -42,6 +47,7 @@ import java.util.Map; import org.glassfish.grizzly.http.Method; import org.glassfish.grizzly.http.util.HttpStatus; import org.onap.vid.utils.Logging; +import org.springframework.http.HttpMethod; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -80,6 +86,8 @@ public class SyncRestClientForHttpServerTest { .get(url, Collections.emptyMap(), Collections.emptyMap()); // then verifyHttp(stubServer).once(Condition.method(Method.GET), Condition.url(url)); + verify(mockLoggingService).logRequest(any(EELFLogger.class), eq(HttpMethod.GET), eq(url), eq(Collections.emptyMap())); + verify(mockLoggingService).logResponse(any(EELFLogger.class), eq(HttpMethod.GET), eq(url), eq(jsonNodeHttpResponse)); assertEquals(jsonNodeHttpResponse.getStatus(), 200); assertEquals(jsonNodeHttpResponse.getBody().getObject().get("key"), 1); assertEquals(jsonNodeHttpResponse.getBody().getObject().get("value"), "test"); @@ -95,6 +103,8 @@ public class SyncRestClientForHttpServerTest { .get(url, Collections.emptyMap(), Collections.emptyMap(), SyncRestClientModel.TestModel.class); // then verifyHttp(stubServer).once(Condition.method(Method.GET), Condition.url(url)); + verify(mockLoggingService).logRequest(any(EELFLogger.class), eq(HttpMethod.GET), eq(url), eq(Collections.emptyMap())); + verify(mockLoggingService).logResponse(any(EELFLogger.class), eq(HttpMethod.GET), eq(url), eq(testModelHttpResponse)); assertEquals(testModelHttpResponse.getStatus(), 200); assertEquals(testModelHttpResponse.getBody().getKey(), 1); assertEquals(testModelHttpResponse.getBody().getValue(), "test"); @@ -108,6 +118,8 @@ public class SyncRestClientForHttpServerTest { // when HttpResponse<JsonNode> jsonNodeHttpResponse = syncRestClient.post(url, Collections.emptyMap(), testObject); // then + verify(mockLoggingService).logRequest(any(EELFLogger.class), eq(HttpMethod.POST), eq(url), eq(testObject)); + verify(mockLoggingService).logResponse(any(EELFLogger.class), eq(HttpMethod.POST), eq(url), eq(jsonNodeHttpResponse)); verifyHttp(stubServer).once(Condition.method(Method.POST), Condition.url(url)); assertEquals(jsonNodeHttpResponse.getStatus(), 200); assertEquals(jsonNodeHttpResponse.getBody().getObject().get("key"), 1); @@ -123,6 +135,8 @@ public class SyncRestClientForHttpServerTest { HttpResponse<JsonNode> jsonNodeHttpResponse = syncRestClient .post(url, Collections.emptyMap(), NOT_EXISTING_OBJECT); // then + verify(mockLoggingService).logRequest(any(EELFLogger.class), eq(HttpMethod.POST), eq(url), eq(NOT_EXISTING_OBJECT)); + verify(mockLoggingService).logResponse(any(EELFLogger.class), eq(HttpMethod.POST), eq(url), eq(jsonNodeHttpResponse)); assertEquals(jsonNodeHttpResponse.getStatus(), 404); assertEquals(jsonNodeHttpResponse.getStatusText(), "Not Found"); } @@ -137,6 +151,8 @@ public class SyncRestClientForHttpServerTest { HttpResponse<JsonNode> jsonNodeHttpResponse = syncRestClient.post(url, headers, testObject); // then verifyHttp(stubServer).once(Condition.withHeader("Authorization")); + verify(mockLoggingService).logRequest(any(EELFLogger.class), eq(HttpMethod.POST), eq(url), eq(testObject)); + verify(mockLoggingService).logResponse(any(EELFLogger.class), eq(HttpMethod.POST), eq(url), eq(jsonNodeHttpResponse)); assertEquals(jsonNodeHttpResponse.getStatus(), 200); } @@ -160,6 +176,8 @@ public class SyncRestClientForHttpServerTest { .post(url, Collections.emptyMap(), testObject, SyncRestClientModel.TestModel.class); // then verifyHttp(stubServer).once(Condition.method(Method.POST), Condition.url(url)); + verify(mockLoggingService).logRequest(any(EELFLogger.class), eq(HttpMethod.POST), eq(url), eq(testObject)); + verify(mockLoggingService).logResponse(any(EELFLogger.class), eq(HttpMethod.POST), eq(url), eq(objectHttpResponse)); assertEquals(objectHttpResponse.getStatus(), 200); assertEquals(objectHttpResponse.getBody().getKey(), 1); assertEquals(objectHttpResponse.getBody().getValue(), "test"); @@ -174,6 +192,8 @@ public class SyncRestClientForHttpServerTest { HttpResponse<JsonNode> jsonNodeHttpResponse = syncRestClient.put(url, Collections.emptyMap(), testObject); // then verifyHttp(stubServer).once(Condition.method(Method.PUT), Condition.url(url)); + verify(mockLoggingService).logRequest(any(EELFLogger.class), eq(HttpMethod.PUT), eq(url), eq(testObject)); + verify(mockLoggingService).logResponse(any(EELFLogger.class), eq(HttpMethod.PUT), eq(url), eq(jsonNodeHttpResponse)); assertEquals(jsonNodeHttpResponse.getStatus(), 201); assertEquals(jsonNodeHttpResponse.getBody().getObject().get("key"), 1); assertEquals(jsonNodeHttpResponse.getBody().getObject().get("value"), "test"); @@ -189,6 +209,8 @@ public class SyncRestClientForHttpServerTest { .put(url, Collections.emptyMap(), testObject, SyncRestClientModel.TestModel.class); // then verifyHttp(stubServer).once(Condition.method(Method.PUT), Condition.url(url)); + verify(mockLoggingService).logRequest(any(EELFLogger.class), eq(HttpMethod.PUT), eq(url), eq(testObject)); + verify(mockLoggingService).logResponse(any(EELFLogger.class), eq(HttpMethod.PUT), eq(url), eq(modelHttpResponse)); assertEquals(modelHttpResponse.getStatus(), 201); assertEquals(modelHttpResponse.getBody().getKey(), 1); assertEquals(modelHttpResponse.getBody().getValue(), "test"); @@ -203,6 +225,8 @@ public class SyncRestClientForHttpServerTest { HttpResponse<JsonNode> jsonNodeHttpResponse = syncRestClient.delete(url, Collections.emptyMap()); // then verifyHttp(stubServer).once(Condition.method(Method.DELETE), Condition.url(url)); + verify(mockLoggingService).logRequest(any(EELFLogger.class), eq(HttpMethod.DELETE), eq(url)); + verify(mockLoggingService).logResponse(any(EELFLogger.class), eq(HttpMethod.DELETE), eq(url), eq(jsonNodeHttpResponse)); assertEquals(jsonNodeHttpResponse.getStatus(), 200); assertEquals(jsonNodeHttpResponse.getBody().getObject().get("key"), 1); assertEquals(jsonNodeHttpResponse.getBody().getObject().get("value"), "test"); @@ -218,6 +242,8 @@ public class SyncRestClientForHttpServerTest { .delete(url, Collections.emptyMap(), SyncRestClientModel.TestModel.class); // then verifyHttp(stubServer).once(Condition.method(Method.DELETE), Condition.url(url)); + verify(mockLoggingService).logRequest(any(EELFLogger.class), eq(HttpMethod.DELETE), eq(url)); + verify(mockLoggingService).logResponse(any(EELFLogger.class), eq(HttpMethod.DELETE), eq(url), eq(modelHttpResponse)); assertEquals(modelHttpResponse.getStatus(), 200); assertEquals(modelHttpResponse.getBody().getKey(), 1); assertEquals(modelHttpResponse.getBody().getValue(), "test"); diff --git a/vid-app-common/src/test/java/org/onap/vid/client/SyncRestClientForHttpsServerTest.java b/vid-app-common/src/test/java/org/onap/vid/client/SyncRestClientForHttpsServerTest.java index 758dd070b..f4692c564 100644 --- a/vid-app-common/src/test/java/org/onap/vid/client/SyncRestClientForHttpsServerTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/client/SyncRestClientForHttpsServerTest.java @@ -3,6 +3,7 @@ * VID * ================================================================================ * Copyright (C) 2018 - 2019 Nokia. All rights reserved. + * Modifications Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,9 +27,13 @@ import static com.xebialabs.restito.semantics.Action.contentType; import static com.xebialabs.restito.semantics.Action.ok; import static com.xebialabs.restito.semantics.Action.stringContent; import static org.apache.http.client.config.RequestConfig.custom; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import static org.testng.Assert.assertEquals; +import com.att.eelf.configuration.EELFLogger; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.xebialabs.restito.semantics.Action; @@ -50,6 +55,7 @@ import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.glassfish.grizzly.http.Method; import org.onap.vid.utils.Logging; +import org.springframework.http.HttpMethod; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -89,6 +95,8 @@ public class SyncRestClientForHttpsServerTest { // then verifyHttp(stubServer) .once(Condition.method(Method.GET), Condition.url(securedUrl), Condition.not(Condition.url(notSecuredUrl))); + verify(mockLoggingService).logRequest(any(EELFLogger.class), eq(HttpMethod.GET), eq(securedUrl), eq(Collections.emptyMap())); + verify(mockLoggingService).logResponse(any(EELFLogger.class), eq(HttpMethod.GET), eq(securedUrl), eq(jsonNodeHttpResponse)); assertEquals(jsonNodeHttpResponse.getStatus(), 200); assertEquals(jsonNodeHttpResponse.getBody().getObject().get("key"), 1); assertEquals(jsonNodeHttpResponse.getBody().getObject().get("value"), "test"); @@ -107,6 +115,8 @@ public class SyncRestClientForHttpsServerTest { // then verifyHttp(stubServer) .once(Condition.method(Method.GET), Condition.url(securedUrl), Condition.not(Condition.url(notSecuredUrl))); + verify(mockLoggingService).logRequest(any(EELFLogger.class), eq(HttpMethod.GET), eq(securedUrl), eq(Collections.emptyMap())); + verify(mockLoggingService).logResponse(any(EELFLogger.class), eq(HttpMethod.GET), eq(securedUrl), eq(testModelHttpResponse)); assertEquals(testModelHttpResponse.getStatus(), 200); assertEquals(testModelHttpResponse.getBody().getKey(), 1); assertEquals(testModelHttpResponse.getBody().getValue(), "test"); |