a826a983f52e85d64bc2f599a755296d750c9cff
[aaf/authz.git] / auth / auth-batch / src / test / java / org / onap / aaf / auth / batch / helpers / JU_CQLBatchTest.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
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  * ============LICENSE_END====================================================
19  *
20  */
21
22 package org.onap.aaf.auth.batch.helpers;
23
24 import static org.junit.Assert.assertNull;
25 import static org.mockito.MockitoAnnotations.initMocks;
26
27 import java.io.IOException;
28 import java.lang.reflect.Field;
29
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.mockito.Mock;
33 import org.mockito.Mockito;
34 import org.onap.aaf.auth.env.AuthzTrans;
35 import org.onap.aaf.misc.env.APIException;
36 import org.onap.aaf.misc.env.LogTarget;
37 import org.onap.aaf.misc.env.TimeTaken;
38
39 import com.datastax.driver.core.ResultSet;
40 import com.datastax.driver.core.Session;
41
42 public class JU_CQLBatchTest {
43
44     @Mock
45     AuthzTrans trans;
46
47     @Mock
48     Session session;
49
50     @Mock
51     LogTarget lg;
52
53     CQLBatch cqlBatchObj;
54
55     @Before
56     public void setUp() throws APIException, IOException {
57         initMocks(this);
58         Mockito.doReturn(lg).when(trans).info();
59         cqlBatchObj = new CQLBatch(lg, session);
60         Mockito.doReturn(Mockito.mock(TimeTaken.class)).when(trans).start(
61                 Mockito.anyString(), Mockito.anyInt(), Mockito.anyString());
62
63         Mockito.doReturn(Mockito.mock(ResultSet.class)).when(session)
64                 .execute(Mockito.anyString());
65     }
66
67     @Test
68     public void testExecute() {
69         ResultSet retVal = cqlBatchObj.execute();
70         assertNull(retVal);
71
72         Field f;
73         try {
74             f = CQLBatch.class.getDeclaredField("sb");
75             f.setAccessible(true);
76             f.set(cqlBatchObj, new StringBuilder("test"));
77             retVal = cqlBatchObj.execute();
78         } catch (NoSuchFieldException | SecurityException
79                 | IllegalArgumentException | IllegalAccessException e) {
80             // TODO Auto-generated catch block
81             e.printStackTrace();
82         }
83
84     }
85
86     @Test
87     public void testExecute2() {
88         ResultSet retVal = cqlBatchObj.execute(false);
89         assertNull(retVal);
90
91         Field f;
92         try {
93             f = CQLBatch.class.getDeclaredField("sb");
94             f.setAccessible(true);
95             f.set(cqlBatchObj, new StringBuilder("test"));
96             retVal = cqlBatchObj.execute(true);
97             cqlBatchObj.toString();
98         } catch (NoSuchFieldException | SecurityException
99                 | IllegalArgumentException | IllegalAccessException e) {
100             // TODO Auto-generated catch block
101             e.printStackTrace();
102         }
103
104     }
105
106     @Test
107     public void testSingleExec() {
108         ResultSet retVal = cqlBatchObj.singleExec(new StringBuilder("test"),
109                 true);
110         assertNull(retVal);
111
112         retVal = cqlBatchObj.singleExec(new StringBuilder("test"), false);
113     }
114
115     @Test
116     public void testTouch() {
117         cqlBatchObj.touch("test", 0, 4, true);
118
119     }
120
121 }