summaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/test')
-rw-r--r--openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/test/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsManagerImplTest.java86
-rw-r--r--openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/test/resources/logback.xml15
2 files changed, 101 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
diff --git a/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/test/resources/logback.xml b/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/test/resources/logback.xml
new file mode 100644
index 0000000000..c1932e31e8
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/test/resources/logback.xml
@@ -0,0 +1,15 @@
+<configuration>
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <!-- encoders are assigned the type
+ ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <root level="warn">
+ <appender-ref ref="STDOUT" />
+ </root>
+
+</configuration> \ No newline at end of file