diff options
author | gabe.maurer <gabe.maurer@att.com> | 2018-04-27 13:22:19 -0500 |
---|---|---|
committer | gabe.maurer <gabe.maurer@att.com> | 2018-04-27 13:23:35 -0500 |
commit | e4c000599ff3185f7f34e7c168568e1d9ed41d65 (patch) | |
tree | 01ed6c6fc86452b3cf7a7d86d13f48a36d0c8123 /auth/auth-cmd/src/test | |
parent | 6913298a6dcadd455314eb96fc940128db49965d (diff) |
Increased coverage for auth cmd List
Issue-ID: AAF-237
Change-Id: Ia31cb8276d1101ebbdfe98a3a3becac794ef6dea
Signed-off-by: gabe.maurer <gabe.maurer@att.com>
Diffstat (limited to 'auth/auth-cmd/src/test')
-rw-r--r-- | auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/ns/JU_List.java | 78 | ||||
-rw-r--r-- | auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/role/JU_List.java | 39 |
2 files changed, 106 insertions, 11 deletions
diff --git a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/ns/JU_List.java b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/ns/JU_List.java index f62a8182..cf8539ab 100644 --- a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/ns/JU_List.java +++ b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/ns/JU_List.java @@ -24,6 +24,7 @@ import static org.junit.Assert.*; import java.io.Writer; import java.net.URI; +import java.util.ArrayList; import org.onap.aaf.auth.cmd.ns.List; import org.onap.aaf.auth.cmd.ns.NS; @@ -38,6 +39,9 @@ import org.onap.aaf.cadi.http.HMangr; import org.onap.aaf.misc.env.APIException; import aaf.v2_0.Nss; +import aaf.v2_0.Roles; +import aaf.v2_0.Users.User; +import junit.framework.Assert; import org.onap.aaf.auth.cmd.AAFcli; import org.junit.After; @@ -52,6 +56,45 @@ import org.junit.Test; public class JU_List { List list; + AAFcli aafcli; + User user; + + private class NssStub extends Nss { + public void addNs(Nss.Ns ns) { + if (this.ns == null) { + this.ns = new ArrayList<Nss.Ns>(); + } + this.ns.add(ns); + } + + private class NsStub extends Ns{ + public void addAttrib(Nss.Ns.Attrib attrib) { + if ( this.attrib == null) { + this.attrib = new ArrayList<Nss.Ns.Attrib>(); + } + this.attrib.add(attrib); + } + + public void addResponsible(String str) { + if (this.responsible == null) { + this.responsible = new ArrayList<String>(); + } + this.responsible.add(str); + } + + public void addAdmin(String str) { + if (this.admin == null) { + this.admin = new ArrayList<String>(); + } + this.admin.add(str); + } + } + + + + + } + @Before public void setUp() throws APIException, LocatorException { @@ -60,23 +103,42 @@ public class JU_List { Writer wtr = mock(Writer.class); Locator loc = mock(Locator.class); HMangr hman = new HMangr(aEnv, loc); - AAFcli aafcli = new AAFcli(prop, aEnv, wtr, hman, null, null); + aafcli = new AAFcli(prop, aEnv, wtr, hman, null, null); + user = new User(); NS ns = new NS(aafcli); list = new List(ns); } @Test - public void testReport() { + public void testReport() throws Exception { Future<Nss> fu = mock(Future.class); - Nss.Ns nss = new Nss.Ns(); - Nss ns = new Nss(); - fu.value = ns; - fu.value.getNs(); - System.out.print(fu.value.getNs()); + NssStub nssStub = new NssStub(); + NssStub.NsStub nsStub = nssStub.new NsStub(); + Nss.Ns.Attrib attrib = mock(Nss.Ns.Attrib.class); + when(attrib.getKey()).thenReturn("key"); + when(attrib.getValue()).thenReturn("value"); + nsStub.addAttrib(attrib); + nsStub.addResponsible("test"); + nsStub.addAdmin("admin"); + nssStub.addNs(nsStub); + fu.value = nssStub; + aafcli.eval("DETAILS @[ 123"); - list.report(null, "test"); list.report(fu, "test"); } + @Test + public void testGetType() { + Assert.assertEquals("n/a", list.getType(user)); + user.setType(1); + Assert.assertEquals("U/P", list.getType(user)); + user.setType(2); + Assert.assertEquals("U/P2", list.getType(user)); + user.setType(10); + Assert.assertEquals("Cert", list.getType(user)); + user.setType(200); + Assert.assertEquals("x509", list.getType(user)); + } + } diff --git a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/role/JU_List.java b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/role/JU_List.java index 7767e054..9eb4b75b 100644 --- a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/role/JU_List.java +++ b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/role/JU_List.java @@ -35,6 +35,7 @@ import org.onap.aaf.auth.cmd.Cmd; import org.onap.aaf.auth.cmd.Param; import org.onap.aaf.auth.env.AuthzEnv; import org.onap.aaf.auth.env.AuthzTrans; +import org.onap.aaf.cadi.Access; import org.onap.aaf.cadi.CadiException; import org.onap.aaf.cadi.Locator; import org.onap.aaf.cadi.LocatorException; @@ -42,10 +43,12 @@ import org.onap.aaf.cadi.PropAccess; import org.onap.aaf.cadi.SecuritySetter; import org.onap.aaf.cadi.client.Future; import org.onap.aaf.cadi.client.Rcli; +import org.onap.aaf.cadi.config.SecurityInfoC; import org.onap.aaf.cadi.http.HMangr; import org.onap.aaf.misc.env.APIException; import aaf.v2_0.Perms; +import aaf.v2_0.Pkey; import aaf.v2_0.Roles; import aaf.v2_0.UserRoles; @@ -59,6 +62,7 @@ import java.net.HttpURLConnection; import java.net.URI; import java.security.GeneralSecurityException; import java.security.Principal; +import java.util.ArrayList; import org.junit.Test; @@ -80,8 +84,25 @@ public class JU_List { super(parent); // TODO Auto-generated constructor stub } - - + } + + private class RolesStub extends Roles { + public void addRole(aaf.v2_0.Role role) { + if (this.role == null) { + this.role = new ArrayList<aaf.v2_0.Role>(); + } + this.role.add(role); + } + } + + private class RoleStub extends aaf.v2_0.Role { + + public void addPerms(Pkey perms) { + if (this.perms == null) { + this.perms = new ArrayList<Pkey>(); + } + this.perms.add(perms); + } } @Before @@ -119,10 +140,22 @@ public class JU_List { public void testReport() throws Exception { UserRoles urs = new UserRoles(); Perms perms = new Perms(); - Roles roles = mock(Roles.class); + RolesStub roles = new RolesStub(); list.report(roles, perms , urs , "test"); AAFcli cli = JU_AAFCli.getAAfCli(); + RoleStub role = new RoleStub(); + roles.addRole(role); + Pkey pkey = new Pkey(); + pkey.setInstance("test"); + pkey.setAction("test"); + pkey.setInstance("test"); + pkey.setType("test"); + + list.report(roles, perms , urs , "test"); + list.report(roles, perms , null , "test"); cli.eval("DETAILS @[ 123"); + role.setName("test"); + role.addPerms(pkey); list.report(roles, perms , urs , "test"); } |