aboutsummaryrefslogtreecommitdiffstats
path: root/prh-aai-client/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'prh-aai-client/src/test')
-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");