From 0d2f003049e562354fda88729dbab70f46daa25f Mon Sep 17 00:00:00 2001 From: "Nelson, Thomas (tn1381)" Date: Mon, 20 Aug 2018 04:45:13 +0000 Subject: Update swagger.json and other updates. Change-Id: I84753300e64ba82072e65ef1bde2cb76771ee046 Issue-ID: MUSIC-97 Signed-off-by: Nelson, Thomas (tn1381) --- WebContent/WEB-INF/web.xml | 5 + docs/swagger.json | 2118 +++++++++++++++++- musictrigger/src/MusicTrigger.java | 49 +- pom.xml | 10 +- .../jsonobjects/JSONCallbackResponse.java | 80 + .../music/datastore/jsonobjects/JsonCallback.java | 20 + .../datastore/jsonobjects/JsonNotification.java | 115 + .../music/lockingservice/MusicLockingService.java | 2 + .../lockingservice/ZkStatelessLockService.java | 1 - src/main/java/org/onap/music/main/CachingUtil.java | 39 +- .../java/org/onap/music/main/CronJobManager.java | 87 +- src/main/java/org/onap/music/main/MusicCore.java | 16 + src/main/java/org/onap/music/main/MusicUtil.java | 21 +- .../org/onap/music/rest/RestMusicAdminAPI.java | 399 +++- .../java/org/onap/music/rest/RestMusicDataAPI.java | 2 +- .../onap/music/unittests/TestRestAdminData.java | 2244 ++++++++++++++++++++ .../onap/music/unittests/TestRestMusicData.java | 2244 -------------------- version.properties | 2 +- 18 files changed, 5040 insertions(+), 2414 deletions(-) mode change 100644 => 100755 musictrigger/src/MusicTrigger.java create mode 100755 src/main/java/org/onap/music/datastore/jsonobjects/JSONCallbackResponse.java mode change 100644 => 100755 src/main/java/org/onap/music/datastore/jsonobjects/JsonCallback.java create mode 100755 src/main/java/org/onap/music/datastore/jsonobjects/JsonNotification.java create mode 100644 src/test/java/org/onap/music/unittests/TestRestAdminData.java delete mode 100644 src/test/java/org/onap/music/unittests/TestRestMusicData.java diff --git a/WebContent/WEB-INF/web.xml b/WebContent/WEB-INF/web.xml index 3bab5589..7b6caf4c 100644 --- a/WebContent/WEB-INF/web.xml +++ b/WebContent/WEB-INF/web.xml @@ -6,6 +6,11 @@ org.onap.music.main.PropertiesListener + + + org.onap.music.main.CronJobManager + + music-servlet diff --git a/docs/swagger.json b/docs/swagger.json index c352537b..3f4e220f 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1 +1,2117 @@ -{"swagger":"2.0","info":{"version":"1.0.0","title":""},"host":"localhost:8080","basePath":"/MUSIC/rest","tags":[{"name":"Version Api"},{"name":"Test Api"},{"name":"Q Api"},{"name":"Data Api"},{"name":"Lock Api"}],"schemes":["http"],"paths":{"/priorityq/keyspaces/{keyspace}/{qname}":{"post":{"tags":["Q Api"],"summary":"","description":"","operationId":"createQ","consumes":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"keyspace","in":"path","description":"Key Space","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}},"delete":{"tags":["Q Api"],"summary":"","description":"","operationId":"dropQ","parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"keyspace","in":"path","description":"Key Space","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}}},"/priorityq/keyspaces/{keyspace}/{qname}/filter":{"get":{"tags":["Q Api"],"summary":"","description":"","operationId":"filter","produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"name":"keyspace","in":"path","description":"Key Space","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}}},"/priorityq/keyspaces/{keyspace}/{qname}/peek":{"get":{"tags":["Q Api"],"summary":"","description":"","operationId":"peek","produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"name":"keyspace","in":"path","description":"Key Space","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}}},"/priorityq/keyspaces/{keyspace}/{qname}/rows":{"post":{"tags":["Q Api"],"summary":"","description":"","operationId":"insertIntoQ","consumes":["application/json"],"produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"keyspace","in":"path","description":"Key Space","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}},"put":{"tags":["Q Api"],"summary":"","description":"","operationId":"updateQ","consumes":["application/json"],"produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"keyspace","in":"path","description":"Key Space","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"string"}}}},"delete":{"tags":["Q Api"],"summary":"","description":"","operationId":"deleteFromQ","consumes":["application/json"],"produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"keyspace","in":"path","description":"Key Space","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"string"}}}}},"/v{version: [0-9]+}/keyspaces/{keyspace}/tables/{tablename}":{"post":{"tags":["Data Api"],"summary":"Create Table","description":"","operationId":"createTable","consumes":["application/json"],"produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"keyspace","in":"path","description":"Keyspace Name","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"string"}}}},"delete":{"tags":["Data Api"],"summary":"Drop Table","description":"","operationId":"dropTable","parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"keyspace","in":"path","description":"Keyspace Name","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"string"}}}}},"/v{version: [0-9]+}/keyspaces/{keyspace}/tables/{tablename}/index/{field}":{"post":{"tags":["Data Api"],"summary":"Create Index","description":"","operationId":"createIndex","produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"name":"keyspace","in":"path","description":"Keyspace Name","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"},{"name":"field","in":"path","description":"Field Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"string"}}}}},"/v{version: [0-9]+}/keyspaces/{keyspace}/tables/{tablename}/rows":{"get":{"tags":["Data Api"],"summary":"Select All or Select Specivic","description":"","operationId":"select","produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"name":"keyspace","in":"path","description":"Keyspace Name","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}},"post":{"tags":["Data Api"],"summary":"Insert Into Table","description":"","operationId":"insertIntoTable","consumes":["application/json"],"produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"keyspace","in":"path","description":"Keyspace Name","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"string"}}}},"put":{"tags":["Data Api"],"summary":"Update Table","description":"","operationId":"updateTable","consumes":["application/json"],"produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"keyspace","in":"path","description":"Keyspace Name","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"string"}}}},"delete":{"tags":["Data Api"],"summary":"Delete From table","description":"","operationId":"deleteFromTable","consumes":["application/json"],"produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"keyspace","in":"path","description":"Keyspace Name","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"string"}}}}},"/v{version: [0-9]+}/keyspaces/{keyspace}/tables/{tablename}/rows/criticalget":{"put":{"tags":["Data Api"],"summary":"Select Critical","description":"","operationId":"selectCritical","consumes":["application/json"],"produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"keyspace","in":"path","description":"Keyspace Name","required":true,"type":"string"},{"name":"tablename","in":"path","description":"Table Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}}},"/v{version: [0-9]+}/keyspaces/{name}":{"post":{"tags":["Data Api"],"summary":"Create Keyspace","description":"","operationId":"createKeySpace","consumes":["application/json"],"produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"name","in":"path","description":"Keyspace Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"string"}}}},"delete":{"tags":["Data Api"],"summary":"Delete Keyspace","description":"","operationId":"dropKeySpace","consumes":["application/json"],"produces":["application/json"],"parameters":[{"name":"version","in":"path","description":"Major Version","required":true,"type":"string"},{"name":"X-minorVersion","in":"header","description":"Minor Version","required":false,"type":"string"},{"name":"X-patchVersion","in":"header","description":"Patch Version","required":false,"type":"string"},{"name":"aid","in":"header","description":"AID","required":true,"type":"string"},{"name":"ns","in":"header","description":"Application namespace","required":true,"type":"string"},{"name":"userId","in":"header","description":"userId","required":true,"type":"string"},{"name":"password","in":"header","description":"Password","required":true,"type":"string"},{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"name","in":"path","description":"Keyspace Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"string"}}}}},"/v{version: [0-9]+}/locks/acquire-with-lease/{lockreference}":{"post":{"tags":["Lock Api"],"summary":"Aquire Lock with Lease","description":"","operationId":"accquireLockWithLease","consumes":["application/json"],"produces":["application/json"],"parameters":[{"in":"body","name":"body","required":false,"schema":{"$ref":"#/definitions/JsonTable"}},{"name":"lockreference","in":"path","description":"Lock Reference","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}}},"/v{version: [0-9]+}/locks/acquire/{lockreference}":{"get":{"tags":["Lock Api"],"summary":"Aquire Lock","description":"Checks if the node is in the top of the queue and hence acquires the lock","operationId":"accquireLock","produces":["application/json"],"parameters":[{"name":"lockreference","in":"path","description":"Lock Reference","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}}},"/v{version: [0-9]+}/locks/create/{lockname}":{"post":{"tags":["Lock Api"],"summary":"Create Lock","description":"Puts the requesting process in the q for this lock. The corresponding node will be created in zookeeper if it did not already exist. Lock Name is the \"key\" of the form keyspaceName.tableName.rowId","operationId":"createLockReference","produces":["application/json"],"parameters":[{"name":"lockname","in":"path","description":"Lock Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}}},"/v{version: [0-9]+}/locks/delete/{lockname}":{"delete":{"tags":["Lock Api"],"summary":"Delete Lock","description":"","operationId":"deleteLock","produces":["application/json"],"parameters":[{"name":"lockname","in":"path","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}}},"/v{version: [0-9]+}/locks/enquire/{lockname}":{"get":{"tags":["Lock Api"],"summary":"Get Lock Holder","description":"Gets the current Lock Holder","operationId":"currentLockHolder","produces":["application/json"],"parameters":[{"name":"lockname","in":"path","description":"Lock Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}}},"/v{version: [0-9]+}/locks/release/{lockreference}":{"delete":{"tags":["Lock Api"],"summary":"Release Lock","description":"deletes the process from the zk queue","operationId":"unLock","produces":["application/json"],"parameters":[{"name":"lockreference","in":"path","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}}},"/v{version: [0-9]+}/locks/{lockname}":{"get":{"tags":["Lock Api"],"summary":"Lock State","description":"Returns current Lock State and Holder.","operationId":"currentLockState","produces":["application/json"],"parameters":[{"name":"lockname","in":"path","description":"Lock Name","required":true,"type":"string"}],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}}},"/v{version: [0-9]+}/test":{"get":{"tags":["Test Api"],"summary":"Get Test","description":"","operationId":"simpleTests","produces":["application/json"],"parameters":[],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}}},"/v{version: [0-9]+}/version":{"get":{"tags":["Version Api"],"summary":"Get Version","description":"","operationId":"version","produces":["application/json"],"parameters":[],"responses":{"200":{"description":"successful operation","schema":{"type":"object","additionalProperties":{"type":"object"}}}}}}},"definitions":{"JsonTable":{"type":"object","properties":{"leasePeriod":{"type":"integer","format":"int64","description":"Lease period"},"notifyUrl":{"type":"string","description":"URL to be notified"}},"description":"model for leased lock"},"PreparedQueryObject":{"type":"object","properties":{"values":{"type":"array","items":{"type":"object"}},"query":{"type":"string"}}}}} \ No newline at end of file +{ + "swagger": "2.0", + "info": { + "version": "1.0.0", + "title": "" + }, + "host": "localhost:8080", + "basePath": "/MUSIC/rest", + "tags": [ + { + "name": "Data Api" + }, + { + "name": "Healthcheck Api" + }, + { + "name": "Lock Api" + }, + { + "name": "Q Api" + }, + { + "name": "Test Api" + }, + { + "name": "Version Api" + } + ], + "schemes": [ + "http" + ], + "paths": { + "/v2/keyspaces/{keyspace}/tables/{tablename}/rows": { + "get": { + "tags": [ + "Data Api" + ], + "summary": "Select All or Select Specific", + "description": "", + "operationId": "select", + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "version", + "in": "path", + "description": "Major Version", + "required": true, + "type": "string" + }, + { + "name": "X-minorVersion", + "in": "header", + "description": "Minor Version", + "required": false, + "type": "string" + }, + { + "name": "X-patchVersion", + "in": "header", + "description": "Patch Version", + "required": false, + "type": "string" + }, + { + "name": "aid", + "in": "header", + "description": "AID", + "required": true, + "type": "string" + }, + { + "name": "ns", + "in": "header", + "description": "Application namespace", + "required": true, + "type": "string" + }, + { + "name": "Authorization", + "in": "header", + "description": "Authorization", + "required": true, + "type": "string" + }, + { + "name": "keyspace", + "in": "path", + "description": "Keyspace Name", + "required": true, + "type": "string" + }, + { + "name": "tablename", + "in": "path", + "description": "Table Name", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "object", + "additionalProperties": { + "type": "object" + } + } + } + } + }, + "post": { + "tags": [ + "Data Api" + ], + "summary": "Insert Into Table", + "description": "", + "operationId": "insertIntoTable", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "version", + "in": "path", + "description": "Major Version", + "required": true, + "type": "string" + }, + { + "name": "X-minorVersion", + "in": "header", + "description": "Minor Version", + "required": false, + "type": "string" + }, + { + "name": "X-patchVersion", + "in": "header", + "description": "Patch Version", + "required": false, + "type": "string" + }, + { + "name": "aid", + "in": "header", + "description": "AID", + "required": true, + "type": "string" + }, + { + "name": "ns", + "in": "header", + "description": "Application namespace", + "required": true, + "type": "string" + }, + { + "name": "Authorization", + "in": "header", + "description": "Authorization", + "required": true, + "type": "string" + }, + { + "in": "body", + "name": "body", + "required": false, + "schema": { + "$ref": "#/definitions/JsonTable" + } + }, + { + "name": "keyspace", + "in": "path", + "description": "Keyspace Name", + "required": true, + "type": "string" + }, + { + "name": "tablename", + "in": "path", + "description": "Table Name", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "string" + } + } + } + }, + "put": { + "tags": [ + "Data Api" + ], + "summary": "Update Table", + "description": "", + "operationId": "updateTable", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "version", + "in": "path", + "description": "Major Version", + "required": true, + "type": "string" + }, + { + "name": "X-minorVersion", + "in": "header", + "description": "Minor Version", + "required": false, + "type": "string" + }, + { + "name": "X-patchVersion", + "in": "header", + "description": "Patch Version", + "required": false, + "type": "string" + }, + { + "name": "aid", + "in": "header", + "description": "AID", + "required": true, + "type": "string" + }, + { + "name": "ns", + "in": "header", + "description": "Application namespace", + "required": true, + "type": "string" + }, + { + "name": "Authorization", + "in": "header", + "description": "Authorization", + "required": true, + "type": "string" + }, + { + "in": "body", + "name": "body", + "required": false, + "schema": { + "$ref": "#/definitions/JsonTable" + } + }, + { + "name": "keyspace", + "in": "path", + "description": "Keyspace Name", + "required": true, + "type": "string" + }, + { + "name": "tablename", + "in": "path", + "description": "Table Name", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "string" + } + } + } + }, + "delete": { + "tags": [ + "Data Api" + ], + "summary": "Delete From table", + "description": "", + "operationId": "deleteFromTable", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "version", + "in": "path", + "description": "Major Version", + "required": true, + "type": "string" + }, + { + "name": "X-minorVersion", + "in": "header", + "description": "Minor Version", + "required": false, + "type": "string" + }, + { + "name": "X-patchVersion", + "in": "header", + "description": "Patch Version", + "required": false, + "type": "string" + }, + { + "name": "aid", + "in": "header", + "description": "AID", + "required": true, + "type": "string" + }, + { + "name": "ns", + "in": "header", + "description": "Application namespace", + "required": true, + "type": "string" + }, + { + "name": "Authorization", + "in": "header", + "description": "Authorization", + "required": true, + "type": "string" + }, + { + "in": "body", + "name": "body", + "required": false, + "schema": { + "$ref": "#/definitions/JsonTable" + } + }, + { + "name": "keyspace", + "in": "path", + "description": "Keyspace Name", + "required": true, + "type": "string" + }, + { + "name": "tablename", + "in": "path", + "description": "Table Name", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "string" + } + } + } + } + }, + "/v2/keyspaces/{name}": { + "post": { + "tags": [ + "Data Api" + ], + "summary": "Create Keyspace", + "description": "", + "operationId": "createKeySpace", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "version", + "in": "path", + "description": "Major Version", + "required": true, + "type": "string" + }, + { + "name": "X-minorVersion", + "in": "header", + "description": "Minor Version", + "required": false, + "type": "string" + }, + { + "name": "X-patchVersion", + "in": "header", + "description": "Patch Version", + "required": false, + "type": "string" + }, + { + "name": "aid", + "in": "header", + "description": "AID", + "required": true, + "type": "string" + }, + { + "name": "Authorization", + "in": "header", + "description": "Authorization", + "required": true, + "type": "string" + }, + { + "name": "ns", + "in": "header", + "description": "Application namespace", + "required": true, + "type": "string" + }, + { + "in": "body", + "name": "body", + "required": false, + "schema": { + "$ref": "#/definitions/JsonTable" + } + }, + { + "name": "name", + "in": "path", + "description": "Keyspace Name", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "string" + } + } + } + }, + "delete": { + "tags": [ + "Data Api" + ], + "summary": "Delete Keyspace", + "description": "", + "operationId": "dropKeySpace", + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "version", + "in": "path", + "description": "Major Version", + "required": true, + "type": "string" + }, + { + "name": "X-minorVersion", + "in": "header", + "description": "Minor Version", + "required": false, + "type": "string" + }, + { + "name": "X-patchVersion", + "in": "header", + "description": "Patch Version", + "required": false, + "type": "string" + }, + { + "name": "aid", + "in": "header", + "description": "AID", + "required": true, + "type": "string" + }, + { + "name": "Authorization", + "in": "header", + "description": "Authorization", + "required": true, + "type": "string" + }, + { + "name": "ns", + "in": "header", + "description": "Application namespace", + "required": true, + "type": "string" + }, + { + "name": "name", + "in": "path", + "description": "Keyspace Name", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "string" + } + } + } + } + }, + "/v2/keyspaces/{keyspace}/tables/{tablename}/index/{field}": { + "post": { + "tags": [ + "Data Api" + ], + "summary": "Create Index", + "description": "", + "operationId": "createIndex", + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "version", + "in": "path", + "description": "Major Version", + "required": true, + "type": "string" + }, + { + "name": "X-minorVersion", + "in": "header", + "description": "Minor Version", + "required": false, + "type": "string" + }, + { + "name": "X-patchVersion", + "in": "header", + "description": "Patch Version", + "required": false, + "type": "string" + }, + { + "name": "aid", + "in": "header", + "description": "AID", + "required": true, + "type": "string" + }, + { + "name": "ns", + "in": "header", + "description": "Application namespace", + "required": true, + "type": "string" + }, + { + "name": "Authorization", + "in": "header", + "description": "Authorization", + "required": true, + "type": "string" + }, + { + "name": "keyspace", + "in": "path", + "description": "Keyspace Name", + "required": true, + "type": "string" + }, + { + "name": "tablename", + "in": "path", + "description": "Table Name", + "required": true, + "type": "string" + }, + { + "name": "field", + "in": "path", + "description": "Field Name", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "string" + } + } + } + } + }, + "/v2/keyspaces/{keyspace}/tables/{tablename}/rows/criticalget": { + "put": { + "tags": [ + "Data Api" + ], + "summary": "Select Critical", + "description": "", + "operationId": "selectCritical", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "version", + "in": "path", + "description": "Major Version", + "required": true, + "type": "string" + }, + { + "name": "X-minorVersion", + "in": "header", + "description": "Minor Version", + "required": false, + "type": "string" + }, + { + "name": "X-patchVersion", + "in": "header", + "description": "Patch Version", + "required": false, + "type": "string" + }, + { + "name": "aid", + "in": "header", + "description": "AID", + "required": true, + "type": "string" + }, + { + "name": "ns", + "in": "header", + "description": "Application namespace", + "required": true, + "type": "string" + }, + { + "name": "Authorization", + "in": "header", + "description": "Authorization", + "required": true, + "type": "string" + }, + { + "in": "body", + "name": "body", + "required": false, + "schema": { + "$ref": "#/definitions/JsonTable" + } + }, + { + "name": "keyspace", + "in": "path", + "description": "Keyspace Name", + "required": true, + "type": "string" + }, + { + "name": "tablename", + "in": "path", + "description": "Table Name", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "object", + "additionalProperties": { + "type": "object" + } + } + } + } + } + }, + "/v2/keyspaces/{keyspace}/tables/{tablename}": { + "post": { + "tags": [ + "Data Api" + ], + "summary": "Create Table", + "description": "", + "operationId": "createTable", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "version", + "in": "path", + "description": "Major Version", + "required": true, + "type": "string" + }, + { + "name": "X-minorVersion", + "in": "header", + "description": "Minor Version", + "required": false, + "type": "string" + }, + { + "name": "X-patchVersion", + "in": "header", + "description": "Patch Version", + "required": false, + "type": "string" + }, + { + "name": "aid", + "in": "header", + "description": "AID", + "required": true, + "type": "string" + }, + { + "name": "ns", + "in": "header", + "description": "Application namespace", + "required": true, + "type": "string" + }, + { + "name": "Authorization", + "in": "header", + "description": "Authorization", + "required": true, + "type": "string" + }, + { + "in": "body", + "name": "body", + "required": false, + "schema": { + "$ref": "#/definitions/JsonTable" + } + }, + { + "name": "keyspace", + "in": "path", + "description": "Keyspace Name", + "required": true, + "type": "string" + }, + { + "name": "tablename", + "in": "path", + "description": "Table Name", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "string" + } + } + } + }, + "delete": { + "tags": [ + "Data Api" + ], + "summary": "Drop Table", + "description": "", + "operationId": "dropTable", + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "version", + "in": "path", + "description": "Major Version", + "required": true, + "type": "string" + }, + { + "name": "X-minorVersion", + "in": "header", + "description": "Minor Version", + "required": false, + "type": "string" + }, + { + "name": "X-patchVersion", + "in": "header", + "description": "Patch Version", + "required": false, + "type": "string" + }, + { + "name": "aid", + "in": "header", + "description": "AID", + "required": true, + "type": "string" + }, + { + "name": "ns", + "in": "header", + "description": "Application namespace", + "required": true, + "type": "string" + }, + { + "name": "Authorization", + "in": "header", + "description": "Authorization", + "required": true, + "type": "string" + }, + { + "name": "keyspace", + "in": "path", + "description": "Keyspace Name", + "required": true, + "type": "string" + }, + { + "name": "tablename", + "in": "path", + "description": "Table Name", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "string" + } + } + } + } + }, + "/v{version}/service/pingCassandra/{consistency}": { + "get": { + "tags": [ + "Healthcheck Api" + ], + "summary": "Get Health Status", + "description": "", + "operationId": "cassandraStatus", + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "consistency", + "in": "path", + "description": "Consistency level", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "object", + "additionalProperties": { + "type": "object" + } + } + } + } + } + }, + "/v{version}/service/pingZookeeper": { + "get": { + "tags": [ + "Healthcheck Api" + ], + "summary": "Get Health Status", + "description": "", + "operationId": "ZKStatus", + "produces": [ + "application/json" + ], + "parameters": [], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "object", + "additionalProperties": { + "type": "object" + } + } + } + } + } + }, + "/v2/locks/create/{lockname}": { + "post": { + "tags": [ + "Lock Api" + ], + "summary": "Create Lock", + "description": "Puts the requesting process in the q for this lock. The corresponding node will be created in zookeeper if it did not already exist. Lock Name is the \"key\" of the form keyspaceName.tableName.rowId", + "operationId": "createLockReference", + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "lockname", + "in": "path", + "description": "Lock Name", + "required": true, + "type": "string" + }, + { + "name": "X-minorVersion", + "in": "header", + "description": "Minor Version", + "required": false, + "type": "string" + }, + { + "name": "X-patchVersion", + "in": "header", + "description": "Patch Version", + "required": false, + "type": "string" + }, + { + "name": "Authorization", + "in": "header", + "description": "Authorization", + "required": true, + "type": "string" + }, + { + "name": "aid", + "in": "header", + "description": "AID", + "required": true, + "type": "string" + }, + { + "name": "ns", + "in": "header", + "description": "Application namespace", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "object", + "additionalProperties": { + "type": "object" + } + } + } + } + } + }, + "/v2/locks/acquire-with-lease/{lockreference}": { + "post": { + "tags": [ + "Lock Api" + ], + "summary": "Aquire Lock with Lease", + "description": "", + "operationId": "accquireLockWithLease", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "required": false, + "schema": { + "$ref": "#/definitions/JsonTable" + } + }, + { + "name": "lockreference", + "in": "path", + "description": "Lock Reference", + "required": true, + "type": "string" + }, + { + "name": "X-minorVersion", + "in": "header", + "description": "Minor Version", + "required": false, + "type": "string" + }, + { + "name": "X-patchVersion", + "in": "header", + "description": "Patch Version", + "required": false, + "type": "string" + }, + { + "name": "Authorization", + "in": "header", + "description": "Authorization", + "required": true, + "type": "string" + }, + { + "name": "aid", + "in": "header", + "description": "AID", + "required": true, + "type": "string" + }, + { + "name": "ns", + "in": "header", + "description": "Application namespace", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "object", + "additionalProperties": { + "type": "object" + } + } + } + } + } + }, + "/v2/locks/acquire/{lockreference}": { + "get": { + "tags": [ + "Lock Api" + ], + "summary": "Aquire Lock", + "description": "Checks if the node is in the top of the queue and hence acquires the lock", + "operationId": "accquireLock", + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "lockreference", + "in": "path", + "description": "Lock Reference", + "required": true, + "type": "string" + }, + { + "name": "X-minorVersion", + "in": "header", + "description": "Minor Version", + "required": false, + "type": "string" + }, + { + "name": "X-patchVersion", + "in": "header", + "description": "Patch Version", + "required": false, + "type": "string" + }, + { + "name": "Authorization", + "in": "header", + "description": "Authorization", + "required": true, + "type": "string" + }, + { + "name": "aid", + "in": "header", + "description": "AID", + "required": true, + "type": "string" + }, + { + "name": "ns", + "in": "header", + "description": "Application namespace", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "object", + "additionalProperties": { + "type": "object" + } + } + } + } + } + }, + "/v2/locks/enquire/{lockname}": { + "get": { + "tags": [ + "Lock Api" + ], + "summary": "Get Lock Holder", + "description": "Gets the current Lock Holder", + "operationId": "currentLockHolder", + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "lockname", + "in": "path", + "description": "Lock Name", + "required": true, + "type": "string" + }, + { + "name": "X-minorVersion", + "in": "header", + "description": "Minor Version", + "required": false, + "type": "string" + }, + { + "name": "X-patchVersion", + "in": "header", + "description": "Patch Version", + "required": false, + "type": "string" + }, + { + "name": "Authorization", + "in": "header", + "description": "Authorization", + "required": true, + "type": "string" + }, + { + "name": "aid", + "in": "header", + "description": "AID", + "required": true, + "type": "string" + }, + { + "name": "ns", + "in": "header", + "description": "Application namespace", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "object", + "additionalProperties": { + "type": "object" + } + } + } + } + } + }, + "/v2/locks/{lockname}": { + "get": { + "tags": [ + "Lock Api" + ], + "summary": "Lock State", + "description": "Returns current Lock State and Holder.", + "operationId": "currentLockState", + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "lockname", + "in": "path", + "description": "Lock Name", + "required": true, + "type": "string" + }, + { + "name": "X-minorVersion", + "in": "header", + "description": "Minor Version", + "required": false, + "type": "string" + }, + { + "name": "X-patchVersion", + "in": "header", + "description": "Patch Version", + "required": false, + "type": "string" + }, + { + "name": "Authorization", + "in": "header", + "description": "Authorization", + "required": true, + "type": "string" + }, + { + "name": "aid", + "in": "header", + "description": "AID", + "required": true, + "type": "string" + }, + { + "name": "ns", + "in": "header", + "description": "Application namespace", + "required": true, + "type": "string" + }, + { + "name": "userId", + "in": "header", + "description": "userId", + "required": true, + "type": "string" + }, + { + "name": "password", + "in": "header", + "description": "Password", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "object", + "additionalProperties": { + "type": "object" + } + } + } + } + } + }, + "/v2/locks/release/{lockreference}": { + "delete": { + "tags": [ + "Lock Api" + ], + "summary": "Release Lock", + "description": "deletes the process from the zk queue", + "operationId": "unLock", + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "lockreference", + "in": "path", + "required": true, + "type": "string" + }, + { + "name": "X-minorVersion", + "in": "header", + "description": "Minor Version", + "required": false, + "type": "string" + }, + { + "name": "X-patchVersion", + "in": "header", + "description": "Patch Version", + "required": false, + "type": "string" + }, + { + "name": "Authorization", + "in": "header", + "description": "Authorization", + "required": true, + "type": "string" + }, + { + "name": "aid", + "in": "header", + "description": "AID", + "required": true, + "type": "string" + }, + { + "name": "ns", + "in": "header", + "description": "Application namespace", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "object", + "additionalProperties": { + "type": "object" + } + } + } + } + } + }, + "/v2/locks/delete/{lockname}": { + "delete": { + "tags": [ + "Lock Api" + ], + "summary": "Delete Lock", + "description": "", + "operationId": "deleteLock", + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "lockname", + "in": "path", + "required": true, + "type": "string" + }, + { + "name": "X-minorVersion", + "in": "header", + "description": "Minor Version", + "required": false, + "type": "string" + }, + { + "name": "X-patchVersion", + "in": "header", + "description": "Patch Version", + "required": false, + "type": "string" + }, + { + "name": "aid", + "in": "header", + "description": "AID", + "required": true, + "type": "string" + }, + { + "name": "Authorization", + "in": "header", + "description": "Authorization", + "required": true, + "type": "string" + }, + { + "name": "ns", + "in": "header", + "description": "Application namespace", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "object", + "additionalProperties": { + "type": "object" + } + } + } + } + } + }, + "/{version}/priorityq/keyspaces/{keyspace}/{qname}": { + "post": { + "tags": [ + "Q Api" + ], + "summary": "Create Q", + "description": "", + "operationId": "createQ", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "version", + "in": "path", + "description": "Major Version", + "required": true, + "type": "string" + }, + { + "name": "X-minorVersion", + "in": "header", + "description": "Minor Version", + "required": false, + "type": "string" + }, + { + "name": "X-patchVersion", + "in": "header", + "description": "Patch Version", + "required": false, + "type": "string" + }, + { + "name": "aid", + "in": "header", + "description": "AID", + "required": true, + "type": "string" + }, + { + "name": "ns", + "in": "header", + "description": "Application namespace", + "required": true, + "type": "string" + }, + { + "name": "Authorization", + "in": "header", + "description": "Authorization", + "required": true, + "type": "string" + }, + { + "in": "body", + "name": "body", + "required": false, + "schema": { + "$ref": "#/definitions/JsonTable" + } + }, + { + "name": "keyspace", + "in": "path", + "description": "Key Space", + "required": true, + "type": "string" + }, + { + "name": "qname", + "in": "path", + "description": "Table Name", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "string" + } + } + } + }, + "delete": { + "tags": [ + "Q Api" + ], + "summary": "DropQ", + "description": "", + "operationId": "dropQ", + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "version", + "in": "path", + "description": "Major Version", + "required": true, + "type": "string" + }, + { + "name": "X-minorVersion", + "in": "header", + "description": "Minor Version", + "required": false, + "type": "string" + }, + { + "name": "X-patchVersion", + "in": "header", + "description": "Patch Version", + "required": false, + "type": "string" + }, + { + "name": "aid", + "in": "header", + "description": "AID", + "required": true, + "type": "string" + }, + { + "name": "ns", + "in": "header", + "description": "Application namespace", + "required": true, + "type": "string" + }, + { + "name": "Authorization", + "in": "header", + "description": "Authorization", + "required": true, + "type": "string" + }, + { + "name": "keyspace", + "in": "path", + "description": "Key Space", + "required": true, + "type": "string" + }, + { + "name": "qname", + "in": "path", + "description": "Table Name", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "string" + } + } + } + } + }, + "/{version}/priorityq/keyspaces/{keyspace}/{qname}/rows": { + "post": { + "tags": [ + "Q Api" + ], + "summary": "", + "description": "", + "operationId": "insertIntoQ", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "version", + "in": "path", + "description": "Major Version", + "required": true, + "type": "string" + }, + { + "name": "X-minorVersion", + "in": "header", + "description": "Minor Version", + "required": false, + "type": "string" + }, + { + "name": "X-patchVersion", + "in": "header", + "description": "Patch Version", + "required": false, + "type": "string" + }, + { + "name": "aid", + "in": "header", + "description": "AID", + "required": true, + "type": "string" + }, + { + "name": "ns", + "in": "header", + "description": "Application namespace", + "required": true, + "type": "string" + }, + { + "name": "Authorization", + "in": "header", + "description": "Authorization", + "required": true, + "type": "string" + }, + { + "in": "body", + "name": "body", + "required": false, + "schema": { + "$ref": "#/definitions/JsonTable" + } + }, + { + "name": "keyspace", + "in": "path", + "description": "Key Space", + "required": true, + "type": "string" + }, + { + "name": "qname", + "in": "path", + "description": "Table Name", + "required": true, + "type": "string" + } + ], + "responses": { + "default": { + "description": "successful operation" + } + } + }, + "put": { + "tags": [ + "Q Api" + ], + "summary": "updateQ", + "description": "", + "operationId": "updateQ", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "version", + "in": "path", + "description": "Major Version", + "required": true, + "type": "string" + }, + { + "name": "X-minorVersion", + "in": "header", + "description": "Minor Version", + "required": false, + "type": "string" + }, + { + "name": "X-patchVersion", + "in": "header", + "description": "Patch Version", + "required": false, + "type": "string" + }, + { + "name": "aid", + "in": "header", + "description": "AID", + "required": true, + "type": "string" + }, + { + "name": "ns", + "in": "header", + "description": "Application namespace", + "required": true, + "type": "string" + }, + { + "name": "Authorization", + "in": "header", + "description": "Authorization", + "required": true, + "type": "string" + }, + { + "in": "body", + "name": "body", + "required": false, + "schema": { + "$ref": "#/definitions/JsonTable" + } + }, + { + "name": "keyspace", + "in": "path", + "description": "Key Space", + "required": true, + "type": "string" + }, + { + "name": "qname", + "in": "path", + "description": "Table Name", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "string" + } + } + } + }, + "delete": { + "tags": [ + "Q Api" + ], + "summary": "deleteQ", + "description": "", + "operationId": "deleteFromQ", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "version", + "in": "path", + "description": "Major Version", + "required": true, + "type": "string" + }, + { + "name": "X-minorVersion", + "in": "header", + "description": "Minor Version", + "required": false, + "type": "string" + }, + { + "name": "X-patchVersion", + "in": "header", + "description": "Patch Version", + "required": false, + "type": "string" + }, + { + "name": "aid", + "in": "header", + "description": "AID", + "required": true, + "type": "string" + }, + { + "name": "ns", + "in": "header", + "description": "Application namespace", + "required": true, + "type": "string" + }, + { + "name": "Authorization", + "in": "header", + "description": "Authorization", + "required": true, + "type": "string" + }, + { + "in": "body", + "name": "body", + "required": false, + "schema": { + "$ref": "#/definitions/JsonTable" + } + }, + { + "name": "keyspace", + "in": "path", + "description": "Key Space", + "required": true, + "type": "string" + }, + { + "name": "qname", + "in": "path", + "description": "Table Name", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "string" + } + } + } + } + }, + "/{version}/priorityq/keyspaces/{keyspace}/{qname}/peek": { + "get": { + "tags": [ + "Q Api" + ], + "summary": "", + "description": "", + "operationId": "peek", + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "version", + "in": "path", + "description": "Major Version", + "required": true, + "type": "string" + }, + { + "name": "X-minorVersion", + "in": "header", + "description": "Minor Version", + "required": false, + "type": "string" + }, + { + "name": "X-patchVersion", + "in": "header", + "description": "Patch Version", + "required": false, + "type": "string" + }, + { + "name": "aid", + "in": "header", + "description": "AID", + "required": true, + "type": "string" + }, + { + "name": "ns", + "in": "header", + "description": "Application namespace", + "required": true, + "type": "string" + }, + { + "name": "Authorization", + "in": "header", + "description": "Authorization", + "required": true, + "type": "string" + }, + { + "name": "keyspace", + "in": "path", + "description": "Key Space", + "required": true, + "type": "string" + }, + { + "name": "qname", + "in": "path", + "description": "Table Name", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "object", + "additionalProperties": { + "type": "object" + } + } + } + } + } + }, + "/{version}/priorityq/keyspaces/{keyspace}/{qname}/filter": { + "get": { + "tags": [ + "Q Api" + ], + "summary": "filter", + "description": "", + "operationId": "filter", + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "version", + "in": "path", + "description": "Major Version", + "required": true, + "type": "string" + }, + { + "name": "X-minorVersion", + "in": "header", + "description": "Minor Version", + "required": false, + "type": "string" + }, + { + "name": "X-patchVersion", + "in": "header", + "description": "Patch Version", + "required": false, + "type": "string" + }, + { + "name": "aid", + "in": "header", + "description": "AID", + "required": true, + "type": "string" + }, + { + "name": "ns", + "in": "header", + "description": "Application namespace", + "required": true, + "type": "string" + }, + { + "name": "Authorization", + "in": "header", + "description": "Authorization", + "required": true, + "type": "string" + }, + { + "name": "keyspace", + "in": "path", + "description": "Key Space", + "required": true, + "type": "string" + }, + { + "name": "qname", + "in": "path", + "description": "Table Name", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "object", + "additionalProperties": { + "type": "object" + } + } + } + } + } + }, + "/v{version}/test": { + "get": { + "tags": [ + "Test Api" + ], + "summary": "Get Test", + "description": "", + "operationId": "simpleTests", + "produces": [ + "application/json" + ], + "parameters": [], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "object", + "additionalProperties": { + "type": "object" + } + } + } + } + } + }, + "/v{version}/version": { + "get": { + "tags": [ + "Version Api" + ], + "summary": "Get Version", + "description": "", + "operationId": "version", + "produces": [ + "application/json" + ], + "parameters": [], + "responses": { + "200": { + "description": "successful operation", + "schema": { + "type": "object", + "additionalProperties": { + "type": "object" + } + } + } + } + } + } + }, + "definitions": { + "JsonTable": { + "type": "object", + "properties": { + "columns": { + "type": "array", + "description": "Column values", + "items": { + "type": "string" + } + }, + "consistencyInfo": { + "type": "object", + "description": "Consistency level", + "additionalProperties": { + "type": "string" + } + }, + "conditions": { + "type": "object", + "description": "Conditions", + "additionalProperties": { + "type": "object" + } + }, + "ttl": { + "type": "string", + "description": "Time to live information" + }, + "timestamp": { + "type": "string", + "description": "Time stamp" + } + }, + "description": "Json model for delete" + } + } +} diff --git a/musictrigger/src/MusicTrigger.java b/musictrigger/src/MusicTrigger.java old mode 100644 new mode 100755 index b3a54293..d70e41a0 --- a/musictrigger/src/MusicTrigger.java +++ b/musictrigger/src/MusicTrigger.java @@ -23,7 +23,9 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.Iterator; +import java.util.Map; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; @@ -74,7 +76,7 @@ public class MusicTrigger implements ITrigger { operation = "insert"; else operation = "update"; - + Map changeMap = new HashMap<>(); obj.put("operation", operation); obj.put("keyspace", ksName); @@ -83,31 +85,38 @@ public class MusicTrigger implements ITrigger { obj.put("primary_key", partition.metadata().getKeyValidator().getString(partition.partitionKey().getKey())); //obj.put("message_id", partition.metadata().getKeyValidator().getString(partition.partitionKey().getKey())); - try { - UnfilteredRowIterator it = partition.unfilteredIterator(); - while (it.hasNext()) { - Unfiltered un = it.next(); - Clustering clt = (Clustering) un.clustering(); - Iterator cells = partition.getRow(clt).cells().iterator(); - Iterator columns = partition.getRow(clt).columns().iterator(); - - while(columns.hasNext()){ - ColumnDefinition columnDef = columns.next(); - Cell cell = cells.next(); - String data = new String(cell.value().array()); // If cell type is text - logger.info("Inside triggers loop: "+columnDef.toString()+" : "+data); - obj.put(columnDef.toString(), data); - } - } - } catch (Exception e) { - + if("update".equals(operation)) { + try { + UnfilteredRowIterator it = partition.unfilteredIterator(); + while (it.hasNext()) { + Unfiltered un = it.next(); + Clustering clt = (Clustering) un.clustering(); + Iterator cells = partition.getRow(clt).cells().iterator(); + Iterator columns = partition.getRow(clt).columns().iterator(); + + while(columns.hasNext()){ + ColumnDefinition columnDef = columns.next(); + Cell cell = cells.next(); + String data = new String(cell.value().array()); // If cell type is text + logger.info("Inside triggers loop: "+columnDef.name+" : "+data); + changeMap.put(ksName+"."+tableName+"."+columnDef.name,data); + changeMap.put("field_value",ksName+"."+tableName+":"+columnDef.name+":"+data); + } + } + } catch (Exception e) { + + } + } else { + changeMap.put("field_value", ksName+"."+tableName); } + + obj.put("changeValue", changeMap); logger.info("Sending response: "+obj.toString()); try { notifyMusic(obj.toString()); } catch(Exception e) { e.printStackTrace(); - logger.error("Notification failed..."+e.getMessage()s); + logger.error("Notification failed..."+e.getMessage()); } return Collections.emptyList(); } diff --git a/pom.xml b/pom.xml index 8ec039d8..657973f6 100755 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ org.onap.music MUSIC war - 3.0.5-SNAPSHOT + 3.0.13-SNAPSHOT This is the MUSIC REST interface, packaged as a war file. @@ -185,7 +185,11 @@ provided - + ch.qos.logback @@ -341,7 +345,7 @@ com.owlike genson - 0.99 + 1.3 diff --git a/src/main/java/org/onap/music/datastore/jsonobjects/JSONCallbackResponse.java b/src/main/java/org/onap/music/datastore/jsonobjects/JSONCallbackResponse.java new file mode 100755 index 00000000..c521d0df --- /dev/null +++ b/src/main/java/org/onap/music/datastore/jsonobjects/JSONCallbackResponse.java @@ -0,0 +1,80 @@ +/* + * ============LICENSE_START========================================== + * org.onap.music + * =================================================================== + * Copyright (c) 2017 AT&T Intellectual Property + * =================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================= + * ==================================================================== + */ + +package org.onap.music.datastore.jsonobjects; + +import java.util.Map; + +public class JSONCallbackResponse { + + private String full_table; + private String keyspace; + private Map changeValue; + private String operation; + private String table_name; + private String primary_key; + private Object miscObjects; + public String getFull_table() { + return full_table; + } + public void setFull_table(String full_table) { + this.full_table = full_table; + } + public String getKeyspace() { + return keyspace; + } + public void setKeyspace(String keyspace) { + this.keyspace = keyspace; + } + public String getOperation() { + return operation; + } + public void setOperation(String operation) { + this.operation = operation; + } + public String getTable_name() { + return table_name; + } + public void setTable_name(String table_name) { + this.table_name = table_name; + } + public String getPrimary_key() { + return primary_key; + } + public void setPrimary_key(String primary_key) { + this.primary_key = primary_key; + } + public Object getMiscObjects() { + return miscObjects; + } + public void setMiscObjects(Object miscObjects) { + this.miscObjects = miscObjects; + } + public void setChangeValue(Map changeValue) { + this.changeValue = changeValue; + } + public Map getChangeValue() { + return changeValue; + } + + +} diff --git a/src/main/java/org/onap/music/datastore/jsonobjects/JsonCallback.java b/src/main/java/org/onap/music/datastore/jsonobjects/JsonCallback.java old mode 100644 new mode 100755 index 42b12f10..4a865320 --- a/src/main/java/org/onap/music/datastore/jsonobjects/JsonCallback.java +++ b/src/main/java/org/onap/music/datastore/jsonobjects/JsonCallback.java @@ -22,6 +22,7 @@ package org.onap.music.datastore.jsonobjects; import java.io.Serializable; +import java.util.Map; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @@ -39,6 +40,17 @@ public class JsonCallback implements Serializable { private String notifyWhenChangeIn; private String notifyWhenInsertsIn; private String notifyWhenDeletesIn; + private Map responseBody; + + private String uuid; + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } @ApiModelProperty(value = "application name") public String getApplicationName() { @@ -112,4 +124,12 @@ public class JsonCallback implements Serializable { this.notifyWhenDeletesIn = notifyWhenDeletesIn; } + public Map getResponseBody() { + return responseBody; + } + + public void setResponseBody(Map responseBody) { + this.responseBody = responseBody; + } + } diff --git a/src/main/java/org/onap/music/datastore/jsonobjects/JsonNotification.java b/src/main/java/org/onap/music/datastore/jsonobjects/JsonNotification.java new file mode 100755 index 00000000..ad999190 --- /dev/null +++ b/src/main/java/org/onap/music/datastore/jsonobjects/JsonNotification.java @@ -0,0 +1,115 @@ +/* + * ============LICENSE_START========================================== + * org.onap.music + * =================================================================== + * Copyright (c) 2017 AT&T Intellectual Property + * =================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================= + * ==================================================================== + */ +package org.onap.music.datastore.jsonobjects; + +import java.io.Serializable; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +@ApiModel(value = "JsonNotification", description = "Json model for callback") +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(Include.NON_NULL) +public class JsonNotification implements Serializable { + + private String notify_field; + private String endpoint; + private String username; + private String password; + private String notify_change; + private String notify_insert; + private String notify_delete; + private String operation_type; + + private Map response_body; + + public String getNotify_field() { + return notify_field; + } + public void setNotify_field(String notify_field) { + this.notify_field = notify_field; + } + public String getEndpoint() { + return endpoint; + } + public void setEndpoint(String endpoint) { + this.endpoint = endpoint; + } + public String getUsername() { + return username; + } + public void setUsername(String username) { + this.username = username; + } + public String getPassword() { + return password; + } + public void setPassword(String password) { + this.password = password; + } + public Map getResponse_body() { + return response_body; + } + public void setResponse_body(Map response_body) { + this.response_body = response_body; + } + public String getNotify_change() { + return notify_change; + } + public void setNotify_change(String notify_change) { + this.notify_change = notify_change; + } + public String getNotify_insert() { + return notify_insert; + } + public void setNotify_insert(String notify_insert) { + this.notify_insert = notify_insert; + } + public String getNotify_delete() { + return notify_delete; + } + public void setNotify_delete(String notify_delete) { + this.notify_delete = notify_delete; + } + public String getOperation_type() { + return operation_type; + } + public void setOperation_type(String operation_type) { + this.operation_type = operation_type; + } + + @Override + public String toString() { + try { + return new com.fasterxml.jackson.databind.ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(this); + } catch (com.fasterxml.jackson.core.JsonProcessingException e) { + return notify_field+ " : "+endpoint+ " : "+username+ " : "+password+ " : "+response_body; + } + + } + +} diff --git a/src/main/java/org/onap/music/lockingservice/MusicLockingService.java b/src/main/java/org/onap/music/lockingservice/MusicLockingService.java index ae026903..f9c09338 100644 --- a/src/main/java/org/onap/music/lockingservice/MusicLockingService.java +++ b/src/main/java/org/onap/music/lockingservice/MusicLockingService.java @@ -33,6 +33,7 @@ import org.onap.music.eelf.logging.format.ErrorSeverity; import org.onap.music.eelf.logging.format.ErrorTypes; import org.onap.music.exceptions.MusicLockingException; import org.onap.music.exceptions.MusicServiceException; +import org.onap.music.main.CachingUtil; import org.onap.music.main.MusicUtil; @@ -131,6 +132,7 @@ public class MusicLockingService implements Watcher { public void unlockAndDeleteId(String lockIdWithDollar) throws KeeperException.NoNodeException { String lockId = lockIdWithDollar.replace('$', '/'); zkLockHandle.unlock(lockId); + CachingUtil.deleteKeysFromDB("'"+lockId+"'"); } public void deleteLock(String lockName) throws MusicLockingException { diff --git a/src/main/java/org/onap/music/lockingservice/ZkStatelessLockService.java b/src/main/java/org/onap/music/lockingservice/ZkStatelessLockService.java index 38c873af..5f9c07ee 100644 --- a/src/main/java/org/onap/music/lockingservice/ZkStatelessLockService.java +++ b/src/main/java/org/onap/music/lockingservice/ZkStatelessLockService.java @@ -301,7 +301,6 @@ public class ZkStatelessLockService extends ProtocolSupport { e1.printStackTrace(); } Long ctime = stat.getCtime(); - System.out.println("Created id ....####"+ctime+"##.......id...:"+id); MusicUtil.zkNodeMap.put(id, ctime); PreparedQueryObject pQuery = new PreparedQueryObject(); pQuery.appendQueryString( diff --git a/src/main/java/org/onap/music/main/CachingUtil.java b/src/main/java/org/onap/music/main/CachingUtil.java index d3654118..83b5158f 100755 --- a/src/main/java/org/onap/music/main/CachingUtil.java +++ b/src/main/java/org/onap/music/main/CachingUtil.java @@ -41,7 +41,8 @@ import org.onap.music.eelf.logging.format.AppMessages; import org.onap.music.eelf.logging.format.ErrorSeverity; import org.onap.music.eelf.logging.format.ErrorTypes; import org.onap.music.exceptions.MusicServiceException; - +import org.onap.music.datastore.jsonobjects.JsonNotification; +import org.onap.music.datastore.jsonobjects.JsonCallback; import com.att.eelf.configuration.EELFLogger; import com.datastax.driver.core.DataType; import com.datastax.driver.core.ResultSet; @@ -65,6 +66,7 @@ public class CachingUtil implements Runnable { private static CacheAccess> aafCache = JCS.getInstance("aafCache"); private static CacheAccess appNameCache = JCS.getInstance("appNameCache"); private static CacheAccess> musicValidateCache = JCS.getInstance("musicValidateCache"); + private static CacheAccess callBackCache = JCS.getInstance("callBackCache"); private static Map userAttempts = new HashMap<>(); private static Map lastFailedTime = new HashMap<>(); @@ -73,6 +75,14 @@ public class CachingUtil implements Runnable { return true; return false; } + + public static void updateCallBackCache(String appName, JsonCallback jsonCallBack) { + callBackCache.put(appName, jsonCallBack); + } + + public static JsonCallback getCallBackCache(String appName) { + return callBackCache.get(appName); + } public void initializeMusicCache() { logger.info(EELFLoggerDelegate.applicationLogger,"Initializing Music Cache..."); @@ -102,8 +112,8 @@ public class CachingUtil implements Runnable { String keySpace = row.getString("application_name"); try { userAttempts.put(nameSpace, 0); - AAFResponse responseObj = triggerAAF(nameSpace, userId, password); - if (responseObj.getNs().size() > 0) { + boolean responseObj = triggerAAF(nameSpace, userId, password); + if (responseObj) { map = new HashMap<>(); map.put(userId, password); aafCache.put(nameSpace, map); @@ -164,8 +174,8 @@ public class CachingUtil implements Runnable { } } - AAFResponse responseObj = triggerAAF(nameSpace, userId, password); - if (responseObj.getNs().size() > 0) { + boolean responseObj = triggerAAF(nameSpace, userId, password); + if (responseObj) { //if (responseObj.getNs().get(0).getAdmin().contains(userId)) { //Map map = new HashMap<>(); //map.put(userId, password); @@ -177,7 +187,7 @@ public class CachingUtil implements Runnable { return false; } - private static AAFResponse triggerAAF(String nameSpace, String userId, String password) + private static boolean triggerAAF(String nameSpace, String userId, String password) throws Exception { if (MusicUtil.getAafEndpointUrl() == null) { logger.error(EELFLoggerDelegate.errorLogger,"",AppMessages.UNKNOWNERROR,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR); @@ -210,14 +220,14 @@ public class CachingUtil implements Runnable { // TODO Allow for 2-3 times and forbid any attempt to trigger AAF with invalid values // for specific time. } - response.getHeaders().put(HttpHeaders.CONTENT_TYPE, + /*response.getHeaders().put(HttpHeaders.CONTENT_TYPE, Arrays.asList(MediaType.APPLICATION_JSON)); // AAFResponse output = response.getEntity(AAFResponse.class); response.bufferEntity(); String x = response.getEntity(String.class); - AAFResponse responseObj = new ObjectMapper().readValue(x, AAFResponse.class); + AAFResponse responseObj = new ObjectMapper().readValue(x, AAFResponse.class);*/ - return responseObj; + return true; } public static void updateMusicCache(String keyspace, String nameSpace) { @@ -417,4 +427,15 @@ public class CachingUtil implements Runnable { CachingUtil.updateMusicValidateCache(nameSpace, userId, pwd); return resultMap; } + + public static void deleteKeysFromDB(String deleteKeys) { + PreparedQueryObject pQuery = new PreparedQueryObject(); + pQuery.appendQueryString( + "DELETE FROM admin.locks WHERE lock_id IN ("+deleteKeys+")"); + try { + MusicCore.nonKeyRelatedPut(pQuery, "eventual"); + } catch (Exception e) { + e.printStackTrace(); + } + } } diff --git a/src/main/java/org/onap/music/main/CronJobManager.java b/src/main/java/org/onap/music/main/CronJobManager.java index 5b7a8de4..0344c4a1 100644 --- a/src/main/java/org/onap/music/main/CronJobManager.java +++ b/src/main/java/org/onap/music/main/CronJobManager.java @@ -32,16 +32,18 @@ import javax.servlet.ServletContextListener; import javax.servlet.annotation.WebListener; import org.onap.music.datastore.PreparedQueryObject; +import org.onap.music.eelf.logging.EELFLoggerDelegate; import org.onap.music.exceptions.MusicLockingException; import org.onap.music.exceptions.MusicServiceException; import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.Row; -@WebListener +//@WebListener public class CronJobManager implements ServletContextListener { private ScheduledExecutorService scheduler; + private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CronJobManager.class); @Override public void contextInitialized(ServletContextEvent event) { @@ -55,8 +57,23 @@ public class CronJobManager implements ServletContextListener { } catch (MusicServiceException e1) { e1.printStackTrace(); } - - pQuery = new PreparedQueryObject(); + + //Zookeeper cleanup + scheduler.scheduleAtFixedRate(new Runnable() { + @Override + public void run() { + deleteLocksFromDB(); + } + } , 0, 24, TimeUnit.HOURS); + } + + @Override + public void contextDestroyed(ServletContextEvent event) { + scheduler.shutdownNow(); + } + + public void deleteLocksFromDB() { + PreparedQueryObject pQuery = new PreparedQueryObject(); pQuery.appendQueryString( "select * from admin.locks"); try { @@ -71,68 +88,22 @@ public class CronJobManager implements ServletContextListener { if(System.currentTimeMillis() >= ctime + 24 * 60 * 60 * 1000) { expiredKeys = true; String new_id = id.substring(1); - MusicCore.deleteLock(new_id); - deleteKeys.append(id).append(","); + try { + MusicCore.deleteLock(new_id); + } catch (MusicLockingException e) { + logger.info(EELFLoggerDelegate.applicationLogger, + e.getMessage()); + } + deleteKeys.append("'").append(id).append("'").append(","); } - else { - MusicUtil.zkNodeMap.put(id, ctime); - } - }; + } if(expiredKeys) { deleteKeys.deleteCharAt(deleteKeys.length()-1); - deleteKeysFromDB(deleteKeys); + CachingUtil.deleteKeysFromDB(deleteKeys.toString()); } } catch (MusicServiceException e) { e.printStackTrace(); - } catch (MusicLockingException e) { - e.printStackTrace(); - } - - //Zookeeper cleanup - scheduler.scheduleAtFixedRate(new Runnable() { - @Override - public void run() { - Iterator> it = MusicUtil.zkNodeMap.entrySet().iterator(); - StringBuilder deleteKeys = new StringBuilder(); - Boolean expiredKeys = false; - while (it.hasNext()) { - Map.Entry pair = (Map.Entry)it.next(); - long ctime = pair.getValue(); - if (System.currentTimeMillis() >= ctime + 24 * 60 * 60 * 1000) { - try { - expiredKeys = true; - String id = pair.getKey(); - deleteKeys.append("'").append(id).append("'").append(","); - MusicCore.deleteLock(id.substring(1)); - MusicUtil.zkNodeMap.remove(id); - - } catch (MusicLockingException e) { - e.printStackTrace(); - } - } - } - if(expiredKeys) { - deleteKeys.deleteCharAt(deleteKeys.length()-1); - deleteKeysFromDB(deleteKeys); - } } - } , 0, 24, TimeUnit.HOURS); - } - - @Override - public void contextDestroyed(ServletContextEvent event) { - scheduler.shutdownNow(); - } - - public void deleteKeysFromDB(StringBuilder deleteKeys) { - PreparedQueryObject pQuery = new PreparedQueryObject(); - pQuery.appendQueryString( - "DELETE FROM admin.locks WHERE lock_id IN ("+deleteKeys+")"); - try { - MusicCore.nonKeyRelatedPut(pQuery, "eventual"); - } catch (Exception e) { - e.printStackTrace(); - } } } diff --git a/src/main/java/org/onap/music/main/MusicCore.java b/src/main/java/org/onap/music/main/MusicCore.java index dfc93ccc..b729ba74 100644 --- a/src/main/java/org/onap/music/main/MusicCore.java +++ b/src/main/java/org/onap/music/main/MusicCore.java @@ -708,6 +708,22 @@ public class MusicCore { } return results; } + + public static String getMyHostId() { + PreparedQueryObject pQuery = new PreparedQueryObject(); + pQuery.appendQueryString("SELECT HOST_ID FROM SYSTEM.LOCAL"); + ResultSet rs = null; + try { + rs = getDSHandle().executeEventualGet(pQuery); + Row row = rs.one(); + return (row == null) ? "UNKNOWN" : row.getUUID("HOST_ID").toString(); + } catch (Exception e) { + e.printStackTrace(); + logger.error(EELFLoggerDelegate.errorLogger,e.getMessage()); + } + logger.error(EELFLoggerDelegate.errorLogger, "Some issue during MusicCore.getMyHostId"); + return "UNKNOW"; + } /** * This method performs DDL operations on cassandra, if the the resource is available. Lock ID diff --git a/src/main/java/org/onap/music/main/MusicUtil.java b/src/main/java/org/onap/music/main/MusicUtil.java index 2dd2f231..40d19766 100755 --- a/src/main/java/org/onap/music/main/MusicUtil.java +++ b/src/main/java/org/onap/music/main/MusicUtil.java @@ -86,6 +86,8 @@ public class MusicUtil { private static String myCassaHost = LOCALHOST; private static String defaultMusicIp = LOCALHOST; private static int cassandraPort = 9042; + private static int notifytimeout = 30000; + private static int notifyinterval = 5000; private static boolean debug = true; private static String version = "2.3.0"; @@ -94,7 +96,7 @@ public class MusicUtil { private static long defaultLockLeasePeriod = 6000; private static final String[] propKeys = new String[] { "zookeeper.host", "cassandra.host", "music.ip", "debug", "version", "music.rest.ip", "music.properties", "lock.lease.period", "id", "all.ids", "public.ip", - "all.pubic.ips", "cassandra.user", "cassandra.password", "aaf.endpoint.url","cassandra.port" }; + "all.pubic.ips", "cassandra.user", "cassandra.password", "aaf.endpoint.url","cassandra.port", "notify.timeout", "notify.interval" }; private static String cassName = "cassandra"; private static String cassPwd; @@ -608,7 +610,24 @@ public class MusicUtil { MusicUtil.setCassName(prop.getProperty("cassandra.user")); MusicUtil.setCassPwd(prop.getProperty("cassandra.password")); MusicUtil.setCassandraPort(Integer.parseInt(prop.getProperty("cassandra.port"))); + MusicUtil.setNotifyTimeOut(Integer.parseInt(prop.getProperty("notify.timeout"))); + MusicUtil.setNotifyInterval(Integer.parseInt(prop.getProperty("notify.interval"))); } + + private static void setNotifyInterval(int notifyinterval) { + MusicUtil.notifyinterval = notifyinterval; + } + private static void setNotifyTimeOut(int notifytimeout) { + MusicUtil.notifytimeout = notifytimeout; + } + public static int getNotifyInterval() { + return MusicUtil.notifyinterval; + } + + public static int getNotifyTimeout() { + return MusicUtil.notifytimeout; + + } } diff --git a/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java b/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java index 71570b6c..e930e48b 100755 --- a/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java +++ b/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java @@ -22,28 +22,32 @@ package org.onap.music.rest; +import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.UUID; + import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; -import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.Produces; -import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.ResponseBuilder; import javax.ws.rs.core.Response.Status; +import org.codehaus.jackson.map.ObjectMapper; import org.mindrot.jbcrypt.BCrypt; import org.onap.music.datastore.PreparedQueryObject; +import org.onap.music.datastore.jsonobjects.JSONCallbackResponse; import org.onap.music.datastore.jsonobjects.JSONObject; import org.onap.music.datastore.jsonobjects.JsonCallback; +import org.onap.music.datastore.jsonobjects.JsonNotification; import org.onap.music.datastore.jsonobjects.JsonOnboard; import org.onap.music.eelf.logging.EELFLoggerDelegate; import org.onap.music.eelf.logging.format.AppMessages; @@ -54,6 +58,7 @@ import org.onap.music.main.CachingUtil; import org.onap.music.main.MusicCore; import org.onap.music.main.MusicUtil; import org.onap.music.main.ResultType; +import org.onap.music.main.ReturnType; import org.onap.music.response.jsonobjects.JsonResponse; import com.datastax.driver.core.DataType; @@ -67,8 +72,15 @@ import com.sun.jersey.core.util.Base64; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.apache.commons.jcs.JCS; -import org.apache.commons.jcs.access.CacheAccess; +import com.datastax.driver.core.TableMetadata; + +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import com.datastax.driver.core.ColumnDefinitions; +import com.datastax.driver.core.ColumnDefinitions.Definition; +import com.datastax.driver.core.TableMetadata; +import java.util.Base64.Encoder; +import java.util.Base64.Decoder; @Path("/v2/admin") // @Path("/v{version: [0-9]+}/admin") @@ -123,7 +135,7 @@ public class RestMusicAdminAPI { MusicUtil.DEFAULTKEYSPACENAME)); pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName)); pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True")); - pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt()))); + pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), password)); pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId)); pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF)); @@ -172,9 +184,8 @@ public class RestMusicAdminAPI { if (cql.endsWith("AND ")) cql = cql.trim().substring(0, cql.length() - 4); - System.out.println("Query is: " + cql); + logger.info("Query in callback is: " + cql); cql = cql + " allow filtering"; - System.out.println("Get OnboardingInfo CQL: " + cql); pQuery.appendQueryString(cql); if (appName != null) pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName)); @@ -390,98 +401,336 @@ public class RestMusicAdminAPI { @Path("/callbackOps") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) - public String callbackOps(JSONObject inputJsonObj) { - // trigger response {"full_table":"admin.race_winners","keyspace":"admin","name":"Siri","operation":"update","table_name":"race_winner","primary_key":"1"} - try { - logger.info("Got notification: " + inputJsonObj.getData()); - String dataStr = inputJsonObj.getData(); - String[] dataStrArr = dataStr.substring(1, dataStr.length() - 1).split(","); - - for (String key : dataStrArr) { - if (key.contains("full_table")) { - String tableName = key.split(":")[1].substring(1, key.split(":")[1].length() - 1); - PreparedQueryObject pQuery = new PreparedQueryObject(); - pQuery.appendQueryString( - "select endpoint, username, password from admin.callback_api where changes = ? allow filtering"); - pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), tableName)); - ResultSet rs = MusicCore.get(pQuery); - Row row = rs.all().get(0); - if(row != null) { - String endpoint = row.getString("endpoint"); - String username = row.getString("username"); - String password = row.getString("password"); - logger.info("Notifying the changes to endpoint: "+endpoint); - WebResource webResource = client.resource(endpoint); - String authData = username+":"+password; - byte[] plainCredsBytes = authData.getBytes(); - byte[] base64CredsBytes = Base64.encode(plainCredsBytes); - String base64Creds = new String(base64CredsBytes); - ClientResponse response = webResource.header("Authorization", "Basic " + base64Creds).accept("application/json") - .post(ClientResponse.class, inputJsonObj); - if(response.getStatus() != 200){ - logger.error("Exception while notifying"); - } - } - break; + public Response callbackOps(final JSONObject inputJsonObj) { + // {"keyspace":"conductor","full_table":"conductor.plans","changeValue":{"conductor.plans.status":"Who??","position":"3"},"operation":"update","table_name":"plans","primary_key":"3"} + Map resultMap = new HashMap<>(); + new Thread(new Runnable() { + public void run() { + makeAsyncCall(inputJsonObj); + } + }).start(); + + return Response.status(Status.OK).entity(resultMap).build(); + } + + private Response makeAsyncCall(JSONObject inputJsonObj) { + + Map resultMap = new HashMap<>(); + try { + logger.info("Got notification: " + inputJsonObj.getData()); + String dataStr = inputJsonObj.getData(); + ObjectMapper mapper = new ObjectMapper(); + JSONCallbackResponse jsonResponse = mapper.readValue(dataStr, JSONCallbackResponse.class); + String operation = jsonResponse.getOperation(); + Map changeValueMap = jsonResponse.getChangeValue(); + String primaryKey = jsonResponse.getPrimary_key(); + //String full_table = jsonResponse.getFull_table(); //conductor.plans + String field_value = changeValueMap.get("field_value"); + if(field_value == null) + field_value = jsonResponse.getFull_table(); + //Get from Cache + JsonCallback baseRequestObj = CachingUtil.getCallBackCache(field_value); + //baseRequestObj = null; + + if(baseRequestObj == null) { + logger.info("Is cache empty? reconstructing Object from cache.."); + baseRequestObj = constructJsonCallbackFromCache(field_value); } - } - } catch(Exception e) { + if(baseRequestObj == null) { + resultMap.put("Exception", + "Oops. Something went wrong. Please make sure Callback properties are onboarded."); + logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.INCORRECTDATA, + ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR); + return Response.status(Status.BAD_REQUEST).entity(resultMap).build(); + } + + String key = "admin" + "." + "notification_master" + "." + baseRequestObj.getUuid(); + String lockId = MusicCore.createLockReference(key); + long lockCreationTime = System.currentTimeMillis(); + ReturnType lockAcqResult = MusicCore.acquireLock(key, lockId); + if(! lockAcqResult.getResult().toString().equals("SUCCESS")) { + logger.info("Some other node is notifying the caller.."); + } + + logger.info(operation+ ": Operation :: changeValue: "+changeValueMap); + if(operation.equals("update")) { + String notifyWhenChangeIn = baseRequestObj.getNotifyWhenChangeIn(); // conductor.plans.status + logger.info("**********notifyWhenChangeIn: "+notifyWhenChangeIn); + if(field_value.equals(notifyWhenChangeIn)) { + logger.info("********** notifyting the endpoint: "+baseRequestObj.getApplicationNotificationEndpoint()); + notifyCallBackAppl(jsonResponse, baseRequestObj); + } + + } else if(operation.equals("delete")) { + String notifyWhenDeletesIn = baseRequestObj.getNotifyWhenDeletesIn(); // conductor.plans.status + logger.info("**********notifyWhenDeletesIn: "+notifyWhenDeletesIn); + if(field_value.equals(notifyWhenDeletesIn)) { + logger.info("********** notifyting the endpoint: "+baseRequestObj.getApplicationNotificationEndpoint()); + notifyCallBackAppl(jsonResponse, baseRequestObj); + } + } else if(operation.equals("insert")) { + String notifyWhenInsertsIn = baseRequestObj.getNotifyWhenInsertsIn(); // conductor.plans.status + logger.info("**********notifyWhenInsertsIn: "+notifyWhenInsertsIn); + if(field_value.equals(notifyWhenInsertsIn)) { + logger.info("********** notifyting the endpoint: "+baseRequestObj.getApplicationNotificationEndpoint()); + notifyCallBackAppl(jsonResponse, baseRequestObj); + } + } + MusicCore.releaseLock(lockId, true); + } catch(Exception e) { e.printStackTrace(); logger.info("Exception..."); } - return "Success"; - } + logger.info(">>> callback is completed. Notification was sent from Music..."); + return Response.status(Status.OK).entity(resultMap).build(); + } + + private void notifyCallBackAppl(JSONCallbackResponse jsonResponse, JsonCallback baseRequestObj) { + int notifytimeout = MusicUtil.getNotifyTimeout(); + int notifyinterval = MusicUtil.getNotifyInterval(); + String endpoint = baseRequestObj.getApplicationNotificationEndpoint(); + String username = baseRequestObj.getApplicationUsername(); + String password = baseRequestObj.getApplicationPassword(); + JsonNotification jsonNotification = constructJsonNotification(jsonResponse, baseRequestObj); + jsonNotification.setOperation_type(jsonResponse.getOperation()); + logger.info("Response sent is: "+jsonNotification); + WebResource webResource = client.resource(endpoint); + String authData = username+":"+password; + byte[] plainCredsBytes = authData.getBytes(); + byte[] base64CredsBytes = Base64.encode(plainCredsBytes); + String base64Creds = new String(base64CredsBytes); + Map response_body = baseRequestObj.getResponseBody(); + ClientResponse response = null; + try { + response = webResource.header("Authorization", "Basic " + base64Creds).accept("application/json").type("application/json") + .post(ClientResponse.class, jsonNotification); + } catch (com.sun.jersey.api.client.ClientHandlerException chf) { + boolean ok = false; + logger.info("Is Service down?"); + long now= System.currentTimeMillis(); + long end = now+notifytimeout; + while(! ok) { + logger.info("retrying since error in notifying callback.."); + try { + response = webResource.header("Authorization", "Basic " + base64Creds).accept("application/json").type("application/json") + .post(ClientResponse.class, jsonNotification); + if(response.getStatus() == 200) ok = true; + }catch (Exception e) { + System.err.println("Is response null: "+response==null); + System.err.println("Retry until "+(end-System.currentTimeMillis())); + if(response == null && System.currentTimeMillis() < end) ok = false; + else ok = true; + try{ Thread.sleep(notifyinterval); } catch(Exception e1) {} + } + } + } + response.bufferEntity(); + String responseStr = response.getEntity(String.class); + logger.info(">>>>> Response from Notified client: "+responseStr); + + if(response.getStatus() != 200){ + long now= System.currentTimeMillis(); + long end = now+30000; + while(response.getStatus() != 200 && System.currentTimeMillis() < end) { + logger.info("retrying since error in notifying callback.."); + response = webResource.header("Authorization", "Basic " + base64Creds).accept("application/json").type("application/json") + .post(ClientResponse.class, jsonNotification); + } + logger.error("Exception while notifying.. "+response.getStatus()); + } + } + + private JsonNotification constructJsonNotification(JSONCallbackResponse jsonResponse, JsonCallback baseRequestObj) { + + JsonNotification jsonNotification = new JsonNotification(); + try { + jsonNotification.setNotify_field(baseRequestObj.getNotifyOn()); + jsonNotification.setEndpoint(baseRequestObj.getApplicationNotificationEndpoint()); + jsonNotification.setUsername(baseRequestObj.getApplicationUsername()); + jsonNotification.setPassword(baseRequestObj.getApplicationPassword()); + String pkValue = jsonResponse.getPrimary_key(); + + String[] fullNotifyArr = baseRequestObj.getNotifyOn().split(":"); + + String[] tableArr = fullNotifyArr[0].split("\\."); + TableMetadata tableInfo = MusicCore.returnColumnMetadata(tableArr[0], tableArr[1]); + DataType primaryIdType = tableInfo.getPrimaryKey().get(0).getType(); + String primaryId = tableInfo.getPrimaryKey().get(0).getName(); + logger.info(">>>>>>> Primary Id: "+primaryId); + + Map responseBodyMap = baseRequestObj.getResponseBody(); + Set keySet = responseBodyMap.keySet(); + /*for (Map.Entry entry : valuesMap.entrySet()) { + DataType colType = null; + try { + colType = tableInfo.getColumn(entry.getKey()).getType(); + } catch(NullPointerException ex) { + + } + }*/ + + + String cql = "select "; + for(String keys: keySet) { + cql = cql + keys + ","; + } + cql = cql.substring(0, cql.length()-1); + cql = cql + " FROM "+fullNotifyArr[0]+" WHERE "+primaryId+" = ?"; + logger.info("CQL in constructJsonNotification: "+cql); + PreparedQueryObject pQuery = new PreparedQueryObject(); + pQuery.appendQueryString(cql); + pQuery.addValue(MusicUtil.convertToActualDataType(primaryIdType, pkValue)); + Row row = MusicCore.get(pQuery).one(); + Map newMap = new HashMap<>(); + if(row != null) { + for(String keys: keySet) { + String value = null; + logger.info("responseBodyMap: "+responseBodyMap.toString()); + logger.info(">>>>>>>> converting <<<<<<<<<<<< "+keys + " : "+responseBodyMap.get(keys)+ ":" +responseBodyMap.get(keys).equals("uuid")); + if(responseBodyMap.get(keys).equals("uuid")) + value = row.getUUID(keys).toString(); + else if (responseBodyMap.get(keys).equals("text")) + value = row.getString(keys); + /*else if (responseBodyMap.get(keys).contains("int")) + value = row.getLong(keys).toString();*/ + newMap.put(keys, value); + } + } + if("delete".equals(jsonResponse.getOperation())) { + newMap.put(primaryId, pkValue); + } + jsonNotification.setResponse_body(newMap); + } catch(Exception e) { + e.printStackTrace(); + } + return jsonNotification; + } + + private JsonCallback constructJsonCallbackFromCache(String fullTable) throws Exception{ + PreparedQueryObject pQuery = new PreparedQueryObject(); + JsonCallback jsonCallback = new JsonCallback(); + String cql = + "select id, endpoint_userid, endpoint_password, notify_to_endpoint, notify_insert_on," + + " notify_delete_on, notify_update_on, request from admin.notification_master where notifyon = ? allow filtering"; + pQuery.appendQueryString(cql); + pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), fullTable)); + logger.info("Query: "+pQuery.getQuery() + " : "+fullTable); + + Row row = MusicCore.get(pQuery).one(); + if(row != null) { + String endpoint = row.getString("notify_to_endpoint"); + String username = row.getString("endpoint_userid"); + String password = row.getString("endpoint_password"); + String insert = row.getString("notify_insert_on"); + String delete = row.getString("notify_delete_on"); + String update = row.getString("notify_update_on"); + String request = row.getString("request"); + String uuid = row.getUUID("id").toString(); + jsonCallback.setApplicationNotificationEndpoint(endpoint); + jsonCallback.setApplicationPassword(password); + jsonCallback.setApplicationUsername(username); + jsonCallback.setNotifyOn(fullTable); + jsonCallback.setNotifyWhenInsertsIn(insert); + jsonCallback.setNotifyWhenDeletesIn(delete); + jsonCallback.setNotifyWhenChangeIn(update); + jsonCallback.setUuid(uuid); + logger.info("From DB. Saved request_body: "+request); + request = request.substring(1, request.length()-1); + String[] keyValuePairs = request.split(","); + Map responseBody = new HashMap<>(); + + for(String pair : keyValuePairs) { + String[] entry = pair.split("="); + String val = ""; + if(entry.length == 2) + val = entry[1]; + responseBody.put(entry[0], val); + } + logger.info("After parsing. Saved request_body: "+responseBody); + jsonCallback.setResponseBody(responseBody); + } + return jsonCallback; + } @POST - @Path("/addCallback") + @Path("/onboardCallback") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) - public Response addCallback(JsonCallback jsonCallback) throws Exception { + public Response addCallback(JsonNotification jsonNotification) { Map resultMap = new HashMap<>(); ResponseBuilder response = Response.noContent().header("X-latestVersion", MusicUtil.getVersion()); - String username = jsonCallback.getApplicationUsername(); - String password = jsonCallback.getApplicationPassword(); - String endpoint = jsonCallback.getApplicationNotificationEndpoint(); - String changes = jsonCallback.getNotifyWhenChangeIn(); - String inserts = jsonCallback.getNotifyWhenInsertsIn(); - String deletes = jsonCallback.getNotifyWhenDeletesIn(); + String username = jsonNotification.getUsername(); + String password = jsonNotification.getPassword(); + String endpoint = jsonNotification.getEndpoint(); + String notify_field = jsonNotification.getNotify_field(); + Map responseBody = jsonNotification.getResponse_body(); + + String[] allFields = notify_field.split(":"); + String inserts = null; + String updates = null; + String deletes = null; + if(allFields.length >= 2) { + inserts = updates = notify_field; + } else if(allFields.length == 1) { + inserts = deletes = notify_field;; + } + PreparedQueryObject pQuery = new PreparedQueryObject(); - if (username == null || password == null || endpoint == null || changes == null || inserts == null || deletes == null) { + /*if (username == null || password == null || endpoint == null) { logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGINFO, ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR); resultMap.put("Exception", "Please check the request parameters. Some of the required values are missing."); return Response.status(Status.BAD_REQUEST).entity(resultMap).build(); - } + }*/ String uuid = CachingUtil.generateUUID(); try { - pQuery.appendQueryString( - "INSERT INTO admin.callback_api (uuid, username, password, endpoint, " - + "changes, inserts, deletes) VALUES (?,?,?,?,?,?,?)"); - pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid)); - pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), username)); - pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), password)); - pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), endpoint)); - pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), changes)); - pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), inserts)); - pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), deletes)); - MusicCore.eventualPut(pQuery); - - Map jsonMap = new HashMap<>(); - jsonMap.put("username", username); - jsonMap.put("password", password); - jsonMap.put("endpoint", endpoint); - jsonMap.put("changes", changes); - jsonMap.put("inserts", inserts); - jsonMap.put("deletes", deletes); - + pQuery.appendQueryString( + "INSERT INTO admin.notification_master (id, endpoint_userid, endpoint_password, notify_to_endpoint, " + + "notifyon, notify_insert_on, notify_delete_on, notify_update_on, request, current_notifier) VALUES (?,?,?,?,?,?,?,?,?,?)"); + pQuery.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid)); + pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), username)); + pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), password)); + pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), endpoint)); + pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), notify_field)); + pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), inserts)); + pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), deletes)); + pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), updates)); + pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), responseBody)); + pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), "UNKNOWN")); + MusicCore.nonKeyRelatedPut(pQuery, MusicUtil.EVENTUAL); + JsonCallback jsonCallback = new JsonCallback(); + jsonCallback.setUuid(uuid); + jsonCallback.setApplicationNotificationEndpoint(endpoint); + jsonCallback.setApplicationPassword(password); + jsonCallback.setApplicationUsername(username); + jsonCallback.setNotifyOn(notify_field); + jsonCallback.setNotifyWhenChangeIn(updates); + jsonCallback.setNotifyWhenDeletesIn(deletes); + jsonCallback.setNotifyWhenInsertsIn(inserts); + jsonCallback.setResponseBody(responseBody); + CachingUtil.updateCallBackCache(notify_field, jsonCallback); + logger.info("Cache updated "); //callBackCache.put(jsonCallback.getApplicationName(), jsonMap); } catch (InvalidQueryException e) { logger.error(EELFLoggerDelegate.errorLogger,"Exception callback_api table not configured."+e.getMessage()); - resultMap.put("Exception", "Please make sure admin.callback_api table is configured."); + resultMap.put("Exception", "Please make sure admin.notification_master table is configured."); + return Response.status(Status.BAD_REQUEST).entity(resultMap).build(); + } catch(Exception e) { + e.printStackTrace(); + resultMap.put("Exception", "Exception Occured."); return Response.status(Status.BAD_REQUEST).entity(resultMap).build(); } return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setMessage("Callback api successfully registered").toMap()).build(); } + + /*public String encodePwd(String password) { + return Base64.getEncoder().encodeToString(password.getBytes()); + } + + public String decodePwd(String password) { + byte[] bytes = Base64.getDecoder().decode(password); + return new String(bytes); + }*/ } diff --git a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java index 30656350..f0c1663c 100755 --- a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java +++ b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java @@ -1380,7 +1380,7 @@ public class RestMusicDataAPI { if(results.getAvailableWithoutFetching() >0) { return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setDataResult(MusicCore.marshallResults(results)).toMap()).build(); } - return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setError("No data found").toMap()).build(); + return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setDataResult(MusicCore.marshallResults(results)).setError("No data found").toMap()).build(); } catch (MusicServiceException ex) { logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.UNKNOWNERROR ,ErrorSeverity.ERROR, ErrorTypes.MUSICSERVICEERROR); return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build(); diff --git a/src/test/java/org/onap/music/unittests/TestRestAdminData.java b/src/test/java/org/onap/music/unittests/TestRestAdminData.java new file mode 100644 index 00000000..892a20f6 --- /dev/null +++ b/src/test/java/org/onap/music/unittests/TestRestAdminData.java @@ -0,0 +1,2244 @@ +/* + * ============LICENSE_START========================================== org.onap.music + * =================================================================== Copyright (c) 2017 AT&T + * Intellectual Property =================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * + * ============LICENSE_END============================================= + * ==================================================================== + */ +package org.onap.music.unittests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.onap.music.main.MusicCore.mLockHandle; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; +import org.apache.curator.test.TestingServer; +import org.apache.http.impl.client.AutoRetryHttpClient; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.mindrot.jbcrypt.BCrypt; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.music.conductor.conditionals.JsonConditional; +import org.onap.music.conductor.conditionals.MusicConditional; +import org.onap.music.conductor.conditionals.RestMusicConditionalAPI; +import org.onap.music.datastore.PreparedQueryObject; +import org.onap.music.datastore.jsonobjects.JsonDelete; +import org.onap.music.datastore.jsonobjects.JsonInsert; +import org.onap.music.datastore.jsonobjects.JsonKeySpace; +import org.onap.music.datastore.jsonobjects.JsonOnboard; +import org.onap.music.datastore.jsonobjects.JsonSelect; +import org.onap.music.datastore.jsonobjects.JsonTable; +import org.onap.music.datastore.jsonobjects.JsonUpdate; +import org.onap.music.exceptions.MusicServiceException; +import org.onap.music.lockingservice.MusicLockState; +import org.onap.music.lockingservice.MusicLockingService; +import org.onap.music.lockingservice.MusicLockState.LockStatus; +import org.onap.music.main.CachingUtil; +import org.onap.music.main.MusicCore; +import org.onap.music.main.MusicUtil; +import org.onap.music.main.ResultType; +import org.onap.music.main.ReturnType; +import org.onap.music.rest.RestMusicAdminAPI; +import org.onap.music.rest.RestMusicBmAPI; +import org.onap.music.rest.RestMusicDataAPI; +import org.onap.music.rest.RestMusicHealthCheckAPI; +import org.onap.music.rest.RestMusicLocksAPI; +import org.onap.music.rest.RestMusicTestAPI; +import org.onap.music.rest.RestMusicVersionAPI; + +import com.datastax.driver.core.ConsistencyLevel; +import com.datastax.driver.core.DataType; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; +import com.sun.jersey.core.util.Base64; +import com.sun.jersey.core.util.MultivaluedMapImpl; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@RunWith(MockitoJUnitRunner.class) +public class TestRestAdminData { + + RestMusicDataAPI data = new RestMusicDataAPI(); + RestMusicAdminAPI admin = new RestMusicAdminAPI(); + RestMusicLocksAPI lock = new RestMusicLocksAPI(); + static PreparedQueryObject testObject; + static TestingServer zkServer; + + @Mock + HttpServletResponse http; + + @Mock + UriInfo info; + + //* cjc out + @Mock + CachingUtil cachUtilMock; + + @InjectMocks + private MusicCore mCore; + //*/ + + static String appName = "TestApp"; + static String userId = "TestUser"; + static String password = "TestPassword"; + static String authData = userId+":"+password; + static String wrongAuthData = userId+":"+"pass"; + static String authorization = new String(Base64.encode(authData.getBytes())); + static String wrongAuthorization = new String(Base64.encode(wrongAuthData.getBytes())); + static boolean isAAF = false; + static UUID uuid = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40ce6"); + static String keyspaceName = "testCassa"; + static String tableName = "employees"; + static String tableNameConditional = "Conductor"; + static String xLatestVersion = "X-latestVersion"; + static String onboardUUID = null; + static String lockId = null; + static String lockName = "testCassa.employees.sample3"; + + @BeforeClass + public static void init() throws Exception { + try { + MusicCore.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra(); + zkServer = new TestingServer(2181, new File("/tmp/zk")); + MusicCore.mLockHandle = new MusicLockingService(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + testObject = new PreparedQueryObject(); + testObject.appendQueryString("DROP KEYSPACE IF EXISTS " + keyspaceName); + MusicCore.eventualPut(testObject); + testObject = new PreparedQueryObject(); + testObject.appendQueryString("DROP KEYSPACE IF EXISTS admin"); + MusicCore.eventualPut(testObject); + MusicCore.mDstoreHandle.close(); + MusicCore.mLockHandle.getzkLockHandle().close(); + MusicCore.mLockHandle.close(); + zkServer.stop(); + } + + @Test + public void Test1_createKeyspace() throws Exception { + testObject = new PreparedQueryObject(); + testObject.appendQueryString("CREATE KEYSPACE admin WITH REPLICATION = " + + "{'class' : 'SimpleStrategy' , " + + "'replication_factor': 1} AND DURABLE_WRITES = true"); + MusicCore.eventualPut(testObject); + testObject = new PreparedQueryObject(); + testObject.appendQueryString( + "CREATE TABLE admin.keyspace_master (" + " uuid uuid, keyspace_name text," + + " application_name text, is_api boolean," + + " password text, username text," + + " is_aaf boolean, PRIMARY KEY (uuid)\n" + ");"); + MusicCore.eventualPut(testObject); + + testObject = new PreparedQueryObject(); + testObject.appendQueryString( + "INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, " + + "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)"); + testObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid)); + testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), + MusicUtil.DEFAULTKEYSPACENAME)); + testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName)); + testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True")); + testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt()))); + testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId)); + testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF)); + MusicCore.eventualPut(testObject); + + testObject = new PreparedQueryObject(); + testObject.appendQueryString( + "INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, " + + "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)"); + testObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), + UUID.fromString("bbc66ccc-d857-4e90-b1e5-df98a3d40de6"))); + testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), + MusicUtil.DEFAULTKEYSPACENAME)); + testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), "TestApp1")); + testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True")); + testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt()))); + testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), "TestUser1")); + testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF)); + MusicCore.eventualPut(testObject); + + testObject = new PreparedQueryObject(); + testObject.appendQueryString( + "select uuid from admin.keyspace_master where application_name = ? allow filtering"); + testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName)); + ResultSet rs = MusicCore.get(testObject); + List rows = rs.all(); + if (rows.size() > 0) { + System.out.println("#######UUID is:" + rows.get(0).getUUID("uuid")); + } + } + + @Test + public void Test2_createKeyspace() throws Exception { + JsonKeySpace jsonKeyspace = new JsonKeySpace(); + Map consistencyInfo = new HashMap<>(); + Map replicationInfo = new HashMap<>(); + consistencyInfo.put("type", "eventual"); + replicationInfo.put("class", "SimpleStrategy"); + replicationInfo.put("replication_factor", 1); + jsonKeyspace.setConsistencyInfo(consistencyInfo); + jsonKeyspace.setDurabilityOfWrites("true"); + jsonKeyspace.setKeyspaceName(keyspaceName); + jsonKeyspace.setReplicationInfo(replicationInfo); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.createKeySpace("1", "1", "1", null,authorization, appName, jsonKeyspace, keyspaceName); + System.out.println("#######status is " + response.getStatus()); + System.out.println("Entity" + response.getEntity()); + assertEquals(200,response.getStatus()); + } + + @Test + public void Test2_createKeyspace1() throws Exception { + JsonKeySpace jsonKeyspace = new JsonKeySpace(); + Map consistencyInfo = new HashMap<>(); + Map replicationInfo = new HashMap<>(); + consistencyInfo.put("type", "eventual"); + replicationInfo.put("class", "SimpleStrategy"); + replicationInfo.put("replication_factor", 1); + jsonKeyspace.setConsistencyInfo(consistencyInfo); + jsonKeyspace.setDurabilityOfWrites("true"); + jsonKeyspace.setKeyspaceName(keyspaceName); + jsonKeyspace.setReplicationInfo(replicationInfo); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.createKeySpace("1", "1", "1", null,authorization, appName, jsonKeyspace, "keyspaceName"); + System.out.println("#######status is " + response.getStatus()); + System.out.println("Entity" + response.getEntity()); + assertEquals(200,response.getStatus()); + } + + @Test + public void Test2_createKeyspace0() throws Exception { + JsonKeySpace jsonKeyspace = new JsonKeySpace(); + Map consistencyInfo = new HashMap<>(); + Map replicationInfo = new HashMap<>(); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.createKeySpace("1", "1", "1", null, authorization,appName, jsonKeyspace, keyspaceName); + System.out.println("#######status is " + response.getStatus()); + System.out.println("Entity" + response.getEntity()); + assertEquals(400,response.getStatus()); + } +//MusicCore.autheticateUser + @Test + public void Test2_createKeyspace01() throws Exception { + JsonKeySpace jsonKeyspace = new JsonKeySpace(); + Map consistencyInfo = new HashMap<>(); + Map replicationInfo = new HashMap<>(); + String appName1 = "test"; + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.createKeySpace("1", "1", "1", null,authorization, appName1, jsonKeyspace, keyspaceName); + System.out.println("#######status is " + response.getStatus()); + System.out.println("Entity" + response.getEntity()); + assertEquals(401,response.getStatus()); + } + + @Test + public void Test3_createKeyspace1() throws Exception { + JsonKeySpace jsonKeyspace = new JsonKeySpace(); + Map consistencyInfo = new HashMap<>(); + Map replicationInfo = new HashMap<>(); + consistencyInfo.put("type", "eventual"); + replicationInfo.put("class", "SimpleStrategy"); + replicationInfo.put("replication_factor", 1); + jsonKeyspace.setConsistencyInfo(consistencyInfo); + jsonKeyspace.setDurabilityOfWrites("true"); + jsonKeyspace.setKeyspaceName("TestApp1"); + jsonKeyspace.setReplicationInfo(replicationInfo); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.createKeySpace("1", "1", "1", null,authorization, "TestApp1", + jsonKeyspace, keyspaceName); + System.out.println("#######status is " + response.getStatus()); + System.out.println("Entity" + response.getEntity()); + assertEquals(401,response.getStatus()); + } + + @Test + public void Test2_createKeyspaceEmptyAuth() throws Exception { + + //MockitoAnnotations.initMocks(this); + JsonKeySpace jsonKeyspace = new JsonKeySpace(); + Map consistencyInfo = new HashMap<>(); + Map replicationInfo = new HashMap<>(); + consistencyInfo.put("type", "eventual"); + replicationInfo.put("class", "SimpleStrategy"); + replicationInfo.put("replication_factor", 1); + jsonKeyspace.setConsistencyInfo(consistencyInfo); + jsonKeyspace.setDurabilityOfWrites("true"); + jsonKeyspace.setKeyspaceName(keyspaceName); + jsonKeyspace.setReplicationInfo(replicationInfo); + //Map m1= new HashMap<>() ; + //Mockito.when(CachingUtil.verifyOnboarding("x","y","x")).thenReturn(m1); + //Mockito.when(CachingUtil.verifyOnboarding(appNamex,userId,password).thenReturn(m1)); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + String authDatax = ":"+password; + String authorizationx = new String(Base64.encode(authDatax.getBytes())); + try { + Response response = data.createKeySpace("1", "1", "1", null,authorizationx, appName, jsonKeyspace, keyspaceName); + //System.out.println("#######status is " + response.getStatus()); + //System.out.println("Entity" + response.getEntity()); + //assertNotEquals(200,response.getStatus()); + } catch (RuntimeException e ) { + System.out.println("#######status is runtime exception= " + e); + } + } + + @Test + public void Test3_createTable() throws Exception { + JsonTable jsonTable = new JsonTable(); + Map consistencyInfo = new HashMap<>(); + Map fields = new HashMap<>(); + fields.put("uuid", "text"); + fields.put("emp_name", "text"); + fields.put("emp_salary", "varint"); + fields.put("PRIMARY KEY", "(emp_name)"); + consistencyInfo.put("type", "eventual"); + jsonTable.setConsistencyInfo(consistencyInfo); + jsonTable.setKeyspaceName(keyspaceName); + jsonTable.setPrimaryKey("emp_name"); + jsonTable.setTableName(tableName); + jsonTable.setFields(fields); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.createTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization, + jsonTable, keyspaceName, tableName); + System.out.println("#######status is " + response.getStatus()); + System.out.println("Entity" + response.getEntity()); + assertEquals(200, response.getStatus()); + } + + + @Test + public void Test3_createTableClusterOrderBad() throws Exception { + JsonTable jsonTable = new JsonTable(); + Map consistencyInfo = new HashMap<>(); + Map fields = new HashMap<>(); + fields.put("uuid", "text"); + fields.put("emp_name", "text"); + fields.put("emp_salary", "varint"); + fields.put("PRIMARY KEY", "(emp_name,emp_salary)"); + consistencyInfo.put("type", "eventual"); + jsonTable.setConsistencyInfo(consistencyInfo); + jsonTable.setKeyspaceName(keyspaceName); + jsonTable.setPrimaryKey("emp_name,emp_salary"); + jsonTable.setClusteringOrder("ASC"); + jsonTable.setTableName(tableName); + jsonTable.setFields(fields); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.createTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization, + jsonTable, keyspaceName, tableName); + System.out.println("#######status is " + response.getStatus()); + System.out.println("Entity" + response.getEntity()); + assertNotEquals(200, response.getStatus()); + } + + @Test + public void Test3_createTable_withPropertiesNotNull() throws Exception { + JsonTable jsonTable = new JsonTable(); + Map consistencyInfo = new HashMap<>(); + Map fields = new HashMap<>(); + fields.put("uuid", "text"); + fields.put("emp_name", "text"); + fields.put("emp_salary", "varint"); + fields.put("PRIMARY KEY", "(emp_name)"); + consistencyInfo.put("type", "eventual"); + Map properties = new HashMap<>(); + properties.put("comment","Testing prperties not null"); + jsonTable.setConsistencyInfo(consistencyInfo); + jsonTable.setKeyspaceName(keyspaceName); + jsonTable.setPrimaryKey("emp_name"); + String tableName_prop=tableName+"_Prop"; + jsonTable.setTableName(tableName_prop); + jsonTable.setFields(fields); + jsonTable.setProperties(properties); + + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.createTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization, + jsonTable, keyspaceName, tableName_prop); + System.out.println("#######status is " + response.getStatus()); + System.out.println("Entity" + response.getEntity()); + assertEquals(200, response.getStatus()); + } + + @Test + public void Test3_createTable_duplicateTable() throws Exception { + JsonTable jsonTable = new JsonTable(); + Map consistencyInfo = new HashMap<>(); + Map fields = new HashMap<>(); + fields.put("uuid", "text"); + fields.put("emp_name", "text"); + fields.put("emp_salary", "varint"); + fields.put("PRIMARY KEY", "(emp_name)"); + consistencyInfo.put("type", "eventual"); + jsonTable.setConsistencyInfo(consistencyInfo); + jsonTable.setKeyspaceName(keyspaceName); + jsonTable.setPrimaryKey("emp_name"); + String tableNameDup=tableName+"X"; + jsonTable.setTableName(tableNameDup); + jsonTable.setFields(fields); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.createTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonTable, keyspaceName, tableNameDup); + System.out.println("#######status for 1st time " + response.getStatus()); + System.out.println("Entity" + response.getEntity()); + + Response response0 = data.createTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonTable, keyspaceName, tableNameDup); + // 400 is the duplicate status found in response + // Music 113 duplicate testing + //import static org.junit.Assert.assertNotEquals; + System.out.println("#######status for 2nd time " + response0.getStatus()); + System.out.println("Entity" + response0.getEntity()); + + assertFalse("Duplicate table not created for "+tableNameDup, 200==response0.getStatus()); + + } + + // Improper Auth + @Test + public void Test3_createTable1() throws Exception { + JsonTable jsonTable = new JsonTable(); + Map consistencyInfo = new HashMap<>(); + Map fields = new HashMap<>(); + fields.put("uuid", "text"); + fields.put("emp_name", "text"); + fields.put("emp_salary", "varint"); + fields.put("PRIMARY KEY", "(emp_name)"); + consistencyInfo.put("type", "eventual"); + jsonTable.setConsistencyInfo(consistencyInfo); + jsonTable.setKeyspaceName(keyspaceName); + jsonTable.setPrimaryKey("emp_name"); + jsonTable.setTableName(tableName); + jsonTable.setFields(fields); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.createTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization, + jsonTable, keyspaceName, tableName); + System.out.println("#######status is " + response.getStatus()); + System.out.println("Entity" + response.getEntity()); + assertEquals(401, response.getStatus()); + } + + // Improper keyspace + @Test + public void Test3_createTable3() throws Exception { + JsonTable jsonTable = new JsonTable(); + Map consistencyInfo = new HashMap<>(); + Map fields = new HashMap<>(); + fields.put("uuid", "text"); + fields.put("emp_name", "text"); + fields.put("emp_salary", "varint"); + fields.put("PRIMARY KEY", "(emp_name)"); + consistencyInfo.put("type", "eventual"); + jsonTable.setConsistencyInfo(consistencyInfo); + jsonTable.setKeyspaceName(keyspaceName); + jsonTable.setPrimaryKey("emp_name"); + jsonTable.setTableName(tableName); + jsonTable.setFields(fields); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.createTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonTable, "wrong", tableName); + System.out.println("#######status is " + response.getStatus()); + System.out.println("Entity" + response.getEntity()); + assertEquals(401, response.getStatus()); + } + + @Test + public void Test3_createTable3_with_samePartition_clusteringKeys() throws Exception { + JsonTable jsonTable = new JsonTable(); + Map consistencyInfo = new HashMap<>(); + Map fields = new HashMap<>(); + fields.put("uuid", "text"); + fields.put("emp_name", "text"); + fields.put("emp_salary", "varint"); + fields.put("PRIMARY KEY", "(emp_name, emp_name)"); + consistencyInfo.put("type", "eventual"); + jsonTable.setConsistencyInfo(consistencyInfo); + jsonTable.setKeyspaceName(keyspaceName); + jsonTable.setPartitionKey("emp_name"); + jsonTable.setClusteringKey("emp_name"); + jsonTable.setTableName(tableName); + jsonTable.setFields(fields); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.createTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonTable, keyspaceName, tableName); + System.out.println("#######status is " + response.getStatus()); + System.out.println("Entity" + response.getEntity()); + assertEquals(400, response.getStatus()); + } + + @Test + public void Test3_createTable3_with_Partition_clusteringKeys() throws Exception { + JsonTable jsonTable = new JsonTable(); + Map consistencyInfo = new HashMap<>(); + Map fields = new HashMap<>(); + fields.put("uuid", "text"); + fields.put("emp_name", "text"); + fields.put("emp_salary", "varint"); + consistencyInfo.put("type", "eventual"); + jsonTable.setConsistencyInfo(consistencyInfo); + jsonTable.setKeyspaceName(keyspaceName); + jsonTable.setPartitionKey("emp_name"); + jsonTable.setClusteringKey("uuid"); + jsonTable.setTableName(tableName); + jsonTable.setFields(fields); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.createTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonTable, keyspaceName, "tableName1"); + System.out.println("#######status is " + response.getStatus()); + System.out.println("Entity" + response.getEntity()); + assertEquals(200, response.getStatus()); + } + + // Improper parenthesis in key field + @Test + public void Test3_createTable_badParantesis() throws Exception { + String tableNameC ="testTable0"; + JsonTable jsonTable = new JsonTable(); + Map consistencyInfo = new HashMap<>(); + Map fields = new HashMap<>(); + fields.put("uuid", "text"); + fields.put("emp_name", "text"); + fields.put("emp_salary", "varint"); + fields.put("PRIMARY KEY", "(emp_name),emp_id)"); + fields.put("emp_id", "varint"); + consistencyInfo.put("type", "eventual"); + jsonTable.setConsistencyInfo(consistencyInfo); + jsonTable.setKeyspaceName(keyspaceName); + jsonTable.setPrimaryKey("emp_name"); + jsonTable.setTableName(tableNameC); + jsonTable.setClusteringOrder("emp_id Desc"); + jsonTable.setFields(fields); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.createTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonTable, keyspaceName, tableNameC); + System.out.println("#######status is " + response.getStatus()); + System.out.println("Entity" + response.getEntity()); + //assertEquals(400, response.getStatus()); + assertTrue(200 != response.getStatus()); + } + + + // good clustering key + @Test + public void Test3_createTable_1_clusterKey_good() throws Exception { + String tableNameC ="testTableC1"; + JsonTable jsonTable = new JsonTable(); + Map consistencyInfo = new HashMap<>(); + Map fields = new HashMap<>(); + fields.put("uuid", "text"); + fields.put("emp_name", "text"); + fields.put("emp_salary", "varint"); + fields.put("PRIMARY KEY", "((emp_name),emp_salary)"); + consistencyInfo.put("type", "eventual"); + jsonTable.setConsistencyInfo(consistencyInfo); + jsonTable.setKeyspaceName(keyspaceName); + // jsonTable.setPrimaryKey("emp_name"); + jsonTable.setTableName(tableNameC); + jsonTable.setClusteringOrder("emp_salary ASC"); + jsonTable.setFields(fields); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.createTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonTable, keyspaceName, tableNameC); + System.out.println("#######status is " + response.getStatus()); + System.out.println("Entity" + response.getEntity()); + assertEquals(200, response.getStatus()); + } + + // bad partition key=clustering key + @Test + public void Test3_createTable_2_clusterKey_bad() throws Exception { + String tableNameC ="testTableC2"; + JsonTable jsonTable = new JsonTable(); + Map consistencyInfo = new HashMap<>(); + Map fields = new HashMap<>(); + fields.put("uuid", "text"); + fields.put("emp_name", "text"); + fields.put("emp_salary", "varint"); + fields.put("PRIMARY KEY", "((emp_name),emp_name)"); + consistencyInfo.put("type", "eventual"); + jsonTable.setConsistencyInfo(consistencyInfo); + jsonTable.setKeyspaceName(keyspaceName); + jsonTable.setPrimaryKey("emp_name"); // "PRIMARY KEY" overrides if primaryKey present + jsonTable.setTableName(tableNameC); + jsonTable.setClusteringOrder("emp_salary ASC"); + jsonTable.setFields(fields); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.createTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonTable, keyspaceName, tableNameC); + System.out.println("#######status is " + response.getStatus()); + System.out.println("Entity" + response.getEntity()); + assertTrue(200 !=response.getStatus()); + } + + // good composite partition key,clustering key + @Test + public void Test3_createTable_3_partition_clusterKey_good() throws Exception { + String tableNameC ="testTableC3"; + JsonTable jsonTable = new JsonTable(); + Map consistencyInfo = new HashMap<>(); + Map fields = new HashMap<>(); + fields.put("uuid", "text"); + fields.put("emp_name", "text"); + fields.put("emp_id", "varint"); + fields.put("emp_salary", "varint"); + fields.put("PRIMARY KEY", "((emp_name,emp_id),emp_salary)"); + consistencyInfo.put("type", "eventual"); + jsonTable.setConsistencyInfo(consistencyInfo); + jsonTable.setKeyspaceName(keyspaceName); + jsonTable.setPrimaryKey("emp_name"); + jsonTable.setTableName(tableNameC); + jsonTable.setClusteringOrder("emp_salary ASC"); + jsonTable.setFields(fields); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.createTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonTable, keyspaceName, tableNameC); + System.out.println("#######status is " + response.getStatus()); + System.out.println("Entity" + response.getEntity()); + assertEquals(200, response.getStatus()); + } + + // bad - not all cols in order by of composite partition key,clustering key + @Test + public void Test3_createTable_4_clusteringOrder_bad() throws Exception { + String tableNameC ="testTableC4"; + JsonTable jsonTable = new JsonTable(); + Map consistencyInfo = new HashMap<>(); + Map fields = new HashMap<>(); + fields.put("uuid", "text"); + fields.put("emp_name", "text"); + fields.put("emp_id", "varint"); + fields.put("emp_salary", "varint"); + fields.put("PRIMARY KEY", "((emp_name),emp_id,emp_salary)"); + consistencyInfo.put("type", "eventual"); + jsonTable.setConsistencyInfo(consistencyInfo); + jsonTable.setKeyspaceName(keyspaceName); + jsonTable.setPrimaryKey("emp_name"); + jsonTable.setTableName(tableNameC); + jsonTable.setClusteringOrder("emp_salary ASC"); + jsonTable.setFields(fields); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.createTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonTable, keyspaceName, tableNameC); + System.out.println("#######status is " + response.getStatus()); + System.out.println("Entity" + response.getEntity()); + assertTrue(200 != response.getStatus()); + } + + // bad - wrong cols in order by of composite partition key,clustering key + @Test + public void Test3_createTable_5_clusteringOrder_bad() throws Exception { + String tableNameC ="testTableC5"; + JsonTable jsonTable = new JsonTable(); + Map consistencyInfo = new HashMap<>(); + Map fields = new HashMap<>(); + fields.put("uuid", "text"); + fields.put("emp_name", "text"); + fields.put("emp_id", "varint"); + fields.put("emp_salary", "varint"); + fields.put("PRIMARY KEY", "((uuid,emp_name),emp_id,emp_salary)"); + consistencyInfo.put("type", "eventual"); + jsonTable.setConsistencyInfo(consistencyInfo); + jsonTable.setKeyspaceName(keyspaceName); + jsonTable.setPrimaryKey("emp_name"); + jsonTable.setTableName(tableNameC); + jsonTable.setClusteringOrder("emp_idx desc, emp_salary ASC"); + jsonTable.setFields(fields); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.createTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonTable, keyspaceName, tableNameC); + System.out.println("#######status is " + response.getStatus()); + System.out.println("Entity" + response.getEntity()); + assertTrue(200 != response.getStatus()); + } + + // bad - wrong cols in order by of composite partition key,clustering key + @Test + public void Test3_createTable_6_clusteringOrder_bad() throws Exception { + String tableNameC ="testTableC6"; + JsonTable jsonTable = new JsonTable(); + Map consistencyInfo = new HashMap<>(); + Map fields = new HashMap<>(); + fields.put("uuid", "text"); + fields.put("emp_name", "text"); + fields.put("emp_id", "varint"); + fields.put("emp_salary", "varint"); + fields.put("PRIMARY KEY", "((uuid,emp_name),emp_id,emp_salary)"); + consistencyInfo.put("type", "eventual"); + jsonTable.setConsistencyInfo(consistencyInfo); + jsonTable.setKeyspaceName(keyspaceName); + jsonTable.setPrimaryKey("((uuid,emp_name),emp_id,emp_salary)"); // overridden by + jsonTable.setTableName(tableNameC); + jsonTable.setClusteringOrder("emp_id desc, emp_salary ASC,uuid desc"); + jsonTable.setFields(fields); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.createTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonTable, keyspaceName, tableNameC); + System.out.println("#######status is " + response.getStatus()); + System.out.println("Entity" + response.getEntity()); + assertTrue(200 != response.getStatus()); + } + + + @Test + public void Test3_createTableIndex_1() throws Exception { + String tableNameC ="testTableCinx"; + JsonTable jsonTable = new JsonTable(); + Map consistencyInfo = new HashMap<>(); + Map fields = new HashMap<>(); + fields.put("uuid", "text"); + fields.put("emp_name", "text"); + fields.put("emp_salary", "varint"); + fields.put("PRIMARY KEY", "((emp_name),emp_salary)"); + consistencyInfo.put("type", "eventual"); + jsonTable.setConsistencyInfo(consistencyInfo); + jsonTable.setKeyspaceName(keyspaceName); + jsonTable.setTableName(tableNameC); + jsonTable.setClusteringOrder("emp_salary ASC"); + jsonTable.setFields(fields); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.createTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonTable, keyspaceName, tableNameC); + MultivaluedMap rowParams = Mockito.mock(MultivaluedMap.class); + Mockito.when(info.getQueryParameters()).thenReturn(rowParams); + Mockito.when(rowParams.getFirst("index_name")).thenReturn("my_index"); + response = data.createIndex("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + keyspaceName, tableNameC,"uuid",info); + assertEquals(200, response.getStatus()); + } + + @Test + public void Test3_createTableIndex_badindexname() throws Exception { + String tableNameC ="testTableCinx"; + JsonTable jsonTable = new JsonTable(); + Map consistencyInfo = new HashMap<>(); + Map fields = new HashMap<>(); + fields.put("uuid", "text"); + fields.put("emp_name", "text"); + fields.put("emp_salary", "varint"); + fields.put("PRIMARY KEY", "((emp_name),emp_salary)"); + consistencyInfo.put("type", "eventual"); + jsonTable.setConsistencyInfo(consistencyInfo); + jsonTable.setKeyspaceName(keyspaceName); + jsonTable.setTableName(tableNameC); + jsonTable.setClusteringOrder("emp_salary ASC"); + jsonTable.setFields(fields); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.createTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonTable, keyspaceName, tableNameC); + MultivaluedMap rowParams = Mockito.mock(MultivaluedMap.class); + Mockito.when(info.getQueryParameters()).thenReturn(rowParams); + Mockito.when(rowParams.getFirst("index_name")).thenReturn("my index"); + response = data.createIndex("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + keyspaceName, tableNameC,"uuid",info); + assertEquals(400, response.getStatus()); + } + + @Test + public void Test3_createTableIndex_wrongindex() throws Exception { + String tableNameC ="testTableCinx"; + JsonTable jsonTable = new JsonTable(); + Map consistencyInfo = new HashMap<>(); + Map fields = new HashMap<>(); + fields.put("uuid", "text"); + fields.put("emp_name", "text"); + fields.put("emp_salary", "varint"); + fields.put("PRIMARY KEY", "((emp_name),emp_salary)"); + consistencyInfo.put("type", "eventual"); + jsonTable.setConsistencyInfo(consistencyInfo); + jsonTable.setKeyspaceName(keyspaceName); + jsonTable.setTableName(tableNameC); + jsonTable.setClusteringOrder("emp_salary ASC"); + jsonTable.setFields(fields); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.createTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonTable, keyspaceName, tableNameC); + MultivaluedMap rowParams = Mockito.mock(MultivaluedMap.class); + Mockito.when(info.getQueryParameters()).thenReturn(rowParams); + Mockito.when(rowParams.getFirst("index_name")).thenReturn("my_index"); + response = data.createIndex("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + keyspaceName, tableNameC,"id",info); + assertEquals(400, response.getStatus()); + } + + @Test + public void Test4_insertIntoTable() throws Exception { + JsonInsert jsonInsert = new JsonInsert(); + Map consistencyInfo = new HashMap<>(); + Map values = new HashMap<>(); + values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); + values.put("emp_name", "testName"); + values.put("emp_salary", 500); + consistencyInfo.put("type", "eventual"); + jsonInsert.setConsistencyInfo(consistencyInfo); + jsonInsert.setKeyspaceName(keyspaceName); + jsonInsert.setTableName(tableName); + jsonInsert.setValues(values); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", + appName, authorization, jsonInsert, keyspaceName, tableName); + assertEquals(200, response.getStatus()); + } + + @Test + public void Test4_insertIntoTable2() throws Exception { + JsonInsert jsonInsert = new JsonInsert(); + Map consistencyInfo = new HashMap<>(); + Map values = new HashMap<>(); + values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); + values.put("emp_name", "test1"); + values.put("emp_salary", 1500); + consistencyInfo.put("type", "eventual"); + jsonInsert.setConsistencyInfo(consistencyInfo); + jsonInsert.setKeyspaceName(keyspaceName); + jsonInsert.setTableName(tableName); + jsonInsert.setValues(values); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.insertIntoTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonInsert, keyspaceName, tableName); + assertEquals(200, response.getStatus()); + } + + // Auth Error + @Test + public void Test4_insertIntoTable3() throws Exception { + JsonInsert jsonInsert = new JsonInsert(); + Map consistencyInfo = new HashMap<>(); + Map values = new HashMap<>(); + values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); + values.put("emp_name", "test1"); + values.put("emp_salary", 1500); + consistencyInfo.put("type", "eventual"); + jsonInsert.setConsistencyInfo(consistencyInfo); + jsonInsert.setKeyspaceName(keyspaceName); + jsonInsert.setTableName(tableName); + jsonInsert.setValues(values); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.insertIntoTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization, + jsonInsert, keyspaceName, tableName); + assertEquals(401, response.getStatus()); + } + + // Table wrong + @Test + public void Test4_insertIntoTable4() throws Exception { + JsonInsert jsonInsert = new JsonInsert(); + Map consistencyInfo = new HashMap<>(); + Map values = new HashMap<>(); + values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); + values.put("emp_name", "test1"); + values.put("emp_salary", 1500); + consistencyInfo.put("type", "eventual"); + jsonInsert.setConsistencyInfo(consistencyInfo); + jsonInsert.setKeyspaceName(keyspaceName); + jsonInsert.setTableName(tableName); + jsonInsert.setValues(values); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.insertIntoTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonInsert, keyspaceName, "wrong"); + assertEquals(400, response.getStatus()); + } + + @Test + public void Test4_insertIntoTable5() throws Exception { + JsonInsert jsonInsert = new JsonInsert(); + Map consistencyInfo = new HashMap<>(); + Map values = new HashMap<>(); + values.put("id", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); + values.put("emp_name", "test1"); + values.put("emp_salary", 1500); + consistencyInfo.put("type", "eventual"); + jsonInsert.setConsistencyInfo(consistencyInfo); + jsonInsert.setKeyspaceName(keyspaceName); + jsonInsert.setTableName(tableName); + jsonInsert.setValues(values); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.insertIntoTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonInsert, keyspaceName, tableName); + assertEquals(400, response.getStatus()); + } + + @Test + public void Test4_insertIntoTable6() throws Exception { + JsonInsert jsonInsert = new JsonInsert(); + Map consistencyInfo = new HashMap<>(); + Map values = new HashMap<>(); + values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); + values.put("emp_salary", 1500); + consistencyInfo.put("type", "eventual"); + jsonInsert.setConsistencyInfo(consistencyInfo); + jsonInsert.setKeyspaceName(keyspaceName); + jsonInsert.setTableName(tableName); + jsonInsert.setValues(values); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.insertIntoTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonInsert, keyspaceName, tableName); + assertEquals(400, response.getStatus()); + } + + @Test + public void Test4_insertIntoTable7() throws Exception { + JsonInsert jsonInsert = new JsonInsert(); + Map consistencyInfo = new HashMap<>(); + Map values = new HashMap<>(); + values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); + values.put("emp_name", "test2"); + values.put("emp_salary", 1500); + consistencyInfo.put("type", "eventual"); + jsonInsert.setConsistencyInfo(consistencyInfo); + jsonInsert.setKeyspaceName(keyspaceName); + jsonInsert.setTableName(tableName); + jsonInsert.setValues(values); + jsonInsert.setTtl("1000"); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.insertIntoTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonInsert, keyspaceName, tableName); + assertEquals(200, response.getStatus()); + } + + @Test + public void Test4_insertIntoTable8() throws Exception { + JsonInsert jsonInsert = new JsonInsert(); + Map consistencyInfo = new HashMap<>(); + Map values = new HashMap<>(); + values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); + values.put("emp_name", "test3"); + values.put("emp_salary", 1500); + consistencyInfo.put("type", "eventual"); + jsonInsert.setConsistencyInfo(consistencyInfo); + jsonInsert.setKeyspaceName(keyspaceName); + jsonInsert.setTableName(tableName); + jsonInsert.setValues(values); + jsonInsert.setTimestamp("15000"); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.insertIntoTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonInsert, keyspaceName, tableName); + assertEquals(200, response.getStatus()); + } + + @Test + public void Test4_insertIntoTable9() throws Exception { + JsonInsert jsonInsert = new JsonInsert(); + Map consistencyInfo = new HashMap<>(); + Map values = new HashMap<>(); + values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); + values.put("emp_name", "test4"); + values.put("emp_salary", 1500); + consistencyInfo.put("type", "eventual"); + jsonInsert.setConsistencyInfo(consistencyInfo); + jsonInsert.setKeyspaceName(keyspaceName); + jsonInsert.setTableName(tableName); + jsonInsert.setValues(values); + jsonInsert.setTtl("1000"); + jsonInsert.setTimestamp("15000"); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.insertIntoTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonInsert, keyspaceName, tableName); + assertEquals(200, response.getStatus()); + } + + @Test + public void Test4_insertIntoTable10() throws Exception { + JsonInsert jsonInsert = new JsonInsert(); + Map consistencyInfo = new HashMap<>(); + Map values = new HashMap<>(); + values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); + values.put("emp_name", "test5"); + values.put("emp_salary", 1500); + consistencyInfo.put("type", "critical"); + jsonInsert.setConsistencyInfo(consistencyInfo); + jsonInsert.setKeyspaceName(keyspaceName); + jsonInsert.setTableName(tableName); + jsonInsert.setValues(values); + jsonInsert.setTtl("1000"); + jsonInsert.setTimestamp("15000"); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.insertIntoTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonInsert, keyspaceName, tableName); + assertEquals(400, response.getStatus()); + } + + @Test + public void Test4_insertIntoTable11() throws Exception { + JsonInsert jsonInsert = new JsonInsert(); + Map consistencyInfo = new HashMap<>(); + Map values = new HashMap<>(); + values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); + values.put("emp_name", "test6"); + values.put("emp_salary", 1500); + consistencyInfo.put("type", "atomic_delete_lock"); + jsonInsert.setConsistencyInfo(consistencyInfo); + jsonInsert.setKeyspaceName(keyspaceName); + jsonInsert.setTableName(tableName); + jsonInsert.setValues(values); + jsonInsert.setTtl("1000"); + jsonInsert.setTimestamp("15000"); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.insertIntoTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonInsert, keyspaceName, tableName); + assertEquals(200, response.getStatus()); + } + + @Test + public void Test4_insertIntoTable12() throws Exception { + JsonInsert jsonInsert = new JsonInsert(); + Map consistencyInfo = new HashMap<>(); + Map values = new HashMap<>(); + values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); + values.put("emp_name", "test7"); + values.put("emp_salary", 1500); + consistencyInfo.put("type", "atomic"); + jsonInsert.setConsistencyInfo(consistencyInfo); + jsonInsert.setKeyspaceName(keyspaceName); + jsonInsert.setTableName(tableName); + jsonInsert.setValues(values); + jsonInsert.setTtl("1000"); + jsonInsert.setTimestamp("15000"); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.insertIntoTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonInsert, keyspaceName, tableName); + assertEquals(200, response.getStatus()); + } + + @Test + public void Test5_updateTable() throws Exception { + JsonUpdate jsonUpdate = new JsonUpdate(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + Map values = new HashMap<>(); + row.add("emp_name", "testName"); + values.put("emp_salary", 2500); + consistencyInfo.put("type", "atomic"); + jsonUpdate.setConsistencyInfo(consistencyInfo); + jsonUpdate.setKeyspaceName(keyspaceName); + jsonUpdate.setTableName(tableName); + jsonUpdate.setValues(values); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, + authorization, jsonUpdate, keyspaceName, tableName, info); + assertEquals(200, response.getStatus()); + } + + // need mock code to create error for MusicCore methods + @Test + public void Test5_updateTableAuthE() throws Exception { + MockitoAnnotations.initMocks(this); + JsonUpdate jsonUpdate = new JsonUpdate(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + Map values = new HashMap<>(); + row.add("emp_name", "testName"); + values.put("emp_salary", 2500); + consistencyInfo.put("type", "atomic"); + jsonUpdate.setConsistencyInfo(consistencyInfo); + jsonUpdate.setKeyspaceName(keyspaceName); + jsonUpdate.setTableName(tableName); + jsonUpdate.setValues(values); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, + authorization, jsonUpdate, keyspaceName, tableName, info); + assertEquals(200, response.getStatus()); + } + + @Test + public void Test5_updateTableAuthException1() throws Exception { + JsonUpdate jsonUpdate = new JsonUpdate(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + Map values = new HashMap<>(); + row.add("emp_name", "testName"); + values.put("emp_salary", 2500); + consistencyInfo.put("type", "atomic"); + jsonUpdate.setConsistencyInfo(consistencyInfo); + jsonUpdate.setKeyspaceName(keyspaceName); + jsonUpdate.setTableName(tableName); + jsonUpdate.setValues(values); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + String authDatax = ":";//+password; + String authorizationx = new String(Base64.encode(authDatax.getBytes())); + try { + Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, + authorizationx, jsonUpdate, keyspaceName, tableName, info); + assertEquals(200, response.getStatus()); + } catch(RuntimeException e) { + System.out.println("Update table Runtime exception="+e); + } + } + + @Test + public void Test5_updateTableAuthEmpty() throws Exception { + JsonUpdate jsonUpdate = new JsonUpdate(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + Map values = new HashMap<>(); + row.add("emp_name", "testName"); + values.put("emp_salary", 2500); + consistencyInfo.put("type", "atomic"); + jsonUpdate.setConsistencyInfo(consistencyInfo); + jsonUpdate.setKeyspaceName(keyspaceName); + jsonUpdate.setTableName(tableName); + jsonUpdate.setValues(values); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + String authDatax =":"+password; + String authorizationx = new String(Base64.encode(authDatax.getBytes())); + String appNamex="xx"; + try { + // Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, + Response response = data.updateTable("1", "1", "1", "", appNamex, + authorizationx, jsonUpdate, keyspaceName, tableName, info); + assertEquals(200, response.getStatus()); + } catch(RuntimeException e) { + System.out.println("Update table Runtime exception="+e); + } + } + + @Test + public void Test5_updateTable_wrongauth() throws Exception { + JsonUpdate jsonUpdate = new JsonUpdate(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + Map values = new HashMap<>(); + row.add("emp_name", "testName"); + values.put("emp_salary", 2500); + consistencyInfo.put("type", "atomic"); + jsonUpdate.setConsistencyInfo(consistencyInfo); + jsonUpdate.setKeyspaceName(keyspaceName); + jsonUpdate.setTableName(tableName); + jsonUpdate.setValues(values); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, + wrongAuthorization, jsonUpdate, keyspaceName, tableName, info); + assertEquals(401, response.getStatus()); + } + + @Test + public void Test5_updateTable_invalidColumn() throws Exception { + JsonUpdate jsonUpdate = new JsonUpdate(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + Map values = new HashMap<>(); + row.add("id", "testName"); + values.put("emp_salary", 2500); + consistencyInfo.put("type", "atomic"); + jsonUpdate.setConsistencyInfo(consistencyInfo); + jsonUpdate.setKeyspaceName(keyspaceName); + jsonUpdate.setTableName(tableName); + jsonUpdate.setValues(values); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, + authorization, jsonUpdate, keyspaceName, tableName, info); + assertEquals(400, response.getStatus()); + } + + @Test + public void Test5_updateTable_ttl() throws Exception { + JsonUpdate jsonUpdate = new JsonUpdate(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + Map values = new HashMap<>(); + row.add("emp_name", "testName8"); + values.put("emp_salary", 2500); + consistencyInfo.put("type", "atomic"); + jsonUpdate.setConsistencyInfo(consistencyInfo); + jsonUpdate.setKeyspaceName(keyspaceName); + jsonUpdate.setTableName(tableName); + jsonUpdate.setValues(values); + jsonUpdate.setTtl("1000"); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, + authorization, jsonUpdate, keyspaceName, tableName, info); + assertEquals(400, response.getStatus()); + } + + @Test + public void Test5_updateTable_timsetamp() throws Exception { + JsonUpdate jsonUpdate = new JsonUpdate(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + Map values = new HashMap<>(); + row.add("emp_name", "testName9"); + values.put("emp_salary", 2500); + consistencyInfo.put("type", "atomic"); + jsonUpdate.setConsistencyInfo(consistencyInfo); + jsonUpdate.setKeyspaceName(keyspaceName); + jsonUpdate.setTableName(tableName); + jsonUpdate.setValues(values); + jsonUpdate.setTimestamp("15000"); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, + authorization, jsonUpdate, keyspaceName, tableName, info); + assertEquals(400, response.getStatus()); + } + + @Test + public void Test5_updateTable_ttl_timestamp() throws Exception { + JsonUpdate jsonUpdate = new JsonUpdate(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + Map values = new HashMap<>(); + row.add("emp_name", "testName10"); + values.put("emp_salary", 2500); + consistencyInfo.put("type", "atomic"); + jsonUpdate.setConsistencyInfo(consistencyInfo); + jsonUpdate.setKeyspaceName(keyspaceName); + jsonUpdate.setTableName(tableName); + jsonUpdate.setValues(values); + jsonUpdate.setTtl("1000"); + jsonUpdate.setTimestamp("15000"); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, + authorization, jsonUpdate, keyspaceName, tableName, info); + assertEquals(400, response.getStatus()); + } + + @Test + public void Test5_updateTable_rowIdEmpty() throws Exception { + JsonUpdate jsonUpdate = new JsonUpdate(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + Map values = new HashMap<>(); + //row.add("emp_name", "testName3"); + values.put("emp_salary", 2500); + consistencyInfo.put("type", "atomic"); + jsonUpdate.setConsistencyInfo(consistencyInfo); + jsonUpdate.setKeyspaceName(keyspaceName); + jsonUpdate.setTableName(tableName); + jsonUpdate.setValues(values); + jsonUpdate.setTtl("1000"); + jsonUpdate.setTimestamp("15000"); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, + authorization, jsonUpdate, keyspaceName, tableName, info); + assertEquals(400, response.getStatus()); + } + + @Test + public void Test5_updateTable_conditions() throws Exception { + JsonUpdate jsonUpdate = new JsonUpdate(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + Map values = new HashMap<>(); + Map conditions = new HashMap<>(); + conditions.put("emp_name","testName3"); + row.add("emp_name", "testName3"); + values.put("emp_salary", 2500); + consistencyInfo.put("type", "atomic"); + jsonUpdate.setConsistencyInfo(consistencyInfo); + jsonUpdate.setKeyspaceName(keyspaceName); + jsonUpdate.setTableName(tableName); + jsonUpdate.setValues(values); + jsonUpdate.setConditions(conditions); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, + authorization, jsonUpdate, keyspaceName, tableName, info); + assertEquals(400, response.getStatus()); + } + + @Test + public void Test5_updateTable_eventual() throws Exception { + JsonUpdate jsonUpdate = new JsonUpdate(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + Map values = new HashMap<>(); + row.add("emp_name", "testName"); + values.put("emp_salary", 2500); + consistencyInfo.put("type", "eventual"); + jsonUpdate.setConsistencyInfo(consistencyInfo); + jsonUpdate.setKeyspaceName(keyspaceName); + jsonUpdate.setTableName(tableName); + jsonUpdate.setValues(values); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, + authorization, jsonUpdate, keyspaceName, tableName, info); + assertEquals(200, response.getStatus()); + } + + @Test + public void Test5_updateTable_critical() throws Exception { + JsonUpdate jsonUpdate = new JsonUpdate(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + Map values = new HashMap<>(); + row.add("emp_name", "testName"); + values.put("emp_salary", 2500); + consistencyInfo.put("type", "critical"); + jsonUpdate.setConsistencyInfo(consistencyInfo); + jsonUpdate.setKeyspaceName(keyspaceName); + jsonUpdate.setTableName(tableName); + jsonUpdate.setValues(values); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, + authorization, jsonUpdate, keyspaceName, tableName, info); + assertEquals(400, response.getStatus()); + } + + @Test + public void Test5_updateTable_atomic_delete_lock() throws Exception { + JsonUpdate jsonUpdate = new JsonUpdate(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + Map values = new HashMap<>(); + row.add("emp_name", "testName"); + values.put("emp_salary", 2500); + consistencyInfo.put("type", "atomic_delete_lock"); + jsonUpdate.setConsistencyInfo(consistencyInfo); + jsonUpdate.setKeyspaceName(keyspaceName); + jsonUpdate.setTableName(tableName); + jsonUpdate.setValues(values); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, + authorization, jsonUpdate, keyspaceName, tableName, info); + assertEquals(200, response.getStatus()); + } + + @Test + public void Test6_select() throws Exception { + JsonSelect jsonSelect = new JsonSelect(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + row.add("emp_name", "testName"); + consistencyInfo.put("type", "atomic"); + jsonSelect.setConsistencyInfo(consistencyInfo); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.select("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6", + appName, authorization, keyspaceName, tableName, info); + HashMap> map = (HashMap>) response.getEntity(); + HashMap result = map.get("result"); + assertEquals("2500", ((HashMap) result.get("row 0")).get("emp_salary").toString()); + } + + @Test + public void Test6_select_withException() throws Exception { + JsonSelect jsonSelect = new JsonSelect(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + row.add("emp_name", "testName"); + consistencyInfo.put("type", "atomic"); + jsonSelect.setConsistencyInfo(consistencyInfo); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + RestMusicDataAPI spyData = Mockito.spy(RestMusicDataAPI.class); + Mockito.doThrow(MusicServiceException.class).when(spyData).selectSpecificQuery("v2", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password, keyspaceName, tableName, info, -1); + Response response = spyData.select("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6", + appName, authorization, keyspaceName, tableName, info); + assertEquals(400, response.getStatus()); + } + + @Test + public void Test6_select_nodata() throws Exception { + JsonSelect jsonSelect = new JsonSelect(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + row.add("emp_name", "testName12"); + consistencyInfo.put("type", "atomic"); + jsonSelect.setConsistencyInfo(consistencyInfo); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.select("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6", + appName, authorization, keyspaceName, tableName, info); + assertEquals(200, response.getStatus()); + } + + @Test + public void Test6_selectCritical() throws Exception { + JsonInsert jsonInsert = new JsonInsert(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + row.add("emp_name", "testName"); + consistencyInfo.put("type", "atomic"); + jsonInsert.setConsistencyInfo(consistencyInfo); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6", + appName, authorization, jsonInsert, keyspaceName, tableName,info); + HashMap> map = (HashMap>) response.getEntity(); + HashMap result = map.get("result"); + assertEquals("2500", ((HashMap) result.get("row 0")).get("emp_salary").toString()); + } + + @Test + public void Test6_selectCritical_without_lockID() throws Exception { + JsonInsert jsonInsert = new JsonInsert(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + row.add("emp_name", "testName"); + consistencyInfo.put("type", "critical"); + jsonInsert.setConsistencyInfo(consistencyInfo); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6", + appName, authorization, jsonInsert, keyspaceName, tableName,info); + assertEquals(400, response.getStatus()); + } + + @Test + public void Test6_selectCritical_with_atomic_delete_lock() throws Exception { + JsonInsert jsonInsert = new JsonInsert(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + row.add("emp_name", "testName"); + consistencyInfo.put("type", "atomic_delete_lock"); + jsonInsert.setConsistencyInfo(consistencyInfo); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6", + appName, authorization, jsonInsert, keyspaceName, tableName,info); + assertEquals(200, response.getStatus()); + } + + @Test + public void Test6_selectCritical_with_nodata() throws Exception { + JsonInsert jsonInsert = new JsonInsert(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + row.add("emp_name", "testName12"); + consistencyInfo.put("type", "atomic_delete_lock"); + jsonInsert.setConsistencyInfo(consistencyInfo); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6", + appName, authorization, jsonInsert, keyspaceName, tableName,info); + assertEquals(200, response.getStatus()); + } + + @Test + public void Test6_select_all() throws Exception { + JsonSelect jsonSelect = new JsonSelect(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl();; + consistencyInfo.put("type", "atomic"); + jsonSelect.setConsistencyInfo(consistencyInfo); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.select("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6", + appName, authorization, keyspaceName, tableName, info); + assertEquals(200, response.getStatus()); + } + + @Test + public void Test6_deleteFromTable() throws Exception { + JsonDelete jsonDelete = new JsonDelete(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + row.add("emp_name", "test1"); + consistencyInfo.put("type", "atomic"); + jsonDelete.setConsistencyInfo(consistencyInfo); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.deleteFromTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonDelete, keyspaceName, tableName, info); + assertEquals(200, response.getStatus()); + } + + // Values + @Test + public void Test6_deleteFromTable1() throws Exception { + JsonDelete jsonDelete = new JsonDelete(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + consistencyInfo.put("type", "atomic"); + jsonDelete.setConsistencyInfo(consistencyInfo); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.deleteFromTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonDelete, keyspaceName, tableName, info); + assertEquals(400, response.getStatus()); + } + + // delObj + @Test + public void Test6_deleteFromTable2() throws Exception { + JsonDelete jsonDelete = new JsonDelete(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + row.add("emp_name", "test1"); + consistencyInfo.put("type", "atomic"); + jsonDelete.setConsistencyInfo(consistencyInfo); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.deleteFromTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + null, keyspaceName, tableName, info); + assertEquals(400, response.getStatus()); + } + + @Test + public void Test6_deleteFromTable_columns() throws Exception { + JsonDelete jsonDelete = new JsonDelete(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + row.add("emp_name", "test1"); + consistencyInfo.put("type", "atomic"); + jsonDelete.setConsistencyInfo(consistencyInfo); + ArrayList columns = new ArrayList<>(); + columns.add("uuid"); + jsonDelete.setColumns(columns); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.deleteFromTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonDelete, keyspaceName, tableName, info); + assertEquals(200, response.getStatus()); + } + + @Test + public void Test6_deleteFromTable_conditions() throws Exception { + JsonDelete jsonDelete = new JsonDelete(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + Map conditions = new HashMap<>(); + conditions.put("emp_name","testName3"); + row.add("emp_name", "test1"); + consistencyInfo.put("type", "atomic"); + jsonDelete.setConsistencyInfo(consistencyInfo); + ArrayList columns = new ArrayList<>(); + jsonDelete.setConditions(conditions); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.deleteFromTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonDelete, keyspaceName, tableName, info); + assertEquals(400, response.getStatus()); + } + + @Test + public void Test6_deleteFromTable_eventual() throws Exception { + JsonDelete jsonDelete = new JsonDelete(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + row.add("emp_name", "test2"); + consistencyInfo.put("type", "eventual"); + jsonDelete.setConsistencyInfo(consistencyInfo); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.deleteFromTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonDelete, keyspaceName, tableName, info); + assertEquals(200, response.getStatus()); + } + + @Test + public void Test6_deleteFromTable_critical() throws Exception { + JsonDelete jsonDelete = new JsonDelete(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + row.add("emp_name", "test2"); + consistencyInfo.put("type", "critical"); + jsonDelete.setConsistencyInfo(consistencyInfo); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.deleteFromTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonDelete, keyspaceName, tableName, info); + assertEquals(400, response.getStatus()); + } + + @Test + public void Test6_deleteFromTable_atomic_delete_lock() throws Exception { + JsonDelete jsonDelete = new JsonDelete(); + Map consistencyInfo = new HashMap<>(); + MultivaluedMap row = new MultivaluedMapImpl(); + row.add("emp_name", "test3"); + consistencyInfo.put("type", "atomic_delete_lock"); + jsonDelete.setConsistencyInfo(consistencyInfo); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Mockito.when(info.getQueryParameters()).thenReturn(row); + Response response = data.deleteFromTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + jsonDelete, keyspaceName, tableName, info); + assertEquals(200, response.getStatus()); + } + + @Test + public void Test7_dropTable() throws Exception { + JsonTable jsonTable = new JsonTable(); + Map consistencyInfo = new HashMap<>(); + consistencyInfo.put("type", "atomic"); + jsonTable.setConsistencyInfo(consistencyInfo); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.dropTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, + keyspaceName, tableName); + assertEquals(200, response.getStatus()); + } + + + @Test + public void Test8_deleteKeyspace() throws Exception { + JsonKeySpace jsonKeyspace = new JsonKeySpace(); + Map consistencyInfo = new HashMap<>(); + Map replicationInfo = new HashMap<>(); + consistencyInfo.put("type", "eventual"); + replicationInfo.put("class", "SimpleStrategy"); + replicationInfo.put("replication_factor", 1); + jsonKeyspace.setConsistencyInfo(consistencyInfo); + jsonKeyspace.setDurabilityOfWrites("true"); + jsonKeyspace.setKeyspaceName("TestApp1"); + jsonKeyspace.setReplicationInfo(replicationInfo); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", + authorization,appName, keyspaceName); + assertEquals(200, response.getStatus()); + } + + @Test + public void Test8_deleteKeyspace1() throws Exception { + JsonKeySpace jsonKeyspace = new JsonKeySpace(); + Map consistencyInfo = new HashMap<>(); + Map replicationInfo = new HashMap<>(); + consistencyInfo.put("type", "eventual"); + replicationInfo.put("class", "SimpleStrategy"); + replicationInfo.put("replication_factor", 1); + jsonKeyspace.setConsistencyInfo(consistencyInfo); + jsonKeyspace.setDurabilityOfWrites("true"); + jsonKeyspace.setKeyspaceName("TestApp1"); + jsonKeyspace.setReplicationInfo(replicationInfo); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", + authorization,appName, "keyspaceName"); + assertEquals(200, response.getStatus()); + } + + @Test + public void Test8_deleteKeyspace2() throws Exception { + JsonKeySpace jsonKeyspace = new JsonKeySpace(); + Map consistencyInfo = new HashMap<>(); + Map replicationInfo = new HashMap<>(); + consistencyInfo.put("type", "eventual"); + replicationInfo.put("class", "SimpleStrategy"); + replicationInfo.put("replication_factor", 1); + jsonKeyspace.setConsistencyInfo(consistencyInfo); + jsonKeyspace.setDurabilityOfWrites("true"); + jsonKeyspace.setKeyspaceName("TestApp1"); + jsonKeyspace.setReplicationInfo(replicationInfo); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", + wrongAuthorization, appName, keyspaceName); + assertEquals(401, response.getStatus()); + } + + @Test + public void Test6_onboard() throws Exception { + JsonOnboard jsonOnboard = new JsonOnboard(); + jsonOnboard.setAppname("TestApp2"); + jsonOnboard.setIsAAF("false"); + jsonOnboard.setUserId("TestUser2"); + jsonOnboard.setPassword("TestPassword2"); + Map resultMap = (Map) admin.onboardAppWithMusic(jsonOnboard).getEntity(); + resultMap.containsKey("success"); + onboardUUID = resultMap.get("Generated AID").toString(); + assertEquals("Your application TestApp2 has been onboarded with MUSIC.", resultMap.get("Success")); + } + + @Test + public void Test6_onboard_duplicate() throws Exception { + JsonOnboard jsonOnboard = new JsonOnboard(); + jsonOnboard.setAppname("TestApp2"); + jsonOnboard.setIsAAF("false"); + jsonOnboard.setUserId("TestUser2"); + jsonOnboard.setPassword("TestPassword2"); + Response response = admin.onboardAppWithMusic(jsonOnboard); + assertEquals(400, response.getStatus()); + } + + // Missing appname + @Test + public void Test6_onboard1() throws Exception { + JsonOnboard jsonOnboard = new JsonOnboard(); + jsonOnboard.setIsAAF("false"); + jsonOnboard.setUserId("TestUser2"); + jsonOnboard.setPassword("TestPassword2"); + Map resultMap = (Map) admin.onboardAppWithMusic(jsonOnboard).getEntity(); + resultMap.containsKey("success"); + System.out.println("--->" + resultMap.toString()); + assertEquals("Unauthorized: Please check the request parameters. Some of the required values appName(ns), userId, password, isAAF are missing.", resultMap.get("Exception")); + } + + + @Test + public void Test7_onboardSearch() throws Exception { + JsonOnboard jsonOnboard = new JsonOnboard(); + jsonOnboard.setAppname("TestApp2"); + jsonOnboard.setIsAAF("false"); + jsonOnboard.setAid(onboardUUID); + Map resultMap = (Map) admin.getOnboardedInfoSearch(jsonOnboard).getEntity(); + resultMap.containsKey("success"); + assertEquals(MusicUtil.DEFAULTKEYSPACENAME, resultMap.get(onboardUUID)); + } + + // Missing appname + @Test + public void Test7_onboardSearch1() throws Exception { + JsonOnboard jsonOnboard = new JsonOnboard(); + jsonOnboard.setIsAAF("false"); + jsonOnboard.setAid(onboardUUID); + Map resultMap = (Map) admin.getOnboardedInfoSearch(jsonOnboard).getEntity(); + System.out.println("--->" + resultMap.toString()); + resultMap.containsKey("success"); + assertEquals(MusicUtil.DEFAULTKEYSPACENAME, resultMap.get(onboardUUID)); + } + + @Test + public void Test7_onboardSearch_empty() throws Exception { + JsonOnboard jsonOnboard = new JsonOnboard(); + Response response = admin.getOnboardedInfoSearch(jsonOnboard); + assertEquals(400, response.getStatus()); + } + + @Test + public void Test7_onboardSearch_invalidAid() throws Exception { + JsonOnboard jsonOnboard = new JsonOnboard(); + jsonOnboard.setAppname("TestApp2"); + jsonOnboard.setIsAAF("false"); + jsonOnboard.setAid("abc66ccc-d857-4e90-b1e5-df98a3d40ce6"); + Response response = admin.getOnboardedInfoSearch(jsonOnboard); + assertEquals(400, response.getStatus()); + } + + @Test + public void Test8_onboardUpdate() throws Exception { + JsonOnboard jsonOnboard = new JsonOnboard(); + jsonOnboard.setIsAAF("false"); + jsonOnboard.setUserId("TestUser3"); + jsonOnboard.setPassword("TestPassword3"); + jsonOnboard.setAid(onboardUUID); + Map resultMap = (Map) admin.updateOnboardApp(jsonOnboard).getEntity(); + System.out.println("--->" + resultMap.toString()); + resultMap.containsKey("success"); + assertEquals("Your application has been updated successfully", resultMap.get("Success")); + } + + // Aid null + @Test + public void Test8_onboardUpdate1() throws Exception { + JsonOnboard jsonOnboard = new JsonOnboard(); + jsonOnboard.setIsAAF("false"); + jsonOnboard.setUserId("TestUser3"); + jsonOnboard.setPassword("TestPassword3"); + Map resultMap = (Map) admin.updateOnboardApp(jsonOnboard).getEntity(); + System.out.println("--->" + resultMap.toString()); + resultMap.containsKey("success"); + assertEquals("Please make sure Aid is present", resultMap.get("Exception")); + } + + // Appname not null + @Test + public void Test8_onboardUpdate2() throws Exception { + JsonOnboard jsonOnboard = new JsonOnboard(); + jsonOnboard.setAppname("TestApp2"); + jsonOnboard.setIsAAF("false"); + jsonOnboard.setUserId("TestUser3"); + jsonOnboard.setPassword("TestPassword3"); + jsonOnboard.setAid(onboardUUID); + Map resultMap = (Map) admin.updateOnboardApp(jsonOnboard).getEntity(); + resultMap.containsKey("success"); + System.out.println("--->" + resultMap.toString()); + assertEquals("Application TestApp2 has already been onboarded. Please contact admin.", resultMap.get("Exception")); + } + + // All null + @Test + public void Test8_onboardUpdate3() throws Exception { + JsonOnboard jsonOnboard = new JsonOnboard(); + jsonOnboard.setAid(onboardUUID); + Map resultMap = (Map) admin.updateOnboardApp(jsonOnboard).getEntity(); + assertTrue(resultMap.containsKey("Exception") ); + } + + @Test + public void Test9_onboardDelete() throws Exception { + JsonOnboard jsonOnboard = new JsonOnboard(); + jsonOnboard.setAppname("TestApp2"); + jsonOnboard.setAid(onboardUUID); + Map resultMap = (Map) admin.deleteOnboardApp(jsonOnboard).getEntity(); + resultMap.containsKey("success"); + assertEquals("Your application has been deleted successfully", resultMap.get("Success")); + } + + @Test + public void Test9_onboardDelete1() throws Exception { + JsonOnboard jsonOnboard = new JsonOnboard(); + Map resultMap = (Map) admin.deleteOnboardApp(jsonOnboard).getEntity(); + assertTrue(resultMap.containsKey("Exception")); + } + + @Test + public void Test3_createLockReference() throws Exception { + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Map resultMap = (Map) lock.createLockReference(lockName,"1","1",authorization, null, appName).getEntity(); + @SuppressWarnings("unchecked") + Map resultMap1 = (Map) resultMap.get("lock"); + lockId = (String) resultMap1.get("lock"); + assertEquals(ResultType.SUCCESS, resultMap.get("status")); + } + + @Test + public void Test4_accquireLock() throws Exception { + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Map resultMap = (Map) lock.accquireLock(lockId,"1","1",authorization, null, appName).getEntity(); + assertEquals(ResultType.SUCCESS, resultMap.get("status")); + } + + @Test + public void Test5_currentLockHolder() throws Exception { + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Map resultMap = (Map) lock.currentLockHolder(lockName,"1","1",authorization, null, appName).getEntity(); + assertEquals(ResultType.SUCCESS, resultMap.get("status")); + } + + @Test + public void Test7_unLock() throws Exception { + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Map resultMap = (Map) lock.unLock(lockId,"1","1",authorization, null, appName).getEntity(); + assertEquals(ResultType.SUCCESS, resultMap.get("status")); + } + + @Test + public void Test8_delete() throws Exception { + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Map resultMap = (Map) lock.deleteLock(lockName,"1","1", null,authorization, appName).getEntity(); + assertEquals(ResultType.SUCCESS, resultMap.get("status")); + } + + // Version api + @Test + public void Test1_version( ) { + RestMusicVersionAPI versionapi = new RestMusicVersionAPI(); + HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class); + Map resultMap = versionapi.version(servletResponse); + assertEquals(ResultType.SUCCESS, resultMap.get("status")); + } + + //Music Test Api + @Test + public void Test2_testAPI() { + RestMusicTestAPI musicTest = new RestMusicTestAPI(); + HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class); + Map> resultMap = musicTest.simpleTests(servletResponse); + assertNotNull(resultMap); + } + + //Music Health Check + @Test + public void Test3_HealthCheck_cassandra() { + String consistency = "ONE"; + RestMusicHealthCheckAPI healthCheck = new RestMusicHealthCheckAPI(); + HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class); + Response response = healthCheck.cassandraStatus(servletResponse, consistency); + assertEquals(200, response.getStatus()); + } + + @Test + public void Test3_HealthCheck_cassandra_cosistencyQuorum() { + String consistency = "QUORUM"; + RestMusicHealthCheckAPI healthCheck = new RestMusicHealthCheckAPI(); + HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class); + Response response = healthCheck.cassandraStatus(servletResponse, consistency); + assertEquals(200, response.getStatus()); + } + + @Test + public void Test3_HealthCheck_zookeeper() { + RestMusicHealthCheckAPI healthCheck = new RestMusicHealthCheckAPI(); + HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class); + Response response = healthCheck.ZKStatus(servletResponse); + assertEquals(200, response.getStatus()); + } + + @Test + public void Test4_pureZKcreate() throws Exception { + RestMusicBmAPI bmApi = new RestMusicBmAPI(); + bmApi.pureZkCreate("sample"); + } + + @Test + public void Test4_pureZKUpdate() throws Exception { + RestMusicBmAPI bmApi = new RestMusicBmAPI(); + bmApi.pureZkCreate("sample1"); + JsonInsert jsonInsert = new JsonInsert(); + Map consistencyInfo = new HashMap<>(); + Map values = new HashMap<>(); + values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); + values.put("emp_name", "testName_create"); + values.put("emp_salary", 500); + consistencyInfo.put("type", "eventual"); + jsonInsert.setConsistencyInfo(consistencyInfo); + jsonInsert.setKeyspaceName(keyspaceName); + jsonInsert.setTableName(tableName); + jsonInsert.setValues(values); + bmApi.pureZkUpdate(jsonInsert, "sampleNode1"); + } + + @Test + public void Test4_pureZKGet() throws Exception { + RestMusicBmAPI bmApi = new RestMusicBmAPI(); + bmApi.pureZkGet("sample"); + } + + @Test + public void Test5_ZKAtomicPut_atomic() throws Exception { + RestMusicBmAPI bmApi = new RestMusicBmAPI(); + JsonInsert jsonInsert = new JsonInsert(); + Map consistencyInfo = new HashMap<>(); + Map values = new HashMap<>(); + values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); + values.put("emp_name", "testName_create"); + values.put("emp_salary", 1500); + consistencyInfo.put("type", "atomic"); + jsonInsert.setConsistencyInfo(consistencyInfo); + jsonInsert.setKeyspaceName(keyspaceName); + jsonInsert.setTableName(tableName); + jsonInsert.setValues(values); + bmApi.pureZkAtomicPut(jsonInsert, "lockname", "sampleNode1"); + } + + @Test + public void Test5_ZKAtomicPut_atomic_with_delete() throws Exception { + RestMusicBmAPI bmApi = new RestMusicBmAPI(); + JsonInsert jsonInsert = new JsonInsert(); + Map consistencyInfo = new HashMap<>(); + Map values = new HashMap<>(); + values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); + values.put("emp_name", "testName_create"); + values.put("emp_salary", 1500); + consistencyInfo.put("type", "atomic_delete_lock"); + jsonInsert.setConsistencyInfo(consistencyInfo); + jsonInsert.setKeyspaceName(keyspaceName); + jsonInsert.setTableName(tableName); + jsonInsert.setValues(values); + bmApi.pureZkAtomicPut(jsonInsert, "lockname", "sampleNode1"); + } + + @Test + public void Test5_ZKAtomicGet_atomic() throws Exception { + RestMusicBmAPI bmApi = new RestMusicBmAPI(); + JsonInsert jsonInsert = new JsonInsert(); + Map consistencyInfo = new HashMap<>(); + Map values = new HashMap<>(); + values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); + values.put("emp_name", "testName_create"); + values.put("emp_salary", 1500); + consistencyInfo.put("type", "atomic_delete_lock"); + jsonInsert.setConsistencyInfo(consistencyInfo); + jsonInsert.setKeyspaceName(keyspaceName); + jsonInsert.setTableName(tableName); + jsonInsert.setValues(values); + bmApi.pureZkAtomicGet(jsonInsert, "lockname", "sampleNode1"); + } + + @Test + public void Test5_ZKAtomicGet_atomic_with_delete() throws Exception { + RestMusicBmAPI bmApi = new RestMusicBmAPI(); + JsonInsert jsonInsert = new JsonInsert(); + Map consistencyInfo = new HashMap<>(); + Map values = new HashMap<>(); + values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); + values.put("emp_name", "testName_create"); + values.put("emp_salary", 1500); + consistencyInfo.put("type", "atomic_delete_lock"); + jsonInsert.setConsistencyInfo(consistencyInfo); + jsonInsert.setKeyspaceName(keyspaceName); + jsonInsert.setTableName(tableName); + jsonInsert.setValues(values); + bmApi.pureZkAtomicGet(jsonInsert, "lockname", "sampleNode1"); + } + + @Test + public void Test5_updateCassa() throws Exception { + RestMusicBmAPI bmApi = new RestMusicBmAPI(); + JsonInsert jsonInsert = new JsonInsert(); + Map consistencyInfo = new HashMap<>(); + Map values = new HashMap<>(); + values.put("emp_salary", 1500); + consistencyInfo.put("type", "eventual"); + jsonInsert.setConsistencyInfo(consistencyInfo); + jsonInsert.setKeyspaceName(keyspaceName); + jsonInsert.setTableName(tableName); + jsonInsert.setValues(values); + MultivaluedMap row = new MultivaluedMapImpl(); + row.add("emp_name", "testName_create"); + Mockito.when(info.getQueryParameters()).thenReturn(row); + bmApi.updateTableCassa(jsonInsert, keyspaceName, tableName, info); + } + + // RestMusicConditional + @Test + public void Test5_createTable_conditional() throws Exception { + JsonTable jsonTable = new JsonTable(); + Map consistencyInfo = new HashMap<>(); + Map fields = new HashMap<>(); + fields.put("id", "text"); + fields.put("plans", "Map"); + fields.put("PRIMARY KEY", "(id)"); + consistencyInfo.put("type", "eventual"); + jsonTable.setConsistencyInfo(consistencyInfo); + jsonTable.setKeyspaceName(keyspaceName); + jsonTable.setPrimaryKey("id"); + jsonTable.setTableName(tableNameConditional); + jsonTable.setFields(fields); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = data.createTable("1", "1", "1", + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization, + jsonTable, keyspaceName, tableNameConditional); + System.out.println("#######status is " + response.getStatus()); + System.out.println("Entity" + response.getEntity()); + assertEquals(200, response.getStatus()); + } + + @Test + public void Test6_insertConditional() throws Exception { + RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI(); + JsonConditional json = new JsonConditional(); + json.setPrimaryKey("id"); + json.setPrimaryKeyValue("123|abc|port"); + json.setCasscadeColumnName("plans"); + Map tableValues = new HashMap<>(); + tableValues.put("id", "123|abc|port"); + json.setTableValues(tableValues); + Map columnData = new HashMap<>(); + Map column = new HashMap<>(); + column.put("created", "time"); + columnData.put("key", "P2"); + columnData.put("value", column); + json.setCasscadeColumnData(columnData); + Map cond = new HashMap<>(); + Map cond1 = new HashMap<>(); + Map> conditions = new HashMap>(); + cond.put("status", "under-spin-up"); + cond1.put("status", "parked"); + conditions.put("exists", cond); + conditions.put("nonexists", cond1); + json.setConditions(conditions); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = conditionalApi.insertConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", + appName, authorization, keyspaceName, tableNameConditional, json); + assertEquals(200, response.getStatus()); + } + + @Test + public void Test6_insertConditional_primaryKey_null() throws Exception { + RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI(); + JsonConditional json = new JsonConditional(); + json.setPrimaryKeyValue("123|abc|port"); + json.setCasscadeColumnName("plans"); + Map tableValues = new HashMap<>(); + tableValues.put("id", "123|abc|port"); + json.setTableValues(tableValues); + Map columnData = new HashMap<>(); + Map column = new HashMap<>(); + column.put("created", "time"); + columnData.put("key", "P2"); + columnData.put("value", column); + json.setCasscadeColumnData(columnData); + Map cond = new HashMap<>(); + Map cond1 = new HashMap<>(); + Map> conditions = new HashMap>(); + cond.put("status", "under-spin-up"); + cond1.put("status", "parked"); + conditions.put("exists", cond); + conditions.put("nonexists", cond1); + json.setConditions(conditions); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = conditionalApi.insertConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", + appName, authorization, keyspaceName, tableNameConditional, json); + assertEquals(401, response.getStatus()); + } + + @Test + public void Test6_insertConditional_wrongAuth() throws Exception { + RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI(); + JsonConditional json = new JsonConditional(); + json.setPrimaryKey("id"); + json.setPrimaryKeyValue("123|abc|port"); + json.setCasscadeColumnName("plans"); + Map tableValues = new HashMap<>(); + tableValues.put("id", "123|abc|port"); + json.setTableValues(tableValues); + Map columnData = new HashMap<>(); + Map column = new HashMap<>(); + column.put("created", "time"); + columnData.put("key", "P2"); + columnData.put("value", column); + json.setCasscadeColumnData(columnData); + Map cond = new HashMap<>(); + Map cond1 = new HashMap<>(); + Map> conditions = new HashMap>(); + cond.put("status", "under-spin-up"); + cond1.put("status", "parked"); + conditions.put("exists", cond); + conditions.put("nonexists", cond1); + json.setConditions(conditions); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = conditionalApi.insertConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", + appName, wrongAuthorization, keyspaceName, tableNameConditional, json); + assertEquals(401, response.getStatus()); + } + + @Test + public void Test7_updateConditional() throws Exception { + RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI(); + JsonConditional json = new JsonConditional(); + json.setPrimaryKey("id"); + json.setPrimaryKeyValue("123|abc|port"); + json.setCasscadeColumnName("plans"); + Map tableValues = new HashMap<>(); + tableValues.put("id", "123|abc|port"); + json.setTableValues(tableValues); + Map columnData = new HashMap<>(); + Map column = new HashMap<>(); + column.put("created", "time"); + columnData.put("key", "P2"); + columnData.put("value", column); + json.setCasscadeColumnData(columnData); + Map cond = new HashMap<>(); + Map cond1 = new HashMap<>(); + Map> conditions = new HashMap>(); + cond.put("updated", "new time"); + conditions.put("exists", cond); + conditions.put("nonexists", cond1); + json.setConditions(conditions); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = conditionalApi.updateConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", + appName, authorization, keyspaceName, tableNameConditional, json); + assertEquals(200, response.getStatus()); + } + + @Test + public void Test7_updateConditional_wrongAuth() throws Exception { + RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI(); + JsonConditional json = new JsonConditional(); + json.setPrimaryKey("id"); + json.setPrimaryKeyValue("123|abc|port"); + json.setCasscadeColumnName("plans"); + Map tableValues = new HashMap<>(); + tableValues.put("id", "123|abc|port"); + json.setTableValues(tableValues); + Map columnData = new HashMap<>(); + Map column = new HashMap<>(); + column.put("created", "time"); + columnData.put("key", "P2"); + columnData.put("value", column); + json.setCasscadeColumnData(columnData); + Map cond = new HashMap<>(); + Map cond1 = new HashMap<>(); + Map> conditions = new HashMap>(); + cond.put("updated", "new time"); + conditions.put("exists", cond); + conditions.put("nonexists", cond1); + json.setConditions(conditions); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = conditionalApi.updateConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", + appName, wrongAuthorization, keyspaceName, tableNameConditional, json); + assertEquals(401, response.getStatus()); + } + + @Test + public void Test7_updateConditional_primarykey_null() throws Exception { + RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI(); + JsonConditional json = new JsonConditional(); + json.setPrimaryKeyValue("123|abc|port"); + json.setCasscadeColumnName("plans"); + Map tableValues = new HashMap<>(); + tableValues.put("id", "123|abc|port"); + json.setTableValues(tableValues); + Map columnData = new HashMap<>(); + Map column = new HashMap<>(); + column.put("created", "time"); + columnData.put("key", "P2"); + columnData.put("value", column); + json.setCasscadeColumnData(columnData); + Map cond = new HashMap<>(); + Map cond1 = new HashMap<>(); + Map> conditions = new HashMap>(); + cond.put("updated", "new time"); + conditions.put("exists", cond); + conditions.put("nonexists", cond1); + json.setConditions(conditions); + Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = conditionalApi.updateConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", + appName, authorization, keyspaceName, tableNameConditional, json); + assertEquals(401, response.getStatus()); + } +} \ No newline at end of file diff --git a/src/test/java/org/onap/music/unittests/TestRestMusicData.java b/src/test/java/org/onap/music/unittests/TestRestMusicData.java deleted file mode 100644 index e18982e5..00000000 --- a/src/test/java/org/onap/music/unittests/TestRestMusicData.java +++ /dev/null @@ -1,2244 +0,0 @@ -/* - * ============LICENSE_START========================================== org.onap.music - * =================================================================== Copyright (c) 2017 AT&T - * Intellectual Property =================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * - * ============LICENSE_END============================================= - * ==================================================================== - */ -package org.onap.music.unittests; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.onap.music.main.MusicCore.mLockHandle; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import org.apache.curator.test.TestingServer; -import org.apache.http.impl.client.AutoRetryHttpClient; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.mindrot.jbcrypt.BCrypt; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.mockito.runners.MockitoJUnitRunner; -import org.onap.music.conductor.conditionals.JsonConditional; -import org.onap.music.conductor.conditionals.MusicConditional; -import org.onap.music.conductor.conditionals.RestMusicConditionalAPI; -import org.onap.music.datastore.PreparedQueryObject; -import org.onap.music.datastore.jsonobjects.JsonDelete; -import org.onap.music.datastore.jsonobjects.JsonInsert; -import org.onap.music.datastore.jsonobjects.JsonKeySpace; -import org.onap.music.datastore.jsonobjects.JsonOnboard; -import org.onap.music.datastore.jsonobjects.JsonSelect; -import org.onap.music.datastore.jsonobjects.JsonTable; -import org.onap.music.datastore.jsonobjects.JsonUpdate; -import org.onap.music.exceptions.MusicServiceException; -import org.onap.music.lockingservice.MusicLockState; -import org.onap.music.lockingservice.MusicLockingService; -import org.onap.music.lockingservice.MusicLockState.LockStatus; -import org.onap.music.main.CachingUtil; -import org.onap.music.main.MusicCore; -import org.onap.music.main.MusicUtil; -import org.onap.music.main.ResultType; -import org.onap.music.main.ReturnType; -import org.onap.music.rest.RestMusicAdminAPI; -import org.onap.music.rest.RestMusicBmAPI; -import org.onap.music.rest.RestMusicDataAPI; -import org.onap.music.rest.RestMusicHealthCheckAPI; -import org.onap.music.rest.RestMusicLocksAPI; -import org.onap.music.rest.RestMusicTestAPI; -import org.onap.music.rest.RestMusicVersionAPI; - -import com.datastax.driver.core.ConsistencyLevel; -import com.datastax.driver.core.DataType; -import com.datastax.driver.core.ResultSet; -import com.datastax.driver.core.Row; -import com.sun.jersey.core.util.Base64; -import com.sun.jersey.core.util.MultivaluedMapImpl; - -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@RunWith(MockitoJUnitRunner.class) -public class TestRestMusicData { - - RestMusicDataAPI data = new RestMusicDataAPI(); - RestMusicAdminAPI admin = new RestMusicAdminAPI(); - RestMusicLocksAPI lock = new RestMusicLocksAPI(); - static PreparedQueryObject testObject; - static TestingServer zkServer; - - @Mock - HttpServletResponse http; - - @Mock - UriInfo info; - - //* cjc out - @Mock - CachingUtil cachUtilMock; - - @InjectMocks - private MusicCore mCore; - //*/ - - static String appName = "TestApp"; - static String userId = "TestUser"; - static String password = "TestPassword"; - static String authData = userId+":"+password; - static String wrongAuthData = userId+":"+"pass"; - static String authorization = new String(Base64.encode(authData.getBytes())); - static String wrongAuthorization = new String(Base64.encode(wrongAuthData.getBytes())); - static boolean isAAF = false; - static UUID uuid = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40ce6"); - static String keyspaceName = "testCassa"; - static String tableName = "employees"; - static String tableNameConditional = "Conductor"; - static String xLatestVersion = "X-latestVersion"; - static String onboardUUID = null; - static String lockId = null; - static String lockName = "testCassa.employees.sample3"; - - @BeforeClass - public static void init() throws Exception { - try { - MusicCore.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra(); - zkServer = new TestingServer(2181, new File("/tmp/zk")); - MusicCore.mLockHandle = new MusicLockingService(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - testObject = new PreparedQueryObject(); - testObject.appendQueryString("DROP KEYSPACE IF EXISTS " + keyspaceName); - MusicCore.eventualPut(testObject); - testObject = new PreparedQueryObject(); - testObject.appendQueryString("DROP KEYSPACE IF EXISTS admin"); - MusicCore.eventualPut(testObject); - MusicCore.mDstoreHandle.close(); - MusicCore.mLockHandle.getzkLockHandle().close(); - MusicCore.mLockHandle.close(); - zkServer.stop(); - } - - @Test - public void Test1_createKeyspace() throws Exception { - testObject = new PreparedQueryObject(); - testObject.appendQueryString("CREATE KEYSPACE admin WITH REPLICATION = " - + "{'class' : 'SimpleStrategy' , " - + "'replication_factor': 1} AND DURABLE_WRITES = true"); - MusicCore.eventualPut(testObject); - testObject = new PreparedQueryObject(); - testObject.appendQueryString( - "CREATE TABLE admin.keyspace_master (" + " uuid uuid, keyspace_name text," - + " application_name text, is_api boolean," - + " password text, username text," - + " is_aaf boolean, PRIMARY KEY (uuid)\n" + ");"); - MusicCore.eventualPut(testObject); - - testObject = new PreparedQueryObject(); - testObject.appendQueryString( - "INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, " - + "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)"); - testObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid)); - testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), - MusicUtil.DEFAULTKEYSPACENAME)); - testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName)); - testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True")); - testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt()))); - testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId)); - testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF)); - MusicCore.eventualPut(testObject); - - testObject = new PreparedQueryObject(); - testObject.appendQueryString( - "INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, " - + "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)"); - testObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), - UUID.fromString("bbc66ccc-d857-4e90-b1e5-df98a3d40de6"))); - testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), - MusicUtil.DEFAULTKEYSPACENAME)); - testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), "TestApp1")); - testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True")); - testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt()))); - testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), "TestUser1")); - testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF)); - MusicCore.eventualPut(testObject); - - testObject = new PreparedQueryObject(); - testObject.appendQueryString( - "select uuid from admin.keyspace_master where application_name = ? allow filtering"); - testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName)); - ResultSet rs = MusicCore.get(testObject); - List rows = rs.all(); - if (rows.size() > 0) { - System.out.println("#######UUID is:" + rows.get(0).getUUID("uuid")); - } - } - - @Test - public void Test2_createKeyspace() throws Exception { - JsonKeySpace jsonKeyspace = new JsonKeySpace(); - Map consistencyInfo = new HashMap<>(); - Map replicationInfo = new HashMap<>(); - consistencyInfo.put("type", "eventual"); - replicationInfo.put("class", "SimpleStrategy"); - replicationInfo.put("replication_factor", 1); - jsonKeyspace.setConsistencyInfo(consistencyInfo); - jsonKeyspace.setDurabilityOfWrites("true"); - jsonKeyspace.setKeyspaceName(keyspaceName); - jsonKeyspace.setReplicationInfo(replicationInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createKeySpace("1", "1", "1", null,authorization, appName, jsonKeyspace, keyspaceName); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - assertEquals(200,response.getStatus()); - } - - @Test - public void Test2_createKeyspace1() throws Exception { - JsonKeySpace jsonKeyspace = new JsonKeySpace(); - Map consistencyInfo = new HashMap<>(); - Map replicationInfo = new HashMap<>(); - consistencyInfo.put("type", "eventual"); - replicationInfo.put("class", "SimpleStrategy"); - replicationInfo.put("replication_factor", 1); - jsonKeyspace.setConsistencyInfo(consistencyInfo); - jsonKeyspace.setDurabilityOfWrites("true"); - jsonKeyspace.setKeyspaceName(keyspaceName); - jsonKeyspace.setReplicationInfo(replicationInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createKeySpace("1", "1", "1", null,authorization, appName, jsonKeyspace, "keyspaceName"); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - assertEquals(200,response.getStatus()); - } - - @Test - public void Test2_createKeyspace0() throws Exception { - JsonKeySpace jsonKeyspace = new JsonKeySpace(); - Map consistencyInfo = new HashMap<>(); - Map replicationInfo = new HashMap<>(); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createKeySpace("1", "1", "1", null, authorization,appName, jsonKeyspace, keyspaceName); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - assertEquals(400,response.getStatus()); - } -//MusicCore.autheticateUser - @Test - public void Test2_createKeyspace01() throws Exception { - JsonKeySpace jsonKeyspace = new JsonKeySpace(); - Map consistencyInfo = new HashMap<>(); - Map replicationInfo = new HashMap<>(); - String appName1 = "test"; - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createKeySpace("1", "1", "1", null,authorization, appName1, jsonKeyspace, keyspaceName); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - assertEquals(401,response.getStatus()); - } - - @Test - public void Test3_createKeyspace1() throws Exception { - JsonKeySpace jsonKeyspace = new JsonKeySpace(); - Map consistencyInfo = new HashMap<>(); - Map replicationInfo = new HashMap<>(); - consistencyInfo.put("type", "eventual"); - replicationInfo.put("class", "SimpleStrategy"); - replicationInfo.put("replication_factor", 1); - jsonKeyspace.setConsistencyInfo(consistencyInfo); - jsonKeyspace.setDurabilityOfWrites("true"); - jsonKeyspace.setKeyspaceName("TestApp1"); - jsonKeyspace.setReplicationInfo(replicationInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createKeySpace("1", "1", "1", null,authorization, "TestApp1", - jsonKeyspace, keyspaceName); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - assertEquals(401,response.getStatus()); - } - - @Test - public void Test2_createKeyspaceEmptyAuth() throws Exception { - - //MockitoAnnotations.initMocks(this); - JsonKeySpace jsonKeyspace = new JsonKeySpace(); - Map consistencyInfo = new HashMap<>(); - Map replicationInfo = new HashMap<>(); - consistencyInfo.put("type", "eventual"); - replicationInfo.put("class", "SimpleStrategy"); - replicationInfo.put("replication_factor", 1); - jsonKeyspace.setConsistencyInfo(consistencyInfo); - jsonKeyspace.setDurabilityOfWrites("true"); - jsonKeyspace.setKeyspaceName(keyspaceName); - jsonKeyspace.setReplicationInfo(replicationInfo); - //Map m1= new HashMap<>() ; - //Mockito.when(CachingUtil.verifyOnboarding("x","y","x")).thenReturn(m1); - //Mockito.when(CachingUtil.verifyOnboarding(appNamex,userId,password).thenReturn(m1)); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - String authDatax = ":"+password; - String authorizationx = new String(Base64.encode(authDatax.getBytes())); - try { - Response response = data.createKeySpace("1", "1", "1", null,authorizationx, appName, jsonKeyspace, keyspaceName); - //System.out.println("#######status is " + response.getStatus()); - //System.out.println("Entity" + response.getEntity()); - //assertNotEquals(200,response.getStatus()); - } catch (RuntimeException e ) { - System.out.println("#######status is runtime exception= " + e); - } - } - - @Test - public void Test3_createTable() throws Exception { - JsonTable jsonTable = new JsonTable(); - Map consistencyInfo = new HashMap<>(); - Map fields = new HashMap<>(); - fields.put("uuid", "text"); - fields.put("emp_name", "text"); - fields.put("emp_salary", "varint"); - fields.put("PRIMARY KEY", "(emp_name)"); - consistencyInfo.put("type", "eventual"); - jsonTable.setConsistencyInfo(consistencyInfo); - jsonTable.setKeyspaceName(keyspaceName); - jsonTable.setPrimaryKey("emp_name"); - jsonTable.setTableName(tableName); - jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization, - jsonTable, keyspaceName, tableName); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - assertEquals(200, response.getStatus()); - } - - - @Test - public void Test3_createTableClusterOrderBad() throws Exception { - JsonTable jsonTable = new JsonTable(); - Map consistencyInfo = new HashMap<>(); - Map fields = new HashMap<>(); - fields.put("uuid", "text"); - fields.put("emp_name", "text"); - fields.put("emp_salary", "varint"); - fields.put("PRIMARY KEY", "(emp_name,emp_salary)"); - consistencyInfo.put("type", "eventual"); - jsonTable.setConsistencyInfo(consistencyInfo); - jsonTable.setKeyspaceName(keyspaceName); - jsonTable.setPrimaryKey("emp_name,emp_salary"); - jsonTable.setClusteringOrder("ASC"); - jsonTable.setTableName(tableName); - jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization, - jsonTable, keyspaceName, tableName); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - assertNotEquals(200, response.getStatus()); - } - - @Test - public void Test3_createTable_withPropertiesNotNull() throws Exception { - JsonTable jsonTable = new JsonTable(); - Map consistencyInfo = new HashMap<>(); - Map fields = new HashMap<>(); - fields.put("uuid", "text"); - fields.put("emp_name", "text"); - fields.put("emp_salary", "varint"); - fields.put("PRIMARY KEY", "(emp_name)"); - consistencyInfo.put("type", "eventual"); - Map properties = new HashMap<>(); - properties.put("comment","Testing prperties not null"); - jsonTable.setConsistencyInfo(consistencyInfo); - jsonTable.setKeyspaceName(keyspaceName); - jsonTable.setPrimaryKey("emp_name"); - String tableName_prop=tableName+"_Prop"; - jsonTable.setTableName(tableName_prop); - jsonTable.setFields(fields); - jsonTable.setProperties(properties); - - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization, - jsonTable, keyspaceName, tableName_prop); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test3_createTable_duplicateTable() throws Exception { - JsonTable jsonTable = new JsonTable(); - Map consistencyInfo = new HashMap<>(); - Map fields = new HashMap<>(); - fields.put("uuid", "text"); - fields.put("emp_name", "text"); - fields.put("emp_salary", "varint"); - fields.put("PRIMARY KEY", "(emp_name)"); - consistencyInfo.put("type", "eventual"); - jsonTable.setConsistencyInfo(consistencyInfo); - jsonTable.setKeyspaceName(keyspaceName); - jsonTable.setPrimaryKey("emp_name"); - String tableNameDup=tableName+"X"; - jsonTable.setTableName(tableNameDup); - jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonTable, keyspaceName, tableNameDup); - System.out.println("#######status for 1st time " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - - Response response0 = data.createTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonTable, keyspaceName, tableNameDup); - // 400 is the duplicate status found in response - // Music 113 duplicate testing - //import static org.junit.Assert.assertNotEquals; - System.out.println("#######status for 2nd time " + response0.getStatus()); - System.out.println("Entity" + response0.getEntity()); - - assertFalse("Duplicate table not created for "+tableNameDup, 200==response0.getStatus()); - - } - - // Improper Auth - @Test - public void Test3_createTable1() throws Exception { - JsonTable jsonTable = new JsonTable(); - Map consistencyInfo = new HashMap<>(); - Map fields = new HashMap<>(); - fields.put("uuid", "text"); - fields.put("emp_name", "text"); - fields.put("emp_salary", "varint"); - fields.put("PRIMARY KEY", "(emp_name)"); - consistencyInfo.put("type", "eventual"); - jsonTable.setConsistencyInfo(consistencyInfo); - jsonTable.setKeyspaceName(keyspaceName); - jsonTable.setPrimaryKey("emp_name"); - jsonTable.setTableName(tableName); - jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization, - jsonTable, keyspaceName, tableName); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - assertEquals(401, response.getStatus()); - } - - // Improper keyspace - @Test - public void Test3_createTable3() throws Exception { - JsonTable jsonTable = new JsonTable(); - Map consistencyInfo = new HashMap<>(); - Map fields = new HashMap<>(); - fields.put("uuid", "text"); - fields.put("emp_name", "text"); - fields.put("emp_salary", "varint"); - fields.put("PRIMARY KEY", "(emp_name)"); - consistencyInfo.put("type", "eventual"); - jsonTable.setConsistencyInfo(consistencyInfo); - jsonTable.setKeyspaceName(keyspaceName); - jsonTable.setPrimaryKey("emp_name"); - jsonTable.setTableName(tableName); - jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonTable, "wrong", tableName); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - assertEquals(401, response.getStatus()); - } - - @Test - public void Test3_createTable3_with_samePartition_clusteringKeys() throws Exception { - JsonTable jsonTable = new JsonTable(); - Map consistencyInfo = new HashMap<>(); - Map fields = new HashMap<>(); - fields.put("uuid", "text"); - fields.put("emp_name", "text"); - fields.put("emp_salary", "varint"); - fields.put("PRIMARY KEY", "(emp_name, emp_name)"); - consistencyInfo.put("type", "eventual"); - jsonTable.setConsistencyInfo(consistencyInfo); - jsonTable.setKeyspaceName(keyspaceName); - jsonTable.setPartitionKey("emp_name"); - jsonTable.setClusteringKey("emp_name"); - jsonTable.setTableName(tableName); - jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonTable, keyspaceName, tableName); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - assertEquals(400, response.getStatus()); - } - - @Test - public void Test3_createTable3_with_Partition_clusteringKeys() throws Exception { - JsonTable jsonTable = new JsonTable(); - Map consistencyInfo = new HashMap<>(); - Map fields = new HashMap<>(); - fields.put("uuid", "text"); - fields.put("emp_name", "text"); - fields.put("emp_salary", "varint"); - consistencyInfo.put("type", "eventual"); - jsonTable.setConsistencyInfo(consistencyInfo); - jsonTable.setKeyspaceName(keyspaceName); - jsonTable.setPartitionKey("emp_name"); - jsonTable.setClusteringKey("uuid"); - jsonTable.setTableName(tableName); - jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonTable, keyspaceName, "tableName1"); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - assertEquals(200, response.getStatus()); - } - - // Improper parenthesis in key field - @Test - public void Test3_createTable_badParantesis() throws Exception { - String tableNameC ="testTable0"; - JsonTable jsonTable = new JsonTable(); - Map consistencyInfo = new HashMap<>(); - Map fields = new HashMap<>(); - fields.put("uuid", "text"); - fields.put("emp_name", "text"); - fields.put("emp_salary", "varint"); - fields.put("PRIMARY KEY", "(emp_name),emp_id)"); - fields.put("emp_id", "varint"); - consistencyInfo.put("type", "eventual"); - jsonTable.setConsistencyInfo(consistencyInfo); - jsonTable.setKeyspaceName(keyspaceName); - jsonTable.setPrimaryKey("emp_name"); - jsonTable.setTableName(tableNameC); - jsonTable.setClusteringOrder("emp_id Desc"); - jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonTable, keyspaceName, tableNameC); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - //assertEquals(400, response.getStatus()); - assertTrue(200 != response.getStatus()); - } - - - // good clustering key - @Test - public void Test3_createTable_1_clusterKey_good() throws Exception { - String tableNameC ="testTableC1"; - JsonTable jsonTable = new JsonTable(); - Map consistencyInfo = new HashMap<>(); - Map fields = new HashMap<>(); - fields.put("uuid", "text"); - fields.put("emp_name", "text"); - fields.put("emp_salary", "varint"); - fields.put("PRIMARY KEY", "((emp_name),emp_salary)"); - consistencyInfo.put("type", "eventual"); - jsonTable.setConsistencyInfo(consistencyInfo); - jsonTable.setKeyspaceName(keyspaceName); - // jsonTable.setPrimaryKey("emp_name"); - jsonTable.setTableName(tableNameC); - jsonTable.setClusteringOrder("emp_salary ASC"); - jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonTable, keyspaceName, tableNameC); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - assertEquals(200, response.getStatus()); - } - - // bad partition key=clustering key - @Test - public void Test3_createTable_2_clusterKey_bad() throws Exception { - String tableNameC ="testTableC2"; - JsonTable jsonTable = new JsonTable(); - Map consistencyInfo = new HashMap<>(); - Map fields = new HashMap<>(); - fields.put("uuid", "text"); - fields.put("emp_name", "text"); - fields.put("emp_salary", "varint"); - fields.put("PRIMARY KEY", "((emp_name),emp_name)"); - consistencyInfo.put("type", "eventual"); - jsonTable.setConsistencyInfo(consistencyInfo); - jsonTable.setKeyspaceName(keyspaceName); - jsonTable.setPrimaryKey("emp_name"); // "PRIMARY KEY" overrides if primaryKey present - jsonTable.setTableName(tableNameC); - jsonTable.setClusteringOrder("emp_salary ASC"); - jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonTable, keyspaceName, tableNameC); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - assertTrue(200 !=response.getStatus()); - } - - // good composite partition key,clustering key - @Test - public void Test3_createTable_3_partition_clusterKey_good() throws Exception { - String tableNameC ="testTableC3"; - JsonTable jsonTable = new JsonTable(); - Map consistencyInfo = new HashMap<>(); - Map fields = new HashMap<>(); - fields.put("uuid", "text"); - fields.put("emp_name", "text"); - fields.put("emp_id", "varint"); - fields.put("emp_salary", "varint"); - fields.put("PRIMARY KEY", "((emp_name,emp_id),emp_salary)"); - consistencyInfo.put("type", "eventual"); - jsonTable.setConsistencyInfo(consistencyInfo); - jsonTable.setKeyspaceName(keyspaceName); - jsonTable.setPrimaryKey("emp_name"); - jsonTable.setTableName(tableNameC); - jsonTable.setClusteringOrder("emp_salary ASC"); - jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonTable, keyspaceName, tableNameC); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - assertEquals(200, response.getStatus()); - } - - // bad - not all cols in order by of composite partition key,clustering key - @Test - public void Test3_createTable_4_clusteringOrder_bad() throws Exception { - String tableNameC ="testTableC4"; - JsonTable jsonTable = new JsonTable(); - Map consistencyInfo = new HashMap<>(); - Map fields = new HashMap<>(); - fields.put("uuid", "text"); - fields.put("emp_name", "text"); - fields.put("emp_id", "varint"); - fields.put("emp_salary", "varint"); - fields.put("PRIMARY KEY", "((emp_name),emp_id,emp_salary)"); - consistencyInfo.put("type", "eventual"); - jsonTable.setConsistencyInfo(consistencyInfo); - jsonTable.setKeyspaceName(keyspaceName); - jsonTable.setPrimaryKey("emp_name"); - jsonTable.setTableName(tableNameC); - jsonTable.setClusteringOrder("emp_salary ASC"); - jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonTable, keyspaceName, tableNameC); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - assertTrue(200 != response.getStatus()); - } - - // bad - wrong cols in order by of composite partition key,clustering key - @Test - public void Test3_createTable_5_clusteringOrder_bad() throws Exception { - String tableNameC ="testTableC5"; - JsonTable jsonTable = new JsonTable(); - Map consistencyInfo = new HashMap<>(); - Map fields = new HashMap<>(); - fields.put("uuid", "text"); - fields.put("emp_name", "text"); - fields.put("emp_id", "varint"); - fields.put("emp_salary", "varint"); - fields.put("PRIMARY KEY", "((uuid,emp_name),emp_id,emp_salary)"); - consistencyInfo.put("type", "eventual"); - jsonTable.setConsistencyInfo(consistencyInfo); - jsonTable.setKeyspaceName(keyspaceName); - jsonTable.setPrimaryKey("emp_name"); - jsonTable.setTableName(tableNameC); - jsonTable.setClusteringOrder("emp_idx desc, emp_salary ASC"); - jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonTable, keyspaceName, tableNameC); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - assertTrue(200 != response.getStatus()); - } - - // bad - wrong cols in order by of composite partition key,clustering key - @Test - public void Test3_createTable_6_clusteringOrder_bad() throws Exception { - String tableNameC ="testTableC6"; - JsonTable jsonTable = new JsonTable(); - Map consistencyInfo = new HashMap<>(); - Map fields = new HashMap<>(); - fields.put("uuid", "text"); - fields.put("emp_name", "text"); - fields.put("emp_id", "varint"); - fields.put("emp_salary", "varint"); - fields.put("PRIMARY KEY", "((uuid,emp_name),emp_id,emp_salary)"); - consistencyInfo.put("type", "eventual"); - jsonTable.setConsistencyInfo(consistencyInfo); - jsonTable.setKeyspaceName(keyspaceName); - jsonTable.setPrimaryKey("((uuid,emp_name),emp_id,emp_salary)"); // overridden by - jsonTable.setTableName(tableNameC); - jsonTable.setClusteringOrder("emp_id desc, emp_salary ASC,uuid desc"); - jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonTable, keyspaceName, tableNameC); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - assertTrue(200 != response.getStatus()); - } - - - @Test - public void Test3_createTableIndex_1() throws Exception { - String tableNameC ="testTableCinx"; - JsonTable jsonTable = new JsonTable(); - Map consistencyInfo = new HashMap<>(); - Map fields = new HashMap<>(); - fields.put("uuid", "text"); - fields.put("emp_name", "text"); - fields.put("emp_salary", "varint"); - fields.put("PRIMARY KEY", "((emp_name),emp_salary)"); - consistencyInfo.put("type", "eventual"); - jsonTable.setConsistencyInfo(consistencyInfo); - jsonTable.setKeyspaceName(keyspaceName); - jsonTable.setTableName(tableNameC); - jsonTable.setClusteringOrder("emp_salary ASC"); - jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonTable, keyspaceName, tableNameC); - MultivaluedMap rowParams = Mockito.mock(MultivaluedMap.class); - Mockito.when(info.getQueryParameters()).thenReturn(rowParams); - Mockito.when(rowParams.getFirst("index_name")).thenReturn("my_index"); - response = data.createIndex("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - keyspaceName, tableNameC,"uuid",info); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test3_createTableIndex_badindexname() throws Exception { - String tableNameC ="testTableCinx"; - JsonTable jsonTable = new JsonTable(); - Map consistencyInfo = new HashMap<>(); - Map fields = new HashMap<>(); - fields.put("uuid", "text"); - fields.put("emp_name", "text"); - fields.put("emp_salary", "varint"); - fields.put("PRIMARY KEY", "((emp_name),emp_salary)"); - consistencyInfo.put("type", "eventual"); - jsonTable.setConsistencyInfo(consistencyInfo); - jsonTable.setKeyspaceName(keyspaceName); - jsonTable.setTableName(tableNameC); - jsonTable.setClusteringOrder("emp_salary ASC"); - jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonTable, keyspaceName, tableNameC); - MultivaluedMap rowParams = Mockito.mock(MultivaluedMap.class); - Mockito.when(info.getQueryParameters()).thenReturn(rowParams); - Mockito.when(rowParams.getFirst("index_name")).thenReturn("my index"); - response = data.createIndex("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - keyspaceName, tableNameC,"uuid",info); - assertEquals(400, response.getStatus()); - } - - @Test - public void Test3_createTableIndex_wrongindex() throws Exception { - String tableNameC ="testTableCinx"; - JsonTable jsonTable = new JsonTable(); - Map consistencyInfo = new HashMap<>(); - Map fields = new HashMap<>(); - fields.put("uuid", "text"); - fields.put("emp_name", "text"); - fields.put("emp_salary", "varint"); - fields.put("PRIMARY KEY", "((emp_name),emp_salary)"); - consistencyInfo.put("type", "eventual"); - jsonTable.setConsistencyInfo(consistencyInfo); - jsonTable.setKeyspaceName(keyspaceName); - jsonTable.setTableName(tableNameC); - jsonTable.setClusteringOrder("emp_salary ASC"); - jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonTable, keyspaceName, tableNameC); - MultivaluedMap rowParams = Mockito.mock(MultivaluedMap.class); - Mockito.when(info.getQueryParameters()).thenReturn(rowParams); - Mockito.when(rowParams.getFirst("index_name")).thenReturn("my_index"); - response = data.createIndex("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - keyspaceName, tableNameC,"id",info); - assertEquals(400, response.getStatus()); - } - - @Test - public void Test4_insertIntoTable() throws Exception { - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - Map values = new HashMap<>(); - values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); - values.put("emp_name", "testName"); - values.put("emp_salary", 500); - consistencyInfo.put("type", "eventual"); - jsonInsert.setConsistencyInfo(consistencyInfo); - jsonInsert.setKeyspaceName(keyspaceName); - jsonInsert.setTableName(tableName); - jsonInsert.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", - appName, authorization, jsonInsert, keyspaceName, tableName); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test4_insertIntoTable2() throws Exception { - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - Map values = new HashMap<>(); - values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); - values.put("emp_name", "test1"); - values.put("emp_salary", 1500); - consistencyInfo.put("type", "eventual"); - jsonInsert.setConsistencyInfo(consistencyInfo); - jsonInsert.setKeyspaceName(keyspaceName); - jsonInsert.setTableName(tableName); - jsonInsert.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.insertIntoTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonInsert, keyspaceName, tableName); - assertEquals(200, response.getStatus()); - } - - // Auth Error - @Test - public void Test4_insertIntoTable3() throws Exception { - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - Map values = new HashMap<>(); - values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); - values.put("emp_name", "test1"); - values.put("emp_salary", 1500); - consistencyInfo.put("type", "eventual"); - jsonInsert.setConsistencyInfo(consistencyInfo); - jsonInsert.setKeyspaceName(keyspaceName); - jsonInsert.setTableName(tableName); - jsonInsert.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.insertIntoTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization, - jsonInsert, keyspaceName, tableName); - assertEquals(401, response.getStatus()); - } - - // Table wrong - @Test - public void Test4_insertIntoTable4() throws Exception { - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - Map values = new HashMap<>(); - values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); - values.put("emp_name", "test1"); - values.put("emp_salary", 1500); - consistencyInfo.put("type", "eventual"); - jsonInsert.setConsistencyInfo(consistencyInfo); - jsonInsert.setKeyspaceName(keyspaceName); - jsonInsert.setTableName(tableName); - jsonInsert.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.insertIntoTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonInsert, keyspaceName, "wrong"); - assertEquals(400, response.getStatus()); - } - - @Test - public void Test4_insertIntoTable5() throws Exception { - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - Map values = new HashMap<>(); - values.put("id", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); - values.put("emp_name", "test1"); - values.put("emp_salary", 1500); - consistencyInfo.put("type", "eventual"); - jsonInsert.setConsistencyInfo(consistencyInfo); - jsonInsert.setKeyspaceName(keyspaceName); - jsonInsert.setTableName(tableName); - jsonInsert.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.insertIntoTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonInsert, keyspaceName, tableName); - assertEquals(400, response.getStatus()); - } - - @Test - public void Test4_insertIntoTable6() throws Exception { - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - Map values = new HashMap<>(); - values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); - values.put("emp_salary", 1500); - consistencyInfo.put("type", "eventual"); - jsonInsert.setConsistencyInfo(consistencyInfo); - jsonInsert.setKeyspaceName(keyspaceName); - jsonInsert.setTableName(tableName); - jsonInsert.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.insertIntoTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonInsert, keyspaceName, tableName); - assertEquals(400, response.getStatus()); - } - - @Test - public void Test4_insertIntoTable7() throws Exception { - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - Map values = new HashMap<>(); - values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); - values.put("emp_name", "test2"); - values.put("emp_salary", 1500); - consistencyInfo.put("type", "eventual"); - jsonInsert.setConsistencyInfo(consistencyInfo); - jsonInsert.setKeyspaceName(keyspaceName); - jsonInsert.setTableName(tableName); - jsonInsert.setValues(values); - jsonInsert.setTtl("1000"); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.insertIntoTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonInsert, keyspaceName, tableName); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test4_insertIntoTable8() throws Exception { - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - Map values = new HashMap<>(); - values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); - values.put("emp_name", "test3"); - values.put("emp_salary", 1500); - consistencyInfo.put("type", "eventual"); - jsonInsert.setConsistencyInfo(consistencyInfo); - jsonInsert.setKeyspaceName(keyspaceName); - jsonInsert.setTableName(tableName); - jsonInsert.setValues(values); - jsonInsert.setTimestamp("15000"); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.insertIntoTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonInsert, keyspaceName, tableName); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test4_insertIntoTable9() throws Exception { - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - Map values = new HashMap<>(); - values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); - values.put("emp_name", "test4"); - values.put("emp_salary", 1500); - consistencyInfo.put("type", "eventual"); - jsonInsert.setConsistencyInfo(consistencyInfo); - jsonInsert.setKeyspaceName(keyspaceName); - jsonInsert.setTableName(tableName); - jsonInsert.setValues(values); - jsonInsert.setTtl("1000"); - jsonInsert.setTimestamp("15000"); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.insertIntoTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonInsert, keyspaceName, tableName); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test4_insertIntoTable10() throws Exception { - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - Map values = new HashMap<>(); - values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); - values.put("emp_name", "test5"); - values.put("emp_salary", 1500); - consistencyInfo.put("type", "critical"); - jsonInsert.setConsistencyInfo(consistencyInfo); - jsonInsert.setKeyspaceName(keyspaceName); - jsonInsert.setTableName(tableName); - jsonInsert.setValues(values); - jsonInsert.setTtl("1000"); - jsonInsert.setTimestamp("15000"); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.insertIntoTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonInsert, keyspaceName, tableName); - assertEquals(400, response.getStatus()); - } - - @Test - public void Test4_insertIntoTable11() throws Exception { - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - Map values = new HashMap<>(); - values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); - values.put("emp_name", "test6"); - values.put("emp_salary", 1500); - consistencyInfo.put("type", "atomic_delete_lock"); - jsonInsert.setConsistencyInfo(consistencyInfo); - jsonInsert.setKeyspaceName(keyspaceName); - jsonInsert.setTableName(tableName); - jsonInsert.setValues(values); - jsonInsert.setTtl("1000"); - jsonInsert.setTimestamp("15000"); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.insertIntoTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonInsert, keyspaceName, tableName); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test4_insertIntoTable12() throws Exception { - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - Map values = new HashMap<>(); - values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); - values.put("emp_name", "test7"); - values.put("emp_salary", 1500); - consistencyInfo.put("type", "atomic"); - jsonInsert.setConsistencyInfo(consistencyInfo); - jsonInsert.setKeyspaceName(keyspaceName); - jsonInsert.setTableName(tableName); - jsonInsert.setValues(values); - jsonInsert.setTtl("1000"); - jsonInsert.setTimestamp("15000"); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.insertIntoTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonInsert, keyspaceName, tableName); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test5_updateTable() throws Exception { - JsonUpdate jsonUpdate = new JsonUpdate(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map values = new HashMap<>(); - row.add("emp_name", "testName"); - values.put("emp_salary", 2500); - consistencyInfo.put("type", "atomic"); - jsonUpdate.setConsistencyInfo(consistencyInfo); - jsonUpdate.setKeyspaceName(keyspaceName); - jsonUpdate.setTableName(tableName); - jsonUpdate.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, - authorization, jsonUpdate, keyspaceName, tableName, info); - assertEquals(200, response.getStatus()); - } - - // need mock code to create error for MusicCore methods - @Test - public void Test5_updateTableAuthE() throws Exception { - MockitoAnnotations.initMocks(this); - JsonUpdate jsonUpdate = new JsonUpdate(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map values = new HashMap<>(); - row.add("emp_name", "testName"); - values.put("emp_salary", 2500); - consistencyInfo.put("type", "atomic"); - jsonUpdate.setConsistencyInfo(consistencyInfo); - jsonUpdate.setKeyspaceName(keyspaceName); - jsonUpdate.setTableName(tableName); - jsonUpdate.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, - authorization, jsonUpdate, keyspaceName, tableName, info); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test5_updateTableAuthException1() throws Exception { - JsonUpdate jsonUpdate = new JsonUpdate(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map values = new HashMap<>(); - row.add("emp_name", "testName"); - values.put("emp_salary", 2500); - consistencyInfo.put("type", "atomic"); - jsonUpdate.setConsistencyInfo(consistencyInfo); - jsonUpdate.setKeyspaceName(keyspaceName); - jsonUpdate.setTableName(tableName); - jsonUpdate.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - String authDatax = ":";//+password; - String authorizationx = new String(Base64.encode(authDatax.getBytes())); - try { - Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, - authorizationx, jsonUpdate, keyspaceName, tableName, info); - assertEquals(200, response.getStatus()); - } catch(RuntimeException e) { - System.out.println("Update table Runtime exception="+e); - } - } - - @Test - public void Test5_updateTableAuthEmpty() throws Exception { - JsonUpdate jsonUpdate = new JsonUpdate(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map values = new HashMap<>(); - row.add("emp_name", "testName"); - values.put("emp_salary", 2500); - consistencyInfo.put("type", "atomic"); - jsonUpdate.setConsistencyInfo(consistencyInfo); - jsonUpdate.setKeyspaceName(keyspaceName); - jsonUpdate.setTableName(tableName); - jsonUpdate.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - String authDatax =":"+password; - String authorizationx = new String(Base64.encode(authDatax.getBytes())); - String appNamex="xx"; - try { - // Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, - Response response = data.updateTable("1", "1", "1", "", appNamex, - authorizationx, jsonUpdate, keyspaceName, tableName, info); - assertEquals(200, response.getStatus()); - } catch(RuntimeException e) { - System.out.println("Update table Runtime exception="+e); - } - } - - @Test - public void Test5_updateTable_wrongauth() throws Exception { - JsonUpdate jsonUpdate = new JsonUpdate(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map values = new HashMap<>(); - row.add("emp_name", "testName"); - values.put("emp_salary", 2500); - consistencyInfo.put("type", "atomic"); - jsonUpdate.setConsistencyInfo(consistencyInfo); - jsonUpdate.setKeyspaceName(keyspaceName); - jsonUpdate.setTableName(tableName); - jsonUpdate.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, - wrongAuthorization, jsonUpdate, keyspaceName, tableName, info); - assertEquals(401, response.getStatus()); - } - - @Test - public void Test5_updateTable_invalidColumn() throws Exception { - JsonUpdate jsonUpdate = new JsonUpdate(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map values = new HashMap<>(); - row.add("id", "testName"); - values.put("emp_salary", 2500); - consistencyInfo.put("type", "atomic"); - jsonUpdate.setConsistencyInfo(consistencyInfo); - jsonUpdate.setKeyspaceName(keyspaceName); - jsonUpdate.setTableName(tableName); - jsonUpdate.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, - authorization, jsonUpdate, keyspaceName, tableName, info); - assertEquals(400, response.getStatus()); - } - - @Test - public void Test5_updateTable_ttl() throws Exception { - JsonUpdate jsonUpdate = new JsonUpdate(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map values = new HashMap<>(); - row.add("emp_name", "testName8"); - values.put("emp_salary", 2500); - consistencyInfo.put("type", "atomic"); - jsonUpdate.setConsistencyInfo(consistencyInfo); - jsonUpdate.setKeyspaceName(keyspaceName); - jsonUpdate.setTableName(tableName); - jsonUpdate.setValues(values); - jsonUpdate.setTtl("1000"); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, - authorization, jsonUpdate, keyspaceName, tableName, info); - assertEquals(400, response.getStatus()); - } - - @Test - public void Test5_updateTable_timsetamp() throws Exception { - JsonUpdate jsonUpdate = new JsonUpdate(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map values = new HashMap<>(); - row.add("emp_name", "testName9"); - values.put("emp_salary", 2500); - consistencyInfo.put("type", "atomic"); - jsonUpdate.setConsistencyInfo(consistencyInfo); - jsonUpdate.setKeyspaceName(keyspaceName); - jsonUpdate.setTableName(tableName); - jsonUpdate.setValues(values); - jsonUpdate.setTimestamp("15000"); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, - authorization, jsonUpdate, keyspaceName, tableName, info); - assertEquals(400, response.getStatus()); - } - - @Test - public void Test5_updateTable_ttl_timestamp() throws Exception { - JsonUpdate jsonUpdate = new JsonUpdate(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map values = new HashMap<>(); - row.add("emp_name", "testName10"); - values.put("emp_salary", 2500); - consistencyInfo.put("type", "atomic"); - jsonUpdate.setConsistencyInfo(consistencyInfo); - jsonUpdate.setKeyspaceName(keyspaceName); - jsonUpdate.setTableName(tableName); - jsonUpdate.setValues(values); - jsonUpdate.setTtl("1000"); - jsonUpdate.setTimestamp("15000"); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, - authorization, jsonUpdate, keyspaceName, tableName, info); - assertEquals(400, response.getStatus()); - } - - @Test - public void Test5_updateTable_rowIdEmpty() throws Exception { - JsonUpdate jsonUpdate = new JsonUpdate(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map values = new HashMap<>(); - //row.add("emp_name", "testName3"); - values.put("emp_salary", 2500); - consistencyInfo.put("type", "atomic"); - jsonUpdate.setConsistencyInfo(consistencyInfo); - jsonUpdate.setKeyspaceName(keyspaceName); - jsonUpdate.setTableName(tableName); - jsonUpdate.setValues(values); - jsonUpdate.setTtl("1000"); - jsonUpdate.setTimestamp("15000"); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, - authorization, jsonUpdate, keyspaceName, tableName, info); - assertEquals(400, response.getStatus()); - } - - @Test - public void Test5_updateTable_conditions() throws Exception { - JsonUpdate jsonUpdate = new JsonUpdate(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map values = new HashMap<>(); - Map conditions = new HashMap<>(); - conditions.put("emp_name","testName3"); - row.add("emp_name", "testName3"); - values.put("emp_salary", 2500); - consistencyInfo.put("type", "atomic"); - jsonUpdate.setConsistencyInfo(consistencyInfo); - jsonUpdate.setKeyspaceName(keyspaceName); - jsonUpdate.setTableName(tableName); - jsonUpdate.setValues(values); - jsonUpdate.setConditions(conditions); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, - authorization, jsonUpdate, keyspaceName, tableName, info); - assertEquals(400, response.getStatus()); - } - - @Test - public void Test5_updateTable_eventual() throws Exception { - JsonUpdate jsonUpdate = new JsonUpdate(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map values = new HashMap<>(); - row.add("emp_name", "testName"); - values.put("emp_salary", 2500); - consistencyInfo.put("type", "eventual"); - jsonUpdate.setConsistencyInfo(consistencyInfo); - jsonUpdate.setKeyspaceName(keyspaceName); - jsonUpdate.setTableName(tableName); - jsonUpdate.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, - authorization, jsonUpdate, keyspaceName, tableName, info); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test5_updateTable_critical() throws Exception { - JsonUpdate jsonUpdate = new JsonUpdate(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map values = new HashMap<>(); - row.add("emp_name", "testName"); - values.put("emp_salary", 2500); - consistencyInfo.put("type", "critical"); - jsonUpdate.setConsistencyInfo(consistencyInfo); - jsonUpdate.setKeyspaceName(keyspaceName); - jsonUpdate.setTableName(tableName); - jsonUpdate.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, - authorization, jsonUpdate, keyspaceName, tableName, info); - assertEquals(400, response.getStatus()); - } - - @Test - public void Test5_updateTable_atomic_delete_lock() throws Exception { - JsonUpdate jsonUpdate = new JsonUpdate(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map values = new HashMap<>(); - row.add("emp_name", "testName"); - values.put("emp_salary", 2500); - consistencyInfo.put("type", "atomic_delete_lock"); - jsonUpdate.setConsistencyInfo(consistencyInfo); - jsonUpdate.setKeyspaceName(keyspaceName); - jsonUpdate.setTableName(tableName); - jsonUpdate.setValues(values); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, - authorization, jsonUpdate, keyspaceName, tableName, info); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test6_select() throws Exception { - JsonSelect jsonSelect = new JsonSelect(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - row.add("emp_name", "testName"); - consistencyInfo.put("type", "atomic"); - jsonSelect.setConsistencyInfo(consistencyInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.select("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6", - appName, authorization, keyspaceName, tableName, info); - HashMap> map = (HashMap>) response.getEntity(); - HashMap result = map.get("result"); - assertEquals("2500", ((HashMap) result.get("row 0")).get("emp_salary").toString()); - } - - @Test - public void Test6_select_withException() throws Exception { - JsonSelect jsonSelect = new JsonSelect(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - row.add("emp_name", "testName"); - consistencyInfo.put("type", "atomic"); - jsonSelect.setConsistencyInfo(consistencyInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - RestMusicDataAPI spyData = Mockito.spy(RestMusicDataAPI.class); - Mockito.doThrow(MusicServiceException.class).when(spyData).selectSpecificQuery("v2", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password, keyspaceName, tableName, info, -1); - Response response = spyData.select("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6", - appName, authorization, keyspaceName, tableName, info); - assertEquals(400, response.getStatus()); - } - - @Test - public void Test6_select_nodata() throws Exception { - JsonSelect jsonSelect = new JsonSelect(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - row.add("emp_name", "testName12"); - consistencyInfo.put("type", "atomic"); - jsonSelect.setConsistencyInfo(consistencyInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.select("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6", - appName, authorization, keyspaceName, tableName, info); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test6_selectCritical() throws Exception { - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - row.add("emp_name", "testName"); - consistencyInfo.put("type", "atomic"); - jsonInsert.setConsistencyInfo(consistencyInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6", - appName, authorization, jsonInsert, keyspaceName, tableName,info); - HashMap> map = (HashMap>) response.getEntity(); - HashMap result = map.get("result"); - assertEquals("2500", ((HashMap) result.get("row 0")).get("emp_salary").toString()); - } - - @Test - public void Test6_selectCritical_without_lockID() throws Exception { - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - row.add("emp_name", "testName"); - consistencyInfo.put("type", "critical"); - jsonInsert.setConsistencyInfo(consistencyInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6", - appName, authorization, jsonInsert, keyspaceName, tableName,info); - assertEquals(400, response.getStatus()); - } - - @Test - public void Test6_selectCritical_with_atomic_delete_lock() throws Exception { - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - row.add("emp_name", "testName"); - consistencyInfo.put("type", "atomic_delete_lock"); - jsonInsert.setConsistencyInfo(consistencyInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6", - appName, authorization, jsonInsert, keyspaceName, tableName,info); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test6_selectCritical_with_nodata() throws Exception { - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - row.add("emp_name", "testName12"); - consistencyInfo.put("type", "atomic_delete_lock"); - jsonInsert.setConsistencyInfo(consistencyInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6", - appName, authorization, jsonInsert, keyspaceName, tableName,info); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test6_select_all() throws Exception { - JsonSelect jsonSelect = new JsonSelect(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl();; - consistencyInfo.put("type", "atomic"); - jsonSelect.setConsistencyInfo(consistencyInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.select("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6", - appName, authorization, keyspaceName, tableName, info); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test6_deleteFromTable() throws Exception { - JsonDelete jsonDelete = new JsonDelete(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - row.add("emp_name", "test1"); - consistencyInfo.put("type", "atomic"); - jsonDelete.setConsistencyInfo(consistencyInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.deleteFromTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonDelete, keyspaceName, tableName, info); - assertEquals(200, response.getStatus()); - } - - // Values - @Test - public void Test6_deleteFromTable1() throws Exception { - JsonDelete jsonDelete = new JsonDelete(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - consistencyInfo.put("type", "atomic"); - jsonDelete.setConsistencyInfo(consistencyInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.deleteFromTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonDelete, keyspaceName, tableName, info); - assertEquals(400, response.getStatus()); - } - - // delObj - @Test - public void Test6_deleteFromTable2() throws Exception { - JsonDelete jsonDelete = new JsonDelete(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - row.add("emp_name", "test1"); - consistencyInfo.put("type", "atomic"); - jsonDelete.setConsistencyInfo(consistencyInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.deleteFromTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - null, keyspaceName, tableName, info); - assertEquals(400, response.getStatus()); - } - - @Test - public void Test6_deleteFromTable_columns() throws Exception { - JsonDelete jsonDelete = new JsonDelete(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - row.add("emp_name", "test1"); - consistencyInfo.put("type", "atomic"); - jsonDelete.setConsistencyInfo(consistencyInfo); - ArrayList columns = new ArrayList<>(); - columns.add("uuid"); - jsonDelete.setColumns(columns); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.deleteFromTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonDelete, keyspaceName, tableName, info); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test6_deleteFromTable_conditions() throws Exception { - JsonDelete jsonDelete = new JsonDelete(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - Map conditions = new HashMap<>(); - conditions.put("emp_name","testName3"); - row.add("emp_name", "test1"); - consistencyInfo.put("type", "atomic"); - jsonDelete.setConsistencyInfo(consistencyInfo); - ArrayList columns = new ArrayList<>(); - jsonDelete.setConditions(conditions); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.deleteFromTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonDelete, keyspaceName, tableName, info); - assertEquals(400, response.getStatus()); - } - - @Test - public void Test6_deleteFromTable_eventual() throws Exception { - JsonDelete jsonDelete = new JsonDelete(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - row.add("emp_name", "test2"); - consistencyInfo.put("type", "eventual"); - jsonDelete.setConsistencyInfo(consistencyInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.deleteFromTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonDelete, keyspaceName, tableName, info); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test6_deleteFromTable_critical() throws Exception { - JsonDelete jsonDelete = new JsonDelete(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - row.add("emp_name", "test2"); - consistencyInfo.put("type", "critical"); - jsonDelete.setConsistencyInfo(consistencyInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.deleteFromTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonDelete, keyspaceName, tableName, info); - assertEquals(400, response.getStatus()); - } - - @Test - public void Test6_deleteFromTable_atomic_delete_lock() throws Exception { - JsonDelete jsonDelete = new JsonDelete(); - Map consistencyInfo = new HashMap<>(); - MultivaluedMap row = new MultivaluedMapImpl(); - row.add("emp_name", "test3"); - consistencyInfo.put("type", "atomic_delete_lock"); - jsonDelete.setConsistencyInfo(consistencyInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Mockito.when(info.getQueryParameters()).thenReturn(row); - Response response = data.deleteFromTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - jsonDelete, keyspaceName, tableName, info); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test7_dropTable() throws Exception { - JsonTable jsonTable = new JsonTable(); - Map consistencyInfo = new HashMap<>(); - consistencyInfo.put("type", "atomic"); - jsonTable.setConsistencyInfo(consistencyInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.dropTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, - keyspaceName, tableName); - assertEquals(200, response.getStatus()); - } - - - @Test - public void Test8_deleteKeyspace() throws Exception { - JsonKeySpace jsonKeyspace = new JsonKeySpace(); - Map consistencyInfo = new HashMap<>(); - Map replicationInfo = new HashMap<>(); - consistencyInfo.put("type", "eventual"); - replicationInfo.put("class", "SimpleStrategy"); - replicationInfo.put("replication_factor", 1); - jsonKeyspace.setConsistencyInfo(consistencyInfo); - jsonKeyspace.setDurabilityOfWrites("true"); - jsonKeyspace.setKeyspaceName("TestApp1"); - jsonKeyspace.setReplicationInfo(replicationInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", - authorization,appName, keyspaceName); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test8_deleteKeyspace1() throws Exception { - JsonKeySpace jsonKeyspace = new JsonKeySpace(); - Map consistencyInfo = new HashMap<>(); - Map replicationInfo = new HashMap<>(); - consistencyInfo.put("type", "eventual"); - replicationInfo.put("class", "SimpleStrategy"); - replicationInfo.put("replication_factor", 1); - jsonKeyspace.setConsistencyInfo(consistencyInfo); - jsonKeyspace.setDurabilityOfWrites("true"); - jsonKeyspace.setKeyspaceName("TestApp1"); - jsonKeyspace.setReplicationInfo(replicationInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", - authorization,appName, "keyspaceName"); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test8_deleteKeyspace2() throws Exception { - JsonKeySpace jsonKeyspace = new JsonKeySpace(); - Map consistencyInfo = new HashMap<>(); - Map replicationInfo = new HashMap<>(); - consistencyInfo.put("type", "eventual"); - replicationInfo.put("class", "SimpleStrategy"); - replicationInfo.put("replication_factor", 1); - jsonKeyspace.setConsistencyInfo(consistencyInfo); - jsonKeyspace.setDurabilityOfWrites("true"); - jsonKeyspace.setKeyspaceName("TestApp1"); - jsonKeyspace.setReplicationInfo(replicationInfo); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", - wrongAuthorization, appName, keyspaceName); - assertEquals(401, response.getStatus()); - } - - @Test - public void Test6_onboard() throws Exception { - JsonOnboard jsonOnboard = new JsonOnboard(); - jsonOnboard.setAppname("TestApp2"); - jsonOnboard.setIsAAF("false"); - jsonOnboard.setUserId("TestUser2"); - jsonOnboard.setPassword("TestPassword2"); - Map resultMap = (Map) admin.onboardAppWithMusic(jsonOnboard).getEntity(); - resultMap.containsKey("success"); - onboardUUID = resultMap.get("Generated AID").toString(); - assertEquals("Your application TestApp2 has been onboarded with MUSIC.", resultMap.get("Success")); - } - - @Test - public void Test6_onboard_duplicate() throws Exception { - JsonOnboard jsonOnboard = new JsonOnboard(); - jsonOnboard.setAppname("TestApp2"); - jsonOnboard.setIsAAF("false"); - jsonOnboard.setUserId("TestUser2"); - jsonOnboard.setPassword("TestPassword2"); - Response response = admin.onboardAppWithMusic(jsonOnboard); - assertEquals(400, response.getStatus()); - } - - // Missing appname - @Test - public void Test6_onboard1() throws Exception { - JsonOnboard jsonOnboard = new JsonOnboard(); - jsonOnboard.setIsAAF("false"); - jsonOnboard.setUserId("TestUser2"); - jsonOnboard.setPassword("TestPassword2"); - Map resultMap = (Map) admin.onboardAppWithMusic(jsonOnboard).getEntity(); - resultMap.containsKey("success"); - System.out.println("--->" + resultMap.toString()); - assertEquals("Unauthorized: Please check the request parameters. Some of the required values appName(ns), userId, password, isAAF are missing.", resultMap.get("Exception")); - } - - - @Test - public void Test7_onboardSearch() throws Exception { - JsonOnboard jsonOnboard = new JsonOnboard(); - jsonOnboard.setAppname("TestApp2"); - jsonOnboard.setIsAAF("false"); - jsonOnboard.setAid(onboardUUID); - Map resultMap = (Map) admin.getOnboardedInfoSearch(jsonOnboard).getEntity(); - resultMap.containsKey("success"); - assertEquals(MusicUtil.DEFAULTKEYSPACENAME, resultMap.get(onboardUUID)); - } - - // Missing appname - @Test - public void Test7_onboardSearch1() throws Exception { - JsonOnboard jsonOnboard = new JsonOnboard(); - jsonOnboard.setIsAAF("false"); - jsonOnboard.setAid(onboardUUID); - Map resultMap = (Map) admin.getOnboardedInfoSearch(jsonOnboard).getEntity(); - System.out.println("--->" + resultMap.toString()); - resultMap.containsKey("success"); - assertEquals(MusicUtil.DEFAULTKEYSPACENAME, resultMap.get(onboardUUID)); - } - - @Test - public void Test7_onboardSearch_empty() throws Exception { - JsonOnboard jsonOnboard = new JsonOnboard(); - Response response = admin.getOnboardedInfoSearch(jsonOnboard); - assertEquals(400, response.getStatus()); - } - - @Test - public void Test7_onboardSearch_invalidAid() throws Exception { - JsonOnboard jsonOnboard = new JsonOnboard(); - jsonOnboard.setAppname("TestApp2"); - jsonOnboard.setIsAAF("false"); - jsonOnboard.setAid("abc66ccc-d857-4e90-b1e5-df98a3d40ce6"); - Response response = admin.getOnboardedInfoSearch(jsonOnboard); - assertEquals(400, response.getStatus()); - } - - @Test - public void Test8_onboardUpdate() throws Exception { - JsonOnboard jsonOnboard = new JsonOnboard(); - jsonOnboard.setIsAAF("false"); - jsonOnboard.setUserId("TestUser3"); - jsonOnboard.setPassword("TestPassword3"); - jsonOnboard.setAid(onboardUUID); - Map resultMap = (Map) admin.updateOnboardApp(jsonOnboard).getEntity(); - System.out.println("--->" + resultMap.toString()); - resultMap.containsKey("success"); - assertEquals("Your application has been updated successfully", resultMap.get("Success")); - } - - // Aid null - @Test - public void Test8_onboardUpdate1() throws Exception { - JsonOnboard jsonOnboard = new JsonOnboard(); - jsonOnboard.setIsAAF("false"); - jsonOnboard.setUserId("TestUser3"); - jsonOnboard.setPassword("TestPassword3"); - Map resultMap = (Map) admin.updateOnboardApp(jsonOnboard).getEntity(); - System.out.println("--->" + resultMap.toString()); - resultMap.containsKey("success"); - assertEquals("Please make sure Aid is present", resultMap.get("Exception")); - } - - // Appname not null - @Test - public void Test8_onboardUpdate2() throws Exception { - JsonOnboard jsonOnboard = new JsonOnboard(); - jsonOnboard.setAppname("TestApp2"); - jsonOnboard.setIsAAF("false"); - jsonOnboard.setUserId("TestUser3"); - jsonOnboard.setPassword("TestPassword3"); - jsonOnboard.setAid(onboardUUID); - Map resultMap = (Map) admin.updateOnboardApp(jsonOnboard).getEntity(); - resultMap.containsKey("success"); - System.out.println("--->" + resultMap.toString()); - assertEquals("Application TestApp2 has already been onboarded. Please contact admin.", resultMap.get("Exception")); - } - - // All null - @Test - public void Test8_onboardUpdate3() throws Exception { - JsonOnboard jsonOnboard = new JsonOnboard(); - jsonOnboard.setAid(onboardUUID); - Map resultMap = (Map) admin.updateOnboardApp(jsonOnboard).getEntity(); - assertTrue(resultMap.containsKey("Exception") ); - } - - @Test - public void Test9_onboardDelete() throws Exception { - JsonOnboard jsonOnboard = new JsonOnboard(); - jsonOnboard.setAppname("TestApp2"); - jsonOnboard.setAid(onboardUUID); - Map resultMap = (Map) admin.deleteOnboardApp(jsonOnboard).getEntity(); - resultMap.containsKey("success"); - assertEquals("Your application has been deleted successfully", resultMap.get("Success")); - } - - @Test - public void Test9_onboardDelete1() throws Exception { - JsonOnboard jsonOnboard = new JsonOnboard(); - Map resultMap = (Map) admin.deleteOnboardApp(jsonOnboard).getEntity(); - assertTrue(resultMap.containsKey("Exception")); - } - - @Test - public void Test3_createLockReference() throws Exception { - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Map resultMap = (Map) lock.createLockReference(lockName,"1","1",authorization, null, appName).getEntity(); - @SuppressWarnings("unchecked") - Map resultMap1 = (Map) resultMap.get("lock"); - lockId = (String) resultMap1.get("lock"); - assertEquals(ResultType.SUCCESS, resultMap.get("status")); - } - - @Test - public void Test4_accquireLock() throws Exception { - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Map resultMap = (Map) lock.accquireLock(lockId,"1","1",authorization, null, appName).getEntity(); - assertEquals(ResultType.SUCCESS, resultMap.get("status")); - } - - @Test - public void Test5_currentLockHolder() throws Exception { - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Map resultMap = (Map) lock.currentLockHolder(lockName,"1","1",authorization, null, appName).getEntity(); - assertEquals(ResultType.SUCCESS, resultMap.get("status")); - } - - @Test - public void Test7_unLock() throws Exception { - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Map resultMap = (Map) lock.unLock(lockId,"1","1",authorization, null, appName).getEntity(); - assertEquals(ResultType.SUCCESS, resultMap.get("status")); - } - - @Test - public void Test8_delete() throws Exception { - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Map resultMap = (Map) lock.deleteLock(lockName,"1","1", null,authorization, appName).getEntity(); - assertEquals(ResultType.SUCCESS, resultMap.get("status")); - } - - // Version api - @Test - public void Test1_version( ) { - RestMusicVersionAPI versionapi = new RestMusicVersionAPI(); - HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class); - Map resultMap = versionapi.version(servletResponse); - assertEquals(ResultType.SUCCESS, resultMap.get("status")); - } - - //Music Test Api - @Test - public void Test2_testAPI() { - RestMusicTestAPI musicTest = new RestMusicTestAPI(); - HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class); - Map> resultMap = musicTest.simpleTests(servletResponse); - assertNotNull(resultMap); - } - - //Music Health Check - @Test - public void Test3_HealthCheck_cassandra() { - String consistency = "ONE"; - RestMusicHealthCheckAPI healthCheck = new RestMusicHealthCheckAPI(); - HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class); - Response response = healthCheck.cassandraStatus(servletResponse, consistency); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test3_HealthCheck_cassandra_cosistencyQuorum() { - String consistency = "QUORUM"; - RestMusicHealthCheckAPI healthCheck = new RestMusicHealthCheckAPI(); - HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class); - Response response = healthCheck.cassandraStatus(servletResponse, consistency); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test3_HealthCheck_zookeeper() { - RestMusicHealthCheckAPI healthCheck = new RestMusicHealthCheckAPI(); - HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class); - Response response = healthCheck.ZKStatus(servletResponse); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test4_pureZKcreate() throws Exception { - RestMusicBmAPI bmApi = new RestMusicBmAPI(); - bmApi.pureZkCreate("sample"); - } - - @Test - public void Test4_pureZKUpdate() throws Exception { - RestMusicBmAPI bmApi = new RestMusicBmAPI(); - bmApi.pureZkCreate("sample1"); - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - Map values = new HashMap<>(); - values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); - values.put("emp_name", "testName_create"); - values.put("emp_salary", 500); - consistencyInfo.put("type", "eventual"); - jsonInsert.setConsistencyInfo(consistencyInfo); - jsonInsert.setKeyspaceName(keyspaceName); - jsonInsert.setTableName(tableName); - jsonInsert.setValues(values); - bmApi.pureZkUpdate(jsonInsert, "sampleNode1"); - } - - @Test - public void Test4_pureZKGet() throws Exception { - RestMusicBmAPI bmApi = new RestMusicBmAPI(); - bmApi.pureZkGet("sample"); - } - - @Test - public void Test5_ZKAtomicPut_atomic() throws Exception { - RestMusicBmAPI bmApi = new RestMusicBmAPI(); - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - Map values = new HashMap<>(); - values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); - values.put("emp_name", "testName_create"); - values.put("emp_salary", 1500); - consistencyInfo.put("type", "atomic"); - jsonInsert.setConsistencyInfo(consistencyInfo); - jsonInsert.setKeyspaceName(keyspaceName); - jsonInsert.setTableName(tableName); - jsonInsert.setValues(values); - bmApi.pureZkAtomicPut(jsonInsert, "lockname", "sampleNode1"); - } - - @Test - public void Test5_ZKAtomicPut_atomic_with_delete() throws Exception { - RestMusicBmAPI bmApi = new RestMusicBmAPI(); - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - Map values = new HashMap<>(); - values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); - values.put("emp_name", "testName_create"); - values.put("emp_salary", 1500); - consistencyInfo.put("type", "atomic_delete_lock"); - jsonInsert.setConsistencyInfo(consistencyInfo); - jsonInsert.setKeyspaceName(keyspaceName); - jsonInsert.setTableName(tableName); - jsonInsert.setValues(values); - bmApi.pureZkAtomicPut(jsonInsert, "lockname", "sampleNode1"); - } - - @Test - public void Test5_ZKAtomicGet_atomic() throws Exception { - RestMusicBmAPI bmApi = new RestMusicBmAPI(); - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - Map values = new HashMap<>(); - values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); - values.put("emp_name", "testName_create"); - values.put("emp_salary", 1500); - consistencyInfo.put("type", "atomic_delete_lock"); - jsonInsert.setConsistencyInfo(consistencyInfo); - jsonInsert.setKeyspaceName(keyspaceName); - jsonInsert.setTableName(tableName); - jsonInsert.setValues(values); - bmApi.pureZkAtomicGet(jsonInsert, "lockname", "sampleNode1"); - } - - @Test - public void Test5_ZKAtomicGet_atomic_with_delete() throws Exception { - RestMusicBmAPI bmApi = new RestMusicBmAPI(); - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - Map values = new HashMap<>(); - values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); - values.put("emp_name", "testName_create"); - values.put("emp_salary", 1500); - consistencyInfo.put("type", "atomic_delete_lock"); - jsonInsert.setConsistencyInfo(consistencyInfo); - jsonInsert.setKeyspaceName(keyspaceName); - jsonInsert.setTableName(tableName); - jsonInsert.setValues(values); - bmApi.pureZkAtomicGet(jsonInsert, "lockname", "sampleNode1"); - } - - @Test - public void Test5_updateCassa() throws Exception { - RestMusicBmAPI bmApi = new RestMusicBmAPI(); - JsonInsert jsonInsert = new JsonInsert(); - Map consistencyInfo = new HashMap<>(); - Map values = new HashMap<>(); - values.put("emp_salary", 1500); - consistencyInfo.put("type", "eventual"); - jsonInsert.setConsistencyInfo(consistencyInfo); - jsonInsert.setKeyspaceName(keyspaceName); - jsonInsert.setTableName(tableName); - jsonInsert.setValues(values); - MultivaluedMap row = new MultivaluedMapImpl(); - row.add("emp_name", "testName_create"); - Mockito.when(info.getQueryParameters()).thenReturn(row); - bmApi.updateTableCassa(jsonInsert, keyspaceName, tableName, info); - } - - // RestMusicConditional - @Test - public void Test5_createTable_conditional() throws Exception { - JsonTable jsonTable = new JsonTable(); - Map consistencyInfo = new HashMap<>(); - Map fields = new HashMap<>(); - fields.put("id", "text"); - fields.put("plans", "Map"); - fields.put("PRIMARY KEY", "(id)"); - consistencyInfo.put("type", "eventual"); - jsonTable.setConsistencyInfo(consistencyInfo); - jsonTable.setKeyspaceName(keyspaceName); - jsonTable.setPrimaryKey("id"); - jsonTable.setTableName(tableNameConditional); - jsonTable.setFields(fields); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = data.createTable("1", "1", "1", - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization, - jsonTable, keyspaceName, tableNameConditional); - System.out.println("#######status is " + response.getStatus()); - System.out.println("Entity" + response.getEntity()); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test6_insertConditional() throws Exception { - RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI(); - JsonConditional json = new JsonConditional(); - json.setPrimaryKey("id"); - json.setPrimaryKeyValue("123|abc|port"); - json.setCasscadeColumnName("plans"); - Map tableValues = new HashMap<>(); - tableValues.put("id", "123|abc|port"); - json.setTableValues(tableValues); - Map columnData = new HashMap<>(); - Map column = new HashMap<>(); - column.put("created", "time"); - columnData.put("key", "P2"); - columnData.put("value", column); - json.setCasscadeColumnData(columnData); - Map cond = new HashMap<>(); - Map cond1 = new HashMap<>(); - Map> conditions = new HashMap>(); - cond.put("status", "under-spin-up"); - cond1.put("status", "parked"); - conditions.put("exists", cond); - conditions.put("nonexists", cond1); - json.setConditions(conditions); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = conditionalApi.insertConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", - appName, authorization, keyspaceName, tableNameConditional, json); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test6_insertConditional_primaryKey_null() throws Exception { - RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI(); - JsonConditional json = new JsonConditional(); - json.setPrimaryKeyValue("123|abc|port"); - json.setCasscadeColumnName("plans"); - Map tableValues = new HashMap<>(); - tableValues.put("id", "123|abc|port"); - json.setTableValues(tableValues); - Map columnData = new HashMap<>(); - Map column = new HashMap<>(); - column.put("created", "time"); - columnData.put("key", "P2"); - columnData.put("value", column); - json.setCasscadeColumnData(columnData); - Map cond = new HashMap<>(); - Map cond1 = new HashMap<>(); - Map> conditions = new HashMap>(); - cond.put("status", "under-spin-up"); - cond1.put("status", "parked"); - conditions.put("exists", cond); - conditions.put("nonexists", cond1); - json.setConditions(conditions); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = conditionalApi.insertConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", - appName, authorization, keyspaceName, tableNameConditional, json); - assertEquals(401, response.getStatus()); - } - - @Test - public void Test6_insertConditional_wrongAuth() throws Exception { - RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI(); - JsonConditional json = new JsonConditional(); - json.setPrimaryKey("id"); - json.setPrimaryKeyValue("123|abc|port"); - json.setCasscadeColumnName("plans"); - Map tableValues = new HashMap<>(); - tableValues.put("id", "123|abc|port"); - json.setTableValues(tableValues); - Map columnData = new HashMap<>(); - Map column = new HashMap<>(); - column.put("created", "time"); - columnData.put("key", "P2"); - columnData.put("value", column); - json.setCasscadeColumnData(columnData); - Map cond = new HashMap<>(); - Map cond1 = new HashMap<>(); - Map> conditions = new HashMap>(); - cond.put("status", "under-spin-up"); - cond1.put("status", "parked"); - conditions.put("exists", cond); - conditions.put("nonexists", cond1); - json.setConditions(conditions); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = conditionalApi.insertConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", - appName, wrongAuthorization, keyspaceName, tableNameConditional, json); - assertEquals(401, response.getStatus()); - } - - @Test - public void Test7_updateConditional() throws Exception { - RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI(); - JsonConditional json = new JsonConditional(); - json.setPrimaryKey("id"); - json.setPrimaryKeyValue("123|abc|port"); - json.setCasscadeColumnName("plans"); - Map tableValues = new HashMap<>(); - tableValues.put("id", "123|abc|port"); - json.setTableValues(tableValues); - Map columnData = new HashMap<>(); - Map column = new HashMap<>(); - column.put("created", "time"); - columnData.put("key", "P2"); - columnData.put("value", column); - json.setCasscadeColumnData(columnData); - Map cond = new HashMap<>(); - Map cond1 = new HashMap<>(); - Map> conditions = new HashMap>(); - cond.put("updated", "new time"); - conditions.put("exists", cond); - conditions.put("nonexists", cond1); - json.setConditions(conditions); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = conditionalApi.updateConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", - appName, authorization, keyspaceName, tableNameConditional, json); - assertEquals(200, response.getStatus()); - } - - @Test - public void Test7_updateConditional_wrongAuth() throws Exception { - RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI(); - JsonConditional json = new JsonConditional(); - json.setPrimaryKey("id"); - json.setPrimaryKeyValue("123|abc|port"); - json.setCasscadeColumnName("plans"); - Map tableValues = new HashMap<>(); - tableValues.put("id", "123|abc|port"); - json.setTableValues(tableValues); - Map columnData = new HashMap<>(); - Map column = new HashMap<>(); - column.put("created", "time"); - columnData.put("key", "P2"); - columnData.put("value", column); - json.setCasscadeColumnData(columnData); - Map cond = new HashMap<>(); - Map cond1 = new HashMap<>(); - Map> conditions = new HashMap>(); - cond.put("updated", "new time"); - conditions.put("exists", cond); - conditions.put("nonexists", cond1); - json.setConditions(conditions); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = conditionalApi.updateConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", - appName, wrongAuthorization, keyspaceName, tableNameConditional, json); - assertEquals(401, response.getStatus()); - } - - @Test - public void Test7_updateConditional_primarykey_null() throws Exception { - RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI(); - JsonConditional json = new JsonConditional(); - json.setPrimaryKeyValue("123|abc|port"); - json.setCasscadeColumnName("plans"); - Map tableValues = new HashMap<>(); - tableValues.put("id", "123|abc|port"); - json.setTableValues(tableValues); - Map columnData = new HashMap<>(); - Map column = new HashMap<>(); - column.put("created", "time"); - columnData.put("key", "P2"); - columnData.put("value", column); - json.setCasscadeColumnData(columnData); - Map cond = new HashMap<>(); - Map cond1 = new HashMap<>(); - Map> conditions = new HashMap>(); - cond.put("updated", "new time"); - conditions.put("exists", cond); - conditions.put("nonexists", cond1); - json.setConditions(conditions); - Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); - Response response = conditionalApi.updateConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", - appName, authorization, keyspaceName, tableNameConditional, json); - assertEquals(401, response.getStatus()); - } -} \ No newline at end of file diff --git a/version.properties b/version.properties index 023460f3..be1ffe50 100644 --- a/version.properties +++ b/version.properties @@ -4,7 +4,7 @@ major=3 minor=0 -patch=5 +patch=13 base_version=${major}.${minor}.${patch} -- cgit 1.2.3-korg