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 } catch (APIException | IOException e) {
273 // TODO Auto-generated catch block
276 Date retVal = daoObj.get(trans, "test", 1011);
277 // assertTrue(retVal.status == 0);
278 retVal = daoObj.get(trans, "test1", 1011);
282 public void testWasMOdified() {
283 TimeTaken tt = Mockito.mock(TimeTaken.class);
284 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE);
285 Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB);
286 Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB);
287 Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB);
288 Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE);
289 Mockito.doNothing().when(tt).done();
290 CacheInfoDAO.Data data = new CacheInfoDAO.Data("test",1);
291 PSInfo createPS = Mockito.mock(PSInfo.class);
293 HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class);
294 Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]);
295 Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any());
297 CacheInfoDAOImpl daoObj=null;
299 daoObj = new CacheInfoDAOImpl(trans, cluster, "test", createPS);
300 } catch (APIException | IOException e) {
301 // TODO Auto-generated catch block
304 daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"});
310 public void testInfoLoader(){
311 TimeTaken tt = Mockito.mock(TimeTaken.class);
312 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE);
313 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO Touch segments test1: 1011", Env.REMOTE);
314 Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB);
315 Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB);
316 Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB);
317 Mockito.doNothing().when(tt).done();
318 CacheInfoDAO.Data data1 = new CacheInfoDAO.Data();
319 PSInfo createPS = Mockito.mock(PSInfo.class);
320 Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]);
321 Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data1);
323 CacheInfoDAOImpl daoObj=null;
325 daoObj = new CacheInfoDAOImpl(trans, cluster, "test", createPS);
326 } catch (APIException | IOException e) {
327 // TODO Auto-generated catch block
330 Class[] classList = CacheInfoDAO.class.getDeclaredClasses();
331 Class<?> innerClass = null;
332 for(Class indCls:classList) {
333 if(indCls.getName().contains("InfoLoader")) {
337 Constructor<?> constructor = innerClass.getDeclaredConstructors()[0];
338 constructor.setAccessible(true);
340 Object obj = constructor.newInstance(1);
341 Method innnerClassMtd;
343 CacheInfoDAO.Data data = new CacheInfoDAO.Data();
344 Row row = Mockito.mock(Row.class);
345 innnerClassMtd = innerClass.getMethod("load", new Class[] {CacheInfoDAO.Data.class, Row.class});
346 innnerClassMtd.invoke(obj, new Object[] {data, row});
348 innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {CacheInfoDAO.Data.class, Integer.TYPE, Object[].class });
349 innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"}});
351 innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {CacheInfoDAO.Data.class, Integer.TYPE, Object[].class });
352 innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"}});
353 } catch (InstantiationException e) {
354 // TODO Auto-generated catch block
356 } catch (IllegalAccessException e) {
357 // TODO Auto-generated catch block
359 } catch (IllegalArgumentException e) {
360 // TODO Auto-generated catch block
362 } catch (InvocationTargetException e) {
363 // TODO Auto-generated catch block
365 } catch (NoSuchMethodException e) {
366 // TODO Auto-generated catch block
368 } catch (SecurityException e) {
369 // TODO Auto-generated catch block
375 public void testCacheUpdate(){
376 TimeTaken tt = Mockito.mock(TimeTaken.class);
377 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE);
378 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO Touch segments test1: 1011", Env.REMOTE);
379 Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB);
380 Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB);
381 Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB);
382 Mockito.doNothing().when(tt).done();
383 CacheInfoDAO.Data data1 = new CacheInfoDAO.Data();
384 PSInfo createPS = Mockito.mock(PSInfo.class);
385 Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]);
386 Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data1);
388 CacheInfoDAOImpl daoObj=null;
390 daoObj = new CacheInfoDAOImpl(trans, cluster, "test", createPS);
391 } catch (APIException | IOException e) {
392 // TODO Auto-generated catch block
395 Class[] classList = CacheInfoDAO.class.getDeclaredClasses();
396 Class<?> innerClass = null;
397 for(Class indCls:classList) {
398 if(indCls.getName().contains("CacheUpdate")) {
402 Constructor<?> constructor = innerClass.getDeclaredConstructors()[0];
403 constructor.setAccessible(true);
405 Object obj = constructor.newInstance(env,Mockito.mock(HMangr.class), Mockito.mock(SecuritySetter.class), "12.0.0.1", 8080);
407 Class<?> innerInnerClass = Class.forName("org.onap.aaf.auth.dao.cass.CacheInfoDAO$CacheUpdate$CacheClear");
408 Constructor<?> innerConstructor = innerInnerClass.getDeclaredConstructors()[0];
409 innerConstructor.setAccessible(true);
410 Object innerClassObj = innerConstructor.newInstance(obj, trans);
412 Method innnerClassMtd;
414 CacheInfoDAO.Data data = new CacheInfoDAO.Data();
415 Row row = Mockito.mock(Row.class);
416 Rcli rcli = Mockito.mock(Rcli.class);
417 URI uri = new URI("ftp","admin:admin@geeksforgeeks.org:1234","/path/data","tt","ttd");
418 Mockito.doReturn(uri).when(rcli).getURI();
419 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");
421 innnerClassMtd = innerInnerClass.getMethod("code", new Class[] {Rcli.class});
422 innnerClassMtd.invoke(innerClassObj, new Object[] {rcli});
424 org.onap.aaf.cadi.client.Future futureObj = Mockito.mock(org.onap.aaf.cadi.client.Future.class);
425 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");
426 Mockito.doReturn(true).when(futureObj).get(0);
427 innnerClassMtd.invoke(innerClassObj, new Object[] {rcli});
429 uri = new URI("ftp","12.0.0.1:8080","/path/data","tt","ttd");
430 Mockito.doReturn(uri).when(rcli).getURI();
431 innnerClassMtd.invoke(innerClassObj, new Object[] {rcli});
432 } catch (InstantiationException e) {
433 // TODO Auto-generated catch block
435 } catch (IllegalAccessException e) {
436 // TODO Auto-generated catch block
438 } catch (IllegalArgumentException e) {
439 // TODO Auto-generated catch block
441 } catch (InvocationTargetException e) {
442 // TODO Auto-generated catch block
444 } catch (SecurityException e) {
445 // TODO Auto-generated catch block
447 } catch (ClassNotFoundException e) {
448 // TODO Auto-generated catch block
450 } catch (NoSuchMethodException e) {
451 // TODO Auto-generated catch block
453 } catch (URISyntaxException e) {
454 // TODO Auto-generated catch block
456 } catch (APIException e) {
457 // TODO Auto-generated catch block
459 } catch (CadiException e) {
460 // TODO Auto-generated catch block
466 public void testIntHolder(){
467 TimeTaken tt = Mockito.mock(TimeTaken.class);
468 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE);
469 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO Touch segments test1: 1011", Env.REMOTE);
470 Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB);
471 Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB);
472 Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB);
473 Mockito.doNothing().when(tt).done();
474 CacheInfoDAO.Data data1 = new CacheInfoDAO.Data();
475 PSInfo createPS = Mockito.mock(PSInfo.class);
476 Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]);
477 Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data1);
479 CacheInfoDAOImpl daoObj=null;
481 daoObj = new CacheInfoDAOImpl(trans, cluster, "test", createPS);
482 } catch (APIException | IOException e) {
483 // TODO Auto-generated catch block
486 Class[] classList = CacheInfoDAO.class.getDeclaredClasses();
487 Class<?> innerClass = null;
488 for(Class indCls:classList) {
489 if(indCls.getName().contains("CacheUpdate")) {
493 Constructor<?> constructor = innerClass.getDeclaredConstructors()[0];
494 constructor.setAccessible(true);
496 Object obj = constructor.newInstance(env,Mockito.mock(HMangr.class), Mockito.mock(SecuritySetter.class), "12.0.0.1", 8080);
498 Class<?> innerInnerClass = Class.forName("org.onap.aaf.auth.dao.cass.CacheInfoDAO$CacheUpdate$IntHolder");
499 Constructor<?> innerConstructor = innerInnerClass.getDeclaredConstructors()[0];
500 innerConstructor.setAccessible(true);
501 int[] a = new int[10];
502 Object innerClassObj = innerConstructor.newInstance(obj, a);
504 Method innnerClassMtd=null;
506 CacheInfoDAO.Data data = new CacheInfoDAO.Data();
507 Row row = Mockito.mock(Row.class);
508 Rcli rcli = Mockito.mock(Rcli.class);
509 URI uri = new URI("ftp","admin:admin@geeksforgeeks.org:1234","/path/data","tt","ttd");
510 Mockito.doReturn(uri).when(rcli).getURI();
511 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");
513 Method[] allMtds = innerInnerClass.getDeclaredMethods();
514 for(Method indMtd:allMtds) {
515 if(indMtd.getName().contains("add")) {
516 innnerClassMtd = indMtd;
519 innnerClassMtd.invoke(innerClassObj, new Object[] {a});
522 } catch (InstantiationException e) {
523 // TODO Auto-generated catch block
525 } catch (IllegalAccessException e) {
526 // TODO Auto-generated catch block
528 } catch (IllegalArgumentException e) {
529 // TODO Auto-generated catch block
531 } catch (InvocationTargetException e) {
532 // TODO Auto-generated catch block
534 } catch (SecurityException e) {
535 // TODO Auto-generated catch block
537 } catch (ClassNotFoundException e) {
538 // TODO Auto-generated catch block
540 } catch (URISyntaxException e) {
541 // TODO Auto-generated catch block
543 } catch (APIException e) {
544 // TODO Auto-generated catch block
546 } catch (CadiException e) {
547 // TODO Auto-generated catch block
553 public void testSecondConstructor() {
554 TimeTaken tt = Mockito.mock(TimeTaken.class);
555 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE);
556 Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB);
557 Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB);
558 Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB);
559 Mockito.doReturn(tt).when(trans).start("DELETE APPROVAL",Env.REMOTE);
560 Mockito.doNothing().when(tt).done();
561 CacheInfoDAO.Data data = new CacheInfoDAO.Data();
562 AbsCassDAO absCassDAO = Mockito.mock(AbsCassDAO.class);
565 CacheInfoDAO daoObj = new CacheInfoDAO(trans, absCassDAO);
566 } catch (APIException | IOException e) {
567 // TODO Auto-generated catch block
573 class CacheInfoDAOImpl extends CacheInfoDAO{
575 public CacheInfoDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace,CacheInfoDAO.Data data,PSInfo createPS ) throws APIException, IOException {
576 super(trans, cluster, keyspace);
577 this.createPS = createPS;
578 // setPs(this, createPS, "psByUser");
579 // setPs(this, createPS, "psByApprover");
580 // setPs(this, createPS, "psByTicket");
581 // setPs(this, createPS, "psByStatus");
582 // setSession(this, Mockito.mock(Session.class));
585 public CacheInfoDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace,PSInfo readPS ) throws APIException, IOException {
586 super(trans, cluster, keyspace);
587 this.readPS = readPS;
591 public void setPs(CacheInfoDAOImpl CacheInfoDAOObj, PSInfo psInfoObj, String methodName) {
594 nsDaoField = CacheInfoDAO.class.getDeclaredField(methodName);
596 nsDaoField.setAccessible(true);
597 // remove final modifier from field
598 Field modifiersField = Field.class.getDeclaredField("modifiers");
599 modifiersField.setAccessible(true);
600 // modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL);
602 nsDaoField.set(CacheInfoDAOObj, psInfoObj);
603 } catch (NoSuchFieldException | SecurityException e) {
604 // TODO Auto-generated catch block
606 } catch (IllegalArgumentException e) {
607 // TODO Auto-generated catch block
609 } catch (IllegalAccessException e) {
610 // TODO Auto-generated catch block
616 public void setSession(CacheInfoDAOImpl CacheInfoDAOObj, Session session) {
619 nsDaoField = AbsCassDAO.class.getDeclaredField("session");
621 nsDaoField.setAccessible(true);
622 // remove final modifier from field
623 Field modifiersField = Field.class.getDeclaredField("modifiers");
624 modifiersField.setAccessible(true);
625 // modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL);
626 nsDaoField.set(CacheInfoDAOObj, session);
627 } catch (NoSuchFieldException | SecurityException e) {
628 // TODO Auto-generated catch block
630 } catch (IllegalArgumentException e) {
631 // TODO Auto-generated catch block
633 } catch (IllegalAccessException e) {
634 // TODO Auto-generated catch block