aboutsummaryrefslogtreecommitdiffstats
path: root/ransim/ransimctrlr/RANSIM-CTRLR/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'ransim/ransimctrlr/RANSIM-CTRLR/src/test')
-rw-r--r--ransim/ransimctrlr/RANSIM-CTRLR/src/test/java/org/onap/ransim/rest/api/controller/TestRansimController.java262
-rw-r--r--ransim/ransimctrlr/RANSIM-CTRLR/src/test/java/org/onap/ransim/rest/api/controller/TestRansimControllerServices.java75
-rw-r--r--ransim/ransimctrlr/RANSIM-CTRLR/src/test/java/org/onap/ransim/rest/api/models/TestApiModels.java60
-rw-r--r--ransim/ransimctrlr/RANSIM-CTRLR/src/test/resources/META-INF/persistence.xml43
-rw-r--r--ransim/ransimctrlr/RANSIM-CTRLR/src/test/resources/hibernate.properties29
-rw-r--r--ransim/ransimctrlr/RANSIM-CTRLR/src/test/resources/log4j.properties8
6 files changed, 477 insertions, 0 deletions
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<CellDetails> cells = new HashSet<CellDetails>();
+ cells.add(cell1);
+ cells.add(cell2);
+ cells.add(cell3);
+
+ NetconfServers server = new NetconfServers("nc1", null, null, cells);
+
+ new MockUp<RansimControllerDatabase>() {
+ @Mock
+ NetconfServers getNetconfServer(String serverId) {
+
+ return server;
+ }
+ };
+ new MockUp<RansimControllerDatabase>() {
+ @Mock
+ CellDetails getCellDetail(String nodeId) {
+
+ return cell4;
+ }
+ };
+ new MockUp<RansimControllerDatabase>() {
+ @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<NeighborDetails> neighborList = new HashSet<NeighborDetails>();
+ 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<RansimControllerDatabase>() {
+ @Mock
+ CellNeighbor getCellNeighbor(String nodeId) {
+ if (nodeId.equals("Chn00")) {
+ return cellNbr;
+ } else {
+ return null;
+ }
+
+ }
+ };
+
+ new MockUp<RansimControllerDatabase>() {
+ @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<String, String> alarmAdditionalInformation = new HashMap<String, String>();
+ 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<RansimController>() {
+ @Mock
+ String getUuid() {
+ return "";
+ }
+ };
+ new MockUp<System>() {
+ @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<RansimControllerDatabase>() {
+ @Mock
+ List<NetconfServers> getNetconfServersList() {
+ System.out.println("getNetconfServersList");
+ List<NetconfServers> ns = new ArrayList<NetconfServers>();
+ 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<RestClient>() {
+ @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
diff --git a/ransim/ransimctrlr/RANSIM-CTRLR/src/test/java/org/onap/ransim/rest/api/controller/TestRansimControllerServices.java b/ransim/ransimctrlr/RANSIM-CTRLR/src/test/java/org/onap/ransim/rest/api/controller/TestRansimControllerServices.java
new file mode 100644
index 0000000..af3659e
--- /dev/null
+++ b/ransim/ransimctrlr/RANSIM-CTRLR/src/test/java/org/onap/ransim/rest/api/controller/TestRansimControllerServices.java
@@ -0,0 +1,75 @@
+/*-
+ * ============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.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.TypedQuery;
+
+import mockit.Mock;
+import mockit.MockUp;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.ransim.rest.api.models.CellDetails;
+import org.springframework.http.ResponseEntity;
+
+public class TestRansimControllerServices {
+
+ @Test
+ public void testGetOperationLog() {
+ ResponseEntity<String> rsEntity = Mockito.mock(ResponseEntity.class);
+
+ EntityManagerFactory emfactory = Mockito.mock(EntityManagerFactory.class);
+ EntityManager entityManager = Mockito.mock(EntityManager.class);
+ Mockito.when(emfactory.createEntityManager()).thenReturn(entityManager);
+
+ TypedQuery<CellDetails> query = Mockito.mock(TypedQuery.class);
+ Mockito.when(entityManager.createQuery("from CellDetails cd", CellDetails.class)).thenReturn(query);
+
+ List<CellDetails> cellDetailList = new ArrayList<CellDetails>();
+ Mockito.when(query.getResultList()).thenReturn(cellDetailList);
+ assertNotNull(rsEntity);
+
+ }
+
+ @Test
+ public void testModifyACell() {
+
+ ResponseEntity<String> rsEntity = Mockito.mock(ResponseEntity.class);
+
+ EntityManagerFactory emfactory = Mockito.mock(EntityManagerFactory.class);
+ EntityManager entityManager = Mockito.mock(EntityManager.class);
+ Mockito.when(emfactory.createEntityManager()).thenReturn(entityManager);
+
+ TypedQuery<CellDetails> query = Mockito.mock(TypedQuery.class);
+ Mockito.when(entityManager.createQuery("from CellDetails cd", CellDetails.class)).thenReturn(query);
+
+
+ }
+
+
+} \ No newline at end of file
diff --git a/ransim/ransimctrlr/RANSIM-CTRLR/src/test/java/org/onap/ransim/rest/api/models/TestApiModels.java b/ransim/ransimctrlr/RANSIM-CTRLR/src/test/java/org/onap/ransim/rest/api/models/TestApiModels.java
new file mode 100644
index 0000000..b9e24fd
--- /dev/null
+++ b/ransim/ransimctrlr/RANSIM-CTRLR/src/test/java/org/onap/ransim/rest/api/models/TestApiModels.java
@@ -0,0 +1,60 @@
+/*-
+ * ============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.models;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.onap.ransim.rest.api.models.CellDetails;
+import org.onap.ransim.rest.api.models.ModifyACellReq;
+import org.onap.ransim.rest.api.models.NetconfServers;
+
+public class TestApiModels {
+
+ @Test
+ public void testsetNewPhysicalCellId() {
+ ModifyACellReq mcell = new ModifyACellReq();
+ mcell.setNewPhysicalCellId(001L);
+ assertTrue(mcell.getNewPhysicalCellId() == 001);
+ }
+
+ @Test
+ public void testsetNewPhysicalCellId1() {
+ ModifyACellReq mcell = new ModifyACellReq();
+ mcell.setNewPhysicalCellId(000L);
+ assertFalse(mcell.getNewPhysicalCellId() == 001);
+ }
+
+ @Test
+ public void testsetNetworkId() {
+ CellDetails cd = new CellDetails();
+ cd.setNetworkId("Ns001");
+ assertTrue(cd.getNetworkId() == "Ns001");
+ }
+
+ @Test
+ public void testsetServerId() {
+ NetconfServers ns = new NetconfServers();
+ ns.setServerId("ns0031");
+ assertTrue(ns.getServerId() == "ns0031");
+ }
+
+}
diff --git a/ransim/ransimctrlr/RANSIM-CTRLR/src/test/resources/META-INF/persistence.xml b/ransim/ransimctrlr/RANSIM-CTRLR/src/test/resources/META-INF/persistence.xml
new file mode 100644
index 0000000..1e194c6
--- /dev/null
+++ b/ransim/ransimctrlr/RANSIM-CTRLR/src/test/resources/META-INF/persistence.xml
@@ -0,0 +1,43 @@
+<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
+ http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
+ version="2.1">
+
+ <persistence-unit name="templatePU" transaction-type="RESOURCE_LOCAL">
+
+ <description>Hibernate test case template Persistence Unit</description>
+ <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
+
+ <exclude-unlisted-classes>false</exclude-unlisted-classes>
+
+ <properties>
+ <property name="hibernate.archive.autodetection" value="class, hbm"/>
+
+ <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
+ <property name="hibernate.connection.driver_class" value="org.h2.Driver"/>
+ <property name="hibernate.connection.url" value="jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1"/>
+ <property name="hibernate.connection.username" value="sa"/>
+
+ <property name="hibernate.connection.pool_size" value="5"/>
+
+ <property name="hibernate.show_sql" value="true"/>
+ <property name="hibernate.format_sql" value="true"/>
+ <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
+
+ <property name="hibernate.max_fetch_depth" value="5"/>
+
+ <property name="hibernate.cache.region_prefix" value="hibernate.test"/>
+ <property name="hibernate.cache.region.factory_class"
+ value="org.hibernate.testing.cache.CachingRegionFactory"/>
+
+ <!--NOTE: hibernate.jdbc.batch_versioned_data should be set to false when testing with Oracle-->
+ <property name="hibernate.jdbc.batch_versioned_data" value="true"/>
+
+ <property name="javax.persistence.validation.mode" value="NONE"/>
+ <property name="hibernate.service.allow_crawling" value="false"/>
+ <property name="hibernate.session.events.log" value="true"/>
+ </properties>
+
+ </persistence-unit>
+</persistence>
diff --git a/ransim/ransimctrlr/RANSIM-CTRLR/src/test/resources/hibernate.properties b/ransim/ransimctrlr/RANSIM-CTRLR/src/test/resources/hibernate.properties
new file mode 100644
index 0000000..9b7d955
--- /dev/null
+++ b/ransim/ransimctrlr/RANSIM-CTRLR/src/test/resources/hibernate.properties
@@ -0,0 +1,29 @@
+#
+# Hibernate, Relational Persistence for Idiomatic Java
+#
+# License: GNU Lesser General Public License (LGPL), version 2.1 or later.
+# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
+#
+
+hibernate.dialect org.hibernate.dialect.H2Dialect
+hibernate.connection.driver_class org.h2.Driver
+#hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE
+hibernate.connection.url jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1
+hibernate.connection.username sa
+
+hibernate.connection.pool_size 5
+
+hibernate.show_sql false
+hibernate.format_sql true
+
+hibernate.max_fetch_depth 5
+
+hibernate.cache.region_prefix hibernate.test
+hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
+
+# NOTE: hibernate.jdbc.batch_versioned_data should be set to false when testing with Oracle
+hibernate.jdbc.batch_versioned_data true
+
+javax.persistence.validation.mode=NONE
+hibernate.service.allow_crawling=false
+hibernate.session.events.log=true \ No newline at end of file
diff --git a/ransim/ransimctrlr/RANSIM-CTRLR/src/test/resources/log4j.properties b/ransim/ransimctrlr/RANSIM-CTRLR/src/test/resources/log4j.properties
new file mode 100644
index 0000000..d42ce42
--- /dev/null
+++ b/ransim/ransimctrlr/RANSIM-CTRLR/src/test/resources/log4j.properties
@@ -0,0 +1,8 @@
+# Root logger option
+log4j.rootLogger=INFO, stdout
+
+# Direct log messages to stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n