summaryrefslogtreecommitdiffstats
path: root/auth
diff options
context:
space:
mode:
authorSai Gandham <sg481n@att.com>2018-12-30 23:17:59 -0600
committerSai Gandham <sg481n@att.com>2018-12-30 23:18:15 -0600
commit850788c053064409ad07b2b313396c674b57ac4b (patch)
tree98fab74319b35d8b661ee2171de01924f61e81f7 /auth
parent52c89c9940544c1b2db1dd1e0ce9b22e2fcdca42 (diff)
Add more junits in auth cass & misc env
Issue-ID: AAF-111 Change-Id: Iac8ff0043b89b00f2f6f9f45ccfa6253552d445d Signed-off-by: Sai Gandham <sg481n@att.com>
Diffstat (limited to 'auth')
-rw-r--r--auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Question.java5
-rw-r--r--auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CachedPermDAOTest.java166
-rw-r--r--auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CachedRoleDAO.java174
-rw-r--r--auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CachedUserRoleDAO.java180
-rw-r--r--auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CassExecutor.java154
-rw-r--r--auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_PermLookup.java383
-rw-r--r--auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedPermDAOTest.java78
-rw-r--r--auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFLocator.java152
-rw-r--r--auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFUserPass.java223
-rw-r--r--auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectLocatorCreateor.java86
-rw-r--r--auth/auth-core/src/main/java/org/onap/aaf/auth/layer/Result.java4
11 files changed, 1350 insertions, 255 deletions
diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Question.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Question.java
index 4a307693..a513da0a 100644
--- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Question.java
+++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Question.java
@@ -132,9 +132,9 @@ public class Question {
public final HistoryDAO historyDAO;
public final CachedNSDAO nsDAO;
- public final CachedRoleDAO roleDAO;
+ public CachedRoleDAO roleDAO;
public final CachedPermDAO permDAO;
- public final CachedUserRoleDAO userRoleDAO;
+ public CachedUserRoleDAO userRoleDAO;
public final CachedCredDAO credDAO;
public final CachedCertDAO certDAO;
public final DelegateDAO delegateDAO;
@@ -145,6 +145,7 @@ public class Question {
public Question(AuthzTrans trans, Cluster cluster, String keyspace, boolean startClean) throws APIException, IOException {
PERMS = trans.slot("USER_PERMS");
+ System.out.println(trans.init());
trans.init().log("Instantiating DAOs");
long expiresIn = Long.parseLong(trans.getProperty(Config.AAF_USER_EXPIRES, Config.AAF_USER_EXPIRES_DEF));
historyDAO = new HistoryDAO(trans, cluster, keyspace);
diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CachedPermDAOTest.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CachedPermDAOTest.java
new file mode 100644
index 00000000..66c32a7b
--- /dev/null
+++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CachedPermDAOTest.java
@@ -0,0 +1,166 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===========================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END====================================================
+ *
+ */
+package org.onap.aaf.auth.dao.cached;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.onap.aaf.auth.dao.CIDAO;
+import org.onap.aaf.auth.dao.cass.PermDAO;
+import org.onap.aaf.auth.dao.cass.PermDAO.Data;
+import org.onap.aaf.auth.dao.cass.RoleDAO;
+import org.onap.aaf.auth.dao.cass.Status;
+import org.onap.aaf.auth.env.AuthzTrans;
+import org.onap.aaf.auth.env.AuthzTransImpl;
+import org.onap.aaf.auth.layer.Result;
+import org.onap.aaf.misc.env.LogTarget;
+
+public class JU_CachedPermDAOTest {
+
+ @Mock
+ private CIDAO<AuthzTrans> info;
+ @Mock
+ private PermDAO dao;
+
+ @Mock
+ RoleDAO.Data role;
+
+ @Mock
+ private PermDAO.Data perm;
+
+ @Mock
+ private AuthzTrans trans;
+ @Mock
+ private Result<List<PermDAO.Data>> value;
+
+ @Before
+ public void setUp() throws Exception {
+ initMocks(this);
+
+ 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;
+ }
+ });
+ }
+
+ @Test
+ public void testReadNS() {
+ when(value.isOKhasData()).thenReturn(true);
+ when(value.isOK()).thenReturn(false);
+ CachedPermDAO ccDao = new CachedPermDAO(dao, info, 100l);
+
+ Result<List<Data>> result = ccDao.readNS(trans, "ns");
+
+ assertEquals(result, value);
+
+ when(value.isOKhasData()).thenReturn(false);
+
+ result = ccDao.readNS(trans, "ns");
+
+ assertEquals(result.status, Status.ERR_PermissionNotFound);
+
+ ccDao.readChildren(trans, "ns", "type");
+
+ verify(dao).readChildren(trans, "ns", "type");
+ }
+
+ @Test
+ public void testReadByTypeSuccess() {
+ CachedPermDAO roleDaoObj =new CachedPermDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);//
+ Result<List<Data>> retVal1 = new Result<List<Data>>(null,1,"test4",new String[0]);
+ Mockito.doReturn(retVal1).when(dao).readByType(trans, "test4","");
+ Result<List<Data>> retVal = roleDaoObj.readByType(trans, "test4","");
+// 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);//
+ Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"test3123",new String[0]);
+ Mockito.doReturn(retVal1).when(dao).readByType(trans, "test3","");
+ Result<List<Data>> retVal = roleDaoObj.readByType(trans, "test3","");
+ //System.out.println(retVal.status);
+ assertEquals("23", Integer.toString(retVal.status));
+ }
+
+ @Test
+ public void testAddRole() {
+ CachedPermDAO roleDaoObj =new CachedPermDAO(dao,info, 10);
+ Result<Void> retVal1 = new Result<Void>(null,0,"testAddRole",new String[0]);
+ Mockito.doReturn(retVal1).when(info).touch(trans, null,null);
+ Mockito.doReturn(retVal1).when(dao).addRole(trans, perm,null);
+ Result<Void> retVal = roleDaoObj.addRole(trans, perm, role);
+// System.out.println("ret value is::"+retVal);
+ assertEquals("testAddRole", retVal.toString());
+ }
+
+ @Test
+ public void testDelRole() {
+ CachedPermDAO roleDaoObj =new CachedPermDAO(dao,info, 10);
+ Result<Void> retVal1 = new Result<Void>(null,0,"testAddRole",new String[0]);
+ Mockito.doReturn(retVal1).when(info).touch(trans, null,null);
+ Mockito.doReturn(retVal1).when(dao).delRole(trans, perm,null);
+ Result<Void> retVal = roleDaoObj.delRole(trans, perm, role);
+// System.out.println(retVal);
+ assertEquals("testAddRole", retVal.toString());
+ }
+
+ @Test
+ public void testAddDescription() {
+ CachedPermDAO roleDaoObj =new CachedPermDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);//
+ Result<Void> retVal1 = new Result<Void>(null,0,"test1",new String[0]);
+ Mockito.doReturn(retVal1).when(dao).addDescription(trans, "","","","","");
+ Result<Void> retVal = roleDaoObj.addDescription(trans, "", "","","","");
+ //System.out.println(retVal.status);
+ assertEquals("0", Integer.toString(retVal.status));
+ }
+
+}
diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CachedRoleDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CachedRoleDAO.java
deleted file mode 100644
index 2e27bfd9..00000000
--- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CachedRoleDAO.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-package org.onap.aaf.auth.dao.cached;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.when;
-import static org.mockito.MockitoAnnotations.initMocks;
-
-import java.util.List;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.onap.aaf.auth.dao.CIDAO;
-import org.onap.aaf.auth.dao.cass.PermDAO;
-import org.onap.aaf.auth.dao.cass.RoleDAO;
-import org.onap.aaf.auth.dao.cass.RoleDAO.Data;
-import org.onap.aaf.auth.env.AuthzTrans;
-import org.onap.aaf.auth.env.AuthzTransImpl;
-import org.onap.aaf.auth.layer.Result;
-import org.onap.aaf.misc.env.LogTarget;
-
-
-@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);//
- Result<List<Data>> retVal1 = new Result<List<Data>>(null,1,"test4",new String[0]);
- Mockito.doReturn(retVal1).when(dao).readName(trans, "test4");
-// Mockito.when(roleDaoObj.get(Mockito.any(), Mockito.any(String.class), Mockito.any())).thenReturn(retVal1);
- Result<List<Data>> retVal = roleDaoObj.readName(trans, "test4");
-// 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);//
- Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"test3123",new String[0]);
- Mockito.doReturn(retVal1).when(dao).readName(trans, "test3");
-// Mockito.when(roleDaoObj.get(Mockito.any(), Mockito.any(String.class), Mockito.any())).thenReturn(retVal1);
- Result<List<Data>> retVal = roleDaoObj.readName(trans, "test3");
-// System.out.println(retVal.status);
- assertEquals("22", Integer.toString(retVal.status));
- }
- @Test
- public void testReadNSSuccess() {
- CachedRoleDAO roleDaoObj =new CachedRoleDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);//
- Result<List<Data>> retVal1 = new Result<List<Data>>(null,1,"test",new String[0]);
- Mockito.doReturn(retVal1).when(dao).readNS(trans, "");
-// Mockito.when(roleDaoObj.get(Mockito.any(), Mockito.any(String.class), Mockito.any())).thenReturn(retVal1);
- 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);//
- Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"test1",new String[0]);
- Mockito.doReturn(retVal1).when(dao).readNS(trans, "");
-// Mockito.when(roleDaoObj.get(Mockito.any(), Mockito.any(String.class), Mockito.any())).thenReturn(retVal1);
- Result<List<Data>> retVal = roleDaoObj.readNS(trans, "");
-// 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);//
- Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"test1",new String[0]);
- Mockito.doReturn(retVal1).when(dao).readChildren(trans, "","");
- Result<List<Data>> retVal = roleDaoObj.readChildren(trans, "", "");
- //System.out.println(retVal.status);
- assertEquals("0", Integer.toString(retVal.status));
- }
-
- @Test
- public void testAddPerm() {
- CachedRoleDAO roleDaoObj =new CachedRoleDAO(dao,info, 10);
- Result<Void> retVal1 = new Result<Void>(null,0,"testAddPerm",new String[0]);
- Mockito.doReturn(retVal1).when(info).touch(trans, null,null);
- Mockito.doReturn(retVal1).when(dao).addPerm(trans, data,permData);
- Result<Void> retVal = roleDaoObj.addPerm(trans, data, permData);
- assertEquals("testAddPerm", retVal.toString());
- }
-
- @Test
- public void testDelPerm() {
- CachedRoleDAO roleDaoObj =new CachedRoleDAO(dao,info, 10);
- Result<Void> retVal1 = new Result<Void>(null,0,"testAddPerm",new String[0]);
- Mockito.doReturn(retVal1).when(info).touch(trans, null,null);
- Mockito.doReturn(retVal1).when(dao).delPerm(trans, data,permData);
- Result<Void> retVal = roleDaoObj.delPerm(trans, data, permData);
- System.out.println(retVal);
- assertEquals("testAddPerm", retVal.toString());
- }
-
- @Test
- public void testAddDescription() {
- CachedRoleDAO roleDaoObj =new CachedRoleDAO(dao,info, 10);//Mockito.mock(CachedRoleDAO.class);//
- Result<Void> retVal1 = new Result<Void>(null,0,"test1",new String[0]);
- Mockito.doReturn(retVal1).when(dao).addDescription(trans, "","","");
- Result<Void> retVal = roleDaoObj.addDescription(trans, "", "","");
- //System.out.println(retVal.status);
- assertEquals("0", Integer.toString(retVal.status));
- }
-} \ No newline at end of file
diff --git a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CachedUserRoleDAO.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CachedUserRoleDAO.java
new file mode 100644
index 00000000..8dcf8e44
--- /dev/null
+++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CachedUserRoleDAO.java
@@ -0,0 +1,180 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===========================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END====================================================
+ *
+ */
+package org.onap.aaf.auth.dao.cached;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.onap.aaf.auth.dao.CIDAO;
+import org.onap.aaf.auth.dao.cass.PermDAO;
+import org.onap.aaf.auth.dao.cass.RoleDAO;
+import org.onap.aaf.auth.dao.cass.UserRoleDAO;
+import org.onap.aaf.auth.dao.cass.UserRoleDAO.Data;
+import org.onap.aaf.auth.env.AuthzEnv;
+import org.onap.aaf.auth.env.AuthzTrans;
+import org.onap.aaf.auth.env.AuthzTransImpl;
+import org.onap.aaf.auth.layer.Result;
+import org.onap.aaf.cadi.principal.TaggedPrincipal;
+import org.onap.aaf.misc.env.LogTarget;
+import org.onap.aaf.misc.env.Slot;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+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(); }
+ public TaggedPrincipalStub(final TagLookup tl) { super(tl); }
+ @Override public String getName() { return name; }
+ @Override public String tag() { return null; }
+ }
+
+ @Test
+ public void testReadName() {
+ CachedUserRoleDAO roleDaoObj =new CachedUserRoleDAO(dao,info, 10L);
+ Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"test4",new String[0]);
+ Mockito.doReturn(retVal1).when(dao).readByUser(trans, "test4");
+// Mockito.when(roleDaoObj.get(Mockito.any(), Mockito.any(String.class), Mockito.any())).thenReturn(retVal1);
+ Result<List<Data>> retVal = roleDaoObj.readByUser(trans, "test4");
+ //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);
+ Result<List<Data>> retVal1 = new Result<List<Data>>(null,1,"TaggedPrincipalStub",new String[0]);
+ AuthzEnv env = Mockito.mock(AuthzEnv.class);
+ AuthzTransImpl transTemp = new AuthzTransImpl(env) {
+ @Override
+ public<T> T get(Slot slot, T deflt) {
+ Object o=null;
+ return (T)o;
+ }
+
+ };
+ transTemp.setUser(new TaggedPrincipalStub());
+ Mockito.doReturn(retVal1).when(info).touch(trans, null,null);
+ Mockito.doReturn(retVal1).when(dao).readByUser(transTemp, "TaggedPrincipalStub");
+ roleDaoObj.invalidate("TaggedPrincipalStub");
+ Result<List<Data>> retVal = roleDaoObj.readByUser(transTemp, "TaggedPrincipalStub");
+// 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);//
+ Result<List<Data>> retVal1 = new Result<List<Data>>(null,1,"test",new String[0]);
+ Mockito.doReturn(retVal1).when(dao).readByRole(trans, "");
+ roleDaoObj.invalidate("");
+ 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);//
+ Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"test1",new String[0]);
+ Mockito.doReturn(retVal1).when(dao).readByRole(trans, "");
+ roleDaoObj.invalidate("");
+ Result<List<Data>> retVal = roleDaoObj.readByRole(trans, "");
+ //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);//
+ Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"TaggedPrincipalStub",new String[0]);
+ AuthzEnv env = Mockito.mock(AuthzEnv.class);
+ AuthzTransImpl transTemp = new AuthzTransImpl(env) {
+ @Override
+ public<T> T get(Slot slot, T deflt) {
+ Object o=null;
+ return (T)o;
+ }
+
+ };
+ transTemp.setUser(new TaggedPrincipalStub());
+ Mockito.doReturn(retVal1).when(info).touch(trans, null,null);
+ Mockito.doReturn(retVal1).when(dao).readByUserRole(transTemp, "","");
+ Mockito.doReturn(retVal1).when(dao).readByUser(transTemp, "TaggedPrincipalStub");
+ Result<List<Data>> retVal = roleDaoObj.readUserInRole(transTemp, "TaggedPrincipalStub","");
+ //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/JU_CassExecutor.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CassExecutor.java
new file mode 100644
index 00000000..5dd33c7e
--- /dev/null
+++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_CassExecutor.java
@@ -0,0 +1,154 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===========================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END====================================================
+ *
+ */
+package org.onap.aaf.auth.dao.hl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import java.util.Properties;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.stubbing.Answer;
+import org.onap.aaf.auth.common.Define;
+import org.onap.aaf.auth.dao.cass.NsSplit;
+import org.onap.aaf.auth.dao.cass.UserRoleDAO.Data;
+import org.onap.aaf.auth.env.AuthzTransImpl;
+import org.onap.aaf.auth.layer.Result;
+import org.onap.aaf.cadi.Access;
+import org.onap.aaf.cadi.CadiException;
+
+
+@RunWith(MockitoJUnitRunner.class)
+public class JU_CassExecutor {
+
+
+
+ @Mock
+ AuthzTransImpl trans;
+
+ @Mock
+ Question q;
+
+ @Mock
+ Access access;
+
+ Function f;
+
+ @Before
+ public void setUp() throws Exception {
+ initMocks(this);
+ try {
+ Mockito.doReturn("0.0").when(access).getProperty("aaf_root_ns","org.osaaf.aaf");
+ Mockito.doReturn(new Properties()).when(access).getProperties();
+ Define.set(access);
+ } catch (CadiException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ 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,"",new String[0]);
+ 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,"",new String[0]);
+ Mockito.doReturn(retVal1).when(q).validNSOfDomain(trans, null);
+
+ String retVal="";
+ try {
+ retVal = cassExecutorObj.namespace();
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ assertEquals("33", e.getMessage());
+ }
+ System.out.println(retVal);
+// assertFalse(retVal);
+ }
+
+ @Test
+ public void testId() {
+ Mockito.doReturn("").when(trans).user();
+ CassExecutor cassExecutorObj =new CassExecutor(trans, f);
+ String retVal = cassExecutorObj.id();
+ assertEquals("", retVal);
+ }
+
+ @Test
+ public void testNamespaceSuccess() {
+ Mockito.doAnswer(new Answer() {
+ private int count = 0;
+
+ public Object answer(InvocationOnMock invocation) {
+ if (count++ == 1)
+ return "test@test.com";
+
+ return null;
+ }
+ }).when(trans).user();
+ f =new Function(trans, q);
+ CassExecutor cassExecutorObj =new CassExecutor(trans, f);
+ Result<Data> retVal1 = new Result<Data>(null,0,"",new String[0]);
+ Mockito.doReturn(retVal1).when(q).validNSOfDomain(trans, null);
+
+
+ String retVal="";
+ try {
+ retVal = cassExecutorObj.namespace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.out.println(e.getMessage());
+// assertNull( e.getMessage());
+ }
+// 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/JU_PermLookup.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_PermLookup.java
new file mode 100644
index 00000000..e63d4b52
--- /dev/null
+++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/JU_PermLookup.java
@@ -0,0 +1,383 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===========================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END====================================================
+ *
+ */
+package org.onap.aaf.auth.dao.hl;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.aaf.auth.common.Define;
+import org.onap.aaf.auth.dao.cached.CachedRoleDAO;
+import org.onap.aaf.auth.dao.cached.CachedUserRoleDAO;
+import org.onap.aaf.auth.dao.cass.PermDAO.Data;
+import org.onap.aaf.auth.dao.cass.RoleDAO;
+import org.onap.aaf.auth.dao.cass.UserRoleDAO;
+import org.onap.aaf.auth.env.AuthzTrans;
+import org.onap.aaf.auth.layer.Result;
+import org.onap.aaf.cadi.Access;
+import org.onap.aaf.cadi.CadiException;
+import org.onap.aaf.misc.env.LogTarget;
+
+
+@RunWith(MockitoJUnitRunner.class)
+public class JU_PermLookup {
+
+
+
+ @Mock
+ AuthzTrans trans;
+
+ @Mock
+ Question q;
+
+ @Mock
+ Access access;
+
+ Function f;
+
+ @Before
+ public void setUp() throws Exception {
+ initMocks(this);
+ 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;
+ }
+ });
+ } catch (CadiException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ 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() {
+ q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class);
+ 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(q.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() {
+ q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class);
+ 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(q.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() {
+ q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class);
+ 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);
+ c.add(Calendar.DATE, 1);
+ dataObj.expires = c.getTime();
+
+ retVal1.value.add(dataObj);
+ Mockito.doReturn(true).when(retVal1).isOKhasData();
+ Mockito.doReturn(retVal1).when(q.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();
+
+ //System.out.println(userRoles1.status);
+ assertEquals(0, userRoles1.status);
+ }
+
+ @Test
+ public void testGetRole() {
+ q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class);
+ 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(q.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() {
+ q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class);
+ q.roleDAO = Mockito.mock(CachedRoleDAO.class);
+ 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();
+ Mockito.doReturn(retVal1).when(q.userRoleDAO).readByUser(trans,"");
+ Mockito.doReturn(retVal1).when(q.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() {
+ q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class);
+ q.roleDAO = Mockito.mock(CachedRoleDAO.class);
+ 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();
+ Mockito.doReturn(retVal1).when(q.userRoleDAO).readByUser(trans,"");
+ Mockito.doReturn(retVal1).when(q.roleDAO).read(trans,"","");
+ 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);
+ }
+ @Test
+ public void testGetPerms() {
+ q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class);
+ Result<List<UserRoleDAO.Data>> retVal1 = Mockito.mock(Result.class);
+ retVal1.value = new ArrayList<UserRoleDAO.Data>();
+ Mockito.doReturn(false).when(retVal1).isOKhasData();
+ Mockito.doReturn(true).when(retVal1).isOK();
+ Mockito.doReturn(retVal1).when(q.userRoleDAO).readByUser(trans,"");
+ PermLookup cassExecutorObj =PermLookup.get(trans, q,"");
+ Result<Set<String>> userRoles = cassExecutorObj.getPermNames();
+ userRoles = cassExecutorObj.getPermNames();
+
+ //System.out.println(""+userRoles.status);
+ assertEquals(0,userRoles.status);
+ }
+ @Test
+ public void testGetPermsRrldOk() {
+ q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class);
+ 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(q.userRoleDAO).readByUser(trans,"");
+ PermLookup cassExecutorObj =PermLookup.get(trans, q,"");
+ Result<Set<String>> userRoles = cassExecutorObj.getPermNames();
+
+ //System.out.println(""+userRoles.status);
+ assertEquals(4,userRoles.status);
+ }
+
+
+ @Test
+ public void testGetPerm() {
+ q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class);
+ q.roleDAO = Mockito.mock(CachedRoleDAO.class);
+ 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);
+ 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.add(Calendar.DATE, 1);
+ dataObj1.ns = "test";
+ dataObj1.perms = permSet;
+
+ retVal1.value.add(dataObj);
+ retVal2.value.add(dataObj1);
+ Mockito.doReturn(true).when(retVal1).isOKhasData();
+ Mockito.doReturn(true).when(retVal1).isOK();
+ Mockito.doReturn(true).when(retVal2).isOK();
+ Mockito.doReturn(retVal1).when(q.userRoleDAO).readByUser(trans,"");
+ Mockito.doReturn(retVal2).when(q.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);
+ }
+
+ @Test
+ public void testGetPermFalse() {
+ q.userRoleDAO = Mockito.mock(CachedUserRoleDAO.class);
+ q.roleDAO = Mockito.mock(CachedRoleDAO.class);
+ 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);
+ 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.add(Calendar.DATE, 1);
+ dataObj1.ns = "test";
+ dataObj1.perms = permSet;
+
+ retVal1.value.add(dataObj);
+ retVal2.value.add(dataObj1);
+ Mockito.doReturn(true).when(retVal1).isOKhasData();
+ Mockito.doReturn(true).when(retVal1).isOK();
+ Mockito.doReturn(true).when(retVal2).isOK();
+ Mockito.doReturn(retVal1).when(q.userRoleDAO).readByUser(trans,"");
+ Mockito.doReturn(retVal2).when(q.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/dao/cached/JU_CachedPermDAOTest.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedPermDAOTest.java
deleted file mode 100644
index 972e366c..00000000
--- a/auth/auth-cass/src/test/java/org/onap/aaf/auth/dao/cached/JU_CachedPermDAOTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * ============LICENSE_START====================================================
- * org.onap.aaf
- * ===========================================================================
- * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
- * ===========================================================================
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END====================================================
- *
- */
-package org.onap.aaf.auth.dao.cached;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.mockito.MockitoAnnotations.initMocks;
-
-import java.util.List;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.onap.aaf.auth.dao.CIDAO;
-import org.onap.aaf.auth.dao.cass.PermDAO;
-import org.onap.aaf.auth.dao.cass.PermDAO.Data;
-import org.onap.aaf.auth.dao.cass.Status;
-import org.onap.aaf.auth.env.AuthzTrans;
-import org.onap.aaf.auth.layer.Result;
-
-public class JU_CachedPermDAOTest {
-
- @Mock
- private CIDAO<AuthzTrans> info;
- @Mock
- private PermDAO dao;
- private AuthzTrans trans;
- @Mock
- private Result<List<PermDAO.Data>> value;
-
- @Before
- public void setUp() throws Exception {
- initMocks(this);
-
- when(dao.readNS(trans, "ns")).thenReturn(value);
- }
-
- @Test
- public void testReadNS() {
- when(value.isOKhasData()).thenReturn(true);
- when(value.isOK()).thenReturn(false);
- CachedPermDAO ccDao = new CachedPermDAO(dao, info, 100l);
-
- Result<List<Data>> result = ccDao.readNS(trans, "ns");
-
- assertEquals(result, value);
-
- when(value.isOKhasData()).thenReturn(false);
-
- result = ccDao.readNS(trans, "ns");
-
- assertEquals(result.status, Status.ERR_PermissionNotFound);
-
- ccDao.readChildren(trans, "ns", "type");
-
- verify(dao).readChildren(trans, "ns", "type");
- }
-
-}
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
new file mode 100644
index 00000000..cf850587
--- /dev/null
+++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFLocator.java
@@ -0,0 +1,152 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===========================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END====================================================
+ *
+ */
+package org.onap.aaf.auth.direct.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.aaf.auth.dao.cass.LocateDAO;
+import org.onap.aaf.auth.dao.cass.LocateDAO.Data;
+import org.onap.aaf.auth.direct.DirectAAFLocator;
+import org.onap.aaf.auth.env.AuthzEnv;
+import org.onap.aaf.auth.env.AuthzTrans;
+import org.onap.aaf.auth.layer.Result;
+import org.onap.aaf.cadi.Access;
+import org.onap.aaf.cadi.LocatorException;
+import org.onap.aaf.cadi.PropAccess;
+import org.onap.aaf.cadi.config.Config;
+
+
+@RunWith(MockitoJUnitRunner.class)
+public class JU_DirectAAFLocator {
+
+ @Mock
+ LocateDAO ldao;
+
+ @Mock
+ AuthzEnv env;
+
+ @Mock
+ AuthzTrans trans;
+
+ @Mock
+ Access access;
+
+ @Before
+ public void setUp() throws Exception {
+ initMocks(this);
+ }
+
+ @Test
+ public void testConstructorExcpetion() {
+
+ PropAccess access = Mockito.mock(PropAccess.class);
+ Mockito.doReturn(access).when(env).access();
+ Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null);
+ Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null);
+ try {
+ DirectAAFLocator aafLocatorObj=new DirectAAFLocator(env, ldao,"test","test");
+ } catch (LocatorException e) {
+// System.out.println(e.getMessage());
+ assertEquals("Invalid Version String: test", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testConstructorUriExcpetion() {
+
+ PropAccess access = Mockito.mock(PropAccess.class);
+ Mockito.doReturn(access).when(env).access();
+ Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null);
+ Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null);
+ try {
+ DirectAAFLocator aafLocatorObj=new DirectAAFLocator(env, ldao," test","3.2");
+ } catch (LocatorException e) {
+// System.out.println(e.getMessage());
+ assertTrue(e.getMessage().contains("Illegal character in path at index"));
+ }
+ }
+ @Test
+ public void testRefresh() {
+
+ DirectAAFLocator aafLocatorObj=null;
+ PropAccess access = Mockito.mock(PropAccess.class);
+ Mockito.doReturn(access).when(env).access();
+ Mockito.doReturn(trans).when(env).newTransNoAvg();
+ Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null);
+ Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null);
+ try {
+ aafLocatorObj = new DirectAAFLocator(env, ldao,"test","30.20.30.30");
+ } catch (LocatorException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ Result<List<Data>> retVal1 = new Result<List<Data>>(null,0,"",new String[0]);
+
+ Data data= new Data();
+ data.major=30;
+ data.minor=30;
+ data.patch=30;
+ 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();
+ Mockito.doReturn(trans).when(env).newTransNoAvg();
+ Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null);
+ Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null);
+ try {
+ aafLocatorObj = new DirectAAFLocator(env, ldao,"test","30.20.30.30");
+ } catch (LocatorException e) {
+ // TODO Auto-generated catch block
+ 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_DirectAAFUserPass.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFUserPass.java
new file mode 100644
index 00000000..ca0a8917
--- /dev/null
+++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectAAFUserPass.java
@@ -0,0 +1,223 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===========================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END====================================================
+ *
+ */
+package org.onap.aaf.auth.direct.test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import java.util.Date;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.aaf.auth.dao.DAOException;
+import org.onap.aaf.auth.dao.hl.Question;
+import org.onap.aaf.auth.direct.DirectAAFUserPass;
+import org.onap.aaf.auth.env.AuthzEnv;
+import org.onap.aaf.auth.env.AuthzTrans;
+import org.onap.aaf.auth.layer.Result;
+import org.onap.aaf.misc.env.LogTarget;
+
+
+@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]);
+ Mockito.doReturn(trans).when(env).newTransNoAvg();
+ try {
+ Mockito.doReturn(retVal1).when(question).doesUserCredMatch(trans, null, null);
+ } catch (DAOException e) {
+ e.printStackTrace();
+ }
+ boolean retVal = aafLocatorObj.validate(null, null, null, null);
+
+ assertTrue(retVal);
+ }
+
+ @Test
+ public void testUserPassStateisRequest() {
+
+ DirectAAFUserPass aafLocatorObj=null;
+ aafLocatorObj = new DirectAAFUserPass(env, question);
+ Result<Date> retVal1 = new Result<Date>(null,1,"",new String[0]);
+ Mockito.doReturn(trans).when(env).newTransNoAvg();
+ try {
+ Mockito.doReturn(retVal1).when(question).doesUserCredMatch(trans, null, null);
+ } catch (DAOException e) {
+ 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]);
+ Mockito.doReturn(trans).when(env).newTransNoAvg();
+ try {
+ Mockito.doReturn(retVal1).when(question).doesUserCredMatch(trans, null, null);
+ } catch (DAOException e) {
+ 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]);
+ Mockito.doReturn(trans).when(env).newTransNoAvg();
+ try {
+ Mockito.doReturn(retVal1).when(question).doesUserCredMatch(trans, null, null);
+ } catch (DAOException e) {
+ 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]);
+ Mockito.doReturn("test").when(trans).ip();
+ Mockito.doReturn(trans).when(env).newTransNoAvg();
+ try {
+ Mockito.doReturn(retVal1).when(question).doesUserCredMatch(trans, null, null);
+ } catch (DAOException e) {
+ 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]);
+ Mockito.doReturn(trans).when(env).newTransNoAvg();
+ try {
+ Mockito.doThrow(DAOException.class).when(question).doesUserCredMatch(trans, null, null);
+ } catch (DAOException e) {
+ // TODO Auto-generated catch block
+// 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_DirectLocatorCreateor.java b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectLocatorCreateor.java
new file mode 100644
index 00000000..d026500c
--- /dev/null
+++ b/auth/auth-cass/src/test/java/org/onap/aaf/auth/direct/test/JU_DirectLocatorCreateor.java
@@ -0,0 +1,86 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===========================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END====================================================
+ *
+ */
+package org.onap.aaf.auth.direct.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.aaf.auth.dao.cass.LocateDAO;
+import org.onap.aaf.auth.direct.DirectLocatorCreator;
+import org.onap.aaf.auth.env.AuthzEnv;
+import org.onap.aaf.cadi.LocatorException;
+import org.onap.aaf.cadi.PropAccess;
+import org.onap.aaf.cadi.config.Config;
+
+
+@RunWith(MockitoJUnitRunner.class)
+public class JU_DirectLocatorCreateor {
+
+ @Mock
+ LocateDAO ldao;
+
+ @Mock
+ AuthzEnv env;
+
+ @Before
+ public void setUp() throws Exception {
+ initMocks(this);
+ }
+
+ @Test
+ public void testCreate() {
+ PropAccess access = Mockito.mock(PropAccess.class);
+ Mockito.doReturn(access).when(env).access();
+ Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null);
+ Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null);
+ DirectLocatorCreator aafLocatorObj=new DirectLocatorCreator(env, ldao);
+ try {
+ aafLocatorObj.setSelf("test", 9080);
+ aafLocatorObj.create("test","30.20.30.30");
+ } catch (LocatorException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testCreateHostnameNull() {
+ PropAccess access = Mockito.mock(PropAccess.class);
+ Mockito.doReturn(access).when(env).access();
+ Mockito.doReturn("20").when(access).getProperty(Config.CADI_LATITUDE,null);
+ Mockito.doReturn("20").when(access).getProperty(Config.CADI_LONGITUDE,null);
+ DirectLocatorCreator aafLocatorObj=new DirectLocatorCreator(env, ldao);
+ try {
+ aafLocatorObj.create("test","30.20.30.30");
+ } catch (LocatorException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+
+} \ No newline at end of file
diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/layer/Result.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/layer/Result.java
index a3abb2bb..3e68e3ab 100644
--- a/auth/auth-core/src/main/java/org/onap/aaf/auth/layer/Result.java
+++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/layer/Result.java
@@ -48,7 +48,7 @@ public class Result<RV> {
ERR_Backend = 9,
ERR_General = 20;
- public final RV value;
+ public RV value;
public final int status;
public final String details;
public final String[] variables;
@@ -275,6 +275,8 @@ public class Result<RV> {
* @return
*/
public boolean isOKhasData() {
+ System.out.println("specialCondition:"+specialCondition);
+ System.out.println("specialCondition:"+(specialCondition & EMPTY_LIST));
return status == OK && (specialCondition & EMPTY_LIST) != EMPTY_LIST;
}