1 /*******************************************************************************
2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (c) 2019 AT&T Intellectual Property
6 * ===================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * ============LICENSE_END=============================================
20 * ====================================================================
21 *******************************************************************************/
23 package org.onap.music.lockingservice.cassandra;
25 import static org.junit.Assert.assertEquals;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.onap.music.lockingservice.cassandra.MusicLockState.LockStatus;
30 public class MusicLockStateTest {
32 MusicLockState musicLockState;
36 musicLockState = new MusicLockState(LockStatus.LOCKED, "", true);
40 public void testGetLeasePeriod() {
41 musicLockState.setLeasePeriod(200L);
42 assertEquals(200L, musicLockState.getLeasePeriod());
46 public void testIsNeedToSyncQuorum() {
47 assertEquals(true, musicLockState.isNeedToSyncQuorum());
51 public void testGetLeaseStartTime() {
52 musicLockState.setLeaseStartTime(200L);
53 assertEquals(200L, musicLockState.getLeaseStartTime());
57 public void testGetLockStatus() {
58 musicLockState.setLockStatus(LockStatus.LOCKED);
59 assertEquals(LockStatus.LOCKED, musicLockState.getLockStatus());
63 public void testGetLockHolder() {
64 musicLockState.setLockHolder("lockHolder");
65 assertEquals("lockHolder", musicLockState.getLockHolder());
69 public void testGetErrorMessage() {
70 MusicLockState musicLockState2 = new MusicLockState("This is error message");
71 assertEquals("This is error message", musicLockState2.getErrorMessage());
75 public void testSerialize() {
76 byte[] serializedBytes = musicLockState.serialize();
77 MusicLockState musicLockState3 = musicLockState.deSerialize(serializedBytes);
78 assertEquals(musicLockState.getLeasePeriod(),musicLockState3.getLeasePeriod());
79 assertEquals(musicLockState.isNeedToSyncQuorum(),musicLockState3.isNeedToSyncQuorum());
80 assertEquals(musicLockState.getLeaseStartTime(),musicLockState3.getLeaseStartTime());
81 assertEquals(musicLockState.getLockStatus(),musicLockState3.getLockStatus());
82 assertEquals(musicLockState.getLockHolder(),musicLockState3.getLockHolder());
83 assertEquals(musicLockState.getErrorMessage(),musicLockState3.getErrorMessage());