diff options
author | 2018-06-26 19:29:43 +0200 | |
---|---|---|
committer | 2018-08-07 08:32:28 +0200 | |
commit | c8c9a242f7a1f8454e2cf94b0442128533569dc5 (patch) | |
tree | 784673c75693f6f77b624e5c83c12e24b73646ec /prh-app-server/src/test/java | |
parent | 8b1502fb0f1af5d00ec26e712e57b792fbd16bd8 (diff) |
DmaapConsumerReactive fixed tests
Change-Id: I888ef94a084f32a18c77c12a18fb6636a4f33649
Issue-ID: DCAEGEN2-557
Signed-off-by: wasala <przemyslaw.wasala@nokia.com>
Diffstat (limited to 'prh-app-server/src/test/java')
4 files changed, 118 insertions, 119 deletions
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/IT/ScheduledXmlContextITest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/IT/ScheduledXmlContextITest.java index 1d740c4a..95e00809 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/IT/ScheduledXmlContextITest.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/IT/ScheduledXmlContextITest.java @@ -1,83 +1,83 @@ -///*- -// * ============LICENSE_START======================================================= -// * PROJECT -// * ================================================================================ -// * 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.IT; -// -//import static org.mockito.Mockito.atLeast; -//import static org.mockito.Mockito.mock; -//import static org.mockito.Mockito.verify; -// -//import java.util.concurrent.Executors; -//import java.util.concurrent.ScheduledExecutorService; -//import java.util.concurrent.TimeUnit; -//import org.junit.jupiter.api.Test; -//import org.junit.jupiter.api.extension.ExtendWith; -//import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; -//import org.onap.dcaegen2.services.prh.IT.junit5.mockito.MockitoExtension; -//import org.onap.dcaegen2.services.prh.configuration.PrhAppConfig; -//import org.onap.dcaegen2.services.prh.tasks.ScheduledTasks; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.context.annotation.Bean; -//import org.springframework.context.annotation.ComponentScan; -//import org.springframework.context.annotation.Configuration; -//import org.springframework.test.context.ContextConfiguration; -//import org.springframework.test.context.junit.jupiter.SpringExtension; -//import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; -// -///** -// * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/27/18 -// */ -// -//@Configuration -//@ComponentScan -//@ExtendWith({MockitoExtension.class, SpringExtension.class}) -//@ContextConfiguration(locations = {"classpath:scheduled-context.xml"}) -//class ScheduledXmlContextITest extends AbstractTestNGSpringContextTests { -// -// private static final int WAIT_FOR_SCHEDULING = 1; -// -// @Autowired -// private ScheduledTasks scheduledTask; -// -// @Test -// void testScheduling() { -// final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(); -// executorService.scheduleWithFixedDelay(this::verifyDmaapConsumerTask, 0, WAIT_FOR_SCHEDULING, TimeUnit.SECONDS); -// } -// -// private void verifyDmaapConsumerTask() { -// verify(scheduledTask, atLeast(1)).scheduleMainPrhEventTask(); -// } -//} -// -//@Configuration -//class ServiceMockProvider { -// -// @Bean -// public PrhAppConfig getPrhAppConfig() { -// return mock(PrhAppConfig.class); -// } -// -// @Bean -// public ConsumerDmaapModel getRequestDetails() { -// return mock(ConsumerDmaapModel.class); -// } -//} -// -// +/*- + * ============LICENSE_START======================================================= + * PROJECT + * ================================================================================ + * 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.IT; + +import static org.mockito.Mockito.atLeast; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; +import org.onap.dcaegen2.services.prh.IT.junit5.mockito.MockitoExtension; +import org.onap.dcaegen2.services.prh.configuration.PrhAppConfig; +import org.onap.dcaegen2.services.prh.tasks.ScheduledTasks; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; + +/** + * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/27/18 + */ + +@Configuration +@ComponentScan +@ExtendWith({MockitoExtension.class, SpringExtension.class}) +@ContextConfiguration(locations = {"classpath:scheduled-context.xml"}) +class ScheduledXmlContextITest extends AbstractTestNGSpringContextTests { + + private static final int WAIT_FOR_SCHEDULING = 1; + + @Autowired + private ScheduledTasks scheduledTask; + + @Test + void testScheduling() { + final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(); + executorService.scheduleWithFixedDelay(this::verifyDmaapConsumerTask, 0, WAIT_FOR_SCHEDULING, TimeUnit.SECONDS); + } + + private void verifyDmaapConsumerTask() { + verify(scheduledTask, atLeast(1)).scheduleMainPrhEventTask(); + } +} + +@Configuration +class ServiceMockProvider { + + @Bean + public PrhAppConfig getPrhAppConfig() { + return mock(PrhAppConfig.class); + } + + @Bean + public ConsumerDmaapModel getRequestDetails() { + return mock(ConsumerDmaapModel.class); + } +} + + diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java index f1dd87ef..f24ef413 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java @@ -28,7 +28,6 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException; -import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException; import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel; import reactor.core.publisher.Mono; @@ -99,7 +98,8 @@ class DmaapConsumerJsonParserTest { JsonElement jsonElement = new JsonParser().parse(parsed); Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())) .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement); - ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser.getJsonObject(Mono.just(message)).block(); + ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser + .getJsonObject(Mono.just(Optional.of(message))).block().get(); //then Assertions.assertNotNull(consumerDmaapModel); Assertions.assertEquals(expectedObject, consumerDmaapModel); @@ -138,7 +138,8 @@ class DmaapConsumerJsonParserTest { JsonElement jsonElement = new JsonParser().parse(parsed); Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())) .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement); - ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser.getJsonObject(Mono.just(message)).block(); + ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser.getJsonObject(Mono.just(Optional.of(message))) + .block().get(); //then Assertions.assertNotNull(consumerDmaapModel); Assertions.assertEquals(expectedObject, consumerDmaapModel); @@ -175,7 +176,8 @@ class DmaapConsumerJsonParserTest { JsonElement jsonElement = new JsonParser().parse(parsed); Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())) .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement); - ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser.getJsonObject(Mono.just(message)).block(); + ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser.getJsonObject(Mono.just(Optional.of(message))) + .block().get(); //then Assertions.assertNotNull(consumerDmaapModel); Assertions.assertEquals(expectedObject, consumerDmaapModel); @@ -205,7 +207,7 @@ class DmaapConsumerJsonParserTest { JsonElement jsonElement = new JsonParser().parse(parsed); Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())) .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement); - StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(message))) + StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(Optional.of(message)))) .expectSubscription().expectError(DmaapNotFoundException.class); } @@ -221,7 +223,7 @@ class DmaapConsumerJsonParserTest { JsonElement jsonElement = new JsonParser().parse(parsed); Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())) .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement); - StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(incorrectMessage))) + StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(Optional.of(incorrectMessage)))) .expectSubscription().expectError(DmaapNotFoundException.class); } @@ -240,7 +242,8 @@ class DmaapConsumerJsonParserTest { JsonElement jsonElement = new JsonParser().parse(parsed); Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())) .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement); - StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(jsonWithoutPnfVendorAndSerialNumber))) + StepVerifier + .create(dmaapConsumerJsonParser.getJsonObject(Mono.just(Optional.of(jsonWithoutPnfVendorAndSerialNumber)))) .expectSubscription().expectError(DmaapNotFoundException.class); } @@ -259,7 +262,7 @@ class DmaapConsumerJsonParserTest { JsonElement jsonElement = new JsonParser().parse(parsed); Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())) .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement); - StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(jsonWithoutIPInformation))) + StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(Optional.of(jsonWithoutIPInformation)))) .expectSubscription().expectError(DmaapNotFoundException.class); } -}
\ No newline at end of file +} diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java index 18be4367..f9d7c7f1 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java @@ -34,26 +34,27 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.function.Executable; import org.mockito.Mockito; import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration; import org.onap.dcaegen2.services.prh.config.ImmutableDmaapConsumerConfiguration; import org.onap.dcaegen2.services.prh.configuration.AppConfig; +import org.onap.dcaegen2.services.prh.exceptions.DmaapEmptyResponseException; import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException; import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel; import org.onap.dcaegen2.services.prh.service.DmaapConsumerJsonParser; -import org.onap.dcaegen2.services.prh.service.consumer.ExtendedDmaapConsumerHttpClientImpl; +import org.onap.dcaegen2.services.prh.service.consumer.DmaapConsumerReactiveHttpClient; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/17/18 */ -@Disabled class DmaapConsumerTaskImplTest { private static ConsumerDmaapModel consumerDmaapModel; private static DmaapConsumerTaskImpl dmaapConsumerTask; - private static ExtendedDmaapConsumerHttpClientImpl extendedDmaapConsumerHttpClient; + private static DmaapConsumerReactiveHttpClient dmaapConsumerReactiveHttpClient; private static AppConfig appConfig; private static DmaapConsumerConfiguration dmaapConsumerConfiguration; private static String message; @@ -93,19 +94,16 @@ class DmaapConsumerTaskImplTest { } @Test - public void whenPassedObjectDoesntFit_DoesNotThrowPrhTaskException() { + public void whenPassedObjectDoesntFit_DoesNotThrowPrhTaskException() throws PrhTaskException { //given prepareMocksForDmaapConsumer(Optional.empty()); - //when - Executable executableFunction = () -> dmaapConsumerTask.execute("Sample input"); - //then - Assertions - .assertThrows(PrhTaskException.class, executableFunction, - "Throwing exception when http response code won't fit to assignment range"); - verify(extendedDmaapConsumerHttpClient, times(1)).getHttpConsumerResponse(); - verifyNoMoreInteractions(extendedDmaapConsumerHttpClient); + StepVerifier.create(dmaapConsumerTask.execute("Sample input")).expectSubscription() + .expectError(DmaapEmptyResponseException.class); + + verify(dmaapConsumerReactiveHttpClient, times(1)).getDmaaPConsumerResponse(); + verifyNoMoreInteractions(dmaapConsumerReactiveHttpClient); } @Test @@ -113,13 +111,14 @@ class DmaapConsumerTaskImplTest { //given prepareMocksForDmaapConsumer(Optional.of(message)); //when - ConsumerDmaapModel response = dmaapConsumerTask.execute("Sample input").block(); + + Mono<Optional<ConsumerDmaapModel>> response = dmaapConsumerTask.execute("Sample input"); //then - verify(extendedDmaapConsumerHttpClient, times(1)).getHttpConsumerResponse(); - verifyNoMoreInteractions(extendedDmaapConsumerHttpClient); + verify(dmaapConsumerReactiveHttpClient, times(1)).getDmaaPConsumerResponse(); + verifyNoMoreInteractions(dmaapConsumerReactiveHttpClient); Assertions.assertNotNull(response); - Assertions.assertEquals(consumerDmaapModel, response); + Assertions.assertEquals(consumerDmaapModel, response.block().get()); } @@ -128,11 +127,11 @@ class DmaapConsumerTaskImplTest { JsonElement jsonElement = new JsonParser().parse(parsed); Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())) .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement); - extendedDmaapConsumerHttpClient = mock(ExtendedDmaapConsumerHttpClientImpl.class); - when(extendedDmaapConsumerHttpClient.getHttpConsumerResponse()).thenReturn(message); + dmaapConsumerReactiveHttpClient = mock(DmaapConsumerReactiveHttpClient.class); + when(dmaapConsumerReactiveHttpClient.getDmaaPConsumerResponse()).thenReturn(Mono.just(message)); when(appConfig.getDmaapConsumerConfiguration()).thenReturn(dmaapConsumerConfiguration); dmaapConsumerTask = spy(new DmaapConsumerTaskImpl(appConfig, dmaapConsumerJsonParser)); when(dmaapConsumerTask.resolveConfiguration()).thenReturn(dmaapConsumerConfiguration); - doReturn(extendedDmaapConsumerHttpClient).when(dmaapConsumerTask).resolveClient(); + doReturn(dmaapConsumerReactiveHttpClient).when(dmaapConsumerTask).resolveClient(); } }
\ No newline at end of file diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskSpy.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskSpy.java index 5736afeb..225dd3f5 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskSpy.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskSpy.java @@ -22,13 +22,10 @@ package org.onap.dcaegen2.services.prh.tasks; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; -import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration; import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration; import org.onap.dcaegen2.services.prh.configuration.AppConfig; -import org.onap.dcaegen2.services.prh.service.AAIProducerClient; -import org.onap.dcaegen2.services.prh.service.consumer.ExtendedDmaapConsumerHttpClientImpl; +import org.onap.dcaegen2.services.prh.service.consumer.DmaapConsumerReactiveHttpClient; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; @@ -45,10 +42,10 @@ public class DmaapConsumerTaskSpy { AppConfig appConfig = spy(AppConfig.class); doReturn(mock(DmaapConsumerConfiguration.class)).when(appConfig).getDmaapConsumerConfiguration(); DmaapConsumerTaskImpl dmaapConsumerTask = spy(new DmaapConsumerTaskImpl(appConfig)); - ExtendedDmaapConsumerHttpClientImpl extendedDmaapConsumerHttpClient = mock( - ExtendedDmaapConsumerHttpClientImpl.class); + DmaapConsumerReactiveHttpClient dmaapConsumerReactiveHttpClient = mock( + DmaapConsumerReactiveHttpClient.class); doReturn(mock(DmaapConsumerConfiguration.class)).when(dmaapConsumerTask).resolveConfiguration(); - doReturn(extendedDmaapConsumerHttpClient).when(dmaapConsumerTask).resolveClient(); + doReturn(dmaapConsumerReactiveHttpClient).when(dmaapConsumerTask).resolveClient(); return dmaapConsumerTask; } } |