aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend
diff options
context:
space:
mode:
authoravigaffa <avi.gaffa@amdocs.com>2017-12-27 14:42:46 +0200
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2017-12-27 14:11:50 +0000
commitfa3d1762fe1f65c5e3ca68a65529e9121c43b727 (patch)
tree02cb50491321afb14164602f79ea8c0718ee6764 /openecomp-be/backend
parentbca6a11c83157cc4f177ee63ef42ae0e81a588d1 (diff)
Validate notification framework called in test
Call to ItemPermissionsManagerImplTest Change-Id: I8b1f0e42c0f7b4ebf821f18e9fbbb801f95052c9 Issue-ID: SDC-803 Signed-off-by: avigaffa <avi.gaffa@amdocs.com>
Diffstat (limited to 'openecomp-be/backend')
-rw-r--r--openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/test/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsManagerImplTest.java64
1 files changed, 48 insertions, 16 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
index e4618246d8..98154b3eaa 100644
--- 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
@@ -1,11 +1,10 @@
package org.openecomp.sdc.itempermissions.dao.impl;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.*;
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.dtos.Event;
import org.openecomp.sdc.notification.services.NotificationPropagationManager;
import org.openecomp.sdc.notification.services.SubscriptionService;
import org.openecomp.sdc.versioning.ItemManager;
@@ -13,14 +12,16 @@ 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.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
+import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.*;
+import static org.openecomp.sdc.itempermissions.notifications.NotificationConstants.PERMISSION_CHANGED;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
/**
* Created by ayalaben on 7/6/2017
@@ -43,9 +44,13 @@ public class ItemPermissionsManagerImplTest {
private SubscriptionService subscriptionServiceMock;
@Mock
private NotificationPropagationManager notifierMock;
+ @Captor
+ private ArgumentCaptor<Event> eventArgumentCaptor;
+
@InjectMocks
private ItemPermissionsManagerImpl permissionsManager;
+
@BeforeMethod
public void setUp() throws Exception {
SessionContextProviderFactory.getInstance().createInterface().create(USER);
@@ -53,13 +58,13 @@ public class ItemPermissionsManagerImplTest {
}
@Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp = "Permissions " +
- "Error. The user does not have permission to perform this action.")
+ "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<>());
+ .updateItemPermissions(ITEM1_ID, PERMISSION, Collections.singleton(AFFECTED_USER1),
+ new HashSet<>());
}
@Test
@@ -70,17 +75,44 @@ public class ItemPermissionsManagerImplTest {
doReturn(item).when(itemManagerMock).get(ITEM1_ID);
Set<String> addedUsersIds =
- Stream.of(AFFECTED_USER1, AFFECTED_USER2).collect(Collectors.toSet());
+ Stream.of(AFFECTED_USER1, AFFECTED_USER2).collect(Collectors.toSet());
Set<String> removedUsersIds = Collections.singleton(AFFECTED_USER3);
permissionsManager
- .updateItemPermissions(ITEM1_ID, PERMISSION, addedUsersIds, removedUsersIds);
+ .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);
+ .updateItemPermissions(ITEM1_ID, PERMISSION, addedUsersIds, removedUsersIds);
+
+ for (String addedUsersId : addedUsersIds) {
+ verifyCallsToNotificationsFramework(addedUsersId, true);
+ }
+ for (String removedUsersId : removedUsersIds) {
+ verifyCallsToNotificationsFramework(removedUsersId, false);
+ }
+ }
+
+ private void verifyCallsToNotificationsFramework(String affectedUser, boolean permissionGranted) {
+ verifyCallToSubscriptionService(affectedUser, permissionGranted);
+ verifyDirectNotificationCallParameters(affectedUser, permissionGranted);
+ }
+
+ private void verifyDirectNotificationCallParameters(String affectedUser, boolean permissionGranted) {
+ verify(notifierMock).directNotification(eventArgumentCaptor.capture(), Matchers.eq(affectedUser));
+ Event event = eventArgumentCaptor.getValue();
+ assertTrue(event.getEventType().equals(PERMISSION_CHANGED));
+ Map<String, Object> attributes = event.getAttributes();
+ assertEquals(attributes.get(PERMISSION_GRANTED), permissionGranted);
+ assertEquals(attributes.get(ITEM_ID_PROP), ITEM1_ID);
+ assertEquals(attributes.get(PERMISSION_ITEM), PERMISSION);
+ }
- // TODO: 12/18/2017 verify notification
+ private void verifyCallToSubscriptionService(String affectedUser, boolean permissionGranted) {
+ if (permissionGranted) {
+ verify(subscriptionServiceMock).subscribe(affectedUser, ITEM1_ID);
+ } else {
+ verify(subscriptionServiceMock).unsubscribe(affectedUser, ITEM1_ID);
+ }
}
+
+
} \ No newline at end of file