diff options
author | Jakub Dominik <j.dominik@samsung.com> | 2021-10-14 15:12:55 +0200 |
---|---|---|
committer | Dan Timoney <dtimoney@att.com> | 2021-11-18 13:19:44 +0000 |
commit | 98aeaac496ac868a97ce9096c1c51ce9a133992a (patch) | |
tree | e3e4a52f786f4dbe271485366f0a0c8d74edc85f /sdnr/wt/data-provider/dblib/src/test/java | |
parent | 5d3bfaac4bc7a8b7b030757e1f35795667915a2b (diff) |
Extend SDNC persistent service to store CM
Extend SDNC persistent service to store received CM events into Elasticsearch and MariaDB
Issue-ID: CCSDK-3497
Signed-off-by: Jakub Dominik <j.dominik@samsung.com>
Change-Id: I39983e59ef6512ad6c3864d47aebe1d615897146
Signed-off-by: Michael DÜrre <michael.duerre@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/data-provider/dblib/src/test/java')
5 files changed, 232 insertions, 0 deletions
diff --git a/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestConfig.java b/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestConfig.java new file mode 100644 index 000000000..676be4178 --- /dev/null +++ b/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestConfig.java @@ -0,0 +1,133 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : ccsdk features + * ================================================================================ + * Copyright (C) 2020 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.dblib.test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import com.google.common.io.Files; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; +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.database.sqldb.SqlDBConfig; + +public class TestConfig { + + + private static final String TEST_CONFIG1 = "test.properties"; + private static final String TEST_CONFIG2 = "test2.properties"; + private static final String TEST_CONFIG3 = "test3.properties"; + protected static final String SDNR_CONTROLLERID_ENV_VALUE = "903f3091-24f6-11ec-9cc3-0242ac130003"; + private static final String CONTENT_CONTROLLER_NULL = "dbType=${SDNRDBTYPE}\n" + + "\n" + + "[mariadb]\n" + + "url=${SDNRDBURL}\n" + + "username=${SDNRDBUSERNAME}\n" + + "password=${SDNRDBPASSWORD}\n" + + "controllerId=null\n" + + "suffix=-v6"; + + @Test + public void testEnvControllerId() { + + ConfigurationFileRepresentation cfg = new ConfigurationFileRepresentation(TEST_CONFIG1); + Section.setEnvGetter(new EnvGetter() { + + @Override + public String getenv(String substring) { + if("SDNRCONTROLLERID".equals(substring)) { + return SDNR_CONTROLLERID_ENV_VALUE; + } + return ""; + } + }); + SqlDBConfig config = new SqlDBConfig(cfg); + assertEquals(SDNR_CONTROLLERID_ENV_VALUE, config.getControllerId()); + } + + @Test + public void testGeneratedControllerId() { + ConfigurationFileRepresentation cfg = new ConfigurationFileRepresentation(TEST_CONFIG2); + Section.setEnvGetter(new EnvGetter() { + + @Override + public String getenv(String substring) { + return ""; + } + }); + SqlDBConfig config = new SqlDBConfig(cfg); + final String controllerId = config.getControllerId(); + assertNotNull(controllerId); + assertFalse(controllerId.isBlank()); + final String controllerId2 = config.getControllerId(); + assertEquals(controllerId, controllerId2); + } + + @Test + public void testNullControllerId() throws IOException { + Files.asCharSink(new File(TEST_CONFIG3), StandardCharsets.UTF_8).write(CONTENT_CONTROLLER_NULL); + ConfigurationFileRepresentation cfg = new ConfigurationFileRepresentation(TEST_CONFIG3); + Section.setEnvGetter(new EnvGetter() { + + @Override + public String getenv(String substring) { + return ""; + } + }); + SqlDBConfig config = new SqlDBConfig(cfg); + final String controllerId = config.getControllerId(); + assertNull(controllerId); + final String controllerId2 = config.getControllerId(); + assertNull(controllerId2); + } + + @Before + @After + public void after() throws InterruptedException, IOException { + + delete(new File(TEST_CONFIG1)); + delete(new File(TEST_CONFIG2)); + delete(new File(TEST_CONFIG3)); + + } + + private static void delete(File f) throws IOException { + if (f.isDirectory()) { + for (File c : f.listFiles()) { + delete(c); + } + } + if (f.exists()) { + if (!f.delete()) { + throw new FileNotFoundException("Failed to delete file: " + f); + } + } + } +} diff --git a/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestMariaDataProvider.java b/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestMariaDataProvider.java index da7450089..b4e0584b0 100644 --- a/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestMariaDataProvider.java +++ b/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestMariaDataProvider.java @@ -5,6 +5,8 @@ * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. * All rights reserved. * ================================================================================ + * Update Copyright (C) 2021 Samsung Electronics 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 @@ -43,6 +45,10 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.dblib.test.util.MariaDBTestB import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapper; import org.opendaylight.netconf.shaded.sshd.common.util.io.IoUtils; 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.CmNotificationType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CmSourceIndicator; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CmlogBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CmlogEntity; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ConnectionLogStatus; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ConnectionlogBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ConnectionlogEntity; @@ -70,6 +76,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.NetworkElementConnectionEntity; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.PmdataEntity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadCmlogListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadConnectionlogListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadEventlogListOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadFaultcurrentListInputBuilder; @@ -113,6 +120,7 @@ public class TestMariaDataProvider { private static final String URI1 = "http://localhost:8181"; private static final String URI2 = "http://localhost:8181"; private static final String URI3 = "http://localhost:8181"; + private static final String PATH = "https://samsung.com/3GPP/simulation/network-function/ves"; private static MariaDBTestBase testBase; private static SqlDBDataProvider dbProvider; private static SqlDBClient dbClient; @@ -199,6 +207,47 @@ public class TestMariaDataProvider { } @Test + public void testCMlog() { + ReadCmlogListOutputBuilder cmlogs = dbProvider.readCMLogList(createInput(1, 20)); + assertEquals(0, cmlogs.getData().size()); + + CmlogEntity cm1 = new CmlogBuilder() + .setNodeId(NODEID2) + .setCounter(1) + .setTimestamp(DateAndTime.getDefaultInstance(TIME1)) + .setObjectId("obj") + .setNotificationType(CmNotificationType.NotifyMOIChanges) + .setNotificationId("1") + .setSourceIndicator(CmSourceIndicator.MANAGEMENTOPERATION) + .setPath(PATH) + .setValue("pnf-registration: true") + .build(); + CmlogEntity cm2 = new CmlogBuilder() + .setNodeId(NODEID2) + .setCounter(2) + .setTimestamp(DateAndTime.getDefaultInstance(TIME2)) + .setObjectId("obj") + .setNotificationType(CmNotificationType.NotifyMOIChanges) + .setNotificationId("2") + .setSourceIndicator(CmSourceIndicator.UNKNOWN) + .setPath(PATH) + .setValue("pnf-registration: false") + .build(); + + dbProvider.writeCMLog(cm1); + dbProvider.writeCMLog(cm2); + cmlogs = dbProvider.readCMLogList(createInput("node-id", NODEID2, 1, 20)); + assertEquals(2, cmlogs.getData().size()); + + List<CmlogEntity> cmLogEntityList = List.of(cm1, cm2); + assertEquals("node2",cmLogEntityList.get(0).getNodeId()); + assertEquals("obj",cmLogEntityList.get(0).getObjectId()); + assertEquals(CmNotificationType.NotifyMOIChanges,cmLogEntityList.get(0).getNotificationType()); + assertEquals("2",cmLogEntityList.get(1).getNotificationId()); + + } + + @Test public void testConnectionlog() { try { dbClient.delete(new DeleteQuery(Entity.Connectionlog, null).toSql()); diff --git a/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestObjectIds.java b/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestObjectIds.java index 7a37345f2..2316e444a 100644 --- a/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestObjectIds.java +++ b/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestObjectIds.java @@ -22,6 +22,8 @@ package org.onap.ccsdk.features.sdnr.wt.dataprovider.dblib.test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.entity.DatabaseIdGenerator; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl; @@ -49,6 +51,11 @@ public class TestObjectIds { @Test public void testGenerator() { + assertEquals(FAULTCURRENTID1, DatabaseIdGenerator.getFaultcurrentId(NODEID1, "toto[layerProtocol="+OBJECTID1+"]", PROBLEMNAME1)); + assertEquals(FAULTCURRENTID1, DatabaseIdGenerator.getFaultcurrentId(NODEID1, "[layerProtocol="+OBJECTID1+"]", PROBLEMNAME1)); + assertEquals(FAULTCURRENTID1, DatabaseIdGenerator.getFaultcurrentId(NODEID1, "[layerPtoto[layerProtocol="+OBJECTID1+"]", PROBLEMNAME1)); + assertNotEquals(FAULTCURRENTID1, DatabaseIdGenerator.getFaultcurrentId(NODEID1, "[layerProtocol="+OBJECTID1+"]aaa", PROBLEMNAME1)); + assertEquals(FAULTCURRENTID1, DatabaseIdGenerator.getFaultcurrentId(NODEID1, OBJECTID1, PROBLEMNAME1)); assertEquals(INVENTORY_ID1, DatabaseIdGenerator .getInventoryId(new InventoryBuilder().setNodeId(NODEID1).setUuid(EQUIPMENT_UUID1).build())); diff --git a/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestQuerySyntax.java b/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestQuerySyntax.java index 758b72f9c..24347c7db 100644 --- a/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestQuerySyntax.java +++ b/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/TestQuerySyntax.java @@ -21,16 +21,22 @@ */ package org.onap.ccsdk.features.sdnr.wt.dataprovider.dblib.test; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.query.SelectQuery; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EntityInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadEventlogListInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadGuiCutThroughEntryInputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.Filter; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.FilterBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.FilterKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.PaginationBuilder; +import org.opendaylight.yangtools.yang.common.Uint32; +import org.opendaylight.yangtools.yang.common.Uint64; public class TestQuerySyntax { @@ -154,4 +160,37 @@ public class TestQuerySyntax { final String sql = query.toSql(); assertTrue(sql.contains("`timestamp`<='2022-01-01 00:00:00.000'")); } + + @Test + public void testSelectForFilterValues() { + EntityInput input = new ReadGuiCutThroughEntryInputBuilder() + .setFilter(Arrays.asList( + new FilterBuilder().setProperty("id").setFiltervalues(Arrays.asList("das", "das2")).build())) + .setPagination(new PaginationBuilder().setSize(Uint32.valueOf(20)).setPage(Uint64.valueOf(1)).build()) + .build(); + SelectQuery query = new SelectQuery(TABLENAME1, input, CONTROLLERID); + System.out.println(query.toSql()); + } + @Test + public void testSelectForFilterValues2() { + EntityInput input = new ReadGuiCutThroughEntryInputBuilder() + .setFilter(Arrays.asList( + new FilterBuilder().setProperty("id").setFiltervalue("*").build())) + .setPagination(new PaginationBuilder().setSize(Uint32.valueOf(20)).setPage(Uint64.valueOf(1)).build()) + .build(); + SelectQuery query = new SelectQuery(TABLENAME1, input, CONTROLLERID); + System.out.println(query.toSql()); + assertFalse(query.toSql().contains("RLIKE")); + } + @Test + public void testSelectForFilterValues3() { + EntityInput input = new ReadGuiCutThroughEntryInputBuilder() + .setFilter(Arrays.asList( + new FilterBuilder().setProperty("id").setFiltervalues(Arrays.asList("*","abc")).build())) + .setPagination(new PaginationBuilder().setSize(Uint32.valueOf(20)).setPage(Uint64.valueOf(1)).build()) + .build(); + SelectQuery query = new SelectQuery(TABLENAME1, input, CONTROLLERID); + System.out.println(query.toSql()); + assertFalse(query.toSql().contains("RLIKE")); + } } diff --git a/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/util/MariaDBTestBase.java b/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/util/MariaDBTestBase.java index b065519f8..3360d3ed8 100644 --- a/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/util/MariaDBTestBase.java +++ b/sdnr/wt/data-provider/dblib/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/dblib/test/util/MariaDBTestBase.java @@ -5,6 +5,8 @@ * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property. * All rights reserved. * ================================================================================ + * Update Copyright (C) 2021 Samsung Electronics 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 @@ -34,6 +36,7 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.SqlDBConfig; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.SqlDBDataProvider; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBMapper; import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.database.SqlDBMapper.UnableToMapClassException; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CmlogEntity; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ConnectionlogEntity; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.EventlogEntity; @@ -163,6 +166,7 @@ public class MariaDBTestBase { createTable(dbService, FaultcurrentEntity.class, Entity.Faultcurrent, false); createTable(dbService, FaultlogEntity.class, Entity.Faultlog, true); createTable(dbService, GuicutthroughEntity.class, Entity.Guicutthrough, false); + createTable(dbService, CmlogEntity.class, Entity.Cmlog, true); createTable(dbService, Pmdata15mEntity.class, Entity.Historicalperformance15min, false); createTable(dbService, Pmdata24hEntity.class, Entity.Historicalperformance24h, false); createTable(dbService, InventoryEntity.class, Entity.Inventoryequipment, false); |