diff options
Diffstat (limited to 'prh-aai-client/src/test/java/org')
-rw-r--r-- | prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AaiConsumerClientTest.java (renamed from prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AAIConsumerClientTest.java) | 49 | ||||
-rw-r--r-- | prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AaiHttpClientImplTest.java (renamed from prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AAIHttpClientImplTest.java) | 26 | ||||
-rw-r--r-- | prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AaiProducerClientTest.java (renamed from prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AAIProducerClientTest.java) | 63 |
3 files changed, 66 insertions, 72 deletions
diff --git a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AAIConsumerClientTest.java b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AaiConsumerClientTest.java index 6045c007..8b4a2110 100644 --- a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AAIConsumerClientTest.java +++ b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AaiConsumerClientTest.java @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * PNF-REGISTRATION-HANDLER * ================================================================================ @@ -20,14 +20,9 @@ package org.onap.dcaegen2.services.prh.service; -import org.apache.http.client.ResponseHandler; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.junit.jupiter.api.Assertions; -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.ConsumerDmaapModel; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import java.io.IOException; import java.lang.reflect.Field; @@ -35,21 +30,27 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import org.apache.http.client.ResponseHandler; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.junit.jupiter.api.Assertions; +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.ConsumerDmaapModel; -public class AAIConsumerClientTest { +class AaiConsumerClientTest { - private static AAIConsumerClient testedObject; - private static AAIClientConfiguration aaiHttpClientConfigurationMock = mock(AAIClientConfiguration.class); + private static AaiConsumerClient testedObject; + private static AaiClientConfiguration aaiHttpClientConfigurationMock = mock(AaiClientConfiguration.class); private static CloseableHttpClient closeableHttpClientMock = mock(CloseableHttpClient.class); - private static final String JSON_MESSAGE = "{ \"pnf-id\": \"example-pnf-id-val-22343\", \"regional-resource-zone\":null, \"ipaddress-v4-oam\": \"11.22.33.44\" }"; - private static ConsumerDmaapModel consumerDmaapModelMock = mock(ConsumerDmaapModel.class); + private static final String JSON_MESSAGE = "{ \"pnf-id\": \"example-pnf-id-val-22343\", " + + "\"regional-resource-zone\":null, \"ipaddress-v4-oam\": \"11.22.33.44\" }"; + private static ConsumerDmaapModel consumerDmaapModelMock = mock(ConsumerDmaapModel.class); private static final String PNF_NAME = "nokia-pnf-nhfsadhff"; @BeforeAll - public static void setup() throws NoSuchFieldException, IllegalAccessException { + static void setup() throws NoSuchFieldException, IllegalAccessException { Map<String, String> aaiHeaders = new HashMap<>(); aaiHeaders.put("X-FromAppId", "prh"); @@ -70,18 +71,18 @@ public class AAIConsumerClientTest { when(consumerDmaapModelMock.getPnfName()).thenReturn(PNF_NAME); - testedObject = new AAIConsumerClient(aaiHttpClientConfigurationMock); + testedObject = new AaiConsumerClient(aaiHttpClientConfigurationMock); setField(); } @Test - public void getExtendedDetails_returnsSuccess() throws IOException { + void getExtendedDetails_returnsSuccess() throws IOException { - when(closeableHttpClientMock.execute(any(HttpGet.class), any(ResponseHandler.class))). - thenReturn(Optional.of(JSON_MESSAGE)); - Optional<String> actualResult = testedObject.getHttpResponse(consumerDmaapModelMock); - Assertions.assertEquals(Optional.of(JSON_MESSAGE),actualResult); + when(closeableHttpClientMock.execute(any(HttpGet.class), any(ResponseHandler.class))) + .thenReturn(Optional.of(JSON_MESSAGE)); + Optional<String> actualResult = testedObject.getHttpResponse(consumerDmaapModelMock); + Assertions.assertEquals(Optional.of(JSON_MESSAGE), actualResult); } diff --git a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AAIHttpClientImplTest.java b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AaiHttpClientImplTest.java index 0e713856..419fe32b 100644 --- a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AAIHttpClientImplTest.java +++ b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/AaiHttpClientImplTest.java @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * PNF-REGISTRATION-HANDLER * ================================================================================ @@ -17,40 +17,38 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.dcaegen2.services.prh.service; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration; +package org.onap.dcaegen2.services.prh.service; import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration; -public class AAIHttpClientImplTest { +class AaiHttpClientImplTest { - private static AAIClientImpl testedObject; - private static AAIClientConfiguration aaiHttpClientConfigurationMock; + private static AaiClientImpl testedObject; @BeforeAll public static void setup() { - aaiHttpClientConfigurationMock = mock(AAIClientConfiguration.class); + AaiClientConfiguration aaiHttpClientConfigurationMock = mock(AaiClientConfiguration.class); when(aaiHttpClientConfigurationMock.aaiHost()).thenReturn("54.45.33.2"); when(aaiHttpClientConfigurationMock.aaiProtocol()).thenReturn("https"); when(aaiHttpClientConfigurationMock.aaiHostPortNumber()).thenReturn(1234); when(aaiHttpClientConfigurationMock.aaiUserName()).thenReturn("PNF"); when(aaiHttpClientConfigurationMock.aaiUserPassword()).thenReturn("PNF"); - when(aaiHttpClientConfigurationMock.aaiIgnoreSSLCertificateErrors()).thenReturn(true); + when(aaiHttpClientConfigurationMock.aaiIgnoreSslCertificateErrors()).thenReturn(true); - testedObject = new AAIClientImpl(aaiHttpClientConfigurationMock); + testedObject = new AaiClientImpl(aaiHttpClientConfigurationMock); } @Test - public void getAAIHttpClientObject_shouldNotBeNull() { - testedObject.getAAIHttpClient(); - assertNotNull(testedObject.getAAIHttpClient()); + public void getAaiHttpClientObject_shouldNotBeNull() { + assertNotNull(testedObject.getAaiHttpClient()); } } 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 b7515ad5..27cb374d 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,6 +20,21 @@ package org.onap.dcaegen2.services.prh.service; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.lang.reflect.Field; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; @@ -29,40 +44,22 @@ 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.config.AaiClientConfiguration; import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModelForUnitTest; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.lang.reflect.Field; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -class AAIProducerClientTest { +class AaiProducerClientTest { private static final Integer SUCCESS = 200; - private static AAIProducerClient testedObject; - private static AAIClientConfiguration aaiHttpClientConfigurationMock = mock(AAIClientConfiguration.class); + private static final HttpResponse httpResponseMock = mock(HttpResponse.class); + private static final HttpEntity httpEntityMock = mock(HttpEntity.class); + private static final StatusLine statusLineMock = mock(StatusLine.class); + + private static AaiProducerClient testedObject; + private static AaiClientConfiguration aaiHttpClientConfigurationMock = mock(AaiClientConfiguration.class); 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 { when(aaiHttpClientConfigurationMock.aaiHost()).thenReturn("eucalyptus.es-si-eu-dhn-20.eecloud.nsn-net.net"); @@ -74,7 +71,7 @@ class AAIProducerClientTest { when(aaiHttpClientConfigurationMock.aaiPnfPath()).thenReturn("/network/pnfs/pnf"); when(aaiHttpClientConfigurationMock.aaiHeaders()).thenReturn(setupHeaders()); - testedObject = new AAIProducerClient(aaiHttpClientConfigurationMock); + testedObject = new AaiProducerClient(aaiHttpClientConfigurationMock); setField(); } @@ -82,19 +79,18 @@ class AAIProducerClientTest { void getHttpResponse_shouldReturnSuccessStatusCode() throws IOException, URISyntaxException { // when when(closeableHttpClientMock.execute(any(HttpPatch.class), any(ResponseHandler.class))) - .thenReturn(Optional.of(SUCCESS)); + .thenReturn(Optional.of(SUCCESS)); Optional<Integer> actualResult = testedObject.getHttpResponse(consumerDmaapModel); // then assertEquals(SUCCESS, actualResult.get()); } @Test - void getHttpResponse_shouldHandleIOException() throws IOException, URISyntaxException { + void getHttpResponse_shouldHandleIoException() throws IOException, URISyntaxException { // when when(closeableHttpClientMock.execute(any(HttpPatch.class), any(ResponseHandler.class))) - .thenThrow(new IOException("Error occur")); + .thenThrow(new IOException("Error occur")); - testedObject.getHttpResponse(consumerDmaapModel); // then assertNotNull(testedObject.getHttpResponse(consumerDmaapModel)); } @@ -103,8 +99,7 @@ class AAIProducerClientTest { void createHttpRequest_shouldCatchUnsupportedEncodingException() throws URISyntaxException, IOException { // when when(closeableHttpClientMock.execute(any(HttpPatch.class), any(ResponseHandler.class))) - .thenThrow(new UnsupportedEncodingException("A new Error")); - testedObject.getHttpResponse(consumerDmaapModel); + .thenThrow(new UnsupportedEncodingException("A new Error")); // then assertNotNull(testedObject.getHttpResponse(consumerDmaapModel)); } @@ -158,7 +153,7 @@ class AAIProducerClientTest { field.set(testedObject, closeableHttpClientMock); } - private static Map<String,String> setupHeaders() { + private static Map<String, String> setupHeaders() { Map<String, String> aaiHeaders = new HashMap<>(); aaiHeaders.put("X-FromAppId", "prh"); aaiHeaders.put("X-TransactionId", "vv-temp"); |