JUnit test case coverage for Condition.java, JsonLock.java, MusicLockState.java,...
[music.git] / music-core / src / test / java / org / onap / music / datastore / ConditionTest.java
1 /*******************************************************************************
2  * ============LICENSE_START========================================== org.onap.music
3  * =================================================================== Copyright (c) 2019 AT&T
4  * Intellectual Property ===================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6  * in compliance with the License. You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software distributed under the License
11  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12  * or implied. See the License for the specific language governing permissions and limitations under
13  * the License.
14  * 
15  * ============LICENSE_END=============================================
16  * ====================================================================
17  *******************************************************************************/
18
19 package org.onap.music.datastore;
20
21 import org.onap.music.datastore.Condition;
22 import org.onap.music.datastore.PreparedQueryObject;
23 import org.onap.music.exceptions.MusicServiceException;
24 import com.datastax.driver.core.ResultSet;
25 import com.datastax.driver.core.Row;
26 import static org.junit.Assert.assertEquals;
27 import static org.mockito.Mockito.spy;
28 import java.util.Map;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.mockito.Mockito;
32 import org.mockito.Spy;
33
34 public class ConditionTest {
35
36     @Spy
37     private Condition condition;
38     private Map<String, Object> conditions;
39     private PreparedQueryObject selectQueryForTheRow;
40
41     @Before
42     public void setup() {
43         conditions = Mockito.mock(Map.class);
44         selectQueryForTheRow = Mockito.mock(PreparedQueryObject.class);
45         condition = spy(new Condition(conditions, selectQueryForTheRow));
46     }
47
48     @Test
49     public void testCondition() throws Exception {
50         ResultSet rs = Mockito.mock(ResultSet.class);
51         Row row = Mockito.mock(Row.class);
52         MusicDataStore dsHandle = Mockito.mock(MusicDataStore.class);
53         Mockito.when(rs.one()).thenReturn(row);
54         Mockito.doReturn(rs).when(condition).quorumGet(Mockito.any());
55         boolean result = false;
56         Mockito.when(dsHandle.doesRowSatisfyCondition(Mockito.any(), Mockito.any())).thenReturn(true);
57         Mockito.doReturn(dsHandle).when(condition).getDSHandle();
58         result = condition.testCondition();
59         assertEquals(true, result);
60     }
61 }