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.List;
37 import org.junit.Before;
38 import org.junit.Test;
39 import org.mockito.Mock;
40 import org.mockito.Mockito;
41 import org.onap.aaf.auth.dao.AbsCassDAO;
42 import org.onap.aaf.auth.dao.AbsCassDAO.CRUD;
43 import org.onap.aaf.auth.dao.AbsCassDAO.PSInfo;
44 import org.onap.aaf.auth.dao.cass.CacheInfoDAO.Data;
45 import org.onap.aaf.auth.env.AuthzEnv;
46 import org.onap.aaf.auth.env.AuthzTrans;
47 import org.onap.aaf.auth.layer.Result;
48 import org.onap.aaf.cadi.CadiException;
49 import org.onap.aaf.cadi.SecuritySetter;
50 import org.onap.aaf.cadi.client.Rcli;
51 import org.onap.aaf.cadi.config.Config;
52 import org.onap.aaf.cadi.http.HMangr;
53 import org.onap.aaf.misc.env.APIException;
54 import org.onap.aaf.misc.env.Env;
55 import org.onap.aaf.misc.env.LogTarget;
56 import org.onap.aaf.misc.env.TimeTaken;
58 import com.datastax.driver.core.Cluster;
59 import com.datastax.driver.core.ColumnDefinitions;
60 import com.datastax.driver.core.PreparedId;
61 import com.datastax.driver.core.PreparedStatement;
62 import com.datastax.driver.core.ResultSet;
63 import com.datastax.driver.core.Row;
64 import com.datastax.driver.core.Session;
65 import com.datastax.driver.core.Statement;
66 import com.datastax.driver.core.exceptions.DriverException;
68 public class JU_CacheInfoDAO {
82 public void setUp() throws APIException, IOException {
84 Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).warn();
85 Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error();
86 Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug();
87 Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info();
88 Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).init();
89 Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LATITUDE);
90 Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LONGITUDE);
91 Mockito.doReturn(session).when(cluster).connect("test");
95 public void testInit() {
96 TimeTaken tt = Mockito.mock(TimeTaken.class);
97 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE);
98 Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB);
99 Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB);
100 Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB);
101 Mockito.doNothing().when(tt).done();
102 CacheInfoDAO.Data data = new CacheInfoDAO.Data();
103 PSInfo createPS = Mockito.mock(PSInfo.class);
104 Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]);
105 Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data);
107 CacheInfoDAOImpl daoObj=null;
109 daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS);
110 } catch (APIException | IOException e) {
111 // TODO Auto-generated catch block
115 Result<Data> retVal = daoObj.create(trans, data);
116 assertTrue(retVal.status == 0);
120 public void testTouch() {
121 TimeTaken tt = Mockito.mock(TimeTaken.class);
122 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE);
123 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO Touch segments test: 1", Env.REMOTE);
124 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO Touch segments test: 1,2", Env.REMOTE);
125 Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB);
126 Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB);
127 Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB);
128 Mockito.doNothing().when(tt).done();
130 Mockito.doReturn(logTarget).when(env).debug();
132 CacheInfoDAO.Data data = new CacheInfoDAO.Data();
133 PSInfo createPS = Mockito.mock(PSInfo.class);
134 Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]);
135 Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data);
137 CacheInfoDAOImpl daoObj=null;
139 daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS);
140 } catch (APIException | IOException e) {
141 // TODO Auto-generated catch block
145 Result<Void> retVal = daoObj.touch(trans, "test", 1, 2);
146 assertTrue(retVal.status == 0);
147 Mockito.doThrow(DriverException.class).when(session).executeAsync(Mockito.anyString());
148 daoObj.startUpdate(env, Mockito.mock(HMangr.class), Mockito.mock(SecuritySetter.class), "12.0.0.1", 8080);
149 retVal = daoObj.touch(trans, "test", 1, 2);
153 daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS);
154 } catch (APIException | IOException e) {
155 // TODO Auto-generated catch block
158 assertTrue(retVal.status == Result.ERR_Backend);
159 Mockito.doThrow(APIException.class).when(session).executeAsync(Mockito.anyString());
160 retVal = daoObj.touch(trans, "test", 1, 2);
162 daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS);
163 } catch (APIException | IOException e) {
164 // TODO Auto-generated catch block
167 assertTrue(retVal.status == Result.ERR_Backend);
168 Mockito.doThrow(IOException.class).when(session).executeAsync(Mockito.anyString());
170 daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS);
171 } catch (APIException | IOException e) {
172 // TODO Auto-generated catch block
175 retVal = daoObj.touch(trans, "test", 1, 2);
176 assertTrue(retVal.status == Result.ERR_Backend);
180 public void testCheck() {
181 TimeTaken tt = Mockito.mock(TimeTaken.class);
182 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE);
183 Mockito.doReturn(tt).when(trans).start("Check Table Timestamps", Env.REMOTE);
184 Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB);
185 Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB);
186 Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB);
187 Mockito.doNothing().when(tt).done();
188 CacheInfoDAO.Data data = new CacheInfoDAO.Data();
189 PSInfo createPS = Mockito.mock(PSInfo.class);
190 Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]);
191 Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data);
193 CacheInfoDAOImpl daoObj=null;
194 PreparedStatement ps = Mockito.mock(PreparedStatement.class);
195 Mockito.doReturn(ps).when(session).prepare(Mockito.anyString());
196 Mockito.doReturn(Mockito.mock(ColumnDefinitions.class)).when(ps).getVariables();
197 Mockito.doReturn(Mockito.mock(PreparedId.class)).when(ps).getPreparedId();
199 daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS);
200 } catch (APIException | IOException e) {
201 // TODO Auto-generated catch block
205 ResultSet resultSet = Mockito.mock(ResultSet.class);
206 List<Row> rowList = new ArrayList<>();
207 Mockito.doReturn(rowList).when(resultSet).all();
208 Mockito.doReturn(resultSet).when(session).execute(Mockito.any(Statement.class));
209 Result<Void> retVal = daoObj.check(trans);
210 assertTrue(retVal.status == 0);
212 Row row = Mockito.mock(Row.class);
213 Mockito.doReturn("test").when(row).getString(Mockito.anyInt());
215 row = Mockito.mock(Row.class);
216 Mockito.doReturn("test").when(row).getString(Mockito.anyInt());
217 Mockito.doReturn(100).when(row).getInt(Mockito.anyInt());
219 retVal = daoObj.check(trans);
220 assertTrue(retVal.status == 0);
222 Mockito.doThrow(DriverException.class).when(session).execute(Mockito.any(Statement.class));
223 retVal = daoObj.check(trans);
224 assertTrue(retVal.status == Result.ERR_Backend);
226 daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS);
227 } catch (APIException | IOException e) {
228 // TODO Auto-generated catch block
231 Mockito.doThrow(APIException.class).when(session).execute(Mockito.any(Statement.class));
232 retVal = daoObj.check(trans);
233 assertTrue(retVal.status == Result.ERR_Backend);
235 daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS);
236 } catch (APIException | IOException e) {
237 // TODO Auto-generated catch block
240 Mockito.doThrow(IOException.class).when(session).execute(Mockito.any(Statement.class));
241 retVal = daoObj.check(trans);
242 assertTrue(retVal.status == Result.ERR_Backend);
245 public void testStopUpdate() {
247 CacheInfoDAO.stopUpdate();
253 * This has intermittent Null Pointers, JUnit only
255 public void testGet() {
256 TimeTaken tt = Mockito.mock(TimeTaken.class);
257 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO CREATE", Env.REMOTE);
258 Mockito.doReturn(tt).when(trans).start("CacheInfoDAO Touch segments test1: 1011", Env.REMOTE);
259 Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB);
260 Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB);
261 Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on CacheInfoDAO", Env.SUB);
262 Mockito.doNothing().when(tt).done();
263 CacheInfoDAO.Data data = new CacheInfoDAO.Data();
264 PSInfo createPS = Mockito.mock(PSInfo.class);
265 Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]);
266 Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data);
268 CacheInfoDAOImpl daoObj=null;
270 daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS);
271 Date retVal = daoObj.get(trans, "test", 1011);
272 // assertTrue(retVal.status == 0);
273 retVal = daoObj.get(trans, "test1", 1011);
274 } 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