From 09893f98631753467a9c2ec8c591b917c0bc25c4 Mon Sep 17 00:00:00 2001 From: pwielebs Date: Mon, 11 Jun 2018 13:39:31 +0200 Subject: 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 --- .../prh/service/AAIProducerClientTest.java | 32 +++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AAIProducerClientTest.java') 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"); -- cgit 1.2.3-korg