summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/onap/music/unittests/MusicUtilTest.java11
-rw-r--r--src/test/java/org/onap/music/unittests/TestMusicCore.java666
-rw-r--r--src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java195
-rw-r--r--src/test/java/org/onap/music/unittests/TestsUsingCassandra.java4
-rw-r--r--src/test/java/org/onap/music/unittests/TstCachingUtil.java178
-rw-r--r--src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java138
-rw-r--r--src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java24
-rw-r--r--src/test/java/org/onap/music/unittests/jsonobjects/MusicHealthCheckTest.java8
8 files changed, 201 insertions, 1023 deletions
diff --git a/src/test/java/org/onap/music/unittests/MusicUtilTest.java b/src/test/java/org/onap/music/unittests/MusicUtilTest.java
index b117c330..47f387cf 100644
--- a/src/test/java/org/onap/music/unittests/MusicUtilTest.java
+++ b/src/test/java/org/onap/music/unittests/MusicUtilTest.java
@@ -31,6 +31,7 @@ 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;
@@ -203,5 +204,15 @@ public class MusicUtilTest {
assertTrue(result.contains("name"));
assertTrue(result.contains("value"));
}
+
+ @Test
+ public void test_generateUUID() {
+ //this function shouldn't be in cachingUtil
+ System.out.println("Testing getUUID");
+ String uuid1 = MusicUtil.generateUUID();
+ String uuid2 = MusicUtil.generateUUID();
+ assertFalse(uuid1==uuid2);
+ }
+
}
diff --git a/src/test/java/org/onap/music/unittests/TestMusicCore.java b/src/test/java/org/onap/music/unittests/TestMusicCore.java
deleted file mode 100644
index 5f9bf8f6..00000000
--- a/src/test/java/org/onap/music/unittests/TestMusicCore.java
+++ /dev/null
@@ -1,666 +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 static org.onap.music.service.impl.MusicZKCore.mLockHandle;
-
-import java.util.HashMap;
-import java.util.Map;
-import org.apache.zookeeper.KeeperException.NoNodeException;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.onap.music.exceptions.MusicLockingException;
-import org.onap.music.exceptions.MusicQueryException;
-import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.lockingservice.cassandra.MusicLockState;
-import org.onap.music.lockingservice.cassandra.MusicLockState.LockStatus;
-import org.onap.music.lockingservice.zookeeper.MusicLockingService;
-import org.onap.music.main.MusicUtil;
-import org.onap.music.main.ResultType;
-import org.onap.music.main.ReturnType;
-import org.onap.music.service.impl.MusicZKCore;
-import org.onap.music.datastore.Condition;
-import org.onap.music.datastore.MusicDataStore;
-import org.onap.music.datastore.MusicDataStoreHandle;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.eelf.logging.EELFLoggerDelegate;
-import org.onap.music.eelf.logging.format.AppMessages;
-import org.onap.music.eelf.logging.format.ErrorSeverity;
-import org.onap.music.eelf.logging.format.ErrorTypes;
-import com.att.eelf.exception.EELFException;
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Session;
-
-
-public class TestMusicCore {
-
-
- private Condition condition;
-
-
- private ResultSet rs;
-
-
- private PreparedQueryObject preparedQueryObject;
-
-
- private Session session;
-
- @Mock
- MusicZKCore musicZKCore;
-
- @Before
- public void setUp() {
- mLockHandle = Mockito.mock(MusicLockingService.class);
- musicZKCore = MusicZKCore.getInstance();
- condition=Mockito.mock(Condition.class);
- rs =Mockito.mock(ResultSet.class);
- preparedQueryObject =Mockito.mock(PreparedQueryObject.class);
- session =Mockito.mock(Session.class);
-
- }
-
- @Test
- public void testCreateLockReferenceforvalidlock() {
- Mockito.when(mLockHandle.createLockId("/" + "test")).thenReturn("lock");
- String lockId = musicZKCore.createLockReference("test");
- assertEquals("lock", lockId);
- Mockito.verify(mLockHandle).createLockId("/" + "test");
- }
-
-
- @Test
- public void testCreateLockReferencefornullname() {
- //Mockito.when(mLockHandle.createLockId("/" + "test")).thenReturn("lock");
- String lockId = musicZKCore.createLockReference("x"); //test");
- //System.out.println("cjc exception lockhandle=" + mLockHandle+"lockid="+lockId );
- assertNotEquals("lock", lockId);
- //Mockito.verify(mLockHandle).createLockId("/" + "test");
- }
-
- @Test
- public void testIsTableOrKeySpaceLock() {
- Boolean result = musicZKCore.isTableOrKeySpaceLock("ks1.tn1");
- assertTrue(result);
- }
-
- @Test
- public void testIsTableOrKeySpaceLockwithPrimarykey() {
- Boolean result = musicZKCore.isTableOrKeySpaceLock("ks1.tn1.pk1");
- assertFalse(result);
- }
-
- @Test
- public void testGetMusicLockState() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
- Mockito.when(mLockHandle.getLockState("ks1.tb1.pk1")).thenReturn(musicLockState);
- MusicLockState mls = MusicZKCore.getMusicLockState("ks1.tb1.pk1");
- assertEquals(musicLockState, mls);
- Mockito.verify(mLockHandle).getLockState("ks1.tb1.pk1");
- }
-
- @Test
- public void testAcquireLockifisMyTurnTrue() throws MusicLockingException {
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- ReturnType lock = musicZKCore.acquireLock("ks1.tn1", "id1");
- assertEquals(lock.getResult(), ResultType.SUCCESS);
- Mockito.verify(mLockHandle).isMyTurn("id1");
- }
-
- @Test
- public void testAcquireLockifisMyTurnFalse() throws MusicLockingException {
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
- ReturnType lock = musicZKCore.acquireLock("ks1.ts1", "id1");
- assertEquals(lock.getResult(), ResultType.FAILURE);
- Mockito.verify(mLockHandle).isMyTurn("id1");
- }
-
- @Test
- public void testAcquireLockifisMyTurnTrueandIsTableOrKeySpaceLockTrue() throws MusicLockingException {
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- ReturnType lock = musicZKCore.acquireLock("ks1.tn1", "id1");
- assertEquals(lock.getResult(), ResultType.SUCCESS);
- Mockito.verify(mLockHandle).isMyTurn("id1");
- }
-
- @Test
- public void testAcquireLockifisMyTurnTrueandIsTableOrKeySpaceLockFalseandHaveLock() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- ReturnType lock = musicZKCore.acquireLock("ks1.tn1.pk1", "id1");
- assertEquals(lock.getResult(), ResultType.SUCCESS);
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle).getLockState("ks1.tn1.pk1");
- }
-
- @Test
- public void testAcquireLockifisMyTurnTrueandIsTableOrKeySpaceLockFalseandDontHaveLock() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id2");
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- ReturnType lock = musicZKCore.acquireLock("ks1.tn1.pk1", "id1");
- assertEquals(lock.getResult(), ResultType.SUCCESS);
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle).getLockState("ks1.tn1.pk1");
- }
-
- @Test
- public void testAcquireLockifLockRefDoesntExist() throws MusicLockingException {
- Mockito.when(mLockHandle.lockIdExists("bs1")).thenReturn(false);
- ReturnType lock = musicZKCore.acquireLock("ks1.ts1", "bs1");
- assertEquals(lock.getResult(), ResultType.FAILURE);
- assertEquals(lock.getMessage(), "Lockid doesn't exist");
- Mockito.verify(mLockHandle).lockIdExists("bs1");
- }
-
- @Test
- public void testAcquireLockWithLeasewithLease() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
- musicLockState.setLeasePeriod(0);
- ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- ReturnType actualResult = musicZKCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
- }
-
- @Test
- public void testAcquireLockWithLeasewithException() throws MusicLockingException {
- ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "failure");
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenThrow(new MusicLockingException());
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- ReturnType actualResult = musicZKCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
- }
-
- @Test
- public void testAcquireLockWithLeasewithLockStatusLOCKED() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
- ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- ReturnType actualResult = musicZKCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
- }
-
- @Test
- public void testAcquireLockWithLeasewithLockStatusUNLOCKED() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
- ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- ReturnType actualResult = musicZKCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
-
- }
-
- @Test
- public void testAcquireLockWithLeaseIfNotMyTurn() throws MusicLockingException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
- ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
- ReturnType actualResult = musicZKCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle).getLockState("ks1.tn1.pk1");
- }
-
- @Test
- public void testQuorumGet() throws MusicServiceException, MusicQueryException {
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- MusicDataStoreHandle.mDstoreHandle = Mockito.mock(MusicDataStore.class);
- rs = Mockito.mock(ResultSet.class);
- session = Mockito.mock(Session.class);
- Mockito.when(MusicDataStoreHandle.mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(MusicDataStoreHandle.mDstoreHandle.executeQuorumConsistencyGet(preparedQueryObject)).thenReturn(rs);
- ResultSet rs1 = musicZKCore.quorumGet(preparedQueryObject);
- assertNotNull(rs1);
- }
-
- @Test
- public void testGetLockNameFromId() {
- String lockname = MusicZKCore.getLockNameFromId("lockName$id");
- assertEquals("lockName", lockname);
- }
-
- @Test
- public void testDestroyLockRef() throws NoNodeException {
- Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1");
- musicZKCore.destroyLockRef("id1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1");
- }
-
- @Test
- public void testreleaseLockwithvoluntaryReleaseTrue() throws NoNodeException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
- Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1");
- MusicLockState musicLockState1 = musicZKCore.releaseLock("id1", true);
- assertEquals(musicLockState.getLockStatus(), musicLockState1.getLockStatus());
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1");
- }
-
- @Test
- public void testreleaseLockwithvoluntaryReleaseFalse() throws NoNodeException {
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
- Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1");
- MusicLockState musicLockState1 = musicZKCore.releaseLock("id1", false);
- assertEquals(musicLockState.getLockStatus(), musicLockState1.getLockStatus());
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1");
- }
-
- @Test
- public void testDeleteLock() throws MusicLockingException {
- Mockito.doNothing().when(mLockHandle).deleteLock("/" + "id1");
- musicZKCore.deleteLock("id1");
- Mockito.verify(mLockHandle).deleteLock("/" + "id1");
- }
-
- /*
- * @Test public void testNonKeyRelatedPut() throws Exception { MusicDataStoreHandle.mDstoreHandle =
- * Mockito.mock(MusicDataStore.class); Mockito.when(MusicDataStoreHandle.mDstoreHandle.executePut("qu1",
- * "consistency")).thenReturn(true); Boolean result = MusicCore.nonKeyRelatedPut("qu1",
- * "consistency"); assertTrue(result); Mockito.verify(MusicDataStoreHandle.mDstoreHandle).executePut("qu1",
- * "consistency"); }
- */
-
- @Test
- public void testEventualPutPreparedQuery() throws MusicServiceException, MusicQueryException {
- MusicDataStoreHandle.mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
- session = Mockito.mock(Session.class);
- Mockito.when(MusicDataStoreHandle.mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(MusicDataStoreHandle.mDstoreHandle.executePut(preparedQueryObject, "eventual")).thenReturn(true);
- ReturnType actualResult = musicZKCore.eventualPut(preparedQueryObject);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(MusicDataStoreHandle.mDstoreHandle).executePut(preparedQueryObject, "eventual");
- }
-
- @Test
- public void testEventualPutPreparedQuerywithResultFalse()
- throws MusicServiceException, MusicQueryException {
- MusicDataStoreHandle.mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
- session = Mockito.mock(Session.class);
- Mockito.when(MusicDataStoreHandle.mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(MusicDataStoreHandle.mDstoreHandle.executePut(preparedQueryObject, "eventual")).thenReturn(false);
- ReturnType actualResult = musicZKCore.eventualPut(preparedQueryObject);
- assertEquals(expectedResult.getResult(), actualResult.getResult());
- Mockito.verify(MusicDataStoreHandle.mDstoreHandle).executePut(preparedQueryObject, "eventual");
- //Mockito.verify(MusicDataStoreHandle.mDstoreHandle).executePut(preparedQueryObject, MusicUtil.EVENTUAL);
- }
-
- @Test
- public void testCriticalPutPreparedQuerywithValidLockId()
- throws Exception {
- MusicDataStoreHandle.mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
- Mockito.when(condition.testCondition()).thenReturn(true);
- session = Mockito.mock(Session.class);
- Mockito.when(MusicDataStoreHandle.mDstoreHandle.getSession()).thenReturn(session);
- ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- Mockito.when(MusicDataStoreHandle.mDstoreHandle.executePut(preparedQueryObject, "critical")).thenReturn(true);
- ReturnType returnType = musicZKCore.criticalPut("ks1", "tn1", "pk1", preparedQueryObject,
- "id1", condition);
- assertEquals(expectedResult.getResult(), returnType.getResult());
- Mockito.verify(condition).testCondition();
- Mockito.verify(mLockHandle).getLockState("ks1" + "." + "tn1" + "." + "pk1");
- Mockito.verify(MusicDataStoreHandle.mDstoreHandle).executePut(preparedQueryObject, "critical");
- }
-
- @Test
- public void testCriticalPutPreparedQuerywithInvalidLockId() throws MusicLockingException {
- MusicDataStoreHandle.mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
- ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- ReturnType returnType = musicZKCore.criticalPut("ks1", "tn1", "pk1", preparedQueryObject,
- "id1", condition);
- assertEquals(expectedResult.getResult(), returnType.getResult());
- Mockito.verify(mLockHandle).getLockState("ks1" + "." + "tn1" + "." + "pk1");
- }
-
- @Test
- public void testCriticalPutPreparedQuerywithvalidLockIdandTestConditionFalse() throws Exception {
- MusicDataStoreHandle.mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
- Mockito.when(condition.testCondition()).thenReturn(false);
- ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- ReturnType returnType = musicZKCore.criticalPut("ks1", "tn1", "pk1", preparedQueryObject,
- "id1", condition);
- assertEquals(expectedResult.getResult(), returnType.getResult());
- Mockito.verify(condition).testCondition();
- Mockito.verify(mLockHandle).getLockState("ks1" + "." + "tn1" + "." + "pk1");
- }
-
- @Test
- public void testNonKeyRelatedPutPreparedQuery() throws Exception {
- MusicDataStoreHandle.mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- session = Mockito.mock(Session.class);
- Mockito.when(MusicDataStoreHandle.mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(MusicDataStoreHandle.mDstoreHandle.executePut(preparedQueryObject, "consistency")).thenReturn(true);
- ResultType result = musicZKCore.nonKeyRelatedPut(preparedQueryObject, "consistency");
- assertEquals(ResultType.SUCCESS, result);
- Mockito.verify(MusicDataStoreHandle.mDstoreHandle).executePut(preparedQueryObject, "consistency");
- }
-
- @Test
- public void testAtomicPutPreparedQuery() throws Exception {
- MusicDataStoreHandle.mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
- ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
- session = Mockito.mock(Session.class);
- Mockito.when(MusicDataStoreHandle.mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- Mockito.when(condition.testCondition()).thenReturn(true);
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- Mockito.when(MusicDataStoreHandle.mDstoreHandle.executePut(preparedQueryObject, "critical")).thenReturn(true);
- ReturnType returnType =
- musicZKCore.atomicPut("ks1", "tn1", "pk1", preparedQueryObject, condition);
- assertEquals(expectedResult.getResult(), returnType.getResult());
- Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(condition).testCondition();
- Mockito.verify(mLockHandle, Mockito.atLeastOnce())
- .getLockState("ks1" + "." + "tn1" + "." + "pk1");
- Mockito.verify(MusicDataStoreHandle.mDstoreHandle).executePut(preparedQueryObject, "critical");
- }
-
- @Test
- public void testAtomicPutPreparedQuerywithAcquireLockWithLeaseFalse() throws MusicLockingException {
- MusicDataStoreHandle.mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
- ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
- ReturnType returnType =
- musicZKCore.atomicPut("ks1", "tn1", "pk1", preparedQueryObject, condition);
- assertEquals(expectedResult.getResult(), returnType.getResult());
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
- }
-
- @Test
- public void testAtomicGetPreparedQuery() throws MusicServiceException, MusicQueryException, MusicLockingException {
- MusicDataStoreHandle.mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- rs = Mockito.mock(ResultSet.class);
- session = Mockito.mock(Session.class);
- Mockito.when(MusicDataStoreHandle.mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
- Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- Mockito.when(MusicDataStoreHandle.mDstoreHandle.executeQuorumConsistencyGet(preparedQueryObject)).thenReturn(rs);
- ResultSet rs1 = musicZKCore.atomicGet("ks1", "tn1", "pk1", preparedQueryObject);
- assertNotNull(rs1);
- Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
- Mockito.verify(mLockHandle).isMyTurn("id1");
- Mockito.verify(mLockHandle, Mockito.atLeastOnce())
- .getLockState("ks1" + "." + "tn1" + "." + "pk1");
- Mockito.verify(MusicDataStoreHandle.mDstoreHandle).executeQuorumConsistencyGet(preparedQueryObject);
- }
-
- @Test
- public void testAtomicGetPreparedQuerywithAcquireLockWithLeaseFalse()
- throws MusicServiceException, MusicLockingException {
- MusicDataStoreHandle.mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- rs = Mockito.mock(ResultSet.class);
- Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
- ResultSet rs1 = musicZKCore.atomicGet("ks1", "tn1", "pk1", preparedQueryObject);
- assertNull(rs1);
- Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
- Mockito.verify(mLockHandle).isMyTurn("id1");
- }
-
- @Test
- public void testGetPreparedQuery() throws MusicServiceException, MusicQueryException {
- MusicDataStoreHandle.mDstoreHandle = Mockito.mock(MusicDataStore.class);
- rs = Mockito.mock(ResultSet.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- session = Mockito.mock(Session.class);
- Mockito.when(MusicDataStoreHandle.mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(MusicDataStoreHandle.mDstoreHandle.executeOneConsistencyGet(preparedQueryObject)).thenReturn(rs);
- ResultSet rs1 = musicZKCore.get(preparedQueryObject);
- assertNotNull(rs1);
- Mockito.verify(MusicDataStoreHandle.mDstoreHandle).executeOneConsistencyGet(preparedQueryObject);
-
- }
-
- @Test
- public void testcriticalGetPreparedQuery() throws MusicServiceException, MusicQueryException, MusicLockingException {
- MusicDataStoreHandle.mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
- rs = Mockito.mock(ResultSet.class);
- session = Mockito.mock(Session.class);
- Mockito.when(MusicDataStoreHandle.mDstoreHandle.getSession()).thenReturn(session);
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- Mockito.when(MusicDataStoreHandle.mDstoreHandle.executeQuorumConsistencyGet(preparedQueryObject)).thenReturn(rs);
- ResultSet rs1 = musicZKCore.criticalGet("ks1", "tn1", "pk1", preparedQueryObject, "id1");
- assertNotNull(rs1);
- Mockito.verify(mLockHandle, Mockito.atLeastOnce())
- .getLockState("ks1" + "." + "tn1" + "." + "pk1");
- Mockito.verify(MusicDataStoreHandle.mDstoreHandle).executeQuorumConsistencyGet(preparedQueryObject);
- }
-
- @Test
- public void testcriticalGetPreparedQuerywithInvalidLockId() throws MusicServiceException, MusicLockingException {
- MusicDataStoreHandle.mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
- Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
- .thenReturn(musicLockState);
- ResultSet rs1 = musicZKCore.criticalGet("ks1", "tn1", "pk1", preparedQueryObject, "id1");
- assertNull(rs1);
- Mockito.verify(mLockHandle, Mockito.atLeastOnce())
- .getLockState("ks1" + "." + "tn1" + "." + "pk1");
- }
-
- @Test
- public void testAtomicGetPreparedQuerywithDeleteLockWithLeaseFalse()
- throws MusicServiceException, MusicLockingException {
- MusicDataStoreHandle.mDstoreHandle = Mockito.mock(MusicDataStore.class);
- preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
- rs = Mockito.mock(ResultSet.class);
- Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
- Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
- ResultSet rs1 = musicZKCore.atomicGet("ks1", "tn1", "pk1", preparedQueryObject);
- assertNull(rs1);
- Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
- Mockito.verify(mLockHandle).isMyTurn("id1");
- }
-
- @Test
- public void testCondition() throws Exception {
- //Condition conClass = Mockito.mock(Condition.class);
- // boolean ret=true;
- //Mockito.when(conClass.testCondition().thenReturn(ret);
- Map<String, Object> conditionsx=null;
- PreparedQueryObject selectQueryForTheRowx=null;
- try {
- Condition con = new Condition(conditionsx,selectQueryForTheRowx);
- assertTrue(con.testCondition());
- } catch (Exception e) {
- assertFalse(false);
- }
- }
- //getLockingServiceHandl
-
- @Ignore
- @Test(expected = MusicLockingException.class) //("Failed to aquire Locl store handle " + e))
- public void testgetLockingServiceHandle() throws Exception {
- // MusicLockingService mLockHandlex = Mockito.mock(MusicLockingService.class);
- //MusicLockingService mLockHandlea = mLockHandle;
- //mLockHandle=null;
- System.out.println("cjc 0 locking test n");
- // Mockito.when(MusicCore.getLockingServiceHandle()).thenReturn(mLockHandle);
- //mLockHandle=null;
- //System.out.println("cjc 0-1 locking test n");
- MusicLockingService mLockHandlea = mLockHandle;
- mLockHandle=null;
-
- MusicLockingService mLockHandley=null; //MusicCore.getLockingServiceHandle();
- Mockito.when(MusicZKCore.getLockingServiceHandle()).thenReturn(mLockHandley);
- System.out.println("cjc locking test n");
- mLockHandle=mLockHandlea;
- assertTrue(true);
-
- }
- //add mocking
- @Ignore
- @Test
- public void testGetDSHandleIp() throws MusicServiceException, MusicQueryException {
- // rs = Mockito.mock(ResultSet.class);
- // session = Mockito.mock(Session.class);
- //Mockito.when(MusicDataStoreHandle.mDstoreHandle.getSession()).thenReturn(session);
- //Mockito.when(MusicDataStoreHandle.mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs);
-
- //MusicDataStoreHandle.mDstoreHandle = Mockito.mock(MusicDataStore.class);
- //MusicUtil mMusicUtil=Mockito.mock(MusicUtil.class);
- System.out.println("cjc 0 getDsHandleIP");
- Mockito.when(MusicDataStoreHandle.getDSHandle("1.127.0.1")).thenReturn(MusicDataStoreHandle.mDstoreHandle);
- System.out.println("cjc localhost");
- // Mockito.when(mMusicUtil.getMyCassaHost().equals("localhost")).thenReturn(null);
- System.out.println("cjc 1 localhost IP");
- // MusicDataStoreHandle.mDstoreHandle = new MusicDataStore(MusicUtil.getMyCassaHost());
- // } else {
- // MusicDataStoreHandle.mDstoreHandle = new MusicDataStore();
- // }
- assertTrue(true);
- }
-
- @Ignore
- @Test
- public void testPureZkCreate() {
- try {
- MusicZKCore.pureZkCreate("local");
- } catch(NullPointerException e) {
- System.out.println("cjc zkcreate null pointwer exception:"+ e);
- }
- }
-
- @Ignore
- @Test
- public void testPureZkRead() { //String nodeName) {
- byte[] data = MusicZKCore.pureZkRead("localhost");
- }
-
- //need fixing
- @Ignore
- @Test
- public void testPureZkWrite() { //String nodeName, byte[] data) {
- /*
- long start = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Performing zookeeper write to " + nodeName);
- try {
- getLockingServiceHandle().getzkLockHandle().setNodeData(nodeName, data);
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), "[ERR512E] Failed to get ZK Lock Handle " ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
- logger.info(EELFLoggerDelegate.applicationLogger,"Performed zookeeper write to " + nodeName);
- long end = System.currentTimeMillis();
- logger.info(EELFLoggerDelegate.applicationLogger,"Time taken for the actual zk put:" + (end - start) + " ms");
- */
-
- // MusicDataStoreHandle.mDstoreHandle = Mockito.mock(MusicDataStore.class);
- // rs = Mockito.mock(ResultSet.class);
- // session = Mockito.mock(Session.class);
- //Mockito.when(MusicDataStoreHandle.mDstoreHandle.getSession()).thenReturn(session);
-
- byte[] data= "Testing Zoo Keeper".getBytes();
- MusicZKCore.pureZkWrite("1.127.0.1", data);
- // assertNotNull(rs1);
- }
-
- @Test
- public void testWhoseTurnIsIt() { //(String lockName) {
-
- /*
- try {
- return getLockingServiceHandle().whoseTurnIsIt("/" + lockName) + "";
- } catch (MusicLockingException e) {
- logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), AppMessages.LOCKINGERROR+lockName ,ErrorSeverity.CRITICAL, ErrorTypes.LOCKINGERROR);
- }
- return null;
- */
-
- String lockName="xxx";
- if (musicZKCore.whoseTurnIsIt(lockName) != null) assertTrue(true);
-
-
-
- }
-
- @Test
- public void testMarshallResults() {
- Map<String, HashMap<String, Object>> ret=null;
- //ResultSet results =null;
- rs = Mockito.mock(ResultSet.class);
- try {
- ret= MusicDataStoreHandle.marshallResults(rs);
-
- } catch( Exception e ) {
-
- }
-
- if (ret != null) assertTrue(true);
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java b/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java
deleted file mode 100644
index f7a22d64..00000000
--- a/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * ============LICENSE_START========================================== org.onap.music
- * ===================================================================
- * Copyright (c) 2017 AT&T Intellectual Property
- * Modifications Copyright (c) 2019 IBM
- * ===================================================================
- * 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.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import java.io.File;
-import java.util.List;
-import org.apache.curator.test.TestingServer;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-import org.onap.music.datastore.MusicDataStoreHandle;
-import org.onap.music.datastore.PreparedQueryObject;
-import org.onap.music.exceptions.MusicQueryException;
-import org.onap.music.exceptions.MusicServiceException;
-import org.onap.music.lockingservice.cassandra.MusicLockState;
-import org.onap.music.lockingservice.cassandra.MusicLockState.LockStatus;
-import org.onap.music.lockingservice.zookeeper.MusicLockingService;
-import org.onap.music.main.MusicUtil;
-import org.onap.music.main.ResultType;
-import org.onap.music.main.ReturnType;
-import org.onap.music.service.impl.MusicZKCore;
-
-import com.datastax.driver.core.ResultSet;
-import com.datastax.driver.core.Row;
-
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class TestMusicCoreIntegration {
-
- static TestingServer zkServer;
- static PreparedQueryObject testObject;
- static String lockId = null;
- static String lockName = "ks1.tb1.pk1";
- static MusicZKCore musicZkCore ;
-
- @BeforeClass
- public static void init() throws Exception {
- try {
- MusicDataStoreHandle.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra();
- musicZkCore = MusicZKCore.getInstance();
- zkServer = new TestingServer(2181, new File("/tmp/zk"));
- MusicZKCore.mLockHandle = new MusicLockingService();
- } catch (Exception e) {
- e.printStackTrace();
- }
- System.out.println("####Port:" + zkServer.getPort());
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- System.out.println("After class");
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.dropKeyspace);
- musicZkCore.eventualPut(testObject);
- musicZkCore.deleteLock(lockName);
- MusicDataStoreHandle.mDstoreHandle.close();
- MusicZKCore.mLockHandle.getzkLockHandle().close();
- MusicZKCore.mLockHandle.close();
- zkServer.stop();
-
- }
-
- @Test
- public void Test1_SetUp() throws MusicServiceException, MusicQueryException {
- MusicZKCore.mLockHandle = new MusicLockingService();
- ResultType result = ResultType.FAILURE;
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.createKeySpace);
- musicZkCore.eventualPut(testObject);
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.createTableEmployees);
- result = musicZkCore.nonKeyRelatedPut(testObject, MusicUtil.EVENTUAL);
- assertEquals(ResultType.SUCCESS, result);
- }
-
- @Test
- public void Test2_atomicPut() throws Exception {
- testObject = new PreparedQueryObject();
- testObject = CassandraCQL.setPreparedInsertQueryObject1();
- ReturnType returnType = musicZkCore.atomicPut("testCassa", "employees", "Mr Test one",
- testObject, null);
- assertEquals(ResultType.SUCCESS, returnType.getResult());
- }
-
- @Test
- public void Test3_atomicPutWithDeleteLock() throws Exception {
- testObject = new PreparedQueryObject();
- testObject = CassandraCQL.setPreparedInsertQueryObject2();
- ReturnType returnType = musicZkCore.atomicPutWithDeleteLock("testCassa", "employees",
- "Mr Test two", testObject, null);
- assertEquals(ResultType.SUCCESS, returnType.getResult());
- }
-
- @Test
- public void Test4_atomicGetWithDeleteLock() throws Exception {
- testObject = new PreparedQueryObject();
- testObject = CassandraCQL.setPreparedGetQuery();
- ResultSet resultSet = musicZkCore.atomicGetWithDeleteLock("testCassa", "employees",
- "Mr Test one", testObject);
- List<Row> rows = resultSet.all();
- assertEquals(1, rows.size());
- }
-
- @Test
- public void Test5_atomicGet() throws Exception {
- testObject = new PreparedQueryObject();
- testObject = CassandraCQL.setPreparedGetQuery();
- ResultSet resultSet =
- musicZkCore.atomicGet("testCassa", "employees", "Mr Test two", testObject);
- List<Row> rows = resultSet.all();
- assertEquals(1, rows.size());
- }
-
- @Test
- public void Test6_createLockReference() throws Exception {
- lockId = musicZkCore.createLockReference(lockName);
- assertNotNull(lockId);
- }
-
- @Test
- public void Test7_acquireLockwithLease() throws Exception {
- ReturnType lockLeaseStatus = musicZkCore.acquireLockWithLease(lockName, lockId, 1000);
- assertEquals(ResultType.SUCCESS, lockLeaseStatus.getResult());
- }
-
- @Test
- public void Test8_acquireLock() throws Exception {
- ReturnType lockStatus = musicZkCore.acquireLock(lockName, lockId);
- assertEquals(ResultType.SUCCESS, lockStatus.getResult());
- }
-
- @Test
- public void Test9_release() throws Exception {
- MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
- MusicLockState musicLockState1 = new MusicLockState(LockStatus.UNLOCKED, "id1");
- musicZkCore.whoseTurnIsIt(lockName);
- MusicLockState mls = MusicZKCore.getMusicLockState(lockName);
- boolean voluntaryRelease = true;
- MusicLockState mls1 = musicZkCore.releaseLock(lockId, voluntaryRelease);
- assertEquals(musicLockState.getLockStatus(), mls.getLockStatus());
- assertEquals(musicLockState1.getLockStatus(), mls1.getLockStatus());
- }
-
- @Test
- public void Test10_create() {
- MusicZKCore.pureZkCreate("/nodeName");
- }
-
- @Test
- public void Test11_write() {
- MusicZKCore.pureZkWrite("nodeName", "I'm Test".getBytes());
- }
-
- @Test
- public void Test12_read() {
- byte[] data = MusicZKCore.pureZkRead("nodeName");
- String data1 = new String(data);
- assertEquals("I'm Test", data1);
- }
- @Test
- public void Test13_ParameterizedConstructorCall() throws MusicServiceException, MusicQueryException {
- MusicZKCore.mLockHandle = new MusicLockingService("localhost");
- ResultType result = ResultType.FAILURE;
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.createKeySpace);
- musicZkCore.eventualPut(testObject);
- testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.createTableEmployees);
- result = musicZkCore.nonKeyRelatedPut(testObject, MusicUtil.EVENTUAL);
- assertEquals(ResultType.SUCCESS, result);
- }
-
-}
diff --git a/src/test/java/org/onap/music/unittests/TestsUsingCassandra.java b/src/test/java/org/onap/music/unittests/TestsUsingCassandra.java
index 35f3b326..d2e898e1 100644
--- a/src/test/java/org/onap/music/unittests/TestsUsingCassandra.java
+++ b/src/test/java/org/onap/music/unittests/TestsUsingCassandra.java
@@ -45,7 +45,6 @@ import com.sun.jersey.core.util.Base64;
@RunWith(Suite.class)
@SuiteClasses({ TstRestMusicDataAPI.class, TstRestMusicLockAPI.class, TstRestMusicAdminAPI.class,
TstRestMusicConditionalAPI.class, TstCachingUtil.class})
-//@SuiteClasses({TstCachingUtil.class})
public class TestsUsingCassandra {
static String appName = "TestApp";
@@ -61,6 +60,7 @@ public class TestsUsingCassandra {
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 {
@@ -92,7 +92,7 @@ public class TestsUsingCassandra {
+ "password, username, is_aaf) VALUES (?,?,?,?,?,?,?)");
testObject.addValue(MusicUtil.convertToActualDataType(DataType.uuid(), uuid));
testObject.addValue(MusicUtil.convertToActualDataType(DataType.text(),
- MusicUtil.DEFAULTKEYSPACENAME));
+ 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())));
diff --git a/src/test/java/org/onap/music/unittests/TstCachingUtil.java b/src/test/java/org/onap/music/unittests/TstCachingUtil.java
index be2783b2..ea47b7c1 100644
--- a/src/test/java/org/onap/music/unittests/TstCachingUtil.java
+++ b/src/test/java/org/onap/music/unittests/TstCachingUtil.java
@@ -1,15 +1,16 @@
/*
* ============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
+ * =================================================================== 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.
+ * 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=============================================
* ====================================================================
@@ -20,7 +21,15 @@ 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;
@@ -28,104 +37,121 @@ 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.main.CachingUtil;
+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 {
- 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 xLatestVersion = "X-latestVersion";
- static String onboardUUID = null;
-
- @BeforeClass
- public static void init() throws Exception {
- System.out.println("Testing CachingUtil class");
- try {
- createKeyspace();
- } catch (Exception e) {
- e.printStackTrace();
- throw new Exception("Unable to initialize before CachingUtil test class. " + e.getMessage());
- }
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- testObject = new PreparedQueryObject();
- testObject.appendQueryString("DROP KEYSPACE IF EXISTS " + keyspaceName);
- MusicCore.eventualPut(testObject);
+ 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_isAAF_False() throws Exception {
- System.out.println("Testing isAAF, nonaaf app");
- assertEquals("false", CachingUtil.isAAFApplication(appName));
- }
-
+
@Test
- public void test_getUUidFromMusicCache() throws Exception {
- System.out.println("Testing getUUID from MusicCache");
- assertEquals(uuid.toString(), CachingUtil.getUuidFromMusicCache(keyspaceName));
+ 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 Exception {
+ 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_verifyOnboarding() throws Exception {
- System.out.println("Testing verifyOnboarding");
- assertTrue(CachingUtil.verifyOnboarding(appName, userId, password).isEmpty());
- }
-
- @Test
- public void test_verifyOnboardingFailure() throws Exception {
- System.out.println("Testing verifyOnboarding with bad password");
- assertFalse(CachingUtil.verifyOnboarding(appName, userId, "pass").isEmpty());
- }
-
-
- @Test
- public void test_authenticateAIDUser() throws Exception {
- System.out.println("Testing authenticateAIDUser");
- assertTrue(CachingUtil.authenticateAIDUser(appName, userId, password, keyspaceName).isEmpty());
+ 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_authenticateAIDUserFailure() throws Exception {
- System.out.println("Testing authenticateAIDUser bad password");
- assertFalse(CachingUtil.authenticateAIDUser(appName, userId, "pass", keyspaceName).isEmpty());
+ 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
+ //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.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));
diff --git a/src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java b/src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java
index 07a1b8e1..23b98505 100644
--- a/src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java
+++ b/src/test/java/org/onap/music/unittests/TstRestMusicDataAPI.java
@@ -1,15 +1,20 @@
/*
- * ============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
+ * ============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
+ * 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.
+ * 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=============================================
* ====================================================================
@@ -53,6 +58,7 @@ import org.onap.music.main.MusicCore;
import org.onap.music.main.MusicUtil;
import org.onap.music.main.ResultType;
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;
@@ -62,14 +68,15 @@ import com.sun.jersey.core.util.MultivaluedMapImpl;
@RunWith(MockitoJUnitRunner.class)
public class TstRestMusicDataAPI {
- RestMusicDataAPI data = new RestMusicDataAPI();
- static PreparedQueryObject testObject;
+ RestMusicDataAPI data = new RestMusicDataAPI();
+ RestMusicLocksAPI lock = new RestMusicLocksAPI();
+ static PreparedQueryObject testObject;
- @Mock
- HttpServletResponse http;
+ @Mock
+ HttpServletResponse http;
- @Mock
- UriInfo info;
+ @Mock
+ UriInfo info;
static String appName = "TestApp";
static String userId = "TestUser";
@@ -84,6 +91,7 @@ public class TstRestMusicDataAPI {
static String tableName = "employees";
static String xLatestVersion = "X-latestVersion";
static String onboardUUID = null;
+ static String aid = TestsUsingCassandra.aid;
@BeforeClass
public static void init() throws Exception {
@@ -438,29 +446,6 @@ public class TstRestMusicDataAPI {
assertEquals(400, response.getStatus());
}
- @Ignore
- @Test
- public void test3_createTablePartitionKey() throws Exception {
- System.out.println("Testing create table with a partitionKey");
- 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);
- jsonTable.setPartitionKey("emp_salary");
- Response response = data.createTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonTable, keyspaceName, tableName);
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
- assertEquals(200, response.getStatus());
- }
// good clustering key, need to pass queryparameter
@Test
@@ -551,7 +536,7 @@ public class TstRestMusicDataAPI {
@Test
public void test4_insertIntoTableCriticalNoLockID() throws Exception {
- System.out.println("Testing atomic insert into table without lockid");
+ System.out.println("Testing critical insert into table without lockid");
createTable();
JsonInsert jsonInsert = new JsonInsert();
Map<String, String> consistencyInfo = new HashMap<>();
@@ -564,13 +549,35 @@ public class TstRestMusicDataAPI {
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);
+ 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_insertIntoTableAtomic() throws Exception {
+ System.out.println("Testing atomic insert into table without lockid");
+ 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", "atomic");
+ 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);
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+ assertEquals(200, response.getStatus());
+ }
+
@Test
public void test4_insertIntoTableNoName() throws Exception {
System.out.println("Testing insert into table w/o table name");
@@ -586,8 +593,8 @@ public class TstRestMusicDataAPI {
jsonInsert.setKeyspaceName(keyspaceName);
jsonInsert.setTableName(tableName);
jsonInsert.setValues(values);
- Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonInsert, "", "");
+ Response response = data.insertIntoTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
+ appName, authorization, jsonInsert, "", "");
System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
assertEquals(400, response.getStatus());
@@ -818,6 +825,27 @@ public class TstRestMusicDataAPI {
assertEquals(401, response.getStatus());
}
+ @Test
+ public void test6_selectAtomic() throws Exception {
+ System.out.println("Testing select atomic");
+ createAndInsertIntoTable();
+ JsonInsert jsonInsert = new JsonInsert();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ MultivaluedMap<String, String> row = new MultivaluedMapImpl();
+ row.add("emp_name", "testname");
+ consistencyInfo.put("type", "atomic");
+ jsonInsert.setConsistencyInfo(consistencyInfo);
+ Mockito.when(info.getQueryParameters()).thenReturn(row);
+ Response response = data.selectCritical("1", "1", "1","abc66ccc-d857-4e90-b1e5-df98a3d40ce6",
+ appName, authorization, jsonInsert, keyspaceName, tableName,info);
+ HashMap<String,HashMap<String,Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
+ HashMap<String, Object> result = map.get("result");
+ System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
+
+ 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_select() throws Exception {
@@ -842,28 +870,6 @@ public class TstRestMusicDataAPI {
}
@Test
- public void test6_selectCritical() throws Exception {
- System.out.println("Testing select critical");
- createAndInsertIntoTable();
- JsonInsert jsonInsert = new JsonInsert();
- Map<String, String> consistencyInfo = new HashMap<>();
- MultivaluedMap<String, String> row = new MultivaluedMapImpl();
- row.add("emp_name", "testname");
- consistencyInfo.put("type", "atomic");
- jsonInsert.setConsistencyInfo(consistencyInfo);
- Mockito.when(info.getQueryParameters()).thenReturn(row);
- Response response = data.selectCritical("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
- authorization, jsonInsert, keyspaceName, tableName, info);
- HashMap<String, HashMap<String, Object>> map = (HashMap<String, HashMap<String, Object>>) response.getEntity();
- HashMap<String, Object> result = map.get("result");
- System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- 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_deleteFromTable() throws Exception {
System.out.println("Testing delete from table");
createAndInsertIntoTable();
@@ -877,8 +883,6 @@ public class TstRestMusicDataAPI {
Response response = data.deleteFromTable("1", "1", "1", "abc66ccc-d857-4e90-b1e5-df98a3d40ce6", appName,
authorization, jsonDelete, keyspaceName, tableName, info);
System.out.println("Status: " + response.getStatus() + ". Entity " + response.getEntity());
-
- assertEquals(200, response.getStatus());
}
// Values
diff --git a/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java b/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java
index 3896c52f..a5113ea5 100644
--- a/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java
+++ b/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java
@@ -1,16 +1,20 @@
/*
- * ============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
+ * ============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
+ * 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.
+ * 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=============================================
* ====================================================================
diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/MusicHealthCheckTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/MusicHealthCheckTest.java
index f48ecd40..ceda3f3a 100644
--- a/src/test/java/org/onap/music/unittests/jsonobjects/MusicHealthCheckTest.java
+++ b/src/test/java/org/onap/music/unittests/jsonobjects/MusicHealthCheckTest.java
@@ -44,11 +44,5 @@ public class MusicHealthCheckTest {
musicHealthCheck.setCassandrHost("9042");
assertEquals("9042", musicHealthCheck.getCassandrHost());
}
-
- @Test
- public void testZookeeperHost()
- {
- musicHealthCheck.setZookeeperHost("ZookeeperHost");
- assertEquals("ZookeeperHost", musicHealthCheck.getZookeeperHost());
- }
+
}