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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
15 * ============LICENSE_END=============================================
16 * ====================================================================
17 *******************************************************************************/
19 package org.onap.music.datastore;
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;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.mockito.Mockito;
32 import org.mockito.Spy;
34 public class ConditionTest {
37 private Condition condition;
38 private Map<String, Object> conditions;
39 private PreparedQueryObject selectQueryForTheRow;
43 conditions = Mockito.mock(Map.class);
44 selectQueryForTheRow = Mockito.mock(PreparedQueryObject.class);
45 condition = spy(new Condition(conditions, selectQueryForTheRow));
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);