JUnit test case coverage for Condition.java, JsonLock.java, MusicLockState.java,...
[music.git] / music-core / src / test / java / org / onap / music / lockingservice / cassandra / MusicLockStateTest.java
1 /*******************************************************************************
2  * ============LICENSE_START==========================================
3  * org.onap.music
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
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *  
19  * ============LICENSE_END=============================================
20  * ====================================================================
21  *******************************************************************************/
22
23 package org.onap.music.lockingservice.cassandra;
24
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;
29
30 public class MusicLockStateTest {
31     
32     MusicLockState musicLockState;
33     
34     @Before
35     public void setup() {
36         musicLockState = new MusicLockState(LockStatus.LOCKED, "", true);
37     }
38     
39     @Test
40     public void testGetLeasePeriod() {
41         musicLockState.setLeasePeriod(200L);
42         assertEquals(200L, musicLockState.getLeasePeriod());
43     }
44     
45     @Test
46     public void testIsNeedToSyncQuorum() {
47         assertEquals(true, musicLockState.isNeedToSyncQuorum());
48     }
49     
50     @Test
51     public void testGetLeaseStartTime() {
52         musicLockState.setLeaseStartTime(200L);
53         assertEquals(200L, musicLockState.getLeaseStartTime());
54     }
55     
56     @Test
57     public void testGetLockStatus() {
58         musicLockState.setLockStatus(LockStatus.LOCKED);
59         assertEquals(LockStatus.LOCKED, musicLockState.getLockStatus());
60     }
61     
62     @Test
63     public void testGetLockHolder() {
64         musicLockState.setLockHolder("lockHolder");
65         assertEquals("lockHolder", musicLockState.getLockHolder());
66     }
67     
68     @Test
69     public void testGetErrorMessage() {
70         MusicLockState musicLockState2 = new MusicLockState("This is error message");
71         assertEquals("This is error message", musicLockState2.getErrorMessage());
72     }
73     
74     @Test
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());
84     }
85     
86 }