diff options
Diffstat (limited to 'prh-app-server')
6 files changed, 32 insertions, 122 deletions
diff --git a/prh-app-server/pom.xml b/prh-app-server/pom.xml index 9ab09495..b26ed86f 100644 --- a/prh-app-server/pom.xml +++ b/prh-app-server/pom.xml @@ -244,7 +244,7 @@ </dependency> <dependency> <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> + <artifactId>mockito-junit-jupiter</artifactId> <scope>test</scope> </dependency> <dependency> diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/ScheduledXmlContextITest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/ScheduledXmlContextITest.java index 03a3b51e..e0198536 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/ScheduledXmlContextITest.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/ScheduledXmlContextITest.java @@ -28,7 +28,7 @@ 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.integration.junit5.mockito.MockitoExtension; +import org.mockito.junit.jupiter.MockitoExtension; import org.onap.dcaegen2.services.prh.tasks.ScheduledTasks; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/junit5/mockito/MockitoExtension.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/junit5/mockito/MockitoExtension.java deleted file mode 100644 index af9c2b44..00000000 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/junit5/mockito/MockitoExtension.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * ============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.integration.junit5.mockito; - -import static org.mockito.Mockito.mock; - -import java.lang.reflect.Parameter; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.api.extension.ExtensionContext.Namespace; -import org.junit.jupiter.api.extension.ExtensionContext.Store; -import org.junit.jupiter.api.extension.ParameterContext; -import org.junit.jupiter.api.extension.ParameterResolver; -import org.junit.jupiter.api.extension.TestInstancePostProcessor; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -/** - * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/27/18 - * - * {@code MockitoExtension } showcases the {@link TestInstancePostProcessor} and {@link ParameterResolver} - * extension APIs of JUnit 5 by providing dependency injection support at the field level and at the method - * parameter level viaMockito 2.x's {@link Mock @Mock} annotation. - */ -public class MockitoExtension implements TestInstancePostProcessor, ParameterResolver { - - @Override - public void postProcessTestInstance(Object testInstance, ExtensionContext context) { - MockitoAnnotations.initMocks(testInstance); - } - - @Override - public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { - return parameterContext.getParameter().isAnnotationPresent(Mock.class); - } - - @Override - public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { - return getMock(parameterContext.getParameter(), extensionContext); - } - - private Object getMock(Parameter parameter, ExtensionContext extensionContext) { - Class<?> mockType = parameter.getType(); - Store mocks = extensionContext.getStore(Namespace.create(MockitoExtension.class, mockType)); - String mockName = getMockName(parameter); - - if (mockName != null) { - return mocks.getOrComputeIfAbsent(mockName, key -> mock(mockType, mockName)); - } else { - return mocks.getOrComputeIfAbsent(mockType.getCanonicalName(), key -> mock(mockType)); - } - } - - private String getMockName(Parameter parameter) { - String explicitMockName = parameter.getAnnotation(Mock.class).name().trim(); - if (!explicitMockName.isEmpty()) { - return explicitMockName; - } else if (parameter.isNamePresent()) { - return parameter.getName(); - } - return null; - } - - -} diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTaskImplTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTaskImplTest.java index 26a6060f..512d1eda 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTaskImplTest.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTaskImplTest.java @@ -26,8 +26,13 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.onap.dcaegen2.services.prh.integration.junit5.mockito.MockitoExtension; -import org.onap.dcaegen2.services.prh.model.*; +import org.mockito.junit.jupiter.MockitoExtension; +import org.onap.dcaegen2.services.prh.model.AaiPnfResultModel; +import org.onap.dcaegen2.services.prh.model.AaiServiceInstanceResultModel; +import org.onap.dcaegen2.services.prh.model.ImmutableRelationshipData; +import org.onap.dcaegen2.services.prh.model.Relationship; +import org.onap.dcaegen2.services.prh.model.RelationshipData; +import org.onap.dcaegen2.services.prh.model.RelationshipDict; import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AaiHttpClient; import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel; import org.onap.dcaegen2.services.sdk.rest.services.model.AaiServiceInstanceQueryModel; @@ -38,10 +43,9 @@ import java.util.List; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) -public class AaiQueryTaskImplTest { +class AaiQueryTaskImplTest { @Mock private AaiHttpClient<AaiModel, AaiPnfResultModel> getPnfModelClient; @@ -60,15 +64,6 @@ public class AaiQueryTaskImplTest { @Mock private AaiServiceInstanceResultModel serviceModel; - @Mock - private RelationshipData customer; - - @Mock - private RelationshipData serviceType; - - @Mock - private RelationshipData serviceInstanceId; - private List<RelationshipData> allRelationData; private AaiQueryTask sut; @@ -77,16 +72,14 @@ public class AaiQueryTaskImplTest { @BeforeEach void setUp() { - when(customer.getRelationshipKey()).thenReturn(AaiQueryTaskImpl.CUSTOMER); - when(customer.getRelationshipValue()).thenReturn("Foo"); - - when(serviceType.getRelationshipKey()).thenReturn(AaiQueryTaskImpl.SERVICE_TYPE); - when(serviceType.getRelationshipValue()).thenReturn("Bar"); - - when(serviceInstanceId.getRelationshipKey()).thenReturn(AaiQueryTaskImpl.SERVICE_INSTANCE_ID); - when(serviceInstanceId.getRelationshipValue()).thenReturn("Baz"); - - allRelationData = Lists.list(customer, serviceType, serviceInstanceId); + allRelationData = Lists.list( + ImmutableRelationshipData.builder() + .relationshipKey(AaiQueryTaskImpl.CUSTOMER).relationshipValue("Foo").build(), + ImmutableRelationshipData.builder() + .relationshipKey(AaiQueryTaskImpl.SERVICE_TYPE).relationshipValue("Bar").build(), + ImmutableRelationshipData.builder() + .relationshipKey(AaiQueryTaskImpl.SERVICE_INSTANCE_ID).relationshipValue("Baz").build() + ); sut = new AaiQueryTaskImpl(getPnfModelClient, getServiceClient); } diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImplTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImplTest.java index b1f97a3c..a5405069 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImplTest.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImplTest.java @@ -28,9 +28,9 @@ import org.junit.jupiter.api.function.Executable; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException; import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException; -import org.onap.dcaegen2.services.prh.integration.junit5.mockito.MockitoExtension; import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel; import org.onap.dcaegen2.services.sdk.model.streams.dmaap.ImmutableMessageRouterSink; import org.onap.dcaegen2.services.sdk.model.streams.dmaap.MessageRouterSink; diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasksTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasksTest.java index 47767bac..cefc5c76 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasksTest.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasksTest.java @@ -23,11 +23,10 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException; -import org.onap.dcaegen2.services.prh.integration.junit5.mockito.MockitoExtension; import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel; -import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishResponse; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -36,14 +35,13 @@ import java.util.Collections; import java.util.Map; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; @ExtendWith(MockitoExtension.class) -public class ScheduledTasksTest { +class ScheduledTasksTest { private final static ConsumerDmaapModel DMAAP_MODEL = ImmutableConsumerDmaapModel .builder() @@ -75,12 +73,7 @@ public class ScheduledTasksTest { private ScheduledTasks sut; @BeforeEach - void setUp() throws PrhTaskException, SSLException { - final Mono<ConsumerDmaapModel> consumerModel = Mono.just(DMAAP_MODEL); - - given(aaiProducer.execute(DMAAP_MODEL)).willReturn(consumerModel); - given(bbsActions.execute(DMAAP_MODEL)).willReturn(consumerModel); - + void setUp() { sut = new ScheduledTasks( consumer, readyPublisher, @@ -124,6 +117,12 @@ public class ScheduledTasksTest { @Test void whenPnfWithoutService_PatchToAaiAndPostToPnfReadyShouldBePerformed() throws SSLException, PrhTaskException { //given + Mono<ConsumerDmaapModel> consumerModel = Mono.just(DMAAP_MODEL); + + given(aaiProducer.execute(DMAAP_MODEL)).willReturn(consumerModel); + given(bbsActions.execute(DMAAP_MODEL)).willReturn(consumerModel); + + given(consumer.execute()).willReturn(Flux.just(DMAAP_MODEL)); given(aaiQuery.execute(any())).willReturn(Mono.just(false)); @@ -157,16 +156,16 @@ public class ScheduledTasksTest { verify(readyPublisher, never()).execute(DMAAP_MODEL); } - private Flux<MessageRouterPublishResponse> verifyThatPnfModelWasNotSentDmaapPnfUpdateTopic() throws PrhTaskException { - return verify(updatePublisher, never()).execute(DMAAP_MODEL); + private void verifyThatPnfModelWasNotSentDmaapPnfUpdateTopic() throws PrhTaskException { + verify(updatePublisher, never()).execute(DMAAP_MODEL); } private void verifyThatPnfModelWasSentDmaapPnfReadyTopic() throws PrhTaskException { verify(readyPublisher, atLeastOnce()).execute(DMAAP_MODEL); } - private Flux<MessageRouterPublishResponse> verifyThatPnfModelWasSentDmaapPnfUpdateTopic() throws PrhTaskException { - return verify(updatePublisher, atLeastOnce()).execute(DMAAP_MODEL); + private void verifyThatPnfModelWasSentDmaapPnfUpdateTopic() throws PrhTaskException { + verify(updatePublisher, atLeastOnce()).execute(DMAAP_MODEL); } private void verifyThatPnfUpdateWasNotSentToAai() throws PrhTaskException, SSLException { |