diff options
Diffstat (limited to 'src/test/java')
6 files changed, 52 insertions, 245 deletions
diff --git a/src/test/java/org/onap/music/unittests/JsonLockResponseTest.java b/src/test/java/org/onap/music/unittests/JsonLockResponseTest.java deleted file mode 100644 index cd5773dc..00000000 --- a/src/test/java/org/onap/music/unittests/JsonLockResponseTest.java +++ /dev/null @@ -1,186 +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.*; -import java.util.Map; -import org.junit.Before; -import org.junit.Test; -import org.onap.music.lockingservice.MusicLockState; -import org.onap.music.lockingservice.MusicLockState.LockStatus; -import org.onap.music.main.ResultType; -import org.onap.music.response.jsonobjects.JsonLockResponse; - -public class JsonLockResponseTest { - - JsonLockResponse response = new JsonLockResponse(ResultType.SUCCESS); - - @Test - public void error1() { - Boolean result = false; - response.setError(""); - result = response.getError().equals("error1"); - assertFalse("Success",result); - } - - @Test - public void error() { - Boolean result = false; - response.setError("error1"); - result = response.getError().equals("error1"); - assertTrue("Success",result); - } - - @Test - public void lock1() { - Boolean result = false; - response.setLock(""); - result = response.getLock().equals("lock1"); - assertFalse("Success",result); - } - - @Test - public void lock() { - Boolean result = false; - response.setLock("lock1"); - result = response.getLock().equals("lock1"); - assertTrue("Success",result); - } - - @Test - public void status1() { - Boolean result = false; - response.setStatus(null); - result = response.getStatus() == ResultType.SUCCESS; - assertFalse("Success",result); - } - - @Test - public void status() { - Boolean result = false; - response.setStatus(ResultType.SUCCESS); - result = response.getStatus() == ResultType.SUCCESS; - assertTrue("Success",result); - } - - - - @Test - public void lockHolder1() { - Boolean result = false; - response.setLockHolder(""); - result = response.getLockHolder().equals("LockHolder"); - assertFalse("Success",result); - } - - @Test - public void lockHolder() { - Boolean result = false; - response.setLockHolder("LockHolder"); - result = response.getLockHolder().equals("LockHolder"); - assertTrue("Success",result); - } - - @Test - public void lockLease1() { - Boolean result = false; - response.setLockLease(""); - result = response.getLockLease().equals("lockLease"); - assertFalse("Success",result); - } - - @Test - public void lockLease() { - Boolean result = false; - response.setLockLease("lockLease"); - result = response.getLockLease().equals("lockLease"); - assertTrue("Success",result); - } - - @Test - public void lockStatus1() { - Boolean result = false; - response.setLockStatus(null); - result = response.getLockStatus() == MusicLockState.LockStatus.LOCKED; - assertFalse("Success",result); - } - - @Test - public void lockStatus() { - Boolean result = false; - response.setLockStatus(MusicLockState.LockStatus.LOCKED); - result = response.getLockStatus() == MusicLockState.LockStatus.LOCKED; - assertTrue("Success",result); - } - - @Test - public void message1() { - Boolean result = false; - response.setMessage(""); - result = response.getMessage().equals("message"); - assertFalse("Success",result); - } - - @Test - public void message() { - Boolean result = false; - response.setMessage("message"); - result = response.getMessage().equals("message"); - assertTrue("Success",result); - } - - @Test - public void map() { - Boolean result = false; - response.setMessage("message"); - response.setLockStatus(MusicLockState.LockStatus.LOCKED); - response.setLockHolder("LockHolder"); - response.setLockLease("lockLease"); - response.setStatus(ResultType.SUCCESS); - response.setLock("lock1"); - response.setError("error1"); - Map<String,Object> myMap = response.toMap(); - result = myMap.containsKey("status"); - System.out.println(response.toString()); - assertTrue("Success",result); - } - - @Test - public void map1() { - Boolean result = false; - response.setMessage(null); - response.setLockStatus(null); - response.setLockHolder(null); - response.setLockLease(null); - response.setStatus(null); - response.setLock(null); - response.setError(null); - Map<String,Object> myMap = response.toMap(); - result = myMap.containsKey("error"); - System.out.println(result); - assertFalse("Success",result); - } - - - - -} diff --git a/src/test/java/org/onap/music/unittests/JsonResponseTest.java b/src/test/java/org/onap/music/unittests/JsonResponseTest.java index 55e5965e..9da10638 100644 --- a/src/test/java/org/onap/music/unittests/JsonResponseTest.java +++ b/src/test/java/org/onap/music/unittests/JsonResponseTest.java @@ -25,6 +25,7 @@ package org.onap.music.unittests; import static org.junit.Assert.*; import java.util.Map; import org.junit.Test; +import org.onap.music.main.ResultType; import org.onap.music.response.jsonobjects.JsonResponse; public class JsonResponseTest { @@ -33,28 +34,22 @@ public class JsonResponseTest { @Test public void testJsonResponseBooleanStringString() { - result = new JsonResponse(true,"error","version"); + result = new JsonResponse(ResultType.SUCCESS).setError("error").setMusicVersion("version"); assertEquals("error",result.getError()); } @Test - public void testJsonResponse() { - result = new JsonResponse(); - assertFalse(result.getStatus()); - } - - @Test public void testStatus() { - result = new JsonResponse(); - result.setStatus(true); - assertTrue(result.getStatus()); - result = new JsonResponse(false,"error","version"); - assertFalse(result.getStatus()); + result = new JsonResponse(ResultType.SUCCESS); + result.setStatus(ResultType.SUCCESS); + assertEquals(ResultType.SUCCESS, result.getStatus()); + result = new JsonResponse(ResultType.FAILURE).setError("error").setMusicVersion("version"); + assertEquals(ResultType.FAILURE, result.getStatus()); } @Test public void testError() { - result = new JsonResponse(); + result = new JsonResponse(ResultType.FAILURE); result.setError("error"); assertTrue(result.getError().equals("error")); result.setError(""); @@ -63,21 +58,26 @@ public class JsonResponseTest { @Test public void testVersion() { - result = new JsonResponse(); - result.setVersion("version"); - assertTrue(result.getVersion().equals("version")); - result.setVersion(""); - assertFalse(result.getVersion().equals("version")); + result = new JsonResponse(ResultType.SUCCESS); + result.setMusicVersion("version"); + assertTrue(result.getMusicVersion().equals("version")); + result.setMusicVersion(""); + assertFalse(result.getMusicVersion().equals("version")); } @Test public void testToMap() { - result = new JsonResponse(true,"error","version"); + result = new JsonResponse(ResultType.SUCCESS).setError("error").setMusicVersion("1.0"); Map<String,Object> myMap = result.toMap(); assertTrue(myMap.containsKey("status")); - result = new JsonResponse(false,"",""); + assertEquals(ResultType.SUCCESS, myMap.get("status")); + assertEquals("error", myMap.get("error")); + assertEquals("1.0", myMap.get("version")); + + result = new JsonResponse(ResultType.FAILURE); myMap = result.toMap(); assertTrue(myMap.containsKey("status")); + assertEquals(ResultType.FAILURE, myMap.get("status")); } } diff --git a/src/test/java/org/onap/music/unittests/MusicUtilTest.java b/src/test/java/org/onap/music/unittests/MusicUtilTest.java index 47edc1e3..b117c330 100644 --- a/src/test/java/org/onap/music/unittests/MusicUtilTest.java +++ b/src/test/java/org/onap/music/unittests/MusicUtilTest.java @@ -204,14 +204,4 @@ public class MusicUtilTest { assertTrue(result.contains("value")); } - @Test - public void testSetErrorResponse() { - Map<String,Object> myMap = new HashMap<>(); - myMap.put("name","tom"); - Map<String,HashMap<String,Object>> result = MusicUtil.setErrorResponse(new MusicServiceException("This is the error")); - Map<String,Object> testMap = (Map<String,Object>) result.get("result"); - Map<String,Object> error = (Map<String,Object>) testMap.get("error"); - assertTrue(error.containsKey("error-description")); - } - } diff --git a/src/test/java/org/onap/music/unittests/TestMusicCore.java b/src/test/java/org/onap/music/unittests/TestMusicCore.java index c571085a..876c78b1 100644 --- a/src/test/java/org/onap/music/unittests/TestMusicCore.java +++ b/src/test/java/org/onap/music/unittests/TestMusicCore.java @@ -24,6 +24,8 @@ package org.onap.music.unittests; import static org.junit.Assert.*; import static org.onap.music.main.MusicCore.mDstoreHandle; import static org.onap.music.main.MusicCore.mLockHandle; + +import org.apache.zookeeper.KeeperException.NoNodeException; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -97,7 +99,7 @@ public class TestMusicCore { } @Test - public void testAcquireLockifisMyTurnTrue() { + public void testAcquireLockifisMyTurnTrue() throws MusicLockingException { Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true); ReturnType lock = MusicCore.acquireLock("ks1.tn1", "id1"); assertEquals(lock.getResult(), ResultType.SUCCESS); @@ -105,7 +107,7 @@ public class TestMusicCore { } @Test - public void testAcquireLockifisMyTurnFalse() { + public void testAcquireLockifisMyTurnFalse() throws MusicLockingException { Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false); ReturnType lock = MusicCore.acquireLock("ks1.ts1", "id1"); assertEquals(lock.getResult(), ResultType.FAILURE); @@ -113,7 +115,7 @@ public class TestMusicCore { } @Test - public void testAcquireLockifisMyTurnTrueandIsTableOrKeySpaceLockTrue() { + public void testAcquireLockifisMyTurnTrueandIsTableOrKeySpaceLockTrue() throws MusicLockingException { Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true); ReturnType lock = MusicCore.acquireLock("ks1.tn1", "id1"); assertEquals(lock.getResult(), ResultType.SUCCESS); @@ -143,7 +145,7 @@ public class TestMusicCore { } @Test - public void testAcquireLockifLockRefDoesntExist() { + public void testAcquireLockifLockRefDoesntExist() throws MusicLockingException { Mockito.when(mLockHandle.lockIdExists("bs1")).thenReturn(false); ReturnType lock = MusicCore.acquireLock("ks1.ts1", "bs1"); assertEquals(lock.getResult(), ResultType.FAILURE); @@ -230,14 +232,14 @@ public class TestMusicCore { } @Test - public void testDestroyLockRef() { + public void testDestroyLockRef() throws NoNodeException { Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1"); MusicCore.destroyLockRef("id1"); Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1"); } @Test - public void testreleaseLockwithvoluntaryReleaseTrue() { + public void testreleaseLockwithvoluntaryReleaseTrue() throws NoNodeException { MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2"); Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1"); MusicLockState musicLockState1 = MusicCore.releaseLock("id1", true); @@ -246,7 +248,7 @@ public class TestMusicCore { } @Test - public void testreleaseLockwithvoluntaryReleaseFalse() { + public void testreleaseLockwithvoluntaryReleaseFalse() throws NoNodeException { MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2"); Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1"); MusicLockState musicLockState1 = MusicCore.releaseLock("id1", false); @@ -355,8 +357,8 @@ public class TestMusicCore { session = Mockito.mock(Session.class); Mockito.when(mDstoreHandle.getSession()).thenReturn(session); Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "consistency")).thenReturn(true); - Boolean result = MusicCore.nonKeyRelatedPut(preparedQueryObject, "consistency"); - assertTrue(result); + ResultType result = MusicCore.nonKeyRelatedPut(preparedQueryObject, "consistency"); + assertEquals(ResultType.SUCCESS, result); Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "consistency"); } diff --git a/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java b/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java index 823badaa..d327d0f0 100644 --- a/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java +++ b/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java @@ -78,14 +78,14 @@ public class TestMusicCoreIntegration { @Test public void Test1_SetUp() throws MusicServiceException, MusicQueryException { MusicCore.mLockHandle = new MusicLockingService(); - boolean result = false; + ResultType result = ResultType.FAILURE; testObject = new PreparedQueryObject(); testObject.appendQueryString(CassandraCQL.createKeySpace); MusicCore.eventualPut(testObject); testObject = new PreparedQueryObject(); testObject.appendQueryString(CassandraCQL.createTableEmployees); result = MusicCore.nonKeyRelatedPut(testObject, MusicUtil.EVENTUAL); - assertTrue(result); + assertEquals(ResultType.SUCCESS, result); } @Test diff --git a/src/test/java/org/onap/music/unittests/TestRestMusicData.java b/src/test/java/org/onap/music/unittests/TestRestMusicData.java index e4d06f70..435b196c 100644 --- a/src/test/java/org/onap/music/unittests/TestRestMusicData.java +++ b/src/test/java/org/onap/music/unittests/TestRestMusicData.java @@ -49,6 +49,7 @@ import org.onap.music.lockingservice.MusicLockingService; import org.onap.music.main.CachingUtil; import org.onap.music.main.MusicCore; import org.onap.music.main.MusicUtil; +import org.onap.music.main.ResultType; import org.onap.music.rest.RestMusicAdminAPI; import org.onap.music.rest.RestMusicDataAPI; import org.onap.music.rest.RestMusicLocksAPI; @@ -181,7 +182,7 @@ public class TestRestMusicData { Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Map<String, Object> resultMap = data.createKeySpace("1", "1", "1", null, appName, userId, password, jsonKeyspace, keyspaceName, http); - assertEquals(uuid.toString(), resultMap.get("aid")); + assertEquals(ResultType.SUCCESS, resultMap.get("status")); } @Test @@ -201,7 +202,7 @@ public class TestRestMusicData { "TestUser1", password, jsonKeyspace, keyspaceName, http); System.out.println("#######status is " + resultMap.get("Exception")); assertEquals("Couldn't create keyspace. Please make sure all the information is correct.", - resultMap.get("Exception")); + resultMap.get("error")); } @Test @@ -223,7 +224,7 @@ public class TestRestMusicData { Map<String, Object> resultMap = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password, jsonTable, keyspaceName, tableName, http); - assertEquals("SUCCESS", resultMap.get("status")); + assertEquals(ResultType.SUCCESS, resultMap.get("status")); } @Test @@ -242,7 +243,7 @@ public class TestRestMusicData { Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Map<String, Object> resultMap = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password, jsonInsert, keyspaceName, tableName, http); - assertEquals("Success", resultMap.get("result")); + assertEquals(ResultType.SUCCESS, resultMap.get("status")); } @Test @@ -262,7 +263,7 @@ public class TestRestMusicData { Map<String, Object> resultMap = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password, jsonInsert, keyspaceName, tableName, http); - assertEquals("Success", resultMap.get("result")); + assertEquals(ResultType.SUCCESS, resultMap.get("status")); } @Test @@ -282,7 +283,7 @@ public class TestRestMusicData { Mockito.when(info.getQueryParameters()).thenReturn(row); Map<String, Object> resultMap = data.updateTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password, jsonUpdate, keyspaceName, tableName, info, http); - assertEquals("Success", resultMap.get("result")); + assertEquals(ResultType.SUCCESS, resultMap.get("status")); } @Test @@ -295,9 +296,9 @@ public class TestRestMusicData { jsonSelect.setConsistencyInfo(consistencyInfo); Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Mockito.when(info.getQueryParameters()).thenReturn(row); - Map<String, HashMap<String, Object>> resultMap = data.select("1", "1", "1", + Map<String, Object> resultMap = data.select("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password, keyspaceName, tableName, info, http); - assertEquals("2500", resultMap.get("row 0").get("emp_salary").toString()); + assertEquals("2500", ((HashMap<String,HashMap<String,Object>>) resultMap.get("result")).get("row 0").get("emp_salary").toString()); } @Test @@ -310,10 +311,10 @@ public class TestRestMusicData { jsonInsert.setConsistencyInfo(consistencyInfo); Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Mockito.when(info.getQueryParameters()).thenReturn(row); - Map<String, HashMap<String, Object>> resultMap = data.selectCritical("1", "1", "1", + Map<String, Object> resultMap = data.selectCritical("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password, jsonInsert, keyspaceName, tableName, info, http); - assertEquals("2500", resultMap.get("row 0").get("emp_salary").toString()); + assertEquals("2500", ((HashMap<String,HashMap<String,Object>>) resultMap.get("result")).get("row 0").get("emp_salary").toString()); } @Test @@ -329,7 +330,7 @@ public class TestRestMusicData { Map<String, Object> resultMap = data.deleteFromTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password, jsonDelete, keyspaceName, tableName, info, http); - assertEquals("Success", resultMap.get("result")); + assertEquals(ResultType.SUCCESS, resultMap.get("status")); } @Test @@ -342,7 +343,7 @@ public class TestRestMusicData { Map<String, Object> resultMap = data.dropTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password, jsonTable, keyspaceName, tableName, http); - assertEquals("SUCCESS", resultMap.get("status")); + assertEquals(ResultType.SUCCESS, resultMap.get("status")); } @Test @@ -360,7 +361,7 @@ public class TestRestMusicData { Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Map<String, Object> resultMap = data.dropKeySpace("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName, userId, password, jsonKeyspace, keyspaceName, http); - assertEquals("SUCCESS", resultMap.get("status")); + assertEquals(ResultType.SUCCESS, resultMap.get("status")); } @Test @@ -417,34 +418,34 @@ public class TestRestMusicData { @SuppressWarnings("unchecked") Map<String, Object> resultMap1 = (Map<String, Object>) resultMap.get("lock"); lockId = (String) resultMap1.get("lock"); - assertEquals("SUCCESS", resultMap.get("status").toString()); + assertEquals(ResultType.SUCCESS, resultMap.get("status")); } @Test public void Test4_accquireLock() throws Exception { Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Map<String, Object> resultMap = lock.accquireLock(lockId, uuid.toString(), appName, null, null, http); - assertEquals("SUCCESS", resultMap.get("status").toString()); + assertEquals(ResultType.SUCCESS, resultMap.get("status")); } @Test public void Test5_currentLockHolder() throws Exception { Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Map<String, Object> resultMap = lock.currentLockHolder(lockName, uuid.toString(), appName, null, null, http); - assertEquals("SUCCESS", resultMap.get("status").toString()); + assertEquals(ResultType.SUCCESS, resultMap.get("status")); } @Test public void Test7_unLock() throws Exception { Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Map<String, Object> resultMap = lock.unLock(lockId, uuid.toString(), appName, null, null, http); - assertEquals("SUCCESS", resultMap.get("status").toString()); + assertEquals(ResultType.SUCCESS, resultMap.get("status")); } @Test public void Test8_delete() throws Exception { Mockito.doNothing().when(http).addHeader(xLatestVersion, MusicUtil.getVersion()); Map<String, Object> resultMap = lock.deleteLock(lockName, uuid.toString(), appName, null, null, http); - assertEquals("SUCCESS", resultMap.get("status").toString()); + assertEquals(ResultType.SUCCESS, resultMap.get("status")); } }
\ No newline at end of file |