diff options
author | Tschaen, Brendan <ctschaen@att.com> | 2019-06-01 21:26:25 -0400 |
---|---|---|
committer | Tschaen, Brendan <ctschaen@att.com> | 2019-06-01 21:26:25 -0400 |
commit | fdf19711e482e5c22f3d6fdb18e0bc052ec37e4e (patch) | |
tree | c856a1d5c58bade7f5cd21b8915c766a5f3c8a30 | |
parent | 641255c612fae09ff8840124eb7dcf5046083dd0 (diff) |
Update unit tests for holders api
Change-Id: Ib4d6ce287cdacc2c0aad36c2936075087a9e6f49
Issue-ID: MUSIC-405
Signed-off-by: Tschaen, Brendan <ctschaen@att.com>
3 files changed, 206 insertions, 3 deletions
diff --git a/src/main/java/org/onap/music/service/impl/MusicCassaCore.java b/src/main/java/org/onap/music/service/impl/MusicCassaCore.java index cf6f5ed3..cebdc667 100644 --- a/src/main/java/org/onap/music/service/impl/MusicCassaCore.java +++ b/src/main/java/org/onap/music/service/impl/MusicCassaCore.java @@ -286,7 +286,7 @@ public class MusicCassaCore implements MusicCoreService { try { LockObject lockOwner = getLockingServiceHandle().peekLockQueue(keyspace, table, primaryKeyValue); if (!lockOwner.getIsLockOwner()) { - return "No lock holder!"; + return null; } return "$" + fullyQualifiedKey + "$" + lockOwner.getLockRef(); } catch (MusicLockingException | MusicServiceException | MusicQueryException e) { diff --git a/src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java b/src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java index 67a68f6e..3bf33179 100644 --- a/src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java +++ b/src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java @@ -136,6 +136,42 @@ public class TstRestMusicDataAPI { Map<String, String> respMap = (Map<String, String>) response.getEntity(); assertEquals(ResultType.FAILURE, respMap.get("status")); } + + @Test + public void test1_createKeyspaceSuccess() throws Exception { + System.out.println("Testing successful creation and deletion of keyspace"); + MusicUtil.setKeyspaceActive(true); + + String keyspaceToCreate = "temp"+keyspaceName; + + + 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"); + //don't overwrite a keyspace we already have + jsonKeyspace.setKeyspaceName(keyspaceToCreate); + jsonKeyspace.setReplicationInfo(replicationInfo); + // Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); + Response response = + data.createKeySpace("1", "1", "1", null, authorization, appName, jsonKeyspace, keyspaceToCreate); + System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity()); + assertEquals(200, response.getStatus()); + Map<String, String> respMap = (Map<String, String>) response.getEntity(); + assertEquals(ResultType.SUCCESS, respMap.get("status")); + + response = data.dropKeySpace("1", "1", "1", null, authorization, appName, keyspaceToCreate); + assertEquals(200, response.getStatus()); + respMap = (Map<String, String>) response.getEntity(); + assertEquals(ResultType.SUCCESS, respMap.get("status")); + + //unset to not mess up any further tests + MusicUtil.setKeyspaceActive(false); + } @Test public void test3_createTable() throws Exception { @@ -180,6 +216,22 @@ public class TstRestMusicDataAPI { System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity()); assertEquals(400, response.getStatus()); } + + @Test + public void test3_createTableNoFields() throws Exception { + System.out.println("Testing create table without fields"); + JsonTable jsonTable = new JsonTable(); + Map<String, String> consistencyInfo = new HashMap<>(); + consistencyInfo.put("type", "eventual"); + jsonTable.setConsistencyInfo(consistencyInfo); + jsonTable.setKeyspaceName(keyspaceName); + jsonTable.setPrimaryKey("emp_name"); + jsonTable.setTableName(""); + Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, + authorization, jsonTable, keyspaceName, ""); + System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity()); + assertEquals(400, response.getStatus()); + } @Test @@ -266,7 +318,7 @@ public class TstRestMusicDataAPI { // Improper parenthesis in key field @Test - public void test3_createTable_badParantesis() throws Exception { + public void test3_createTable_badParanthesis() throws Exception { System.out.println("Testing malformed create table request"); String tableNameC = "testTable0"; JsonTable jsonTable = new JsonTable(); @@ -489,6 +541,24 @@ public class TstRestMusicDataAPI { } @Test + public void test4_insertIntoTableNoValues() throws Exception { + System.out.println("Testing insert into table"); + createTable(); + JsonInsert jsonInsert = new JsonInsert(); + Map<String, String> consistencyInfo = new HashMap<>(); + consistencyInfo.put("type", "eventual"); + jsonInsert.setConsistencyInfo(consistencyInfo); + jsonInsert.setKeyspaceName(keyspaceName); + jsonInsert.setTableName(tableName); + + Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, + authorization, jsonInsert, keyspaceName, tableName); + System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity()); + + assertEquals(400, response.getStatus()); + } + + @Test public void test4_insertIntoTableCriticalNoLockID() throws Exception { System.out.println("Testing critical insert into table without lockid"); createTable(); @@ -647,6 +717,19 @@ public class TstRestMusicDataAPI { assertEquals(200, response.getStatus()); } + + public void test5_updateTableNoBody() throws Exception { + System.out.println("Testing update table no body"); + createTable(); + + Response response = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, + authorization, null, keyspaceName, tableName, info); + + System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity()); + + assertEquals(400, response.getStatus()); + } + @Test public void test5_updateTable_tableDNE() throws Exception { System.out.println("Testing update table that does not exist"); @@ -740,7 +823,8 @@ public class TstRestMusicDataAPI { Map<String, String> row0 = (Map<String, String>) result.get("row 0"); assertEquals("testname", row0.get("emp_name")); assertEquals(BigInteger.valueOf(500), row0.get("emp_salary")); - } + } + @Test public void test6_critical_selectCritical_nolockid() throws Exception { diff --git a/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java b/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java index 86746472..1e9ed79a 100644 --- a/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java +++ b/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java @@ -123,6 +123,18 @@ public class TstRestMusicLockAPI { assertTrue(respMap.containsKey("lock")); assertTrue(((Map<String, String>) respMap.get("lock")).containsKey("lock")); } + + @Test + public void test_createBadLockReference() throws Exception { + System.out.println("Testing create bad lockref"); + createAndInsertIntoTable(); + Response response = lock.createLockReference("badlock", "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()); + } @Test public void test_createReadLock() throws Exception { @@ -267,6 +279,20 @@ public class TstRestMusicLockAPI { } @Test + public void test_accquireBadLockWLease() throws Exception { + System.out.println("Testing acquire bad lock ref with lease"); + createAndInsertIntoTable(); + String lockRef = createLockReference(); + + JsonLeasedLock jsonLock = new JsonLeasedLock(); + jsonLock.setLeasePeriod(10000); // 10 second lease period? + Response response = lock.accquireLockWithLease(jsonLock, "badlock", "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_accquireBadLock() throws Exception { System.out.println("Testing acquire lock that is not lock-holder"); createAndInsertIntoTable(); @@ -282,6 +308,19 @@ public class TstRestMusicLockAPI { } @Test + public void test_accquireBadLockRef() throws Exception { + System.out.println("Testing acquire bad lock ref"); + createAndInsertIntoTable(); + // This is required to create an initial loc reference. + String lockRef1 = createLockReference(); + + Response response = lock.accquireLock("badlockref", "1", "1", authorization, + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName); + System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity()); + assertEquals(400, response.getStatus()); + } + + @Test public void test_currentLockHolder() throws Exception { System.out.println("Testing get current lock holder"); createAndInsertIntoTable(); @@ -297,6 +336,59 @@ public class TstRestMusicLockAPI { } @Test + public void test_nocurrentLockHolder() throws Exception { + System.out.println("Testing get current lock holder w/ bad lockref"); + createAndInsertIntoTable(); + + Response response = + lock.enquireLock(lockName, "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_badcurrentLockHolder() throws Exception { + System.out.println("Testing get current lock holder w/ bad lockref"); + createAndInsertIntoTable(); + + String lockRef = createLockReference(); + + Response response = + lock.enquireLock("badlock", "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_holders() throws Exception { + System.out.println("Testing holders api"); + createAndInsertIntoTable(); + + String lockRef = createLockReference(); + + Response response = + lock.currentLockHolder(lockName, "1", "1", authorization, "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName); + System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity()); + assertEquals(200, response.getStatus()); + Map<String, Object> respMap = (Map<String, Object>) response.getEntity(); + //TODO: this should be lockRef + assertEquals("1", ((Map<String, String>) respMap.get("lock")).get("lock-holder")); + } + + @Test + public void test_holdersbadRef() throws Exception { + System.out.println("Testing holders api w/ bad lockref"); + createAndInsertIntoTable(); + + String lockRef = createLockReference(); + + Response response = + lock.currentLockHolder("badname", "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(); @@ -309,6 +401,18 @@ public class TstRestMusicLockAPI { } @Test + public void test_unLockBadRef() throws Exception { + System.out.println("Testing unlock w/ bad lock ref"); + createAndInsertIntoTable(); + String lockRef = createLockReference(); + + Response response = + lock.unLock("badref", "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_getLockState() throws Exception { System.out.println("Testing get lock state"); createAndInsertIntoTable(); @@ -322,6 +426,19 @@ 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_getLockStateBadRef() throws Exception { + System.out.println("Testing get lock state w/ bad ref"); + createAndInsertIntoTable(); + + String lockRef = createLockReference(); + + Response response = lock.currentLockState("badname", "1", "1", authorization, + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName); + System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity()); + assertEquals(400, response.getStatus()); + } // Ignoring since this is now a duplicate of delete lock ref. @Test @@ -329,6 +446,8 @@ public class TstRestMusicLockAPI { public void test_deleteLock() throws Exception { System.out.println("Testing get lock state"); createAndInsertIntoTable(); + + String lockRef = createLockReference(); Response response = lock.deleteLock(lockName, "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", authorization, appName); |