aboutsummaryrefslogtreecommitdiffstats
path: root/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/commit
diff options
context:
space:
mode:
Diffstat (limited to 'prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/commit')
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/commit/EpochDateTimeConversionTest.java52
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/commit/KafkaConsumerTaskImplTest.java86
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/commit/ScheduledTasksRunnerWithCommitTest.java72
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/commit/ScheduledTasksWithCommitTest.java263
4 files changed, 473 insertions, 0 deletions
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/commit/EpochDateTimeConversionTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/commit/EpochDateTimeConversionTest.java
new file mode 100644
index 00000000..850587e0
--- /dev/null
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/commit/EpochDateTimeConversionTest.java
@@ -0,0 +1,52 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2023 Deutsche Telekom 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.tasks.commit;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+@ExtendWith(MockitoExtension.class)
+public class EpochDateTimeConversionTest {
+
+ private EpochDateTimeConversion epochDateTimeConversion;
+
+ @BeforeEach
+ void setUp() {
+ epochDateTimeConversion = new EpochDateTimeConversion();
+ epochDateTimeConversion.setDaysForRecords("3");
+ }
+
+ @Test
+ public void getStartDateOfTheDayTest(){
+ epochDateTimeConversion.getDaysForRecords();
+ Long day = epochDateTimeConversion.getStartDateOfTheDay();
+ Assertions.assertNotNull(day);
+ }
+
+ @Test
+ public void getEndDateOfTheDayTest(){
+ Long day = epochDateTimeConversion.getEndDateOfTheDay();
+ Assertions.assertNotNull(day);
+ }
+}
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/commit/KafkaConsumerTaskImplTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/commit/KafkaConsumerTaskImplTest.java
new file mode 100644
index 00000000..c23a1886
--- /dev/null
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/commit/KafkaConsumerTaskImplTest.java
@@ -0,0 +1,86 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2023 Deutsche Telekom 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.tasks;
+
+import org.apache.kafka.clients.consumer.ConsumerRecord;
+import org.apache.kafka.common.header.Headers;
+import org.apache.kafka.common.header.internals.RecordHeaders;
+import org.apache.kafka.common.record.TimestampType;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.onap.dcaegen2.services.prh.adapter.aai.api.ConsumerDmaapModel;
+import org.onap.dcaegen2.services.prh.adapter.aai.api.ImmutableConsumerDmaapModel;
+import org.onap.dcaegen2.services.prh.service.DmaapConsumerJsonParser;
+import org.onap.dcaegen2.services.prh.tasks.commit.EpochDateTimeConversion;
+import org.onap.dcaegen2.services.prh.tasks.commit.KafkaConsumerTaskImpl;
+import org.springframework.boot.configurationprocessor.json.JSONException;
+import org.springframework.kafka.support.Acknowledgment;
+import reactor.core.publisher.Flux;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+public class KafkaConsumerTaskImplTest {
+
+ @Mock
+ private Acknowledgment acknowledgment;
+
+ @Mock
+ private DmaapConsumerJsonParser dmaapConsumerJsonParser;
+
+ @Mock
+ private EpochDateTimeConversion epochDateTimeConversion;
+
+ @InjectMocks
+ private KafkaConsumerTaskImpl kafkaConsumerTask;
+
+ @Test
+ public void onMessageTest(){
+ List<ConsumerRecord<String, String>> list = new ArrayList<>();
+ TimestampType timestampType = null;
+ Headers headers = new RecordHeaders();
+ epochDateTimeConversion.setDaysForRecords("3");
+ ConsumerRecord<String, String> records = new ConsumerRecord<>
+ ("test-topic", 1, 1l, 0l, timestampType, 1, 1, "test-key", "test-value", headers
+ , null);
+ list.add(records);
+ kafkaConsumerTask.onMessage(list, acknowledgment);
+ }
+
+ @Test
+ public void commitOffsetTest(){
+ kafkaConsumerTask.commitOffset();
+ }
+
+ @Test
+ public void executeTest() throws JSONException {
+ List<String> jsonEvent = new ArrayList<>();
+ ConsumerDmaapModel consumerDmaapModel = ImmutableConsumerDmaapModel.builder().correlationId("123").build();
+ when(dmaapConsumerJsonParser.getConsumerDmaapModelFromKafkaConsumerRecord(jsonEvent)).thenReturn(Flux.just(consumerDmaapModel));
+ kafkaConsumerTask.execute();
+ }
+}
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/commit/ScheduledTasksRunnerWithCommitTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/commit/ScheduledTasksRunnerWithCommitTest.java
new file mode 100644
index 00000000..401e351f
--- /dev/null
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/commit/ScheduledTasksRunnerWithCommitTest.java
@@ -0,0 +1,72 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2023 Deutsche Telekom 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.tasks.commit;
+
+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.configuration.PrhProperties;
+import org.springframework.boot.context.event.ApplicationStartedEvent;
+import org.springframework.scheduling.TaskScheduler;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+@ExtendWith(MockitoExtension.class)
+public class ScheduledTasksRunnerWithCommitTest {
+
+ @Mock
+ private ScheduledTasksWithCommit scheduledTasksWithCommit;
+
+ @Mock
+ private TaskScheduler taskScheduler;
+
+ @Mock
+ private PrhProperties prhProperties;
+
+ @Mock
+ private ApplicationStartedEvent applicationStartedEvent;
+
+ private ScheduledTasksRunnerWithCommit scheduledTasksRunnerWithCommit;
+
+ @BeforeEach
+ void setUp() {
+ scheduledTasksRunnerWithCommit = new ScheduledTasksRunnerWithCommit(taskScheduler, scheduledTasksWithCommit, prhProperties);
+ }
+
+ @Test
+ void onApplicationStartedEvent() {
+ scheduledTasksRunnerWithCommit.onApplicationStartedEvent(applicationStartedEvent);
+ assertFalse(scheduledTasksRunnerWithCommit.tryToStartTaskWithCommit());
+ }
+
+ @Test
+ void cancelTasks() {
+ scheduledTasksRunnerWithCommit.cancelTasks();
+ }
+
+ @Test
+ void tryToStartTaskWithCommit() {
+ scheduledTasksRunnerWithCommit.tryToStartTaskWithCommit();
+ assertFalse(scheduledTasksRunnerWithCommit.tryToStartTaskWithCommit());
+ }
+}
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/commit/ScheduledTasksWithCommitTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/commit/ScheduledTasksWithCommitTest.java
new file mode 100644
index 00000000..64779027
--- /dev/null
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/commit/ScheduledTasksWithCommitTest.java
@@ -0,0 +1,263 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2023 Deutsche Telekom 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.tasks.commit;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import java.util.Collections;
+import java.util.Map;
+import org.jetbrains.annotations.Nullable;
+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.adapter.aai.api.ConsumerDmaapModel;
+import org.onap.dcaegen2.services.prh.adapter.aai.api.ImmutableConsumerDmaapModel;
+import org.onap.dcaegen2.services.prh.exceptions.DmaapEmptyResponseException;
+import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException;
+import org.onap.dcaegen2.services.prh.tasks.AaiProducerTask;
+import org.onap.dcaegen2.services.prh.tasks.AaiQueryTask;
+import org.onap.dcaegen2.services.prh.tasks.BbsActionsTask;
+import org.onap.dcaegen2.services.prh.tasks.DmaapPublisherTask;
+import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishResponse;
+import org.springframework.boot.configurationprocessor.json.JSONException;
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+
+@ExtendWith(MockitoExtension.class)
+class ScheduledTasksWithCommitTest {
+ private final static ConsumerDmaapModel DMAAP_MODEL =
+ ImmutableConsumerDmaapModel
+ .builder()
+ .correlationId("SomeId")
+ .ipv4("ipv4")
+ .ipv6("ipv6")
+ .build();
+
+ @Mock
+ private DmaapPublisherTask readyPublisher;
+
+ @Mock
+ private DmaapPublisherTask updatePublisher;
+
+
+ @Mock
+ private BbsActionsTask bbsActionsTask;
+
+ @Mock
+ private KafkaConsumerTask kafkaConsumerTask;
+
+ @Mock
+ private AaiQueryTask aaiQueryTask;
+
+ @Mock
+ private AaiProducerTask aaiProducerTask;
+
+ private final Map<String, String> context = Collections.emptyMap();
+
+ private ScheduledTasksWithCommit sut;
+
+ @BeforeEach
+ void setUp() {
+ sut = new ScheduledTasksWithCommit(
+ kafkaConsumerTask,
+ readyPublisher,
+ updatePublisher,
+ aaiQueryTask,
+ aaiProducerTask,
+ bbsActionsTask,
+ context);
+ }
+
+ @Test
+ void testQueryAAiForPNFOnSuccess() throws JSONException, PrhTaskException {
+ ScheduledTasksWithCommit.State state = new ScheduledTasksWithCommit.State(DMAAP_MODEL, false );
+ MessageRouterPublishResponse messageRouterPublishResponse = new MessageRouterPublishResponse() {
+ @Override
+ public @Nullable String failReason() {
+ return null;
+ }
+ };
+ when(kafkaConsumerTask.execute()).thenReturn(Flux.just(DMAAP_MODEL));
+ when(aaiQueryTask.findPnfinAAI(DMAAP_MODEL)).thenReturn(Mono.just(DMAAP_MODEL));
+ when(aaiQueryTask.execute(DMAAP_MODEL)).thenReturn(Mono.just(true));
+ when(aaiProducerTask.execute(state.dmaapModel)).thenReturn(Mono.just(DMAAP_MODEL));
+ when(updatePublisher.execute(state.dmaapModel)).thenReturn(Flux.just(messageRouterPublishResponse));
+
+ sut.scheduleKafkaPrhEventTask();
+
+ verifyIfLogicalLinkWasNotCreated();
+ verifyThatPnfModelWasNotSentDmaapPnfReadyTopic();
+ }
+
+ @Test
+ void testQueryAAiForPNF() throws JSONException, PrhTaskException {
+ ScheduledTasksWithCommit.State state = new ScheduledTasksWithCommit.State(DMAAP_MODEL, true);
+ MessageRouterPublishResponse messageRouterPublishResponse = new MessageRouterPublishResponse() {
+ @Override
+ public @Nullable String failReason() {
+ return null;
+ }
+ };
+ when(kafkaConsumerTask.execute()).thenReturn(Flux.just(DMAAP_MODEL));
+ when(aaiQueryTask.findPnfinAAI(DMAAP_MODEL)).thenReturn(Mono.just(DMAAP_MODEL));
+ when(aaiQueryTask.execute(DMAAP_MODEL)).thenReturn(Mono.just(true));
+ when(aaiProducerTask.execute(state.dmaapModel)).thenReturn(Mono.just(DMAAP_MODEL));
+ when(updatePublisher.execute(state.dmaapModel)).thenReturn(Flux.just(messageRouterPublishResponse));
+
+ sut.scheduleKafkaPrhEventTask();
+
+ verifyIfLogicalLinkWasNotCreated();
+ verifyThatPnfModelWasNotSentDmaapPnfReadyTopic();
+ }
+
+ @Test
+ void testQueryAAiForPNFOnError() throws JSONException, PrhTaskException {
+ when(kafkaConsumerTask.execute()).thenReturn(Flux.just(DMAAP_MODEL));
+
+ sut.scheduleKafkaPrhEventTask();
+
+ verifyThatPnfUpdateWasNotSentToAai();
+
+ verifyIfLogicalLinkWasNotCreated();
+ verifyThatPnfModelWasNotSentDmaapPnfReadyTopic();
+ verifyThatPnfModelWasNotSentDmaapPnfUpdateTopic();
+ }
+
+ @Test
+ void testQueryAAiForPNFOnPRHException() throws JSONException, PrhTaskException {
+ ScheduledTasksWithCommit.State state = new ScheduledTasksWithCommit.State(DMAAP_MODEL, false );
+ MessageRouterPublishResponse messageRouterPublishResponse = new MessageRouterPublishResponse() {
+ @Override
+ public @Nullable String failReason() {
+ return null;
+ }
+ };
+ when(kafkaConsumerTask.execute()).thenReturn(Flux.just(DMAAP_MODEL));
+ when(aaiQueryTask.findPnfinAAI(DMAAP_MODEL)).thenReturn(Mono.just(DMAAP_MODEL));
+ when(aaiQueryTask.execute(DMAAP_MODEL)).thenReturn(Mono.just(true));
+ when(aaiProducerTask.execute(state.dmaapModel)).thenThrow(new PrhTaskException());
+
+ sut.scheduleKafkaPrhEventTask();
+
+ verifyIfLogicalLinkWasNotCreated();
+ verifyThatPnfModelWasNotSentDmaapPnfReadyTopic();
+ }
+
+ @Test
+ void queryAAiForPNFOnPRHExceptionTest() throws JSONException, PrhTaskException {
+ ScheduledTasksWithCommit.State state = new ScheduledTasksWithCommit.State(DMAAP_MODEL, true);
+ MessageRouterPublishResponse messageRouterPublishResponse = new MessageRouterPublishResponse() {
+ @Override
+ public @Nullable String failReason() {
+ return null;
+ }
+ };
+ when(kafkaConsumerTask.execute()).thenReturn(Flux.just(DMAAP_MODEL));
+ when(aaiQueryTask.findPnfinAAI(DMAAP_MODEL)).thenReturn(Mono.just(DMAAP_MODEL));
+ when(aaiQueryTask.execute(DMAAP_MODEL)).thenReturn(Mono.just(true));
+ when(aaiProducerTask.execute(state.dmaapModel)).thenReturn(Mono.just(DMAAP_MODEL));
+ when(updatePublisher.execute(state.dmaapModel)).thenThrow(new PrhTaskException());
+
+ sut.scheduleKafkaPrhEventTask();
+
+ verifyIfLogicalLinkWasNotCreated();
+ verifyThatPnfModelWasNotSentDmaapPnfReadyTopic();
+ }
+
+ @Test
+ void queryAAiForPNFOnPRHExceptionOnDmaapEmptyResponseExceptionTest() throws JSONException, PrhTaskException {
+ ScheduledTasksWithCommit.State state = new ScheduledTasksWithCommit.State(DMAAP_MODEL, true);
+ MessageRouterPublishResponse messageRouterPublishResponse = new MessageRouterPublishResponse() {
+ @Override
+ public @Nullable String failReason() {
+ return null;
+ }
+ };
+ when(kafkaConsumerTask.execute()).thenReturn(Flux.just(DMAAP_MODEL));
+ when(aaiQueryTask.findPnfinAAI(DMAAP_MODEL)).thenReturn(Mono.just(DMAAP_MODEL));
+ when(aaiQueryTask.execute(DMAAP_MODEL)).thenReturn(Mono.just(true));
+ when(aaiProducerTask.execute(state.dmaapModel)).thenReturn(Mono.just(DMAAP_MODEL));
+ when(updatePublisher.execute(state.dmaapModel)).thenThrow(new DmaapEmptyResponseException());
+
+ sut.scheduleKafkaPrhEventTask();
+
+ verifyIfLogicalLinkWasNotCreated();
+ verifyThatPnfModelWasNotSentDmaapPnfReadyTopic();
+ }
+
+ @Test
+ void queryAAiForPNFOnPRHExceptionOnFalseTest() throws JSONException, PrhTaskException {
+ ScheduledTasksWithCommit.State state = new ScheduledTasksWithCommit.State(DMAAP_MODEL, false);
+ MessageRouterPublishResponse messageRouterPublishResponse = new MessageRouterPublishResponse() {
+ @Override
+ public @Nullable String failReason() {
+ return null;
+ }
+ };
+ when(kafkaConsumerTask.execute()).thenReturn(Flux.just(DMAAP_MODEL));
+ when(aaiQueryTask.findPnfinAAI(DMAAP_MODEL)).thenReturn(Mono.just(DMAAP_MODEL));
+ when(aaiQueryTask.execute(DMAAP_MODEL)).thenReturn(Mono.just(false));
+ when(aaiProducerTask.execute(state.dmaapModel)).thenReturn(Mono.just(DMAAP_MODEL));
+
+ sut.scheduleKafkaPrhEventTask();
+ verifyThatPnfModelWasNotSentDmaapPnfReadyTopic();
+ }
+
+ @Test
+ void queryAAiForPNFOnPRHExceptionOnJSONExceptionTest() throws PrhTaskException, JSONException {
+ ScheduledTasksWithCommit.State state = new ScheduledTasksWithCommit.State(DMAAP_MODEL, true);
+ MessageRouterPublishResponse messageRouterPublishResponse = new MessageRouterPublishResponse() {
+ @Override
+ public @Nullable String failReason() {
+ return null;
+ }
+ };
+ when(kafkaConsumerTask.execute()).thenThrow(new JSONException("json format exception"));
+
+ sut.scheduleKafkaPrhEventTask();
+
+ verifyIfLogicalLinkWasNotCreated();
+ verifyThatPnfModelWasNotSentDmaapPnfReadyTopic();
+ }
+
+ private void verifyThatPnfModelWasNotSentDmaapPnfReadyTopic() throws PrhTaskException {
+ verify(readyPublisher, never()).execute(DMAAP_MODEL);
+ }
+
+ private void verifyThatPnfModelWasNotSentDmaapPnfUpdateTopic() throws PrhTaskException {
+ verify(updatePublisher, never()).execute(DMAAP_MODEL);
+ }
+
+ private void verifyThatPnfUpdateWasNotSentToAai() throws PrhTaskException {
+ verify(aaiProducerTask, never()).execute(DMAAP_MODEL);
+ }
+
+ private void verifyIfLogicalLinkWasNotCreated(){
+ verify(bbsActionsTask, never()).execute(DMAAP_MODEL);
+ }
+}
+