summaryrefslogtreecommitdiffstats
path: root/music-core/src/test
diff options
context:
space:
mode:
authorTschaen, Brendan <ctschaen@att.com>2019-11-12 14:28:26 -0500
committerTschaen, Brendan <ctschaen@att.com>2019-11-12 14:30:29 -0500
commitd4f4d573469aaa9b284313e4bd9535e6d8e3dd10 (patch)
treeeede993180da0d5dd777b02be6ce4097a4deb189 /music-core/src/test
parent5300ffcc9f94bfe04b11485d9e0cdbc02db0bd22 (diff)
Update junits
Change-Id: Ic08113ccee0c11e541764059632dfb2692eba657 Issue-ID: MUSIC-521 Signed-off-by: Tschaen, Brendan <ctschaen@att.com>
Diffstat (limited to 'music-core/src/test')
-rw-r--r--music-core/src/test/java/org/onap/music/cassandra/MusicUtilTest.java (renamed from music-core/src/test/java/org/onap/music/unittests/MusicUtilTest.java)2
-rw-r--r--music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonDeleteTest.java (renamed from music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java)3
-rw-r--r--music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonInsertTest.java (renamed from music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java)71
-rw-r--r--music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonKeySpaceTest.java (renamed from music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java)3
-rw-r--r--music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonSelectTest.java (renamed from music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java)3
-rw-r--r--music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonTableTest.java (renamed from music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java)57
-rw-r--r--music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonUpdateTest.java (renamed from music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java)59
-rw-r--r--music-core/src/test/java/org/onap/music/main/ResultTypeTest.java (renamed from music-core/src/test/java/org/onap/music/unittests/ResultTypeTest.java)3
-rw-r--r--music-core/src/test/java/org/onap/music/main/ReturnTypeTest.java (renamed from music-core/src/test/java/org/onap/music/unittests/ReturnTypeTest.java)4
-rw-r--r--music-core/src/test/java/org/onap/music/unittests/CassandraCQL.java245
10 files changed, 186 insertions, 264 deletions
diff --git a/music-core/src/test/java/org/onap/music/unittests/MusicUtilTest.java b/music-core/src/test/java/org/onap/music/cassandra/MusicUtilTest.java
index 39432d07..90cd68e2 100644
--- a/music-core/src/test/java/org/onap/music/unittests/MusicUtilTest.java
+++ b/music-core/src/test/java/org/onap/music/cassandra/MusicUtilTest.java
@@ -21,7 +21,7 @@
* ====================================================================
*/
-package org.onap.music.unittests;
+package org.onap.music.cassandra;
import static org.junit.Assert.*;
import java.math.BigInteger;
diff --git a/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonDeleteTest.java
index a069b81d..0014f823 100644
--- a/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java
+++ b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonDeleteTest.java
@@ -22,7 +22,7 @@
* ====================================================================
*/
-package org.onap.music.unittests.jsonobjects;
+package org.onap.music.datastore.jsonobjects;
import static org.junit.Assert.*;
import java.util.ArrayList;
@@ -31,7 +31,6 @@ import java.util.List;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonDelete;
public class JsonDeleteTest {
diff --git a/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonInsertTest.java
index 4992af7b..ad71c9ea 100644
--- a/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java
+++ b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonInsertTest.java
@@ -22,17 +22,31 @@
* ====================================================================
*/
-package org.onap.music.unittests.jsonobjects;
+package org.onap.music.datastore.jsonobjects;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-
+import static org.junit.Assert.assertTrue;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.SerializationUtils;
import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonInsert;
+import org.mockito.Mockito;
+import org.mockito.internal.util.reflection.FieldSetter;
+import org.onap.music.datastore.MusicDataStore;
+import org.onap.music.datastore.MusicDataStoreHandle;
+import org.onap.music.datastore.PreparedQueryObject;
+import org.onap.music.exceptions.MusicQueryException;
+import org.onap.music.exceptions.MusicServiceException;
+import com.datastax.driver.core.ColumnMetadata;
+import com.datastax.driver.core.DataType;
+import com.datastax.driver.core.Session;
+//import org.mockito.internal.util.reflection.Whitebox;
+import com.datastax.driver.core.TableMetadata;
+
public class JsonInsertTest {
@@ -107,5 +121,56 @@ public class JsonInsertTest {
ji.setObjectMap(map);
assertEquals(map, ji.getObjectMap());
}
+
+ @Test
+ public void testPrimaryKey() {
+ ji.setPrimaryKeyVal("primKey");
+ assertEquals("primKey", ji.getPrimaryKeyVal());
+ }
+
+ @Test
+ public void testGenInsertPreparedQueryObj() throws Exception {
+ ji.setKeyspaceName("keyspace");
+ ji.setTableName("table");
+ ji.setPrimaryKeyVal("value");
+ Map<String,Object> rowSpec = new HashMap<>();
+ rowSpec.put("val1","one");
+ rowSpec.put("val2","two");
+ ji.setRowSpecification(rowSpec);
+ Map<String,Object> vals = new HashMap<>();
+ vals.put("val1","one");
+ vals.put("val2","two");
+ ji.setValues(vals);
+
+ Map<String,String> cons = new HashMap<>();
+ cons.put("type","quorum");
+ ji.setConsistencyInfo(cons);
+
+ MusicDataStore mds = Mockito.mock(MusicDataStore.class);
+ Session session = Mockito.mock(Session.class);
+ Mockito.when(mds.getSession()).thenReturn(session);
+ MusicDataStoreHandle mdsh = Mockito.mock(MusicDataStoreHandle.class);
+ FieldSetter.setField(mdsh, mdsh.getClass().getDeclaredField("mDstoreHandle"), mds);
+ TableMetadata tableMeta = Mockito.mock(TableMetadata.class);
+ Mockito.when(mds.returnColumnMetadata(Mockito.anyString(), Mockito.anyString()))
+ .thenReturn(tableMeta);
+
+ ColumnMetadata cmd = Mockito.mock(ColumnMetadata.class);
+ List<ColumnMetadata> listcmd = new ArrayList<>();
+ listcmd.add(cmd);
+ Mockito.when(tableMeta.getPrimaryKey()).thenReturn(listcmd);
+ Mockito.when(cmd.getName()).thenReturn("val1");
+ Mockito.when(tableMeta.getColumn("val1")).thenReturn(cmd);
+ Mockito.when(tableMeta.getColumn("val2")).thenReturn(cmd);
+ Mockito.when(cmd.getType()).thenReturn(DataType.text());
+
+ PreparedQueryObject query = ji.genInsertPreparedQueryObj();
+ System.out.println(query.getQuery());
+ System.out.println(query.getValues());
+
+
+ assertEquals("INSERT INTO keyspace.table (vector_ts,val2,val1) VALUES (?,?,?);", query.getQuery());
+ assertTrue(query.getValues().containsAll(vals.values()));
+ }
}
diff --git a/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonKeySpaceTest.java
index 0f4abd7c..a3fa58e4 100644
--- a/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java
+++ b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonKeySpaceTest.java
@@ -20,14 +20,13 @@
* ====================================================================
*/
-package org.onap.music.unittests.jsonobjects;
+package org.onap.music.datastore.jsonobjects;
import static org.junit.Assert.*;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonKeySpace;
public class JsonKeySpaceTest {
diff --git a/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonSelectTest.java
index 37d1787a..21c022ab 100644
--- a/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java
+++ b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonSelectTest.java
@@ -22,7 +22,7 @@
* ====================================================================
*/
-package org.onap.music.unittests.jsonobjects;
+package org.onap.music.datastore.jsonobjects;
import static org.junit.Assert.assertEquals;
@@ -31,7 +31,6 @@ import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonSelect;
public class JsonSelectTest {
diff --git a/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonTableTest.java
index 4e3b4629..3ab32d40 100644
--- a/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java
+++ b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonTableTest.java
@@ -22,14 +22,14 @@
* ====================================================================
*/
-package org.onap.music.unittests.jsonobjects;
+package org.onap.music.datastore.jsonobjects;
import static org.junit.Assert.*;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonTable;
+import org.onap.music.exceptions.MusicQueryException;
public class JsonTableTest {
@@ -53,6 +53,7 @@ public class JsonTableTest {
Map<String, Object> properties = new HashMap<>();
properties.put("k1", "one");
jt.setProperties(properties);
+ assertEquals(properties.size(), jt.getProperties().size());
}
@Test
@@ -83,6 +84,13 @@ public class JsonTableTest {
jt.setClusteringOrder(clusteringOrder);
assertEquals(clusteringOrder,jt.getClusteringOrder());
}
+
+ @Test
+ public void testGetClusterKey() {
+ String clusterKey = "clusterKey";
+ jt.setClusteringKey(clusterKey);
+ assertEquals(clusterKey, jt.getClusteringKey());
+ }
@Test
public void testGetPrimaryKey() {
@@ -96,5 +104,50 @@ public class JsonTableTest {
jt.setFilteringKey("FilteringKey");
assertEquals("FilteringKey",jt.getFilteringKey());
}
+
+ @Test
+ public void testPartitionKey() {
+ jt.setPartitionKey("ParitionKey");
+ assertEquals("ParitionKey",jt.getPartitionKey());
+ }
+ @Test
+ public void genCreateTableQuery() throws MusicQueryException {
+ JsonTable jt2 = new JsonTable();
+ jt2.setKeyspaceName("keyspace");
+ jt2.setTableName("table");
+ Map<String, String> fields = new HashMap<>();
+ fields.put("k1", "one");
+ jt2.setFields(fields);
+ jt2.setPrimaryKey("k1");
+ Map<String, String> mapSs = new HashMap<>();
+ mapSs.put("k1", "one");
+ jt2.setConsistencyInfo(mapSs);
+ String clusteringOrder = "clusteringOrder";
+ jt.setClusteringOrder(clusteringOrder);
+ String clusterKey = "clusterKey";
+ jt.setClusteringKey(clusterKey);
+
+ System.out.println(jt2.genCreateTableQuery().getQuery());
+ assertEquals("CREATE TABLE keyspace.table (vector_ts text,k1 one, PRIMARY KEY ( (k1) ));",
+ jt2.genCreateTableQuery().getQuery());
+ }
+
+ @Test
+ public void genDropTableQuery() throws MusicQueryException {
+ JsonTable jt2 = new JsonTable();
+ jt2.setKeyspaceName("keyspace");
+ jt2.setTableName("table");
+ Map<String, String> fields = new HashMap<>();
+ fields.put("k1", "one");
+ jt2.setFields(fields);
+ jt2.setPrimaryKey("k1");
+ Map<String, String> mapSs = new HashMap<>();
+ mapSs.put("k1", "one");
+ jt.setConsistencyInfo(mapSs);
+
+ System.out.println(jt2.genDropTableQuery().getQuery());
+ assertEquals("DROP TABLE keyspace.table;",
+ jt2.genDropTableQuery().getQuery());
+ }
}
diff --git a/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonUpdateTest.java
index e00cb463..37c729f4 100644
--- a/music-core/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java
+++ b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonUpdateTest.java
@@ -22,14 +22,22 @@
* ====================================================================
*******************************************************************************/
-package org.onap.music.unittests.jsonobjects;
+package org.onap.music.datastore.jsonobjects;
import static org.junit.Assert.*;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import javax.ws.rs.core.MultivaluedMap;
import org.junit.Before;
import org.junit.Test;
-import org.onap.music.datastore.jsonobjects.JsonUpdate;
+import org.mockito.Mockito;
+import org.onap.music.datastore.jsonobjects.JsonUpdate.RowIdentifier;
+import com.datastax.driver.core.ColumnMetadata;
+import com.datastax.driver.core.DataType;
+import com.datastax.driver.core.TableMetadata;
public class JsonUpdateTest {
@@ -108,4 +116,51 @@ public class JsonUpdateTest {
assertTrue(ju.serialize() instanceof byte[]);
}
+ @Test
+ public void testRowIdString() {
+ ju.setRowIdString("testing");
+ assertEquals("testing", ju.getRowIdString());
+ }
+
+ @Test
+ public void testPrimaryKeyValue() {
+ ju.setPrimarKeyValue("primeKey");
+ assertEquals("primeKey", ju.getPrimarKeyValue());
+ }
+
+ @Test
+ public void testGenUpdatePreparedQueryObj() throws Exception {
+ JsonUpdate ju = Mockito.spy(JsonUpdate.class);
+ MultivaluedMap<String, String> rowParams = Mockito.mock(MultivaluedMap.class);
+
+ ju.setKeyspaceName("keyspace");
+ ju.setTableName("table");
+ ju.setPrimarKeyValue("primaryKeyValue");
+ Map<String, String> consistencyInfo = new HashMap<>();
+ consistencyInfo.put("type", "critical");
+ ju.setConsistencyInfo(consistencyInfo);
+ Map<String, Object> values = new HashMap<>();
+ values.put("col1", "val1");
+ ju.setValues(values);
+
+ TableMetadata tmd = Mockito.mock(TableMetadata.class);
+ Mockito.doReturn(tmd).when(ju).returnColumnMetadata(Mockito.anyString(), Mockito.anyString());
+ ColumnMetadata cmd = Mockito.mock(ColumnMetadata.class);
+ Mockito.when(tmd.getColumn("col1")).thenReturn(cmd);
+ List<ColumnMetadata> colList = new ArrayList<>();
+ colList.add(cmd);
+ Mockito.when(tmd.getPrimaryKey()).thenReturn(colList);
+ Mockito.when(cmd.getType()).thenReturn(DataType.varchar());
+
+ RowIdentifier rowId = Mockito.mock(RowIdentifier.class);
+ Mockito.doReturn(rowId).when(ju).getRowIdentifier(Mockito.anyString(), Mockito.anyString(), Mockito.any(),
+ Mockito.any());
+
+ Mockito.when(rowId.getRowIdString()).thenReturn("col1");
+ Mockito.when(rowId.getPrimaryKeyValue()).thenReturn("val1");
+
+
+ assertEquals("UPDATE keyspace.table SET vector_ts=?,col1= ? WHERE col1;",
+ ju.genUpdatePreparedQueryObj(rowParams).getQuery());
+ }
}
diff --git a/music-core/src/test/java/org/onap/music/unittests/ResultTypeTest.java b/music-core/src/test/java/org/onap/music/main/ResultTypeTest.java
index 012629e0..d6ccc1f1 100644
--- a/music-core/src/test/java/org/onap/music/unittests/ResultTypeTest.java
+++ b/music-core/src/test/java/org/onap/music/main/ResultTypeTest.java
@@ -20,11 +20,10 @@
* ====================================================================
*/
-package org.onap.music.unittests;
+package org.onap.music.main;
import static org.junit.Assert.*;
import org.junit.Test;
-import org.onap.music.main.ResultType;
public class ResultTypeTest {
diff --git a/music-core/src/test/java/org/onap/music/unittests/ReturnTypeTest.java b/music-core/src/test/java/org/onap/music/main/ReturnTypeTest.java
index 490020ac..fbb5f84d 100644
--- a/music-core/src/test/java/org/onap/music/unittests/ReturnTypeTest.java
+++ b/music-core/src/test/java/org/onap/music/main/ReturnTypeTest.java
@@ -20,7 +20,7 @@
* ====================================================================
*/
-package org.onap.music.unittests;
+package org.onap.music.main;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -28,8 +28,6 @@ import static org.junit.Assert.assertTrue;
import java.util.Map;
import org.junit.Test;
-import org.onap.music.main.ResultType;
-import org.onap.music.main.ReturnType;
public class ReturnTypeTest {
diff --git a/music-core/src/test/java/org/onap/music/unittests/CassandraCQL.java b/music-core/src/test/java/org/onap/music/unittests/CassandraCQL.java
deleted file mode 100644
index 582744fb..00000000
--- a/music-core/src/test/java/org/onap/music/unittests/CassandraCQL.java
+++ /dev/null
@@ -1,245 +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.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.List;
-import java.util.Map;
-import java.util.UUID;
-
-//import org.apache.thrift.transport.TTransportException;
-import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
-import org.onap.music.datastore.MusicDataStore;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.lockingservice.cassandra.LockType;
-import com.datastax.driver.core.Cluster;
-import com.datastax.driver.core.Session;
-import com.datastax.driver.extras.codecs.enums.EnumNameCodec;
-
-public class CassandraCQL {
- public static final String createAdminKeyspace = "CREATE KEYSPACE admin WITH REPLICATION = "
- + "{'class' : 'SimpleStrategy' , 'replication_factor': 1} AND DURABLE_WRITES = true";
-
- public static final String createAdminTable = "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" + ");";
-
- 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() throws Exception {
- System.setProperty("log4j.configuration", "log4j.properties");
-
- String address = "localhost";
-
- EmbeddedCassandraServerHelper.startEmbeddedCassandra();
- Cluster cluster = new Cluster.Builder().withoutJMXReporting().withoutMetrics().addContactPoint(address).withPort(9142).build();
- cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(5000);
-
- Session session = cluster.connect();
-
- return new MusicDataStore(cluster, session);
- }
-
-}