X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-cass%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fdao%2Fcass%2FJU_UserRoleDAO.java;h=22824fd5bb73088013d08678b699858cf1fea120;hb=1296352d8eafee57f982a4342ad79ada4aa56d28;hp=43496fd5ca62eca88a2367aeb35a67b73cd7b483;hpb=3d1706fcbe7f95830ff6fd23cf679ee55c6d0595;p=aaf%2Fauthz.git diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_UserRoleDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_UserRoleDAO.java index 43496fd5..22824fd5 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_UserRoleDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_UserRoleDAO.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -66,7 +66,7 @@ public class JU_UserRoleDAO { Cluster cluster; @Mock Session session; - + @Before public void setUp() throws APIException, IOException { initMocks(this); @@ -109,13 +109,13 @@ public class JU_UserRoleDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + PSInfo psObj = Mockito.mock(PSInfo.class); setPsByStartAndTarget(daoObj, psObj, "psByUser"); - + Result> rs1 = new Result>(null,0,"test",new Object[0]); Mockito.doReturn(rs1).when(psObj).read(trans, "UserRoleDAO READ", new Object[]{"test"}); - + daoObj.readByUser(trans, "test"); } @Test @@ -132,13 +132,13 @@ public class JU_UserRoleDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + PSInfo psObj = Mockito.mock(PSInfo.class); setPsByStartAndTarget(daoObj, psObj, "psByRole"); - + Result> rs1 = new Result>(null,0,"test",new Object[0]); Mockito.doReturn(rs1).when(psObj).read(trans, "UserRoleDAO READ", new Object[]{"test"}); - + daoObj.readByRole(trans, "test"); } @Test @@ -155,28 +155,28 @@ public class JU_UserRoleDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + PSInfo psObj = Mockito.mock(PSInfo.class); setPsByStartAndTarget(daoObj, psObj, "psUserInRole"); - + Result> rs1 = new Result>(null,0,"test",new Object[0]); Mockito.doReturn(rs1).when(psObj).read(trans, "UserRoleDAO READ", new Object[]{"test"}); - + daoObj.readByUserRole(trans, "test","test"); } - - + + public void setPsByStartAndTarget(UserRoleDAO UserRoleDAOObj, PSInfo psInfoObj, String fieldName) { Field UserRoleDAOField; try { UserRoleDAOField = UserRoleDAO.class.getDeclaredField(fieldName); - + UserRoleDAOField.setAccessible(true); // remove final modifier from field Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); // modifiersField.setInt(UserRoleDAOField, UserRoleDAOField.getModifiers() & ~Modifier.FINAL); - + UserRoleDAOField.set(UserRoleDAOObj, psInfoObj); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -189,7 +189,7 @@ public class JU_UserRoleDAO { e.printStackTrace(); } } - + @Test public void testWasMOdified() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -202,15 +202,15 @@ public class JU_UserRoleDAO { Mockito.doNothing().when(tt).done(); UserRoleDAO.Data data = new UserRoleDAO.Data(); PSInfo createPS = Mockito.mock(PSInfo.class); - + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); Result rs1 = new Result(null,0,"test",new Object[0]); Result rs2 = new Result(null,0,"test",new Object[0]); Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); - + UserRoleDAOImpl daoObj = null; try { daoObj = new UserRoleDAOImpl(trans, historyDAO, cacheInfoDAO, createPS ); @@ -219,7 +219,7 @@ public class JU_UserRoleDAO { e.printStackTrace(); } daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); - + daoObj.wasModified(trans, CRUD.update, data, new String[] {}); daoObj.wasModified(trans, CRUD.create, data, new String[] {null}); daoObj.wasModified(trans, CRUD.create, data, new String[] {"test",null}); @@ -227,24 +227,24 @@ public class JU_UserRoleDAO { daoObj.wasModified(trans, CRUD.delete, data, new String[] {"test","test"}); daoObj.wasModified(trans, CRUD.delete, data, new String[] {}); - + rs2 = new Result(null,1,"test",new Object[0]); Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); daoObj.wasModified(trans, CRUD.read, data, new String[] {"test","test"}); daoObj.wasModified(trans, CRUD.read, data, new String[] {}); - + rs1 = new Result(null,1,"test",new String[0]); Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); daoObj.wasModified(trans, CRUD.delete, data, new String[] {"test","test"}); } - + @Test public void testSecondConstructor() { HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); UserRoleDAO daoObj = new UserRoleDAO(trans, historyDAO, cacheInfoDAO); - + } @Test @@ -257,15 +257,15 @@ public class JU_UserRoleDAO { break; } } - + Constructor constructor = innerClass.getDeclaredConstructors()[0]; constructor.setAccessible(true); - + try { - + Object obj = constructor.newInstance(1); Method innnerClassMtd; - + UserRoleDAO.Data data = new UserRoleDAO.Data(); Row row = Mockito.mock(Row.class); ByteBuffer bbObj = ByteBuffer.allocateDirect(10); @@ -274,16 +274,16 @@ public class JU_UserRoleDAO { bbObj.put(1, new Byte("1")); bbObj.put(2, new Byte("2")); Mockito.doReturn(bbObj).when(row).getBytesUnsafe(1); - + innnerClassMtd = innerClass.getMethod("load", new Class[] {UserRoleDAO.Data.class, Row.class}); innnerClassMtd.invoke(obj, new Object[] {data, row}); - + innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {UserRoleDAO.Data.class, Integer.TYPE, Object[].class }); innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test"} }); -// +// innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {UserRoleDAO.Data.class, Integer.TYPE, Object[].class }); innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test","test","test","test","test","test","test","test","test"} }); - + ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {UserRoleDAO.Data.class, DataOutputStream.class }); @@ -293,7 +293,7 @@ public class JU_UserRoleDAO { DataInputStream dis = new DataInputStream(bais); innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {UserRoleDAO.Data.class, DataInputStream.class }); innnerClassMtd.invoke(obj, new Object[] {data, dis }); - + } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -312,36 +312,36 @@ public class JU_UserRoleDAO { } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); - } + } } - + @Test public void testData() { UserRoleDAO.Data data = new UserRoleDAO.Data(); NsSplit nss = new NsSplit("test", "test"); data = new UserRoleDAO.Data(); - + data.toString(); data.role("test", "test"); assertTrue("test".equals(data.ns)); - + RoleDAO.Data rdd = new RoleDAO.Data(); rdd.ns="test"; data.role(rdd); assertTrue("test".equals(data.ns)); - + Question q = Mockito.mock( Question.class); Result rs = new Result(nss,0,"test",new Object[0]); Mockito.doReturn(rs).when(q).deriveNsSplit(trans, "test"); - + data.role(trans, q, "test"); - + rs = new Result(nss,1,"test",new Object[0]); Mockito.doReturn(rs).when(q).deriveNsSplit(trans, "test"); - + data.role(trans, q, "test"); } - + } class UserRoleDAOImpl extends UserRoleDAO{ @@ -349,25 +349,25 @@ class UserRoleDAOImpl extends UserRoleDAO{ super(trans, historyDAO, cacheDao); setPs(this, readPS, "createPS"); } - + public UserRoleDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,CacheInfoDAO cacheDao, PSInfo readPS, Session session ) throws APIException, IOException { super(trans, historyDAO, cacheDao); setPs(this, readPS, "createPS"); setSession(this, session); } - + public void setPs(UserRoleDAOImpl UserRoleDAOObj, PSInfo psInfoObj, String methodName) { Field UserRoleDAOField; try { UserRoleDAOField = CassDAOImpl.class.getDeclaredField(methodName); - + UserRoleDAOField.setAccessible(true); // remove final modifier from field Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); // modifiersField.setInt(UserRoleDAOField, UserRoleDAOField.getModifiers() & ~Modifier.FINAL); - + UserRoleDAOField.set(UserRoleDAOObj, psInfoObj); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -380,18 +380,18 @@ class UserRoleDAOImpl extends UserRoleDAO{ e.printStackTrace(); } } - + public void setSession(UserRoleDAOImpl approvalDaoObj, Session session) { Field nsDaoField; try { nsDaoField = AbsCassDAO.class.getDeclaredField("session"); - + nsDaoField.setAccessible(true); // remove final modifier from field Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); // modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - + nsDaoField.set(approvalDaoObj, session); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block