aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/data-provider/provider/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'sdnr/wt/data-provider/provider/src/test')
-rw-r--r--sdnr/wt/data-provider/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/test/TestUserdata.java58
-rw-r--r--sdnr/wt/data-provider/provider/src/test/resources/userdata/full.json7
2 files changed, 63 insertions, 2 deletions
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)));
}
diff --git a/sdnr/wt/data-provider/provider/src/test/resources/userdata/full.json b/sdnr/wt/data-provider/provider/src/test/resources/userdata/full.json
index c5b41ec21..4206ddc31 100644
--- a/sdnr/wt/data-provider/provider/src/test/resources/userdata/full.json
+++ b/sdnr/wt/data-provider/provider/src/test/resources/userdata/full.json
@@ -8,6 +8,13 @@
"zoom": "10",
"longitude": "13.35"
},
+ "themes": [
+ {
+ "key": "light",
+ "padding": 10,
+ "mainColor": "#ff0000"
+ }
+ ],
"tileOpacity": "26"
}
} \ No newline at end of file