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=810a93444f51b3c9afdd75bb42e9f80667391c14;hb=1296352d8eafee57f982a4342ad79ada4aa56d28;hp=1a13580fffa9b0729ccd9eb823b45a90b353eee8;hpb=53247c1dd17dd5740bfbe22f1865543f3e185cdf;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..810a9344 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 @@ -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. @@ -18,6 +18,7 @@ * ============LICENSE_END==================================================== * */ + package org.onap.aaf.auth.oauth.service; import static org.junit.Assert.assertEquals; @@ -54,147 +55,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_API_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_API_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_API_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(); + } }