From 3e559e25389b24d1cacedc8983334054e33faf14 Mon Sep 17 00:00:00 2001 From: wasala Date: Thu, 17 May 2018 08:16:09 +0200 Subject: Change package in prh-dmaap-client module Move package org.onap.dcaegen2.services to org.onap.dcaegen2.services.prh Change-Id: Idef63833dcbc9cd28dda6b893245fcd16df4d97d Issue-ID: DCAEGEN2-396 Signed-off-by: wasala --- .../ExtendedDmaapConsumerHttpClientImplTest.java | 96 +++++++++++++++++++++ .../ExtendedDmaapProducerHttpClientImplTest.java | 98 ++++++++++++++++++++++ .../ExtendedDmaapConsumerHttpClientImplTest.java | 96 --------------------- .../ExtendedDmaapProducerHttpClientImplTest.java | 98 ---------------------- 4 files changed, 194 insertions(+), 194 deletions(-) create mode 100644 prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/consumer/ExtendedDmaapConsumerHttpClientImplTest.java create mode 100644 prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/ExtendedDmaapProducerHttpClientImplTest.java delete mode 100644 prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/consumer/ExtendedDmaapConsumerHttpClientImplTest.java delete mode 100644 prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImplTest.java (limited to 'prh-dmaap-client/src/test/java/org') diff --git a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/consumer/ExtendedDmaapConsumerHttpClientImplTest.java b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/consumer/ExtendedDmaapConsumerHttpClientImplTest.java new file mode 100644 index 00000000..39c10de5 --- /dev/null +++ b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/consumer/ExtendedDmaapConsumerHttpClientImplTest.java @@ -0,0 +1,96 @@ +/*- + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2018 NOKIA 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.prh.service.consumer; + +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.DmaapConsumerConfiguration; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.util.Optional; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + + +public class ExtendedDmaapConsumerHttpClientImplTest { + + private static ExtendedDmaapConsumerHttpClientImpl objectUnderTest; + + private static DmaapConsumerConfiguration configurationMock = mock(DmaapConsumerConfiguration.class); + private static CloseableHttpClient closeableHttpClientMock = mock(CloseableHttpClient.class); + + private static final String JSON_MESSAGE = "{ \"responseFromDmaap\": \"Success\" }"; + + private static Optional expectedResult = Optional.empty(); + + @BeforeAll + public static void init() throws NoSuchFieldException, IllegalAccessException { + + when(configurationMock.dmaapHostName()).thenReturn("54.45.33.2"); + when(configurationMock.dmaapProtocol()).thenReturn("https"); + when(configurationMock.dmaapPortNumber()).thenReturn(1234); + when(configurationMock.dmaapUserName()).thenReturn("PRH"); + when(configurationMock.dmaapUserPassword()).thenReturn("PRH"); + when(configurationMock.dmaapContentType()).thenReturn("application/json"); + when(configurationMock.dmaapTopicName()).thenReturn("unauthenticated.SEC_OTHER_OUTPUT"); + when(configurationMock.consumerGroup()).thenReturn("OpenDCAE-c12"); + when(configurationMock.consumerId()).thenReturn("c12"); + + objectUnderTest = new ExtendedDmaapConsumerHttpClientImpl(configurationMock); + + setField(); + } + + + @Test + public void getHttpResponseGet_success() throws IOException { + expectedResult = Optional.of(JSON_MESSAGE); + + when(closeableHttpClientMock.execute(any(HttpGet.class), any(ResponseHandler.class))) + .thenReturn(expectedResult); + + Optional actualResult = objectUnderTest.getHttpConsumerResponse(); + + Assertions.assertEquals(expectedResult.get(), actualResult.get()); + } + + @Test + public void getExtendedDetails_returnsNull() throws IOException { + when(closeableHttpClientMock.execute(any(HttpGet.class), any(ResponseHandler.class))). + thenReturn(Optional.empty()); + Optional actualResult = objectUnderTest.getHttpConsumerResponse(); + Assertions.assertEquals(Optional.empty(),actualResult); + } + + + private static void setField() throws NoSuchFieldException, IllegalAccessException { + Field field = objectUnderTest.getClass().getDeclaredField("closeableHttpClient"); + field.setAccessible(true); + field.set(objectUnderTest, closeableHttpClientMock); + } +} diff --git a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/ExtendedDmaapProducerHttpClientImplTest.java b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/ExtendedDmaapProducerHttpClientImplTest.java new file mode 100644 index 00000000..3cb84206 --- /dev/null +++ b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/ExtendedDmaapProducerHttpClientImplTest.java @@ -0,0 +1,98 @@ +/*- + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2018 NOKIA 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.prh.service.producer; + +import org.apache.http.client.ResponseHandler; +import org.apache.http.client.methods.HttpPost; +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.DmaapPublisherConfiguration; +import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; +import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModelForUnitTest; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.util.Optional; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + + +public class ExtendedDmaapProducerHttpClientImplTest { + + private static ExtendedDmaapProducerHttpClientImpl objectUnderTest; + + private static DmaapPublisherConfiguration configurationMock = mock(DmaapPublisherConfiguration.class); + private static CloseableHttpClient closeableHttpClientMock = mock(CloseableHttpClient.class); + private static ConsumerDmaapModel consumerDmaapModel = new ConsumerDmaapModelForUnitTest(); + + private static Optional expectedResult = Optional.empty(); + private static final String RESPONSE_SUCCESS = "200"; + private static final String RESPONSE_FAILURE = "404"; + + @BeforeAll + public static void init() throws NoSuchFieldException, IllegalAccessException { + + when(configurationMock.dmaapHostName()).thenReturn("54.45.33.2"); + when(configurationMock.dmaapProtocol()).thenReturn("https"); + when(configurationMock.dmaapPortNumber()).thenReturn(1234); + when(configurationMock.dmaapUserName()).thenReturn("PRH"); + when(configurationMock.dmaapUserPassword()).thenReturn("PRH"); + when(configurationMock.dmaapContentType()).thenReturn("application/json"); + when(configurationMock.dmaapTopicName()).thenReturn("pnfReady"); + + objectUnderTest = new ExtendedDmaapProducerHttpClientImpl(configurationMock); + + setField(); + } + + + @Test + public void getHttpResponsePost_success() throws IOException { + expectedResult = Optional.of(RESPONSE_SUCCESS); + + when(closeableHttpClientMock.execute(any(HttpPost.class), any(ResponseHandler.class))) + .thenReturn(expectedResult); + + Optional actualResult = objectUnderTest.getHttpProducerResponse(consumerDmaapModel); + + Assertions.assertEquals(expectedResult.get(), actualResult.get()); + } + + @Test + public void getExtendedDetails_returnsFailure() throws IOException { + expectedResult = Optional.of(RESPONSE_FAILURE); + when(closeableHttpClientMock.execute(any(HttpPost.class), any(ResponseHandler.class))) + .thenReturn(Optional.empty()); + Optional actualResult = objectUnderTest.getHttpProducerResponse(consumerDmaapModel); + Assertions.assertEquals(Optional.empty(), actualResult); + } + + + private static void setField() throws NoSuchFieldException, IllegalAccessException { + Field field = objectUnderTest.getClass().getDeclaredField("closeableHttpClient"); + field.setAccessible(true); + field.set(objectUnderTest, closeableHttpClientMock); + } +} diff --git a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/consumer/ExtendedDmaapConsumerHttpClientImplTest.java b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/consumer/ExtendedDmaapConsumerHttpClientImplTest.java deleted file mode 100644 index 1df025ca..00000000 --- a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/consumer/ExtendedDmaapConsumerHttpClientImplTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * PNF-REGISTRATION-HANDLER - * ================================================================================ - * Copyright (C) 2018 NOKIA 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.dcaegen2.services.service.consumer; - -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.config.DmaapConsumerConfiguration; - -import java.io.IOException; -import java.lang.reflect.Field; -import java.util.Optional; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - - -public class ExtendedDmaapConsumerHttpClientImplTest { - - private static ExtendedDmaapConsumerHttpClientImpl objectUnderTest; - - private static DmaapConsumerConfiguration configurationMock = mock(DmaapConsumerConfiguration.class); - private static CloseableHttpClient closeableHttpClientMock = mock(CloseableHttpClient.class); - - private static final String JSON_MESSAGE = "{ \"responseFromDmaap\": \"Success\" }"; - - private static Optional expectedResult = Optional.empty(); - - @BeforeAll - public static void init() throws NoSuchFieldException, IllegalAccessException { - - when(configurationMock.dmaapHostName()).thenReturn("54.45.33.2"); - when(configurationMock.dmaapProtocol()).thenReturn("https"); - when(configurationMock.dmaapPortNumber()).thenReturn(1234); - when(configurationMock.dmaapUserName()).thenReturn("PRH"); - when(configurationMock.dmaapUserPassword()).thenReturn("PRH"); - when(configurationMock.dmaapContentType()).thenReturn("application/json"); - when(configurationMock.dmaapTopicName()).thenReturn("unauthenticated.SEC_OTHER_OUTPUT"); - when(configurationMock.consumerGroup()).thenReturn("OpenDCAE-c12"); - when(configurationMock.consumerId()).thenReturn("c12"); - - objectUnderTest = new ExtendedDmaapConsumerHttpClientImpl(configurationMock); - - setField(); - } - - - @Test - public void getHttpResponseGet_success() throws IOException { - expectedResult = Optional.of(JSON_MESSAGE); - - when(closeableHttpClientMock.execute(any(HttpGet.class), any(ResponseHandler.class))) - .thenReturn(expectedResult); - - Optional actualResult = objectUnderTest.getHttpConsumerResponse(); - - Assertions.assertEquals(expectedResult.get(), actualResult.get()); - } - - @Test - public void getExtendedDetails_returnsNull() throws IOException { - when(closeableHttpClientMock.execute(any(HttpGet.class), any(ResponseHandler.class))). - thenReturn(Optional.empty()); - Optional actualResult = objectUnderTest.getHttpConsumerResponse(); - Assertions.assertEquals(Optional.empty(),actualResult); - } - - - private static void setField() throws NoSuchFieldException, IllegalAccessException { - Field field = objectUnderTest.getClass().getDeclaredField("closeableHttpClient"); - field.setAccessible(true); - field.set(objectUnderTest, closeableHttpClientMock); - } -} diff --git a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImplTest.java b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImplTest.java deleted file mode 100644 index 6e7d81f6..00000000 --- a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImplTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * PNF-REGISTRATION-HANDLER - * ================================================================================ - * Copyright (C) 2018 NOKIA 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.dcaegen2.services.service.producer; - -import org.apache.http.client.ResponseHandler; -import org.apache.http.client.methods.HttpPost; -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.config.DmaapPublisherConfiguration; -import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; -import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModelForUnitTest; - -import java.io.IOException; -import java.lang.reflect.Field; -import java.util.Optional; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - - -public class ExtendedDmaapProducerHttpClientImplTest { - - private static ExtendedDmaapProducerHttpClientImpl objectUnderTest; - - private static DmaapPublisherConfiguration configurationMock = mock(DmaapPublisherConfiguration.class); - private static CloseableHttpClient closeableHttpClientMock = mock(CloseableHttpClient.class); - private static ConsumerDmaapModel consumerDmaapModel = new ConsumerDmaapModelForUnitTest(); - - private static Optional expectedResult = Optional.empty(); - private static final String RESPONSE_SUCCESS = "200"; - private static final String RESPONSE_FAILURE = "404"; - - @BeforeAll - public static void init() throws NoSuchFieldException, IllegalAccessException { - - when(configurationMock.dmaapHostName()).thenReturn("54.45.33.2"); - when(configurationMock.dmaapProtocol()).thenReturn("https"); - when(configurationMock.dmaapPortNumber()).thenReturn(1234); - when(configurationMock.dmaapUserName()).thenReturn("PRH"); - when(configurationMock.dmaapUserPassword()).thenReturn("PRH"); - when(configurationMock.dmaapContentType()).thenReturn("application/json"); - when(configurationMock.dmaapTopicName()).thenReturn("pnfReady"); - - objectUnderTest = new ExtendedDmaapProducerHttpClientImpl(configurationMock); - - setField(); - } - - - @Test - public void getHttpResponsePost_success() throws IOException { - expectedResult = Optional.of(RESPONSE_SUCCESS); - - when(closeableHttpClientMock.execute(any(HttpPost.class), any(ResponseHandler.class))) - .thenReturn(expectedResult); - - Optional actualResult = objectUnderTest.getHttpProducerResponse(consumerDmaapModel); - - Assertions.assertEquals(expectedResult.get(), actualResult.get()); - } - - @Test - public void getExtendedDetails_returnsFailure() throws IOException { - expectedResult = Optional.of(RESPONSE_FAILURE); - when(closeableHttpClientMock.execute(any(HttpPost.class), any(ResponseHandler.class))) - .thenReturn(Optional.empty()); - Optional actualResult = objectUnderTest.getHttpProducerResponse(consumerDmaapModel); - Assertions.assertEquals(Optional.empty(), actualResult); - } - - - private static void setField() throws NoSuchFieldException, IllegalAccessException { - Field field = objectUnderTest.getClass().getDeclaredField("closeableHttpClient"); - field.setAccessible(true); - field.set(objectUnderTest, closeableHttpClientMock); - } -} -- cgit 1.2.3-korg