X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-service%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fservice%2Ftest%2FJU_BaseServiceImpl.java;h=5e6cfb62e5599732f49f58e4740783be163fd939;hb=d41b490db09178a9da02cd20f6d2368b38ca6475;hp=c9ebc281179f193cc618a8d8940cf5a0fcbe1d4f;hpb=b3814beaec2b6f439ffb7af1594e70b5339a9e5f;p=aaf%2Fauthz.git diff --git a/auth/auth-service/src/test/java/org/onap/aaf/auth/service/test/JU_BaseServiceImpl.java b/auth/auth-service/src/test/java/org/onap/aaf/auth/service/test/JU_BaseServiceImpl.java index c9ebc281..5e6cfb62 100644 --- a/auth/auth-service/src/test/java/org/onap/aaf/auth/service/test/JU_BaseServiceImpl.java +++ b/auth/auth-service/src/test/java/org/onap/aaf/auth/service/test/JU_BaseServiceImpl.java @@ -20,7 +20,9 @@ */ package org.onap.aaf.auth.service.test; +import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import java.util.ArrayList; @@ -49,6 +51,7 @@ import org.onap.aaf.auth.dao.cass.UserRoleDAO; import org.onap.aaf.auth.dao.hl.Question; 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.auth.service.AuthzCassServiceImpl; import org.onap.aaf.auth.service.mapper.Mapper_2_0; import org.onap.aaf.cadi.PropAccess; @@ -75,12 +78,17 @@ public abstract class JU_BaseServiceImpl { protected AuthzCassServiceImpl acsi; protected Mapper_2_0 mapper; - - @Mock + + @Mock protected DefaultOrg org; - @Mock + @Mock protected DefaultOrgIdentity orgIdentity; - + +// +// NOTE: Annotation format (@Mock and @Spy) do NOT seem to always work as a Base Class, +// so we construct manually. +// +// Mock Objects protected HistoryDAO historyDAO = mock(HistoryDAO.class); protected CacheInfoDAO cacheInfoDAO = mock(CacheInfoDAO.class); protected CachedNSDAO nsDAO = mock(CachedNSDAO.class); @@ -93,20 +101,21 @@ public abstract class JU_BaseServiceImpl { protected FutureDAO futureDAO = mock(FutureDAO.class); protected DelegateDAO delegateDAO = mock(DelegateDAO.class); protected ApprovalDAO approvalDAO = mock(ApprovalDAO.class); - + + // Spy Objects @Spy protected static PropAccess access = new PropAccess(); - @Spy protected static AuthzEnv env = new AuthzEnv(access); - @Spy protected static AuthzTrans trans = env.newTransNoAvg(); - + // @Spy doesn't seem to work on Question. @Spy - protected Question question = new Question(trans,historyDAO,cacheInfoDAO,nsDAO,permDAO,roleDAO,userRoleDAO, - credDAO,certDAO,locateDAO,futureDAO,delegateDAO,approvalDAO); + protected Question question = spy(new Question(trans, + historyDAO,cacheInfoDAO,nsDAO,permDAO, + roleDAO,userRoleDAO,credDAO,certDAO, + locateDAO,futureDAO,delegateDAO,approvalDAO)); public void setUp() throws Exception { when(trans.org()).thenReturn(org); @@ -114,7 +123,7 @@ public abstract class JU_BaseServiceImpl { Define.set(access); access.setProperty(Config.CADI_LATITUDE, "38.0"); access.setProperty(Config.CADI_LONGITUDE, "-72.0"); - + mapper = new Mapper_2_0(question); acsi = new AuthzCassServiceImpl<>(trans, mapper, question); } @@ -136,6 +145,25 @@ public abstract class JU_BaseServiceImpl { return rv; } + /** + * Setup Role Data for Mock Usages + * @param trans + * @param user + * @param ns + * @param role + * @param exists + * @param days + */ + protected void whenRole(AuthzTrans trans, String user, String ns, String role, boolean exists, int days) { + Result> result; + if(exists) { + result = Result.ok(listOf(urData(user,ns,role,days))); + } else { + result = Result.ok(emptyList(UserRoleDAO.Data.class)); + } + when(question.userRoleDAO().read(trans, user, ns+'.'+role)).thenReturn(result); + } + protected UserRoleDAO.Data urData(String user, String ns, String rname, int days) { UserRoleDAO.Data urdd = new UserRoleDAO.Data(); urdd.user = user;