2 * ============LICENSE_START====================================================
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
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.
18 * ============LICENSE_END====================================================
22 package org.onap.aaf.auth.dao.cass;
24 import static org.junit.Assert.assertTrue;
25 import static org.mockito.MockitoAnnotations.initMocks;
27 import java.io.IOException;
28 import java.lang.reflect.Constructor;
29 import java.lang.reflect.Field;
30 import java.lang.reflect.InvocationTargetException;
31 import java.lang.reflect.Method;
33 import java.net.URISyntaxException;
34 import java.util.ArrayList;
35 import java.util.Date;
36 import java.util.List;
38 import org.junit.Before;
39 import org.junit.Test;
40 import org.mockito.Mock;
41 import org.mockito.Mockito;
42 import org.onap.aaf.auth.dao.AbsCassDAO;
43 import org.onap.aaf.auth.dao.AbsCassDAO.CRUD;
44 import org.onap.aaf.auth.dao.AbsCassDAO.PSInfo;
45 import org.onap.aaf.auth.dao.cass.CacheInfoDAO.Data;
46 import org.onap.aaf.auth.env.AuthzEnv;
47 import org.onap.aaf.auth.env.AuthzTrans;
48 import org.onap.aaf.auth.layer.Result;
49 import org.onap.aaf.cadi.CadiException;
50 import org.onap.aaf.cadi.SecuritySetter;
51 import org.onap.aaf.cadi.client.Rcli;
52 import org.onap.aaf.cadi.config.Config;
53 import org.onap.aaf.cadi.http.HMangr;
54 import org.onap.aaf.misc.env.APIException;
55 import org.onap.aaf.misc.env.Env;
56 import org.onap.aaf.misc.env.LogTarget;
57 import org.onap.aaf.misc.env.TimeTaken;
59 import com.datastax.driver.core.Cluster;
60 import com.datastax.driver.core.ColumnDefinitions;
61 import com.datastax.driver.core.PreparedId;
62 import com.datastax.driver.core.PreparedStatement;
63 import com.datastax.driver.core.ResultSet;
64 import com.datastax.driver.core.Row;
65 import com.datastax.driver.core.Session;
66 import com.datastax.driver.core.Statement;
67 import com.datastax.driver.core.exceptions.DriverException;
69 import io.netty.util.concurrent.Future;
71 public class JU_CacheInfoDAO {
85 public void setUp() throws APIException, IOException {
87 Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).warn();
88 Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error();
89 Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug();
90 Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info();
91 Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).init();
92 Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LATITUDE);
93 Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LONGITUDE);
94 Mockito.doReturn(session).when(cluster).connect("test");
98 public void testInit() {
99 TimeTaken tt = Mockito.mock(TimeTaken.class);
100 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE);
101 Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB);
102 Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB);
103 Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB);
104 Mockito.doNothing().when(tt).done();
105 CacheInfoDAO.Data data = new CacheInfoDAO.Data();
106 PSInfo createPS = Mockito.mock(PSInfo.class);
107 Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]);
108 Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data);
110 CacheInfoDAOImpl daoObj=null;
112 daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS);
113 } catch (APIException | IOException e) {
114 // TODO Auto-generated catch block
118 Result<Data> retVal = daoObj.create(trans, data);
119 assertTrue(retVal.status == 0);
123 public void testTouch() {
124 TimeTaken tt = Mockito.mock(TimeTaken.class);
125 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE);
126 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO Touch segments test: 1", Env.REMOTE);
127 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO Touch segments test: 1,2", Env.REMOTE);
128 Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB);
129 Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB);
130 Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB);
131 Mockito.doNothing().when(tt).done();
133 Mockito.doReturn(logTarget).when(env).debug();
135 CacheInfoDAO.Data data = new CacheInfoDAO.Data();
136 PSInfo createPS = Mockito.mock(PSInfo.class);
137 Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]);
138 Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data);
140 CacheInfoDAOImpl daoObj=null;
142 daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS);
143 } catch (APIException | IOException e) {
144 // TODO Auto-generated catch block
148 Result<Void> retVal = daoObj.touch(trans, "test", 1, 2);
149 assertTrue(retVal.status == 0);
150 Mockito.doThrow(DriverException.class).when(session).executeAsync(Mockito.anyString());
151 daoObj.startUpdate(env, Mockito.mock(HMangr.class), Mockito.mock(SecuritySetter.class), "12.0.0.1", 8080);
152 retVal = daoObj.touch(trans, "test", 1, 2);
156 daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS);
157 } catch (APIException | IOException e) {
158 // TODO Auto-generated catch block
161 assertTrue(retVal.status == Result.ERR_Backend);
162 Mockito.doThrow(APIException.class).when(session).executeAsync(Mockito.anyString());
163 retVal = daoObj.touch(trans, "test", 1, 2);
165 daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS);
166 } catch (APIException | IOException e) {
167 // TODO Auto-generated catch block
170 assertTrue(retVal.status == Result.ERR_Backend);
171 Mockito.doThrow(IOException.class).when(session).executeAsync(Mockito.anyString());
173 daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS);
174 } catch (APIException | IOException e) {
175 // TODO Auto-generated catch block
178 retVal = daoObj.touch(trans, "test", 1, 2);
179 assertTrue(retVal.status == Result.ERR_Backend);
183 public void testCheck() {
184 TimeTaken tt = Mockito.mock(TimeTaken.class);
185 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE);
186 Mockito.doReturn(tt).when(trans).start("Check Table Timestamps", Env.REMOTE);
187 Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB);
188 Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB);
189 Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB);
190 Mockito.doNothing().when(tt).done();
191 CacheInfoDAO.Data data = new CacheInfoDAO.Data();
192 PSInfo createPS = Mockito.mock(PSInfo.class);
193 Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]);
194 Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data);
196 CacheInfoDAOImpl daoObj=null;
197 PreparedStatement ps = Mockito.mock(PreparedStatement.class);
198 Mockito.doReturn(ps).when(session).prepare(Mockito.anyString());
199 Mockito.doReturn(Mockito.mock(ColumnDefinitions.class)).when(ps).getVariables();
200 Mockito.doReturn(Mockito.mock(PreparedId.class)).when(ps).getPreparedId();
202 daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS);
203 } catch (APIException | IOException e) {
204 // TODO Auto-generated catch block
208 ResultSet resultSet = Mockito.mock(ResultSet.class);
209 List<Row> rowList = new ArrayList<>();
210 Mockito.doReturn(rowList).when(resultSet).all();
211 Mockito.doReturn(resultSet).when(session).execute(Mockito.any(Statement.class));
212 Result<Void> retVal = daoObj.check(trans);
213 assertTrue(retVal.status == 0);
215 Row row = Mockito.mock(Row.class);
216 Mockito.doReturn("test").when(row).getString(Mockito.anyInt());
218 row = Mockito.mock(Row.class);
219 Mockito.doReturn("test").when(row).getString(Mockito.anyInt());
220 Mockito.doReturn(100).when(row).getInt(Mockito.anyInt());
222 retVal = daoObj.check(trans);
223 assertTrue(retVal.status == 0);
225 Mockito.doThrow(DriverException.class).when(session).execute(Mockito.any(Statement.class));
226 retVal = daoObj.check(trans);
227 assertTrue(retVal.status == Result.ERR_Backend);
229 daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS);
230 } catch (APIException | IOException e) {
231 // TODO Auto-generated catch block
234 Mockito.doThrow(APIException.class).when(session).execute(Mockito.any(Statement.class));
235 retVal = daoObj.check(trans);
236 assertTrue(retVal.status == Result.ERR_Backend);
238 daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS);
239 } catch (APIException | IOException e) {
240 // TODO Auto-generated catch block
243 Mockito.doThrow(IOException.class).when(session).execute(Mockito.any(Statement.class));
244 retVal = daoObj.check(trans);
245 assertTrue(retVal.status == Result.ERR_Backend);
248 public void testStopUpdate() {
250 CacheInfoDAO.stopUpdate();
256 public void testGet() {
257 TimeTaken tt = Mockito.mock(TimeTaken.class);
258 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE);
259 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO Touch segments test1: 1011", Env.REMOTE);
260 Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB);
261 Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB);
262 Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB);
263 Mockito.doNothing().when(tt).done();
264 CacheInfoDAO.Data data = new CacheInfoDAO.Data();
265 PSInfo createPS = Mockito.mock(PSInfo.class);
266 Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]);
267 Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data);
269 CacheInfoDAOImpl daoObj=null;
271 daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS);
272 Date retVal = daoObj.get(trans, "test", 1011);
273 // assertTrue(retVal.status == 0);
274 retVal = daoObj.get(trans, "test1", 1011);
275 } catch (APIException | IOException e) {
281 public void testWasMOdified() {
282 TimeTaken tt = Mockito.mock(TimeTaken.class);
283 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE);
284 Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB);
285 Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB);
286 Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB);
287 Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE);
288 Mockito.doNothing().when(tt).done();
289 CacheInfoDAO.Data data = new CacheInfoDAO.Data("test",1);
290 PSInfo createPS = Mockito.mock(PSInfo.class);
292 HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class);
293 Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]);
294 Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any());
296 CacheInfoDAOImpl daoObj=null;
298 daoObj = new CacheInfoDAOImpl(trans, cluster, "test", createPS);
299 } catch (APIException | IOException e) {
300 // TODO Auto-generated catch block
303 daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"});
309 public void testInfoLoader(){
310 TimeTaken tt = Mockito.mock(TimeTaken.class);
311 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE);
312 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO Touch segments test1: 1011", Env.REMOTE);
313 Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB);
314 Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB);
315 Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB);
316 Mockito.doNothing().when(tt).done();
317 CacheInfoDAO.Data data1 = new CacheInfoDAO.Data();
318 PSInfo createPS = Mockito.mock(PSInfo.class);
319 Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]);
320 Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data1);
322 CacheInfoDAOImpl daoObj=null;
324 daoObj = new CacheInfoDAOImpl(trans, cluster, "test", createPS);
325 } catch (APIException | IOException e) {
326 // TODO Auto-generated catch block
329 Class[] classList = CacheInfoDAO.class.getDeclaredClasses();
330 Class<?> innerClass = null;
331 for(Class indCls:classList) {
332 if(indCls.getName().contains("InfoLoader")) {
336 Constructor<?> constructor = innerClass.getDeclaredConstructors()[0];
337 constructor.setAccessible(true);
339 Object obj = constructor.newInstance(1);
340 Method innnerClassMtd;
342 CacheInfoDAO.Data data = new CacheInfoDAO.Data();
343 Row row = Mockito.mock(Row.class);
344 innnerClassMtd = innerClass.getMethod("load", new Class[] {CacheInfoDAO.Data.class, Row.class});
345 innnerClassMtd.invoke(obj, new Object[] {data, row});
347 innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {CacheInfoDAO.Data.class, Integer.TYPE, Object[].class });
348 innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"}});
350 innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {CacheInfoDAO.Data.class, Integer.TYPE, Object[].class });
351 innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"}});
352 } catch (InstantiationException e) {
353 // TODO Auto-generated catch block
355 } catch (IllegalAccessException e) {
356 // TODO Auto-generated catch block
358 } catch (IllegalArgumentException e) {
359 // TODO Auto-generated catch block
361 } catch (InvocationTargetException e) {
362 // TODO Auto-generated catch block
364 } catch (NoSuchMethodException e) {
365 // TODO Auto-generated catch block
367 } catch (SecurityException e) {
368 // TODO Auto-generated catch block
374 public void testCacheUpdate(){
375 TimeTaken tt = Mockito.mock(TimeTaken.class);
376 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE);
377 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO Touch segments test1: 1011", Env.REMOTE);
378 Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB);
379 Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB);
380 Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB);
381 Mockito.doNothing().when(tt).done();
382 CacheInfoDAO.Data data1 = new CacheInfoDAO.Data();
383 PSInfo createPS = Mockito.mock(PSInfo.class);
384 Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]);
385 Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data1);
387 CacheInfoDAOImpl daoObj=null;
389 daoObj = new CacheInfoDAOImpl(trans, cluster, "test", createPS);
390 } catch (APIException | IOException e) {
391 // TODO Auto-generated catch block
394 Class[] classList = CacheInfoDAO.class.getDeclaredClasses();
395 Class<?> innerClass = null;
396 for(Class indCls:classList) {
397 if(indCls.getName().contains("CacheUpdate")) {
401 Constructor<?> constructor = innerClass.getDeclaredConstructors()[0];
402 constructor.setAccessible(true);
404 Object obj = constructor.newInstance(env,Mockito.mock(HMangr.class), Mockito.mock(SecuritySetter.class), "12.0.0.1", 8080);
406 Class<?> innerInnerClass = Class.forName("org.onap.aaf.auth.dao.cass.CacheInfoDAO$CacheUpdate$CacheClear");
407 Constructor<?> innerConstructor = innerInnerClass.getDeclaredConstructors()[0];
408 innerConstructor.setAccessible(true);
409 Object innerClassObj = innerConstructor.newInstance(obj, trans);
411 Method innnerClassMtd;
413 CacheInfoDAO.Data data = new CacheInfoDAO.Data();
414 Row row = Mockito.mock(Row.class);
415 Rcli rcli = Mockito.mock(Rcli.class);
416 URI uri = new URI("ftp","admin:admin@geeksforgeeks.org:1234","/path/data","tt","ttd");
417 Mockito.doReturn(uri).when(rcli).getURI();
418 Mockito.doReturn(Mockito.mock(org.onap.aaf.cadi.client.Future.class)).when(rcli).delete("/mgmt/cache/null/null", "application/Void+json;q=1.0;charset=utf-8;version=2.0,application/json;q=1.0;version=2.0,*/*;q=1.0");
420 innnerClassMtd = innerInnerClass.getMethod("code", new Class[] {Rcli.class});
421 innnerClassMtd.invoke(innerClassObj, new Object[] {rcli});
423 org.onap.aaf.cadi.client.Future futureObj = Mockito.mock(org.onap.aaf.cadi.client.Future.class);
424 Mockito.doReturn(futureObj).when(rcli).delete("/mgmt/cache/null/null", "application/Void+json;q=1.0;charset=utf-8;version=2.0,application/json;q=1.0;version=2.0,*/*;q=1.0");
425 Mockito.doReturn(true).when(futureObj).get(0);
426 innnerClassMtd.invoke(innerClassObj, new Object[] {rcli});
428 uri = new URI("ftp","12.0.0.1:8080","/path/data","tt","ttd");
429 Mockito.doReturn(uri).when(rcli).getURI();
430 innnerClassMtd.invoke(innerClassObj, new Object[] {rcli});
431 } catch (InstantiationException e) {
432 // TODO Auto-generated catch block
434 } catch (IllegalAccessException e) {
435 // TODO Auto-generated catch block
437 } catch (IllegalArgumentException e) {
438 // TODO Auto-generated catch block
440 } catch (InvocationTargetException e) {
441 // TODO Auto-generated catch block
443 } catch (SecurityException e) {
444 // TODO Auto-generated catch block
446 } catch (ClassNotFoundException e) {
447 // TODO Auto-generated catch block
449 } catch (NoSuchMethodException e) {
450 // TODO Auto-generated catch block
452 } catch (URISyntaxException e) {
453 // TODO Auto-generated catch block
455 } catch (APIException e) {
456 // TODO Auto-generated catch block
458 } catch (CadiException e) {
459 // TODO Auto-generated catch block
465 public void testIntHolder(){
466 TimeTaken tt = Mockito.mock(TimeTaken.class);
467 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE);
468 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO Touch segments test1: 1011", Env.REMOTE);
469 Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB);
470 Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB);
471 Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB);
472 Mockito.doNothing().when(tt).done();
473 CacheInfoDAO.Data data1 = new CacheInfoDAO.Data();
474 PSInfo createPS = Mockito.mock(PSInfo.class);
475 Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]);
476 Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data1);
478 CacheInfoDAOImpl daoObj=null;
480 daoObj = new CacheInfoDAOImpl(trans, cluster, "test", createPS);
481 } catch (APIException | IOException e) {
482 // TODO Auto-generated catch block
485 Class[] classList = CacheInfoDAO.class.getDeclaredClasses();
486 Class<?> innerClass = null;
487 for(Class indCls:classList) {
488 if(indCls.getName().contains("CacheUpdate")) {
492 Constructor<?> constructor = innerClass.getDeclaredConstructors()[0];
493 constructor.setAccessible(true);
495 Object obj = constructor.newInstance(env,Mockito.mock(HMangr.class), Mockito.mock(SecuritySetter.class), "12.0.0.1", 8080);
497 Class<?> innerInnerClass = Class.forName("org.onap.aaf.auth.dao.cass.CacheInfoDAO$CacheUpdate$IntHolder");
498 Constructor<?> innerConstructor = innerInnerClass.getDeclaredConstructors()[0];
499 innerConstructor.setAccessible(true);
500 int[] a = new int[10];
501 Object innerClassObj = innerConstructor.newInstance(obj, a);
503 Method innnerClassMtd=null;
505 CacheInfoDAO.Data data = new CacheInfoDAO.Data();
506 Row row = Mockito.mock(Row.class);
507 Rcli rcli = Mockito.mock(Rcli.class);
508 URI uri = new URI("ftp","admin:admin@geeksforgeeks.org:1234","/path/data","tt","ttd");
509 Mockito.doReturn(uri).when(rcli).getURI();
510 Mockito.doReturn(Mockito.mock(org.onap.aaf.cadi.client.Future.class)).when(rcli).delete("/mgmt/cache/null/null", "application/Void+json;q=1.0;charset=utf-8;version=2.0,application/json;q=1.0;version=2.0,*/*;q=1.0");
512 Method[] allMtds = innerInnerClass.getDeclaredMethods();
513 for(Method indMtd:allMtds) {
514 if(indMtd.getName().contains("add")) {
515 innnerClassMtd = indMtd;
518 innnerClassMtd.invoke(innerClassObj, new Object[] {a});
521 } catch (InstantiationException e) {
522 // TODO Auto-generated catch block
524 } catch (IllegalAccessException e) {
525 // TODO Auto-generated catch block
527 } catch (IllegalArgumentException e) {
528 // TODO Auto-generated catch block
530 } catch (InvocationTargetException e) {
531 // TODO Auto-generated catch block
533 } catch (SecurityException e) {
534 // TODO Auto-generated catch block
536 } catch (ClassNotFoundException e) {
537 // TODO Auto-generated catch block
539 } catch (URISyntaxException e) {
540 // TODO Auto-generated catch block
542 } catch (APIException e) {
543 // TODO Auto-generated catch block
545 } catch (CadiException e) {
546 // TODO Auto-generated catch block
552 public void testSecondConstructor() {
553 TimeTaken tt = Mockito.mock(TimeTaken.class);
554 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE);
555 Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB);
556 Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB);
557 Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB);
558 Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE);
559 Mockito.doNothing().when(tt).done();
560 CacheInfoDAO.Data data = new CacheInfoDAO.Data();
561 AbsCassDAO absCassDAO = Mockito.mock(AbsCassDAO.class);
564 CacheInfoDAO daoObj = new CacheInfoDAO(trans, absCassDAO);
565 } catch (APIException | IOException e) {
566 // TODO Auto-generated catch block
572 class CacheInfoDAOImpl extends CacheInfoDAO{
574 public CacheInfoDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace,CacheInfoDAO.Data data,PSInfo createPS ) throws APIException, IOException {
575 super(trans, cluster, keyspace);
576 this.createPS = createPS;
577 // setPs(this, createPS, "psByUser");
578 // setPs(this, createPS, "psByApprover");
579 // setPs(this, createPS, "psByTicket");
580 // setPs(this, createPS, "psByStatus");
581 // setSession(this, Mockito.mock(Session.class));
584 public CacheInfoDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace,PSInfo readPS ) throws APIException, IOException {
585 super(trans, cluster, keyspace);
586 this.readPS = readPS;
590 public void setPs(CacheInfoDAOImpl CacheInfoDAOObj, PSInfo psInfoObj, String methodName) {
593 nsDaoField = CacheInfoDAO.class.getDeclaredField(methodName);
595 nsDaoField.setAccessible(true);
596 // remove final modifier from field
597 Field modifiersField = Field.class.getDeclaredField("modifiers");
598 modifiersField.setAccessible(true);
599 // modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL);
601 nsDaoField.set(CacheInfoDAOObj, psInfoObj);
602 } catch (NoSuchFieldException | SecurityException e) {
603 // TODO Auto-generated catch block
605 } catch (IllegalArgumentException e) {
606 // TODO Auto-generated catch block
608 } catch (IllegalAccessException e) {
609 // TODO Auto-generated catch block
615 public void setSession(CacheInfoDAOImpl CacheInfoDAOObj, Session session) {
618 nsDaoField = AbsCassDAO.class.getDeclaredField("session");
620 nsDaoField.setAccessible(true);
621 // remove final modifier from field
622 Field modifiersField = Field.class.getDeclaredField("modifiers");
623 modifiersField.setAccessible(true);
624 // modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL);
625 nsDaoField.set(CacheInfoDAOObj, session);
626 } catch (NoSuchFieldException | SecurityException e) {
627 // TODO Auto-generated catch block
629 } catch (IllegalArgumentException e) {
630 // TODO Auto-generated catch block
632 } catch (IllegalAccessException e) {
633 // TODO Auto-generated catch block