Fix JU_CachInfoDAO
[aaf/authz.git] / auth / auth-cass / src / test / java / org / onap / aaf / auth / dao / cass / JU_CacheInfoDAO.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.dao.cass;
23
24 import static org.junit.Assert.assertTrue;
25 import static org.mockito.MockitoAnnotations.initMocks;
26
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;
32 import java.net.URI;
33 import java.net.URISyntaxException;
34 import java.util.ArrayList;
35 import java.util.Date;
36 import java.util.List;
37
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;
58
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;
68
69 import io.netty.util.concurrent.Future;
70
71 public class JU_CacheInfoDAO {
72
73         @Mock
74     AuthzTrans trans;
75         @Mock
76         Cluster cluster;
77         @Mock
78         Session session;
79         @Mock
80         AuthzEnv env;
81         @Mock
82         LogTarget logTarget;
83         
84         @Before
85         public void setUp() throws APIException, IOException {
86                 initMocks(this);
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");
95         }
96         
97         @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);
109                 
110                 CacheInfoDAOImpl daoObj=null;
111                 try {
112                         daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS);
113                 } catch (APIException | IOException e) {
114                         // TODO Auto-generated catch block
115                         e.printStackTrace();
116                 }
117 //              data.id
118                 Result<Data> retVal = daoObj.create(trans, data);
119                 assertTrue(retVal.status == 0);
120         }
121         
122         @Test
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();
132
133                 Mockito.doReturn(logTarget).when(env).debug();
134                 
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);
139                 
140                 CacheInfoDAOImpl daoObj=null;
141                 try {
142                         daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS);
143                 } catch (APIException | IOException e) {
144                         // TODO Auto-generated catch block
145                         e.printStackTrace();
146                 }
147 //              data.id
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);
153                 
154                 
155                 try {
156                         daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS);
157                 } catch (APIException | IOException e) {
158                         // TODO Auto-generated catch block
159                         e.printStackTrace();
160                 }
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);
164                 try {
165                         daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS);
166                 } catch (APIException | IOException e) {
167                         // TODO Auto-generated catch block
168                         e.printStackTrace();
169                 }
170                 assertTrue(retVal.status == Result.ERR_Backend);
171                 Mockito.doThrow(IOException.class).when(session).executeAsync(Mockito.anyString());
172                 try {
173                         daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS);
174                 } catch (APIException | IOException e) {
175                         // TODO Auto-generated catch block
176                         e.printStackTrace();
177                 }
178                 retVal = daoObj.touch(trans, "test", 1, 2);
179                 assertTrue(retVal.status == Result.ERR_Backend);
180         }
181         
182         @Test
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);
195                 
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();
201                 try {
202                         daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS);
203                 } catch (APIException | IOException e) {
204                         // TODO Auto-generated catch block
205                         e.printStackTrace();
206                 }
207 //              data.id
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);
214                 
215                 Row row  = Mockito.mock(Row.class);
216                 Mockito.doReturn("test").when(row).getString(Mockito.anyInt());
217                 rowList.add(row);
218                 row  = Mockito.mock(Row.class);
219                 Mockito.doReturn("test").when(row).getString(Mockito.anyInt());
220                 Mockito.doReturn(100).when(row).getInt(Mockito.anyInt());
221                 rowList.add(row);
222                 retVal = daoObj.check(trans);
223                 assertTrue(retVal.status == 0);
224
225                 Mockito.doThrow(DriverException.class).when(session).execute(Mockito.any(Statement.class));
226                 retVal = daoObj.check(trans);
227                 assertTrue(retVal.status == Result.ERR_Backend);
228                 try {
229                         daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS);
230                 } catch (APIException | IOException e) {
231                         // TODO Auto-generated catch block
232                         e.printStackTrace();
233                 }
234                 Mockito.doThrow(APIException.class).when(session).execute(Mockito.any(Statement.class));
235                 retVal = daoObj.check(trans);
236                 assertTrue(retVal.status == Result.ERR_Backend);
237                 try {
238                         daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS);
239                 } catch (APIException | IOException e) {
240                         // TODO Auto-generated catch block
241                         e.printStackTrace();
242                 }
243                 Mockito.doThrow(IOException.class).when(session).execute(Mockito.any(Statement.class));
244                 retVal = daoObj.check(trans);
245                 assertTrue(retVal.status == Result.ERR_Backend);
246         }
247         @Test
248         public void testStopUpdate() {
249                 
250                 CacheInfoDAO.stopUpdate();
251                 
252         }
253
254
255         @Test
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);
268                 
269                 CacheInfoDAOImpl daoObj=null;
270                 try {
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) {
276                         // TODO Auto-generated catch block
277                         e.printStackTrace();
278                 }
279         }
280         
281         @Test
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);
292                 
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());
296                 
297                 CacheInfoDAOImpl daoObj=null;
298                 try {
299                         daoObj = new CacheInfoDAOImpl(trans, cluster, "test", createPS);
300                 } catch (APIException | IOException e) {
301                         // TODO Auto-generated catch block
302                         e.printStackTrace();
303                 }
304                 daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"});
305                 
306                 
307         }
308         
309         @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);
322
323                 CacheInfoDAOImpl daoObj=null;
324                 try {
325                         daoObj = new CacheInfoDAOImpl(trans, cluster, "test", createPS);
326                 } catch (APIException | IOException e) {
327                         // TODO Auto-generated catch block
328                         e.printStackTrace();
329                 }
330                 Class[] classList = CacheInfoDAO.class.getDeclaredClasses();
331                 Class<?> innerClass = null;
332                 for(Class indCls:classList) {
333                         if(indCls.getName().contains("InfoLoader")) {
334                                 innerClass = indCls;
335                         }
336                 }
337         Constructor<?> constructor = innerClass.getDeclaredConstructors()[0];
338         constructor.setAccessible(true);
339         try {
340                         Object obj = constructor.newInstance(1);
341                         Method innnerClassMtd;
342                                 
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});
347                         
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"}});
350
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
355                         e.printStackTrace();
356                 } catch (IllegalAccessException e) {
357                         // TODO Auto-generated catch block
358                         e.printStackTrace();
359                 } catch (IllegalArgumentException e) {
360                         // TODO Auto-generated catch block
361                         e.printStackTrace();
362                 } catch (InvocationTargetException e) {
363                         // TODO Auto-generated catch block
364                         e.printStackTrace();
365                 } catch (NoSuchMethodException e) {
366                         // TODO Auto-generated catch block
367                         e.printStackTrace();
368                 } catch (SecurityException e) {
369                         // TODO Auto-generated catch block
370                         e.printStackTrace();
371                 } 
372         }
373         
374         @Test
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);
387
388                 CacheInfoDAOImpl daoObj=null;
389                 try {
390                         daoObj = new CacheInfoDAOImpl(trans, cluster, "test", createPS);
391                 } catch (APIException | IOException e) {
392                         // TODO Auto-generated catch block
393                         e.printStackTrace();
394                 }
395                 Class[] classList = CacheInfoDAO.class.getDeclaredClasses();
396                 Class<?> innerClass = null;
397                 for(Class indCls:classList) {
398                         if(indCls.getName().contains("CacheUpdate")) {
399                                 innerClass = indCls;
400                         }
401                 }
402         Constructor<?> constructor = innerClass.getDeclaredConstructors()[0];
403         constructor.setAccessible(true);
404         try {
405                         Object obj = constructor.newInstance(env,Mockito.mock(HMangr.class), Mockito.mock(SecuritySetter.class), "12.0.0.1", 8080);
406
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);
411                 
412                         Method innnerClassMtd;
413                                 
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");
420                         
421                         innnerClassMtd = innerInnerClass.getMethod("code", new Class[] {Rcli.class});
422                         innnerClassMtd.invoke(innerClassObj, new Object[] {rcli});
423                         
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});
428                         
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
434                         e.printStackTrace();
435                 } catch (IllegalAccessException e) {
436                         // TODO Auto-generated catch block
437                         e.printStackTrace();
438                 } catch (IllegalArgumentException e) {
439                         // TODO Auto-generated catch block
440                         e.printStackTrace();
441                 } catch (InvocationTargetException e) {
442                         // TODO Auto-generated catch block
443                         e.printStackTrace();
444                 }  catch (SecurityException e) {
445                         // TODO Auto-generated catch block
446                         e.printStackTrace();
447                 } catch (ClassNotFoundException e) {
448                         // TODO Auto-generated catch block
449                         e.printStackTrace();
450                 } catch (NoSuchMethodException e) {
451                         // TODO Auto-generated catch block
452                         e.printStackTrace();
453                 } catch (URISyntaxException e) {
454                         // TODO Auto-generated catch block
455                         e.printStackTrace();
456                 } catch (APIException e) {
457                         // TODO Auto-generated catch block
458                         e.printStackTrace();
459                 } catch (CadiException e) {
460                         // TODO Auto-generated catch block
461                         e.printStackTrace();
462                 } 
463         }
464         
465         @Test
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);
478
479                 CacheInfoDAOImpl daoObj=null;
480                 try {
481                         daoObj = new CacheInfoDAOImpl(trans, cluster, "test", createPS);
482                 } catch (APIException | IOException e) {
483                         // TODO Auto-generated catch block
484                         e.printStackTrace();
485                 }
486                 Class[] classList = CacheInfoDAO.class.getDeclaredClasses();
487                 Class<?> innerClass = null;
488                 for(Class indCls:classList) {
489                         if(indCls.getName().contains("CacheUpdate")) {
490                                 innerClass = indCls;
491                         }
492                 }
493         Constructor<?> constructor = innerClass.getDeclaredConstructors()[0];
494         constructor.setAccessible(true);
495         try {
496                         Object obj = constructor.newInstance(env,Mockito.mock(HMangr.class), Mockito.mock(SecuritySetter.class), "12.0.0.1", 8080);
497
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);
503                 
504                         Method innnerClassMtd=null;
505                                 
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");
512                         
513                         Method[] allMtds = innerInnerClass.getDeclaredMethods();
514                         for(Method indMtd:allMtds) {
515                                 if(indMtd.getName().contains("add")) {
516                                         innnerClassMtd = indMtd;
517                                 }
518                         }
519                         innnerClassMtd.invoke(innerClassObj, new Object[] {a});
520                         
521                         
522                 } catch (InstantiationException e) {
523                         // TODO Auto-generated catch block
524                         e.printStackTrace();
525                 } catch (IllegalAccessException e) {
526                         // TODO Auto-generated catch block
527                         e.printStackTrace();
528                 } catch (IllegalArgumentException e) {
529                         // TODO Auto-generated catch block
530                         e.printStackTrace();
531                 } catch (InvocationTargetException e) {
532                         // TODO Auto-generated catch block
533                         e.printStackTrace();
534                 }  catch (SecurityException e) {
535                         // TODO Auto-generated catch block
536                         e.printStackTrace();
537                 } catch (ClassNotFoundException e) {
538                         // TODO Auto-generated catch block
539                         e.printStackTrace();
540                 } catch (URISyntaxException e) {
541                         // TODO Auto-generated catch block
542                         e.printStackTrace();
543                 } catch (APIException e) {
544                         // TODO Auto-generated catch block
545                         e.printStackTrace();
546                 } catch (CadiException e) {
547                         // TODO Auto-generated catch block
548                         e.printStackTrace();
549                 } 
550         }
551         
552         //@Test
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);
563
564                 try {
565                         CacheInfoDAO daoObj = new CacheInfoDAO(trans, absCassDAO);
566                 } catch (APIException | IOException e) {
567                         // TODO Auto-generated catch block
568                         e.printStackTrace();
569                 }
570         }
571 }
572
573 class CacheInfoDAOImpl extends CacheInfoDAO{
574
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));
583         }
584         
585         public CacheInfoDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace,PSInfo readPS  ) throws APIException, IOException {
586                 super(trans, cluster, keyspace);
587                 this.readPS = readPS;
588         }
589         
590
591         public void setPs(CacheInfoDAOImpl CacheInfoDAOObj, PSInfo psInfoObj, String methodName) {
592                 Field nsDaoField;
593                 try {
594                         nsDaoField = CacheInfoDAO.class.getDeclaredField(methodName);
595                         
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);
601                 
602                 nsDaoField.set(CacheInfoDAOObj, psInfoObj);
603                 } catch (NoSuchFieldException | SecurityException e) {
604                         // TODO Auto-generated catch block
605                         e.printStackTrace();
606                 } catch (IllegalArgumentException e) {
607                         // TODO Auto-generated catch block
608                         e.printStackTrace();
609                 } catch (IllegalAccessException e) {
610                         // TODO Auto-generated catch block
611                         e.printStackTrace();
612                 }
613         }
614
615         
616         public void setSession(CacheInfoDAOImpl CacheInfoDAOObj, Session session) {
617                 Field nsDaoField;
618                 try {
619                         nsDaoField = AbsCassDAO.class.getDeclaredField("session");
620                         
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
629                         e.printStackTrace();
630                 } catch (IllegalArgumentException e) {
631                         // TODO Auto-generated catch block
632                         e.printStackTrace();
633                 } catch (IllegalAccessException e) {
634                         // TODO Auto-generated catch block
635                         e.printStackTrace();
636                 }
637         }
638         
639 }