From cfb63b2c5c381434a6fdea794ad0c2e89a2be328 Mon Sep 17 00:00:00 2001 From: Priyadharshini Date: Mon, 16 Mar 2020 05:55:43 +0000 Subject: Initial code check-in RANSim Controller and RANSim GUI Issue-ID: INT-1485 Signed-off-by: Priyadharshini Change-Id: I99fe693065072ff5c9b188f2177488a4cd93237d --- .../rest/api/controller/TestRansimController.java | 262 +++++++++++++++++++++ 1 file changed, 262 insertions(+) create mode 100644 ransim/ransimctrlr/RANSIM-CTRLR/src/test/java/org/onap/ransim/rest/api/controller/TestRansimController.java (limited to 'ransim/ransimctrlr/RANSIM-CTRLR/src/test/java/org/onap/ransim/rest/api/controller/TestRansimController.java') diff --git a/ransim/ransimctrlr/RANSIM-CTRLR/src/test/java/org/onap/ransim/rest/api/controller/TestRansimController.java b/ransim/ransimctrlr/RANSIM-CTRLR/src/test/java/org/onap/ransim/rest/api/controller/TestRansimController.java new file mode 100644 index 0000000..ff88afa --- /dev/null +++ b/ransim/ransimctrlr/RANSIM-CTRLR/src/test/java/org/onap/ransim/rest/api/controller/TestRansimController.java @@ -0,0 +1,262 @@ +/*- + * ============LICENSE_START======================================================= + * Ran Simulator Controller + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ================================================================================ + * 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.ransim.rest.api.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import mockit.Mock; +import mockit.MockUp; + +import org.junit.Test; +import org.junit.runner.RunWith; +//import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.ransim.rest.api.models.CellDetails; +import org.onap.ransim.rest.api.models.CellNeighbor; +import org.onap.ransim.rest.api.models.FmAlarmInfo; +import org.onap.ransim.rest.api.models.GetNeighborList; +import org.onap.ransim.rest.api.models.NeighborDetails; +import org.onap.ransim.rest.api.models.NeihborId; +import org.onap.ransim.rest.api.models.NetconfServers; +import org.onap.ransim.rest.client.RestClient; +import org.onap.ransim.websocket.model.CommonEventHeaderFm; +import org.onap.ransim.websocket.model.EventFm; +import org.onap.ransim.websocket.model.FaultFields; +import org.springframework.context.annotation.PropertySource; + +import com.google.gson.Gson; + +/** + * @author ubuntu16 + * + */ +@RunWith(MockitoJUnitRunner.class) +@PropertySource("classpath:ransim.properties") +public class TestRansimController { + @Test + public void testGetRansimController() { + + RansimController rc = RansimController.getRansimController(); + assertNotNull(rc); + } + + @Test + public void testsetNetconfServers() { + // fail("Not yet implemented"); + RansimController rscontroller = Mockito.mock(RansimController.class); + CellDetails cell1 = new CellDetails("Chn01", 1, "nc1"); + CellDetails cell2 = new CellDetails("Chn02", 2, "nc1"); + CellDetails cell3 = new CellDetails("Chn03", 3, "nc1"); + CellDetails cell4 = new CellDetails("Chn04", 4, "nc1"); + + Set cells = new HashSet(); + cells.add(cell1); + cells.add(cell2); + cells.add(cell3); + + NetconfServers server = new NetconfServers("nc1", null, null, cells); + + new MockUp() { + @Mock + NetconfServers getNetconfServer(String serverId) { + + return server; + } + }; + new MockUp() { + @Mock + CellDetails getCellDetail(String nodeId) { + + return cell4; + } + }; + new MockUp() { + @Mock + void mergeNetconfServers(NetconfServers netconfServers) { + + } + }; + + rscontroller.setNetconfServers("Chn04"); + + boolean check = server.getCells().contains(cell4); + + assertTrue(check); + + } + + @Test + public void testGenerateNeighborList() { + // fail("Not yet implemented"); + RansimController rscontroller = Mockito.mock(RansimController.class); + Set neighborList = new HashSet(); + NeighborDetails nbr1 = new NeighborDetails(new NeihborId("Chn00", "Chn01"), false); + NeighborDetails nbr2 = new NeighborDetails(new NeihborId("Chn00", "Chn02"), false); + NeighborDetails nbr3 = new NeighborDetails(new NeihborId("Chn00", "Chn03"), true); + + neighborList.add(nbr1); + neighborList.add(nbr2); + neighborList.add(nbr3); + + CellDetails cell0 = new CellDetails("Chn00", 4, "nc1"); + CellDetails cell1 = new CellDetails("Chn01", 1, "nc1"); + CellDetails cell2 = new CellDetails("Chn02", 2, "nc1"); + CellDetails cell3 = new CellDetails("Chn03", 3, "nc1"); + + CellNeighbor cellNbr = new CellNeighbor(); + cellNbr.setNodeId("Chn00"); + cellNbr.setNeighborList(neighborList); + + new MockUp() { + @Mock + CellNeighbor getCellNeighbor(String nodeId) { + if (nodeId.equals("Chn00")) { + return cellNbr; + } else { + return null; + } + + } + }; + + new MockUp() { + @Mock + CellDetails getCellDetail(String nodeId) { + if (nodeId.equals("Chn00")) { + return cell0; + } else if (nodeId.equals("Chn01")) { + return cell1; + } else if (nodeId.equals("Chn02")) { + return cell2; + } else if (nodeId.equals("Chn03")) { + return cell3; + } else { + return null; + } + + } + }; + + /* + * GetNeighborList nbrListFct = rscontroller.generateNeighborList("Chn00"); + * + * boolean result = false; + * + * if (nbrListFct.getCellsWithHo().contains(cell1)) { if + * (nbrListFct.getCellsWithHo().contains(cell2)) { if + * (nbrListFct.getCellsWithNoHo().contains(cell3)) { result = true; } } } + * + * assertTrue(result); + */ + + } + + @Test + public void testSetEventFm() { + // fail("Not yet implemented"); + RansimController rscontroller = Mockito.mock(RansimController.class); + Map alarmAdditionalInformation = new HashMap(); + alarmAdditionalInformation.put("networkId", "abc"); + alarmAdditionalInformation.put("collisions", "1"); + alarmAdditionalInformation.put("confusions", "0"); + CommonEventHeaderFm commonEventHeader = new CommonEventHeaderFm("Chn00", "", "nc1", 0, 0); + FaultFields faultFields = new FaultFields("RanPciCollisionConfusionOccurred", "other", "Collision", "CRITICAL", + alarmAdditionalInformation); + EventFm checkObj = new EventFm(commonEventHeader, faultFields); + + new MockUp() { + @Mock + String getUuid() { + return ""; + } + }; + new MockUp() { + @Mock + public long currentTimeMillis() { + return (long) 0; + } + }; + + String networkId = "abc"; + String ncServer = "nc1"; + String cellId = "Chn00"; + FmAlarmInfo issue = new FmAlarmInfo("Collision", "1", "0"); + /* + * EventFm eventObj = rscontroller.setEventFm(networkId, ncServer, cellId, + * issue); + * + * boolean result = false; + * + * Gson gson = new Gson(); String eventStr = gson.toJson(eventObj); String + * checkStr = gson.toJson(checkObj); + * + * System.out.println("eventStr: " + eventStr); System.out.println("checkStr: " + * + checkStr); + * + * if (eventStr.equals(checkStr)) { result = true; } + * + * assertTrue(result); + */ + } + + + + //@Test + public void testStopAllCells() { + RansimController rscontroller = Mockito.mock(RansimController.class); + + new MockUp() { + @Mock + List getNetconfServersList() { + System.out.println("getNetconfServersList"); + List ns = new ArrayList(); + NetconfServers n1 = new NetconfServers("nc1", null, null, null); + NetconfServers n2 = new NetconfServers("nc2", null, null, null); + ns.add(n1); + ns.add(n2); + return ns; + } + }; + + new MockUp() { + @Mock + public String sendUnmountRequestToSdnr(String serverId, String ip, int port, String sdnrUsername, + String sdnrPassword) { + System.out.println("sendUnmountRequestToSdnr"); + return ""; + } + }; + + String result = rscontroller.stopAllCells(); + System.out.println("testStopAllCells: " + result); + assertEquals("Netconf servers unmounted.", result); + } + +} \ No newline at end of file -- cgit 1.2.3-korg