2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (c) 2019 AT&T Intellectual Property
6 * ===================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * ============LICENSE_END=============================================
20 * ====================================================================
23 package org.onap.music.unittests;
25 import static org.junit.Assert.assertEquals;
26 import java.math.BigInteger;
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.List;
31 import java.util.UUID;
32 import javax.servlet.http.HttpServletResponse;
33 import javax.ws.rs.core.MultivaluedHashMap;
34 import javax.ws.rs.core.MultivaluedMap;
35 import javax.ws.rs.core.Response;
36 import javax.ws.rs.core.UriInfo;
37 import org.junit.After;
38 import org.junit.AfterClass;
39 import org.junit.BeforeClass;
40 import org.junit.Ignore;
41 import org.junit.Test;
42 import org.junit.runner.RunWith;
43 import org.mindrot.jbcrypt.BCrypt;
44 import org.mockito.Mock;
45 import org.mockito.Mockito;
46 import org.mockito.junit.MockitoJUnitRunner;
47 import org.onap.music.datastore.MusicDataStoreHandle;
48 import org.onap.music.datastore.PreparedQueryObject;
49 import org.onap.music.datastore.jsonobjects.JsonDelete;
50 import org.onap.music.datastore.jsonobjects.JsonInsert;
51 import org.onap.music.datastore.jsonobjects.JsonKeySpace;
52 import org.onap.music.datastore.jsonobjects.JsonSelect;
53 import org.onap.music.datastore.jsonobjects.JsonTable;
54 import org.onap.music.datastore.jsonobjects.JsonUpdate;
55 import org.onap.music.exceptions.MusicServiceException;
56 import org.onap.music.main.MusicCore;
57 import org.onap.music.main.MusicUtil;
58 import org.onap.music.main.ResultType;
59 import org.onap.music.rest.RestMusicDataAPI;
60 import org.onap.music.rest.RestMusicLocksAPI;
61 import com.datastax.driver.core.DataType;
62 import com.datastax.driver.core.ResultSet;
63 import com.datastax.driver.core.Row;
64 import com.sun.jersey.core.util.Base64;
65 import com.sun.jersey.core.util.MultivaluedMapImpl;
67 @RunWith(MockitoJUnitRunner.class)
68 public class TstRestMusicDataAPI {
70 RestMusicDataAPI data = new RestMusicDataAPI();
71 RestMusicLocksAPI lock = new RestMusicLocksAPI();
72 static PreparedQueryObject testObject;
75 HttpServletResponse http;
80 static String appName = "TestApp";
81 static String userId = "TestUser";
82 static String password = "TestPassword";
83 static String authData = userId + ":" + password;
84 static String wrongAuthData = userId + ":" + "pass";
85 static String authorization = new String(Base64.encode(authData.getBytes()));
86 static String wrongAuthorization = new String(Base64.encode(wrongAuthData.getBytes()));
87 static boolean isAAF = false;
88 static UUID uuid = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40ce6");
89 static String keyspaceName = "testcassa";
90 static String tableName = "employees";
91 static String xLatestVersion = "X-latestVersion";
92 static String onboardUUID = null;
93 static String aid = TestsUsingCassandra.aid;
96 public static void init() throws Exception {
97 System.out.println("Testing RestMusicData class");
100 } catch (Exception e) {
102 throw new Exception("Unable to initialize before TestRestMusicData test class. " + e.getMessage());
107 public void afterEachTest() throws MusicServiceException {
108 clearAllTablesFromKeyspace();
112 public static void tearDownAfterClass() throws Exception {
113 testObject = new PreparedQueryObject();
114 testObject.appendQueryString("DROP KEYSPACE IF EXISTS " + keyspaceName);
115 MusicCore.eventualPut(testObject);
119 public void test1_createKeyspace() throws Exception {
120 System.out.println("Testing create keyspace");
121 JsonKeySpace jsonKeyspace = new JsonKeySpace();
122 Map<String, String> consistencyInfo = new HashMap<>();
123 Map<String, Object> replicationInfo = new HashMap<>();
124 consistencyInfo.put("type", "eventual");
125 replicationInfo.put("class", "SimpleStrategy");
126 replicationInfo.put("replication_factor", 1);
127 jsonKeyspace.setConsistencyInfo(consistencyInfo);
128 jsonKeyspace.setDurabilityOfWrites("true");
129 jsonKeyspace.setKeyspaceName(keyspaceName);
130 jsonKeyspace.setReplicationInfo(replicationInfo);
131 // Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
133 data.createKeySpace("1", "1", "1", null, authorization, appName, jsonKeyspace, keyspaceName);
134 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
135 assertEquals(400, response.getStatus());
136 Map<String, String> respMap = (Map<String, String>) response.getEntity();
137 assertEquals(ResultType.FAILURE, respMap.get("status"));
141 public void test1_createKeyspaceSuccess() throws Exception {
142 System.out.println("Testing successful creation and deletion of keyspace");
143 MusicUtil.setKeyspaceActive(true);
145 String keyspaceToCreate = "temp"+keyspaceName;
148 JsonKeySpace jsonKeyspace = new JsonKeySpace();
149 Map<String, String> consistencyInfo = new HashMap<>();
150 Map<String, Object> replicationInfo = new HashMap<>();
151 consistencyInfo.put("type", "eventual");
152 replicationInfo.put("class", "SimpleStrategy");
153 replicationInfo.put("replication_factor", 1);
154 jsonKeyspace.setConsistencyInfo(consistencyInfo);
155 jsonKeyspace.setDurabilityOfWrites("true");
156 //don't overwrite a keyspace we already have
157 jsonKeyspace.setKeyspaceName(keyspaceToCreate);
158 jsonKeyspace.setReplicationInfo(replicationInfo);
159 // Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
161 data.createKeySpace("1", "1", "1", null, authorization, appName, jsonKeyspace, keyspaceToCreate);
162 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
163 assertEquals(200, response.getStatus());
164 Map<String, String> respMap = (Map<String, String>) response.getEntity();
165 assertEquals(ResultType.SUCCESS, respMap.get("status"));
167 response = data.dropKeySpace("1", "1", "1", null, authorization, appName, keyspaceToCreate);
168 assertEquals(200, response.getStatus());
169 respMap = (Map<String, String>) response.getEntity();
170 assertEquals(ResultType.SUCCESS, respMap.get("status"));
172 //unset to not mess up any further tests
173 MusicUtil.setKeyspaceActive(false);
177 public void test3_createTable() throws Exception {
178 System.out.println("Testing create table");
179 JsonTable jsonTable = new JsonTable();
180 Map<String, String> consistencyInfo = new HashMap<>();
181 Map<String, String> fields = new HashMap<>();
182 fields.put("uuid", "text");
183 fields.put("emp_name", "text");
184 fields.put("emp_salary", "varint");
185 fields.put("PRIMARY KEY", "(emp_name)");
186 consistencyInfo.put("type", "eventual");
187 jsonTable.setConsistencyInfo(consistencyInfo);
188 jsonTable.setKeyspaceName(keyspaceName);
189 jsonTable.setPrimaryKey("emp_name");
190 jsonTable.setTableName(tableName);
191 jsonTable.setFields(fields);
192 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
193 authorization, jsonTable, keyspaceName, tableName);
194 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
195 assertEquals(200, response.getStatus());
199 public void test3_createTableNoName() throws Exception {
200 System.out.println("Testing create table without name");
201 JsonTable jsonTable = new JsonTable();
202 Map<String, String> consistencyInfo = new HashMap<>();
203 Map<String, String> fields = new HashMap<>();
204 fields.put("uuid", "text");
205 fields.put("emp_name", "text");
206 fields.put("emp_salary", "varint");
207 fields.put("PRIMARY KEY", "(emp_name)");
208 consistencyInfo.put("type", "eventual");
209 jsonTable.setConsistencyInfo(consistencyInfo);
210 jsonTable.setKeyspaceName(keyspaceName);
211 jsonTable.setPrimaryKey("emp_name");
212 jsonTable.setTableName("");
213 jsonTable.setFields(fields);
214 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
215 authorization, jsonTable, keyspaceName, "");
216 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
217 assertEquals(400, response.getStatus());
221 public void test3_createTableNoFields() throws Exception {
222 System.out.println("Testing create table without fields");
223 JsonTable jsonTable = new JsonTable();
224 Map<String, String> consistencyInfo = new HashMap<>();
225 consistencyInfo.put("type", "eventual");
226 jsonTable.setConsistencyInfo(consistencyInfo);
227 jsonTable.setKeyspaceName(keyspaceName);
228 jsonTable.setPrimaryKey("emp_name");
229 jsonTable.setTableName("");
230 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
231 authorization, jsonTable, keyspaceName, "");
232 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
233 assertEquals(400, response.getStatus());
238 public void test3_createTableClusterOrderBad() throws Exception {
239 System.out.println("Testing create table bad clustering");
240 JsonTable jsonTable = new JsonTable();
241 Map<String, String> consistencyInfo = new HashMap<>();
242 Map<String, String> fields = new HashMap<>();
243 fields.put("uuid", "text");
244 fields.put("emp_name", "text");
245 fields.put("emp_salary", "varint");
246 fields.put("PRIMARY KEY", "(emp_name,emp_salary)");
247 consistencyInfo.put("type", "eventual");
248 jsonTable.setConsistencyInfo(consistencyInfo);
249 jsonTable.setKeyspaceName(keyspaceName);
250 jsonTable.setPrimaryKey("emp_name,emp_salary");
251 jsonTable.setClusteringOrder("ASC");
252 jsonTable.setTableName(tableName);
253 jsonTable.setFields(fields);
254 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
255 authorization, jsonTable, keyspaceName, tableName);
256 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
257 assertEquals(400, response.getStatus());
261 public void test3_createTable_withPropertiesNotNull() throws Exception {
262 System.out.println("Testing create table with properties");
263 JsonTable jsonTable = new JsonTable();
264 Map<String, String> consistencyInfo = new HashMap<>();
265 Map<String, String> fields = new HashMap<>();
266 fields.put("uuid", "text");
267 fields.put("emp_name", "text");
268 fields.put("emp_salary", "varint");
269 fields.put("PRIMARY KEY", "(emp_name)");
270 consistencyInfo.put("type", "eventual");
271 Map<String, Object> properties = new HashMap<>();
272 properties.put("comment", "Testing prperties not null");
273 jsonTable.setConsistencyInfo(consistencyInfo);
274 jsonTable.setKeyspaceName(keyspaceName);
275 jsonTable.setPrimaryKey("emp_name");
276 String tableName_prop = tableName + "_Prop";
277 jsonTable.setTableName(tableName_prop);
278 jsonTable.setFields(fields);
279 jsonTable.setProperties(properties);
281 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
282 authorization, jsonTable, keyspaceName, tableName_prop);
283 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
284 assertEquals(200, response.getStatus());
288 public void test3_createTable_duplicateTable() throws Exception {
289 System.out.println("Testing creating duplicate tables");
290 JsonTable jsonTable = new JsonTable();
291 Map<String, String> consistencyInfo = new HashMap<>();
292 Map<String, String> fields = new HashMap<>();
293 fields.put("uuid", "text");
294 fields.put("emp_name", "text");
295 fields.put("emp_salary", "varint");
296 fields.put("PRIMARY KEY", "(emp_name)");
297 consistencyInfo.put("type", "eventual");
298 jsonTable.setConsistencyInfo(consistencyInfo);
299 jsonTable.setKeyspaceName(keyspaceName);
300 jsonTable.setPrimaryKey("emp_name");
301 String tableNameDup = tableName + "x";
302 jsonTable.setTableName(tableNameDup);
303 jsonTable.setFields(fields);
304 // Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
305 Response response1 = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
306 authorization, jsonTable, keyspaceName, tableNameDup);
308 Response response2 = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
309 authorization, jsonTable, keyspaceName, tableNameDup);
310 System.out.println("Status: " + response2.getStatus() + ". Entity " + response2.getEntity());
312 assertEquals(400, response2.getStatus());
313 Map<String, String> respMap = (Map<String, String>) response2.getEntity();
314 assertEquals(ResultType.FAILURE, respMap.get("status"));
315 assertEquals("Table " + keyspaceName + "." + tableNameDup + " already exists", respMap.get("error"));
319 // Improper parenthesis in key field
321 public void test3_createTable_badParanthesis() throws Exception {
322 System.out.println("Testing malformed create table request");
323 String tableNameC = "testTable0";
324 JsonTable jsonTable = new JsonTable();
325 Map<String, String> consistencyInfo = new HashMap<>();
326 Map<String, String> fields = new HashMap<>();
327 fields.put("uuid", "text");
328 fields.put("emp_name", "text");
329 fields.put("emp_salary", "varint");
330 fields.put("PRIMARY KEY", "(emp_name),emp_id)");
331 fields.put("emp_id", "varint");
332 consistencyInfo.put("type", "eventual");
333 jsonTable.setConsistencyInfo(consistencyInfo);
334 jsonTable.setKeyspaceName(keyspaceName);
335 jsonTable.setPrimaryKey("emp_name");
336 jsonTable.setTableName(tableNameC);
337 jsonTable.setClusteringOrder("emp_id Desc");
338 jsonTable.setFields(fields);
339 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
340 authorization, jsonTable, keyspaceName, tableNameC);
341 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
343 assertEquals(400, response.getStatus());
347 // good clustering key
349 public void test3_createTable_1_clusterKey_good() throws Exception {
350 System.out.println("Testing create w/ clusterKey");
352 String tableNameC = "testTableC1";
353 JsonTable jsonTable = new JsonTable();
354 Map<String, String> consistencyInfo = new HashMap<>();
355 Map<String, String> fields = new HashMap<>();
356 fields.put("uuid", "text");
357 fields.put("emp_name", "text");
358 fields.put("emp_salary", "varint");
359 fields.put("PRIMARY KEY", "((emp_name),emp_salary)");
360 consistencyInfo.put("type", "eventual");
361 jsonTable.setConsistencyInfo(consistencyInfo);
362 jsonTable.setKeyspaceName(keyspaceName);
363 // jsonTable.setPrimaryKey("emp_name");
364 jsonTable.setTableName(tableNameC);
365 jsonTable.setClusteringOrder("emp_salary ASC");
366 jsonTable.setFields(fields);
367 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
368 authorization, jsonTable, keyspaceName, tableNameC);
369 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
371 assertEquals(200, response.getStatus());
374 // bad partition key=clustering key
376 public void test3_createTable_2_clusterKey_bad() throws Exception {
377 System.out.println("Testing create w/ bad clusterKey");
378 String tableNameC = "testTableC2";
379 JsonTable jsonTable = new JsonTable();
380 Map<String, String> consistencyInfo = new HashMap<>();
381 Map<String, String> fields = new HashMap<>();
382 fields.put("uuid", "text");
383 fields.put("emp_name", "text");
384 fields.put("emp_salary", "varint");
385 fields.put("PRIMARY KEY", "((emp_name),emp_name)");
386 consistencyInfo.put("type", "eventual");
387 jsonTable.setConsistencyInfo(consistencyInfo);
388 jsonTable.setKeyspaceName(keyspaceName);
389 jsonTable.setPrimaryKey("emp_name"); // "PRIMARY KEY" overrides if primaryKey present
390 jsonTable.setTableName(tableNameC);
391 jsonTable.setClusteringOrder("emp_salary ASC");
392 jsonTable.setFields(fields);
393 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
394 authorization, jsonTable, keyspaceName, tableNameC);
395 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
397 assertEquals(400, response.getStatus());
400 // good composite partition key,clustering key
402 public void test3_createTable_3_pfartition_clusterKey_good() throws Exception {
403 System.out.println("Testing create w/ composite partition key, clusterKey");
405 String tableNameC = "testTableC3";
406 JsonTable jsonTable = new JsonTable();
407 Map<String, String> consistencyInfo = new HashMap<>();
408 Map<String, String> fields = new HashMap<>();
409 fields.put("uuid", "text");
410 fields.put("emp_name", "text");
411 fields.put("emp_id", "varint");
412 fields.put("emp_salary", "varint");
413 fields.put("PRIMARY KEY", "((emp_name,emp_id),emp_salary)");
414 consistencyInfo.put("type", "eventual");
415 jsonTable.setConsistencyInfo(consistencyInfo);
416 jsonTable.setKeyspaceName(keyspaceName);
417 jsonTable.setPrimaryKey("emp_name");
418 jsonTable.setTableName(tableNameC);
419 jsonTable.setClusteringOrder("emp_salary ASC");
420 jsonTable.setFields(fields);
421 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
422 authorization, jsonTable, keyspaceName, tableNameC);
423 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
425 assertEquals(200, response.getStatus());
428 // bad - wrong cols in order by of composite partition key,clustering key
430 public void test3_createTable_5_clusteringOrder_bad() throws Exception {
431 System.out.println("Testing create table bad request with clustering & composite keys");
432 String tableNameC = "testTableC5";
433 JsonTable jsonTable = new JsonTable();
434 Map<String, String> consistencyInfo = new HashMap<>();
435 Map<String, String> fields = new HashMap<>();
436 fields.put("uuid", "text");
437 fields.put("emp_name", "text");
438 fields.put("emp_id", "varint");
439 fields.put("emp_salary", "varint");
440 fields.put("PRIMARY KEY", "((uuid,emp_name),emp_id,emp_salary)");
441 consistencyInfo.put("type", "eventual");
442 jsonTable.setConsistencyInfo(consistencyInfo);
443 jsonTable.setKeyspaceName(keyspaceName);
444 jsonTable.setPrimaryKey("emp_name");
445 jsonTable.setTableName(tableNameC);
446 jsonTable.setClusteringOrder("emp_idx desc, emp_salary ASC");
447 jsonTable.setFields(fields);
448 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
449 authorization, jsonTable, keyspaceName, tableNameC);
450 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
452 assertEquals(400, response.getStatus());
456 // good clustering key, need to pass queryparameter
458 public void test3_createTableIndex_1() throws Exception {
459 System.out.println("Testing index in create table");
460 String tableNameC = "testTableCinx";
461 JsonTable jsonTable = new JsonTable();
462 Map<String, String> consistencyInfo = new HashMap<>();
463 Map<String, String> fields = new HashMap<>();
464 fields.put("uuid", "text");
465 fields.put("emp_name", "text");
466 fields.put("emp_salary", "varint");
467 fields.put("PRIMARY KEY", "((emp_name),emp_salary)");
468 consistencyInfo.put("type", "eventual");
469 jsonTable.setConsistencyInfo(consistencyInfo);
470 jsonTable.setKeyspaceName(keyspaceName);
471 jsonTable.setTableName(tableNameC);
472 jsonTable.setClusteringOrder("emp_salary ASC");
473 jsonTable.setFields(fields);
474 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
475 authorization, jsonTable, keyspaceName, tableNameC);
476 // if 200 print to log otherwise fail assertEquals(200, response.getStatus());
477 // info.setQueryParameters("index_name=inx_uuid");
478 Map<String, String> queryParametersMap = new HashMap<String, String>();
480 queryParametersMap.put("index_name", "inxuuid");
481 Mockito.when(info.getQueryParameters()).thenReturn(new MultivaluedHashMap<String, String>(queryParametersMap));
482 response = data.createIndex("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
483 keyspaceName, tableNameC, "uuid", info);
484 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
486 assertEquals(200, response.getStatus());
489 // create index without table name
491 public void test3_createTableIndexNoName() throws Exception {
492 System.out.println("Testing index in create table w/o tablename");
493 String tableNameC = "testTableCinx";
494 JsonTable jsonTable = new JsonTable();
495 Map<String, String> consistencyInfo = new HashMap<>();
496 Map<String, String> fields = new HashMap<>();
497 fields.put("uuid", "text");
498 fields.put("emp_name", "text");
499 fields.put("emp_salary", "varint");
500 fields.put("PRIMARY KEY", "((emp_name),emp_salary)");
501 consistencyInfo.put("type", "eventual");
502 jsonTable.setConsistencyInfo(consistencyInfo);
503 jsonTable.setKeyspaceName(keyspaceName);
504 jsonTable.setTableName(tableNameC);
505 jsonTable.setClusteringOrder("emp_salary ASC");
506 jsonTable.setFields(fields);
507 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
508 authorization, jsonTable, keyspaceName, tableNameC);
509 // if 200 print to log otherwise fail assertEquals(200, response.getStatus());
510 // info.setQueryParameters("index_name=inx_uuid");
511 Map<String, String> queryParametersMap = new HashMap<String, String>();
513 queryParametersMap.put("index_name", "inxuuid");
514 response = data.createIndex("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, "",
516 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
518 assertEquals(400, response.getStatus());
522 public void test4_insertIntoTable() throws Exception {
523 System.out.println("Testing insert into table");
525 JsonInsert jsonInsert = new JsonInsert();
526 Map<String, String> consistencyInfo = new HashMap<>();
527 Map<String, Object> values = new HashMap<>();
528 values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
529 values.put("emp_name", "testname");
530 values.put("emp_salary", 500);
531 consistencyInfo.put("type", "eventual");
532 jsonInsert.setConsistencyInfo(consistencyInfo);
533 jsonInsert.setKeyspaceName(keyspaceName);
534 jsonInsert.setTableName(tableName);
535 jsonInsert.setValues(values);
536 Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
537 authorization, jsonInsert, keyspaceName, tableName);
538 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
540 assertEquals(200, response.getStatus());
544 public void test4_insertIntoTableNoValues() throws Exception {
545 System.out.println("Testing insert into table");
547 JsonInsert jsonInsert = new JsonInsert();
548 Map<String, String> consistencyInfo = new HashMap<>();
549 consistencyInfo.put("type", "eventual");
550 jsonInsert.setConsistencyInfo(consistencyInfo);
551 jsonInsert.setKeyspaceName(keyspaceName);
552 jsonInsert.setTableName(tableName);
554 Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
555 authorization, jsonInsert, keyspaceName, tableName);
556 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
558 assertEquals(400, response.getStatus());
562 public void test4_insertIntoTableCriticalNoLockID() throws Exception {
563 System.out.println("Testing critical insert into table without lockid");
565 JsonInsert jsonInsert = new JsonInsert();
566 Map<String, String> consistencyInfo = new HashMap<>();
567 Map<String, Object> values = new HashMap<>();
568 values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
569 values.put("emp_name", "testname");
570 values.put("emp_salary", 500);
571 consistencyInfo.put("type", "critical");
572 jsonInsert.setConsistencyInfo(consistencyInfo);
573 jsonInsert.setKeyspaceName(keyspaceName);
574 jsonInsert.setTableName(tableName);
575 jsonInsert.setValues(values);
576 Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
577 appName, authorization, jsonInsert, keyspaceName, tableName);
578 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
580 assertEquals(400, response.getStatus());
584 public void test4_insertIntoTableAtomic() throws Exception {
585 System.out.println("Testing atomic insert into table without lockid");
587 JsonInsert jsonInsert = new JsonInsert();
588 Map<String, String> consistencyInfo = new HashMap<>();
589 Map<String, Object> values = new HashMap<>();
590 values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
591 values.put("emp_name", "testname");
592 values.put("emp_salary", 500);
593 consistencyInfo.put("type", "atomic");
594 jsonInsert.setConsistencyInfo(consistencyInfo);
595 jsonInsert.setKeyspaceName(keyspaceName);
596 jsonInsert.setTableName(tableName);
597 jsonInsert.setValues(values);
598 Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
599 appName, authorization, jsonInsert, keyspaceName, tableName);
600 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
602 assertEquals(200, response.getStatus());
606 public void test4_insertIntoTableNoName() throws Exception {
607 System.out.println("Testing insert into table w/o table name");
609 JsonInsert jsonInsert = new JsonInsert();
610 Map<String, String> consistencyInfo = new HashMap<>();
611 Map<String, Object> values = new HashMap<>();
612 values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
613 values.put("emp_name", "testname");
614 values.put("emp_salary", 500);
615 consistencyInfo.put("type", "eventual");
616 jsonInsert.setConsistencyInfo(consistencyInfo);
617 jsonInsert.setKeyspaceName(keyspaceName);
618 jsonInsert.setTableName(tableName);
619 jsonInsert.setValues(values);
620 Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
621 appName, authorization, jsonInsert, "", "");
622 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
624 assertEquals(400, response.getStatus());
628 public void test4_insertIntoTable2() throws Exception {
629 System.out.println("Testing insert into table #2");
631 JsonInsert jsonInsert = new JsonInsert();
632 Map<String, String> consistencyInfo = new HashMap<>();
633 Map<String, Object> values = new HashMap<>();
634 values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
635 values.put("emp_name", "test1");
636 values.put("emp_salary", 1500);
637 consistencyInfo.put("type", "eventual");
638 jsonInsert.setConsistencyInfo(consistencyInfo);
639 jsonInsert.setKeyspaceName(keyspaceName);
640 jsonInsert.setTableName(tableName);
641 jsonInsert.setValues(values);
642 Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
643 authorization, jsonInsert, keyspaceName, tableName);
644 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
646 assertEquals(200, response.getStatus());
651 public void test4_insertIntoTable4() throws Exception {
652 System.out.println("Testing insert into wrong table");
654 JsonInsert jsonInsert = new JsonInsert();
655 Map<String, String> consistencyInfo = new HashMap<>();
656 Map<String, Object> values = new HashMap<>();
657 values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
658 values.put("emp_name", "test1");
659 values.put("emp_salary", 1500);
660 consistencyInfo.put("type", "eventual");
661 jsonInsert.setConsistencyInfo(consistencyInfo);
662 jsonInsert.setKeyspaceName(keyspaceName);
663 jsonInsert.setTableName(tableName);
664 jsonInsert.setValues(values);
665 Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
666 authorization, jsonInsert, keyspaceName, "wrong");
667 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
669 assertEquals(400, response.getStatus());
673 public void test4_insertBlobIntoTable() throws Exception {
674 System.out.println("Testing insert a blob into table");
676 JsonInsert jsonInsert = new JsonInsert();
677 Map<String, String> consistencyInfo = new HashMap<>();
678 Map<String, Object> values = new HashMap<>();
679 values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
680 values.put("emp_name", "testname");
681 values.put("emp_salary", 500);
682 values.put("binary", "somestuffhere");
683 consistencyInfo.put("type", "eventual");
684 jsonInsert.setConsistencyInfo(consistencyInfo);
685 jsonInsert.setKeyspaceName(keyspaceName);
686 jsonInsert.setTableName(tableName);
687 jsonInsert.setValues(values);
688 Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
689 authorization, jsonInsert, keyspaceName, tableName);
690 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
692 assertEquals(200, response.getStatus());
696 public void test5_updateTable() throws Exception {
697 System.out.println("Testing update table");
700 JsonUpdate jsonUpdate = new JsonUpdate();
701 Map<String, String> consistencyInfo = new HashMap<>();
702 MultivaluedMap<String, String> row = new MultivaluedMapImpl();
703 Map<String, Object> values = new HashMap<>();
704 row.add("emp_name", "testname");
705 values.put("emp_salary", 2500);
706 consistencyInfo.put("type", "atomic");
707 jsonUpdate.setConsistencyInfo(consistencyInfo);
708 jsonUpdate.setKeyspaceName(keyspaceName);
709 jsonUpdate.setTableName(tableName);
710 jsonUpdate.setValues(values);
711 Mockito.when(info.getQueryParameters()).thenReturn(row);
712 Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
713 authorization, jsonUpdate, keyspaceName, tableName, info);
715 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
717 assertEquals(200, response.getStatus());
721 public void test5_updateTableNoBody() throws Exception {
722 System.out.println("Testing update table no body");
725 Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
726 authorization, null, keyspaceName, tableName, info);
728 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
730 assertEquals(400, response.getStatus());
734 public void test5_updateTable_tableDNE() throws Exception {
735 System.out.println("Testing update table that does not exist");
738 JsonUpdate jsonUpdate = new JsonUpdate();
739 Map<String, String> consistencyInfo = new HashMap<>();
740 Map<String, Object> values = new HashMap<>();
741 values.put("emp_salary", 2500);
742 consistencyInfo.put("type", "atomic");
743 jsonUpdate.setConsistencyInfo(consistencyInfo);
744 jsonUpdate.setKeyspaceName(keyspaceName);
745 jsonUpdate.setTableName("wrong_"+tableName);
746 jsonUpdate.setValues(values);
747 Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
748 authorization, jsonUpdate, keyspaceName, "wrong_"+ tableName, info);
750 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
752 assertEquals(400, response.getStatus());
756 public void test5_updateTableNoName() throws Exception {
757 System.out.println("Testing update table without tablename");
760 JsonUpdate jsonUpdate = new JsonUpdate();
761 Map<String, String> consistencyInfo = new HashMap<>();
762 Map<String, Object> values = new HashMap<>();
763 values.put("emp_salary", 2500);
764 consistencyInfo.put("type", "atomic");
765 jsonUpdate.setConsistencyInfo(consistencyInfo);
766 jsonUpdate.setKeyspaceName(keyspaceName);
767 jsonUpdate.setTableName(tableName);
768 jsonUpdate.setValues(values);
769 Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
770 authorization, jsonUpdate, "", "", info);
772 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
774 assertEquals(400, response.getStatus());
777 // need mock code to create error for MusicCore methods
779 public void test5_updateTableAuthE() throws Exception {
780 System.out.println("Testing update table #2");
782 // MockitoAnnotations.initMocks(this);
783 JsonUpdate jsonUpdate = new JsonUpdate();
784 Map<String, String> consistencyInfo = new HashMap<>();
785 MultivaluedMap<String, String> row = new MultivaluedMapImpl();
786 Map<String, Object> values = new HashMap<>();
787 row.add("emp_name", "testname");
788 values.put("emp_salary", 2500);
789 consistencyInfo.put("type", "atomic");
790 jsonUpdate.setConsistencyInfo(consistencyInfo);
791 jsonUpdate.setKeyspaceName(keyspaceName);
792 jsonUpdate.setTableName(tableName);
793 jsonUpdate.setValues(values);
794 // add ttl & timestamp
795 // Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
796 Mockito.when(info.getQueryParameters()).thenReturn(row);
797 // Map<String, Object> m1= new HashMap<>() ;
798 // Mockito.when(MusicCore.autheticateUser(appName,userId,password,keyspaceName,"abc66ccc-d857-4e90-b1e5-df98a3d40ce6","updateTable")).thenReturn(m1);
799 Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
800 authorization, jsonUpdate, keyspaceName, tableName, info);
801 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
803 assertEquals(200, response.getStatus());
807 public void test6_critical_selectAtomic() throws Exception {
808 System.out.println("Testing critical select atomic");
809 createAndInsertIntoTable();
810 JsonInsert jsonInsert = new JsonInsert();
811 Map<String, String> consistencyInfo = new HashMap<>();
812 MultivaluedMap<String, String> row = new MultivaluedMapImpl();
813 row.add("emp_name", "testname");
814 consistencyInfo.put("type", "atomic");
815 jsonInsert.setConsistencyInfo(consistencyInfo);
816 Mockito.when(info.getQueryParameters()).thenReturn(row);
817 Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
818 appName, authorization, jsonInsert, keyspaceName, tableName,info);
819 HashMap<String,HashMap<String,Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
820 HashMap<String, Object> result = map.get("result");
821 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
823 Map<String, String> row0 = (Map<String, String>) result.get("row 0");
824 assertEquals("testname", row0.get("emp_name"));
825 assertEquals(BigInteger.valueOf(500), row0.get("emp_salary"));
830 public void test6_critical_selectCritical_nolockid() throws Exception {
831 System.out.println("Testing critical select critical w/o lockid");
832 createAndInsertIntoTable();
833 JsonInsert jsonInsert = new JsonInsert();
834 Map<String, String> consistencyInfo = new HashMap<>();
835 MultivaluedMap<String, String> row = new MultivaluedMapImpl();
836 row.add("emp_name", "testname");
837 consistencyInfo.put("type", "critical");
838 jsonInsert.setConsistencyInfo(consistencyInfo);
839 Mockito.when(info.getQueryParameters()).thenReturn(row);
840 Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
841 appName, authorization, jsonInsert, keyspaceName, tableName,info);
842 HashMap<String,HashMap<String,Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
843 HashMap<String, Object> result = map.get("result");
844 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
846 assertEquals(400, response.getStatus());
850 public void test6_critical_select_nulltable() throws Exception {
851 System.out.println("Testing critical select w/ null tablename");
852 createAndInsertIntoTable();
853 JsonInsert jsonInsert = new JsonInsert();
854 Map<String, String> consistencyInfo = new HashMap<>();
855 consistencyInfo.put("type", "atomic");
856 jsonInsert.setConsistencyInfo(consistencyInfo);
857 Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
858 appName, authorization, jsonInsert, keyspaceName, null,info);
859 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
861 assertEquals(400, response.getStatus());
865 public void test6_select() throws Exception {
866 System.out.println("Testing select");
867 createAndInsertIntoTable();
868 JsonSelect jsonSelect = new JsonSelect();
869 Map<String, String> consistencyInfo = new HashMap<>();
870 MultivaluedMap<String, String> row = new MultivaluedMapImpl();
871 row.add("emp_name", "testname");
872 consistencyInfo.put("type", "atomic");
873 jsonSelect.setConsistencyInfo(consistencyInfo);
874 Mockito.when(info.getQueryParameters()).thenReturn(row);
875 Response response = data.select("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
876 keyspaceName, tableName, info);
877 HashMap<String, HashMap<String, Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
878 HashMap<String, Object> result = map.get("result");
879 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
881 Map<String, String> row0 = (Map<String, String>) result.get("row 0");
882 assertEquals("testname", row0.get("emp_name"));
883 assertEquals(BigInteger.valueOf(500), row0.get("emp_salary"));
887 public void test6_select_nullTablename() throws Exception {
888 System.out.println("Testing select w/ null tablename");
889 createAndInsertIntoTable();
890 JsonSelect jsonSelect = new JsonSelect();
891 Map<String, String> consistencyInfo = new HashMap<>();
892 consistencyInfo.put("type", "atomic");
893 jsonSelect.setConsistencyInfo(consistencyInfo);
894 Response response = data.select("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
895 appName, wrongAuthorization, keyspaceName, null, info);
896 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
898 assertEquals(400, response.getStatus());
902 public void test6_deleteFromTable() throws Exception {
903 System.out.println("Testing delete from table");
904 createAndInsertIntoTable();
905 JsonDelete jsonDelete = new JsonDelete();
906 Map<String, String> consistencyInfo = new HashMap<>();
907 MultivaluedMap<String, String> row = new MultivaluedMapImpl();
908 row.add("emp_name", "test1");
909 consistencyInfo.put("type", "atomic");
910 jsonDelete.setConsistencyInfo(consistencyInfo);
911 Mockito.when(info.getQueryParameters()).thenReturn(row);
912 Response response = data.deleteFromTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
913 authorization, jsonDelete, keyspaceName, tableName, info);
914 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
915 assertEquals(200, response.getStatus());
919 public void test6_deleteFromTable_missingTablename() throws Exception {
920 System.out.println("Testing delete from table w/ null tablename");
921 createAndInsertIntoTable();
922 JsonDelete jsonDelete = new JsonDelete();
923 Map<String, String> consistencyInfo = new HashMap<>();
924 consistencyInfo.put("type", "atomic");
925 jsonDelete.setConsistencyInfo(consistencyInfo);
926 Response response = data.deleteFromTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
927 wrongAuthorization, jsonDelete, keyspaceName, null, info);
928 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
929 assertEquals(400, response.getStatus());
935 public void test6_deleteFromTable1() throws Exception {
936 System.out.println("Testing delete from table missing delete object");
937 createAndInsertIntoTable();
939 JsonDelete jsonDelete = new JsonDelete();
940 Map<String, String> consistencyInfo = new HashMap<>();
941 MultivaluedMap<String, String> row = new MultivaluedMapImpl();
942 consistencyInfo.put("type", "atomic");
943 jsonDelete.setConsistencyInfo(consistencyInfo);
944 Mockito.when(info.getQueryParameters()).thenReturn(row);
945 Response response = data.deleteFromTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
946 authorization, jsonDelete, keyspaceName, tableName, info);
947 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
949 assertEquals(400, response.getStatus());
954 public void test6_deleteFromTable2() throws Exception {
955 System.out.println("Testing delete from table missing delete object");
956 createAndInsertIntoTable();
957 JsonDelete jsonDelete = new JsonDelete();
958 Map<String, String> consistencyInfo = new HashMap<>();
959 consistencyInfo.put("type", "atomic");
960 jsonDelete.setConsistencyInfo(consistencyInfo);
961 Response response = data.deleteFromTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
962 authorization, null, keyspaceName, tableName, info);
963 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
965 assertEquals(400, response.getStatus());
969 public void test7_dropTable() throws Exception {
970 System.out.println("Testing drop table");
972 JsonTable jsonTable = new JsonTable();
973 Map<String, String> consistencyInfo = new HashMap<>();
974 consistencyInfo.put("type", "atomic");
975 jsonTable.setConsistencyInfo(consistencyInfo);
976 Response response = data.dropTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
977 authorization, keyspaceName, tableName);
978 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
980 assertEquals(200, response.getStatus());
984 public void test7_dropTable_nullTablename() throws Exception {
985 System.out.println("Testing drop table w/ null tablename");
987 JsonTable jsonTable = new JsonTable();
988 Map<String, String> consistencyInfo = new HashMap<>();
989 consistencyInfo.put("type", "atomic");
990 jsonTable.setConsistencyInfo(consistencyInfo);
991 Response response = data.dropTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
992 authorization, keyspaceName, null);
993 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
995 assertEquals(400, response.getStatus());
1000 public void test8_deleteKeyspace() throws Exception {
1001 System.out.println("Testing drop keyspace");
1003 JsonKeySpace jsonKeyspace = new JsonKeySpace();
1004 Map<String, String> consistencyInfo = new HashMap<>();
1005 Map<String, Object> replicationInfo = new HashMap<>();
1006 consistencyInfo.put("type", "eventual");
1007 replicationInfo.put("class", "SimpleStrategy");
1008 replicationInfo.put("replication_factor", 1);
1009 jsonKeyspace.setConsistencyInfo(consistencyInfo);
1010 jsonKeyspace.setDurabilityOfWrites("true");
1011 jsonKeyspace.setKeyspaceName("TestApp1");
1012 jsonKeyspace.setReplicationInfo(replicationInfo);
1013 Response response = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", authorization,
1014 appName, keyspaceName);
1015 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
1017 assertEquals(400, response.getStatus());
1020 private static void createKeyspace() throws Exception {
1021 // shouldn't really be doing this here, but create keyspace is currently turned off
1022 PreparedQueryObject query = new PreparedQueryObject();
1023 query.appendQueryString(CassandraCQL.createKeySpace);
1024 MusicCore.eventualPut(query);
1026 boolean isAAF = false;
1027 String hashedpwd = BCrypt.hashpw(password, BCrypt.gensalt());
1028 query = new PreparedQueryObject();
1029 query.appendQueryString("INSERT into admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
1030 + "password, username, is_aaf) values (?,?,?,?,?,?,?)");
1031 query.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
1032 query.addValue(MusicUtil.convertToActualDataType(DataType.text(), keyspaceName));
1033 query.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
1034 query.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
1035 query.addValue(MusicUtil.convertToActualDataType(DataType.text(), hashedpwd));
1036 query.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
1037 query.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
1038 MusicCore.eventualPut(query);
1041 private void clearAllTablesFromKeyspace() throws MusicServiceException {
1042 ArrayList<String> tableNames = new ArrayList<>();
1043 PreparedQueryObject query = new PreparedQueryObject();
1044 query.appendQueryString(
1045 "SELECT table_name FROM system_schema.tables WHERE keyspace_name = '" + keyspaceName + "';");
1046 ResultSet rs = MusicCore.get(query);
1047 for (Row row : rs) {
1048 tableNames.add(row.getString("table_name"));
1050 for (String table : tableNames) {
1051 query = new PreparedQueryObject();
1052 query.appendQueryString("DROP TABLE " + keyspaceName + "." + table);
1053 MusicCore.eventualPut(query);
1058 * Create a table {@link tableName} in {@link keyspaceName}
1062 private void createTable() throws Exception {
1063 JsonTable jsonTable = new JsonTable();
1064 Map<String, String> consistencyInfo = new HashMap<>();
1065 Map<String, String> fields = new HashMap<>();
1066 fields.put("uuid", "text");
1067 fields.put("emp_name", "text");
1068 fields.put("emp_salary", "varint");
1069 fields.put("binary", "blob");
1070 fields.put("PRIMARY KEY", "(emp_name)");
1071 consistencyInfo.put("type", "eventual");
1072 jsonTable.setConsistencyInfo(consistencyInfo);
1073 jsonTable.setKeyspaceName(keyspaceName);
1074 jsonTable.setPrimaryKey("emp_name");
1075 jsonTable.setTableName(tableName);
1076 jsonTable.setFields(fields);
1077 // Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
1078 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
1079 authorization, jsonTable, keyspaceName, tableName);
1083 * Create table {@link createTable} and insert into said table
1087 private void createAndInsertIntoTable() throws Exception {
1090 JsonInsert jsonInsert = new JsonInsert();
1091 Map<String, String> consistencyInfo = new HashMap<>();
1092 Map<String, Object> values = new HashMap<>();
1093 values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
1094 values.put("emp_name", "testname");
1095 values.put("emp_salary", 500);
1096 values.put("binary", "binarydatahere");
1097 consistencyInfo.put("type", "eventual");
1098 jsonInsert.setConsistencyInfo(consistencyInfo);
1099 jsonInsert.setKeyspaceName(keyspaceName);
1100 jsonInsert.setTableName(tableName);
1101 jsonInsert.setValues(values);
1102 Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
1103 authorization, jsonInsert, keyspaceName, tableName);