From ac2041bbd4f3f7212f91b75bc72d3735b6bc3642 Mon Sep 17 00:00:00 2001 From: pkaras Date: Fri, 31 May 2019 12:42:52 +0200 Subject: AafPermissionService refactor Change-Id: I7c1fecf232f86b4352d24b26ae3b8da47559c428 Issue-ID: DMAAP-1211 Signed-off-by: piotr.karas --- .../dbcapi/service/AafPermissionServiceTest.java | 30 ++++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'src/test') diff --git a/src/test/java/org/onap/dmaap/dbcapi/service/AafPermissionServiceTest.java b/src/test/java/org/onap/dmaap/dbcapi/service/AafPermissionServiceTest.java index 1bba2bf..bad66b8 100644 --- a/src/test/java/org/onap/dmaap/dbcapi/service/AafPermissionServiceTest.java +++ b/src/test/java/org/onap/dmaap/dbcapi/service/AafPermissionServiceTest.java @@ -39,6 +39,8 @@ import static org.junit.Assert.assertTrue; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.verifyZeroInteractions; +import static org.onap.dmaap.dbcapi.model.DmaapObject.DmaapObject_Status.INVALID; +import static org.onap.dmaap.dbcapi.model.DmaapObject.DmaapObject_Status.VALID; @RunWith(JUnitParamsRunner.class) public class AafPermissionServiceTest { @@ -70,87 +72,87 @@ public class AafPermissionServiceTest { @Test @Parameters({"201", "409"}) public void shouldAssignClientToRole(int aafServiceReturnedCode) { - ApiError apiError = new ApiError(); AafUserRole userRole = new AafUserRole(IDENTITY, ROLE); given(aafService.addUserRole(userRole)).willReturn(aafServiceReturnedCode); - aafPermissionService.assignIdentityToRole(mrClient, ROLE, apiError); + ApiError apiError = aafPermissionService.assignClientToRole(mrClient, ROLE); then(aafService).should().addUserRole(userRole); + then(mrClient).should().setStatus(VALID); assertOkStatus(apiError); } @Test public void shouldReturnErrorStatusWhenClientWasNotAssignedToRole() { - ApiError apiError = new ApiError(); AafUserRole userRole = new AafUserRole(IDENTITY, ROLE); given(aafService.addUserRole(userRole)).willReturn(INTERNAL_SERVER_ERROR); - aafPermissionService.assignIdentityToRole(mrClient, ROLE, apiError); + ApiError apiError = aafPermissionService.assignClientToRole(mrClient, ROLE); + then(mrClient).should().setStatus(INVALID); assertErrorStatus(apiError, INTERNAL_SERVER_ERROR); } @Test @Parameters({"201", "409"}) public void shouldGrantActionPermissionForClientRole(int aafServiceReturnedCode) { - ApiError apiError = new ApiError(); DmaapGrant grant = new DmaapGrant(new DmaapPerm(TOPIC_PERM, ":topic." + FQTN, PUB_ACTION), ROLE); given(mrClient.getClientRole()).willReturn(ROLE); given(aafService.addGrant(grant)).willReturn(aafServiceReturnedCode); - aafPermissionService.grantClientRolePerms(mrClient, apiError); + ApiError apiError = aafPermissionService.grantClientRolePerms(mrClient); then(aafService).should().addGrant(grant); + then(mrClient).should().setStatus(VALID); assertOkStatus(apiError); } @Test public void shouldReturnErrorStatusWhenPermissionWasNotGrantToRole() { - ApiError apiError = new ApiError(); DmaapGrant grant = new DmaapGrant(new DmaapPerm(TOPIC_PERM, ":topic." + FQTN, PUB_ACTION), ROLE); given(mrClient.getClientRole()).willReturn(ROLE); given(aafService.addGrant(grant)).willReturn(INTERNAL_SERVER_ERROR); - aafPermissionService.grantClientRolePerms(mrClient, apiError); + ApiError apiError = aafPermissionService.grantClientRolePerms(mrClient); + then(mrClient).should().setStatus(INVALID); assertErrorStatus(apiError, INTERNAL_SERVER_ERROR); } @Test public void shouldReturnOkStatusWhenClientRoleIsNull() { - ApiError apiError = new ApiError(); given(mrClient.getClientRole()).willReturn(null); - aafPermissionService.grantClientRolePerms(mrClient, apiError); + ApiError apiError = aafPermissionService.grantClientRolePerms(mrClient); verifyZeroInteractions(aafService); + then(mrClient).should().setStatus(VALID); assertOkStatus(apiError); } @Test @Parameters({"200", "404"}) public void shouldRevokeActionPermissionForClientRole(int aafServiceReturnedCode) { - ApiError apiError = new ApiError(); DmaapGrant grant = new DmaapGrant(new DmaapPerm(TOPIC_PERM, ":topic." + FQTN, PUB_ACTION), ROLE); given(mrClient.getClientRole()).willReturn(ROLE); given(aafService.delGrant(grant)).willReturn(aafServiceReturnedCode); - aafPermissionService.revokeClientPerms(mrClient, apiError); + ApiError apiError = aafPermissionService.revokeClientPerms(mrClient); then(aafService).should().delGrant(grant); + then(mrClient).should().setStatus(VALID); assertOkStatus(apiError); } @Test public void shouldReturnErrorStatusWhenPermissionWasNotRevokedFromRole() { - ApiError apiError = new ApiError(); DmaapGrant grant = new DmaapGrant(new DmaapPerm(TOPIC_PERM, ":topic." + FQTN, PUB_ACTION), ROLE); given(mrClient.getClientRole()).willReturn(ROLE); given(aafService.delGrant(grant)).willReturn(INTERNAL_SERVER_ERROR); - aafPermissionService.revokeClientPerms(mrClient, apiError); + ApiError apiError = aafPermissionService.revokeClientPerms(mrClient); + then(mrClient).should().setStatus(INVALID); assertErrorStatus(apiError, INTERNAL_SERVER_ERROR); } -- cgit 1.2.3-korg