aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/onap')
-rw-r--r--src/test/java/org/onap/music/benchmarks/MicroBenchMarkRestClient.java73
-rw-r--r--src/test/java/org/onap/music/benchmarks/MicroBenchMarks.java440
-rw-r--r--src/test/java/org/onap/music/e2eTests/MusicConnector.java80
-rw-r--r--src/test/java/org/onap/music/e2eTests/TestMusicE2E.java478
-rw-r--r--src/test/java/org/onap/music/unittests/CassandraCQL.java3
-rw-r--r--src/test/java/org/onap/music/unittests/MusicDataStoreTest.java214
-rw-r--r--src/test/java/org/onap/music/unittests/MusicUtilTest.java20
-rw-r--r--src/test/java/org/onap/music/unittests/TestMusicCore.java71
-rw-r--r--src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java176
-rw-r--r--src/test/java/org/onap/music/unittests/TestRestMusicData.java450
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/AAFResponseTest.java54
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java86
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java86
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java72
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonLeasedLockTest.java53
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonOnboardTest.java78
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java41
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java99
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java103
19 files changed, 1484 insertions, 1193 deletions
diff --git a/src/test/java/org/onap/music/benchmarks/MicroBenchMarkRestClient.java b/src/test/java/org/onap/music/benchmarks/MicroBenchMarkRestClient.java
deleted file mode 100644
index 2dcecfc2..00000000
--- a/src/test/java/org/onap/music/benchmarks/MicroBenchMarkRestClient.java
+++ /dev/null
@@ -1,73 +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.benchmarks;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import org.onap.music.main.MusicUtil;
-
-
-@Path("/tests")
-public class MicroBenchMarkRestClient {
- static double version = 9.7;
-
- @GET
- @Path("/run")
- @Produces(MediaType.TEXT_PLAIN)
- public String runTests() {
- String testType = MusicUtil.getTestType();
- String candidateName = "shankar" + System.currentTimeMillis();
- MicroBenchMarks msHandle = new MicroBenchMarks();
- switch (testType) {
- case "musicPut":
- return msHandle.musicPutAndUpdate(candidateName);
-
- case "musicCriticalPut":
- return msHandle.musicCriticalPutAndUpdate(candidateName);
-
- case "musicGet":
- return msHandle.musicGet();
-
- case "cassaPut":
- return msHandle.cassaPutAndUpdate(candidateName);
-
- case "cassaQuorumPut":
- return msHandle.cassaQuorumPutAndUpdate(candidateName);
-
- case "cassaGet":
- return msHandle.cassaGet();
-
- case "zkPut":
- return msHandle.zkPutAndUpdate(candidateName);
-
- case "zkGet":
- return msHandle.zkGet();
-
- }
- return "something wrong!";
-
- }
-
-}
-
diff --git a/src/test/java/org/onap/music/benchmarks/MicroBenchMarks.java b/src/test/java/org/onap/music/benchmarks/MicroBenchMarks.java
deleted file mode 100644
index c267d254..00000000
--- a/src/test/java/org/onap/music/benchmarks/MicroBenchMarks.java
+++ /dev/null
@@ -1,440 +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.benchmarks;
-
-import java.util.HashMap;
-import java.util.Map;
-import javax.ws.rs.core.MediaType;
-import org.onap.music.datastore.jsonobjects.JsonInsert;
-import org.onap.music.datastore.jsonobjects.JsonKeySpace;
-import org.onap.music.datastore.jsonobjects.JsonTable;
-import org.onap.music.main.MusicUtil;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.client.config.ClientConfig;
-import com.sun.jersey.api.client.config.DefaultClientConfig;
-import com.sun.jersey.api.json.JSONConfiguration;
-
-public class MicroBenchMarks {
- final String keyspaceName = "shankarks";
- final String musicurl = "http://" + MusicUtil.getMusicRestIp() + ":8080/MUSIC/rest/formal";
- final String userForGets = "shankarUserForGets";
-
- public MicroBenchMarks() {
- bootStrap();
- }
-
- private void createVotingKeyspace() {
- System.out.println(keyspaceName);
- Map<String, Object> replicationInfo = new HashMap<String, Object>();
- replicationInfo.put("class", "SimpleStrategy");
- replicationInfo.put("replication_factor", 3);
- String durabilityOfWrites = "false";
- Map<String, String> consistencyInfo = new HashMap<String, String>();
- consistencyInfo.put("type", "eventual");
- JsonKeySpace jsonKp = new JsonKeySpace();
- jsonKp.setConsistencyInfo(consistencyInfo);
- jsonKp.setDurabilityOfWrites(durabilityOfWrites);
- jsonKp.setReplicationInfo(replicationInfo);
-
- ClientConfig clientConfig = new DefaultClientConfig();
-
- clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
-
- Client client = Client.create(clientConfig);
-
- WebResource webResource = client.resource(musicurl + "/keyspaces/" + keyspaceName);
-
- ClientResponse response = webResource.accept("application/json").type("application/json")
- .post(ClientResponse.class, jsonKp);
-
- if (response.getStatus() < 200 || response.getStatus() > 299)
- throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
-
- }
-
- private void createVotingTable() {
- Map<String, String> fields = new HashMap<String, String>();
- fields.put("name", "text");
- fields.put("count", "varint");
- fields.put("PRIMARY KEY", "(name)");
-
-
- Map<String, String> consistencyInfo = new HashMap<String, String>();
- consistencyInfo.put("type", "eventual");
-
- JsonTable jtab = new JsonTable();
- jtab.setFields(fields);
- jtab.setConsistencyInfo(consistencyInfo);
-
- ClientConfig clientConfig = new DefaultClientConfig();
-
- clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
-
- Client client = Client.create(clientConfig);
-
- WebResource webResource = client
- .resource(musicurl + "/keyspaces/" + keyspaceName + "/tables/votecount");
-
- ClientResponse response = webResource.accept("application/json").type("application/json")
- .post(ClientResponse.class, jtab);
-
- if (response.getStatus() < 200 || response.getStatus() > 299)
- throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
-
- }
-
- private void createEntryForCandidate(String candidateName) {
- Map<String, Object> values = new HashMap<String, Object>();
- values.put("name", candidateName);
- values.put("count", 0);
-
- Map<String, String> consistencyInfo = new HashMap<String, String>();
- consistencyInfo.put("type", "eventual");
-
- JsonInsert jIns = new JsonInsert();
- jIns.setValues(values);
- jIns.setConsistencyInfo(consistencyInfo);
- ClientConfig clientConfig = new DefaultClientConfig();
-
- clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
-
- Client client = Client.create(clientConfig);
-
- String url = musicurl + "/keyspaces/" + keyspaceName + "/tables/votecount/rows";
- WebResource webResource = client.resource(url);
-
- ClientResponse response = webResource.accept("application/json").type("application/json")
- .post(ClientResponse.class, jIns);
-
- if (response.getStatus() < 200 || response.getStatus() > 299)
- throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
- }
-
- private String createLock(String lockName) {
- Client client = Client.create();
- String msg = musicurl + "/locks/create/" + lockName;
- WebResource webResource = client.resource(msg);
- System.out.println(msg);
-
- WebResource.Builder wb = webResource.accept(MediaType.TEXT_PLAIN);
-
- ClientResponse response = wb.post(ClientResponse.class);
-
- if (response.getStatus() != 200) {
- throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
- }
-
- String output = response.getEntity(String.class);
-
- return output;
- }
-
- private boolean acquireLock(String lockId) {
- Client client = Client.create();
- String msg = musicurl + "/locks/acquire/" + lockId;
- System.out.println(msg);
- WebResource webResource = client.resource(msg);
-
-
- WebResource.Builder wb = webResource.accept(MediaType.TEXT_PLAIN);
-
- ClientResponse response = wb.get(ClientResponse.class);
-
- if (response.getStatus() != 200) {
- throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
- }
-
- String output = response.getEntity(String.class);
- Boolean status = Boolean.parseBoolean(output);
- System.out.println("Server response .... \n");
- System.out.println(output);
- return status;
- }
-
- private void unlock(String lockId) {
- Client client = Client.create();
- WebResource webResource = client.resource(musicurl + "/locks/release/" + lockId);
-
- ClientResponse response = webResource.delete(ClientResponse.class);
-
-
- if (response.getStatus() != 204) {
- throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
- }
- }
-
- public String musicCriticalPutAndUpdate(String candidateName) {
- /*
- * create lock for the candidate. The music API dictates that the lock name must be of the
- * form keyspacename.tableName.primaryKeyName
- */
- createEntryForCandidate(candidateName);
- System.out.println("trying to acquire lock!");
-
- String lockName = keyspaceName + ".votecount." + candidateName;
- String lockId = createLock(lockName);
- while (acquireLock(lockId) != true);
-
- System.out.println("acquired lock!");
- // update candidate entry if you have the lock
- Map<String, Object> values = new HashMap<String, Object>();
- values.put("count", 5);
-
- Map<String, String> consistencyInfo = new HashMap<String, String>();
- consistencyInfo.put("type", "atomic");
- consistencyInfo.put("lockId", lockId);
-
- JsonInsert jIns = new JsonInsert();
- jIns.setValues(values);
- jIns.setConsistencyInfo(consistencyInfo);
- ClientConfig clientConfig = new DefaultClientConfig();
-
- clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
-
- Client client = Client.create(clientConfig);
- String url = musicurl + "/keyspaces/" + keyspaceName + "/tables/votecount/rows?name="
- + candidateName;
- WebResource webResource = client.resource(url);
-
- ClientResponse response = webResource.accept("application/json").type("application/json")
- .put(ClientResponse.class, jIns);
-
- if (response.getStatus() < 200 || response.getStatus() > 299)
- throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
-
- // release lock now that the operation is done
- unlock(lockId);
- return "musicCriticalPutAndUpdate:" + url;
-
- }
-
- public String musicPutAndUpdate(String candidateName) {
- createEntryForCandidate(candidateName);
-
- Map<String, Object> values = new HashMap<String, Object>();
- values.put("count", 5);
-
- Map<String, String> consistencyInfo = new HashMap<String, String>();
- consistencyInfo.put("type", "eventual");
-
- JsonInsert jIns = new JsonInsert();
- jIns.setValues(values);
- jIns.setConsistencyInfo(consistencyInfo);
- ClientConfig clientConfig = new DefaultClientConfig();
-
- clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
-
- Client client = Client.create(clientConfig);
- String url = musicurl + "/keyspaces/" + keyspaceName + "/tables/votecount/rows?name="
- + candidateName;
- WebResource webResource = client.resource(url);
-
- ClientResponse response = webResource.accept("application/json").type("application/json")
- .put(ClientResponse.class, jIns);
-
- if (response.getStatus() < 200 || response.getStatus() > 299)
- throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
- return "musicPutAndUpdate:" + url;
- }
-
- public String musicGet() {
- ClientConfig clientConfig = new DefaultClientConfig();
-
- clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
-
- Client client = Client.create(clientConfig);
-
- String url = musicurl + "/keyspaces/" + keyspaceName + "/tables/votecount/rows?name="
- + userForGets;
- WebResource webResource = client.resource(url);
-
- ClientResponse response = webResource.accept("application/json").get(ClientResponse.class);
-
- if (response.getStatus() < 200 || response.getStatus() > 299)
- throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
-
- Map<String, Object> output = response.getEntity(Map.class);
- return "musicGet:" + url;
- }
-
- public String cassaQuorumPutAndUpdate(String candidateName) {
- // http://135.197.226.98:8080/MUSIC/rest/formal/purecassa/keyspaces/shankarks/tables/employees/rows?emp_name=shankaruser1
- Map<String, Object> values = new HashMap<String, Object>();
- values.put("count", 5);
-
- Map<String, String> consistencyInfo = new HashMap<String, String>();
- consistencyInfo.put("type", "atomic");
-
- JsonInsert jIns = new JsonInsert();
- jIns.setValues(values);
- jIns.setConsistencyInfo(consistencyInfo);
- ClientConfig clientConfig = new DefaultClientConfig();
-
- clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
-
- Client client = Client.create(clientConfig);
- String url = musicurl + "/purecassa/keyspaces/" + keyspaceName
- + "/tables/votecount/rows?name=" + candidateName;
- WebResource webResource = client.resource(url);
-
- ClientResponse response = webResource.accept("application/json").type("application/json")
- .put(ClientResponse.class, jIns);
-
- if (response.getStatus() < 200 || response.getStatus() > 299)
- throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
- return "cassaQuorumPutAndUpdate:" + url;
-
- }
-
- public String cassaPutAndUpdate(String candidateName) {
- // http://135.197.226.98:8080/MUSIC/rest/formal/purecassa/keyspaces/shankarks/tables/employees/rows?emp_name=shankaruser1
- long start = System.currentTimeMillis();
- createEntryForCandidate(candidateName);
-
- Map<String, Object> values = new HashMap<String, Object>();
- values.put("count", 5);
-
- Map<String, String> consistencyInfo = new HashMap<String, String>();
- consistencyInfo.put("type", "eventual");
-
- JsonInsert jIns = new JsonInsert();
- jIns.setValues(values);
- jIns.setConsistencyInfo(consistencyInfo);
- ClientConfig clientConfig = new DefaultClientConfig();
-
- clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
-
- Client client = Client.create(clientConfig);
- String url = musicurl + "/purecassa/keyspaces/" + keyspaceName
- + "/tables/votecount/rows?name=" + candidateName;
- WebResource webResource = client.resource(url);
- long end = System.currentTimeMillis();
- String time = (end - start) + "";
-
- start = System.currentTimeMillis();
- ClientResponse response = webResource.accept("application/json").type("application/json")
- .put(ClientResponse.class, jIns);
- end = System.currentTimeMillis();
- String time2 = (end - start) + "";
- if (response.getStatus() < 200 || response.getStatus() > 299)
- throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
- return "cassaPutAndUpdate:" + url;
- }
-
- public String cassaGet() {
- ClientConfig clientConfig = new DefaultClientConfig();
-
- clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
-
- Client client = Client.create(clientConfig);
-
- String url = musicurl + "/keyspaces/" + keyspaceName + "/tables/votecount/rows?name="
- + userForGets;
- WebResource webResource = client.resource(url);
-
- ClientResponse response = webResource.accept("application/json").get(ClientResponse.class);
-
- if (response.getStatus() < 200 || response.getStatus() > 299)
- throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
-
- Map<String, Object> output = response.getEntity(Map.class);
- return "cassaGet:" + url;
- }
-
- private void zkCreate(String candidateName) {
- // http://135.197.226.98:8080/MUSIC/rest/formal/purezk/shankarzknode
- ClientConfig clientConfig = new DefaultClientConfig();
-
- clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
-
- Client client = Client.create(clientConfig);
-
- WebResource webResource = client.resource(musicurl + "/purezk/" + candidateName);
-
- ClientResponse response = webResource.accept("application/json").type("application/json")
- .post(ClientResponse.class);
-
- if (response.getStatus() < 200 || response.getStatus() > 299)
- throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
- }
-
- public String zkPutAndUpdate(String candidateName) {
- // http://135.197.226.99:8080/MUSIC/rest/formal/purezk/shankarzknode
-
- // CREATE IT FIRST
- zkCreate(candidateName);
-
- Map<String, Object> values = new HashMap<String, Object>();
- values.put("count", 5);
-
- Map<String, String> consistencyInfo = new HashMap<String, String>();
- consistencyInfo.put("type", "atomic");
-
- JsonInsert jIns = new JsonInsert();
- jIns.setValues(values);
- jIns.setConsistencyInfo(consistencyInfo);
- ClientConfig clientConfig = new DefaultClientConfig();
-
- clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
-
- Client client = Client.create(clientConfig);
- String url = musicurl + "/purezk/" + candidateName;
- System.out.println("in zk put:" + url);
- WebResource webResource = client.resource(url);
-
- ClientResponse response = webResource.accept("application/json").type("application/json")
- .put(ClientResponse.class, jIns);
-
- if (response.getStatus() < 200 || response.getStatus() > 299)
- throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
-
- return "zkPutAndUpdate:" + url;
- }
-
- public String zkGet() {
- Client client = Client.create();
- String url = musicurl + "/purezk/" + userForGets;
- System.out.println("in zk get:" + url);
- WebResource webResource = client.resource(url);
-
- ClientResponse response = webResource.accept("text/plain").get(ClientResponse.class);
-
- if (response.getStatus() != 200) {
- throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
- }
-
- String output = response.getEntity(String.class);
- return "zkGet:" + url;
- }
-
-
- public void bootStrap() {
- // createVotingKeyspace();
- // createVotingTable();
- // createEntryForCandidate(userForGets);
- // zkPutAndUpdate(userForGets);
- }
-
-
-}
diff --git a/src/test/java/org/onap/music/e2eTests/MusicConnector.java b/src/test/java/org/onap/music/e2eTests/MusicConnector.java
deleted file mode 100644
index bb3d1f1b..00000000
--- a/src/test/java/org/onap/music/e2eTests/MusicConnector.java
+++ /dev/null
@@ -1,80 +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.e2eTests;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.Random;
-
-public class MusicConnector {
-
- // change this to point to relevant cluster
- public String[] musicNodes;
-
- public MusicConnector(String[] musicNodes) {
- this.musicNodes = musicNodes;
- }
-
- private String getMusicNodeIp() {
- Random r = new Random();
- int index = r.nextInt(musicNodes.length);
- return musicNodes[index];
- }
-
- /*
- * public static String toggle(String serverAddress){ if(serverAddress.equals(agaveMusicNode)){
- * System.out.println("Agave is down...connect to Big Site"); serverAddress = bigSiteMusicNode;
- * }else if(serverAddress.equals(bigSiteMusicNode)){
- * System.out.println("Big Site is down...connect to Agave"); serverAddress = agaveMusicNode; }
- * return serverAddress; }
- */
-
- public String getMusicNodeURL() {
- String musicurl = "http://" + getMusicNodeIp() + ":8080/MUSIC/rest";
- System.out.println(musicurl);
- return musicurl;
- }
-
- public boolean isHostUp(String serverAddress) {
- Boolean isUp = false;
- try {
- InetAddress inet = InetAddress.getByName(serverAddress);
- isUp = inet.isReachable(1000);
- } catch (UnknownHostException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return isUp;
- }
-
- /*
- * private static String getMusicNodeIp(){
- *
- * //return "54.224.168.13"; return bigSiteMusicNode; String serverAddress; serverAddress =
- * agaveMusicNode; while(isHostUp(serverAddress) != true) serverAddress = toggle(serverAddress);
- * return serverAddress; }
- */
-}
diff --git a/src/test/java/org/onap/music/e2eTests/TestMusicE2E.java b/src/test/java/org/onap/music/e2eTests/TestMusicE2E.java
deleted file mode 100644
index 25021e82..00000000
--- a/src/test/java/org/onap/music/e2eTests/TestMusicE2E.java
+++ /dev/null
@@ -1,478 +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.e2eTests;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-import javax.ws.rs.core.MediaType;
-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.JsonTable;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.client.config.ClientConfig;
-import com.sun.jersey.api.client.config.DefaultClientConfig;
-import com.sun.jersey.api.json.JSONConfiguration;
-
-public class TestMusicE2E {
- String keyspaceName;
- ArrayList<String> lockNames;
- MusicConnector musicHandle;
-
- public TestMusicE2E(String[] musicIps) {
- lockNames = new ArrayList<String>();
- musicHandle = new MusicConnector(musicIps);
- bootStrap();
- }
-
- public void createVotingKeyspace() {
- keyspaceName = "VotingAppForMusic" + System.currentTimeMillis();
- Map<String, Object> replicationInfo = new HashMap<String, Object>();
- replicationInfo.put("class", "SimpleStrategy");
- replicationInfo.put("replication_factor", 1);
- String durabilityOfWrites = "false";
- Map<String, String> consistencyInfo = new HashMap<String, String>();
- consistencyInfo.put("type", "eventual");
- JsonKeySpace jsonKp = new JsonKeySpace();
- jsonKp.setConsistencyInfo(consistencyInfo);
- jsonKp.setDurabilityOfWrites(durabilityOfWrites);
- jsonKp.setReplicationInfo(replicationInfo);
-
- ClientConfig clientConfig = new DefaultClientConfig();
-
- clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
-
- Client client = Client.create(clientConfig);
-
- WebResource webResource = client
- .resource(musicHandle.getMusicNodeURL() + "/keyspaces/" + keyspaceName);
-
- ClientResponse response = webResource.accept("application/json").type("application/json")
- .post(ClientResponse.class, jsonKp);
-
- if (response.getStatus() < 200 || response.getStatus() > 299)
- throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
-
- }
-
- public void createVotingTable() {
- Map<String, String> fields = new HashMap<String, String>();
- fields.put("name", "text");
- fields.put("count", "varint");
- fields.put("PRIMARY KEY", "(name)");
-
-
- Map<String, String> consistencyInfo = new HashMap<String, String>();
- consistencyInfo.put("type", "eventual");
-
- JsonTable jtab = new JsonTable();
- jtab.setFields(fields);
- jtab.setConsistencyInfo(consistencyInfo);
-
- ClientConfig clientConfig = new DefaultClientConfig();
-
- clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
-
- Client client = Client.create(clientConfig);
- String url = musicHandle.getMusicNodeURL() + "/keyspaces/" + keyspaceName
- + "/tables/votecount";
- System.out.println("create url:" + url);
- WebResource webResource = client.resource(url);
-
- ClientResponse response = webResource.accept("application/json").type("application/json")
- .post(ClientResponse.class, jtab);
-
- if (response.getStatus() < 200 || response.getStatus() > 299)
- throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
-
- }
-
- private void checkMusicVersion() {
- Client client = Client.create();
- System.out.println(musicHandle.getMusicNodeURL() + "/version");
-
-
- // System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
- WebResource webResource = client.resource(musicHandle.getMusicNodeURL() + "/version");
-
-
- ClientResponse response = webResource.accept("text/plain").header("Connection", "close")
- .get(ClientResponse.class);
-
- if (response.getStatus() != 200) {
- throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
- }
-
- String output = response.getEntity(String.class);
-
- // System.out.println("Output from Server .... \n");
- System.out.println(output);
-
- }
-
- private void createEntryForCandidate(String candidateName) {
- Map<String, Object> values = new HashMap<String, Object>();
- values.put("name", candidateName);
- values.put("count", 0);
-
- Map<String, String> consistencyInfo = new HashMap<String, String>();
- consistencyInfo.put("type", "eventual");
-
- JsonInsert jIns = new JsonInsert();
- jIns.setValues(values);
- jIns.setConsistencyInfo(consistencyInfo);
- ClientConfig clientConfig = new DefaultClientConfig();
-
- clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
-
- Client client = Client.create(clientConfig);
-
- String url = musicHandle.getMusicNodeURL() + "/keyspaces/" + keyspaceName
- + "/tables/votecount/rows";
- WebResource webResource = client.resource(url);
-
- ClientResponse response = webResource.accept("application/json").type("application/json")
- .post(ClientResponse.class, jIns);
-
- if (response.getStatus() < 200 || response.getStatus() > 299)
- throw new RuntimeException("Failed : HTTP error code : " + response.getStatus() + "url:"
- + url + " candidate name:" + candidateName);
-
-
- }
-
- private String createLock(String lockName) {
- Client client = Client.create();
- String msg = musicHandle.getMusicNodeURL() + "/locks/create/" + lockName;
- WebResource webResource = client.resource(msg);
- System.out.println(msg);
- WebResource.Builder wb = webResource.accept(MediaType.TEXT_PLAIN);
-
- ClientResponse response = wb.post(ClientResponse.class);
-
- if (response.getStatus() != 200) {
- throw new RuntimeException(
- "Failed : HTTP error code : " + response.getStatus() + "url:" + msg);
- }
-
- String output = response.getEntity(String.class);
-
- // System.out.println("Server response .... \n");
- // System.out.println(output);
- return output;
- }
-
- private boolean acquireLock(String lockId) {
- Client client = Client.create();
- String msg = musicHandle.getMusicNodeURL() + "/locks/acquire/" + lockId;
- System.out.println(msg);
- WebResource webResource = client.resource(msg);
-
-
- WebResource.Builder wb = webResource.accept(MediaType.TEXT_PLAIN);
-
- ClientResponse response = wb.get(ClientResponse.class);
-
- if (response.getStatus() != 200) {
- throw new RuntimeException(
- "Failed : HTTP error code : " + response.getStatus() + "url:" + msg);
- }
-
- String output = response.getEntity(String.class);
- Boolean status = Boolean.parseBoolean(output);
- System.out.println("Server response .... \n");
- System.out.println(output);
- return status;
- }
-
- private void unlock(String lockId) {
- Client client = Client.create();
- WebResource webResource =
- client.resource(musicHandle.getMusicNodeURL() + "/locks/release/" + lockId);
-
- ClientResponse response = webResource.delete(ClientResponse.class);
-
-
- if (response.getStatus() != 204) {
- throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
- }
- }
-
- private void updateVoteCountAtomically(String candidateName, int count) {
- /*
- * create lock for the candidate. The music API dictates that the lock name must be of the
- * form keyspacename.tableName.primaryKeyName
- */
- System.out.println("trying to acquire lock!");
-
- String lockName = keyspaceName + ".votecount." + candidateName;
- lockNames.add(lockName);
- String lockId = createLock(lockName);
- while (acquireLock(lockId) != true);
-
- System.out.println("acquired lock!");
- // update candidate entry if you have the lock
- Map<String, Object> values = new HashMap<String, Object>();
- values.put("count", count);
-
- Map<String, String> consistencyInfo = new HashMap<String, String>();
- consistencyInfo.put("type", "critical");
- consistencyInfo.put("lockId", lockId);
-
- JsonInsert jIns = new JsonInsert();
- jIns.setValues(values);
- jIns.setConsistencyInfo(consistencyInfo);
- ClientConfig clientConfig = new DefaultClientConfig();
-
- clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
-
- Client client = Client.create(clientConfig);
- String url = musicHandle.getMusicNodeURL() + "/keyspaces/" + keyspaceName
- + "/tables/votecount/rows?name=" + candidateName;
- System.out.println(url);
- WebResource webResource = client.resource(url);
-
- ClientResponse response = webResource.accept("application/json").type("application/json")
- .put(ClientResponse.class, jIns);
-
- if (response.getStatus() < 200 || response.getStatus() > 299)
- throw new RuntimeException(
- "Failed : HTTP error code : " + response.getStatus() + "url:" + url);
-
- // release lock now that the operation is done
- unlock(lockId);
-
- }
-
- private void deleteCandidateEntryEventually(String candidateName) {
- Map<String, String> consistencyInfo = new HashMap<String, String>();
- consistencyInfo.put("type", "eventual");
-
- JsonDelete jDel = new JsonDelete();
- jDel.setConsistencyInfo(consistencyInfo);
- ClientConfig clientConfig = new DefaultClientConfig();
-
- clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
-
- Client client = Client.create(clientConfig);
- String url = musicHandle.getMusicNodeURL() + "/keyspaces/" + keyspaceName
- + "/tables/votecount/rows?name=" + candidateName;
- System.out.println(url);
- WebResource webResource = client.resource(url);
-
- ClientResponse response = webResource.accept("application/json").type("application/json")
- .delete(ClientResponse.class, jDel);
-
- if (response.getStatus() < 200 || response.getStatus() > 299)
- throw new RuntimeException(
- "Failed : HTTP error code : " + response.getStatus() + "url:" + url);
-
- }
-
- public Map<String, Object> readVoteCountForCandidate(String candidateName) {
- ClientConfig clientConfig = new DefaultClientConfig();
-
- clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
-
- Client client = Client.create(clientConfig);
- String url = musicHandle.getMusicNodeURL() + "/keyspaces/" + keyspaceName
- + "/tables/votecount/rows?name=" + candidateName;
- WebResource webResource = client.resource(url);
-
- ClientResponse response = webResource.accept("application/json").get(ClientResponse.class);
-
- if (response.getStatus() < 200 || response.getStatus() > 299)
- throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
-
- Map<String, Object> output = response.getEntity(Map.class);
- return output;
- }
-
- public Map<String, Object> readAllVotes() {
- ClientConfig clientConfig = new DefaultClientConfig();
-
- clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
-
- Client client = Client.create(clientConfig);
- String url = musicHandle.getMusicNodeURL() + "/keyspaces/" + keyspaceName
- + "/tables/votecount/rows";
- WebResource webResource = client.resource(url);
-
- ClientResponse response = webResource.accept("application/json").get(ClientResponse.class);
-
- if (response.getStatus() < 200 || response.getStatus() > 299)
- throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
-
- Map<String, Object> output = response.getEntity(Map.class);
- return output;
- }
-
-
- /*
- * Unable to use this because of the error: Exception in thread "main"
- * com.sun.jersey.api.client.ClientHandlerException: java.net.ProtocolException: HTTP method
- * DELETE doesn't support output. Seems to be a error in the rest java combination according to
- * the interwebs
- */
- private void dropKeySpace() {
- Map<String, String> consistencyInfo = new HashMap<String, String>();
- consistencyInfo.put("type", "eventual");
-
- JsonKeySpace jsonKp = new JsonKeySpace();
- jsonKp.setConsistencyInfo(consistencyInfo);
-
- ClientConfig clientConfig = new DefaultClientConfig();
-
- clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
-
- Client client = Client.create(clientConfig);
-
- WebResource webResource = client
- .resource(musicHandle.getMusicNodeURL() + "/keyspaces/" + keyspaceName);
-
- ClientResponse response =
- webResource.type("application/json").delete(ClientResponse.class, jsonKp);
-
- if (response.getStatus() < 200 || response.getStatus() > 299)
- throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
- }
-
- private void deleteLock(String lockName) {
- Client client = Client.create();
- WebResource webResource = client
- .resource(musicHandle.getMusicNodeURL() + "/locks/delete/" + lockName);
-
- ClientResponse response = webResource.delete(ClientResponse.class);
-
-
- if (response.getStatus() != 204) {
- throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
- }
- }
-
- private void resetMusic() {
- Client client = Client.create();
- WebResource webResource = client.resource(musicHandle.getMusicNodeURL() + "/reset");
-
- ClientResponse response = webResource.delete(ClientResponse.class);
-
-
- if (response.getStatus() != 204) {
- throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
- }
-
- }
-
- public void deleteAllLocks() {
- for (String lockName : lockNames) {
- deleteLock(lockName);
- }
- }
-
-
- public void bootStrap() {
- checkMusicVersion();
- createVotingKeyspace();
-
-
- createVotingTable();
-
-
- // the next few lines just create an entry in the voting table for all these candidates with
- // vote count as 0
- createEntryForCandidate("Popeye");
-
- createEntryForCandidate("Judy");
-
- createEntryForCandidate("Flash");
-
- createEntryForCandidate("Mickey");
-
- }
-
- public void overAllTests() {
- // update the count atomically
- updateVoteCountAtomically("Popeye", 5);
-
- updateVoteCountAtomically("Judy", 7);
-
- updateVoteCountAtomically("Mickey", 8);
-
- updateVoteCountAtomically("Flash", 2);
-
-
- // read votecount
- System.out.println(readAllVotes());
-
- System.out.println(readVoteCountForCandidate("Popeye"));
-
- System.out.println(readVoteCountForCandidate("Flash"));
-
- deleteCandidateEntryEventually("Mickey");
-
- System.out.println(readAllVotes());
-
- dropKeySpace();
-
- deleteAllLocks();
- }
-
- public void flipTest() {
- checkMusicVersion();
- }
-
- public static String executeBashScript(String pathToScript, String arg1, String arg2) {
- try {
- ProcessBuilder pb = new ProcessBuilder(pathToScript, arg1, arg2);
- final Process process = pb.start();
- InputStream is = process.getInputStream();
- InputStreamReader isr = new InputStreamReader(is);
- BufferedReader br = new BufferedReader(isr);
- return br.readLine();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
-
- public static void main(String[] args) {
- long start = System.currentTimeMillis();
- for (int i = 0; i < 2; ++i) {
- TestMusicE2E vHandle = new TestMusicE2E(args);
- vHandle.overAllTests();
-
- System.out.println("=====================================");
- System.out.println("Test no." + i + " completed:");
- }
- long diff = System.currentTimeMillis() - start;
- System.out.println(diff);
- }
-
-
-}
diff --git a/src/test/java/org/onap/music/unittests/CassandraCQL.java b/src/test/java/org/onap/music/unittests/CassandraCQL.java
index ed8f13f4..a4c250c2 100644
--- a/src/test/java/org/onap/music/unittests/CassandraCQL.java
+++ b/src/test/java/org/onap/music/unittests/CassandraCQL.java
@@ -232,13 +232,14 @@ public class CassandraCQL {
try {
try {
- EmbeddedCassandraServerHelper.startEmbeddedCassandra(60000);
+ EmbeddedCassandraServerHelper.startEmbeddedCassandra(80000);
} catch (ConfigurationException | TTransportException | IOException e) {
System.out.println(e.getMessage());
}
cluster = new Cluster.Builder().addContactPoint(address).withPort(9142).build();
+ cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(20000);
session = cluster.connect();
break;
diff --git a/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java b/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java
index 520a5fe4..16d2af02 100644
--- a/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java
+++ b/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java
@@ -22,6 +22,7 @@
package org.onap.music.unittests;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -34,113 +35,128 @@ import org.onap.music.exceptions.MusicServiceException;
import org.onap.music.datastore.MusicDataStore;
import org.onap.music.datastore.PreparedQueryObject;
+
+import com.datastax.driver.core.DataType;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
+import com.datastax.driver.core.TableMetadata;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class MusicDataStoreTest {
- static MusicDataStore dataStore;
- static PreparedQueryObject testObject;
+ static MusicDataStore dataStore;
+ static PreparedQueryObject testObject;
- @BeforeClass
- public static void init() {
- dataStore = CassandraCQL.connectToEmbeddedCassandra();
+ @BeforeClass
+ public static void init() {
+ dataStore = CassandraCQL.connectToEmbeddedCassandra();
- }
+ }
- @AfterClass
- public static void close() throws MusicServiceException, MusicQueryException {
+ @AfterClass
+ public static void close() throws MusicServiceException, MusicQueryException {
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.dropKeyspace);
- dataStore.executePut(testObject, "eventual");
- dataStore.close();
-
- }
-
- @Test
- public void Test1_SetUp() throws MusicServiceException, MusicQueryException {
- boolean result = false;
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.createKeySpace);
- result = dataStore.executePut(testObject, "eventual");;
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.createTableEmployees);
- result = dataStore.executePut(testObject, "eventual");
- assertEquals(true, result);
-
- }
-
- @Test
- public void Test2_ExecutePut_eventual_insert() throws MusicServiceException, MusicQueryException {
- testObject = CassandraCQL.setPreparedInsertQueryObject1();
- boolean result = dataStore.executePut(testObject, "eventual");
- assertEquals(true, result);
- }
-
- @Test
- public void Test3_ExecutePut_critical_insert() throws MusicServiceException, MusicQueryException {
- testObject = CassandraCQL.setPreparedInsertQueryObject2();
- boolean result = dataStore.executePut(testObject, "Critical");
- assertEquals(true, result);
- }
-
- @Test
- public void Test4_ExecutePut_eventual_update() throws MusicServiceException, MusicQueryException {
- testObject = CassandraCQL.setPreparedUpdateQueryObject();
- boolean result = false;
- result = dataStore.executePut(testObject, "eventual");
- assertEquals(true, result);
- }
-
- @Test
- public void Test5_ExecuteEventualGet() throws MusicServiceException, MusicQueryException {
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.selectALL);
- boolean result = false;
- int count = 0;
- ResultSet output = null;
- output = dataStore.executeEventualGet(testObject);
- System.out.println(output);
- ;
- for (Row row : output) {
- count++;
- System.out.println(row.toString());
- }
- if (count == 2) {
- result = true;
- }
- assertEquals(true, result);
- }
-
- @Test
- public void Test6_ExecuteCriticalGet() throws MusicServiceException, MusicQueryException {
- testObject = CassandraCQL.setPreparedGetQuery();
- boolean result = false;
- int count = 0;
- ResultSet output = null;
- output = dataStore.executeCriticalGet(testObject);
- System.out.println(output);
- ;
- for (Row row : output) {
- count++;
- System.out.println(row.toString());
- }
- if (count == 1) {
- result = true;
- }
- assertEquals(true, result);
- }
-
- @Test(expected = NullPointerException.class)
- public void Test7_exception() {
- PreparedQueryObject queryObject = null;
- try {
- dataStore.executePut(queryObject, "critical");
- } catch (MusicQueryException | MusicServiceException e) {
- System.out.println(e.getMessage());
- }
-
- }
+ testObject = new PreparedQueryObject();
+ testObject.appendQueryString(CassandraCQL.dropKeyspace);
+ dataStore.executePut(testObject, "eventual");
+ dataStore.close();
+
+ }
+
+ @Test
+ public void Test1_SetUp() throws MusicServiceException, MusicQueryException {
+ boolean result = false;
+ testObject = new PreparedQueryObject();
+ testObject.appendQueryString(CassandraCQL.createKeySpace);
+ result = dataStore.executePut(testObject, "eventual");;
+ testObject = new PreparedQueryObject();
+ testObject.appendQueryString(CassandraCQL.createTableEmployees);
+ result = dataStore.executePut(testObject, "eventual");
+ assertEquals(true, result);
+
+ }
+
+ @Test
+ public void Test2_ExecutePut_eventual_insert() throws MusicServiceException, MusicQueryException {
+ testObject = CassandraCQL.setPreparedInsertQueryObject1();
+ boolean result = dataStore.executePut(testObject, "eventual");
+ assertEquals(true, result);
+ }
+
+ @Test
+ public void Test3_ExecutePut_critical_insert() throws MusicServiceException, MusicQueryException {
+ testObject = CassandraCQL.setPreparedInsertQueryObject2();
+ boolean result = dataStore.executePut(testObject, "Critical");
+ assertEquals(true, result);
+ }
+
+ @Test
+ public void Test4_ExecutePut_eventual_update() throws MusicServiceException, MusicQueryException {
+ testObject = CassandraCQL.setPreparedUpdateQueryObject();
+ boolean result = false;
+ result = dataStore.executePut(testObject, "eventual");
+ assertEquals(true, result);
+ }
+
+ @Test
+ public void Test5_ExecuteEventualGet() throws MusicServiceException, MusicQueryException {
+ testObject = new PreparedQueryObject();
+ testObject.appendQueryString(CassandraCQL.selectALL);
+ boolean result = false;
+ int count = 0;
+ ResultSet output = null;
+ output = dataStore.executeEventualGet(testObject);
+ System.out.println(output);
+ ;
+ for (Row row : output) {
+ count++;
+ System.out.println(row.toString());
+ }
+ if (count == 2) {
+ result = true;
+ }
+ assertEquals(true, result);
+ }
+
+ @Test
+ public void Test6_ExecuteCriticalGet() throws MusicServiceException, MusicQueryException {
+ testObject = CassandraCQL.setPreparedGetQuery();
+ boolean result = false;
+ int count = 0;
+ ResultSet output = null;
+ output = dataStore.executeCriticalGet(testObject);
+ System.out.println(output);
+ ;
+ for (Row row : output) {
+ count++;
+ System.out.println(row.toString());
+ }
+ if (count == 1) {
+ result = true;
+ }
+ assertEquals(true, result);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void Test7_exception() {
+ PreparedQueryObject queryObject = null;
+ try {
+ dataStore.executePut(queryObject, "critical");
+ } catch (MusicQueryException | MusicServiceException e) {
+ System.out.println(e.getMessage());
+ }
+ }
+
+ @Test
+ public void Test8_columnDataType() {
+ DataType data = dataStore.returnColumnDataType("testCassa", "employees", "empName");
+ String datatype = data.toString();
+ assertEquals("text",datatype);
+ }
+
+ @Test
+ public void Test8_columnMetdaData() {
+ TableMetadata data = dataStore.returnColumnMetadata("testCassa", "employees");
+ assertNotNull(data);
+ }
}
diff --git a/src/test/java/org/onap/music/unittests/MusicUtilTest.java b/src/test/java/org/onap/music/unittests/MusicUtilTest.java
index 35ec3791..47edc1e3 100644
--- a/src/test/java/org/onap/music/unittests/MusicUtilTest.java
+++ b/src/test/java/org/onap/music/unittests/MusicUtilTest.java
@@ -73,11 +73,11 @@ public class MusicUtilTest {
assertEquals(MusicUtil.getAllIds().get(0),"1");
}
- @Test
- public void testGetPublicIp() {
- MusicUtil.setPublicIp("10.0.0.1");
- assertEquals(MusicUtil.getPublicIp(),"10.0.0.1");
- }
+// @Test
+// public void testGetPublicIp() {
+// MusicUtil.setPublicIp("10.0.0.1");
+// assertEquals(MusicUtil.getPublicIp(),"10.0.0.1");
+// }
@Test
public void testGetAllPublicIps() {
@@ -124,11 +124,11 @@ public class MusicUtilTest {
assertEquals(MusicUtil.getVersion(),"1.0.0");
}
- @Test
+ /*@Test
public void testGetMyZkHost() {
MusicUtil.setMyZkHost("10.0.0.2");
assertEquals(MusicUtil.getMyZkHost(),"10.0.0.2");
- }
+ }*/
@Test
public void testGetMyCassaHost() {
@@ -169,7 +169,7 @@ public class MusicUtilTest {
}
@Test
- public void testConvertToCQLDataType() {
+ public void testConvertToCQLDataType() throws Exception {
Map<String,Object> myMap = new HashMap<String,Object>();
myMap.put("name","tom");
assertEquals(MusicUtil.convertToCQLDataType(DataType.varchar(),"Happy People"),"'Happy People'");
@@ -179,7 +179,7 @@ public class MusicUtilTest {
}
@Test
- public void testConvertToActualDataType() {
+ public void testConvertToActualDataType() throws Exception {
assertEquals(MusicUtil.convertToActualDataType(DataType.varchar(),"Happy People"),"Happy People");
assertEquals(MusicUtil.convertToActualDataType(DataType.uuid(),"29dc2afa-c2c0-47ae-afae-e72a645308ab"),UUID.fromString("29dc2afa-c2c0-47ae-afae-e72a645308ab"));
assertEquals(MusicUtil.convertToActualDataType(DataType.varint(),"1234"),BigInteger.valueOf(Long.parseLong("1234")));
@@ -195,7 +195,7 @@ public class MusicUtilTest {
}
@Test
- public void testJsonMaptoSqlString() {
+ public void testJsonMaptoSqlString() throws Exception {
Map<String,Object> myMap = new HashMap<>();
myMap.put("name","tom");
myMap.put("value",5);
diff --git a/src/test/java/org/onap/music/unittests/TestMusicCore.java b/src/test/java/org/onap/music/unittests/TestMusicCore.java
index 2deb3496..c571085a 100644
--- a/src/test/java/org/onap/music/unittests/TestMusicCore.java
+++ b/src/test/java/org/onap/music/unittests/TestMusicCore.java
@@ -37,12 +37,14 @@ import org.onap.music.lockingservice.MusicLockState;
import org.onap.music.lockingservice.MusicLockingService;
import org.onap.music.lockingservice.MusicLockState.LockStatus;
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.main.MusicCore.Condition;
import org.onap.music.datastore.MusicDataStore;
import org.onap.music.datastore.PreparedQueryObject;
import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.Session;
@RunWith(MockitoJUnitRunner.class)
public class TestMusicCore {
@@ -55,6 +57,9 @@ public class TestMusicCore {
@Mock
private PreparedQueryObject preparedQueryObject;
+
+ @Mock
+ private Session session;
@Before
public void setUp() {
@@ -145,6 +150,29 @@ public class TestMusicCore {
assertEquals(lock.getMessage(), "Lockid doesn't exist");
Mockito.verify(mLockHandle).lockIdExists("bs1");
}
+
+ @Test
+ public void testAcquireLockWithLeasewithLease() throws MusicLockingException {
+ MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
+ musicLockState.setLeasePeriod(0);
+ ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
+ Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
+ Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
+ ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
+ assertEquals(expectedResult.getResult(), actualResult.getResult());
+ Mockito.verify(mLockHandle).isMyTurn("id1");
+ Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
+ }
+
+ @Test
+ public void testAcquireLockWithLeasewithException() throws MusicLockingException {
+ ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "failure");
+ Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenThrow(new MusicLockingException());
+ Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
+ ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
+ assertEquals(expectedResult.getResult(), actualResult.getResult());
+ Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
+ }
@Test
public void testAcquireLockWithLeasewithLockStatusLOCKED() throws MusicLockingException {
@@ -183,15 +211,17 @@ public class TestMusicCore {
Mockito.verify(mLockHandle).getLockState("ks1.tn1.pk1");
}
- /*
- * @Test public void testQuorumGet() { mDstoreHandle = Mockito.mock(MusicDataStore.class); rs =
- * Mockito.mock(ResultSet.class);
- * Mockito.when(mDstoreHandle.executeCriticalGet("qu1")).thenReturn(rs); ResultSet rs1 =
- * MusicCore.quorumGet("qu1"); assertNotNull(rs1);
- * Mockito.verify(mDstoreHandle).executeCriticalGet("qu1");
- *
- * }
- */
+ @Test
+ public void testQuorumGet() throws MusicServiceException, MusicQueryException {
+ preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
+ mDstoreHandle = Mockito.mock(MusicDataStore.class);
+ rs = Mockito.mock(ResultSet.class);
+ session = Mockito.mock(Session.class);
+ Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
+ Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs);
+ ResultSet rs1 = MusicCore.quorumGet(preparedQueryObject);
+ assertNotNull(rs1);
+ }
@Test
public void testGetLockNameFromId() {
@@ -244,6 +274,8 @@ public class TestMusicCore {
mDstoreHandle = Mockito.mock(MusicDataStore.class);
preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
+ session = Mockito.mock(Session.class);
+ Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "eventual")).thenReturn(true);
ReturnType actualResult = MusicCore.eventualPut(preparedQueryObject);
assertEquals(expectedResult.getResult(), actualResult.getResult());
@@ -256,19 +288,24 @@ public class TestMusicCore {
mDstoreHandle = Mockito.mock(MusicDataStore.class);
preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
+ session = Mockito.mock(Session.class);
+ Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "eventual")).thenReturn(false);
ReturnType actualResult = MusicCore.eventualPut(preparedQueryObject);
assertEquals(expectedResult.getResult(), actualResult.getResult());
Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "eventual");
+ //Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, MusicUtil.EVENTUAL);
}
@Test
public void testCriticalPutPreparedQuerywithValidLockId()
- throws MusicServiceException, MusicQueryException, MusicLockingException {
+ throws Exception {
mDstoreHandle = Mockito.mock(MusicDataStore.class);
preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
Mockito.when(condition.testCondition()).thenReturn(true);
+ session = Mockito.mock(Session.class);
+ Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
.thenReturn(musicLockState);
@@ -296,7 +333,7 @@ public class TestMusicCore {
}
@Test
- public void testCriticalPutPreparedQuerywithvalidLockIdandTestConditionFalse() throws MusicLockingException {
+ public void testCriticalPutPreparedQuerywithvalidLockIdandTestConditionFalse() throws Exception {
mDstoreHandle = Mockito.mock(MusicDataStore.class);
preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
@@ -315,6 +352,8 @@ public class TestMusicCore {
public void testNonKeyRelatedPutPreparedQuery() throws Exception {
mDstoreHandle = Mockito.mock(MusicDataStore.class);
preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
+ session = Mockito.mock(Session.class);
+ Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "consistency")).thenReturn(true);
Boolean result = MusicCore.nonKeyRelatedPut(preparedQueryObject, "consistency");
assertTrue(result);
@@ -322,12 +361,14 @@ public class TestMusicCore {
}
@Test
- public void testAtomicPutPreparedQuery() throws MusicServiceException, MusicQueryException, MusicLockingException {
+ public void testAtomicPutPreparedQuery() throws Exception {
mDstoreHandle = Mockito.mock(MusicDataStore.class);
preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
+ session = Mockito.mock(Session.class);
+ Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
Mockito.when(condition.testCondition()).thenReturn(true);
@@ -365,6 +406,8 @@ public class TestMusicCore {
mDstoreHandle = Mockito.mock(MusicDataStore.class);
preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
rs = Mockito.mock(ResultSet.class);
+ session = Mockito.mock(Session.class);
+ Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
@@ -401,6 +444,8 @@ public class TestMusicCore {
mDstoreHandle = Mockito.mock(MusicDataStore.class);
rs = Mockito.mock(ResultSet.class);
preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
+ session = Mockito.mock(Session.class);
+ Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
Mockito.when(mDstoreHandle.executeEventualGet(preparedQueryObject)).thenReturn(rs);
ResultSet rs1 = MusicCore.get(preparedQueryObject);
assertNotNull(rs1);
@@ -414,6 +459,8 @@ public class TestMusicCore {
preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
rs = Mockito.mock(ResultSet.class);
+ session = Mockito.mock(Session.class);
+ Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
.thenReturn(musicLockState);
Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs);
diff --git a/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java b/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java
new file mode 100644
index 00000000..823badaa
--- /dev/null
+++ b/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java
@@ -0,0 +1,176 @@
+/*
+ * ============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.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import java.io.File;
+import java.util.List;
+import org.apache.curator.test.TestingServer;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+import org.onap.music.datastore.PreparedQueryObject;
+import org.onap.music.exceptions.MusicQueryException;
+import org.onap.music.exceptions.MusicServiceException;
+import org.onap.music.lockingservice.MusicLockState;
+import org.onap.music.lockingservice.MusicLockingService;
+import org.onap.music.lockingservice.MusicLockState.LockStatus;
+import org.onap.music.main.MusicCore;
+import org.onap.music.main.MusicUtil;
+import org.onap.music.main.ResultType;
+import org.onap.music.main.ReturnType;
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.Row;
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestMusicCoreIntegration {
+
+ static TestingServer zkServer;
+ static PreparedQueryObject testObject;
+ static String lockId = null;
+ static String lockName = "ks1.tb1.pk1";
+
+ @BeforeClass
+ public static void init() throws Exception {
+ try {
+ MusicCore.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra();
+ zkServer = new TestingServer(2181, new File("/tmp/zk"));
+ MusicCore.mLockHandle = new MusicLockingService();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ System.out.println("####Port:" + zkServer.getPort());
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ System.out.println("After class");
+ testObject = new PreparedQueryObject();
+ testObject.appendQueryString(CassandraCQL.dropKeyspace);
+ MusicCore.eventualPut(testObject);
+ MusicCore.deleteLock(lockName);
+ MusicCore.mDstoreHandle.close();
+ MusicCore.mLockHandle.getzkLockHandle().close();
+ MusicCore.mLockHandle.close();
+ zkServer.stop();
+
+ }
+
+ @Test
+ public void Test1_SetUp() throws MusicServiceException, MusicQueryException {
+ MusicCore.mLockHandle = new MusicLockingService();
+ boolean result = false;
+ testObject = new PreparedQueryObject();
+ testObject.appendQueryString(CassandraCQL.createKeySpace);
+ MusicCore.eventualPut(testObject);
+ testObject = new PreparedQueryObject();
+ testObject.appendQueryString(CassandraCQL.createTableEmployees);
+ result = MusicCore.nonKeyRelatedPut(testObject, MusicUtil.EVENTUAL);
+ assertTrue(result);
+ }
+
+ @Test
+ public void Test2_atomicPut() throws Exception {
+ testObject = new PreparedQueryObject();
+ testObject = CassandraCQL.setPreparedInsertQueryObject1();
+ ReturnType returnType = MusicCore.atomicPut("testCassa", "employees", "Mr Test one",
+ testObject, null);
+ assertEquals(ResultType.SUCCESS, returnType.getResult());
+ }
+
+ @Test
+ public void Test3_atomicPutWithDeleteLock() throws Exception {
+ testObject = new PreparedQueryObject();
+ testObject = CassandraCQL.setPreparedInsertQueryObject2();
+ ReturnType returnType = MusicCore.atomicPutWithDeleteLock("testCassa", "employees",
+ "Mr Test two", testObject, null);
+ assertEquals(ResultType.SUCCESS, returnType.getResult());
+ }
+
+ @Test
+ public void Test4_atomicGetWithDeleteLock() throws Exception {
+ testObject = new PreparedQueryObject();
+ testObject = CassandraCQL.setPreparedGetQuery();
+ ResultSet resultSet = MusicCore.atomicGetWithDeleteLock("testCassa", "employees",
+ "Mr Test one", testObject);
+ List<Row> rows = resultSet.all();
+ assertEquals(1, rows.size());
+ }
+
+ @Test
+ public void Test5_atomicGet() throws Exception {
+ testObject = new PreparedQueryObject();
+ testObject = CassandraCQL.setPreparedGetQuery();
+ ResultSet resultSet =
+ MusicCore.atomicGet("testCassa", "employees", "Mr Test two", testObject);
+ List<Row> rows = resultSet.all();
+ assertEquals(1, rows.size());
+ }
+
+ @Test
+ public void Test6_createLockReference() throws Exception {
+ lockId = MusicCore.createLockReference(lockName);
+ assertNotNull(lockId);
+ }
+
+ @Test
+ public void Test7_acquireLockwithLease() throws Exception {
+ ReturnType lockLeaseStatus = MusicCore.acquireLockWithLease(lockName, lockId, 1000);
+ assertEquals(ResultType.SUCCESS, lockLeaseStatus.getResult());
+ }
+
+ @Test
+ public void Test8_acquireLock() throws Exception {
+ ReturnType lockStatus = MusicCore.acquireLock(lockName, lockId);
+ assertEquals(ResultType.SUCCESS, lockStatus.getResult());
+ }
+
+ @Test
+ public void Test9_release() throws Exception {
+ MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
+ MusicLockState musicLockState1 = new MusicLockState(LockStatus.UNLOCKED, "id1");
+ MusicCore.whoseTurnIsIt(lockName);
+ MusicLockState mls = MusicCore.getMusicLockState(lockName);
+ boolean voluntaryRelease = true;
+ MusicLockState mls1 = MusicCore.releaseLock(lockId, voluntaryRelease);
+ assertEquals(musicLockState.getLockStatus(), mls.getLockStatus());
+ assertEquals(musicLockState1.getLockStatus(), mls1.getLockStatus());
+ }
+
+ @Test
+ public void Test10_create() {
+ MusicCore.pureZkCreate("/nodeName");
+ }
+
+ @Test
+ public void Test11_write() {
+ MusicCore.pureZkWrite("nodeName", "I'm Test".getBytes());
+ }
+
+ @Test
+ public void Test12_read() {
+ byte[] data = MusicCore.pureZkRead("nodeName");
+ String data1 = new String(data);
+ assertEquals("I'm Test", data1);
+ }
+
+}
diff --git a/src/test/java/org/onap/music/unittests/TestRestMusicData.java b/src/test/java/org/onap/music/unittests/TestRestMusicData.java
new file mode 100644
index 00000000..e4d06f70
--- /dev/null
+++ b/src/test/java/org/onap/music/unittests/TestRestMusicData.java
@@ -0,0 +1,450 @@
+/*
+ * ============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.onap.music.main.MusicCore.mLockHandle;
+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.UriInfo;
+import org.apache.curator.test.TestingServer;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+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.MusicLockingService;
+import org.onap.music.main.CachingUtil;
+import org.onap.music.main.MusicCore;
+import org.onap.music.main.MusicUtil;
+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.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 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 {
+ MusicCore.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra();
+ zkServer = new TestingServer(2181, new File(" mp/zk"));
+ MusicCore.mLockHandle = new MusicLockingService();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ System.out.println("After class");
+ testObject = new PreparedQueryObject();
+ testObject.appendQueryString("DROP KEYSPACE IF EXISTS " + keyspaceName);
+ MusicCore.eventualPut(testObject);
+ testObject = new PreparedQueryObject();
+ testObject.appendQueryString("DROP KEYSPACE IF EXISTS admin");
+ MusicCore.eventualPut(testObject);
+ MusicCore.mDstoreHandle.close();
+ MusicCore.mLockHandle.getzkLockHandle().close();
+ MusicCore.mLockHandle.close();
+ zkServer.stop();
+ }
+
+ @Test
+ public void Test1_createKeyspace() throws Exception {
+ testObject = new PreparedQueryObject();
+ testObject.appendQueryString("CREATE KEYSPACE admin WITH REPLICATION = "
+ + "{'class' : 'SimpleStrategy' , "
+ + "'replication_factor': 1} AND DURABLE_WRITES = true");
+ MusicCore.eventualPut(testObject);
+ testObject = new PreparedQueryObject();
+ testObject.appendQueryString(
+ "CREATE TABLE admin.keyspace_master (" + " uuid uuid, keyspace_name text,"
+ + " application_name text, is_api boolean,"
+ + " password text, username text,"
+ + " is_aaf boolean, PRIMARY KEY (uuid)\n" + ");");
+ MusicCore.eventualPut(testObject);
+
+ testObject = new PreparedQueryObject();
+ testObject.appendQueryString(
+ "INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
+ + "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)");
+ testObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
+ testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(),
+ MusicUtil.DEFAULTKEYSPACENAME));
+ testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
+ testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
+ testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), password));
+ 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(), password));
+ 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());
+ Map<String, Object> resultMap = data.createKeySpace("1", "1", "1", null, appName, userId,
+ password, jsonKeyspace, keyspaceName, http);
+ assertEquals(uuid.toString(), resultMap.get("aid"));
+ }
+
+ @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());
+ Map<String, Object> resultMap = data.createKeySpace("1", "1", "1", null, "TestApp1",
+ "TestUser1", password, jsonKeyspace, keyspaceName, http);
+ System.out.println("#######status is " + resultMap.get("Exception"));
+ assertEquals("Couldn't create keyspace. Please make sure all the information is correct.",
+ resultMap.get("Exception"));
+ }
+
+ @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());
+ Map<String, Object> resultMap = data.createTable("1", "1", "1",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
+ jsonTable, keyspaceName, tableName, http);
+ assertEquals("SUCCESS", resultMap.get("status"));
+ }
+
+ @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());
+ Map<String, Object> resultMap = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
+ appName, userId, password, jsonInsert, keyspaceName, tableName, http);
+ assertEquals("Success", resultMap.get("result"));
+ }
+
+ @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());
+ Map<String, Object> resultMap = data.insertIntoTable("1", "1", "1",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
+ jsonInsert, keyspaceName, tableName, http);
+ assertEquals("Success", resultMap.get("result"));
+ }
+
+ @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);
+ Map<String, Object> resultMap = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ userId, password, jsonUpdate, keyspaceName, tableName, info, http);
+ assertEquals("Success", resultMap.get("result"));
+ }
+
+ @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);
+ Map<String, HashMap<String, Object>> resultMap = data.select("1", "1", "1",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password, keyspaceName, tableName, info, http);
+ assertEquals("2500", resultMap.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);
+ Map<String, HashMap<String, Object>> resultMap = data.selectCritical("1", "1", "1",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password, jsonInsert, keyspaceName, tableName,
+ info, http);
+ assertEquals("2500", resultMap.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);
+ Map<String, Object> resultMap = data.deleteFromTable("1", "1", "1",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
+ jsonDelete, keyspaceName, tableName, info, http);
+ assertEquals("Success", resultMap.get("result"));
+ }
+
+ @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());
+ Map<String, Object> resultMap = data.dropTable("1", "1", "1",
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
+ jsonTable, keyspaceName, tableName, http);
+ assertEquals("SUCCESS", resultMap.get("status"));
+ }
+
+ @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());
+ Map<String, Object> resultMap = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
+ appName, userId, password, jsonKeyspace, keyspaceName, http);
+ assertEquals("SUCCESS", resultMap.get("status"));
+ }
+
+ @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 = admin.onboardAppWithMusic(jsonOnboard, http);
+ resultMap.containsKey("success");
+ onboardUUID = resultMap.get("Generated AID").toString();
+ assertEquals("Your application TestApp2 has been onboarded with MUSIC.", resultMap.get("Success"));
+ }
+
+ @Test
+ public void Test7_onboardSearch() throws Exception {
+ JsonOnboard jsonOnboard = new JsonOnboard();
+ jsonOnboard.setAppname("TestApp2");
+ jsonOnboard.setIsAAF("false");
+ jsonOnboard.setAid(onboardUUID);
+ Map<String, Object> resultMap = admin.getOnboardedInfoSearch(jsonOnboard, http);
+ resultMap.containsKey("success");
+ assertEquals(MusicUtil.DEFAULTKEYSPACENAME, 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 = admin.updateOnboardApp(jsonOnboard, http);
+ resultMap.containsKey("success");
+ assertEquals("Your application has been updated successfully", resultMap.get("Success"));
+ }
+
+ @Test
+ public void Test9_onboardDelete() throws Exception {
+ JsonOnboard jsonOnboard = new JsonOnboard();
+ jsonOnboard.setAppname("TestApp2");
+ jsonOnboard.setAid(onboardUUID);
+ Map<String, Object> resultMap = admin.deleteOnboardApp(jsonOnboard, http);
+ resultMap.containsKey("success");
+ assertEquals("Your application has been deleted successfully", resultMap.get("Success"));
+ }
+
+ @Test
+ public void Test3_createLockReference() throws Exception {
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Map<String, Object> resultMap = lock.createLockReference(lockName, uuid.toString(), appName, null, null, http);
+ @SuppressWarnings("unchecked")
+ Map<String, Object> resultMap1 = (Map<String, Object>) resultMap.get("lock");
+ lockId = (String) resultMap1.get("lock");
+ assertEquals("SUCCESS", resultMap.get("status").toString());
+ }
+
+ @Test
+ public void Test4_accquireLock() throws Exception {
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Map<String, Object> resultMap = lock.accquireLock(lockId, uuid.toString(), appName, null, null, http);
+ assertEquals("SUCCESS", resultMap.get("status").toString());
+ }
+
+ @Test
+ public void Test5_currentLockHolder() throws Exception {
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Map<String, Object> resultMap = lock.currentLockHolder(lockName, uuid.toString(), appName, null, null, http);
+ assertEquals("SUCCESS", resultMap.get("status").toString());
+ }
+
+ @Test
+ public void Test7_unLock() throws Exception {
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Map<String, Object> resultMap = lock.unLock(lockId, uuid.toString(), appName, null, null, http);
+ assertEquals("SUCCESS", resultMap.get("status").toString());
+ }
+
+ @Test
+ public void Test8_delete() throws Exception {
+ Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Map<String, Object> resultMap = lock.deleteLock(lockName, uuid.toString(), appName, null, null, http);
+ assertEquals("SUCCESS", resultMap.get("status").toString());
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/AAFResponseTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/AAFResponseTest.java
new file mode 100644
index 00000000..354668c7
--- /dev/null
+++ b/src/test/java/org/onap/music/unittests/jsonobjects/AAFResponseTest.java
@@ -0,0 +1,54 @@
+/*
+ * ============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.jsonobjects;
+
+import static org.junit.Assert.*;
+import java.util.ArrayList;
+import org.junit.Test;
+import org.onap.music.datastore.jsonobjects.AAFResponse;
+import org.onap.music.datastore.jsonobjects.NameSpace;
+
+public class AAFResponseTest {
+
+ @Test
+ public void testGetNs() {
+ NameSpace ns = new NameSpace();
+ AAFResponse ar = new AAFResponse();
+ ArrayList<NameSpace> nsArray = new ArrayList<>();
+ ns.setName("tom");
+ ArrayList<String> admin = new ArrayList<>();
+ admin.add("admin1");
+ ns.setAdmin(admin);
+ nsArray.add(ns);
+ ar.setNs(nsArray);
+ assertEquals("tom",ar.getNs().get(0).getName());
+ assertEquals("admin1",ar.getNs().get(0).getAdmin().get(0));
+
+ }
+
+// @Test
+// public void testSetNs() {
+// fail("Not yet implemented");
+// }
+
+}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java
new file mode 100644
index 00000000..885694bd
--- /dev/null
+++ b/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java
@@ -0,0 +1,86 @@
+/*
+ * ============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.jsonobjects;
+
+import static org.junit.Assert.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+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);
+ assertEquals("one",jd.getConditions().get("key1"));
+ }
+
+ @Test
+ public void testGetConsistencyInfo() {
+ Map<String,String> mapSs = new HashMap<>();
+ mapSs = new HashMap<>();
+ mapSs.put("key3","three");
+ mapSs.put("key4","four");
+ jd.setConsistencyInfo(mapSs);
+ assertEquals("three",jd.getConsistencyInfo().get("key3"));
+ }
+
+ @Test
+ public void testGetColumns() {
+ ArrayList<String> ary = new ArrayList<>();
+ ary = new ArrayList<>();
+ ary.add("e1");
+ ary.add("e2");
+ ary.add("e3");
+ jd.setColumns(ary);
+ assertEquals("e1",jd.getColumns().get(0));
+ }
+
+ @Test
+ public void testGetTtl() {
+ jd.setTtl("2000");
+ assertEquals("2000",jd.getTtl());
+ }
+
+ @Test
+ public void testGetTimestamp() {
+ jd.setTimestamp("20:00");
+ assertEquals("20:00",jd.getTimestamp());
+
+ }
+
+}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java
new file mode 100644
index 00000000..69403cc7
--- /dev/null
+++ b/src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java
@@ -0,0 +1,86 @@
+/*
+ * ============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.jsonobjects;
+
+import static org.junit.Assert.*;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.Test;
+import org.onap.music.datastore.jsonobjects.JsonInsert;
+
+public class JsonInsertTest {
+
+ JsonInsert ji = new JsonInsert();
+
+ @Test
+ public void testGetKeyspaceName() {
+ ji.setKeyspaceName("keyspace");
+ assertEquals("keyspace",ji.getKeyspaceName());
+ }
+
+ @Test
+ public void testGetTableName() {
+ ji.setTableName("table");
+ assertEquals("table",ji.getTableName());
+ }
+
+ @Test
+ public void testGetConsistencyInfo() {
+ Map<String,String> cons = new HashMap<>();
+ cons.put("test","true");
+ ji.setConsistencyInfo(cons);
+ assertEquals("true",ji.getConsistencyInfo().get("test"));
+ }
+
+ @Test
+ public void testGetTtl() {
+ ji.setTtl("ttl");
+ assertEquals("ttl",ji.getTtl());
+ }
+
+ @Test
+ public void testGetTimestamp() {
+ ji.setTimestamp("10:30");
+ assertEquals("10:30",ji.getTimestamp());
+ }
+
+ @Test
+ public void testGetValues() {
+ Map<String,Object> cons = new HashMap<>();
+ cons.put("val1","one");
+ cons.put("val2","two");
+ ji.setValues(cons);
+ assertEquals("one",ji.getValues().get("val1"));
+ }
+
+ @Test
+ public void testGetRow_specification() {
+ Map<String,Object> cons = new HashMap<>();
+ cons.put("val1","one");
+ cons.put("val2","two");
+ ji.setRow_specification(cons);
+ assertEquals("two",ji.getRow_specification().get("val2"));
+ }
+
+
+}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java
new file mode 100644
index 00000000..882d5d5e
--- /dev/null
+++ b/src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java
@@ -0,0 +1,72 @@
+/*
+ * ============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.jsonobjects;
+
+import static org.junit.Assert.*;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.music.datastore.jsonobjects.JsonKeySpace;
+
+public class JsonKeySpaceTest {
+
+ JsonKeySpace jk = null;
+
+
+ @Before
+ public void init() {
+ jk = new JsonKeySpace();
+ }
+
+
+
+ @Test
+ public void testGetConsistencyInfo() {
+ Map<String, String> mapSs = new HashMap<>();
+ mapSs.put("k1", "one");
+ jk.setConsistencyInfo(mapSs);
+ assertEquals("one",jk.getConsistencyInfo().get("k1"));
+ }
+
+ @Test
+ public void testGetReplicationInfo() {
+ Map<String,Object> mapSo = new HashMap<>();
+ mapSo.put("k1", "one");
+ jk.setReplicationInfo(mapSo);
+ assertEquals("one",jk.getReplicationInfo().get("k1"));
+
+ }
+
+ @Test
+ public void testGetDurabilityOfWrites() {
+ jk.setDurabilityOfWrites("1");
+ assertEquals("1",jk.getDurabilityOfWrites());
+ }
+
+ @Test
+ public void testGetKeyspaceName() {
+ jk.setKeyspaceName("Keyspace");
+ assertEquals("Keyspace",jk.getKeyspaceName());
+ }
+
+}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonLeasedLockTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonLeasedLockTest.java
new file mode 100644
index 00000000..63f901c6
--- /dev/null
+++ b/src/test/java/org/onap/music/unittests/jsonobjects/JsonLeasedLockTest.java
@@ -0,0 +1,53 @@
+/*
+ * ============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.jsonobjects;
+
+import static org.junit.Assert.*;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.music.datastore.jsonobjects.JsonLeasedLock;
+
+public class JsonLeasedLockTest {
+
+ JsonLeasedLock jl = null;
+
+ @Before
+ public void init() {
+ jl = new JsonLeasedLock();
+ }
+
+
+ @Test
+ public void testGetLeasePeriod() {
+ long lease = 20000;
+ jl.setLeasePeriod(lease);
+ assertEquals(lease,jl.getLeasePeriod());
+ }
+
+ @Test
+ public void testGetNotifyUrl() {
+ String url = "http://somewhere.com";
+ jl.setNotifyUrl(url);
+ assertEquals(url,jl.getNotifyUrl());
+ }
+
+}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonOnboardTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonOnboardTest.java
new file mode 100644
index 00000000..82f1748a
--- /dev/null
+++ b/src/test/java/org/onap/music/unittests/jsonobjects/JsonOnboardTest.java
@@ -0,0 +1,78 @@
+/*
+ * ============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.jsonobjects;
+
+import static org.junit.Assert.*;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.music.datastore.jsonobjects.JsonOnboard;
+
+public class JsonOnboardTest {
+
+ JsonOnboard jo = null;
+
+ @Before
+ public void init() {
+ jo = new JsonOnboard();
+ }
+
+
+ @Test
+ public void testGetPassword() {
+ String password = "password";
+ jo.setPassword(password);
+ assertEquals(password,jo.getPassword());
+ }
+
+ @Test
+ public void testGetAid() {
+ String aid = "aid";
+ jo.setAid(aid);
+ assertEquals(aid,jo.getAid());
+
+ }
+
+ @Test
+ public void testGetAppname() {
+ String appName = "appName";
+ jo.setAppname(appName);
+ assertEquals(appName,jo.getAppname());
+
+ }
+
+ @Test
+ public void testGetUserId() {
+ String userId = "userId";
+ jo.setUserId(userId);
+ assertEquals(userId,jo.getUserId());
+
+ }
+
+ @Test
+ public void testGetIsAAF() {
+ String aaf = "true";
+ jo.setIsAAF(aaf);
+ assertEquals(aaf,jo.getIsAAF());
+
+ }
+
+}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java
new file mode 100644
index 00000000..0243232f
--- /dev/null
+++ b/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java
@@ -0,0 +1,41 @@
+/*
+ * ============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.jsonobjects;
+
+import static org.junit.Assert.*;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.Test;
+import org.onap.music.datastore.jsonobjects.JsonSelect;
+
+public class JsonSelectTest {
+
+ @Test
+ public void testGetConsistencyInfo() {
+ JsonSelect js = new JsonSelect();
+ Map<String, String> mapSs = new HashMap<>();
+ mapSs.put("k1", "one");
+ js.setConsistencyInfo(mapSs);
+ assertEquals("one",js.getConsistencyInfo().get("k1"));
+ }
+
+}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java
new file mode 100644
index 00000000..e4c800fc
--- /dev/null
+++ b/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java
@@ -0,0 +1,99 @@
+/*
+ * ============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.jsonobjects;
+
+import static org.junit.Assert.*;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.music.datastore.jsonobjects.JsonTable;
+
+public class JsonTableTest {
+
+ JsonTable jt = null;
+
+ @Before
+ public void init() {
+ jt = new JsonTable();
+ }
+
+ @Test
+ public void testGetConsistencyInfo() {
+ Map<String, String> mapSs = new HashMap<>();
+ mapSs.put("k1", "one");
+ jt.setConsistencyInfo(mapSs);
+ assertEquals("one",jt.getConsistencyInfo().get("k1"));
+ }
+
+ @Test
+ public void testGetProperties() {
+ Map<String, Object> properties = new HashMap<>();
+ properties.put("k1", "one");
+ jt.setProperties(properties);
+ }
+
+ @Test
+ public void testGetFields() {
+ Map<String, String> fields = new HashMap<>();
+ fields.put("k1", "one");
+ jt.setFields(fields);
+ assertEquals("one",jt.getFields().get("k1"));
+ }
+
+ @Test
+ public void testGetKeyspaceName() {
+ String keyspace = "keyspace";
+ jt.setKeyspaceName(keyspace);
+ assertEquals(keyspace,jt.getKeyspaceName());
+ }
+
+ @Test
+ public void testGetTableName() {
+ String table = "table";
+ jt.setTableName(table);
+ assertEquals(table,jt.getTableName());
+ }
+
+ @Test
+ public void testGetSortingKey() {
+ String sortKey = "sortkey";
+ jt.setSortingKey(sortKey);
+ assertEquals(sortKey,jt.getSortingKey());
+ }
+
+ @Test
+ public void testGetClusteringOrder() {
+ String clusteringOrder = "clusteringOrder";
+ jt.setClusteringOrder(clusteringOrder);
+ assertEquals(clusteringOrder,jt.getClusteringOrder());
+ }
+
+ @Test
+ public void testGetPrimaryKey() {
+ String primaryKey = "primaryKey";
+ jt.setPrimaryKey(primaryKey);
+ assertEquals(primaryKey,jt.getPrimaryKey());
+ }
+
+}
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java
new file mode 100644
index 00000000..54db0540
--- /dev/null
+++ b/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * ============LICENSE_START==========================================
+ * org.onap.music
+ * ===================================================================
+ * Copyright (c) 2018 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.jsonobjects;
+
+import static org.junit.Assert.*;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.music.datastore.jsonobjects.JsonUpdate;
+
+public class JsonUpdateTest {
+
+ JsonUpdate ju = null;
+
+ @Before
+ public void init() {
+ ju = new JsonUpdate();
+ }
+
+
+ @Test
+ public void testGetConditions() {
+ Map<String,Object> mapSo = new HashMap<>();
+ mapSo.put("key1","one");
+ mapSo.put("key2","two");
+ ju.setConditions(mapSo);
+ assertEquals("one",ju.getConditions().get("key1"));
+ }
+
+ @Test
+ public void testGetRow_specification() {
+ Map<String,Object> mapSo = new HashMap<>();
+ mapSo.put("key1","one");
+ mapSo.put("key2","two");
+ ju.setRow_specification(mapSo);
+ assertEquals("one",ju.getRow_specification().get("key1"));
+ }
+
+ @Test
+ public void testGetKeyspaceName() {
+ String keyspace = "keyspace";
+ ju.setKeyspaceName(keyspace);
+ assertEquals(keyspace,ju.getKeyspaceName());
+ }
+
+ @Test
+ public void testGetTableName() {
+ String table = "table";
+ ju.setTableName(table);
+ assertEquals(table,ju.getTableName());
+ }
+
+ @Test
+ public void testGetConsistencyInfo() {
+ Map<String, String> mapSs = new HashMap<>();
+ mapSs.put("k1", "one");
+ ju.setConsistencyInfo(mapSs);
+ assertEquals("one",ju.getConsistencyInfo().get("k1"));
+ }
+
+ @Test
+ public void testGetTtl() {
+ ju.setTtl("2000");
+ assertEquals("2000",ju.getTtl());
+ }
+
+ @Test
+ public void testGetTimestamp() {
+ ju.setTimestamp("20:00");
+ assertEquals("20:00",ju.getTimestamp());
+
+ }
+
+ @Test
+ public void testGetValues() {
+ Map<String,Object> cons = new HashMap<>();
+ cons.put("val1","one");
+ cons.put("val2","two");
+ ju.setValues(cons);
+ assertEquals("one",ju.getValues().get("val1"));
+ }
+
+}