aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorNelson, Thomas (arthurdent3) <nelson24@att.com>2019-05-14 20:23:59 +0000
committerTschaen, Brendan <ctschaen@att.com>2019-05-16 12:59:46 -0400
commit66aac8e2b8f61f075b285f969c1f8a88fdb313bd (patch)
tree8ee4e4c06b6a95c6b596c503fa9a6b19936917f0 /src/test
parentd6e7b63cc580e7b3822be61fe92a493ad5e222a3 (diff)
CADI and a few small updates.
- Include CADI and remove Admin API and admin code. - A few Sonar Fixes. - Properties File Clean up. - Read/Write Locking API. - Various whitespace fixes. Issue-ID: MUSIC-394 Change-Id: I58e1b64b71796bb6bda1c97ea688f434a836d3c7 Signed-off-by: Nelson, Thomas (arthurdent3) <nelson24@att.com>
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/onap/music/unittests/JsonResponseTest.java17
-rw-r--r--src/test/java/org/onap/music/unittests/MusicDataStoreTest.java3
-rw-r--r--src/test/java/org/onap/music/unittests/MusicUtilTest.java42
-rw-r--r--src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java85
-rw-r--r--src/test/java/org/onap/music/unittests/TestsUsingCassandra.java111
-rw-r--r--src/test/java/org/onap/music/unittests/TstCachingUtil.java167
-rw-r--r--src/test/java/org/onap/music/unittests/TstRestMusicAdminAPI.java464
-rw-r--r--src/test/java/org/onap/music/unittests/TstRestMusicConditionalAPI.java3
-rw-r--r--src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java240
-rw-r--r--src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java612
10 files changed, 376 insertions, 1368 deletions
diff --git a/src/test/java/org/onap/music/unittests/JsonResponseTest.java b/src/test/java/org/onap/music/unittests/JsonResponseTest.java
index 88fddf4e..20ac1562 100644
--- a/src/test/java/org/onap/music/unittests/JsonResponseTest.java
+++ b/src/test/java/org/onap/music/unittests/JsonResponseTest.java
@@ -26,7 +26,9 @@ package org.onap.music.unittests;
import static org.junit.Assert.*;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.onap.music.lockingservice.cassandra.MusicLockState.LockStatus;
@@ -125,4 +127,19 @@ public class JsonResponseTest {
assertTrue(result.toString() instanceof String);
}
+
+ @Test
+ public void testLockHolders() {
+ result = new JsonResponse(ResultType.SUCCESS).setLock("lockName").setLockHolder("lockholder1");
+ Map<String, Object> lockMap = (Map<String, Object>) result.toMap().get("lock");
+ // assure that this is string for backwards compatibility
+ assertEquals("lockholder1", lockMap.get("lock-holder"));
+
+ List<String> lockholders = new ArrayList<>();
+ lockholders.add("lockholder1");
+ lockholders.add("lockholder2");
+ result.setLockHolder(lockholders);
+ lockMap = (Map<String, Object>) result.toMap().get("lock");
+ assertEquals(lockMap.get("lock-holder"), lockholders);
+ }
}
diff --git a/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java b/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java
index 6b7dc781..68e6f3dc 100644
--- a/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java
+++ b/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java
@@ -37,7 +37,6 @@ import org.onap.music.exceptions.MusicServiceException;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import org.onap.music.authentication.CachingUtil;
import org.onap.music.datastore.MusicDataStore;
import org.onap.music.datastore.PreparedQueryObject;
@@ -84,7 +83,7 @@ public class MusicDataStoreTest {
assertEquals(true, result);
}
-
+
@Test
public void Test2_ExecutePut_eventual_insert() throws MusicServiceException, MusicQueryException {
testObject = CassandraCQL.setPreparedInsertQueryObject1();
diff --git a/src/test/java/org/onap/music/unittests/MusicUtilTest.java b/src/test/java/org/onap/music/unittests/MusicUtilTest.java
index 04149fc6..21b943f0 100644
--- a/src/test/java/org/onap/music/unittests/MusicUtilTest.java
+++ b/src/test/java/org/onap/music/unittests/MusicUtilTest.java
@@ -30,14 +30,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
-import org.apache.cassandra.exceptions.PreparedQueryNotFoundException;
import org.junit.Test;
-import org.onap.music.authentication.CachingUtil;
import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.exceptions.MusicServiceException;
import org.onap.music.main.MusicUtil;
import com.datastax.driver.core.DataType;
-import javassist.CodeConverter.ArrayAccessReplacementMethodNames;
public class MusicUtilTest {
@@ -60,49 +56,11 @@ public class MusicUtilTest {
}
@Test
- public void testGetMyId() {
- MusicUtil.setMyId(1);
- assertEquals(MusicUtil.getMyId(),1);
- }
-
- @Test
- public void testGetAllIds() {
- List<String> ids = new ArrayList<String>();
- ids.add("1");
- ids.add("2");
- ids.add("3");
- MusicUtil.setAllIds(ids);
- 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 testGetAllPublicIps() {
- List<String> ips = new ArrayList<String>();
- ips.add("10.0.0.1");
- ips.add("10.0.0.2");
- ips.add("10.0.0.3");
- MusicUtil.setAllPublicIps(ips);
- assertEquals(MusicUtil.getAllPublicIps().get(1),"10.0.0.2");
- }
-
- @Test
public void testGetPropkeys() {
assertEquals(MusicUtil.getPropkeys()[2],"debug");
}
@Test
- public void testGetMusicRestIp() {
- MusicUtil.setMusicRestIp("localhost");
- assertEquals(MusicUtil.getMusicRestIp(),"localhost");
- }
-
- @Test
public void testGetMusicPropertiesFilePath() {
MusicUtil.setMusicPropertiesFilePath("filepath");
assertEquals(MusicUtil.getMusicPropertiesFilePath(),"filepath");
diff --git a/src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java b/src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java
index 163f8dda..a9e6e4b6 100644
--- a/src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java
+++ b/src/test/java/org/onap/music/unittests/TestRestMusicQAPI.java
@@ -52,6 +52,7 @@ import org.mindrot.jbcrypt.BCrypt;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.music.datastore.MusicDataStore;
import org.onap.music.datastore.MusicDataStoreHandle;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.datastore.jsonobjects.JsonDelete;
@@ -66,9 +67,10 @@ import org.onap.music.lockingservice.cassandra.CassaLockStore;
import org.onap.music.main.MusicCore;
import org.onap.music.main.MusicUtil;
//import org.onap.music.main.ResultType;
-import org.onap.music.rest.RestMusicAdminAPI;
+//import org.onap.music.rest.RestMusicAdminAPI;
import org.onap.music.rest.RestMusicDataAPI;
import org.onap.music.rest.RestMusicQAPI;
+import org.springframework.test.util.ReflectionTestUtils;
import org.onap.music.rest.RestMusicLocksAPI;
import com.datastax.driver.core.DataType;
import com.datastax.driver.core.ResultSet;
@@ -84,7 +86,7 @@ import com.sun.jersey.core.util.MultivaluedMapImpl;
public class TestRestMusicQAPI {
- RestMusicAdminAPI admin = new RestMusicAdminAPI();
+ //RestMusicAdminAPI admin = new RestMusicAdminAPI();
RestMusicLocksAPI lock = new RestMusicLocksAPI();
RestMusicQAPI qData = new RestMusicQAPI();
static PreparedQueryObject testObject;
@@ -128,8 +130,9 @@ public class TestRestMusicQAPI {
@BeforeClass
public static void init() throws Exception {
try {
- MusicDataStoreHandle.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra();
- MusicCore.mLockHandle = new CassaLockStore(MusicDataStoreHandle.mDstoreHandle);
+ ReflectionTestUtils.setField(MusicDataStoreHandle.class, "mDstoreHandle",
+ CassandraCQL.connectToEmbeddedCassandra());
+ MusicCore.mLockHandle = new CassaLockStore(MusicDataStoreHandle.getDSHandle());
// System.out.println("before class keysp");
//resp=data.createKeySpace(majorV,minorV,patchV,aid,appName,userId,password,kspObject,keyspaceName);
@@ -216,8 +219,9 @@ public class TestRestMusicQAPI {
testObject = new PreparedQueryObject();
testObject.appendQueryString("DROP KEYSPACE IF EXISTS admin");
MusicCore.eventualPut(testObject);
- if (MusicDataStoreHandle.mDstoreHandle!=null) {}
- //MusicDataStoreHandle.mDstoreHandle.close();
+ MusicDataStore mds = (MusicDataStore) ReflectionTestUtils.getField(MusicDataStoreHandle.class, "mDstoreHandle");
+ if (mds != null)
+ mds.close();
}
@@ -472,7 +476,7 @@ public class TestRestMusicQAPI {
// "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password,
System.out.println("#######status is " + response.getStatus()+"table namec="+tableNameC);
System.out.println("Entity" + response.getEntity());
- assertEquals(401, response.getStatus());
+ assertEquals(400, response.getStatus());
}
@@ -514,34 +518,9 @@ public class TestRestMusicQAPI {
//assertNotEquals(200,response0.getStatus());
}
- // Improper Auth
- @Test
- public void Test3_createQ1() 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.setPartitionKey("emp_name");
- jsonTable.setClusteringKey("uuid");
- jsonTable.setTableName(tableName);
- jsonTable.setClusteringOrder("uuid DESC");
- jsonTable.setFields(fields);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.createQ(majorV, minorV,patchV,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization,
- jsonTable, keyspaceName, tableName);
- System.out.println("#######status is " + response.getStatus());
- System.out.println("Entity" + response.getEntity());
- assertEquals(401, response.getStatus());
- }
// Improper keyspace
+ @Ignore
@Test
public void Test3_createQ2() throws Exception {
JsonTable jsonTable = new JsonTable();
@@ -631,47 +610,7 @@ public class TestRestMusicQAPI {
assertEquals(200, response.getStatus());
}*/
- // Auth Error
- @Test
- public void Test4_insertIntoQ3() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test1");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.insertIntoQ(majorV, minorV,patchV,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, wrongAuthorization,
- jsonInsert, keyspaceName, tableName);
- assertEquals(401, response.getStatus());
- }
- // Table wrong
- @Test
- public void Test4_insertIntoQ4() throws Exception {
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test1");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = qData.insertIntoQ(majorV, minorV,patchV,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, authorization,
- jsonInsert, keyspaceName, "wrong");
- assertEquals(401, response.getStatus());
- }
/* @Test
public void Test5_updateQ() throws Exception {
diff --git a/src/test/java/org/onap/music/unittests/TestsUsingCassandra.java b/src/test/java/org/onap/music/unittests/TestsUsingCassandra.java
index ef2867d8..e2c65447 100644
--- a/src/test/java/org/onap/music/unittests/TestsUsingCassandra.java
+++ b/src/test/java/org/onap/music/unittests/TestsUsingCassandra.java
@@ -30,74 +30,77 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import org.mindrot.jbcrypt.BCrypt;
+import org.onap.music.datastore.MusicDataStore;
import org.onap.music.datastore.MusicDataStoreHandle;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.lockingservice.cassandra.CassaLockStore;
import org.onap.music.main.MusicCore;
import org.onap.music.main.MusicUtil;
-
+import org.springframework.test.util.ReflectionTestUtils;
import com.datastax.driver.core.DataType;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import com.sun.jersey.core.util.Base64;
@RunWith(Suite.class)
-@SuiteClasses({ TstRestMusicDataAPI.class, TstRestMusicLockAPI.class, TstRestMusicAdminAPI.class,
- TstRestMusicConditionalAPI.class, TstCachingUtil.class})
+@SuiteClasses({ TstRestMusicDataAPI.class, TstRestMusicLockAPI.class,
+ TstRestMusicConditionalAPI.class})
public class TestsUsingCassandra {
- static String appName = "TestApp";
- static String userId = "TestUser";
- static String password = "TestPassword";
- static String authData = userId+":"+password;
- static String wrongAuthData = userId+":"+"pass";
- static String authorization = new String(Base64.encode(authData.getBytes()));
- static String wrongAuthorization = new String(Base64.encode(wrongAuthData.getBytes()));
- static boolean isAAF = false;
- static UUID uuid = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40ce6");
- static String keyspaceName = "testcassa";
- static String tableName = "employees";
- static String xLatestVersion = "X-latestVersion";
- static String onboardUUID = null;
- static String aid = "abc66ccc-d857-4e90-b1e5-df98a3d40ce6";
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- MusicDataStoreHandle.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra();
- MusicCore.mLockHandle = new CassaLockStore(MusicDataStoreHandle.mDstoreHandle);
- createAdminTable();
- }
-
- @AfterClass
- public static void afterClass() {
- PreparedQueryObject testObject = new PreparedQueryObject();
- testObject.appendQueryString("DROP KEYSPACE IF EXISTS admin");
- MusicCore.eventualPut(testObject);
- if(MusicDataStoreHandle.mDstoreHandle!=null)
- MusicDataStoreHandle.mDstoreHandle.close();
- }
-
- private static void createAdminTable() throws Exception {
- PreparedQueryObject testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.createAdminKeyspace);
- MusicCore.eventualPut(testObject);
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.createAdminTable);
- MusicCore.eventualPut(testObject);
+ static String appName = "TestApp";
+ static String userId = "TestUser";
+ static String password = "TestPassword";
+ static String authData = userId+":"+password;
+ static String wrongAuthData = userId+":"+"pass";
+ static String authorization = new String(Base64.encode(authData.getBytes()));
+ static String wrongAuthorization = new String(Base64.encode(wrongAuthData.getBytes()));
+ static boolean isAAF = false;
+ static UUID uuid = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40ce6");
+ static String keyspaceName = "testcassa";
+ static String tableName = "employees";
+ static String xLatestVersion = "X-latestVersion";
+ static String onboardUUID = null;
+ static String aid = "abc66ccc-d857-4e90-b1e5-df98a3d40ce6";
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ ReflectionTestUtils.setField(MusicDataStoreHandle.class, "mDstoreHandle",
+ CassandraCQL.connectToEmbeddedCassandra());
+ MusicCore.mLockHandle = new CassaLockStore(MusicDataStoreHandle.getDSHandle());
+ createAdminTable();
+ }
+
+ @AfterClass
+ public static void afterClass() {
+ PreparedQueryObject testObject = new PreparedQueryObject();
+ testObject.appendQueryString("DROP KEYSPACE IF EXISTS admin");
+ MusicCore.eventualPut(testObject);
+ MusicDataStore mds = (MusicDataStore) ReflectionTestUtils.getField(MusicDataStoreHandle.class, "mDstoreHandle");
+ if (mds != null)
+ mds.close();
+ }
+
+ private static void createAdminTable() throws Exception {
+ PreparedQueryObject testObject = new PreparedQueryObject();
+ testObject.appendQueryString(CassandraCQL.createAdminKeyspace);
+ MusicCore.eventualPut(testObject);
+ testObject = new PreparedQueryObject();
+ testObject.appendQueryString(CassandraCQL.createAdminTable);
+ MusicCore.eventualPut(testObject);
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(
- "INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
- + "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)");
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(),
- keyspaceName));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt())));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
- testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
- MusicCore.eventualPut(testObject);
+ testObject = new PreparedQueryObject();
+ testObject.appendQueryString(
+ "INSERT INTO admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
+ + "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)");
+ testObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
+ testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(),
+ keyspaceName));
+ testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
+ testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
+ testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), BCrypt.hashpw(password, BCrypt.gensalt())));
+ testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
+ testObject.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
+ MusicCore.eventualPut(testObject);
testObject = new PreparedQueryObject();
testObject.appendQueryString(
diff --git a/src/test/java/org/onap/music/unittests/TstCachingUtil.java b/src/test/java/org/onap/music/unittests/TstCachingUtil.java
deleted file mode 100644
index ea47b7c1..00000000
--- a/src/test/java/org/onap/music/unittests/TstCachingUtil.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * ============LICENSE_START========================================== org.onap.music
- * =================================================================== Copyright (c) 2017 AT&T
- * Intellectual Property ===================================================================
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- *
- * ============LICENSE_END=============================================
- * ====================================================================
- */
-
-package org.onap.music.unittests;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import javax.ws.rs.core.Response;
-
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mindrot.jbcrypt.BCrypt;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.music.authentication.CachingUtil;
-import org.onap.music.datastore.MusicDataStoreHandle;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.datastore.jsonobjects.JsonInsert;
-import org.onap.music.datastore.jsonobjects.JsonLeasedLock;
-import org.onap.music.datastore.jsonobjects.JsonTable;
-import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.lockingservice.cassandra.CassaLockStore;
-import org.onap.music.main.MusicCore;
-import org.onap.music.main.MusicUtil;
-import org.onap.music.rest.RestMusicDataAPI;
-import org.onap.music.rest.RestMusicLocksAPI;
-import com.datastax.driver.core.DataType;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
-import com.sun.jersey.core.util.Base64;
-
-@RunWith(MockitoJUnitRunner.class)
-public class TstCachingUtil {
-
- RestMusicLocksAPI lock = new RestMusicLocksAPI();
- RestMusicDataAPI data = new RestMusicDataAPI();
- static PreparedQueryObject testObject;
-
- static String appName = TestsUsingCassandra.appName;
- static String userId = TestsUsingCassandra.userId;
- static String password = TestsUsingCassandra.password;
- static String authData = TestsUsingCassandra.authData;
- static String authorization = TestsUsingCassandra.authorization;
- static boolean isAAF = TestsUsingCassandra.isAAF;
- static UUID uuid = TestsUsingCassandra.uuid;
- static String keyspaceName = TestsUsingCassandra.keyspaceName;
- static String tableName = TestsUsingCassandra.tableName;
- static String onboardUUID = null;
-
- @BeforeClass
- public static void init() throws Exception {
- System.out.println("Testing CachingUtil class");
- try {
-
- } catch (Exception e) {
- e.printStackTrace();
- throw new Exception("Unable to initialize before TestRestMusicData test class. " + e.getMessage());
- }
- }
-
- @After
- public void afterEachTest( ) throws MusicServiceException {
-
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- testObject = new PreparedQueryObject();
- testObject.appendQueryString("DROP KEYSPACE IF EXISTS " + keyspaceName);
- MusicCore.eventualPut(testObject);
- }
-
- @Test
- public void test_verifyOnboard() throws Exception {
- System.out.println("Testing onboarding of app");
- CachingUtil cache = new CachingUtil();
- cache.initializeAafCache();
- Map<String, Object> authMap = CachingUtil.verifyOnboarding(appName, userId, password);
- assertEquals(0, authMap.size());
- }
-
- @Test
- public void test_authenticateAIDUser() throws Exception {
- System.out.println("Testing authentication of AID user");
- createKeyspace();
- CachingUtil cache = new CachingUtil();
- cache.initializeAafCache();
- Map<String, Object> authMap = CachingUtil.authenticateAIDUser(appName,
- userId, password, keyspaceName);
- System.out.println("authMap is: " + authMap);
- assertEquals(0, authMap.size());
- }
-
- @Test
- public void test_getAppName() throws MusicServiceException {
- System.out.println("Testing getAppName");
- CachingUtil cache = new CachingUtil();
- cache.initializeAafCache();
- assertEquals(appName, CachingUtil.getAppName(keyspaceName));
- }
-
- @Test
- public void test_getUUIDFromCache() throws MusicServiceException {
- System.out.println("Testing getUUID");
- CachingUtil cache = new CachingUtil();
- cache.initializeAafCache();
- assertEquals(uuid.toString(), CachingUtil.getUuidFromMusicCache(keyspaceName));
- }
-
- @Test
- public void test_isAAFApplcation() throws MusicServiceException {
- System.out.println("Testing to see if cache gets correct isAAF info");
- CachingUtil cache = new CachingUtil();
- cache.initializeAafCache();
- assertEquals(isAAF, Boolean.valueOf(CachingUtil.isAAFApplication(appName)));
- }
-
- private static void createKeyspace() throws Exception {
- //shouldn't really be doing this here, but create keyspace is currently turned off
- PreparedQueryObject query = new PreparedQueryObject();
- query.appendQueryString(CassandraCQL.createKeySpace);
- MusicCore.eventualPut(query);
-
- boolean isAAF = false;
- String hashedpwd = BCrypt.hashpw(password, BCrypt.gensalt());
- query = new PreparedQueryObject();
- query.appendQueryString(
- "INSERT into admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
- + "password, username, is_aaf) values (?,?,?,?,?,?,?)");
- query.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
- query.addValue(MusicUtil.convertToActualDataType(DataType.text(), keyspaceName));
- query.addValue(MusicUtil.convertToActualDataType(DataType.text(), appName));
- query.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), "True"));
- query.addValue(MusicUtil.convertToActualDataType(DataType.text(), hashedpwd));
- query.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
- query.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
- CachingUtil.updateMusicCache(keyspaceName, appName);
- CachingUtil.updateMusicValidateCache(appName, userId, hashedpwd);
- MusicCore.eventualPut(query);
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/TstRestMusicAdminAPI.java b/src/test/java/org/onap/music/unittests/TstRestMusicAdminAPI.java
deleted file mode 100644
index e6bc3107..00000000
--- a/src/test/java/org/onap/music/unittests/TstRestMusicAdminAPI.java
+++ /dev/null
@@ -1,464 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * org.onap.music
- * ===================================================================
- * Copyright (c) 2019 AT&T Intellectual Property
- * ===================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * ============LICENSE_END=============================================
- * ====================================================================
- */
-
-package org.onap.music.unittests;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Map;
-import java.util.UUID;
-
-import javax.ws.rs.core.Response;
-
-
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.internal.util.reflection.FieldSetter;
-import org.onap.music.authentication.MusicAAFAuthentication;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.datastore.jsonobjects.JsonOnboard;
-import org.onap.music.datastore.jsonobjects.MusicResponse;
-import org.onap.music.main.MusicCore;
-import org.onap.music.rest.RestMusicAdminAPI;
-import com.sun.jersey.core.util.Base64;
-
-public class TstRestMusicAdminAPI {
-
- RestMusicAdminAPI admin = new RestMusicAdminAPI();
- static PreparedQueryObject testObject;
-
- @Mock
- MusicAAFAuthentication authMock;
-
- static String appName = "TestApp";
- static String userId = "TestUser";
- static String password = "TestPassword";
- static String adminName = "username";
- static String adminPassword = "password";
- static String adminAuthData = adminName +":"+adminPassword;
- static String wrongAdminAuthData = adminName+"123"+":"+adminPassword;
- static String authData = userId+":"+password;
- static String wrongAuthData = userId+":"+"pass";
- static String authorization = new String(Base64.encode(authData.getBytes()));
- static String wrongAuthorization = new String(Base64.encode(wrongAuthData.getBytes()));
- static String adminAuthorization = new String(Base64.encode(adminAuthData.getBytes()));
- static String wrongAdminAuthorization = new String(Base64.encode(wrongAdminAuthData.getBytes()));
-
- static boolean isAAF = false;
- static UUID uuid = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40ce6");
- static String keyspaceName = "testCassa";
- static String tableName = "employees";
- static String tableNameConditional = "Conductor";
- static String xLatestVersion = "X-latestVersion";
- static String onboardUUID = TestsUsingCassandra.onboardUUID;
- static String lockId = null;
- static String lockName = "testCassa.employees.sample3";
-
- @BeforeClass
- public static void init() throws Exception {
- System.out.println("Testing RestMusicAdmin class");
- //PowerMockito.mockStatic(MusicAuthentication.class);
- try {
- //MusicDataStoreHandle.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra();
- } catch (Exception e) {
- e.printStackTrace();
- throw new Exception("Unable to initialize before TestRestMusicData test class. " + e.getMessage());
- }
- }
-
- @Before
- public void beforeEach() throws NoSuchFieldException {
- authenticateAdminTrue();
- }
-
- @After
- public void afterEach() {
- testObject = new PreparedQueryObject();
- testObject.appendQueryString("DELETE * FROM admin.keyspace_master;");
- MusicCore.eventualPut(testObject);
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- testObject = new PreparedQueryObject();
- testObject.appendQueryString("DROP KEYSPACE IF EXISTS " + keyspaceName);
- MusicCore.eventualPut(testObject);
- }
-
- @Ignore
- @Test
- public void test6_onboard() throws Exception {
- System.out.println("Testing application onboarding");
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setIsAAF("false"); jsonOnboard.setUserId("TestUser2");
- jsonOnboard.setKeyspace_name(keyspaceName);
- jsonOnboard.setPassword("TestPassword2");
-
- Response response = admin.onboardAppWithMusic(jsonOnboard,adminAuthorization);
-
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void test6_onboard_wrongCredentials() throws Exception {
- System.out.println("Testing application onboarding wrong credentials");
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setIsAAF("false"); jsonOnboard.setUserId("TestUser2");
- jsonOnboard.setKeyspace_name(keyspaceName);
- jsonOnboard.setPassword("TestPassword2");
-
- Response response = admin.onboardAppWithMusic(jsonOnboard,wrongAdminAuthorization);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
- @Ignore
- @Test
- public void test6_onboard_duplicate() throws Exception {
- System.out.println("Testing a duplicate onboarding call");
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setKeyspace_name(keyspaceName);
- jsonOnboard.setUserId("TestUser2");
- jsonOnboard.setPassword("TestPassword2");
- Response response = admin.onboardAppWithMusic(jsonOnboard,adminAuthorization);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- // Missing appname
- @Test
- public void test6_onboard_noAppName() throws Exception {
- System.out.println("Testing onboard missing app name");
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setKeyspace_name(keyspaceName);
- jsonOnboard.setUserId("TestUser2");
- jsonOnboard.setPassword("TestPassword2");
- Response response = admin.onboardAppWithMusic(jsonOnboard,adminAuthorization);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(400, response.getStatus());
- }
-
-
- @Test
- public void test7_onboardSearch_notOnboarded() throws Exception {
- System.out.println("Testing application onboarding search for app that isn't onboarded");
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setAid(onboardUUID);
- Response response = admin.getOnboardedInfoSearch(jsonOnboard,adminAuthorization);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- //Application is not onboarded
- assertEquals(400, response.getStatus());
- }
-
- @Ignore
- @Test
- public void test7_onboardSearch() throws Exception {
- System.out.println("Testing application onboarding search no matching app");
- onboardApp();
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setAid(onboardUUID);
-
- Response response = admin.getOnboardedInfoSearch(jsonOnboard,adminAuthorization);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void test7_onboardSearch_wrongCredentials() throws Exception {
- System.out.println("Testing application onboarding search w/ wrong credentials");
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setAid(onboardUUID);
- Response response = admin.getOnboardedInfoSearch(jsonOnboard,wrongAdminAuthorization);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(401, response.getStatus());
- }
-
- // Missing appname
- @Test
- public void test7_onboardSearch_noAppName() throws Exception {
- System.out.println("Testing application onboarding search w/o appname");
- onboardApp();
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setAid(onboardUUID);
- Response response = admin.getOnboardedInfoSearch(jsonOnboard,adminAuthorization);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(200, response.getStatus());
- }
-
- @Ignore
- @Test
- public void test7_onboardSearch_empty() throws Exception {
- System.out.println("Testing onboard search no app information");
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- Response response = admin.getOnboardedInfoSearch(jsonOnboard,adminAuthorization);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(400, response.getStatus());
- }
-
- @Ignore
- @Test
- public void test8_onboardUpdate() throws Exception {
- System.out.println("Testing application onboarding update");
- onboardApp();
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser3");
- jsonOnboard.setPassword("TestPassword3");
- jsonOnboard.setAid(onboardUUID);
- Response response = admin.updateOnboardApp(jsonOnboard,adminAuthorization);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(200, response.getStatus());
- }
-
- @Ignore //not working correctly
- @Test
- public void test8_onboardUpdate_withAppName() throws Exception {
- System.out.println("Testing application onboarding update w appname");
- onboardApp();
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser3");
- jsonOnboard.setPassword("TestPassword3");
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setAid(onboardUUID);
- Response response = admin.updateOnboardApp(jsonOnboard,adminAuthorization);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void test8_onboardUpdate_noUUID() throws Exception {
- System.out.println("Testing application onboarding update null uuid");
- onboardApp();
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser3");
- jsonOnboard.setPassword("TestPassword3");
- jsonOnboard.setAid(null);
- Response response = admin.updateOnboardApp(jsonOnboard,adminAuthorization);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void test8_onboardUpdate_wrongCredentialsNoAAF() throws Exception {
- System.out.println("Testing update application onboarding search w/ wrong credentials");
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser3");
- jsonOnboard.setPassword("TestPassword3");
- jsonOnboard.setAid(onboardUUID);
- Response response = admin.updateOnboardApp(jsonOnboard,wrongAdminAuthorization);
-
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
- // All null
- @Test
- public void test8_onboardUpdate_noAppInfo() throws Exception {
- System.out.println("Testing update application onboarding update no app information");
- onboardApp();
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAid(onboardUUID);
- Response response = admin.updateOnboardApp(jsonOnboard,adminAuthorization);
-
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- @Test
- @Ignore
- public void test9_onboardDelete() throws Exception {
- System.out.println("Testing update application onboarding delete");
- onboardApp();
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setAid(onboardUUID);
- Response response = admin.deleteOnboardApp(jsonOnboard,adminAuthorization);
-
- //only 1 app matches keyspace
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- @Ignore //not working as expected
- @Test
- public void test9_onboardDelete_noAID() throws Exception {
- System.out.println("Testing update application onboarding delete no AID");
- onboardApp();
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setAid(null);
- Response response = admin.deleteOnboardApp(jsonOnboard,adminAuthorization);
-
- //only 1 app matches name
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- @Ignore
- @Test
- public void test9_onboardDelete_noAIDManyMatch() throws Exception {
- System.out.println("Testing update application onboarding delete no AID many apps in namespace");
- onboardApp();
- onboardApp();
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setAid(null);
- Response response = admin.deleteOnboardApp(jsonOnboard,adminAuthorization);
-
- //multiple apps matches name
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- @Ignore
- @Test
- public void test9_onboardDelete_noAID_noApp() throws Exception {
- System.out.println("Testing update application onboarding delete no AID, app not onboarded");
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setAid(null);
- Response response = admin.deleteOnboardApp(jsonOnboard,adminAuthorization);
-
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void test9_onboardDelete_noAppToDelete() throws Exception {
- System.out.println("Testing update application onboarding delete no app information");
- onboardApp();
-
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname(null);
- jsonOnboard.setAid(null);
- Response response = admin.deleteOnboardApp(jsonOnboard,adminAuthorization);
-
- //only 1 app matches keyspace
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- @Test
- public void test9_onboardDelete_wrongCredentials() throws Exception {
- System.out.println("Testing onboard delete with wrong credentials");
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setAid(onboardUUID);
- Response response = admin.deleteOnboardApp(jsonOnboard,wrongAdminAuthorization);
-
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
- @Ignore
- @Test
- public void test10_delete() throws Exception {
- System.out.println("Testing GUI delete call");
- onboardApp();
- MusicResponse response = admin.delete(adminAuthorization, onboardUUID);
- assertEquals(200, response.getStatus());
- //assertTrue(admin.delete(adminAuthorization, onboardUUID));
- }
-
- @Test
- public void test11_getAll() {
- System.out.println("Testing GUI getall call");
-
- System.out.println("admin.getall(adminAuthorization)");
- }
-
- /**
- * Inject our mocked class and accept admin credentials
- * @throws NoSuchFieldException
- */
- public void authenticateAdminTrue() throws NoSuchFieldException {
- authMock = Mockito.mock(MusicAAFAuthentication.class);
- FieldSetter.setField(admin, admin.getClass().getDeclaredField("authenticator"), authMock);
-
- Mockito.when(authMock.authenticateAdmin(Mockito.matches(adminAuthorization))).thenReturn(true);
- }
-
- /**
- * onboard the application and store generate uuid into {@link onboardUUID}
- * @param onboard
- * @throws Exception
- */
- public void onboardApp() throws Exception {
- JsonOnboard jsonOnboard = new JsonOnboard();
- jsonOnboard.setAppname("TestApp2");
- jsonOnboard.setIsAAF("false");
- jsonOnboard.setUserId("TestUser2");
- jsonOnboard.setPassword("TestPassword2");
-
- Response response = admin.onboardAppWithMusic(jsonOnboard,adminAuthorization);
- Map<String, String> respMap = (Map<String, String>) response.getEntity();
- onboardUUID = respMap.get("Generated AID");
- }
-
-} \ No newline at end of file
diff --git a/src/test/java/org/onap/music/unittests/TstRestMusicConditionalAPI.java b/src/test/java/org/onap/music/unittests/TstRestMusicConditionalAPI.java
index 3adab912..7021178e 100644
--- a/src/test/java/org/onap/music/unittests/TstRestMusicConditionalAPI.java
+++ b/src/test/java/org/onap/music/unittests/TstRestMusicConditionalAPI.java
@@ -39,7 +39,6 @@ import org.mindrot.jbcrypt.BCrypt;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.music.authentication.CachingUtil;
import org.onap.music.conductor.conditionals.JsonConditional;
import org.onap.music.conductor.conditionals.RestMusicConditionalAPI;
import org.onap.music.datastore.MusicDataStoreHandle;
@@ -293,8 +292,6 @@ public class TstRestMusicConditionalAPI {
query.addValue(MusicUtil.convertToActualDataType(DataType.text(), hashedpwd));
query.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
query.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
- CachingUtil.updateMusicCache(keyspaceName, appName);
- CachingUtil.updateMusicValidateCache(appName, userId, hashedpwd);
MusicCore.eventualPut(query);
}
diff --git a/src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java b/src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java
index 18692915..67a68f6e 100644
--- a/src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java
+++ b/src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java
@@ -44,7 +44,6 @@ import org.mindrot.jbcrypt.BCrypt;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.music.authentication.CachingUtil;
import org.onap.music.datastore.MusicDataStoreHandle;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.datastore.jsonobjects.JsonDelete;
@@ -264,51 +263,6 @@ public class TstRestMusicDataAPI {
assertEquals("Table " + keyspaceName + "." + tableNameDup + " already exists", respMap.get("error"));
}
- // Improper Auth
- @Test
- public void test3_createTable1() throws Exception {
- System.out.println("Testing create table w/ improper authentication");
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- wrongAuthorization, jsonTable, keyspaceName, tableName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
- // Improper keyspace
- @Test
- public void test3_createTable3() throws Exception {
- System.out.println("Testing create table for wrong keyspace");
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonTable, "wrong", tableName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(401, response.getStatus());
- }
// Improper parenthesis in key field
@Test
@@ -479,38 +433,6 @@ public class TstRestMusicDataAPI {
assertEquals(200, response.getStatus());
}
-
- // good clustering key, need to pass queryparameter
- @Test
- public void test3_createTableIndex_badAuth() throws Exception {
- System.out.println("Testing index in create table w/ wrong authorization");
- String tableNameC = "testTableCinx";
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "((emp_name),emp_salary)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setTableName(tableNameC);
- jsonTable.setClusteringOrder("emp_salary ASC");
- jsonTable.setFields(fields);
- Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonTable, keyspaceName, tableNameC);
- // if 200 print to log otherwise fail assertEquals(200, response.getStatus());
- // info.setQueryParameters("index_name=inx_uuid");
- Map<String, String> queryParametersMap = new HashMap<String, String>();
-
- queryParametersMap.put("index_name", "inxuuid");
- response = data.createIndex("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- wrongAuthorization, keyspaceName, tableNameC, "uuid", info);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(401, response.getStatus());
- }
// create index without table name
@Test
@@ -654,29 +576,6 @@ public class TstRestMusicDataAPI {
assertEquals(200, response.getStatus());
}
- // Auth Error
- @Test
- public void test4_insertIntoTable3() throws Exception {
- System.out.println("Testing insert into table with bad credentials");
- createTable();
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "test1");
- values.put("emp_salary", 1500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- wrongAuthorization, jsonInsert, keyspaceName, tableName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(401, response.getStatus());
- }
-
// Table wrong
@Test
public void test4_insertIntoTable4() throws Exception {
@@ -749,28 +648,6 @@ public class TstRestMusicDataAPI {
}
@Test
- public void test5_updateTable_wrongAuth() throws Exception {
- System.out.println("Testing update table w/ wrong credentials");
- createTable();
-
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- wrongAuthorization, jsonUpdate, keyspaceName, tableName, info);
-
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(401, response.getStatus());
- }
-
- @Test
public void test5_updateTable_tableDNE() throws Exception {
System.out.println("Testing update table that does not exist");
createTable();
@@ -843,62 +720,6 @@ public class TstRestMusicDataAPI {
assertEquals(200, response.getStatus());
}
- @Ignore
- @Test
- public void test5_updateTableAuthException1() throws Exception {
- System.out.println("Testing update table authentication error");
- createTable();
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testname");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
-
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- String authDatax = ":";
- String authorizationx = new String(Base64.encode(authDatax.getBytes()));
- Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorizationx, jsonUpdate, keyspaceName, tableName, info);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(401, response.getStatus());
- }
-
- @Ignore
- @Test
- public void test5_updateTableAuthEmpty() throws Exception {
- System.out.println("Testing update table without authentication");
- createTable();
-
- JsonUpdate jsonUpdate = new JsonUpdate();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- Map<String, Object> values = new HashMap<>();
- row.add("emp_name", "testname");
- values.put("emp_salary", 2500);
- consistencyInfo.put("type", "atomic");
- jsonUpdate.setConsistencyInfo(consistencyInfo);
- jsonUpdate.setKeyspaceName(keyspaceName);
- jsonUpdate.setTableName(tableName);
- jsonUpdate.setValues(values);
-
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- String authDatax = ":" + password;
- String authorizationx = new String(Base64.encode(authDatax.getBytes()));
- String appNamex = "xx";
- Response response = data.updateTable("1", "1", "1", "", appNamex, authorizationx, jsonUpdate, keyspaceName,
- tableName, info);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(401, response.getStatus());
- }
-
@Test
public void test6_critical_selectAtomic() throws Exception {
System.out.println("Testing critical select atomic");
@@ -942,21 +763,6 @@ public class TstRestMusicDataAPI {
}
@Test
- public void test6_critical_select_wrongAuth() throws Exception {
- System.out.println("Testing critical select w/ wrong authentication");
- createAndInsertIntoTable();
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- consistencyInfo.put("type", "atomic");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, wrongAuthorization, jsonInsert, keyspaceName, tableName,info);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(401, response.getStatus());
- }
-
- @Test
public void test6_critical_select_nulltable() throws Exception {
System.out.println("Testing critical select w/ null tablename");
createAndInsertIntoTable();
@@ -994,21 +800,6 @@ public class TstRestMusicDataAPI {
}
@Test
- public void test6_select_wrongAuth() throws Exception {
- System.out.println("Testing select w/ wrong authentication");
- createAndInsertIntoTable();
- JsonSelect jsonSelect = new JsonSelect();
- Map<String, String> consistencyInfo = new HashMap<>();
- consistencyInfo.put("type", "atomic");
- jsonSelect.setConsistencyInfo(consistencyInfo);
- Response response = data.select("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, wrongAuthorization, keyspaceName, tableName, info);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(401, response.getStatus());
- }
-
- @Test
public void test6_select_nullTablename() throws Exception {
System.out.println("Testing select w/ null tablename");
createAndInsertIntoTable();
@@ -1041,20 +832,6 @@ public class TstRestMusicDataAPI {
}
@Test
- public void test6_deleteFromTable_wrongAuth() throws Exception {
- System.out.println("Testing delete from table");
- createAndInsertIntoTable();
- JsonDelete jsonDelete = new JsonDelete();
- Map<String, String> consistencyInfo = new HashMap<>();
- consistencyInfo.put("type", "atomic");
- jsonDelete.setConsistencyInfo(consistencyInfo);
- Response response = data.deleteFromTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- wrongAuthorization, jsonDelete, keyspaceName, tableName, info);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
- @Test
public void test6_deleteFromTable_missingTablename() throws Exception {
System.out.println("Testing delete from table w/ null tablename");
createAndInsertIntoTable();
@@ -1120,21 +897,6 @@ public class TstRestMusicDataAPI {
}
@Test
- public void test7_dropTable_wrongAuth() throws Exception {
- System.out.println("Testing drop table w/ wrong auth");
- createTable();
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- consistencyInfo.put("type", "atomic");
- jsonTable.setConsistencyInfo(consistencyInfo);
- Response response = data.dropTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- wrongAuthorization, keyspaceName, tableName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(401, response.getStatus());
- }
-
- @Test
public void test7_dropTable_nullTablename() throws Exception {
System.out.println("Testing drop table w/ null tablename");
createTable();
@@ -1189,8 +951,6 @@ public class TstRestMusicDataAPI {
query.addValue(MusicUtil.convertToActualDataType(DataType.text(), hashedpwd));
query.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
query.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
- CachingUtil.updateMusicCache(keyspaceName, appName);
- CachingUtil.updateMusicValidateCache(appName, userId, hashedpwd);
MusicCore.eventualPut(query);
}
diff --git a/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java b/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java
index 956a266d..86746472 100644
--- a/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java
+++ b/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java
@@ -29,9 +29,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
-
+import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
-
+import javax.ws.rs.core.UriInfo;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -39,15 +39,18 @@ import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mindrot.jbcrypt.BCrypt;
+import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.music.authentication.CachingUtil;
-import org.onap.music.datastore.MusicDataStoreHandle;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.datastore.jsonobjects.JsonInsert;
import org.onap.music.datastore.jsonobjects.JsonLeasedLock;
+import org.onap.music.datastore.jsonobjects.JsonLock;
import org.onap.music.datastore.jsonobjects.JsonTable;
+import org.onap.music.datastore.jsonobjects.JsonUpdate;
import org.onap.music.exceptions.MusicServiceException;
import org.onap.music.lockingservice.cassandra.CassaLockStore;
+import org.onap.music.lockingservice.cassandra.LockType;
import org.onap.music.main.MusicCore;
import org.onap.music.main.MusicUtil;
import org.onap.music.rest.RestMusicDataAPI;
@@ -56,256 +59,253 @@ import com.datastax.driver.core.DataType;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import com.sun.jersey.core.util.Base64;
+import com.sun.jersey.core.util.MultivaluedMapImpl;
@RunWith(MockitoJUnitRunner.class)
public class TstRestMusicLockAPI {
- RestMusicLocksAPI lock = new RestMusicLocksAPI();
- RestMusicDataAPI data = new RestMusicDataAPI();
- static PreparedQueryObject testObject;
-
- static String appName = "TestApp";
- static String userId = "TestUser";
- static String password = "TestPassword";
- static String authData = userId+":"+password;
- static String wrongAuthData = userId+":"+"pass";
- static String authorization = new String(Base64.encode(authData.getBytes()));
- static String wrongAuthorization = new String(Base64.encode(wrongAuthData.getBytes()));
- static boolean isAAF = false;
- static UUID uuid = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40ce6");
- static String keyspaceName = "testcassa";
- static String tableName = "employees";
- static String onboardUUID = null;
- static String lockName = "testcassa.employees.testname";
- static String malformedLock = "malformedLock";
-
- @BeforeClass
- public static void init() throws Exception {
- System.out.println("Testing RestMusicLock class");
- try {
- createKeyspace();
- } catch (Exception e) {
- e.printStackTrace();
- throw new Exception("Unable to initialize before TestRestMusicData test class. " + e.getMessage());
- }
- }
-
- @After
- public void afterEachTest( ) throws MusicServiceException {
- clearAllTablesFromKeyspace();
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- testObject = new PreparedQueryObject();
- testObject.appendQueryString("DROP KEYSPACE IF EXISTS " + keyspaceName);
- MusicCore.eventualPut(testObject);
- }
- @SuppressWarnings("unchecked")
- @Test
- public void test_createLockReference() throws Exception {
- System.out.println("Testing create lockref");
- createAndInsertIntoTable();
- Response response =lock.createLockReference(lockName,"1","1",authorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- Map<String,Object> respMap = (Map<String, Object>) response.getEntity();
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(200, response.getStatus());
- assertTrue(respMap.containsKey("lock"));
- assertTrue(((Map<String,String>) respMap.get("lock")).containsKey("lock"));
+ @Mock
+ UriInfo info;
+
+ RestMusicLocksAPI lock = new RestMusicLocksAPI();
+ RestMusicDataAPI data = new RestMusicDataAPI();
+ static PreparedQueryObject testObject;
+
+ static String appName = "TestApp";
+ static String userId = "TestUser";
+ static String password = "TestPassword";
+ static String authData = userId + ":" + password;
+ static String wrongAuthData = userId + ":" + "pass";
+ static String authorization = new String(Base64.encode(authData.getBytes()));
+ static String wrongAuthorization = new String(Base64.encode(wrongAuthData.getBytes()));
+ static boolean isAAF = false;
+ static UUID uuid = UUID.fromString("abc66ccc-d857-4e90-b1e5-df98a3d40ce6");
+ static String keyspaceName = "testcassa";
+ static String tableName = "employees";
+ static String onboardUUID = null;
+ static String lockName = "testcassa.employees.testname";
+
+ @BeforeClass
+ public static void init() throws Exception {
+ System.out.println("Testing RestMusicLock class");
+ try {
+ createKeyspace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new Exception("Unable to initialize before TestRestMusicData test class. " + e.getMessage());
+ }
}
- @Test
- public void test_createLockReference_wrongAuth() throws Exception {
- System.out.println("Testing create lockref with wrong auth");
- createAndInsertIntoTable();
- Response response =lock.createLockReference(lockName,"1","1", wrongAuthorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ @After
+ public void afterEachTest() throws MusicServiceException {
+ clearAllTablesFromKeyspace();
+ }
- assertEquals(401, response.getStatus());
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ testObject = new PreparedQueryObject();
+ testObject.appendQueryString("DROP KEYSPACE IF EXISTS " + keyspaceName);
+ MusicCore.eventualPut(testObject);
}
-
+
+ @SuppressWarnings("unchecked")
@Test
- public void test_createLockReference_malformedLockName() throws Exception {
- System.out.println("Testing create lockref w/ malformed lock");
+ public void test_createLockReference() throws Exception {
+ System.out.println("Testing create lockref");
createAndInsertIntoTable();
- Response response =lock.createLockReference(malformedLock,"1","1",authorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
+ Response response = lock.createLockReference(lockName, "1", "1", authorization,
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", null, appName);
+ Map<String, Object> respMap = (Map<String, Object>) response.getEntity();
System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(400, response.getStatus());
+ assertEquals(200, response.getStatus());
+ assertTrue(respMap.containsKey("lock"));
+ assertTrue(((Map<String, String>) respMap.get("lock")).containsKey("lock"));
}
@Test
- public void test_accquireLock() throws Exception {
- System.out.println("Testing acquire lock");
- createAndInsertIntoTable();
- String lockRef = createLockReference();
-
- Response response = lock.accquireLock(lockRef, "1", "1", authorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void test_accquireLock_wrongAuth() throws Exception {
- System.out.println("Testing acquire lock w/ wrong auth");
+ public void test_createReadLock() throws Exception {
+ System.out.println("Testing create read lockref");
createAndInsertIntoTable();
- String lockRef = createLockReference();
-
- Response response = lock.accquireLock(lockRef, "1", "1", wrongAuthorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
+ JsonLock jsonLock = createJsonLock(LockType.READ);
+ Response response = lock.createLockReference(lockName, "1", "1", authorization,
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", jsonLock, appName);
+ Map<String, Object> respMap = (Map<String, Object>) response.getEntity();
System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(401, response.getStatus());
+
+ assertEquals(200, response.getStatus());
+ assertTrue(respMap.containsKey("lock"));
+ assertTrue(((Map<String, String>) respMap.get("lock")).containsKey("lock"));
}
-
+
@Test
- public void test_accquireBadLock() throws Exception {
- System.out.println("Testing acquire lock that is not lock-holder");
+ public void test_createWriteLock() throws Exception {
+ System.out.println("Testing create read lockref");
createAndInsertIntoTable();
-
- String lockRef1 = createLockReference();
- String lockRef2 = createLockReference();
-
-
- Response response = lock.accquireLock(lockRef2, "1", "1", authorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
+ JsonLock jsonLock = createJsonLock(LockType.WRITE);
+ Response response = lock.createLockReference(lockName, "1", "1", authorization,
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", jsonLock, appName);
+ Map<String, Object> respMap = (Map<String, Object>) response.getEntity();
System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(400, response.getStatus());
+
+ assertEquals(200, response.getStatus());
+ assertTrue(respMap.containsKey("lock"));
+ assertTrue(((Map<String, String>) respMap.get("lock")).containsKey("lock"));
}
-
+
@Test
- public void test_accquireLock_malformedLock() throws Exception {
- System.out.println("Testing acquire lock w/ malformedLock");
+ public void test_accquireLock() throws Exception {
+ System.out.println("Testing acquire lock");
createAndInsertIntoTable();
+ String lockRef = createLockReference();
- Response response = lock.accquireLock(malformedLock, "1", "1", wrongAuthorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
+ Response response =
+ lock.accquireLock(lockRef, "1", "1", authorization, "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(400, response.getStatus());
+ assertEquals(200, response.getStatus());
}
-
+
@Test
- public void test_accquireLockWLease() throws Exception {
- System.out.println("Testing acquire lock with lease");
+ public void test_acquireReadLock() throws Exception {
+ System.out.println("Testing acquire read lock");
createAndInsertIntoTable();
- String lockRef = createLockReference();
+ String lockRef = createLockReference(LockType.READ);
+ String lockRef2 = createLockReference(LockType.READ);
- JsonLeasedLock jsonLock = new JsonLeasedLock();
- jsonLock.setLeasePeriod(10000); //10 second lease period?
- Response response = lock.accquireLockWithLease(jsonLock, lockRef, "1", "1", authorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
+ Response response =
+ lock.accquireLock(lockRef, "1", "1", authorization, "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ assertEquals(200, response.getStatus());
+ response =
+ lock.accquireLock(lockRef2, "1", "1", authorization, "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
assertEquals(200, response.getStatus());
}
@Test
- public void test_accquireLockWLease_wrongAuth() throws Exception {
- System.out.println("Testing acquire lock with lease w/ wrong Auth");
+ public void test_acquireReadLockaFail() throws Exception {
+ System.out.println("Testing acquire read lock");
createAndInsertIntoTable();
- String lockRef = createLockReference();
+ String lockRef = createLockReference(LockType.WRITE);
+ String lockRef2 = createLockReference(LockType.READ);
- JsonLeasedLock jsonLock = new JsonLeasedLock();
- jsonLock.setLeasePeriod(10000); //10 second lease period?
- Response response = lock.accquireLockWithLease(jsonLock, lockRef, "1", "1", wrongAuthorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
+ Response response =
+ lock.accquireLock(lockRef, "1", "1", authorization, "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ assertEquals(200, response.getStatus());
+ response =
+ lock.accquireLock(lockRef2, "1", "1", authorization, "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(401, response.getStatus());
+ assertEquals(400, response.getStatus());
}
-
+
@Test
- public void test_accquireLockWLease_malformedLock() throws Exception {
- System.out.println("Testing acquire lock with lease w/ malformed lock");
+ public void test_writeWReadLock() throws Exception {
+ System.out.println("Testing writing with a read lock");
createAndInsertIntoTable();
- String lockRef = createLockReference();
+ String lockRef = createLockReference(LockType.READ);
+
+ JsonUpdate jsonUpdate = new JsonUpdate();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, Object> values = new HashMap<>();
+ values.put("emp_salary", 2500);
+ consistencyInfo.put("type", "critical");
+ consistencyInfo.put("lockId", lockRef);
+ jsonUpdate.setConsistencyInfo(consistencyInfo);
+ jsonUpdate.setKeyspaceName(keyspaceName);
+ jsonUpdate.setTableName(tableName);
+ jsonUpdate.setValues(values);
+ MultivaluedMap<String, String> row = new MultivaluedMapImpl();
+ row.add("emp_name", "testname");
+ Mockito.when(info.getQueryParameters()).thenReturn(row);
+
+ Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonUpdate, keyspaceName, tableName, info);
- JsonLeasedLock jsonLock = new JsonLeasedLock();
- jsonLock.setLeasePeriod(10000); //10 second lease period?
- Response response = lock.accquireLockWithLease(jsonLock, malformedLock, "1", "1",
- wrongAuthorization, "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
assertEquals(400, response.getStatus());
}
-
- @Test
- public void test_currentLockHolder() throws Exception {
- System.out.println("Testing get current lock holder");
- createAndInsertIntoTable();
- String lockRef = createLockReference();
+ @Test
+ public void test_writeWWriteLock() throws Exception {
+ System.out.println("Testing writing with a read lock");
+ createAndInsertIntoTable();
+ String lockRef = createLockReference(LockType.WRITE);
+
+ JsonUpdate jsonUpdate = new JsonUpdate();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, Object> values = new HashMap<>();
+ values.put("emp_salary", 2500);
+ consistencyInfo.put("type", "critical");
+ consistencyInfo.put("lockId", lockRef);
+ jsonUpdate.setConsistencyInfo(consistencyInfo);
+ jsonUpdate.setKeyspaceName(keyspaceName);
+ jsonUpdate.setTableName(tableName);
+ jsonUpdate.setValues(values);
+ MultivaluedMap<String, String> row = new MultivaluedMapImpl();
+ row.add("emp_name", "testname");
+ Mockito.when(info.getQueryParameters()).thenReturn(row);
+
+ Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonUpdate, keyspaceName, tableName, info);
- Response response = lock.currentLockHolder(lockName, "1", "1", authorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(200, response.getStatus());
- Map<String,Object> respMap = (Map<String, Object>) response.getEntity();
- assertEquals(lockRef, ((Map<String,String>) respMap.get("lock")).get("lock-holder"));
+ assertEquals(200, response.getStatus());
}
-
+
@Test
- public void test_currentLockHolder_wrongAuth() throws Exception {
- System.out.println("Testing get current lock holder w/ wrong Auth");
+ public void test_accquireLockWLease() throws Exception {
+ System.out.println("Testing acquire lock with lease");
createAndInsertIntoTable();
-
String lockRef = createLockReference();
- Response response = lock.currentLockHolder(lockName, "1", "1", wrongAuthorization,
+ JsonLeasedLock jsonLock = new JsonLeasedLock();
+ jsonLock.setLeasePeriod(10000); // 10 second lease period?
+ Response response = lock.accquireLockWithLease(jsonLock, lockRef, "1", "1", authorization,
"abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(401, response.getStatus());
+ assertEquals(200, response.getStatus());
}
@Test
- public void test_currentLockHolder_malformedLock() throws Exception {
- System.out.println("Testing get current lock holder w/ malformed lock");
+ public void test_accquireBadLock() throws Exception {
+ System.out.println("Testing acquire lock that is not lock-holder");
createAndInsertIntoTable();
+ // This is required to create an initial loc reference.
+ String lockRef1 = createLockReference();
+ // This will create the next lock reference, whcih will not be avalale yet.
+ String lockRef2 = createLockReference();
- String lockRef = createLockReference();
-
- Response response = lock.currentLockHolder(malformedLock, "1", "1", wrongAuthorization,
+ Response response = lock.accquireLock(lockRef2, "1", "1", authorization,
"abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
assertEquals(400, response.getStatus());
}
@Test
- public void test_unLock() throws Exception {
- System.out.println("Testing unlock");
- createAndInsertIntoTable();
- String lockRef = createLockReference();
-
- Response response = lock.unLock(lockRef, "1", "1", authorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(200, response.getStatus());
- }
-
- @Test
- public void test_unLock_wrongAuth() throws Exception {
- System.out.println("Testing unlock w/ wrong auth");
+ public void test_currentLockHolder() throws Exception {
+ System.out.println("Testing get current lock holder");
createAndInsertIntoTable();
+
String lockRef = createLockReference();
- Response response = lock.unLock(lockRef, "1", "1", wrongAuthorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
+ Response response =
+ lock.enquireLock(lockName, "1", "1", authorization, "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(401, response.getStatus());
+ assertEquals(200, response.getStatus());
+ Map<String, Object> respMap = (Map<String, Object>) response.getEntity();
+ assertEquals(lockRef, ((Map<String, String>) respMap.get("lock")).get("lock-holder"));
}
@Test
- public void test_unLock_malformedLock() throws Exception {
- System.out.println("Testing unlock w/ malformedLock");
+ public void test_unLock() throws Exception {
+ System.out.println("Testing unlock");
createAndInsertIntoTable();
String lockRef = createLockReference();
- Response response = lock.unLock("malformedLock", "1", "1", wrongAuthorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
+ Response response =
+ lock.unLock(lockRef, "1", "1", authorization, "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(400, response.getStatus());
+ assertEquals(200, response.getStatus());
}
@Test
@@ -322,102 +322,59 @@ public class TstRestMusicLockAPI {
Map<String,Object> respMap = (Map<String, Object>) response.getEntity();
assertEquals(lockRef, ((Map<String,String>) respMap.get("lock")).get("lock-holder"));
}
-
- @Test
- public void test_getLockState_wrongAuth() throws Exception {
- System.out.println("Testing get lock state w/ wrong auth");
- createAndInsertIntoTable();
-
- String lockRef = createLockReference();
- Response response = lock.currentLockState(lockName, "1", "1", wrongAuthorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(401, response.getStatus());
- }
-
+ // Ignoring since this is now a duplicate of delete lock ref.
@Test
- public void test_getLockState_malformedLock() throws Exception {
- System.out.println("Testing get lock state w/ malformedLock");
- createAndInsertIntoTable();
-
- String lockRef = createLockReference();
-
- Response response = lock.currentLockState(malformedLock, "1", "1", wrongAuthorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(400, response.getStatus());
- }
-
- @Test
- @Ignore //deprecated function
+ @Ignore
public void test_deleteLock() throws Exception {
- System.out.println("Testing delete lock");
+ System.out.println("Testing get lock state");
createAndInsertIntoTable();
- String lockRef = createLockReference();
-
Response response = lock.deleteLock(lockName, "1", "1",
"abc66ccc-d857-4e90-b1e5-df98a3d40ce6", authorization, appName);
System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
assertEquals(200, response.getStatus());
}
- @Test
- @Ignore //deprecated function
- public void test_deleteLock_wrongAuth() throws Exception {
- System.out.println("Testing delete lock w/ wrong auth");
- createAndInsertIntoTable();
-
- String lockRef = createLockReference();
-
- Response response = lock.deleteLock(lockName, "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", wrongAuthorization, appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(401, response.getStatus());
+ /**
+ * Create table and lock reference
+ *
+ * @return the lock ref created
+ * @throws Exception
+ */
+ @SuppressWarnings("unchecked")
+ private String createLockReference() throws Exception {
+ Response response = lock.createLockReference(lockName, "1", "1", authorization,
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", null, appName);
+ Map<String, Object> respMap = (Map<String, Object>) response.getEntity();
+ return ((Map<String, String>) respMap.get("lock")).get("lock");
}
-
- @Test
- @Ignore //deprecated function
- public void test_deleteLock_malformedLock() throws Exception {
- System.out.println("Testing delete lock w/ malformed lock");
- createAndInsertIntoTable();
-
- String lockRef = createLockReference();
- Response response = lock.deleteLock(malformedLock, "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", wrongAuthorization, appName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(400, response.getStatus());
+ /**
+ * Create table and lock reference
+ *
+ * @return the lock ref created
+ * @throws Exception
+ */
+ @SuppressWarnings("unchecked")
+ private String createLockReference(LockType lockType) throws Exception {
+ JsonLock jsonLock = createJsonLock(lockType);
+ Response response = lock.createLockReference(lockName, "1", "1", authorization,
+ "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", jsonLock, appName);
+ Map<String, Object> respMap = (Map<String, Object>) response.getEntity();
+ return ((Map<String, String>) respMap.get("lock")).get("lock");
}
-
- /**
- * Create table and lock reference
- * @return the lock ref created
- * @throws Exception
- */
- @SuppressWarnings("unchecked")
- private String createLockReference() throws Exception {
- Response response =lock.createLockReference(lockName,"1","1",authorization,
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName);
- Map<String,Object> respMap = (Map<String, Object>) response.getEntity();
- return ((Map<String,String>) respMap.get("lock")).get("lock");
- }
-
-
-
-
- private static void createKeyspace() throws Exception {
- //shouldn't really be doing this here, but create keyspace is currently turned off
- PreparedQueryObject query = new PreparedQueryObject();
- query.appendQueryString(CassandraCQL.createKeySpace);
- MusicCore.eventualPut(query);
-
- boolean isAAF = false;
+
+ private static void createKeyspace() throws Exception {
+ // shouldn't really be doing this here, but create keyspace is currently turned off
+ PreparedQueryObject query = new PreparedQueryObject();
+ query.appendQueryString(CassandraCQL.createKeySpace);
+ MusicCore.eventualPut(query);
+
+ boolean isAAF = false;
String hashedpwd = BCrypt.hashpw(password, BCrypt.gensalt());
query = new PreparedQueryObject();
- query.appendQueryString(
- "INSERT into admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
+ query.appendQueryString("INSERT into admin.keyspace_master (uuid, keyspace_name, application_name, is_api, "
+ "password, username, is_aaf) values (?,?,?,?,?,?,?)");
query.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
query.addValue(MusicUtil.convertToActualDataType(DataType.text(), keyspaceName));
@@ -426,69 +383,78 @@ public class TstRestMusicLockAPI {
query.addValue(MusicUtil.convertToActualDataType(DataType.text(), hashedpwd));
query.addValue(MusicUtil.convertToActualDataType(DataType.text(), userId));
query.addValue(MusicUtil.convertToActualDataType(DataType.cboolean(), isAAF));
- CachingUtil.updateMusicCache(keyspaceName, appName);
- CachingUtil.updateMusicValidateCache(appName, userId, hashedpwd);
+ //CachingUtil.updateMusicCache(keyspaceName, appName);
+ //CachingUtil.updateMusicValidateCache(appName, userId, hashedpwd);
MusicCore.eventualPut(query);
- }
-
- private void clearAllTablesFromKeyspace() throws MusicServiceException {
- ArrayList<String> tableNames = new ArrayList<>();
- PreparedQueryObject query = new PreparedQueryObject();
- query.appendQueryString("SELECT table_name FROM system_schema.tables WHERE keyspace_name = '"+keyspaceName+"';");
- ResultSet rs = MusicCore.get(query);
- for (Row row: rs) {
- tableNames.add(row.getString("table_name"));
- }
- for (String table: tableNames) {
- query = new PreparedQueryObject();
- query.appendQueryString("DROP TABLE " + keyspaceName + "." + table);
- MusicCore.eventualPut(query);
- }
- }
-
- /**
- * Create a table {@link tableName} in {@link keyspaceName}
- * @throws Exception
- */
- private void createTable() throws Exception {
- JsonTable jsonTable = new JsonTable();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, String> fields = new HashMap<>();
- fields.put("uuid", "text");
- fields.put("emp_name", "text");
- fields.put("emp_salary", "varint");
- fields.put("PRIMARY KEY", "(emp_name)");
- consistencyInfo.put("type", "eventual");
- jsonTable.setConsistencyInfo(consistencyInfo);
- jsonTable.setKeyspaceName(keyspaceName);
- jsonTable.setPrimaryKey("emp_name");
- jsonTable.setTableName(tableName);
- jsonTable.setFields(fields);
- //Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
- Response response = data.createTable("1", "1", "1",
- "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",appName, authorization,
- jsonTable, keyspaceName, tableName);
- }
-
- /**
- * Create table {@link createTable} and insert into said table
- * @throws Exception
- */
- private void createAndInsertIntoTable() throws Exception {
- createTable();
-
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- Map<String, Object> values = new HashMap<>();
- values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
- values.put("emp_name", "testname");
- values.put("emp_salary", 500);
- consistencyInfo.put("type", "eventual");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- jsonInsert.setKeyspaceName(keyspaceName);
- jsonInsert.setTableName(tableName);
- jsonInsert.setValues(values);
- Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
- appName, authorization, jsonInsert, keyspaceName, tableName);
- }
-}
+ }
+
+ private void clearAllTablesFromKeyspace() throws MusicServiceException {
+ ArrayList<String> tableNames = new ArrayList<>();
+ PreparedQueryObject query = new PreparedQueryObject();
+ query.appendQueryString(
+ "SELECT table_name FROM system_schema.tables WHERE keyspace_name = '" + keyspaceName + "';");
+ ResultSet rs = MusicCore.get(query);
+ for (Row row : rs) {
+ tableNames.add(row.getString("table_name"));
+ }
+ for (String table : tableNames) {
+ query = new PreparedQueryObject();
+ query.appendQueryString("DROP TABLE " + keyspaceName + "." + table);
+ MusicCore.eventualPut(query);
+ }
+ }
+
+ /**
+ * Create a table {@link tableName} in {@link keyspaceName}
+ *
+ * @throws Exception
+ */
+ private void createTable() throws Exception {
+ JsonTable jsonTable = new JsonTable();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, String> fields = new HashMap<>();
+ fields.put("uuid", "text");
+ fields.put("emp_name", "text");
+ fields.put("emp_salary", "varint");
+ fields.put("PRIMARY KEY", "(emp_name)");
+ consistencyInfo.put("type", "eventual");
+ jsonTable.setConsistencyInfo(consistencyInfo);
+ jsonTable.setKeyspaceName(keyspaceName);
+ jsonTable.setPrimaryKey("emp_name");
+ jsonTable.setTableName(tableName);
+ jsonTable.setFields(fields);
+ // Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion());
+ Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonTable, keyspaceName, tableName);
+ }
+
+ /**
+ * Create table {@link createTable} and insert into said table
+ *
+ * @throws Exception
+ */
+ private void createAndInsertIntoTable() throws Exception {
+ createTable();
+
+ JsonInsert jsonInsert = new JsonInsert();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, Object> values = new HashMap<>();
+ values.put("uuid", "cfd66ccc-d857-4e90-b1e5-df98a3d40cd6");
+ values.put("emp_name", "testname");
+ values.put("emp_salary", 500);
+ consistencyInfo.put("type", "eventual");
+ jsonInsert.setConsistencyInfo(consistencyInfo);
+ jsonInsert.setKeyspaceName(keyspaceName);
+ jsonInsert.setTableName(tableName);
+ jsonInsert.setValues(values);
+ Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonInsert, keyspaceName, tableName);
+ }
+
+ private JsonLock createJsonLock(LockType lockType) {
+ JsonLock jsonLock = new JsonLock();
+ jsonLock.setLockType(lockType);
+ return jsonLock;
+ }
+
+} \ No newline at end of file