aboutsummaryrefslogtreecommitdiffstats
path: root/prh-aai-client/src/test/java
diff options
context:
space:
mode:
authorpwielebs <piotr.wielebski@nokia.com>2018-06-11 13:39:31 +0200
committerwasala <przemyslaw.wasala@nokia.com>2018-06-12 08:24:43 +0200
commit09893f98631753467a9c2ec8c591b917c0bc25c4 (patch)
tree6057670c6e40bea850c4d04cf762543564febf7e /prh-aai-client/src/test/java
parentdabda661a59fb07c640bfe96bfc4675e3b10f04f (diff)
handleResponse refactor
Due to logs consistency handleResponse method was incorporated to the each of http producers. Change-Id: I621d1795c376161273270f07ff3dd6caca2fc1d6 Issue-ID: DCAEGEN2-451 Signed-off-by: pwielebs <piotr.wielebski@nokia.com>
Diffstat (limited to 'prh-aai-client/src/test/java')
-rw-r--r--prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AAIProducerClientTest.java32
1 files changed, 31 insertions, 1 deletions
diff --git a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AAIProducerClientTest.java b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AAIProducerClientTest.java
index 1ef90180..b7515ad5 100644
--- a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AAIProducerClientTest.java
+++ b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AAIProducerClientTest.java
@@ -20,12 +20,17 @@
package org.onap.dcaegen2.services.prh.service;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.StatusLine;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpPatch;
import org.apache.http.impl.client.CloseableHttpClient;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration;
+import org.onap.dcaegen2.services.prh.model.CommonFunctions;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModelForUnitTest;
@@ -44,7 +49,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-public class AAIProducerClientTest {
+class AAIProducerClientTest {
private static final Integer SUCCESS = 200;
private static AAIProducerClient testedObject;
@@ -52,6 +57,11 @@ public class AAIProducerClientTest {
private static CloseableHttpClient closeableHttpClientMock = mock(CloseableHttpClient.class);
private static ConsumerDmaapModel consumerDmaapModel = new ConsumerDmaapModelForUnitTest();
+ private final static HttpResponse httpResponseMock = mock(HttpResponse.class);
+ private final static HttpEntity httpEntityMock = mock(HttpEntity.class);
+ private final static StatusLine statusLineMock = mock(StatusLine.class);
+
+
@BeforeAll
static void setup() throws NoSuchFieldException, IllegalAccessException {
@@ -121,6 +131,26 @@ public class AAIProducerClientTest {
assertEquals(expected, patch.getLastHeader("Authorization").toString());
}
+ @Test
+ void handleResponse_shouldReturn200() throws IOException {
+ // When
+ when(httpResponseMock.getEntity()).thenReturn(httpEntityMock);
+ when(httpResponseMock.getStatusLine()).thenReturn(statusLineMock);
+ when(httpResponseMock.getStatusLine().getStatusCode()).thenReturn(HttpStatus.SC_OK);
+ // Then
+ assertEquals(Optional.of(HttpStatus.SC_OK), testedObject.handleResponse(httpResponseMock));
+ }
+
+ @Test
+ void handleResponse_shouldReturn300() throws IOException {
+ // When
+ when(httpResponseMock.getEntity()).thenReturn(httpEntityMock);
+ when(httpResponseMock.getStatusLine()).thenReturn(statusLineMock);
+ when(httpResponseMock.getStatusLine().getStatusCode()).thenReturn(HttpStatus.SC_BAD_REQUEST);
+ // Then
+ assertEquals(Optional.of(HttpStatus.SC_BAD_REQUEST), testedObject.handleResponse(httpResponseMock));
+ }
+
private static void setField() throws NoSuchFieldException, IllegalAccessException {
Field field = testedObject.getClass().getDeclaredField("closeableHttpClient");