From cb9bd650a1ba6c1c2f5c7dd410f640b9b6f876c7 Mon Sep 17 00:00:00 2001 From: Ravi Pendurty Date: Fri, 20 Oct 2023 13:23:33 +0530 Subject: Extend user settings API Extend user settings API Issue-ID: CCSDK-3947 Change-Id: Ic0e7783abb2b084142c5bc2d36dc31810f6ca9cf Signed-off-by: Ravi Pendurty --- .../sdnr/wt/dataprovider/test/TestUserdata.java | 58 +++++++++++++++++++++- 1 file changed, 56 insertions(+), 2 deletions(-) (limited to 'sdnr/wt/data-provider/provider/src/test/java') 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 index ce4044780..79c4dd185 100644 --- 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 @@ -21,10 +21,12 @@ */ package org.onap.ccsdk.features.sdnr.wt.dataprovider.test; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.io.IOException; import org.apache.sshd.common.util.io.IoUtils; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import org.junit.BeforeClass; import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient; @@ -36,6 +38,8 @@ import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest; public class TestUserdata { private static final String USERNAME = "admin132"; + private static final String USERNAME2 = "admin133"; + private static HtDatabaseClient dbRawProvider; private static HtUserdataManagerImpl userDbProvider; @@ -45,6 +49,7 @@ public class TestUserdata { HostInfo[] hosts = HostInfoForTest.get(); dbRawProvider = HtDatabaseClient.getClient(hosts); userDbProvider = new HtUserdataManagerImpl(dbRawProvider); + } public static void trySleep(long ms) { @@ -89,6 +94,55 @@ public class TestUserdata { JSONAssert.assertEquals(mergedContent, userdata, false); } + @Test + public void test2() { + String fullContent = ""; + boolean success = false; + try { + fullContent = getFileContent("/userdata/full.json"); + success = userDbProvider.setUserdata(USERNAME2, fullContent); + } catch (IOException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + assertTrue("problem writing data into db",success); + + trySleep(2000); + // read with complex key + String userdata = userDbProvider.getUserdata(USERNAME2, "networkMap.styling"); + JSONAssert.assertEquals("{\"theme\": \"dark\"}", userdata, false); + userdata = userDbProvider.getUserdata(USERNAME2, "networkMap.startupPosition.longitude"); + assertEquals("\"13.35\"", userdata); + userdata = userDbProvider.getUserdata(USERNAME2, "networkMap.tileOpacity"); + assertEquals("\"26\"", userdata); + + // write with complex key => forbidden + success = userDbProvider.setUserdata(USERNAME2,"networkMap.styling.theme",null); + assertFalse(success); + success = userDbProvider.setUserdata(USERNAME2,"networkMap.themes.key","\"abc\""); + assertFalse(success); + // write with complex key => allowed + success = userDbProvider.setUserdata(USERNAME2,"networkMap.styling.theme","\"test\""); + assertTrue(success); + userdata = userDbProvider.getUserdata(USERNAME2, "networkMap.styling.theme"); + assertEquals("\"test\"",userdata); + success = userDbProvider.setUserdata(USERNAME2,"networkMap.styling.theme","{\"test\":\"abc\"}"); + assertTrue(success); + userdata = userDbProvider.getUserdata(USERNAME2, "networkMap.styling.theme"); + assertEquals("{\"test\":\"abc\"}",userdata); + + // delete with complex key => forbidden + success = userDbProvider.removeUserdata(USERNAME2,"networkMap.styling.theme2"); + assertFalse(success); + // delete with complex key => allowed + success = userDbProvider.removeUserdata(USERNAME2,"networkMap.styling.theme"); + assertTrue(success); + userdata = userDbProvider.getUserdata(USERNAME2, "networkMap.styling"); + assertEquals("{}",userdata); + + + } + private static String getFileContent(String filename) throws IOException { return String.join("\n", IoUtils.readAllLines(TestUserdata.class.getResourceAsStream(filename))); } -- cgit 1.2.3-korg