diff options
Diffstat (limited to 'sdnr/wt/data-provider/provider/src/test/java')
9 files changed, 183 insertions, 47 deletions
diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java index b7a4db51b..5a8c549d8 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestCRUDforDatabase.java @@ -40,9 +40,11 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo; import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders; import org.onap.ccsdk.features.sdnr.wt.common.database.requests.BaseRequest; import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.ElasticSearchDataProvider; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.HtUserdataManagerImpl; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.UserdataHttpServlet; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.YangHelper2; import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.DataProviderYangToolsMapper; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMaintenanceInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMaintenanceInputBuilder; @@ -227,7 +229,8 @@ public class TestCRUDforDatabase { // ==READ=========================== System.out.println("try to read entry"); ReadMediatorServerListInput readinput = new ReadMediatorServerListInputBuilder() - .setFilter(YangHelper2.getListOrMap(FilterKey.class,new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) + .setFilter(YangHelper2.getListOrMap(FilterKey.class, + new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) .setPagination(getPagination(20, 1)).build(); ReadMediatorServerListOutputBuilder readoutput = dbProvider.readMediatorServerList(readinput); List<Data> data = readoutput.getData(); @@ -254,7 +257,8 @@ public class TestCRUDforDatabase { // ==READ============================ System.out.println("try to read entry"); readinput = new ReadMediatorServerListInputBuilder() - .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("name").setFiltervalue(NAME2).build())) + .setFilter(YangHelper2.getListOrMap(FilterKey.class, + new FilterBuilder().setProperty("name").setFiltervalue(NAME2).build())) .setPagination(getPagination(20, 1)).build(); readoutput = dbProvider.readMediatorServerList(readinput); data = readoutput.getData(); @@ -277,7 +281,8 @@ public class TestCRUDforDatabase { // ==READ/VERIFY DELETE============================ System.out.println("try to read entry"); readinput = new ReadMediatorServerListInputBuilder() - .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("name").setFiltervalue(NAME2).build())) + .setFilter(YangHelper2.getListOrMap(FilterKey.class, + new FilterBuilder().setProperty("name").setFiltervalue(NAME2).build())) .setPagination(getPagination(20, 1)).build(); readoutput = dbProvider.readMediatorServerList(readinput); data = readoutput.getData(); @@ -322,7 +327,8 @@ public class TestCRUDforDatabase { // ==READ=========================== ReadNetworkElementConnectionListInput readInput = new ReadNetworkElementConnectionListInputBuilder() - .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) + .setFilter(YangHelper2.getListOrMap(FilterKey.class, + new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) .setPagination(getPagination(20, 1)).build(); ReadNetworkElementConnectionListOutputBuilder readOperation = @@ -393,7 +399,8 @@ public class TestCRUDforDatabase { } readInput = new ReadNetworkElementConnectionListInputBuilder() - .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) + .setFilter(YangHelper2.getListOrMap(FilterKey.class, + new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) .setPagination(getPagination(20, 1)).build(); readOperation = dbProvider.readNetworkElementConnectionList(readInput); data = readOperation.getData(); @@ -437,7 +444,8 @@ public class TestCRUDforDatabase { System.out.println("Try read..."); ReadMaintenanceListInput readinput = new ReadMaintenanceListInputBuilder() - .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) + .setFilter(YangHelper2.getListOrMap(FilterKey.class, + new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) .setPagination(getPagination(20, 1)).build(); ReadMaintenanceListOutputBuilder readResult = dbProvider.readMaintenanceList(readinput); List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.maintenance.list.output.Data> data = @@ -502,7 +510,8 @@ public class TestCRUDforDatabase { System.out.println("try to read entry"); ReadFaultlogListInput readinput = new ReadFaultlogListInputBuilder() - .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) + .setFilter(YangHelper2.getListOrMap(FilterKey.class, + new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) .setPagination(getPagination(20, 1)).build(); ReadFaultlogListOutputBuilder readResult = null; @@ -530,7 +539,8 @@ public class TestCRUDforDatabase { System.out.println("try to search entry 1"); readinput = new ReadFaultlogListInputBuilder() - .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("node-id").setFiltervalue("test").build())) + .setFilter(YangHelper2.getListOrMap(FilterKey.class, + new FilterBuilder().setProperty("node-id").setFiltervalue("test").build())) .setPagination(getPagination(20, 1)).build(); //== VERIFY UPDATE ================================ @@ -545,7 +555,8 @@ public class TestCRUDforDatabase { System.out.println("try to search entry 2"); readinput = new ReadFaultlogListInputBuilder() - .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("node-id").setFiltervalue("test*").build())) + .setFilter(YangHelper2.getListOrMap(FilterKey.class, + new FilterBuilder().setProperty("node-id").setFiltervalue("test*").build())) .setPagination(getPagination(20, 1)).build(); readResult = dbProvider.readFaultLogList(readinput); @@ -589,7 +600,8 @@ public class TestCRUDforDatabase { ReadFaultcurrentListInput readinput = new ReadFaultcurrentListInputBuilder() - .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) + .setFilter(YangHelper2.getListOrMap(FilterKey.class, + new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) .setPagination(getPagination(20, 1)).build(); ReadFaultcurrentListOutputBuilder readResult = null; @@ -693,7 +705,8 @@ public class TestCRUDforDatabase { System.out.println("Try read entry"); ReadConnectionlogListInput readinput = new ReadConnectionlogListInputBuilder() - .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) + .setFilter(YangHelper2.getListOrMap(FilterKey.class, + new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) .setPagination(getPagination(20, 1)).build(); ReadConnectionlogListOutputBuilder readResult = null; @@ -722,7 +735,8 @@ public class TestCRUDforDatabase { System.out.println("Try read updated entry"); readinput = new ReadConnectionlogListInputBuilder() - .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("status").setFiltervalue("Connected").build())) + .setFilter(YangHelper2.getListOrMap(FilterKey.class, + new FilterBuilder().setProperty("status").setFiltervalue("Connected").build())) .setPagination(getPagination(20, 1)).build(); try { @@ -782,7 +796,8 @@ public class TestCRUDforDatabase { // ==READ=========================== ReadEventlogListInput readinput = new ReadEventlogListInputBuilder() - .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) + .setFilter(YangHelper2.getListOrMap(FilterKey.class, + new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) .setPagination(getPagination(20, 1)).build(); ReadEventlogListOutputBuilder readResult = null; try { @@ -850,7 +865,8 @@ public class TestCRUDforDatabase { // ==READ=========================== ReadInventoryListInput readinput = new ReadInventoryListInputBuilder() - .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) + .setFilter(YangHelper2.getListOrMap(FilterKey.class, + new FilterBuilder().setProperty("id").setFiltervalue(dbId).build())) .setPagination(getPagination(20, 1)).build(); ReadInventoryListOutputBuilder readResult = null; try { @@ -1015,7 +1031,8 @@ public class TestCRUDforDatabase { System.out.println("read list entries..."); ReadPmdata15mListInput read = new ReadPmdata15mListInputBuilder() - .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("node-name").setFiltervalue("a2").build())) + .setFilter(YangHelper2.getListOrMap(FilterKey.class, + new FilterBuilder().setProperty("node-name").setFiltervalue("a2").build())) .setPagination(getPagination(20, 1)).build(); ReadPmdata15mListOutputBuilder readResult = null; @@ -1035,7 +1052,8 @@ public class TestCRUDforDatabase { System.out.println("read ltp entries with node name set..."); ReadPmdata15mLtpListInput readLtp = new ReadPmdata15mLtpListInputBuilder() - .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("node-name").setFiltervalue("a2").build())) + .setFilter(YangHelper2.getListOrMap(FilterKey.class, + new FilterBuilder().setProperty("node-name").setFiltervalue("a2").build())) .setPagination(getPagination(20, 1)).build(); ReadPmdata15mLtpListOutputBuilder readltpResult = null; @@ -1133,7 +1151,8 @@ public class TestCRUDforDatabase { System.out.println("filter list entries..."); read = new ReadPmdata24hListInputBuilder() - .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("node-name").setFiltervalue("a2").build())) + .setFilter(YangHelper2.getListOrMap(FilterKey.class, + new FilterBuilder().setProperty("node-name").setFiltervalue("a2").build())) .setPagination(getPagination(20, 1)).build(); readResult = null; @@ -1152,7 +1171,8 @@ public class TestCRUDforDatabase { System.out.println("read ltp entries with node name set..."); ReadPmdata24hLtpListInput readLtp = new ReadPmdata24hLtpListInputBuilder() - .setFilter(YangHelper2.getListOrMap(FilterKey.class, new FilterBuilder().setProperty("node-name").setFiltervalue("a2").build())) + .setFilter(YangHelper2.getListOrMap(FilterKey.class, + new FilterBuilder().setProperty("node-name").setFiltervalue("a2").build())) .setPagination(getPagination(20, 1)).build(); ReadPmdata24hLtpListOutputBuilder readltpResult = null; @@ -1363,7 +1383,7 @@ public class TestCRUDforDatabase { + "\"implemented-interface\": \"org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Faultlog\",\n" + "\"source-type\": \"Netconf\",\n" + "\"node-id\": \"sim4\",\n" + "\"problem\": \"signalIsLost\"\n" + "}"; - YangToolsMapper yangtoolsMapper = new YangToolsMapper(); + DataProviderYangToolsMapper yangtoolsMapper = new DataProviderYangToolsMapper(); Faultlog log = yangtoolsMapper.readValue(jsonString, Faultlog.class); System.out.println(yangtoolsMapper.writeValueAsString((new FaultlogBuilder(log).build()))); System.out.println("Check3"); @@ -1374,6 +1394,27 @@ public class TestCRUDforDatabase { } + @Test + public void testUserdata() { + final String USERNAME = "admin"; + final String DATA1 = "{\n" + " \"networkMap\":{\n" + + " \"startupPosition\": {\"lat\": 52.5095, \"lon\":13.329, \"zoom\": 10},\n" + + " \"tileOpacity\": 90,\n" + " \"styling\":{\n" + " \"theme\": \"light\"\n" + + " }\n" + " },\n" + " \"dashboard\":{\n" + " \"color\":\"#F00\"\n" + " }\n" + + "}"; + HtUserdataManagerImpl client = new HtUserdataManagerImpl(dbRawProvider); + boolean success = client.setUserdata(USERNAME, DATA1); + assertTrue(success); + String data = client.getUserdata(USERNAME); + //JSONAssert.assertEquals(DATA1,data,false); + + assertEquals("admin", UserdataHttpServlet.decodeJWTPayloadUsername(String.format("Bearer %s", + "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbkBzZG4iLCJyb2xlcyI6WyJ1c2VyIiwiYWRtaW4iXSwiaXN" + + "zIjoiT3BlbmRheWxpZ2h0IiwibmFtZSI6ImFkbWluQHNkbiIsImV4cCI6MTYxNTc5NTg1NywiZmFtaWx5X25hbWUiOiIifQ.wB" + + "PdB45_bryU6_kSCu3be3dq3yth24niSXi6b2_1ufc"), + "sub")); + } + private Pagination getPagination(long pageSize, int page) { return new PaginationBuilder().setPage(YangHelper2.getBigIntegerOrUint64(BigInteger.valueOf(page))) .setSize(YangHelper2.getLongOrUint32(pageSize)).build(); diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataMappings.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataMappings.java index eaaa31107..56bc32ce3 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataMappings.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestDataMappings.java @@ -24,7 +24,7 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.test; import static org.junit.Assert.fail; import java.io.IOException; import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper2; +import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapper2; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.read.pmdata._15m.list.output.Data; public class TestDataMappings { diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java index 7e63c183c..56138b0b1 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestEventService.java @@ -63,6 +63,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.PmdataEntityBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SourceType; +import org.opendaylight.yangtools.yang.common.Uint32; /** * @author Michael Dürre @@ -205,6 +206,7 @@ public class TestEventService { List<NetworkElementConnectionEntity> nes = service.getNetworkElementConnections(); assertEquals(0, nes.size()); service.updateNetworkConnection22(createNeConnection(NODEID, NetworkElementDeviceType.Unknown), NODEID); + service.updateNetworkConnection22(createNeConnection(NODEID, NetworkElementDeviceType.Unknown), NODEID); service.updateNetworkConnection22(createNeConnection(NODEID2, NetworkElementDeviceType.ORAN), NODEID2); nes = service.getNetworkElementConnections(); assertEquals(2, nes.size()); @@ -243,11 +245,9 @@ public class TestEventService { @Test public void testInventory() { clearDbEntity(Entity.Inventoryequipment); - service.writeInventory(createEquipment(NODEID, "uuid1")); - service.writeInventory(createEquipment(NODEID, "uuid2")); - service.writeInventory(createEquipment(NODEID2, "uuid3")); - service.writeInventory(createEquipment(NODEID2, "uuid4")); - service.writeInventory(createEquipment(NODEID2, "uuid5")); + service.writeInventory(NODEID,Arrays.asList(createEquipment(NODEID, "uuid1"), createEquipment(NODEID, "uuid2"), + createEquipment(NODEID, "uuid3"), createEquipment(NODEID, "uuid4"), + createEquipment(NODEID, "uuid5"))); assertEquals(5, getDbEntityEntries(Entity.Inventoryequipment).getTotal()); } @@ -272,19 +272,21 @@ public class TestEventService { * @return */ private Inventory createEquipment(String nodeId, String uuid) { - return new InventoryBuilder().setNodeId(nodeId).setParentUuid("").setDescription("desc") - .setManufacturerName("manu").setDate(NetconfTimeStampImpl.getConverter().getTimeStampAsNetconfString()).setUuid(uuid).build(); + return new InventoryBuilder().setNodeId(nodeId).setParentUuid(null).setDescription("desc") + .setTreeLevel(Uint32.valueOf(0)).setManufacturerName("manu") + .setDate(NetconfTimeStampImpl.getConverter().getTimeStampAsNetconfString()).setUuid(uuid).build(); } /** * @param devType + * @param mountMethod * @param nodename3 * @return */ private static NetworkElementConnectionEntity createNeConnection(String nodeId, NetworkElementDeviceType devType) { - return new NetworkElementConnectionBuilder().setNodeId(nodeId).setHost("host").setPort(YangHelper2.getLongOrUint32(1234L)) - .setCoreModelCapability("123").setStatus(ConnectionLogStatus.Connected).setDeviceType(devType) - .setIsRequired(true).build(); + return new NetworkElementConnectionBuilder().setNodeId(nodeId).setHost("host") + .setPort(YangHelper2.getLongOrUint32(1234L)).setCoreModelCapability("123") + .setStatus(ConnectionLogStatus.Connected).setDeviceType(devType).setIsRequired(true).build(); } /** diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestImplementation.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestImplementation.java index aa010939d..16dfa0ec6 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestImplementation.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestImplementation.java @@ -22,14 +22,13 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.test; import static org.junit.Assert.fail; - import java.util.Set; - import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.common.configuration.subtypes.Section; import org.onap.ccsdk.features.sdnr.wt.common.configuration.subtypes.Section.EnvGetter; import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeHttpServlet; import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.MsServlet; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.UserdataHttpServlet; import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.about.AboutHttpServlet; import org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.DataProviderImpl; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.StatusChangedHandler.StatusKey; @@ -73,6 +72,7 @@ public class TestImplementation { impl.setMediatorServerServlet(new MsServlet()); impl.setAboutServlet(new AboutHttpServlet()); impl.setTreeServlet(new DataTreeHttpServlet()); + impl.setUserdataServlet(new UserdataHttpServlet()); try { impl.init(); } catch (Exception e) { diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNuMappings.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNuMappings.java index 76286c820..b52e34c49 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNuMappings.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestNuMappings.java @@ -24,7 +24,7 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.test; import static org.junit.Assert.assertTrue; import java.io.IOException; import org.junit.Test; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.DataProviderYangToolsMapper; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Faultcurrent; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultcurrentBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType; @@ -33,7 +33,7 @@ public class TestNuMappings { @Test public void testMapObjectToJson() throws IOException { - YangToolsMapper mapper = new YangToolsMapper(); + DataProviderYangToolsMapper mapper = new DataProviderYangToolsMapper(); Faultcurrent c = new FaultcurrentBuilder().setSeverity(SeverityType.Critical).build(); String json = mapper.writeValueAsString(c); @@ -42,7 +42,7 @@ public class TestNuMappings { @Test public void testMapJsonToObject() throws IOException { - YangToolsMapper mapper = new YangToolsMapper(); + DataProviderYangToolsMapper mapper = new DataProviderYangToolsMapper(); Faultcurrent f = mapper.readValue("{\"severity\":\"Critical\"}", Faultcurrent.class); assertTrue("Critical expected", f.getSeverity().equals(SeverityType.Critical)); diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTree.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTree.java index 53c72115d..e32179122 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTree.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestTree.java @@ -36,7 +36,6 @@ import org.onap.ccsdk.features.sdnr.wt.common.test.JSONAssert; import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.ElasticSearchDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeHttpServlet; import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeHttpServlet.EntityWithTree; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeHttpServlet.FilterMode; import org.onap.ccsdk.features.sdnr.wt.dataprovider.http.DataTreeObject; import org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.DataTreeProviderImpl; import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest; @@ -91,14 +90,14 @@ public class TestTree { provider.setDatabaseClient(dbRawProvider); - DataTreeObject tree = provider.readInventoryTree(null, null, FilterMode.Lazy); + DataTreeObject tree = provider.readInventoryTree(null, null); System.out.println(tree.toJSON()); JSONObject o = new JSONObject(tree.toJSON()); JSONAssert.assertContainsOnlyKey(o, "sim1"); JSONObject children = o.getJSONObject("sim1").getJSONObject("children"); this.assertSim1(children); - tree = provider.readInventoryTree(Arrays.asList("sim1"), "*", FilterMode.Lazy); + tree = provider.readInventoryTree(Arrays.asList("sim1"), "*"); this.assertSim1(new JSONObject(tree.toJSON())); System.out.println(tree.toJSON()); diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestUserdata.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestUserdata.java new file mode 100644 index 000000000..fd397840e --- /dev/null +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestUserdata.java @@ -0,0 +1,94 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2021 highstreet technologies GmbH 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.ccsdk.features.sdnr.wt.dataprovider.test; + +import static org.junit.Assert.fail; +import java.io.IOException; +import org.apache.sshd.common.util.io.IoUtils; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; +import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo; +import org.onap.ccsdk.features.sdnr.wt.common.test.JSONAssert; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.HtUserdataManagerImpl; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest; + +public class TestUserdata { + + private static final String USERNAME = "admin"; + private static HtDatabaseClient dbRawProvider; + private static HtUserdataManagerImpl userDbProvider; + + @BeforeClass + public static void init() throws Exception { + + HostInfo[] hosts = HostInfoForTest.get(); + dbRawProvider = HtDatabaseClient.getClient(hosts); + userDbProvider = new HtUserdataManagerImpl(dbRawProvider); + } + + public static void trySleep(long ms) { + try { + Thread.sleep(ms); + } catch (Exception e) { + Thread.currentThread().interrupt(); + } + } + + @Ignore + @Test + public void test1() { + String fullContent = ""; + try { + fullContent = getFileContent("/userdata/full.json"); + userDbProvider.setUserdata(USERNAME, fullContent); + } catch (IOException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + + trySleep(2000); + + String userdata = userDbProvider.getUserdata(USERNAME); + JSONAssert.assertEquals(fullContent, userdata, false); + String networkMapContent = ""; + String mergedContent = ""; + try { + networkMapContent = getFileContent("/userdata/networkmap.json"); + mergedContent = getFileContent("/userdata/merged.json"); + userDbProvider.setUserdata(USERNAME, "networkMap", networkMapContent); + } catch (IOException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + + trySleep(2000); + + userdata = userDbProvider.getUserdata(USERNAME); + JSONAssert.assertEquals(mergedContent, userdata, false); + } + + private static String getFileContent(String filename) throws IOException { + return String.join("\n", IoUtils.readAllLines(TestTree.class.getResourceAsStream(filename))); + } +} diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java index 3c9d4946b..524659e99 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMapping.java @@ -40,8 +40,8 @@ import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteIndexReque import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.EsDataObjectReaderWriter2; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.YangHelper2; import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapperHelper; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.DataProviderYangToolsMapper; +import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapperHelper; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; @@ -65,7 +65,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.pro public class TestYangGenSalMapping { // Create mapper for serialization and deserialization - YangToolsMapper mapper = new YangToolsMapper(); + DataProviderYangToolsMapper mapper = new DataProviderYangToolsMapper(); @Test public void test1() throws IOException { diff --git a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMappingOpenRoadm.java b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMappingOpenRoadm.java index 56df62819..1345d4edf 100644 --- a/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMappingOpenRoadm.java +++ b/sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestYangGenSalMappingOpenRoadm.java @@ -32,8 +32,8 @@ import org.jline.utils.Log; import org.junit.Test; import org.mockito.Mockito; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.YangHelper2; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper; -import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.YangToolsMapper2; +import org.onap.ccsdk.features.sdnr.wt.dataprovider.yangtools.DataProviderYangToolsMapper; +import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapper2; import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129.PmDataType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.openroadm.pm.types.rev200413.BIPErrorCounter; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.openroadm.pm.types.rev200413.OpticalPowerInputOSCMin; @@ -74,7 +74,7 @@ public class TestYangGenSalMappingOpenRoadm extends Mockito { PmdataEntity pmDataType = pmDataEntitybuilder.build(); - YangToolsMapper mapper2 = new YangToolsMapper(); + DataProviderYangToolsMapper mapper2 = new DataProviderYangToolsMapper(); String jsonString = mapper2.writeValueAsString(pmDataType); out("Result json after mapping: " + jsonString); @@ -88,7 +88,7 @@ public class TestYangGenSalMappingOpenRoadm extends Mockito { public void testOpenroadmPMString1() throws IOException, ClassNotFoundException { out("Test: " + method()); String jsonString2 = getFileContent("pmdata1.json"); - YangToolsMapper mapper2 = new YangToolsMapper(); + DataProviderYangToolsMapper mapper2 = new DataProviderYangToolsMapper(); PmdataEntity generatepmdNode = mapper2.readValue(jsonString2.getBytes(), PmdataEntity.class); out("String1:"+generatepmdNode.toString()); // Print it with specified indentation assertTrue("GranularityPeriod", generatepmdNode.getGranularityPeriod().equals(GranularityPeriodType.Period15Min)); @@ -105,7 +105,7 @@ public class TestYangGenSalMappingOpenRoadm extends Mockito { public void testOpenroadmPMString2() throws IOException, ClassNotFoundException { out("Test: " + method()); String jsonString2 = getFileContent("pmdata2.json"); - YangToolsMapper mapper2 = new YangToolsMapper(); + DataProviderYangToolsMapper mapper2 = new DataProviderYangToolsMapper(); PmdataEntity generatepmdNode = mapper2.readValue(jsonString2.getBytes(), PmdataEntity.class); out(generatepmdNode.toString()); // Print it with specified indentation } |