aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/onap/music/unittests/CassandraCQL.java256
-rw-r--r--src/test/java/org/onap/music/unittests/JsonResponseTest.java83
-rw-r--r--src/test/java/org/onap/music/unittests/MusicDataStoreTest.java162
-rw-r--r--src/test/java/org/onap/music/unittests/MusicUtilTest.java207
-rw-r--r--src/test/java/org/onap/music/unittests/ResultTypeTest.java43
-rw-r--r--src/test/java/org/onap/music/unittests/ReturnTypeTest.java83
-rw-r--r--src/test/java/org/onap/music/unittests/TestLockStore.java53
-rw-r--r--src/test/java/org/onap/music/unittests/TestMusicCore.java678
-rw-r--r--src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java176
-rw-r--r--src/test/java/org/onap/music/unittests/TestRestAdminData.java2244
-rw-r--r--src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java1031
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/AAFResponseTest.java54
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JSONObjectTest.java44
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java86
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java86
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java72
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonLeasedLockTest.java53
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonNotifyClientResponseTest.java46
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonOnboardTest.java78
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java41
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java99
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java103
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/NameSpaceTest.java56
23 files changed, 0 insertions, 5834 deletions
diff --git a/src/test/java/org/onap/music/unittests/CassandraCQL.java b/src/test/java/org/onap/music/unittests/CassandraCQL.java
deleted file mode 100644
index a4c250c2..00000000
--- a/src/test/java/org/onap/music/unittests/CassandraCQL.java
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * ============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.unittests;
-
-/**
- * @author srupane
- *
- */
-
-import java.io.IOException;
-import java.math.BigInteger;
-import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.net.SocketException;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import com.datastax.driver.core.Cluster;
-import com.datastax.driver.core.Session;
-import com.datastax.driver.core.exceptions.NoHostAvailableException;
-import org.apache.cassandra.exceptions.ConfigurationException;
-import org.apache.thrift.transport.TTransportException;
-import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
-import org.onap.music.datastore.MusicDataStore;
-import org.onap.music.datastore.PreparedQueryObject;
-
-public class CassandraCQL {
-
- public static final String createKeySpace =
- "CREATE KEYSPACE IF NOT EXISTS testCassa WITH replication = "
- +"{'class':'SimpleStrategy','replication_factor':1} AND durable_writes = true;";
-
- public static final String dropKeyspace = "DROP KEYSPACE IF EXISTS testCassa";
-
- public static final String createTableEmployees =
- "CREATE TABLE IF NOT EXISTS testCassa.employees "
- + "(vector_ts text,empId uuid,empName text,empSalary varint,address Map<text,text>,PRIMARY KEY (empName)) "
- + "WITH comment='Financial Info of employees' "
- + "AND compression={'sstable_compression':'DeflateCompressor','chunk_length_kb':64} "
- + "AND compaction={'class':'SizeTieredCompactionStrategy','min_threshold':6};";
-
- public static final String insertIntoTablePrepared1 =
- "INSERT INTO testCassa.employees (vector_ts,empId,empName,empSalary) VALUES (?,?,?,?); ";
-
- public static final String insertIntoTablePrepared2 =
- "INSERT INTO testCassa.employees (vector_ts,empId,empName,empSalary,address) VALUES (?,?,?,?,?);";
-
- public static final String selectALL = "SELECT * FROM testCassa.employees;";
-
- public static final String selectSpecific =
- "SELECT * FROM testCassa.employees WHERE empName= ?;";
-
- public static final String updatePreparedQuery =
- "UPDATE testCassa.employees SET vector_ts=?,address= ? WHERE empName= ?;";
-
- public static final String deleteFromTable = " ";
-
- public static final String deleteFromTablePrepared = " ";
-
- // Set Values for Prepared Query
-
- public static List<Object> setPreparedInsertValues1() {
-
- List<Object> preppreparedInsertValues1 = new ArrayList<>();
- String vectorTs =
- String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis());
- UUID empId = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40cd6");
- BigInteger empSalary = BigInteger.valueOf(23443);
- String empName = "Mr Test one";
- preppreparedInsertValues1.add(vectorTs);
- preppreparedInsertValues1.add(empId);
- preppreparedInsertValues1.add(empName);
- preppreparedInsertValues1.add(empSalary);
- return preppreparedInsertValues1;
- }
-
- public static List<Object> setPreparedInsertValues2() {
-
- List<Object> preparedInsertValues2 = new ArrayList<>();
- String vectorTs =
- String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis());
- UUID empId = UUID.fromString("abc434cc-d657-4e90-b4e5-df4223d40cd6");
- BigInteger empSalary = BigInteger.valueOf(45655);
- String empName = "Mr Test two";
- Map<String, String> address = new HashMap<>();
- preparedInsertValues2.add(vectorTs);
- preparedInsertValues2.add(empId);
- preparedInsertValues2.add(empName);
- preparedInsertValues2.add(empSalary);
- address.put("Street", "1 some way");
- address.put("City", "Some town");
- preparedInsertValues2.add(address);
- return preparedInsertValues2;
- }
-
- public static List<Object> setPreparedUpdateValues() {
-
- List<Object> preparedUpdateValues = new ArrayList<>();
- String vectorTs =
- String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis());
- Map<String, String> address = new HashMap<>();
- preparedUpdateValues.add(vectorTs);
- String empName = "Mr Test one";
- address.put("Street", "101 Some Way");
- address.put("City", "New York");
- preparedUpdateValues.add(address);
- preparedUpdateValues.add(empName);
- return preparedUpdateValues;
- }
-
- // Generate Different Prepared Query Objects
- /**
- * Query Object for Get.
- *
- * @return
- */
- public static PreparedQueryObject setPreparedGetQuery() {
-
- PreparedQueryObject queryObject = new PreparedQueryObject();
- String empName1 = "Mr Test one";
- queryObject.appendQueryString(selectSpecific);
- queryObject.addValue(empName1);
- return queryObject;
- }
-
- /**
- * Query Object 1 for Insert.
- *
- * @return {@link PreparedQueryObject}
- */
- public static PreparedQueryObject setPreparedInsertQueryObject1() {
-
- PreparedQueryObject queryobject = new PreparedQueryObject();
- queryobject.appendQueryString(insertIntoTablePrepared1);
- List<Object> values = setPreparedInsertValues1();
- if (!values.isEmpty() || values != null) {
- for (Object o : values) {
- queryobject.addValue(o);
- }
- }
- return queryobject;
-
- }
-
- /**
- * Query Object 2 for Insert.
- *
- * @return {@link PreparedQueryObject}
- */
- public static PreparedQueryObject setPreparedInsertQueryObject2() {
-
- PreparedQueryObject queryobject = new PreparedQueryObject();
- queryobject.appendQueryString(insertIntoTablePrepared2);
- List<Object> values = setPreparedInsertValues2();
- if (!values.isEmpty() || values != null) {
- for (Object o : values) {
- queryobject.addValue(o);
- }
- }
- return queryobject;
-
- }
-
- /**
- * Query Object for Update.
- *
- * @return {@link PreparedQueryObject}
- */
- public static PreparedQueryObject setPreparedUpdateQueryObject() {
-
- PreparedQueryObject queryobject = new PreparedQueryObject();
- queryobject.appendQueryString(updatePreparedQuery);
- List<Object> values = setPreparedUpdateValues();
- if (!values.isEmpty() || values != null) {
- for (Object o : values) {
- queryobject.addValue(o);
- }
- }
- return queryobject;
-
- }
-
- private static ArrayList<String> getAllPossibleLocalIps() {
- ArrayList<String> allPossibleIps = new ArrayList<String>();
- try {
- Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
- while (en.hasMoreElements()) {
- NetworkInterface ni = (NetworkInterface) en.nextElement();
- Enumeration<InetAddress> ee = ni.getInetAddresses();
- while (ee.hasMoreElements()) {
- InetAddress ia = (InetAddress) ee.nextElement();
- allPossibleIps.add(ia.getHostAddress());
- }
- }
- } catch (SocketException e) {
- System.out.println(e.getMessage());
- }
- return allPossibleIps;
- }
-
- public static MusicDataStore connectToEmbeddedCassandra() {
- Iterator<String> it = getAllPossibleLocalIps().iterator();
- String address = "localhost";
-
- Cluster cluster = null;
- Session session = null;
- while (it.hasNext()) {
- try {
-
- try {
- EmbeddedCassandraServerHelper.startEmbeddedCassandra(80000);
- } catch (ConfigurationException | TTransportException | IOException e) {
-
- System.out.println(e.getMessage());
- }
-
- cluster = new Cluster.Builder().addContactPoint(address).withPort(9142).build();
- cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(20000);
- session = cluster.connect();
-
- break;
- } catch (NoHostAvailableException e) {
- address = it.next();
- System.out.println(e.getMessage());
-
- }
- }
- return new MusicDataStore(cluster, session);
-
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/JsonResponseTest.java b/src/test/java/org/onap/music/unittests/JsonResponseTest.java
deleted file mode 100644
index 9da10638..00000000
--- a/src/test/java/org/onap/music/unittests/JsonResponseTest.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * ============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.unittests;
-
-import static org.junit.Assert.*;
-import java.util.Map;
-import org.junit.Test;
-import org.onap.music.main.ResultType;
-import org.onap.music.response.jsonobjects.JsonResponse;
-
-public class JsonResponseTest {
-
- JsonResponse result = null;
-
- @Test
- public void testJsonResponseBooleanStringString() {
- result = new JsonResponse(ResultType.SUCCESS).setError("error").setMusicVersion("version");
- assertEquals("error",result.getError());
- }
-
- @Test
- public void testStatus() {
- result = new JsonResponse(ResultType.SUCCESS);
- result.setStatus(ResultType.SUCCESS);
- assertEquals(ResultType.SUCCESS, result.getStatus());
- result = new JsonResponse(ResultType.FAILURE).setError("error").setMusicVersion("version");
- assertEquals(ResultType.FAILURE, result.getStatus());
- }
-
- @Test
- public void testError() {
- result = new JsonResponse(ResultType.FAILURE);
- result.setError("error");
- assertTrue(result.getError().equals("error"));
- result.setError("");
- assertFalse(result.getError().equals("error"));
- }
-
- @Test
- public void testVersion() {
- result = new JsonResponse(ResultType.SUCCESS);
- result.setMusicVersion("version");
- assertTrue(result.getMusicVersion().equals("version"));
- result.setMusicVersion("");
- assertFalse(result.getMusicVersion().equals("version"));
- }
-
- @Test
- public void testToMap() {
- result = new JsonResponse(ResultType.SUCCESS).setError("error").setMusicVersion("1.0");
- Map<String,Object> myMap = result.toMap();
- assertTrue(myMap.containsKey("status"));
- assertEquals(ResultType.SUCCESS, myMap.get("status"));
- assertEquals("error", myMap.get("error"));
- assertEquals("1.0", myMap.get("version"));
-
- result = new JsonResponse(ResultType.FAILURE);
- myMap = result.toMap();
- assertTrue(myMap.containsKey("status"));
- assertEquals(ResultType.FAILURE, myMap.get("status"));
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java b/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java
deleted file mode 100644
index 16d2af02..00000000
--- a/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * ============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.unittests;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-import org.mockito.Mock;
-import org.onap.music.exceptions.MusicQueryException;
-import org.onap.music.exceptions.MusicServiceException;
-
-import org.onap.music.datastore.MusicDataStore;
-import org.onap.music.datastore.PreparedQueryObject;
-
-import com.datastax.driver.core.DataType;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
-import com.datastax.driver.core.TableMetadata;
-
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class MusicDataStoreTest {
-
- static MusicDataStore dataStore;
- static PreparedQueryObject testObject;
-
- @BeforeClass
- public static void init() {
- dataStore = CassandraCQL.connectToEmbeddedCassandra();
-
- }
-
- @AfterClass
- public static void close() throws MusicServiceException, MusicQueryException {
-
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.dropKeyspace);
- dataStore.executePut(testObject, "eventual");
- dataStore.close();
-
- }
-
- @Test
- public void Test1_SetUp() throws MusicServiceException, MusicQueryException {
- boolean result = false;
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.createKeySpace);
- result = dataStore.executePut(testObject, "eventual");;
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.createTableEmployees);
- result = dataStore.executePut(testObject, "eventual");
- assertEquals(true, result);
-
- }
-
- @Test
- public void Test2_ExecutePut_eventual_insert() throws MusicServiceException, MusicQueryException {
- testObject = CassandraCQL.setPreparedInsertQueryObject1();
- boolean result = dataStore.executePut(testObject, "eventual");
- assertEquals(true, result);
- }
-
- @Test
- public void Test3_ExecutePut_critical_insert() throws MusicServiceException, MusicQueryException {
- testObject = CassandraCQL.setPreparedInsertQueryObject2();
- boolean result = dataStore.executePut(testObject, "Critical");
- assertEquals(true, result);
- }
-
- @Test
- public void Test4_ExecutePut_eventual_update() throws MusicServiceException, MusicQueryException {
- testObject = CassandraCQL.setPreparedUpdateQueryObject();
- boolean result = false;
- result = dataStore.executePut(testObject, "eventual");
- assertEquals(true, result);
- }
-
- @Test
- public void Test5_ExecuteEventualGet() throws MusicServiceException, MusicQueryException {
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.selectALL);
- boolean result = false;
- int count = 0;
- ResultSet output = null;
- output = dataStore.executeEventualGet(testObject);
- System.out.println(output);
- ;
- for (Row row : output) {
- count++;
- System.out.println(row.toString());
- }
- if (count == 2) {
- result = true;
- }
- assertEquals(true, result);
- }
-
- @Test
- public void Test6_ExecuteCriticalGet() throws MusicServiceException, MusicQueryException {
- testObject = CassandraCQL.setPreparedGetQuery();
- boolean result = false;
- int count = 0;
- ResultSet output = null;
- output = dataStore.executeCriticalGet(testObject);
- System.out.println(output);
- ;
- for (Row row : output) {
- count++;
- System.out.println(row.toString());
- }
- if (count == 1) {
- result = true;
- }
- assertEquals(true, result);
- }
-
- @Test(expected = NullPointerException.class)
- public void Test7_exception() {
- PreparedQueryObject queryObject = null;
- try {
- dataStore.executePut(queryObject, "critical");
- } catch (MusicQueryException | MusicServiceException e) {
- System.out.println(e.getMessage());
- }
- }
-
- @Test
- public void Test8_columnDataType() {
- DataType data = dataStore.returnColumnDataType("testCassa", "employees", "empName");
- String datatype = data.toString();
- assertEquals("text",datatype);
- }
-
- @Test
- public void Test8_columnMetdaData() {
- TableMetadata data = dataStore.returnColumnMetadata("testCassa", "employees");
- assertNotNull(data);
- }
-}
diff --git a/src/test/java/org/onap/music/unittests/MusicUtilTest.java b/src/test/java/org/onap/music/unittests/MusicUtilTest.java
deleted file mode 100644
index b117c330..00000000
--- a/src/test/java/org/onap/music/unittests/MusicUtilTest.java
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * ============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.unittests;
-
-import static org.junit.Assert.*;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import org.apache.cassandra.exceptions.PreparedQueryNotFoundException;
-import org.junit.Test;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.main.MusicUtil;
-import com.datastax.driver.core.DataType;
-import javassist.CodeConverter.ArrayAccessReplacementMethodNames;
-
-public class MusicUtilTest {
-
- @Test
- public void testGetCassName() {
- MusicUtil.setCassName("Cassandra");
- assertTrue(MusicUtil.getCassName().equals("Cassandra"));
- }
-
- @Test
- public void testGetCassPwd() {
- MusicUtil.setCassPwd("Cassandra");
- assertTrue(MusicUtil.getCassPwd().equals("Cassandra"));
- }
-
- @Test
- public void testGetAafEndpointUrl() {
- MusicUtil.setAafEndpointUrl("url");
- assertEquals(MusicUtil.getAafEndpointUrl(),"url");
- }
-
- @Test
- public void testGetMyId() {
- MusicUtil.setMyId(1);
- assertEquals(MusicUtil.getMyId(),1);
- }
-
- @Test
- public void testGetAllIds() {
- List<String> ids = new ArrayList<String>();
- ids.add("1");
- ids.add("2");
- ids.add("3");
- MusicUtil.setAllIds(ids);
- assertEquals(MusicUtil.getAllIds().get(0),"1");
- }
-
-// @Test
-// public void testGetPublicIp() {
-// MusicUtil.setPublicIp("10.0.0.1");
-// assertEquals(MusicUtil.getPublicIp(),"10.0.0.1");
-// }
-
- @Test
- public void testGetAllPublicIps() {
- List<String> ips = new ArrayList<String>();
- ips.add("10.0.0.1");
- ips.add("10.0.0.2");
- ips.add("10.0.0.3");
- MusicUtil.setAllPublicIps(ips);
- assertEquals(MusicUtil.getAllPublicIps().get(1),"10.0.0.2");
- }
-
- @Test
- public void testGetPropkeys() {
- assertEquals(MusicUtil.getPropkeys()[2],"music.ip");
- }
-
- @Test
- public void testGetMusicRestIp() {
- MusicUtil.setMusicRestIp("localhost");
- assertEquals(MusicUtil.getMusicRestIp(),"localhost");
- }
-
- @Test
- public void testGetMusicPropertiesFilePath() {
- MusicUtil.setMusicPropertiesFilePath("filepath");
- assertEquals(MusicUtil.getMusicPropertiesFilePath(),"filepath");
- }
-
- @Test
- public void testGetDefaultLockLeasePeriod() {
- MusicUtil.setDefaultLockLeasePeriod(5000);
- assertEquals(MusicUtil.getDefaultLockLeasePeriod(),5000);
- }
-
- @Test
- public void testIsDebug() {
- MusicUtil.setDebug(true);
- assertTrue(MusicUtil.isDebug());
- }
-
- @Test
- public void testGetVersion() {
- MusicUtil.setVersion("1.0.0");
- assertEquals(MusicUtil.getVersion(),"1.0.0");
- }
-
- /*@Test
- public void testGetMyZkHost() {
- MusicUtil.setMyZkHost("10.0.0.2");
- assertEquals(MusicUtil.getMyZkHost(),"10.0.0.2");
- }*/
-
- @Test
- public void testGetMyCassaHost() {
- MusicUtil.setMyCassaHost("10.0.0.2");
- assertEquals(MusicUtil.getMyCassaHost(),"10.0.0.2");
- }
-
- @Test
- public void testGetDefaultMusicIp() {
- MusicUtil.setDefaultMusicIp("10.0.0.2");
- assertEquals(MusicUtil.getDefaultMusicIp(),"10.0.0.2");
- }
-
-// @Test
-// public void testGetTestType() {
-// fail("Not yet implemented"); // TODO
-// }
-
- @Test
- public void testIsValidQueryObject() {
- PreparedQueryObject myQueryObject = new PreparedQueryObject();
- myQueryObject.appendQueryString("select * from apple where type = ?");
- myQueryObject.addValue("macintosh");
- assertTrue(MusicUtil.isValidQueryObject(true,myQueryObject));
-
- myQueryObject.appendQueryString("select * from apple");
- assertTrue(MusicUtil.isValidQueryObject(false,myQueryObject));
-
- myQueryObject.appendQueryString("select * from apple where type = ?");
- assertFalse(MusicUtil.isValidQueryObject(true,myQueryObject));
-
- myQueryObject = new PreparedQueryObject();
- myQueryObject.appendQueryString("");
- System.out.println("#######" + myQueryObject.getQuery().isEmpty());
- assertFalse(MusicUtil.isValidQueryObject(false,myQueryObject));
-
-
- }
-
- @Test
- public void testConvertToCQLDataType() throws Exception {
- Map<String,Object> myMap = new HashMap<String,Object>();
- myMap.put("name","tom");
- assertEquals(MusicUtil.convertToCQLDataType(DataType.varchar(),"Happy People"),"'Happy People'");
- assertEquals(MusicUtil.convertToCQLDataType(DataType.uuid(),UUID.fromString("29dc2afa-c2c0-47ae-afae-e72a645308ab")),"29dc2afa-c2c0-47ae-afae-e72a645308ab");
- assertEquals(MusicUtil.convertToCQLDataType(DataType.blob(),"Hi"),"Hi");
- assertEquals(MusicUtil.convertToCQLDataType(DataType.map(DataType.varchar(),DataType.varchar()),myMap),"{'name':'tom'}");
- }
-
- @Test
- public void testConvertToActualDataType() throws Exception {
- assertEquals(MusicUtil.convertToActualDataType(DataType.varchar(),"Happy People"),"Happy People");
- assertEquals(MusicUtil.convertToActualDataType(DataType.uuid(),"29dc2afa-c2c0-47ae-afae-e72a645308ab"),UUID.fromString("29dc2afa-c2c0-47ae-afae-e72a645308ab"));
- assertEquals(MusicUtil.convertToActualDataType(DataType.varint(),"1234"),BigInteger.valueOf(Long.parseLong("1234")));
- assertEquals(MusicUtil.convertToActualDataType(DataType.bigint(),"123"),Long.parseLong("123"));
- assertEquals(MusicUtil.convertToActualDataType(DataType.cint(),"123"),Integer.parseInt("123"));
- assertEquals(MusicUtil.convertToActualDataType(DataType.cfloat(),"123.01"),Float.parseFloat("123.01"));
- assertEquals(MusicUtil.convertToActualDataType(DataType.cdouble(),"123.02"),Double.parseDouble("123.02"));
- assertEquals(MusicUtil.convertToActualDataType(DataType.cboolean(),"true"),Boolean.parseBoolean("true"));
- Map<String,Object> myMap = new HashMap<String,Object>();
- myMap.put("name","tom");
- assertEquals(MusicUtil.convertToActualDataType(DataType.map(DataType.varchar(),DataType.varchar()),myMap),myMap);
-
- }
-
- @Test
- public void testJsonMaptoSqlString() throws Exception {
- Map<String,Object> myMap = new HashMap<>();
- myMap.put("name","tom");
- myMap.put("value",5);
- String result = MusicUtil.jsonMaptoSqlString(myMap,",");
- assertTrue(result.contains("name"));
- assertTrue(result.contains("value"));
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/ResultTypeTest.java b/src/test/java/org/onap/music/unittests/ResultTypeTest.java
deleted file mode 100644
index 012629e0..00000000
--- a/src/test/java/org/onap/music/unittests/ResultTypeTest.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * ============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.unittests;
-
-import static org.junit.Assert.*;
-import org.junit.Test;
-import org.onap.music.main.ResultType;
-
-public class ResultTypeTest {
-
- @Test
- public void testResultType() {
- assertEquals("SUCCESS",ResultType.SUCCESS.name());
- assertEquals("FAILURE",ResultType.FAILURE.name());
- }
-
- @Test
- public void testGetResult() {
- assertEquals("Success",ResultType.SUCCESS.getResult());
- assertEquals("Failure",ResultType.FAILURE.getResult());
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/ReturnTypeTest.java b/src/test/java/org/onap/music/unittests/ReturnTypeTest.java
deleted file mode 100644
index c22b0155..00000000
--- a/src/test/java/org/onap/music/unittests/ReturnTypeTest.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * ============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.unittests;
-
-import static org.junit.Assert.*;
-import java.util.Map;
-import org.apache.tools.ant.filters.TokenFilter.ContainsString;
-import org.hamcrest.core.AnyOf;
-import org.junit.Test;
-import org.onap.music.main.ResultType;
-import org.onap.music.main.ReturnType;
-
-public class ReturnTypeTest {
-
- @Test
- public void testReturnType() {
- ReturnType result = new ReturnType(ResultType.SUCCESS,"message");
- assertEquals(result.getMessage(),"message");
- assertEquals(result.getResult(),ResultType.SUCCESS);
- }
-
- @Test
- public void testTimingInfo() {
- ReturnType result = new ReturnType(ResultType.SUCCESS,"message");
- result.setTimingInfo("123");
- assertEquals(result.getTimingInfo(),"123");
- }
-
- @Test
- public void testGetResult() {
- ReturnType result = new ReturnType(ResultType.FAILURE,"message");
- assertEquals(result.getResult(),ResultType.FAILURE);
- }
-
- @Test
- public void testGetMessage() {
- ReturnType result = new ReturnType(ResultType.SUCCESS,"message");
- result.setMessage("NewMessage");
- assertEquals(result.getMessage(),"NewMessage");
- }
-
- @Test
- public void testToJson() {
- ReturnType result = new ReturnType(ResultType.SUCCESS,"message");
- String myJson = result.toJson();
- assertTrue(myJson.contains("message"));
- }
-
- @Test
- public void testToString() {
- ReturnType result = new ReturnType(ResultType.SUCCESS,"message");
- String test = result.toString();
- assertTrue(test.contains("message"));
- }
-
- @Test
- public void testToMap() {
- ReturnType result = new ReturnType(ResultType.SUCCESS,"message");
- Map<String, Object> myMap = result.toMap();
- assertTrue(myMap.containsKey("message"));
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/TestLockStore.java b/src/test/java/org/onap/music/unittests/TestLockStore.java
deleted file mode 100644
index 4dbc7b4f..00000000
--- a/src/test/java/org/onap/music/unittests/TestLockStore.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * ============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.unittests;
-
-import org.apache.log4j.Logger;
-import org.onap.music.lockingservice.MusicLockingService;
-
-public class TestLockStore {
- final static Logger logger = Logger.getLogger(TestLockStore.class);
-
- public static void main(String[] args) throws Exception {
- String lockName = "/achristmkllas";
- MusicLockingService ml = new MusicLockingService();
- ml.deleteLock(lockName);
-
-
- logger.info("lockname:" + lockName);
-
- String lockId1 = ml.createLockId(lockName);
- logger.info("lockId1 " + lockId1);
- logger.info(ml.isMyTurn(lockId1));
-
- String lockId2 = ml.createLockId(lockName);
- logger.info("lockId2 " + lockId2);
- logger.info("check " + ml.isMyTurn("$bank$x-94608776321630264-0000000000"));
- logger.info(ml.isMyTurn(lockId2));
-
- // zkClient.unlock(lockId1);
- // logger.info(ml.lock(lockId2));
- // zkClient.unlock(lockId2);
- }
-
-
-}
diff --git a/src/test/java/org/onap/music/unittests/TestMusicCore.java b/src/test/java/org/onap/music/unittests/TestMusicCore.java
deleted file mode 100644
index ed9c2f68..00000000
--- a/src/test/java/org/onap/music/unittests/TestMusicCore.java
+++ /dev/null
@@ -1,678 +0,0 @@
-/*
- * ============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.unittests;
-
-import static org.junit.Assert.*;
-import static org.onap.music.main.MusicCore.mDstoreHandle;
-import static org.onap.music.main.MusicCore.mLockHandle;
-import java.util.HashMap;
-import java.util.Map;
-import org.apache.zookeeper.KeeperException.NoNodeException;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.onap.music.exceptions.MusicLockingException;
-import org.onap.music.exceptions.MusicQueryException;
-import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.lockingservice.MusicLockState;
-import org.onap.music.lockingservice.MusicLockingService;
-import org.onap.music.lockingservice.MusicLockState.LockStatus;
-import org.onap.music.main.MusicCore;
-import org.onap.music.main.MusicUtil;
-import org.onap.music.main.ResultType;
-import org.onap.music.main.ReturnType;
-import org.onap.music.main.MusicCore.Condition;
-import org.onap.music.datastore.MusicDataStore;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.eelf.logging.format.AppMessages;
-import org.onap.music.eelf.logging.format.ErrorSeverity;
-import org.onap.music.eelf.logging.format.ErrorTypes;
-import com.att.eelf.exception.EELFException;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Session;
-
-@RunWith(MockitoJUnitRunner.class)
-public class TestMusicCore {
-
- @Mock
- private Condition condition;
-
- @Mock
- private ResultSet rs;
-
- @Mock
- private PreparedQueryObject preparedQueryObject;
-
- @Mock
- private Session session;
-
- @Before
- public void setUp() {
- mLockHandle = Mockito.mock(MusicLockingService.class);
-
- }
-
- @Test
- public void testCreateLockReferenceforvalidlock() {
- Mockito.when(mLockHandle.createLockId("/" + "test")).thenReturn("lock");
- String lockId = MusicCore.createLockReference("test");
- assertEquals("lock", lockId);
- Mockito.verify(mLockHandle).createLockId("/" + "test");
- }
-
-
- @Test
- public void testCreateLockReferencefornullname() {
- Mockito.when(mLockHandle.createLockId("/" + "test")).thenReturn("lock");
- String lockId = MusicCore.createLockReference("x"); //test");
- //System.out.println("cjc exception lockhandle=" + mLockHandle+"lockid="+lockId );
- assertNotEquals("lock", lockId);
- //Mockito.verify(mLockHandle).createLockId("/" + "test");
- }
-
- @Test
- public void testIsTableOrKeySpaceLock() {
- Boolean result = MusicCore.isTableOrKeySpaceLock("ks1.tn1");
- assertTrue(result);
- }
-
- @Test
- public void testIsTableOrKeySpaceLockwithPrimarykey() {
- Boolean result = MusicCore.isTableOrKeySpaceLock("ks1.tn1.pk1");
- assertFalse(result);
- }
-
- @Test
- public void testGetMusicLockState() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
- Mockito.when(mLockHandle.getLockState("ks1.tb1.pk1")).thenReturn(musicLockState);
- MusicLockState mls = MusicCore.getMusicLockState("ks1.tb1.pk1");
- assertEquals(musicLockState, mls);
- Mockito.verify(mLockHandle).getLockState("ks1.tb1.pk1");
- }
-
- @Test
- public void testAcquireLockifisMyTurnTrue() throws MusicLockingException {
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- ReturnType lock = MusicCore.acquireLock("ks1.tn1", "id1");
- assertEquals(lock.getResult(), ResultType.SUCCESS);
- Mockito.verify(mLockHandle).isMyTurn("id1");
- }
-
- @Test
- public void testAcquireLockifisMyTurnFalse() throws MusicLockingException {
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
- ReturnType lock = MusicCore.acquireLock("ks1.ts1", "id1");
- assertEquals(lock.getResult(), ResultType.FAILURE);
- Mockito.verify(mLockHandle).isMyTurn("id1");
- }
-
- @Test
- public void testAcquireLockifisMyTurnTrueandIsTableOrKeySpaceLockTrue() throws MusicLockingException {
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- ReturnType lock = MusicCore.acquireLock("ks1.tn1", "id1");
- assertEquals(lock.getResult(), ResultType.SUCCESS);
- Mockito.verify(mLockHandle).isMyTurn("id1");
- }
-
- @Test
- public void testAcquireLockifisMyTurnTrueandIsTableOrKeySpaceLockFalseandHaveLock() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- ReturnType lock = MusicCore.acquireLock("ks1.tn1.pk1", "id1");
- assertEquals(lock.getResult(), ResultType.SUCCESS);
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle).getLockState("ks1.tn1.pk1");
- }
-
- @Test
- public void testAcquireLockifisMyTurnTrueandIsTableOrKeySpaceLockFalseandDontHaveLock() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id2");
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- ReturnType lock = MusicCore.acquireLock("ks1.tn1.pk1", "id1");
- assertEquals(lock.getResult(), ResultType.SUCCESS);
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle).getLockState("ks1.tn1.pk1");
- }
-
- @Test
- public void testAcquireLockifLockRefDoesntExist() throws MusicLockingException {
- Mockito.when(mLockHandle.lockIdExists("bs1")).thenReturn(false);
- ReturnType lock = MusicCore.acquireLock("ks1.ts1", "bs1");
- assertEquals(lock.getResult(), ResultType.FAILURE);
- assertEquals(lock.getMessage(), "Lockid doesn't exist");
- Mockito.verify(mLockHandle).lockIdExists("bs1");
- }
-
- @Test
- public void testAcquireLockWithLeasewithLease() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
- musicLockState.setLeasePeriod(0);
- ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
- }
-
- @Test
- public void testAcquireLockWithLeasewithException() throws MusicLockingException {
- ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "failure");
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenThrow(new MusicLockingException());
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
- }
-
- @Test
- public void testAcquireLockWithLeasewithLockStatusLOCKED() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
- ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
- }
-
- @Test
- public void testAcquireLockWithLeasewithLockStatusUNLOCKED() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
- ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
-
- }
-
- @Test
- public void testAcquireLockWithLeaseIfNotMyTurn() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
- ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
- ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle).getLockState("ks1.tn1.pk1");
- }
-
- @Test
- public void testQuorumGet() throws MusicServiceException, MusicQueryException {
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- rs = Mockito.mock(ResultSet.class);
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs);
- ResultSet rs1 = MusicCore.quorumGet(preparedQueryObject);
- assertNotNull(rs1);
- }
-
- @Test
- public void testGetLockNameFromId() {
- String lockname = MusicCore.getLockNameFromId("lockName$id");
- assertEquals("lockName", lockname);
- }
-
- @Test
- public void testDestroyLockRef() throws NoNodeException {
- Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1");
- MusicCore.destroyLockRef("id1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1");
- }
-
- @Test
- public void testreleaseLockwithvoluntaryReleaseTrue() throws NoNodeException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
- Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1");
- MusicLockState musicLockState1 = MusicCore.releaseLock("id1", true);
- assertEquals(musicLockState.getLockStatus(), musicLockState1.getLockStatus());
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1");
- }
-
- @Test
- public void testreleaseLockwithvoluntaryReleaseFalse() throws NoNodeException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
- Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1");
- MusicLockState musicLockState1 = MusicCore.releaseLock("id1", false);
- assertEquals(musicLockState.getLockStatus(), musicLockState1.getLockStatus());
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1");
- }
-
- @Test
- public void testDeleteLock() throws MusicLockingException {
- Mockito.doNothing().when(mLockHandle).deleteLock("/" + "id1");
- MusicCore.deleteLock("id1");
- Mockito.verify(mLockHandle).deleteLock("/" + "id1");
- }
-
- /*
- * @Test public void testNonKeyRelatedPut() throws Exception { mDstoreHandle =
- * Mockito.mock(MusicDataStore.class); Mockito.when(mDstoreHandle.executePut("qu1",
- * "consistency")).thenReturn(true); Boolean result = MusicCore.nonKeyRelatedPut("qu1",
- * "consistency"); assertTrue(result); Mockito.verify(mDstoreHandle).executePut("qu1",
- * "consistency"); }
- */
-
- @Test
- public void testEventualPutPreparedQuery() throws MusicServiceException, MusicQueryException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "eventual")).thenReturn(true);
- ReturnType actualResult = MusicCore.eventualPut(preparedQueryObject);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "eventual");
- }
-
- @Test
- public void testEventualPutPreparedQuerywithResultFalse()
- throws MusicServiceException, MusicQueryException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "eventual")).thenReturn(false);
- ReturnType actualResult = MusicCore.eventualPut(preparedQueryObject);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "eventual");
- //Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, MusicUtil.EVENTUAL);
- }
-
- @Test
- public void testCriticalPutPreparedQuerywithValidLockId()
- throws Exception {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
- Mockito.when(condition.testCondition()).thenReturn(true);
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "critical")).thenReturn(true);
- ReturnType returnType = MusicCore.criticalPut("ks1", "tn1", "pk1", preparedQueryObject,
- "id1", condition);
- assertEquals(expectedResult.getResult(), returnType.getResult());
- Mockito.verify(condition).testCondition();
- Mockito.verify(mLockHandle).getLockState("ks1" + "." + "tn1" + "." + "pk1");
- Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "critical");
- }
-
- @Test
- public void testCriticalPutPreparedQuerywithInvalidLockId() throws MusicLockingException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
- ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- ReturnType returnType = MusicCore.criticalPut("ks1", "tn1", "pk1", preparedQueryObject,
- "id1", condition);
- assertEquals(expectedResult.getResult(), returnType.getResult());
- Mockito.verify(mLockHandle).getLockState("ks1" + "." + "tn1" + "." + "pk1");
- }
-
- @Test
- public void testCriticalPutPreparedQuerywithvalidLockIdandTestConditionFalse() throws Exception {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
- Mockito.when(condition.testCondition()).thenReturn(false);
- ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- ReturnType returnType = MusicCore.criticalPut("ks1", "tn1", "pk1", preparedQueryObject,
- "id1", condition);
- assertEquals(expectedResult.getResult(), returnType.getResult());
- Mockito.verify(condition).testCondition();
- Mockito.verify(mLockHandle).getLockState("ks1" + "." + "tn1" + "." + "pk1");
- }
-
- @Test
- public void testNonKeyRelatedPutPreparedQuery() throws Exception {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "consistency")).thenReturn(true);
- ResultType result = MusicCore.nonKeyRelatedPut(preparedQueryObject, "consistency");
- assertEquals(ResultType.SUCCESS, result);
- Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "consistency");
- }
-
- @Test
- public void testAtomicPutPreparedQuery() throws Exception {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
- ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- Mockito.when(condition.testCondition()).thenReturn(true);
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "critical")).thenReturn(true);
- ReturnType returnType =
- MusicCore.atomicPut("ks1", "tn1", "pk1", preparedQueryObject, condition);
- assertEquals(expectedResult.getResult(), returnType.getResult());
- Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(condition).testCondition();
- Mockito.verify(mLockHandle, Mockito.atLeastOnce())
- .getLockState("ks1" + "." + "tn1" + "." + "pk1");
- Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "critical");
- }
-
- @Test
- public void testAtomicPutPreparedQuerywithAcquireLockWithLeaseFalse() throws MusicLockingException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
- ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
- ReturnType returnType =
- MusicCore.atomicPut("ks1", "tn1", "pk1", preparedQueryObject, condition);
- assertEquals(expectedResult.getResult(), returnType.getResult());
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
- }
-
- @Test
- public void testAtomicGetPreparedQuery() throws MusicServiceException, MusicQueryException, MusicLockingException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- rs = Mockito.mock(ResultSet.class);
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs);
- ResultSet rs1 = MusicCore.atomicGet("ks1", "tn1", "pk1", preparedQueryObject);
- assertNotNull(rs1);
- Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce())
- .getLockState("ks1" + "." + "tn1" + "." + "pk1");
- Mockito.verify(mDstoreHandle).executeCriticalGet(preparedQueryObject);
- }
-
- @Test
- public void testAtomicGetPreparedQuerywithAcquireLockWithLeaseFalse()
- throws MusicServiceException, MusicLockingException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- rs = Mockito.mock(ResultSet.class);
- Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
- ResultSet rs1 = MusicCore.atomicGet("ks1", "tn1", "pk1", preparedQueryObject);
- assertNull(rs1);
- Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
- Mockito.verify(mLockHandle).isMyTurn("id1");
- }
-
- @Test
- public void testGetPreparedQuery() throws MusicServiceException, MusicQueryException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- rs = Mockito.mock(ResultSet.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mDstoreHandle.executeEventualGet(preparedQueryObject)).thenReturn(rs);
- ResultSet rs1 = MusicCore.get(preparedQueryObject);
- assertNotNull(rs1);
- Mockito.verify(mDstoreHandle).executeEventualGet(preparedQueryObject);
-
- }
-
- @Test
- public void testcriticalGetPreparedQuery() throws MusicServiceException, MusicQueryException, MusicLockingException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
- rs = Mockito.mock(ResultSet.class);
- session = Mockito.mock(Session.class);
- Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs);
- ResultSet rs1 = MusicCore.criticalGet("ks1", "tn1", "pk1", preparedQueryObject, "id1");
- assertNotNull(rs1);
- Mockito.verify(mLockHandle, Mockito.atLeastOnce())
- .getLockState("ks1" + "." + "tn1" + "." + "pk1");
- Mockito.verify(mDstoreHandle).executeCriticalGet(preparedQueryObject);
- }
-
- @Test
- public void testcriticalGetPreparedQuerywithInvalidLockId() throws MusicServiceException, MusicLockingException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- ResultSet rs1 = MusicCore.criticalGet("ks1", "tn1", "pk1", preparedQueryObject, "id1");
- assertNull(rs1);
- Mockito.verify(mLockHandle, Mockito.atLeastOnce())
- .getLockState("ks1" + "." + "tn1" + "." + "pk1");
- }
-
- @Test
- public void testAtomicGetPreparedQuerywithDeleteLockWithLeaseFalse()
- throws MusicServiceException, MusicLockingException {
- mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- rs = Mockito.mock(ResultSet.class);
- Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
- ResultSet rs1 = MusicCore.atomicGet("ks1", "tn1", "pk1", preparedQueryObject);
- assertNull(rs1);
- Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
- Mockito.verify(mLockHandle).isMyTurn("id1");
- }
-
- @Test
- public void testCondition() throws Exception {
- //Condition conClass = Mockito.mock(Condition.class);
- // boolean ret=true;
- //Mockito.when(conClass.testCondition().thenReturn(ret);
- Map<String, Object> conditionsx=null;
- PreparedQueryObject selectQueryForTheRowx=null;
- try {
- Condition con = new Condition(conditionsx,selectQueryForTheRowx);
- assertTrue(con.testCondition());
- } catch (Exception e) {
- assertFalse(false);
- }
- }
- //getLockingServiceHandl
-
- @Ignore
- @Test(expected = MusicLockingException.class) //("Failed to aquire Locl store handle " + e))
- public void testgetLockingServiceHandle() throws Exception {
- // MusicLockingService mLockHandlex = Mockito.mock(MusicLockingService.class);
- //MusicLockingService mLockHandlea = mLockHandle;
- //mLockHandle=null;
- System.out.println("cjc 0 locking test n");
- // Mockito.when(MusicCore.getLockingServiceHandle()).thenReturn(mLockHandle);
- //mLockHandle=null;
- //System.out.println("cjc 0-1 locking test n");
- MusicLockingService mLockHandlea = mLockHandle;
- mLockHandle=null;
-
- MusicLockingService mLockHandley=null; //MusicCore.getLockingServiceHandle();
- Mockito.when(MusicCore.getLockingServiceHandle()).thenReturn(mLockHandley);
- System.out.println("cjc locking test n");
- mLockHandle=mLockHandlea;
- assertTrue(true);
-
- }
-
- @Test(expected = MusicServiceException.class)
- public void testGetDSHandle() throws MusicServiceException, MusicQueryException {
- // rs = Mockito.mock(ResultSet.class);
- // session = Mockito.mock(Session.class);
- //Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- //Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs);
-
- MusicDataStore mDstoreHandlea = Mockito.mock(MusicDataStore.class);
- //MusicUtil mMusicUtil=Mockito.mock(MusicUtil.class);
- //System.out.println("cjc 0 getDsHandle");
- Mockito.when(MusicCore.getDSHandle()).thenReturn(mDstoreHandlea);
- // System.out.println("cjc localhost");
- // Mockito.when(mMusicUtil.getMyCassaHost().equals("localhost")).thenReturn(null);
- //System.out.println("cjc 1 localhost");
- // mDstoreHandle = new MusicDataStore(MusicUtil.getMyCassaHost());
- // } else {
- // mDstoreHandle = new MusicDataStore();
- // }
- assertTrue(true);
- }
-
- //add mocking
- @Ignore
- @Test
- public void testGetDSHandleIp() throws MusicServiceException, MusicQueryException {
- // rs = Mockito.mock(ResultSet.class);
- // session = Mockito.mock(Session.class);
- //Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
- //Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs);
-
- //mDstoreHandle = Mockito.mock(MusicDataStore.class);
- //MusicUtil mMusicUtil=Mockito.mock(MusicUtil.class);
- System.out.println("cjc 0 getDsHandleIP");
- Mockito.when(MusicCore.getDSHandle("1.127.0.1")).thenReturn(mDstoreHandle);
- System.out.println("cjc localhost");
- // Mockito.when(mMusicUtil.getMyCassaHost().equals("localhost")).thenReturn(null);
- System.out.println("cjc 1 localhost IP");
- // mDstoreHandle = new MusicDataStore(MusicUtil.getMyCassaHost());
- // } else {
- // mDstoreHandle = new MusicDataStore();
- // }
- assertTrue(true);
- }
-
- @Ignore
- @Test
- public void testPureZkCreate() {
- try {
- MusicCore.pureZkCreate("local");
- } catch(NullPointerException e) {
- System.out.println("cjc zkcreate null pointwer exception:"+ e);
- }
- }
-
- @Ignore
- @Test
- public void testPureZkRead() { //String nodeName) {
- byte[] data = MusicCore.pureZkRead("localhost");
- }
-
- //need fixing
- @Ignore
- @Test
- public void testPureZkWrite() { //String nodeName, byte[] data) {
- /*
- long start = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Performing zookeeper write to " + nodeName);
- try {
- getLockingServiceHandle().getzkLockHandle().setNodeData(nodeName, data);
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), "[ERR512E] Failed to get ZK Lock Handle " ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
- logger.info(EELFLoggerDelegate.applicationLogger,"Performed zookeeper write to " + nodeName);
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Time taken for the actual zk put:" + (end - start) + " ms");
- */
-
- // mDstoreHandle = Mockito.mock(MusicDataStore.class);
- // rs = Mockito.mock(ResultSet.class);
- // session = Mockito.mock(Session.class);
- //Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
-
- byte[] data= "Testing Zoo Keeper".getBytes();
- MusicCore.pureZkWrite("1.127.0.1", data);
- // assertNotNull(rs1);
- }
-
- @Test
- public void testWhoseTurnIsIt() { //(String lockName) {
-
- /*
- try {
- return getLockingServiceHandle().whoseTurnIsIt("/" + lockName) + "";
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.LOCKINGERROR+lockName ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
- return null;
- */
-
- String lockName="xxx";
- if (MusicCore.whoseTurnIsIt(lockName) != null) assertTrue(true);
-
-
-
- }
-
- @Test
- public void testMarshallResults() {
- Map<String, HashMap<String, Object>> ret=null;
- //ResultSet results =null;
- rs = Mockito.mock(ResultSet.class);
- try {
- ret= MusicCore.marshallResults(rs);
-
- } catch( Exception e ) {
-
- }
-
- if (ret != null) assertTrue(true);
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java b/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java
deleted file mode 100644
index d327d0f0..00000000
--- a/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * ============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.unittests;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import java.io.File;
-import java.util.List;
-import org.apache.curator.test.TestingServer;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.exceptions.MusicQueryException;
-import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.lockingservice.MusicLockState;
-import org.onap.music.lockingservice.MusicLockingService;
-import org.onap.music.lockingservice.MusicLockState.LockStatus;
-import org.onap.music.main.MusicCore;
-import org.onap.music.main.MusicUtil;
-import org.onap.music.main.ResultType;
-import org.onap.music.main.ReturnType;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
-
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class TestMusicCoreIntegration {
-
- static TestingServer zkServer;
- static PreparedQueryObject testObject;
- static String lockId = null;
- static String lockName = "ks1.tb1.pk1";
-
- @BeforeClass
- public static void init() throws Exception {
- try {
- MusicCore.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra();
- zkServer = new TestingServer(2181, new File("/tmp/zk"));
- MusicCore.mLockHandle = new MusicLockingService();
- } catch (Exception e) {
- e.printStackTrace();
- }
- System.out.println("####Port:" + zkServer.getPort());
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- System.out.println("After class");
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.dropKeyspace);
- MusicCore.eventualPut(testObject);
- MusicCore.deleteLock(lockName);
- MusicCore.mDstoreHandle.close();
- MusicCore.mLockHandle.getzkLockHandle().close();
- MusicCore.mLockHandle.close();
- zkServer.stop();
-
- }
-
- @Test
- public void Test1_SetUp() throws MusicServiceException, MusicQueryException {
- MusicCore.mLockHandle = new MusicLockingService();
- ResultType result = ResultType.FAILURE;
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.createKeySpace);
- MusicCore.eventualPut(testObject);
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.createTableEmployees);
- result = MusicCore.nonKeyRelatedPut(testObject, MusicUtil.EVENTUAL);
- assertEquals(ResultType.SUCCESS, result);
- }
-
- @Test
- public void Test2_atomicPut() throws Exception {
- testObject = new PreparedQueryObject();
- testObject = CassandraCQL.setPreparedInsertQueryObject1();
- ReturnType returnType = MusicCore.atomicPut("testCassa", "employees", "Mr Test one",
- testObject, null);
- assertEquals(ResultType.SUCCESS, returnType.getResult());
- }
-
- @Test
- public void Test3_atomicPutWithDeleteLock() throws Exception {
- testObject = new PreparedQueryObject();
- testObject = CassandraCQL.setPreparedInsertQueryObject2();
- ReturnType returnType = MusicCore.atomicPutWithDeleteLock("testCassa", "employees",
- "Mr Test two", testObject, null);
- assertEquals(ResultType.SUCCESS, returnType.getResult());
- }
-
- @Test
- public void Test4_atomicGetWithDeleteLock() throws Exception {
- testObject = new PreparedQueryObject();
- testObject = CassandraCQL.setPreparedGetQuery();
- ResultSet resultSet = MusicCore.atomicGetWithDeleteLock("testCassa", "employees",
- "Mr Test one", testObject);
- List<Row> rows = resultSet.all();
- assertEquals(1, rows.size());
- }
-
- @Test
- public void Test5_atomicGet() throws Exception {
- testObject = new PreparedQueryObject();
- testObject = CassandraCQL.setPreparedGetQuery();
- ResultSet resultSet =
- MusicCore.atomicGet("testCassa", "employees", "Mr Test two", testObject);
- List<Row> rows = resultSet.all();
- assertEquals(1, rows.size());
- }
-
- @Test
- public void Test6_createLockReference() throws Exception {
- lockId = MusicCore.createLockReference(lockName);
- assertNotNull(lockId);
- }
-
- @Test
- public void Test7_acquireLockwithLease() throws Exception {
- ReturnType lockLeaseStatus = MusicCore.acquireLockWithLease(lockName, lockId, 1000);
- assertEquals(ResultType.SUCCESS, lockLeaseStatus.getResult());
- }
-
- @Test
- public void Test8_acquireLock() throws Exception {
- ReturnType lockStatus = MusicCore.acquireLock(lockName, lockId);
- assertEquals(ResultType.SUCCESS, lockStatus.getResult());
- }
-
- @Test
- public void Test9_release() throws Exception {
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
- MusicLockState musicLockState1 = new MusicLockState(LockStatus.UNLOCKED, "id1");
- MusicCore.whoseTurnIsIt(lockName);
- MusicLockState mls = MusicCore.getMusicLockState(lockName);
- boolean voluntaryRelease = true;
- MusicLockState mls1 = MusicCore.releaseLock(lockId, voluntaryRelease);
- assertEquals(musicLockState.getLockStatus(), mls.getLockStatus());
- assertEquals(musicLockState1.getLockStatus(), mls1.getLockStatus());
- }
-
- @Test
- public void Test10_create() {
- MusicCore.pureZkCreate("/nodeName");
- }
-
- @Test
- public void Test11_write() {
- MusicCore.pureZkWrite("nodeName", "I'm Test".getBytes());
- }
-
- @Test
- public void Test12_read() {
- byte[] data = MusicCore.pureZkRead("nodeName");
- String data1 = new String(data);
- assertEquals("I'm Test", data1);
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/TestRestAdminData.java b/src/test/java/org/onap/music/unittests/TestRestAdminData.java
deleted file mode 100644
index 892a20f6..00000000
--- a/src/test/java/org/onap/music/unittests/TestRestAdminData.java
+++ /dev/null
@@ -1,2244 +0,0 @@
-/*
- * ============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.unittests;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.onap.music.main.MusicCore.mLockHandle;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import javax.servlet.http.HttpServletResponse;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-import org.apache.curator.test.TestingServer;
-import org.apache.http.impl.client.AutoRetryHttpClient;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.MethodSorters;
-import org.mindrot.jbcrypt.BCrypt;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.onap.music.conductor.conditionals.JsonConditional;
-import org.onap.music.conductor.conditionals.MusicConditional;
-import org.onap.music.conductor.conditionals.RestMusicConditionalAPI;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.datastore.jsonobjects.JsonDelete;
-import org.onap.music.datastore.jsonobjects.JsonInsert;
-import org.onap.music.datastore.jsonobjects.JsonKeySpace;
-import org.onap.music.datastore.jsonobjects.JsonOnboard;
-import org.onap.music.datastore.jsonobjects.JsonSelect;
-import org.onap.music.datastore.jsonobjects.JsonTable;
-import org.onap.music.datastore.jsonobjects.JsonUpdate;
-import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.lockingservice.MusicLockState;
-import org.onap.music.lockingservice.MusicLockingService;
-import org.onap.music.lockingservice.MusicLockState.LockStatus;
-import org.onap.music.main.CachingUtil;
-import org.onap.music.main.MusicCore;
-import org.onap.music.main.MusicUtil;
-import org.onap.music.main.ResultType;
-import org.onap.music.main.ReturnType;
-import org.onap.music.rest.RestMusicAdminAPI;
-import org.onap.music.rest.RestMusicBmAPI;
-import org.onap.music.rest.RestMusicDataAPI;
-import org.onap.music.rest.RestMusicHealthCheckAPI;
-import org.onap.music.rest.RestMusicLocksAPI;
-import org.onap.music.rest.RestMusicTestAPI;
-import org.onap.music.rest.RestMusicVersionAPI;
-
-import com.datastax.driver.core.ConsistencyLevel;
-import com.datastax.driver.core.DataType;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
-import com.sun.jersey.core.util.Base64;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
-
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-@RunWith(MockitoJUnitRunner.class)
-public class TestRestAdminData {
-
- RestMusicDataAPI data = new RestMusicDataAPI();
- RestMusicAdminAPI admin = new RestMusicAdminAPI();
- RestMusicLocksAPI lock = new RestMusicLocksAPI();
- static PreparedQueryObject testObject;
- static TestingServer zkServer;
-
- @Mock
- HttpServletResponse http;
-
- @Mock
- UriInfo info;
-
- //* cjc out
- @Mock
- CachingUtil cachUtilMock;
-
- @InjectMocks
- private MusicCore mCore;
- //*/
-
- static String appName = "TestApp";
- static String userId = "TestUser";
- static String password = "TestPassword";
- static String authData = userId+":"+password;
- static String wrongAuthData = userId+":"+"pass";
- static String authorization = new String(Base64.encode(authData.getBytes()));
- static String wrongAuthorization = new String(Base64.encode(wrongAuthData.getBytes()));
- static boolean isAAF = false;
- static UUID uuid = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40ce6");
- static String keyspaceName = "testCassa";
- static String tableName = "employees";
- static String tableNameConditional = "Conductor";
- static String xLatestVersion = "X-latestVersion";
- static String onboardUUID = null;
- static String lockId = null;
- static String lockName = "testCassa.employees.sample3";
-
- @BeforeClass
- public static void init() throws Exception {
- try {
- MusicCore.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra();
- zkServer = new TestingServer(2181, new File("/tmp/zk"));
- MusicCore.mLockHandle = new MusicLockingService();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- testObject = new PreparedQueryObject();
- testObject.appendQueryString("DROP KEYSPACE IF EXISTS " + keyspaceName);
- MusicCore.eventualPut(testObject);
- testObject = new PreparedQueryObject();
- testObject.appendQueryString("DROP KEYSPACE IF EXISTS admin");
- MusicCore.eventualPut(testObject);
- MusicCore.mDstoreHandle.close();
- MusicCore.mLockHandle.getzkLockHandle().close();
- MusicCore.mLockHandle.close();
- zkServer.stop();
- }
-
- @Test
- public void Test1_createKeyspace() throws Exception {
- testObject = new PreparedQueryObject();
- testObject.appendQueryString("CREATE KEYSPACE admin WITH REPLICATION = "
- + "{'class' : 'SimpleStrategy' , "
- + "'replication_factor': 1} AND DURABLE_WRITES = true");
- MusicCore.eventualPut(testObject);
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "CREATE TABLE admin.keyspace_master (" + " uuid uuid, keyspace_name text,"
- + " application_name text, is_api boolean,"
- + " password text, username text,"
- + " is_aaf boolean, PRIMARY KEY (uuid)\n" + ");");
- MusicCore.eventualPut(testObject);
-
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
- + "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)");
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(),
- MusicUtil.DEFAULTKEYSPACENAME));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt())));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
- MusicCore.eventualPut(testObject);
-
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
- + "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)");
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
- UUID.fromString("bbc66ccc-d857-4e90-b1e5-df98a3d40de6")));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(),
- MusicUtil.DEFAULTKEYSPACENAME));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), "TestApp1"));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt())));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), "TestUser1"));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
- MusicCore.eventualPut(testObject);
-
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "select uuid from admin.keyspace_master where application_name = ? allow filtering");
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- ResultSet rs = MusicCore.get(testObject);
- List<Row> rows = rs.all();
- if (rows.size() > 0) {
- System.out.println("#######UUID is:" + rows.get(0).getUUID("uuid"));
- }
- }
-
- @Test
- public void Test2_createKeyspace() throws Exception {
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- consistencyInfo.put("type", "eventual");
- replicationInfo.put("class", "SimpleStrategy");
- replicationInfo.put("replication_factor", 1);
- jsonKeyspace.setConsistencyInfo(consistencyInfo);
- jsonKeyspace.setDurabilityOfWrites("true");
- jsonKeyspace.setKeyspaceName(keyspaceName);
- jsonKeyspace.setReplicationInfo(replicationInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createKeySpace("1", "1", "1", null,authorization, appName, jsonKeyspace, keyspaceName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(200,response.getStatus());
- }
-
- @Test
- public void Test2_createKeyspace1() throws Exception {
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- consistencyInfo.put("type", "eventual");
- replicationInfo.put("class", "SimpleStrategy");
- replicationInfo.put("replication_factor", 1);
- jsonKeyspace.setConsistencyInfo(consistencyInfo);
- jsonKeyspace.setDurabilityOfWrites("true");
- jsonKeyspace.setKeyspaceName(keyspaceName);
- jsonKeyspace.setReplicationInfo(replicationInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createKeySpace("1", "1", "1", null,authorization, appName, jsonKeyspace, "keyspaceName");
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(200,response.getStatus());
- }
-
- @Test
- public void Test2_createKeyspace0() throws Exception {
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createKeySpace("1", "1", "1", null, authorization,appName, jsonKeyspace, keyspaceName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(400,response.getStatus());
- }
-//MusicCore.autheticateUser
- @Test
- public void Test2_createKeyspace01() throws Exception {
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- String appName1 = "test";
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createKeySpace("1", "1", "1", null,authorization, appName1, jsonKeyspace, keyspaceName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(401,response.getStatus());
- }
-
- @Test
- public void Test3_createKeyspace1() throws Exception {
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- consistencyInfo.put("type", "eventual");
- replicationInfo.put("class", "SimpleStrategy");
- replicationInfo.put("replication_factor", 1);
- jsonKeyspace.setConsistencyInfo(consistencyInfo);
- jsonKeyspace.setDurabilityOfWrites("true");
- jsonKeyspace.setKeyspaceName("TestApp1");
- jsonKeyspace.setReplicationInfo(replicationInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createKeySpace("1", "1", "1", null,authorization, "TestApp1",
- jsonKeyspace, keyspaceName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(401,response.getStatus());
- }
-
- @Test
- public void Test2_createKeyspaceEmptyAuth() throws Exception {
-
- //MockitoAnnotations.initMocks(this);
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- consistencyInfo.put("type", "eventual");
- replicationInfo.put("class", "SimpleStrategy");
- replicationInfo.put("replication_factor", 1);
- jsonKeyspace.setConsistencyInfo(consistencyInfo);
- jsonKeyspace.setDurabilityOfWrites("true");
- jsonKeyspace.setKeyspaceName(keyspaceName);
- jsonKeyspace.setReplicationInfo(replicationInfo);
- //Map<String, Object> m1= new HashMap<>() ;
- //Mockito.when(CachingUtil.verifyOnboarding("x","y","x")).thenReturn(m1);
- //Mockito.when(CachingUtil.verifyOnboarding(appNamex,userId,password).thenReturn(m1));
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- String authDatax = ":"+password;
- String authorizationx = new String(Base64.encode(authDatax.getBytes()));
- try {
- Response response = data.createKeySpace("1", "1", "1", null,authorizationx, appName, jsonKeyspace, keyspaceName);
- //System.out.println("#######status is " + response.getStatus());
- //System.out.println("Entity" + response.getEntity());
- //assertNotEquals(200,response.getStatus());
- } catch (RuntimeException e ) {
- System.out.println("#######status is runtime exception= " + e);
- }
- }
-
- @Test
- public void Test3_createTable() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization,
- jsonTable, keyspaceName, tableName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
-
- @Test
- public void Test3_createTableClusterOrderBad() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name,emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name,emp_salary");
- jsonTable.setClusteringOrder("ASC");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization,
- jsonTable, keyspaceName, tableName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertNotEquals(200, response.getStatus());
- }
-
- @Test
- public void Test3_createTable_withPropertiesNotNull() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name)");
- consistencyInfo.put("type", "eventual");
- Map<String, Object> properties = new HashMap<>();
- properties.put("comment","Testing prperties not null");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- String tableName_prop=tableName+"_Prop";
- jsonTable.setTableName(tableName_prop);
- jsonTable.setFields(fields);
- jsonTable.setProperties(properties);
-
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization,
- jsonTable, keyspaceName, tableName_prop);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test3_createTable_duplicateTable() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- String tableNameDup=tableName+"X";
- jsonTable.setTableName(tableNameDup);
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameDup);
- System.out.println("#######status for 1st time " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
-
- Response response0 = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameDup);
- // 400 is the duplicate status found in response
- // Music 113 duplicate testing
- //import static org.junit.Assert.assertNotEquals;
- System.out.println("#######status for 2nd time " + response0.getStatus());
- System.out.println("Entity" + response0.getEntity());
-
- assertFalse("Duplicate table not created for "+tableNameDup, 200==response0.getStatus());
-
- }
-
- // Improper Auth
- @Test
- public void Test3_createTable1() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization,
- jsonTable, keyspaceName, tableName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
- // Improper keyspace
- @Test
- public void Test3_createTable3() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, "wrong", tableName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test3_createTable3_with_samePartition_clusteringKeys() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name, emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPartitionKey("emp_name");
- jsonTable.setClusteringKey("emp_name");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test3_createTable3_with_Partition_clusteringKeys() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPartitionKey("emp_name");
- jsonTable.setClusteringKey("uuid");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, "tableName1");
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- // Improper parenthesis in key field
- @Test
- public void Test3_createTable_badParantesis() throws Exception {
- String tableNameC ="testTable0";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name),emp_id)");
- fields.put("emp_id", "varint");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_id Desc");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- //assertEquals(400, response.getStatus());
- assertTrue(200 != response.getStatus());
- }
-
-
- // good clustering key
- @Test
- public void Test3_createTable_1_clusterKey_good() throws Exception {
- String tableNameC ="testTableC1";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name),emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- // jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- // bad partition key=clustering key
- @Test
- public void Test3_createTable_2_clusterKey_bad() throws Exception {
- String tableNameC ="testTableC2";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name),emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name"); // "PRIMARY KEY" overrides if primaryKey present
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertTrue(200 !=response.getStatus());
- }
-
- // good composite partition key,clustering key
- @Test
- public void Test3_createTable_3_partition_clusterKey_good() throws Exception {
- String tableNameC ="testTableC3";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_id", "varint");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name,emp_id),emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- // bad - not all cols in order by of composite partition key,clustering key
- @Test
- public void Test3_createTable_4_clusteringOrder_bad() throws Exception {
- String tableNameC ="testTableC4";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_id", "varint");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name),emp_id,emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertTrue(200 != response.getStatus());
- }
-
- // bad - wrong cols in order by of composite partition key,clustering key
- @Test
- public void Test3_createTable_5_clusteringOrder_bad() throws Exception {
- String tableNameC ="testTableC5";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_id", "varint");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((uuid,emp_name),emp_id,emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_idx desc, emp_salary ASC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertTrue(200 != response.getStatus());
- }
-
- // bad - wrong cols in order by of composite partition key,clustering key
- @Test
- public void Test3_createTable_6_clusteringOrder_bad() throws Exception {
- String tableNameC ="testTableC6";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_id", "varint");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((uuid,emp_name),emp_id,emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("((uuid,emp_name),emp_id,emp_salary)"); // overridden by
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_id desc, emp_salary ASC,uuid desc");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertTrue(200 != response.getStatus());
- }
-
-
- @Test
- public void Test3_createTableIndex_1() throws Exception {
- String tableNameC ="testTableCinx";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name),emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- MultivaluedMap<String, String> rowParams = Mockito.mock(MultivaluedMap.class);
- Mockito.when(info.getQueryParameters()).thenReturn(rowParams);
- Mockito.when(rowParams.getFirst("index_name")).thenReturn("my_index");
- response = data.createIndex("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- keyspaceName, tableNameC,"uuid",info);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test3_createTableIndex_badindexname() throws Exception {
- String tableNameC ="testTableCinx";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name),emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- MultivaluedMap<String, String> rowParams = Mockito.mock(MultivaluedMap.class);
- Mockito.when(info.getQueryParameters()).thenReturn(rowParams);
- Mockito.when(rowParams.getFirst("index_name")).thenReturn("my index");
- response = data.createIndex("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- keyspaceName, tableNameC,"uuid",info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test3_createTableIndex_wrongindex() throws Exception {
- String tableNameC ="testTableCinx";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name),emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- MultivaluedMap<String, String> rowParams = Mockito.mock(MultivaluedMap.class);
- Mockito.when(info.getQueryParameters()).thenReturn(rowParams);
- Mockito.when(rowParams.getFirst("index_name")).thenReturn("my_index");
- response = data.createIndex("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- keyspaceName, tableNameC,"id",info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test4_insertIntoTable() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "testName");
- values.put("emp_salary", 500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, jsonInsert, keyspaceName, tableName);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test4_insertIntoTable2() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test1");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(200, response.getStatus());
- }
-
- // Auth Error
- @Test
- public void Test4_insertIntoTable3() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test1");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(401, response.getStatus());
- }
-
- // Table wrong
- @Test
- public void Test4_insertIntoTable4() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test1");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, "wrong");
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test4_insertIntoTable5() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("id", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test1");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test4_insertIntoTable6() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test4_insertIntoTable7() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test2");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- jsonInsert.setTtl("1000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test4_insertIntoTable8() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test3");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- jsonInsert.setTimestamp("15000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test4_insertIntoTable9() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test4");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- jsonInsert.setTtl("1000");
- jsonInsert.setTimestamp("15000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test4_insertIntoTable10() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test5");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "critical");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- jsonInsert.setTtl("1000");
- jsonInsert.setTimestamp("15000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test4_insertIntoTable11() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test6");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "atomic_delete_lock");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- jsonInsert.setTtl("1000");
- jsonInsert.setTimestamp("15000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test4_insertIntoTable12() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test7");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "atomic");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- jsonInsert.setTtl("1000");
- jsonInsert.setTimestamp("15000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- }
-
- // need mock code to create error for MusicCore methods
- @Test
- public void Test5_updateTableAuthE() throws Exception {
- MockitoAnnotations.initMocks(this);
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test5_updateTableAuthException1() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- String authDatax = ":";//+password;
- String authorizationx = new String(Base64.encode(authDatax.getBytes()));
- try {
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorizationx, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- } catch(RuntimeException e) {
- System.out.println("Update table Runtime exception="+e);
- }
- }
-
- @Test
- public void Test5_updateTableAuthEmpty() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- String authDatax =":"+password;
- String authorizationx = new String(Base64.encode(authDatax.getBytes()));
- String appNamex="xx";
- try {
- // Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- Response response = data.updateTable("1", "1", "1", "", appNamex,
- authorizationx, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- } catch(RuntimeException e) {
- System.out.println("Update table Runtime exception="+e);
- }
- }
-
- @Test
- public void Test5_updateTable_wrongauth() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- wrongAuthorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_invalidColumn() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("id", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_ttl() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName8");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- jsonUpdate.setTtl("1000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_timsetamp() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName9");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- jsonUpdate.setTimestamp("15000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_ttl_timestamp() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName10");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- jsonUpdate.setTtl("1000");
- jsonUpdate.setTimestamp("15000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_rowIdEmpty() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- //row.add("emp_name", "testName3");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- jsonUpdate.setTtl("1000");
- jsonUpdate.setTimestamp("15000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_conditions() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- Map<String, Object> conditions = new HashMap<>();
- conditions.put("emp_name","testName3");
- row.add("emp_name", "testName3");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- jsonUpdate.setConditions(conditions);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_eventual() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "eventual");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_critical() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "critical");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_atomic_delete_lock() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic_delete_lock");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test6_select() throws Exception {
- JsonSelect jsonSelect = new JsonSelect();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName");
- consistencyInfo.put("type", "atomic");
- jsonSelect.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.select("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableName, info);
- HashMap<String,HashMap<String,Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
- HashMap<String, Object> result = map.get("result");
- assertEquals("2500", ((HashMap<String,Object>) result.get("row 0")).get("emp_salary").toString());
- }
-
- @Test
- public void Test6_select_withException() throws Exception {
- JsonSelect jsonSelect = new JsonSelect();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName");
- consistencyInfo.put("type", "atomic");
- jsonSelect.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- RestMusicDataAPI spyData = Mockito.spy(RestMusicDataAPI.class);
- Mockito.doThrow(MusicServiceException.class).when(spyData).selectSpecificQuery("v2", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password, keyspaceName, tableName, info, -1);
- Response response = spyData.select("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test6_select_nodata() throws Exception {
- JsonSelect jsonSelect = new JsonSelect();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName12");
- consistencyInfo.put("type", "atomic");
- jsonSelect.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.select("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test6_selectCritical() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName");
- consistencyInfo.put("type", "atomic");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, jsonInsert, keyspaceName, tableName,info);
- HashMap<String,HashMap<String,Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
- HashMap<String, Object> result = map.get("result");
- assertEquals("2500", ((HashMap<String,Object>) result.get("row 0")).get("emp_salary").toString());
- }
-
- @Test
- public void Test6_selectCritical_without_lockID() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName");
- consistencyInfo.put("type", "critical");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, jsonInsert, keyspaceName, tableName,info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test6_selectCritical_with_atomic_delete_lock() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName");
- consistencyInfo.put("type", "atomic_delete_lock");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, jsonInsert, keyspaceName, tableName,info);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test6_selectCritical_with_nodata() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName12");
- consistencyInfo.put("type", "atomic_delete_lock");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, jsonInsert, keyspaceName, tableName,info);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test6_select_all() throws Exception {
- JsonSelect jsonSelect = new JsonSelect();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();;
- consistencyInfo.put("type", "atomic");
- jsonSelect.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.select("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test6_deleteFromTable() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "test1");
- consistencyInfo.put("type", "atomic");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.deleteFromTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonDelete, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- }
-
- // Values
- @Test
- public void Test6_deleteFromTable1() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- consistencyInfo.put("type", "atomic");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.deleteFromTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonDelete, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-
- // delObj
- @Test
- public void Test6_deleteFromTable2() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "test1");
- consistencyInfo.put("type", "atomic");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.deleteFromTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- null, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test6_deleteFromTable_columns() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "test1");
- consistencyInfo.put("type", "atomic");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- ArrayList<String> columns = new ArrayList<>();
- columns.add("uuid");
- jsonDelete.setColumns(columns);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.deleteFromTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonDelete, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test6_deleteFromTable_conditions() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> conditions = new HashMap<>();
- conditions.put("emp_name","testName3");
- row.add("emp_name", "test1");
- consistencyInfo.put("type", "atomic");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- ArrayList<String> columns = new ArrayList<>();
- jsonDelete.setConditions(conditions);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.deleteFromTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonDelete, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test6_deleteFromTable_eventual() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "test2");
- consistencyInfo.put("type", "eventual");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.deleteFromTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonDelete, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test6_deleteFromTable_critical() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "test2");
- consistencyInfo.put("type", "critical");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.deleteFromTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonDelete, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test6_deleteFromTable_atomic_delete_lock() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "test3");
- consistencyInfo.put("type", "atomic_delete_lock");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.deleteFromTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonDelete, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test7_dropTable() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- consistencyInfo.put("type", "atomic");
- jsonTable.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.dropTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- keyspaceName, tableName);
- assertEquals(200, response.getStatus());
- }
-
-
- @Test
- public void Test8_deleteKeyspace() throws Exception {
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- consistencyInfo.put("type", "eventual");
- replicationInfo.put("class", "SimpleStrategy");
- replicationInfo.put("replication_factor", 1);
- jsonKeyspace.setConsistencyInfo(consistencyInfo);
- jsonKeyspace.setDurabilityOfWrites("true");
- jsonKeyspace.setKeyspaceName("TestApp1");
- jsonKeyspace.setReplicationInfo(replicationInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- authorization,appName, keyspaceName);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test8_deleteKeyspace1() throws Exception {
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- consistencyInfo.put("type", "eventual");
- replicationInfo.put("class", "SimpleStrategy");
- replicationInfo.put("replication_factor", 1);
- jsonKeyspace.setConsistencyInfo(consistencyInfo);
- jsonKeyspace.setDurabilityOfWrites("true");
- jsonKeyspace.setKeyspaceName("TestApp1");
- jsonKeyspace.setReplicationInfo(replicationInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- authorization,appName, "keyspaceName");
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test8_deleteKeyspace2() throws Exception {
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- consistencyInfo.put("type", "eventual");
- replicationInfo.put("class", "SimpleStrategy");
- replicationInfo.put("replication_factor", 1);
- jsonKeyspace.setConsistencyInfo(consistencyInfo);
- jsonKeyspace.setDurabilityOfWrites("true");
- jsonKeyspace.setKeyspaceName("TestApp1");
- jsonKeyspace.setReplicationInfo(replicationInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- wrongAuthorization, appName, keyspaceName);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test6_onboard() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser2");
- jsonOnboard.setPassword("TestPassword2");
- Map<String, Object> resultMap = (Map<String, Object>) admin.onboardAppWithMusic(jsonOnboard).getEntity();
- resultMap.containsKey("success");
- onboardUUID = resultMap.get("Generated AID").toString();
- assertEquals("Your application TestApp2 has been onboarded with MUSIC.", resultMap.get("Success"));
- }
-
- @Test
- public void Test6_onboard_duplicate() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser2");
- jsonOnboard.setPassword("TestPassword2");
- Response response = admin.onboardAppWithMusic(jsonOnboard);
- assertEquals(400, response.getStatus());
- }
-
- // Missing appname
- @Test
- public void Test6_onboard1() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser2");
- jsonOnboard.setPassword("TestPassword2");
- Map<String, Object> resultMap = (Map<String, Object>) admin.onboardAppWithMusic(jsonOnboard).getEntity();
- resultMap.containsKey("success");
- System.out.println("--->" + resultMap.toString());
- assertEquals("Unauthorized: Please check the request parameters. Some of the required values appName(ns), userId, password, isAAF are missing.", resultMap.get("Exception"));
- }
-
-
- @Test
- public void Test7_onboardSearch() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setAid(onboardUUID);
- Map<String, Object> resultMap = (Map<String, Object>) admin.getOnboardedInfoSearch(jsonOnboard).getEntity();
- resultMap.containsKey("success");
- assertEquals(MusicUtil.DEFAULTKEYSPACENAME, resultMap.get(onboardUUID));
- }
-
- // Missing appname
- @Test
- public void Test7_onboardSearch1() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setAid(onboardUUID);
- Map<String, Object> resultMap = (Map<String, Object>) admin.getOnboardedInfoSearch(jsonOnboard).getEntity();
- System.out.println("--->" + resultMap.toString());
- resultMap.containsKey("success");
- assertEquals(MusicUtil.DEFAULTKEYSPACENAME, resultMap.get(onboardUUID));
- }
-
- @Test
- public void Test7_onboardSearch_empty() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- Response response = admin.getOnboardedInfoSearch(jsonOnboard);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test7_onboardSearch_invalidAid() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setAid("abc66ccc-d857-4e90-b1e5-df98a3d40ce6");
- Response response = admin.getOnboardedInfoSearch(jsonOnboard);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test8_onboardUpdate() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser3");
- jsonOnboard.setPassword("TestPassword3");
- jsonOnboard.setAid(onboardUUID);
- Map<String, Object> resultMap = (Map<String, Object>) admin.updateOnboardApp(jsonOnboard).getEntity();
- System.out.println("--->" + resultMap.toString());
- resultMap.containsKey("success");
- assertEquals("Your application has been updated successfully", resultMap.get("Success"));
- }
-
- // Aid null
- @Test
- public void Test8_onboardUpdate1() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser3");
- jsonOnboard.setPassword("TestPassword3");
- Map<String, Object> resultMap = (Map<String, Object>) admin.updateOnboardApp(jsonOnboard).getEntity();
- System.out.println("--->" + resultMap.toString());
- resultMap.containsKey("success");
- assertEquals("Please make sure Aid is present", resultMap.get("Exception"));
- }
-
- // Appname not null
- @Test
- public void Test8_onboardUpdate2() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser3");
- jsonOnboard.setPassword("TestPassword3");
- jsonOnboard.setAid(onboardUUID);
- Map<String, Object> resultMap = (Map<String, Object>) admin.updateOnboardApp(jsonOnboard).getEntity();
- resultMap.containsKey("success");
- System.out.println("--->" + resultMap.toString());
- assertEquals("Application TestApp2 has already been onboarded. Please contact admin.", resultMap.get("Exception"));
- }
-
- // All null
- @Test
- public void Test8_onboardUpdate3() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAid(onboardUUID);
- Map<String, Object> resultMap = (Map<String, Object>) admin.updateOnboardApp(jsonOnboard).getEntity();
- assertTrue(resultMap.containsKey("Exception") );
- }
-
- @Test
- public void Test9_onboardDelete() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setAid(onboardUUID);
- Map<String, Object> resultMap = (Map<String, Object>) admin.deleteOnboardApp(jsonOnboard).getEntity();
- resultMap.containsKey("success");
- assertEquals("Your application has been deleted successfully", resultMap.get("Success"));
- }
-
- @Test
- public void Test9_onboardDelete1() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- Map<String, Object> resultMap = (Map<String, Object>) admin.deleteOnboardApp(jsonOnboard).getEntity();
- assertTrue(resultMap.containsKey("Exception"));
- }
-
- @Test
- public void Test3_createLockReference() throws Exception {
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = (Map<String, Object>) lock.createLockReference(lockName,"1","1",authorization, null, appName).getEntity();
- @SuppressWarnings("unchecked")
- Map<String, Object> resultMap1 = (Map<String, Object>) resultMap.get("lock");
- lockId = (String) resultMap1.get("lock");
- assertEquals(ResultType.SUCCESS, resultMap.get("status"));
- }
-
- @Test
- public void Test4_accquireLock() throws Exception {
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = (Map<String, Object>) lock.accquireLock(lockId,"1","1",authorization, null, appName).getEntity();
- assertEquals(ResultType.SUCCESS, resultMap.get("status"));
- }
-
- @Test
- public void Test5_currentLockHolder() throws Exception {
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = (Map<String, Object>) lock.currentLockHolder(lockName,"1","1",authorization, null, appName).getEntity();
- assertEquals(ResultType.SUCCESS, resultMap.get("status"));
- }
-
- @Test
- public void Test7_unLock() throws Exception {
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = (Map<String, Object>) lock.unLock(lockId,"1","1",authorization, null, appName).getEntity();
- assertEquals(ResultType.SUCCESS, resultMap.get("status"));
- }
-
- @Test
- public void Test8_delete() throws Exception {
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = (Map<String, Object>) lock.deleteLock(lockName,"1","1", null,authorization, appName).getEntity();
- assertEquals(ResultType.SUCCESS, resultMap.get("status"));
- }
-
- // Version api
- @Test
- public void Test1_version( ) {
- RestMusicVersionAPI versionapi = new RestMusicVersionAPI();
- HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class);
- Map<String, Object> resultMap = versionapi.version(servletResponse);
- assertEquals(ResultType.SUCCESS, resultMap.get("status"));
- }
-
- //Music Test Api
- @Test
- public void Test2_testAPI() {
- RestMusicTestAPI musicTest = new RestMusicTestAPI();
- HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class);
- Map<String, HashMap<String, String>> resultMap = musicTest.simpleTests(servletResponse);
- assertNotNull(resultMap);
- }
-
- //Music Health Check
- @Test
- public void Test3_HealthCheck_cassandra() {
- String consistency = "ONE";
- RestMusicHealthCheckAPI healthCheck = new RestMusicHealthCheckAPI();
- HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class);
- Response response = healthCheck.cassandraStatus(servletResponse, consistency);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test3_HealthCheck_cassandra_cosistencyQuorum() {
- String consistency = "QUORUM";
- RestMusicHealthCheckAPI healthCheck = new RestMusicHealthCheckAPI();
- HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class);
- Response response = healthCheck.cassandraStatus(servletResponse, consistency);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test3_HealthCheck_zookeeper() {
- RestMusicHealthCheckAPI healthCheck = new RestMusicHealthCheckAPI();
- HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class);
- Response response = healthCheck.ZKStatus(servletResponse);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test4_pureZKcreate() throws Exception {
- RestMusicBmAPI bmApi = new RestMusicBmAPI();
- bmApi.pureZkCreate("sample");
- }
-
- @Test
- public void Test4_pureZKUpdate() throws Exception {
- RestMusicBmAPI bmApi = new RestMusicBmAPI();
- bmApi.pureZkCreate("sample1");
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "testName_create");
- values.put("emp_salary", 500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- bmApi.pureZkUpdate(jsonInsert, "sampleNode1");
- }
-
- @Test
- public void Test4_pureZKGet() throws Exception {
- RestMusicBmAPI bmApi = new RestMusicBmAPI();
- bmApi.pureZkGet("sample");
- }
-
- @Test
- public void Test5_ZKAtomicPut_atomic() throws Exception {
- RestMusicBmAPI bmApi = new RestMusicBmAPI();
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "testName_create");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "atomic");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- bmApi.pureZkAtomicPut(jsonInsert, "lockname", "sampleNode1");
- }
-
- @Test
- public void Test5_ZKAtomicPut_atomic_with_delete() throws Exception {
- RestMusicBmAPI bmApi = new RestMusicBmAPI();
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "testName_create");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "atomic_delete_lock");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- bmApi.pureZkAtomicPut(jsonInsert, "lockname", "sampleNode1");
- }
-
- @Test
- public void Test5_ZKAtomicGet_atomic() throws Exception {
- RestMusicBmAPI bmApi = new RestMusicBmAPI();
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "testName_create");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "atomic_delete_lock");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- bmApi.pureZkAtomicGet(jsonInsert, "lockname", "sampleNode1");
- }
-
- @Test
- public void Test5_ZKAtomicGet_atomic_with_delete() throws Exception {
- RestMusicBmAPI bmApi = new RestMusicBmAPI();
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "testName_create");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "atomic_delete_lock");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- bmApi.pureZkAtomicGet(jsonInsert, "lockname", "sampleNode1");
- }
-
- @Test
- public void Test5_updateCassa() throws Exception {
- RestMusicBmAPI bmApi = new RestMusicBmAPI();
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName_create");
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- bmApi.updateTableCassa(jsonInsert, keyspaceName, tableName, info);
- }
-
- // RestMusicConditional
- @Test
- public void Test5_createTable_conditional() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("id", "text");
- fields.put("plans", "Map<text,text>");
- fields.put("PRIMARY KEY", "(id)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("id");
- jsonTable.setTableName(tableNameConditional);
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization,
- jsonTable, keyspaceName, tableNameConditional);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test6_insertConditional() throws Exception {
- RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI();
- JsonConditional json = new JsonConditional();
- json.setPrimaryKey("id");
- json.setPrimaryKeyValue("123|abc|port");
- json.setCasscadeColumnName("plans");
- Map<String, Object> tableValues = new HashMap<>();
- tableValues.put("id", "123|abc|port");
- json.setTableValues(tableValues);
- Map<String, Object> columnData = new HashMap<>();
- Map<String, String> column = new HashMap<>();
- column.put("created", "time");
- columnData.put("key", "P2");
- columnData.put("value", column);
- json.setCasscadeColumnData(columnData);
- Map<String, String> cond = new HashMap<>();
- Map<String, String> cond1 = new HashMap<>();
- Map<String, Map<String, String>> conditions = new HashMap<String, Map<String, String>>();
- cond.put("status", "under-spin-up");
- cond1.put("status", "parked");
- conditions.put("exists", cond);
- conditions.put("nonexists", cond1);
- json.setConditions(conditions);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = conditionalApi.insertConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableNameConditional, json);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test6_insertConditional_primaryKey_null() throws Exception {
- RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI();
- JsonConditional json = new JsonConditional();
- json.setPrimaryKeyValue("123|abc|port");
- json.setCasscadeColumnName("plans");
- Map<String, Object> tableValues = new HashMap<>();
- tableValues.put("id", "123|abc|port");
- json.setTableValues(tableValues);
- Map<String, Object> columnData = new HashMap<>();
- Map<String, String> column = new HashMap<>();
- column.put("created", "time");
- columnData.put("key", "P2");
- columnData.put("value", column);
- json.setCasscadeColumnData(columnData);
- Map<String, String> cond = new HashMap<>();
- Map<String, String> cond1 = new HashMap<>();
- Map<String, Map<String, String>> conditions = new HashMap<String, Map<String, String>>();
- cond.put("status", "under-spin-up");
- cond1.put("status", "parked");
- conditions.put("exists", cond);
- conditions.put("nonexists", cond1);
- json.setConditions(conditions);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = conditionalApi.insertConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableNameConditional, json);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test6_insertConditional_wrongAuth() throws Exception {
- RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI();
- JsonConditional json = new JsonConditional();
- json.setPrimaryKey("id");
- json.setPrimaryKeyValue("123|abc|port");
- json.setCasscadeColumnName("plans");
- Map<String, Object> tableValues = new HashMap<>();
- tableValues.put("id", "123|abc|port");
- json.setTableValues(tableValues);
- Map<String, Object> columnData = new HashMap<>();
- Map<String, String> column = new HashMap<>();
- column.put("created", "time");
- columnData.put("key", "P2");
- columnData.put("value", column);
- json.setCasscadeColumnData(columnData);
- Map<String, String> cond = new HashMap<>();
- Map<String, String> cond1 = new HashMap<>();
- Map<String, Map<String, String>> conditions = new HashMap<String, Map<String, String>>();
- cond.put("status", "under-spin-up");
- cond1.put("status", "parked");
- conditions.put("exists", cond);
- conditions.put("nonexists", cond1);
- json.setConditions(conditions);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = conditionalApi.insertConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, wrongAuthorization, keyspaceName, tableNameConditional, json);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test7_updateConditional() throws Exception {
- RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI();
- JsonConditional json = new JsonConditional();
- json.setPrimaryKey("id");
- json.setPrimaryKeyValue("123|abc|port");
- json.setCasscadeColumnName("plans");
- Map<String, Object> tableValues = new HashMap<>();
- tableValues.put("id", "123|abc|port");
- json.setTableValues(tableValues);
- Map<String, Object> columnData = new HashMap<>();
- Map<String, String> column = new HashMap<>();
- column.put("created", "time");
- columnData.put("key", "P2");
- columnData.put("value", column);
- json.setCasscadeColumnData(columnData);
- Map<String, String> cond = new HashMap<>();
- Map<String, String> cond1 = new HashMap<>();
- Map<String, Map<String, String>> conditions = new HashMap<String, Map<String, String>>();
- cond.put("updated", "new time");
- conditions.put("exists", cond);
- conditions.put("nonexists", cond1);
- json.setConditions(conditions);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = conditionalApi.updateConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableNameConditional, json);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test7_updateConditional_wrongAuth() throws Exception {
- RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI();
- JsonConditional json = new JsonConditional();
- json.setPrimaryKey("id");
- json.setPrimaryKeyValue("123|abc|port");
- json.setCasscadeColumnName("plans");
- Map<String, Object> tableValues = new HashMap<>();
- tableValues.put("id", "123|abc|port");
- json.setTableValues(tableValues);
- Map<String, Object> columnData = new HashMap<>();
- Map<String, String> column = new HashMap<>();
- column.put("created", "time");
- columnData.put("key", "P2");
- columnData.put("value", column);
- json.setCasscadeColumnData(columnData);
- Map<String, String> cond = new HashMap<>();
- Map<String, String> cond1 = new HashMap<>();
- Map<String, Map<String, String>> conditions = new HashMap<String, Map<String, String>>();
- cond.put("updated", "new time");
- conditions.put("exists", cond);
- conditions.put("nonexists", cond1);
- json.setConditions(conditions);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = conditionalApi.updateConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, wrongAuthorization, keyspaceName, tableNameConditional, json);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test7_updateConditional_primarykey_null() throws Exception {
- RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI();
- JsonConditional json = new JsonConditional();
- json.setPrimaryKeyValue("123|abc|port");
- json.setCasscadeColumnName("plans");
- Map<String, Object> tableValues = new HashMap<>();
- tableValues.put("id", "123|abc|port");
- json.setTableValues(tableValues);
- Map<String, Object> columnData = new HashMap<>();
- Map<String, String> column = new HashMap<>();
- column.put("created", "time");
- columnData.put("key", "P2");
- columnData.put("value", column);
- json.setCasscadeColumnData(columnData);
- Map<String, String> cond = new HashMap<>();
- Map<String, String> cond1 = new HashMap<>();
- Map<String, Map<String, String>> conditions = new HashMap<String, Map<String, String>>();
- cond.put("updated", "new time");
- conditions.put("exists", cond);
- conditions.put("nonexists", cond1);
- json.setConditions(conditions);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = conditionalApi.updateConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableNameConditional, json);
- assertEquals(401, response.getStatus());
- }
-} \ No newline at end of file
diff --git a/src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java b/src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java
deleted file mode 100644
index e75835d1..00000000
--- a/src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java
+++ /dev/null
@@ -1,1031 +0,0 @@
-/*
- * ============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.unittests;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertTrue;
-//cjc import static org.junit.Assert.assertTrue;
-import java.io.File;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.HashMap;
-import java.util.List;
-//cjc import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import javax.servlet.http.HttpServletResponse;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-import org.apache.curator.test.TestingServer;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.MethodSorters;
-import org.mindrot.jbcrypt.BCrypt;
-//cjcimport org.mindrot.jbcrypt.BCrypt;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.datastore.jsonobjects.JsonDelete;
-import org.onap.music.datastore.jsonobjects.JsonInsert;
-import org.onap.music.datastore.jsonobjects.JsonKeySpace;
-//cjc import org.onap.music.datastore.jsonobjects.JsonKeySpace;
-//import org.onap.music.datastore.jsonobjects.JsonOnboard;
-import org.onap.music.datastore.jsonobjects.JsonSelect;
-import org.onap.music.datastore.jsonobjects.JsonTable;
-import org.onap.music.datastore.jsonobjects.JsonUpdate;
-import org.onap.music.lockingservice.MusicLockingService;
-import org.onap.music.main.MusicCore;
-import org.onap.music.main.MusicUtil;
-//import org.onap.music.main.ResultType;
-import org.onap.music.rest.RestMusicAdminAPI;
-import org.onap.music.rest.RestMusicDataAPI;
-import org.onap.music.rest.RestMusicQAPI;
-import org.onap.music.rest.RestMusicLocksAPI;
-import com.datastax.driver.core.DataType;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
-import com.sun.jersey.core.util.Base64;
-//import com.datastax.driver.core.DataType;
-//import com.datastax.driver.core.ResultSet;
-//import com.datastax.driver.core.Row;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
-
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-@RunWith(MockitoJUnitRunner.class)
-public class TestRestMusicQAPI {
-
-
- RestMusicAdminAPI admin = new RestMusicAdminAPI();
- RestMusicLocksAPI lock = new RestMusicLocksAPI();
- RestMusicQAPI qData = new RestMusicQAPI();
- static PreparedQueryObject testObject;
- static TestingServer zkServer;
-
- @Mock
- static HttpServletResponse http;
-
- @Mock
- UriInfo info;
-
- static String appName = "TestApp";
- static String userId = "TestUser";
- static String password = "TestPassword";
- /*
- static String appName = "com.att.ecomp.portal.demeter.aid";//"TestApp";
- static String userId = "m00468@portal.ecomp.att.com";//"TestUser";
- static String password = "happy123";//"TestPassword";
- */
- static String authData = userId+":"+password;
- static String wrongAuthData = userId+":"+"pass";
- static String authorization = new String(Base64.encode(authData.getBytes()));
- static String wrongAuthorization = new String(Base64.encode(wrongAuthData.getBytes()));
-
- static boolean isAAF = false;
- static UUID uuid = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40ce6");
- static String uuidS = "abc66ccc-d857-4e90-b1e5-df98a3d40ce6";
- static String keyspaceName = "testkscjc";
- static String tableName = "employees";
- static String xLatestVersion = "X-latestVersion";
- static String onboardUUID = null;
- static String lockId = null;
- static String lockName = "testkscjc.employees.sample3";
- static String majorV="3";
- static String minorV="0";
- static String patchV="1";
- static String aid=null;
- static JsonKeySpace kspObject=null;
- static RestMusicDataAPI data = new RestMusicDataAPI();
- static Response resp;
-
- @BeforeClass
- public static void init() throws Exception {
- try {
- System.out.println("before class cassandra");
- MusicCore.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra();
- System.out.println("before class zoo");
- zkServer = new TestingServer(2181, new File("/tmp/zk"));
- MusicCore.mLockHandle = new MusicLockingService();
- // System.out.println("before class keysp");
- //resp=data.createKeySpace(majorV,minorV,patchV,aid,appName,userId,password,kspObject,keyspaceName);
- //System.out.println("after keyspace="+keyspaceName);
- } catch (Exception e) {
- System.out.println("before class exception ");
- e.printStackTrace();
- }
- // admin keyspace and table
- testObject = new PreparedQueryObject();
- testObject.appendQueryString("CREATE KEYSPACE admin WITH REPLICATION = "
- + "{'class' : 'SimpleStrategy' , "
- + "'replication_factor': 1} AND DURABLE_WRITES = true");
- MusicCore.eventualPut(testObject);
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "CREATE TABLE admin.keyspace_master (" + " uuid uuid, keyspace_name text,"
- + " application_name text, is_api boolean,"
- + " password text, username text,"
- + " is_aaf boolean, PRIMARY KEY (uuid)\n" + ");");
- MusicCore.eventualPut(testObject);
-
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
- + "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)");
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(),
- MusicUtil.DEFAULTKEYSPACENAME));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt())));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
- MusicCore.eventualPut(testObject);
-
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
- + "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)");
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
- UUID.fromString("bbc66ccc-d857-4e90-b1e5-df98a3d40de6")));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(),
- MusicUtil.DEFAULTKEYSPACENAME));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), "TestApp1"));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt())));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), "TestUser1"));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
- MusicCore.eventualPut(testObject);
-
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "select uuid from admin.keyspace_master where application_name = ? allow filtering");
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- ResultSet rs = MusicCore.get(testObject);
- List<Row> rows = rs.all();
- if (rows.size() > 0) {
- System.out.println("#######UUID is:" + rows.get(0).getUUID("uuid"));
- }
-
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- consistencyInfo.put("type", "eventual");
- replicationInfo.put("class", "SimpleStrategy");
- replicationInfo.put("replication_factor", 1);
- jsonKeyspace.setConsistencyInfo(consistencyInfo);
- jsonKeyspace.setDurabilityOfWrites("true");
- jsonKeyspace.setKeyspaceName(keyspaceName);
- jsonKeyspace.setReplicationInfo(replicationInfo);
- Response response = data.createKeySpace(majorV, minorV, patchV, null, authorization, appName,
- jsonKeyspace, keyspaceName);
- System.out.println("#######status is " + response.getStatus()+" keyspace="+keyspaceName);
-
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- System.out.println("After class");
- testObject = new PreparedQueryObject();
- testObject.appendQueryString("DROP KEYSPACE IF EXISTS " + keyspaceName);
- MusicCore.eventualPut(testObject);
- testObject = new PreparedQueryObject();
- testObject.appendQueryString("DROP KEYSPACE IF EXISTS admin");
- MusicCore.eventualPut(testObject);
- MusicCore.mDstoreHandle.close();
- MusicCore.mLockHandle.getzkLockHandle().close();
- MusicCore.mLockHandle.close();
- zkServer.stop();
- }
-
-
- @Test
- public void Test1_createQ_good() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- jsonTable.setPartitionKey("emp_name");
- jsonTable.setClusteringKey("uuid");
- jsonTable.setClusteringOrder("uuid ASC");
- //System.out.println("cjc before print version, xLatestVersion="+xLatestVersion);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableName);
- // "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test1_createQ_FieldsEmpty() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- /*
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name)");
- */
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- //System.out.println("cjc before print version, xLatestVersion="+xLatestVersion);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableName);
- // "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
- System.out.println("EmptyFields #######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertNotEquals(200, response.getStatus());
- }
- @Test
- public void Test1_createQ_Clustergood() throws Exception {
- String tableNameC="testcjcC";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_id", "text");
- fields.put("emp_salary", "varint");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPartitionKey("emp_name");
- jsonTable.setClusteringKey("emp_id");
- jsonTable.setClusteringOrder("emp_id DESC");
- jsonTable.setTableName(tableNameC);
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- // "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
- System.out.println("#######status is " + response.getStatus()+"table namec="+tableNameC);
- System.out.println("Entity" + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test1_createQ_ClusterOrderGood1() throws Exception {
- String tableNameC="testcjcO";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_id", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name,emp_id)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_id DESC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- // "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
- System.out.println("#######status is " + response.getStatus()+"table namec="+tableNameC);
- System.out.println("Entity" + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test1_createQ_PartitionKeygood() throws Exception {
- String tableNameP="testcjcP";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_id", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name,emp_salary),emp_id)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setTableName(tableNameP);
- jsonTable.setClusteringOrder("emp_id DESC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameP);
- // "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
- System.out.println("#######status is " + response.getStatus()+"table namec="+tableNameP);
- System.out.println("Entity" + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test1_createQ_PartitionKeybadclose() throws Exception {
- String tableNameC="testcjcP1";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_id", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name,emp_salary),emp_id))");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name,emp_id");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_id DESC");
- jsonTable.setFields(fields);
- //System.out.println("cjc before print version, xLatestVersion="+xLatestVersion);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- // "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
- System.out.println("#######status is " + response.getStatus()+"table namec="+tableNameC);
- System.out.println("Entity" + response.getEntity());
- //assertEquals(400, response.getStatus());
- assertTrue(200 != response.getStatus());
- }
-
- @Test
- public void Test1_createQ_ClusterOrderGood2() throws Exception {
- String tableNameC="testcjcO1g";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_id", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name,emp_salary,emp_id)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name,emp_id");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC,emp_id DESC");
- jsonTable.setFields(fields);
- //System.out.println("cjc before print version, xLatestVersion="+xLatestVersion);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- // "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
- System.out.println("#######status is " + response.getStatus()+"table namec="+tableNameC);
- System.out.println("Entity" + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test1_createQ_ColPkeyoverridesPrimaryKeyGood() throws Exception {
- String tableNameC="testcjcPr";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_id", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name),emp_salary,emp_id)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name,emp_id");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC,emp_id DESC");
- jsonTable.setFields(fields);
- //System.out.println("cjc before print version, xLatestVersion="+xLatestVersion);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- // "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
- System.out.println("#######status is " + response.getStatus()+"table namec="+tableNameC);
- System.out.println("Entity" + response.getEntity());
- assertEquals(200, response.getStatus());
- //assertTrue(200 != response.getStatus());
- }
-
- @Test
- public void Test1_createQ_ClusterOrderBad() throws Exception {
- String tableNameC="testcjcO1b";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_id", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name,emp_id)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name,emp_id");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_id DESCx");
- jsonTable.setFields(fields);
- //System.out.println("cjc before print version, xLatestVersion="+xLatestVersion);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- // "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
- System.out.println("#######status is " + response.getStatus()+"table namec="+tableNameC);
- System.out.println("Entity" + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
-
- @Test
- public void Test3_createQ_0() throws Exception {
- //duplicate testing ...
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- String tableNameDup=tableName+"X";
- jsonTable.setTableName(tableNameDup);
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameDup);
- System.out.println("#######status for 1st time " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
-
- Response response0 = qData.createQ(majorV, minorV,patchV,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameDup);
- // 400 is the duplicate status found in response
- // Music 113 duplicate testing
- //import static org.junit.Assert.assertNotEquals;
- System.out.println("#######status for 2nd time " + response0.getStatus());
- System.out.println("Entity" + response0.getEntity());
-
- assertFalse("Duplicate table not created for "+tableNameDup, 200==response0.getStatus());
- //assertEquals(400, response0.getStatus());
- //assertNotEquals(200,response0.getStatus());
- }
-
- // Improper Auth
- @Test
- public void Test3_createQ1() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPartitionKey("emp_name");
- jsonTable.setClusteringKey("uuid");
- jsonTable.setTableName(tableName);
- jsonTable.setClusteringOrder("uuid DESC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization,
- jsonTable, keyspaceName, tableName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
- // Improper keyspace
- @Test
- public void Test3_createQ2() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPartitionKey("emp_name");
- jsonTable.setTableName(tableName);
- jsonTable.setClusteringKey("emp_salary");
- jsonTable.setClusteringOrder("emp_salary DESC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, "wrong", tableName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
-
-
- @Test
- public void Test4_insertIntoQ() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "testName");
- values.put("emp_salary", 500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.insertIntoQ(majorV, minorV,patchV, "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, jsonInsert, keyspaceName, tableName);
- assertEquals(200, response.getStatus());
- }
-
-
- @Test
- public void Test4_insertIntoQ_valuesEmpty() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- /*
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "testName");
- values.put("emp_salary", 500);
- */
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.insertIntoQ(majorV, minorV,patchV, "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, jsonInsert, keyspaceName, tableName);
- assertNotEquals(200, response.getStatus());
- }
-
- @Test
- public void Test4_insertIntoQ2() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test1");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.insertIntoQ(majorV, minorV,patchV,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(200, response.getStatus());
- }
-
- // Auth Error
- @Test
- public void Test4_insertIntoQ3() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test1");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.insertIntoQ(majorV, minorV,patchV,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(401, response.getStatus());
- }
-
- // Table wrong
- @Test
- public void Test4_insertIntoQ4() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test1");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.insertIntoQ(majorV, minorV,patchV,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, "wrong");
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test5_updateQ() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- row.add("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_salary", "2500");
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = qData.updateQ(majorV, minorV,patchV, "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test5_updateQEmptyValues() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- //values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = qData.updateQ(majorV, minorV,patchV, "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertNotEquals(200, response.getStatus());
- }
-
- @Test
- public void Test6_filterQ() throws Exception { //select
- JsonSelect jsonSelect = new JsonSelect();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName");
- row.add("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- consistencyInfo.put("type", "atomic");
- jsonSelect.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = qData.filter(majorV, minorV,patchV,"abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableName, info);
- HashMap<String,HashMap<String,Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
- HashMap<String, Object> result = map.get("result");
- assertEquals("2500", ((HashMap<String,Object>) result.get("row 0")).get("emp_salary").toString());
- }
-
- @Test
- public void Test6_peekQ() throws Exception { //select
- JsonSelect jsonSelect = new JsonSelect();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName");
- consistencyInfo.put("type", "atomic");
- jsonSelect.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = qData.peek(majorV, minorV,patchV,"abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableName, info);
- HashMap<String,HashMap<String,Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
- HashMap<String, Object> result = map.get("result");
- if (result.isEmpty() ) assertTrue(true);
- else assertFalse(false);
- //assertEquals("2500", ((HashMap<String,Object>) result.get("row 0")).get("emp_salary").toString());
- }
-
- @Test
- public void Test6_peekQ_empty() throws Exception { //select
- // row is not needed in thhis test
- JsonSelect jsonSelect = new JsonSelect();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName");
- consistencyInfo.put("type", "atomic");
- jsonSelect.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- UriInfo infoe= mockUriInfo("/peek?");//empty queryParam: cause exception
- // infoe.setQueryParameters("");
- System.out.println("uriinfo="+infoe.getQueryParameters());
- Mockito.when(infoe.getQueryParameters()).thenReturn(row);
- Response response = qData.peek(majorV, minorV,patchV,"abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableName, infoe);
- HashMap<String,HashMap<String,Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
- HashMap<String, Object> result = map.get("result");
- if (result.isEmpty() ) assertTrue(true);
- else assertFalse(false);
- //assertEquals("2500", ((HashMap<String,Object>) result.get("row 0")).get("emp_salary").toString());
- }
-
- @Test
- public void Test6_deleteFromQ1() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "test1");
- consistencyInfo.put("type", "atomic");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = qData.deleteFromQ(majorV, minorV,patchV,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonDelete, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- }
-
- // Values
- @Test
- public void Test6_deleteFromQ() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- consistencyInfo.put("type", "atomic");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = qData.deleteFromQ(majorV, minorV,patchV,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonDelete, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-
- // delObj
- @Test
- public void Test6_deleteFromQ2() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "test1");
- consistencyInfo.put("type", "atomic");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = qData.deleteFromQ(majorV, minorV,patchV,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- null, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test7_dropQ() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- consistencyInfo.put("type", "atomic");
- jsonTable.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.dropQ(majorV, minorV,patchV,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- keyspaceName, tableName);
- assertEquals(200, response.getStatus());
- }
-
- private UriInfo mockUriInfo(String urix) throws URISyntaxException {
- String uri="http://localhost:8080/MUSIC/rest/v"+majorV+"/priorityq/keyspaces/"+keyspaceName+"/"+tableName+urix;
- UriInfo uriInfo = Mockito.mock(UriInfo.class);
- System.out.println("mock urix="+urix+" uri="+uri);
- Mockito.when(uriInfo.getRequestUri()).thenReturn(new URI(uri));
- return uriInfo;
- }
-
-
- //Empty Fields
- @Test
- public void Test8_createQ_fields_empty() throws Exception {
- String tableNameC="testcjcC";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPartitionKey("emp_name");
- jsonTable.setClusteringKey("emp_id");
- jsonTable.setClusteringOrder("emp_id DESC");
- jsonTable.setTableName(tableNameC);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus()+"table namec="+tableNameC);
- System.out.println("Entity" + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- //Partition key null
- @Test
- public void Test8_createQ_partitionKey_empty() throws Exception {
- String tableNameC="testcjcC";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_id", "text");
- fields.put("emp_salary", "varint");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setClusteringKey("emp_id");
- jsonTable.setClusteringOrder("emp_id DESC");
- jsonTable.setTableName(tableNameC);
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus()+"table namec="+tableNameC);
- System.out.println("Entity" + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- //Clustering key null
- @Test
- public void Test8_createQ_ClusteringKey_empty() throws Exception {
- String tableNameC="testcjcC";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_id", "text");
- fields.put("emp_salary", "varint");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPartitionKey("emp_name");
- jsonTable.setClusteringOrder("emp_id DESC");
- jsonTable.setTableName(tableNameC);
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus()+"table namec="+tableNameC);
- System.out.println("Entity" + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- //Clustering Order null
- @Test
- public void Test8_createQ_ClusteringOrder_empty() throws Exception {
- String tableNameC="testcjcC";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_id", "text");
- fields.put("emp_salary", "varint");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPartitionKey("emp_name");
- jsonTable.setClusteringKey("emp_id");
- jsonTable.setTableName(tableNameC);
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus()+"table namec="+tableNameC);
- System.out.println("Entity" + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- //Invalid primary key
- @Test
- public void Test8_createQ_primaryKey_invalid() throws Exception {
- String tableNameC="testcjcC";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_id", "text");
- fields.put("emp_salary", "varint");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setPrimaryKey("(emp_name");
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setClusteringKey("emp_id");
- jsonTable.setClusteringOrder("emp_id ASC");
- jsonTable.setTableName(tableNameC);
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus()+"table namec="+tableNameC);
- System.out.println("Entity" + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- //Primary key with no clustering key
- @Test
- public void Test8_createQ_primaryKey_with_empty_clusteringKey() throws Exception {
- String tableNameC="testcjcC";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_id", "text");
- fields.put("emp_salary", "varint");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableNameC);
- jsonTable.setFields(fields);
- jsonTable.setClusteringOrder("emp_id ASC");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus()+"table namec="+tableNameC);
- System.out.println("Entity" + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- //Primary key with no partition key
- @Test
- public void Test8_createQ_primaryKey_with_empty_partitionKey() throws Exception {
- String tableNameC="testcjcC";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_id", "text");
- fields.put("emp_salary", "varint");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey(" ");
- jsonTable.setTableName(tableNameC);
- jsonTable.setFields(fields);
- jsonTable.setClusteringOrder("emp_id ASC");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- aid, appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus()+"table namec="+tableNameC);
- System.out.println("Entity" + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
-} \ No newline at end of file
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/AAFResponseTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/AAFResponseTest.java
deleted file mode 100644
index 354668c7..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/AAFResponseTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * ============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.unittests.jsonobjects;
-
-import static org.junit.Assert.*;
-import java.util.ArrayList;
-import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.AAFResponse;
-import org.onap.music.datastore.jsonobjects.NameSpace;
-
-public class AAFResponseTest {
-
- @Test
- public void testGetNs() {
- NameSpace ns = new NameSpace();
- AAFResponse ar = new AAFResponse();
- ArrayList<NameSpace> nsArray = new ArrayList<>();
- ns.setName("tom");
- ArrayList<String> admin = new ArrayList<>();
- admin.add("admin1");
- ns.setAdmin(admin);
- nsArray.add(ns);
- ar.setNs(nsArray);
- assertEquals("tom",ar.getNs().get(0).getName());
- assertEquals("admin1",ar.getNs().get(0).getAdmin().get(0));
-
- }
-
-// @Test
-// public void testSetNs() {
-// fail("Not yet implemented");
-// }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JSONObjectTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JSONObjectTest.java
deleted file mode 100644
index 7f6af4c5..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/JSONObjectTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2017 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.unittests.jsonobjects;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import org.onap.music.datastore.jsonobjects.JSONObject;
-
-public class JSONObjectTest {
- private JSONObject jsonObject;
-
- @Before
- public void setUp() {
- jsonObject = new JSONObject();
- }
-
- @Test
- public void testGetSetData() {
- jsonObject.setData("data");
- Assert.assertEquals("data", jsonObject.getData());
- }
-}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java
deleted file mode 100644
index 885694bd..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * ============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.unittests.jsonobjects;
-
-import static org.junit.Assert.*;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonDelete;
-
-public class JsonDeleteTest {
-
- JsonDelete jd = null;
-
- @Before
- public void init() {
- jd = new JsonDelete();
- }
-
-
- @Test
- public void testGetConditions() {
- Map<String,Object> mapSo = new HashMap<>();
- 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 = new HashMap<>();
- mapSs.put("key3","three");
- mapSs.put("key4","four");
- jd.setConsistencyInfo(mapSs);
- assertEquals("three",jd.getConsistencyInfo().get("key3"));
- }
-
- @Test
- public void testGetColumns() {
- ArrayList<String> ary = new ArrayList<>();
- 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());
-
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java
deleted file mode 100644
index 69403cc7..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * ============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.unittests.jsonobjects;
-
-import static org.junit.Assert.*;
-import java.util.HashMap;
-import java.util.Map;
-import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonInsert;
-
-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 testGetRow_specification() {
- Map<String,Object> cons = new HashMap<>();
- cons.put("val1","one");
- cons.put("val2","two");
- ji.setRow_specification(cons);
- assertEquals("two",ji.getRow_specification().get("val2"));
- }
-
-
-}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java
deleted file mode 100644
index 882d5d5e..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * ============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.unittests.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.jsonobjects.JsonKeySpace;
-
-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/src/test/java/org/onap/music/unittests/jsonobjects/JsonLeasedLockTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonLeasedLockTest.java
deleted file mode 100644
index 63f901c6..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/JsonLeasedLockTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * ============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.unittests.jsonobjects;
-
-import static org.junit.Assert.*;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonLeasedLock;
-
-public class JsonLeasedLockTest {
-
- JsonLeasedLock jl = null;
-
- @Before
- public void init() {
- jl = new JsonLeasedLock();
- }
-
-
- @Test
- public void testGetLeasePeriod() {
- long lease = 20000;
- jl.setLeasePeriod(lease);
- assertEquals(lease,jl.getLeasePeriod());
- }
-
- @Test
- public void testGetNotifyUrl() {
- String url = "http://somewhere.com";
- jl.setNotifyUrl(url);
- assertEquals(url,jl.getNotifyUrl());
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonNotifyClientResponseTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonNotifyClientResponseTest.java
deleted file mode 100644
index 07f4dbb4..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/JsonNotifyClientResponseTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2018 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.unittests.jsonobjects;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import org.onap.music.datastore.jsonobjects.JsonNotifyClientResponse;
-
-public class JsonNotifyClientResponseTest {
- private JsonNotifyClientResponse response;
-
- @Before
- public void setUp() {
- response = new JsonNotifyClientResponse();
- }
-
- @Test
- public void testGetSetMethods() {
- response.setMessage("message");
- response.setStatus("success");
- Assert.assertEquals("message", response.getMessage());
- Assert.assertEquals("success", response.getStatus());
- }
-}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonOnboardTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonOnboardTest.java
deleted file mode 100644
index 82f1748a..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/JsonOnboardTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * ============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.unittests.jsonobjects;
-
-import static org.junit.Assert.*;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonOnboard;
-
-public class JsonOnboardTest {
-
- JsonOnboard jo = null;
-
- @Before
- public void init() {
- jo = new JsonOnboard();
- }
-
-
- @Test
- public void testGetPassword() {
- String password = "password";
- jo.setPassword(password);
- assertEquals(password,jo.getPassword());
- }
-
- @Test
- public void testGetAid() {
- String aid = "aid";
- jo.setAid(aid);
- assertEquals(aid,jo.getAid());
-
- }
-
- @Test
- public void testGetAppname() {
- String appName = "appName";
- jo.setAppname(appName);
- assertEquals(appName,jo.getAppname());
-
- }
-
- @Test
- public void testGetUserId() {
- String userId = "userId";
- jo.setUserId(userId);
- assertEquals(userId,jo.getUserId());
-
- }
-
- @Test
- public void testGetIsAAF() {
- String aaf = "true";
- jo.setIsAAF(aaf);
- assertEquals(aaf,jo.getIsAAF());
-
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java
deleted file mode 100644
index 0243232f..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * ============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.unittests.jsonobjects;
-
-import static org.junit.Assert.*;
-import java.util.HashMap;
-import java.util.Map;
-import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonSelect;
-
-public class JsonSelectTest {
-
- @Test
- public void testGetConsistencyInfo() {
- JsonSelect js = new JsonSelect();
- Map<String, String> mapSs = new HashMap<>();
- mapSs.put("k1", "one");
- js.setConsistencyInfo(mapSs);
- assertEquals("one",js.getConsistencyInfo().get("k1"));
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java
deleted file mode 100644
index e4c800fc..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * ============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.unittests.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.jsonobjects.JsonTable;
-
-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);
- }
-
- @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 testGetSortingKey() {
- String sortKey = "sortkey";
- jt.setSortingKey(sortKey);
- assertEquals(sortKey,jt.getSortingKey());
- }
-
- @Test
- public void testGetClusteringOrder() {
- String clusteringOrder = "clusteringOrder";
- jt.setClusteringOrder(clusteringOrder);
- assertEquals(clusteringOrder,jt.getClusteringOrder());
- }
-
- @Test
- public void testGetPrimaryKey() {
- String primaryKey = "primaryKey";
- jt.setPrimaryKey(primaryKey);
- assertEquals(primaryKey,jt.getPrimaryKey());
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java
deleted file mode 100644
index 54db0540..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2018 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.unittests.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.jsonobjects.JsonUpdate;
-
-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"));
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/NameSpaceTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/NameSpaceTest.java
deleted file mode 100644
index ee4d3933..00000000
--- a/src/test/java/org/onap/music/unittests/jsonobjects/NameSpaceTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2018 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.unittests.jsonobjects;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import org.onap.music.datastore.jsonobjects.NameSpace;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-public class NameSpaceTest {
- private NameSpace nameSpace;
-
- @Before
- public void setUp() {
- nameSpace = new NameSpace();
- }
-
- @Test
- public void testGetSetAdmin() {
- List<String> list = new ArrayList<String>();
- list.add("admin");
- nameSpace.setAdmin(list);
- Assert.assertEquals(list, nameSpace.getAdmin());
- }
-
- @Test
- public void testGetSetName() {
- nameSpace.setName("name");
- Assert.assertEquals("name", nameSpace.getName());
- }
-}