diff options
author | talig <talig@amdocs.com> | 2017-12-20 14:30:43 +0200 |
---|---|---|
committer | Vitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com> | 2017-12-21 11:12:33 +0000 |
commit | 8e9c0653dd6c6862123c9609ae34e1206d86456e (patch) | |
tree | 5eeef00ec0677133baa439ca8d7ffd7aca4804b6 /openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/test/java | |
parent | 785ebcc95de3e064e843bec04ba7a209d854fc7c (diff) |
Add collaboration feature
Issue-ID: SDC-767
Change-Id: I14fb4c1f54086ed03a56a7ff7fab9ecd40381795
Signed-off-by: talig <talig@amdocs.com>
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/test/java')
-rw-r--r-- | openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/test/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsManagerImplTest.java | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/test/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/test/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsManagerImplTest.java new file mode 100644 index 0000000000..e4618246d8 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/test/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsManagerImplTest.java @@ -0,0 +1,86 @@ +package org.openecomp.sdc.itempermissions.dao.impl; + +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.session.SessionContextProviderFactory; +import org.openecomp.sdc.itempermissions.PermissionsServices; +import org.openecomp.sdc.notification.services.NotificationPropagationManager; +import org.openecomp.sdc.notification.services.SubscriptionService; +import org.openecomp.sdc.versioning.ItemManager; +import org.openecomp.sdc.versioning.types.Item; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; + +/** + * Created by ayalaben on 7/6/2017 + */ +public class ItemPermissionsManagerImplTest { + + private static final String ITEM1_ID = "1"; + private static final String PERMISSION = "Contributor"; + private static final String ACTION = "Change_Item_Permissions"; + private static final String USER = "user"; + private static final String AFFECTED_USER1 = "affected_user1"; + private static final String AFFECTED_USER2 = "affected_user2"; + private static final String AFFECTED_USER3 = "affected_user3"; + + @Mock + private PermissionsServices permissionsServicesMock; + @Mock + private ItemManager itemManagerMock; + @Mock + private SubscriptionService subscriptionServiceMock; + @Mock + private NotificationPropagationManager notifierMock; + @InjectMocks + private ItemPermissionsManagerImpl permissionsManager; + + @BeforeMethod + public void setUp() throws Exception { + SessionContextProviderFactory.getInstance().createInterface().create(USER); + MockitoAnnotations.initMocks(this); + } + + @Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp = "Permissions " + + "Error. The user does not have permission to perform this action.") + public void testUpdateItemPermissionsWhenNotAllowed() { + doReturn(false).when(permissionsServicesMock).isAllowed(ITEM1_ID, USER, ACTION); + + permissionsManager + .updateItemPermissions(ITEM1_ID, PERMISSION, Collections.singleton(AFFECTED_USER1), + new HashSet<>()); + } + + @Test + public void testUpdateItemPermissions() { + doReturn(true).when(permissionsServicesMock).isAllowed(ITEM1_ID, USER, ACTION); + Item item = new Item(); + item.setName("Item 1 Name"); + doReturn(item).when(itemManagerMock).get(ITEM1_ID); + + Set<String> addedUsersIds = + Stream.of(AFFECTED_USER1, AFFECTED_USER2).collect(Collectors.toSet()); + Set<String> removedUsersIds = Collections.singleton(AFFECTED_USER3); + permissionsManager + .updateItemPermissions(ITEM1_ID, PERMISSION, addedUsersIds, removedUsersIds); + + verify(permissionsServicesMock) + .updateItemPermissions(ITEM1_ID, PERMISSION, addedUsersIds, removedUsersIds); + verify(subscriptionServiceMock).subscribe(AFFECTED_USER1, ITEM1_ID); + verify(subscriptionServiceMock).subscribe(AFFECTED_USER2, ITEM1_ID); + verify(subscriptionServiceMock).unsubscribe(AFFECTED_USER3, ITEM1_ID); + + // TODO: 12/18/2017 verify notification + } +}
\ No newline at end of file |