aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStanislav Marszalek <s.marszalek2@partner.samsung.com>2021-08-02 13:07:23 +0200
committerStanislav Marszalek <s.marszalek2@partner.samsung.com>2021-08-10 08:59:11 +0000
commit6bbd0749c646e79c7e686e7cd4be06667ab65736 (patch)
treea0ecb0f76e792543fd9a002357281b459804cbb6
parent2d8d909f4c3ef935583f551e556e67064112016e (diff)
O1 PM Bulk support - PM Bulk File Unit tests 3
Issue-ID: INT-1945 Signed-off-by: Stanislav Marszalek <s.marszalek2@partner.samsung.com> Change-Id: I02d3684c98d563d7f386de2fdf032e930ac48b3f
-rw-r--r--src/test/java/org/onap/a1pesimulator/TestHelpers.java4
-rw-r--r--src/test/java/org/onap/a1pesimulator/service/cell/RanCellStateServiceTest.java87
-rw-r--r--src/test/java/org/onap/a1pesimulator/service/ves/RanVesHolderTest.java128
3 files changed, 218 insertions, 1 deletions
diff --git a/src/test/java/org/onap/a1pesimulator/TestHelpers.java b/src/test/java/org/onap/a1pesimulator/TestHelpers.java
index f336340..d029bc9 100644
--- a/src/test/java/org/onap/a1pesimulator/TestHelpers.java
+++ b/src/test/java/org/onap/a1pesimulator/TestHelpers.java
@@ -20,7 +20,9 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
+import java.util.Collections;
import java.util.List;
+import java.util.Optional;
import org.onap.a1pesimulator.data.cell.CellDetails;
import org.onap.a1pesimulator.data.cell.CellWithStatus;
@@ -74,7 +76,7 @@ public class TestHelpers {
}
public static void deleteTempFiles(List<File> files) {
- files.forEach(file -> {
+ Optional.ofNullable(files).orElse(Collections.emptyList()).forEach(file -> {
try {
if (Files.exists(file.toPath())) {
Files.delete(file.toPath());
diff --git a/src/test/java/org/onap/a1pesimulator/service/cell/RanCellStateServiceTest.java b/src/test/java/org/onap/a1pesimulator/service/cell/RanCellStateServiceTest.java
new file mode 100644
index 0000000..120e041
--- /dev/null
+++ b/src/test/java/org/onap/a1pesimulator/service/cell/RanCellStateServiceTest.java
@@ -0,0 +1,87 @@
+package org.onap.a1pesimulator.service.cell;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.onap.a1pesimulator.service.fileready.CommonFileReady.TEST_CELL_ID;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.a1pesimulator.data.cell.CellDetails;
+import org.onap.a1pesimulator.data.cell.state.machine.ActiveState;
+import org.springframework.messaging.simp.SimpMessagingTemplate;
+
+class RanCellStateServiceTest {
+
+ private RanCellStateService ranCellStateService;
+
+ @Mock
+ RanCellsHolder ranCellsHolder;
+
+ @Mock
+ SimpMessagingTemplate messagingTemplate;
+
+ @BeforeEach
+ void setUp() {
+ MockitoAnnotations.initMocks(this);
+ ranCellStateService = spy(new RanCellStateService(ranCellsHolder, messagingTemplate));
+
+ }
+
+ @Test
+ void activateState() {
+ doReturn(getTestCellDetails()).when(ranCellsHolder).getCellById(TEST_CELL_ID);
+ ranCellStateService.activateState(TEST_CELL_ID);
+ verify(messagingTemplate, times(1)).convertAndSend(anyString(), (Object) any());
+ }
+
+ @Test
+ void failingState() {
+
+ CellDetails cell = getTestCellDetails();
+ doReturn(cell).when(ranCellsHolder).getCellById(TEST_CELL_ID);
+
+ // Not allow changing state, cell is in INACTIVE state
+ ranCellStateService.failingState(TEST_CELL_ID);
+ verify(messagingTemplate, times(0)).convertAndSend(anyString(), (Object) any());
+
+ // Allow changing state, cell is in ACTIVE state
+ cell.setCellStateMachine(new ActiveState());
+ doReturn(cell).when(ranCellsHolder).getCellById(TEST_CELL_ID);
+ ranCellStateService.failingState(TEST_CELL_ID);
+ verify(messagingTemplate, times(1)).convertAndSend(anyString(), (Object) any());
+ }
+
+ @Test
+ void stopState() {
+ CellDetails cell = getTestCellDetails();
+ doReturn(cell).when(ranCellsHolder).getCellById(TEST_CELL_ID);
+
+ // Not allow changing state, cell is in INACTIVE state
+ ranCellStateService.stopState(TEST_CELL_ID);
+ verify(messagingTemplate, times(0)).convertAndSend(anyString(), (Object) any());
+
+ // Allow changing state, cell is in ACTIVE state
+ cell.setCellStateMachine(new ActiveState());
+ doReturn(cell).when(ranCellsHolder).getCellById(TEST_CELL_ID);
+ ranCellStateService.stopState(TEST_CELL_ID);
+ verify(messagingTemplate, times(1)).convertAndSend(anyString(), (Object) any());
+ }
+
+ @Test
+ void cellDoesNotExist() {
+ doReturn(null).when(ranCellsHolder).getCellById(TEST_CELL_ID);
+ ranCellStateService.activateState(TEST_CELL_ID);
+ verify(messagingTemplate, times(0)).convertAndSend(anyString(), (Object) any());
+
+ }
+
+ private CellDetails getTestCellDetails() {
+ return CellDetails.builder().id(TEST_CELL_ID).latitude(23.5).longitude(45.8).build();
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/a1pesimulator/service/ves/RanVesHolderTest.java b/src/test/java/org/onap/a1pesimulator/service/ves/RanVesHolderTest.java
new file mode 100644
index 0000000..890c689
--- /dev/null
+++ b/src/test/java/org/onap/a1pesimulator/service/ves/RanVesHolderTest.java
@@ -0,0 +1,128 @@
+package org.onap.a1pesimulator.service.ves;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Optional;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.a1pesimulator.data.ReportingMethodEnum;
+import org.onap.a1pesimulator.data.fileready.RanPeriodicEvent;
+import org.onap.a1pesimulator.data.ves.VesEvent;
+import org.onap.a1pesimulator.service.common.EventCustomizer;
+import org.onap.a1pesimulator.service.fileready.CommonFileReady;
+import org.onap.a1pesimulator.service.fileready.RanFileReadyHolder;
+import org.onap.a1pesimulator.service.ue.RanUeHolder;
+import org.onap.a1pesimulator.util.VnfConfigReader;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
+import org.springframework.test.util.ReflectionTestUtils;
+
+class RanVesHolderTest extends CommonFileReady {
+
+ private RanVesHolder ranCellsHolder;
+
+ @Mock
+ RanVesDataProvider vesDataProvider;
+
+ @Mock
+ Collection<OnEventAction> onEventActions;
+
+ @Mock
+ RanFileReadyHolder ranFileReadyHolder;
+
+ @Mock
+ RanVesSender vesSender;
+
+ @Mock
+ EventCustomizer regularEventCustomizer;
+
+ @Mock
+ RanUeHolder ranUeHolder;
+
+ @InjectMocks
+ VnfConfigReader vnfConfigReader;
+
+ @BeforeEach
+ void setUp() {
+ MockitoAnnotations.initMocks(this);
+ ReflectionTestUtils.setField(vnfConfigReader, "vnfConfigFile", "src/test/resources/vnf.config");
+ ThreadPoolTaskScheduler vesPmThreadPoolTaskScheduler = spy(new ThreadPoolTaskScheduler());
+ vesPmThreadPoolTaskScheduler.initialize();
+ RanEventCustomizerFactory eventCustomizerFactory = spy(new RanEventCustomizerFactory(regularEventCustomizer, ranUeHolder));
+ ranCellsHolder = spy(new RanVesHolder(vesPmThreadPoolTaskScheduler, ranFileReadyHolder, vesSender,
+ vnfConfigReader, eventCustomizerFactory, vesDataProvider, onEventActions));
+ }
+
+ @Test
+ void getPeriodicEventsCache() {
+ ranCellsHolder.startSendingVesEvents(TEST_CELL_ID, loadEventFromFile(), 10, ReportingMethodEnum.FILE_READY);
+ Map<String, RanPeriodicEvent> periodicEventsCache = ranCellsHolder.getPeriodicEventsCache();
+ assertThat(periodicEventsCache).containsKey(TEST_CELL_ID);
+ }
+
+ @Test
+ void startSendingVesEvents() {
+ ResponseEntity<String> response = ranCellsHolder.startSendingVesEvents(TEST_CELL_ID, loadEventFromFile(), 10, ReportingMethodEnum.FILE_READY);
+ assertThat(response.getStatusCode()).isEqualByComparingTo(HttpStatus.ACCEPTED);
+ assertThat(response.getBody()).contains("VES Event sending started");
+ }
+
+ @Test
+ void startSendingFailureVesEvents() {
+ doReturn(10).when(vesDataProvider).getFailureVesInterval();
+ ResponseEntity<String> response = ranCellsHolder.startSendingFailureVesEvents(TEST_CELL_ID, loadEventFromFile(), ReportingMethodEnum.FILE_READY);
+ assertThat(response.getStatusCode()).isEqualByComparingTo(HttpStatus.ACCEPTED);
+ assertThat(response.getBody()).contains("Failure VES Event sending started");
+ }
+
+ @Test
+ void stopSendingVesEvents() {
+ ranCellsHolder.startSendingVesEvents(TEST_CELL_ID, loadEventFromFile(), 10, ReportingMethodEnum.FILE_READY);
+ Optional<RanPeriodicEvent> response = ranCellsHolder.stopSendingVesEvents(TEST_CELL_ID);
+ assertThat(response).isPresent();
+ }
+
+ @Test
+ void getEnabledEventElementIdentifiers() {
+ ranCellsHolder.startSendingVesEvents(TEST_CELL_ID, loadEventFromFile(), 10, ReportingMethodEnum.VES);
+ Collection<String> elements = ranCellsHolder.getEnabledEventElementIdentifiers();
+ assertThat(elements).isNotEmpty();
+ }
+
+ @Test
+ void isEventEnabled() {
+ ranCellsHolder.startSendingVesEvents(TEST_CELL_ID, loadEventFromFile(), 10, ReportingMethodEnum.FILE_READY);
+ boolean enabled = ranCellsHolder.isEventEnabled(TEST_CELL_ID);
+ assertThat(enabled).isTrue();
+ }
+
+ @Test
+ void isAnyEventRunning() {
+ ranCellsHolder.startSendingVesEvents(TEST_CELL_ID, loadEventFromFile(), 10, ReportingMethodEnum.FILE_READY);
+ boolean isRunning = ranCellsHolder.isAnyEventRunning();
+ assertThat(isRunning).isTrue();
+ }
+
+ @Test
+ void getEventStructure() {
+ VesEvent testedEvent = loadEventFromFile();
+ ranCellsHolder.startSendingVesEvents(TEST_CELL_ID, testedEvent, 10, ReportingMethodEnum.FILE_READY);
+ VesEvent event = ranCellsHolder.getEventStructure(TEST_CELL_ID);
+ assertThat(event).isEqualTo(testedEvent);
+ }
+
+ @Test
+ void getEventStructureError() {
+ assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> ranCellsHolder.getEventStructure(TEST_CELL_ID));
+ }
+} \ No newline at end of file