diff options
author | Instrumental <jonathan.gathman@att.com> | 2019-10-15 08:19:50 -0500 |
---|---|---|
committer | Instrumental <jonathan.gathman@att.com> | 2019-10-15 08:35:35 -0500 |
commit | 1296352d8eafee57f982a4342ad79ada4aa56d28 (patch) | |
tree | 355cdb89d85530a861319f892b0f24236e6adc50 /auth/auth-cass/src/test/java/org | |
parent | bdce7667a6e272e2fa32e298d957a0d9090c5bc9 (diff) |
Sonar Fixes, Formatting
Issue-ID: AAF-1019
Change-Id: Ica49d9e7323aad9622ff9d95cc21b87430c22c54
Signed-off-by: Instrumental <jonathan.gathman@att.com>
Diffstat (limited to 'auth/auth-cass/src/test/java/org')
38 files changed, 1341 insertions, 1341 deletions
diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_Cached.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_Cached.java index 055e91ed..f6bdf20a 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_Cached.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_Cached.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. @@ -59,20 +59,20 @@ public class JU_Cached { @Mock CIDAO<AuthzTrans> cidaoATMock; - + String name = "nameString"; @Before public void setUp(){ MockitoAnnotations.initMocks(this); } - + @Test public void testCachedIdx(){ Cached<Trans, DataStub> cached = new Cached<Trans, DataStub>(ciDaoMock, name, 1, 30000L); assertThat(cached.cacheIdx("1234567890"), is(0)); } - + @Test public void testInvalidate(){ Cached<Trans, DataStub> cached = new Cached<Trans, DataStub>(ciDaoMock, name, 5, 30000L); @@ -103,26 +103,26 @@ public class JU_Cached { // Trans transMock; // @Mock // Getter<DAO> getterMock; -// +// // @Test // public void testGet(){ // cached.get(transMock, name, getterMock); // fail("not implemented"); // } -// +// // @SuppressWarnings("unchecked") // public Result<List<DATA>> get(TRANS trans, String key, Getter<DATA> getter) { // List<DATA> ld = null; // Result<List<DATA>> rld = null; -// +// // int cacheIdx = cacheIdx(key); // Map<String, Dated> map = ((Map<String,Dated>)cache[cacheIdx]); -// +// // // Check for saved element in cache // Dated cached = map.get(key); // // Note: These Segment Timestamps are kept up to date with DB // Date dbStamp = info.get(trans, name,cacheIdx); -// +// // // Check for cache Entry and whether it is still good (a good Cache Entry is same or after DBEntry, so we use "before" syntax) // if (cached!=null && dbStamp.before(cached.timestamp)) { // ld = (List<DATA>)cached.data; diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CachedDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CachedDAO.java index 242904ac..23deced0 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CachedDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CachedDAO.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. @@ -44,22 +44,22 @@ public class JU_CachedDAO { @Mock DAO daoMock; @Mock - CIDAO<Trans> ciDAOMock; + CIDAO<Trans> ciDAOMock; int segsize=1; Object[ ] objs = new Object[2]; - + @Before public void setUp(){ objs[0] = "helo"; objs[1] = "polo"; cachedDAO = new CachedDAO(daoMock, ciDAOMock, segsize, segsize); } - + @Test public void testKeyFromObjs(){ String result = cachedDAO.keyFromObjs(objs); System.out.println("value of resut " +result); assertTrue(true); } - + } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CassAccess.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CassAccess.java index c06cd5c1..3f6b1500 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CassAccess.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CassAccess.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. @@ -43,7 +43,7 @@ import com.datastax.driver.core.Cluster.Builder; @RunWith(PowerMockRunner.class) public class JU_CassAccess { CassAccess cassAccess; - + public static final String KEYSPACE = "authz"; public static final String CASSANDRA_CLUSTERS = "cassandra.clusters"; public static final String CASSANDRA_CLUSTERS_PORT = "cassandra.clusters.port"; @@ -58,7 +58,7 @@ public class JU_CassAccess { @Mock Env envMock; String prefix=null; - + @Before public void setUp(){ cassAccess = new CassAccess(); @@ -68,7 +68,7 @@ public class JU_CassAccess { // @Test(expected=APIException.class) // public void testCluster() throws APIException, IOException { //// cassAccess.cluster(envMock, prefix); -// +// // } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CassDAOImpl.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CassDAOImpl.java index 2e03c060..9eab56ff 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CassDAOImpl.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CassDAOImpl.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. @@ -76,7 +76,7 @@ AuthzTrans authzTransMock; } //TODO: Gabe [JUnit] Visibility issue - @Test + @Test public void testReadConsistency() { String table = "users"; PowerMockito.when(authzTransMock.getProperty(CASS_READ_CONSISTENCY+'.'+table)).thenReturn("TWO"); @@ -84,8 +84,8 @@ AuthzTrans authzTransMock; System.out.println("Consistency level" + consistencyLevel.name()); assertEquals("TWO", consistencyLevel.name()); } - - @Test + + @Test public void testWriteConsistency() { String table = "users"; PowerMockito.when(authzTransMock.getProperty(CASS_WRITE_CONSISTENCY+'.'+table)).thenReturn(null); @@ -93,5 +93,5 @@ AuthzTrans authzTransMock; System.out.println("Consistency level" + consistencyLevel.name()); assertEquals("ONE", consistencyLevel.name()); } - + } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_DAOException.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_DAOException.java index c1592bdb..f8a09c60 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_DAOException.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_DAOException.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. @@ -35,32 +35,32 @@ public class JU_DAOException { DAOException daoException; String message = "message"; - Throwable cause; + Throwable cause; @Before public void setUp(){ - daoException = new DAOException(); + daoException = new DAOException(); } @Test public void testNoArgConstructor(){ assertNull(daoException.getMessage()); } - + @Test public void testOneArgConstructorMsg(){ - daoException = new DAOException("test message"); + daoException = new DAOException("test message"); assertTrue("test message".equalsIgnoreCase(daoException.getMessage())); } - + @Test public void testOneArgConstructorThrowable(){ - daoException = new DAOException(new Throwable()); + daoException = new DAOException(new Throwable()); assertTrue("java.lang.Throwable".equalsIgnoreCase(daoException.getMessage())); } - + @Test public void testTwoArgConstructor(){ - daoException = new DAOException("test message", new Throwable()); + daoException = new DAOException("test message", new Throwable()); assertTrue("test message".equalsIgnoreCase(daoException.getMessage())); } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/aaf/test/AbsJUCass.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/aaf/test/AbsJUCass.java index bb0fcd43..7780a165 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/aaf/test/AbsJUCass.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/aaf/test/AbsJUCass.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. @@ -50,7 +50,7 @@ import junit.framework.Assert; /** * Do Setup of Cassandra for Cassandra JUnit Testing - * + * * */ public class AbsJUCass { @@ -63,8 +63,8 @@ public class AbsJUCass { protected static float json = 0.0f; protected static AuthzTrans trans; protected static boolean details = true; - - @BeforeClass + + @BeforeClass public static void startup() throws APIException, IOException { synchronized(AUTHZ) { if (env==null) { @@ -101,14 +101,14 @@ public class AbsJUCass { Assert.fail("Not able to connect to DB: " + e.getLocalizedMessage()); } env.info().log("Connected"); - + // Load special data here - - + + iterations = 0; - + } - + @AfterClass public static void shutdown() { if (cluster!=null) { @@ -120,10 +120,10 @@ public class AbsJUCass { @Before public void newTrans() { trans = env.newTrans(); - + trans.setProperty(CassDAOImpl.USER_NAME, System.getProperty("user.name")); } - + @After public void auditTrail() { if (totals==0) { // "updateTotals()" was not called... just do one Trans @@ -144,7 +144,7 @@ public class AbsJUCass { } } } - + protected void updateTotals() { Metric metric = trans.auditTrail(0, null, Env.JSON, Env.REMOTE); totals+=metric.total; @@ -163,7 +163,7 @@ public class AbsJUCass { } env.info().log( "Total time:", - totals, + totals, "JSON time:", json, "REMOTE time:", @@ -174,10 +174,10 @@ public class AbsJUCass { transTime ); } - + /** * Take a User/Pass and turn into an MD5 Hashed BasicAuth - * + * * @param user * @param pass * @return diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/aaf/test/JU_Bytification.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/aaf/test/JU_Bytification.java index 7e460899..2ef15ff3 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/aaf/test/JU_Bytification.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/aaf/test/JU_Bytification.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. @@ -41,25 +41,25 @@ public class JU_Bytification { @Test public void testNS() throws IOException { - + // Normal NsDAO.Data ns = new NsDAO.Data(); ns.name = "org.osaaf.<pass>"; ns.type = NsType.APP.type; ByteBuffer bb = ns.bytify(); - + NsDAO.Data nsr = new NsDAO.Data(); nsr.reconstitute(bb); check(ns,nsr); - + // Empty admin // ns.admin(true).clear(); bb = ns.bytify(); nsr = new NsDAO.Data(); nsr.reconstitute(bb); check(ns,nsr); - + // Empty responsible // ns.responsible(true).clear(); bb = ns.bytify(); @@ -72,16 +72,16 @@ public class JU_Bytification { nsr.reconstitute(bb); check(ns,nsr); } - + private void check(NsDAO.Data a, NsDAO.Data b) { assertEquals(a.name,b.name); assertEquals(a.type,b.type); // assertEquals(a.admin.size(),b.admin.size()); - + // for (String s: a.admin) { // assertTrue(b.admin.contains(s)); // } -// +// // assertEquals(a.responsible.size(),b.responsible.size()); // for (String s: a.responsible) { // assertTrue(b.responsible.contains(s)); @@ -101,7 +101,7 @@ public class JU_Bytification { RoleDAO.Data rd2 = new RoleDAO.Data(); rd2.reconstitute(bb); check(rd1,rd2); - + // Overshoot Buffer StringBuilder sb = new StringBuilder(300); sb.append("role|instance|veryLongAction..."); @@ -113,15 +113,15 @@ public class JU_Bytification { rd2 = new RoleDAO.Data(); rd2.reconstitute(bb); check(rd1,rd2); - + // No Perms rd1.perms.clear(); - + bb = rd1.bytify(); rd2 = new RoleDAO.Data(); rd2.reconstitute(bb); check(rd1,rd2); - + // 1000 Perms for (int i=0;i<1000;++i) { rd1.perms(true).add("com|inst|action"+ i); @@ -133,11 +133,11 @@ public class JU_Bytification { check(rd1,rd2); } - + private void check(RoleDAO.Data a, RoleDAO.Data b) { assertEquals(a.ns,b.ns); assertEquals(a.name,b.name); - + assertEquals(a.perms.size(),b.perms.size()); for (String s: a.perms) { assertTrue(b.perms.contains(s)); @@ -159,15 +159,15 @@ public class JU_Bytification { PermDAO.Data rd2 = new PermDAO.Data(); rd2.reconstitute(bb); check(pd1,rd2); - + // No Perms pd1.roles.clear(); - + bb = pd1.bytify(); rd2 = new PermDAO.Data(); rd2.reconstitute(bb); check(pd1,rd2); - + // 1000 Perms for (int i=0;i<1000;++i) { pd1.roles(true).add("org.osaaf.<pass>.my.Role"+ i); @@ -179,13 +179,13 @@ public class JU_Bytification { check(pd1,rd2); } - + private void check(PermDAO.Data a, PermDAO.Data b) { assertEquals(a.ns,b.ns); assertEquals(a.type,b.type); assertEquals(a.instance,b.instance); assertEquals(a.action,b.action); - + assertEquals(a.roles.size(),b.roles.size()); for (String s: a.roles) { assertTrue(b.roles.contains(s)); @@ -204,11 +204,11 @@ public class JU_Bytification { UserRoleDAO.Data urd2 = new UserRoleDAO.Data(); urd2.reconstitute(bb); check(urd1,urd2); - + // A null - urd1.expires = null; + urd1.expires = null; urd1.role = null; - + bb = urd1.bytify(); urd2 = new UserRoleDAO.Data(); urd2.reconstitute(bb); @@ -221,7 +221,7 @@ public class JU_Bytification { assertEquals(a.expires,b.expires); } - + @Test public void testCred() throws IOException { CredDAO.Data cd = new CredDAO.Data(); @@ -236,11 +236,11 @@ public class JU_Bytification { CredDAO.Data cd2 = new CredDAO.Data(); cd2.reconstitute(bb); check(cd,cd2); - + // nulls cd.expires = null; cd.cred = null; - + bb = cd.bytify(); cd2 = new CredDAO.Data(); cd2.reconstitute(bb); @@ -253,7 +253,7 @@ public class JU_Bytification { assertEquals(a.ns,b.ns); assertEquals(a.type,b.type); if (a.cred==null) { - assertEquals(a.cred,b.cred); + assertEquals(a.cred,b.cred); } else { int l = a.cred.limit(); assertEquals(l,b.cred.limit()); diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/aaf/test/JU_NsType.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/aaf/test/JU_NsType.java index 05195eeb..bd07e594 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/aaf/test/JU_NsType.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/aaf/test/JU_NsType.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. @@ -41,15 +41,15 @@ public class JU_NsType { for (String s : tests) { nt = NsType.valueOf(s); assertEquals(s,nt.name()); - + nt2 = NsType.fromString(s); assertEquals(nt,nt2); - + int t = nt.type; nt2 = NsType.fromType(t); assertEquals(nt,nt2); } - + nt = NsType.fromType(Integer.MIN_VALUE); assertEquals(nt,NsType.UNKNOWN); nt = NsType.fromString("Garbage"); diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedCertDAOTest.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedCertDAOTest.java index de004fd5..54da1bf0 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedCertDAOTest.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedCertDAOTest.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. diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedCredDAOTest.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedCredDAOTest.java index 7f5ed85c..3d98dcda 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedCredDAOTest.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedCredDAOTest.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. diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedNSDAOTest.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedNSDAOTest.java index 064b985c..9298b9fd 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedNSDAOTest.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedNSDAOTest.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. diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedPermDAOTest.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedPermDAOTest.java index 46bbc7e6..8a505479 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedPermDAOTest.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedPermDAOTest.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. @@ -47,13 +47,13 @@ public class JU_CachedPermDAOTest { private CIDAO<AuthzTrans> info; @Mock private PermDAO dao; - + @Mock RoleDAO.Data role; - + @Mock private PermDAO.Data perm; - + @Mock private AuthzTrans trans; @Mock @@ -65,25 +65,25 @@ public class JU_CachedPermDAOTest { when(dao.readNS(trans, "ns")).thenReturn(value); when(trans.debug()).thenReturn(new LogTarget() { - + @Override public void printf(String fmt, Object... vars) {} - + @Override public void log(Throwable e, Object... msgs) { e.getMessage(); e.printStackTrace(); msgs.toString(); - + } - + @Override public void log(Object... msgs) { } - + @Override public boolean isLoggable() { - + return true; } }); @@ -109,7 +109,7 @@ public class JU_CachedPermDAOTest { verify(dao).readChildren(trans, "ns", "type"); } - + @Test public void testReadByTypeSuccess() { CachedPermDAO roleDaoObj =new CachedPermDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// @@ -119,8 +119,8 @@ public class JU_CachedPermDAOTest { // System.out.println(retVal.status); //retVal.status = 0; assertEquals("1", Integer.toString(retVal.status)); - } - + } + @Test public void testReadByTypeFailure() { CachedPermDAO roleDaoObj =new CachedPermDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// @@ -130,7 +130,7 @@ public class JU_CachedPermDAOTest { //System.out.println(retVal.status); assertEquals("23", Integer.toString(retVal.status)); } - + @Test public void testAddRole() { CachedPermDAO roleDaoObj =new CachedPermDAO(dao,info, 10); @@ -141,7 +141,7 @@ public class JU_CachedPermDAOTest { // System.out.println("ret value is::"+retVal); assertEquals("testAddRole", retVal.toString()); } - + @Test public void testDelRole() { CachedPermDAO roleDaoObj =new CachedPermDAO(dao,info, 10); diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedRoleDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedRoleDAO.java index 4d9527c5..d4062b73 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedRoleDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedRoleDAO.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. @@ -42,52 +42,52 @@ import org.onap.aaf.auth.layer.Result; import org.onap.aaf.misc.env.LogTarget; -@RunWith(MockitoJUnitRunner.class) +@RunWith(MockitoJUnitRunner.class) public class JU_CachedRoleDAO { @Mock RoleDAO dao; - + @Mock CIDAO<AuthzTrans> info; - + @Mock AuthzTransImpl trans; - + @Mock RoleDAO.Data data; - + @Mock PermDAO.Data permData; - + @Before public void setUp() throws Exception { initMocks(this); when(trans.debug()).thenReturn(new LogTarget() { - + @Override public void printf(String fmt, Object... vars) {} - + @Override public void log(Throwable e, Object... msgs) { e.getMessage(); e.printStackTrace(); msgs.toString(); - + } - + @Override public void log(Object... msgs) { } - + @Override public boolean isLoggable() { - + return true; } }); } - + @Test public void testReadNameSuccess() { CachedRoleDAO roleDaoObj =new CachedRoleDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// @@ -99,8 +99,8 @@ public class JU_CachedRoleDAO { // System.out.println(retVal.status); //retVal.status = 0; assertEquals("1", Integer.toString(retVal.status)); - } - + } + @Test public void testReadNameFailure() { CachedRoleDAO roleDaoObj =new CachedRoleDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// @@ -120,7 +120,7 @@ public class JU_CachedRoleDAO { Result<List<Data>> retVal = roleDaoObj.readNS(trans, ""); // System.out.println(retVal.status); assertEquals("1", Integer.toString(retVal.status)); - } + } @Test public void testReadNSFailure() { CachedRoleDAO roleDaoObj =new CachedRoleDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// @@ -131,7 +131,7 @@ public class JU_CachedRoleDAO { // System.out.println(retVal.status); assertEquals("22", Integer.toString(retVal.status)); } - + @Test public void testReadChildren() { CachedRoleDAO roleDaoObj =new CachedRoleDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// @@ -141,7 +141,7 @@ public class JU_CachedRoleDAO { //System.out.println(retVal.status); assertEquals("0", Integer.toString(retVal.status)); } - + @Test public void testAddPerm() { CachedRoleDAO roleDaoObj =new CachedRoleDAO(dao,info, 10); @@ -151,7 +151,7 @@ public class JU_CachedRoleDAO { Result<Void> retVal = roleDaoObj.addPerm(trans, data, permData); assertEquals("testAddPerm", retVal.toString()); } - + @Test public void testDelPerm() { CachedRoleDAO roleDaoObj =new CachedRoleDAO(dao,info, 10); diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedUserRoleDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedUserRoleDAO.java index 053fc889..814a03fe 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedUserRoleDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedUserRoleDAO.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. @@ -50,47 +50,47 @@ public class JU_CachedUserRoleDAO { @Mock UserRoleDAO dao; - + @Mock CIDAO<AuthzTrans> info; - + @Mock AuthzTransImpl trans; - + @Mock RoleDAO.Data data; - + @Mock PermDAO.Data permData; - + @Before public void setUp() throws Exception { initMocks(this); when(trans.debug()).thenReturn(new LogTarget() { - + @Override public void printf(String fmt, Object... vars) {} - + @Override public void log(Throwable e, Object... msgs) { e.getMessage(); e.printStackTrace(); msgs.toString(); - + } - + @Override public void log(Object... msgs) { } - + @Override public boolean isLoggable() { - + return true; } }); } - + private class TaggedPrincipalStub extends TaggedPrincipal { String name="TaggedPrincipalStub"; public TaggedPrincipalStub() { super(); } @@ -98,7 +98,7 @@ public class JU_CachedUserRoleDAO { @Override public String getName() { return name; } @Override public String tag() { return null; } } - + @Test public void testReadName() { CachedUserRoleDAO roleDaoObj =new CachedUserRoleDAO(dao,info, 10L); @@ -109,8 +109,8 @@ public class JU_CachedUserRoleDAO { //System.out.println(retVal.status); //retVal.status = 0; assertEquals("25", Integer.toString(retVal.status)); - } - + } + @Test public void testReadNameUser() { CachedUserRoleDAO roleDaoObj =new CachedUserRoleDAO(dao,info, 10L); @@ -122,7 +122,7 @@ public class JU_CachedUserRoleDAO { Object o=null; return (T)o; } - + }; transTemp.setUser(new TaggedPrincipalStub()); Mockito.doReturn(retVal1).when(info).touch(trans, null,null); @@ -132,7 +132,7 @@ public class JU_CachedUserRoleDAO { // System.out.println(retVal.status); assertEquals("1", Integer.toString(retVal.status)); } - + @Test public void testReadByRoleSuccess() { CachedUserRoleDAO roleDaoObj =new CachedUserRoleDAO(dao,info, 0);//Mockito.mock(CachedRoleDAO.class);// @@ -142,7 +142,7 @@ public class JU_CachedUserRoleDAO { Result<List<Data>> retVal = roleDaoObj.readByRole(trans, ""); //System.out.println(retVal.status); assertEquals("1", Integer.toString(retVal.status)); - } + } @Test public void testReadByRoleFailure() { CachedUserRoleDAO roleDaoObj =new CachedUserRoleDAO(dao,info, 0);//Mockito.mock(CachedRoleDAO.class);// @@ -153,7 +153,7 @@ public class JU_CachedUserRoleDAO { //System.out.println(retVal.status); assertEquals("25", Integer.toString(retVal.status)); } - + @Test public void testReadUserInRole() { CachedUserRoleDAO roleDaoObj =new CachedUserRoleDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);// @@ -165,7 +165,7 @@ public class JU_CachedUserRoleDAO { Object o=null; return (T)o; } - + }; transTemp.setUser(new TaggedPrincipalStub()); Mockito.doReturn(retVal1).when(info).touch(trans, null,null); @@ -175,6 +175,6 @@ public class JU_CachedUserRoleDAO { //System.out.println(retVal.status); assertEquals("25", Integer.toString(retVal.status)); } - + }
\ No newline at end of file diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ApprovalDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ApprovalDAO.java index 2b303673..c990c2fe 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ApprovalDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ApprovalDAO.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. @@ -60,7 +60,7 @@ public class JU_ApprovalDAO { AuthzTrans trans; @Mock Cluster cluster; - + @Before public void setUp() throws APIException, IOException { initMocks(this); @@ -69,7 +69,7 @@ public class JU_ApprovalDAO { Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info(); } - + @Test public void testInit() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -82,35 +82,35 @@ public class JU_ApprovalDAO { PSInfo createPS = Mockito.mock(PSInfo.class); Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); Mockito.doReturn(rs).when(createPS).exec(trans, "ApprovalDAOImpl CREATE", data); - + ApprovalDAOImpl daoObj = new ApprovalDAOImpl(trans, cluster, "test",data, createPS); // data.id Result<Data> retVal = daoObj.create(trans, data); assertTrue(retVal.status == 0); - + rs = new Result<ResultSet>(null,1,"test",new String[0]); Mockito.doReturn(rs).when(createPS).exec(trans, "ApprovalDAOImpl CREATE", data); retVal = daoObj.create(trans, data); assertTrue(retVal.status == 1); - + Result<List<ApprovalDAO.Data>> rs1 = new Result<List<ApprovalDAO.Data>>(null,0,"test",new String[0]); Mockito.doReturn(rs1).when(createPS).read(trans, "ApprovalDAOImpl CREATE", new Object[]{"testUser"}); Result<List<ApprovalDAO.Data>> retVal1 = daoObj.readByUser(trans, "testUser"); assertNull(retVal1); - + Mockito.doReturn(rs1).when(createPS).read(trans, "ApprovalDAOImpl CREATE", new Object[]{"testApprover"}); retVal1 = daoObj.readByApprover(trans, "testApprover"); assertNull(retVal1); - + Mockito.doReturn(rs1).when(createPS).read(trans, "ApprovalDAOImpl CREATE", new Object[]{new UUID(0, 0)}); retVal1 = daoObj.readByTicket(trans, new UUID(0, 0)); assertNull(retVal1); - + Mockito.doReturn(rs1).when(createPS).read(trans, "ApprovalDAOImpl CREATE", new Object[]{"testStatus"}); retVal1 = daoObj.readByStatus(trans, "testStatus"); assertNull(retVal1); } - + @Test public void testDelete() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -125,28 +125,28 @@ public class JU_ApprovalDAO { HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - + PSInfo createPS = Mockito.mock(PSInfo.class); ResultSet rsObj = new ResultSetImpl(); Result<ResultSet> rs = new Result<ResultSet>(rsObj,0,"test",new String[0]); Mockito.doReturn(rs).when(createPS).exec(trans, "ApprovalDAOImpl READ", data); Mockito.doReturn(rs).when(createPS).exec(trans, "ApprovalDAOImpl DELETE", data); - + ApprovalDAOImpl daoObj = new ApprovalDAOImpl(trans, cluster, "test", createPS, historyDAO); // data.id Result<Void> retVal = daoObj.delete(trans, data, true); assertTrue(retVal.status == 0); - + rs = new Result<ResultSet>(rsObj,1,"test",new String[0]); Mockito.doReturn(rs).when(createPS).exec(trans, "ApprovalDAOImpl READ", data); retVal = daoObj.delete(trans, data, true); assertTrue(retVal.status == 1); - + data.status="approved"; data.memo="test"; retVal = daoObj.delete(trans, data, false); assertTrue(retVal.status == 0); - + daoObj.async(true); data.status="denied"; retVal = daoObj.delete(trans, data, false); @@ -155,7 +155,7 @@ public class JU_ApprovalDAO { data.status=null; retVal = daoObj.delete(trans, data, false); } - + @Test public void testWasMOdified() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -167,24 +167,24 @@ public class JU_ApprovalDAO { Mockito.doNothing().when(tt).done(); ApprovalDAO.Data data = new ApprovalDAO.Data(); PSInfo createPS = Mockito.mock(PSInfo.class); - + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - + ApprovalDAOImpl daoObj = new ApprovalDAOImpl(trans, cluster, "test", createPS, historyDAO); daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); - + daoObj.wasModified(trans, CRUD.create, data, new String[] {}); daoObj.wasModified(trans, CRUD.create, data, new String[] {null}); daoObj.wasModified(trans, CRUD.create, data, new String[] {"test",null}); daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); - + rs1 = new Result<ResultSet>(null,1,"test",new String[0]); Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); } - + @Test public void testSecondConstructor() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -196,7 +196,7 @@ public class JU_ApprovalDAO { Mockito.doNothing().when(tt).done(); ApprovalDAO.Data data = new ApprovalDAO.Data(); HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - + ApprovalDAO daoObj = new ApprovalDAO(trans, historyDAO); } } @@ -270,7 +270,7 @@ class ResultSetImpl implements ResultSet{ // TODO Auto-generated method stub return false; } - + } class ApprovalDAOImpl extends ApprovalDAO{ @@ -283,12 +283,12 @@ class ApprovalDAOImpl extends ApprovalDAO{ setPs(this, createPS, "psByTicket"); setPs(this, createPS, "psByStatus"); } - + public ApprovalDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace,PSInfo readPS ) { super(trans, cluster, keyspace); this.readPS = readPS; } - + public ApprovalDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace,PSInfo readPS, HistoryDAO historyDAO ) { super(trans, cluster, keyspace); this.deletePS = readPS; @@ -296,18 +296,18 @@ class ApprovalDAOImpl extends ApprovalDAO{ setHistoryDao(this, historyDAO); setSession(this, Mockito.mock(Session.class)); } - + public void setPs(ApprovalDAOImpl approvalDaoObj, PSInfo psInfoObj, String methodName) { Field nsDaoField; try { nsDaoField = ApprovalDAO.class.getDeclaredField(methodName); - + 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, psInfoObj); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -325,13 +325,13 @@ class ApprovalDAOImpl extends ApprovalDAO{ Field nsDaoField; try { nsDaoField = ApprovalDAO.class.getDeclaredField("historyDAO"); - + 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, historyDAO); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -348,13 +348,13 @@ class ApprovalDAOImpl extends ApprovalDAO{ 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 diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ArtiDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ArtiDAO.java index d6e1fb55..c71da3bc 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ArtiDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ArtiDAO.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. @@ -59,7 +59,7 @@ public class JU_ArtiDAO { AuthzTrans trans; @Mock Cluster cluster; - + @Before public void setUp() throws APIException, IOException { initMocks(this); @@ -68,7 +68,7 @@ public class JU_ArtiDAO { Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).info(); } - + @Test public void testReadByMechID() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -77,17 +77,17 @@ public class JU_ArtiDAO { Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on ArtiDAO", Env.SUB); Mockito.doNothing().when(tt).done(); - + PSInfo psByMechIdObj = Mockito.mock(PSInfo.class); Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); // Mockito.doReturn(rs).when(createPS).exec(trans, "ArtiDAOImpl CREATE", data); - + ArtiDAOImpl daoObj = new ArtiDAOImpl(trans, cluster, "test", psByMechIdObj); - + Result<List<ArtiDAO.Data>> rs1 = new Result<List<ArtiDAO.Data>>(null,0,"test",new String[0]); Mockito.doReturn(rs1).when(psByMechIdObj).read(trans, "ArtiDAOImpl READ", new Object[]{"testMechId"}); daoObj.readByMechID(trans, "testMechId"); - + rs1 = new Result<List<ArtiDAO.Data>>(null,0,"test",new String[0]); Mockito.doReturn(rs1).when(psByMechIdObj).read(trans, "ArtiDAOImpl READ", new Object[]{"testMachine"}); daoObj.readByMachine(trans, "testMachine"); @@ -96,7 +96,7 @@ public class JU_ArtiDAO { Mockito.doReturn(rs1).when(psByMechIdObj).read(trans, "ArtiDAOImpl READ", new Object[]{"testNs"}); daoObj.readByNs(trans, "testNs"); } - + @Test public void testWasMOdified() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -108,43 +108,43 @@ public class JU_ArtiDAO { Mockito.doNothing().when(tt).done(); ArtiDAO.Data data = new ArtiDAO.Data(); PSInfo createPS = Mockito.mock(PSInfo.class); - + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - + ArtiDAOImpl daoObj = new ArtiDAOImpl(trans, cluster, "test", createPS, historyDAO); daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); - + daoObj.wasModified(trans, CRUD.create, data, new String[] {}); daoObj.wasModified(trans, CRUD.create, data, new String[] {null}); daoObj.wasModified(trans, CRUD.create, data, new String[] {"test",null}); daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); - + rs1 = new Result<ResultSet>(null,1,"test",new String[0]); Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); - + data.type(true); daoObj.wasModified(trans, CRUD.delete, data, new String[] {"test","test"}); - + } @Test public void testData(){ ArtiDAO.Data data = new ArtiDAO.Data(); data.type(true); data.type(false); - + data.sans(true); data.sans(false); data.sans = new TreeSet(); data.sans(false); data.sans(true); - + data.expires = new Date(); data.toString(); } - + @Test public void testArtifactLoader(){ ArtiDAO daoObj = new ArtiDAO(trans, cluster, "test"); @@ -154,18 +154,18 @@ public class JU_ArtiDAO { try { Object obj = constructor.newInstance(10); Method innnerClassMtd; - + ArtiDAO.Data data = new ArtiDAO.Data(); Row row = Mockito.mock(Row.class); innnerClassMtd = innerClass.getMethod("load", new Class[] {ArtiDAO.Data.class, Row.class}); innnerClassMtd.invoke(obj, new Object[] {data, row}); - + innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {ArtiDAO.Data.class, Integer.TYPE, Object[].class }); innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"} }); - + innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {ArtiDAO.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"} }); - + // DataInputStream in = Mockito.mock(DataInputStream.class); //// Mockito.doReturn(100).when(in).read(); //// Mockito.doReturn(100).when(in).readInt(); @@ -189,9 +189,9 @@ public class JU_ArtiDAO { } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); - } + } } - + @Test public void testSecondConstructor() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -203,10 +203,10 @@ public class JU_ArtiDAO { Mockito.doNothing().when(tt).done(); ArtiDAO.Data data = new ArtiDAO.Data(); HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - + ArtiDAO daoObj = new ArtiDAO(trans, historyDAO, Mockito.mock(CacheInfoDAO.class)); } - + } @@ -219,7 +219,7 @@ class ArtiDAOImpl extends ArtiDAO{ setPs(this, createPS, "psByMachine"); setPs(this, createPS, "psByNs"); } - + public ArtiDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace,PSInfo readPS, HistoryDAO historyDAO ) { super(trans, cluster, keyspace); this.deletePS = readPS; @@ -227,18 +227,18 @@ class ArtiDAOImpl extends ArtiDAO{ setHistoryDao(this, historyDAO); setSession(this, Mockito.mock(Session.class)); } - + public void setPs(ArtiDAOImpl ArtiDAOObj, PSInfo psInfoObj, String methodName) { Field nsDaoField; try { nsDaoField = ArtiDAO.class.getDeclaredField(methodName); - + 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(ArtiDAOObj, psInfoObj); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -256,13 +256,13 @@ class ArtiDAOImpl extends ArtiDAO{ Field nsDaoField; try { nsDaoField = ArtiDAO.class.getDeclaredField("historyDAO"); - + 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(ArtiDAOObj, historyDAO); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -279,13 +279,13 @@ class ArtiDAOImpl extends ArtiDAO{ 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(ArtiDAOObj, session); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_CacheInfoDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_CacheInfoDAO.java index c23a3729..695de1f0 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_CacheInfoDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_CacheInfoDAO.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. @@ -77,7 +77,7 @@ public class JU_CacheInfoDAO { AuthzEnv env; @Mock LogTarget logTarget; - + @Before public void setUp() throws APIException, IOException { initMocks(this); @@ -90,7 +90,7 @@ public class JU_CacheInfoDAO { Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LONGITUDE); Mockito.doReturn(session).when(cluster).connect("test"); } - + @Test public void testInit() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -103,7 +103,7 @@ public class JU_CacheInfoDAO { PSInfo createPS = Mockito.mock(PSInfo.class); Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data); - + CacheInfoDAOImpl daoObj=null; try { daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS); @@ -115,7 +115,7 @@ public class JU_CacheInfoDAO { Result<Data> retVal = daoObj.create(trans, data); assertTrue(retVal.status == 0); } - + @Test public void testTouch() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -128,12 +128,12 @@ public class JU_CacheInfoDAO { Mockito.doNothing().when(tt).done(); Mockito.doReturn(logTarget).when(env).debug(); - + CacheInfoDAO.Data data = new CacheInfoDAO.Data(); PSInfo createPS = Mockito.mock(PSInfo.class); Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data); - + CacheInfoDAOImpl daoObj=null; try { daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS); @@ -147,8 +147,8 @@ public class JU_CacheInfoDAO { Mockito.doThrow(DriverException.class).when(session).executeAsync(Mockito.anyString()); daoObj.startUpdate(env, Mockito.mock(HMangr.class), Mockito.mock(SecuritySetter.class), "12.0.0.1", 8080); retVal = daoObj.touch(trans, "test", 1, 2); - - + + try { daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS); } catch (APIException | IOException e) { @@ -175,7 +175,7 @@ public class JU_CacheInfoDAO { retVal = daoObj.touch(trans, "test", 1, 2); assertTrue(retVal.status == Result.ERR_Backend); } - + @Test public void testCheck() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -189,7 +189,7 @@ public class JU_CacheInfoDAO { PSInfo createPS = Mockito.mock(PSInfo.class); Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data); - + CacheInfoDAOImpl daoObj=null; PreparedStatement ps = Mockito.mock(PreparedStatement.class); Mockito.doReturn(ps).when(session).prepare(Mockito.anyString()); @@ -208,7 +208,7 @@ public class JU_CacheInfoDAO { Mockito.doReturn(resultSet).when(session).execute(Mockito.any(Statement.class)); Result<Void> retVal = daoObj.check(trans); assertTrue(retVal.status == 0); - + Row row = Mockito.mock(Row.class); Mockito.doReturn("test").when(row).getString(Mockito.anyInt()); rowList.add(row); @@ -243,9 +243,9 @@ public class JU_CacheInfoDAO { } @Test public void testStopUpdate() { - + CacheInfoDAO.stopUpdate(); - + } @@ -264,7 +264,7 @@ public class JU_CacheInfoDAO { PSInfo createPS = Mockito.mock(PSInfo.class); Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); Mockito.doReturn(rs).when(createPS).exec(trans, "CacheInfoDAOImpl CREATE", data); - + CacheInfoDAOImpl daoObj=null; try { daoObj = new CacheInfoDAOImpl(trans, cluster, "test",data, createPS); @@ -276,7 +276,7 @@ public class JU_CacheInfoDAO { } } */ - + @Test public void testWasMOdified() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -288,11 +288,11 @@ public class JU_CacheInfoDAO { Mockito.doNothing().when(tt).done(); CacheInfoDAO.Data data = new CacheInfoDAO.Data("test",1); PSInfo createPS = Mockito.mock(PSInfo.class); - + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - + CacheInfoDAOImpl daoObj=null; try { daoObj = new CacheInfoDAOImpl(trans, cluster, "test", createPS); @@ -301,10 +301,10 @@ public class JU_CacheInfoDAO { e.printStackTrace(); } daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); - - + + } - + @Test public void testInfoLoader(){ TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -338,12 +338,12 @@ public class JU_CacheInfoDAO { try { Object obj = constructor.newInstance(1); Method innnerClassMtd; - + CacheInfoDAO.Data data = new CacheInfoDAO.Data(); Row row = Mockito.mock(Row.class); innnerClassMtd = innerClass.getMethod("load", new Class[] {CacheInfoDAO.Data.class, Row.class}); innnerClassMtd.invoke(obj, new Object[] {data, row}); - + innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {CacheInfoDAO.Data.class, Integer.TYPE, Object[].class }); innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"}}); @@ -367,9 +367,9 @@ public class JU_CacheInfoDAO { } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); - } + } } - + @Test public void testCacheUpdate(){ TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -407,24 +407,24 @@ public class JU_CacheInfoDAO { Constructor<?> innerConstructor = innerInnerClass.getDeclaredConstructors()[0]; innerConstructor.setAccessible(true); Object innerClassObj = innerConstructor.newInstance(obj, trans); - + Method innnerClassMtd; - + CacheInfoDAO.Data data = new CacheInfoDAO.Data(); Row row = Mockito.mock(Row.class); Rcli rcli = Mockito.mock(Rcli.class); URI uri = new URI("ftp","admin:admin@geeksforgeeks.org:1234","/path/data","tt","ttd"); Mockito.doReturn(uri).when(rcli).getURI(); 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"); - + innnerClassMtd = innerInnerClass.getMethod("code", new Class[] {Rcli.class}); innnerClassMtd.invoke(innerClassObj, new Object[] {rcli}); - + org.onap.aaf.cadi.client.Future futureObj = Mockito.mock(org.onap.aaf.cadi.client.Future.class); 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"); Mockito.doReturn(true).when(futureObj).get(0); innnerClassMtd.invoke(innerClassObj, new Object[] {rcli}); - + uri = new URI("ftp","12.0.0.1:8080","/path/data","tt","ttd"); Mockito.doReturn(uri).when(rcli).getURI(); innnerClassMtd.invoke(innerClassObj, new Object[] {rcli}); @@ -458,9 +458,9 @@ public class JU_CacheInfoDAO { } catch (CadiException e) { // TODO Auto-generated catch block e.printStackTrace(); - } + } } - + @Test public void testIntHolder(){ TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -499,16 +499,16 @@ public class JU_CacheInfoDAO { innerConstructor.setAccessible(true); int[] a = new int[10]; Object innerClassObj = innerConstructor.newInstance(obj, a); - + Method innnerClassMtd=null; - + CacheInfoDAO.Data data = new CacheInfoDAO.Data(); Row row = Mockito.mock(Row.class); Rcli rcli = Mockito.mock(Rcli.class); URI uri = new URI("ftp","admin:admin@geeksforgeeks.org:1234","/path/data","tt","ttd"); Mockito.doReturn(uri).when(rcli).getURI(); 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"); - + Method[] allMtds = innerInnerClass.getDeclaredMethods(); for(Method indMtd:allMtds) { if(indMtd.getName().contains("add")) { @@ -516,8 +516,8 @@ public class JU_CacheInfoDAO { } } innnerClassMtd.invoke(innerClassObj, new Object[] {a}); - - + + } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -545,9 +545,9 @@ public class JU_CacheInfoDAO { } catch (CadiException e) { // TODO Auto-generated catch block e.printStackTrace(); - } + } } - + //@Test public void testSecondConstructor() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -580,24 +580,24 @@ class CacheInfoDAOImpl extends CacheInfoDAO{ // setPs(this, createPS, "psByStatus"); // setSession(this, Mockito.mock(Session.class)); } - + public CacheInfoDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace,PSInfo readPS ) throws APIException, IOException { super(trans, cluster, keyspace); this.readPS = readPS; } - + public void setPs(CacheInfoDAOImpl CacheInfoDAOObj, PSInfo psInfoObj, String methodName) { Field nsDaoField; try { nsDaoField = CacheInfoDAO.class.getDeclaredField(methodName); - + 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(CacheInfoDAOObj, psInfoObj); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -611,12 +611,12 @@ class CacheInfoDAOImpl extends CacheInfoDAO{ } } - + public void setSession(CacheInfoDAOImpl CacheInfoDAOObj, Session session) { Field nsDaoField; try { nsDaoField = AbsCassDAO.class.getDeclaredField("session"); - + nsDaoField.setAccessible(true); // remove final modifier from field Field modifiersField = Field.class.getDeclaredField("modifiers"); @@ -634,5 +634,5 @@ class CacheInfoDAOImpl extends CacheInfoDAO{ e.printStackTrace(); } } - + } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_CertDAOTest.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_CertDAOTest.java index 782bd985..718d9dec 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_CertDAOTest.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_CertDAOTest.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_CertDAOTest { AuthzEnv env; @Mock LogTarget logTarget; - + @Before public void setUp() throws APIException, IOException { initMocks(this); @@ -79,7 +79,7 @@ public class JU_CertDAOTest { Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LONGITUDE); Mockito.doReturn(session).when(cluster).connect("test"); } - + @Test public void testInit() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -92,7 +92,7 @@ public class JU_CertDAOTest { PSInfo createPS = Mockito.mock(PSInfo.class); Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); Mockito.doReturn(rs).when(createPS).exec(trans, "CertDAOImpl CREATE", data); - + CertDAOImpl daoObj=null; try { daoObj = new CertDAOImpl(trans, cluster, "test",data, createPS); @@ -102,17 +102,17 @@ public class JU_CertDAOTest { } } - + @Test public void testCertLoader(){ - + Class<?> innerClass = CertDAO.class.getDeclaredClasses()[0]; Constructor<?> constructor = innerClass.getDeclaredConstructors()[0]; constructor.setAccessible(true); try { Object obj = constructor.newInstance(1); Method innnerClassMtd; - + CertDAO.Data data = new CertDAO.Data(); Row row = Mockito.mock(Row.class); ByteBuffer bbObj = ByteBuffer.allocateDirect(10); @@ -121,16 +121,16 @@ public class JU_CertDAOTest { 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[] {CertDAO.Data.class, Row.class}); innnerClassMtd.invoke(obj, new Object[] {data, row}); - + innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {CertDAO.Data.class, Integer.TYPE, Object[].class }); innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"} }); -// +// innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {CertDAO.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"} }); - + // DataInputStream in = Mockito.mock(DataInputStream.class); //// Mockito.doReturn(100).when(in).read(); //// Mockito.doReturn(100).when(in).readInt(); @@ -154,9 +154,9 @@ public class JU_CertDAOTest { } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); - } + } } - + @Test public void testWasMOdified() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -168,14 +168,14 @@ public class JU_CertDAOTest { Mockito.doNothing().when(tt).done(); CertDAO.Data data = new CertDAO.Data(); PSInfo createPS = Mockito.mock(PSInfo.class); - + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); Mockito.doReturn(rs1).when(cacheInfoDAO).touch(trans, CertDAO.TABLE, new int[1]); - + CertDAO daoObj = null; try { daoObj = new CertDAO(trans, historyDAO, cacheInfoDAO); @@ -183,21 +183,21 @@ public class JU_CertDAOTest { // TODO Auto-generated catch block e.printStackTrace(); } - + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); - + rs1 = new Result<ResultSet>(null,1,"test",new String[0]); Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - + Mockito.doReturn(rs1).when(cacheInfoDAO).touch(trans, CertDAO.TABLE, new int[1]); - + try { daoObj = new CertDAO(trans, historyDAO, cacheInfoDAO); } catch (APIException | IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } - + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); daoObj.wasModified(trans, CRUD.delete, data, new String[] {"test"}); @@ -205,7 +205,7 @@ public class JU_CertDAOTest { daoObj.wasModified(trans, CRUD.delete, data, new String[] {"test", "test"}); daoObj.wasModified(trans, CRUD.delete, data, new String[] {null}); daoObj.wasModified(trans, CRUD.delete, data, new String[] {}); - + try { CertDAO.Data data1 = Mockito.mock(CertDAO.Data.class); Mockito.doThrow(new IOException()).when(data1).bytify(); @@ -216,7 +216,7 @@ public class JU_CertDAOTest { e.printStackTrace(); } } - + @Test public void testRead() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -235,14 +235,14 @@ public class JU_CertDAOTest { Mockito.doNothing().when(tt).done(); CertDAO.Data data = new CertDAO.Data(); PSInfo createPS = Mockito.mock(PSInfo.class); - + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - + CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); Mockito.doReturn(rs1).when(cacheInfoDAO).touch(trans, CertDAO.TABLE, new int[1]); - + CertDAOImpl daoObj = null; try { daoObj = new CertDAOImpl(trans, historyDAO, cacheInfoDAO, createPS); @@ -250,15 +250,15 @@ public class JU_CertDAOTest { // TODO Auto-generated catch block e.printStackTrace(); } - + daoObj.read(trans, new Object[] {"test", BigInteger.ONE}); Field cbField; try { cbField = CassAccess.class.getDeclaredField("cb"); - + cbField.setAccessible(true); // modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - + cbField.set(null, null); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -270,15 +270,15 @@ public class JU_CertDAOTest { // TODO Auto-generated catch block e.printStackTrace(); } - + daoObj.readX500(trans, "test"); - + try { cbField = CassAccess.class.getDeclaredField("cb"); - + cbField.setAccessible(true); // modifiersField.setInt(nsDaoField, nsDaoField.getModifiers() & ~Modifier.FINAL); - + cbField.set(null, null); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -290,11 +290,11 @@ public class JU_CertDAOTest { // TODO Auto-generated catch block e.printStackTrace(); } - - daoObj.readID(trans, "test"); + + daoObj.readID(trans, "test"); } - + @Test public void testSecondConstructor() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -328,24 +328,24 @@ class CertDAOImpl extends CertDAO{ // setPs(this, createPS, "psByStatus"); // setSession(this, Mockito.mock(Session.class)); } - + public CertDAOImpl(AuthzTrans trans, HistoryDAO historyDAO, CacheInfoDAO cacheInfoDAO,PSInfo readPS ) throws APIException, IOException { super(trans, historyDAO, cacheInfoDAO); this.readPS = readPS; } - + public void setPs(CertDAOImpl CertDAOObj, PSInfo psInfoObj, String methodName) { Field nsDaoField; try { nsDaoField = CertDAO.class.getDeclaredField(methodName); - + 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(CertDAOObj, psInfoObj); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -359,12 +359,12 @@ class CertDAOImpl extends CertDAO{ } } - + public void setSession(CertDAOImpl CertDAOObj, Session session) { Field nsDaoField; try { nsDaoField = AbsCassDAO.class.getDeclaredField("session"); - + nsDaoField.setAccessible(true); // remove final modifier from field Field modifiersField = Field.class.getDeclaredField("modifiers"); @@ -382,5 +382,5 @@ class CertDAOImpl extends CertDAO{ e.printStackTrace(); } } - + } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ConfigDAOTest.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ConfigDAOTest.java index 91d16970..30004e91 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ConfigDAOTest.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_ConfigDAOTest.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. @@ -73,7 +73,7 @@ public class JU_ConfigDAOTest { AuthzEnv env; @Mock LogTarget logTarget; - + @Before public void setUp() throws APIException, IOException { initMocks(this); @@ -86,7 +86,7 @@ public class JU_ConfigDAOTest { Mockito.doReturn("100").when(trans).getProperty(Config.CADI_LONGITUDE); Mockito.doReturn(session).when(cluster).connect("test"); } - + @Test public void testInit() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -99,7 +99,7 @@ public class JU_ConfigDAOTest { PSInfo createPS = Mockito.mock(PSInfo.class); Result<ResultSet> rs = new Result<ResultSet>(null,0,"test",new String[0]); Mockito.doReturn(rs).when(createPS).exec(trans, "ConfigDAOImpl CREATE", data); - + ConfigDAO daoObj=null; try { daoObj = new ConfigDAO(trans, cluster, "test"); @@ -109,17 +109,17 @@ public class JU_ConfigDAOTest { } } - + @Test public void testConfigLoader(){ - + Class<?> innerClass = ConfigDAO.class.getDeclaredClasses()[0]; Constructor<?> constructor = innerClass.getDeclaredConstructors()[0]; constructor.setAccessible(true); try { Object obj = constructor.newInstance(1); Method innnerClassMtd; - + ConfigDAO.Data data = new ConfigDAO.Data(); Row row = Mockito.mock(Row.class); ByteBuffer bbObj = ByteBuffer.allocateDirect(10); @@ -128,16 +128,16 @@ public class JU_ConfigDAOTest { 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[] {ConfigDAO.Data.class, Row.class}); innnerClassMtd.invoke(obj, new Object[] {data, row}); - + innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {ConfigDAO.Data.class, Integer.TYPE, Object[].class }); innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"} }); -// +// innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {ConfigDAO.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[] {ConfigDAO.Data.class, DataOutputStream.class }); @@ -147,7 +147,7 @@ public class JU_ConfigDAOTest { DataInputStream dis = new DataInputStream(bais); innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {ConfigDAO.Data.class, DataInputStream.class }); innnerClassMtd.invoke(obj, new Object[] {data, dis }); - + } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -166,9 +166,9 @@ public class JU_ConfigDAOTest { } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); - } + } } - + @Test public void testWasMOdified() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -180,7 +180,7 @@ public class JU_ConfigDAOTest { Mockito.doNothing().when(tt).done(); ConfigDAO.Data data = new ConfigDAO.Data(); PSInfo createPS = Mockito.mock(PSInfo.class); - + ConfigDAO daoObj = null; try { daoObj = new ConfigDAO(trans, cluster, "test"); @@ -188,13 +188,13 @@ public class JU_ConfigDAOTest { // TODO Auto-generated catch block e.printStackTrace(); } - + daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); - - - + + + } - + @Test public void testRead() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -210,9 +210,9 @@ public class JU_ConfigDAOTest { Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,null); Mockito.doReturn(Mockito.mock(Decryptor.class)).when(trans).decryptor(); Mockito.doNothing().when(tt).done(); - + Result<List<Data>> rs1 = new Result<List<Data>>(null,0,"test",new String[0]); - + PSInfo psObj = Mockito.mock(PSInfo.class); ConfigDAOImpl daoObj = null; @@ -224,12 +224,12 @@ public class JU_ConfigDAOTest { } Mockito.doReturn(rs1).when(psObj).read(trans, "ConfigDAO READ", new Object[]{"test"}); daoObj.readName(trans, "test"); - - + + } - - + + @Test public void testSecondConstructor() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -252,24 +252,24 @@ public class JU_ConfigDAOTest { class ConfigDAOImpl extends ConfigDAO{ - + public ConfigDAOImpl(AuthzTrans trans, Cluster cluster, String keyspace,PSInfo readPS ) throws APIException, IOException { super(trans, cluster, keyspace); setPs(this, readPS, "psName"); } - + public void setPs(ConfigDAOImpl ConfigDAOObj, PSInfo psInfoObj, String methodName) { Field nsDaoField; try { nsDaoField = ConfigDAO.class.getDeclaredField(methodName); - + 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(ConfigDAOObj, psInfoObj); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -283,12 +283,12 @@ class ConfigDAOImpl extends ConfigDAO{ } } - + public void setSession(ConfigDAOImpl ConfigDAOObj, Session session) { Field nsDaoField; try { nsDaoField = AbsCassDAO.class.getDeclaredField("session"); - + nsDaoField.setAccessible(true); // remove final modifier from field Field modifiersField = Field.class.getDeclaredField("modifiers"); @@ -306,5 +306,5 @@ class ConfigDAOImpl extends ConfigDAO{ e.printStackTrace(); } } - + } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_DelegateDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_DelegateDAO.java index 39d7492a..3826fcbe 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_DelegateDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_DelegateDAO.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. @@ -51,7 +51,7 @@ public class JU_DelegateDAO { AuthzTrans trans; @Mock Cluster cluster; - + @Before public void setUp() throws APIException, IOException { initMocks(this); @@ -65,27 +65,27 @@ public class JU_DelegateDAO { @Test public void testReadByDelegate() { DelegateDAO daoObj = new DelegateDAO(trans, cluster, "test"); - + PSInfo psObj = Mockito.mock(PSInfo.class); setPsDelegate(daoObj, psObj, "psByDelegate"); - + Result<List<DelegateDAO.Data>> rs1 = new Result<List<DelegateDAO.Data>>(null,0,"test",new String[0]); Mockito.doReturn(rs1).when(psObj).read(trans, "DelegateDAO READ", new Object[]{"test"}); - + daoObj.readByDelegate(trans, "test"); } - + public void setPsDelegate(DelegateDAO delegateDAOObj, PSInfo psInfoObj, String fieldName) { Field nsDaoField; try { nsDaoField = DelegateDAO.class.getDeclaredField(fieldName); - + 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(delegateDAOObj, psInfoObj); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -98,13 +98,13 @@ public class JU_DelegateDAO { e.printStackTrace(); } } - + @Test public void testSecondConstructor() { AbsCassDAO absDAO = Mockito.mock(AbsCassDAO.class); DelegateDAO daoObj = new DelegateDAO(trans, absDAO); - + } @Test @@ -117,13 +117,13 @@ public class JU_DelegateDAO { break; } } - + Constructor<?> constructor = innerClass.getDeclaredConstructors()[0]; constructor.setAccessible(true); try { Object obj = constructor.newInstance(1); Method innnerClassMtd; - + DelegateDAO.Data data = new DelegateDAO.Data(); Row row = Mockito.mock(Row.class); ByteBuffer bbObj = ByteBuffer.allocateDirect(10); @@ -132,16 +132,16 @@ public class JU_DelegateDAO { 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[] {DelegateDAO.Data.class, Row.class}); innnerClassMtd.invoke(obj, new Object[] {data, row}); - + innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {DelegateDAO.Data.class, Integer.TYPE, Object[].class }); innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"} }); -// +// innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {DelegateDAO.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"} }); - + // DataOutputStream dos = new DataOutputStream(new FileOutputStream("JU_DelegateDAOTest.java")); // innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {DelegateDAO.Data.class, DataOutputStream.class }); // innnerClassMtd.invoke(obj, new Object[] {data, dos }); @@ -149,7 +149,7 @@ public class JU_DelegateDAO { // DataInputStream dis = new DataInputStream(new FileInputStream("JU_DelegateDAOTest.java")); // innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {DelegateDAO.Data.class, DataInputStream.class }); // innnerClassMtd.invoke(obj, new Object[] {data, dis }); - + } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -168,9 +168,9 @@ public class JU_DelegateDAO { } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); - } + } } - + @Test public void testData(){ DelegateDAO.Data data = new DelegateDAO.Data(); @@ -184,5 +184,5 @@ public class JU_DelegateDAO { e.printStackTrace(); } } - + } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_FutureDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_FutureDAO.java index 07946156..f05738ea 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_FutureDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_FutureDAO.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. @@ -58,7 +58,7 @@ public class JU_FutureDAO { AuthzTrans trans; @Mock Cluster cluster; - + @Before public void setUp() throws APIException, IOException { initMocks(this); @@ -72,13 +72,13 @@ public class JU_FutureDAO { @Test public void testReadByStartAndTarget() { FutureDAO daoObj = new FutureDAO(trans, cluster, "test"); - + PSInfo psObj = Mockito.mock(PSInfo.class); setPsByStartAndTarget(daoObj, psObj, "psByStartAndTarget"); - + Result<List<FutureDAO.Data>> rs1 = new Result<List<FutureDAO.Data>>(null,0,"test",new String[0]); Mockito.doReturn(rs1).when(psObj).read(trans, "FutureDAO READ", new Object[]{"test"}); - + daoObj.readByStartAndTarget(trans,new Date(), "test"); } @Test @@ -91,7 +91,7 @@ public class JU_FutureDAO { Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); Mockito.doReturn(rs1).when(psObj).exec(trans, "FutureDAOImpl CREATE", data); Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - + FutureDAOImpl daoObj=null; try { daoObj = new FutureDAOImpl(trans, historyDAO, psObj); @@ -100,35 +100,35 @@ public class JU_FutureDAO { e.printStackTrace(); } Mockito.doReturn("test user").when(trans).user(); - + Result<FutureDAO.Data> retVal = daoObj.create(trans,data, "test"); assertTrue(retVal.status == 0); - + StringBuilder sb = new StringBuilder(trans.user()); sb.append(data.target); sb.append(System.currentTimeMillis()); data.id = UUID.nameUUIDFromBytes(sb.toString().getBytes()); - + rs1 = new Result<ResultSet>(null,1,"test",new String[0]); Mockito.doReturn(rs1).when(psObj).exec(trans, "FutureDAOImpl CREATE", data); - + retVal = daoObj.create(trans,data, "test"); assertTrue(retVal.status != 0); - - + + } - + public void setPsByStartAndTarget(FutureDAO FutureDAOObj, PSInfo psInfoObj, String fieldName) { Field nsDaoField; try { nsDaoField = FutureDAO.class.getDeclaredField(fieldName); - + 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(FutureDAOObj, psInfoObj); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -141,7 +141,7 @@ public class JU_FutureDAO { e.printStackTrace(); } } - + @Test public void testWasMOdified() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -154,11 +154,11 @@ public class JU_FutureDAO { Mockito.doNothing().when(tt).done(); FutureDAO.Data data = new FutureDAO.Data(); PSInfo createPS = Mockito.mock(PSInfo.class); - + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - + FutureDAOImpl daoObj = null; try { daoObj = new FutureDAOImpl(trans, historyDAO, createPS ); @@ -167,23 +167,23 @@ public class JU_FutureDAO { e.printStackTrace(); } daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); - + daoObj.wasModified(trans, CRUD.create, data, new String[] {}); daoObj.wasModified(trans, CRUD.create, data, new String[] {null}); daoObj.wasModified(trans, CRUD.create, data, new String[] {"test",null}); daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); - + rs1 = new Result<ResultSet>(null,1,"test",new String[0]); Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); } - + @Test public void testSecondConstructor() { HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); FutureDAO daoObj = new FutureDAO(trans, historyDAO); - + } @Test @@ -196,18 +196,18 @@ public class JU_FutureDAO { break; } } - + Constructor<?> constructor = innerClass.getDeclaredConstructors()[1]; constructor.setAccessible(true); - + Constructor<?> constructor1 = innerClass.getDeclaredConstructors()[0]; constructor1.setAccessible(true); try { - + Object obj = constructor.newInstance(1); obj = constructor1.newInstance(); Method innnerClassMtd; - + FutureDAO.Data data = new FutureDAO.Data(); Row row = Mockito.mock(Row.class); ByteBuffer bbObj = ByteBuffer.allocateDirect(10); @@ -216,16 +216,16 @@ public class JU_FutureDAO { 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[] {FutureDAO.Data.class, Row.class}); innnerClassMtd.invoke(obj, new Object[] {data, row}); - + innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {FutureDAO.Data.class, Integer.TYPE, Object[].class }); innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"} }); -// +// innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {FutureDAO.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"} }); - + // DataOutputStream dos = new DataOutputStream(new FileOutputStream("JU_FutureDAOTest.java")); // innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {FutureDAO.Data.class, DataOutputStream.class }); // innnerClassMtd.invoke(obj, new Object[] {data, dos }); @@ -233,7 +233,7 @@ public class JU_FutureDAO { // DataInputStream dis = new DataInputStream(new FileInputStream("JU_FutureDAOTest.java")); // innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {FutureDAO.Data.class, DataInputStream.class }); // innnerClassMtd.invoke(obj, new Object[] {data, dis }); - + } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -252,31 +252,31 @@ public class JU_FutureDAO { } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); - } + } } - + } class FutureDAOImpl extends FutureDAO{ - + public FutureDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,PSInfo readPS ) throws APIException, IOException { super(trans, historyDAO); setPs(this, readPS, "createPS"); } - + public void setPs(FutureDAOImpl FutureDAOObj, PSInfo psInfoObj, String methodName) { Field nsDaoField; try { nsDaoField = CassDAOImpl.class.getDeclaredField(methodName); - + 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(FutureDAOObj, psInfoObj); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -289,5 +289,5 @@ class FutureDAOImpl extends FutureDAO{ e.printStackTrace(); } } - + } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_HistoryDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_HistoryDAO.java index f6d0a65b..3503adff 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_HistoryDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_HistoryDAO.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. @@ -61,7 +61,7 @@ public class JU_HistoryDAO { AuthzTrans trans; @Mock Cluster cluster; - + @Before public void setUp() throws APIException, IOException { initMocks(this); @@ -77,7 +77,7 @@ public class JU_HistoryDAO { HistoryDAO.Data data = daoObj.newInitedData(); assertTrue( Integer.toString(((new Date()).getYear())+1900).equalsIgnoreCase(Integer.toString(data.yr_mon).substring(0,4)) ); } - + @Test public void testCreateBatch() { HistoryDAO daoObj = new HistoryDAO(trans, cluster, "test"); @@ -86,81 +86,81 @@ public class JU_HistoryDAO { daoObj.createBatch(sb, data); assertTrue(sb.toString().contains("INSERT INTO history")); } - + @Test public void testReadByYYYYMM() { HistoryDAO daoObj = new HistoryDAO(trans, cluster, "test"); AbsCassDAO<AuthzTrans, Data>.PSInfo psInfoObj = Mockito.mock(PSInfo.class); setAbsCassDAO(daoObj, psInfoObj, "readByYRMN"); - + ResultSet rs = Mockito.mock(ResultSet.class); Result<ResultSet> rs1 = new Result<ResultSet>(rs,0,"test",new String[0]); Mockito.doReturn(rs1).when(psInfoObj).exec(trans, "yr_mon", 201905); - + Result<List<Data>> retVal = daoObj.readByYYYYMM(trans, 201905); assertTrue(retVal.status !=1); - + rs1 = new Result<ResultSet>(rs,1,"test",new String[0]); Mockito.doReturn(rs1).when(psInfoObj).exec(trans, "yr_mon", 201905); retVal = daoObj.readByYYYYMM(trans, 201905); assertTrue(retVal.status !=0); } - + @Test public void testReadByUser() { HistoryDAO daoObj = new HistoryDAO(trans, cluster, "test"); AbsCassDAO<AuthzTrans, Data>.PSInfo psInfoObj = Mockito.mock(PSInfo.class); setAbsCassDAO(daoObj, psInfoObj, "readByUser"); - + ResultSet rs = Mockito.mock(ResultSet.class); Result<ResultSet> rs1 = new Result<ResultSet>(rs,0,"test",new String[0]); Mockito.doReturn(rs1).when(psInfoObj).exec(trans, "user", "test"); - + Result<List<Data>> retVal = daoObj.readByUser(trans, "test", 201905); assertTrue(retVal.status !=1); - + rs1 = new Result<ResultSet>(rs,1,"test",new String[0]); Mockito.doReturn(rs1).when(psInfoObj).exec(trans, "user", "test"); retVal = daoObj.readByUser(trans,"test", 201905); assertTrue(retVal.status !=0); - + retVal = daoObj.readByUser(trans,"test"); assertTrue(retVal.status !=0); } - + @Test public void testReadBySubject() { HistoryDAO daoObj = new HistoryDAO(trans, cluster, "test"); AbsCassDAO<AuthzTrans, Data>.PSInfo psInfoObj = Mockito.mock(PSInfo.class); setAbsCassDAO(daoObj, psInfoObj, "readBySubject"); - + ResultSet rs = Mockito.mock(ResultSet.class); Result<ResultSet> rs1 = new Result<ResultSet>(rs,0,"test",new String[0]); Mockito.doReturn(rs1).when(psInfoObj).exec(trans, "subject", "test", "test"); - + Result<List<Data>> retVal = daoObj.readBySubject(trans, "test", "test", 201905); assertTrue(retVal.status !=1); - + rs1 = new Result<ResultSet>(rs,1,"test",new String[0]); Mockito.doReturn(rs1).when(psInfoObj).exec(trans, "subject", "test", "test"); retVal = daoObj.readBySubject(trans,"test", "test", 201905); assertTrue(retVal.status !=0); - + retVal = daoObj.readBySubject(trans,"test", "test"); assertTrue(retVal.status !=0); } - + public void setAbsCassDAO(HistoryDAO HistoryDAOObj, PSInfo psInfoObj, String fieldName) { Field nsDaoField; try { nsDaoField = HistoryDAO.class.getDeclaredField(fieldName); - + 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(HistoryDAOObj, psInfoObj); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -173,14 +173,14 @@ public class JU_HistoryDAO { e.printStackTrace(); } } - - + + @Test public void testSecondConstructor() { HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); HistoryDAO daoObj = new HistoryDAO(trans, historyDAO); - + } @Test @@ -193,14 +193,14 @@ public class JU_HistoryDAO { break; } } - + Constructor<?> constructor = innerClass.getDeclaredConstructors()[0]; constructor.setAccessible(true); - + try { Object obj = constructor.newInstance(1); Method innnerClassMtd; - + HistoryDAO.Data data = new HistoryDAO.Data(); Row row = Mockito.mock(Row.class); ByteBuffer bbObj = ByteBuffer.allocateDirect(10); @@ -209,16 +209,16 @@ public class JU_HistoryDAO { 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[] {HistoryDAO.Data.class, Row.class}); innnerClassMtd.invoke(obj, new Object[] {data, row}); - + innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {HistoryDAO.Data.class, Integer.TYPE, Object[].class }); innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"} }); -// +// innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {HistoryDAO.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"} }); - + } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -237,9 +237,9 @@ public class JU_HistoryDAO { } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); - } + } } - + @Test public void testYYYYMM(){ Class<?> innerClass = null; @@ -250,14 +250,14 @@ public class JU_HistoryDAO { break; } } - + Constructor<?> constructor = innerClass.getDeclaredConstructors()[0]; constructor.setAccessible(true); int yyyymm[] = new int[2]; try { Object obj = constructor.newInstance(new HistoryDAO(trans, cluster, "test"), yyyymm); Method innnerClassMtd; - + HistoryDAO.Data data = new HistoryDAO.Data(); Row row = Mockito.mock(Row.class); ByteBuffer bbObj = ByteBuffer.allocateDirect(10); @@ -266,13 +266,13 @@ public class JU_HistoryDAO { bbObj.put(1, new Byte("1")); bbObj.put(2, new Byte("2")); Mockito.doReturn(bbObj).when(row).getBytesUnsafe(1); - + innnerClassMtd = innerClass.getMethod("ok", new Class[] {HistoryDAO.Data.class}); innnerClassMtd.invoke(obj, new Object[] {data}); - + data.yr_mon=201904; innnerClassMtd.invoke(obj, new Object[] {data}); - + } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -291,30 +291,30 @@ public class JU_HistoryDAO { } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); - } + } } - + } class HistoryDAOImpl extends HistoryDAO{ - + public HistoryDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,PSInfo readPS ) throws APIException, IOException { super(trans, historyDAO); setPs(this, readPS, "createPS"); } - + public void setPs(HistoryDAOImpl HistoryDAOObj, PSInfo psInfoObj, String methodName) { Field nsDaoField; try { nsDaoField = CassDAOImpl.class.getDeclaredField(methodName); - + 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(HistoryDAOObj, psInfoObj); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -327,5 +327,5 @@ class HistoryDAOImpl extends HistoryDAO{ e.printStackTrace(); } } - + } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_LocateDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_LocateDAO.java index 53bad44e..d4f2c981 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_LocateDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_LocateDAO.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. @@ -60,7 +60,7 @@ public class JU_LocateDAO { AuthzTrans trans; @Mock Cluster cluster; - + @Before public void setUp() throws APIException, IOException { initMocks(this); @@ -84,28 +84,28 @@ public class JU_LocateDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + PSInfo psObj = Mockito.mock(PSInfo.class); setPsByStartAndTarget(daoObj, psObj, "psName"); - + Result<List<LocateDAO.Data>> rs1 = new Result<List<LocateDAO.Data>>(null,0,"test",new String[0]); Mockito.doReturn(rs1).when(psObj).read(trans, "LocateDAO READ", new Object[]{"test"}); - + daoObj.readByName(trans, "test"); } - - + + public void setPsByStartAndTarget(LocateDAO LocateDAOObj, PSInfo psInfoObj, String fieldName) { Field nsDaoField; try { nsDaoField = LocateDAO.class.getDeclaredField(fieldName); - + 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(LocateDAOObj, psInfoObj); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -118,14 +118,14 @@ public class JU_LocateDAO { e.printStackTrace(); } } - + @Test public void testWasMOdified() { - + LocateDAO.Data data = new LocateDAO.Data(); - + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); - + LocateDAO daoObj = null; try { daoObj = new LocateDAO(trans, historyDAO ); @@ -134,10 +134,10 @@ public class JU_LocateDAO { e.printStackTrace(); } daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); - - + + } - + @Test public void testSecondConstructor() { AbsCassDAO historyDAO = Mockito.mock(AbsCassDAO.class); @@ -148,7 +148,7 @@ public class JU_LocateDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + } @Test @@ -161,15 +161,15 @@ public class JU_LocateDAO { break; } } - + Constructor<?> constructor = innerClass.getDeclaredConstructors()[0]; constructor.setAccessible(true); - + try { - + Object obj = constructor.newInstance(1); Method innnerClassMtd; - + LocateDAO.Data data = new LocateDAO.Data(); Row row = Mockito.mock(Row.class); ByteBuffer bbObj = ByteBuffer.allocateDirect(10); @@ -178,16 +178,16 @@ public class JU_LocateDAO { 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[] {LocateDAO.Data.class, Row.class}); innnerClassMtd.invoke(obj, new Object[] {data, row}); - + innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {LocateDAO.Data.class, Integer.TYPE, Object[].class }); innnerClassMtd.invoke(obj, new Object[] {data, 0, new Object[] {"test","test","test"} }); - + innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {LocateDAO.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[] {LocateDAO.Data.class, DataOutputStream.class }); @@ -197,7 +197,7 @@ public class JU_LocateDAO { DataInputStream dis = new DataInputStream(bais); innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {LocateDAO.Data.class, DataInputStream.class }); innnerClassMtd.invoke(obj, new Object[] {data, dis }); - + } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -216,9 +216,9 @@ public class JU_LocateDAO { } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); - } + } } - + @Test public void testData(){ LocateDAO.Data data = new LocateDAO.Data(); @@ -230,16 +230,16 @@ public class JU_LocateDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + data.subprotocol(true); - + Set<String> subProt = new HashSet<String>(); Field protField; try { protField = LocateDAO.Data.class.getDeclaredField("subprotocol"); - + protField.setAccessible(true); - + protField.set(data, subProt); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -251,15 +251,15 @@ public class JU_LocateDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + data.subprotocol(true); subProt = new TreeSet<String>(); subProt.add("test"); try { protField = LocateDAO.Data.class.getDeclaredField("subprotocol"); - + protField.setAccessible(true); - + protField.set(data, subProt); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -271,36 +271,36 @@ public class JU_LocateDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + data.subprotocol(true); data.subprotocol(false); - + LocateDAO.Data newDate = data.copy(); assertTrue(data.name.equals(newDate.name)); } - + } class LocateDAOImpl extends LocateDAO{ - + public LocateDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,PSInfo readPS ) throws APIException, IOException { super(trans, historyDAO); setPs(this, readPS, "createPS"); } - + public void setPs(LocateDAOImpl LocateDAOObj, PSInfo psInfoObj, String methodName) { Field nsDaoField; try { nsDaoField = CassDAOImpl.class.getDeclaredField(methodName); - + 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(LocateDAOObj, psInfoObj); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -313,5 +313,5 @@ class LocateDAOImpl extends LocateDAO{ e.printStackTrace(); } } - + } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_Namespace.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_Namespace.java index 6bdb3d76..e1c13999 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_Namespace.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_Namespace.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. @@ -38,7 +38,7 @@ import org.onap.aaf.misc.env.APIException; public class JU_Namespace { Namespace namespace; - + @Before public void setUp() throws APIException, IOException { initMocks(this); @@ -56,9 +56,9 @@ public class JU_Namespace { data.attrib.put("test", "test"); namespace = new Namespace(data); } - - - + + + @Test public void testSecondConstructor() { @@ -72,10 +72,10 @@ public class JU_Namespace { namespace = new Namespace(data,owner, admin); data.attrib.put("test", "test"); namespace = new Namespace(data ,owner, admin); - + NsDAO.Data retData = namespace.data(); assertTrue(retData.name.equals("name")); - + } @Test public void testBytify() { @@ -101,5 +101,5 @@ public class JU_Namespace { nameObj = new Namespace(data); assertTrue(namespace.equals(nameObj)); } - + }
\ No newline at end of file diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_NsDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_NsDAO.java index 9be4f5a2..3923d7e4 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_NsDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_NsDAO.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. @@ -76,7 +76,7 @@ public class JU_NsDAO { Session session; @Mock ResultSet rs; - + @Before public void setUp() throws APIException, IOException { initMocks(this); @@ -105,18 +105,18 @@ public class JU_NsDAO { e.printStackTrace(); } } - + public void setPsByStartAndTarget(NsDAO NsDAOObj, PSInfo psInfoObj, String fieldName) { Field nsDaoField; try { nsDaoField = NsDAO.class.getDeclaredField(fieldName); - + 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(NsDAOObj, psInfoObj); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -129,7 +129,7 @@ public class JU_NsDAO { e.printStackTrace(); } } - + @Test public void testWasMOdified() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -141,13 +141,13 @@ public class JU_NsDAO { Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); Mockito.doNothing().when(tt).done(); NsDAO.Data data = new NsDAO.Data(); - + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new Object[0]); Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); CacheInfoDAO cacheInfoDAO = Mockito.mock(CacheInfoDAO.class); Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); - + NsDAO daoObj = null; try { daoObj = new NsDAO(trans, historyDAO, cacheInfoDAO); @@ -156,17 +156,17 @@ public class JU_NsDAO { e.printStackTrace(); } daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); - + daoObj.wasModified(trans, CRUD.create, data, new String[] {}); daoObj.wasModified(trans, CRUD.create, data, new String[] {null}); daoObj.wasModified(trans, CRUD.create, data, new String[] {"test",null}); daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); - + rs1 = new Result<ResultSet>(null,1,"test",new Object[0]); Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); } - + @Test public void testSecondConstructor() { HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); @@ -178,7 +178,7 @@ public class JU_NsDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + } @Test @@ -191,15 +191,15 @@ public class JU_NsDAO { break; } } - + Constructor<?> constructor = innerClass.getDeclaredConstructors()[0]; constructor.setAccessible(true); - + try { - + Object obj = constructor.newInstance(1); Method innnerClassMtd; - + NsDAO.Data data = new NsDAO.Data(); Row row = Mockito.mock(Row.class); ByteBuffer bbObj = ByteBuffer.allocateDirect(10); @@ -208,16 +208,16 @@ public class JU_NsDAO { 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[] {NsDAO.Data.class, Row.class}); innnerClassMtd.invoke(obj, new Object[] {data, row}); - + innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {NsDAO.Data.class, Integer.TYPE, Object[].class }); innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"} }); -// +// innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {NsDAO.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[] {NsDAO.Data.class, DataOutputStream.class }); @@ -227,7 +227,7 @@ public class JU_NsDAO { DataInputStream dis = new DataInputStream(bais); innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {NsDAO.Data.class, DataInputStream.class }); innnerClassMtd.invoke(obj, new Object[] {data, dis }); - + } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -246,7 +246,7 @@ public class JU_NsDAO { } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); - } + } } @Test public void testCreate() { @@ -267,7 +267,7 @@ public class JU_NsDAO { e.printStackTrace(); } Mockito.doReturn("test user").when(trans).user(); - + Result<NsDAO.Data> retVal = daoObj.create(trans,data); assertTrue(retVal.status == 4); @@ -278,7 +278,7 @@ public class JU_NsDAO { data.parent = "parent"; data.attrib = new HashMap<>(); data.attrib.put("test", "test"); - + Field cbField; Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); try { @@ -295,10 +295,10 @@ public class JU_NsDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + retVal = daoObj.create(trans,data); assertTrue(retVal.status == 9); - + Field owningField; Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); try { @@ -317,9 +317,9 @@ public class JU_NsDAO { } retVal = daoObj.create(trans,data); assertTrue(retVal.status == 0); - + } - + @Test public void testUpdate() { PSInfo psObj = Mockito.mock(PSInfo.class); @@ -340,7 +340,7 @@ public class JU_NsDAO { e.printStackTrace(); } Mockito.doReturn("test user").when(trans).user(); - + Result<Void> retVal = daoObj.update(trans,data); assertTrue(retVal.status == 4); @@ -367,10 +367,10 @@ public class JU_NsDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + retVal = daoObj.update(trans,data); assertTrue(retVal.status == 0); - + ResultSet rsMock = Mockito.mock(ResultSet.class); Iterator<Row> iteMock = Mockito.mock(Iterator.class); Mockito.doReturn(iteMock).when(rsMock).iterator(); @@ -382,7 +382,7 @@ public class JU_NsDAO { retVal = daoObj.update(trans,data); assertTrue(retVal.status == 0); } - + @Test public void testRead() { PSInfo psObj = Mockito.mock(PSInfo.class); @@ -408,7 +408,7 @@ public class JU_NsDAO { e.printStackTrace(); } Mockito.doReturn("test user").when(trans).user(); - + Result<List<Data>> retVal = daoObj.read(trans,data); assertTrue(retVal.status == 0); @@ -436,7 +436,7 @@ public class JU_NsDAO { assertTrue(retVal.status == 0); } - + @Test public void testReadByObject() { PSInfo psObj = Mockito.mock(PSInfo.class); @@ -462,7 +462,7 @@ public class JU_NsDAO { e.printStackTrace(); } Mockito.doReturn("test user").when(trans).user(); - + Result<List<Data>> retVal = daoObj.read(trans,new Object[] {}); assertTrue(retVal.status == 0); @@ -490,7 +490,7 @@ public class JU_NsDAO { assertTrue(retVal.status == 0); } - + @Test public void testDelete() { PSInfo psObj = Mockito.mock(PSInfo.class); @@ -533,7 +533,7 @@ public class JU_NsDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + Result<Void> retVal = daoObj.delete(trans,data, false); assertTrue(retVal.status == 0); @@ -541,12 +541,12 @@ public class JU_NsDAO { dataAL.add(data); rs1 = new Result<List<Data>>(dataAL,0,"test",new Object[0]); Mockito.doReturn(rs1).when(psObj).read(trans, "NsDAOImpl READ", data); - + retVal = daoObj.delete(trans,data, false); assertTrue(retVal.status == 0); } - + @Test public void testReadNsByAttrib() { PSInfo psObj = Mockito.mock(PSInfo.class); @@ -560,7 +560,7 @@ public class JU_NsDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); @@ -572,7 +572,7 @@ public class JU_NsDAO { Mockito.doReturn(rs1).when(psObj).read(trans, "NsDAOImpl READ", data); Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl DELETE", data); Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - + Mockito.doReturn("test user").when(trans).user(); Field cbField; try { @@ -589,10 +589,10 @@ public class JU_NsDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + Result<Set<String>> retVal = daoObj.readNsByAttrib(trans,"test"); assertTrue(retVal.status == 0); - + ResultSet rsMock = Mockito.mock(ResultSet.class); Iterator<Row> iteMock = Mockito.mock(Iterator.class); Mockito.doReturn(iteMock).when(rsMock).iterator(); @@ -619,7 +619,7 @@ public class JU_NsDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); @@ -631,7 +631,7 @@ public class JU_NsDAO { Mockito.doReturn(rs1).when(psObj).read(trans, "NsDAOImpl READ", data); Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl DELETE", data); Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - + Mockito.doReturn("test user").when(trans).user(); Field cbField; try { @@ -648,11 +648,11 @@ public class JU_NsDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + Result<Void> retVal = daoObj.attribAdd(trans, "test", "test", "test"); assertTrue(retVal.status == 0); } - + @Test public void testAttribRemove() { PSInfo psObj = Mockito.mock(PSInfo.class); @@ -666,7 +666,7 @@ public class JU_NsDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); @@ -678,7 +678,7 @@ public class JU_NsDAO { Mockito.doReturn(rs1).when(psObj).read(trans, "NsDAOImpl READ", data); Mockito.doReturn(rs1).when(psObj).exec(trans, "NsDAOImpl DELETE", data); Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - + Mockito.doReturn("test user").when(trans).user(); Field cbField; try { @@ -695,11 +695,11 @@ public class JU_NsDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + Result<Void> retVal = daoObj.attribRemove(trans, "test", "test"); assertTrue(retVal.status == 0); } - + @Test public void testAddDescription() { PSInfo psObj = Mockito.mock(PSInfo.class); @@ -713,7 +713,7 @@ public class JU_NsDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); @@ -744,11 +744,11 @@ public class JU_NsDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + Result<Void> retVal = daoObj.addDescription(trans, "test", "test"); assertTrue(retVal.status == 0); } - + @Test public void testGetChildren() { PSInfo psObj = Mockito.mock(PSInfo.class); @@ -761,11 +761,11 @@ public class JU_NsDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + Result<List<Data>> retVal = daoObj.getChildren(trans, "test"); assertNull(retVal); } - + @Test public void testData() { NsDAO.Data data = new NsDAO.Data(); @@ -778,10 +778,10 @@ public class JU_NsDAO { data.attrib(false); data.attrib = new ConcurrentHashMap<>(); data.attrib(true); - + data.name="123"; data.split("test"); - + data.toString(); } @@ -789,12 +789,12 @@ public class JU_NsDAO { class NsDAOImpl extends NsDAO{ - + // public NsDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,PSInfo readPS ) throws APIException, IOException { // super(trans, historyDAO); // setSession(this, Mockito.mock(Session.class)); // } - + public NsDAOImpl(AuthzTrans trans, Cluster cluster, String keySpace, Session session)throws APIException, IOException { super(trans, cluster, keySpace); @@ -816,13 +816,13 @@ class NsDAOImpl extends NsDAO{ Field nsDaoField; try { nsDaoField = NsDAO.class.getDeclaredField(methodName); - + 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(NsDAOObj, psInfoObj); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -840,13 +840,13 @@ class NsDAOImpl extends NsDAO{ Field nsDaoField; try { nsDaoField = CassDAOImpl.class.getDeclaredField(methodName); - + 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(NsDAOObj, psInfoObj); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -863,13 +863,13 @@ class NsDAOImpl extends NsDAO{ 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 diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_OAuthTokenDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_OAuthTokenDAO.java index 5c158b6a..93c595d4 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_OAuthTokenDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_OAuthTokenDAO.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. @@ -63,7 +63,7 @@ public class JU_OAuthTokenDAO { AuthzTrans trans; @Mock Cluster cluster; - + @Before public void setUp() throws APIException, IOException { initMocks(this); @@ -77,27 +77,27 @@ public class JU_OAuthTokenDAO { @Test public void testReadByUser() { OAuthTokenDAO daoObj = new OAuthTokenDAO(trans, cluster, "test"); - + PSInfo psObj = Mockito.mock(PSInfo.class); setPsByStartAndTarget(daoObj, psObj, "psByUser"); - + Result<List<OAuthTokenDAO.Data>> rs1 = new Result<List<OAuthTokenDAO.Data>>(null,0,"test",new String[0]); Mockito.doReturn(rs1).when(psObj).read(trans, "OAuthTokenDAO READ", new Object[]{"test"}); - + daoObj.readByUser(trans, "test"); } - + public void setPsByStartAndTarget(OAuthTokenDAO OAuthTokenDAOObj, PSInfo psInfoObj, String fieldName) { Field nsDaoField; try { nsDaoField = OAuthTokenDAO.class.getDeclaredField(fieldName); - + 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(OAuthTokenDAOObj, psInfoObj); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -110,7 +110,7 @@ public class JU_OAuthTokenDAO { e.printStackTrace(); } } - + @Test public void testWasMOdified() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -126,15 +126,15 @@ public class JU_OAuthTokenDAO { OAuthTokenDAO daoObj = null; daoObj = new OAuthTokenDAO(trans, cluster, "test" ); daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); - + } - + @Test public void testSecondConstructor() { AbsCassDAO absCassDAO = Mockito.mock(AbsCassDAO.class); OAuthTokenDAO daoObj = new OAuthTokenDAO(trans, absCassDAO); - + } @Test @@ -149,15 +149,15 @@ public class JU_OAuthTokenDAO { data.scopes(false); data.scopes = new ConcurrentHashSet<>(); data.scopes(true); - + data.expires = new Date(); data.user="test"; data.id="id"; data.toString(); - + data.active=true; data.toString(); - + try { ByteBuffer bb = data.bytify(); data.reconstitute(bb); @@ -176,15 +176,15 @@ public class JU_OAuthTokenDAO { break; } } - + Constructor<?> constructor = innerClass.getDeclaredConstructors()[0]; constructor.setAccessible(true); - + try { - + Object obj = constructor.newInstance(1); Method innnerClassMtd; - + OAuthTokenDAO.Data data = new OAuthTokenDAO.Data(); Row row = Mockito.mock(Row.class); ByteBuffer bbObj = ByteBuffer.allocateDirect(10); @@ -193,16 +193,16 @@ public class JU_OAuthTokenDAO { 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[] {OAuthTokenDAO.Data.class, Row.class}); innnerClassMtd.invoke(obj, new Object[] {data, row}); - + innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {OAuthTokenDAO.Data.class, Integer.TYPE, Object[].class }); innnerClassMtd.invoke(obj, new Object[] {data, 1, new Object[] {"test","test","test"} }); -// +// innnerClassMtd = innerClass.getDeclaredMethod("body", new Class[] {OAuthTokenDAO.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","test"} }); - + ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); innnerClassMtd = innerClass.getDeclaredMethod("marshal", new Class[] {OAuthTokenDAO.Data.class, DataOutputStream.class }); @@ -212,7 +212,7 @@ public class JU_OAuthTokenDAO { DataInputStream dis = new DataInputStream(bais); innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {OAuthTokenDAO.Data.class, DataInputStream.class }); innnerClassMtd.invoke(obj, new Object[] {data, dis }); - + } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -231,31 +231,31 @@ public class JU_OAuthTokenDAO { } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); - } + } } - + } class OAuthTokenDAOImpl extends OAuthTokenDAO{ - + public OAuthTokenDAOImpl(AuthzTrans trans, HistoryDAO historyDAO,PSInfo readPS ) throws APIException, IOException { super(trans, historyDAO); setPs(this, readPS, "createPS"); } - + public void setPs(OAuthTokenDAOImpl OAuthTokenDAOObj, PSInfo psInfoObj, String methodName) { Field nsDaoField; try { nsDaoField = CassDAOImpl.class.getDeclaredField(methodName); - + 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(OAuthTokenDAOObj, psInfoObj); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -268,5 +268,5 @@ class OAuthTokenDAOImpl extends OAuthTokenDAO{ e.printStackTrace(); } } - + } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_PermDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_PermDAO.java index 57f39922..28f92890 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_PermDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_PermDAO.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. @@ -69,7 +69,7 @@ public class JU_PermDAO { Cluster cluster; @Mock Session session; - + @Before public void setUp() throws APIException, IOException { initMocks(this); @@ -114,13 +114,13 @@ public class JU_PermDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + PSInfo psObj = Mockito.mock(PSInfo.class); setPsByStartAndTarget(daoObj, psObj, "psByType"); - + Result<List<PermDAO.Data>> rs1 = new Result<List<PermDAO.Data>>(null,0,"test",new String[0]); Mockito.doReturn(rs1).when(psObj).read(trans, "PermDAO READ", new Object[]{"test"}); - + daoObj.readByType(trans, "test", "test"); } @Test @@ -138,13 +138,13 @@ public class JU_PermDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + PSInfo psObj = Mockito.mock(PSInfo.class); setPsByStartAndTarget(daoObj, psObj, "psChildren"); - + Result<List<PermDAO.Data>> rs1 = new Result<List<PermDAO.Data>>(null,0,"test",new String[0]); Mockito.doReturn(rs1).when(psObj).read(trans, "PermDAO READ", new Object[]{"test"}); - + daoObj.readChildren(trans, "test", "test"); } @Test @@ -162,13 +162,13 @@ public class JU_PermDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + PSInfo psObj = Mockito.mock(PSInfo.class); setPsByStartAndTarget(daoObj, psObj, "psNS"); - + Result<List<PermDAO.Data>> rs1 = new Result<List<PermDAO.Data>>(null,0,"test",new String[0]); Mockito.doReturn(rs1).when(psObj).read(trans, "PermDAO READ", new Object[]{"test"}); - + daoObj.readNS(trans, "test"); } @Test @@ -190,7 +190,7 @@ public class JU_PermDAO { Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on PermDAO", Env.SUB); - + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); @@ -202,10 +202,10 @@ public class JU_PermDAO { Mockito.doReturn(rs1).when(psObj).read(trans, "PermDAOImpl READ", data); Mockito.doReturn(rs1).when(psObj).exec(trans, "PermDAOImpl DELETE", data); Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - + Result<Void> rs2 = new Result<Void>(null,0,"test",new String[0]); Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); - + rs1 = new Result<List<Data>>(null,1,"test",new String[0]); Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); Mockito.doReturn("test user").when(trans).user(); @@ -224,11 +224,11 @@ public class JU_PermDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + PermDAO.Data perm = new PermDAO.Data(); Result<Void> retVal = daoObj.addRole(trans, perm, "test"); assertTrue(retVal.status == 9); - + Field owningField; try { owningField = AbsCassDAO.class.getDeclaredField("owningDAO"); @@ -247,7 +247,7 @@ public class JU_PermDAO { retVal = daoObj.addRole(trans, perm, "test"); assertTrue(retVal.status == 0); } - + @Test public void testDelRole() { PSInfo psObj = Mockito.mock(PSInfo.class); @@ -267,7 +267,7 @@ public class JU_PermDAO { Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on PermDAO", Env.SUB); - + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); @@ -279,14 +279,14 @@ public class JU_PermDAO { Mockito.doReturn(rs1).when(psObj).read(trans, "PermDAOImpl READ", data); Mockito.doReturn(rs1).when(psObj).exec(trans, "PermDAOImpl DELETE", data); Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - + Result<Void> rs2 = new Result<Void>(null,0,"test",new String[0]); Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); - + rs1 = new Result<List<Data>>(null,1,"test",new String[0]); Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); Mockito.doReturn("test user").when(trans).user(); - + PermDAO.Data perm = new PermDAO.Data(); Field cbField; try { @@ -303,10 +303,10 @@ public class JU_PermDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + Result<Void> retVal = daoObj.delRole(trans, perm, "test"); assertTrue(retVal.status == 9); - + Field owningDaoField; try { owningDaoField = AbsCassDAO.class.getDeclaredField("owningDAO"); @@ -325,7 +325,7 @@ public class JU_PermDAO { retVal = daoObj.delRole(trans, perm, "test"); assertTrue(retVal.status == 0); } - + @Test public void testAddDescription() { PSInfo psObj = Mockito.mock(PSInfo.class); @@ -345,7 +345,7 @@ public class JU_PermDAO { Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on PermDAO", Env.SUB); - + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); @@ -357,14 +357,14 @@ public class JU_PermDAO { Mockito.doReturn(rs1).when(psObj).read(trans, "PermDAOImpl READ", data); Mockito.doReturn(rs1).when(psObj).exec(trans, "PermDAOImpl DELETE", data); Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - + Result<Void> rs2 = new Result<Void>(null,1,"test",new String[0]); Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); - + rs1 = new Result<List<Data>>(null,1,"test",new String[0]); Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); Mockito.doReturn("test user").when(trans).user(); - + PermDAO.Data perm = new PermDAO.Data(); Field cbField; try { @@ -381,10 +381,10 @@ public class JU_PermDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + Result<Void> retVal = daoObj.addDescription(trans, "test", "test", "test", "test", "test"); assertTrue(retVal.status == 9); - + Field owningDaoField; try { owningDaoField = AbsCassDAO.class.getDeclaredField("owningDAO"); @@ -403,18 +403,18 @@ public class JU_PermDAO { retVal = daoObj.addDescription(trans, "test", "test", "test", "test", "test"); assertTrue(retVal.status == 0); } - + public void setPsByStartAndTarget(PermDAO PermDAOObj, PSInfo psInfoObj, String fieldName) { Field PermDAOField; try { PermDAOField = PermDAO.class.getDeclaredField(fieldName); - + PermDAOField.setAccessible(true); // remove final modifier from field Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); // modifiersField.setInt(PermDAOField, PermDAOField.getModifiers() & ~Modifier.FINAL); - + PermDAOField.set(PermDAOObj, psInfoObj); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -427,7 +427,7 @@ public class JU_PermDAO { e.printStackTrace(); } } - + @Test public void testWasMOdified() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -440,15 +440,15 @@ public class JU_PermDAO { Mockito.doNothing().when(tt).done(); PermDAO.Data data = new PermDAO.Data(); PSInfo createPS = Mockito.mock(PSInfo.class); - + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); Result<Void> rs2 = new Result<Void>(null,0,"test",new String[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()); - + PermDAOImpl daoObj = null; try { daoObj = new PermDAOImpl(trans, historyDAO, cacheInfoDAO, createPS ); @@ -457,24 +457,24 @@ public class JU_PermDAO { e.printStackTrace(); } daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); - + daoObj.wasModified(trans, CRUD.create, data, new String[] {}); daoObj.wasModified(trans, CRUD.create, data, new String[] {null}); daoObj.wasModified(trans, CRUD.create, data, new String[] {"test",null}); daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); - + rs1 = new Result<ResultSet>(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); PermDAO daoObj = new PermDAO(trans, historyDAO, cacheInfoDAO); - + } @Test @@ -487,15 +487,15 @@ public class JU_PermDAO { break; } } - + Constructor<?> constructor = innerClass.getDeclaredConstructors()[0]; constructor.setAccessible(true); - + try { - + Object obj = constructor.newInstance(1); Method innnerClassMtd; - + PermDAO.Data data = new PermDAO.Data(); Row row = Mockito.mock(Row.class); ByteBuffer bbObj = ByteBuffer.allocateDirect(10); @@ -504,16 +504,16 @@ public class JU_PermDAO { 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[] {PermDAO.Data.class, Row.class}); innnerClassMtd.invoke(obj, new Object[] {data, row}); - + innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {PermDAO.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[] {PermDAO.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[] {PermDAO.Data.class, DataOutputStream.class }); @@ -523,7 +523,7 @@ public class JU_PermDAO { DataInputStream dis = new DataInputStream(bais); innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {PermDAO.Data.class, DataInputStream.class }); innnerClassMtd.invoke(obj, new Object[] {data, dis }); - + } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -542,21 +542,21 @@ public class JU_PermDAO { } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); - } + } } - + @Test public void testData() { PermDAO.Data data = new PermDAO.Data(); NsSplit nss = new NsSplit("test", "test"); data = new PermDAO.Data(nss, "test", "test"); - + data.toString(); - + assertTrue("test.test|test|test".equalsIgnoreCase(data.fullPerm())); - + Question q = Mockito.mock( Question.class); - + Result<NsSplit> rs = new Result<NsSplit>(nss,0,"test",new Object[0]); Mockito.doReturn(rs).when(q).deriveNsSplit(trans, "test"); Result<Data> retVal= PermDAO.Data.decode(trans, q, "test|||"); @@ -566,7 +566,7 @@ public class JU_PermDAO { retVal= PermDAO.Data.decode(trans, q, "test||"); retVal1= PermDAO.Data.decodeToArray(trans, q, "test||"); assertTrue(retVal.status==0); - + rs = new Result<NsSplit>(nss,1,"test",new Object[0]); Mockito.doReturn(rs).when(q).deriveNsSplit(trans, "test"); retVal= PermDAO.Data.decode(trans, q, "test||"); @@ -576,7 +576,7 @@ public class JU_PermDAO { retVal= PermDAO.Data.decode(trans, q, "test|"); retVal1= PermDAO.Data.decodeToArray(trans, q, "test|"); assertTrue(retVal.status==4); - + NsDAO.Data ns = new NsDAO.Data(); ns.name="test"; PermDAO.Data.create(ns, "test"); @@ -586,7 +586,7 @@ public class JU_PermDAO { Mockito.doReturn(rs).when(q).deriveNsSplit(trans, "test"); PermDAO.Data.create(trans,q, "test|test|test|test"); } - + } class PermDAOImpl extends PermDAO{ @@ -594,25 +594,25 @@ class PermDAOImpl extends PermDAO{ super(trans, historyDAO, cacheDao); setPs(this, readPS, "createPS"); } - + public PermDAOImpl(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(PermDAOImpl PermDAOObj, PSInfo psInfoObj, String methodName) { Field PermDAOField; try { PermDAOField = CassDAOImpl.class.getDeclaredField(methodName); - + PermDAOField.setAccessible(true); // remove final modifier from field Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); // modifiersField.setInt(PermDAOField, PermDAOField.getModifiers() & ~Modifier.FINAL); - + PermDAOField.set(PermDAOObj, psInfoObj); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -625,18 +625,18 @@ class PermDAOImpl extends PermDAO{ e.printStackTrace(); } } - + public void setSession(PermDAOImpl 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 diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_RoleDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_RoleDAO.java index 4057a6ed..f91fac44 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_RoleDAO.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cass/JU_RoleDAO.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. @@ -70,7 +70,7 @@ public class JU_RoleDAO { Cluster cluster; @Mock Session session; - + @Before public void setUp() throws APIException, IOException { initMocks(this); @@ -113,13 +113,13 @@ public class JU_RoleDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + PSInfo psObj = Mockito.mock(PSInfo.class); setPsByStartAndTarget(daoObj, psObj, "psName"); - + Result<List<RoleDAO.Data>> rs1 = new Result<List<RoleDAO.Data>>(null,0,"test",new Object[0]); Mockito.doReturn(rs1).when(psObj).read(trans, "RoleDAO READ", new Object[]{"test"}); - + daoObj.readName(trans, "test"); } @Test @@ -136,15 +136,15 @@ public class JU_RoleDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + PSInfo psObj = Mockito.mock(PSInfo.class); setPsByStartAndTarget(daoObj, psObj, "psChildren"); - + Result<List<RoleDAO.Data>> rs1 = new Result<List<RoleDAO.Data>>(null,0,"test",new Object[0]); Mockito.doReturn(rs1).when(psObj).read(trans, "RoleDAO READ", new Object[]{"test"}); - + daoObj.readChildren(trans, "test", "test"); - + daoObj.readChildren(trans, "test", "*"); daoObj.readChildren(trans, "test", ""); } @@ -162,13 +162,13 @@ public class JU_RoleDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + PSInfo psObj = Mockito.mock(PSInfo.class); setPsByStartAndTarget(daoObj, psObj, "psNS"); - + Result<List<RoleDAO.Data>> rs1 = new Result<List<RoleDAO.Data>>(null,0,"test",new Object[0]); Mockito.doReturn(rs1).when(psObj).read(trans, "RoleDAO READ", new Object[]{"test"}); - + daoObj.readNS(trans, "test"); } @Test @@ -190,7 +190,7 @@ public class JU_RoleDAO { Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on RoleDAO", Env.SUB); - + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); @@ -202,10 +202,10 @@ public class JU_RoleDAO { Mockito.doReturn(rs1).when(psObj).read(trans, "RoleDAOImpl READ", data); Mockito.doReturn(rs1).when(psObj).exec(trans, "RoleDAOImpl DELETE", data); Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - + Result<Void> rs2 = new Result<Void>(null,0,"test",new Object[0]); Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); - + rs1 = new Result<List<Data>>(null,1,"test",new Object[0]); Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); Mockito.doReturn("test user").when(trans).user(); @@ -224,12 +224,12 @@ public class JU_RoleDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + PermDAO.Data perm = new PermDAO.Data(); RoleDAO.Data role = new RoleDAO.Data(); Result<Void> retVal = daoObj.addPerm(trans, role, perm); assertTrue(retVal.status == 9); - + Field owningField; try { owningField = AbsCassDAO.class.getDeclaredField("owningDAO"); @@ -248,7 +248,7 @@ public class JU_RoleDAO { retVal = daoObj.addPerm(trans, role, perm); assertTrue(retVal.status == 0); } - + @Test public void testDelRole() { PSInfo psObj = Mockito.mock(PSInfo.class); @@ -268,7 +268,7 @@ public class JU_RoleDAO { Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on RoleDAO", Env.SUB); - + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); @@ -280,14 +280,14 @@ public class JU_RoleDAO { Mockito.doReturn(rs1).when(psObj).read(trans, "RoleDAOImpl READ", data); Mockito.doReturn(rs1).when(psObj).exec(trans, "RoleDAOImpl DELETE", data); Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - + Result<Void> rs2 = new Result<Void>(null,0,"test",new String[0]); Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); - + rs1 = new Result<List<Data>>(null,1,"test",new String[0]); Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); Mockito.doReturn("test user").when(trans).user(); - + PermDAO.Data perm = new PermDAO.Data(); Field cbField; try { @@ -307,7 +307,7 @@ public class JU_RoleDAO { RoleDAO.Data role = new RoleDAO.Data(); Result<Void> retVal = daoObj.delPerm(trans, role, perm); assertTrue(retVal.status == 9); - + Field owningDaoField; try { owningDaoField = AbsCassDAO.class.getDeclaredField("owningDAO"); @@ -326,7 +326,7 @@ public class JU_RoleDAO { retVal = daoObj.delPerm(trans,role, perm); assertTrue(retVal.status == 0); } - + @Test public void testAddDescription() { PSInfo psObj = Mockito.mock(PSInfo.class); @@ -346,7 +346,7 @@ public class JU_RoleDAO { Mockito.doReturn(tt).when(trans).start("Clear Reset Deque", Env.SUB); Mockito.doReturn(tt).when(trans).start("New Cassandra Session", Env.SUB); Mockito.doReturn(tt).when(trans).start("Preparing PSInfo CREATE on RoleDAO", Env.SUB); - + Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"100"); Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_PORT,"9042"); Mockito.doReturn("100").when(trans).getProperty(CassAccess.CASSANDRA_CLUSTERS_USER_NAME,"100"); @@ -358,14 +358,14 @@ public class JU_RoleDAO { Mockito.doReturn(rs1).when(psObj).read(trans, "RoleDAOImpl READ", data); Mockito.doReturn(rs1).when(psObj).exec(trans, "RoleDAOImpl DELETE", data); Mockito.doReturn(rs1).when(historyDAO).create(Mockito.any(), Mockito.any()); - + Result<Void> rs2 = new Result<Void>(null,1,"test",new String[0]); Mockito.doReturn(rs2).when(cacheInfoDAO).touch(Mockito.any(AuthzTrans.class),Mockito.anyString(), Mockito.anyVararg()); - + rs1 = new Result<List<Data>>(null,1,"test",new String[0]); Mockito.doReturn(rs1).when(cacheInfoDAO).touch(Mockito.any(), Mockito.anyString(), Mockito.anyInt()); Mockito.doReturn("test user").when(trans).user(); - + RoleDAO.Data perm = new RoleDAO.Data(); Field cbField; try { @@ -382,10 +382,10 @@ public class JU_RoleDAO { // TODO Auto-generated catch block e.printStackTrace(); } - + Result<Void> retVal = daoObj.addDescription(trans, "test", "test", "test"); assertTrue(retVal.status == 9); - + Field owningDaoField; try { owningDaoField = AbsCassDAO.class.getDeclaredField("owningDAO"); @@ -404,18 +404,18 @@ public class JU_RoleDAO { retVal = daoObj.addDescription(trans, "test", "test", "test"); assertTrue(retVal.status == 0); } - + public void setPsByStartAndTarget(RoleDAO RoleDAOObj, PSInfo psInfoObj, String fieldName) { Field RoleDAOField; try { RoleDAOField = RoleDAO.class.getDeclaredField(fieldName); - + RoleDAOField.setAccessible(true); // remove final modifier from field Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); // modifiersField.setInt(RoleDAOField, RoleDAOField.getModifiers() & ~Modifier.FINAL); - + RoleDAOField.set(RoleDAOObj, psInfoObj); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -428,7 +428,7 @@ public class JU_RoleDAO { e.printStackTrace(); } } - + @Test public void testWasModified() { TimeTaken tt = Mockito.mock(TimeTaken.class); @@ -441,15 +441,15 @@ public class JU_RoleDAO { Mockito.doNothing().when(tt).done(); RoleDAO.Data data = new RoleDAO.Data(); PSInfo createPS = Mockito.mock(PSInfo.class); - + HistoryDAO historyDAO = Mockito.mock(HistoryDAO.class); Result<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new String[0]); Result<Void> rs2 = new Result<Void>(null,0,"test",new String[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()); - + RoleDAOImpl daoObj = null; try { daoObj = new RoleDAOImpl(trans, historyDAO, cacheInfoDAO, createPS ); @@ -458,24 +458,24 @@ public class JU_RoleDAO { e.printStackTrace(); } daoObj.wasModified(trans, CRUD.create, data, new String[] {"test"}); - + daoObj.wasModified(trans, CRUD.create, data, new String[] {}); daoObj.wasModified(trans, CRUD.create, data, new String[] {null}); daoObj.wasModified(trans, CRUD.create, data, new String[] {"test",null}); daoObj.wasModified(trans, CRUD.create, data, new String[] {"test","test"}); - + rs1 = new Result<ResultSet>(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); RoleDAO daoObj = new RoleDAO(trans, historyDAO, cacheInfoDAO); - + } @Test @@ -488,15 +488,15 @@ public class JU_RoleDAO { break; } } - + Constructor<?> constructor = innerClass.getDeclaredConstructors()[0]; constructor.setAccessible(true); - + try { - + Object obj = constructor.newInstance(1); Method innnerClassMtd; - + RoleDAO.Data data = new RoleDAO.Data(); Row row = Mockito.mock(Row.class); ByteBuffer bbObj = ByteBuffer.allocateDirect(10); @@ -505,16 +505,16 @@ public class JU_RoleDAO { 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[] {RoleDAO.Data.class, Row.class}); innnerClassMtd.invoke(obj, new Object[] {data, row}); - + innnerClassMtd = innerClass.getDeclaredMethod("key", new Class[] {RoleDAO.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[] {RoleDAO.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[] {RoleDAO.Data.class, DataOutputStream.class }); @@ -524,7 +524,7 @@ public class JU_RoleDAO { DataInputStream dis = new DataInputStream(bais); innnerClassMtd = innerClass.getDeclaredMethod("unmarshal", new Class[] {RoleDAO.Data.class, DataInputStream.class }); innnerClassMtd.invoke(obj, new Object[] {data, dis }); - + } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -543,20 +543,20 @@ public class JU_RoleDAO { } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); - } + } } - + @Test public void testData() { RoleDAO.Data data = new RoleDAO.Data(); NsSplit nss = new NsSplit("test", "test"); data = new RoleDAO.Data(); - + data.toString(); - - + + Question q = Mockito.mock( Question.class); - + Result<NsSplit> rs = new Result<NsSplit>(nss,0,"test",new Object[0]); Mockito.doReturn(rs).when(q).deriveNsSplit(trans, "test"); Result<Data> retVal= RoleDAO.Data.decode(trans, q, "test|||"); @@ -566,7 +566,7 @@ public class JU_RoleDAO { retVal= RoleDAO.Data.decode(trans, q, "test"); retVal1= RoleDAO.Data.decodeToArray(trans, q, "test"); assertTrue(retVal.status==0); - + rs = new Result<NsSplit>(nss,1,"test",new Object[0]); Mockito.doReturn(rs).when(q).deriveNsSplit(trans, "test"); retVal= RoleDAO.Data.decode(trans, q, "test"); @@ -576,7 +576,7 @@ public class JU_RoleDAO { retVal= RoleDAO.Data.decode(trans, q, "test"); retVal1= RoleDAO.Data.decodeToArray(trans, q, "test"); assertTrue(retVal.status==1); - + NsDAO.Data ns = new NsDAO.Data(); ns.name="test"; RoleDAO.Data.create(ns, "test"); @@ -585,9 +585,9 @@ public class JU_RoleDAO { urdd.ns="test"; RoleDAO.Data dd=RoleDAO.Data.decode(urdd); assertTrue("test".equals(dd.ns)); - + assertTrue(data.encode().contains("null")); - + data.perms = null; data.perms(true); @@ -598,7 +598,7 @@ public class JU_RoleDAO { data.perms = new TreeSet<>(); data.perms(true); } - + } class RoleDAOImpl extends RoleDAO{ @@ -606,25 +606,25 @@ class RoleDAOImpl extends RoleDAO{ super(trans, historyDAO, cacheDao); setPs(this, readPS, "createPS"); } - + public RoleDAOImpl(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(RoleDAOImpl RoleDAOObj, PSInfo psInfoObj, String methodName) { Field RoleDAOField; try { RoleDAOField = CassDAOImpl.class.getDeclaredField(methodName); - + RoleDAOField.setAccessible(true); // remove final modifier from field Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); // modifiersField.setInt(RoleDAOField, RoleDAOField.getModifiers() & ~Modifier.FINAL); - + RoleDAOField.set(RoleDAOObj, psInfoObj); } catch (NoSuchFieldException | SecurityException e) { // TODO Auto-generated catch block @@ -637,18 +637,18 @@ class RoleDAOImpl extends RoleDAO{ e.printStackTrace(); } } - + public void setSession(RoleDAOImpl 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 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<List<UserRoleDAO.Data>> rs1 = new Result<List<UserRoleDAO.Data>>(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<List<UserRoleDAO.Data>> rs1 = new Result<List<UserRoleDAO.Data>>(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<List<UserRoleDAO.Data>> rs1 = new Result<List<UserRoleDAO.Data>>(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<ResultSet> rs1 = new Result<ResultSet>(null,0,"test",new Object[0]); Result<Void> rs2 = new Result<Void>(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<Void>(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<ResultSet>(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<NsSplit> rs = new Result<NsSplit>(nss,0,"test",new Object[0]); Mockito.doReturn(rs).when(q).deriveNsSplit(trans, "test"); - + data.role(trans, q, "test"); - + rs = new Result<NsSplit>(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 diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_CassExecutor.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_CassExecutor.java index 6d029933..8305944f 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_CassExecutor.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_CassExecutor.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. @@ -43,24 +43,24 @@ import org.onap.aaf.cadi.Access; import org.onap.aaf.cadi.CadiException; -@RunWith(MockitoJUnitRunner.class) +@RunWith(MockitoJUnitRunner.class) public class JU_CassExecutor { - - + + private static final Object NO_PARAM = new Object[0]; @Mock AuthzTransImpl trans; - + @Mock Question q; - + @Mock Access access; - + Function f; - + @Before public void setUp() throws Exception { initMocks(this); @@ -74,36 +74,36 @@ public class JU_CassExecutor { } f =new Function(trans, q); } - + @Test public void testHasPermission() { - + CassExecutor cassExecutorObj =new CassExecutor(trans, f); Mockito.doReturn(false).when(q).isGranted(trans, "","","","",""); boolean retVal = cassExecutorObj.hasPermission("", "", "", "", ""); // System.out.println(retVal); assertFalse(retVal); - } - + } + @Test public void testInRole() { - + CassExecutor cassExecutorObj =new CassExecutor(trans, f); Result<NsSplit> retVal1 = new Result<NsSplit>(null,1,"",NO_PARAM); Mockito.doReturn(retVal1).when(q).deriveNsSplit(trans, "test"); - + boolean retVal = cassExecutorObj.inRole("test"); // System.out.println(retVal); assertFalse(retVal); } - + @Test public void testNamespace() { f =new Function(trans, q); CassExecutor cassExecutorObj =new CassExecutor(trans, f); Result<Data> retVal1 = new Result<Data>(null,1,"",NO_PARAM); Mockito.doReturn(retVal1).when(q).validNSOfDomain(trans, null); - + String retVal=""; try { retVal = cassExecutorObj.namespace(); @@ -114,7 +114,7 @@ public class JU_CassExecutor { System.out.println(retVal); // assertFalse(retVal); } - + @Test public void testId() { Mockito.doReturn("").when(trans).user(); @@ -122,7 +122,7 @@ public class JU_CassExecutor { String retVal = cassExecutorObj.id(); assertEquals("", retVal); } - + @Test public void testNamespaceSuccess() { Mockito.doAnswer(new Answer<Object>() { @@ -139,8 +139,8 @@ public class JU_CassExecutor { CassExecutor cassExecutorObj =new CassExecutor(trans, f); Result<Data> retVal1 = new Result<Data>(null,0,"",NO_PARAM); Mockito.doReturn(retVal1).when(q).validNSOfDomain(trans, null); - - + + // String retVal=""; try { /*retVal =*/ cassExecutorObj.namespace(); @@ -152,5 +152,5 @@ public class JU_CassExecutor { // System.out.println(retVal); // assertFalse(retVal); } - + }
\ No newline at end of file diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_Function.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_Function.java index bfa5838c..cb52cf44 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_Function.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_Function.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. @@ -81,21 +81,21 @@ import org.onap.aaf.misc.env.LogTarget; public class JU_Function { private static final Object NO_PARAM = new Object[0]; - + @Mock AuthzTrans trans; @Mock PropAccess access; - + @Mock Question ques; - - @Mock + + @Mock Organization org; - + @Mock CachedNSDAO nsDAO; - + @Mock CachedRoleDAO roleDAO; @@ -131,7 +131,7 @@ public class JU_Function { Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).debug(); Mockito.doReturn(Mockito.mock(Properties.class)).when(access).getProperties(); Mockito.doReturn("test.test").when(access).getProperty(Config.AAF_ROOT_NS,"org.osaaf.aaf"); - + try { Define.set(access); } catch (CadiException e) { @@ -154,14 +154,14 @@ public class JU_Function { Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); Result<Void> retVal = new Result<Void>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); //setQuestion(ques, cachedNS); - + Function funcObj = new Function(trans, ques); Result<Void> result = funcObj.createNS(trans, namespace, true); assertTrue(3 == result.status); } - + @Test public void testCreateNsReadSuccess() { Namespace namespace = Mockito.mock(Namespace.class); @@ -172,50 +172,50 @@ public class JU_Function { List<String> admin = new ArrayList<String>(); admin.add("test"); namespace.admin= admin; - + Organization org = Mockito.mock(Organization.class); Mockito.doReturn(org).when(trans).org(); - + NsDAO.Data data = new NsDAO.Data(); data.name="test"; Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); Result<Void> retVal = new Result<Void>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); - + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); + Function funcObj = new Function(trans, ques); Result<Void> result = funcObj.createNS(trans, namespace, true); assertTrue(3 == result.status); } - + @Test public void testCreateNsFromApprovaFalse() { Namespace namespace = Mockito.mock(Namespace.class); namespace.name = "test.test"; List<String> owner = new ArrayList<String>(); namespace.owner = owner; - + Organization org = Mockito.mock(Organization.class); Mockito.doReturn(org).when(trans).org(); - + NsDAO.Data data = new NsDAO.Data(); data.name="test"; Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(data,1,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal1.value, Access.write); - + Function funcObj = new Function(trans, ques); Result<Void> result = funcObj.createNS(trans, namespace, false); assertTrue(1 == result.status); - + Mockito.doReturn(retVal2).when(ques).deriveNs(trans, "test"); funcObj = new Function(trans, ques); result = funcObj.createNS(trans, namespace, false); assertTrue(1 == result.status); } - + @Test public void testCreateNsownerLoop() { Namespace namespace = Mockito.mock(Namespace.class); @@ -223,16 +223,16 @@ public class JU_Function { List<String> owner = new ArrayList<String>(); owner.add("test"); namespace.owner = owner; - + Organization org = Mockito.mock(Organization.class); Mockito.doReturn(org).when(trans).org(); Mockito.doReturn(org).when(trans).org(); - + Function funcObj = new Function(trans, ques); Result<Void> result = funcObj.createNS(trans, namespace, true); assertTrue(result.status == Status.ERR_Policy); assertTrue(result.details.contains("is not a valid user at")); - + Identity iden=Mockito.mock(Identity.class); try { Mockito.doReturn(iden).when(org).getIdentity(trans, "test"); @@ -249,7 +249,7 @@ public class JU_Function { result = funcObj.createNS(trans, namespace, true); assertTrue(result.status == Status.ERR_Policy); assertTrue(result.details.contains("cannot be the owner of the namespace ")); - + Mockito.doReturn(true).when(org).isTestEnv(); try { Mockito.doReturn("test").when(org).validate(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()); @@ -261,7 +261,7 @@ public class JU_Function { e.printStackTrace(); } } - + @Test public void testCreateNsownerLoopException() { Namespace namespace = Mockito.mock(Namespace.class); @@ -269,12 +269,12 @@ public class JU_Function { List<String> owner = new ArrayList<String>(); owner.add("test"); namespace.owner = owner; - + Organization org = Mockito.mock(Organization.class); Mockito.doReturn(org).when(trans).org(); - + Function funcObj = new Function(trans, ques); - + Identity iden=Mockito.mock(Identity.class); try { Mockito.doThrow(new OrganizationException()).when(org).getIdentity(trans, "test"); @@ -283,26 +283,26 @@ public class JU_Function { // TODO Auto-generated catch block e.printStackTrace(); } - + NsDAO.Data data = new NsDAO.Data(); data.name="test"; Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,1,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - + Result<Void> result = funcObj.createNS(trans, namespace, true); assertTrue(result.status == Status.ERR_Security); assertTrue(result.details.contains("may not create Root Namespaces")); - + Mockito.doReturn(true).when(ques).isGranted(Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, null); - + Result<Void> retVal = new Result<Void>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); - + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); + result = funcObj.createNS(trans, namespace, true); assertTrue(24 == result.status); - + } @Test @@ -313,15 +313,15 @@ public class JU_Function { owner.add("test"); namespace.owner = owner; namespace.admin = owner; - + Organization org = Mockito.mock(Organization.class); Mockito.doReturn(org).when(trans).org(); - + NsDAO.Data data = new NsDAO.Data(); data.name="test"; Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - + Result<Void> retVal = new Result<Void>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); Mockito.doReturn(retVal).when(nsDAO).create(Mockito.any(), Mockito.any()); @@ -338,8 +338,8 @@ public class JU_Function { } dataObj.add(indData); Result<List<CredDAO.Data>> retVal2 = new Result<List<CredDAO.Data>>(dataObj,0,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(credDAO).readID(Mockito.any(), Mockito.anyString()); - + Mockito.doReturn(retVal2).when(credDAO).readID(Mockito.any(), Mockito.anyString()); + Identity iden=Mockito.mock(Identity.class); try { Mockito.doReturn(iden).when(org).getIdentity(trans, "test"); @@ -349,16 +349,16 @@ public class JU_Function { // TODO Auto-generated catch block e.printStackTrace(); } - + Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(roleDAO).read(trans, "test","test"); Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(permDAO).readByType(trans, "test","test"); Function funcObj = new Function(trans, ques); Result<Void> result = funcObj.createNS(trans, namespace, true); assertTrue(result.status == 1); - + } - + @Test public void testCreateNsAdminLoopCreateSucReadChildrenFailure() { Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); @@ -377,15 +377,15 @@ public class JU_Function { owner.add("test"); namespace.owner = owner; namespace.admin = owner; - + Organization org = Mockito.mock(Organization.class); Mockito.doReturn(org).when(trans).org(); - + NsDAO.Data data = new NsDAO.Data(); data.name="test"; Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - + Result<Void> retVal = new Result<Void>(null,0,"test",NO_PARAM); Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); Mockito.doReturn(retVal).when(nsDAO).create(Mockito.any(), Mockito.any()); @@ -409,34 +409,34 @@ public class JU_Function { permsSet.add("test|test"); indData1.perms = permsSet; dataObj1.add(indData1); - + List<UserRoleDAO.Data> dataObj4 = new ArrayList<>(); UserRoleDAO.Data indData4 = new UserRoleDAO.Data(); indData4.ns = "test"; indData4.rname = "test"; dataObj4.add(indData4); - + List<PermDAO.Data> dataObj5 = new ArrayList<>(); PermDAO.Data indData5 = new PermDAO.Data(); indData5.ns = "test"; indData5.type = "test"; dataObj5.add(indData5); - + Result<List<CredDAO.Data>> retVal2 = new Result<List<CredDAO.Data>>(dataObj,0,"test",NO_PARAM); Result<List<CredDAO.Data>> retVal6 = new Result<List<CredDAO.Data>>(dataObj,1,"test",NO_PARAM); Result<List<RoleDAO.Data>> retVal3 = new Result<List<RoleDAO.Data>>(dataObj1,0,"test",NO_PARAM); Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(dataObj4,0,"test",NO_PARAM); Result<List<PermDAO.Data>> retVal5 = new Result<List<PermDAO.Data>>(dataObj5,0,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(credDAO).readID(Mockito.any(), Mockito.anyString()); - Mockito.doReturn(retVal4).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - Mockito.doReturn(retVal2).when(userRoleDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal6).when(roleDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal6).when(roleDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); - Mockito.doReturn(retVal2).when(permDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal5).when(permDAO).readChildren(trans, "test", "test"); - Mockito.doReturn(retVal5).when(permDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); - Mockito.doReturn(retVal3).when(roleDAO).readChildren(trans, "test", "test"); - + Mockito.doReturn(retVal2).when(credDAO).readID(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal4).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal2).when(userRoleDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal6).when(roleDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal6).when(roleDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + Mockito.doReturn(retVal2).when(permDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal5).when(permDAO).readChildren(trans, "test", "test"); + Mockito.doReturn(retVal5).when(permDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + Mockito.doReturn(retVal3).when(roleDAO).readChildren(trans, "test", "test"); + Identity iden=Mockito.mock(Identity.class); try { Mockito.doReturn(iden).when(org).getIdentity(trans, "test"); @@ -447,16 +447,16 @@ public class JU_Function { // TODO Auto-generated catch block e.printStackTrace(); } - + Function funcObj = new Function(trans, ques); Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(roleDAO).read(trans, "test","test"); Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(permDAO).readByType(trans, "test","test"); Result<Void> result = funcObj.createNS(trans, namespace, true); assertTrue(result.status == Status.ERR_ActionNotCompleted); - + } - + @Test public void testCreateNsAdminLoopCreateSuc() { Namespace namespace = Mockito.mock(Namespace.class); @@ -465,15 +465,15 @@ public class JU_Function { owner.add("test"); namespace.owner = owner; namespace.admin = owner; - + Organization org = Mockito.mock(Organization.class); Mockito.doReturn(org).when(trans).org(); - + NsDAO.Data data = new NsDAO.Data(); data.name="test"; Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - + Result<Void> retVal = new Result<Void>(null,0,"test",NO_PARAM); Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); Mockito.doReturn(retVal).when(nsDAO).create(Mockito.any(), Mockito.any()); @@ -497,13 +497,13 @@ public class JU_Function { permsSet.add("test|test|test|test"); indData1.perms = permsSet; dataObj1.add(indData1); - + List<UserRoleDAO.Data> dataObj4 = new ArrayList<>(); UserRoleDAO.Data indData4 = new UserRoleDAO.Data(); indData4.ns = "test"; indData4.rname = "test"; dataObj4.add(indData4); - + List<PermDAO.Data> dataObj5 = new ArrayList<>(); PermDAO.Data indData5 = new PermDAO.Data(); indData5.ns = "test"; @@ -512,21 +512,21 @@ public class JU_Function { rolesSet.add("test|test|test|test"); indData5.roles = rolesSet; dataObj5.add(indData5); - + Result<List<CredDAO.Data>> retVal2 = new Result<List<CredDAO.Data>>(dataObj,0,"test",NO_PARAM); Result<List<RoleDAO.Data>> retVal3 = new Result<List<RoleDAO.Data>>(dataObj1,0,"test",NO_PARAM); Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(dataObj4,0,"test",NO_PARAM); Result<List<PermDAO.Data>> retVal5 = new Result<List<PermDAO.Data>>(dataObj5,0,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(credDAO).readID(Mockito.any(), Mockito.anyString()); - Mockito.doReturn(retVal4).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - Mockito.doReturn(retVal2).when(userRoleDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal2).when(roleDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal2).when(roleDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); - Mockito.doReturn(retVal2).when(permDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal5).when(permDAO).readChildren(trans, "test", "test"); - Mockito.doReturn(retVal5).when(permDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); - Mockito.doReturn(retVal3).when(roleDAO).readChildren(trans, "test", "test"); - + Mockito.doReturn(retVal2).when(credDAO).readID(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal4).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal2).when(userRoleDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal2).when(roleDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal2).when(roleDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + Mockito.doReturn(retVal2).when(permDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal5).when(permDAO).readChildren(trans, "test", "test"); + Mockito.doReturn(retVal5).when(permDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + Mockito.doReturn(retVal3).when(roleDAO).readChildren(trans, "test", "test"); + Identity iden=Mockito.mock(Identity.class); try { Mockito.doReturn(iden).when(org).getIdentity(trans, "test"); @@ -537,27 +537,27 @@ public class JU_Function { // TODO Auto-generated catch block e.printStackTrace(); } - + Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(roleDAO).read(trans, "test","test"); Mockito.doReturn(Result.err(Result.ERR_NotFound, "Not Found")).when(permDAO).readByType(trans, "test","test"); Function funcObj = new Function(trans, ques); Result<Void> result = funcObj.createNS(trans, namespace, true); assertTrue(result.status == 0); - + } - + @Test public void test4DeleteNs() { Result<Void> retVal = new Result<Void>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); - + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); + Function funcObj = new Function(trans, ques); Result<Void> result = funcObj.deleteNS(trans, "test"); - + assertTrue(result.status == Status.ERR_NsNotFound); } - + @Test public void test4DeleteCanMoveFail() { List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); @@ -565,17 +565,17 @@ public class JU_Function { dataObj.type=1; dataAl.add(dataObj); Result<List<NsDAO.Data>> retVal = new Result<List<NsDAO.Data>>(dataAl,0,"test",NO_PARAM); - Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); - + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(false).when(ques).canMove(Mockito.any()); Mockito.doReturn(retVal).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); - + Function funcObj = new Function(trans, ques); Result<Void> result = funcObj.deleteNS(trans, "test"); assertTrue(result.status == Status.ERR_Security); - + } - + @Test public void test4DeleteNsReadSuc() { List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); @@ -583,17 +583,17 @@ public class JU_Function { dataObj.type=1; dataAl.add(dataObj); Result<List<NsDAO.Data>> retVal = new Result<List<NsDAO.Data>>(dataAl,0,"test",NO_PARAM); - Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); - + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); - + Function funcObj = new Function(trans, ques); Result<Void> result = funcObj.deleteNS(trans, "test"); assertTrue(result.status == 1); - + } - + @Test public void test4DeleteNsMayUserSuc() { List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); @@ -601,22 +601,22 @@ public class JU_Function { dataObj.type=1; dataAl.add(dataObj); Result<List<NsDAO.Data>> retVal = new Result<List<NsDAO.Data>>(dataAl,0,"test",NO_PARAM); - Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); - + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); - + Function funcObj = new Function(trans, ques); Result<Void> result = funcObj.deleteNS(trans, "test"); assertTrue(result.status == 1); Mockito.doReturn(true).when(ques).isGranted(Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); - Mockito.doReturn(retVal2).when(credDAO).readNS(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal2).when(credDAO).readNS(Mockito.any(), Mockito.anyString()); Result<List<PermDAO.Data>> retVal5 = new Result<List<PermDAO.Data>>(null,0,"test",NO_PARAM); Mockito.doReturn(retVal5).when(permDAO).readNS(trans, "test"); - + List<UserRoleDAO.Data> dataObj4 = new ArrayList<>(); UserRoleDAO.Data indData4 = new UserRoleDAO.Data(); indData4.ns = "test"; @@ -624,7 +624,7 @@ public class JU_Function { dataObj4.add(indData4); Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(dataObj4,0,"test",NO_PARAM); Mockito.doReturn(retVal4).when(userRoleDAO).readByRole(trans, "test"); - + List<RoleDAO.Data> dataObj1 = new ArrayList<>(); RoleDAO.Data indData1 = new RoleDAO.Data(); indData1.ns = "test"; @@ -634,15 +634,15 @@ public class JU_Function { indData1.perms = permsSet; dataObj1.add(indData1); Result<List<RoleDAO.Data>> retVal3 = new Result<List<RoleDAO.Data>>(dataObj1,0,"test",NO_PARAM); - Mockito.doReturn(retVal3).when(roleDAO).readNS(trans, "test"); + Mockito.doReturn(retVal3).when(roleDAO).readNS(trans, "test"); Mockito.doReturn(retVal3).when(roleDAO).read(trans, indData1); - + funcObj = new Function(trans, ques); result = funcObj.deleteNS(trans, "test"); assertTrue(result.status == Status.ERR_DependencyExists); - - Mockito.doReturn(retVal4).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - + + Mockito.doReturn(retVal4).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(true).when(trans).requested(REQD_TYPE.force); funcObj = new Function(trans, ques); result = funcObj.deleteNS(trans, "test"); @@ -655,18 +655,18 @@ public class JU_Function { dataObj.type=1; dataAl.add(dataObj); Result<List<NsDAO.Data>> retVal = new Result<List<NsDAO.Data>>(dataAl,0,"test",NO_PARAM); - Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); - + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); - + Function funcObj = new Function(trans, ques); Result<Void> result = funcObj.deleteNS(trans, "test"); assertTrue(result.status == 1); Mockito.doReturn(true).when(ques).isGranted(Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); - Mockito.doReturn(retVal2).when(credDAO).readNS(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal2).when(credDAO).readNS(Mockito.any(), Mockito.anyString()); List<PermDAO.Data> dataObj5 = new ArrayList<>(); PermDAO.Data indData5 = new PermDAO.Data(); @@ -677,8 +677,8 @@ public class JU_Function { Mockito.doReturn(retVal5).when(permDAO).readNS(trans, "test"); Mockito.doReturn(retVal5).when(permDAO).readNS(trans, "test.test"); Mockito.doReturn(retVal5).when(permDAO).read(trans, indData5); - - + + List<RoleDAO.Data> dataObj1 = new ArrayList<>(); RoleDAO.Data indData1 = new RoleDAO.Data(); indData1.ns = "test"; @@ -688,19 +688,19 @@ public class JU_Function { indData1.perms = permsSet; dataObj1.add(indData1); Result<List<RoleDAO.Data>> retVal3 = new Result<List<RoleDAO.Data>>(dataObj1,0,"test",NO_PARAM); - Mockito.doReturn(retVal3).when(roleDAO).readNS(trans, "test"); - Mockito.doReturn(retVal3).when(roleDAO).readNS(trans, "test.test"); + Mockito.doReturn(retVal3).when(roleDAO).readNS(trans, "test"); + Mockito.doReturn(retVal3).when(roleDAO).readNS(trans, "test.test"); Mockito.doReturn(retVal3).when(roleDAO).read(trans, indData1); - + funcObj = new Function(trans, ques); result = funcObj.deleteNS(trans, "test"); assertTrue(result.status == Status.ERR_DependencyExists); - + NsDAO.Data data = new NsDAO.Data(); data.name="test"; Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,1,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - + Mockito.doReturn(true).when(trans).requested(REQD_TYPE.force); funcObj = new Function(trans, ques); result = funcObj.deleteNS(trans, "test.test"); @@ -714,8 +714,8 @@ public class JU_Function { dataObj.type=1; dataAl.add(dataObj); Result<List<NsDAO.Data>> retVal = new Result<List<NsDAO.Data>>(dataAl,0,"test",NO_PARAM); - Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); - + Mockito.doReturn(retVal).when(nsDAO).read(Mockito.any(), Mockito.anyString()); + List<CredDAO.Data> nsDataList = new ArrayList<CredDAO.Data>(); CredDAO.Data nsData = new CredDAO.Data(); nsData.id="test"; @@ -723,15 +723,15 @@ public class JU_Function { Result<List<CredDAO.Data>> retVal21 = new Result<List<CredDAO.Data>>(nsDataList,0,"test",NO_PARAM); Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); - + Function funcObj = new Function(trans, ques); Result<Void> result = funcObj.deleteNS(trans, "test"); assertTrue(result.status == 1); Mockito.doReturn(true).when(ques).isGranted(Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); - Mockito.doReturn(retVal21).when(credDAO).readNS(Mockito.any(), Mockito.anyString()); - Mockito.doReturn(retVal21).when(credDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + Mockito.doReturn(retVal21).when(credDAO).readNS(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal21).when(credDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); List<PermDAO.Data> dataObj5 = new ArrayList<>(); PermDAO.Data indData5 = new PermDAO.Data(); @@ -742,7 +742,7 @@ public class JU_Function { Mockito.doReturn(retVal5).when(permDAO).readNS(trans, "test"); Mockito.doReturn(retVal5).when(permDAO).readNS(trans, "test.test"); Mockito.doReturn(retVal5).when(permDAO).read(trans, indData5); - + List<UserRoleDAO.Data> dataObj4 = new ArrayList<>(); UserRoleDAO.Data indData4 = new UserRoleDAO.Data(); indData4.ns = "test"; @@ -751,7 +751,7 @@ public class JU_Function { Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(dataObj4,0,"test",NO_PARAM); Mockito.doReturn(retVal4).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); Mockito.doReturn(retVal4).when(userRoleDAO).readByUser(Mockito.any(), Mockito.anyString()); - + List<RoleDAO.Data> dataObj1 = new ArrayList<>(); RoleDAO.Data indData1 = new RoleDAO.Data(); indData1.ns = "test"; @@ -761,25 +761,25 @@ public class JU_Function { indData1.perms = permsSet; dataObj1.add(indData1); Result<List<RoleDAO.Data>> retVal3 = new Result<List<RoleDAO.Data>>(dataObj1,0,"test",NO_PARAM); - Mockito.doReturn(retVal3).when(roleDAO).readNS(trans, "test"); - Mockito.doReturn(retVal3).when(roleDAO).readNS(trans, "test.test"); + Mockito.doReturn(retVal3).when(roleDAO).readNS(trans, "test"); + Mockito.doReturn(retVal3).when(roleDAO).readNS(trans, "test.test"); Mockito.doReturn(retVal3).when(roleDAO).read(trans, indData1); - + funcObj = new Function(trans, ques); result = funcObj.deleteNS(trans, "test"); assertTrue(result.status == Status.ERR_DependencyExists); - + NsDAO.Data data = new NsDAO.Data(); data.name="test"; Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - + Mockito.doReturn(true).when(trans).requested(REQD_TYPE.force); funcObj = new Function(trans, ques); result = funcObj.deleteNS(trans, "test.test"); assertNull(result); } - + @Test public void testGetOwners() { // List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); @@ -787,49 +787,49 @@ public class JU_Function { // dataObj.type=1; // dataAl.add(dataObj); Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); -// + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); +// // Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); // Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); -// +// Function funcObj = new Function(trans, ques); Result<List<String>> result = funcObj.getOwners(trans, "test", false); assertTrue(result.status == 1); -// +// } - + @Test public void testDelOwner() { Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any( UserRoleDAO.Data.class)); + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any( UserRoleDAO.Data.class)); NsDAO.Data data = new NsDAO.Data(); data.name="test"; Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(data,1,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal1.value, Access.write); - + Function funcObj = new Function(trans, ques); Result<Void> result = funcObj.delOwner(trans, "test", "test"); assertTrue(result.status == 1); - + retVal1 = new Result<NsDAO.Data>(data,1,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); result = funcObj.delOwner(trans, "test", "test"); assertTrue(result.status == 1); - + retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); result = funcObj.delOwner(trans, "test", "test"); retVal2 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal1.value, Access.write); result = funcObj.delOwner(trans, "test", "test"); -// +// } - + @Test public void testGetAdmins() { // List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); @@ -837,49 +837,49 @@ public class JU_Function { // dataObj.type=1; // dataAl.add(dataObj); Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); -// + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); +// // Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); // Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); -// +// Function funcObj = new Function(trans, ques); Result<List<String>> result = funcObj.getAdmins(trans, "test", false); assertTrue(result.status == 1); -// +// } - + @Test public void testDelAdmin() { Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readUserInRole(Mockito.any(), Mockito.anyString(), Mockito.anyString()); - Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any( UserRoleDAO.Data.class)); + Mockito.doReturn(retVal).when(userRoleDAO).readUserInRole(Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any( UserRoleDAO.Data.class)); NsDAO.Data data = new NsDAO.Data(); data.name="test"; Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); - + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(data,1,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal1.value, Access.write); - + Function funcObj = new Function(trans, ques); Result<Void> result = funcObj.delAdmin(trans, "test", "test"); assertTrue(result.status == 1); - + retVal1 = new Result<NsDAO.Data>(data,1,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); result = funcObj.delAdmin(trans, "test", "test"); assertTrue(result.status == 1); - + retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); Mockito.doReturn(retVal1).when(ques).deriveNs(trans, "test"); result = funcObj.delOwner(trans, "test", "test"); retVal2 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal1.value, Access.write); result = funcObj.delAdmin(trans, "test", "test"); -// +// } - + @Test public void testMovePerms() { // List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); @@ -887,19 +887,19 @@ public class JU_Function { // dataObj.type=1; // dataAl.add(dataObj); Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - - Mockito.doReturn(retVal).when(roleDAO).delPerm(Mockito.any(), Mockito.any(), Mockito.any()); - - Mockito.doReturn(retVal).when(permDAO).create(Mockito.any(), Mockito.any()); - + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + + Mockito.doReturn(retVal).when(roleDAO).delPerm(Mockito.any(), Mockito.any(), Mockito.any()); + + Mockito.doReturn(retVal).when(permDAO).create(Mockito.any(), Mockito.any()); + NsDAO.Data nsDataObj = new NsDAO.Data(); nsDataObj.name="test"; StringBuilder sb = new StringBuilder(); Result<List<PermDAO.Data>> retVal1 = new Result<List<PermDAO.Data>>(null,1,"test",NO_PARAM); - + invokeMovePerms(nsDataObj, sb, retVal1); - + List<PermDAO.Data> dataObj5 = new ArrayList<>(); PermDAO.Data indData5 = new PermDAO.Data(); indData5.ns = "test"; @@ -915,25 +915,25 @@ public class JU_Function { retVal1 = new Result<List<PermDAO.Data>>(dataObj5,0,"test",NO_PARAM); Result<List<UserRoleDAO.Data>> retVal3 = new Result<List<UserRoleDAO.Data>>(null,0,"test",NO_PARAM); - Mockito.doReturn(retVal3).when(permDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal3).when(permDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + Mockito.doReturn(retVal3).when(permDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal3).when(permDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); NsSplit splitObj = new NsSplit("test", "test"); Result<NsSplit> retVal2 = new Result<NsSplit>(splitObj,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); - + invokeMovePerms(nsDataObj, sb, retVal1); - + Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal4).when(permDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal4).when(permDAO).create(Mockito.any(), Mockito.any()); invokeMovePerms(nsDataObj, sb, retVal1); - - Mockito.doReturn(retVal3).when(permDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal4).when(permDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + + Mockito.doReturn(retVal3).when(permDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal4).when(permDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); invokeMovePerms(nsDataObj, sb, retVal1); - + } - + private void invokeMovePerms(NsDAO.Data nsDataObj, StringBuilder sb,Result<List<PermDAO.Data>> retVal1) { Function funcObj = new Function(trans, ques); Method met; @@ -955,7 +955,7 @@ public class JU_Function { e.printStackTrace(); } } - + @Test public void testMoveRoles() { // List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); @@ -963,19 +963,19 @@ public class JU_Function { // dataObj.type=1; // dataAl.add(dataObj); Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - - Mockito.doReturn(retVal).when(roleDAO).delPerm(Mockito.any(), Mockito.any(), Mockito.any()); - - Mockito.doReturn(retVal).when(roleDAO).create(Mockito.any(), Mockito.any()); - + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + + Mockito.doReturn(retVal).when(roleDAO).delPerm(Mockito.any(), Mockito.any(), Mockito.any()); + + Mockito.doReturn(retVal).when(roleDAO).create(Mockito.any(), Mockito.any()); + NsDAO.Data nsDataObj = new NsDAO.Data(); nsDataObj.name="test"; StringBuilder sb = new StringBuilder(); Result<List<RoleDAO.Data>> retVal1 = new Result<List<RoleDAO.Data>>(null,1,"test",NO_PARAM); - + invokeMoveRoles(nsDataObj, sb, retVal1); - + List<RoleDAO.Data> dataObj5 = new ArrayList<>(); RoleDAO.Data indData5 = new RoleDAO.Data(); indData5.ns = "test"; @@ -989,27 +989,27 @@ public class JU_Function { indData5.name = "admin"; dataObj5.add(indData5); retVal1 = new Result<List<RoleDAO.Data>>(dataObj5,0,"test",NO_PARAM); - + Result<List<UserRoleDAO.Data>> retVal3 = new Result<List<UserRoleDAO.Data>>(null,0,"test",NO_PARAM); - Mockito.doReturn(retVal3).when(roleDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal3).when(roleDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + Mockito.doReturn(retVal3).when(roleDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal3).when(roleDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); NsSplit splitObj = new NsSplit("test", "test"); Result<NsSplit> retVal2 = new Result<NsSplit>(splitObj,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); - + invokeMoveRoles(nsDataObj, sb, retVal1); - + Result<List<UserRoleDAO.Data>> retVal4 = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal4).when(roleDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal4).when(roleDAO).create(Mockito.any(), Mockito.any()); invokeMoveRoles(nsDataObj, sb, retVal1); - - Mockito.doReturn(retVal3).when(roleDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal4).when(roleDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); + + Mockito.doReturn(retVal3).when(roleDAO).create(Mockito.any(), Mockito.any()); + Mockito.doReturn(retVal4).when(roleDAO).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); invokeMoveRoles(nsDataObj, sb, retVal1); - + } - + private void invokeMoveRoles(NsDAO.Data nsDataObj, StringBuilder sb,Result<List<RoleDAO.Data>> retVal1) { Function funcObj = new Function(trans, ques); Method met; @@ -1031,7 +1031,7 @@ public class JU_Function { e.printStackTrace(); } } - + @Test public void testCreatePerm() { try { @@ -1049,20 +1049,20 @@ public class JU_Function { dataAl.add(perm); Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); - - Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any(UserRoleDAO.Data.class)); - Mockito.doReturn(retVal).when(userRoleDAO).create(Mockito.any(), Mockito.any(UserRoleDAO.Data.class)); - + + Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any(UserRoleDAO.Data.class)); + Mockito.doReturn(retVal).when(userRoleDAO).create(Mockito.any(), Mockito.any(UserRoleDAO.Data.class)); + Mockito.doReturn(retVal).when(permDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal).when(permDAO).read(trans, perm); - + Mockito.doReturn(retVal).when(permDAO).read(trans, perm); + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,perm, Access.write); - + Function funcObj = new Function(trans, ques); Result<Void> result = funcObj.createPerm(trans, perm, false); assertTrue(result.status == 1); - + retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,perm, Access.write); result = funcObj.createPerm(trans, perm, false); @@ -1077,21 +1077,21 @@ public class JU_Function { Result<List<RoleDAO.Data>> retVal4 = Result.err(Result.ERR_NotFound,""); Mockito.doReturn(retVal4).when(roleDAO).create(Mockito.any(),Mockito.any(RoleDAO.Data.class)); result = funcObj.createPerm(trans, perm, false); - - Mockito.doReturn(retVal).when(permDAO).read(trans, perm); + + Mockito.doReturn(retVal).when(permDAO).read(trans, perm); result = funcObj.createPerm(trans, perm, true); assertTrue(result.status == 1); Mockito.doReturn(retVal2).when(permDAO).create(Mockito.any(), Mockito.any()); result = funcObj.createPerm(trans, perm, true); assertTrue(result.status == 0); - + Mockito.doReturn(false).when(trans).requested(REQD_TYPE.force); Result<List<PermDAO.Data>> retVal1 = new Result<List<PermDAO.Data>>(dataAl,0,"test",NO_PARAM); - Mockito.doReturn(retVal1).when(permDAO).read(trans, perm); + Mockito.doReturn(retVal1).when(permDAO).read(trans, perm); result = funcObj.createPerm(trans, perm, true); assertTrue(result.status == Status.ERR_ConflictAlreadyExists); - + } @Test public void testDeletePerm() { @@ -1108,24 +1108,24 @@ public class JU_Function { perm.roles = rolesSet; // perm.type=1 dataAl.add(perm); - + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,perm, Access.write); - + // List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); // NsDAO.Data dataObj = new NsDAO.Data(); // dataObj.type=1; // dataAl.add(dataObj); Result<List<PermDAO.Data>> retVal = new Result<List<PermDAO.Data>>(dataAl,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); - + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + Function funcObj = new Function(trans, ques); Result<Void> result = funcObj.deletePerm(trans, perm, true,false); assertTrue(result.status == 1); // Mockito.doReturn(retVal).when(cachedPermDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal).when(permDAO).read(trans, perm); - + Mockito.doReturn(retVal).when(permDAO).read(trans, perm); + result = funcObj.deletePerm(trans, perm, true,true); assertTrue(result.status == Status.ERR_PermissionNotFound); @@ -1133,24 +1133,24 @@ public class JU_Function { Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,perm, Access.write); Result<List<PermDAO.Data>> retVal3 = new Result<List<PermDAO.Data>>(dataAl,0,"test",NO_PARAM); Mockito.doReturn(retVal3).when(permDAO).read(trans, perm); - + NsSplit nsObj = new NsSplit("test","test"); Result<NsSplit> retValNs = new Result<NsSplit>(nsObj,0,"test",NO_PARAM); Mockito.doReturn(retValNs).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); - - Mockito.doReturn(retVal).when(roleDAO).delPerm(Mockito.any(), Mockito.any(), Mockito.any()); - + + Mockito.doReturn(retVal).when(roleDAO).delPerm(Mockito.any(), Mockito.any(), Mockito.any()); + result = funcObj.deletePerm(trans, perm, true,false); - assertNull(result); - - Mockito.doReturn(retVal2).when(roleDAO).delPerm(Mockito.any(), Mockito.any(), Mockito.any()); + assertNull(result); + + Mockito.doReturn(retVal2).when(roleDAO).delPerm(Mockito.any(), Mockito.any(), Mockito.any()); result = funcObj.deletePerm(trans, perm, true,false); - assertNull(result); - + assertNull(result); + result = funcObj.deletePerm(trans, perm, false,false); // assertTrue(result.status == 1); } - + @Test public void testDeleteRole() { try { @@ -1167,7 +1167,7 @@ public class JU_Function { // perm.roles = rolesSet; // perm.type=1 dataAlUser.add(roleUser); - + List<RoleDAO.Data> dataAl = new ArrayList<RoleDAO.Data>(); RoleDAO.Data role = new RoleDAO.Data(); Set<String> rolesSet = new HashSet<>(); @@ -1176,48 +1176,48 @@ public class JU_Function { // perm.roles = rolesSet; // perm.type=1 dataAl.add(role); - + Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,role, Access.write); - + // List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); // NsDAO.Data dataObj = new NsDAO.Data(); // dataObj.type=1; // dataAl.add(dataObj); Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); -// + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); +// // Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); // Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); -// +// Function funcObj = new Function(trans, ques); Result<Void> result = funcObj.deleteRole(trans, role, true, false); assertTrue(result.status == 1); Result<List<RoleDAO.Data>> retVal1 = new Result<List<RoleDAO.Data>>(dataAl,0,"test",NO_PARAM); - Mockito.doReturn(retVal1).when(roleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); + Mockito.doReturn(retVal1).when(roleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); NsSplit splitObj = new NsSplit("test", "test"); Result<NsSplit> retVal3 = new Result<NsSplit>(splitObj,0,"test",NO_PARAM); Mockito.doReturn(retVal3).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); // Mockito.doReturn(retVal).when(cachedPermDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal).when(permDAO).delRole(Mockito.any(), Mockito.any(),Mockito.any()); + Mockito.doReturn(retVal).when(permDAO).delRole(Mockito.any(), Mockito.any(),Mockito.any()); result = funcObj.deleteRole(trans, role, true, true); assertNull(result); - + Mockito.doReturn(retVal1).when(permDAO).delRole(Mockito.any(), Mockito.any(),Mockito.any()); result = funcObj.deleteRole(trans, role, true, true); assertNull(result); - Mockito.doReturn(retVal).when(roleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); + Mockito.doReturn(retVal).when(roleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); result = funcObj.deleteRole(trans, role, true, true); assertTrue(result.status == Status.ERR_RoleNotFound); - + retVal = new Result<List<UserRoleDAO.Data>>(dataAlUser,0,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); result = funcObj.deleteRole(trans, role, false, true); assertTrue(result.status == Status.ERR_DependencyExists); } - + @Test public void testAddPermToRole() { List<PermDAO.Data> dataAlPerm = new ArrayList<PermDAO.Data>(); @@ -1227,7 +1227,7 @@ public class JU_Function { // perm.roles = rolesSet; // perm.type=1 dataAlPerm.add(rolePerm); - + List<RoleDAO.Data> dataAl = new ArrayList<RoleDAO.Data>(); RoleDAO.Data role = new RoleDAO.Data(); Set<String> rolesSet = new HashSet<>(); @@ -1236,27 +1236,27 @@ public class JU_Function { // perm.roles = rolesSet; // perm.type=1 dataAl.add(role); - + NsDAO.Data nsObj = new NsDAO.Data(); nsObj.name="test"; NsDAO.Data nsObj1 = new NsDAO.Data(); nsObj1.name="test12"; - + // List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); // NsDAO.Data dataObj = new NsDAO.Data(); // dataObj.type=1; // dataAl.add(dataObj); Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(nsObj,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, role.ns, NsType.COMPANY); Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, rolePerm.ns, NsType.COMPANY); - + Result<NsDAO.Data> retVal3 = new Result<NsDAO.Data>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal3).when(ques).mayUser(trans, null,rolePerm, Access.write); Mockito.doReturn(retVal3).when(ques).mayUser(trans, null,role, Access.write); - + Function funcObj = new Function(trans, ques); Result<Void> result = funcObj.addPermToRole(trans, role, rolePerm, false); assertTrue(result.status == 1); @@ -1266,62 +1266,62 @@ public class JU_Function { Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, rolePerm.ns, NsType.COMPANY); result = funcObj.addPermToRole(trans, role, rolePerm, false); assertTrue(result.status == 1); - + role.ns="test2"; retVal2 = new Result<NsDAO.Data>(nsObj,0,"test",NO_PARAM); Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, role.ns, NsType.COMPANY); result = funcObj.addPermToRole(trans, role, rolePerm, false); assertTrue(result.status == 1); - + retVal2 = new Result<NsDAO.Data>(nsObj,0,"test1",NO_PARAM); Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, role.ns, NsType.COMPANY); Result<NsDAO.Data> retVal21 = new Result<NsDAO.Data>(nsObj1,0,"test1",NO_PARAM); Mockito.doReturn(retVal21).when(ques).deriveFirstNsForType(trans, rolePerm.ns, NsType.COMPANY); result = funcObj.addPermToRole(trans, role, rolePerm, false); assertTrue(result.status == 1); - + retVal3 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); Mockito.doReturn(retVal3).when(ques).mayUser(trans, null,rolePerm, Access.write); retVal2 = new Result<NsDAO.Data>(nsObj,0,"test1",NO_PARAM); Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, role.ns, NsType.COMPANY); Mockito.doReturn(retVal2).when(ques).deriveFirstNsForType(trans, rolePerm.ns, NsType.COMPANY); - + // Mockito.doReturn(retVal).when(cachedPermDAO).create(Mockito.any(), Mockito.any()); - Mockito.doReturn(retVal).when(permDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); - + Mockito.doReturn(retVal).when(permDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); + result = funcObj.addPermToRole(trans, role, rolePerm, false); assertTrue(result.status == Status.ERR_PermissionNotFound); - + Result<List<PermDAO.Data>> retValPerm= new Result<List<PermDAO.Data>>(dataAlPerm,0,"test1",NO_PARAM); - Mockito.doReturn(retValPerm).when(permDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); - + Mockito.doReturn(retValPerm).when(permDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); + Mockito.doReturn(retVal3).when(roleDAO).read(trans, role); - + result = funcObj.addPermToRole(trans, role, rolePerm, true); assertTrue(result.status == 22); Mockito.doReturn(true).when(trans).requested(REQD_TYPE.force); result = funcObj.addPermToRole(trans, role, rolePerm, true); assertTrue(result.status == 2); - + retVal3 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); Mockito.doReturn(retVal3).when(ques).mayUser(trans, null,role, Access.write); Mockito.doReturn(retVal3).when(roleDAO).create(trans, role); result = funcObj.addPermToRole(trans, role, rolePerm, true); // System.out.println(result.status); assertNull(result); - + retVal3 = new Result<NsDAO.Data>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal3).when(roleDAO).create(trans, role); result = funcObj.addPermToRole(trans, role, rolePerm, true); assertTrue(result.status == 1); - + Result<List<RoleDAO.Data>> retVal31 = new Result<List<RoleDAO.Data>>(dataAl,0,"test",NO_PARAM); Mockito.doReturn(retVal31).when(roleDAO).read(trans, role); result = funcObj.addPermToRole(trans, role, rolePerm, true); assertTrue(result.status == 7); } - + @Test public void testDelPermFromRole() { List<PermDAO.Data> dataAlPerm = new ArrayList<PermDAO.Data>(); @@ -1331,78 +1331,78 @@ public class JU_Function { // perm.roles = rolesSet; // perm.type=1 dataAlPerm.add(rolePerm); - + List<RoleDAO.Data> dataAl = new ArrayList<RoleDAO.Data>(); RoleDAO.Data role = new RoleDAO.Data(); Set<String> rolesSet = new HashSet<>(); rolesSet.add("17623"); role.perms = rolesSet; dataAl.add(role); - + // List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); // NsDAO.Data dataObj = new NsDAO.Data(); // dataObj.type=1; // dataAl.add(dataObj); Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); Result<NsDAO.Data> retValFail = new Result<NsDAO.Data>(null,1,"test",NO_PARAM); Result<NsDAO.Data> retValSuc = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); Mockito.doReturn(retValFail).when(ques).mayUser(trans, null,rolePerm, Access.write); Mockito.doReturn(retValFail).when(ques).mayUser(trans, null,role, Access.write); - + Function funcObj = new Function(trans, ques); Result<Void> result = funcObj.delPermFromRole(trans, role, rolePerm, false); assertTrue(result.status == Status.ERR_Denied); - + Mockito.doReturn(retValFail).when(ques).mayUser(trans, null,rolePerm, Access.write); - Mockito.doReturn(retValSuc).when(ques).mayUser(trans, null,role, Access.write); - + Mockito.doReturn(retValSuc).when(ques).mayUser(trans, null,role, Access.write); + Mockito.doReturn(retValFail).when(roleDAO).read(trans, role); - - Mockito.doReturn(retVal).when(permDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); - + + Mockito.doReturn(retVal).when(permDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); + result = funcObj.delPermFromRole(trans, role, rolePerm, false); assertTrue(result.status == 1); - + Result<List<PermDAO.Data>> retValPermSuc = new Result<List<PermDAO.Data>>(dataAlPerm,0,"test",NO_PARAM); - Mockito.doReturn(retValPermSuc).when(permDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); + Mockito.doReturn(retValPermSuc).when(permDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); result = funcObj.delPermFromRole(trans, role, rolePerm, false); assertTrue(result.status == 1); - + Result<List<RoleDAO.Data>> retValRoleSuc = new Result<List<RoleDAO.Data>>(dataAl,0,"test",NO_PARAM); - Mockito.doReturn(retValRoleSuc).when(roleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); + Mockito.doReturn(retValRoleSuc).when(roleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); result = funcObj.delPermFromRole(trans, role, rolePerm, true); assertTrue(result.status == Status.ERR_PermissionNotFound); - + role.perms = null; dataAl.add(role); rolesSet.add("null|null|null|null"); role.perms = rolesSet; dataAl.add(role); - Mockito.doReturn(retValRoleSuc).when(roleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); - Mockito.doReturn(retVal).when(permDAO).delRole(Mockito.any(), Mockito.any(),Mockito.any(RoleDAO.Data.class)); + Mockito.doReturn(retValRoleSuc).when(roleDAO).read(Mockito.any(), Mockito.any(RoleDAO.Data.class)); + Mockito.doReturn(retVal).when(permDAO).delRole(Mockito.any(), Mockito.any(),Mockito.any(RoleDAO.Data.class)); result = funcObj.delPermFromRole(trans, role, rolePerm, true); assertTrue(result.status == 1); - - Mockito.doReturn(true).when(trans).requested(REQD_TYPE.force); + + Mockito.doReturn(true).when(trans).requested(REQD_TYPE.force); result = funcObj.delPermFromRole(trans, role, rolePerm, true); assertTrue(result.status == 1); - + Mockito.doReturn(retValRoleSuc).when(permDAO).delRole(Mockito.any(), Mockito.any(),Mockito.any(RoleDAO.Data.class)); - Mockito.doReturn(retVal).when(roleDAO).delPerm(Mockito.any(), Mockito.any(),Mockito.any(PermDAO.Data.class)); + Mockito.doReturn(retVal).when(roleDAO).delPerm(Mockito.any(), Mockito.any(),Mockito.any(PermDAO.Data.class)); result = funcObj.delPermFromRole(trans, role, rolePerm, true); assertTrue(result.status == 1); - - Mockito.doReturn(retValPermSuc).when(roleDAO).delPerm(Mockito.any(), Mockito.any(),Mockito.any(PermDAO.Data.class)); + + Mockito.doReturn(retValPermSuc).when(roleDAO).delPerm(Mockito.any(), Mockito.any(),Mockito.any(PermDAO.Data.class)); result = funcObj.delPermFromRole(trans, role, rolePerm, true); assertTrue(result.status == 0); - + Mockito.doReturn(retVal).when(permDAO).read(Mockito.any(), Mockito.any(PermDAO.Data.class)); result = funcObj.delPermFromRole(trans, role, rolePerm, true); assertTrue(result.status == 0); - - Mockito.doReturn(retVal).when(roleDAO).delPerm(Mockito.any(), Mockito.any(),Mockito.any(PermDAO.Data.class)); + + Mockito.doReturn(retVal).when(roleDAO).delPerm(Mockito.any(), Mockito.any(),Mockito.any(PermDAO.Data.class)); result = funcObj.delPermFromRole(trans, role, rolePerm, true); assertTrue(result.status == 1); @@ -1413,7 +1413,7 @@ public class JU_Function { Mockito.doReturn(retValFail).when(ques).mayUser(Mockito.any(), Mockito.anyString(),Mockito.any(PermDAO.Data.class), Mockito.any()); result = funcObj.delPermFromRole(trans, "test", rolePerm); assertTrue(result.status == 2); - + retVal3 = new Result<NsSplit>(null,1,"test",NO_PARAM); Mockito.doReturn(retVal3).when(ques).deriveNsSplit(Mockito.any(), Mockito.anyString()); result = funcObj.delPermFromRole(trans, "test", rolePerm); @@ -1427,29 +1427,29 @@ public class JU_Function { urData.rname="test"; urData.user="test"; urDataAl.add(urData); - + Organization org = Mockito.mock(Organization.class); Mockito.doReturn(org).when(trans).org(); Mockito.doReturn(Mockito.mock(GregorianCalendar.class)).when(org).expiration(Mockito.any(), Mockito.any(), Mockito.anyString()); - + Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); Result<List<UserRoleDAO.Data>> retValSuc = new Result<List<UserRoleDAO.Data>>(urDataAl,0,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any(UserRoleDAO.Data.class)); - Mockito.doReturn(retVal).when(userRoleDAO).create(Mockito.any(), Mockito.any(UserRoleDAO.Data.class)); - Mockito.doReturn(retValSuc).when(roleDAO).read(Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.doReturn(retVal).when(userRoleDAO).create(Mockito.any(), Mockito.any(UserRoleDAO.Data.class)); + Mockito.doReturn(retValSuc).when(roleDAO).read(Mockito.any(), Mockito.anyString(), Mockito.anyString()); Result<List<CredDAO.Data>> retVal2 = new Result<List<CredDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal2).when(credDAO).readID(Mockito.any(), Mockito.anyString()); - + Mockito.doReturn(retVal2).when(credDAO).readID(Mockito.any(), Mockito.anyString()); + Function funcObj = new Function(trans, ques); Result<Void> result = funcObj.addUserRole(trans, urData); assertTrue(result.status == 1); - + urData.rname=Question.ADMIN; result = funcObj.addUserRole(trans, urData); assertTrue(result.status == 1); - + NsDAO.Data data = new NsDAO.Data(); data.name="test"; Result<NsDAO.Data> retVal1 = new Result<NsDAO.Data>(data,0,"test",NO_PARAM); @@ -1465,21 +1465,21 @@ public class JU_Function { result = funcObj.addUserRole(trans, urData); assertTrue(result.status == 1); - Mockito.doReturn(retValSuc).when(userRoleDAO).create(Mockito.any(), Mockito.any(UserRoleDAO.Data.class)); + Mockito.doReturn(retValSuc).when(userRoleDAO).create(Mockito.any(), Mockito.any(UserRoleDAO.Data.class)); result = funcObj.addUserRole(trans, urData); assertTrue(result.status == 0); Mockito.doReturn(retVal).when(roleDAO).read(Mockito.any(), Mockito.anyString(), Mockito.anyString()); result = funcObj.addUserRole(trans, urData); assertTrue(result.status == Status.ERR_RoleNotFound); - + Mockito.doReturn(retValSuc).when(userRoleDAO).read(Mockito.any(), Mockito.any(UserRoleDAO.Data.class)); result = funcObj.addUserRole(trans, urData); assertTrue(result.status == Status.ERR_ConflictAlreadyExists); - + result = funcObj.addUserRole(trans, "test", "test", "test"); assertTrue(result.status == 1); - + try { Mockito.doReturn(null).when(org).getIdentity(trans, "test"); } catch (OrganizationException e) { @@ -1488,7 +1488,7 @@ public class JU_Function { } result = funcObj.addUserRole(trans, "test", "test", "test"); assertTrue(result.status == Result.ERR_BadData); - + try { Mockito.doThrow(OrganizationException.class).when(org).getIdentity(trans, "test"); } catch (OrganizationException e) { @@ -1498,7 +1498,7 @@ public class JU_Function { result = funcObj.addUserRole(trans, "test", "test", "test"); assertTrue(result.status == 20); } - + @Test public void testExtendUserRole() { List<UserRoleDAO.Data> urDataAl = new ArrayList<>(); @@ -1508,34 +1508,34 @@ public class JU_Function { urData.user="test"; urData.expires=new Date(); urDataAl.add(urData); - + // List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); // NsDAO.Data dataObj = new NsDAO.Data(); // dataObj.type=1; // dataAl.add(dataObj); Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); Result<List<UserRoleDAO.Data>> retValSuc = new Result<List<UserRoleDAO.Data>>(urDataAl,0,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); Mockito.doReturn(retValSuc).when(roleDAO).read(Mockito.any(), Mockito.anyString(), Mockito.anyString()); Organization org = Mockito.mock(Organization.class); Mockito.doReturn(org).when(trans).org(); Mockito.doReturn(Mockito.mock(GregorianCalendar.class)).when(org).expiration(Mockito.any(), Mockito.any()); - + Function funcObj = new Function(trans, ques); Result<Void> result = funcObj.extendUserRole(trans, urData, false); assertNull(result); - + Mockito.doReturn(retVal).when(roleDAO).read(Mockito.any(), Mockito.anyString(), Mockito.anyString()); Mockito.doReturn(retValSuc).when(userRoleDAO).read(trans, urData); result = funcObj.extendUserRole(trans, urData, true); assertTrue(result.status == Status.ERR_RoleNotFound); - + Mockito.doReturn(retVal).when(userRoleDAO).read(trans, urData); result = funcObj.extendUserRole(trans, urData, true); assertTrue(result.status == Status.ERR_UserRoleNotFound); } - + @SuppressWarnings("deprecation") @Test public void testGetUsersByRole() { @@ -1547,7 +1547,7 @@ public class JU_Function { urData.expires=new Date(); urDataAl.add(urData); Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(urDataAl,0,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); Function funcObj = new Function(trans, ques); Result<List<String>> result = funcObj.getUsersByRole(trans, "test", false); @@ -1555,11 +1555,11 @@ public class JU_Function { result = funcObj.getUsersByRole(trans, "test", true); assertTrue(result.status == 0); - + urData.expires=new Date(130,1,1); result = funcObj.getUsersByRole(trans, "test", true); assertTrue(result.status == 0); -// +// } @Test public void testDelUserRole() { @@ -1571,26 +1571,26 @@ public class JU_Function { urData.expires=new Date(); urDataAl.add(urData); Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(urDataAl,0,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any( UserRoleDAO.Data.class)); + Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any( UserRoleDAO.Data.class)); Function funcObj = new Function(trans, ques); Result<Void> result = funcObj.delUserRole(trans, "test", "test", "test"); assertNull(result); - + retVal = new Result<List<UserRoleDAO.Data>>(urDataAl,1,"test",NO_PARAM); Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any( UserRoleDAO.Data.class)); result = funcObj.delUserRole(trans, "test", "test", "test"); -// assertTrue(result.status ==1); -// +// assertTrue(result.status ==1); +// } - + @Test public void testCreateFuture() { FutureDAO.Data data = new FutureDAO.Data(); data.memo = "test"; NsDAO.Data nsd = new NsDAO.Data(); nsd.name = "test"; - + List<UserRoleDAO.Data> urDataAl = new ArrayList<>(); UserRoleDAO.Data urData = new UserRoleDAO.Data(); urData.ns="test"; @@ -1600,7 +1600,7 @@ public class JU_Function { urDataAl.add(urData); Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(urDataAl,0,"test",NO_PARAM); Result<List<UserRoleDAO.Data>> retValFail = new Result<List<UserRoleDAO.Data>>(urDataAl,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any( UserRoleDAO.Data.class)); + Mockito.doReturn(retVal).when(userRoleDAO).read(Mockito.any(), Mockito.any( UserRoleDAO.Data.class)); Function funcObj = new Function(trans, ques); Result<String> result = funcObj.createFuture(trans, data, "test", "test", nsd, FUTURE_OP.A); @@ -1618,23 +1618,23 @@ public class JU_Function { data.memo = "test"; Result<FutureDAO.Data> retValFuture = new Result<FutureDAO.Data>(futureData,0,"test",NO_PARAM); Mockito.doReturn(retValFuture).when(futureDAO).create(Mockito.any(), Mockito.any( FutureDAO.Data.class), Mockito.anyString()); - + ApprovalDAO.Data approvalData = new ApprovalDAO.Data(); data.memo = "test"; Result<ApprovalDAO.Data> retValApproval = new Result<ApprovalDAO.Data>(approvalData,0,"test",NO_PARAM); Mockito.doReturn(retValApproval).when(approvalDAO).create(Mockito.any(), Mockito.any( ApprovalDAO.Data.class)); - - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); + + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); result = funcObj.createFuture(trans, data, "test", "test", nsd, FUTURE_OP.A); assertTrue(result.status == 0); - + result = funcObj.createFuture(trans, data, "test", "test", null, FUTURE_OP.A); assertTrue(result.status == 20); Mockito.doReturn(retValFail).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); result = funcObj.createFuture(trans, data, "test", "test", nsd, FUTURE_OP.A); assertTrue(result.status == Result.ERR_NotFound); - + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); try { Mockito.doReturn(null).when(org).getIdentity(trans, "test"); @@ -1644,7 +1644,7 @@ public class JU_Function { } result = funcObj.createFuture(trans, data, "test", "test", nsd, FUTURE_OP.A); assertTrue(result.status == Result.ERR_NotFound); - + try { Mockito.doReturn(iden).when(org).getIdentity(trans, "test"); } catch (OrganizationException e) { @@ -1653,7 +1653,7 @@ public class JU_Function { } result = funcObj.createFuture(trans, data, "test", "test", nsd, FUTURE_OP.C); assertTrue(result.status == 0); - + retValApproval = new Result<ApprovalDAO.Data>(null,1,"test",NO_PARAM); Mockito.doReturn(retValApproval).when(approvalDAO).create(Mockito.any(), Mockito.any( ApprovalDAO.Data.class)); result = funcObj.createFuture(trans, data, "test", "test", nsd, FUTURE_OP.A); @@ -1671,22 +1671,22 @@ public class JU_Function { urDataAl.add(urData); Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(urDataAl,0,"test",NO_PARAM); Result<List<UserRoleDAO.Data>> retValFail = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).read(trans, objArr); - + Mockito.doReturn(retVal).when(userRoleDAO).read(trans, objArr); + Function funcObj = new Function(trans, ques); funcObj.urDBLookup.get(trans, objArr); - - Mockito.doReturn(retValFail).when(userRoleDAO).read(trans, objArr); + + Mockito.doReturn(retValFail).when(userRoleDAO).read(trans, objArr); funcObj.urDBLookup.get(trans, objArr); } - + @Test public void testPerformFutureOp() { FutureDAO.Data futureDataDaoObj = new FutureDAO.Data(); futureDataDaoObj.memo="test"; futureDataDaoObj.target = "test"; futureDataDaoObj.id = new UUID(10L,10L); - + final List<ApprovalDAO.Data> apprs = new ArrayList<>(); ApprovalDAO.Data approvalObj = new ApprovalDAO.Data(); approvalObj.status = "approved"; @@ -1698,7 +1698,7 @@ public class JU_Function { return apprs; } }; - + final UserRoleDAO.Data userObj = new UserRoleDAO.Data(); Lookup<UserRoleDAO.Data> lookupUserObj = new Lookup<UserRoleDAO.Data>() { @Override @@ -1706,61 +1706,61 @@ public class JU_Function { return userObj; } }; - + FutureDAO.Data futureData = new FutureDAO.Data(); // data.memo = "test"; Result<FutureDAO.Data> retValFuture = new Result<FutureDAO.Data>(futureData,0,"test",NO_PARAM); Mockito.doReturn(retValFuture).when(futureDAO).delete(Mockito.any(), Mockito.any( FutureDAO.Data.class), Mockito.anyBoolean()); - + // List<NsDAO.Data> dataAl = new ArrayList<NsDAO.Data>(); // NsDAO.Data dataObj = new NsDAO.Data(); // dataObj.type=1; // dataAl.add(dataObj); Result<List<UserRoleDAO.Data>> retVal = new Result<List<UserRoleDAO.Data>>(null,1,"test",NO_PARAM); - Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); -// + Mockito.doReturn(retVal).when(userRoleDAO).readByRole(Mockito.any(), Mockito.anyString()); +// // Result<NsDAO.Data> retVal2 = new Result<NsDAO.Data>(null,0,"test",NO_PARAM); // Mockito.doReturn(retVal2).when(ques).mayUser(trans, null,retVal.value.get(0), Access.write); -// +// Function funcObj = new Function(trans, ques); Result<Function.OP_STATUS> result = funcObj.performFutureOp(trans, FUTURE_OP.A, futureDataDaoObj, lookupApprovalObj, lookupUserObj); assertTrue(result.status == 0); - + approvalObj.status = "approved"; approvalObj.type = "supervisor"; result = funcObj.performFutureOp(trans, FUTURE_OP.A, futureDataDaoObj, lookupApprovalObj, lookupUserObj); assertTrue(result.status == 0); - + approvalObj.status = "approved"; approvalObj.type = ""; result = funcObj.performFutureOp(trans, FUTURE_OP.A, futureDataDaoObj, lookupApprovalObj, lookupUserObj); assertTrue(result.status == 0); - + approvalObj.status = "pending"; approvalObj.type = "supervisor"; result = funcObj.performFutureOp(trans, FUTURE_OP.A, futureDataDaoObj, lookupApprovalObj, lookupUserObj); assertTrue(result.status == 0); - + approvalObj.status = "pending"; approvalObj.type = "owner"; result = funcObj.performFutureOp(trans, FUTURE_OP.A, futureDataDaoObj, lookupApprovalObj, lookupUserObj); assertTrue(result.status == 0); - + approvalObj.status = "pending"; approvalObj.type = ""; result = funcObj.performFutureOp(trans, FUTURE_OP.A, futureDataDaoObj, lookupApprovalObj, lookupUserObj); assertTrue(result.status == 0); - + approvalObj.status = "denied"; approvalObj.type = ""; result = funcObj.performFutureOp(trans, FUTURE_OP.A, futureDataDaoObj, lookupApprovalObj, lookupUserObj); assertTrue(result.status == 0); - + retValFuture = new Result<FutureDAO.Data>(futureData,1,"test",NO_PARAM); Mockito.doReturn(retValFuture).when(futureDAO).delete(Mockito.any(), Mockito.any( FutureDAO.Data.class), Mockito.anyBoolean()); result = funcObj.performFutureOp(trans, FUTURE_OP.A, futureDataDaoObj, lookupApprovalObj, lookupUserObj); System.out.println(result); assertTrue(result.status == 0); -// +// } } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_PermLookup.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_PermLookup.java index 7e1abeba..f5d22ba2 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_PermLookup.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/hl/JU_PermLookup.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. @@ -51,17 +51,17 @@ import org.onap.aaf.cadi.CadiException; import org.onap.aaf.misc.env.LogTarget; -@RunWith(MockitoJUnitRunner.class) +@RunWith(MockitoJUnitRunner.class) public class JU_PermLookup { - - + + @Mock AuthzTrans trans; - + @Mock Question q; - + @Mock Access access; @@ -70,40 +70,40 @@ public class JU_PermLookup { @Mock CachedUserRoleDAO userRoleDAO; - + Function f; - + @Before public void setUp() throws Exception { initMocks(this); Mockito.doReturn(userRoleDAO).when(q).userRoleDAO(); Mockito.doReturn(roleDAO).when(q).roleDAO(); - + try { Mockito.doReturn("0.0").when(access).getProperty("aaf_root_ns","org.osaaf.aaf"); Mockito.doReturn(new Properties()).when(access).getProperties(); Define.set(access); - + when(trans.error()).thenReturn(new LogTarget() { - + @Override public void printf(String fmt, Object... vars) {} - + @Override public void log(Throwable e, Object... msgs) { e.getMessage(); e.printStackTrace(); msgs.toString(); - + } - + @Override public void log(Object... msgs) { } - + @Override public boolean isLoggable() { - + return true; } }); @@ -113,70 +113,70 @@ public class JU_PermLookup { } f =new Function(trans, q); } - - + + // @Test // public void testPerm() { -// +// // PermLookup cassExecutorObj =PermLookup.get(trans, q,""); -// +// //// System.out.println(cassExecutorObj); //// assertFalse(retVal); // } - + @Test public void testGetUserRole() { @SuppressWarnings("unchecked") Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); retVal1.value = new ArrayList<UserRoleDAO.Data>(); UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); - + dataObj.expires = new Date(); - + retVal1.value.add(dataObj); Mockito.doReturn(true).when(retVal1).isOKhasData(); Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); PermLookup cassExecutorObj =PermLookup.get(trans, q,""); Result<List<UserRoleDAO.Data>> userRoles = cassExecutorObj.getUserRoles(); - + //System.out.println(""+userRoles.status); assertEquals(24,userRoles.status); } - + @Test public void testGetUserRolesFirstIf() { @SuppressWarnings("unchecked") Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); retVal1.value = new ArrayList<UserRoleDAO.Data>(); - + Mockito.doReturn(false).when(retVal1).isOKhasData(); Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); PermLookup cassExecutorObj =PermLookup.get(trans, q,""); Result<List<UserRoleDAO.Data>> userRoles = cassExecutorObj.getUserRoles(); - + // System.out.println("output is"+userRoles.status); assertEquals(0,userRoles.status); } - + @Test public void testGetUserRolesSecondIf() { @SuppressWarnings("unchecked") Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); retVal1.value = new ArrayList<UserRoleDAO.Data>(); UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); - + Date dt = new Date(); - Calendar c = Calendar.getInstance(); - c.setTime(dt); + Calendar c = Calendar.getInstance(); + c.setTime(dt); c.add(Calendar.DATE, 1); dataObj.expires = c.getTime(); - + retVal1.value.add(dataObj); Mockito.doReturn(true).when(retVal1).isOKhasData(); Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); PermLookup cassExecutorObj =PermLookup.get(trans, q,""); Result<List<UserRoleDAO.Data>> userRoles = cassExecutorObj.getUserRoles(); - + //System.out.println(userRoles.status); assertEquals("Success",userRoles.details); Result<List<UserRoleDAO.Data>> userRoles1 = cassExecutorObj.getUserRoles(); @@ -184,38 +184,38 @@ public class JU_PermLookup { //System.out.println(userRoles1.status); assertEquals(0, userRoles1.status); } - + @Test public void testGetRole() { @SuppressWarnings("unchecked") Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); retVal1.value = new ArrayList<UserRoleDAO.Data>(); UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); - + dataObj.expires = new Date(); - + retVal1.value.add(dataObj); Mockito.doReturn(false).when(retVal1).isOKhasData(); Mockito.doReturn(true).when(retVal1).isOK(); Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); PermLookup cassExecutorObj =PermLookup.get(trans, q,""); Result<List<RoleDAO.Data>> userRoles = cassExecutorObj.getRoles(); - + //System.out.println(""+userRoles.status); assertEquals(4,userRoles.status); } - + @Test public void testGetRoleFirstIf() { @SuppressWarnings("unchecked") Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); retVal1.value = new ArrayList<UserRoleDAO.Data>(); UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); - + dataObj.expires = new Date(); dataObj.ns=""; dataObj.rname=""; - + retVal1.value.add(dataObj); Mockito.doReturn(false).when(retVal1).isOKhasData(); Mockito.doReturn(false).when(retVal1).isOK(); @@ -223,22 +223,22 @@ public class JU_PermLookup { Mockito.doReturn(retVal1).when(roleDAO).read(trans,"",""); PermLookup cassExecutorObj =PermLookup.get(trans, q,""); Result<List<RoleDAO.Data>> userRoles = cassExecutorObj.getRoles(); - + // System.out.println(""+userRoles.status); assertEquals(0,userRoles.status); } - + @Test public void testGetRoleSecondIf() { @SuppressWarnings("unchecked") Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); retVal1.value = new ArrayList<UserRoleDAO.Data>(); UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); - + dataObj.expires = new Date(); dataObj.ns=""; dataObj.rname=""; - + retVal1.value.add(dataObj); Mockito.doReturn(false).when(retVal1).isOKhasData(); Mockito.doReturn(true).when(retVal1).isOK(); @@ -247,7 +247,7 @@ public class JU_PermLookup { PermLookup cassExecutorObj =PermLookup.get(trans, q,""); Result<List<RoleDAO.Data>> userRoles = cassExecutorObj.getRoles(); userRoles = cassExecutorObj.getRoles(); - + // System.out.println(""+userRoles.status); assertEquals(0,userRoles.status); } @@ -262,7 +262,7 @@ public class JU_PermLookup { PermLookup cassExecutorObj =PermLookup.get(trans, q,""); Result<Set<String>> userRoles = cassExecutorObj.getPermNames(); userRoles = cassExecutorObj.getPermNames(); - + //System.out.println(""+userRoles.status); assertEquals(0,userRoles.status); } @@ -272,19 +272,19 @@ public class JU_PermLookup { Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); retVal1.value = new ArrayList<UserRoleDAO.Data>(); UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); - + dataObj.expires = new Date(); - + retVal1.value.add(dataObj); Mockito.doReturn(false).when(retVal1).isOKhasData(); Mockito.doReturn(true).when(retVal1).isOK(); Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); PermLookup cassExecutorObj =PermLookup.get(trans, q,""); Result<Set<String>> userRoles = cassExecutorObj.getPermNames(); - + //System.out.println(""+userRoles.status); assertEquals(4,userRoles.status); - } + } @SuppressWarnings("unchecked") @@ -292,31 +292,31 @@ public class JU_PermLookup { public void testGetPerm() { Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); Result<List<RoleDAO.Data>> retVal2 = Mockito.mock(Result.class); - + retVal1.value = new ArrayList<UserRoleDAO.Data>(); retVal2.value = new ArrayList<RoleDAO.Data>(); UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); - + Date dt = new Date(); - Calendar c = Calendar.getInstance(); - c.setTime(dt); + Calendar c = Calendar.getInstance(); + c.setTime(dt); c.add(Calendar.DATE, 1); dataObj.expires = c.getTime(); dataObj.ns = ""; dataObj.rname=""; - + RoleDAO.Data dataObj1 = Mockito.mock( RoleDAO.Data.class); Set<String> permSet = new HashSet<String>(); permSet.add("test"); Mockito.doReturn(permSet).when(dataObj1).perms(false); - + dt = new Date(); - c = Calendar.getInstance(); - c.setTime(dt); + c = Calendar.getInstance(); + c.setTime(dt); c.add(Calendar.DATE, 1); dataObj1.ns = "test"; dataObj1.perms = permSet; - + retVal1.value.add(dataObj); retVal2.value.add(dataObj1); Mockito.doReturn(true).when(retVal1).isOKhasData(); @@ -325,47 +325,47 @@ public class JU_PermLookup { Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); Mockito.doReturn(retVal2).when(roleDAO).read(trans,"",""); - + PermLookup cassExecutorObj =PermLookup.get(trans, q,""); -// +// // Mockito.doReturn(retVal2).when(cassExecutorObj).getPermNames(); Result<List<Data>> userRoles = cassExecutorObj.getPerms(true); // userRoles = cassExecutorObj.getPerms(false); - + // System.out.println(""+userRoles.status); assertEquals(0,userRoles.status); } - + @SuppressWarnings("unchecked") @Test public void testGetPermFalse() { Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class); Result<List<RoleDAO.Data>> retVal2 = Mockito.mock(Result.class); - + retVal1.value = new ArrayList<UserRoleDAO.Data>(); retVal2.value = new ArrayList<RoleDAO.Data>(); UserRoleDAO.Data dataObj = Mockito.mock( UserRoleDAO.Data.class); - + Date dt = new Date(); - Calendar c = Calendar.getInstance(); - c.setTime(dt); + Calendar c = Calendar.getInstance(); + c.setTime(dt); c.add(Calendar.DATE, 1); dataObj.expires = c.getTime(); dataObj.ns = ""; dataObj.rname=""; - + RoleDAO.Data dataObj1 = Mockito.mock( RoleDAO.Data.class); Set<String> permSet = new HashSet<String>(); permSet.add("test"); Mockito.doReturn(permSet).when(dataObj1).perms(false); - + dt = new Date(); - c = Calendar.getInstance(); - c.setTime(dt); + c = Calendar.getInstance(); + c.setTime(dt); c.add(Calendar.DATE, 1); dataObj1.ns = "test"; dataObj1.perms = permSet; - + retVal1.value.add(dataObj); retVal2.value.add(dataObj1); Mockito.doReturn(true).when(retVal1).isOKhasData(); @@ -374,15 +374,15 @@ public class JU_PermLookup { Mockito.doReturn(retVal1).when(userRoleDAO).readByUser(trans,""); Mockito.doReturn(retVal2).when(roleDAO).read(trans,"",""); - + PermLookup cassExecutorObj =PermLookup.get(trans, q,""); -// +// // Mockito.doReturn(retVal2).when(cassExecutorObj).getPermNames(); Result<List<Data>> userRoles = cassExecutorObj.getPerms(false); userRoles = cassExecutorObj.getPerms(false); - + // System.out.println(""+userRoles.status); assertEquals(0,userRoles.status); } - + }
\ No newline at end of file diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFLocator.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFLocator.java index 5a7d4959..05623127 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFLocator.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFLocator.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. @@ -48,26 +48,26 @@ import org.onap.aaf.cadi.config.Config; import junit.framework.Assert; -@RunWith(MockitoJUnitRunner.class) +@RunWith(MockitoJUnitRunner.class) public class JU_DirectAAFLocator { @Mock LocateDAO ldao; - + @Mock AuthzEnv env; - + @Mock AuthzTrans trans; - + @Mock PropAccess access; - + @Before public void setUp() throws Exception { initMocks(this); } - + @Test public void testConstructorVersionExcpetion() { Mockito.doReturn(access).when(env).access(); @@ -97,7 +97,7 @@ public class JU_DirectAAFLocator { assertEquals("Invalid Version String: 20.20.20.test", e.getMessage()); } } - + @Test public void testConstructorExcpetion() { Mockito.doReturn(access).when(env).access(); @@ -112,7 +112,7 @@ public class JU_DirectAAFLocator { // System.out.println(e.getMessage()); } } - + // NOTE: These mocks to not well represent the DirectAAFLocator Class. @Test public void testConstructorUriExcpetion() { @@ -133,7 +133,7 @@ public class JU_DirectAAFLocator { @Test public void testRefresh() { - + DirectAAFLocator aafLocatorObj=null; PropAccess access = Mockito.mock(PropAccess.class); Mockito.doReturn(access).when(env).access(); @@ -150,7 +150,7 @@ public class JU_DirectAAFLocator { e.printStackTrace(); } Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"",new Object[0]); - + Data data= new Data(); data.major=30; data.minor=30; @@ -158,16 +158,16 @@ public class JU_DirectAAFLocator { data.pkg=30; retVal1.value = new ArrayList<Data>(); retVal1.value.add(data); - + Mockito.doReturn(retVal1).when(ldao).readByName(trans,"test"); boolean retVal = aafLocatorObj.refresh(); // System.out.println(retVal); assertTrue(retVal); - } - + } + @Test public void testRefreshNOK() { - + DirectAAFLocator aafLocatorObj=null; PropAccess access = Mockito.mock(PropAccess.class); Mockito.doReturn(access).when(env).access(); @@ -184,11 +184,11 @@ public class JU_DirectAAFLocator { e.printStackTrace(); } Result<List<Data>> retVal1 = new Result<List<Data>>(null,1,"",new String[0]); - + Mockito.doReturn(retVal1).when(ldao).readByName(trans,"test"); boolean retVal = aafLocatorObj.refresh(); // System.out.println(retVal); assertFalse(retVal); - } - + } + }
\ No newline at end of file diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFLur.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFLur.java index 0ed6e60c..dbd517a0 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFLur.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFLur.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. @@ -51,34 +51,34 @@ import org.onap.aaf.cadi.lur.LocalPermission; import org.onap.aaf.misc.env.LogTarget; import org.onap.aaf.misc.env.Trans; -@RunWith(MockitoJUnitRunner.class) +@RunWith(MockitoJUnitRunner.class) public class JU_DirectAAFLur { @Mock AuthzEnv env; - + @Mock Question question; - + @Mock Principal bait; - + @Mock Permission pond; - + @Mock AuthzTrans trans; - + @Before public void setUp() throws Exception { initMocks(this); Mockito.when(env.newTransNoAvg()).thenReturn(trans); Mockito.doReturn(Mockito.mock(LogTarget.class)).when(trans).error(); } - + public void testFish() { DirectAAFLur aafLurObj = new DirectAAFLur(env, question); - + List<PermDAO.Data> rsVal = new ArrayList<PermDAO.Data>(); Result<List<Data>> rs = new Result<List<Data>>(rsVal,0,"test",new Object[0]); Mockito.when(question.getPermsByUser(env.newTransNoAvg(), bait.getName(), false)).thenReturn(rs); @@ -88,7 +88,7 @@ public class JU_DirectAAFLur { @Test public void testFishSecondMtd() { DirectAAFLur aafLurObj = new DirectAAFLur(env, question); - + List<PermDAO.Data> rsVal = new ArrayList<PermDAO.Data>(); PermDAO.Data pd = new PermDAO.Data(); pd.ns = "ns"; @@ -101,7 +101,7 @@ public class JU_DirectAAFLur { pd.instance = "instance"; pd.action = null; rsVal.add(pd); - + pd = new PermDAO.Data(); pd.ns = "ns"; pd.type = "name"; @@ -115,25 +115,25 @@ public class JU_DirectAAFLur { pd.ns = "ns"; pd.type = "name1"; rsVal.add(pd); - + pd = new PermDAO.Data(); pd.ns = "ns"; pd.type = "name"; pd.instance = "instance"; pd.action = "action"; rsVal.add(pd); - + pond = new DirectAAFLur.PermPermission("ns", "name", "instance", "action"); - + Result<List<Data>> rs = new Result<List<Data>>(rsVal,0,"test",new Object[0]); Mockito.when(question.getPermsByUser(env.newTransNoAvg(), bait.getName(), false)).thenReturn(rs); aafLurObj.fish(bait, pond); - + pond = new AAFPermission("ns", "name", "instance", "action"); - + Mockito.when(question.getPermsByUser(env.newTransNoAvg(), bait.getName(), false)).thenReturn(rs); aafLurObj.fish(bait, pond); - + rs = new Result<List<Data>>(rsVal,1,"test",new Object[0]); Mockito.when(question.getPermsByUser(env.newTransNoAvg(), bait.getName(), false)).thenReturn(rs); aafLurObj.fish(bait, pond); @@ -144,76 +144,76 @@ public class JU_DirectAAFLur { Mockito.when(question.getPermsByUser(env.newTransNoAvg(), bait.getName(), false)).thenReturn(rs); aafLurObj.fish(bait, pond); } - + @Test public void testFishAll() { Mockito.doReturn(Mockito.mock(LogTarget.class)).when(env).error(); DirectAAFLur aafLurObj = new DirectAAFLur(env, question); - + List<PermDAO.Data> rsVal = new ArrayList<PermDAO.Data>(); PermDAO.Data pd = new PermDAO.Data(); pd.ns = "ns"; pd.type = "name"; pd.instance = null; rsVal.add(pd); - + pond = new DirectAAFLur.PermPermission("ns", "name", "instance", "action"); List<Permission> permissions = new ArrayList<>(); permissions.add(pond); - + Result<List<Data>> rs = new Result<List<Data>>(rsVal,0,"test",new Object[0]); Mockito.when(question.getPermsByUser(env.newTrans(), bait.getName(), false)).thenReturn(rs); aafLurObj.fishAll(bait, permissions); assertTrue(permissions.size() == 2); - + rs = new Result<List<Data>>(rsVal,1,"test",new Object[0]); Mockito.when(question.getPermsByUser(env.newTrans(), bait.getName(), false)).thenReturn(rs); aafLurObj.fishAll(bait, permissions); } - + @Test public void testDestroy() { DirectAAFLur aafLurObj = new DirectAAFLur(env, question); aafLurObj.destroy(); } - + @Test public void testHandlesExclusively() { DirectAAFLur aafLurObj = new DirectAAFLur(env, question); pond = new DirectAAFLur.PermPermission("ns", "name", "instance", "action"); assertFalse(aafLurObj.handlesExclusively(pond)); } - + @Test public void testToString() { DirectAAFLur aafLurObj = new DirectAAFLur(env, question); assertTrue(aafLurObj.toString().contains("DirectAAFLur is enabled")); } - + @Test public void testHandles() { DirectAAFLur aafLurObj = new DirectAAFLur(env, question); assertTrue(aafLurObj.handles(null)); } - + @Test public void testCreatePerm() { DirectAAFLur aafLurObj = new DirectAAFLur(env, question); Permission retVal = aafLurObj.createPerm("test"); assertTrue(retVal instanceof LocalPermission); - + NsSplit nss = new NsSplit("test", "test"); Result<NsSplit> rs = new Result<NsSplit>(nss,0,"test",new Object[0]); Mockito.when(question.deriveNsSplit(NullTrans.singleton() , "test")).thenReturn(rs); retVal = aafLurObj.createPerm("test|1|2"); assertTrue(retVal instanceof PermPermission); - + rs = new Result<NsSplit>(null,1,"test",new Object[0]); Mockito.when(question.deriveNsSplit(NullTrans.singleton() , "test")).thenReturn(rs); retVal = aafLurObj.createPerm("test|1|2"); assertTrue(retVal instanceof LocalPermission); } - + @Test public void testClear() { AuthzTransImpl trans = Mockito.mock(AuthzTransImpl.class); @@ -223,7 +223,7 @@ public class JU_DirectAAFLur { Mockito.when(trans.auditTrail(0, sb)).thenReturn(Mockito.mock(Trans.Metric.class)); aafLurObj.clear(bait, sb); } - + @Test public void testPermPermission() { AuthzTransImpl trans = Mockito.mock(AuthzTransImpl.class); @@ -231,12 +231,12 @@ public class JU_DirectAAFLur { Result<NsSplit> rs = new Result<NsSplit>(nss,0,"test",new Object[0]); Mockito.when(question.deriveNsSplit(trans , "test")).thenReturn(rs); PermPermission pp = new PermPermission(trans, question, "test|test|test|test"); - + assertTrue("test".equalsIgnoreCase(pp.getKey())); assertTrue("AAFLUR".equalsIgnoreCase(pp.permType())); - + assertFalse(pp.match(null)); - + pond = new AAFPermission("test.test", "test", "test", "test"); assertTrue(pp.match(pond)); } diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFUserPass.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFUserPass.java index 241d407b..03e3e932 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFUserPass.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFUserPass.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. @@ -44,76 +44,76 @@ import org.onap.aaf.auth.layer.Result; import org.onap.aaf.misc.env.LogTarget; -@RunWith(MockitoJUnitRunner.class) +@RunWith(MockitoJUnitRunner.class) public class JU_DirectAAFUserPass { @Mock Question question; - + @Mock AuthzEnv env; - + @Mock AuthzTrans trans; - + @Mock HttpServletRequest request; - - + + @Before public void setUp() throws Exception { initMocks(this); when(env.warn()).thenReturn(new LogTarget() { - + @Override public void printf(String fmt, Object... vars) {} - + @Override public void log(Throwable e, Object... msgs) { e.getMessage(); e.printStackTrace(); msgs.toString(); - + } - + @Override public void log(Object... msgs) { } - + @Override public boolean isLoggable() { - + return true; } }); when(env.error()).thenReturn(new LogTarget() { - + @Override public void printf(String fmt, Object... vars) {} - + @Override public void log(Throwable e, Object... msgs) { e.getMessage(); e.printStackTrace(); msgs.toString(); - + } - + @Override public void log(Object... msgs) { } - + @Override public boolean isLoggable() { - + return true; } }); } - + @Test public void testUserPass() { - + DirectAAFUserPass aafLocatorObj=null; aafLocatorObj = new DirectAAFUserPass(env, question); Result<Date> retVal1 = new Result<Date>(null,0,"",new String[0]); @@ -124,13 +124,13 @@ public class JU_DirectAAFUserPass { e.printStackTrace(); } boolean retVal = aafLocatorObj.validate(null, null, null, null); - + assertFalse(retVal); - } - + } + @Test public void testUserPassStateisRequest() { - + DirectAAFUserPass aafLocatorObj=null; aafLocatorObj = new DirectAAFUserPass(env, question); Result<Date> retVal1 = new Result<Date>(null,1,"",new String[0]); @@ -141,14 +141,14 @@ public class JU_DirectAAFUserPass { e.printStackTrace(); } boolean retVal = aafLocatorObj.validate(null, null, null, request); - + // System.out.println(retVal); assertFalse(retVal); } - + @Test public void testUserPassStateNotNull() { - + DirectAAFUserPass aafLocatorObj=null; aafLocatorObj = new DirectAAFUserPass(env, question); Result<Date> retVal1 = new Result<Date>(null,1,"",new String[0]); @@ -159,14 +159,14 @@ public class JU_DirectAAFUserPass { e.printStackTrace(); } boolean retVal = aafLocatorObj.validate(null, null, null, "test"); - + // System.out.println(retVal); assertFalse(retVal); } - + @Test public void testUserPassTransChk() { - + DirectAAFUserPass aafLocatorObj=null; aafLocatorObj = new DirectAAFUserPass(env, question); Result<Date> retVal1 = new Result<Date>(null,1,"",new String[0]); @@ -177,14 +177,14 @@ public class JU_DirectAAFUserPass { e.printStackTrace(); } boolean retVal = aafLocatorObj.validate(null, null, null, trans); - + // System.out.println(retVal); assertFalse(retVal); } - + @Test public void testUserPassTransIpNotNull() { - + DirectAAFUserPass aafLocatorObj=null; aafLocatorObj = new DirectAAFUserPass(env, question); Result<Date> retVal1 = new Result<Date>(null,1,"",new String[0]); @@ -196,14 +196,14 @@ public class JU_DirectAAFUserPass { e.printStackTrace(); } boolean retVal = aafLocatorObj.validate(null, null, null, trans); - + // System.out.println(retVal); assertFalse(retVal); } - + @Test public void testUserExceptionChk() { - + DirectAAFUserPass aafLocatorObj=null; aafLocatorObj = new DirectAAFUserPass(env, question); Result<Date> retVal1 = new Result<Date>(null,1,"",new String[0]); @@ -215,9 +215,9 @@ public class JU_DirectAAFUserPass { // e.printStackTrace(); } boolean retVal = aafLocatorObj.validate(null, null, null, trans); - + // System.out.println(retVal); assertFalse(retVal); } - + }
\ No newline at end of file diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectCertIdentity.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectCertIdentity.java index 81195e5d..d59e615c 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectCertIdentity.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectCertIdentity.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,17 +66,17 @@ public class JU_DirectCertIdentity { try { Principal p = directCertIdentity.identity(req, cert, _certBytes); assertEquals(((p) == null), true); - + cert = Mockito.mock(X509Certificate.class); Mockito.when(cert.getEncoded()).thenReturn(new byte[128]); - + Result<List<CertDAO.Data>> rs = new Result<List<CertDAO.Data>>(null, 1, "test", new Object[0]); - + CachedCertDAO cacheDao = Mockito.mock(CachedCertDAO.class); Mockito.when(cacheDao.read(Mockito.any(AuthzTrans.class),Mockito.any(Object[].class))).thenReturn(rs); DirectCertIdentity.set(cacheDao); p = directCertIdentity.identity(req, cert, _certBytes); - + _certBytes = new byte[128]; List<CertDAO.Data> dataAL = new ArrayList<>(); CertDAO.Data data = new CertDAO.Data(); @@ -86,7 +86,7 @@ public class JU_DirectCertIdentity { DirectCertIdentity.set(cacheDao); p = directCertIdentity.identity(req, cert, _certBytes); assertTrue(p.toString().contains("X509 Authentication for null")); - + cert = null; directCertIdentity.identity(req, cert, _certBytes); } catch (CertificateException e) { diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectLocatorCreator.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectLocatorCreator.java index 7ac4ed1b..d745b145 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectLocatorCreator.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectLocatorCreator.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. @@ -35,23 +35,23 @@ import org.onap.aaf.cadi.LocatorException; import org.onap.aaf.cadi.PropAccess; import org.onap.aaf.cadi.config.Config; -@RunWith(MockitoJUnitRunner.class) +@RunWith(MockitoJUnitRunner.class) public class JU_DirectLocatorCreator { @Mock AuthzEnv env; - + @Mock LocateDAO locateDAO; - + @Mock PropAccess access; - + @Before public void setUp() throws Exception { initMocks(this); } - + @Test public void testCreate() { Mockito.doReturn(access).when(env).access(); diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectRegistrar.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectRegistrar.java index cf1bd9d4..833b8970 100644 --- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectRegistrar.java +++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectRegistrar.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. @@ -74,12 +74,12 @@ public class JU_DirectRegistrar { Mockito.doReturn(rs).when(ldao).update(Mockito.any(), Mockito.any()); registrarObj = new DirectRegistrar(access, ldao, 9080); - + org.onap.aaf.auth.layer.Result<Void> retVal1 = new Result<Void>(null, 0, "test", new Object[0]); Mockito.doReturn(trans).when(env).newTransNoAvg(); // Mockito.doReturn(retVal1).when(ldao).update(trans,locate); registrarObj.update(env); - + rs = new org.onap.aaf.auth.layer.Result<Void>(null, 1, "test", new Object[0]); Mockito.doReturn(rs).when(ldao).update(Mockito.any(), Mockito.any()); registrarObj = new DirectRegistrar(access, ldao, 9080); @@ -100,7 +100,7 @@ public class JU_DirectRegistrar { Mockito.doReturn("20").when(access).getProperty(Config.AAF_LOCATOR_CONTAINER, ""); Mockito.doReturn("20,test,test").when(access).getProperty(Config.AAF_LOCATOR_ENTRIES, ""); registrarObj = new DirectRegistrar(access, ldao, 9080); - + org.onap.aaf.auth.layer.Result<Void> rs = new org.onap.aaf.auth.layer.Result<Void>(null, 1, "test", new Object[0]); Mockito.doReturn(rs).when(ldao).delete(Mockito.any(), Mockito.any(), Mockito.anyBoolean()); } catch (CadiException e) { |