aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrendan Tschaen <ctschaen@att.com>2020-01-30 20:54:49 +0000
committerGerrit Code Review <gerrit@onap.org>2020-01-30 20:54:49 +0000
commit712f0dddc791f9ef8283fb40b5b5f326bc4ea0d9 (patch)
treeddc25cbe84f375b5b6a04d74f0bd75becde73775
parent3e7717442eceb670bfa69ddb27c9abe68e99a920 (diff)
parent950bed75318edc958d763eaee1d0c7a493e3dbd2 (diff)
Merge "JUnit test case coverage for Condition.java, JsonLock.java, MusicLockState.java, MusicCore.java Issue-ID: MUSIC-521"
-rw-r--r--music-core/src/main/java/org/onap/music/datastore/Condition.java16
-rw-r--r--music-core/src/test/java/org/onap/music/datastore/ConditionTest.java61
-rw-r--r--music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonLockTest.java50
-rw-r--r--music-core/src/test/java/org/onap/music/lockingservice/cassandra/MusicLockStateTest.java86
-rw-r--r--music-core/src/test/java/org/onap/music/main/MusicCoreTest.java391
-rw-r--r--music-rest/src/test/java/org/onap/music/conductor/conditionals/JsonConditionalTest.java82
-rw-r--r--music-rest/src/test/java/org/onap/music/conductor/conditionals/UpdateDataObjectTest.java98
7 files changed, 781 insertions, 3 deletions
diff --git a/music-core/src/main/java/org/onap/music/datastore/Condition.java b/music-core/src/main/java/org/onap/music/datastore/Condition.java
index 6587748e..c17d9c07 100644
--- a/music-core/src/main/java/org/onap/music/datastore/Condition.java
+++ b/music-core/src/main/java/org/onap/music/datastore/Condition.java
@@ -23,7 +23,7 @@
package org.onap.music.datastore;
import java.util.Map;
-
+import org.onap.music.exceptions.MusicServiceException;
import org.onap.music.main.MusicCore;
import com.datastax.driver.core.ResultSet;
@@ -40,7 +40,7 @@ public class Condition {
public boolean testCondition() throws Exception {
// first generate the row
- ResultSet results = MusicCore.quorumGet(selectQueryForTheRow);
+ ResultSet results = quorumGet(selectQueryForTheRow);
Row row = null;
if(results != null) {
row = results.one();
@@ -48,6 +48,16 @@ public class Condition {
if(row == null) {
throw new Exception(" No data found to update");
}
- return MusicDataStoreHandle.getDSHandle().doesRowSatisfyCondition(row, conditions);
+ return getDSHandle().doesRowSatisfyCondition(row, conditions);
+ }
+
+ /* For JUnit testing only */
+ public ResultSet quorumGet(PreparedQueryObject selectQueryForTheRow) {
+ return MusicCore.quorumGet(selectQueryForTheRow);
+ }
+
+ /* For JUnit testing only */
+ public MusicDataStore getDSHandle() throws MusicServiceException {
+ return MusicDataStoreHandle.getDSHandle();
}
} \ No newline at end of file
diff --git a/music-core/src/test/java/org/onap/music/datastore/ConditionTest.java b/music-core/src/test/java/org/onap/music/datastore/ConditionTest.java
new file mode 100644
index 00000000..2aac62af
--- /dev/null
+++ b/music-core/src/test/java/org/onap/music/datastore/ConditionTest.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * ============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.datastore;
+
+import org.onap.music.datastore.Condition;
+import org.onap.music.datastore.PreparedQueryObject;
+import org.onap.music.exceptions.MusicServiceException;
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.Row;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.spy;
+import java.util.Map;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.Spy;
+
+public class ConditionTest {
+
+ @Spy
+ private Condition condition;
+ private Map<String, Object> conditions;
+ private PreparedQueryObject selectQueryForTheRow;
+
+ @Before
+ public void setup() {
+ conditions = Mockito.mock(Map.class);
+ selectQueryForTheRow = Mockito.mock(PreparedQueryObject.class);
+ condition = spy(new Condition(conditions, selectQueryForTheRow));
+ }
+
+ @Test
+ public void testCondition() throws Exception {
+ ResultSet rs = Mockito.mock(ResultSet.class);
+ Row row = Mockito.mock(Row.class);
+ MusicDataStore dsHandle = Mockito.mock(MusicDataStore.class);
+ Mockito.when(rs.one()).thenReturn(row);
+ Mockito.doReturn(rs).when(condition).quorumGet(Mockito.any());
+ boolean result = false;
+ Mockito.when(dsHandle.doesRowSatisfyCondition(Mockito.any(), Mockito.any())).thenReturn(true);
+ Mockito.doReturn(dsHandle).when(condition).getDSHandle();
+ result = condition.testCondition();
+ assertEquals(true, result);
+ }
+}
diff --git a/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonLockTest.java b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonLockTest.java
new file mode 100644
index 00000000..75db75e5
--- /dev/null
+++ b/music-core/src/test/java/org/onap/music/datastore/jsonobjects/JsonLockTest.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * ============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.datastore.jsonobjects;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.music.lockingservice.cassandra.LockType;
+
+public class JsonLockTest {
+
+ JsonLock jsonLock;
+
+ @Before
+ public void setup() {
+ jsonLock = new JsonLock();
+ }
+
+ @Test
+ public void testSetLockType() {
+ jsonLock.setLockType(LockType.READ);
+ assertEquals(LockType.READ, jsonLock.getLocktype());
+
+ jsonLock.setLockType(LockType.WRITE);
+ assertEquals(LockType.WRITE, jsonLock.getLocktype());
+
+ jsonLock.setLockType(LockType.PROMOTING);
+ assertEquals(LockType.PROMOTING, jsonLock.getLocktype());
+ }
+}
diff --git a/music-core/src/test/java/org/onap/music/lockingservice/cassandra/MusicLockStateTest.java b/music-core/src/test/java/org/onap/music/lockingservice/cassandra/MusicLockStateTest.java
new file mode 100644
index 00000000..e5b655bd
--- /dev/null
+++ b/music-core/src/test/java/org/onap/music/lockingservice/cassandra/MusicLockStateTest.java
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * ============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.lockingservice.cassandra;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.music.lockingservice.cassandra.MusicLockState.LockStatus;
+
+public class MusicLockStateTest {
+
+ MusicLockState musicLockState;
+
+ @Before
+ public void setup() {
+ musicLockState = new MusicLockState(LockStatus.LOCKED, "", true);
+ }
+
+ @Test
+ public void testGetLeasePeriod() {
+ musicLockState.setLeasePeriod(200L);
+ assertEquals(200L, musicLockState.getLeasePeriod());
+ }
+
+ @Test
+ public void testIsNeedToSyncQuorum() {
+ assertEquals(true, musicLockState.isNeedToSyncQuorum());
+ }
+
+ @Test
+ public void testGetLeaseStartTime() {
+ musicLockState.setLeaseStartTime(200L);
+ assertEquals(200L, musicLockState.getLeaseStartTime());
+ }
+
+ @Test
+ public void testGetLockStatus() {
+ musicLockState.setLockStatus(LockStatus.LOCKED);
+ assertEquals(LockStatus.LOCKED, musicLockState.getLockStatus());
+ }
+
+ @Test
+ public void testGetLockHolder() {
+ musicLockState.setLockHolder("lockHolder");
+ assertEquals("lockHolder", musicLockState.getLockHolder());
+ }
+
+ @Test
+ public void testGetErrorMessage() {
+ MusicLockState musicLockState2 = new MusicLockState("This is error message");
+ assertEquals("This is error message", musicLockState2.getErrorMessage());
+ }
+
+ @Test
+ public void testSerialize() {
+ byte[] serializedBytes = musicLockState.serialize();
+ MusicLockState musicLockState3 = musicLockState.deSerialize(serializedBytes);
+ assertEquals(musicLockState.getLeasePeriod(),musicLockState3.getLeasePeriod());
+ assertEquals(musicLockState.isNeedToSyncQuorum(),musicLockState3.isNeedToSyncQuorum());
+ assertEquals(musicLockState.getLeaseStartTime(),musicLockState3.getLeaseStartTime());
+ assertEquals(musicLockState.getLockStatus(),musicLockState3.getLockStatus());
+ assertEquals(musicLockState.getLockHolder(),musicLockState3.getLockHolder());
+ assertEquals(musicLockState.getErrorMessage(),musicLockState3.getErrorMessage());
+ }
+
+}
diff --git a/music-core/src/test/java/org/onap/music/main/MusicCoreTest.java b/music-core/src/test/java/org/onap/music/main/MusicCoreTest.java
new file mode 100644
index 00000000..4714778b
--- /dev/null
+++ b/music-core/src/test/java/org/onap/music/main/MusicCoreTest.java
@@ -0,0 +1,391 @@
+/*******************************************************************************
+ * ============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.main;
+
+import static org.junit.Assert.assertEquals;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.ws.rs.core.MultivaluedMap;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.internal.util.reflection.FieldSetter;
+import org.onap.music.datastore.Condition;
+import org.onap.music.datastore.PreparedQueryObject;
+import org.onap.music.datastore.jsonobjects.JsonDelete;
+import org.onap.music.datastore.jsonobjects.JsonIndex;
+import org.onap.music.datastore.jsonobjects.JsonInsert;
+import org.onap.music.datastore.jsonobjects.JsonKeySpace;
+import org.onap.music.datastore.jsonobjects.JsonSelect;
+import org.onap.music.datastore.jsonobjects.JsonTable;
+import org.onap.music.datastore.jsonobjects.JsonUpdate;
+import org.onap.music.exceptions.MusicLockingException;
+import org.onap.music.exceptions.MusicQueryException;
+import org.onap.music.exceptions.MusicServiceException;
+import org.onap.music.lockingservice.cassandra.CassaLockStore;
+import org.onap.music.lockingservice.cassandra.LockType;
+import org.onap.music.lockingservice.cassandra.MusicLockState;
+import org.onap.music.service.MusicCoreService;
+import com.datastax.driver.core.ResultSet;
+
+public class MusicCoreTest {
+
+ MusicCore mCore;
+ MusicCoreService musicCore;
+ CassaLockStore mLockHandle;
+
+ @Before
+ public void setup() {
+ mCore = new MusicCore();
+ musicCore = Mockito.mock(MusicCoreService.class);
+ mLockHandle = Mockito.mock(CassaLockStore.class);
+ try {
+ FieldSetter.setField(mCore, mCore.getClass().getDeclaredField("musicCore"), musicCore);
+ } catch (NoSuchFieldException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (SecurityException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testAcquireLock() throws MusicLockingException, MusicQueryException, MusicServiceException {
+ ReturnType returnType = Mockito.mock(ReturnType.class);
+ ReturnType result = null;
+ Mockito.when(musicCore.acquireLock(Mockito.any(), Mockito.any())).thenReturn(returnType);
+ result = MusicCore.acquireLock("key1", "lockid1");
+ assertEquals(returnType, result);
+ }
+
+ @Test
+ public void testacquireLockWithLease() throws MusicLockingException, MusicQueryException, MusicServiceException {
+ ReturnType returnType = Mockito.mock(ReturnType.class);
+ ReturnType result = null;
+ Mockito.when(musicCore.acquireLockWithLease(Mockito.anyString(), Mockito.anyString(), Mockito.anyLong()))
+ .thenReturn(returnType);
+ result = MusicCore.acquireLockWithLease("key1", "lockid1", 100L);
+ assertEquals(returnType, result);
+ }
+
+ @Test
+ public void testCreateLockReferenceAtomic() throws MusicLockingException {
+ String result = null;
+ Mockito.when(musicCore.createLockReferenceAtomic(Mockito.any())).thenReturn("lockreference1");
+ result = MusicCore.createLockReferenceAtomic("key2");
+ assertEquals("lockreference1", result);
+ }
+
+ @Test
+ public void testCreateLockReference() throws MusicLockingException {
+ String result = null;
+ Mockito.when(musicCore.createLockReference(Mockito.any(), Mockito.any())).thenReturn("lockreference2");
+ result = MusicCore.createLockReference("key3", "owner3");
+ assertEquals("lockreference2", result);
+ }
+
+ @Test
+ public void testCreateLockReferenceAtomic2() throws MusicLockingException {
+ String result = null;
+ Mockito.when(musicCore.createLockReferenceAtomic(Mockito.any(), Mockito.any())).thenReturn("lockreference3");
+ result = MusicCore.createLockReferenceAtomic("key4", LockType.READ);
+ assertEquals("lockreference3", result);
+ }
+
+ @Test
+ public void testCreateLockReference2() throws MusicLockingException {
+ String result = null;
+ Mockito.when(musicCore.createLockReference(Mockito.any(), Mockito.any(), Mockito.any()))
+ .thenReturn("lockreference4");
+ result = MusicCore.createLockReference("key4", LockType.READ, "owner4");
+ assertEquals("lockreference4", result);
+ }
+
+ @Test
+ public void testCreateTable() throws MusicServiceException {
+ ResultType resultType = Mockito.mock(ResultType.class);
+ ResultType result = null;
+ Mockito.when(musicCore.createTable(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()))
+ .thenReturn(resultType);
+ result = MusicCore.createTable("keyspace1", "table1", new PreparedQueryObject(), "consistency");
+ assertEquals(resultType, result);
+ }
+
+ @Test
+ public void testQuorumGet() {
+ ResultSet rs = Mockito.mock(ResultSet.class);
+ Mockito.when(musicCore.quorumGet(Mockito.any())).thenReturn(rs);
+ assertEquals(rs, MusicCore.quorumGet(new PreparedQueryObject()));
+ }
+
+ @Test
+ public void testWhoseTurnIsIt() {
+ Mockito.when(musicCore.whoseTurnIsIt(Mockito.any())).thenReturn("turn");
+ assertEquals("turn", MusicCore.whoseTurnIsIt("key5"));
+ }
+
+ @Test
+ public void testGetCurrentLockHolders() {
+ List<String> result = Mockito.mock(List.class);
+ Mockito.when(musicCore.getCurrentLockHolders(Mockito.any())).thenReturn(result);
+ assertEquals(result, MusicCore.getCurrentLockHolders("key6"));
+ }
+
+ @Test
+ public void testPromoteLock() throws MusicLockingException {
+ ReturnType returnType = Mockito.mock(ReturnType.class);
+ ReturnType result = null;
+ Mockito.when(musicCore.promoteLock(Mockito.any())).thenReturn(returnType);
+ result = MusicCore.promoteLock("lockid2");
+ assertEquals(returnType, result);
+ }
+
+ @Test
+ public void testEventualPut() {
+ ReturnType returnType = Mockito.mock(ReturnType.class);
+ Mockito.when(musicCore.eventualPut(Mockito.any())).thenReturn(returnType);
+ assertEquals(returnType, MusicCore.eventualPut(new PreparedQueryObject()));
+ }
+
+ @Test
+ public void testEventualPut_nb() {
+ ReturnType returnType = Mockito.mock(ReturnType.class);
+ Mockito.when(musicCore.eventualPut_nb(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()))
+ .thenReturn(returnType);
+ assertEquals(returnType,
+ MusicCore.eventualPut_nb(new PreparedQueryObject(), "keyspace2", "table2", "primarykey1"));
+ }
+
+ @Test
+ public void testCriticalPut() {
+ ReturnType returnType = Mockito.mock(ReturnType.class);
+ Mockito.when(musicCore.criticalPut(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(),
+ Mockito.any())).thenReturn(returnType);
+ assertEquals(returnType, MusicCore.criticalPut("keyspace3", "table3", "primarykey2", new PreparedQueryObject(),
+ "lockreference2", new Condition(new HashMap(), new PreparedQueryObject())));
+ }
+
+ @Test
+ public void testNonKeyRelatedPut() throws MusicServiceException, MusicQueryException {
+ ResultType resultType = Mockito.mock(ResultType.class);
+ ResultType result = null;
+ Mockito.when(musicCore.nonKeyRelatedPut(Mockito.any(), Mockito.any())).thenReturn(resultType);
+ result = MusicCore.nonKeyRelatedPut(new PreparedQueryObject(), "consistency2");
+ assertEquals(resultType, result);
+ }
+
+ @Test
+ public void testGet() throws MusicServiceException {
+ ResultSet rs = Mockito.mock(ResultSet.class);
+ ResultSet result = null;
+ Mockito.when(musicCore.get(Mockito.any())).thenReturn(rs);
+ result = MusicCore.get(new PreparedQueryObject());
+ assertEquals(rs, result);
+ }
+
+ @Test
+ public void testCriticalGet() throws MusicServiceException {
+ ResultSet rs = Mockito.mock(ResultSet.class);
+ ResultSet result = null;
+ Mockito.when(musicCore.criticalGet(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()))
+ .thenReturn(rs);
+ result = MusicCore.criticalGet("keyspace4", "table4", "primarykey3", new PreparedQueryObject(),
+ "lockreference3");
+ assertEquals(rs, result);
+ }
+
+ @Test
+ public void testAtomicPut() throws MusicLockingException, MusicQueryException, MusicServiceException {
+ ReturnType returnType = Mockito.mock(ReturnType.class);
+ ReturnType result = null;
+ Mockito.when(musicCore.atomicPut(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()))
+ .thenReturn(returnType);
+ result = MusicCore.atomicPut("keyspace5", "table5", "primarykey4", new PreparedQueryObject(),
+ new Condition(new HashMap(), new PreparedQueryObject()));
+ assertEquals(returnType, result);
+ }
+
+ @Test
+ public void testAtomicGet() throws MusicServiceException, MusicLockingException, MusicQueryException {
+ ResultSet rs = Mockito.mock(ResultSet.class);
+ ResultSet result = null;
+ Mockito.when(musicCore.atomicGet(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(rs);
+ result = MusicCore.atomicGet("keyspace5", "table5", "primarykey4", new PreparedQueryObject());
+ assertEquals(rs, result);
+ }
+
+ @Test
+ public void testGetLockQueue() throws MusicServiceException, MusicQueryException, MusicLockingException {
+ List<String> result = Mockito.mock(List.class);
+ List<String> rst = null;
+ Mockito.when(musicCore.getLockQueue(Mockito.any())).thenReturn(result);
+ rst = MusicCore.getLockQueue("key5");
+ assertEquals(result, rst);
+ }
+
+ @Test
+ public void testGetLockQueueSize() throws MusicServiceException, MusicQueryException, MusicLockingException {
+ long result = 0L;
+ Mockito.when(musicCore.getLockQueueSize(Mockito.any())).thenReturn(100L);
+ result = MusicCore.getLockQueueSize("key6");
+ assertEquals(100L, result);
+ }
+
+ @Test
+ public void testatomicPutWithDeleteLock() throws MusicLockingException {
+ ReturnType returnType = Mockito.mock(ReturnType.class);
+ ReturnType result = null;
+ Mockito.when(musicCore.atomicPutWithDeleteLock(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(),
+ Mockito.any())).thenReturn(returnType);
+ result = MusicCore.atomicPutWithDeleteLock("keyspace5", "table5", "primarykey4", new PreparedQueryObject(),
+ new Condition(new HashMap(), new PreparedQueryObject()));
+ assertEquals(returnType, result);
+ }
+
+ @Test
+ public void testAtomicGetWithDeleteLock() throws MusicServiceException, MusicLockingException {
+ ResultSet rs = Mockito.mock(ResultSet.class);
+ ResultSet result = null;
+ Mockito.when(musicCore.atomicGetWithDeleteLock(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()))
+ .thenReturn(rs);
+ result = MusicCore.atomicGetWithDeleteLock("keyspace5", "table5", "primarykey4", new PreparedQueryObject());
+ assertEquals(rs, result);
+ }
+
+ @Test
+ public void testValidateLock() {
+ Map<String, Object> map = Mockito.mock(Map.class);
+ Mockito.when(musicCore.validateLock(Mockito.any())).thenReturn(map);
+ assertEquals(map, MusicCore.validateLock("lockname"));
+ }
+
+ @Test
+ public void testReleaseLock() throws MusicLockingException {
+ MusicLockState musicLockState = Mockito.mock(MusicLockState.class);
+ MusicLockState result = null;
+ Mockito.when(musicCore.releaseLock(Mockito.anyString(), Mockito.anyBoolean())).thenReturn(musicLockState);
+ result = MusicCore.releaseLock("lockid", true);
+ assertEquals(musicLockState, result);
+ }
+
+ @Test
+ public void testReleaseAllLocksForOwner() throws MusicLockingException, MusicServiceException, MusicQueryException {
+ List<String> result = Mockito.mock(List.class);
+ List<String> rst = null;
+ Mockito.when(musicCore.releaseAllLocksForOwner(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(result);
+ rst = MusicCore.releaseAllLocksForOwner("owner2", "keyspace6", "table6");
+ assertEquals(result, rst);
+ }
+
+ @Test
+ public void testCreateKeyspace() throws MusicServiceException, MusicQueryException {
+ ResultType resultType = Mockito.mock(ResultType.class);
+ ResultType result = null;
+ Mockito.when(musicCore.createKeyspace(Mockito.any(), Mockito.any())).thenReturn(resultType);
+ result = MusicCore.createKeyspace(new JsonKeySpace(), "consistency3");
+ assertEquals(resultType, result);
+ }
+
+ @Test
+ public void testDropKeyspace() throws MusicServiceException, MusicQueryException {
+ ResultType resultType = Mockito.mock(ResultType.class);
+ ResultType result = null;
+ Mockito.when(musicCore.dropKeyspace(Mockito.any(), Mockito.any())).thenReturn(resultType);
+ result = MusicCore.dropKeyspace(new JsonKeySpace(), "consistency4");
+ assertEquals(resultType, result);
+ }
+
+ @Test
+ public void testCreateTable2() throws MusicServiceException, MusicQueryException {
+ ResultType resultType = Mockito.mock(ResultType.class);
+ ResultType result = null;
+ Mockito.when(musicCore.createTable(Mockito.any(), Mockito.any())).thenReturn(resultType);
+ result = MusicCore.createTable(new JsonTable(), "consistency5");
+ assertEquals(resultType, result);
+ }
+
+ @Test
+ public void testDropTable() throws MusicServiceException, MusicQueryException {
+ ResultType resultType = Mockito.mock(ResultType.class);
+ ResultType result = null;
+ Mockito.when(musicCore.dropTable(Mockito.any(), Mockito.any())).thenReturn(resultType);
+ result = MusicCore.dropTable(new JsonTable(), "consistency5");
+ assertEquals(resultType, result);
+ }
+
+ @Test
+ public void testCreateIndex() throws MusicServiceException, MusicQueryException {
+ ResultType resultType = Mockito.mock(ResultType.class);
+ ResultType result = null;
+ Mockito.when(musicCore.createIndex(Mockito.any(), Mockito.any())).thenReturn(resultType);
+ result = MusicCore.createIndex(new JsonIndex("indexName", "keyspace7", "table7", "field"), "consistency6");
+ assertEquals(resultType, result);
+ }
+
+ @Test
+ public void testSelect() throws MusicServiceException, MusicQueryException {
+ ResultSet rs = Mockito.mock(ResultSet.class);
+ ResultSet result = null;
+ Mockito.when(musicCore.select(Mockito.any(), Mockito.any())).thenReturn(rs);
+ MultivaluedMap<String, String> map = Mockito.mock(MultivaluedMap.class);
+ result = MusicCore.select(new JsonSelect(), map);
+ assertEquals(rs, result);
+ }
+
+ @Test
+ public void testSelectCritical() throws MusicLockingException, MusicQueryException, MusicServiceException {
+ ResultSet rs = Mockito.mock(ResultSet.class);
+ ResultSet result = null;
+ Mockito.when(musicCore.selectCritical(Mockito.any(), Mockito.any())).thenReturn(rs);
+ MultivaluedMap<String, String> map = Mockito.mock(MultivaluedMap.class);
+ result = MusicCore.selectCritical(new JsonInsert(), map);
+ assertEquals(rs, result);
+ }
+
+ @Test
+ public void testInsertIntoTable() throws MusicLockingException, MusicQueryException, MusicServiceException {
+ ReturnType returnType = Mockito.mock(ReturnType.class);
+ ReturnType result = null;
+ Mockito.when(musicCore.insertIntoTable(Mockito.any())).thenReturn(returnType);
+ result = MusicCore.insertIntoTable(new JsonInsert());
+ assertEquals(returnType, result);
+ }
+
+ @Test
+ public void testUpdateTable() throws MusicLockingException, MusicQueryException, MusicServiceException {
+ ReturnType returnType = Mockito.mock(ReturnType.class);
+ ReturnType result = null;
+ Mockito.when(musicCore.updateTable(Mockito.any(), Mockito.any())).thenReturn(returnType);
+ MultivaluedMap<String, String> map = Mockito.mock(MultivaluedMap.class);
+ result = MusicCore.updateTable(new JsonUpdate(), map);
+ assertEquals(returnType, result);
+ }
+
+ @Test
+ public void testDeleteFromTable() throws MusicLockingException, MusicQueryException, MusicServiceException {
+ ReturnType returnType = Mockito.mock(ReturnType.class);
+ ReturnType result = null;
+ MultivaluedMap<String, String> map = Mockito.mock(MultivaluedMap.class);
+ Mockito.when(musicCore.deleteFromTable(Mockito.any(), Mockito.any())).thenReturn(returnType);
+ result = MusicCore.deleteFromTable(new JsonDelete(), map);
+ assertEquals(returnType, result);
+ }
+}
diff --git a/music-rest/src/test/java/org/onap/music/conductor/conditionals/JsonConditionalTest.java b/music-rest/src/test/java/org/onap/music/conductor/conditionals/JsonConditionalTest.java
new file mode 100644
index 00000000..07c43114
--- /dev/null
+++ b/music-rest/src/test/java/org/onap/music/conductor/conditionals/JsonConditionalTest.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * ============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.conductor.conditionals;
+
+import static org.junit.Assert.assertEquals;
+import java.util.Map;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class JsonConditionalTest {
+
+ Map<String,Object> tableValues;
+ Map<String,Object> casscadeColumnData;
+ Map<String,Map<String,String>> conditions;
+ JsonConditional jsonConditional;
+
+ @Before
+ public void setup() {
+ tableValues = Mockito.mock(Map.class);
+ casscadeColumnData = Mockito.mock(Map.class);
+ conditions = Mockito.mock(Map.class);
+ jsonConditional = new JsonConditional();
+ }
+
+ @Test
+ public void testSetTableValues() {
+ jsonConditional.setTableValues(tableValues);
+ assertEquals(tableValues, jsonConditional.getTableValues());
+ }
+
+ @Test
+ public void testSetPrimaryKey() {
+ jsonConditional.setPrimaryKey("primarykey");
+ assertEquals("primarykey", jsonConditional.getPrimaryKey());
+ }
+
+ @Test
+ public void testSetPrimaryKeyValue() {
+ jsonConditional.setPrimaryKeyValue("primarykeyvalue");
+ assertEquals("primarykeyvalue", jsonConditional.getPrimaryKeyValue());
+ }
+
+ @Test
+ public void testSetCasscadeColumnName() {
+ jsonConditional.setCasscadeColumnName("columnname");
+ assertEquals("columnname", jsonConditional.getCasscadeColumnName());
+ }
+
+ @Test
+ public void testSetCasscadeColumnData() {
+ jsonConditional.setCasscadeColumnData(casscadeColumnData);
+ assertEquals(casscadeColumnData, jsonConditional.getCasscadeColumnData());
+ }
+
+ @Test
+ public void testSetConditions() {
+ jsonConditional.setConditions(conditions);
+ assertEquals(conditions, jsonConditional.getConditions());
+ }
+
+}
diff --git a/music-rest/src/test/java/org/onap/music/conductor/conditionals/UpdateDataObjectTest.java b/music-rest/src/test/java/org/onap/music/conductor/conditionals/UpdateDataObjectTest.java
new file mode 100644
index 00000000..b651f5e9
--- /dev/null
+++ b/music-rest/src/test/java/org/onap/music/conductor/conditionals/UpdateDataObjectTest.java
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * ============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.conductor.conditionals;
+
+import static org.junit.Assert.assertEquals;
+import java.util.Map;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.music.datastore.PreparedQueryObject;
+
+public class UpdateDataObjectTest {
+
+ UpdateDataObject updateDataObject;
+ Map<String, PreparedQueryObject> queryBank;
+ Map<String, String> cascadeColumnValues;
+
+ @Before
+ public void setup() {
+ updateDataObject = new UpdateDataObject();
+ queryBank = Mockito.mock(Map.class);
+ cascadeColumnValues = Mockito.mock(Map.class);
+ }
+
+ @Test
+ public void testSetQueryBank() {
+ updateDataObject.setQueryBank(queryBank);
+ assertEquals(queryBank, updateDataObject.getQueryBank());
+ }
+
+ @Test
+ public void testSetKeyspace() {
+ updateDataObject.setKeyspace("keyspace");
+ assertEquals("keyspace", updateDataObject.getKeyspace());
+ }
+
+ @Test
+ public void testSetTableName() {
+ updateDataObject.setTableName("table");
+ assertEquals("table", updateDataObject.getTableName());
+ }
+
+ @Test
+ public void testSetPrimaryKey() {
+ updateDataObject.setPrimaryKey("primarykey");
+ assertEquals("primarykey", updateDataObject.getPrimaryKey());
+ }
+
+ @Test
+ public void testSetPrimaryKeyValue() {
+ updateDataObject.setPrimaryKeyValue("primarykeyvalue");
+ assertEquals("primarykeyvalue", updateDataObject.getPrimaryKeyValue());
+ }
+
+ @Test
+ public void testSetPlanId() {
+ updateDataObject.setPlanId("planid");
+ assertEquals("planid", updateDataObject.getPlanId());
+ }
+
+ @Test
+ public void testSetCascadeColumnName() {
+ updateDataObject.setCascadeColumnName("columnname");
+ assertEquals("columnname", updateDataObject.getCascadeColumnName());
+ }
+
+ @Test
+ public void testSetCascadeColumnValues() {
+ updateDataObject.setCascadeColumnValues(cascadeColumnValues);
+ assertEquals(cascadeColumnValues, updateDataObject.getCascadeColumnValues());
+ }
+
+ @Test
+ public void testSetLockId() {
+ updateDataObject.setLockId("lockid");
+ assertEquals("lockid", updateDataObject.getLockId());
+ }
+}