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.authentication.CachingUtil;
48 import org.onap.music.datastore.MusicDataStoreHandle;
49 import org.onap.music.datastore.PreparedQueryObject;
50 import org.onap.music.datastore.jsonobjects.JsonDelete;
51 import org.onap.music.datastore.jsonobjects.JsonInsert;
52 import org.onap.music.datastore.jsonobjects.JsonKeySpace;
53 import org.onap.music.datastore.jsonobjects.JsonSelect;
54 import org.onap.music.datastore.jsonobjects.JsonTable;
55 import org.onap.music.datastore.jsonobjects.JsonUpdate;
56 import org.onap.music.exceptions.MusicServiceException;
57 import org.onap.music.main.MusicCore;
58 import org.onap.music.main.MusicUtil;
59 import org.onap.music.main.ResultType;
60 import org.onap.music.rest.RestMusicDataAPI;
61 import org.onap.music.rest.RestMusicLocksAPI;
62 import com.datastax.driver.core.DataType;
63 import com.datastax.driver.core.ResultSet;
64 import com.datastax.driver.core.Row;
65 import com.sun.jersey.core.util.Base64;
66 import com.sun.jersey.core.util.MultivaluedMapImpl;
68 @RunWith(MockitoJUnitRunner.class)
69 public class TstRestMusicDataAPI {
71 RestMusicDataAPI data = new RestMusicDataAPI();
72 RestMusicLocksAPI lock = new RestMusicLocksAPI();
73 static PreparedQueryObject testObject;
76 HttpServletResponse http;
81 static String appName = "TestApp";
82 static String userId = "TestUser";
83 static String password = "TestPassword";
84 static String authData = userId + ":" + password;
85 static String wrongAuthData = userId + ":" + "pass";
86 static String authorization = new String(Base64.encode(authData.getBytes()));
87 static String wrongAuthorization = new String(Base64.encode(wrongAuthData.getBytes()));
88 static boolean isAAF = false;
89 static UUID uuid = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40ce6");
90 static String keyspaceName = "testcassa";
91 static String tableName = "employees";
92 static String xLatestVersion = "X-latestVersion";
93 static String onboardUUID = null;
94 static String aid = TestsUsingCassandra.aid;
97 public static void init() throws Exception {
98 System.out.println("Testing RestMusicData class");
101 } catch (Exception e) {
103 throw new Exception("Unable to initialize before TestRestMusicData test class. " + e.getMessage());
108 public void afterEachTest() throws MusicServiceException {
109 clearAllTablesFromKeyspace();
113 public static void tearDownAfterClass() throws Exception {
114 testObject = new PreparedQueryObject();
115 testObject.appendQueryString("DROP KEYSPACE IF EXISTS " + keyspaceName);
116 MusicCore.eventualPut(testObject);
120 public void test1_createKeyspace() throws Exception {
121 System.out.println("Testing create keyspace");
122 JsonKeySpace jsonKeyspace = new JsonKeySpace();
123 Map<String, String> consistencyInfo = new HashMap<>();
124 Map<String, Object> replicationInfo = new HashMap<>();
125 consistencyInfo.put("type", "eventual");
126 replicationInfo.put("class", "SimpleStrategy");
127 replicationInfo.put("replication_factor", 1);
128 jsonKeyspace.setConsistencyInfo(consistencyInfo);
129 jsonKeyspace.setDurabilityOfWrites("true");
130 jsonKeyspace.setKeyspaceName(keyspaceName);
131 jsonKeyspace.setReplicationInfo(replicationInfo);
132 // Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
134 data.createKeySpace("1", "1", "1", null, authorization, appName, jsonKeyspace, keyspaceName);
135 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
136 assertEquals(400, response.getStatus());
137 Map<String, String> respMap = (Map<String, String>) response.getEntity();
138 assertEquals(ResultType.FAILURE, respMap.get("status"));
142 public void test3_createTable() throws Exception {
143 System.out.println("Testing create table");
144 JsonTable jsonTable = new JsonTable();
145 Map<String, String> consistencyInfo = new HashMap<>();
146 Map<String, String> fields = new HashMap<>();
147 fields.put("uuid", "text");
148 fields.put("emp_name", "text");
149 fields.put("emp_salary", "varint");
150 fields.put("PRIMARY KEY", "(emp_name)");
151 consistencyInfo.put("type", "eventual");
152 jsonTable.setConsistencyInfo(consistencyInfo);
153 jsonTable.setKeyspaceName(keyspaceName);
154 jsonTable.setPrimaryKey("emp_name");
155 jsonTable.setTableName(tableName);
156 jsonTable.setFields(fields);
157 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
158 authorization, jsonTable, keyspaceName, tableName);
159 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
160 assertEquals(200, response.getStatus());
164 public void test3_createTableNoName() throws Exception {
165 System.out.println("Testing create table without name");
166 JsonTable jsonTable = new JsonTable();
167 Map<String, String> consistencyInfo = new HashMap<>();
168 Map<String, String> fields = new HashMap<>();
169 fields.put("uuid", "text");
170 fields.put("emp_name", "text");
171 fields.put("emp_salary", "varint");
172 fields.put("PRIMARY KEY", "(emp_name)");
173 consistencyInfo.put("type", "eventual");
174 jsonTable.setConsistencyInfo(consistencyInfo);
175 jsonTable.setKeyspaceName(keyspaceName);
176 jsonTable.setPrimaryKey("emp_name");
177 jsonTable.setTableName("");
178 jsonTable.setFields(fields);
179 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
180 authorization, jsonTable, keyspaceName, "");
181 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
182 assertEquals(400, response.getStatus());
187 public void test3_createTableClusterOrderBad() throws Exception {
188 System.out.println("Testing create table bad clustering");
189 JsonTable jsonTable = new JsonTable();
190 Map<String, String> consistencyInfo = new HashMap<>();
191 Map<String, String> fields = new HashMap<>();
192 fields.put("uuid", "text");
193 fields.put("emp_name", "text");
194 fields.put("emp_salary", "varint");
195 fields.put("PRIMARY KEY", "(emp_name,emp_salary)");
196 consistencyInfo.put("type", "eventual");
197 jsonTable.setConsistencyInfo(consistencyInfo);
198 jsonTable.setKeyspaceName(keyspaceName);
199 jsonTable.setPrimaryKey("emp_name,emp_salary");
200 jsonTable.setClusteringOrder("ASC");
201 jsonTable.setTableName(tableName);
202 jsonTable.setFields(fields);
203 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
204 authorization, jsonTable, keyspaceName, tableName);
205 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
206 assertEquals(400, response.getStatus());
210 public void test3_createTable_withPropertiesNotNull() throws Exception {
211 System.out.println("Testing create table with properties");
212 JsonTable jsonTable = new JsonTable();
213 Map<String, String> consistencyInfo = new HashMap<>();
214 Map<String, String> fields = new HashMap<>();
215 fields.put("uuid", "text");
216 fields.put("emp_name", "text");
217 fields.put("emp_salary", "varint");
218 fields.put("PRIMARY KEY", "(emp_name)");
219 consistencyInfo.put("type", "eventual");
220 Map<String, Object> properties = new HashMap<>();
221 properties.put("comment", "Testing prperties not null");
222 jsonTable.setConsistencyInfo(consistencyInfo);
223 jsonTable.setKeyspaceName(keyspaceName);
224 jsonTable.setPrimaryKey("emp_name");
225 String tableName_prop = tableName + "_Prop";
226 jsonTable.setTableName(tableName_prop);
227 jsonTable.setFields(fields);
228 jsonTable.setProperties(properties);
230 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
231 authorization, jsonTable, keyspaceName, tableName_prop);
232 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
233 assertEquals(200, response.getStatus());
237 public void test3_createTable_duplicateTable() throws Exception {
238 System.out.println("Testing creating duplicate tables");
239 JsonTable jsonTable = new JsonTable();
240 Map<String, String> consistencyInfo = new HashMap<>();
241 Map<String, String> fields = new HashMap<>();
242 fields.put("uuid", "text");
243 fields.put("emp_name", "text");
244 fields.put("emp_salary", "varint");
245 fields.put("PRIMARY KEY", "(emp_name)");
246 consistencyInfo.put("type", "eventual");
247 jsonTable.setConsistencyInfo(consistencyInfo);
248 jsonTable.setKeyspaceName(keyspaceName);
249 jsonTable.setPrimaryKey("emp_name");
250 String tableNameDup = tableName + "x";
251 jsonTable.setTableName(tableNameDup);
252 jsonTable.setFields(fields);
253 // Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
254 Response response1 = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
255 authorization, jsonTable, keyspaceName, tableNameDup);
257 Response response2 = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
258 authorization, jsonTable, keyspaceName, tableNameDup);
259 System.out.println("Status: " + response2.getStatus() + ". Entity " + response2.getEntity());
261 assertEquals(400, response2.getStatus());
262 Map<String, String> respMap = (Map<String, String>) response2.getEntity();
263 assertEquals(ResultType.FAILURE, respMap.get("status"));
264 assertEquals("Table " + keyspaceName + "." + tableNameDup + " already exists", respMap.get("error"));
269 public void test3_createTable1() throws Exception {
270 System.out.println("Testing create table w/ improper authentication");
271 JsonTable jsonTable = new JsonTable();
272 Map<String, String> consistencyInfo = new HashMap<>();
273 Map<String, String> fields = new HashMap<>();
274 fields.put("uuid", "text");
275 fields.put("emp_name", "text");
276 fields.put("emp_salary", "varint");
277 fields.put("PRIMARY KEY", "(emp_name)");
278 consistencyInfo.put("type", "eventual");
279 jsonTable.setConsistencyInfo(consistencyInfo);
280 jsonTable.setKeyspaceName(keyspaceName);
281 jsonTable.setPrimaryKey("emp_name");
282 jsonTable.setTableName(tableName);
283 jsonTable.setFields(fields);
284 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
285 wrongAuthorization, jsonTable, keyspaceName, tableName);
286 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
287 assertEquals(401, response.getStatus());
292 public void test3_createTable3() throws Exception {
293 System.out.println("Testing create table for wrong keyspace");
294 JsonTable jsonTable = new JsonTable();
295 Map<String, String> consistencyInfo = new HashMap<>();
296 Map<String, String> fields = new HashMap<>();
297 fields.put("uuid", "text");
298 fields.put("emp_name", "text");
299 fields.put("emp_salary", "varint");
300 fields.put("PRIMARY KEY", "(emp_name)");
301 consistencyInfo.put("type", "eventual");
302 jsonTable.setConsistencyInfo(consistencyInfo);
303 jsonTable.setKeyspaceName(keyspaceName);
304 jsonTable.setPrimaryKey("emp_name");
305 jsonTable.setTableName(tableName);
306 jsonTable.setFields(fields);
307 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
308 authorization, jsonTable, "wrong", tableName);
309 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
310 assertEquals(401, response.getStatus());
313 // Improper parenthesis in key field
315 public void test3_createTable_badParantesis() throws Exception {
316 System.out.println("Testing malformed create table request");
317 String tableNameC = "testTable0";
318 JsonTable jsonTable = new JsonTable();
319 Map<String, String> consistencyInfo = new HashMap<>();
320 Map<String, String> fields = new HashMap<>();
321 fields.put("uuid", "text");
322 fields.put("emp_name", "text");
323 fields.put("emp_salary", "varint");
324 fields.put("PRIMARY KEY", "(emp_name),emp_id)");
325 fields.put("emp_id", "varint");
326 consistencyInfo.put("type", "eventual");
327 jsonTable.setConsistencyInfo(consistencyInfo);
328 jsonTable.setKeyspaceName(keyspaceName);
329 jsonTable.setPrimaryKey("emp_name");
330 jsonTable.setTableName(tableNameC);
331 jsonTable.setClusteringOrder("emp_id Desc");
332 jsonTable.setFields(fields);
333 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
334 authorization, jsonTable, keyspaceName, tableNameC);
335 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
337 assertEquals(400, response.getStatus());
341 // good clustering key
343 public void test3_createTable_1_clusterKey_good() throws Exception {
344 System.out.println("Testing create w/ clusterKey");
346 String tableNameC = "testTableC1";
347 JsonTable jsonTable = new JsonTable();
348 Map<String, String> consistencyInfo = new HashMap<>();
349 Map<String, String> fields = new HashMap<>();
350 fields.put("uuid", "text");
351 fields.put("emp_name", "text");
352 fields.put("emp_salary", "varint");
353 fields.put("PRIMARY KEY", "((emp_name),emp_salary)");
354 consistencyInfo.put("type", "eventual");
355 jsonTable.setConsistencyInfo(consistencyInfo);
356 jsonTable.setKeyspaceName(keyspaceName);
357 // jsonTable.setPrimaryKey("emp_name");
358 jsonTable.setTableName(tableNameC);
359 jsonTable.setClusteringOrder("emp_salary ASC");
360 jsonTable.setFields(fields);
361 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
362 authorization, jsonTable, keyspaceName, tableNameC);
363 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
365 assertEquals(200, response.getStatus());
368 // bad partition key=clustering key
370 public void test3_createTable_2_clusterKey_bad() throws Exception {
371 System.out.println("Testing create w/ bad clusterKey");
372 String tableNameC = "testTableC2";
373 JsonTable jsonTable = new JsonTable();
374 Map<String, String> consistencyInfo = new HashMap<>();
375 Map<String, String> fields = new HashMap<>();
376 fields.put("uuid", "text");
377 fields.put("emp_name", "text");
378 fields.put("emp_salary", "varint");
379 fields.put("PRIMARY KEY", "((emp_name),emp_name)");
380 consistencyInfo.put("type", "eventual");
381 jsonTable.setConsistencyInfo(consistencyInfo);
382 jsonTable.setKeyspaceName(keyspaceName);
383 jsonTable.setPrimaryKey("emp_name"); // "PRIMARY KEY" overrides if primaryKey present
384 jsonTable.setTableName(tableNameC);
385 jsonTable.setClusteringOrder("emp_salary ASC");
386 jsonTable.setFields(fields);
387 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
388 authorization, jsonTable, keyspaceName, tableNameC);
389 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
391 assertEquals(400, response.getStatus());
394 // good composite partition key,clustering key
396 public void test3_createTable_3_pfartition_clusterKey_good() throws Exception {
397 System.out.println("Testing create w/ composite partition key, clusterKey");
399 String tableNameC = "testTableC3";
400 JsonTable jsonTable = new JsonTable();
401 Map<String, String> consistencyInfo = new HashMap<>();
402 Map<String, String> fields = new HashMap<>();
403 fields.put("uuid", "text");
404 fields.put("emp_name", "text");
405 fields.put("emp_id", "varint");
406 fields.put("emp_salary", "varint");
407 fields.put("PRIMARY KEY", "((emp_name,emp_id),emp_salary)");
408 consistencyInfo.put("type", "eventual");
409 jsonTable.setConsistencyInfo(consistencyInfo);
410 jsonTable.setKeyspaceName(keyspaceName);
411 jsonTable.setPrimaryKey("emp_name");
412 jsonTable.setTableName(tableNameC);
413 jsonTable.setClusteringOrder("emp_salary ASC");
414 jsonTable.setFields(fields);
415 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
416 authorization, jsonTable, keyspaceName, tableNameC);
417 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
419 assertEquals(200, response.getStatus());
422 // bad - wrong cols in order by of composite partition key,clustering key
424 public void test3_createTable_5_clusteringOrder_bad() throws Exception {
425 System.out.println("Testing create table bad request with clustering & composite keys");
426 String tableNameC = "testTableC5";
427 JsonTable jsonTable = new JsonTable();
428 Map<String, String> consistencyInfo = new HashMap<>();
429 Map<String, String> fields = new HashMap<>();
430 fields.put("uuid", "text");
431 fields.put("emp_name", "text");
432 fields.put("emp_id", "varint");
433 fields.put("emp_salary", "varint");
434 fields.put("PRIMARY KEY", "((uuid,emp_name),emp_id,emp_salary)");
435 consistencyInfo.put("type", "eventual");
436 jsonTable.setConsistencyInfo(consistencyInfo);
437 jsonTable.setKeyspaceName(keyspaceName);
438 jsonTable.setPrimaryKey("emp_name");
439 jsonTable.setTableName(tableNameC);
440 jsonTable.setClusteringOrder("emp_idx desc, emp_salary ASC");
441 jsonTable.setFields(fields);
442 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
443 authorization, jsonTable, keyspaceName, tableNameC);
444 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
446 assertEquals(400, response.getStatus());
450 // good clustering key, need to pass queryparameter
452 public void test3_createTableIndex_1() throws Exception {
453 System.out.println("Testing index in create table");
454 String tableNameC = "testTableCinx";
455 JsonTable jsonTable = new JsonTable();
456 Map<String, String> consistencyInfo = new HashMap<>();
457 Map<String, String> fields = new HashMap<>();
458 fields.put("uuid", "text");
459 fields.put("emp_name", "text");
460 fields.put("emp_salary", "varint");
461 fields.put("PRIMARY KEY", "((emp_name),emp_salary)");
462 consistencyInfo.put("type", "eventual");
463 jsonTable.setConsistencyInfo(consistencyInfo);
464 jsonTable.setKeyspaceName(keyspaceName);
465 jsonTable.setTableName(tableNameC);
466 jsonTable.setClusteringOrder("emp_salary ASC");
467 jsonTable.setFields(fields);
468 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
469 authorization, jsonTable, keyspaceName, tableNameC);
470 // if 200 print to log otherwise fail assertEquals(200, response.getStatus());
471 // info.setQueryParameters("index_name=inx_uuid");
472 Map<String, String> queryParametersMap = new HashMap<String, String>();
474 queryParametersMap.put("index_name", "inxuuid");
475 Mockito.when(info.getQueryParameters()).thenReturn(new MultivaluedHashMap<String, String>(queryParametersMap));
476 response = data.createIndex("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
477 keyspaceName, tableNameC, "uuid", info);
478 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
480 assertEquals(200, response.getStatus());
483 // good clustering key, need to pass queryparameter
485 public void test3_createTableIndex_badAuth() throws Exception {
486 System.out.println("Testing index in create table w/ wrong authorization");
487 String tableNameC = "testTableCinx";
488 JsonTable jsonTable = new JsonTable();
489 Map<String, String> consistencyInfo = new HashMap<>();
490 Map<String, String> fields = new HashMap<>();
491 fields.put("uuid", "text");
492 fields.put("emp_name", "text");
493 fields.put("emp_salary", "varint");
494 fields.put("PRIMARY KEY", "((emp_name),emp_salary)");
495 consistencyInfo.put("type", "eventual");
496 jsonTable.setConsistencyInfo(consistencyInfo);
497 jsonTable.setKeyspaceName(keyspaceName);
498 jsonTable.setTableName(tableNameC);
499 jsonTable.setClusteringOrder("emp_salary ASC");
500 jsonTable.setFields(fields);
501 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
502 authorization, jsonTable, keyspaceName, tableNameC);
503 // if 200 print to log otherwise fail assertEquals(200, response.getStatus());
504 // info.setQueryParameters("index_name=inx_uuid");
505 Map<String, String> queryParametersMap = new HashMap<String, String>();
507 queryParametersMap.put("index_name", "inxuuid");
508 response = data.createIndex("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
509 wrongAuthorization, keyspaceName, tableNameC, "uuid", info);
510 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
512 assertEquals(401, response.getStatus());
515 // create index without table name
517 public void test3_createTableIndexNoName() throws Exception {
518 System.out.println("Testing index in create table w/o tablename");
519 String tableNameC = "testTableCinx";
520 JsonTable jsonTable = new JsonTable();
521 Map<String, String> consistencyInfo = new HashMap<>();
522 Map<String, String> fields = new HashMap<>();
523 fields.put("uuid", "text");
524 fields.put("emp_name", "text");
525 fields.put("emp_salary", "varint");
526 fields.put("PRIMARY KEY", "((emp_name),emp_salary)");
527 consistencyInfo.put("type", "eventual");
528 jsonTable.setConsistencyInfo(consistencyInfo);
529 jsonTable.setKeyspaceName(keyspaceName);
530 jsonTable.setTableName(tableNameC);
531 jsonTable.setClusteringOrder("emp_salary ASC");
532 jsonTable.setFields(fields);
533 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
534 authorization, jsonTable, keyspaceName, tableNameC);
535 // if 200 print to log otherwise fail assertEquals(200, response.getStatus());
536 // info.setQueryParameters("index_name=inx_uuid");
537 Map<String, String> queryParametersMap = new HashMap<String, String>();
539 queryParametersMap.put("index_name", "inxuuid");
540 response = data.createIndex("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, "",
542 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
544 assertEquals(400, response.getStatus());
548 public void test4_insertIntoTable() throws Exception {
549 System.out.println("Testing insert into table");
551 JsonInsert jsonInsert = new JsonInsert();
552 Map<String, String> consistencyInfo = new HashMap<>();
553 Map<String, Object> values = new HashMap<>();
554 values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
555 values.put("emp_name", "testname");
556 values.put("emp_salary", 500);
557 consistencyInfo.put("type", "eventual");
558 jsonInsert.setConsistencyInfo(consistencyInfo);
559 jsonInsert.setKeyspaceName(keyspaceName);
560 jsonInsert.setTableName(tableName);
561 jsonInsert.setValues(values);
562 Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
563 authorization, jsonInsert, keyspaceName, tableName);
564 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
566 assertEquals(200, response.getStatus());
570 public void test4_insertIntoTableCriticalNoLockID() throws Exception {
571 System.out.println("Testing critical insert into table without lockid");
573 JsonInsert jsonInsert = new JsonInsert();
574 Map<String, String> consistencyInfo = new HashMap<>();
575 Map<String, Object> values = new HashMap<>();
576 values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
577 values.put("emp_name", "testname");
578 values.put("emp_salary", 500);
579 consistencyInfo.put("type", "critical");
580 jsonInsert.setConsistencyInfo(consistencyInfo);
581 jsonInsert.setKeyspaceName(keyspaceName);
582 jsonInsert.setTableName(tableName);
583 jsonInsert.setValues(values);
584 Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
585 appName, authorization, jsonInsert, keyspaceName, tableName);
586 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
588 assertEquals(400, response.getStatus());
592 public void test4_insertIntoTableAtomic() throws Exception {
593 System.out.println("Testing atomic insert into table without lockid");
595 JsonInsert jsonInsert = new JsonInsert();
596 Map<String, String> consistencyInfo = new HashMap<>();
597 Map<String, Object> values = new HashMap<>();
598 values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
599 values.put("emp_name", "testname");
600 values.put("emp_salary", 500);
601 consistencyInfo.put("type", "atomic");
602 jsonInsert.setConsistencyInfo(consistencyInfo);
603 jsonInsert.setKeyspaceName(keyspaceName);
604 jsonInsert.setTableName(tableName);
605 jsonInsert.setValues(values);
606 Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
607 appName, authorization, jsonInsert, keyspaceName, tableName);
608 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
610 assertEquals(200, response.getStatus());
614 public void test4_insertIntoTableNoName() throws Exception {
615 System.out.println("Testing insert into table w/o table name");
617 JsonInsert jsonInsert = new JsonInsert();
618 Map<String, String> consistencyInfo = new HashMap<>();
619 Map<String, Object> values = new HashMap<>();
620 values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
621 values.put("emp_name", "testname");
622 values.put("emp_salary", 500);
623 consistencyInfo.put("type", "eventual");
624 jsonInsert.setConsistencyInfo(consistencyInfo);
625 jsonInsert.setKeyspaceName(keyspaceName);
626 jsonInsert.setTableName(tableName);
627 jsonInsert.setValues(values);
628 Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
629 appName, authorization, jsonInsert, "", "");
630 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
632 assertEquals(400, response.getStatus());
636 public void test4_insertIntoTable2() throws Exception {
637 System.out.println("Testing insert into table #2");
639 JsonInsert jsonInsert = new JsonInsert();
640 Map<String, String> consistencyInfo = new HashMap<>();
641 Map<String, Object> values = new HashMap<>();
642 values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
643 values.put("emp_name", "test1");
644 values.put("emp_salary", 1500);
645 consistencyInfo.put("type", "eventual");
646 jsonInsert.setConsistencyInfo(consistencyInfo);
647 jsonInsert.setKeyspaceName(keyspaceName);
648 jsonInsert.setTableName(tableName);
649 jsonInsert.setValues(values);
650 Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
651 authorization, jsonInsert, keyspaceName, tableName);
652 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
654 assertEquals(200, response.getStatus());
659 public void test4_insertIntoTable3() throws Exception {
660 System.out.println("Testing insert into table with bad credentials");
662 JsonInsert jsonInsert = new JsonInsert();
663 Map<String, String> consistencyInfo = new HashMap<>();
664 Map<String, Object> values = new HashMap<>();
665 values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
666 values.put("emp_name", "test1");
667 values.put("emp_salary", 1500);
668 consistencyInfo.put("type", "eventual");
669 jsonInsert.setConsistencyInfo(consistencyInfo);
670 jsonInsert.setKeyspaceName(keyspaceName);
671 jsonInsert.setTableName(tableName);
672 jsonInsert.setValues(values);
673 Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
674 wrongAuthorization, jsonInsert, keyspaceName, tableName);
675 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
677 assertEquals(401, response.getStatus());
682 public void test4_insertIntoTable4() throws Exception {
683 System.out.println("Testing insert into wrong table");
685 JsonInsert jsonInsert = new JsonInsert();
686 Map<String, String> consistencyInfo = new HashMap<>();
687 Map<String, Object> values = new HashMap<>();
688 values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
689 values.put("emp_name", "test1");
690 values.put("emp_salary", 1500);
691 consistencyInfo.put("type", "eventual");
692 jsonInsert.setConsistencyInfo(consistencyInfo);
693 jsonInsert.setKeyspaceName(keyspaceName);
694 jsonInsert.setTableName(tableName);
695 jsonInsert.setValues(values);
696 Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
697 authorization, jsonInsert, keyspaceName, "wrong");
698 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
700 assertEquals(400, response.getStatus());
704 public void test4_insertBlobIntoTable() throws Exception {
705 System.out.println("Testing insert a blob into table");
707 JsonInsert jsonInsert = new JsonInsert();
708 Map<String, String> consistencyInfo = new HashMap<>();
709 Map<String, Object> values = new HashMap<>();
710 values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
711 values.put("emp_name", "testname");
712 values.put("emp_salary", 500);
713 values.put("binary", "somestuffhere");
714 consistencyInfo.put("type", "eventual");
715 jsonInsert.setConsistencyInfo(consistencyInfo);
716 jsonInsert.setKeyspaceName(keyspaceName);
717 jsonInsert.setTableName(tableName);
718 jsonInsert.setValues(values);
719 Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
720 authorization, jsonInsert, keyspaceName, tableName);
721 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
723 assertEquals(200, response.getStatus());
727 public void test5_updateTable() throws Exception {
728 System.out.println("Testing update table");
731 JsonUpdate jsonUpdate = new JsonUpdate();
732 Map<String, String> consistencyInfo = new HashMap<>();
733 MultivaluedMap<String, String> row = new MultivaluedMapImpl();
734 Map<String, Object> values = new HashMap<>();
735 row.add("emp_name", "testname");
736 values.put("emp_salary", 2500);
737 consistencyInfo.put("type", "atomic");
738 jsonUpdate.setConsistencyInfo(consistencyInfo);
739 jsonUpdate.setKeyspaceName(keyspaceName);
740 jsonUpdate.setTableName(tableName);
741 jsonUpdate.setValues(values);
742 Mockito.when(info.getQueryParameters()).thenReturn(row);
743 Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
744 authorization, jsonUpdate, keyspaceName, tableName, info);
746 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
748 assertEquals(200, response.getStatus());
752 public void test5_updateTable_wrongAuth() throws Exception {
753 System.out.println("Testing update table w/ wrong credentials");
756 JsonUpdate jsonUpdate = new JsonUpdate();
757 Map<String, String> consistencyInfo = new HashMap<>();
758 Map<String, Object> values = new HashMap<>();
759 values.put("emp_salary", 2500);
760 consistencyInfo.put("type", "atomic");
761 jsonUpdate.setConsistencyInfo(consistencyInfo);
762 jsonUpdate.setKeyspaceName(keyspaceName);
763 jsonUpdate.setTableName(tableName);
764 jsonUpdate.setValues(values);
765 Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
766 wrongAuthorization, jsonUpdate, keyspaceName, tableName, info);
768 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
770 assertEquals(401, response.getStatus());
774 public void test5_updateTable_tableDNE() throws Exception {
775 System.out.println("Testing update table that does not exist");
778 JsonUpdate jsonUpdate = new JsonUpdate();
779 Map<String, String> consistencyInfo = new HashMap<>();
780 Map<String, Object> values = new HashMap<>();
781 values.put("emp_salary", 2500);
782 consistencyInfo.put("type", "atomic");
783 jsonUpdate.setConsistencyInfo(consistencyInfo);
784 jsonUpdate.setKeyspaceName(keyspaceName);
785 jsonUpdate.setTableName("wrong_"+tableName);
786 jsonUpdate.setValues(values);
787 Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
788 authorization, jsonUpdate, keyspaceName, "wrong_"+ tableName, info);
790 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
792 assertEquals(400, response.getStatus());
796 public void test5_updateTableNoName() throws Exception {
797 System.out.println("Testing update table without tablename");
800 JsonUpdate jsonUpdate = new JsonUpdate();
801 Map<String, String> consistencyInfo = new HashMap<>();
802 Map<String, Object> values = new HashMap<>();
803 values.put("emp_salary", 2500);
804 consistencyInfo.put("type", "atomic");
805 jsonUpdate.setConsistencyInfo(consistencyInfo);
806 jsonUpdate.setKeyspaceName(keyspaceName);
807 jsonUpdate.setTableName(tableName);
808 jsonUpdate.setValues(values);
809 Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
810 authorization, jsonUpdate, "", "", info);
812 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
814 assertEquals(400, response.getStatus());
817 // need mock code to create error for MusicCore methods
819 public void test5_updateTableAuthE() throws Exception {
820 System.out.println("Testing update table #2");
822 // MockitoAnnotations.initMocks(this);
823 JsonUpdate jsonUpdate = new JsonUpdate();
824 Map<String, String> consistencyInfo = new HashMap<>();
825 MultivaluedMap<String, String> row = new MultivaluedMapImpl();
826 Map<String, Object> values = new HashMap<>();
827 row.add("emp_name", "testname");
828 values.put("emp_salary", 2500);
829 consistencyInfo.put("type", "atomic");
830 jsonUpdate.setConsistencyInfo(consistencyInfo);
831 jsonUpdate.setKeyspaceName(keyspaceName);
832 jsonUpdate.setTableName(tableName);
833 jsonUpdate.setValues(values);
834 // add ttl & timestamp
835 // Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
836 Mockito.when(info.getQueryParameters()).thenReturn(row);
837 // Map<String, Object> m1= new HashMap<>() ;
838 // Mockito.when(MusicCore.autheticateUser(appName,userId,password,keyspaceName,"abc66ccc-d857-4e90-b1e5-df98a3d40ce6","updateTable")).thenReturn(m1);
839 Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
840 authorization, jsonUpdate, keyspaceName, tableName, info);
841 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
843 assertEquals(200, response.getStatus());
848 public void test5_updateTableAuthException1() throws Exception {
849 System.out.println("Testing update table authentication error");
851 JsonUpdate jsonUpdate = new JsonUpdate();
852 Map<String, String> consistencyInfo = new HashMap<>();
853 MultivaluedMap<String, String> row = new MultivaluedMapImpl();
854 Map<String, Object> values = new HashMap<>();
855 row.add("emp_name", "testname");
856 values.put("emp_salary", 2500);
857 consistencyInfo.put("type", "atomic");
858 jsonUpdate.setConsistencyInfo(consistencyInfo);
859 jsonUpdate.setKeyspaceName(keyspaceName);
860 jsonUpdate.setTableName(tableName);
861 jsonUpdate.setValues(values);
863 Mockito.when(info.getQueryParameters()).thenReturn(row);
864 String authDatax = ":";
865 String authorizationx = new String(Base64.encode(authDatax.getBytes()));
866 Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
867 authorizationx, jsonUpdate, keyspaceName, tableName, info);
868 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
870 assertEquals(401, response.getStatus());
875 public void test5_updateTableAuthEmpty() throws Exception {
876 System.out.println("Testing update table without authentication");
879 JsonUpdate jsonUpdate = new JsonUpdate();
880 Map<String, String> consistencyInfo = new HashMap<>();
881 MultivaluedMap<String, String> row = new MultivaluedMapImpl();
882 Map<String, Object> values = new HashMap<>();
883 row.add("emp_name", "testname");
884 values.put("emp_salary", 2500);
885 consistencyInfo.put("type", "atomic");
886 jsonUpdate.setConsistencyInfo(consistencyInfo);
887 jsonUpdate.setKeyspaceName(keyspaceName);
888 jsonUpdate.setTableName(tableName);
889 jsonUpdate.setValues(values);
891 Mockito.when(info.getQueryParameters()).thenReturn(row);
892 String authDatax = ":" + password;
893 String authorizationx = new String(Base64.encode(authDatax.getBytes()));
894 String appNamex = "xx";
895 Response response = data.updateTable("1", "1", "1", "", appNamex, authorizationx, jsonUpdate, keyspaceName,
897 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
899 assertEquals(401, response.getStatus());
903 public void test6_critical_selectAtomic() throws Exception {
904 System.out.println("Testing critical select atomic");
905 createAndInsertIntoTable();
906 JsonInsert jsonInsert = new JsonInsert();
907 Map<String, String> consistencyInfo = new HashMap<>();
908 MultivaluedMap<String, String> row = new MultivaluedMapImpl();
909 row.add("emp_name", "testname");
910 consistencyInfo.put("type", "atomic");
911 jsonInsert.setConsistencyInfo(consistencyInfo);
912 Mockito.when(info.getQueryParameters()).thenReturn(row);
913 Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
914 appName, authorization, jsonInsert, keyspaceName, tableName,info);
915 HashMap<String,HashMap<String,Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
916 HashMap<String, Object> result = map.get("result");
917 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
919 Map<String, String> row0 = (Map<String, String>) result.get("row 0");
920 assertEquals("testname", row0.get("emp_name"));
921 assertEquals(BigInteger.valueOf(500), row0.get("emp_salary"));
925 public void test6_critical_selectCritical_nolockid() throws Exception {
926 System.out.println("Testing critical select critical w/o lockid");
927 createAndInsertIntoTable();
928 JsonInsert jsonInsert = new JsonInsert();
929 Map<String, String> consistencyInfo = new HashMap<>();
930 MultivaluedMap<String, String> row = new MultivaluedMapImpl();
931 row.add("emp_name", "testname");
932 consistencyInfo.put("type", "critical");
933 jsonInsert.setConsistencyInfo(consistencyInfo);
934 Mockito.when(info.getQueryParameters()).thenReturn(row);
935 Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
936 appName, authorization, jsonInsert, keyspaceName, tableName,info);
937 HashMap<String,HashMap<String,Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
938 HashMap<String, Object> result = map.get("result");
939 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
941 assertEquals(400, response.getStatus());
945 public void test6_critical_select_wrongAuth() throws Exception {
946 System.out.println("Testing critical select w/ wrong authentication");
947 createAndInsertIntoTable();
948 JsonInsert jsonInsert = new JsonInsert();
949 Map<String, String> consistencyInfo = new HashMap<>();
950 consistencyInfo.put("type", "atomic");
951 jsonInsert.setConsistencyInfo(consistencyInfo);
952 Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
953 appName, wrongAuthorization, jsonInsert, keyspaceName, tableName,info);
954 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
956 assertEquals(401, response.getStatus());
960 public void test6_critical_select_nulltable() throws Exception {
961 System.out.println("Testing critical select w/ null tablename");
962 createAndInsertIntoTable();
963 JsonInsert jsonInsert = new JsonInsert();
964 Map<String, String> consistencyInfo = new HashMap<>();
965 consistencyInfo.put("type", "atomic");
966 jsonInsert.setConsistencyInfo(consistencyInfo);
967 Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
968 appName, authorization, jsonInsert, keyspaceName, null,info);
969 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
971 assertEquals(400, response.getStatus());
975 public void test6_select() throws Exception {
976 System.out.println("Testing select");
977 createAndInsertIntoTable();
978 JsonSelect jsonSelect = new JsonSelect();
979 Map<String, String> consistencyInfo = new HashMap<>();
980 MultivaluedMap<String, String> row = new MultivaluedMapImpl();
981 row.add("emp_name", "testname");
982 consistencyInfo.put("type", "atomic");
983 jsonSelect.setConsistencyInfo(consistencyInfo);
984 Mockito.when(info.getQueryParameters()).thenReturn(row);
985 Response response = data.select("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
986 keyspaceName, tableName, info);
987 HashMap<String, HashMap<String, Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
988 HashMap<String, Object> result = map.get("result");
989 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
991 Map<String, String> row0 = (Map<String, String>) result.get("row 0");
992 assertEquals("testname", row0.get("emp_name"));
993 assertEquals(BigInteger.valueOf(500), row0.get("emp_salary"));
997 public void test6_select_wrongAuth() throws Exception {
998 System.out.println("Testing select w/ wrong authentication");
999 createAndInsertIntoTable();
1000 JsonSelect jsonSelect = new JsonSelect();
1001 Map<String, String> consistencyInfo = new HashMap<>();
1002 consistencyInfo.put("type", "atomic");
1003 jsonSelect.setConsistencyInfo(consistencyInfo);
1004 Response response = data.select("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
1005 appName, wrongAuthorization, keyspaceName, tableName, info);
1006 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
1008 assertEquals(401, response.getStatus());
1012 public void test6_select_nullTablename() throws Exception {
1013 System.out.println("Testing select w/ null tablename");
1014 createAndInsertIntoTable();
1015 JsonSelect jsonSelect = new JsonSelect();
1016 Map<String, String> consistencyInfo = new HashMap<>();
1017 consistencyInfo.put("type", "atomic");
1018 jsonSelect.setConsistencyInfo(consistencyInfo);
1019 Response response = data.select("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
1020 appName, wrongAuthorization, keyspaceName, null, info);
1021 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
1023 assertEquals(400, response.getStatus());
1027 public void test6_deleteFromTable() throws Exception {
1028 System.out.println("Testing delete from table");
1029 createAndInsertIntoTable();
1030 JsonDelete jsonDelete = new JsonDelete();
1031 Map<String, String> consistencyInfo = new HashMap<>();
1032 MultivaluedMap<String, String> row = new MultivaluedMapImpl();
1033 row.add("emp_name", "test1");
1034 consistencyInfo.put("type", "atomic");
1035 jsonDelete.setConsistencyInfo(consistencyInfo);
1036 Mockito.when(info.getQueryParameters()).thenReturn(row);
1037 Response response = data.deleteFromTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
1038 authorization, jsonDelete, keyspaceName, tableName, info);
1039 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
1040 assertEquals(200, response.getStatus());
1044 public void test6_deleteFromTable_wrongAuth() throws Exception {
1045 System.out.println("Testing delete from table");
1046 createAndInsertIntoTable();
1047 JsonDelete jsonDelete = new JsonDelete();
1048 Map<String, String> consistencyInfo = new HashMap<>();
1049 consistencyInfo.put("type", "atomic");
1050 jsonDelete.setConsistencyInfo(consistencyInfo);
1051 Response response = data.deleteFromTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
1052 wrongAuthorization, jsonDelete, keyspaceName, tableName, info);
1053 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
1054 assertEquals(401, response.getStatus());
1058 public void test6_deleteFromTable_missingTablename() throws Exception {
1059 System.out.println("Testing delete from table w/ null tablename");
1060 createAndInsertIntoTable();
1061 JsonDelete jsonDelete = new JsonDelete();
1062 Map<String, String> consistencyInfo = new HashMap<>();
1063 consistencyInfo.put("type", "atomic");
1064 jsonDelete.setConsistencyInfo(consistencyInfo);
1065 Response response = data.deleteFromTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
1066 wrongAuthorization, jsonDelete, keyspaceName, null, info);
1067 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
1068 assertEquals(400, response.getStatus());
1074 public void test6_deleteFromTable1() throws Exception {
1075 System.out.println("Testing delete from table missing delete object");
1076 createAndInsertIntoTable();
1078 JsonDelete jsonDelete = new JsonDelete();
1079 Map<String, String> consistencyInfo = new HashMap<>();
1080 MultivaluedMap<String, String> row = new MultivaluedMapImpl();
1081 consistencyInfo.put("type", "atomic");
1082 jsonDelete.setConsistencyInfo(consistencyInfo);
1083 Mockito.when(info.getQueryParameters()).thenReturn(row);
1084 Response response = data.deleteFromTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
1085 authorization, jsonDelete, keyspaceName, tableName, info);
1086 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
1088 assertEquals(400, response.getStatus());
1093 public void test6_deleteFromTable2() throws Exception {
1094 System.out.println("Testing delete from table missing delete object");
1095 createAndInsertIntoTable();
1096 JsonDelete jsonDelete = new JsonDelete();
1097 Map<String, String> consistencyInfo = new HashMap<>();
1098 consistencyInfo.put("type", "atomic");
1099 jsonDelete.setConsistencyInfo(consistencyInfo);
1100 Response response = data.deleteFromTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
1101 authorization, null, keyspaceName, tableName, info);
1102 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
1104 assertEquals(400, response.getStatus());
1108 public void test7_dropTable() throws Exception {
1109 System.out.println("Testing drop table");
1111 JsonTable jsonTable = new JsonTable();
1112 Map<String, String> consistencyInfo = new HashMap<>();
1113 consistencyInfo.put("type", "atomic");
1114 jsonTable.setConsistencyInfo(consistencyInfo);
1115 Response response = data.dropTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
1116 authorization, keyspaceName, tableName);
1117 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
1119 assertEquals(200, response.getStatus());
1123 public void test7_dropTable_wrongAuth() throws Exception {
1124 System.out.println("Testing drop table w/ wrong auth");
1126 JsonTable jsonTable = new JsonTable();
1127 Map<String, String> consistencyInfo = new HashMap<>();
1128 consistencyInfo.put("type", "atomic");
1129 jsonTable.setConsistencyInfo(consistencyInfo);
1130 Response response = data.dropTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
1131 wrongAuthorization, keyspaceName, tableName);
1132 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
1134 assertEquals(401, response.getStatus());
1138 public void test7_dropTable_nullTablename() throws Exception {
1139 System.out.println("Testing drop table w/ null tablename");
1141 JsonTable jsonTable = new JsonTable();
1142 Map<String, String> consistencyInfo = new HashMap<>();
1143 consistencyInfo.put("type", "atomic");
1144 jsonTable.setConsistencyInfo(consistencyInfo);
1145 Response response = data.dropTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
1146 authorization, keyspaceName, null);
1147 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
1149 assertEquals(400, response.getStatus());
1154 public void test8_deleteKeyspace() throws Exception {
1155 System.out.println("Testing drop keyspace");
1157 JsonKeySpace jsonKeyspace = new JsonKeySpace();
1158 Map<String, String> consistencyInfo = new HashMap<>();
1159 Map<String, Object> replicationInfo = new HashMap<>();
1160 consistencyInfo.put("type", "eventual");
1161 replicationInfo.put("class", "SimpleStrategy");
1162 replicationInfo.put("replication_factor", 1);
1163 jsonKeyspace.setConsistencyInfo(consistencyInfo);
1164 jsonKeyspace.setDurabilityOfWrites("true");
1165 jsonKeyspace.setKeyspaceName("TestApp1");
1166 jsonKeyspace.setReplicationInfo(replicationInfo);
1167 Response response = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", authorization,
1168 appName, keyspaceName);
1169 System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
1171 assertEquals(400, response.getStatus());
1174 private static void createKeyspace() throws Exception {
1175 // shouldn't really be doing this here, but create keyspace is currently turned off
1176 PreparedQueryObject query = new PreparedQueryObject();
1177 query.appendQueryString(CassandraCQL.createKeySpace);
1178 MusicCore.eventualPut(query);
1180 boolean isAAF = false;
1181 String hashedpwd = BCrypt.hashpw(password, BCrypt.gensalt());
1182 query = new PreparedQueryObject();
1183 query.appendQueryString("INSERT into admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
1184 + "password, username, is_aaf) values (?,?,?,?,?,?,?)");
1185 query.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
1186 query.addValue(MusicUtil.convertToActualDataType(DataType.text(), keyspaceName));
1187 query.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
1188 query.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
1189 query.addValue(MusicUtil.convertToActualDataType(DataType.text(), hashedpwd));
1190 query.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
1191 query.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
1192 CachingUtil.updateMusicCache(keyspaceName, appName);
1193 CachingUtil.updateMusicValidateCache(appName, userId, hashedpwd);
1194 MusicCore.eventualPut(query);
1197 private void clearAllTablesFromKeyspace() throws MusicServiceException {
1198 ArrayList<String> tableNames = new ArrayList<>();
1199 PreparedQueryObject query = new PreparedQueryObject();
1200 query.appendQueryString(
1201 "SELECT table_name FROM system_schema.tables WHERE keyspace_name = '" + keyspaceName + "';");
1202 ResultSet rs = MusicCore.get(query);
1203 for (Row row : rs) {
1204 tableNames.add(row.getString("table_name"));
1206 for (String table : tableNames) {
1207 query = new PreparedQueryObject();
1208 query.appendQueryString("DROP TABLE " + keyspaceName + "." + table);
1209 MusicCore.eventualPut(query);
1214 * Create a table {@link tableName} in {@link keyspaceName}
1218 private void createTable() throws Exception {
1219 JsonTable jsonTable = new JsonTable();
1220 Map<String, String> consistencyInfo = new HashMap<>();
1221 Map<String, String> fields = new HashMap<>();
1222 fields.put("uuid", "text");
1223 fields.put("emp_name", "text");
1224 fields.put("emp_salary", "varint");
1225 fields.put("binary", "blob");
1226 fields.put("PRIMARY KEY", "(emp_name)");
1227 consistencyInfo.put("type", "eventual");
1228 jsonTable.setConsistencyInfo(consistencyInfo);
1229 jsonTable.setKeyspaceName(keyspaceName);
1230 jsonTable.setPrimaryKey("emp_name");
1231 jsonTable.setTableName(tableName);
1232 jsonTable.setFields(fields);
1233 // Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
1234 Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
1235 authorization, jsonTable, keyspaceName, tableName);
1239 * Create table {@link createTable} and insert into said table
1243 private void createAndInsertIntoTable() throws Exception {
1246 JsonInsert jsonInsert = new JsonInsert();
1247 Map<String, String> consistencyInfo = new HashMap<>();
1248 Map<String, Object> values = new HashMap<>();
1249 values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
1250 values.put("emp_name", "testname");
1251 values.put("emp_salary", 500);
1252 values.put("binary", "binarydatahere");
1253 consistencyInfo.put("type", "eventual");
1254 jsonInsert.setConsistencyInfo(consistencyInfo);
1255 jsonInsert.setKeyspaceName(keyspaceName);
1256 jsonInsert.setTableName(tableName);
1257 jsonInsert.setValues(values);
1258 Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
1259 authorization, jsonInsert, keyspaceName, tableName);