diff options
author | Tschaen, Brendan <ctschaen@att.com> | 2019-02-26 17:35:35 -0500 |
---|---|---|
committer | Tschaen, Brendan <ctschaen@att.com> | 2019-02-26 17:35:35 -0500 |
commit | d350d020b40aad0b67bd5698f7c009733e81d7ca (patch) | |
tree | 21204197a5545f130847a914daa9051944871bc2 /src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java | |
parent | b58e1d3db05aed02b62a557bf14db6ea7b8df5f5 (diff) |
Test for wrong user, missing required inputs
Change-Id: If7625349ea0cbb9bedf15554ca72d29dbaa1ba0d
Issue-ID: MUSIC-341
Signed-off-by: Tschaen, Brendan <ctschaen@att.com>
Diffstat (limited to 'src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java')
-rw-r--r-- | src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java | 198 |
1 files changed, 187 insertions, 11 deletions
diff --git a/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java b/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java index a5113ea5..92c5d818 100644 --- a/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java +++ b/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java @@ -77,6 +77,7 @@ public class TstRestMusicLockAPI { 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 { @@ -115,6 +116,28 @@ public class TstRestMusicLockAPI { assertTrue(respMap.containsKey("lock")); assertTrue(((Map<String,String>) respMap.get("lock")).containsKey("lock")); } + + @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()); + + assertEquals(401, response.getStatus()); + } + + @Test + public void test_createLockReference_malformedLockName() throws Exception { + System.out.println("Testing create lockref w/ malformed lock"); + createAndInsertIntoTable(); + Response response =lock.createLockReference(malformedLock,"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_accquireLock() throws Exception { @@ -129,6 +152,44 @@ public class TstRestMusicLockAPI { } @Test + public void test_accquireLock_wrongAuth() throws Exception { + System.out.println("Testing acquire lock w/ wrong auth"); + createAndInsertIntoTable(); + String lockRef = createLockReference(); + + Response response = lock.accquireLock(lockRef, "1", "1", wrongAuthorization, + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName); + System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity()); + assertEquals(401, response.getStatus()); + } + + @Test + public void test_accquireBadLock() throws Exception { + System.out.println("Testing acquire lock that is not lock-holder"); + createAndInsertIntoTable(); + + String lockRef1 = createLockReference(); + String lockRef2 = createLockReference(); + + + Response response = lock.accquireLock(lockRef2, "1", "1", authorization, + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName); + System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity()); + assertEquals(400, response.getStatus()); + } + + @Test + public void test_accquireLock_malformedLock() throws Exception { + System.out.println("Testing acquire lock w/ malformedLock"); + createAndInsertIntoTable(); + + Response response = lock.accquireLock(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_accquireLockWLease() throws Exception { System.out.println("Testing acquire lock with lease"); createAndInsertIntoTable(); @@ -143,18 +204,31 @@ public class TstRestMusicLockAPI { } @Test - public void test_accquireBadLock() throws Exception { - System.out.println("Testing acquire lock that is not lock-holder"); - createAndInsertIntoTable(); - - String lockRef1 = createLockReference(); - String lockRef2 = createLockReference(); + public void test_accquireLockWLease_wrongAuth() throws Exception { + System.out.println("Testing acquire lock with lease w/ wrong Auth"); + createAndInsertIntoTable(); + String lockRef = createLockReference(); + 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); + System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity()); + assertEquals(401, response.getStatus()); + } + + @Test + public void test_accquireLockWLease_malformedLock() throws Exception { + System.out.println("Testing acquire lock with lease w/ malformed lock"); + createAndInsertIntoTable(); + String lockRef = createLockReference(); - Response response = lock.accquireLock(lockRef2, "1", "1", authorization, - "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName); - System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity()); - assertEquals(400, response.getStatus()); + 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 @@ -173,6 +247,32 @@ public class TstRestMusicLockAPI { } @Test + public void test_currentLockHolder_wrongAuth() throws Exception { + System.out.println("Testing get current lock holder w/ wrong Auth"); + createAndInsertIntoTable(); + + String lockRef = createLockReference(); + + Response response = lock.currentLockHolder(lockName, "1", "1", wrongAuthorization, + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName); + System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity()); + assertEquals(401, response.getStatus()); + } + + @Test + public void test_currentLockHolder_malformedLock() throws Exception { + System.out.println("Testing get current lock holder w/ malformed lock"); + createAndInsertIntoTable(); + + String lockRef = createLockReference(); + + Response response = lock.currentLockHolder(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_unLock() throws Exception { System.out.println("Testing unlock"); createAndInsertIntoTable(); @@ -185,6 +285,30 @@ public class TstRestMusicLockAPI { } @Test + public void test_unLock_wrongAuth() throws Exception { + System.out.println("Testing unlock w/ wrong auth"); + createAndInsertIntoTable(); + String lockRef = createLockReference(); + + Response response = lock.unLock(lockRef, "1", "1", wrongAuthorization, + "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName); + System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity()); + assertEquals(401, response.getStatus()); + } + + @Test + public void test_unLock_malformedLock() throws Exception { + System.out.println("Testing unlock w/ malformedLock"); + createAndInsertIntoTable(); + String lockRef = createLockReference(); + + Response response = lock.unLock("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_getLockState() throws Exception { System.out.println("Testing get lock state"); createAndInsertIntoTable(); @@ -200,8 +324,34 @@ public class TstRestMusicLockAPI { } @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()); + } + + @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 public void test_deleteLock() throws Exception { - System.out.println("Testing get lock state"); + System.out.println("Testing delete lock"); createAndInsertIntoTable(); String lockRef = createLockReference(); @@ -211,6 +361,32 @@ public class TstRestMusicLockAPI { System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity()); assertEquals(200, response.getStatus()); } + + @Test + 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()); + } + + @Test + 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 |