aboutsummaryrefslogtreecommitdiffstats
path: root/music-core/src/test/java/org/onap/music/datastore/jsonobjects
diff options
context:
space:
mode:
Diffstat (limited to 'music-core/src/test/java/org/onap/music/datastore/jsonobjects')
-rw-r--r--music-core/src/test/java/org/onap/music/datastore/jsonobjects/JSONObjectTest.java54
-rw-r--r--music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonDeleteTest.java113
-rw-r--r--music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonIndexTest.java74
-rw-r--r--music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonInsertTest.java176
-rw-r--r--music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonKeySpaceTest.java72
-rw-r--r--music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonLockTest.java50
-rw-r--r--music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonSelectTest.java68
-rw-r--r--music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonTableTest.java153
-rw-r--r--music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonUpdateTest.java166
-rw-r--r--music-core/src/test/java/org/onap/music/datastore/jsonobjects/RowIdentifierTest.java60
10 files changed, 986 insertions, 0 deletions
diff --git a/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JSONObjectTest.java b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JSONObjectTest.java
new file mode 100644
index 00000000..9fb549d2
--- /dev/null
+++ b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JSONObjectTest.java
@@ -0,0 +1,54 @@
+
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP MUSIC
+ * ===================================================================
+ * Copyright (C) 2020 IBM Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.music.datastore.jsonobjects;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class JSONObjectTest {
+
+ @Test
+ public void testGetData(){
+ JSONObject js=new JSONObject();
+ js.setData("test");
+ assertEquals(js.getData(),"test");
+
+ }
+}
diff --git a/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonDeleteTest.java b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonDeleteTest.java
new file mode 100644
index 00000000..5b9cef8b
--- /dev/null
+++ b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonDeleteTest.java
@@ -0,0 +1,113 @@
+/*
+ * ============LICENSE_START==========================================
+ * org.onap.music
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property
+ * ===================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ===================================================================
+ * 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.music.datastore.jsonobjects;
+
+import static org.junit.Assert.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JsonDeleteTest {
+
+ JsonDelete jd = null;
+
+ @Before
+ public void init() {
+ jd = new JsonDelete();
+ }
+
+ @Test
+ public void testGetConditions() {
+ Map<String,Object> mapSo = new HashMap<>();
+ mapSo.put("key1","one");
+ mapSo.put("key2","two");
+ jd.setConditions(mapSo);
+ assertEquals("one",jd.getConditions().get("key1"));
+ }
+
+ @Test
+ public void testGetConsistencyInfo() {
+ Map<String,String> mapSs = new HashMap<>();
+ mapSs.put("key3","three");
+ mapSs.put("key4","four");
+ jd.setConsistencyInfo(mapSs);
+ assertEquals("three",jd.getConsistencyInfo().get("key3"));
+ }
+
+ @Test
+ public void testGetColumns() {
+ List<String> ary = new ArrayList<>();
+ ary.add("e1");
+ ary.add("e2");
+ ary.add("e3");
+ jd.setColumns(ary);
+ assertEquals("e1",jd.getColumns().get(0));
+ }
+
+ @Test
+ public void testGetTtl() {
+ jd.setTtl("2000");
+ assertEquals("2000",jd.getTtl());
+ }
+
+ @Test
+ public void testGetTimestamp() {
+ jd.setTimestamp("20:00");
+ assertEquals("20:00",jd.getTimestamp());
+
+ }
+
+ @Test
+ public void testGetKeyspaceName() {
+ jd.setKeyspaceName("keyspace");
+ assertEquals("keyspace",jd.getKeyspaceName());
+
+ }
+
+ @Test
+ public void testGetTableName() {
+ jd.setTableName("tablename");
+ assertEquals("tablename",jd.getTableName());
+
+ }
+
+ @Test
+ public void testGetPrimarKeyValue() {
+ jd.setPrimarKeyValue("primarykey");
+ assertEquals("primarykey",jd.getPrimarKeyValue());
+
+ }
+
+ @Test
+ public void testRowIdString() {
+ StringBuilder builder = new StringBuilder("testing");
+ jd.setRowIdString(builder);
+ assertEquals(jd.getRowIdString().toString(),builder.toString());
+ }
+
+}
diff --git a/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonIndexTest.java b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonIndexTest.java
new file mode 100644
index 00000000..0d89a339
--- /dev/null
+++ b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonIndexTest.java
@@ -0,0 +1,74 @@
+/*
+ * ============LICENSE_START==========================================
+ * org.onap.music
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property
+ * ===================================================================
+ * 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.music.datastore.jsonobjects;
+
+import static org.junit.Assert.*;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.music.datastore.PreparedQueryObject;
+
+public class JsonIndexTest {
+
+ JsonIndex ji = null;
+
+
+ @Before
+ public void init() {
+ ji = new JsonIndex(null, null, null, null);
+ }
+
+
+
+ @Test
+ public void testKeyspace() {
+ ji.setKeyspaceName("keyspaceName");
+ assertEquals("keyspaceName", ji.getKeyspaceName());
+ }
+
+ @Test
+ public void testIndexName() {
+ ji.setIndexName("indexName");
+ assertEquals("indexName", ji.getIndexName());
+ }
+
+ @Test
+ public void testFieldName() {
+ ji.setFieldName("field");
+ assertEquals("field", ji.getFieldName());
+ }
+
+ @Test
+ public void testTableName() {
+ ji.setTableName("table");
+ assertEquals("table", ji.getTableName());
+ }
+
+ @Test
+ public void testCreateIndexQuery() {
+ JsonIndex ji2 = new JsonIndex("index", "keyspace", "table", "field");
+ PreparedQueryObject query = ji2.genCreateIndexQuery();
+ assertEquals("Create index if not exists index on keyspace.table (field);", query.getQuery());
+ }
+}
diff --git a/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonInsertTest.java b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonInsertTest.java
new file mode 100644
index 00000000..ad71c9ea
--- /dev/null
+++ b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonInsertTest.java
@@ -0,0 +1,176 @@
+/*
+ * ============LICENSE_START==========================================
+ * org.onap.music
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property
+ * ===================================================================
+ * Modifications Copyright (c) 2019 IBM.
+ * ===================================================================
+ * 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.music.datastore.jsonobjects;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang3.SerializationUtils;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.internal.util.reflection.FieldSetter;
+import org.onap.music.datastore.MusicDataStore;
+import org.onap.music.datastore.MusicDataStoreHandle;
+import org.onap.music.datastore.PreparedQueryObject;
+import org.onap.music.exceptions.MusicQueryException;
+import org.onap.music.exceptions.MusicServiceException;
+import com.datastax.driver.core.ColumnMetadata;
+import com.datastax.driver.core.DataType;
+import com.datastax.driver.core.Session;
+//import org.mockito.internal.util.reflection.Whitebox;
+import com.datastax.driver.core.TableMetadata;
+
+
+public class JsonInsertTest {
+
+ JsonInsert ji = new JsonInsert();
+
+ @Test
+ public void testGetKeyspaceName() {
+ ji.setKeyspaceName("keyspace");
+ assertEquals("keyspace",ji.getKeyspaceName());
+ }
+
+ @Test
+ public void testGetTableName() {
+ ji.setTableName("table");
+ assertEquals("table",ji.getTableName());
+ }
+
+ @Test
+ public void testGetConsistencyInfo() {
+ Map<String,String> cons = new HashMap<>();
+ cons.put("test","true");
+ ji.setConsistencyInfo(cons);
+ assertEquals("true",ji.getConsistencyInfo().get("test"));
+ }
+
+ @Test
+ public void testGetTtl() {
+ ji.setTtl("ttl");
+ assertEquals("ttl",ji.getTtl());
+ }
+
+ @Test
+ public void testGetTimestamp() {
+ ji.setTimestamp("10:30");
+ assertEquals("10:30",ji.getTimestamp());
+ }
+
+ @Test
+ public void testGetValues() {
+ Map<String,Object> cons = new HashMap<>();
+ cons.put("val1","one");
+ cons.put("val2","two");
+ ji.setValues(cons);
+ assertEquals("one",ji.getValues().get("val1"));
+ }
+
+ @Test
+ public void testGetRowSpecification() {
+ Map<String,Object> cons = new HashMap<>();
+ cons.put("val1","one");
+ cons.put("val2","two");
+ ji.setRowSpecification(cons);
+ assertEquals("two",ji.getRowSpecification().get("val2"));
+ }
+
+ @Test
+ public void testSerialize() {
+ Map<String,Object> cons = new HashMap<>();
+ cons.put("val1","one");
+ cons.put("val2","two");
+ ji.setTimestamp("10:30");
+ ji.setRowSpecification(cons);
+ byte[] test1 = ji.serialize();
+ byte[] ji1 = SerializationUtils.serialize(ji);
+ assertArrayEquals(ji1,test1);
+ }
+
+ @Test
+ public void testObjectMap()
+ {
+ Map<String, byte[]> map = new HashMap<>();
+ ji.setObjectMap(map);
+ assertEquals(map, ji.getObjectMap());
+ }
+
+ @Test
+ public void testPrimaryKey() {
+ ji.setPrimaryKeyVal("primKey");
+ assertEquals("primKey", ji.getPrimaryKeyVal());
+ }
+
+ @Test
+ public void testGenInsertPreparedQueryObj() throws Exception {
+ ji.setKeyspaceName("keyspace");
+ ji.setTableName("table");
+ ji.setPrimaryKeyVal("value");
+ Map<String,Object> rowSpec = new HashMap<>();
+ rowSpec.put("val1","one");
+ rowSpec.put("val2","two");
+ ji.setRowSpecification(rowSpec);
+ Map<String,Object> vals = new HashMap<>();
+ vals.put("val1","one");
+ vals.put("val2","two");
+ ji.setValues(vals);
+
+ Map<String,String> cons = new HashMap<>();
+ cons.put("type","quorum");
+ ji.setConsistencyInfo(cons);
+
+ MusicDataStore mds = Mockito.mock(MusicDataStore.class);
+ Session session = Mockito.mock(Session.class);
+ Mockito.when(mds.getSession()).thenReturn(session);
+ MusicDataStoreHandle mdsh = Mockito.mock(MusicDataStoreHandle.class);
+ FieldSetter.setField(mdsh, mdsh.getClass().getDeclaredField("mDstoreHandle"), mds);
+ TableMetadata tableMeta = Mockito.mock(TableMetadata.class);
+ Mockito.when(mds.returnColumnMetadata(Mockito.anyString(), Mockito.anyString()))
+ .thenReturn(tableMeta);
+
+ ColumnMetadata cmd = Mockito.mock(ColumnMetadata.class);
+ List<ColumnMetadata> listcmd = new ArrayList<>();
+ listcmd.add(cmd);
+ Mockito.when(tableMeta.getPrimaryKey()).thenReturn(listcmd);
+ Mockito.when(cmd.getName()).thenReturn("val1");
+ Mockito.when(tableMeta.getColumn("val1")).thenReturn(cmd);
+ Mockito.when(tableMeta.getColumn("val2")).thenReturn(cmd);
+ Mockito.when(cmd.getType()).thenReturn(DataType.text());
+
+ PreparedQueryObject query = ji.genInsertPreparedQueryObj();
+ System.out.println(query.getQuery());
+ System.out.println(query.getValues());
+
+
+ assertEquals("INSERT INTO keyspace.table (vector_ts,val2,val1) VALUES (?,?,?);", query.getQuery());
+ assertTrue(query.getValues().containsAll(vals.values()));
+ }
+
+}
diff --git a/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonKeySpaceTest.java b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonKeySpaceTest.java
new file mode 100644
index 00000000..a3fa58e4
--- /dev/null
+++ b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonKeySpaceTest.java
@@ -0,0 +1,72 @@
+/*
+ * ============LICENSE_START==========================================
+ * org.onap.music
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property
+ * ===================================================================
+ * 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.music.datastore.jsonobjects;
+
+import static org.junit.Assert.*;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JsonKeySpaceTest {
+
+ JsonKeySpace jk = null;
+
+
+ @Before
+ public void init() {
+ jk = new JsonKeySpace();
+ }
+
+
+
+ @Test
+ public void testGetConsistencyInfo() {
+ Map<String, String> mapSs = new HashMap<>();
+ mapSs.put("k1", "one");
+ jk.setConsistencyInfo(mapSs);
+ assertEquals("one",jk.getConsistencyInfo().get("k1"));
+ }
+
+ @Test
+ public void testGetReplicationInfo() {
+ Map<String,Object> mapSo = new HashMap<>();
+ mapSo.put("k1", "one");
+ jk.setReplicationInfo(mapSo);
+ assertEquals("one",jk.getReplicationInfo().get("k1"));
+
+ }
+
+ @Test
+ public void testGetDurabilityOfWrites() {
+ jk.setDurabilityOfWrites("1");
+ assertEquals("1",jk.getDurabilityOfWrites());
+ }
+
+ @Test
+ public void testGetKeyspaceName() {
+ jk.setKeyspaceName("Keyspace");
+ assertEquals("Keyspace",jk.getKeyspaceName());
+ }
+
+}
diff --git a/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonLockTest.java b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonLockTest.java
new file mode 100644
index 00000000..75db75e5
--- /dev/null
+++ b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonLockTest.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * ============LICENSE_START==========================================
+ * org.onap.music
+ * ===================================================================
+ * Copyright (c) 2019 AT&T Intellectual Property
+ * ===================================================================
+ * 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.music.datastore.jsonobjects;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.music.lockingservice.cassandra.LockType;
+
+public class JsonLockTest {
+
+ JsonLock jsonLock;
+
+ @Before
+ public void setup() {
+ jsonLock = new JsonLock();
+ }
+
+ @Test
+ public void testSetLockType() {
+ jsonLock.setLockType(LockType.READ);
+ assertEquals(LockType.READ, jsonLock.getLocktype());
+
+ jsonLock.setLockType(LockType.WRITE);
+ assertEquals(LockType.WRITE, jsonLock.getLocktype());
+
+ jsonLock.setLockType(LockType.PROMOTING);
+ assertEquals(LockType.PROMOTING, jsonLock.getLocktype());
+ }
+}
diff --git a/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonSelectTest.java b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonSelectTest.java
new file mode 100644
index 00000000..baada1d5
--- /dev/null
+++ b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonSelectTest.java
@@ -0,0 +1,68 @@
+/*
+ * ============LICENSE_START==========================================
+ * org.onap.music
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property
+ * ===================================================================
+ * Modifications Copyright (c) 2018-2019 IBM
+ * ===================================================================
+ * 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.music.datastore.jsonobjects;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Test;
+
+public class JsonSelectTest {
+ JsonSelect js = new JsonSelect();
+
+ @Test
+ public void testGetConsistencyInfo() {
+ Map<String, String> mapSs = new HashMap<>();
+ mapSs.put("k1", "one");
+ js.setConsistencyInfo(mapSs);
+ assertEquals("one", js.getConsistencyInfo().get("k1"));
+ }
+
+ @Test
+ public void testSerialize() throws IOException {
+ Map<String, String> mapSs = new HashMap<>();
+ mapSs.put("Key", "Value");
+ js.setConsistencyInfo(mapSs);
+ js.serialize();
+ }
+
+ @Test
+ public void testGetKeyspaceName() {
+ js.setKeyspaceName("testkeyspace");
+ assertEquals("testkeyspace",js.getKeyspaceName());
+
+ }
+
+ @Test
+ public void testGetTableName() {
+ js.setTableName("testkeyspace");
+ assertEquals("testkeyspace",js.getTableName());
+
+ }
+
+}
diff --git a/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonTableTest.java b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonTableTest.java
new file mode 100644
index 00000000..3ab32d40
--- /dev/null
+++ b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonTableTest.java
@@ -0,0 +1,153 @@
+/*
+ * ============LICENSE_START==========================================
+ * org.onap.music
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property
+ * ===================================================================
+ * Modifications Copyright (c) 2019 IBM.
+ * ===================================================================
+ * 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.music.datastore.jsonobjects;
+
+import static org.junit.Assert.*;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.music.exceptions.MusicQueryException;
+
+public class JsonTableTest {
+
+ JsonTable jt = null;
+
+ @Before
+ public void init() {
+ jt = new JsonTable();
+ }
+
+ @Test
+ public void testGetConsistencyInfo() {
+ Map<String, String> mapSs = new HashMap<>();
+ mapSs.put("k1", "one");
+ jt.setConsistencyInfo(mapSs);
+ assertEquals("one",jt.getConsistencyInfo().get("k1"));
+ }
+
+ @Test
+ public void testGetProperties() {
+ Map<String, Object> properties = new HashMap<>();
+ properties.put("k1", "one");
+ jt.setProperties(properties);
+ assertEquals(properties.size(), jt.getProperties().size());
+ }
+
+ @Test
+ public void testGetFields() {
+ Map<String, String> fields = new HashMap<>();
+ fields.put("k1", "one");
+ jt.setFields(fields);
+ assertEquals("one",jt.getFields().get("k1"));
+ }
+
+ @Test
+ public void testGetKeyspaceName() {
+ String keyspace = "keyspace";
+ jt.setKeyspaceName(keyspace);
+ assertEquals(keyspace,jt.getKeyspaceName());
+ }
+
+ @Test
+ public void testGetTableName() {
+ String table = "table";
+ jt.setTableName(table);
+ assertEquals(table,jt.getTableName());
+ }
+
+ @Test
+ public void testGetClusteringOrder() {
+ String clusteringOrder = "clusteringOrder";
+ jt.setClusteringOrder(clusteringOrder);
+ assertEquals(clusteringOrder,jt.getClusteringOrder());
+ }
+
+ @Test
+ public void testGetClusterKey() {
+ String clusterKey = "clusterKey";
+ jt.setClusteringKey(clusterKey);
+ assertEquals(clusterKey, jt.getClusteringKey());
+ }
+
+ @Test
+ public void testGetPrimaryKey() {
+ String primaryKey = "primaryKey";
+ jt.setPrimaryKey(primaryKey);
+ assertEquals(primaryKey,jt.getPrimaryKey());
+ }
+
+ @Test
+ public void testFilteringKey() {
+ jt.setFilteringKey("FilteringKey");
+ assertEquals("FilteringKey",jt.getFilteringKey());
+ }
+
+ @Test
+ public void testPartitionKey() {
+ jt.setPartitionKey("ParitionKey");
+ assertEquals("ParitionKey",jt.getPartitionKey());
+ }
+
+ @Test
+ public void genCreateTableQuery() throws MusicQueryException {
+ JsonTable jt2 = new JsonTable();
+ jt2.setKeyspaceName("keyspace");
+ jt2.setTableName("table");
+ Map<String, String> fields = new HashMap<>();
+ fields.put("k1", "one");
+ jt2.setFields(fields);
+ jt2.setPrimaryKey("k1");
+ Map<String, String> mapSs = new HashMap<>();
+ mapSs.put("k1", "one");
+ jt2.setConsistencyInfo(mapSs);
+ String clusteringOrder = "clusteringOrder";
+ jt.setClusteringOrder(clusteringOrder);
+ String clusterKey = "clusterKey";
+ jt.setClusteringKey(clusterKey);
+
+ System.out.println(jt2.genCreateTableQuery().getQuery());
+ assertEquals("CREATE TABLE keyspace.table (vector_ts text,k1 one, PRIMARY KEY ( (k1) ));",
+ jt2.genCreateTableQuery().getQuery());
+ }
+
+ @Test
+ public void genDropTableQuery() throws MusicQueryException {
+ JsonTable jt2 = new JsonTable();
+ jt2.setKeyspaceName("keyspace");
+ jt2.setTableName("table");
+ Map<String, String> fields = new HashMap<>();
+ fields.put("k1", "one");
+ jt2.setFields(fields);
+ jt2.setPrimaryKey("k1");
+ Map<String, String> mapSs = new HashMap<>();
+ mapSs.put("k1", "one");
+ jt.setConsistencyInfo(mapSs);
+
+ System.out.println(jt2.genDropTableQuery().getQuery());
+ assertEquals("DROP TABLE keyspace.table;",
+ jt2.genDropTableQuery().getQuery());
+ }
+}
diff --git a/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonUpdateTest.java b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonUpdateTest.java
new file mode 100644
index 00000000..37c729f4
--- /dev/null
+++ b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonUpdateTest.java
@@ -0,0 +1,166 @@
+/*******************************************************************************
+ * ============LICENSE_START==========================================
+ * org.onap.music
+ * ===================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property
+ * ===================================================================
+ * Modifications Copyright (c) 2019 IBM.
+ * ===================================================================
+ * 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.music.datastore.jsonobjects;
+
+import static org.junit.Assert.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.ws.rs.core.MultivaluedMap;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.music.datastore.jsonobjects.JsonUpdate.RowIdentifier;
+import com.datastax.driver.core.ColumnMetadata;
+import com.datastax.driver.core.DataType;
+import com.datastax.driver.core.TableMetadata;
+
+public class JsonUpdateTest {
+
+ JsonUpdate ju = null;
+
+ @Before
+ public void init() {
+ ju = new JsonUpdate();
+ }
+
+
+ @Test
+ public void testGetConditions() {
+ Map<String,Object> mapSo = new HashMap<>();
+ mapSo.put("key1","one");
+ mapSo.put("key2","two");
+ ju.setConditions(mapSo);
+ assertEquals("one",ju.getConditions().get("key1"));
+ }
+
+ @Test
+ public void testGetRow_specification() {
+ Map<String,Object> mapSo = new HashMap<>();
+ mapSo.put("key1","one");
+ mapSo.put("key2","two");
+ ju.setRow_specification(mapSo);
+ assertEquals("one",ju.getRow_specification().get("key1"));
+ }
+
+ @Test
+ public void testGetKeyspaceName() {
+ String keyspace = "keyspace";
+ ju.setKeyspaceName(keyspace);
+ assertEquals(keyspace,ju.getKeyspaceName());
+ }
+
+ @Test
+ public void testGetTableName() {
+ String table = "table";
+ ju.setTableName(table);
+ assertEquals(table,ju.getTableName());
+ }
+
+ @Test
+ public void testGetConsistencyInfo() {
+ Map<String, String> mapSs = new HashMap<>();
+ mapSs.put("k1", "one");
+ ju.setConsistencyInfo(mapSs);
+ assertEquals("one",ju.getConsistencyInfo().get("k1"));
+ }
+
+ @Test
+ public void testGetTtl() {
+ ju.setTtl("2000");
+ assertEquals("2000",ju.getTtl());
+ }
+
+ @Test
+ public void testGetTimestamp() {
+ ju.setTimestamp("20:00");
+ assertEquals("20:00",ju.getTimestamp());
+
+ }
+
+ @Test
+ public void testGetValues() {
+ Map<String,Object> cons = new HashMap<>();
+ cons.put("val1","one");
+ cons.put("val2","two");
+ ju.setValues(cons);
+ assertEquals("one",ju.getValues().get("val1"));
+ }
+
+ @Test
+ public void testSerialize() {
+ assertTrue(ju.serialize() instanceof byte[]);
+ }
+
+ @Test
+ public void testRowIdString() {
+ ju.setRowIdString("testing");
+ assertEquals("testing", ju.getRowIdString());
+ }
+
+ @Test
+ public void testPrimaryKeyValue() {
+ ju.setPrimarKeyValue("primeKey");
+ assertEquals("primeKey", ju.getPrimarKeyValue());
+ }
+
+ @Test
+ public void testGenUpdatePreparedQueryObj() throws Exception {
+ JsonUpdate ju = Mockito.spy(JsonUpdate.class);
+ MultivaluedMap<String, String> rowParams = Mockito.mock(MultivaluedMap.class);
+
+ ju.setKeyspaceName("keyspace");
+ ju.setTableName("table");
+ ju.setPrimarKeyValue("primaryKeyValue");
+ Map<String, String> consistencyInfo = new HashMap<>();
+ consistencyInfo.put("type", "critical");
+ ju.setConsistencyInfo(consistencyInfo);
+ Map<String, Object> values = new HashMap<>();
+ values.put("col1", "val1");
+ ju.setValues(values);
+
+ TableMetadata tmd = Mockito.mock(TableMetadata.class);
+ Mockito.doReturn(tmd).when(ju).returnColumnMetadata(Mockito.anyString(), Mockito.anyString());
+ ColumnMetadata cmd = Mockito.mock(ColumnMetadata.class);
+ Mockito.when(tmd.getColumn("col1")).thenReturn(cmd);
+ List<ColumnMetadata> colList = new ArrayList<>();
+ colList.add(cmd);
+ Mockito.when(tmd.getPrimaryKey()).thenReturn(colList);
+ Mockito.when(cmd.getType()).thenReturn(DataType.varchar());
+
+ RowIdentifier rowId = Mockito.mock(RowIdentifier.class);
+ Mockito.doReturn(rowId).when(ju).getRowIdentifier(Mockito.anyString(), Mockito.anyString(), Mockito.any(),
+ Mockito.any());
+
+ Mockito.when(rowId.getRowIdString()).thenReturn("col1");
+ Mockito.when(rowId.getPrimaryKeyValue()).thenReturn("val1");
+
+
+ assertEquals("UPDATE keyspace.table SET vector_ts=?,col1= ? WHERE col1;",
+ ju.genUpdatePreparedQueryObj(rowParams).getQuery());
+ }
+}
diff --git a/music-core/src/test/java/org/onap/music/datastore/jsonobjects/RowIdentifierTest.java b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/RowIdentifierTest.java
new file mode 100644
index 00000000..e29f0377
--- /dev/null
+++ b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/RowIdentifierTest.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP MUSIC
+ * ===================================================================
+ * Copyright (C) 2020 IBM Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.music.datastore.jsonobjects;
+
+import org.onap.music.datastore.PreparedQueryObject;
+import org.onap.music.datastore.jsonobjects.JsonUpdate;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class RowIdentifierTest {
+ String primarykey="primarykey";
+ String rowIdString="123";
+ PreparedQueryObject queryObject=new PreparedQueryObject("select * from employee");
+ JsonUpdate ju=new JsonUpdate();
+ JsonUpdate.RowIdentifier rowId= ju.new RowIdentifier(primarykey,rowIdString,queryObject);
+ @Test
+ public void testConstructor(){
+ rowId.setPrimaryKeyValue(primarykey);
+ rowId.setRowIdString(rowIdString);
+ assertEquals(rowId.getPrimaryKeyValue(),"primarykey");
+ assertEquals(rowId.getRowIdString(),"123");
+ }
+}