X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-oauth%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Foauth%2Fservice%2FJU_JSONPermLoaderFactoryTest.java;h=4a26da7d143d356bf43381c50bf24c5aca488f2e;hb=refs%2Fchanges%2F75%2F65275%2F1;hp=1a13580fffa9b0729ccd9eb823b45a90b353eee8;hpb=824dc7b5fc0e1ccdf7f460479aff344727f0f01e;p=aaf%2Fauthz.git diff --git a/auth/auth-oauth/src/test/java/org/onap/aaf/auth/oauth/service/JU_JSONPermLoaderFactoryTest.java b/auth/auth-oauth/src/test/java/org/onap/aaf/auth/oauth/service/JU_JSONPermLoaderFactoryTest.java index 1a13580f..4a26da7d 100644 --- a/auth/auth-oauth/src/test/java/org/onap/aaf/auth/oauth/service/JU_JSONPermLoaderFactoryTest.java +++ b/auth/auth-oauth/src/test/java/org/onap/aaf/auth/oauth/service/JU_JSONPermLoaderFactoryTest.java @@ -54,147 +54,147 @@ import org.onap.aaf.misc.env.Env; import org.onap.aaf.misc.env.TimeTaken; public class JU_JSONPermLoaderFactoryTest { - @Mock - private AAFCon aafcon; - @Mock - private AuthzTrans trans; - @Mock - private TimeTaken tt; - @Mock - Rcli c; - @Mock - private Future fs; - @Mock - private Question question; - @Mock - private Result rdns; - private NsSplit nss; + @Mock + private AAFCon aafcon; + @Mock + private AuthzTrans trans; + @Mock + private TimeTaken tt; + @Mock + Rcli c; + @Mock + private Future fs; + @Mock + private Question question; + @Mock + private Result rdns; + private NsSplit nss; - private Access access; + private Access access; - @Before - public void setup() throws CadiException { - access = new AuthzEnv(); - Define.set(access); - initMocks(this); - nss = new NsSplit("APPLICATION", "APPLICATION"); - } + @Before + public void setup() throws CadiException { + access = new AuthzEnv(); + Define.set(access); + initMocks(this); + nss = new NsSplit("APPLICATION", "APPLICATION"); + } - @Test - public void testRemoteWithTimeOut() throws APIException, CadiException { - when(trans.start("Call AAF Service", Env.REMOTE)).thenReturn(tt); - when(aafcon.clientAs(Config.AAF_DEFAULT_VERSION, trans.getUserPrincipal())).thenReturn(c); - when(c.read("/authz/perms/user/null?scopes=APPLICATION:HANDLER", - "application/Perms+json;charset=utf-8;version=2.0")).thenReturn(fs); - when(fs.get(0)).thenReturn(true); + @Test + public void testRemoteWithTimeOut() throws APIException, CadiException { + when(trans.start("Call AAF Service", Env.REMOTE)).thenReturn(tt); + when(aafcon.clientAs(Config.AAF_DEFAULT_VERSION, trans.getUserPrincipal())).thenReturn(c); + when(c.read("/authz/perms/user/null?scopes=APPLICATION:HANDLER", + "application/Perms+json;charset=utf-8;version=2.0")).thenReturn(fs); + when(fs.get(0)).thenReturn(true); - Set scopes = new HashSet(); - scopes.add(Scope.APPLICATION.toString()); - scopes.add(Scope.HANDLER.toString()); + Set scopes = new HashSet(); + scopes.add(Scope.APPLICATION.toString()); + scopes.add(Scope.HANDLER.toString()); - JSONPermLoader factory = JSONPermLoaderFactory.remote(aafcon, 0); + JSONPermLoader factory = JSONPermLoaderFactory.remote(aafcon, 0); - Result loadJSONPerms = factory.loadJSONPerms(trans, null, scopes); + Result loadJSONPerms = factory.loadJSONPerms(trans, null, scopes); - assertEquals(0, loadJSONPerms.status); + assertEquals(0, loadJSONPerms.status); - verify(tt, only()).done(); - } + verify(tt, only()).done(); + } - @Test - public void testRemoteWith404() throws APIException, CadiException { - when(trans.start("Call AAF Service", Env.REMOTE)).thenReturn(tt); - when(aafcon.clientAs(Config.AAF_DEFAULT_VERSION, trans.getUserPrincipal())).thenReturn(c); - when(c.read("/authz/perms/user/null?scopes=APPLICATION:HANDLER", - "application/Perms+json;charset=utf-8;version=2.0")).thenReturn(fs); - when(fs.get(0)).thenReturn(false); - when(fs.code()).thenReturn(404); + @Test + public void testRemoteWith404() throws APIException, CadiException { + when(trans.start("Call AAF Service", Env.REMOTE)).thenReturn(tt); + when(aafcon.clientAs(Config.AAF_DEFAULT_VERSION, trans.getUserPrincipal())).thenReturn(c); + when(c.read("/authz/perms/user/null?scopes=APPLICATION:HANDLER", + "application/Perms+json;charset=utf-8;version=2.0")).thenReturn(fs); + when(fs.get(0)).thenReturn(false); + when(fs.code()).thenReturn(404); - Set scopes = new HashSet(); - scopes.add(Scope.APPLICATION.toString()); - scopes.add(Scope.HANDLER.toString()); + Set scopes = new HashSet(); + scopes.add(Scope.APPLICATION.toString()); + scopes.add(Scope.HANDLER.toString()); - JSONPermLoader factory = JSONPermLoaderFactory.remote(aafcon, 0); + JSONPermLoader factory = JSONPermLoaderFactory.remote(aafcon, 0); - Result loadJSONPerms = factory.loadJSONPerms(trans, null, scopes); + Result loadJSONPerms = factory.loadJSONPerms(trans, null, scopes); - assertEquals(Result.ERR_NotFound, loadJSONPerms.status); + assertEquals(Result.ERR_NotFound, loadJSONPerms.status); - verify(tt, only()).done(); - } + verify(tt, only()).done(); + } - @Test - public void testRemote() throws APIException, CadiException { - when(trans.start("Call AAF Service", Env.REMOTE)).thenReturn(tt); - when(aafcon.clientAs(Config.AAF_DEFAULT_VERSION, trans.getUserPrincipal())).thenReturn(c); - when(c.read("/authz/perms/user/null?scopes=APPLICATION:HANDLER", - "application/Perms+json;charset=utf-8;version=2.0")).thenReturn(fs); - when(fs.get(0)).thenReturn(false); + @Test + public void testRemote() throws APIException, CadiException { + when(trans.start("Call AAF Service", Env.REMOTE)).thenReturn(tt); + when(aafcon.clientAs(Config.AAF_DEFAULT_VERSION, trans.getUserPrincipal())).thenReturn(c); + when(c.read("/authz/perms/user/null?scopes=APPLICATION:HANDLER", + "application/Perms+json;charset=utf-8;version=2.0")).thenReturn(fs); + when(fs.get(0)).thenReturn(false); - Set scopes = new HashSet(); - scopes.add(Scope.APPLICATION.toString()); - scopes.add(Scope.HANDLER.toString()); + Set scopes = new HashSet(); + scopes.add(Scope.APPLICATION.toString()); + scopes.add(Scope.HANDLER.toString()); - JSONPermLoader factory = JSONPermLoaderFactory.remote(aafcon, 0); + JSONPermLoader factory = JSONPermLoaderFactory.remote(aafcon, 0); - Result loadJSONPerms = factory.loadJSONPerms(trans, null, scopes); + Result loadJSONPerms = factory.loadJSONPerms(trans, null, scopes); - assertEquals(Result.ERR_Backend, loadJSONPerms.status); + assertEquals(Result.ERR_Backend, loadJSONPerms.status); - verify(tt, only()).done(); - } + verify(tt, only()).done(); + } - @Test - public void testDirectWhenPdNotOk() throws APIException, CadiException { + @Test + public void testDirectWhenPdNotOk() throws APIException, CadiException { - Result> pd = Result.create(null, Result.ERR_Backend, "details", "vars"); + Result> pd = Result.create(null, Result.ERR_Backend, "details", "vars"); - when(question.getPermsByUser(trans, "user", false)).thenReturn(pd); - when(trans.start("Cached DB Perm lookup", Env.SUB)).thenReturn(tt); + when(question.getPermsByUser(trans, "user", false)).thenReturn(pd); + when(trans.start("Cached DB Perm lookup", Env.SUB)).thenReturn(tt); - Set scopes = new HashSet(); - scopes.add(Scope.APPLICATION.toString()); - scopes.add(Scope.HANDLER.toString()); + Set scopes = new HashSet(); + scopes.add(Scope.APPLICATION.toString()); + scopes.add(Scope.HANDLER.toString()); - JSONPermLoader factory = JSONPermLoaderFactory.direct(question); + JSONPermLoader factory = JSONPermLoaderFactory.direct(question); - Result loadJSONPerms = factory.loadJSONPerms(trans, "user", scopes); + Result loadJSONPerms = factory.loadJSONPerms(trans, "user", scopes); - assertEquals(Result.ERR_Backend, loadJSONPerms.status); + assertEquals(Result.ERR_Backend, loadJSONPerms.status); - verify(tt, only()).done(); - } + verify(tt, only()).done(); + } - @Test - public void testDirectWhenPdOk() throws APIException, CadiException { + @Test + public void testDirectWhenPdOk() throws APIException, CadiException { - when(trans.start("Cached DB Perm lookup", Env.SUB)).thenReturn(tt); - when(question.deriveNsSplit(trans, "name")).thenReturn(rdns); - when(rdns.isOKhasData()).thenReturn(false); + when(trans.start("Cached DB Perm lookup", Env.SUB)).thenReturn(tt); + when(question.deriveNsSplit(trans, "name")).thenReturn(rdns); + when(rdns.isOKhasData()).thenReturn(false); - List list = new ArrayList(); - list.add(new PermDAO.Data(nss, "instance", "action")); - list.add(new PermDAO.Data(nss, "instance", "action")); + List list = new ArrayList(); + list.add(new PermDAO.Data(nss, "instance", "action")); + list.add(new PermDAO.Data(nss, "instance", "action")); - Result> pd = Result.create(list, Result.OK, "details", "vars"); + Result> pd = Result.create(list, Result.OK, "details", "vars"); - when(question.getPermsByUser(trans, "user", false)).thenReturn(pd); + when(question.getPermsByUser(trans, "user", false)).thenReturn(pd); - Set scopes = new HashSet(); - scopes.add(Scope.APPLICATION.toString()); - scopes.add(Scope.HANDLER.toString()); + Set scopes = new HashSet(); + scopes.add(Scope.APPLICATION.toString()); + scopes.add(Scope.HANDLER.toString()); - JSONPermLoader factory = JSONPermLoaderFactory.direct(question); + JSONPermLoader factory = JSONPermLoaderFactory.direct(question); - Result loadJSONPerms = factory.loadJSONPerms(trans, "user", scopes); + Result loadJSONPerms = factory.loadJSONPerms(trans, "user", scopes); - assertEquals(Result.OK, loadJSONPerms.status); - assertEquals("Success", loadJSONPerms.details); - assertEquals( - "{\"perm\":[{\"ns\":\"APPLICATION\",\"type\":\"APPLICATION\",\"instance\":\"instance\",\"action\":\"action\"},{\"ns\":\"APPLICATION\",\"type\":\"APPLICATION\",\"instance\":\"instance\",\"action\":\"action\"}]}", - loadJSONPerms.value); + assertEquals(Result.OK, loadJSONPerms.status); + assertEquals("Success", loadJSONPerms.details); + assertEquals( + "{\"perm\":[{\"ns\":\"APPLICATION\",\"type\":\"APPLICATION\",\"instance\":\"instance\",\"action\":\"action\"},{\"ns\":\"APPLICATION\",\"type\":\"APPLICATION\",\"instance\":\"instance\",\"action\":\"action\"}]}", + loadJSONPerms.value); - verify(tt, only()).done(); - } + verify(tt, only()).done(); + } }