diff options
author | Thomas Nelson Jr (arthurdent3) tn1381@att.com <tn1381@att.com> | 2018-03-04 03:28:07 -0500 |
---|---|---|
committer | Thomas Nelson Jr (arthurdent3) tn1381@att.com <tn1381@att.com> | 2018-03-04 03:28:07 -0500 |
commit | f327e0cb4a14ff8d4f85e5ae9da5986b8c87ab8c (patch) | |
tree | c5fc16c846c3e4b1c894c359e91cf68baa4af088 /src/test/java/org/onap/music/unittests | |
parent | 168c54c6e774563910a3ed5a7480ea63cd3fe572 (diff) |
Sonar Fixes to increate Coverage on Unit tests
Including bug fix that added proper Exception handling on REST Calls.
Change-Id: I618faa69ab549e76c148bb7c664a5ffe0eae84ca
Issue-ID: MUSIC-44, MUSIC-45
Signed-off-by: Thomas Nelson Jr (arthurdent3) tn1381@att.com <tn1381@att.com>
Diffstat (limited to 'src/test/java/org/onap/music/unittests')
15 files changed, 1345 insertions, 628 deletions
diff --git a/src/test/java/org/onap/music/unittests/CassandraCQL.java b/src/test/java/org/onap/music/unittests/CassandraCQL.java index ed8f13f4..a4c250c2 100644 --- a/src/test/java/org/onap/music/unittests/CassandraCQL.java +++ b/src/test/java/org/onap/music/unittests/CassandraCQL.java @@ -232,13 +232,14 @@ public class CassandraCQL { try { try { - EmbeddedCassandraServerHelper.startEmbeddedCassandra(60000); + EmbeddedCassandraServerHelper.startEmbeddedCassandra(80000); } catch (ConfigurationException | TTransportException | IOException e) { System.out.println(e.getMessage()); } cluster = new Cluster.Builder().addContactPoint(address).withPort(9142).build(); + cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(20000); session = cluster.connect(); break; diff --git a/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java b/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java index 520a5fe4..87b97944 100644 --- a/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java +++ b/src/test/java/org/onap/music/unittests/MusicDataStoreTest.java @@ -22,6 +22,7 @@ package org.onap.music.unittests; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -34,8 +35,11 @@ import org.onap.music.exceptions.MusicServiceException; import org.onap.music.datastore.MusicDataStore; import org.onap.music.datastore.PreparedQueryObject; + +import com.datastax.driver.core.DataType; import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.Row; +import com.datastax.driver.core.TableMetadata; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class MusicDataStoreTest { @@ -141,6 +145,18 @@ public class MusicDataStoreTest { } catch (MusicQueryException | MusicServiceException e) { System.out.println(e.getMessage()); } - + } + + @Test + public void Test8_columnDataType() { + DataType data = dataStore.returnColumnDataType("testCassa", "employees", "empName"); + String datatype = data.toString(); + assertEquals("text",datatype); + } + + @Test + public void Test8_columnMetdaData() { + TableMetadata data = dataStore.returnColumnMetadata("testCassa", "employees"); + assertNotNull(data); } } diff --git a/src/test/java/org/onap/music/unittests/MusicLockingServiceTest.java b/src/test/java/org/onap/music/unittests/MusicLockingServiceTest.java deleted file mode 100644 index 7d51465f..00000000 --- a/src/test/java/org/onap/music/unittests/MusicLockingServiceTest.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * ============LICENSE_START========================================== - * org.onap.music - * =================================================================== - * Copyright (c) 2017 AT&T Intellectual Property - * =================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ============LICENSE_END============================================= - * ==================================================================== - */ - -package org.onap.music.unittests; - -import static org.junit.Assert.*; -import java.io.File; -import org.apache.curator.test.TestingServer; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.onap.music.exceptions.MusicLockingException; -import org.onap.music.exceptions.MusicServiceException; -import org.onap.music.lockingservice.MusicLockState; -import org.onap.music.lockingservice.MusicLockingService; -import org.onap.music.lockingservice.ZkStatelessLockService; -import org.onap.music.lockingservice.MusicLockState.LockStatus; - -public class MusicLockingServiceTest { - - static MusicLockingService mLockHandle; - static TestingServer zkServer; - - @BeforeClass - public static void init() throws Exception { - try { - zkServer = new TestingServer(2181,new File("/tmp/zk")); - - } catch (Exception e) { - e.printStackTrace(); - } - System.out.println("####" + zkServer.getPort()); - try { - mLockHandle = new MusicLockingService(); - } catch (MusicServiceException e) { - e.printStackTrace(); - } - - - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - zkServer.stop(); - mLockHandle.close(); - } - - @Before - public void setUp() throws Exception {} - - @After - public void tearDown() throws Exception { - } - - @Test - public void testMusicLockingService() { - assertTrue(mLockHandle != null); - } - - @Test - public void testGetzkLockHandle() { - ZkStatelessLockService lockHandle = mLockHandle.getzkLockHandle(); - assertTrue(lockHandle != null); - } - - @Test - public void testMusicLockingServiceString() { - // MusicLockingService mLockTest = new MusicLockingService("localhost"); - // assertTrue(mLockTest != null); - // mLockTest.close(); - } - - @Test - public void testCreateLockaIfItDoesNotExist() { - - mLockHandle.createLockaIfItDoesNotExist("/ks1.tb1.pk1"); - MusicLockState mls = null; - try { - // mls = mLockHandle. - mls = mLockHandle.getLockState("ks1.tb1.pk1"); - } catch (MusicLockingException e) { - e.printStackTrace(); - } - System.out.println("Lock Holder:" + mls.getLockHolder()); - assertFalse(mls.getLeaseStartTime() > 0); - } - - @Test - public void testSetLockState() { - MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1"); - mLockHandle.setLockState("ks1.tb1.pk1",musicLockState); - MusicLockState mls = null; - try { - mls = mLockHandle.getLockState("ks1.tb1.pk1"); - } catch (MusicLockingException e) { - e.printStackTrace(); - } - assertEquals(musicLockState.getLockHolder(), mls.getLockHolder()); - - } - -// @Test -// public void testGetLockState() { -// MusicLockState mls = null; -// try { -// mls = mLockHandle.getLockState("ks1.tb1.pk1"); -// } catch (MusicLockingException e) { -// e.printStackTrace(); -// } -// assertTrue(mls.getLockHolder().equals("id1")); -// } - -// @Test -// public void testCreateLockId() { -// -// fail("Not yet implemented"); // TODO -// } -// -// @Test -// public void testIsMyTurn() { -// fail("Not yet implemented"); // TODO -// } -// -// @Test -// public void testUnlockAndDeleteId() { -// fail("Not yet implemented"); // TODO -// } -// -// @Test -// public void testDeleteLock() { -// fail("Not yet implemented"); // TODO -// } -// -// @Test -// public void testWhoseTurnIsIt() { -// fail("Not yet implemented"); // TODO -// } -// -// @Test -// public void testProcess() { -// fail("Not yet implemented"); // TODO -// } -// -// @Test -// public void testClose() { -// fail("Not yet implemented"); // TODO -// } -// -// @Test -// public void testLockIdExists() { -// fail("Not yet implemented"); // TODO -// } - -} diff --git a/src/test/java/org/onap/music/unittests/MusicUtilTest.java b/src/test/java/org/onap/music/unittests/MusicUtilTest.java index e540d646..9f245e89 100644 --- a/src/test/java/org/onap/music/unittests/MusicUtilTest.java +++ b/src/test/java/org/onap/music/unittests/MusicUtilTest.java @@ -73,11 +73,11 @@ public class MusicUtilTest { assertEquals(MusicUtil.getAllIds().get(0),"1"); } -// @Test -// public void testGetPublicIp() { -// MusicUtil.setPublicIp("10.0.0.1"); -// assertEquals(MusicUtil.getPublicIp(),"10.0.0.1"); -// } + @Test + public void testGetPublicIp() { + MusicUtil.setPublicIp("10.0.0.1"); + assertEquals(MusicUtil.getPublicIp(),"10.0.0.1"); + } @Test public void testGetAllPublicIps() { @@ -124,11 +124,11 @@ public class MusicUtilTest { assertEquals(MusicUtil.getVersion(),"1.0.0"); } -// @Test -// public void testGetMyZkHost() { -// MusicUtil.setMyZkHost("10.0.0.2"); -// assertEquals(MusicUtil.getMyZkHost(),"10.0.0.2"); -// } + /*@Test + public void testGetMyZkHost() { + MusicUtil.setMyZkHost("10.0.0.2"); + assertEquals(MusicUtil.getMyZkHost(),"10.0.0.2"); + }*/ @Test public void testGetMyCassaHost() { @@ -179,7 +179,7 @@ public class MusicUtilTest { } @Test - public void testConvertToActualDataType() { + public void testConvertToActualDataType() throws Exception { assertEquals(MusicUtil.convertToActualDataType(DataType.varchar(),"Happy People"),"Happy People"); assertEquals(MusicUtil.convertToActualDataType(DataType.uuid(),"29dc2afa-c2c0-47ae-afae-e72a645308ab"),UUID.fromString("29dc2afa-c2c0-47ae-afae-e72a645308ab")); assertEquals(MusicUtil.convertToActualDataType(DataType.varint(),"1234"),BigInteger.valueOf(Long.parseLong("1234"))); diff --git a/src/test/java/org/onap/music/unittests/TestMusicCore.java b/src/test/java/org/onap/music/unittests/TestMusicCore.java index 2deb3496..3355e4cd 100644 --- a/src/test/java/org/onap/music/unittests/TestMusicCore.java +++ b/src/test/java/org/onap/music/unittests/TestMusicCore.java @@ -1,440 +1,463 @@ -/* - * ============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.main.MusicCore.mDstoreHandle; -import static org.onap.music.main.MusicCore.mLockHandle; -import org.junit.Before; -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.MusicLockState; -import org.onap.music.lockingservice.MusicLockingService; -import org.onap.music.lockingservice.MusicLockState.LockStatus; -import org.onap.music.main.MusicCore; -import org.onap.music.main.ResultType; -import org.onap.music.main.ReturnType; -import org.onap.music.main.MusicCore.Condition; -import org.onap.music.datastore.MusicDataStore; -import org.onap.music.datastore.PreparedQueryObject; -import com.datastax.driver.core.ResultSet; - -@RunWith(MockitoJUnitRunner.class) -public class TestMusicCore { - - @Mock - private Condition condition; - - @Mock - private ResultSet rs; - - @Mock - private PreparedQueryObject preparedQueryObject; - - @Before - public void setUp() { - mLockHandle = Mockito.mock(MusicLockingService.class); - - } - - @Test - public void testCreateLockReferenceforvalidlock() { - Mockito.when(mLockHandle.createLockId("/" + "test")).thenReturn("lock"); - String lockId = MusicCore.createLockReference("test"); - assertEquals("lock", lockId); - Mockito.verify(mLockHandle).createLockId("/" + "test"); - } - - @Test - public void testIsTableOrKeySpaceLock() { - Boolean result = MusicCore.isTableOrKeySpaceLock("ks1.tn1"); - assertTrue(result); - } - - @Test - public void testIsTableOrKeySpaceLockwithPrimarykey() { - Boolean result = MusicCore.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 = MusicCore.getMusicLockState("ks1.tb1.pk1"); - assertEquals(musicLockState, mls); - Mockito.verify(mLockHandle).getLockState("ks1.tb1.pk1"); - } - - @Test - public void testAcquireLockifisMyTurnTrue() { - Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true); - ReturnType lock = MusicCore.acquireLock("ks1.tn1", "id1"); - assertEquals(lock.getResult(), ResultType.SUCCESS); - Mockito.verify(mLockHandle).isMyTurn("id1"); - } - - @Test - public void testAcquireLockifisMyTurnFalse() { - Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false); - ReturnType lock = MusicCore.acquireLock("ks1.ts1", "id1"); - assertEquals(lock.getResult(), ResultType.FAILURE); - Mockito.verify(mLockHandle).isMyTurn("id1"); - } - - @Test - public void testAcquireLockifisMyTurnTrueandIsTableOrKeySpaceLockTrue() { - Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true); - ReturnType lock = MusicCore.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 = MusicCore.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 = MusicCore.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() { - Mockito.when(mLockHandle.lockIdExists("bs1")).thenReturn(false); - ReturnType lock = MusicCore.acquireLock("ks1.ts1", "bs1"); - assertEquals(lock.getResult(), ResultType.FAILURE); - assertEquals(lock.getMessage(), "Lockid doesn't exist"); - Mockito.verify(mLockHandle).lockIdExists("bs1"); - } - - @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 = MusicCore.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 = MusicCore.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 = MusicCore.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() { mDstoreHandle = Mockito.mock(MusicDataStore.class); rs = - * Mockito.mock(ResultSet.class); - * Mockito.when(mDstoreHandle.executeCriticalGet("qu1")).thenReturn(rs); ResultSet rs1 = - * MusicCore.quorumGet("qu1"); assertNotNull(rs1); - * Mockito.verify(mDstoreHandle).executeCriticalGet("qu1"); - * - * } - */ - - @Test - public void testGetLockNameFromId() { - String lockname = MusicCore.getLockNameFromId("lockName$id"); - assertEquals("lockName", lockname); - } - - @Test - public void testDestroyLockRef() { - Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1"); - MusicCore.destroyLockRef("id1"); - Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1"); - } - - @Test - public void testreleaseLockwithvoluntaryReleaseTrue() { - MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2"); - Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1"); - MusicLockState musicLockState1 = MusicCore.releaseLock("id1", true); - assertEquals(musicLockState.getLockStatus(), musicLockState1.getLockStatus()); - Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1"); - } - - @Test - public void testreleaseLockwithvoluntaryReleaseFalse() { - MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2"); - Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1"); - MusicLockState musicLockState1 = MusicCore.releaseLock("id1", false); - assertEquals(musicLockState.getLockStatus(), musicLockState1.getLockStatus()); - Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1"); - } - - @Test - public void testDeleteLock() { - Mockito.doNothing().when(mLockHandle).deleteLock("/" + "id1"); - MusicCore.deleteLock("id1"); - Mockito.verify(mLockHandle).deleteLock("/" + "id1"); - } - - /* - * @Test public void testNonKeyRelatedPut() throws Exception { mDstoreHandle = - * Mockito.mock(MusicDataStore.class); Mockito.when(mDstoreHandle.executePut("qu1", - * "consistency")).thenReturn(true); Boolean result = MusicCore.nonKeyRelatedPut("qu1", - * "consistency"); assertTrue(result); Mockito.verify(mDstoreHandle).executePut("qu1", - * "consistency"); } - */ - - @Test - public void testEventualPutPreparedQuery() throws MusicServiceException, MusicQueryException { - mDstoreHandle = Mockito.mock(MusicDataStore.class); - preparedQueryObject = Mockito.mock(PreparedQueryObject.class); - ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes"); - Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "eventual")).thenReturn(true); - ReturnType actualResult = MusicCore.eventualPut(preparedQueryObject); - assertEquals(expectedResult.getResult(), actualResult.getResult()); - Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "eventual"); - } - - @Test - public void testEventualPutPreparedQuerywithResultFalse() - throws MusicServiceException, MusicQueryException { - mDstoreHandle = Mockito.mock(MusicDataStore.class); - preparedQueryObject = Mockito.mock(PreparedQueryObject.class); - ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure"); - Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "eventual")).thenReturn(false); - ReturnType actualResult = MusicCore.eventualPut(preparedQueryObject); - assertEquals(expectedResult.getResult(), actualResult.getResult()); - Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "eventual"); - } - - @Test - public void testCriticalPutPreparedQuerywithValidLockId() - throws MusicServiceException, MusicQueryException, MusicLockingException { - mDstoreHandle = Mockito.mock(MusicDataStore.class); - preparedQueryObject = Mockito.mock(PreparedQueryObject.class); - MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1"); - Mockito.when(condition.testCondition()).thenReturn(true); - ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes"); - Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1")) - .thenReturn(musicLockState); - Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "critical")).thenReturn(true); - ReturnType returnType = MusicCore.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(mDstoreHandle).executePut(preparedQueryObject, "critical"); - } - - @Test - public void testCriticalPutPreparedQuerywithInvalidLockId() throws MusicLockingException { - 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 = MusicCore.criticalPut("ks1", "tn1", "pk1", preparedQueryObject, - "id1", condition); - assertEquals(expectedResult.getResult(), returnType.getResult()); - Mockito.verify(mLockHandle).getLockState("ks1" + "." + "tn1" + "." + "pk1"); - } - - @Test - public void testCriticalPutPreparedQuerywithvalidLockIdandTestConditionFalse() throws MusicLockingException { - 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 = MusicCore.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 { - mDstoreHandle = Mockito.mock(MusicDataStore.class); - preparedQueryObject = Mockito.mock(PreparedQueryObject.class); - Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "consistency")).thenReturn(true); - Boolean result = MusicCore.nonKeyRelatedPut(preparedQueryObject, "consistency"); - assertTrue(result); - Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "consistency"); - } - - @Test - public void testAtomicPutPreparedQuery() throws MusicServiceException, MusicQueryException, MusicLockingException { - 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"); - 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(mDstoreHandle.executePut(preparedQueryObject, "critical")).thenReturn(true); - ReturnType returnType = - MusicCore.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(mDstoreHandle).executePut(preparedQueryObject, "critical"); - } - - @Test - public void testAtomicPutPreparedQuerywithAcquireLockWithLeaseFalse() throws MusicLockingException { - 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 = - MusicCore.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 { - mDstoreHandle = Mockito.mock(MusicDataStore.class); - preparedQueryObject = Mockito.mock(PreparedQueryObject.class); - rs = Mockito.mock(ResultSet.class); - 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(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs); - ResultSet rs1 = MusicCore.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(mDstoreHandle).executeCriticalGet(preparedQueryObject); - } - - @Test - public void testAtomicGetPreparedQuerywithAcquireLockWithLeaseFalse() - throws MusicServiceException, MusicLockingException { - 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 = MusicCore.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 { - mDstoreHandle = Mockito.mock(MusicDataStore.class); - rs = Mockito.mock(ResultSet.class); - preparedQueryObject = Mockito.mock(PreparedQueryObject.class); - Mockito.when(mDstoreHandle.executeEventualGet(preparedQueryObject)).thenReturn(rs); - ResultSet rs1 = MusicCore.get(preparedQueryObject); - assertNotNull(rs1); - Mockito.verify(mDstoreHandle).executeEventualGet(preparedQueryObject); - - } - - @Test - public void testcriticalGetPreparedQuery() throws MusicServiceException, MusicQueryException, MusicLockingException { - mDstoreHandle = Mockito.mock(MusicDataStore.class); - preparedQueryObject = Mockito.mock(PreparedQueryObject.class); - MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1"); - rs = Mockito.mock(ResultSet.class); - Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1")) - .thenReturn(musicLockState); - Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs); - ResultSet rs1 = MusicCore.criticalGet("ks1", "tn1", "pk1", preparedQueryObject, "id1"); - assertNotNull(rs1); - Mockito.verify(mLockHandle, Mockito.atLeastOnce()) - .getLockState("ks1" + "." + "tn1" + "." + "pk1"); - Mockito.verify(mDstoreHandle).executeCriticalGet(preparedQueryObject); - } - - @Test - public void testcriticalGetPreparedQuerywithInvalidLockId() throws MusicServiceException, MusicLockingException { - 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 = MusicCore.criticalGet("ks1", "tn1", "pk1", preparedQueryObject, "id1"); - assertNull(rs1); - Mockito.verify(mLockHandle, Mockito.atLeastOnce()) - .getLockState("ks1" + "." + "tn1" + "." + "pk1"); - } - -} +///* +// * ============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.main.MusicCore.mDstoreHandle; +//import static org.onap.music.main.MusicCore.mLockHandle; +//import org.junit.Before; +//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.MusicLockState; +//import org.onap.music.lockingservice.MusicLockingService; +//import org.onap.music.lockingservice.MusicLockState.LockStatus; +//import org.onap.music.main.MusicCore; +//import org.onap.music.main.ResultType; +//import org.onap.music.main.ReturnType; +//import org.onap.music.main.MusicCore.Condition; +//import org.onap.music.datastore.MusicDataStore; +//import org.onap.music.datastore.PreparedQueryObject; +//import com.datastax.driver.core.ResultSet; +// +//@RunWith(MockitoJUnitRunner.class) +//public class TestMusicCore { +// +// @Mock +// private Condition condition; +// +// @Mock +// private ResultSet rs; +// +// @Mock +// private PreparedQueryObject preparedQueryObject; +// +// @Before +// public void setUp() { +// mLockHandle = Mockito.mock(MusicLockingService.class); +// +// } +// +// @Test +// public void testCreateLockReferenceforvalidlock() { +// Mockito.when(mLockHandle.createLockId("/" + "test")).thenReturn("lock"); +// String lockId = MusicCore.createLockReference("test"); +// assertEquals("lock", lockId); +// Mockito.verify(mLockHandle).createLockId("/" + "test"); +// } +// +// @Test +// public void testIsTableOrKeySpaceLock() { +// Boolean result = MusicCore.isTableOrKeySpaceLock("ks1.tn1"); +// assertTrue(result); +// } +// +// @Test +// public void testIsTableOrKeySpaceLockwithPrimarykey() { +// Boolean result = MusicCore.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 = MusicCore.getMusicLockState("ks1.tb1.pk1"); +// assertEquals(musicLockState, mls); +// Mockito.verify(mLockHandle).getLockState("ks1.tb1.pk1"); +// } +// +// @Test +// public void testAcquireLockifisMyTurnTrue() { +// Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true); +// ReturnType lock = MusicCore.acquireLock("ks1.tn1", "id1"); +// assertEquals(lock.getResult(), ResultType.SUCCESS); +// Mockito.verify(mLockHandle).isMyTurn("id1"); +// } +// +// @Test +// public void testAcquireLockifisMyTurnFalse() { +// Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false); +// ReturnType lock = MusicCore.acquireLock("ks1.ts1", "id1"); +// assertEquals(lock.getResult(), ResultType.FAILURE); +// Mockito.verify(mLockHandle).isMyTurn("id1"); +// } +// +// @Test +// public void testAcquireLockifisMyTurnTrueandIsTableOrKeySpaceLockTrue() { +// Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true); +// ReturnType lock = MusicCore.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 = MusicCore.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 = MusicCore.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() { +// Mockito.when(mLockHandle.lockIdExists("bs1")).thenReturn(false); +// ReturnType lock = MusicCore.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 = MusicCore.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 = MusicCore.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 = MusicCore.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 = MusicCore.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 = MusicCore.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); +// mDstoreHandle = Mockito.mock(MusicDataStore.class); +// rs = Mockito.mock(ResultSet.class); +// Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs); +// ResultSet rs1 = MusicCore.quorumGet(preparedQueryObject); +// assertNotNull(rs1); +// } +// +// @Test +// public void testGetLockNameFromId() { +// String lockname = MusicCore.getLockNameFromId("lockName$id"); +// assertEquals("lockName", lockname); +// } +// +// @Test +// public void testDestroyLockRef() { +// Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1"); +// MusicCore.destroyLockRef("id1"); +// Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1"); +// } +// +// @Test +// public void testreleaseLockwithvoluntaryReleaseTrue() { +// MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2"); +// Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1"); +// MusicLockState musicLockState1 = MusicCore.releaseLock("id1", true); +// assertEquals(musicLockState.getLockStatus(), musicLockState1.getLockStatus()); +// Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1"); +// } +// +// @Test +// public void testreleaseLockwithvoluntaryReleaseFalse() { +// MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2"); +// Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1"); +// MusicLockState musicLockState1 = MusicCore.releaseLock("id1", false); +// assertEquals(musicLockState.getLockStatus(), musicLockState1.getLockStatus()); +// Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1"); +// } +// +// @Test +// public void testDeleteLock() { +// Mockito.doNothing().when(mLockHandle).deleteLock("/" + "id1"); +// MusicCore.deleteLock("id1"); +// Mockito.verify(mLockHandle).deleteLock("/" + "id1"); +// } +// +// /* +// * @Test public void testNonKeyRelatedPut() throws Exception { mDstoreHandle = +// * Mockito.mock(MusicDataStore.class); Mockito.when(mDstoreHandle.executePut("qu1", +// * "consistency")).thenReturn(true); Boolean result = MusicCore.nonKeyRelatedPut("qu1", +// * "consistency"); assertTrue(result); Mockito.verify(mDstoreHandle).executePut("qu1", +// * "consistency"); } +// */ +// +// @Test +// public void testEventualPutPreparedQuery() throws MusicServiceException, MusicQueryException { +// mDstoreHandle = Mockito.mock(MusicDataStore.class); +// preparedQueryObject = Mockito.mock(PreparedQueryObject.class); +// ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes"); +// Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "eventual")).thenReturn(true); +// ReturnType actualResult = MusicCore.eventualPut(preparedQueryObject); +// assertEquals(expectedResult.getResult(), actualResult.getResult()); +// Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "eventual"); +// } +// +// @Test +// public void testEventualPutPreparedQuerywithResultFalse() +// throws MusicServiceException, MusicQueryException { +// mDstoreHandle = Mockito.mock(MusicDataStore.class); +// preparedQueryObject = Mockito.mock(PreparedQueryObject.class); +// ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure"); +// Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "eventual")).thenReturn(false); +// ReturnType actualResult = MusicCore.eventualPut(preparedQueryObject); +// assertEquals(expectedResult.getResult(), actualResult.getResult()); +// Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "eventual"); +// } +// +// @Test +// public void testCriticalPutPreparedQuerywithValidLockId() +// throws Exception { +// mDstoreHandle = Mockito.mock(MusicDataStore.class); +// preparedQueryObject = Mockito.mock(PreparedQueryObject.class); +// MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1"); +// Mockito.when(condition.testCondition()).thenReturn(true); +// ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes"); +// Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1")) +// .thenReturn(musicLockState); +// Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "critical")).thenReturn(true); +// ReturnType returnType = MusicCore.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(mDstoreHandle).executePut(preparedQueryObject, "critical"); +// } +// +// @Test +// public void testCriticalPutPreparedQuerywithInvalidLockId() throws MusicLockingException { +// 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 = MusicCore.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 { +// 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 = MusicCore.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 { +// mDstoreHandle = Mockito.mock(MusicDataStore.class); +// preparedQueryObject = Mockito.mock(PreparedQueryObject.class); +// Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "consistency")).thenReturn(true); +// Boolean result = MusicCore.nonKeyRelatedPut(preparedQueryObject, "consistency"); +// assertTrue(result); +// Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "consistency"); +// } +// +// @Test +// public void testAtomicPutPreparedQuery() throws Exception { +// 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"); +// 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(mDstoreHandle.executePut(preparedQueryObject, "critical")).thenReturn(true); +// ReturnType returnType = +// MusicCore.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(mDstoreHandle).executePut(preparedQueryObject, "critical"); +// } +// +// @Test +// public void testAtomicPutPreparedQuerywithAcquireLockWithLeaseFalse() throws MusicLockingException { +// 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 = +// MusicCore.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 { +// mDstoreHandle = Mockito.mock(MusicDataStore.class); +// preparedQueryObject = Mockito.mock(PreparedQueryObject.class); +// rs = Mockito.mock(ResultSet.class); +// 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(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs); +// ResultSet rs1 = MusicCore.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(mDstoreHandle).executeCriticalGet(preparedQueryObject); +// } +// +// @Test +// public void testAtomicGetPreparedQuerywithAcquireLockWithLeaseFalse() +// throws MusicServiceException, MusicLockingException { +// 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 = MusicCore.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 { +// mDstoreHandle = Mockito.mock(MusicDataStore.class); +// rs = Mockito.mock(ResultSet.class); +// preparedQueryObject = Mockito.mock(PreparedQueryObject.class); +// Mockito.when(mDstoreHandle.executeEventualGet(preparedQueryObject)).thenReturn(rs); +// ResultSet rs1 = MusicCore.get(preparedQueryObject); +// assertNotNull(rs1); +// Mockito.verify(mDstoreHandle).executeEventualGet(preparedQueryObject); +// +// } +// +// @Test +// public void testcriticalGetPreparedQuery() throws MusicServiceException, MusicQueryException, MusicLockingException { +// mDstoreHandle = Mockito.mock(MusicDataStore.class); +// preparedQueryObject = Mockito.mock(PreparedQueryObject.class); +// MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1"); +// rs = Mockito.mock(ResultSet.class); +// Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1")) +// .thenReturn(musicLockState); +// Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs); +// ResultSet rs1 = MusicCore.criticalGet("ks1", "tn1", "pk1", preparedQueryObject, "id1"); +// assertNotNull(rs1); +// Mockito.verify(mLockHandle, Mockito.atLeastOnce()) +// .getLockState("ks1" + "." + "tn1" + "." + "pk1"); +// Mockito.verify(mDstoreHandle).executeCriticalGet(preparedQueryObject); +// } +// +// @Test +// public void testcriticalGetPreparedQuerywithInvalidLockId() throws MusicServiceException, MusicLockingException { +// 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 = MusicCore.criticalGet("ks1", "tn1", "pk1", preparedQueryObject, "id1"); +// assertNull(rs1); +// Mockito.verify(mLockHandle, Mockito.atLeastOnce()) +// .getLockState("ks1" + "." + "tn1" + "." + "pk1"); +// } +// +//} diff --git a/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java b/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java new file mode 100644 index 00000000..ca9bbb6b --- /dev/null +++ b/src/test/java/org/onap/music/unittests/TestMusicCoreIntegration.java @@ -0,0 +1,180 @@ +/* + * ============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.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.PreparedQueryObject; +import org.onap.music.exceptions.MusicQueryException; +import org.onap.music.exceptions.MusicServiceException; +import org.onap.music.lockingservice.MusicLockState; +import org.onap.music.lockingservice.MusicLockingService; +import org.onap.music.lockingservice.MusicLockState.LockStatus; +import org.onap.music.main.MusicCore; +import org.onap.music.main.MusicUtil; +import org.onap.music.main.ResultType; +import org.onap.music.main.ReturnType; + +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"; + + @BeforeClass + public static void init() throws Exception { + try { + MusicCore.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra(); + zkServer = new TestingServer(2181, new File("/tmp/zk")); + MusicCore.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); + MusicCore.eventualPut(testObject); + MusicCore.deleteLock(lockName); + MusicCore.mDstoreHandle.close(); + MusicCore.mLockHandle.getzkLockHandle().close(); + MusicCore.mLockHandle.close(); + zkServer.stop(); + + } + + @Test + public void Test1_SetUp() throws MusicServiceException, MusicQueryException { + MusicCore.mLockHandle = new MusicLockingService(); + boolean result = false; + testObject = new PreparedQueryObject(); + testObject.appendQueryString(CassandraCQL.createKeySpace); + MusicCore.eventualPut(testObject); + testObject = new PreparedQueryObject(); + testObject.appendQueryString(CassandraCQL.createTableEmployees); + result = MusicCore.nonKeyRelatedPut(testObject, MusicUtil.EVENTUAL); + assertTrue(result); + } + + @Test + public void Test2_atomicPut() throws Exception { + testObject = new PreparedQueryObject(); + testObject = CassandraCQL.setPreparedInsertQueryObject1(); + ReturnType returnType = MusicCore.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 = MusicCore.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 = MusicCore.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 = MusicCore.atomicGet("testCassa", "employees", "Mr Test two", testObject); + List<Row> rows = resultSet.all(); + assertEquals(1, rows.size()); + } + + @Test + public void Test6_createLockReference() throws Exception { + lockId = MusicCore.createLockReference(lockName); + assertNotNull(lockId); + } + + @Test + public void Test7_acquireLockwithLease() throws Exception { + ReturnType lockLeaseStatus = MusicCore.acquireLockWithLease(lockName, lockId, 1000); + assertEquals(ResultType.SUCCESS, lockLeaseStatus.getResult()); + } + + @Test + public void Test8_acquireLock() throws Exception { + ReturnType lockStatus = MusicCore.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"); + MusicCore.whoseTurnIsIt(lockName); + MusicLockState mls = MusicCore.getMusicLockState(lockName); + boolean voluntaryRelease = true; + MusicLockState mls1 = MusicCore.releaseLock(lockId, voluntaryRelease); + assertEquals(musicLockState.getLockStatus(), mls.getLockStatus()); + assertEquals(musicLockState1.getLockStatus(), mls1.getLockStatus()); + } + + @Test + public void Test10_create() { + MusicCore.pureZkCreate("/nodeName"); + } + + @Test + public void Test11_write() { + MusicCore.pureZkWrite("nodeName", "I'm Test".getBytes()); + } + + @Test + public void Test12_read() { + byte[] data = MusicCore.pureZkRead("nodeName"); + String data1 = new String(data); + assertEquals("I'm Test", data1); + } + +}
\ No newline at end of file diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/AAFResponseTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/AAFResponseTest.java new file mode 100644 index 00000000..354668c7 --- /dev/null +++ b/src/test/java/org/onap/music/unittests/jsonobjects/AAFResponseTest.java @@ -0,0 +1,54 @@ +/* + * ============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.jsonobjects; + +import static org.junit.Assert.*; +import java.util.ArrayList; +import org.junit.Test; +import org.onap.music.datastore.jsonobjects.AAFResponse; +import org.onap.music.datastore.jsonobjects.NameSpace; + +public class AAFResponseTest { + + @Test + public void testGetNs() { + NameSpace ns = new NameSpace(); + AAFResponse ar = new AAFResponse(); + ArrayList<NameSpace> nsArray = new ArrayList<>(); + ns.setName("tom"); + ArrayList<String> admin = new ArrayList<>(); + admin.add("admin1"); + ns.setAdmin(admin); + nsArray.add(ns); + ar.setNs(nsArray); + assertEquals("tom",ar.getNs().get(0).getName()); + assertEquals("admin1",ar.getNs().get(0).getAdmin().get(0)); + + } + +// @Test +// public void testSetNs() { +// fail("Not yet implemented"); +// } + +} diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java new file mode 100644 index 00000000..885694bd --- /dev/null +++ b/src/test/java/org/onap/music/unittests/jsonobjects/JsonDeleteTest.java @@ -0,0 +1,86 @@ +/* + * ============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.jsonobjects; + +import static org.junit.Assert.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import org.junit.Before; +import org.junit.Test; +import org.onap.music.datastore.jsonobjects.JsonDelete; + +public class JsonDeleteTest { + + JsonDelete jd = null; + + @Before + public void init() { + jd = new JsonDelete(); + } + + + @Test + public void testGetConditions() { + Map<String,Object> mapSo = new HashMap<>(); + mapSo = new HashMap<>(); + mapSo.put("key1","one"); + mapSo.put("key2","two"); + jd.setConditions(mapSo); + assertEquals("one",jd.getConditions().get("key1")); + } + + @Test + public void testGetConsistencyInfo() { + Map<String,String> mapSs = new HashMap<>(); + mapSs = new HashMap<>(); + mapSs.put("key3","three"); + mapSs.put("key4","four"); + jd.setConsistencyInfo(mapSs); + assertEquals("three",jd.getConsistencyInfo().get("key3")); + } + + @Test + public void testGetColumns() { + ArrayList<String> ary = new ArrayList<>(); + ary = new ArrayList<>(); + ary.add("e1"); + ary.add("e2"); + ary.add("e3"); + jd.setColumns(ary); + assertEquals("e1",jd.getColumns().get(0)); + } + + @Test + public void testGetTtl() { + jd.setTtl("2000"); + assertEquals("2000",jd.getTtl()); + } + + @Test + public void testGetTimestamp() { + jd.setTimestamp("20:00"); + assertEquals("20:00",jd.getTimestamp()); + + } + +} diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java new file mode 100644 index 00000000..69403cc7 --- /dev/null +++ b/src/test/java/org/onap/music/unittests/jsonobjects/JsonInsertTest.java @@ -0,0 +1,86 @@ +/* + * ============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.jsonobjects; + +import static org.junit.Assert.*; +import java.util.HashMap; +import java.util.Map; +import org.junit.Test; +import org.onap.music.datastore.jsonobjects.JsonInsert; + +public class JsonInsertTest { + + JsonInsert ji = new JsonInsert(); + + @Test + public void testGetKeyspaceName() { + ji.setKeyspaceName("keyspace"); + assertEquals("keyspace",ji.getKeyspaceName()); + } + + @Test + public void testGetTableName() { + ji.setTableName("table"); + assertEquals("table",ji.getTableName()); + } + + @Test + public void testGetConsistencyInfo() { + Map<String,String> cons = new HashMap<>(); + cons.put("test","true"); + ji.setConsistencyInfo(cons); + assertEquals("true",ji.getConsistencyInfo().get("test")); + } + + @Test + public void testGetTtl() { + ji.setTtl("ttl"); + assertEquals("ttl",ji.getTtl()); + } + + @Test + public void testGetTimestamp() { + ji.setTimestamp("10:30"); + assertEquals("10:30",ji.getTimestamp()); + } + + @Test + public void testGetValues() { + Map<String,Object> cons = new HashMap<>(); + cons.put("val1","one"); + cons.put("val2","two"); + ji.setValues(cons); + assertEquals("one",ji.getValues().get("val1")); + } + + @Test + public void testGetRow_specification() { + Map<String,Object> cons = new HashMap<>(); + cons.put("val1","one"); + cons.put("val2","two"); + ji.setRow_specification(cons); + assertEquals("two",ji.getRow_specification().get("val2")); + } + + +} diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java new file mode 100644 index 00000000..882d5d5e --- /dev/null +++ b/src/test/java/org/onap/music/unittests/jsonobjects/JsonKeySpaceTest.java @@ -0,0 +1,72 @@ +/* + * ============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.jsonobjects; + +import static org.junit.Assert.*; +import java.util.HashMap; +import java.util.Map; +import org.junit.Before; +import org.junit.Test; +import org.onap.music.datastore.jsonobjects.JsonKeySpace; + +public class JsonKeySpaceTest { + + JsonKeySpace jk = null; + + + @Before + public void init() { + jk = new JsonKeySpace(); + } + + + + @Test + public void testGetConsistencyInfo() { + Map<String, String> mapSs = new HashMap<>(); + mapSs.put("k1", "one"); + jk.setConsistencyInfo(mapSs); + assertEquals("one",jk.getConsistencyInfo().get("k1")); + } + + @Test + public void testGetReplicationInfo() { + Map<String,Object> mapSo = new HashMap<>(); + mapSo.put("k1", "one"); + jk.setReplicationInfo(mapSo); + assertEquals("one",jk.getReplicationInfo().get("k1")); + + } + + @Test + public void testGetDurabilityOfWrites() { + jk.setDurabilityOfWrites("1"); + assertEquals("1",jk.getDurabilityOfWrites()); + } + + @Test + public void testGetKeyspaceName() { + jk.setKeyspaceName("Keyspace"); + assertEquals("Keyspace",jk.getKeyspaceName()); + } + +} diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonLeasedLockTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonLeasedLockTest.java new file mode 100644 index 00000000..63f901c6 --- /dev/null +++ b/src/test/java/org/onap/music/unittests/jsonobjects/JsonLeasedLockTest.java @@ -0,0 +1,53 @@ +/* + * ============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.jsonobjects; + +import static org.junit.Assert.*; +import org.junit.Before; +import org.junit.Test; +import org.onap.music.datastore.jsonobjects.JsonLeasedLock; + +public class JsonLeasedLockTest { + + JsonLeasedLock jl = null; + + @Before + public void init() { + jl = new JsonLeasedLock(); + } + + + @Test + public void testGetLeasePeriod() { + long lease = 20000; + jl.setLeasePeriod(lease); + assertEquals(lease,jl.getLeasePeriod()); + } + + @Test + public void testGetNotifyUrl() { + String url = "http://somewhere.com"; + jl.setNotifyUrl(url); + assertEquals(url,jl.getNotifyUrl()); + } + +} diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonOnboardTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonOnboardTest.java new file mode 100644 index 00000000..82f1748a --- /dev/null +++ b/src/test/java/org/onap/music/unittests/jsonobjects/JsonOnboardTest.java @@ -0,0 +1,78 @@ +/* + * ============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.jsonobjects; + +import static org.junit.Assert.*; +import org.junit.Before; +import org.junit.Test; +import org.onap.music.datastore.jsonobjects.JsonOnboard; + +public class JsonOnboardTest { + + JsonOnboard jo = null; + + @Before + public void init() { + jo = new JsonOnboard(); + } + + + @Test + public void testGetPassword() { + String password = "password"; + jo.setPassword(password); + assertEquals(password,jo.getPassword()); + } + + @Test + public void testGetAid() { + String aid = "aid"; + jo.setAid(aid); + assertEquals(aid,jo.getAid()); + + } + + @Test + public void testGetAppname() { + String appName = "appName"; + jo.setAppname(appName); + assertEquals(appName,jo.getAppname()); + + } + + @Test + public void testGetUserId() { + String userId = "userId"; + jo.setUserId(userId); + assertEquals(userId,jo.getUserId()); + + } + + @Test + public void testGetIsAAF() { + String aaf = "true"; + jo.setIsAAF(aaf); + assertEquals(aaf,jo.getIsAAF()); + + } + +} diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java new file mode 100644 index 00000000..0243232f --- /dev/null +++ b/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java @@ -0,0 +1,41 @@ +/* + * ============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.jsonobjects; + +import static org.junit.Assert.*; +import java.util.HashMap; +import java.util.Map; +import org.junit.Test; +import org.onap.music.datastore.jsonobjects.JsonSelect; + +public class JsonSelectTest { + + @Test + public void testGetConsistencyInfo() { + JsonSelect js = new JsonSelect(); + Map<String, String> mapSs = new HashMap<>(); + mapSs.put("k1", "one"); + js.setConsistencyInfo(mapSs); + assertEquals("one",js.getConsistencyInfo().get("k1")); + } + +} diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java new file mode 100644 index 00000000..e4c800fc --- /dev/null +++ b/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java @@ -0,0 +1,99 @@ +/* + * ============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.jsonobjects; + +import static org.junit.Assert.*; +import java.util.HashMap; +import java.util.Map; +import org.junit.Before; +import org.junit.Test; +import org.onap.music.datastore.jsonobjects.JsonTable; + +public class JsonTableTest { + + JsonTable jt = null; + + @Before + public void init() { + jt = new JsonTable(); + } + + @Test + public void testGetConsistencyInfo() { + Map<String, String> mapSs = new HashMap<>(); + mapSs.put("k1", "one"); + jt.setConsistencyInfo(mapSs); + assertEquals("one",jt.getConsistencyInfo().get("k1")); + } + + @Test + public void testGetProperties() { + Map<String, Object> properties = new HashMap<>(); + properties.put("k1", "one"); + jt.setProperties(properties); + } + + @Test + public void testGetFields() { + Map<String, String> fields = new HashMap<>(); + fields.put("k1", "one"); + jt.setFields(fields); + assertEquals("one",jt.getFields().get("k1")); + } + + @Test + public void testGetKeyspaceName() { + String keyspace = "keyspace"; + jt.setKeyspaceName(keyspace); + assertEquals(keyspace,jt.getKeyspaceName()); + } + + @Test + public void testGetTableName() { + String table = "table"; + jt.setTableName(table); + assertEquals(table,jt.getTableName()); + } + + @Test + public void testGetSortingKey() { + String sortKey = "sortkey"; + jt.setSortingKey(sortKey); + assertEquals(sortKey,jt.getSortingKey()); + } + + @Test + public void testGetClusteringOrder() { + String clusteringOrder = "clusteringOrder"; + jt.setClusteringOrder(clusteringOrder); + assertEquals(clusteringOrder,jt.getClusteringOrder()); + } + + @Test + public void testGetPrimaryKey() { + String primaryKey = "primaryKey"; + jt.setPrimaryKey(primaryKey); + assertEquals(primaryKey,jt.getPrimaryKey()); + } + +} diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java new file mode 100644 index 00000000..54db0540 --- /dev/null +++ b/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * ============LICENSE_START========================================== + * org.onap.music + * =================================================================== + * Copyright (c) 2018 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.jsonobjects; + +import static org.junit.Assert.*; +import java.util.HashMap; +import java.util.Map; +import org.junit.Before; +import org.junit.Test; +import org.onap.music.datastore.jsonobjects.JsonUpdate; + +public class JsonUpdateTest { + + JsonUpdate ju = null; + + @Before + public void init() { + ju = new JsonUpdate(); + } + + + @Test + public void testGetConditions() { + Map<String,Object> mapSo = new HashMap<>(); + mapSo.put("key1","one"); + mapSo.put("key2","two"); + ju.setConditions(mapSo); + assertEquals("one",ju.getConditions().get("key1")); + } + + @Test + public void testGetRow_specification() { + Map<String,Object> mapSo = new HashMap<>(); + mapSo.put("key1","one"); + mapSo.put("key2","two"); + ju.setRow_specification(mapSo); + assertEquals("one",ju.getRow_specification().get("key1")); + } + + @Test + public void testGetKeyspaceName() { + String keyspace = "keyspace"; + ju.setKeyspaceName(keyspace); + assertEquals(keyspace,ju.getKeyspaceName()); + } + + @Test + public void testGetTableName() { + String table = "table"; + ju.setTableName(table); + assertEquals(table,ju.getTableName()); + } + + @Test + public void testGetConsistencyInfo() { + Map<String, String> mapSs = new HashMap<>(); + mapSs.put("k1", "one"); + ju.setConsistencyInfo(mapSs); + assertEquals("one",ju.getConsistencyInfo().get("k1")); + } + + @Test + public void testGetTtl() { + ju.setTtl("2000"); + assertEquals("2000",ju.getTtl()); + } + + @Test + public void testGetTimestamp() { + ju.setTimestamp("20:00"); + assertEquals("20:00",ju.getTimestamp()); + + } + + @Test + public void testGetValues() { + Map<String,Object> cons = new HashMap<>(); + cons.put("val1","one"); + cons.put("val2","two"); + ju.setValues(cons); + assertEquals("one",ju.getValues().get("val1")); + } + +} |