aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rwxr-xr-xpom.xml51
-rwxr-xr-xsrc/main/java/org/onap/music/JerseyConfig.java97
-rwxr-xr-xsrc/main/java/org/onap/music/authentication/CachingUtil.java (renamed from src/main/java/org/onap/music/main/CachingUtil.java)56
-rw-r--r--src/main/java/org/onap/music/authentication/MusicAuthentication.java131
-rw-r--r--src/main/java/org/onap/music/authentication/MusicAuthenticator.java58
-rw-r--r--src/main/java/org/onap/music/conductor/conditionals/MusicConditional.java5
-rw-r--r--src/main/java/org/onap/music/conductor/conditionals/RestMusicConditionalAPI.java4
-rwxr-xr-xsrc/main/java/org/onap/music/datastore/MusicDataStore.java11
-rw-r--r--src/main/java/org/onap/music/datastore/MusicDataStoreHandle.java11
-rw-r--r--src/main/java/org/onap/music/datastore/jsonobjects/JsonDelete.java10
-rw-r--r--src/main/java/org/onap/music/datastore/jsonobjects/JsonTable.java10
-rw-r--r--src/main/java/org/onap/music/eelf/healthcheck/MusicHealthCheck.java29
-rw-r--r--src/main/java/org/onap/music/lockingservice/zookeeper/MusicLockingService.java2
-rw-r--r--src/main/java/org/onap/music/lockingservice/zookeeper/ZkStatelessLockService.java38
-rw-r--r--src/main/java/org/onap/music/main/CronJobManager.java24
-rwxr-xr-xsrc/main/java/org/onap/music/main/MusicUtil.java59
-rwxr-xr-xsrc/main/java/org/onap/music/rest/RestMusicAdminAPI.java125
-rw-r--r--src/main/java/org/onap/music/rest/RestMusicBmAPI.java319
-rwxr-xr-xsrc/main/java/org/onap/music/rest/RestMusicDataAPI.java402
-rwxr-xr-xsrc/main/java/org/onap/music/rest/RestMusicQAPI.java3
-rw-r--r--src/main/java/org/onap/music/service/impl/MusicCassaCore.java223
-rw-r--r--src/main/java/org/onap/music/service/impl/MusicZKCore.java95
-rw-r--r--src/main/resources/logback.xml2
-rw-r--r--src/test/java/org/onap/music/unittests/CassandraCQL.java62
-rw-r--r--src/test/java/org/onap/music/unittests/MusicDataStoreTest.java2
-rw-r--r--src/test/java/org/onap/music/unittests/TestLockStore.java54
-rw-r--r--src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java18
-rw-r--r--src/test/java/org/onap/music/unittests/TestRestAdminData.java2571
-rw-r--r--src/test/java/org/onap/music/unittests/TestRestMusicData.java1186
-rw-r--r--src/test/java/org/onap/music/unittests/TestsUsingCassandra.java113
-rw-r--r--src/test/java/org/onap/music/unittests/TstCachingUtil.java141
-rw-r--r--src/test/java/org/onap/music/unittests/TstRestMusicAdminAPI.java327
-rw-r--r--src/test/java/org/onap/music/unittests/TstRestMusicConditionalAPI.java376
-rw-r--r--src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java1045
-rw-r--r--src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java311
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java15
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java7
38 files changed, 3097 insertions, 4898 deletions
diff --git a/README.md b/README.md
index 3f83f2da..9d5c4cd1 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
## MUSIC - Multi-site State Coordination Service
-To achieve 5 9s of availability on 3 9s or lower software and infrastructure in a cost-effective manner, ONAP components need to work in a reliable, active-active manner across multiple sites (platform-maturity resiliency level 3). A fundamental aspect of this is state management across geo-distributed sites in a reliable, scalable, highly available and efficient manner. This is an important and challenging problem because of three fundamental reasons:
+To truly achieve 5 9s of availability on 3 9s or lower software and infrastructure in a cost-effective manner, ONAP components need to work in a reliable, active-active manner across multiple sites (platform-maturity resiliency level 3). A fundamental aspect of this is state management across geo-distributed sites in a reliable, scalable, highly available and efficient manner. This is an important and challenging problem because of three fundamental reasons:
* Current solutions for state-management of ONAP components like MariaDB clustering, that work very effectively within a site, may not scale across geo-distributed sites (e.g., Beijing, Amsterdam and Irvine) or allow partitioned operation (thereby compromising availability). This is mainly because WAN latencies are much higher across sites and frequent network partitions can occur.
diff --git a/pom.xml b/pom.xml
index f0b41c47..a623853c 100755
--- a/pom.xml
+++ b/pom.xml
@@ -306,15 +306,20 @@
<groupId>com.att.eelf</groupId>
<artifactId>eelf-core</artifactId>
<version>1.0.1-oss</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<!-- End Logging -->
<!-- Cassandra -->
<dependency>
- <groupId>com.codahale.metrics</groupId>
- <artifactId>metrics-core</artifactId>
- <version>3.0.2</version>
- </dependency>
- <dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
<version>4.1.0-rc3</version>
@@ -416,13 +421,26 @@
<version>3.5.0.1</version>
<scope>test</scope>
<exclusions>
- <exclusion>
-
- <groupId>org.cassandraunit</groupId>
-
- <artifactId>cassandra-unit</artifactId>
-
- </exclusion>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.cassandraunit</groupId>
+ <artifactId>cassandra-unit</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>io.dropwizard.metrics</groupId>
+ <artifactId>metrics-core</artifactId>
+ </exclusion>
</exclusions>
</dependency>
<dependency>
@@ -432,6 +450,11 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>io.dropwizard.metrics</groupId>
+ <artifactId>metrics-core</artifactId>
+ <version>3.1.0</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
<version>2.3.0</version>
@@ -449,8 +472,8 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
- <artifactId>mockito-all</artifactId>
- <version>1.9.0</version>
+ <artifactId>mockito-core</artifactId>
+ <version>2.23.4</version>
<scope>test</scope>
</dependency>
<!-- /Testing -->
diff --git a/src/main/java/org/onap/music/JerseyConfig.java b/src/main/java/org/onap/music/JerseyConfig.java
index 74958363..1b5f034a 100755
--- a/src/main/java/org/onap/music/JerseyConfig.java
+++ b/src/main/java/org/onap/music/JerseyConfig.java
@@ -1,64 +1,55 @@
-/*
- * Copyright 2012-2015 the original author or authors.
- *
- * 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.
- */
-
-package org.onap.music;
-
-import javax.annotation.PostConstruct;
-import javax.ws.rs.ApplicationPath;
-import org.glassfish.jersey.server.ResourceConfig;
-import org.onap.music.rest.RestMusicAdminAPI;
-import org.onap.music.rest.RestMusicDataAPI;
-import org.onap.music.rest.RestMusicHealthCheckAPI;
-import org.onap.music.rest.RestMusicLocksAPI;
-import org.onap.music.rest.RestMusicQAPI;
-import org.onap.music.rest.RestMusicTestAPI;
-import org.onap.music.rest.RestMusicVersionAPI;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Component;
+/*
+ * Copyright 2012-2015 the original author or authors.
+ *
+ * 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.
+ */
+
+package org.onap.music;
+
import io.swagger.jaxrs.config.BeanConfig;
import io.swagger.jaxrs.listing.ApiListingResource;
-import io.swagger.jaxrs.listing.SwaggerSerializers;
-
-@Component
-public class JerseyConfig extends ResourceConfig {
-
- @Value("${spring.jersey.application-path:/}")
- private String apiPath;
-
- public JerseyConfig() {
+import io.swagger.jaxrs.listing.SwaggerSerializers;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.onap.music.rest.*;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+
+@Component public class JerseyConfig extends ResourceConfig {
+
+ @Value("${spring.jersey.application-path:/}") private String apiPath;
+
+ public JerseyConfig() {
this.registerEndpoints();
- }
-
- @PostConstruct
- public void init() {
+ }
+
+ @PostConstruct public void init() {
this.configureSwagger();
}
-
+
private void registerEndpoints() {
- register(RestMusicAdminAPI.class);
- register(RestMusicDataAPI.class);
- register(RestMusicLocksAPI.class);
- register(RestMusicQAPI.class);
- register(RestMusicTestAPI.class);
+ register(RestMusicAdminAPI.class);
+ register(RestMusicDataAPI.class);
+ register(RestMusicLocksAPI.class);
+ register(RestMusicQAPI.class);
+ register(RestMusicTestAPI.class);
register(RestMusicVersionAPI.class);
register(RestMusicHealthCheckAPI.class);
}
-
+
private void configureSwagger() {
- // Available at localhost:port/swagger.json
+ //Available at localhost:port/swagger.json
this.register(ApiListingResource.class);
this.register(SwaggerSerializers.class);
@@ -67,11 +58,11 @@ public class JerseyConfig extends ResourceConfig {
config.setTitle("MUSIC");
config.setVersion("v2");
config.setContact("Thomas Nelson");
- config.setSchemes(new String[] { "http", "https" });
+ config.setSchemes(new String[] {"http", "https"});
config.setBasePath("/MUSIC/rest");
config.setResourcePackage("org.onap.music");
config.setPrettyPrint(true);
config.setScan(true);
}
-
+
}
diff --git a/src/main/java/org/onap/music/main/CachingUtil.java b/src/main/java/org/onap/music/authentication/CachingUtil.java
index 9c975191..534038e3 100755
--- a/src/main/java/org/onap/music/main/CachingUtil.java
+++ b/src/main/java/org/onap/music/authentication/CachingUtil.java
@@ -5,6 +5,7 @@
* Copyright (c) 2017 AT&T Intellectual Property
* ===================================================================
* Modifications Copyright (c) 2018 IBM
+ * Modifications Copyright (c) 2019 Samsung
* ===================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,33 +23,28 @@
* ====================================================================
*/
-package org.onap.music.main;
+package org.onap.music.authentication;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.UUID;
-
import javax.ws.rs.core.MediaType;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.jcs.JCS;
import org.apache.commons.jcs.access.CacheAccess;
-import org.apache.commons.jcs.engine.CompositeCacheAttributes;
-import org.apache.commons.jcs.engine.ElementAttributes;
-import org.apache.commons.jcs.engine.behavior.ICompositeCacheAttributes;
-import org.apache.commons.jcs.engine.behavior.IElementAttributes;
import org.mindrot.jbcrypt.BCrypt;
+import org.onap.music.authentication.MusicAuthenticator.Operation;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
import org.onap.music.eelf.logging.format.AppMessages;
import org.onap.music.eelf.logging.format.ErrorSeverity;
import org.onap.music.eelf.logging.format.ErrorTypes;
import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.service.impl.MusicZKCore;
-
+import org.onap.music.main.MusicCore;
+import org.onap.music.main.MusicUtil;
import com.datastax.driver.core.DataType;
import com.datastax.driver.core.PreparedStatement;
import com.datastax.driver.core.ResultSet;
@@ -133,7 +129,6 @@ public class CachingUtil implements Runnable {
pQuery.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), false));
} catch (Exception e1) {
logger.error(EELFLoggerDelegate.errorLogger, e1.getMessage(),AppMessages.CACHEERROR, ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
- e1.printStackTrace();
}
ResultSet rs = MusicCore.get(pQuery);
Iterator<Row> it = rs.iterator();
@@ -158,7 +153,6 @@ public class CachingUtil implements Runnable {
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.INFO, ErrorTypes.GENERALSERVICEERROR);
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),"Something at AAF was changed for ns: " + nameSpace+" So not updating Cache for the namespace. ");
- e.printStackTrace();
}
}
@@ -317,7 +311,6 @@ public class CachingUtil implements Runnable {
appNameCache.put(namespace, isAAF);
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), AppMessages.QUERYERROR,ErrorSeverity.ERROR, ErrorTypes.QUERYERROR);
- e.printStackTrace();
}
}
return isAAF;
@@ -334,8 +327,7 @@ public class CachingUtil implements Runnable {
try {
uuid = rs.getUUID("uuid").toString();
} catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,"Exception occured during uuid retrieval from DB."+e.getMessage());
- e.printStackTrace();
+ logger.error(EELFLoggerDelegate.errorLogger,"Exception occurred during uuid retrieval from DB."+e.getMessage());
}
}
return uuid;
@@ -352,17 +344,11 @@ public class CachingUtil implements Runnable {
appName = rs.getString("application_name");
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), AppMessages.QUERYERROR, ErrorSeverity.ERROR, ErrorTypes.QUERYERROR);
- e.printStackTrace();
}
return appName;
}
- public static String generateUUID() {
- String uuid = UUID.randomUUID().toString();
- logger.info(EELFLoggerDelegate.applicationLogger,"New AID generated: "+uuid);
- return uuid;
- }
-
+ @Deprecated
public static Map<String, Object> validateRequest(String nameSpace, String userId,
String password, String keyspace, String aid, String operation) {
Map<String, Object> resultMap = new HashMap<>();
@@ -372,9 +358,19 @@ public class CachingUtil implements Runnable {
}
}
return resultMap;
-
}
+ public static Map<String, Object> validateRequest(String nameSpace, String userId,
+ String password, String keyspace, String aid, Operation operation) {
+ Map<String, Object> resultMap = new HashMap<>();
+ if (Operation.CREATE_KEYSPACE!=operation) {
+ if (nameSpace == null) {
+ resultMap.put("Exception", "Application namespace is mandatory.");
+ }
+ }
+ return resultMap;
+ }
+
public static Map<String, Object> verifyOnboarding(String ns, String userId, String password) {
Map<String, Object> resultMap = new HashMap<>();
if (ns == null || userId == null || password == null) {
@@ -398,9 +394,9 @@ public class CachingUtil implements Runnable {
try {
rs = MusicCore.get(queryObject).one();
} catch (MusicServiceException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- resultMap.put("Exception", "Unable to process operation. Error is "+e.getMessage());
+ String errorMsg = "Unable to process operation. Error is "+e.getMessage();
+ logger.error(EELFLoggerDelegate.errorLogger, errorMsg);
+ resultMap.put("Exception", errorMsg);
return resultMap;
} catch (InvalidQueryException e) {
logger.error(EELFLoggerDelegate.errorLogger,"Exception admin keyspace not configured."+e.getMessage());
@@ -443,14 +439,15 @@ public class CachingUtil implements Runnable {
try {
queryObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), keyspace));
} catch (Exception e) {
- e.printStackTrace();
+ logger.error(EELFLoggerDelegate.errorLogger,"Adding value to query object failed: " + e.getMessage());
}
Row rs = null;
try {
rs = MusicCore.get(queryObject).one();
} catch (MusicServiceException e) {
- e.printStackTrace();
- resultMap.put("Exception", "Unable to process operation. Error is "+e.getMessage());
+ String errMsg = "Unable to process operation. Error is "+e.getMessage();
+ logger.error(EELFLoggerDelegate.errorLogger, errMsg);
+ resultMap.put("Exception", errMsg);
return resultMap;
}
if(rs == null) {
@@ -486,7 +483,8 @@ public class CachingUtil implements Runnable {
try {
MusicCore.nonKeyRelatedPut(pQuery, "eventual");
} catch (Exception e) {
- e.printStackTrace();
+ logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), "Deleting keys from "
+ + "DB failed.");
}
}
}
diff --git a/src/main/java/org/onap/music/authentication/MusicAuthentication.java b/src/main/java/org/onap/music/authentication/MusicAuthentication.java
index 1d845b3c..10f1e30c 100644
--- a/src/main/java/org/onap/music/authentication/MusicAuthentication.java
+++ b/src/main/java/org/onap/music/authentication/MusicAuthentication.java
@@ -34,7 +34,7 @@ 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.main.CachingUtil;
+import org.onap.music.authentication.MusicAuthenticator.Operation;
import org.onap.music.main.MusicCore;
import org.onap.music.main.MusicUtil;
@@ -44,7 +44,7 @@ import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
-public class MusicAuthentication {
+public class MusicAuthentication implements MusicAuthenticator {
private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicAuthentication.class);
@@ -60,6 +60,7 @@ public class MusicAuthentication {
* @return
* @throws Exception
*/
+ @Deprecated
public static Map<String, Object> autheticateUser(String nameSpace, String userId,
String password, String keyspace, String aid, String operation)
throws Exception {
@@ -142,7 +143,7 @@ public class MusicAuthentication {
resultMap.put("uuid", "existing");
} catch (Exception e) {
logger.error(EELFLoggerDelegate.applicationLogger,"No UUID found in DB. So creating new UUID.");
- uuid = CachingUtil.generateUUID();
+ uuid = MusicUtil.generateUUID();
resultMap.put("uuid", "new");
}
resultMap.put("aid", uuid);
@@ -152,21 +153,9 @@ public class MusicAuthentication {
return resultMap;
}
-
- public static boolean authenticateAdmin(String id,String password) {
- return (id.equals(MusicUtil.getAdminId()) && password.equals(MusicUtil.getAdminPass()));
- }
-
- public static boolean authenticateAdmin(Map<String,String> adminCredentials) {
- if(adminCredentials.containsKey("ERROR"))
- return false;
- String admin_id = adminCredentials.get(MusicUtil.USERID);
- String admin_password = adminCredentials.get(MusicUtil.PASSWORD);
- return (admin_id.equals(MusicUtil.getAdminId()) && admin_password.equals(MusicUtil.getAdminPass()));
- }
-
- public static boolean authenticateAdmin(String authorization) throws Exception {
- logger.info(EELFLoggerDelegate.applicationLogger, "MusicCore.authenticateAdmin: "+authorization);
+ @Override
+ public boolean authenticateAdmin(String authorization) {
+ logger.info(EELFLoggerDelegate.applicationLogger, "MusicCore.authenticateAdmin: ");
String userId = MusicUtil.extractBasicAuthentication(authorization).get(MusicUtil.USERID);
if(MusicUtil.getIsCadi()) {
CachingUtil.updateAdminUserCache(authorization, userId);
@@ -174,18 +163,23 @@ public class MusicAuthentication {
}
CacheAccess<String, String> adminCache = CachingUtil.getAdminUserCache();
if (authorization == null) {
- logger.error(EELFLoggerDelegate.errorLogger, "Authorization cannot be empty..."+authorization);
- throw new Exception("Authorization cannot be empty");
+ logger.error(EELFLoggerDelegate.errorLogger, "Authorization cannot be empty...");
+ return false;
}
if (adminCache.get(authorization) != null && adminCache.get(authorization).equals(userId)) {
- logger.info(EELFLoggerDelegate.applicationLogger, "MusicCore.authenticateAdmin: Validated against admincache.. "+authorization);
+ logger.info(EELFLoggerDelegate.applicationLogger, "MusicCore.authenticateAdmin: Validated against admincache.. ");
return true;
}
else {
Client client = Client.create();
+ String aafUrl = MusicUtil.getAafAdminUrl();
+ if (aafUrl==null) {
+ logger.error(EELFLoggerDelegate.errorLogger, "Admin url is not set, please set in properties");
+ return false;
+ }
+
WebResource webResource = client.resource(
MusicUtil.getAafAdminUrl().concat(userId).concat("/").concat(MusicUtil.getAdminAafRole()));
- ;
ClientResponse response = webResource.accept(MediaType.APPLICATION_JSON)
.header("Authorization", authorization).get(ClientResponse.class);
@@ -195,7 +189,100 @@ public class MusicAuthentication {
}
}
return false;
+ }
+
+ @Override
+ public boolean authenticateUser(String namespace, String authorization, String keyspace,
+ String aid, Operation operation) {
+ logger.info(EELFLoggerDelegate.applicationLogger,"Inside User Authentication.......");
+ Map<String,String> userCredentials = MusicUtil.extractBasicAuthentication(authorization);
+ String userId = userCredentials.get(MusicUtil.USERID);
+ String password = userCredentials.get(MusicUtil.PASSWORD);
+ Map<String, Object> resultMap = new HashMap<>();
+ String uuid = null;
+ if(! MusicUtil.getIsCadi()) {
+ resultMap = CachingUtil.validateRequest(namespace, userId, password, keyspace, aid,
+ operation);
+ if (!resultMap.isEmpty())
+ return false;
+ String isAAFApp = null;
+ try {
+ isAAFApp= CachingUtil.isAAFApplication(namespace);
+ } catch(MusicServiceException e) {
+ logger.error(e.getErrorMessage(), e);
+ resultMap.put("Exception", e.getMessage());
+ return false;
+ }
+ if(isAAFApp == null) {
+ resultMap.put("Exception", "Namespace: "+namespace+" doesn't exist. Please make sure ns(appName)"
+ + " is correct and Application is onboarded.");
+ return false;
+ }
+ boolean isAAF = Boolean.parseBoolean(isAAFApp);
+ if (userId == null || password == null) {
+ logger.error(EELFLoggerDelegate.errorLogger,"", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ logger.error(EELFLoggerDelegate.errorLogger,"UserId/Password or more required headers is missing.");
+ resultMap.put("Exception",
+ "UserId and Password are mandatory for the operation " + operation);
+ return false;
+ }
+ if(!isAAF && !(operation==Operation.CREATE_KEYSPACE)) {
+ resultMap = CachingUtil.authenticateAIDUser(namespace, userId, password, keyspace);
+ if (!resultMap.isEmpty())
+ return false;
+
+ }
+ if (isAAF && namespace != null && userId != null && password != null) {
+ boolean isValid = true;
+ try {
+ isValid = CachingUtil.authenticateAAFUser(namespace, userId, password, keyspace);
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger,"Error while aaf authentication for user:" + userId);
+ logger.error(EELFLoggerDelegate.errorLogger,"Error: "+ e.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.AUTHENTICATIONERROR ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ logger.error(EELFLoggerDelegate.errorLogger,"Got exception while AAF authentication for namespace " + namespace);
+ resultMap.put("Exception", e.getMessage());
+ }
+ if (!isValid) {
+ logger.error(EELFLoggerDelegate.errorLogger,"User not authenticated...", AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
+ resultMap.put("Exception", "User not authenticated...");
+ }
+ if (!resultMap.isEmpty())
+ return false;
+
+ }
+ } else {
+
+ String cachedKS = CachingUtil.getKSFromCadiCache(userId);
+ if(cachedKS != null && !cachedKS.equals(keyspace)) {
+ resultMap.put("Exception", "User not authenticated to access this keyspace...");
+ return false;
+ }
+ }
+
+ if (operation==Operation.CREATE_KEYSPACE) {
+ try {
+ logger.info(EELFLoggerDelegate.applicationLogger,"AID is not provided. Creating new UUID for keyspace.");
+ PreparedQueryObject pQuery = new PreparedQueryObject();
+ pQuery.appendQueryString(
+ "select uuid from admin.keyspace_master where application_name=? and username=? and keyspace_name=? allow filtering");
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), namespace));
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(),
+ MusicUtil.DEFAULTKEYSPACENAME));
+ Row rs = MusicCore.get(pQuery).one();
+ uuid = rs.getUUID("uuid").toString();
+ resultMap.put("uuid", "existing");
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.applicationLogger,"No UUID found in DB. So creating new UUID.");
+ uuid = MusicUtil.generateUUID();
+ resultMap.put("uuid", "new");
+ }
+ resultMap.put("aid", uuid);
+ CachingUtil.updateCadiCache(userId, keyspace);
+ }
+ return true;
}
}
diff --git a/src/main/java/org/onap/music/authentication/MusicAuthenticator.java b/src/main/java/org/onap/music/authentication/MusicAuthenticator.java
new file mode 100644
index 00000000..0b1fd5c8
--- /dev/null
+++ b/src/main/java/org/onap/music/authentication/MusicAuthenticator.java
@@ -0,0 +1,58 @@
+/*
+ * ============LICENSE_START==========================================
+ * org.onap.music
+ * ===================================================================
+ * Copyright (c) 2019 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.authentication;
+
+public interface MusicAuthenticator {
+ public enum Operation{
+ CREATE_KEYSPACE,
+ DROP_KEYSPACE,
+ CREATE_TABLE,
+ CREATE_INDEX,
+ INSERT_INTO_TABLE,
+ UPDATE_TABLE,
+ DELETE_FROM_TABLE,
+ DROP_TABLE,
+ SELECT_CRITICAL,
+ SELECT
+ }
+
+ /**
+ * Authenticate a user account
+ * @param namespace - user's namespace
+ * @param authorization - basicAuth representation of username/password
+ * @param keyspace - keyspace user is trying to access
+ * @param aid - aid that identifies the user
+ * @param operation - operation that user is trying to do
+ * @return true if user has access
+ */
+ public boolean authenticateUser(String namespace, String authorization,
+ String keyspace, String aid, Operation operation);
+
+ /**
+ * Authenticate an administrative account
+ * @param authorization - basicAuth representation of username/password
+ * @return true if user has admin privileges
+ */
+ public boolean authenticateAdmin(String authorization);
+
+}
diff --git a/src/main/java/org/onap/music/conductor/conditionals/MusicConditional.java b/src/main/java/org/onap/music/conductor/conditionals/MusicConditional.java
index ff77bfde..045abd98 100644
--- a/src/main/java/org/onap/music/conductor/conditionals/MusicConditional.java
+++ b/src/main/java/org/onap/music/conductor/conditionals/MusicConditional.java
@@ -254,6 +254,7 @@ public class MusicConditional {
StringBuilder fieldsString = new StringBuilder("(vector_ts"+",");
StringBuilder valueString = new StringBuilder("(" + "?" + ",");
String vector = String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis());
+ String localPrimaryKey;
queryObject.addValue(vector);
if(casscadeColumn!=null && casscadeColumnValues!=null) {
fieldsString.append(casscadeColumn).append(" ,");
@@ -267,8 +268,8 @@ public class MusicConditional {
fieldsString.append(entry.getKey());
Object valueObj = entry.getValue();
if (primaryKeyName.equals(entry.getKey())) {
- primaryKey = entry.getValue() + "";
- primaryKey = primaryKey.replace("'", "''");
+ localPrimaryKey = entry.getValue() + "";
+ localPrimaryKey = localPrimaryKey.replace("'", "''");
}
DataType colType = null;
try {
diff --git a/src/main/java/org/onap/music/conductor/conditionals/RestMusicConditionalAPI.java b/src/main/java/org/onap/music/conductor/conditionals/RestMusicConditionalAPI.java
index 2a267387..c523d5f4 100644
--- a/src/main/java/org/onap/music/conductor/conditionals/RestMusicConditionalAPI.java
+++ b/src/main/java/org/onap/music/conductor/conditionals/RestMusicConditionalAPI.java
@@ -82,8 +82,8 @@ public class RestMusicConditionalAPI {
@ApiParam(value = "AID", required = true) @HeaderParam("aid") String aid,
@ApiParam(value = "Application namespace", required = true) @HeaderParam(NS) String ns,
@ApiParam(value = "Authorization", required = true) @HeaderParam("Authorization") String authorization,
- @ApiParam(value = "Major Version", required = true) @PathParam("keyspace") String keyspace,
- @ApiParam(value = "Major Version", required = true) @PathParam("tablename") String tablename,
+ @ApiParam(value = "Keyspace Name", required = true) @PathParam("keyspace") String keyspace,
+ @ApiParam(value = "Table Name", required = true) @PathParam("tablename") String tablename,
JsonConditional jsonObj) throws Exception {
ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
String primaryKey = jsonObj.getPrimaryKey();
diff --git a/src/main/java/org/onap/music/datastore/MusicDataStore.java b/src/main/java/org/onap/music/datastore/MusicDataStore.java
index bb8e537e..f58bd831 100755
--- a/src/main/java/org/onap/music/datastore/MusicDataStore.java
+++ b/src/main/java/org/onap/music/datastore/MusicDataStore.java
@@ -4,7 +4,7 @@
* ===================================================================
* Copyright (c) 2017 AT&T Intellectual Property
* ===================================================================
- * Modifications Copyright (c) 2018 IBM
+ * Modifications Copyright (c) 2018-2019 IBM
* ===================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,13 +35,13 @@ import java.util.Iterator;
import java.util.Map;
import org.apache.commons.jcs.access.CacheAccess;
+import org.onap.music.authentication.CachingUtil;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
import org.onap.music.eelf.logging.format.AppMessages;
import org.onap.music.eelf.logging.format.ErrorSeverity;
import org.onap.music.eelf.logging.format.ErrorTypes;
import org.onap.music.exceptions.MusicQueryException;
import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.main.CachingUtil;
import org.onap.music.main.MusicUtil;
import com.codahale.metrics.JmxReporter;
@@ -127,7 +127,6 @@ public class MusicDataStore {
try {
connectToCassaCluster(remoteIp);
} catch (MusicServiceException e) {
- logger.error("Exception", e);
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage());
}
}
@@ -149,10 +148,8 @@ public class MusicDataStore {
}
}
} catch (SocketException e) {
- logger.error("Exception", e);
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), AppMessages.CONNCECTIVITYERROR, ErrorSeverity.ERROR, ErrorTypes.CONNECTIONERROR);
}catch(Exception e) {
- logger.error("Exception", e);
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(), ErrorSeverity.ERROR, ErrorTypes.GENERALSERVICEERROR);
}
return allPossibleIps;
@@ -200,7 +197,6 @@ public class MusicDataStore {
break;
} catch (NoHostAvailableException e) {
- logger.error("Exception", e);
address = it.next();
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.HOSTUNAVAILABLE, ErrorSeverity.ERROR, ErrorTypes.CONNECTIONERROR);
}
@@ -257,7 +253,6 @@ public class MusicDataStore {
try {
session = cluster.connect();
} catch (Exception ex) {
- logger.error("Exception", ex);
logger.error(EELFLoggerDelegate.errorLogger, ex.getMessage(),AppMessages.CASSANDRACONNECTIVITY, ErrorSeverity.ERROR, ErrorTypes.SERVICEUNAVAILABLE);
throw new MusicServiceException(
"Error while connecting to Cassandra cluster.. " + ex.getMessage());
@@ -451,12 +446,10 @@ public class MusicDataStore {
}
catch (AlreadyExistsException ae) {
- logger.error("Exception", ae);
logger.error(EELFLoggerDelegate.errorLogger, ae.getMessage(),AppMessages.SESSIONFAILED+ " [" + queryObject.getQuery() + "]", ErrorSeverity.ERROR, ErrorTypes.QUERYERROR);
throw new MusicServiceException(ae.getMessage());
}
catch (Exception e) {
- logger.error("Exception", e);
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.SESSIONFAILED+ " [" + queryObject.getQuery() + "]", ErrorSeverity.ERROR, ErrorTypes.QUERYERROR);
throw new MusicQueryException("Executing Session Failure for Request = " + "["
+ queryObject.getQuery() + "]" + " Reason = " + e.getMessage());
diff --git a/src/main/java/org/onap/music/datastore/MusicDataStoreHandle.java b/src/main/java/org/onap/music/datastore/MusicDataStoreHandle.java
index bb8f3cbd..194fdad1 100644
--- a/src/main/java/org/onap/music/datastore/MusicDataStoreHandle.java
+++ b/src/main/java/org/onap/music/datastore/MusicDataStoreHandle.java
@@ -4,6 +4,8 @@
* ===================================================================
* Copyright (c) 2017 AT&T Intellectual Property
* ===================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ===================================================================
* 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
@@ -28,15 +30,16 @@ import java.util.Map;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
import org.onap.music.exceptions.MusicServiceException;
import org.onap.music.main.MusicUtil;
-import org.onap.music.service.impl.MusicZKCore;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.TableMetadata;
public class MusicDataStoreHandle {
-
-
-
+
+ private MusicDataStoreHandle(){
+ throw new IllegalStateException("Utility class");
+ }
+
public static MusicDataStore mDstoreHandle = null;
private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicDataStoreHandle.class);
diff --git a/src/main/java/org/onap/music/datastore/jsonobjects/JsonDelete.java b/src/main/java/org/onap/music/datastore/jsonobjects/JsonDelete.java
index c90dd005..b98a391d 100644
--- a/src/main/java/org/onap/music/datastore/jsonobjects/JsonDelete.java
+++ b/src/main/java/org/onap/music/datastore/jsonobjects/JsonDelete.java
@@ -4,6 +4,8 @@
* ===================================================================
* Copyright (c) 2017 AT&T Intellectual Property
* ===================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ===================================================================
* 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
@@ -22,7 +24,7 @@
package org.onap.music.datastore.jsonobjects;
-import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@@ -34,7 +36,7 @@ import io.swagger.annotations.ApiModelProperty;
@JsonIgnoreProperties(ignoreUnknown = true)
public class JsonDelete {
- private ArrayList<String> columns = null;
+ private List<String> columns = null;
private Map<String, String> consistencyInfo;
private Map<String, Object> conditions;
String ttl, timestamp;
@@ -59,11 +61,11 @@ public class JsonDelete {
}
@ApiModelProperty(value = "Column values")
- public ArrayList<String> getColumns() {
+ public List<String> getColumns() {
return columns;
}
- public void setColumns(ArrayList<String> columns) {
+ public void setColumns(List<String> columns) {
this.columns = columns;
}
diff --git a/src/main/java/org/onap/music/datastore/jsonobjects/JsonTable.java b/src/main/java/org/onap/music/datastore/jsonobjects/JsonTable.java
index cf691590..badcaebe 100644
--- a/src/main/java/org/onap/music/datastore/jsonobjects/JsonTable.java
+++ b/src/main/java/org/onap/music/datastore/jsonobjects/JsonTable.java
@@ -38,7 +38,6 @@ public class JsonTable {
private Map<String, String> fields;
private Map<String, Object> properties;
private String primaryKey;
- private String sortingKey;
private String partitionKey;
private String clusteringKey;
private String filteringKey;
@@ -90,15 +89,6 @@ public class JsonTable {
this.tableName = tableName;
}
- @ApiModelProperty(value = "Sorting Key")
- public String getSortingKey() {
- return sortingKey;
- }
-
- public void setSortingKey(String sortingKey) {
- this.sortingKey = sortingKey;
- }
-
@ApiModelProperty(value = "Clustering Order", notes = "")
public String getClusteringOrder() {
return clusteringOrder;
diff --git a/src/main/java/org/onap/music/eelf/healthcheck/MusicHealthCheck.java b/src/main/java/org/onap/music/eelf/healthcheck/MusicHealthCheck.java
index 93c44468..1f9fe5ba 100644
--- a/src/main/java/org/onap/music/eelf/healthcheck/MusicHealthCheck.java
+++ b/src/main/java/org/onap/music/eelf/healthcheck/MusicHealthCheck.java
@@ -3,6 +3,8 @@
* org.onap.music
* ===================================================================
* Copyright (c) 2017 AT&T Intellectual Property
+ *
+ * Modifications Copyright (C) 2019 IBM.
* ===================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -65,9 +67,7 @@ public class MusicHealthCheck {
try {
result = getAdminKeySpace(consistency);
} catch (MusicServiceException e1) {
- // TODO Auto-generated catch block
- logger.error("Error", e);
- e1.printStackTrace();
+ logger.error(EELFLoggerDelegate.errorLogger, e1.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.ERROR, ErrorTypes.UNKNOWN);
}
} else {
logger.error("Error", e);
@@ -83,20 +83,12 @@ public class MusicHealthCheck {
}
private Boolean getAdminKeySpace(String consistency) throws MusicServiceException {
-
-
PreparedQueryObject pQuery = new PreparedQueryObject();
pQuery.appendQueryString("insert into admin.healthcheck (id) values (?)");
pQuery.addValue(UUID.randomUUID());
- ResultType rs = MusicCore.nonKeyRelatedPut(pQuery, consistency);
- logger.info(rs.toString());
- if (rs != null) {
- return Boolean.TRUE;
- } else {
- return Boolean.FALSE;
- }
-
-
+ ResultType rs = MusicCore.nonKeyRelatedPut(pQuery, consistency);
+ logger.info(rs.toString());
+ return null != rs;
}
private boolean createKeyspace() {
@@ -106,14 +98,9 @@ public class MusicHealthCheck {
try {
rs = MusicCore.nonKeyRelatedPut(pQuery, ConsistencyLevel.ONE.toString());
} catch (MusicServiceException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- logger.error("Error", e);
+ logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.ERROR, ErrorTypes.UNKNOWN);
}
- if(rs != null && rs.getResult().toLowerCase().contains("success"))
- return true;
- else
- return false;
+ return rs != null && rs.getResult().toLowerCase().contains("success");
}
public String getZookeeperStatus() {
diff --git a/src/main/java/org/onap/music/lockingservice/zookeeper/MusicLockingService.java b/src/main/java/org/onap/music/lockingservice/zookeeper/MusicLockingService.java
index e7cad139..a35e236b 100644
--- a/src/main/java/org/onap/music/lockingservice/zookeeper/MusicLockingService.java
+++ b/src/main/java/org/onap/music/lockingservice/zookeeper/MusicLockingService.java
@@ -32,6 +32,7 @@ import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.Watcher.Event.KeeperState;
import org.apache.zookeeper.ZooKeeper;
+import org.onap.music.authentication.CachingUtil;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
import org.onap.music.eelf.logging.format.AppMessages;
import org.onap.music.eelf.logging.format.ErrorSeverity;
@@ -39,7 +40,6 @@ import org.onap.music.eelf.logging.format.ErrorTypes;
import org.onap.music.exceptions.MusicLockingException;
import org.onap.music.exceptions.MusicServiceException;
import org.onap.music.lockingservice.cassandra.MusicLockState;
-import org.onap.music.main.CachingUtil;
import org.onap.music.main.MusicUtil;
diff --git a/src/main/java/org/onap/music/lockingservice/zookeeper/ZkStatelessLockService.java b/src/main/java/org/onap/music/lockingservice/zookeeper/ZkStatelessLockService.java
index 38c4726f..e8ed257a 100644
--- a/src/main/java/org/onap/music/lockingservice/zookeeper/ZkStatelessLockService.java
+++ b/src/main/java/org/onap/music/lockingservice/zookeeper/ZkStatelessLockService.java
@@ -3,7 +3,8 @@
* ===================================================================
* Copyright (c) 2017 AT&T Intellectual Property
* ===================================================================
- * Modifications Copyright (c) 2018 IBM.
+ * Modifications Copyright (c) 2018 IBM.
+ * Modifications Copyright (c) 2019 Samsung.
* ===================================================================
* 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
@@ -39,7 +40,6 @@ import org.onap.music.eelf.logging.format.ErrorSeverity;
import org.onap.music.eelf.logging.format.ErrorTypes;
import org.onap.music.main.MusicCore;
import org.onap.music.main.MusicUtil;
-import org.onap.music.service.impl.MusicZKCore;
import com.datastax.driver.core.DataType;
@@ -127,6 +127,7 @@ public class ZkStatelessLockService extends ProtocolSupport {
}
}catch (InterruptedException e) {
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
+ Thread.currentThread().interrupt();
}catch (KeeperException e) {
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.KEEPERERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
}
@@ -144,6 +145,7 @@ public class ZkStatelessLockService extends ProtocolSupport {
retryOperation(zop);
}catch (InterruptedException e) {
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
+ Thread.currentThread().interrupt();
}catch (KeeperException e) {
logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.KEEPERERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
}
@@ -303,20 +305,26 @@ public class ZkStatelessLockService extends ProtocolSupport {
Stat stat = null;
try {
stat = zookeeper.exists(id, false);
- } catch (KeeperException | InterruptedException e1) {
- e1.printStackTrace();
+ } catch (InterruptedException e) {
+ logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.EXECUTIONINTERRUPTED, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
+ Thread.currentThread().interrupt();
+ } catch (KeeperException e) {
+ logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.KEEPERERROR, ErrorSeverity.ERROR, ErrorTypes.LOCKINGERROR);
}
- Long ctime = stat.getCtime();
- MusicUtil.zkNodeMap.put(id, ctime);
- PreparedQueryObject pQuery = new PreparedQueryObject();
- pQuery.appendQueryString(
- "INSERT INTO admin.locks(lock_id, ctime) VALUES (?,?)");
- try {
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), id));
- pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), ctime));
- MusicCore.eventualPut(pQuery);
- } catch (Exception e) {
- e.printStackTrace();
+
+ if (stat != null){
+ Long ctime = stat.getCtime();
+ MusicUtil.zkNodeMap.put(id, ctime);
+ PreparedQueryObject pQuery = new PreparedQueryObject();
+ pQuery.appendQueryString(
+ "INSERT INTO admin.locks(lock_id, ctime) VALUES (?,?)");
+ try {
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), id));
+ pQuery.addValue(MusicUtil.convertToActualDataType(DataType.text(), ctime));
+ MusicCore.eventualPut(pQuery);
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.ERROR, ErrorTypes.UNKNOWN);
+ }
}
break;
}
diff --git a/src/main/java/org/onap/music/main/CronJobManager.java b/src/main/java/org/onap/music/main/CronJobManager.java
index 9cd9f33f..0d7d9239 100644
--- a/src/main/java/org/onap/music/main/CronJobManager.java
+++ b/src/main/java/org/onap/music/main/CronJobManager.java
@@ -4,6 +4,8 @@
* ===================================================================
* Copyright (c) 2017 AT&T Intellectual Property
* ===================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ===================================================================
* 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
@@ -25,13 +27,7 @@ package org.onap.music.main;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Iterator;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-import javax.servlet.annotation.WebListener;
-
+import org.onap.music.authentication.CachingUtil;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
import org.onap.music.eelf.logging.format.AppMessages;
@@ -52,13 +48,13 @@ public class CronJobManager {
private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
-
+
@Scheduled(cron = "0 0 0 * * ?")
public void scheduleTaskWithFixedRate() {
logger.info("Executing cronjob to cleanup locks..", dateTimeFormatter.format(LocalDateTime.now()) );
deleteLocksFromDB();
}
-
+
public void deleteLocksFromDB() {
PreparedQueryObject pQuery = new PreparedQueryObject();
String consistency = MusicUtil.EVENTUAL;
@@ -69,10 +65,9 @@ public class CronJobManager {
logger.error(EELFLoggerDelegate.errorLogger,"Error creating Admin.locks table.",AppMessages.QUERYERROR,ErrorSeverity.CRITICAL, ErrorTypes.QUERYERROR);
}
} catch (MusicServiceException e1) {
- logger.error(EELFLoggerDelegate.errorLogger,e1.getMessage(),AppMessages.QUERYERROR,ErrorSeverity.CRITICAL, ErrorTypes.QUERYERROR);
- e1.printStackTrace();
+ logger.error(EELFLoggerDelegate.errorLogger,e1,AppMessages.QUERYERROR,ErrorSeverity.CRITICAL, ErrorTypes.QUERYERROR);
}
-
+
pQuery = new PreparedQueryObject();
pQuery.appendQueryString(
"select * from admin.locks");
@@ -82,7 +77,7 @@ public class CronJobManager {
StringBuilder deleteKeys = new StringBuilder();
Boolean expiredKeys = false;
while (it.hasNext()) {
- Row row = (Row) it.next();
+ Row row = it.next();
String id = row.getString("lock_id");
long ctime = Long.parseLong(row.getString("ctime"));
if(System.currentTimeMillis() >= ctime + 24 * 60 * 60 * 1000) {
@@ -102,8 +97,7 @@ public class CronJobManager {
CachingUtil.deleteKeysFromDB(deleteKeys.toString());
}
} catch (MusicServiceException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(),AppMessages.CACHEERROR,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
- e.printStackTrace();
+ logger.error(EELFLoggerDelegate.errorLogger,e,AppMessages.CACHEERROR,ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
}
}
}
diff --git a/src/main/java/org/onap/music/main/MusicUtil.java b/src/main/java/org/onap/music/main/MusicUtil.java
index 805f459f..06eeb805 100755
--- a/src/main/java/org/onap/music/main/MusicUtil.java
+++ b/src/main/java/org/onap/music/main/MusicUtil.java
@@ -4,7 +4,8 @@
* ===================================================================
* Copyright (c) 2017 AT&T Intellectual Property
* ===================================================================
- * Modifications Copyright (c) 2018 IBM.
+ * Modifications Copyright (c) 2018 IBM.
+ * Modifications Copyright (c) 2019 Samsung.
* ===================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,6 +25,10 @@
package org.onap.music.main;
+import com.datastax.driver.core.ColumnDefinitions;
+import com.datastax.driver.core.ColumnDefinitions.Definition;
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.Row;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -43,9 +48,12 @@ import java.util.concurrent.ConcurrentMap;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
-
+import org.onap.music.datastore.MusicDataStoreHandle;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
+import org.onap.music.eelf.logging.format.AppMessages;
+import org.onap.music.eelf.logging.format.ErrorSeverity;
+import org.onap.music.eelf.logging.format.ErrorTypes;
import org.onap.music.exceptions.MusicQueryException;
import org.onap.music.exceptions.MusicServiceException;
import org.onap.music.service.MusicCoreService;
@@ -806,13 +814,58 @@ public class MusicUtil {
public static void setIsCadi(boolean isCadi) {
- // TODO Auto-generated method stub
MusicUtil.isCadi = isCadi;
}
+
+ public static void writeBackToQuorum(PreparedQueryObject selectQuery, String primaryKeyName,
+ PreparedQueryObject updateQuery, String keyspace, String table,
+ Object cqlFormattedPrimaryKeyValue)
+ throws Exception {
+ try {
+ ResultSet results = MusicDataStoreHandle.getDSHandle().executeQuorumConsistencyGet(selectQuery);
+ // write it back to a quorum
+ Row row = results.one();
+ ColumnDefinitions colInfo = row.getColumnDefinitions();
+ int totalColumns = colInfo.size();
+ int counter = 1;
+ StringBuilder fieldValueString = new StringBuilder("");
+ for (Definition definition : colInfo) {
+ String colName = definition.getName();
+ if (colName.equals(primaryKeyName))
+ continue;
+ DataType colType = definition.getType();
+ Object valueObj = MusicDataStoreHandle.getDSHandle().getColValue(row, colName, colType);
+ Object valueString = MusicUtil.convertToActualDataType(colType, valueObj);
+ fieldValueString.append(colName + " = ?");
+ updateQuery.addValue(valueString);
+ if (counter != (totalColumns - 1))
+ fieldValueString.append(",");
+ counter = counter + 1;
+ }
+ updateQuery.appendQueryString("UPDATE " + keyspace + "." + table + " SET "
+ + fieldValueString + " WHERE " + primaryKeyName + "= ? " + ";");
+ updateQuery.addValue(cqlFormattedPrimaryKeyValue);
+
+ MusicDataStoreHandle.getDSHandle().executePut(updateQuery, "critical");
+ } catch (MusicServiceException | MusicQueryException e) {
+ logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.QUERYERROR +""+updateQuery ,
+ ErrorSeverity.MAJOR, ErrorTypes.QUERYERROR);
+ }
+ }
public static boolean getIsCadi() {
return MusicUtil.isCadi;
}
+
+ /**
+ * @return a random uuid
+ */
+ public static String generateUUID() {
+ String uuid = UUID.randomUUID().toString();
+ logger.info(EELFLoggerDelegate.applicationLogger,"New AID generated: "+uuid);
+ return uuid;
+ }
+
}
diff --git a/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java b/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java
index 289cab06..0bca1f99 100755
--- a/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java
+++ b/src/main/java/org/onap/music/rest/RestMusicAdminAPI.java
@@ -46,7 +46,9 @@ import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
import org.mindrot.jbcrypt.BCrypt;
+import org.onap.music.authentication.CachingUtil;
import org.onap.music.authentication.MusicAuthentication;
+import org.onap.music.authentication.MusicAuthenticator;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.datastore.jsonobjects.JsonOnboard;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
@@ -54,8 +56,6 @@ 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.main.CacheAccess;
-import org.onap.music.main.CachingUtil;
import org.onap.music.main.MusicCore;
import org.onap.music.main.MusicUtil;
import org.onap.music.main.ResultType;
@@ -80,6 +80,8 @@ public class RestMusicAdminAPI {
EELFLoggerDelegate.getLogger(RestMusicAdminAPI.class);
// Set to true in env like ONAP. Where access to creating and dropping keyspaces exist.
private static final boolean KEYSPACE_ACTIVE = false;
+
+ private MusicAuthenticator authenticator = new MusicAuthentication();
/*
* API to onboard an application with MUSIC. This is the mandatory first step.
@@ -95,25 +97,22 @@ public class RestMusicAdminAPI {
logger.info(EELFLoggerDelegate.errorLogger, "oboarding app");
ResponseBuilder response =
Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
+ if (!authenticator.authenticateAdmin(authorization)) {
+ logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check admin username,password and try again", AppMessages.AUTHENTICATIONERROR, ErrorSeverity.CRITICAL,
+ ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.UNAUTHORIZED)
+ .entity(new JsonResponse(ResultType.FAILURE)
+ .setError("Unauthorized: Please check admin username,password and try again").toMap())
+ .build();
+ }
+
Map<String, Object> resultMap = new HashMap<>();
String appName = jsonObj.getAppname();
String userId = jsonObj.getUserId();
String isAAF = jsonObj.getIsAAF();
String password = jsonObj.getPassword();
String keyspace_name = jsonObj.getKeyspace();
- try {
- if (!MusicAuthentication.authenticateAdmin(authorization)) {
- logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check admin username,password and try again", AppMessages.MISSINGDATA, ErrorSeverity.CRITICAL,
- ErrorTypes.AUTHENTICATIONERROR);
- response.status(Status.UNAUTHORIZED);
- return response
- .entity(new JsonResponse(ResultType.FAILURE)
- .setError("Unauthorized: Please check admin username,password and try again").toMap())
- .build();
- }
- } catch (Exception e) {
- return response.entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
- }
+
if (appName == null || userId == null || isAAF == null || password == null) {
logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check the request parameters. Some of the required values appName(ns), userId, password, isAAF are missing.", AppMessages.MISSINGINFO,
ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
@@ -135,7 +134,7 @@ public class RestMusicAdminAPI {
* " has already been onboarded. Please contact admin.").toMap()).build(); }
*/
//pQuery = new PreparedQueryObject();
- String uuid = CachingUtil.generateUUID();
+ String uuid = MusicUtil.generateUUID();
pQuery.appendQueryString(
"INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
+ "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)");
@@ -169,24 +168,20 @@ public class RestMusicAdminAPI {
public Response getOnboardedInfoSearch(JsonOnboard jsonObj,
@ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization) throws Exception {
ResponseBuilder response = Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
+
+ if (!authenticator.authenticateAdmin(authorization)) {
+ logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check admin username,password and try again", AppMessages.AUTHENTICATIONERROR, ErrorSeverity.CRITICAL,
+ ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.UNAUTHORIZED)
+ .entity(new JsonResponse(ResultType.FAILURE)
+ .setError("Unauthorized: Please check admin username,password and try again").toMap())
+ .build();
+ }
+
Map<String, Object> resultMap = new HashMap<>();
String appName = jsonObj.getAppname();
String uuid = jsonObj.getAid();
String isAAF = jsonObj.getIsAAF();
-
- try {
- if (!MusicAuthentication.authenticateAdmin(authorization)) {
- logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGDATA, ErrorSeverity.CRITICAL,
- ErrorTypes.AUTHENTICATIONERROR);
- response.status(Status.UNAUTHORIZED);
- return response
- .entity(new JsonResponse(ResultType.FAILURE)
- .setError("Unauthorized: Please check admin username,password and try again").toMap())
- .build();
- }
- } catch (Exception e) {
- return response.entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
- }
if (appName == null && uuid == null && isAAF == null) {
logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check the request parameters. Enter atleast one of the following parameters: appName(ns), aid, isAAF.", AppMessages.MISSINGINFO,
ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
@@ -246,24 +241,21 @@ public class RestMusicAdminAPI {
public Response deleteOnboardApp(JsonOnboard jsonObj,
@ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization) throws Exception {
ResponseBuilder response = Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
+
+ if (!authenticator.authenticateAdmin(authorization)) {
+ logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check admin username,password and try again", AppMessages.AUTHENTICATIONERROR, ErrorSeverity.CRITICAL,
+ ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.UNAUTHORIZED)
+ .entity(new JsonResponse(ResultType.FAILURE)
+ .setError("Unauthorized: Please check admin username,password and try again").toMap())
+ .build();
+ }
+
Map<String, Object> resultMap = new HashMap<>();
String appName = jsonObj.getAppname();
String aid = jsonObj.getAid();
PreparedQueryObject pQuery = new PreparedQueryObject();
- String consistency = MusicUtil.EVENTUAL;;
- try {
- if (!MusicAuthentication.authenticateAdmin(authorization)) {
- logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGDATA, ErrorSeverity.CRITICAL,
- ErrorTypes.AUTHENTICATIONERROR);
- response.status(Status.UNAUTHORIZED);
- return response
- .entity(new JsonResponse(ResultType.FAILURE)
- .setError("Unauthorized: Please check admin username,password and try again").toMap())
- .build();
- }
- } catch (Exception e) {
- return response.entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
- }
+ String consistency = MusicUtil.EVENTUAL;
if (appName == null && aid == null) {
logger.error(EELFLoggerDelegate.errorLogger, "Please make sure either appName(ns) or Aid is present", AppMessages.MISSINGINFO,
ErrorSeverity.CRITICAL, ErrorTypes.DATAERROR);
@@ -356,6 +348,15 @@ public class RestMusicAdminAPI {
public Response updateOnboardApp(JsonOnboard jsonObj,
@ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization) throws Exception {
ResponseBuilder response = Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
+ if (!authenticator.authenticateAdmin(authorization)) {
+ logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check admin username,password and try again", AppMessages.AUTHENTICATIONERROR, ErrorSeverity.CRITICAL,
+ ErrorTypes.AUTHENTICATIONERROR);
+ return response.status(Status.UNAUTHORIZED)
+ .entity(new JsonResponse(ResultType.FAILURE)
+ .setError("Unauthorized: Please check admin username,password and try again").toMap())
+ .build();
+ }
+
Map<String, Object> resultMap = new HashMap<>();
String aid = jsonObj.getAid();
String appName = jsonObj.getAppname();
@@ -364,19 +365,7 @@ public class RestMusicAdminAPI {
String password = jsonObj.getPassword();
String consistency = "eventual";
PreparedQueryObject pQuery;
- try {
- if (!MusicAuthentication.authenticateAdmin(authorization)) {
- logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.MISSINGDATA, ErrorSeverity.CRITICAL,
- ErrorTypes.AUTHENTICATIONERROR);
- response.status(Status.UNAUTHORIZED);
- return response
- .entity(new JsonResponse(ResultType.FAILURE)
- .setError("Unauthorized: Please check admin username,password and try again").toMap())
- .build();
- }
- } catch (Exception e) {
- return response.entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
- }
+
if (aid == null) {
resultMap.put("Exception", "Please make sure Aid is present");
logger.error(EELFLoggerDelegate.errorLogger, "Please make sure Aid is present", AppMessages.MISSINGDATA,
@@ -456,6 +445,12 @@ public class RestMusicAdminAPI {
List<Application> appList = new ArrayList<>();
ResponseBuilder response =
Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
+ if (!authenticator.authenticateAdmin(authorization)) {
+ logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check admin username,password and try again", AppMessages.AUTHENTICATIONERROR, ErrorSeverity.CRITICAL,
+ ErrorTypes.AUTHENTICATIONERROR);
+ return appList;
+ }
+
PreparedQueryObject queryObject = new PreparedQueryObject();
queryObject.appendQueryString("SELECT * FROM " + "admin" + "." + "keyspace_master" + ";");
ResultSet results = MusicCore.get(queryObject);
@@ -482,6 +477,11 @@ public class RestMusicAdminAPI {
@ApiParam(value = "uuid", required = true) @HeaderParam("uuid") String uuid) throws Exception {
ResponseBuilder response =
Response.noContent().header("X-latestVersion", MusicUtil.getVersion());
+ if (!authenticator.authenticateAdmin(authorization)) {
+ logger.error(EELFLoggerDelegate.errorLogger, "Unauthorized: Please check admin username,password and try again", AppMessages.AUTHENTICATIONERROR, ErrorSeverity.CRITICAL,
+ ErrorTypes.AUTHENTICATIONERROR);
+ return false;
+ }
PreparedQueryObject queryObject = new PreparedQueryObject();
queryObject.appendQueryString("delete from admin.keyspace_master where uuid=?");
queryObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),uuid));
@@ -493,15 +493,4 @@ public class RestMusicAdminAPI {
}
return true;
}
-
-
- @GET
- @Path("/login")
- @Produces(MediaType.APPLICATION_JSON)
- @Consumes(MediaType.APPLICATION_JSON)
- public boolean login(@ApiParam(value = "Authorization", required = true) @HeaderParam(MusicUtil.AUTHORIZATION) String authorization) throws Exception {
-
- boolean result = MusicAuthentication.authenticateAdmin(authorization);
- return result;
- }
}
diff --git a/src/main/java/org/onap/music/rest/RestMusicBmAPI.java b/src/main/java/org/onap/music/rest/RestMusicBmAPI.java
deleted file mode 100644
index f2946c14..00000000
--- a/src/main/java/org/onap/music/rest/RestMusicBmAPI.java
+++ /dev/null
@@ -1,319 +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.rest;
-
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.UriInfo;
-import org.onap.music.datastore.jsonobjects.JsonInsert;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-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.service.impl.MusicZKCore;
-import org.onap.music.datastore.MusicDataStoreHandle;
-import org.onap.music.datastore.PreparedQueryObject;
-import com.datastax.driver.core.DataType;
-import com.datastax.driver.core.TableMetadata;
-import io.swagger.annotations.Api;
-
-/*
- * These are functions created purely for benchmarking purposes. Commented out Swagger - This should
- * be undocumented API
- *
- */
-@Path("/v{version: [0-9]+}/benchmarks/")
-@Api(value = "Benchmark API", hidden = true)
-public class RestMusicBmAPI {
-
- private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RestMusicBmAPI.class);
- public static final String UPDATE_CONST=" update-";
- // pure zk calls...
-
- /**
- *
- * @param nodeName
- * @throws Exception
- */
- @POST
- @Path("/purezk/{name}")
- @Consumes(MediaType.APPLICATION_JSON)
- public void pureZkCreate(@PathParam("name") String nodeName) throws Exception {
- MusicZKCore.pureZkCreate("/" + nodeName);
- }
-
-
- /**
- *
- * @param insObj
- * @param nodeName
- * @throws Exception
- */
- @PUT
- @Path("/purezk/{name}")
- @Consumes(MediaType.APPLICATION_JSON)
- public void pureZkUpdate(JsonInsert insObj, @PathParam("name") String nodeName)
- throws Exception {
- logger.info(EELFLoggerDelegate.applicationLogger,"--------------Zk normal update-------------------------");
- long start = System.currentTimeMillis();
- MusicZKCore.pureZkWrite(nodeName, insObj.serialize());
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Total time taken for Zk normal update:" + (end - start) + " ms");
- }
-
- /**
- *
- * @param nodeName
- * @return
- * @throws Exception
- */
- @GET
- @Path("/purezk/{name}")
- @Consumes(MediaType.TEXT_PLAIN)
- public byte[] pureZkGet(@PathParam("name") String nodeName) throws Exception {
- return MusicZKCore.pureZkRead(nodeName);
- }
-
- /**
- *
- * @param insObj
- * @param lockName
- * @param nodeName
- * @throws Exception
- */
- @PUT
- @Path("/purezk/atomic/{lockname}/{name}")
- @Consumes(MediaType.APPLICATION_JSON)
- public void pureZkAtomicPut(JsonInsert updateObj, @PathParam("lockname") String lockname,
- @PathParam("name") String nodeName) throws Exception {
- long startTime = System.currentTimeMillis();
- String operationId = UUID.randomUUID().toString();// just for debugging purposes.
- String consistency = updateObj.getConsistencyInfo().get("type");
-
- logger.info(EELFLoggerDelegate.applicationLogger,"--------------Zookeeper " + consistency + UPDATE_CONST + operationId
- + "-------------------------");
-
- byte[] data = updateObj.serialize();
- long jsonParseCompletionTime = System.currentTimeMillis();
-
- String lockId = MusicCore.createLockReference(lockname);
-
- long lockCreationTime = System.currentTimeMillis();
-
- long leasePeriod = MusicUtil.getDefaultLockLeasePeriod();
- ReturnType lockAcqResult = MusicCore.acquireLockWithLease(lockname, lockId, leasePeriod);
- long lockAcqTime = System.currentTimeMillis();
- long zkPutTime = 0;
- long lockReleaseTime = 0;
-
- if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
- logger.info(EELFLoggerDelegate.applicationLogger,"acquired lock with id " + lockId);
- MusicZKCore.pureZkWrite(lockname, data);
- zkPutTime = System.currentTimeMillis();
- boolean voluntaryRelease = true;
-/*<<<<<<< HEAD
- if (("atomic").equals(consistency))
- MusicCore.releaseLock(lockId, voluntaryRelease);
- else if (("atomic_delete_lock").equals(consistency))
- MusicCore.deleteLock(lockname);
-=======*/
- if (consistency.equals("atomic"))
- MusicCore.releaseLock(lockId, voluntaryRelease);
- else if (consistency.equals("atomic_delete_lock"))
- MusicCore.deleteLock(lockname);
- lockReleaseTime = System.currentTimeMillis();
- } else {
- MusicCore.destroyLockRef(lockId);
- }
-
- long actualUpdateCompletionTime = System.currentTimeMillis();
-
-
- long endTime = System.currentTimeMillis();
-
- String lockingInfo = "|lock creation time:" + (lockCreationTime - jsonParseCompletionTime)
- + "|lock accquire time:" + (lockAcqTime - lockCreationTime)
- + "|zk put time:" + (zkPutTime - lockAcqTime);
-
- if ("atomic".equals(consistency))
- lockingInfo = lockingInfo + "|lock release time:" + (lockReleaseTime - zkPutTime) + "|";
- else if ("atomic_delete_lock".equals(consistency))
- lockingInfo = lockingInfo + "|lock delete time:" + (lockReleaseTime - zkPutTime) + "|";
-
- String timingString = "Time taken in ms for Zookeeper " + consistency + UPDATE_CONST
- + operationId + ":" + "|total operation time:" + (endTime - startTime)
- + "|json parsing time:" + (jsonParseCompletionTime - startTime)
- + "|update time:" + (actualUpdateCompletionTime - jsonParseCompletionTime)
- + lockingInfo;
-
- logger.info(EELFLoggerDelegate.applicationLogger,timingString);
- }
-
- /**
- *
- * @param insObj
- * @param lockName
- * @param nodeName
- * @throws Exception
- */
- @GET
- @Path("/purezk/atomic/{lockname}/{name}")
- @Consumes(MediaType.APPLICATION_JSON)
- public void pureZkAtomicGet(JsonInsert insObj, @PathParam("lockname") String lockName,
- @PathParam("name") String nodeName) throws Exception {
- logger.info("--------------Zk atomic read-------------------------");
- long start = System.currentTimeMillis();
- String lockId = MusicCore.createLockReference(lockName);
- long leasePeriod = MusicUtil.getDefaultLockLeasePeriod();
- ReturnType lockAcqResult = MusicCore.acquireLockWithLease(lockName, lockId, leasePeriod);
- if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
- logger.info("acquired lock with id " + lockId);
- MusicZKCore.pureZkRead(nodeName);
- boolean voluntaryRelease = true;
- MusicCore.releaseLock(lockId, voluntaryRelease);
- } else {
- MusicCore.destroyLockRef(lockId);
- }
-
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Total time taken for Zk atomic read:" + (end - start) + " ms");
- }
-
- /**
- *
- * doing an update directly to cassa but through the rest api
- *
- * @param insObj
- * @param keyspace
- * @param tablename
- * @param info
- * @return
- * @throws Exception
- */
- @PUT
- @Path("/cassa/keyspaces/{keyspace}/tables/{tablename}/rows")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public boolean updateTableCassa(JsonInsert insObj, @PathParam("keyspace") String keyspace,
- @PathParam("tablename") String tablename, @Context UriInfo info)
- throws Exception {
- long startTime = System.currentTimeMillis();
- String operationId = UUID.randomUUID().toString();// just for debugging purposes.
- String consistency = insObj.getConsistencyInfo().get("type");
- logger.info(EELFLoggerDelegate.applicationLogger,"--------------Cassandra " + consistency + UPDATE_CONST + operationId
- + "-------------------------");
- PreparedQueryObject queryObject = new PreparedQueryObject();
- Map<String, Object> valuesMap = insObj.getValues();
- TableMetadata tableInfo = MusicDataStoreHandle.returnColumnMetadata(keyspace, tablename);
- String vectorTs = "'" + Thread.currentThread().getId() + System.currentTimeMillis() + "'";
- String fieldValueString = "vector_ts= ? ,";
- queryObject.addValue(vectorTs);
-
- int counter = 0;
- for (Map.Entry<String, Object> entry : valuesMap.entrySet()) {
- Object valueObj = entry.getValue();
- DataType colType = tableInfo.getColumn(entry.getKey()).getType();
- Object valueString = MusicUtil.convertToActualDataType(colType, valueObj);
- fieldValueString = fieldValueString + entry.getKey() + "= ?";
- queryObject.addValue(valueString);
- if (counter != valuesMap.size() - 1)
- fieldValueString = fieldValueString + ",";
- counter = counter + 1;
- }
-
- // get the row specifier
- String rowSpec = "";
- counter = 0;
- queryObject.appendQueryString("UPDATE " + keyspace + "." + tablename + " ");
- MultivaluedMap<String, String> rowParams = info.getQueryParameters();
- String primaryKey = "";
- for (MultivaluedMap.Entry<String, List<String>> entry : rowParams.entrySet()) {
- String keyName = entry.getKey();
- List<String> valueList = entry.getValue();
- String indValue = valueList.get(0);
- DataType colType = tableInfo.getColumn(entry.getKey()).getType();
- Object formattedValue = MusicUtil.convertToActualDataType(colType, indValue);
- primaryKey = primaryKey + indValue;
- rowSpec = rowSpec + keyName + "= ? ";
- queryObject.addValue(formattedValue);
- if (counter != rowParams.size() - 1)
- rowSpec = rowSpec + " AND ";
- counter = counter + 1;
- }
-
-
- String ttl = insObj.getTtl();
- String timestamp = insObj.getTimestamp();
-
- if ((ttl != null) && (timestamp != null)) {
-
- logger.info(EELFLoggerDelegate.applicationLogger,"both there");
- queryObject.appendQueryString(" USING TTL ? AND TIMESTAMP ?");
- queryObject.addValue(Integer.parseInt(ttl));
- queryObject.addValue(Long.parseLong(timestamp));
- }
-
- if ((ttl != null) && (timestamp == null)) {
- logger.info(EELFLoggerDelegate.applicationLogger,"ONLY TTL there");
- queryObject.appendQueryString(" USING TTL ?");
- queryObject.addValue(Integer.parseInt(ttl));
- }
-
- if ((ttl == null) && (timestamp != null)) {
- logger.info(EELFLoggerDelegate.applicationLogger,"ONLY timestamp there");
- queryObject.appendQueryString(" USING TIMESTAMP ?");
- queryObject.addValue(Long.parseLong(timestamp));
- }
- queryObject.appendQueryString(" SET " + fieldValueString + " WHERE " + rowSpec + ";");
-
- long jsonParseCompletionTime = System.currentTimeMillis();
-
- boolean operationResult = true;
- MusicDataStoreHandle.getDSHandle().executePut(queryObject, insObj.getConsistencyInfo().get("type"));
-
- long actualUpdateCompletionTime = System.currentTimeMillis();
-
- long endTime = System.currentTimeMillis();
-
- String timingString = "Time taken in ms for Cassandra " + consistency + UPDATE_CONST
- + operationId + ":" + "|total operation time:" + (endTime - startTime)
- + "|json parsing time:" + (jsonParseCompletionTime - startTime)
- + "|update time:" + (actualUpdateCompletionTime - jsonParseCompletionTime)
- + "|";
- logger.info(EELFLoggerDelegate.applicationLogger,timingString);
-
- return operationResult;
- }
-}
diff --git a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
index 507bcd40..f72a1ac9 100755
--- a/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
+++ b/src/main/java/org/onap/music/rest/RestMusicDataAPI.java
@@ -4,6 +4,8 @@
* ===================================================================
* Copyright (c) 2017 AT&T Intellectual Property
* ===================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ===================================================================
* 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
@@ -23,12 +25,10 @@
package org.onap.music.rest;
import java.nio.ByteBuffer;
-import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
-import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
@@ -39,7 +39,6 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
-import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
@@ -49,7 +48,10 @@ import javax.ws.rs.core.UriInfo;
import org.apache.commons.lang3.StringUtils;
import org.mindrot.jbcrypt.BCrypt;
+import org.onap.music.authentication.CachingUtil;
import org.onap.music.authentication.MusicAuthentication;
+import org.onap.music.authentication.MusicAuthenticator;
+import org.onap.music.authentication.MusicAuthenticator.Operation;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.datastore.jsonobjects.JsonDelete;
import org.onap.music.datastore.jsonobjects.JsonInsert;
@@ -63,7 +65,6 @@ 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.main.CachingUtil;
import org.onap.music.main.MusicCore;
import org.onap.music.datastore.Condition;
import org.onap.music.datastore.MusicDataStoreHandle;
@@ -71,7 +72,6 @@ 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 org.onap.music.service.impl.MusicZKCore;
import com.datastax.driver.core.DataType;
import com.datastax.driver.core.ResultSet;
@@ -117,6 +117,7 @@ public class RestMusicDataAPI {
private static final String XPATCHVERSION = "X-patchVersion";
private static final String NS = "ns";
private static final String VERSION = "v2";
+ private MusicAuthenticator authenticator = new MusicAuthentication();
// Set to true in env like ONAP. Where access to creating and dropping keyspaces exist.
private static final boolean KEYSPACE_ACTIVE = false;
@@ -149,7 +150,6 @@ public class RestMusicDataAPI {
@ApiOperation(value = "Create Keyspace", response = String.class,hidden = true)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- //public Map<String, Object> createKeySpace(
public Response createKeySpace(
@ApiParam(value = "Major Version",required = true) @PathParam("version") String version,
@ApiParam(value = "Minor Version",required = false) @HeaderParam(XMINORVERSION) String minorVersion,
@@ -404,23 +404,20 @@ public class RestMusicDataAPI {
@ApiParam(value = "Table Name",required = true) @PathParam("tablename") String tablename) throws Exception {
try {
ResponseBuilder response = MusicUtil.buildVersionResponse(VERSION, minorVersion, patchVersion);
- if((keyspace == null || keyspace == null) || (tablename.isEmpty() || tablename.isEmpty())){
+ if(keyspace == null || keyspace.isEmpty() || tablename == null || tablename.isEmpty()){
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
- .setError("one or more path parameters are not set, please check and try again")
+ .setError("One or more path parameters are not set, please check and try again."
+ + "Parameter values: keyspace='" + keyspace + "' tablename='" + tablename + "'")
.toMap()).build();
}
EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspace+" ) ");
- Map<String,String> userCredentials = MusicUtil.extractBasicAuthentication(authorization);
- String userId = userCredentials.get(MusicUtil.USERID);
- String password = userCredentials.get(MusicUtil.PASSWORD);
- Map<String, Object> authMap = MusicAuthentication.autheticateUser(ns, userId, password, keyspace,
- aid, "createTable");
- if (authMap.containsKey("aid"))
- authMap.remove("aid");
- if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,authMap.get("Exception").toString(), AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
- }
+ if (!authenticator.authenticateUser(ns, authorization, keyspace, aid, Operation.CREATE_TABLE)) {
+ return response.status(Status.UNAUTHORIZED)
+ .entity(new JsonResponse(ResultType.FAILURE)
+ .setError("Unauthorized: Please check username, password and make sure your app is onboarded")
+ .toMap()).build();
+ }
+
String consistency = MusicUtil.EVENTUAL;
// for now this needs only eventual consistency
@@ -447,90 +444,90 @@ public class RestMusicDataAPI {
else fieldsString.append("," + entry.getKey() + " " + entry.getValue() + "");
}
- if (counter != (fields.size() - 1) ) {
-
- counter = counter + 1;
- } else {
-
- if((primaryKey != null) && (partitionKey == null)) {
- primaryKey = primaryKey.trim();
- int count1 = StringUtils.countMatches(primaryKey, ')');
- int count2 = StringUtils.countMatches(primaryKey, '(');
- if (count1 != count2) {
+ if (counter != (fields.size() - 1) ) {
+
+ counter = counter + 1;
+ } else {
+
+ if((primaryKey != null) && (partitionKey == null)) {
+ primaryKey = primaryKey.trim();
+ int count1 = StringUtils.countMatches(primaryKey, ')');
+ int count2 = StringUtils.countMatches(primaryKey, '(');
+ if (count1 != count2) {
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
- .setError("Create Table Error: primary key '(' and ')' do not match, primary key=" + primaryKey)
- .toMap()).build();
- }
+ .setError("Create Table Error: primary key '(' and ')' do not match, primary key=" + primaryKey)
+ .toMap()).build();
+ }
- if ( primaryKey.indexOf('(') == -1 || ( count2 == 1 && (primaryKey.lastIndexOf(')') +1) == primaryKey.length() ) )
- {
- if (primaryKey.contains(",") ) {
+ if ( primaryKey.indexOf('(') == -1 || ( count2 == 1 && (primaryKey.lastIndexOf(')') +1) == primaryKey.length() ) )
+ {
+ if (primaryKey.contains(",") ) {
partitionKey= primaryKey.substring(0,primaryKey.indexOf(','));
- partitionKey=partitionKey.replaceAll("[\\(]+","");
- clusterKey=primaryKey.substring(primaryKey.indexOf(',')+1); // make sure index
- clusterKey=clusterKey.replaceAll("[)]+", "");
- } else {
- partitionKey=primaryKey;
- partitionKey=partitionKey.replaceAll("[\\)]+","");
- partitionKey=partitionKey.replaceAll("[\\(]+","");
- clusterKey="";
+ partitionKey=partitionKey.replaceAll("[\\(]+","");
+ clusterKey=primaryKey.substring(primaryKey.indexOf(',')+1); // make sure index
+ clusterKey=clusterKey.replaceAll("[)]+", "");
+ } else {
+ partitionKey=primaryKey;
+ partitionKey=partitionKey.replaceAll("[\\)]+","");
+ partitionKey=partitionKey.replaceAll("[\\(]+","");
+ clusterKey="";
+ }
+ } else { // not null and has ) before the last char
+ partitionKey= primaryKey.substring(0,primaryKey.indexOf(')'));
+ partitionKey=partitionKey.replaceAll("[\\(]+","");
+ partitionKey = partitionKey.trim();
+ clusterKey= primaryKey.substring(primaryKey.indexOf(')'));
+ clusterKey=clusterKey.replaceAll("[\\(]+","");
+ clusterKey=clusterKey.replaceAll("[\\)]+","");
+ clusterKey = clusterKey.trim();
+ if (clusterKey.indexOf(',') == 0) clusterKey=clusterKey.substring(1);
+ clusterKey = clusterKey.trim();
+ if (clusterKey.equals(",") ) clusterKey=""; // print error if needed ( ... ),)
}
- } else { // not null and has ) before the last char
- partitionKey= primaryKey.substring(0,primaryKey.indexOf(')'));
- partitionKey=partitionKey.replaceAll("[\\(]+","");
- partitionKey = partitionKey.trim();
- clusterKey= primaryKey.substring(primaryKey.indexOf(')'));
- clusterKey=clusterKey.replaceAll("[\\(]+","");
- clusterKey=clusterKey.replaceAll("[\\)]+","");
- clusterKey = clusterKey.trim();
- if (clusterKey.indexOf(',') == 0) clusterKey=clusterKey.substring(1);
- clusterKey = clusterKey.trim();
- if (clusterKey.equals(",") ) clusterKey=""; // print error if needed ( ... ),)
- }
-
- if (!(partitionKey.isEmpty() || clusterKey.isEmpty())
- && (partitionKey.equalsIgnoreCase(clusterKey) ||
- clusterKey.contains(partitionKey) || partitionKey.contains(clusterKey)) )
- {
- logger.error("DataAPI createTable partition/cluster key ERROR: partitionKey="+partitionKey+", clusterKey=" + clusterKey + " and primary key=" + primaryKey );
- return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(
- "Create Table primary key error: clusterKey(" + clusterKey + ") equals/contains/overlaps partitionKey(" +partitionKey+ ") of"
- + " primary key=" + primaryKey)
- .toMap()).build();
- }
+ if (!(partitionKey.isEmpty() || clusterKey.isEmpty())
+ && (partitionKey.equalsIgnoreCase(clusterKey) ||
+ clusterKey.contains(partitionKey) || partitionKey.contains(clusterKey)) )
+ {
+ logger.error("DataAPI createTable partition/cluster key ERROR: partitionKey="+partitionKey+", clusterKey=" + clusterKey + " and primary key=" + primaryKey );
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(
+ "Create Table primary key error: clusterKey(" + clusterKey + ") equals/contains/overlaps partitionKey(" +partitionKey+ ") of"
+ + " primary key=" + primaryKey)
+ .toMap()).build();
- if (partitionKey.isEmpty() ) primaryKey="";
- else if (clusterKey.isEmpty() ) primaryKey=" (" + partitionKey + ")";
- else primaryKey=" (" + partitionKey + ")," + clusterKey;
-
-
- if (primaryKey != null) fieldsString.append(", PRIMARY KEY (" + primaryKey + " )");
-
- } // end of length > 0
- else {
- if (!(partitionKey.isEmpty() || clusterKey.isEmpty())
- && (partitionKey.equalsIgnoreCase(clusterKey) ||
- clusterKey.contains(partitionKey) || partitionKey.contains(clusterKey)) )
- {
- logger.error("DataAPI createTable partition/cluster key ERROR: partitionKey="+partitionKey+", clusterKey=" + clusterKey);
- return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(
+ }
+
+ if (partitionKey.isEmpty() ) primaryKey="";
+ else if (clusterKey.isEmpty() ) primaryKey=" (" + partitionKey + ")";
+ else primaryKey=" (" + partitionKey + ")," + clusterKey;
+
+
+ if (primaryKey != null) fieldsString.append(", PRIMARY KEY (" + primaryKey + " )");
+
+ } // end of length > 0
+ else {
+ if (!(partitionKey.isEmpty() || clusterKey.isEmpty())
+ && (partitionKey.equalsIgnoreCase(clusterKey) ||
+ clusterKey.contains(partitionKey) || partitionKey.contains(clusterKey)) )
+ {
+ logger.error("DataAPI createTable partition/cluster key ERROR: partitionKey="+partitionKey+", clusterKey=" + clusterKey);
+ return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(
"Create Table primary key error: clusterKey(" + clusterKey + ") equals/contains/overlaps partitionKey(" +partitionKey+ ")")
.toMap()).build();
- }
+ }
- if (partitionKey.isEmpty() ) primaryKey="";
- else if (clusterKey.isEmpty() ) primaryKey=" (" + partitionKey + ")";
- else primaryKey=" (" + partitionKey + ")," + clusterKey;
+ if (partitionKey.isEmpty() ) primaryKey="";
+ else if (clusterKey.isEmpty() ) primaryKey=" (" + partitionKey + ")";
+ else primaryKey=" (" + partitionKey + ")," + clusterKey;
-
- if (primaryKey != null) fieldsString.append(", PRIMARY KEY (" + primaryKey + " )");
- }
- fieldsString.append(")");
- } // end of last field check
+ if (primaryKey != null) fieldsString.append(", PRIMARY KEY (" + primaryKey + " )");
+ }
+ fieldsString.append(")");
+
+ } // end of last field check
- } // end of for each
+ } // end of for each
// information about the name-value style properties
Map<String, Object> propertiesMap = tableObj.getProperties();
StringBuilder propertiesString = new StringBuilder();
@@ -558,40 +555,40 @@ public class RestMusicDataAPI {
String clusteringOrder = tableObj.getClusteringOrder();
if (clusteringOrder != null && !(clusteringOrder.isEmpty())) {
- String[] arrayClusterOrder = clusteringOrder.split("[,]+");
+ String[] arrayClusterOrder = clusteringOrder.split("[,]+");
- for (int i = 0; i < arrayClusterOrder.length; i++) {
- String[] clusterS = arrayClusterOrder[i].trim().split("[ ]+");
- if ( (clusterS.length ==2) && (clusterS[1].equalsIgnoreCase("ASC") || clusterS[1].equalsIgnoreCase("DESC"))) {
- continue;
- } else {
- return response.status(Status.BAD_REQUEST)
- .entity(new JsonResponse(ResultType.FAILURE)
- .setError("createTable/Clustering Order vlaue ERROR: valid clustering order is ASC or DESC or expecting colname order; please correct clusteringOrder:"+ clusteringOrder+".")
- .toMap()).build();
- }
+ for (int i = 0; i < arrayClusterOrder.length; i++) {
+ String[] clusterS = arrayClusterOrder[i].trim().split("[ ]+");
+ if ( (clusterS.length ==2) && (clusterS[1].equalsIgnoreCase("ASC") || clusterS[1].equalsIgnoreCase("DESC"))) {
+ continue;
+ } else {
+ return response.status(Status.BAD_REQUEST)
+ .entity(new JsonResponse(ResultType.FAILURE)
+ .setError("createTable/Clustering Order vlaue ERROR: valid clustering order is ASC or DESC or expecting colname order; please correct clusteringOrder:"+ clusteringOrder+".")
+ .toMap()).build();
+ }
// add validation for column names in cluster key
- }
+ }
- if (!(clusterKey.isEmpty())) {
- clusteringOrder = "CLUSTERING ORDER BY (" +clusteringOrder +")";
- //cjc check if propertiesString.length() >0 instead propertiesMap
- if (propertiesMap != null) {
- propertiesString.append(" AND "+ clusteringOrder);
+ if (!(clusterKey.isEmpty())) {
+ clusteringOrder = "CLUSTERING ORDER BY (" +clusteringOrder +")";
+ //cjc check if propertiesString.length() >0 instead propertiesMap
+ if (propertiesMap != null) {
+ propertiesString.append(" AND "+ clusteringOrder);
+ } else {
+ propertiesString.append(clusteringOrder);
+ }
} else {
- propertiesString.append(clusteringOrder);
- }
- } else {
logger.warn("Skipping clustering order=("+clusteringOrder+ ") since clustering key is empty ");
- }
- } //if non empty
+ }
+ } //if non empty
- queryObject.appendQueryString(
- "CREATE TABLE " + keyspace + "." + tablename + " " + fieldsString);
+ queryObject.appendQueryString(
+ "CREATE TABLE " + keyspace + "." + tablename + " " + fieldsString);
- if (propertiesString != null && propertiesString.length()>0 )
- queryObject.appendQueryString(" WITH " + propertiesString);
+ if (propertiesString != null && propertiesString.length()>0 )
+ queryObject.appendQueryString(" WITH " + propertiesString);
queryObject.appendQueryString(";");
ResultType result = ResultType.FAILURE;
try {
@@ -641,17 +638,13 @@ public class RestMusicDataAPI {
.toMap()).build();
}
EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspace+" ) ");
- Map<String,String> userCredentials = MusicUtil.extractBasicAuthentication(authorization);
- String userId = userCredentials.get(MusicUtil.USERID);
- String password = userCredentials.get(MusicUtil.PASSWORD);
- Map<String, Object> authMap = MusicAuthentication.autheticateUser(ns, userId, password, keyspace,aid, "createIndex");
- if (authMap.containsKey("aid"))
- authMap.remove("aid");
- if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,authMap.get("Exception").toString(), AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
- response.status(Status.UNAUTHORIZED);
- return response.entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
- }
+ if (!authenticator.authenticateUser(ns, authorization, keyspace, aid, Operation.CREATE_INDEX)) {
+ return response.status(Status.UNAUTHORIZED)
+ .entity(new JsonResponse(ResultType.FAILURE)
+ .setError("Unauthorized: Please check username, password and make sure your app is onboarded")
+ .toMap()).build();
+ }
+
MultivaluedMap<String, String> rowParams = info.getQueryParameters();
String indexName = "";
if (rowParams.getFirst("index_name") != null)
@@ -711,23 +704,11 @@ public class RestMusicDataAPI {
.toMap()).build();
}
EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspace+" ) ");
- Map<String,String> userCredentials = MusicUtil.extractBasicAuthentication(authorization);
- String userId = userCredentials.get(MusicUtil.USERID);
- String password = userCredentials.get(MusicUtil.PASSWORD);
- Map<String, Object> authMap = null;
-
- try {
- authMap = MusicAuthentication.autheticateUser(ns, userId, password, keyspace,
- aid, "insertIntoTable");
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
- }
- if (authMap.containsKey("aid"))
- authMap.remove("aid");
- if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,authMap.get("Exception").toString(), AppMessages.MISSINGINFO ,ErrorSeverity.CRITICAL, ErrorTypes.AUTHENTICATIONERROR);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
+ if (!authenticator.authenticateUser(ns, authorization, keyspace, aid, Operation.INSERT_INTO_TABLE)) {
+ return response.status(Status.UNAUTHORIZED)
+ .entity(new JsonResponse(ResultType.FAILURE)
+ .setError("Unauthorized: Please check username, password and make sure your app is onboarded")
+ .toMap()).build();
}
Map<String, Object> valuesMap = insObj.getValues();
@@ -739,7 +720,7 @@ public class RestMusicDataAPI {
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Table name doesn't exists. Please check the table name.").toMap()).build();
}
} catch (MusicServiceException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
+ logger.error(EELFLoggerDelegate.errorLogger, e, AppMessages.UNKNOWNERROR ,ErrorSeverity.CRITICAL, ErrorTypes.GENERALSERVICEERROR);
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
}
String primaryKeyName = tableInfo.getPrimaryKey().get(0).getName();
@@ -770,7 +751,7 @@ public class RestMusicDataAPI {
try {
formattedValue = MusicUtil.convertToActualDataType(colType, valueObj);
} catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger,e);
}
valueString.append("?");
@@ -943,23 +924,13 @@ public class RestMusicDataAPI {
.toMap()).build();
}
EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspace+" ) ");
- Map<String,String> userCredentials = MusicUtil.extractBasicAuthentication(authorization);
- String userId = userCredentials.get(MusicUtil.USERID);
- String password = userCredentials.get(MusicUtil.PASSWORD);
- Map<String, Object> authMap;
- try {
- authMap = MusicAuthentication.autheticateUser(ns, userId, password, keyspace,
- aid, "updateTable");
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
- }
- if (authMap.containsKey("aid"))
- authMap.remove("aid");
- if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,authMap.get("Exception").toString(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
+ if (!authenticator.authenticateUser(ns, authorization, keyspace, aid, Operation.UPDATE_TABLE)) {
+ return response.status(Status.UNAUTHORIZED)
+ .entity(new JsonResponse(ResultType.FAILURE)
+ .setError("Unauthorized: Please check username, password and make sure your app is onboarded")
+ .toMap()).build();
}
+
long startTime = System.currentTimeMillis();
String operationId = UUID.randomUUID().toString();// just for infoging
// purposes.
@@ -976,7 +947,7 @@ public class RestMusicDataAPI {
try {
tableInfo = MusicDataStoreHandle.returnColumnMetadata(keyspace, tablename);
} catch (MusicServiceException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ logger.error(EELFLoggerDelegate.errorLogger,e, AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
}
if (tableInfo == null) {
@@ -996,14 +967,14 @@ public class RestMusicDataAPI {
try {
colType = tableInfo.getColumn(entry.getKey()).getType();
} catch(NullPointerException ex) {
- logger.error(EELFLoggerDelegate.errorLogger, "Invalid column name : "+entry.getKey());
+ logger.error(EELFLoggerDelegate.errorLogger, ex, "Invalid column name : "+entry.getKey());
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Invalid column name : "+entry.getKey()).toMap()).build();
}
Object valueString = null;
try {
valueString = MusicUtil.convertToActualDataType(colType, valueObj);
} catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger,e);
}
fieldValueString.append(entry.getKey() + "= ?");
queryObject.addValue(valueString);
@@ -1043,7 +1014,7 @@ public class RestMusicDataAPI {
.setError("Mandatory WHERE clause is missing. Please check the input request.").toMap()).build();
}
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ logger.error(EELFLoggerDelegate.errorLogger,ex, AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
@@ -1091,7 +1062,7 @@ public class RestMusicDataAPI {
operationResult = MusicCore.atomicPutWithDeleteLock(keyspace, tablename,
rowId.primarKeyValue, queryObject, conditionInfo);
} catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ logger.error(EELFLoggerDelegate.errorLogger,e, AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
}
} else if (consistency.equalsIgnoreCase(MusicUtil.ATOMIC)) {
@@ -1099,7 +1070,7 @@ public class RestMusicDataAPI {
operationResult = MusicCore.atomicPut(keyspace, tablename, rowId.primarKeyValue,
queryObject, conditionInfo);
} catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ logger.error(EELFLoggerDelegate.errorLogger,e, AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
}
}else if(consistency.equalsIgnoreCase(MusicUtil.EVENTUAL_NB)) {
@@ -1176,23 +1147,13 @@ public class RestMusicDataAPI {
.toMap()).build();
}
EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspace+" ) ");
- Map<String,String> userCredentials = MusicUtil.extractBasicAuthentication(authorization);
- String userId = userCredentials.get(MusicUtil.USERID);
- String password = userCredentials.get(MusicUtil.PASSWORD);
- Map<String, Object> authMap = null;
- try {
- authMap = MusicAuthentication.autheticateUser(ns, userId, password, keyspace,
- aid, "deleteFromTable");
- } catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(e.getMessage()).toMap()).build();
- }
- if (authMap.containsKey("aid"))
- authMap.remove("aid");
- if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,authMap.get("Exception").toString(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
+ if (!authenticator.authenticateUser(ns, authorization, keyspace, aid, Operation.DELETE_FROM_TABLE)) {
+ return response.status(Status.UNAUTHORIZED)
+ .entity(new JsonResponse(ResultType.FAILURE)
+ .setError("Unauthorized: Please check username, password and make sure your app is onboarded")
+ .toMap()).build();
}
+
if(delObj == null) {
logger.error(EELFLoggerDelegate.errorLogger,"Required HTTP Request body is missing.", AppMessages.MISSINGDATA ,ErrorSeverity.WARN, ErrorTypes.DATAERROR);
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError("Required HTTP Request body is missing.").toMap()).build();
@@ -1201,7 +1162,7 @@ public class RestMusicDataAPI {
StringBuilder columnString = new StringBuilder();
int counter = 0;
- ArrayList<String> columnList = delObj.getColumns();
+ List<String> columnList = delObj.getColumns();
if (columnList != null) {
for (String column : columnList) {
columnString.append(column);
@@ -1216,7 +1177,7 @@ public class RestMusicDataAPI {
try {
rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(), queryObject);
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ logger.error(EELFLoggerDelegate.errorLogger,ex, AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
String rowSpec = rowId.rowIdString.toString();
@@ -1286,7 +1247,7 @@ public class RestMusicDataAPI {
operationResult = MusicCore.eventualPut_nb(queryObject, keyspace, tablename, rowId.primarKeyValue);
}
} catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ logger.error(EELFLoggerDelegate.errorLogger,e, AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE)
.setError("Unable to perform Delete operation. Exception from music").toMap()).build();
}
@@ -1339,17 +1300,13 @@ public class RestMusicDataAPI {
.toMap()).build();
}
EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspace+" ) ");
- Map<String,String> userCredentials = MusicUtil.extractBasicAuthentication(authorization);
- String userId = userCredentials.get(MusicUtil.USERID);
- String password = userCredentials.get(MusicUtil.PASSWORD);
- Map<String, Object> authMap =
- MusicAuthentication.autheticateUser(ns, userId, password, keyspace, aid, "dropTable");
- if (authMap.containsKey("aid"))
- authMap.remove("aid");
- if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,authMap.get("Exception").toString(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
+ if (!authenticator.authenticateUser(ns, authorization, keyspace, aid, Operation.DROP_TABLE)) {
+ return response.status(Status.UNAUTHORIZED)
+ .entity(new JsonResponse(ResultType.FAILURE)
+ .setError("Unauthorized: Please check username, password and make sure your app is onboarded")
+ .toMap()).build();
}
+
String consistency = "eventual";// for now this needs only eventual
// consistency
PreparedQueryObject query = new PreparedQueryObject();
@@ -1357,7 +1314,7 @@ public class RestMusicDataAPI {
try {
return response.status(Status.OK).entity(new JsonResponse(MusicCore.nonKeyRelatedPut(query, consistency)).toMap()).build();
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ logger.error(EELFLoggerDelegate.errorLogger,ex, AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
} finally {
@@ -1403,16 +1360,13 @@ public class RestMusicDataAPI {
.toMap()).build();
}
EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspace+" ) ");
- Map<String,String> userCredentials = MusicUtil.extractBasicAuthentication(authorization);
- String userId = userCredentials.get(MusicUtil.USERID);
- String password = userCredentials.get(MusicUtil.PASSWORD);
- Map<String, Object> authMap = MusicAuthentication.autheticateUser(ns, userId, password, keyspace,aid, "selectCritical");
- if (authMap.containsKey("aid"))
- authMap.remove("aid");
- if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,authMap.get("Exception").toString(), AppMessages.MISSINGINFO ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
+ if (!authenticator.authenticateUser(ns, authorization, keyspace, aid, Operation.SELECT_CRITICAL)) {
+ return response.status(Status.UNAUTHORIZED)
+ .entity(new JsonResponse(ResultType.FAILURE)
+ .setError("Unauthorized: Please check username, password and make sure your app is onboarded")
+ .toMap()).build();
}
+
String lockId = selObj.getConsistencyInfo().get("lockId");
PreparedQueryObject queryObject = new PreparedQueryObject();
@@ -1421,7 +1375,7 @@ public class RestMusicDataAPI {
try {
rowId = getRowIdentifier(keyspace, tablename, info.getQueryParameters(), queryObject);
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ logger.error(EELFLoggerDelegate.errorLogger,ex, AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
queryObject.appendQueryString(
@@ -1493,17 +1447,13 @@ public class RestMusicDataAPI {
.toMap()).build();
}
EELFLoggerDelegate.mdcPut("keyspace", "( "+keyspace+" ) ");
- Map<String,String> userCredentials = MusicUtil.extractBasicAuthentication(authorization);
- String userId = userCredentials.get(MusicUtil.USERID);
- String password = userCredentials.get(MusicUtil.PASSWORD);
- Map<String, Object> authMap =
- MusicAuthentication.autheticateUser(ns, userId, password, keyspace, aid, "select");
- if (authMap.containsKey("aid"))
- authMap.remove("aid");
- if (!authMap.isEmpty()) {
- logger.error(EELFLoggerDelegate.errorLogger,authMap.get("Exception").toString(), AppMessages.AUTHENTICATIONERROR ,ErrorSeverity.WARN, ErrorTypes.AUTHENTICATIONERROR);
- return response.status(Status.UNAUTHORIZED).entity(new JsonResponse(ResultType.FAILURE).setError(String.valueOf(authMap.get("Exception"))).toMap()).build();
+ if (!authenticator.authenticateUser(ns, authorization, keyspace, aid, Operation.SELECT)) {
+ return response.status(Status.UNAUTHORIZED)
+ .entity(new JsonResponse(ResultType.FAILURE)
+ .setError("Unauthorized: Please check username, password and make sure your app is onboarded")
+ .toMap()).build();
}
+
PreparedQueryObject queryObject = new PreparedQueryObject();
if (info.getQueryParameters().isEmpty())// select all
@@ -1511,10 +1461,9 @@ public class RestMusicDataAPI {
else {
int limit = -1; // do not limit the number of results
try {
- queryObject = selectSpecificQuery(VERSION, minorVersion, patchVersion, aid, ns,
- userId, password, keyspace, tablename, info, limit);
+ queryObject = selectSpecificQuery(keyspace, tablename, info, limit);
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
+ logger.error(EELFLoggerDelegate.errorLogger, ex, AppMessages.UNKNOWNERROR ,ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
}
@@ -1526,7 +1475,7 @@ public class RestMusicDataAPI {
}
return response.status(Status.OK).entity(new JsonResponse(ResultType.SUCCESS).setDataResult(MusicDataStoreHandle.marshallResults(results)).setError("No data found").toMap()).build();
} catch (MusicServiceException ex) {
- logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.ERROR, ErrorTypes.MUSICSERVICEERROR);
+ logger.error(EELFLoggerDelegate.errorLogger, ex, AppMessages.UNKNOWNERROR ,ErrorSeverity.ERROR, ErrorTypes.MUSICSERVICEERROR);
return response.status(Status.BAD_REQUEST).entity(new JsonResponse(ResultType.FAILURE).setError(ex.getMessage()).toMap()).build();
}
} finally {
@@ -1543,9 +1492,8 @@ public class RestMusicDataAPI {
* @return
* @throws MusicServiceException
*/
- public PreparedQueryObject selectSpecificQuery(String version, String minorVersion,
- String patchVersion, String aid, String ns, String userId, String password,
- String keyspace, String tablename, UriInfo info, int limit)
+ public PreparedQueryObject selectSpecificQuery(String keyspace,
+ String tablename, UriInfo info, int limit)
throws MusicServiceException {
PreparedQueryObject queryObject = new PreparedQueryObject();
@@ -1598,7 +1546,7 @@ public class RestMusicDataAPI {
colType = tableInfo.getColumn(entry.getKey()).getType();
formattedValue = MusicUtil.convertToActualDataType(colType, indValue);
} catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage());
+ logger.error(EELFLoggerDelegate.errorLogger,e);
}
if(tableInfo.getPrimaryKey().get(0).getName().equals(entry.getKey()))
primaryKey.append(indValue);
diff --git a/src/main/java/org/onap/music/rest/RestMusicQAPI.java b/src/main/java/org/onap/music/rest/RestMusicQAPI.java
index 4164f27f..800dad71 100755
--- a/src/main/java/org/onap/music/rest/RestMusicQAPI.java
+++ b/src/main/java/org/onap/music/rest/RestMusicQAPI.java
@@ -377,8 +377,7 @@ public class RestMusicQAPI {
else {
try {
- queryObject = new RestMusicDataAPI().selectSpecificQuery(version, minorVersion,
- patchVersion, aid, ns, userId, password, keyspace, tablename, info, limit);
+ queryObject = new RestMusicDataAPI().selectSpecificQuery(keyspace, tablename, info, limit);
} catch (MusicServiceException ex) {
logger.error(EELFLoggerDelegate.errorLogger, "", AppMessages.UNKNOWNERROR,
ErrorSeverity.WARN, ErrorTypes.GENERALSERVICEERROR);
diff --git a/src/main/java/org/onap/music/service/impl/MusicCassaCore.java b/src/main/java/org/onap/music/service/impl/MusicCassaCore.java
index 8737a060..cb6e1ce4 100644
--- a/src/main/java/org/onap/music/service/impl/MusicCassaCore.java
+++ b/src/main/java/org/onap/music/service/impl/MusicCassaCore.java
@@ -3,6 +3,9 @@
* org.onap.music
* ===================================================================
* Copyright (c) 2017 AT&T Intellectual Property
+ * Modifications Copyright (c) 2018 IBM.
+ * ===================================================================
+ * Modifications Copyright (c) 2019 Samsung
* ===================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +26,6 @@
package org.onap.music.service.impl;
import java.io.StringWriter;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
@@ -47,13 +49,10 @@ import org.onap.music.main.ResultType;
import org.onap.music.main.ReturnType;
import org.onap.music.service.MusicCoreService;
-import com.datastax.driver.core.ColumnDefinitions;
-import com.datastax.driver.core.ColumnDefinitions.Definition;
import com.datastax.driver.core.DataType;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.TableMetadata;
-import com.google.common.util.concurrent.Monitor.Guard;
import org.onap.music.datastore.*;
@@ -63,18 +62,18 @@ public class MusicCassaCore implements MusicCoreService {
private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicCassaCore.class);
private static boolean unitTestRun=true;
private static MusicCassaCore musicCassaCoreInstance = null;
-
+
private MusicCassaCore() {
-
+
}
public static MusicCassaCore getInstance() {
-
+
if(musicCassaCoreInstance == null) {
musicCassaCoreInstance = new MusicCassaCore();
}
return musicCassaCoreInstance;
}
-
+
public static CassaLockStore getLockingServiceHandle() throws MusicLockingException {
logger.info(EELFLoggerDelegate.applicationLogger,"Acquiring lock store handle");
long start = System.currentTimeMillis();
@@ -127,19 +126,19 @@ public class MusicCassaCore implements MusicCoreService {
String primaryKeyValue = splitString[2];
LockObject currentLockHolderObject = getLockingServiceHandle().peekLockQueue(keyspace, table, primaryKeyValue);
-
- /* Release the lock of the previous holder if it has expired. if the update to the acquire time has not reached due to network delays, simply use the create time as the
+
+ /* Release the lock of the previous holder if it has expired. if the update to the acquire time has not reached due to network delays, simply use the create time as the
* reference*/
-
+
long referenceTime = Math.max(Long.parseLong(currentLockHolderObject.acquireTime), Long.parseLong(currentLockHolderObject.createTime));
if((System.currentTimeMillis() - referenceTime) > leasePeriod) {
forciblyReleaseLock(fullyQualifiedKey, currentLockHolderObject.lockRef+"");
logger.info(EELFLoggerDelegate.applicationLogger, currentLockHolderObject.lockRef+" forcibly released");
- }
+ }
}
-
+
private static ReturnType isTopOfLockStore(String keyspace, String table, String primaryKeyValue, String lockReference) throws MusicLockingException, MusicQueryException, MusicServiceException {
-
+
//return failure to lock holders too early or already evicted from the lock store
String topOfLockStoreS = getLockingServiceHandle().peekLockQueue(keyspace, table, primaryKeyValue).lockRef;
long topOfLockStoreL = Long.parseLong(topOfLockStoreS);
@@ -149,36 +148,36 @@ public class MusicCassaCore implements MusicCoreService {
logger.info(EELFLoggerDelegate.applicationLogger, lockReference+" is not the lock holder yet");
return new ReturnType(ResultType.FAILURE, lockReference+" is not the lock holder yet");
}
-
+
if(lockReferenceL < topOfLockStoreL) {
logger.info(EELFLoggerDelegate.applicationLogger, lockReference+" is no longer/or was never in the lock store queue");
return new ReturnType(ResultType.FAILURE, lockReference+" is no longer/or was never in the lock store queue");
}
-
+
return new ReturnType(ResultType.SUCCESS, lockReference+" is top of lock store");
}
-
+
public ReturnType acquireLock(String fullyQualifiedKey, String lockId)
throws MusicLockingException, MusicQueryException, MusicServiceException {
String[] splitString = lockId.split("\\.");
String keyspace = splitString[0].substring(1);//remove '$'
String table = splitString[1];
String primaryKeyValue = splitString[2].substring(0, splitString[2].lastIndexOf("$"));
- fullyQualifiedKey = lockId.substring(1, lockId.lastIndexOf("$"));
+ String localFullyQualifiedKey = lockId.substring(1, lockId.lastIndexOf("$"));
String lockRef = lockId.substring(lockId.lastIndexOf("$")+1); //lockRef is "$" to end
-
+
ReturnType result = isTopOfLockStore(keyspace, table, primaryKeyValue, lockRef);
-
+
if(result.getResult().equals(ResultType.FAILURE))
return result;//not top of the lock store q
-
+
//check to see if the value of the key has to be synced in case there was a forceful release
String syncTable = keyspace+".unsyncedKeys_"+table;
- String query = "select * from "+syncTable+" where key='"+fullyQualifiedKey+"';";
+ String query = "select * from "+syncTable+" where key='"+localFullyQualifiedKey+"';";
PreparedQueryObject readQueryObject = new PreparedQueryObject();
readQueryObject.appendQueryString(query);
- ResultSet results = MusicDataStoreHandle.getDSHandle().executeQuorumConsistencyGet(readQueryObject);
+ ResultSet results = MusicDataStoreHandle.getDSHandle().executeQuorumConsistencyGet(readQueryObject);
if (results.all().size() != 0) {
logger.info("In acquire lock: Since there was a forcible release, need to sync quorum!");
try {
@@ -187,54 +186,53 @@ public class MusicCassaCore implements MusicCoreService {
StringWriter sw = new StringWriter();
logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), "[ERR506E] Failed to aquire lock ",ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
String exceptionAsString = sw.toString();
- return new ReturnType(ResultType.FAILURE, "Exception thrown while syncing key:\n" + exceptionAsString);
+ return new ReturnType(ResultType.FAILURE, "Exception thrown while syncing key:\n" + exceptionAsString);
}
- String cleanQuery = "delete from music_internal.unsynced_keys where key='"+fullyQualifiedKey+"';";
+ String cleanQuery = "delete from music_internal.unsynced_keys where key='"+localFullyQualifiedKey+"';";
PreparedQueryObject deleteQueryObject = new PreparedQueryObject();
deleteQueryObject.appendQueryString(cleanQuery);
MusicDataStoreHandle.getDSHandle().executePut(deleteQueryObject, "critical");
}
-
+
getLockingServiceHandle().updateLockAcquireTime(keyspace, table, primaryKeyValue, lockRef);
-
+
return new ReturnType(ResultType.SUCCESS, lockRef+" is the lock holder for the key");
}
/**
- *
+ *
* @param tableQueryObject
* @param consistency
* @return Boolean Indicates success or failure
- * @throws MusicServiceException
- *
- *
+ * @throws MusicServiceException
+ *
+ *
*/
public ResultType createTable(String keyspace, String table, PreparedQueryObject tableQueryObject, String consistency) throws MusicServiceException {
boolean result = false;
-
+
try {
- //create shadow locking table
+ //create shadow locking table
result = getLockingServiceHandle().createLockQueue(keyspace, table);
- if(result == false)
+ if(result == false)
return ResultType.FAILURE;
-
+
result = false;
-
+
//create table to track unsynced_keys
- table = "unsyncedKeys_"+table;
-
+ table = "unsyncedKeys_"+table;
+
String tabQuery = "CREATE TABLE IF NOT EXISTS "+keyspace+"."+table
+ " ( key text,PRIMARY KEY (key) );";
- System.out.println(tabQuery);
- PreparedQueryObject queryObject = new PreparedQueryObject();
-
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+
queryObject.appendQueryString(tabQuery);
result = false;
result = MusicDataStoreHandle.getDSHandle().executePut(queryObject, "eventual");
-
+
//create actual table
result = MusicDataStoreHandle.getDSHandle().executePut(tableQueryObject, consistency);
} catch (MusicQueryException | MusicServiceException | MusicLockingException ex) {
@@ -261,43 +259,13 @@ public class MusicCassaCore implements MusicCoreService {
selectQuery.appendQueryString("SELECT * FROM " + keyspace + "." + table + " WHERE "
+ primaryKeyName + "= ?" + ";");
selectQuery.addValue(cqlFormattedPrimaryKeyValue);
- ResultSet results = null;
- try {
- results = MusicDataStoreHandle.getDSHandle().executeQuorumConsistencyGet(selectQuery);
- // write it back to a quorum
- Row row = results.one();
- ColumnDefinitions colInfo = row.getColumnDefinitions();
- int totalColumns = colInfo.size();
- int counter = 1;
- StringBuilder fieldValueString = new StringBuilder("");
- for (Definition definition : colInfo) {
- String colName = definition.getName();
- if (colName.equals(primaryKeyName))
- continue;
- DataType colType = definition.getType();
- Object valueObj = MusicDataStoreHandle.getDSHandle().getColValue(row, colName, colType);
- Object valueString = MusicUtil.convertToActualDataType(colType, valueObj);
- fieldValueString.append(colName + " = ?");
- updateQuery.addValue(valueString);
- if (counter != (totalColumns - 1))
- fieldValueString.append(",");
- counter = counter + 1;
- }
- updateQuery.appendQueryString("UPDATE " + keyspace + "." + table + " SET "
- + fieldValueString + " WHERE " + primaryKeyName + "= ? " + ";");
- updateQuery.addValue(cqlFormattedPrimaryKeyValue);
+ MusicUtil.writeBackToQuorum(selectQuery, primaryKeyName, updateQuery, keyspace, table,
+ cqlFormattedPrimaryKeyValue);
- MusicDataStoreHandle.getDSHandle().executePut(updateQuery, "critical");
- } catch (MusicServiceException | MusicQueryException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.QUERYERROR +""+updateQuery ,ErrorSeverity.MAJOR, ErrorTypes.QUERYERROR);
- }
}
-
-
-
/**
- *
+ *
* @param query
* @return ResultSet
*/
@@ -307,16 +275,14 @@ public class MusicCassaCore implements MusicCoreService {
results = MusicDataStoreHandle.getDSHandle().executeQuorumConsistencyGet(query);
} catch (MusicServiceException | MusicQueryException e) {
logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.UNKNOWNERROR ,ErrorSeverity.MAJOR, ErrorTypes.GENERALSERVICEERROR);
-
+
}
return results;
}
-
-
/**
- *
+ *
* @param fullyQualifiedKey lockName
* @return
*/
@@ -326,7 +292,7 @@ public class MusicCassaCore implements MusicCoreService {
String table = splitString[1];
String primaryKeyValue = splitString[2];
try {
- return "$" + fullyQualifiedKey + "$"
+ return "$" + fullyQualifiedKey + "$"
+ getLockingServiceHandle().peekLockQueue(keyspace, table, primaryKeyValue).lockRef;
} catch (MusicLockingException | MusicServiceException | MusicQueryException e) {
logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.LOCKINGERROR+fullyQualifiedKey ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
@@ -335,7 +301,7 @@ public class MusicCassaCore implements MusicCoreService {
}
/**
- *
+ *
* @param lockReference
* @return
*/
@@ -357,11 +323,11 @@ public class MusicCassaCore implements MusicCoreService {
getLockingServiceHandle().deQueueLockRef(keyspace, table, primaryKeyValue, lockRef);
} catch (MusicLockingException | MusicServiceException | MusicQueryException e) {
logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.DESTROYLOCK+lockRef ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
+ }
long end = System.currentTimeMillis();
logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to destroy lock reference:" + (end - start) + " ms");
}
-
+
public MusicLockState destroyLockRef(String fullyQualifiedKey, String lockReference) {
long start = System.currentTimeMillis();
String[] splitString = fullyQualifiedKey.split("\\.");
@@ -372,7 +338,7 @@ public class MusicCassaCore implements MusicCoreService {
getLockingServiceHandle().deQueueLockRef(keyspace, table, primaryKeyValue, lockReference);
} catch (MusicLockingException | MusicServiceException | MusicQueryException e) {
logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.DESTROYLOCK+lockReference ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
+ }
long end = System.currentTimeMillis();
logger.info(EELFLoggerDelegate.applicationLogger,"Time taken to destroy lock reference:" + (end - start) + " ms");
return new MusicLockState(LockStatus.UNLOCKED, "");
@@ -388,7 +354,7 @@ public class MusicCassaCore implements MusicCoreService {
return forciblyReleaseLock(fullyQualifiedKey, lockRef);
}
}
-
+
public MusicLockState voluntaryReleaseLock(String fullyQualifiedKey, String lockReference) {
return destroyLockRef(fullyQualifiedKey, lockReference);
}
@@ -399,7 +365,7 @@ public class MusicCassaCore implements MusicCoreService {
String table = splitString[1];
//leave a signal that this key could potentially be unsynchronized
- String syncTable = keyspace+".unsyncedKeys_"+table;
+ String syncTable = keyspace+".unsyncedKeys_"+table;
PreparedQueryObject queryObject = new PreparedQueryObject();
String values = "(?)";
queryObject.addValue(fullyQualifiedKey);
@@ -408,18 +374,18 @@ public class MusicCassaCore implements MusicCoreService {
try {
MusicDataStoreHandle.getDSHandle().executePut(queryObject, "critical");
} catch (Exception e) {
- logger.error("Cannot forcibly release lock: " + fullyQualifiedKey + " " + lockReference + ". "
+ logger.error("Cannot forcibly release lock: " + fullyQualifiedKey + " " + lockReference + ". "
+ e.getMessage());
}
-
+
//now release the lock
return destroyLockRef(fullyQualifiedKey, lockReference);
}
/**
- *
+ *
* @param lockName
- * @throws MusicLockingException
+ * @throws MusicLockingException
*/
public void deleteLock(String lockName) throws MusicLockingException {
//deprecated
@@ -428,7 +394,7 @@ public class MusicCassaCore implements MusicCoreService {
// Prepared Query Additions.
/**
- *
+ *
* @param queryObject
* @return ReturnType
* @throws MusicServiceException
@@ -448,9 +414,9 @@ public class MusicCassaCore implements MusicCoreService {
return new ReturnType(ResultType.FAILURE, "Eventual Operation failed to perform");
}
}
-
+
/**
- *
+ *
* @param queryObject
* @return ReturnType
* @throws MusicServiceException
@@ -477,10 +443,10 @@ public class MusicCassaCore implements MusicCoreService {
}
queryObject.replaceQueryString(query);
}
-
+
} catch (MusicServiceException | MusicQueryException e) {
logger.error(EELFLoggerDelegate.applicationLogger,e.getMessage());
- }
+ }
try {
result = MusicDataStoreHandle.getDSHandle().executePut(queryObject, MusicUtil.EVENTUAL);
} catch (MusicServiceException | MusicQueryException ex) {
@@ -494,9 +460,9 @@ public class MusicCassaCore implements MusicCoreService {
return new ReturnType(ResultType.FAILURE, "Eventual Operation failed to perform");
}
}
-
+
/**
- *
+ *
* @param keyspace
* @param table
* @param primaryKeyValue
@@ -523,7 +489,7 @@ public class MusicCassaCore implements MusicCoreService {
"Exception thrown while checking the condition, check its sanctity:\n"
+ e.getMessage());
}
-
+
String query = queryObject.getQuery();
long timeOfWrite = System.currentTimeMillis();
long lockOrdinal = Long.parseLong(lockId.substring(lockId.lastIndexOf("$")+1));
@@ -551,15 +517,15 @@ public class MusicCassaCore implements MusicCoreService {
return new ReturnType(ResultType.SUCCESS, "Update performed");
}
-
+
/**
- *
+ *
* @param queryObject
* @param consistency
* @return Boolean Indicates success or failure
- * @throws MusicServiceException
- *
- *
+ * @throws MusicServiceException
+ *
+ *
*/
public ResultType nonKeyRelatedPut(PreparedQueryObject queryObject, String consistency) throws MusicServiceException {
// this is mainly for some functions like keyspace creation etc which does not
@@ -577,10 +543,10 @@ public class MusicCassaCore implements MusicCoreService {
/**
* This method performs DDL operation on cassandra.
- *
+ *
* @param queryObject query object containing prepared query and values
* @return ResultSet
- * @throws MusicServiceException
+ * @throws MusicServiceException
*/
public ResultSet get(PreparedQueryObject queryObject) throws MusicServiceException {
ResultSet results = null;
@@ -596,7 +562,7 @@ public class MusicCassaCore implements MusicCoreService {
/**
* This method performs DDL operations on cassandra, if the the resource is available. Lock ID
* is used to check if the resource is free.
- *
+ *
* @param keyspace name of the keyspace
* @param table name of the table
* @param primaryKeyValue primary key value
@@ -607,9 +573,9 @@ public class MusicCassaCore implements MusicCoreService {
public ResultSet criticalGet(String keyspace, String table, String primaryKeyValue,
PreparedQueryObject queryObject, String lockId) throws MusicServiceException {
ResultSet results = null;
-
+
try {
- ReturnType result = isTopOfLockStore(keyspace, table, primaryKeyValue,
+ ReturnType result = isTopOfLockStore(keyspace, table, primaryKeyValue,
lockId.substring(lockId.lastIndexOf("$")+1));
if(result.getResult().equals(ResultType.FAILURE))
return null;//not top of the lock store q
@@ -622,15 +588,15 @@ public class MusicCassaCore implements MusicCoreService {
/**
* This method performs DML operation on cassandra, when the lock of the dd is acquired.
- *
+ *
* @param keyspaceName name of the keyspace
* @param tableName name of the table
* @param primaryKey primary key value
* @param queryObject query object containing prepared query and values
* @return ReturnType
- * @throws MusicLockingException
- * @throws MusicServiceException
- * @throws MusicQueryException
+ * @throws MusicLockingException
+ * @throws MusicServiceException
+ * @throws MusicQueryException
*/
public ReturnType atomicPut(String keyspaceName, String tableName, String primaryKey,
PreparedQueryObject queryObject, Condition conditionInfo) throws MusicLockingException, MusicQueryException, MusicServiceException {
@@ -661,21 +627,21 @@ public class MusicCassaCore implements MusicCoreService {
criticalPutResult.setTimingInfo(timingInfo);
return criticalPutResult;
}
-
+
/**
* This method performs DDL operation on cassasndra, when the lock for the resource is acquired.
- *
+ *
* @param keyspaceName name of the keyspace
* @param tableName name of the table
* @param primaryKey primary key value
* @param queryObject query object containing prepared query and values
* @return ResultSet
* @throws MusicServiceException
- * @throws MusicLockingException
- * @throws MusicQueryException
+ * @throws MusicLockingException
+ * @throws MusicQueryException
*/
public ResultSet atomicGet(String keyspaceName, String tableName, String primaryKey,
PreparedQueryObject queryObject) throws MusicServiceException, MusicLockingException, MusicQueryException {
@@ -697,34 +663,15 @@ public class MusicCassaCore implements MusicCoreService {
}
}
-
-
+
+
/**
* @param lockName
* @return
*/
public Map<String, Object> validateLock(String lockName) {
- Map<String, Object> resultMap = new HashMap<>();
- String[] locks = lockName.split("\\.");
- if(locks.length < 3) {
- resultMap.put("Error", "Invalid lock. Please make sure lock is of the type keyspaceName.tableName.primaryKey");
- return resultMap;
- }
- String keyspace= locks[0];
- if(keyspace.startsWith("$"))
- keyspace = keyspace.substring(1);
- resultMap.put("keyspace",keyspace);
- return resultMap;
+ return MusicUtil.validateLock(lockName);
}
-
-
- public static void main(String[] args) {
- String x = "axe top";
- x = x.replaceFirst("top", "sword");
- System.out.print(x); //returns sword pickaxe
- }
-
-
@Override
public ReturnType atomicPutWithDeleteLock(String keyspaceName, String tableName, String primaryKey,
diff --git a/src/main/java/org/onap/music/service/impl/MusicZKCore.java b/src/main/java/org/onap/music/service/impl/MusicZKCore.java
index 1662b20c..93c5abc8 100644
--- a/src/main/java/org/onap/music/service/impl/MusicZKCore.java
+++ b/src/main/java/org/onap/music/service/impl/MusicZKCore.java
@@ -4,6 +4,8 @@
* ===================================================================
* Copyright (c) 2017 AT&T Intellectual Property
* ===================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ===================================================================
* 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
@@ -24,17 +26,12 @@ package org.onap.music.service.impl;
import java.io.StringWriter;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
-import javax.ws.rs.core.MediaType;
-
-import org.apache.commons.jcs.access.CacheAccess;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.KeeperException.NoNodeException;
-import org.onap.music.datastore.MusicDataStore;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.datastore.jsonobjects.JsonKeySpace;
import org.onap.music.eelf.logging.EELFLoggerDelegate;
@@ -53,15 +50,10 @@ import org.onap.music.main.ReturnType;
import org.onap.music.service.MusicCoreService;
import org.onap.music.datastore.*;
-import com.datastax.driver.core.ColumnDefinitions;
-import com.datastax.driver.core.ColumnDefinitions.Definition;
import com.datastax.driver.core.DataType;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.TableMetadata;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.WebResource;
/**
* This class .....
@@ -73,18 +65,18 @@ public class MusicZKCore implements MusicCoreService {
public static MusicLockingService mLockHandle = null;
private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicZKCore.class);
private static MusicZKCore musicZKCoreInstance = null;
-
+
private MusicZKCore() {
-
+
}
public static MusicZKCore getInstance() {
-
+
if(musicZKCoreInstance == null) {
musicZKCoreInstance = new MusicZKCore();
}
return musicZKCoreInstance;
}
-
+
@@ -344,36 +336,8 @@ public class MusicZKCore implements MusicCoreService {
selectQuery.appendQueryString("SELECT * FROM " + keyspaceName + "." + tableName + " WHERE "
+ primaryKeyName + "= ?" + ";");
selectQuery.addValue(cqlFormattedPrimaryKeyValue);
- ResultSet results = null;
- try {
- results = MusicDataStoreHandle.getDSHandle().executeQuorumConsistencyGet(selectQuery);
- // write it back to a quorum
- Row row = results.one();
- ColumnDefinitions colInfo = row.getColumnDefinitions();
- int totalColumns = colInfo.size();
- int counter = 1;
- StringBuilder fieldValueString = new StringBuilder("");
- for (Definition definition : colInfo) {
- String colName = definition.getName();
- if (colName.equals(primaryKeyName))
- continue;
- DataType colType = definition.getType();
- Object valueObj = MusicDataStoreHandle.getDSHandle().getColValue(row, colName, colType);
- Object valueString = MusicUtil.convertToActualDataType(colType, valueObj);
- fieldValueString.append(colName + " = ?");
- updateQuery.addValue(valueString);
- if (counter != (totalColumns - 1))
- fieldValueString.append(",");
- counter = counter + 1;
- }
- updateQuery.appendQueryString("UPDATE " + keyspaceName + "." + tableName + " SET "
- + fieldValueString + " WHERE " + primaryKeyName + "= ? " + ";");
- updateQuery.addValue(cqlFormattedPrimaryKeyValue);
-
- MusicDataStoreHandle.getDSHandle().executePut(updateQuery, "critical");
- } catch (MusicServiceException | MusicQueryException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.QUERYERROR +""+updateQuery ,ErrorSeverity.MAJOR, ErrorTypes.QUERYERROR);
- }
+ MusicUtil.writeBackToQuorum(selectQuery, primaryKeyName, updateQuery, keyspaceName, tableName,
+ cqlFormattedPrimaryKeyValue);
}
@@ -843,47 +807,34 @@ public class MusicZKCore implements MusicCoreService {
* @return
*/
public Map<String, Object> validateLock(String lockName) {
- Map<String, Object> resultMap = new HashMap<>();
- String[] locks = lockName.split("\\.");
- if(locks.length < 3) {
- resultMap.put("Error", "Invalid lock. Please make sure lock is of the type keyspaceName.tableName.primaryKey");
- return resultMap;
- }
- String keyspace= locks[0];
- if(keyspace.startsWith("$"))
- keyspace = keyspace.substring(1);
- resultMap.put("keyspace",keyspace);
- return resultMap;
+ return MusicUtil.validateLock(lockName);
}
-
-
@Override
public ResultType createTable(String keyspace, String table, PreparedQueryObject tableQueryObject,
String consistency) throws MusicServiceException {
boolean result = false;
-
try {
- //create shadow locking table
- result = createLockQueue(keyspace, table);
- if(result == false)
- return ResultType.FAILURE;
+ //create shadow locking table
+ //result = createLockQueue(keyspace, table);
+ if(result == false)
+ return ResultType.FAILURE;
result = false;
-
+
//create table to track unsynced_keys
- table = "unsyncedKeys_"+table;
-
+ table = "unsyncedKeys_"+table;
+
String tabQuery = "CREATE TABLE IF NOT EXISTS "+keyspace+"."+table
+ " ( key text,PRIMARY KEY (key) );";
System.out.println(tabQuery);
- PreparedQueryObject queryObject = new PreparedQueryObject();
-
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+
queryObject.appendQueryString(tabQuery);
result = false;
result = MusicDataStoreHandle.getDSHandle().executePut(queryObject, "eventual");
-
+
//create actual table
result = MusicDataStoreHandle.getDSHandle().executePut(tableQueryObject, consistency);
} catch (MusicQueryException | MusicServiceException ex) {
@@ -892,17 +843,17 @@ public class MusicZKCore implements MusicCoreService {
}
return result?ResultType.SUCCESS:ResultType.FAILURE;
}
-
+
public static boolean createLockQueue(String keyspace, String table) throws MusicServiceException, MusicQueryException {
logger.info(EELFLoggerDelegate.applicationLogger,
"Create lock queue/table for " + keyspace+"."+table);
- table = "lockQ_"+table;
+ table = "lockQ_"+table;
String tabQuery = "CREATE TABLE IF NOT EXISTS "+keyspace+"."+table
+ " ( key text, lockReference bigint, createTime text, acquireTime text, guard bigint static, PRIMARY KEY ((key), lockReference) ) "
+ "WITH CLUSTERING ORDER BY (lockReference ASC);";
System.out.println(tabQuery);
- PreparedQueryObject queryObject = new PreparedQueryObject();
-
+ PreparedQueryObject queryObject = new PreparedQueryObject();
+
queryObject.appendQueryString(tabQuery);
boolean result;
result = MusicDataStoreHandle.mDstoreHandle.executePut(queryObject, "eventual");
diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml
index 8d3164f0..6bc5fd5e 100644
--- a/src/main/resources/logback.xml
+++ b/src/main/resources/logback.xml
@@ -292,7 +292,7 @@
<root level="INFO">
<appender-ref ref="asyncEELF" />
- <appender-ref ref="STDOUT" />
+ <!-- <appender-ref ref="STDOUT" /> -->
</root>
<!-- Conductor Specific additions to squash WARNING and INFO -->
diff --git a/src/test/java/org/onap/music/unittests/CassandraCQL.java b/src/test/java/org/onap/music/unittests/CassandraCQL.java
index 4ae78236..32072145 100644
--- a/src/test/java/org/onap/music/unittests/CassandraCQL.java
+++ b/src/test/java/org/onap/music/unittests/CassandraCQL.java
@@ -27,7 +27,6 @@ package org.onap.music.unittests;
*
*/
-import java.io.IOException;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.NetworkInterface;
@@ -35,7 +34,6 @@ import java.net.SocketException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@@ -47,36 +45,42 @@ import org.onap.music.datastore.PreparedQueryObject;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
-import com.datastax.driver.core.exceptions.NoHostAvailableException;
public class CassandraCQL {
-
+ public static final String createAdminKeyspace = "CREATE KEYSPACE admin WITH REPLICATION = "
+ + "{'class' : 'SimpleStrategy' , 'replication_factor': 1} AND DURABLE_WRITES = true";
+
+ public static final String createAdminTable = "CREATE TABLE admin.keyspace_master (" + " uuid uuid, keyspace_name text,"
+ + " application_name text, is_api boolean,"
+ + " password text, username text,"
+ + " is_aaf boolean, PRIMARY KEY (uuid)\n" + ");";
+
public static final String createKeySpace =
- "CREATE KEYSPACE IF NOT EXISTS testCassa WITH replication = "
+ "CREATE KEYSPACE IF NOT EXISTS testcassa WITH replication = "
+"{'class':'SimpleStrategy','replication_factor':1} AND durable_writes = true;";
- public static final String dropKeyspace = "DROP KEYSPACE IF EXISTS testCassa";
+ public static final String dropKeyspace = "DROP KEYSPACE IF EXISTS testcassa";
public static final String createTableEmployees =
- "CREATE TABLE IF NOT EXISTS testCassa.employees "
- + "(vector_ts text,empId uuid,empName text,empSalary varint,address Map<text,text>,PRIMARY KEY (empName)) "
+ "CREATE TABLE IF NOT EXISTS testcassa.employees "
+ + "(vector_ts text,empid uuid,empname text,empsalary varint,address Map<text,text>,PRIMARY KEY (empname)) "
+ "WITH comment='Financial Info of employees' "
+ "AND compression={'sstable_compression':'DeflateCompressor','chunk_length_kb':64} "
+ "AND compaction={'class':'SizeTieredCompactionStrategy','min_threshold':6};";
public static final String insertIntoTablePrepared1 =
- "INSERT INTO testCassa.employees (vector_ts,empId,empName,empSalary) VALUES (?,?,?,?); ";
+ "INSERT INTO testcassa.employees (vector_ts,empid,empname,empsalary) VALUES (?,?,?,?); ";
public static final String insertIntoTablePrepared2 =
- "INSERT INTO testCassa.employees (vector_ts,empId,empName,empSalary,address) VALUES (?,?,?,?,?);";
+ "INSERT INTO testcassa.employees (vector_ts,empid,empname,empsalary,address) VALUES (?,?,?,?,?);";
- public static final String selectALL = "SELECT * FROM testCassa.employees;";
+ public static final String selectALL = "SELECT * FROM testcassa.employees;";
public static final String selectSpecific =
- "SELECT * FROM testCassa.employees WHERE empName= ?;";
+ "SELECT * FROM testcassa.employees WHERE empname= ?;";
public static final String updatePreparedQuery =
- "UPDATE testCassa.employees SET vector_ts=?,address= ? WHERE empName= ?;";
+ "UPDATE testcassa.employees SET vector_ts=?,address= ? WHERE empname= ?;";
public static final String deleteFromTable = " ";
@@ -223,33 +227,17 @@ public class CassandraCQL {
return allPossibleIps;
}
- public static MusicDataStore connectToEmbeddedCassandra() {
- Iterator<String> it = getAllPossibleLocalIps().iterator();
+ public static MusicDataStore connectToEmbeddedCassandra() throws Exception {
+ System.setProperty("log4j.configuration", "log4j.properties");
+
String address = "localhost";
- Cluster cluster = null;
- Session session = null;
- while (it.hasNext()) {
- try {
-
- try {
- EmbeddedCassandraServerHelper.startEmbeddedCassandra();
- } catch (Exception e) {
- e.printStackTrace();
- }
- cluster = new Cluster.Builder().withoutJMXReporting().withoutMetrics().addContactPoint(address).withPort(9142).build();
- cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(5000);
- session = cluster.connect();
-
- break;
- } catch (NoHostAvailableException e) {
- address = it.next();
- System.out.println(e.getMessage());
-
- }
- }
+ EmbeddedCassandraServerHelper.startEmbeddedCassandra();
+ Cluster cluster = new Cluster.Builder().withoutJMXReporting().withoutMetrics().addContactPoint(address).withPort(9142).build();
+ cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(5000);
+ Session session = cluster.connect();
+
return new MusicDataStore(cluster, session);
-
}
}
diff --git a/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java b/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java
index ab10335e..ec17d17d 100644
--- a/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java
+++ b/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java
@@ -34,10 +34,10 @@ import org.junit.runners.MethodSorters;
import org.mockito.Mock;
import org.onap.music.exceptions.MusicQueryException;
import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.main.CachingUtil;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.onap.music.authentication.CachingUtil;
import org.onap.music.datastore.MusicDataStore;
import org.onap.music.datastore.PreparedQueryObject;
diff --git a/src/test/java/org/onap/music/unittests/TestLockStore.java b/src/test/java/org/onap/music/unittests/TestLockStore.java
deleted file mode 100644
index cdca4214..00000000
--- a/src/test/java/org/onap/music/unittests/TestLockStore.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property
- * ===================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * ============LICENSE_END=============================================
- * ====================================================================
- */
-
-package org.onap.music.unittests;
-
-import org.apache.log4j.Logger;
-import org.onap.music.lockingservice.zookeeper.MusicLockingService;
-
-public class TestLockStore {
- final static Logger logger = Logger.getLogger(TestLockStore.class);
-
- public static void main(String[] args) throws Exception {
- String lockName = "/achristmkllas";
- MusicLockingService ml = new MusicLockingService();
- ml.deleteLock(lockName);
-
-
- logger.info("lockname:" + lockName);
-
- String lockId1 = ml.createLockId(lockName);
- logger.info("lockId1 " + lockId1);
- logger.info(ml.isMyTurn(lockId1));
-
- String lockId2 = ml.createLockId(lockName);
- logger.info("lockId2 " + lockId2);
- logger.info("check " + ml.isMyTurn("$bank$x-94608776321630264-0000000000"));
- logger.info(ml.isMyTurn(lockId2));
-
- // zkClient.unlock(lockId1);
- // logger.info(ml.lock(lockId2));
- // zkClient.unlock(lockId2);
- }
-
-
-}
diff --git a/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java b/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java
index 7242d542..f7a22d64 100644
--- a/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java
+++ b/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java
@@ -1,7 +1,9 @@
/*
* ============LICENSE_START========================================== org.onap.music
- * =================================================================== Copyright (c) 2017 AT&T
- * Intellectual Property ===================================================================
+ * ===================================================================
+ * Copyright (c) 2017 AT&T Intellectual Property
+ * Modifications Copyright (c) 2019 IBM
+ * ===================================================================
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
@@ -177,5 +179,17 @@ public class TestMusicCoreIntegration {
String data1 = new String(data);
assertEquals("I'm Test", data1);
}
+ @Test
+ public void Test13_ParameterizedConstructorCall() throws MusicServiceException, MusicQueryException {
+ MusicZKCore.mLockHandle = new MusicLockingService("localhost");
+ ResultType result = ResultType.FAILURE;
+ testObject = new PreparedQueryObject();
+ testObject.appendQueryString(CassandraCQL.createKeySpace);
+ musicZkCore.eventualPut(testObject);
+ testObject = new PreparedQueryObject();
+ testObject.appendQueryString(CassandraCQL.createTableEmployees);
+ result = musicZkCore.nonKeyRelatedPut(testObject, MusicUtil.EVENTUAL);
+ assertEquals(ResultType.SUCCESS, result);
+ }
}
diff --git a/src/test/java/org/onap/music/unittests/TestRestAdminData.java b/src/test/java/org/onap/music/unittests/TestRestAdminData.java
deleted file mode 100644
index 0471d6f0..00000000
--- a/src/test/java/org/onap/music/unittests/TestRestAdminData.java
+++ /dev/null
@@ -1,2571 +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.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.FixMethodOrder;
-import org.junit.Ignore;
-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.RestMusicConditionalAPI;
-import org.onap.music.datastore.MusicDataStoreHandle;
-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.JsonLeasedLock;
-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.zookeeper.MusicLockingService;
-import org.onap.music.main.MusicCore;
-import org.onap.music.main.MusicUtil;
-import org.onap.music.main.ResultType;
-import org.onap.music.rest.RestMusicAdminAPI;
-import org.onap.music.rest.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 org.onap.music.service.impl.MusicZKCore;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-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(SpringJUnit4ClassRunner.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
-
-
- @InjectMocks
- private MusicCore mCore;
-
- static MusicLockingService mLockHandle;
- //*/
-
- static String appName = "TestApp";
- static String userId = "TestUser";
- static String password = "TestPassword";
- static String adminName = "username";
- static String adminPassword = "password";
- static String adminAuthData = adminName +":"+adminPassword;
- static String wrongAdminAuthData = adminName+"123"+":"+adminPassword;
- 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 String adminAuthorization = new String(Base64.encode(adminAuthData.getBytes()));
- static String worngAdminAuthorization = new String(Base64.encode(wrongAdminAuthData.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 {
- MusicDataStoreHandle.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra();
- zkServer = new TestingServer(2181, new File("/tmp/zk"));
- mLockHandle = MusicZKCore.getLockingServiceHandle();
- } 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);
- MusicDataStoreHandle.mDstoreHandle.close();
- mLockHandle.close();
- zkServer.stop();
- }
-
- @Test
- public void Test1_createKeyspace() throws Exception {
- testObject = new PreparedQueryObject();
- testObject.appendQueryString("CREATE KEYSPACE admin WITH REPLICATION = "
- + "{'class' : 'SimpleStrategy' , "
- + "'replication_factor': 1} AND DURABLE_WRITES = true");
- MusicCore.eventualPut(testObject);
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "CREATE TABLE admin.keyspace_master (" + " uuid uuid, keyspace_name text,"
- + " application_name text, is_api boolean,"
- + " password text, username text,"
- + " is_aaf boolean, PRIMARY KEY (uuid)\n" + ");");
- MusicCore.eventualPut(testObject);
-
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
- + "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)");
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(),
- MusicUtil.DEFAULTKEYSPACENAME));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt())));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
- MusicCore.eventualPut(testObject);
-
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
- + "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)");
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
- UUID.fromString("bbc66ccc-d857-4e90-b1e5-df98a3d40de6")));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(),
- MusicUtil.DEFAULTKEYSPACENAME));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), "TestApp1"));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt())));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), "TestUser1"));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
- MusicCore.eventualPut(testObject);
-
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "select uuid from admin.keyspace_master where application_name = ? allow filtering");
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- ResultSet rs = MusicCore.get(testObject);
- List<Row> rows = rs.all();
- if (rows.size() > 0) {
- System.out.println("#######UUID is:" + rows.get(0).getUUID("uuid"));
- }
- PreparedQueryObject pQuery = new PreparedQueryObject();
- String consistency = MusicUtil.EVENTUAL;
- pQuery.appendQueryString("CREATE TABLE IF NOT EXISTS admin.locks ( lock_id text PRIMARY KEY, ctime text)");
- try {
- ResultType result = MusicCore.nonKeyRelatedPut(pQuery, consistency);
- } catch (MusicServiceException e1) {
- e1.printStackTrace();
- }
- }
-
- @Test
- public void Test2_createKeyspace() throws Exception {
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- consistencyInfo.put("type", "eventual");
- replicationInfo.put("class", "SimpleStrategy");
- replicationInfo.put("replication_factor", 1);
- jsonKeyspace.setConsistencyInfo(consistencyInfo);
- jsonKeyspace.setDurabilityOfWrites("true");
- jsonKeyspace.setKeyspaceName(keyspaceName);
- jsonKeyspace.setReplicationInfo(replicationInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createKeySpace("1", "1", "1", null,authorization, appName, jsonKeyspace, keyspaceName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- //assertEquals(200,response.getStatus());
- assertEquals(400,response.getStatus());
- }
-
- @Test
- public void Test2_createKeyspace_wrongConsistency() throws Exception {
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- consistencyInfo.put("type", "eventual123");
- 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(400,response.getStatus());
- }
-
- @Test
- public void Test2_createKeyspace1() throws Exception {
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- consistencyInfo.put("type", "eventual");
- replicationInfo.put("class", "SimpleStrategy");
- replicationInfo.put("replication_factor", 1);
- jsonKeyspace.setConsistencyInfo(consistencyInfo);
- jsonKeyspace.setDurabilityOfWrites("true");
- jsonKeyspace.setKeyspaceName(keyspaceName);
- jsonKeyspace.setReplicationInfo(replicationInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createKeySpace("1", "1", "1", null,authorization, appName, jsonKeyspace, "keyspaceName");
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- //assertEquals(200,response.getStatus());
- assertEquals(400,response.getStatus());
- }
-
- @Test
- public void Test2_createKeyspace0() throws Exception {
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createKeySpace("1", "1", "1", null, authorization,appName, jsonKeyspace, keyspaceName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(400,response.getStatus());
- }
-//MusicCore.autheticateUser
- @Test
- public void Test2_createKeyspace01() throws Exception {
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- String appName1 = "test";
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createKeySpace("1", "1", "1", null,authorization, appName1, jsonKeyspace, keyspaceName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- //assertEquals(401,response.getStatus());
- assertEquals(400,response.getStatus());
- }
-
- @Test
- public void Test3_createKeyspace1() throws Exception {
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- consistencyInfo.put("type", "eventual");
- replicationInfo.put("class", "SimpleStrategy");
- replicationInfo.put("replication_factor", 1);
- jsonKeyspace.setConsistencyInfo(consistencyInfo);
- jsonKeyspace.setDurabilityOfWrites("true");
- jsonKeyspace.setKeyspaceName("TestApp1");
- jsonKeyspace.setReplicationInfo(replicationInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createKeySpace("1", "1", "1", null,authorization, "TestApp1",
- jsonKeyspace, keyspaceName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- //assertEquals(401,response.getStatus());
- assertEquals(400,response.getStatus());
- }
-
- @Test
- public void Test2_createKeyspaceEmptyAuth() throws Exception {
-
- //MockitoAnnotations.initMocks(this);
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- consistencyInfo.put("type", "eventual");
- replicationInfo.put("class", "SimpleStrategy");
- replicationInfo.put("replication_factor", 1);
- jsonKeyspace.setConsistencyInfo(consistencyInfo);
- jsonKeyspace.setDurabilityOfWrites("true");
- jsonKeyspace.setKeyspaceName(keyspaceName);
- jsonKeyspace.setReplicationInfo(replicationInfo);
- //Map<String, Object> m1= new HashMap<>() ;
- //Mockito.when(CachingUtil.verifyOnboarding("x","y","x")).thenReturn(m1);
- //Mockito.when(CachingUtil.verifyOnboarding(appNamex,userId,password).thenReturn(m1));
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- String authDatax = ":"+password;
- String authorizationx = new String(Base64.encode(authDatax.getBytes()));
- try {
- Response response = data.createKeySpace("1", "1", "1", null,authorizationx, appName, jsonKeyspace, keyspaceName);
- //System.out.println("#######status is " + response.getStatus());
- //System.out.println("Entity" + response.getEntity());
- //assertNotEquals(200,response.getStatus());
- } catch (RuntimeException e ) {
- System.out.println("#######status is runtime exception= " + e);
- }
- }
-
- @Test
- public void Test3_createTable() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization,
- jsonTable, keyspaceName, tableName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- //assertEquals(200, response.getStatus());
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test3_createTable_wrongKeyspace() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName("keyspaceName12");
- 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(400, response.getStatus());
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test3_createTableClusterOrderBad() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name,emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name,emp_salary");
- jsonTable.setClusteringOrder("ASC");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization,
- jsonTable, keyspaceName, tableName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertNotEquals(200, response.getStatus());
- }
-
- @Test
- public void Test3_createTable_withPropertiesNotNull() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name)");
- consistencyInfo.put("type", "eventual");
- Map<String, Object> properties = new HashMap<>();
- properties.put("comment","Testing prperties not null");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- String tableName_prop=tableName+"_Prop";
- jsonTable.setTableName(tableName_prop);
- jsonTable.setFields(fields);
- jsonTable.setProperties(properties);
-
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization,
- jsonTable, keyspaceName, tableName_prop);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- //assertEquals(200, response.getStatus());
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test3_createTable_duplicateTable() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- String tableNameDup=tableName+"X";
- jsonTable.setTableName(tableNameDup);
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameDup);
- System.out.println("#######status for 1st time " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
-
- Response response0 = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameDup);
- // 400 is the duplicate status found in response
- // Music 113 duplicate testing
- //import static org.junit.Assert.assertNotEquals;
- System.out.println("#######status for 2nd time " + response0.getStatus());
- System.out.println("Entity" + response0.getEntity());
-
- assertFalse("Duplicate table not created for "+tableNameDup, 200==response0.getStatus());
-
- }
-
- // Improper Auth
- @Test
- public void Test3_createTable1() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization,
- jsonTable, keyspaceName, tableName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
- // Improper keyspace
- @Test
- public void Test3_createTable3() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, "wrong", tableName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test3_createTable3_with_samePartition_clusteringKeys() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name, emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPartitionKey("emp_name");
- jsonTable.setClusteringKey("emp_name");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(401, response.getStatus());
-
- }
-
- @Test
- public void Test3_createTable3_with_Partition_clusteringKeys() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPartitionKey("emp_name");
- jsonTable.setClusteringKey("uuid");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, "tableName1");
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- //assertEquals(200, response.getStatus());
- assertEquals(401, response.getStatus());
- }
-
- // Improper parenthesis in key field
- @Test
- public void Test3_createTable_badParantesis() throws Exception {
- String tableNameC ="testTable0";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name),emp_id)");
- fields.put("emp_id", "varint");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_id Desc");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- //assertEquals(400, response.getStatus());
- assertTrue(200 != response.getStatus());
- }
-
-
- // good clustering key
- @Test
- public void Test3_createTable_1_clusterKey_good() throws Exception {
- String tableNameC ="testTableC1";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name),emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- // jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- //assertEquals(200, response.getStatus());
- assertEquals(401, response.getStatus());
- }
-
- // bad partition key=clustering key
- @Test
- public void Test3_createTable_2_clusterKey_bad() throws Exception {
- String tableNameC ="testTableC2";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name),emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name"); // "PRIMARY KEY" overrides if primaryKey present
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertTrue(200 !=response.getStatus());
- }
-
- // good composite partition key,clustering key
- @Test
- public void Test3_createTable_3_partition_clusterKey_good() throws Exception {
- String tableNameC ="testTableC3";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_id", "varint");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name,emp_id),emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- //assertEquals(200, response.getStatus());
- assertEquals(401, response.getStatus());
- }
-
- // bad - not all cols in order by of composite partition key,clustering key
- @Test
- public void Test3_createTable_4_clusteringOrder_bad() throws Exception {
- String tableNameC ="testTableC4";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_id", "varint");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name),emp_id,emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertTrue(200 != response.getStatus());
- }
-
- // bad - wrong cols in order by of composite partition key,clustering key
- @Test
- public void Test3_createTable_5_clusteringOrder_bad() throws Exception {
- String tableNameC ="testTableC5";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_id", "varint");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((uuid,emp_name),emp_id,emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_idx desc, emp_salary ASC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertTrue(200 != response.getStatus());
- }
-
- // bad - wrong cols in order by of composite partition key,clustering key
- @Test
- public void Test3_createTable_6_clusteringOrder_bad() throws Exception {
- String tableNameC ="testTableC6";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_id", "varint");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((uuid,emp_name),emp_id,emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("((uuid,emp_name),emp_id,emp_salary)"); // overridden by
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_id desc, emp_salary ASC,uuid desc");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertTrue(200 != response.getStatus());
- }
-
-
- @Test
- public void Test3_createTableIndex_1() throws Exception {
- String tableNameC ="testTableCinx";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name),emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- MultivaluedMap<String, String> rowParams = Mockito.mock(MultivaluedMap.class);
- Mockito.when(info.getQueryParameters()).thenReturn(rowParams);
- Mockito.when(rowParams.getFirst("index_name")).thenReturn("my_index");
- response = data.createIndex("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- keyspaceName, tableNameC,"uuid",info);
- //assertEquals(200, response.getStatus());
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test3_createTableIndex_authorizationWrong() throws Exception {
- String tableNameC ="testTableCinx";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name),emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, null,
- jsonTable, keyspaceName, tableNameC);
- MultivaluedMap<String, String> rowParams = Mockito.mock(MultivaluedMap.class);
- Mockito.when(info.getQueryParameters()).thenReturn(rowParams);
- Mockito.when(rowParams.getFirst("index_name")).thenReturn("my_index");
- response = data.createIndex("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization,
- keyspaceName, tableNameC,"uuid",info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test3_createTableIndex_badindexname() throws Exception {
- String tableNameC ="testTableCinx";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name),emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- MultivaluedMap<String, String> rowParams = Mockito.mock(MultivaluedMap.class);
- Mockito.when(info.getQueryParameters()).thenReturn(rowParams);
- Mockito.when(rowParams.getFirst("index_name")).thenReturn("my index");
- response = data.createIndex("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- keyspaceName, tableNameC,"uuid",info);
- //assertEquals(400, response.getStatus());
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test3_createTableIndex_wrongindex() throws Exception {
- String tableNameC ="testTableCinx";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name),emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- MultivaluedMap<String, String> rowParams = Mockito.mock(MultivaluedMap.class);
- Mockito.when(info.getQueryParameters()).thenReturn(rowParams);
- Mockito.when(rowParams.getFirst("index_name")).thenReturn("my_index");
- response = data.createIndex("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- keyspaceName, tableNameC,"id",info);
- //assertEquals(400, response.getStatus());
- assertEquals(401, response.getStatus());
- }
-
- /*
- * @Test public void Test4_insertIntoTable() throws Exception { JsonInsert
- * jsonInsert = new JsonInsert(); Map<String, String> consistencyInfo = new
- * HashMap<>(); Map<String, Object> values = new HashMap<>(); values.put("uuid",
- * "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); values.put("emp_name", "testName");
- * values.put("emp_salary", 500); consistencyInfo.put("type", "eventual");
- * jsonInsert.setConsistencyInfo(consistencyInfo);
- * jsonInsert.setKeyspaceName(keyspaceName); jsonInsert.setTableName(tableName);
- * jsonInsert.setValues(values);
- * Mockito.doNothing().when(http).addHeader(xLatestVersion,
- * MusicUtil.getVersion()); Response response = data.insertIntoTable("1", "1",
- * "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- * jsonInsert, keyspaceName, tableName); assertEquals(200,
- * response.getStatus()); }
- */
-
- @Ignore
- public void Test4_insertIntoTable_wrongConsistency() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "testName");
- values.put("emp_salary", 500);
- consistencyInfo.put("type", "eventual123");
- 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());
- }
-
- @Ignore
- public void Test4_insertIntoTable2() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test1");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(200, response.getStatus());
- }
-
- // Auth Error
- @Ignore
- public void Test4_insertIntoTable3() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test1");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(401, response.getStatus());
- }
-
- // Table wrong
- @Ignore
- public void Test4_insertIntoTable4() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test1");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, "wrong");
- assertEquals(400, response.getStatus());
- }
-
- @Ignore
- public void Test4_insertIntoTable5() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("id", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test1");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(400, response.getStatus());
- }
-
- @Ignore
- public void Test4_insertIntoTable6() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(400, response.getStatus());
- }
-
- @Ignore
- public void Test4_insertIntoTable7() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test2");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- jsonInsert.setTtl("1000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(200, response.getStatus());
- }
-
- @Ignore
- public void Test4_insertIntoTable8() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test3");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- jsonInsert.setTimestamp("15000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(200, response.getStatus());
- }
-
- @Ignore
- public void Test4_insertIntoTable9() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test4");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- jsonInsert.setTtl("1000");
- jsonInsert.setTimestamp("15000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(200, response.getStatus());
- }
-
- /*
- * @Test public void Test4_insertIntoTable10() throws Exception { JsonInsert
- * jsonInsert = new JsonInsert(); Map<String, String> consistencyInfo = new
- * HashMap<>(); Map<String, Object> values = new HashMap<>(); values.put("uuid",
- * "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); values.put("emp_name", "test5");
- * values.put("emp_salary", 1500); consistencyInfo.put("type", "critical");
- * jsonInsert.setConsistencyInfo(consistencyInfo);
- * jsonInsert.setKeyspaceName(keyspaceName); jsonInsert.setTableName(tableName);
- * jsonInsert.setValues(values); jsonInsert.setTtl("1000");
- * jsonInsert.setTimestamp("15000");
- * Mockito.doNothing().when(http).addHeader(xLatestVersion,
- * MusicUtil.getVersion()); Response response = data.insertIntoTable("1", "1",
- * "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- * jsonInsert, keyspaceName, tableName); assertEquals(400,
- * response.getStatus()); }
- */
-
- /*
- * @Test public void Test4_insertIntoTable11() throws Exception { JsonInsert
- * jsonInsert = new JsonInsert(); Map<String, String> consistencyInfo = new
- * HashMap<>(); Map<String, Object> values = new HashMap<>(); values.put("uuid",
- * "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); values.put("emp_name", "test6");
- * values.put("emp_salary", 1500); consistencyInfo.put("type",
- * "atomic_delete_lock"); jsonInsert.setConsistencyInfo(consistencyInfo);
- * jsonInsert.setKeyspaceName(keyspaceName); jsonInsert.setTableName(tableName);
- * jsonInsert.setValues(values); jsonInsert.setTtl("1000");
- * jsonInsert.setTimestamp("15000");
- * Mockito.doNothing().when(http).addHeader(xLatestVersion,
- * MusicUtil.getVersion()); Response response = data.insertIntoTable("1", "1",
- * "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- * jsonInsert, keyspaceName, tableName); //TODO 200 assertEquals(400,
- * response.getStatus()); }
- */
-
- @Ignore
- public void Test4_insertIntoTable12() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test7");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "atomic");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- jsonInsert.setTtl("1000");
- jsonInsert.setTimestamp("15000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- //assertEquals(200, response.getStatus());
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_wrongTablename() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName("tableName123");
- 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, "tableName123", info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_wrongConsistency() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "eventual123");
- 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(401, response.getStatus());
- }
-
- // need mock code to create error for MusicCore methods
- @Test
- public void Test5_updateTableAuthE() throws Exception {
- MockitoAnnotations.initMocks(this);
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- //assertEquals(200, response.getStatus());
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test5_updateTableAuthException1() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- String authDatax = ":";//+password;
- String authorizationx = new String(Base64.encode(authDatax.getBytes()));
- try {
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorizationx, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- } catch(RuntimeException e) {
- System.out.println("Update table Runtime exception="+e);
- }
- }
-
- @Test
- public void Test5_updateTableAuthEmpty() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- String authDatax =":"+password;
- String authorizationx = new String(Base64.encode(authDatax.getBytes()));
- String appNamex="xx";
- try {
- // Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- Response response = data.updateTable("1", "1", "1", "", appNamex,
- authorizationx, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- } catch(RuntimeException e) {
- System.out.println("Update table Runtime exception="+e);
- }
- }
-
- @Test
- public void Test5_updateTable_wrongauth() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- wrongAuthorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_invalidColumn() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("id", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_ttl() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName8");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- jsonUpdate.setTtl("1000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_timsetamp() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName9");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- jsonUpdate.setTimestamp("15000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_ttl_timestamp() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName10");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- jsonUpdate.setTtl("1000");
- jsonUpdate.setTimestamp("15000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_rowIdEmpty() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- //row.add("emp_name", "testName3");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- jsonUpdate.setTtl("1000");
- jsonUpdate.setTimestamp("15000");
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_conditions() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- Map<String, Object> conditions = new HashMap<>();
- conditions.put("emp_name","testName3");
- row.add("emp_name", "testName3");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- jsonUpdate.setConditions(conditions);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_eventual() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "eventual");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_critical() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "critical");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test5_updateTable_atomic_delete_lock() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic_delete_lock");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test6_select() throws Exception {
- JsonSelect jsonSelect = new JsonSelect();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName");
- consistencyInfo.put("type", "atomic");
- jsonSelect.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.select("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableName, info);
- HashMap<String,HashMap<String,Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
- HashMap<String, Object> result = map.get("result");
- //assertEquals("2500", ((HashMap<String,Object>) result.get("row 0")).get("emp_salary").toString());
- }
-
- @Test
- public void Test6_select_withException() throws Exception {
- JsonSelect jsonSelect = new JsonSelect();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName");
- consistencyInfo.put("type", "atomic");
- jsonSelect.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- RestMusicDataAPI spyData = Mockito.spy(RestMusicDataAPI.class);
- Mockito.doThrow(MusicServiceException.class).when(spyData).selectSpecificQuery("v2", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password, keyspaceName, tableName, info, -1);
- Response response = spyData.select("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableName, info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test6_select_nodata() throws Exception {
- JsonSelect jsonSelect = new JsonSelect();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName12");
- consistencyInfo.put("type", "atomic");
- jsonSelect.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.select("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableName, info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test6_selectCritical() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName");
- consistencyInfo.put("type", "atomic");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, jsonInsert, keyspaceName, tableName,info);
- HashMap<String,HashMap<String,Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
- HashMap<String, Object> result = map.get("result");
- //assertEquals("2500", ((HashMap<String,Object>) result.get("row 0")).get("emp_salary").toString());
- }
-
- @Test
- public void Test6_selectCritical_wrongAuthorization() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName");
- consistencyInfo.put("type", "atomic");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, wrongAuthorization, jsonInsert, keyspaceName, tableName,info);
- /*HashMap<String,HashMap<String,Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
- HashMap<String, Object> result = map.get("result");
- assertEquals("2500", ((HashMap<String,Object>) result.get("row 0")).get("emp_salary").toString());*/
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test6_selectCritical_without_lockID() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName");
- consistencyInfo.put("type", "critical");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, jsonInsert, keyspaceName, tableName,info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test6_selectCritical_with_atomic_delete_lock() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName");
- consistencyInfo.put("type", "atomic_delete_lock");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, jsonInsert, keyspaceName, tableName,info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test6_selectCritical_with_nodata() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName12");
- consistencyInfo.put("type", "atomic_delete_lock");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, jsonInsert, keyspaceName, tableName,info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test6_select_all() throws Exception {
- JsonSelect jsonSelect = new JsonSelect();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();;
- consistencyInfo.put("type", "atomic");
- jsonSelect.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.select("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableName, info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test6_select_all_wrongAuthorization() throws Exception {
- JsonSelect jsonSelect = new JsonSelect();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();;
- consistencyInfo.put("type", "atomic");
- jsonSelect.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.select("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, wrongAuthorization, keyspaceName, tableName, info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test6_deleteFromTable() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "test1");
- consistencyInfo.put("type", "atomic");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.deleteFromTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonDelete, keyspaceName, tableName, info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test6_deleteFromTable_wrongAuthorization() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "test1");
- consistencyInfo.put("type", "atomic");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.deleteFromTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization,
- jsonDelete, keyspaceName, tableName, info);
- assertEquals(401, response.getStatus());
- }
-
- // Values
- /*
- * @Test public void Test6_deleteFromTable1() throws Exception { JsonDelete
- * jsonDelete = new JsonDelete(); Map<String, String> consistencyInfo = new
- * HashMap<>(); MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- * consistencyInfo.put("type", "atomic");
- * jsonDelete.setConsistencyInfo(consistencyInfo);
- * Mockito.doNothing().when(http).addHeader(xLatestVersion,
- * MusicUtil.getVersion());
- * Mockito.when(info.getQueryParameters()).thenReturn(row); Response response =
- * data.deleteFromTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- * appName, authorization, jsonDelete, keyspaceName, tableName, info);
- * assertEquals(400, response.getStatus()); }
- */
-
- // delObj
- @Test
- public void Test6_deleteFromTable2() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "test1");
- consistencyInfo.put("type", "atomic");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.deleteFromTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- null, keyspaceName, tableName, info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test6_deleteFromTable_columns() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "test1");
- consistencyInfo.put("type", "atomic");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- ArrayList<String> columns = new ArrayList<>();
- columns.add("uuid");
- jsonDelete.setColumns(columns);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.deleteFromTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonDelete, keyspaceName, tableName, info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test6_deleteFromTable_conditions() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> conditions = new HashMap<>();
- conditions.put("emp_name","testName3");
- row.add("emp_name", "test1");
- consistencyInfo.put("type", "atomic");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- ArrayList<String> columns = new ArrayList<>();
- jsonDelete.setConditions(conditions);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.deleteFromTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonDelete, keyspaceName, tableName, info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test6_deleteFromTable_eventual() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "test2");
- consistencyInfo.put("type", "eventual");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.deleteFromTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonDelete, keyspaceName, tableName, info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test6_deleteFromTable_wrongConsistency() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "test2");
- consistencyInfo.put("type", "eventual123");
- 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(401, response.getStatus());
- }
-
- @Test
- public void Test6_deleteFromTable_critical() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "test2");
- consistencyInfo.put("type", "critical");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.deleteFromTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonDelete, keyspaceName, tableName, info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test6_deleteFromTable_atomic_delete_lock() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "test3");
- consistencyInfo.put("type", "atomic_delete_lock");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.deleteFromTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonDelete, keyspaceName, tableName, info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test7_dropTable() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- consistencyInfo.put("type", "atomic");
- jsonTable.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.dropTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- keyspaceName, tableName);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test7_dropTable_wrongAuthorization() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- consistencyInfo.put("type", "atomic");
- jsonTable.setConsistencyInfo(consistencyInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.dropTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization,
- keyspaceName, tableName);
- assertEquals(401, response.getStatus());
- }
-
-
- /*
- * @Test public void Test8_deleteKeyspace() throws Exception { JsonKeySpace
- * jsonKeyspace = new JsonKeySpace(); Map<String, String> consistencyInfo = new
- * HashMap<>(); Map<String, Object> replicationInfo = new HashMap<>();
- * consistencyInfo.put("type", "eventual"); replicationInfo.put("class",
- * "SimpleStrategy"); replicationInfo.put("replication_factor", 1);
- * jsonKeyspace.setConsistencyInfo(consistencyInfo);
- * jsonKeyspace.setDurabilityOfWrites("true");
- * jsonKeyspace.setKeyspaceName("TestApp1");
- * jsonKeyspace.setReplicationInfo(replicationInfo);
- * Mockito.doNothing().when(http).addHeader(xLatestVersion,
- * MusicUtil.getVersion()); Response response = data.dropKeySpace("1", "1", "1",
- * "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", authorization,appName, keyspaceName);
- * assertEquals(200, response.getStatus()); }
- */
-
- @Test
- public void Test8_deleteKeyspace1() throws Exception {
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- consistencyInfo.put("type", "eventual");
- replicationInfo.put("class", "SimpleStrategy");
- replicationInfo.put("replication_factor", 1);
- jsonKeyspace.setConsistencyInfo(consistencyInfo);
- jsonKeyspace.setDurabilityOfWrites("true");
- jsonKeyspace.setKeyspaceName("TestApp1");
- jsonKeyspace.setReplicationInfo(replicationInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- authorization,appName, "keyspaceName");
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test8_deleteKeyspace2() throws Exception {
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- consistencyInfo.put("type", "eventual");
- replicationInfo.put("class", "SimpleStrategy");
- replicationInfo.put("replication_factor", 1);
- jsonKeyspace.setConsistencyInfo(consistencyInfo);
- jsonKeyspace.setDurabilityOfWrites("true");
- jsonKeyspace.setKeyspaceName("TestApp1");
- jsonKeyspace.setReplicationInfo(replicationInfo);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- wrongAuthorization, appName, keyspaceName);
- assertEquals(400, 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");
- *
- * @SuppressWarnings("unchecked") Map<String, Object> resultMap = (Map<String,
- * Object>)
- * admin.onboardAppWithMusic(jsonOnboard,adminAuthorization).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,adminAuthorization);
- assertEquals(204, response.getStatus());
- }
-
- // Missing appname
- @Test
- public void Test6_onboard1() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser2");
- jsonOnboard.setPassword("TestPassword2");
- Map<String, Object> resultMap = (Map<String, Object>) admin.onboardAppWithMusic(jsonOnboard,adminAuthorization).getEntity();
-// assertTrue(resultMap.containsKey("error"));
- //System.out.println("--->" + resultMap.toString());
- //assertEquals("Unauthorized: Please check the request parameters. Some of the required values appName(ns), userId, password, isAAF are missing.", resultMap.get("Exception"));
- }
-
-
- @Test
- public void Test7_onboardSearch() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setAid(onboardUUID);
- Map<String, Object> resultMap = (Map<String, Object>) admin.getOnboardedInfoSearch(jsonOnboard,adminAuthorization).getEntity();
- resultMap.containsKey("success");
- assertEquals(null, resultMap.get(onboardUUID));
- }
-
- // Missing appname
- @Test
- public void Test7_onboardSearch1() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setAid(onboardUUID);
- Map<String, Object> resultMap = (Map<String, Object>) admin.getOnboardedInfoSearch(jsonOnboard,adminAuthorization).getEntity();
- System.out.println("--->" + resultMap.toString());
- resultMap.containsKey("success");
- assertEquals(null, resultMap.get(onboardUUID));
- }
-
- @Test
- public void Test7_onboardSearch_empty() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- Response response = admin.getOnboardedInfoSearch(jsonOnboard,adminAuthorization);
- // 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,adminAuthorization);
- // assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test8_onboardUpdate() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser3");
- jsonOnboard.setPassword("TestPassword3");
- jsonOnboard.setAid(onboardUUID);
- Map<String, Object> resultMap = (Map<String, Object>) admin.updateOnboardApp(jsonOnboard,adminAuthorization).getEntity();
- System.out.println("--->" + resultMap.toString());
- resultMap.containsKey("success");
- assertNotNull(resultMap);
- }
-
- // Aid null
- @Test
- public void Test8_onboardUpdate1() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser3");
- jsonOnboard.setPassword("TestPassword3");
- Map<String, Object> resultMap = (Map<String, Object>) admin.updateOnboardApp(jsonOnboard,adminAuthorization).getEntity();
- System.out.println("--->" + resultMap.toString());
- assertNotNull(resultMap);
- }
-
- // Appname not null
- @Test
- public void Test8_onboardUpdate2() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser3");
- jsonOnboard.setPassword("TestPassword3");
- jsonOnboard.setAid(onboardUUID);
- Map<String, Object> resultMap = (Map<String, Object>) admin.updateOnboardApp(jsonOnboard,adminAuthorization).getEntity();
- assertNotNull(resultMap);
- }
-
- // All null
- @Test
- public void Test8_onboardUpdate3() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAid(onboardUUID);
- Map<String, Object> resultMap = (Map<String, Object>) admin.updateOnboardApp(jsonOnboard,adminAuthorization).getEntity();
- assertNotNull(resultMap);
- }
-
- @Test
- public void Test9_onboardDelete() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setAid(onboardUUID);
- Map<String, Object> resultMap = (Map<String, Object>) admin.deleteOnboardApp(jsonOnboard,adminAuthorization).getEntity();
- resultMap.containsKey("success");
- assertNotNull(resultMap);
- }
-
- @Test
- public void Test9_onboardDelete1() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- Map<String, Object> resultMap = (Map<String, Object>) admin.deleteOnboardApp(jsonOnboard,adminAuthorization).getEntity();
- assertNotNull(resultMap);
- }
-
- @Test
- public void Test3_createLockReference() throws Exception {
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = (Map<String, Object>) lock.createLockReference(lockName,"1","1",authorization, null, appName).getEntity();
- //TODO Success
- assertEquals(ResultType.FAILURE, resultMap.get("status"));
- }
-
- @Test
- public void Test3_createLockReference_invalidLock() throws Exception {
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- if (lock.createLockReference("lockName","1","1",authorization, null, appName).getEntity() == null) {
- System.err.println("yo");
- System.exit(-1);
- }
- Map<String, Object> resultMap = (Map<String, Object>) lock.createLockReference("lockName","1","1",authorization, null, appName).getEntity();
- assertEquals(ResultType.FAILURE, resultMap.get("status"));
- }
-
- @Test
- public void Test3_createLockReference_invalidAuthorization() throws Exception {
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = (Map<String, Object>) lock.createLockReference(lockName,"1","1",wrongAuthorization, null, appName).getEntity();
- assertEquals(ResultType.FAILURE, resultMap.get("status"));
- }
-
- @Test
- public void Test4_accquireLock() throws Exception {
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = (Map<String, Object>) lock.accquireLock(lockName,"1","1",authorization, null, appName).getEntity();
- //TODO Sucess
- assertEquals(ResultType.FAILURE, resultMap.get("status"));
- }
-
- /*
- * @Test public void Test4_accquireLock_wrongAuthorization() throws Exception {
- * Mockito.doNothing().when(http).addHeader(xLatestVersion,
- * MusicUtil.getVersion()); Map<String, Object> resultMap = (Map<String,
- * Object>) lock.accquireLock(Mockito.anyString(),"1","1",wrongAuthorization,
- * null, appName).getEntity(); assertEquals(ResultType.FAILURE,
- * resultMap.get("status")); }
- */
-
- /*
- * @Test public void Test5_accquireLockwithLease() throws Exception {
- * Mockito.doNothing().when(http).addHeader(xLatestVersion,
- * MusicUtil.getVersion()); JsonLeasedLock leasedLock = new JsonLeasedLock();
- * leasedLock.setLeasePeriod(1000l); Map<String, Object> resultMap =
- * (Map<String, Object>)
- * lock.accquireLockWithLease(leasedLock,lockId,"1","1",authorization, null,
- * appName).getEntity(); assertEquals(ResultType.SUCCESS,
- * resultMap.get("status")); }
- */
-
- @Test
- public void Test5_accquireLockwithLease_invalidLock() throws Exception {
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- JsonLeasedLock leasedLock = new JsonLeasedLock();
- leasedLock.setLeasePeriod(1000l);
- Map<String, Object> resultMap = (Map<String, Object>) lock.accquireLockWithLease(leasedLock,"lockId","1","1",authorization, null, appName).getEntity();
- assertEquals(ResultType.FAILURE, resultMap.get("status"));
- }
-
-
- /*
- * @Test public void Test5_currentLockHolder() throws Exception {
- * Mockito.doNothing().when(http).addHeader(xLatestVersion,
- * MusicUtil.getVersion()); Map<String, Object> resultMap = (Map<String,
- * Object>) lock.currentLockHolder(lockName,"1","1",authorization, null,
- * appName).getEntity(); assertEquals(ResultType.SUCCESS,
- * resultMap.get("status")); }
- */
-
- @Test
- public void Test5_currentLockHolder_invalidLock() throws Exception {
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = (Map<String, Object>) lock.currentLockHolder("lockName","1","1",authorization, null, appName).getEntity();
- assertEquals(ResultType.FAILURE, resultMap.get("status"));
- }
-
- @Test
- public void Test5_currentLockHolder_wrongAuthorization() throws Exception {
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = (Map<String, Object>) lock.currentLockHolder(lockName,"1","1",wrongAuthorization, null, appName).getEntity();
- assertEquals(ResultType.FAILURE, resultMap.get("status"));
- }
-
- @Test
- public void Test6_currentLockState() throws Exception {
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = (Map<String, Object>) lock.currentLockState(lockName,"1","1",authorization, null, appName).getEntity();
- //TODO Success
- assertEquals(ResultType.FAILURE, resultMap.get("status"));
- }
-
- @Test
- public void Test6_currentLockState_invalidLock() throws Exception {
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = (Map<String, Object>) lock.currentLockState("lockName","1","1",authorization, null, appName).getEntity();
- assertEquals(ResultType.FAILURE, resultMap.get("status"));
- }
-
- @Test
- public void Test6_currentLockState_wrongAuthorization() throws Exception {
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = (Map<String, Object>) lock.currentLockState(lockName,"1","1",wrongAuthorization, null, appName).getEntity();
- assertEquals(ResultType.FAILURE, resultMap.get("status"));
- }
-
- /*
- * @Test public void Test7_unLock() throws Exception {
- * Mockito.doNothing().when(http).addHeader(xLatestVersion,
- * MusicUtil.getVersion()); Map<String, Object> resultMap = (Map<String,
- * Object>) lock.unLock(lockId,"1","1",authorization, null,
- * appName).getEntity(); assertEquals(ResultType.SUCCESS,
- * resultMap.get("status")); }
- */
-
- /*
- * @Test public void Test7_unLock_invalidLock() throws Exception {
- * Mockito.doNothing().when(http).addHeader(xLatestVersion,
- * MusicUtil.getVersion()); Map<String, Object> resultMap = (Map<String,
- * Object>) lock.unLock("lockId","1","1",authorization, null,
- * appName).getEntity(); assertEquals(ResultType.FAILURE,
- * resultMap.get("status")); }
- */
- /*
- * @Test public void Test7_unLock_wrongAUthorization() throws Exception {
- * Mockito.doNothing().when(http).addHeader(xLatestVersion,
- * MusicUtil.getVersion()); Map<String, Object> resultMap = (Map<String,
- * Object>) lock.unLock(lockId,"1","1",wrongAuthorization, null,
- * appName).getEntity(); assertEquals(ResultType.FAILURE,
- * resultMap.get("status")); }
- */
-
- @Test
- public void Test8_delete() throws Exception {
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = (Map<String, Object>) lock.deleteLock(lockName,"1","1", null,authorization, appName).getEntity();
- assertEquals(ResultType.FAILURE, resultMap.get("status"));
- }
-
- @Test
- public void Test8_delete_invalidLock() throws Exception {
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = (Map<String, Object>) lock.deleteLock("lockName","1","1", null,authorization, appName).getEntity();
- assertEquals(ResultType.FAILURE, resultMap.get("status"));
- }
-
- @Test
- public void Test8_delete_wrongAuthorization() throws Exception {
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = (Map<String, Object>) lock.deleteLock(lockName,"1","1", null,wrongAuthorization, appName).getEntity();
- assertEquals(ResultType.FAILURE, resultMap.get("status"));
- }
- // Version api
- @Test
- public void Test1_version( ) {
- RestMusicVersionAPI versionapi = new RestMusicVersionAPI();
- HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class);
- Map<String, Object> resultMap = versionapi.version(servletResponse);
- assertEquals(ResultType.SUCCESS, resultMap.get("status"));
- }
-
- //Music Test Api
- @Test
- public void Test2_testAPI() {
- RestMusicTestAPI musicTest = new RestMusicTestAPI();
- HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class);
- Map<String, HashMap<String, String>> resultMap = musicTest.simpleTests(servletResponse);
- assertNotNull(resultMap);
- }
-
- //Music Health Check
- @Test
- public void Test3_HealthCheck_cassandra() {
- String consistency = "ONE";
- RestMusicHealthCheckAPI healthCheck = new RestMusicHealthCheckAPI();
- HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class);
- Response response = healthCheck.cassandraStatus(servletResponse, consistency);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test3_HealthCheck_cassandra_cosistencyQuorum() {
- String consistency = "QUORUM";
- RestMusicHealthCheckAPI healthCheck = new RestMusicHealthCheckAPI();
- HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class);
- Response response = healthCheck.cassandraStatus(servletResponse, consistency);
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void Test3_HealthCheck_zookeeper() {
- RestMusicHealthCheckAPI healthCheck = new RestMusicHealthCheckAPI();
- HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class);
- Response response = healthCheck.ZKStatus(servletResponse);
- assertEquals(200, response.getStatus());
- }
-
- @Ignore
- public void Test4_pureZKcreate() throws Exception {
- RestMusicBmAPI bmApi = new RestMusicBmAPI();
- bmApi.pureZkCreate("sample");
- }
-
- @Ignore
- public void Test4_pureZKUpdate() throws Exception {
- RestMusicBmAPI bmApi = new RestMusicBmAPI();
- bmApi.pureZkCreate("sample1");
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "testName_create");
- values.put("emp_salary", 500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- bmApi.pureZkUpdate(jsonInsert, "sampleNode1");
- }
-
- @Ignore
- public void Test4_pureZKGet() throws Exception {
- RestMusicBmAPI bmApi = new RestMusicBmAPI();
- bmApi.pureZkGet("sample");
- }
-
- /*
- * @Test public void Test5_ZKAtomicPut_atomic() throws Exception {
- * RestMusicBmAPI bmApi = new RestMusicBmAPI(); JsonInsert jsonInsert = new
- * JsonInsert(); Map<String, String> consistencyInfo = new HashMap<>();
- * Map<String, Object> values = new HashMap<>(); values.put("uuid",
- * "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); values.put("emp_name",
- * "testName_create"); values.put("emp_salary", 1500);
- * consistencyInfo.put("type", "atomic");
- * jsonInsert.setConsistencyInfo(consistencyInfo);
- * jsonInsert.setKeyspaceName(keyspaceName); jsonInsert.setTableName(tableName);
- * jsonInsert.setValues(values); bmApi.pureZkAtomicPut(jsonInsert, lockName,
- * "sampleNode1"); }
- */
- /*
- * @Test public void Test5_ZKAtomicPut_atomic_with_delete() throws Exception {
- * RestMusicBmAPI bmApi = new RestMusicBmAPI(); JsonInsert jsonInsert = new
- * JsonInsert(); Map<String, String> consistencyInfo = new HashMap<>();
- * Map<String, Object> values = new HashMap<>(); values.put("uuid",
- * "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); values.put("emp_name",
- * "testName_create"); values.put("emp_salary", 1500);
- * consistencyInfo.put("type", "atomic_delete_lock");
- * jsonInsert.setConsistencyInfo(consistencyInfo);
- * jsonInsert.setKeyspaceName(keyspaceName); jsonInsert.setTableName(tableName);
- * jsonInsert.setValues(values); bmApi.pureZkAtomicPut(jsonInsert, lockName,
- * "sampleNode1"); }
- */
-
- /*
- * @Test public void Test5_ZKAtomicGet_atomic() throws Exception {
- * RestMusicBmAPI bmApi = new RestMusicBmAPI(); JsonInsert jsonInsert = new
- * JsonInsert(); Map<String, String> consistencyInfo = new HashMap<>();
- * Map<String, Object> values = new HashMap<>(); values.put("uuid",
- * "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); values.put("emp_name",
- * "testName_create"); values.put("emp_salary", 1500);
- * consistencyInfo.put("type", "atomic_delete_lock");
- * jsonInsert.setConsistencyInfo(consistencyInfo);
- * jsonInsert.setKeyspaceName(keyspaceName); jsonInsert.setTableName(tableName);
- * jsonInsert.setValues(values); bmApi.pureZkAtomicGet(jsonInsert, lockName,
- * "sampleNode1"); }
- */
-
- /*
- * @Test public void Test5_ZKAtomicGet_atomic_with_delete() throws Exception {
- * RestMusicBmAPI bmApi = new RestMusicBmAPI(); JsonInsert jsonInsert = new
- * JsonInsert(); Map<String, String> consistencyInfo = new HashMap<>();
- * Map<String, Object> values = new HashMap<>(); values.put("uuid",
- * "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); values.put("emp_name",
- * "testName_create"); values.put("emp_salary", 1500);
- * consistencyInfo.put("type", "atomic_delete_lock");
- * jsonInsert.setConsistencyInfo(consistencyInfo);
- * jsonInsert.setKeyspaceName(keyspaceName); jsonInsert.setTableName(tableName);
- * jsonInsert.setValues(values); bmApi.pureZkAtomicGet(jsonInsert, lockName,
- * "sampleNode1"); }
- */
-
- @Test
- public void Test5_updateCassa() throws Exception {
- RestMusicBmAPI bmApi = new RestMusicBmAPI();
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName_create");
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- //bmApi.updateTableCassa(jsonInsert, keyspaceName, tableName, info);
- }
-
- // RestMusicConditional
- @Test
- public void Test5_createTable_conditional() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("id", "text");
- fields.put("plans", "Map<text,text>");
- fields.put("PRIMARY KEY", "(id)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("id");
- jsonTable.setTableName(tableNameConditional);
- jsonTable.setFields(fields);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization,
- jsonTable, keyspaceName, tableNameConditional);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- //assertEquals(200, response.getStatus());
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test6_insertConditional() throws Exception {
- RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI();
- JsonConditional json = new JsonConditional();
- json.setPrimaryKey("id");
- json.setPrimaryKeyValue("123|abc|port");
- json.setCasscadeColumnName("plans");
- Map<String, Object> tableValues = new HashMap<>();
- tableValues.put("id", "123|abc|port");
- json.setTableValues(tableValues);
- Map<String, Object> columnData = new HashMap<>();
- Map<String, String> column = new HashMap<>();
- column.put("created", "time");
- columnData.put("key", "P2");
- columnData.put("value", column);
- json.setCasscadeColumnData(columnData);
- Map<String, String> cond = new HashMap<>();
- Map<String, String> cond1 = new HashMap<>();
- Map<String, Map<String, String>> conditions = new HashMap<String, Map<String, String>>();
- cond.put("status", "under-spin-up");
- cond1.put("status", "parked");
- conditions.put("exists", cond);
- conditions.put("nonexists", cond1);
- json.setConditions(conditions);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = conditionalApi.insertConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableNameConditional, json);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test6_insertConditional_primaryKey_null() throws Exception {
- RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI();
- JsonConditional json = new JsonConditional();
- json.setPrimaryKeyValue("123|abc|port");
- json.setCasscadeColumnName("plans");
- Map<String, Object> tableValues = new HashMap<>();
- tableValues.put("id", "123|abc|port");
- json.setTableValues(tableValues);
- Map<String, Object> columnData = new HashMap<>();
- Map<String, String> column = new HashMap<>();
- column.put("created", "time");
- columnData.put("key", "P2");
- columnData.put("value", column);
- json.setCasscadeColumnData(columnData);
- Map<String, String> cond = new HashMap<>();
- Map<String, String> cond1 = new HashMap<>();
- Map<String, Map<String, String>> conditions = new HashMap<String, Map<String, String>>();
- cond.put("status", "under-spin-up");
- cond1.put("status", "parked");
- conditions.put("exists", cond);
- conditions.put("nonexists", cond1);
- json.setConditions(conditions);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = conditionalApi.insertConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableNameConditional, json);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test6_insertConditional_wrongAuth() throws Exception {
- RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI();
- JsonConditional json = new JsonConditional();
- json.setPrimaryKey("id");
- json.setPrimaryKeyValue("123|abc|port");
- json.setCasscadeColumnName("plans");
- Map<String, Object> tableValues = new HashMap<>();
- tableValues.put("id", "123|abc|port");
- json.setTableValues(tableValues);
- Map<String, Object> columnData = new HashMap<>();
- Map<String, String> column = new HashMap<>();
- column.put("created", "time");
- columnData.put("key", "P2");
- columnData.put("value", column);
- json.setCasscadeColumnData(columnData);
- Map<String, String> cond = new HashMap<>();
- Map<String, String> cond1 = new HashMap<>();
- Map<String, Map<String, String>> conditions = new HashMap<String, Map<String, String>>();
- cond.put("status", "under-spin-up");
- cond1.put("status", "parked");
- conditions.put("exists", cond);
- conditions.put("nonexists", cond1);
- json.setConditions(conditions);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = conditionalApi.insertConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, wrongAuthorization, keyspaceName, tableNameConditional, json);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test7_updateConditional() throws Exception {
- RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI();
- JsonConditional json = new JsonConditional();
- json.setPrimaryKey("id");
- json.setPrimaryKeyValue("123|abc|port");
- json.setCasscadeColumnName("plans");
- Map<String, Object> tableValues = new HashMap<>();
- tableValues.put("id", "123|abc|port");
- json.setTableValues(tableValues);
- Map<String, Object> columnData = new HashMap<>();
- Map<String, String> column = new HashMap<>();
- column.put("created", "time");
- columnData.put("key", "P2");
- columnData.put("value", column);
- json.setCasscadeColumnData(columnData);
- Map<String, String> cond = new HashMap<>();
- Map<String, String> cond1 = new HashMap<>();
- Map<String, Map<String, String>> conditions = new HashMap<String, Map<String, String>>();
- cond.put("updated", "new time");
- conditions.put("exists", cond);
- conditions.put("nonexists", cond1);
- json.setConditions(conditions);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = conditionalApi.updateConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableNameConditional, json);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test7_updateConditional_wrongAuth() throws Exception {
- RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI();
- JsonConditional json = new JsonConditional();
- json.setPrimaryKey("id");
- json.setPrimaryKeyValue("123|abc|port");
- json.setCasscadeColumnName("plans");
- Map<String, Object> tableValues = new HashMap<>();
- tableValues.put("id", "123|abc|port");
- json.setTableValues(tableValues);
- Map<String, Object> columnData = new HashMap<>();
- Map<String, String> column = new HashMap<>();
- column.put("created", "time");
- columnData.put("key", "P2");
- columnData.put("value", column);
- json.setCasscadeColumnData(columnData);
- Map<String, String> cond = new HashMap<>();
- Map<String, String> cond1 = new HashMap<>();
- Map<String, Map<String, String>> conditions = new HashMap<String, Map<String, String>>();
- cond.put("updated", "new time");
- conditions.put("exists", cond);
- conditions.put("nonexists", cond1);
- json.setConditions(conditions);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = conditionalApi.updateConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, wrongAuthorization, keyspaceName, tableNameConditional, json);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test7_updateConditional_primarykey_null() throws Exception {
- RestMusicConditionalAPI conditionalApi = new RestMusicConditionalAPI();
- JsonConditional json = new JsonConditional();
- json.setPrimaryKeyValue("123|abc|port");
- json.setCasscadeColumnName("plans");
- Map<String, Object> tableValues = new HashMap<>();
- tableValues.put("id", "123|abc|port");
- json.setTableValues(tableValues);
- Map<String, Object> columnData = new HashMap<>();
- Map<String, String> column = new HashMap<>();
- column.put("created", "time");
- columnData.put("key", "P2");
- columnData.put("value", column);
- json.setCasscadeColumnData(columnData);
- Map<String, String> cond = new HashMap<>();
- Map<String, String> cond1 = new HashMap<>();
- Map<String, Map<String, String>> conditions = new HashMap<String, Map<String, String>>();
- cond.put("updated", "new time");
- conditions.put("exists", cond);
- conditions.put("nonexists", cond1);
- json.setConditions(conditions);
- Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = conditionalApi.updateConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableNameConditional, json);
- assertEquals(401, response.getStatus());
- }
-} \ No newline at end of file
diff --git a/src/test/java/org/onap/music/unittests/TestRestMusicData.java b/src/test/java/org/onap/music/unittests/TestRestMusicData.java
deleted file mode 100644
index d42ef452..00000000
--- a/src/test/java/org/onap/music/unittests/TestRestMusicData.java
+++ /dev/null
@@ -1,1186 +0,0 @@
-/*
- * ============LICENSE_START========================================== org.onap.music
- * =================================================================== Copyright (c) 2017 AT&T
- * Intellectual Property ===================================================================
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- *
- * ============LICENSE_END=============================================
- * ====================================================================
- */
-
-package org.onap.music.unittests;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertTrue;
-import java.io.File;
-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.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.FixMethodOrder;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.MethodSorters;
-import org.mindrot.jbcrypt.BCrypt;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.music.datastore.MusicDataStoreHandle;
-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.lockingservice.cassandra.CassaLockStore;
-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.rest.RestMusicAdminAPI;
-import org.onap.music.rest.RestMusicDataAPI;
-import org.onap.music.rest.RestMusicLocksAPI;
-import com.datastax.driver.core.DataType;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
-import com.sun.jersey.core.util.Base64;
-import com.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;
-
- 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 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 {
- MusicDataStoreHandle.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra();
- MusicCore.mLockHandle = new CassaLockStore(MusicDataStoreHandle.mDstoreHandle);
- } 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);
- if(MusicDataStoreHandle.mDstoreHandle!=null)
- MusicDataStoreHandle.mDstoreHandle.close();
- if(zkServer!=null)
- zkServer.stop();
- }
-
- @Test
- public void Test1_createKeyspace() throws Exception {
- testObject = new PreparedQueryObject();
- testObject.appendQueryString("CREATE KEYSPACE admin WITH REPLICATION = "
- + "{'class' : 'SimpleStrategy' , "
- + "'replication_factor': 1} AND DURABLE_WRITES = true");
- MusicCore.eventualPut(testObject);
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "CREATE TABLE admin.keyspace_master (" + " uuid uuid, keyspace_name text,"
- + " application_name text, is_api boolean,"
- + " password text, username text,"
- + " is_aaf boolean, PRIMARY KEY (uuid)\n" + ");");
- MusicCore.eventualPut(testObject);
-
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
- + "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)");
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(),
- MusicUtil.DEFAULTKEYSPACENAME));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt())));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
- MusicCore.eventualPut(testObject);
-
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
- + "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)");
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(),
- UUID.fromString("bbc66ccc-d857-4e90-b1e5-df98a3d40de6")));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(),
- MusicUtil.DEFAULTKEYSPACENAME));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), "TestApp1"));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt())));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), "TestUser1"));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
- MusicCore.eventualPut(testObject);
-
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "select uuid from admin.keyspace_master where application_name = ? allow filtering");
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- ResultSet rs = MusicCore.get(testObject);
- List<Row> rows = rs.all();
- if (rows.size() > 0) {
- System.out.println("#######UUID is:" + rows.get(0).getUUID("uuid"));
- }
- }
-
- @Test
- public void Test2_createKeyspace() throws Exception {
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- consistencyInfo.put("type", "eventual");
- replicationInfo.put("class", "SimpleStrategy");
- replicationInfo.put("replication_factor", 1);
- jsonKeyspace.setConsistencyInfo(consistencyInfo);
- jsonKeyspace.setDurabilityOfWrites("true");
- jsonKeyspace.setKeyspaceName(keyspaceName);
- jsonKeyspace.setReplicationInfo(replicationInfo);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createKeySpace("1", "1", "1", null,authorization, appName, jsonKeyspace, keyspaceName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(400,response.getStatus());
- }
-
- @Test
- public void Test2_createKeyspace0() throws Exception {
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createKeySpace("1", "1", "1", null, authorization,appName, jsonKeyspace, keyspaceName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(400,response.getStatus());
- }
-//MusicCore.autheticateUser
- @Test
- public void Test2_createKeyspace01() throws Exception {
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- String appName1 = "test";
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createKeySpace("1", "1", "1", null,authorization, appName1, jsonKeyspace, keyspaceName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(400,response.getStatus());
- }
-
- @Test
- public void Test3_createKeyspace1() throws Exception {
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- consistencyInfo.put("type", "eventual");
- replicationInfo.put("class", "SimpleStrategy");
- replicationInfo.put("replication_factor", 1);
- jsonKeyspace.setConsistencyInfo(consistencyInfo);
- jsonKeyspace.setDurabilityOfWrites("true");
- jsonKeyspace.setKeyspaceName("TestApp1");
- jsonKeyspace.setReplicationInfo(replicationInfo);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createKeySpace("1", "1", "1", null,authorization, "TestApp1",
- jsonKeyspace, keyspaceName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(400,response.getStatus());
- }
-
- @Test
- public void Test2_createKeyspaceEmptyAuth() throws Exception {
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- consistencyInfo.put("type", "eventual");
- replicationInfo.put("class", "SimpleStrategy");
- replicationInfo.put("replication_factor", 1);
- jsonKeyspace.setConsistencyInfo(consistencyInfo);
- jsonKeyspace.setDurabilityOfWrites("true");
- jsonKeyspace.setKeyspaceName(keyspaceName);
- jsonKeyspace.setReplicationInfo(replicationInfo);
- //Map<String, Object> m1= new HashMap<>() ;
- //Mockito.when(CachingUtil.verifyOnboarding("x","y","x")).thenReturn(m1);
- //Mockito.when(CachingUtil.verifyOnboarding(appNamex,userId,password).thenReturn(m1));
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- String authDatax = ":"+password;
- String authorizationx = new String(Base64.encode(authDatax.getBytes()));
- try {
- Response response = data.createKeySpace("1", "1", "1", null,authorizationx, appName, jsonKeyspace, keyspaceName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertNotEquals(200,response.getStatus());
- } catch (RuntimeException e ) {
- System.out.println("#######status is runtime exception= " + e);
- }
- }
-
- @Test
- public void Test3_createTable() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization,
- jsonTable, keyspaceName, tableName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- //assertEquals(200, response.getStatus());
- assertEquals(401, response.getStatus());
- }
-
-
- @Test
- public void Test3_createTableClusterOrderBad() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name,emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name,emp_salary");
- jsonTable.setClusteringOrder("ASC");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization,
- jsonTable, keyspaceName, tableName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertNotEquals(200, response.getStatus());
- }
-
- @Test
- public void Test3_createTable_withPropertiesNotNull() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name)");
- consistencyInfo.put("type", "eventual");
- Map<String, Object> properties = new HashMap<>();
- properties.put("comment","Testing prperties not null");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- String tableName_prop=tableName+"_Prop";
- jsonTable.setTableName(tableName_prop);
- jsonTable.setFields(fields);
- jsonTable.setProperties(properties);
-
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization,
- jsonTable, keyspaceName, tableName_prop);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- //assertEquals(200, response.getStatus());
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test3_createTable_duplicateTable() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- String tableNameDup=tableName+"X";
- jsonTable.setTableName(tableNameDup);
- jsonTable.setFields(fields);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameDup);
- System.out.println("#######status for 1st time " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
-
- Response response0 = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameDup);
- // 400 is the duplicate status found in response
- // Music 113 duplicate testing
- //import static org.junit.Assert.assertNotEquals;
- System.out.println("#######status for 2nd time " + response0.getStatus());
- System.out.println("Entity" + response0.getEntity());
-
- assertFalse("Duplicate table not created for "+tableNameDup, 200==response0.getStatus());
-
- }
-
- // Improper Auth
- @Test
- public void Test3_createTable1() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization,
- jsonTable, keyspaceName, tableName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
- // Improper keyspace
- @Test
- public void Test3_createTable3() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, "wrong", tableName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
- // Improper parenthesis in key field
- @Test
- public void Test3_createTable_badParantesis() throws Exception {
- String tableNameC ="testTable0";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name),emp_id)");
- fields.put("emp_id", "varint");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_id Desc");
- jsonTable.setFields(fields);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- //assertEquals(400, response.getStatus());
- assertTrue(200 != response.getStatus());
- }
-
-
- // good clustering key
- @Test
- public void Test3_createTable_1_clusterKey_good() throws Exception {
- String tableNameC ="testTableC1";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name),emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- // jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- //assertEquals(200, response.getStatus());
- assertEquals(401, response.getStatus());
- }
-
- // bad partition key=clustering key
- @Test
- public void Test3_createTable_2_clusterKey_bad() throws Exception {
- String tableNameC ="testTableC2";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name),emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name"); // "PRIMARY KEY" overrides if primaryKey present
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertTrue(200 !=response.getStatus());
- }
-
- // good composite partition key,clustering key
- @Test
- public void Test3_createTable_3_partition_clusterKey_good() throws Exception {
- String tableNameC ="testTableC3";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_id", "varint");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name,emp_id),emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- //assertEquals(200, response.getStatus());
- assertEquals(401, response.getStatus());
- }
-
- // bad - not all cols in order by of composite partition key,clustering key
- @Test
- public void Test3_createTable_4_clusteringOrder_bad() throws Exception {
- String tableNameC ="testTableC4";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_id", "varint");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name),emp_id,emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertTrue(200 != response.getStatus());
- }
-
- // bad - wrong cols in order by of composite partition key,clustering key
- @Test
- public void Test3_createTable_5_clusteringOrder_bad() throws Exception {
- String tableNameC ="testTableC5";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_id", "varint");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((uuid,emp_name),emp_id,emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_idx desc, emp_salary ASC");
- jsonTable.setFields(fields);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertTrue(200 != response.getStatus());
- }
-
- // bad - wrong cols in order by of composite partition key,clustering key
- @Test
- public void Test3_createTable_6_clusteringOrder_bad() throws Exception {
- String tableNameC ="testTableC6";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_id", "varint");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((uuid,emp_name),emp_id,emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("((uuid,emp_name),emp_id,emp_salary)"); // overridden by
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_id desc, emp_salary ASC,uuid desc");
- jsonTable.setFields(fields);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonTable, keyspaceName, tableNameC);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertTrue(200 != response.getStatus());
- }
-
-
- // good clustering key, need to pass queryparameter
- @Test
- public void Test3_createTableIndex_1() throws Exception {
- String tableNameC ="testTableCinx";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name),emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- // jsonTable.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());
- // if 200 print to log otherwise fail assertEquals(200, response.getStatus());
- // info.setQueryParameters("index_name=inx_uuid");
- Map<String,String> queryParametersMap =new HashMap<String, String>();
-
- queryParametersMap.put("index_name","inxuuid");
- // Mockito.when(info.getQueryParameters()).thenReturn(new MultivaluedMap<String, String>(queryParametersMap));
- try {
- response = data.createIndex("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- keyspaceName, tableNameC,"uuid",info);
- assertEquals(401, response.getStatus());
- } catch (NullPointerException e) {
-
- }
- }
-
- @Test
- public void Test4_insertIntoTable() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "testName");
- values.put("emp_salary", 500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, jsonInsert, keyspaceName, tableName);
- //assertEquals(200, response.getStatus());
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test4_insertIntoTable2() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test1");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, tableName);
- //assertEquals(200, response.getStatus());
- assertEquals(401, response.getStatus());
- }
-
- // Auth Error
- @Test
- public void Test4_insertIntoTable3() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test1");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(401, response.getStatus());
- }
-
- // Table wrong
- @Test
- public void Test4_insertIntoTable4() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test1");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.insertIntoTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, "wrong");
- assertEquals(401, response.getStatus());
- }
-
-
- @Test
- public void Test5_updateTable() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- //Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- //assertEquals(200, response.getStatus());
- assertEquals(401, response.getStatus());
- }
-
- // need mock code to create error for MusicCore methods
- @Test
- public void Test5_updateTableAuthE() throws Exception {
- //MockitoAnnotations.initMocks(this);
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- //add ttl & timestamp
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- //Mockito.when(info.getQueryParameters()).thenReturn(row);
- //Map<String, Object> m1= new HashMap<>() ;
- //Mockito.when(MusicCore.autheticateUser(appName,userId,password,keyspaceName,"abc66ccc-d857-4e90-b1e5-df98a3d40ce6","updateTable")).thenReturn(m1);
- try {
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonUpdate, keyspaceName, tableName, info);
- //assertEquals(200, response.getStatus());
- assertEquals(401, response.getStatus());
- } catch(NullPointerException e) {
-
- }
- }
-
- @Test
- public void Test5_updateTableAuthException1() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
-
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- //Mockito.when(info.getQueryParameters()).thenReturn(row);
- String authDatax = ":";//+password;
- String authorizationx = new String(Base64.encode(authDatax.getBytes()));
- try {
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorizationx, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- } catch(RuntimeException e) {
- System.out.println("Update table Runtime exception="+e);
-
- }
- }
-
- @Test
- public void Test5_updateTableAuthEmpty() throws Exception {
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testName");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
-
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- //Mockito.when(info.getQueryParameters()).thenReturn(row);
- String authDatax =":"+password;
- String authorizationx = new String(Base64.encode(authDatax.getBytes()));
- String appNamex="xx";
- try {
- // Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- Response response = data.updateTable("1", "1", "1", "", appNamex,
- authorizationx, jsonUpdate, keyspaceName, tableName, info);
- assertEquals(200, response.getStatus());
- } catch(RuntimeException e) {
- System.out.println("Update table Runtime exception="+e);
-
- }
- }
-
-
- @Test
- public void Test6_select() throws Exception {
- JsonSelect jsonSelect = new JsonSelect();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName");
- consistencyInfo.put("type", "atomic");
- jsonSelect.setConsistencyInfo(consistencyInfo);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- //Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.select("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, keyspaceName, tableName, info);
- HashMap<String,HashMap<String,Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
- HashMap<String, Object> result = map.get("result");
- //assertEquals("2500", ((HashMap<String,Object>) result.get("row 0")).get("emp_salary").toString());
- }
-
- @Test
- public void Test6_selectCritical() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testName");
- consistencyInfo.put("type", "atomic");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- //Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, jsonInsert, keyspaceName, tableName,info);
- HashMap<String,HashMap<String,Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
- HashMap<String, Object> result = map.get("result");
- //assertEquals("2500", ((HashMap<String,Object>) result.get("row 0")).get("emp_salary").toString());
- }
-
- @Test
- public void Test6_deleteFromTable() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "test1");
- consistencyInfo.put("type", "atomic");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- //Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.deleteFromTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonDelete, keyspaceName, tableName, info);
- //assertEquals(200, response.getStatus());
- assertEquals(401, response.getStatus());
- }
-
- // Values
- @Ignore
- @Test
- public void Test6_deleteFromTable1() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- consistencyInfo.put("type", "atomic");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.deleteFromTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonDelete, keyspaceName, tableName, info);
- assertEquals(400, response.getStatus());
- }
-
- // delObj
- @Test
- public void Test6_deleteFromTable2() throws Exception {
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "test1");
- consistencyInfo.put("type", "atomic");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- //Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.deleteFromTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- null, keyspaceName, tableName, info);
- assertEquals(401, response.getStatus());
- }
-
- @Test
- public void Test7_dropTable() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- consistencyInfo.put("type", "atomic");
- jsonTable.setConsistencyInfo(consistencyInfo);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.dropTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- keyspaceName, tableName);
- //assertEquals(200, response.getStatus());
- assertEquals(401, response.getStatus());
- }
-
-
- @Test
- public void Test8_deleteKeyspace() throws Exception {
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- consistencyInfo.put("type", "eventual");
- replicationInfo.put("class", "SimpleStrategy");
- replicationInfo.put("replication_factor", 1);
- jsonKeyspace.setConsistencyInfo(consistencyInfo);
- jsonKeyspace.setDurabilityOfWrites("true");
- jsonKeyspace.setKeyspaceName("TestApp1");
- jsonKeyspace.setReplicationInfo(replicationInfo);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- /*
- * Response response = data.dropKeySpace("1", "1", "1",
- * "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", authorization,appName, keyspaceName);
- * assertEquals(200, response.getStatus());
- */
- }
-
- @Test
- public void Test8_deleteKeyspace2() throws Exception {
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- consistencyInfo.put("type", "eventual");
- replicationInfo.put("class", "SimpleStrategy");
- replicationInfo.put("replication_factor", 1);
- jsonKeyspace.setConsistencyInfo(consistencyInfo);
- jsonKeyspace.setDurabilityOfWrites("true");
- jsonKeyspace.setKeyspaceName("TestApp1");
- jsonKeyspace.setReplicationInfo(replicationInfo);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- wrongAuthorization, appName, keyspaceName);
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void Test8_deleteKeyspace3() throws Exception {
- JsonKeySpace jsonKeyspace = new JsonKeySpace();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> replicationInfo = new HashMap<>();
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- /*
- * Response response = data.dropKeySpace("1", "1", "1",
- * "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", authorization, appName,
- * keyspaceName); assertEquals(400, response.getStatus());
- */
- }
-
-
-
- @Test
- public void Test6_onboard() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser2");
- jsonOnboard.setPassword("TestPassword2");
- Map<String, Object> resultMap = (Map<String, Object>) admin.onboardAppWithMusic(jsonOnboard, null).getEntity();
- resultMap.containsKey("success");
- //onboardUUID = resultMap.get("Generated AID").toString();
- //assertEquals("Your application TestApp2 has been onboarded with MUSIC.", resultMap.get("Success"));
- }
- // Missing appname
- @Test
- public void Test6_onboard1() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser2");
- jsonOnboard.setPassword("TestPassword2");
- Map<String, Object> resultMap = (Map<String, Object>) admin.onboardAppWithMusic(jsonOnboard, null).getEntity();
- resultMap.containsKey("success");
- System.out.println("--->" + resultMap.toString());
- //assertEquals("Unauthorized: Please check the request parameters. Some of the required values appName(ns), userId, password, isAAF are missing.", resultMap.get("Exception"));
- }
-
-
- @Test
- public void Test7_onboardSearch() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setAid(onboardUUID);
- Map<String, Object> resultMap = (Map<String, Object>) admin.getOnboardedInfoSearch(jsonOnboard, null).getEntity();
- resultMap.containsKey("success");
- //assertEquals(MusicUtil.DEFAULTKEYSPACENAME, resultMap.get(onboardUUID));
- assertEquals(null, resultMap.get(onboardUUID));
-
- }
-
- // Missing appname
- @Test
- public void Test7_onboardSearch1() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setAid(onboardUUID);
- Map<String, Object> resultMap = (Map<String, Object>) admin.getOnboardedInfoSearch(jsonOnboard, null).getEntity();
- System.out.println("--->" + resultMap.toString());
- //resultMap.containsKey("success");
- resultMap.containsKey(null);
- //assertEquals(MusicUtil.DEFAULTKEYSPACENAME, resultMap.get(onboardUUID));
- assertEquals(null, resultMap.get(onboardUUID));
-
- }
-
- @Test
- public void Test8_onboardUpdate() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser3");
- jsonOnboard.setPassword("TestPassword3");
- jsonOnboard.setAid(onboardUUID);
- Map<String, Object> resultMap = (Map<String, Object>) admin.updateOnboardApp(jsonOnboard, null).getEntity();
- System.out.println("--->" + resultMap.toString());
- resultMap.containsKey("success");
- //assertEquals("Your application has been updated successfully", resultMap.get("Success"));
- assertEquals(null, resultMap.get("Success"));
- }
-
- // Aid null
- @Test
- public void Test8_onboardUpdate1() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser3");
- jsonOnboard.setPassword("TestPassword3");
- Map<String, Object> resultMap = (Map<String, Object>) admin.updateOnboardApp(jsonOnboard, null).getEntity();
- System.out.println("--->" + resultMap.toString());
- resultMap.containsKey("success");
- //assertEquals("Please make sure Aid is present", resultMap.get("Exception"));
- assertEquals(null, resultMap.get("Exception"));
- }
-
- // Appname not null
- @Test
- public void Test8_onboardUpdate2() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser3");
- jsonOnboard.setPassword("TestPassword3");
- jsonOnboard.setAid(onboardUUID);
- Map<String, Object> resultMap = (Map<String, Object>) admin.updateOnboardApp(jsonOnboard, null).getEntity();
- resultMap.containsKey("success");
- System.out.println("--->" + resultMap.toString());
- //assertEquals("Application TestApp2 has already been onboarded. Please contact admin.", resultMap.get("Exception"));
- assertEquals(null, resultMap.get("Exception"));
- }
-
- // All null
- @Test
- public void Test8_onboardUpdate3() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAid(onboardUUID);
- Map<String, Object> resultMap = (Map<String, Object>) admin.updateOnboardApp(jsonOnboard, null).getEntity();
- //assertTrue(resultMap.containsKey("Exception") );
- }
-
- @Test
- public void Test9_onboardDelete() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setAid(onboardUUID);
- Map<String, Object> resultMap = (Map<String, Object>) admin.deleteOnboardApp(jsonOnboard, null).getEntity();
- resultMap.containsKey("success");
- //assertEquals("Your application has been deleted successfully", resultMap.get("Success"));
- assertEquals(null, resultMap.get("Success"));
- }
-
- @Test
- public void Test9_onboardDelete1() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- Map<String, Object> resultMap = (Map<String, Object>) admin.deleteOnboardApp(jsonOnboard, null).getEntity();
- //assertTrue(resultMap.containsKey("Exception"));
- }
-
- @Ignore
- @Test
- public void Test3_createLockReference() throws Exception {
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = (Map<String, Object>) lock.createLockReference(lockName,"1","1",authorization, null, appName).getEntity();
- @SuppressWarnings("unchecked")
- Map<String, Object> resultMap1 = (Map<String, Object>) resultMap.get("lock");
- lockId = (String) resultMap1.get("lock");
- assertEquals(ResultType.SUCCESS, resultMap.get("status"));
- }
-
- @Ignore
- @Test
- public void Test4_accquireLock() throws Exception {
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = (Map<String, Object>) lock.accquireLock(lockId,"1","1",authorization, null, appName).getEntity();
- assertEquals(ResultType.SUCCESS, resultMap.get("status"));
- }
-
- @Ignore
- @Test
- public void Test5_currentLockHolder() throws Exception {
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = (Map<String, Object>) lock.currentLockHolder(lockName,"1","1",authorization, null, appName).getEntity();
- assertEquals(ResultType.SUCCESS, resultMap.get("status"));
- }
-
- @Ignore
- @Test
- public void Test7_unLock() throws Exception {
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Map<String, Object> resultMap = (Map<String, Object>) lock.unLock(lockId,"1","1",authorization, null, appName).getEntity();
- assertEquals(ResultType.SUCCESS, resultMap.get("status"));
- }
-
-
-}
diff --git a/src/test/java/org/onap/music/unittests/TestsUsingCassandra.java b/src/test/java/org/onap/music/unittests/TestsUsingCassandra.java
new file mode 100644
index 00000000..35f3b326
--- /dev/null
+++ b/src/test/java/org/onap/music/unittests/TestsUsingCassandra.java
@@ -0,0 +1,113 @@
+/*
+ * ============LICENSE_START==========================================
+ * org.onap.music
+ * ===================================================================
+ * Copyright (c) 2019 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 java.util.List;
+import java.util.UUID;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+import org.mindrot.jbcrypt.BCrypt;
+import org.onap.music.datastore.MusicDataStoreHandle;
+import org.onap.music.datastore.PreparedQueryObject;
+import org.onap.music.lockingservice.cassandra.CassaLockStore;
+import org.onap.music.main.MusicCore;
+import org.onap.music.main.MusicUtil;
+
+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;
+
+@RunWith(Suite.class)
+@SuiteClasses({ TstRestMusicDataAPI.class, TstRestMusicLockAPI.class, TstRestMusicAdminAPI.class,
+ TstRestMusicConditionalAPI.class, TstCachingUtil.class})
+//@SuiteClasses({TstCachingUtil.class})
+public class TestsUsingCassandra {
+
+ 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 xLatestVersion = "X-latestVersion";
+ static String onboardUUID = null;
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ MusicDataStoreHandle.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra();
+ MusicCore.mLockHandle = new CassaLockStore(MusicDataStoreHandle.mDstoreHandle);
+ createAdminTable();
+ }
+
+ @AfterClass
+ public static void afterClass() {
+ PreparedQueryObject testObject = new PreparedQueryObject();
+ testObject.appendQueryString("DROP KEYSPACE IF EXISTS admin");
+ MusicCore.eventualPut(testObject);
+ if(MusicDataStoreHandle.mDstoreHandle!=null)
+ MusicDataStoreHandle.mDstoreHandle.close();
+ }
+
+ private static void createAdminTable() throws Exception {
+ PreparedQueryObject testObject = new PreparedQueryObject();
+ testObject.appendQueryString(CassandraCQL.createAdminKeyspace);
+ MusicCore.eventualPut(testObject);
+ testObject = new PreparedQueryObject();
+ testObject.appendQueryString(CassandraCQL.createAdminTable);
+ 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(
+ "select uuid from admin.keyspace_master where application_name = ? allow filtering");
+ testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
+ ResultSet rs = MusicCore.get(testObject);
+ List<Row> rows = rs.all();
+ if (rows.size() > 0) {
+ System.out.println("#######UUID is:" + rows.get(0).getUUID("uuid"));
+ }
+ }
+}
diff --git a/src/test/java/org/onap/music/unittests/TstCachingUtil.java b/src/test/java/org/onap/music/unittests/TstCachingUtil.java
new file mode 100644
index 00000000..be2783b2
--- /dev/null
+++ b/src/test/java/org/onap/music/unittests/TstCachingUtil.java
@@ -0,0 +1,141 @@
+/*
+ * ============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.assertTrue;
+import java.util.UUID;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mindrot.jbcrypt.BCrypt;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.music.datastore.PreparedQueryObject;
+import org.onap.music.main.CachingUtil;
+import org.onap.music.main.MusicCore;
+import org.onap.music.main.MusicUtil;
+import org.onap.music.rest.RestMusicDataAPI;
+import com.datastax.driver.core.DataType;
+import com.sun.jersey.core.util.Base64;
+
+public class TstCachingUtil {
+
+ static PreparedQueryObject testObject;
+
+ 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 xLatestVersion = "X-latestVersion";
+ static String onboardUUID = null;
+
+ @BeforeClass
+ public static void init() throws Exception {
+ System.out.println("Testing CachingUtil class");
+ try {
+ createKeyspace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new Exception("Unable to initialize before CachingUtil test class. " + e.getMessage());
+ }
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ testObject = new PreparedQueryObject();
+ testObject.appendQueryString("DROP KEYSPACE IF EXISTS " + keyspaceName);
+ MusicCore.eventualPut(testObject);
+ }
+
+ @Test
+ public void test_isAAF_False() throws Exception {
+ System.out.println("Testing isAAF, nonaaf app");
+ assertEquals("false", CachingUtil.isAAFApplication(appName));
+ }
+
+ @Test
+ public void test_getUUidFromMusicCache() throws Exception {
+ System.out.println("Testing getUUID from MusicCache");
+ assertEquals(uuid.toString(), CachingUtil.getUuidFromMusicCache(keyspaceName));
+ }
+
+ @Test
+ public void test_getAppName() throws Exception {
+ System.out.println("Testing getAppName");
+ assertEquals(appName, CachingUtil.getAppName(keyspaceName));
+ }
+
+ @Test
+ public void test_verifyOnboarding() throws Exception {
+ System.out.println("Testing verifyOnboarding");
+ assertTrue(CachingUtil.verifyOnboarding(appName, userId, password).isEmpty());
+ }
+
+ @Test
+ public void test_verifyOnboardingFailure() throws Exception {
+ System.out.println("Testing verifyOnboarding with bad password");
+ assertFalse(CachingUtil.verifyOnboarding(appName, userId, "pass").isEmpty());
+ }
+
+
+ @Test
+ public void test_authenticateAIDUser() throws Exception {
+ System.out.println("Testing authenticateAIDUser");
+ assertTrue(CachingUtil.authenticateAIDUser(appName, userId, password, keyspaceName).isEmpty());
+ }
+
+ @Test
+ public void test_authenticateAIDUserFailure() throws Exception {
+ System.out.println("Testing authenticateAIDUser bad password");
+ assertFalse(CachingUtil.authenticateAIDUser(appName, userId, "pass", keyspaceName).isEmpty());
+ }
+
+ private static void createKeyspace() throws Exception {
+ // shouldn't really be doing this here, but create keyspace is currently turned off
+ PreparedQueryObject query = new PreparedQueryObject();
+ query.appendQueryString(CassandraCQL.createKeySpace);
+ MusicCore.eventualPut(query);
+
+ boolean isAAF = false;
+ String hashedpwd = BCrypt.hashpw(password, BCrypt.gensalt());
+ query = new PreparedQueryObject();
+ query.appendQueryString("INSERT into admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
+ + "password, username, is_aaf) values (?,?,?,?,?,?,?)");
+ query.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
+ query.addValue(MusicUtil.convertToActualDataType(DataType.text(), keyspaceName));
+ query.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
+ query.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
+ query.addValue(MusicUtil.convertToActualDataType(DataType.text(), hashedpwd));
+ query.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
+ query.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
+ CachingUtil.updateMusicCache(keyspaceName, appName);
+ CachingUtil.updateMusicValidateCache(appName, userId, hashedpwd);
+ MusicCore.eventualPut(query);
+ }
+
+}
diff --git a/src/test/java/org/onap/music/unittests/TstRestMusicAdminAPI.java b/src/test/java/org/onap/music/unittests/TstRestMusicAdminAPI.java
new file mode 100644
index 00000000..58d1d11b
--- /dev/null
+++ b/src/test/java/org/onap/music/unittests/TstRestMusicAdminAPI.java
@@ -0,0 +1,327 @@
+/*
+ * ============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 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.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.FixMethodOrder;
+import org.junit.Ignore;
+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.onap.music.authentication.MusicAuthentication;
+import org.onap.music.conductor.conditionals.JsonConditional;
+import org.onap.music.conductor.conditionals.RestMusicConditionalAPI;
+import org.onap.music.datastore.MusicDataStoreHandle;
+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.JsonLeasedLock;
+import org.onap.music.datastore.jsonobjects.JsonOnboard;
+import org.onap.music.datastore.jsonobjects.JsonTable;
+import org.onap.music.main.MusicCore;
+import org.onap.music.main.MusicUtil;
+import org.onap.music.rest.RestMusicAdminAPI;
+import org.onap.music.rest.RestMusicHealthCheckAPI;
+
+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;
+
+public class TstRestMusicAdminAPI {
+
+ RestMusicAdminAPI admin = new RestMusicAdminAPI();
+ static PreparedQueryObject testObject;
+
+ @Mock
+ HttpServletResponse http;
+
+ @Mock
+ UriInfo info;
+
+ static String appName = "TestApp";
+ static String userId = "TestUser";
+ static String password = "TestPassword";
+ static String adminName = "username";
+ static String adminPassword = "password";
+ static String adminAuthData = adminName +":"+adminPassword;
+ static String wrongAdminAuthData = adminName+"123"+":"+adminPassword;
+ 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 String adminAuthorization = new String(Base64.encode(adminAuthData.getBytes()));
+ static String worngAdminAuthorization = new String(Base64.encode(wrongAdminAuthData.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 {
+ System.out.println("Testing RestMusicAdmin class");
+ //PowerMockito.mockStatic(MusicAuthentication.class);
+ try {
+ //MusicDataStoreHandle.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra();
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new Exception("Unable to initialize before TestRestMusicData test class. " + e.getMessage());
+ }
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ testObject = new PreparedQueryObject();
+ testObject.appendQueryString("DROP KEYSPACE IF EXISTS " + keyspaceName);
+ MusicCore.eventualPut(testObject);
+ }
+
+ @Ignore
+ @Test
+ public void test6_onboard() throws Exception {
+ System.out.println("Testing application onboarding");
+
+ JsonOnboard jsonOnboard = new JsonOnboard();
+ jsonOnboard.setAppname("TestApp2");
+ jsonOnboard.setIsAAF("false"); jsonOnboard.setUserId("TestUser2");
+ jsonOnboard.setPassword("TestPassword2");
+
+ Response response = admin.onboardAppWithMusic(jsonOnboard,adminAuthorization);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ /*resultMap.containsKey("success"); onboardUUID =
+ resultMap.get("Generated AID").toString();
+ assertEquals("Your application TestApp2 has been onboarded with MUSIC.",
+ resultMap.get("Success")); */
+ assertEquals(200, response.getStatus());
+ }
+
+ @Test
+ public void test6_onboardCantReachAAF() throws Exception {
+ System.out.println("Testing application onboarding without reaching aaf");
+ JsonOnboard jsonOnboard = new JsonOnboard();
+ jsonOnboard.setAppname("TestApp2");
+ jsonOnboard.setIsAAF("false"); jsonOnboard.setUserId("TestUser2");
+ jsonOnboard.setPassword("TestPassword2");
+
+ Response response = admin.onboardAppWithMusic(jsonOnboard,adminAuthorization);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ //TODO FIX when we can authenticate
+ assertEquals(401, response.getStatus());
+ }
+
+ @Ignore
+ @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,adminAuthorization);
+ assertEquals(204, response.getStatus());
+ }
+
+ // Missing appname
+ @Ignore
+ @Test
+ public void test6_onboard1() throws Exception {
+ JsonOnboard jsonOnboard = new JsonOnboard();
+ jsonOnboard.setIsAAF("false");
+ jsonOnboard.setUserId("TestUser2");
+ jsonOnboard.setPassword("TestPassword2");
+ Map<String, Object> resultMap = (Map<String, Object>) admin.onboardAppWithMusic(jsonOnboard,adminAuthorization).getEntity();
+// assertTrue(resultMap.containsKey("error"));
+ //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 {
+ System.out.println("Testing application onboarding search w/o reaching aaf");
+ JsonOnboard jsonOnboard = new JsonOnboard();
+ jsonOnboard.setAppname("TestApp2");
+ jsonOnboard.setIsAAF("false");
+ jsonOnboard.setAid(onboardUUID);
+ Response response = admin.getOnboardedInfoSearch(jsonOnboard,adminAuthorization);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ //TODO FIX when we can authenticate
+ assertEquals(401, response.getStatus());
+ }
+
+ // Missing appname
+ @Ignore
+ @Test
+ public void test7_onboardSearch1() throws Exception {
+ JsonOnboard jsonOnboard = new JsonOnboard();
+ jsonOnboard.setIsAAF("false");
+ jsonOnboard.setAid(onboardUUID);
+ Map<String, Object> resultMap = (Map<String, Object>) admin.getOnboardedInfoSearch(jsonOnboard,adminAuthorization).getEntity();
+ System.out.println("--->" + resultMap.toString());
+ resultMap.containsKey("success");
+ assertEquals(null, resultMap.get(onboardUUID));
+ }
+
+ @Ignore
+ @Test
+ public void test7_onboardSearch_empty() throws Exception {
+ JsonOnboard jsonOnboard = new JsonOnboard();
+ Response response = admin.getOnboardedInfoSearch(jsonOnboard,adminAuthorization);
+ // assertEquals(400, response.getStatus());
+ }
+
+ @Ignore
+ @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,adminAuthorization);
+ // assertEquals(400, response.getStatus());
+ }
+
+ @Ignore
+ @Test
+ public void test8_onboardUpdate() throws Exception {
+ JsonOnboard jsonOnboard = new JsonOnboard();
+ jsonOnboard.setIsAAF("false");
+ jsonOnboard.setUserId("TestUser3");
+ jsonOnboard.setPassword("TestPassword3");
+ jsonOnboard.setAid(onboardUUID);
+ Map<String, Object> resultMap = (Map<String, Object>) admin.updateOnboardApp(jsonOnboard,adminAuthorization).getEntity();
+ System.out.println("--->" + resultMap.toString());
+ resultMap.containsKey("success");
+ assertNotNull(resultMap);
+ }
+
+ @Test
+ public void test8_onboardUpdateNoAAF() throws Exception {
+ System.out.println("Testing update application onboarding search w/o reaching aaf");
+ JsonOnboard jsonOnboard = new JsonOnboard();
+ jsonOnboard.setIsAAF("false");
+ jsonOnboard.setUserId("TestUser3");
+ jsonOnboard.setPassword("TestPassword3");
+ jsonOnboard.setAid(onboardUUID);
+ Response response = admin.updateOnboardApp(jsonOnboard,adminAuthorization);
+
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ assertEquals(401, response.getStatus());
+ }
+
+ // Aid null
+ @Ignore
+ @Test
+ public void test8_onboardUpdate1() throws Exception {
+ JsonOnboard jsonOnboard = new JsonOnboard();
+ jsonOnboard.setIsAAF("false");
+ jsonOnboard.setUserId("TestUser3");
+ jsonOnboard.setPassword("TestPassword3");
+ Map<String, Object> resultMap = (Map<String, Object>) admin.updateOnboardApp(jsonOnboard,adminAuthorization).getEntity();
+ System.out.println("--->" + resultMap.toString());
+ assertNotNull(resultMap);
+ }
+
+ // Appname not null
+ @Ignore
+ @Test
+ public void test8_onboardUpdate2() throws Exception {
+ JsonOnboard jsonOnboard = new JsonOnboard();
+ jsonOnboard.setAppname("TestApp2");
+ jsonOnboard.setIsAAF("false");
+ jsonOnboard.setUserId("TestUser3");
+ jsonOnboard.setPassword("TestPassword3");
+ jsonOnboard.setAid(onboardUUID);
+ Map<String, Object> resultMap = (Map<String, Object>) admin.updateOnboardApp(jsonOnboard,adminAuthorization).getEntity();
+ assertNotNull(resultMap);
+ }
+
+ // All null
+ @Ignore
+ @Test
+ public void test8_onboardUpdate3() throws Exception {
+ JsonOnboard jsonOnboard = new JsonOnboard();
+ jsonOnboard.setAid(onboardUUID);
+ Map<String, Object> resultMap = (Map<String, Object>) admin.updateOnboardApp(jsonOnboard,adminAuthorization).getEntity();
+ assertNotNull(resultMap);
+ }
+
+ @Ignore
+ @Test
+ public void test9_onboardDelete() throws Exception {
+ JsonOnboard jsonOnboard = new JsonOnboard();
+ jsonOnboard.setAppname("TestApp2");
+ jsonOnboard.setAid(onboardUUID);
+ Map<String, Object> resultMap = (Map<String, Object>) admin.deleteOnboardApp(jsonOnboard,adminAuthorization).getEntity();
+ resultMap.containsKey("success");
+ assertNotNull(resultMap);
+ }
+
+ @Test
+ public void test9_onboardDeleteNoAAF() throws Exception {
+ System.out.println("Testing onboard delete without aaf");
+ JsonOnboard jsonOnboard = new JsonOnboard();
+ jsonOnboard.setAppname("TestApp2");
+ jsonOnboard.setAid(onboardUUID);
+ Response response = admin.deleteOnboardApp(jsonOnboard,adminAuthorization);
+
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ assertEquals(401, response.getStatus());
+ }
+
+ @Ignore
+ @Test
+ public void test9_onboardDelete1() throws Exception {
+ JsonOnboard jsonOnboard = new JsonOnboard();
+ Map<String, Object> resultMap = (Map<String, Object>) admin.deleteOnboardApp(jsonOnboard,adminAuthorization).getEntity();
+ assertNotNull(resultMap);
+ }
+
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/music/unittests/TstRestMusicConditionalAPI.java b/src/test/java/org/onap/music/unittests/TstRestMusicConditionalAPI.java
new file mode 100644
index 00000000..3adab912
--- /dev/null
+++ b/src/test/java/org/onap/music/unittests/TstRestMusicConditionalAPI.java
@@ -0,0 +1,376 @@
+/*
+ * ============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 java.math.BigInteger;
+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.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mindrot.jbcrypt.BCrypt;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.music.authentication.CachingUtil;
+import org.onap.music.conductor.conditionals.JsonConditional;
+import org.onap.music.conductor.conditionals.RestMusicConditionalAPI;
+import org.onap.music.datastore.MusicDataStoreHandle;
+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.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.main.MusicCore;
+import org.onap.music.main.MusicUtil;
+import org.onap.music.main.ResultType;
+import org.onap.music.rest.RestMusicDataAPI;
+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;
+
+@RunWith(MockitoJUnitRunner.class)
+public class TstRestMusicConditionalAPI {
+
+ RestMusicDataAPI data = new RestMusicDataAPI();
+ RestMusicConditionalAPI cond = new RestMusicConditionalAPI();
+ static PreparedQueryObject testObject;
+
+ @Mock
+ HttpServletResponse http;
+
+ @Mock
+ UriInfo info;
+
+ 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 xLatestVersion = "X-latestVersion";
+ static String onboardUUID = null;
+
+ @BeforeClass
+ public static void init() throws Exception {
+ System.out.println("Testing RestMusicConditional class");
+ try {
+ createKeyspace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new Exception("Unable to initialize before TestRestMusicData test class. " + e.getMessage());
+ }
+ }
+
+ @After
+ public void afterEachTest() throws MusicServiceException {
+ clearAllTablesFromKeyspace();
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ testObject = new PreparedQueryObject();
+ testObject.appendQueryString("DROP KEYSPACE IF EXISTS " + keyspaceName);
+ MusicCore.eventualPut(testObject);
+ }
+
+ @Test
+ public void test_insertIntoTable() throws Exception {
+ System.out.println("Testing conditional insert into table");
+ createTable();
+
+ JsonConditional jsonCond = new JsonConditional();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, Object> values = new HashMap<>();
+ values.put("id", "test_id");
+ consistencyInfo.put("type", "eventual");
+ HashMap<String, Object> cascadeData = new HashMap<>();
+ HashMap<String, String> cascadeValue = new HashMap<>();
+ cascadeValue.put("created", "hello");
+ cascadeValue.put("updated", "world");
+ cascadeData.put("key", "p1");
+ cascadeData.put("value", cascadeValue);
+ HashMap<String, Map<String, String>> condition = new HashMap<>();
+ HashMap<String, String> exists = new HashMap<>();
+ exists.put("status", "parked");
+ HashMap<String, String> nonexists = new HashMap<>();
+ nonexists.put("status", "underway");
+ condition.put("exists", exists);
+ condition.put("nonexists", nonexists);
+
+ jsonCond.setPrimaryKey("id");
+ jsonCond.setPrimaryKeyValue("testname");
+ jsonCond.setCasscadeColumnName("plans");
+ jsonCond.setTableValues(values);
+ jsonCond.setCasscadeColumnData(cascadeData);
+ jsonCond.setConditions(condition);
+
+ Response response = cond.insertConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, keyspaceName, tableName, jsonCond);
+
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(200, response.getStatus());
+ }
+ /*
+ * @Test public void test4_insertIntoTable2() throws Exception { System.out.println("Testing insert into table #2");
+ * createTable(); JsonInsert jsonInsert = new JsonInsert(); Map<String, String> consistencyInfo = new HashMap<>();
+ * Map<String, Object> values = new HashMap<>(); values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
+ * values.put("emp_name", "test1"); values.put("emp_salary", 1500); consistencyInfo.put("type", "eventual");
+ * jsonInsert.setConsistencyInfo(consistencyInfo); jsonInsert.setKeyspaceName(keyspaceName);
+ * jsonInsert.setTableName(tableName); jsonInsert.setValues(values); Response response = data.insertIntoTable("1",
+ * "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, jsonInsert, keyspaceName, tableName);
+ * System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ *
+ * assertEquals(200, response.getStatus()); }
+ *
+ * // Auth Error
+ *
+ * @Test public void test4_insertIntoTable3() throws Exception {
+ * System.out.println("Testing insert into table with bad credentials"); createTable(); JsonInsert jsonInsert = new
+ * JsonInsert(); Map<String, String> consistencyInfo = new HashMap<>(); Map<String, Object> values = new
+ * HashMap<>(); values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); values.put("emp_name", "test1");
+ * values.put("emp_salary", 1500); consistencyInfo.put("type", "eventual");
+ * jsonInsert.setConsistencyInfo(consistencyInfo); jsonInsert.setKeyspaceName(keyspaceName);
+ * jsonInsert.setTableName(tableName); jsonInsert.setValues(values); Response response = data.insertIntoTable("1",
+ * "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization, jsonInsert, keyspaceName,
+ * tableName); System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ *
+ * assertEquals(401, response.getStatus()); }
+ *
+ * // Table wrong
+ *
+ * @Test public void test4_insertIntoTable4() throws Exception {
+ * System.out.println("Testing insert into wrong table"); createTable(); JsonInsert jsonInsert = new JsonInsert();
+ * Map<String, String> consistencyInfo = new HashMap<>(); Map<String, Object> values = new HashMap<>();
+ * values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6"); values.put("emp_name", "test1");
+ * values.put("emp_salary", 1500); consistencyInfo.put("type", "eventual");
+ * jsonInsert.setConsistencyInfo(consistencyInfo); jsonInsert.setKeyspaceName(keyspaceName);
+ * jsonInsert.setTableName(tableName); jsonInsert.setValues(values); Response response = data.insertIntoTable("1",
+ * "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, jsonInsert, keyspaceName, "wrong");
+ * System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ *
+ * assertEquals(400, response.getStatus()); }
+ */
+
+ @Test
+ public void test5_updateTable() throws Exception {
+ System.out.println("Testing conditional update table");
+ createAndInsertIntoTable();
+
+ Map<String, String> consistencyInfo = new HashMap<>();
+ consistencyInfo.put("type", "eventual");
+
+ JsonConditional jsonCond = new JsonConditional();
+ Map<String, Object> values = new HashMap<>();
+ values.put("id", "test_id");
+ HashMap<String, Object> cascadeData = new HashMap<>();
+ HashMap<String, String> cascadeValue = new HashMap<>();
+ cascadeValue.put("created", "hello");
+ cascadeValue.put("updated", "world");
+ cascadeData.put("key", "p1");
+ cascadeData.put("value", cascadeValue);
+
+ jsonCond.setPrimaryKey("id");
+ jsonCond.setPrimaryKeyValue("test_id");
+ jsonCond.setCasscadeColumnName("plans");
+ jsonCond.setTableValues(values);
+ jsonCond.setCasscadeColumnData(cascadeData);
+
+ Response response = cond.updateConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, keyspaceName, tableName, jsonCond);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(200, response.getStatus());
+ }
+ /*
+ * // need mock code to create error for MusicCore methods
+ *
+ * @Test public void test5_updateTableAuthE() throws Exception { System.out.println("Testing update table #2");
+ * createTable(); //MockitoAnnotations.initMocks(this); JsonUpdate jsonUpdate = new JsonUpdate(); Map<String,
+ * String> consistencyInfo = new HashMap<>(); MultivaluedMap<String, String> row = new MultivaluedMapImpl();
+ * Map<String, Object> values = new HashMap<>(); row.add("emp_name", "testname"); values.put("emp_salary", 2500);
+ * consistencyInfo.put("type", "atomic"); jsonUpdate.setConsistencyInfo(consistencyInfo);
+ * jsonUpdate.setKeyspaceName(keyspaceName); jsonUpdate.setTableName(tableName); jsonUpdate.setValues(values); //add
+ * ttl & timestamp //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ * Mockito.when(info.getQueryParameters()).thenReturn(row); //Map<String, Object> m1= new HashMap<>() ;
+ * //Mockito.when(MusicCore.autheticateUser(appName,userId,password,keyspaceName,
+ * "abc66ccc-d857-4e90-b1e5-df98a3d40ce6","updateTable")).thenReturn(m1); Response response = data.updateTable("1",
+ * "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, jsonUpdate, keyspaceName, tableName,
+ * info); System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ *
+ * assertEquals(200, response.getStatus()); }
+ *
+ * @Ignore
+ *
+ * @Test public void test5_updateTableAuthException1() throws Exception {
+ * System.out.println("Testing update table authentication error"); createTable(); JsonUpdate jsonUpdate = new
+ * JsonUpdate(); Map<String, String> consistencyInfo = new HashMap<>(); MultivaluedMap<String, String> row = new
+ * MultivaluedMapImpl(); Map<String, Object> values = new HashMap<>(); row.add("emp_name", "testname");
+ * values.put("emp_salary", 2500); consistencyInfo.put("type", "atomic");
+ * jsonUpdate.setConsistencyInfo(consistencyInfo); jsonUpdate.setKeyspaceName(keyspaceName);
+ * jsonUpdate.setTableName(tableName); jsonUpdate.setValues(values);
+ *
+ * Mockito.when(info.getQueryParameters()).thenReturn(row); String authDatax = ":"; String authorizationx = new
+ * String(Base64.encode(authDatax.getBytes())); Response response = data.updateTable("1", "1", "1",
+ * "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorizationx, jsonUpdate, keyspaceName, tableName, info);
+ * System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ *
+ * assertEquals(401, response.getStatus()); }
+ *
+ * @Ignore
+ *
+ * @Test public void test5_updateTableAuthEmpty() throws Exception {
+ * System.out.println("Testing update table without authentication"); createTable();
+ *
+ * JsonUpdate jsonUpdate = new JsonUpdate(); Map<String, String> consistencyInfo = new HashMap<>();
+ * MultivaluedMap<String, String> row = new MultivaluedMapImpl(); Map<String, Object> values = new HashMap<>();
+ * row.add("emp_name", "testname"); values.put("emp_salary", 2500); consistencyInfo.put("type", "atomic");
+ * jsonUpdate.setConsistencyInfo(consistencyInfo); jsonUpdate.setKeyspaceName(keyspaceName);
+ * jsonUpdate.setTableName(tableName); jsonUpdate.setValues(values);
+ *
+ * Mockito.when(info.getQueryParameters()).thenReturn(row); String authDatax =":"+password; String authorizationx =
+ * new String(Base64.encode(authDatax.getBytes())); String appNamex="xx"; Response response = data.updateTable("1",
+ * "1", "1", "", appNamex, authorizationx, jsonUpdate, keyspaceName, tableName, info); System.out.println("Status: "
+ * + response.getStatus() + ". Entity " + response.getEntity());
+ *
+ * assertEquals(401, response.getStatus()); }
+ *
+ */
+
+ private static void createKeyspace() throws Exception {
+ // shouldn't really be doing this here, but create keyspace is currently turned off
+ PreparedQueryObject query = new PreparedQueryObject();
+ query.appendQueryString(CassandraCQL.createKeySpace);
+ MusicCore.eventualPut(query);
+
+ boolean isAAF = false;
+ String hashedpwd = BCrypt.hashpw(password, BCrypt.gensalt());
+ query = new PreparedQueryObject();
+ query.appendQueryString("INSERT into admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
+ + "password, username, is_aaf) values (?,?,?,?,?,?,?)");
+ query.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
+ query.addValue(MusicUtil.convertToActualDataType(DataType.text(), keyspaceName));
+ query.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
+ query.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
+ query.addValue(MusicUtil.convertToActualDataType(DataType.text(), hashedpwd));
+ query.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
+ query.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
+ CachingUtil.updateMusicCache(keyspaceName, appName);
+ CachingUtil.updateMusicValidateCache(appName, userId, hashedpwd);
+ MusicCore.eventualPut(query);
+ }
+
+ private void clearAllTablesFromKeyspace() throws MusicServiceException {
+ ArrayList<String> tableNames = new ArrayList<>();
+ PreparedQueryObject query = new PreparedQueryObject();
+ query.appendQueryString(
+ "SELECT table_name FROM system_schema.tables WHERE keyspace_name = '" + keyspaceName + "';");
+ ResultSet rs = MusicCore.get(query);
+ for (Row row : rs) {
+ tableNames.add(row.getString("table_name"));
+ }
+ for (String table : tableNames) {
+ query = new PreparedQueryObject();
+ query.appendQueryString("DROP TABLE " + keyspaceName + "." + table);
+ MusicCore.eventualPut(query);
+ }
+ }
+
+ /**
+ * Create a table {@link tableName} in {@link keyspaceName}
+ *
+ * @throws Exception
+ */
+ private void createTable() throws Exception {
+ JsonTable jsonTable = new JsonTable();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, String> fields = new HashMap<>();
+ fields.put("id", "text");
+ fields.put("plans", "map<text,text>");
+ fields.put("PRIMARY KEY", "(id)");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setPrimaryKey("id");
+ jsonTable.setTableName(tableName);
+ jsonTable.setFields(fields);
+ Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonTable, keyspaceName, tableName);
+ }
+
+ /**
+ * Create table {@link createTable} and insert into said table
+ *
+ * @throws Exception
+ */
+ private void createAndInsertIntoTable() throws Exception {
+ createTable();
+
+ Map<String, String> consistencyInfo = new HashMap<>();
+ consistencyInfo.put("type", "eventual");
+ JsonConditional jsonCond = new JsonConditional();
+ Map<String, Object> values = new HashMap<>();
+ values.put("id", "test_id");
+ HashMap<String, Object> cascadeData = new HashMap<>();
+ HashMap<String, String> cascadeValue = new HashMap<>();
+ cascadeValue.put("created", "hello");
+ cascadeValue.put("updated", "world");
+ cascadeData.put("key", "p1");
+ cascadeData.put("value", cascadeValue);
+ HashMap<String, Map<String, String>> condition = new HashMap<>();
+ HashMap<String, String> exists = new HashMap<>();
+ exists.put("status", "parked");
+ HashMap<String, String> nonexists = new HashMap<>();
+ nonexists.put("status", "underway");
+ condition.put("exists", exists);
+ condition.put("nonexists", nonexists);
+
+ jsonCond.setPrimaryKey("id");
+ jsonCond.setPrimaryKeyValue("test_id");
+ jsonCond.setCasscadeColumnName("plans");
+ jsonCond.setTableValues(values);
+ jsonCond.setCasscadeColumnData(cascadeData);
+ jsonCond.setConditions(condition);
+
+ Response response = cond.insertConditional("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, keyspaceName, tableName, jsonCond);
+ }
+}
diff --git a/src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java b/src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java
new file mode 100644
index 00000000..07a1b8e1
--- /dev/null
+++ b/src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java
@@ -0,0 +1,1045 @@
+/*
+ * ============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 java.math.BigInteger;
+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.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mindrot.jbcrypt.BCrypt;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.music.authentication.CachingUtil;
+import org.onap.music.datastore.MusicDataStoreHandle;
+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.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.main.MusicCore;
+import org.onap.music.main.MusicUtil;
+import org.onap.music.main.ResultType;
+import org.onap.music.rest.RestMusicDataAPI;
+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;
+
+@RunWith(MockitoJUnitRunner.class)
+public class TstRestMusicDataAPI {
+
+ RestMusicDataAPI data = new RestMusicDataAPI();
+ static PreparedQueryObject testObject;
+
+ @Mock
+ HttpServletResponse http;
+
+ @Mock
+ UriInfo info;
+
+ 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 xLatestVersion = "X-latestVersion";
+ static String onboardUUID = null;
+
+ @BeforeClass
+ public static void init() throws Exception {
+ System.out.println("Testing RestMusicData class");
+ try {
+ createKeyspace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new Exception("Unable to initialize before TestRestMusicData test class. " + e.getMessage());
+ }
+ }
+
+ @After
+ public void afterEachTest() throws MusicServiceException {
+ clearAllTablesFromKeyspace();
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ testObject = new PreparedQueryObject();
+ testObject.appendQueryString("DROP KEYSPACE IF EXISTS " + keyspaceName);
+ MusicCore.eventualPut(testObject);
+ }
+
+ @Test
+ public void test1_createKeyspace() throws Exception {
+ System.out.println("Testing create keyspace");
+ JsonKeySpace jsonKeyspace = new JsonKeySpace();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, Object> replicationInfo = new HashMap<>();
+ consistencyInfo.put("type", "eventual");
+ replicationInfo.put("class", "SimpleStrategy");
+ replicationInfo.put("replication_factor", 1);
+ jsonKeyspace.setConsistencyInfo(consistencyInfo);
+ jsonKeyspace.setDurabilityOfWrites("true");
+ jsonKeyspace.setKeyspaceName(keyspaceName);
+ jsonKeyspace.setReplicationInfo(replicationInfo);
+ // Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Response response =
+ data.createKeySpace("1", "1", "1", null, authorization, appName, jsonKeyspace, keyspaceName);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ assertEquals(400, response.getStatus());
+ Map<String, String> respMap = (Map<String, String>) response.getEntity();
+ assertEquals(ResultType.FAILURE, respMap.get("status"));
+ }
+
+ @Test
+ public void test3_createTable() throws Exception {
+ System.out.println("Testing create table");
+ JsonTable jsonTable = new JsonTable();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, String> fields = new HashMap<>();
+ fields.put("uuid", "text");
+ fields.put("emp_name", "text");
+ fields.put("emp_salary", "varint");
+ fields.put("PRIMARY KEY", "(emp_name)");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setPrimaryKey("emp_name");
+ jsonTable.setTableName(tableName);
+ jsonTable.setFields(fields);
+ Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonTable, keyspaceName, tableName);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ assertEquals(200, response.getStatus());
+ }
+
+ @Test
+ public void test3_createTableNoName() throws Exception {
+ System.out.println("Testing create table without name");
+ JsonTable jsonTable = new JsonTable();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, String> fields = new HashMap<>();
+ fields.put("uuid", "text");
+ fields.put("emp_name", "text");
+ fields.put("emp_salary", "varint");
+ fields.put("PRIMARY KEY", "(emp_name)");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setPrimaryKey("emp_name");
+ jsonTable.setTableName("");
+ jsonTable.setFields(fields);
+ Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonTable, keyspaceName, "");
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ assertEquals(400, response.getStatus());
+ }
+
+
+ @Test
+ public void test3_createTableClusterOrderBad() throws Exception {
+ System.out.println("Testing create table bad clustering");
+ JsonTable jsonTable = new JsonTable();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, String> fields = new HashMap<>();
+ fields.put("uuid", "text");
+ fields.put("emp_name", "text");
+ fields.put("emp_salary", "varint");
+ fields.put("PRIMARY KEY", "(emp_name,emp_salary)");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setPrimaryKey("emp_name,emp_salary");
+ jsonTable.setClusteringOrder("ASC");
+ jsonTable.setTableName(tableName);
+ jsonTable.setFields(fields);
+ Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonTable, keyspaceName, tableName);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ assertEquals(400, response.getStatus());
+ }
+
+ @Test
+ public void test3_createTable_withPropertiesNotNull() throws Exception {
+ System.out.println("Testing create table with properties");
+ JsonTable jsonTable = new JsonTable();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, String> fields = new HashMap<>();
+ fields.put("uuid", "text");
+ fields.put("emp_name", "text");
+ fields.put("emp_salary", "varint");
+ fields.put("PRIMARY KEY", "(emp_name)");
+ consistencyInfo.put("type", "eventual");
+ Map<String, Object> properties = new HashMap<>();
+ properties.put("comment", "Testing prperties not null");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setPrimaryKey("emp_name");
+ String tableName_prop = tableName + "_Prop";
+ jsonTable.setTableName(tableName_prop);
+ jsonTable.setFields(fields);
+ jsonTable.setProperties(properties);
+
+ Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonTable, keyspaceName, tableName_prop);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ assertEquals(200, response.getStatus());
+ }
+
+ @Test
+ public void test3_createTable_duplicateTable() throws Exception {
+ System.out.println("Testing creating duplicate tables");
+ JsonTable jsonTable = new JsonTable();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, String> fields = new HashMap<>();
+ fields.put("uuid", "text");
+ fields.put("emp_name", "text");
+ fields.put("emp_salary", "varint");
+ fields.put("PRIMARY KEY", "(emp_name)");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setPrimaryKey("emp_name");
+ String tableNameDup = tableName + "x";
+ jsonTable.setTableName(tableNameDup);
+ jsonTable.setFields(fields);
+ // Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Response response1 = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonTable, keyspaceName, tableNameDup);
+
+ Response response2 = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonTable, keyspaceName, tableNameDup);
+ System.out.println("Status: " + response2.getStatus() + ". Entity " + response2.getEntity());
+
+ assertEquals(400, response2.getStatus());
+ Map<String, String> respMap = (Map<String, String>) response2.getEntity();
+ assertEquals(ResultType.FAILURE, respMap.get("status"));
+ assertEquals("Table " + keyspaceName + "." + tableNameDup + " already exists", respMap.get("error"));
+ }
+
+ // Improper Auth
+ @Test
+ public void test3_createTable1() throws Exception {
+ System.out.println("Testing create table w/ improper authentication");
+ JsonTable jsonTable = new JsonTable();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, String> fields = new HashMap<>();
+ fields.put("uuid", "text");
+ fields.put("emp_name", "text");
+ fields.put("emp_salary", "varint");
+ fields.put("PRIMARY KEY", "(emp_name)");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setPrimaryKey("emp_name");
+ jsonTable.setTableName(tableName);
+ jsonTable.setFields(fields);
+ Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ wrongAuthorization, jsonTable, keyspaceName, tableName);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ assertEquals(401, response.getStatus());
+ }
+
+ // Improper keyspace
+ @Test
+ public void test3_createTable3() throws Exception {
+ System.out.println("Testing create table for wrong keyspace");
+ JsonTable jsonTable = new JsonTable();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, String> fields = new HashMap<>();
+ fields.put("uuid", "text");
+ fields.put("emp_name", "text");
+ fields.put("emp_salary", "varint");
+ fields.put("PRIMARY KEY", "(emp_name)");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setPrimaryKey("emp_name");
+ jsonTable.setTableName(tableName);
+ jsonTable.setFields(fields);
+ Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonTable, "wrong", tableName);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ assertEquals(401, response.getStatus());
+ }
+
+ // Improper parenthesis in key field
+ @Test
+ public void test3_createTable_badParantesis() throws Exception {
+ System.out.println("Testing malformed create table request");
+ String tableNameC = "testTable0";
+ JsonTable jsonTable = new JsonTable();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, String> fields = new HashMap<>();
+ fields.put("uuid", "text");
+ fields.put("emp_name", "text");
+ fields.put("emp_salary", "varint");
+ fields.put("PRIMARY KEY", "(emp_name),emp_id)");
+ fields.put("emp_id", "varint");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setPrimaryKey("emp_name");
+ jsonTable.setTableName(tableNameC);
+ jsonTable.setClusteringOrder("emp_id Desc");
+ jsonTable.setFields(fields);
+ Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonTable, keyspaceName, tableNameC);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(400, response.getStatus());
+ }
+
+
+ // good clustering key
+ @Test
+ public void test3_createTable_1_clusterKey_good() throws Exception {
+ System.out.println("Testing create w/ clusterKey");
+
+ String tableNameC = "testTableC1";
+ JsonTable jsonTable = new JsonTable();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, String> fields = new HashMap<>();
+ fields.put("uuid", "text");
+ fields.put("emp_name", "text");
+ fields.put("emp_salary", "varint");
+ fields.put("PRIMARY KEY", "((emp_name),emp_salary)");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ // jsonTable.setPrimaryKey("emp_name");
+ jsonTable.setTableName(tableNameC);
+ jsonTable.setClusteringOrder("emp_salary ASC");
+ jsonTable.setFields(fields);
+ Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonTable, keyspaceName, tableNameC);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(200, response.getStatus());
+ }
+
+ // bad partition key=clustering key
+ @Test
+ public void test3_createTable_2_clusterKey_bad() throws Exception {
+ System.out.println("Testing create w/ bad clusterKey");
+ String tableNameC = "testTableC2";
+ JsonTable jsonTable = new JsonTable();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, String> fields = new HashMap<>();
+ fields.put("uuid", "text");
+ fields.put("emp_name", "text");
+ fields.put("emp_salary", "varint");
+ fields.put("PRIMARY KEY", "((emp_name),emp_name)");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setPrimaryKey("emp_name"); // "PRIMARY KEY" overrides if primaryKey present
+ jsonTable.setTableName(tableNameC);
+ jsonTable.setClusteringOrder("emp_salary ASC");
+ jsonTable.setFields(fields);
+ Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonTable, keyspaceName, tableNameC);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(400, response.getStatus());
+ }
+
+ // good composite partition key,clustering key
+ @Test
+ public void test3_createTable_3_pfartition_clusterKey_good() throws Exception {
+ System.out.println("Testing create w/ composite partition key, clusterKey");
+
+ String tableNameC = "testTableC3";
+ JsonTable jsonTable = new JsonTable();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, String> fields = new HashMap<>();
+ fields.put("uuid", "text");
+ fields.put("emp_name", "text");
+ fields.put("emp_id", "varint");
+ fields.put("emp_salary", "varint");
+ fields.put("PRIMARY KEY", "((emp_name,emp_id),emp_salary)");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setPrimaryKey("emp_name");
+ jsonTable.setTableName(tableNameC);
+ jsonTable.setClusteringOrder("emp_salary ASC");
+ jsonTable.setFields(fields);
+ Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonTable, keyspaceName, tableNameC);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(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 {
+ System.out.println("Testing create table bad request with clustering & composite keys");
+ String tableNameC = "testTableC5";
+ JsonTable jsonTable = new JsonTable();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, String> fields = new HashMap<>();
+ fields.put("uuid", "text");
+ fields.put("emp_name", "text");
+ fields.put("emp_id", "varint");
+ fields.put("emp_salary", "varint");
+ fields.put("PRIMARY KEY", "((uuid,emp_name),emp_id,emp_salary)");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setPrimaryKey("emp_name");
+ jsonTable.setTableName(tableNameC);
+ jsonTable.setClusteringOrder("emp_idx desc, emp_salary ASC");
+ jsonTable.setFields(fields);
+ Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonTable, keyspaceName, tableNameC);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(400, response.getStatus());
+ }
+
+ @Ignore
+ @Test
+ public void test3_createTablePartitionKey() throws Exception {
+ System.out.println("Testing create table with a partitionKey");
+ JsonTable jsonTable = new JsonTable();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, String> fields = new HashMap<>();
+ fields.put("uuid", "text");
+ fields.put("emp_name", "text");
+ fields.put("emp_salary", "varint");
+ fields.put("PRIMARY KEY", "(emp_name)");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setPrimaryKey("emp_name");
+ jsonTable.setTableName(tableName);
+ jsonTable.setFields(fields);
+ jsonTable.setPartitionKey("emp_salary");
+ Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonTable, keyspaceName, tableName);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ assertEquals(200, response.getStatus());
+ }
+
+ // good clustering key, need to pass queryparameter
+ @Test
+ public void test3_createTableIndex_1() throws Exception {
+ System.out.println("Testing index in create table");
+ String tableNameC = "testTableCinx";
+ JsonTable jsonTable = new JsonTable();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, String> fields = new HashMap<>();
+ fields.put("uuid", "text");
+ fields.put("emp_name", "text");
+ fields.put("emp_salary", "varint");
+ fields.put("PRIMARY KEY", "((emp_name),emp_salary)");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setTableName(tableNameC);
+ jsonTable.setClusteringOrder("emp_salary ASC");
+ jsonTable.setFields(fields);
+ Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonTable, keyspaceName, tableNameC);
+ // if 200 print to log otherwise fail assertEquals(200, response.getStatus());
+ // info.setQueryParameters("index_name=inx_uuid");
+ Map<String, String> queryParametersMap = new HashMap<String, String>();
+
+ queryParametersMap.put("index_name", "inxuuid");
+ Mockito.when(info.getQueryParameters()).thenReturn(new MultivaluedHashMap<String, String>(queryParametersMap));
+ response = data.createIndex("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
+ keyspaceName, tableNameC, "uuid", info);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(200, response.getStatus());
+ }
+
+ // create index without table name
+ @Test
+ public void test3_createTableIndexNoName() throws Exception {
+ System.out.println("Testing index in create table w/o tablename");
+ String tableNameC = "testTableCinx";
+ JsonTable jsonTable = new JsonTable();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, String> fields = new HashMap<>();
+ fields.put("uuid", "text");
+ fields.put("emp_name", "text");
+ fields.put("emp_salary", "varint");
+ fields.put("PRIMARY KEY", "((emp_name),emp_salary)");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setTableName(tableNameC);
+ jsonTable.setClusteringOrder("emp_salary ASC");
+ jsonTable.setFields(fields);
+ Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonTable, keyspaceName, tableNameC);
+ // if 200 print to log otherwise fail assertEquals(200, response.getStatus());
+ // info.setQueryParameters("index_name=inx_uuid");
+ Map<String, String> queryParametersMap = new HashMap<String, String>();
+
+ queryParametersMap.put("index_name", "inxuuid");
+ response = data.createIndex("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization, "",
+ "", "uuid", info);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(400, response.getStatus());
+ }
+
+ @Test
+ public void test4_insertIntoTable() throws Exception {
+ System.out.println("Testing insert into table");
+ createTable();
+ JsonInsert jsonInsert = new JsonInsert();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, Object> values = new HashMap<>();
+ values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
+ values.put("emp_name", "testname");
+ values.put("emp_salary", 500);
+ consistencyInfo.put("type", "eventual");
+ jsonInsert.setConsistencyInfo(consistencyInfo);
+ jsonInsert.setKeyspaceName(keyspaceName);
+ jsonInsert.setTableName(tableName);
+ jsonInsert.setValues(values);
+ Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonInsert, keyspaceName, tableName);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(200, response.getStatus());
+ }
+
+ @Test
+ public void test4_insertIntoTableCriticalNoLockID() throws Exception {
+ System.out.println("Testing atomic insert into table without lockid");
+ createTable();
+ JsonInsert jsonInsert = new JsonInsert();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, Object> values = new HashMap<>();
+ values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
+ values.put("emp_name", "testname");
+ values.put("emp_salary", 500);
+ consistencyInfo.put("type", "critical");
+ jsonInsert.setConsistencyInfo(consistencyInfo);
+ jsonInsert.setKeyspaceName(keyspaceName);
+ jsonInsert.setTableName(tableName);
+ jsonInsert.setValues(values);
+ Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonInsert, keyspaceName, tableName);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(400, response.getStatus());
+ }
+
+ @Test
+ public void test4_insertIntoTableNoName() throws Exception {
+ System.out.println("Testing insert into table w/o table name");
+ createTable();
+ JsonInsert jsonInsert = new JsonInsert();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, Object> values = new HashMap<>();
+ values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
+ values.put("emp_name", "testname");
+ values.put("emp_salary", 500);
+ consistencyInfo.put("type", "eventual");
+ jsonInsert.setConsistencyInfo(consistencyInfo);
+ jsonInsert.setKeyspaceName(keyspaceName);
+ jsonInsert.setTableName(tableName);
+ jsonInsert.setValues(values);
+ Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonInsert, "", "");
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(400, response.getStatus());
+ }
+
+ @Test
+ public void test4_insertIntoTable2() throws Exception {
+ System.out.println("Testing insert into table #2");
+ createTable();
+ JsonInsert jsonInsert = new JsonInsert();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, Object> values = new HashMap<>();
+ values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
+ values.put("emp_name", "test1");
+ values.put("emp_salary", 1500);
+ consistencyInfo.put("type", "eventual");
+ jsonInsert.setConsistencyInfo(consistencyInfo);
+ jsonInsert.setKeyspaceName(keyspaceName);
+ jsonInsert.setTableName(tableName);
+ jsonInsert.setValues(values);
+ Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonInsert, keyspaceName, tableName);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(200, response.getStatus());
+ }
+
+ // Auth Error
+ @Test
+ public void test4_insertIntoTable3() throws Exception {
+ System.out.println("Testing insert into table with bad credentials");
+ createTable();
+ JsonInsert jsonInsert = new JsonInsert();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, Object> values = new HashMap<>();
+ values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
+ values.put("emp_name", "test1");
+ values.put("emp_salary", 1500);
+ consistencyInfo.put("type", "eventual");
+ jsonInsert.setConsistencyInfo(consistencyInfo);
+ jsonInsert.setKeyspaceName(keyspaceName);
+ jsonInsert.setTableName(tableName);
+ jsonInsert.setValues(values);
+ Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ wrongAuthorization, jsonInsert, keyspaceName, tableName);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(401, response.getStatus());
+ }
+
+ // Table wrong
+ @Test
+ public void test4_insertIntoTable4() throws Exception {
+ System.out.println("Testing insert into wrong table");
+ createTable();
+ JsonInsert jsonInsert = new JsonInsert();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, Object> values = new HashMap<>();
+ values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
+ values.put("emp_name", "test1");
+ values.put("emp_salary", 1500);
+ consistencyInfo.put("type", "eventual");
+ jsonInsert.setConsistencyInfo(consistencyInfo);
+ jsonInsert.setKeyspaceName(keyspaceName);
+ jsonInsert.setTableName(tableName);
+ jsonInsert.setValues(values);
+ Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonInsert, keyspaceName, "wrong");
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(400, response.getStatus());
+ }
+
+ @Test
+ public void test4_insertBlobIntoTable() throws Exception {
+ System.out.println("Testing insert a blob into table");
+ createTable();
+ JsonInsert jsonInsert = new JsonInsert();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, Object> values = new HashMap<>();
+ values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
+ values.put("emp_name", "testname");
+ values.put("emp_salary", 500);
+ values.put("binary", "somestuffhere");
+ consistencyInfo.put("type", "eventual");
+ jsonInsert.setConsistencyInfo(consistencyInfo);
+ jsonInsert.setKeyspaceName(keyspaceName);
+ jsonInsert.setTableName(tableName);
+ jsonInsert.setValues(values);
+ Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonInsert, keyspaceName, tableName);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(200, response.getStatus());
+ }
+
+ @Test
+ public void test5_updateTable() throws Exception {
+ System.out.println("Testing update table");
+ createTable();
+
+ JsonUpdate jsonUpdate = new JsonUpdate();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ MultivaluedMap<String, String> row = new MultivaluedMapImpl();
+ Map<String, Object> values = new HashMap<>();
+ row.add("emp_name", "testname");
+ values.put("emp_salary", 2500);
+ consistencyInfo.put("type", "atomic");
+ jsonUpdate.setConsistencyInfo(consistencyInfo);
+ jsonUpdate.setKeyspaceName(keyspaceName);
+ jsonUpdate.setTableName(tableName);
+ jsonUpdate.setValues(values);
+ Mockito.when(info.getQueryParameters()).thenReturn(row);
+ Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonUpdate, keyspaceName, tableName, info);
+
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(200, response.getStatus());
+ }
+
+ @Test
+ public void test5_updateTableNoName() throws Exception {
+ System.out.println("Testing update table without tablename");
+ createTable();
+
+ JsonUpdate jsonUpdate = new JsonUpdate();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ MultivaluedMap<String, String> row = new MultivaluedMapImpl();
+ Map<String, Object> values = new HashMap<>();
+ row.add("emp_name", "testname");
+ values.put("emp_salary", 2500);
+ consistencyInfo.put("type", "atomic");
+ jsonUpdate.setConsistencyInfo(consistencyInfo);
+ jsonUpdate.setKeyspaceName(keyspaceName);
+ jsonUpdate.setTableName(tableName);
+ jsonUpdate.setValues(values);
+ Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonUpdate, "", "", info);
+
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(400, response.getStatus());
+ }
+
+ // need mock code to create error for MusicCore methods
+ @Test
+ public void test5_updateTableAuthE() throws Exception {
+ System.out.println("Testing update table #2");
+ createTable();
+ // MockitoAnnotations.initMocks(this);
+ JsonUpdate jsonUpdate = new JsonUpdate();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ MultivaluedMap<String, String> row = new MultivaluedMapImpl();
+ Map<String, Object> values = new HashMap<>();
+ row.add("emp_name", "testname");
+ values.put("emp_salary", 2500);
+ consistencyInfo.put("type", "atomic");
+ jsonUpdate.setConsistencyInfo(consistencyInfo);
+ jsonUpdate.setKeyspaceName(keyspaceName);
+ jsonUpdate.setTableName(tableName);
+ jsonUpdate.setValues(values);
+ // add ttl & timestamp
+ // Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Mockito.when(info.getQueryParameters()).thenReturn(row);
+ // Map<String, Object> m1= new HashMap<>() ;
+ // Mockito.when(MusicCore.autheticateUser(appName,userId,password,keyspaceName,"abc66ccc-d857-4e90-b1e5-df98a3d40ce6","updateTable")).thenReturn(m1);
+ Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonUpdate, keyspaceName, tableName, info);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(200, response.getStatus());
+ }
+
+ @Ignore
+ @Test
+ public void test5_updateTableAuthException1() throws Exception {
+ System.out.println("Testing update table authentication error");
+ createTable();
+ JsonUpdate jsonUpdate = new JsonUpdate();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ MultivaluedMap<String, String> row = new MultivaluedMapImpl();
+ Map<String, Object> values = new HashMap<>();
+ row.add("emp_name", "testname");
+ values.put("emp_salary", 2500);
+ consistencyInfo.put("type", "atomic");
+ jsonUpdate.setConsistencyInfo(consistencyInfo);
+ jsonUpdate.setKeyspaceName(keyspaceName);
+ jsonUpdate.setTableName(tableName);
+ jsonUpdate.setValues(values);
+
+ Mockito.when(info.getQueryParameters()).thenReturn(row);
+ String authDatax = ":";
+ String authorizationx = new String(Base64.encode(authDatax.getBytes()));
+ Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorizationx, jsonUpdate, keyspaceName, tableName, info);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(401, response.getStatus());
+ }
+
+ @Ignore
+ @Test
+ public void test5_updateTableAuthEmpty() throws Exception {
+ System.out.println("Testing update table without authentication");
+ createTable();
+
+ JsonUpdate jsonUpdate = new JsonUpdate();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ MultivaluedMap<String, String> row = new MultivaluedMapImpl();
+ Map<String, Object> values = new HashMap<>();
+ row.add("emp_name", "testname");
+ values.put("emp_salary", 2500);
+ consistencyInfo.put("type", "atomic");
+ jsonUpdate.setConsistencyInfo(consistencyInfo);
+ jsonUpdate.setKeyspaceName(keyspaceName);
+ jsonUpdate.setTableName(tableName);
+ jsonUpdate.setValues(values);
+
+ Mockito.when(info.getQueryParameters()).thenReturn(row);
+ String authDatax = ":" + password;
+ String authorizationx = new String(Base64.encode(authDatax.getBytes()));
+ String appNamex = "xx";
+ Response response = data.updateTable("1", "1", "1", "", appNamex, authorizationx, jsonUpdate, keyspaceName,
+ tableName, info);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(401, response.getStatus());
+ }
+
+
+ @Test
+ public void test6_select() throws Exception {
+ System.out.println("Testing select");
+ createAndInsertIntoTable();
+ JsonSelect jsonSelect = new JsonSelect();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ MultivaluedMap<String, String> row = new MultivaluedMapImpl();
+ row.add("emp_name", "testname");
+ consistencyInfo.put("type", "atomic");
+ jsonSelect.setConsistencyInfo(consistencyInfo);
+ Mockito.when(info.getQueryParameters()).thenReturn(row);
+ Response response = data.select("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
+ keyspaceName, tableName, info);
+ HashMap<String, HashMap<String, Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
+ HashMap<String, Object> result = map.get("result");
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ Map<String, String> row0 = (Map<String, String>) result.get("row 0");
+ assertEquals("testname", row0.get("emp_name"));
+ assertEquals(BigInteger.valueOf(500), row0.get("emp_salary"));
+ }
+
+ @Test
+ public void test6_selectCritical() throws Exception {
+ System.out.println("Testing select critical");
+ createAndInsertIntoTable();
+ JsonInsert jsonInsert = new JsonInsert();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ MultivaluedMap<String, String> row = new MultivaluedMapImpl();
+ row.add("emp_name", "testname");
+ consistencyInfo.put("type", "atomic");
+ jsonInsert.setConsistencyInfo(consistencyInfo);
+ Mockito.when(info.getQueryParameters()).thenReturn(row);
+ Response response = data.selectCritical("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonInsert, keyspaceName, tableName, info);
+ HashMap<String, HashMap<String, Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
+ HashMap<String, Object> result = map.get("result");
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ Map<String, String> row0 = (Map<String, String>) result.get("row 0");
+ assertEquals("testname", row0.get("emp_name"));
+ assertEquals(BigInteger.valueOf(500), row0.get("emp_salary"));
+ }
+
+ @Test
+ public void test6_deleteFromTable() throws Exception {
+ System.out.println("Testing delete from table");
+ createAndInsertIntoTable();
+ JsonDelete jsonDelete = new JsonDelete();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ MultivaluedMap<String, String> row = new MultivaluedMapImpl();
+ row.add("emp_name", "test1");
+ consistencyInfo.put("type", "atomic");
+ jsonDelete.setConsistencyInfo(consistencyInfo);
+ Mockito.when(info.getQueryParameters()).thenReturn(row);
+ Response response = data.deleteFromTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonDelete, keyspaceName, tableName, info);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(200, response.getStatus());
+ }
+
+ // Values
+ @Ignore
+ @Test
+ public void test6_deleteFromTable1() throws Exception {
+ System.out.println("Testing delete from table missing delete object");
+ createAndInsertIntoTable();
+
+ JsonDelete jsonDelete = new JsonDelete();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ MultivaluedMap<String, String> row = new MultivaluedMapImpl();
+ consistencyInfo.put("type", "atomic");
+ jsonDelete.setConsistencyInfo(consistencyInfo);
+ // Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Mockito.when(info.getQueryParameters()).thenReturn(row);
+ Response response = data.deleteFromTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonDelete, keyspaceName, tableName, info);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(400, response.getStatus());
+ }
+
+ // delObj
+ @Test
+ public void test6_deleteFromTable2() throws Exception {
+ System.out.println("Testing delete from table missing delete object");
+ createAndInsertIntoTable();
+ JsonDelete jsonDelete = new JsonDelete();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ consistencyInfo.put("type", "atomic");
+ jsonDelete.setConsistencyInfo(consistencyInfo);
+ Response response = data.deleteFromTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, null, keyspaceName, tableName, info);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(400, response.getStatus());
+ }
+
+ @Test
+ public void test7_dropTable() throws Exception {
+ System.out.println("Testing drop table");
+ createTable();
+ JsonTable jsonTable = new JsonTable();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ consistencyInfo.put("type", "atomic");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ Response response = data.dropTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, keyspaceName, tableName);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(200, response.getStatus());
+ }
+
+
+ @Test
+ public void test8_deleteKeyspace() throws Exception {
+ System.out.println("Testing drop keyspace");
+
+ JsonKeySpace jsonKeyspace = new JsonKeySpace();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, Object> replicationInfo = new HashMap<>();
+ consistencyInfo.put("type", "eventual");
+ replicationInfo.put("class", "SimpleStrategy");
+ replicationInfo.put("replication_factor", 1);
+ jsonKeyspace.setConsistencyInfo(consistencyInfo);
+ jsonKeyspace.setDurabilityOfWrites("true");
+ jsonKeyspace.setKeyspaceName("TestApp1");
+ jsonKeyspace.setReplicationInfo(replicationInfo);
+ Response response = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", authorization,
+ appName, keyspaceName);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(400, response.getStatus());
+ }
+
+ private static void createKeyspace() throws Exception {
+ // shouldn't really be doing this here, but create keyspace is currently turned off
+ PreparedQueryObject query = new PreparedQueryObject();
+ query.appendQueryString(CassandraCQL.createKeySpace);
+ MusicCore.eventualPut(query);
+
+ boolean isAAF = false;
+ String hashedpwd = BCrypt.hashpw(password, BCrypt.gensalt());
+ query = new PreparedQueryObject();
+ query.appendQueryString("INSERT into admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
+ + "password, username, is_aaf) values (?,?,?,?,?,?,?)");
+ query.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
+ query.addValue(MusicUtil.convertToActualDataType(DataType.text(), keyspaceName));
+ query.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
+ query.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
+ query.addValue(MusicUtil.convertToActualDataType(DataType.text(), hashedpwd));
+ query.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
+ query.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
+ CachingUtil.updateMusicCache(keyspaceName, appName);
+ CachingUtil.updateMusicValidateCache(appName, userId, hashedpwd);
+ MusicCore.eventualPut(query);
+ }
+
+ private void clearAllTablesFromKeyspace() throws MusicServiceException {
+ ArrayList<String> tableNames = new ArrayList<>();
+ PreparedQueryObject query = new PreparedQueryObject();
+ query.appendQueryString(
+ "SELECT table_name FROM system_schema.tables WHERE keyspace_name = '" + keyspaceName + "';");
+ ResultSet rs = MusicCore.get(query);
+ for (Row row : rs) {
+ tableNames.add(row.getString("table_name"));
+ }
+ for (String table : tableNames) {
+ query = new PreparedQueryObject();
+ query.appendQueryString("DROP TABLE " + keyspaceName + "." + table);
+ MusicCore.eventualPut(query);
+ }
+ }
+
+ /**
+ * Create a table {@link tableName} in {@link keyspaceName}
+ *
+ * @throws Exception
+ */
+ private void createTable() throws Exception {
+ JsonTable jsonTable = new JsonTable();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, String> fields = new HashMap<>();
+ fields.put("uuid", "text");
+ fields.put("emp_name", "text");
+ fields.put("emp_salary", "varint");
+ fields.put("binary", "blob");
+ 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);
+ }
+
+ /**
+ * Create table {@link createTable} and insert into said table
+ *
+ * @throws Exception
+ */
+ private void createAndInsertIntoTable() throws Exception {
+ createTable();
+
+ JsonInsert jsonInsert = new JsonInsert();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, Object> values = new HashMap<>();
+ values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
+ values.put("emp_name", "testname");
+ values.put("emp_salary", 500);
+ values.put("binary", "binarydatahere");
+ consistencyInfo.put("type", "eventual");
+ jsonInsert.setConsistencyInfo(consistencyInfo);
+ jsonInsert.setKeyspaceName(keyspaceName);
+ jsonInsert.setTableName(tableName);
+ jsonInsert.setValues(values);
+ Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonInsert, keyspaceName, tableName);
+ }
+}
diff --git a/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java b/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java
new file mode 100644
index 00000000..3896c52f
--- /dev/null
+++ b/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java
@@ -0,0 +1,311 @@
+/*
+ * ============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.assertTrue;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.ws.rs.core.Response;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mindrot.jbcrypt.BCrypt;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.music.authentication.CachingUtil;
+import org.onap.music.datastore.MusicDataStoreHandle;
+import org.onap.music.datastore.PreparedQueryObject;
+import org.onap.music.datastore.jsonobjects.JsonInsert;
+import org.onap.music.datastore.jsonobjects.JsonLeasedLock;
+import org.onap.music.datastore.jsonobjects.JsonTable;
+import org.onap.music.exceptions.MusicServiceException;
+import org.onap.music.lockingservice.cassandra.CassaLockStore;
+import org.onap.music.main.MusicCore;
+import org.onap.music.main.MusicUtil;
+import org.onap.music.rest.RestMusicDataAPI;
+import org.onap.music.rest.RestMusicLocksAPI;
+import com.datastax.driver.core.DataType;
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.Row;
+import com.sun.jersey.core.util.Base64;
+
+@RunWith(MockitoJUnitRunner.class)
+public class TstRestMusicLockAPI {
+
+ RestMusicLocksAPI lock = new RestMusicLocksAPI();
+ RestMusicDataAPI data = new RestMusicDataAPI();
+ static PreparedQueryObject testObject;
+
+ 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 onboardUUID = null;
+ static String lockName = "testcassa.employees.testname";
+
+ @BeforeClass
+ public static void init() throws Exception {
+ System.out.println("Testing RestMusicLock class");
+ try {
+ createKeyspace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new Exception("Unable to initialize before TestRestMusicData test class. " + e.getMessage());
+ }
+ }
+
+ @After
+ public void afterEachTest( ) throws MusicServiceException {
+ clearAllTablesFromKeyspace();
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ testObject = new PreparedQueryObject();
+ testObject.appendQueryString("DROP KEYSPACE IF EXISTS " + keyspaceName);
+ MusicCore.eventualPut(testObject);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void test_createLockReference() throws Exception {
+ System.out.println("Testing create lockref");
+ createAndInsertIntoTable();
+ Response response =lock.createLockReference(lockName,"1","1",authorization,
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
+ Map<String,Object> respMap = (Map<String, Object>) response.getEntity();
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ assertEquals(200, response.getStatus());
+ assertTrue(respMap.containsKey("lock"));
+ assertTrue(((Map<String,String>) respMap.get("lock")).containsKey("lock"));
+ }
+
+ @Test
+ public void test_accquireLock() throws Exception {
+ System.out.println("Testing acquire lock");
+ createAndInsertIntoTable();
+ String lockRef = createLockReference();
+
+ Response response = lock.accquireLock(lockRef, "1", "1", authorization,
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ assertEquals(200, response.getStatus());
+ }
+
+ @Test
+ public void test_accquireLockWLease() throws Exception {
+ System.out.println("Testing acquire lock with lease");
+ createAndInsertIntoTable();
+ String lockRef = createLockReference();
+
+ JsonLeasedLock jsonLock = new JsonLeasedLock();
+ jsonLock.setLeasePeriod(10000); //10 second lease period?
+ Response response = lock.accquireLockWithLease(jsonLock, lockRef, "1", "1", authorization,
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ assertEquals(200, response.getStatus());
+ }
+
+ @Test
+ public void test_accquireBadLock() throws Exception {
+ System.out.println("Testing acquire lock that is not lock-holder");
+ createAndInsertIntoTable();
+
+ String lockRef1 = createLockReference();
+ String lockRef2 = createLockReference();
+
+
+ Response response = lock.accquireLock(lockRef2, "1", "1", authorization,
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ assertEquals(400, response.getStatus());
+ }
+
+ @Test
+ public void test_currentLockHolder() throws Exception {
+ System.out.println("Testing get current lock holder");
+ createAndInsertIntoTable();
+
+ String lockRef = createLockReference();
+
+ Response response = lock.currentLockHolder(lockName, "1", "1", authorization,
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ assertEquals(200, response.getStatus());
+ Map<String,Object> respMap = (Map<String, Object>) response.getEntity();
+ assertEquals(lockRef, ((Map<String,String>) respMap.get("lock")).get("lock-holder"));
+ }
+
+ @Test
+ public void test_unLock() throws Exception {
+ System.out.println("Testing unlock");
+ createAndInsertIntoTable();
+ String lockRef = createLockReference();
+
+ Response response = lock.unLock(lockRef, "1", "1", authorization,
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ assertEquals(200, response.getStatus());
+ }
+
+ @Test
+ public void test_getLockState() throws Exception {
+ System.out.println("Testing get lock state");
+ createAndInsertIntoTable();
+
+ String lockRef = createLockReference();
+
+ Response response = lock.currentLockState(lockName, "1", "1", authorization,
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ assertEquals(200, response.getStatus());
+ Map<String,Object> respMap = (Map<String, Object>) response.getEntity();
+ assertEquals(lockRef, ((Map<String,String>) respMap.get("lock")).get("lock-holder"));
+ }
+
+ @Test
+ public void test_deleteLock() throws Exception {
+ System.out.println("Testing get lock state");
+ createAndInsertIntoTable();
+
+ String lockRef = createLockReference();
+
+ Response response = lock.deleteLock(lockName, "1", "1",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", authorization, appName);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ assertEquals(200, response.getStatus());
+ }
+
+ /**
+ * Create table and lock reference
+ * @return the lock ref created
+ * @throws Exception
+ */
+ @SuppressWarnings("unchecked")
+ private String createLockReference() throws Exception {
+ Response response =lock.createLockReference(lockName,"1","1",authorization,
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
+ Map<String,Object> respMap = (Map<String, Object>) response.getEntity();
+ return ((Map<String,String>) respMap.get("lock")).get("lock");
+ }
+
+
+
+
+ private static void createKeyspace() throws Exception {
+ //shouldn't really be doing this here, but create keyspace is currently turned off
+ PreparedQueryObject query = new PreparedQueryObject();
+ query.appendQueryString(CassandraCQL.createKeySpace);
+ MusicCore.eventualPut(query);
+
+ boolean isAAF = false;
+ String hashedpwd = BCrypt.hashpw(password, BCrypt.gensalt());
+ query = new PreparedQueryObject();
+ query.appendQueryString(
+ "INSERT into admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
+ + "password, username, is_aaf) values (?,?,?,?,?,?,?)");
+ query.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
+ query.addValue(MusicUtil.convertToActualDataType(DataType.text(), keyspaceName));
+ query.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
+ query.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
+ query.addValue(MusicUtil.convertToActualDataType(DataType.text(), hashedpwd));
+ query.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
+ query.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
+ CachingUtil.updateMusicCache(keyspaceName, appName);
+ CachingUtil.updateMusicValidateCache(appName, userId, hashedpwd);
+ MusicCore.eventualPut(query);
+ }
+
+ private void clearAllTablesFromKeyspace() throws MusicServiceException {
+ ArrayList<String> tableNames = new ArrayList<>();
+ PreparedQueryObject query = new PreparedQueryObject();
+ query.appendQueryString("SELECT table_name FROM system_schema.tables WHERE keyspace_name = '"+keyspaceName+"';");
+ ResultSet rs = MusicCore.get(query);
+ for (Row row: rs) {
+ tableNames.add(row.getString("table_name"));
+ }
+ for (String table: tableNames) {
+ query = new PreparedQueryObject();
+ query.appendQueryString("DROP TABLE " + keyspaceName + "." + table);
+ MusicCore.eventualPut(query);
+ }
+ }
+
+ /**
+ * Create a table {@link tableName} in {@link keyspaceName}
+ * @throws Exception
+ */
+ private void createTable() throws Exception {
+ JsonTable jsonTable = new JsonTable();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, String> fields = new HashMap<>();
+ fields.put("uuid", "text");
+ fields.put("emp_name", "text");
+ fields.put("emp_salary", "varint");
+ fields.put("PRIMARY KEY", "(emp_name)");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setPrimaryKey("emp_name");
+ jsonTable.setTableName(tableName);
+ jsonTable.setFields(fields);
+ //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Response response = data.createTable("1", "1", "1",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization,
+ jsonTable, keyspaceName, tableName);
+ }
+
+ /**
+ * Create table {@link createTable} and insert into said table
+ * @throws Exception
+ */
+ private void createAndInsertIntoTable() throws Exception {
+ createTable();
+
+ JsonInsert jsonInsert = new JsonInsert();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, Object> values = new HashMap<>();
+ values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
+ values.put("emp_name", "testname");
+ values.put("emp_salary", 500);
+ consistencyInfo.put("type", "eventual");
+ jsonInsert.setConsistencyInfo(consistencyInfo);
+ jsonInsert.setKeyspaceName(keyspaceName);
+ jsonInsert.setTableName(tableName);
+ jsonInsert.setValues(values);
+ Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
+ appName, authorization, jsonInsert, keyspaceName, tableName);
+ }
+}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java
index 4c5af38f..a069b81d 100644
--- a/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java
+++ b/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java
@@ -4,6 +4,8 @@
* ===================================================================
* Copyright (c) 2017 AT&T Intellectual Property
* ===================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ===================================================================
* 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
@@ -25,25 +27,24 @@ package org.onap.music.unittests.jsonobjects;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.onap.music.datastore.jsonobjects.JsonDelete;
public class JsonDeleteTest {
-
+
JsonDelete jd = null;
-
+
@Before
public void init() {
jd = new JsonDelete();
}
-
-
+
@Test
public void testGetConditions() {
Map<String,Object> mapSo = new HashMap<>();
- mapSo = new HashMap<>();
mapSo.put("key1","one");
mapSo.put("key2","two");
jd.setConditions(mapSo);
@@ -53,7 +54,6 @@ public class JsonDeleteTest {
@Test
public void testGetConsistencyInfo() {
Map<String,String> mapSs = new HashMap<>();
- mapSs = new HashMap<>();
mapSs.put("key3","three");
mapSs.put("key4","four");
jd.setConsistencyInfo(mapSs);
@@ -62,8 +62,7 @@ public class JsonDeleteTest {
@Test
public void testGetColumns() {
- ArrayList<String> ary = new ArrayList<>();
- ary = new ArrayList<>();
+ List<String> ary = new ArrayList<>();
ary.add("e1");
ary.add("e2");
ary.add("e3");
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java
index 2279cf0b..4e3b4629 100644
--- a/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java
+++ b/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java
@@ -78,13 +78,6 @@ public class JsonTableTest {
}
@Test
- public void testGetSortingKey() {
- String sortKey = "sortkey";
- jt.setSortingKey(sortKey);
- assertEquals(sortKey,jt.getSortingKey());
- }
-
- @Test
public void testGetClusteringOrder() {
String clusteringOrder = "clusteringOrder";
jt.setClusteringOrder(clusteringOrder);