aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/a1pesimulator/service
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/onap/a1pesimulator/service')
-rw-r--r--src/test/java/org/onap/a1pesimulator/service/CellServiceTest.java79
-rw-r--r--src/test/java/org/onap/a1pesimulator/service/RanUeServiceImplTest.java52
-rw-r--r--src/test/java/org/onap/a1pesimulator/service/UeServiceTest.java106
-rw-r--r--src/test/java/org/onap/a1pesimulator/service/VesBrokerServiceImplTest.java84
4 files changed, 321 insertions, 0 deletions
diff --git a/src/test/java/org/onap/a1pesimulator/service/CellServiceTest.java b/src/test/java/org/onap/a1pesimulator/service/CellServiceTest.java
new file mode 100644
index 0000000..5e9dc05
--- /dev/null
+++ b/src/test/java/org/onap/a1pesimulator/service/CellServiceTest.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2021 Samsung Electronics
+ * 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
+ */
+
+package org.onap.a1pesimulator.service;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.onap.a1pesimulator.TestHelpers.CELL_ARRAY_SIZE;
+import static org.onap.a1pesimulator.TestHelpers.CELL_PREFIX;
+import static org.onap.a1pesimulator.TestHelpers.FIRST_CELL_ID;
+import static org.onap.a1pesimulator.TestHelpers.UE_ARRAY_SIZE;
+import static org.onap.a1pesimulator.TestHelpers.checkFirstCell;
+import static org.onap.a1pesimulator.TestHelpers.checkFirstCellWithStatus;
+import static org.onap.a1pesimulator.TestHelpers.checkFirstUserEquipment;
+
+import java.util.Collection;
+import java.util.Set;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.a1pesimulator.data.Topology;
+import org.onap.a1pesimulator.data.cell.CellDetails;
+import org.onap.a1pesimulator.data.cell.CellWithStatus;
+import org.onap.a1pesimulator.service.cell.RanCellService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@SpringBootTest
+@RunWith(SpringRunner.class)
+public class CellServiceTest {
+
+ @Autowired
+ private RanCellService cellService;
+
+ @Test
+ public void testGetTopology() {
+ Topology topology = cellService.getTopology();
+
+ assertNotNull(topology);
+
+ assertEquals(CELL_ARRAY_SIZE, topology.getCells().size());
+ assertEquals(UE_ARRAY_SIZE, topology.getUserEquipments().size());
+
+ checkFirstCell(topology.getCells().iterator().next());
+ checkFirstUserEquipment(topology.getUserEquipments().iterator().next());
+ }
+
+ @Test
+ public void testGetCellById() {
+ CellDetails cellDetails = cellService.getCellById(FIRST_CELL_ID);
+ checkFirstCell(cellDetails);
+ }
+
+ @Test
+ public void testGetCellIds() {
+ Set<String> ids = cellService.getCellIds();
+ assertEquals(CELL_ARRAY_SIZE, ids.size());
+ ids.forEach(id -> assertTrue(id.startsWith(CELL_PREFIX)));
+ }
+
+ @Test
+ public void testGetCellWithStatus() {
+ Collection<CellWithStatus> cells = cellService.getAllCellsWithStatus();
+
+ assertEquals(CELL_ARRAY_SIZE, cells.size());
+ checkFirstCellWithStatus(cells.iterator().next());
+ }
+}
diff --git a/src/test/java/org/onap/a1pesimulator/service/RanUeServiceImplTest.java b/src/test/java/org/onap/a1pesimulator/service/RanUeServiceImplTest.java
new file mode 100644
index 0000000..6409700
--- /dev/null
+++ b/src/test/java/org/onap/a1pesimulator/service/RanUeServiceImplTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2021 Samsung Electronics
+ * 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
+ */
+
+package org.onap.a1pesimulator.service;
+
+import static org.onap.a1pesimulator.TestHelpers.FIRST_CELL_CONNECTED_UE_ID;
+import static org.onap.a1pesimulator.TestHelpers.FIRST_CELL_ID;
+import static org.onap.a1pesimulator.TestHelpers.FIRST_UE_HANDOVER_CELL;
+
+import java.util.Optional;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.a1pesimulator.data.ue.UserEquipment;
+import org.onap.a1pesimulator.service.ue.RanUeServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class RanUeServiceImplTest {
+
+ @Autowired
+ private RanUeServiceImpl ranUeService;
+
+ @Test
+ public void testHandover() {
+ // when
+ ranUeService.handover(FIRST_CELL_CONNECTED_UE_ID, FIRST_UE_HANDOVER_CELL);
+
+ // then
+ Optional<UserEquipment> optUserEquipment = ranUeService.getUserEquipment(FIRST_CELL_CONNECTED_UE_ID);
+
+ Assert.assertTrue(optUserEquipment.isPresent());
+ UserEquipment userEquipment = optUserEquipment.get();
+ Assert.assertEquals(FIRST_UE_HANDOVER_CELL, userEquipment.getCellId());
+
+ // cleanup
+ userEquipment.setCellId(FIRST_CELL_ID);
+ }
+}
diff --git a/src/test/java/org/onap/a1pesimulator/service/UeServiceTest.java b/src/test/java/org/onap/a1pesimulator/service/UeServiceTest.java
new file mode 100644
index 0000000..53c63ce
--- /dev/null
+++ b/src/test/java/org/onap/a1pesimulator/service/UeServiceTest.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2021 Samsung Electronics
+ * 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
+ */
+
+package org.onap.a1pesimulator.service;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.onap.a1pesimulator.TestHelpers.FIRST_CELL_CONNECTED_UE_ID;
+import static org.onap.a1pesimulator.TestHelpers.FIRST_CELL_ID;
+import static org.onap.a1pesimulator.TestHelpers.FIRST_UE_CELL_ID;
+import static org.onap.a1pesimulator.TestHelpers.FIRST_UE_HANDOVER_CELL;
+import static org.onap.a1pesimulator.TestHelpers.FIRST_UE_ID;
+import static org.onap.a1pesimulator.TestHelpers.UE_ARRAY_SIZE;
+import static org.onap.a1pesimulator.TestHelpers.checkFirstUserEquipment;
+
+import java.util.Collection;
+import java.util.Optional;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.a1pesimulator.data.ue.UserEquipment;
+import org.onap.a1pesimulator.service.ue.RanUeService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@SpringBootTest
+@RunWith(SpringRunner.class)
+public class UeServiceTest {
+
+ @Autowired
+ private RanUeService ueService;
+
+ @Test
+ public void testGetUes() {
+ Collection<UserEquipment> userEquipments = ueService.getUserEquipments();
+
+ assertNotNull(userEquipments);
+ assertEquals(UE_ARRAY_SIZE, userEquipments.size());
+
+ UserEquipment userEquipment = userEquipments.iterator().next();
+ checkFirstUserEquipment(userEquipment);
+ }
+
+ @Test
+ public void testGetUeConnectedToCell() {
+ Collection<UserEquipment> userEquipments = ueService.getUserEquipmentsConnectedToCell(FIRST_CELL_ID);
+
+ assertNotNull(userEquipments);
+ assertEquals(1, userEquipments.size());
+
+ UserEquipment userEquipment = userEquipments.iterator().next();
+ assertEquals(FIRST_CELL_CONNECTED_UE_ID, userEquipment.getId());
+ }
+
+ @Test
+ public void testGetUeByID() {
+ Optional<UserEquipment> userEquipmentOpt = ueService.getUserEquipment(FIRST_UE_ID);
+
+ assertNotNull(userEquipmentOpt);
+ assertTrue(userEquipmentOpt.isPresent());
+
+ UserEquipment userEquipment = userEquipmentOpt.get();
+ checkFirstUserEquipment(userEquipment);
+ }
+
+ @Test
+ public void testGetUeByNotCorrectID() {
+ Optional<UserEquipment> userEquipmentOpt = ueService.getUserEquipment("BAD_ID");
+
+ assertFalse(userEquipmentOpt.isPresent());
+ assertNull(userEquipmentOpt.orElse(null));
+ }
+
+ @Test
+ public void testHandoverFlow() {
+ boolean canHandover = ueService.canHandover(FIRST_UE_ID, FIRST_UE_HANDOVER_CELL);
+ assertTrue(canHandover);
+
+ ueService.handover(FIRST_UE_ID, FIRST_UE_HANDOVER_CELL);
+
+ UserEquipment userEquipment = ueService.getUserEquipment(FIRST_UE_ID).orElse(null);
+ assertNotNull(userEquipment);
+ assertEquals(FIRST_UE_HANDOVER_CELL, userEquipment.getCellId());
+
+ ueService.handover(FIRST_UE_ID, FIRST_UE_CELL_ID);
+ }
+
+ @Test
+ public void testCantHandoverFlow() {
+ boolean canHandover = ueService.canHandover(FIRST_UE_ID, "BAD_CELL_ID");
+ assertFalse(canHandover);
+ }
+}
diff --git a/src/test/java/org/onap/a1pesimulator/service/VesBrokerServiceImplTest.java b/src/test/java/org/onap/a1pesimulator/service/VesBrokerServiceImplTest.java
new file mode 100644
index 0000000..5b27529
--- /dev/null
+++ b/src/test/java/org/onap/a1pesimulator/service/VesBrokerServiceImplTest.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2021 Samsung Electronics
+ * 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
+ */
+
+package org.onap.a1pesimulator.service;
+
+import static org.mockito.Mockito.when;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mock;
+import org.onap.a1pesimulator.data.ves.Event;
+import org.onap.a1pesimulator.service.ves.RanVesBrokerService;
+import org.onap.a1pesimulator.service.ves.RanVesSender;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.util.ReflectionTestUtils;
+import org.springframework.web.client.RestTemplate;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class VesBrokerServiceImplTest {
+
+ private static final String VES_COLLECTOR_URL = "someProtocol://someVesCollectorIP:someVesCollectorPort/somePath";
+
+ @Autowired
+ private RanVesBrokerService vesBrokerService;
+ @Autowired
+ private RanVesSender vesSender;
+ @Autowired
+ private ObjectMapper mapper;
+ @Mock
+ private RestTemplate restTemplate;
+
+ @Before
+ public void before() {
+ ReflectionTestUtils.setField(vesSender, "restTemplate", restTemplate);
+ }
+
+ @Test
+ public void testStartSendingVes() throws Exception {
+ ResponseEntity<String> responseEntity = new ResponseEntity<>(HttpStatus.OK);
+
+ when(restTemplate.exchange(ArgumentMatchers.eq(VES_COLLECTOR_URL), ArgumentMatchers.eq(HttpMethod.POST),
+ ArgumentMatchers.any(HttpEntity.class), ArgumentMatchers.eq(String.class))).thenReturn(responseEntity);
+
+ ResponseEntity<String> response = vesBrokerService.startSendingVesEvents("CustomIdentifier",
+ loadEventFromFile("VesBrokerControllerTest_pm_ves.json"), 10);
+
+ Assert.assertEquals(HttpStatus.ACCEPTED, response.getStatusCode());
+ }
+
+ private Event loadEventFromFile(String fileName) throws Exception {
+ return mapper.readValue(loadFileContent(fileName), Event.class);
+ }
+
+ private String loadFileContent(String fileName) throws IOException, URISyntaxException {
+ Path path = Paths.get(VesBrokerServiceImplTest.class.getResource(fileName).toURI());
+ return new String(Files.readAllBytes(path));
+ }
+}