added svcapi ui and camunda code
[it/otf.git] / otf-service-api / src / test / java / org / oran / otf / api / tests / unit / utility / UserPermissionTest.java
diff --git a/otf-service-api/src/test/java/org/oran/otf/api/tests/unit/utility/UserPermissionTest.java b/otf-service-api/src/test/java/org/oran/otf/api/tests/unit/utility/UserPermissionTest.java
new file mode 100644 (file)
index 0000000..e2d7954
--- /dev/null
@@ -0,0 +1,67 @@
+/*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
+#                                                                              #\r
+#   Licensed under the Apache License, Version 2.0 (the "License");            #\r
+#   you may not use this file except in compliance with the License.           #\r
+#   You may obtain a copy of the License at                                    #\r
+#                                                                              #\r
+#       http://www.apache.org/licenses/LICENSE-2.0                             #\r
+#                                                                              #\r
+#   Unless required by applicable law or agreed to in writing, software        #\r
+#   distributed under the License is distributed on an "AS IS" BASIS,          #\r
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
+#   See the License for the specific language governing permissions and        #\r
+#   limitations under the License.                                             #\r
+##############################################################################*/\r
+\r
+\r
+package org.oran.otf.api.tests.unit.utility;\r
+\r
+import org.oran.otf.common.utility.permissions.UserPermission;\r
+import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.mockito.InjectMocks;\r
+import org.mockito.Mock;\r
+import org.mockito.Mockito;\r
+import org.mockito.junit.MockitoJUnitRunner;\r
+\r
+import java.util.*;\r
+\r
+@RunWith(MockitoJUnitRunner.class)\r
+public class UserPermissionTest {\r
+\r
+    @Mock\r
+    Map<String, Set<String>> userAccessMap ;\r
+\r
+    @InjectMocks\r
+    private UserPermission userPermission;\r
+\r
+    @Before\r
+    public void setUp()\r
+    {\r
+        String fakeGroupId1 = "abc123";\r
+        Set<String> user1Permissions = new HashSet<>(Arrays.asList("READ","WRITE"));\r
+        Mockito.when(userAccessMap.get(fakeGroupId1)).thenReturn(user1Permissions);\r
+    }\r
+\r
+    @Test\r
+    public void testHasAccessToMethod(){\r
+\r
+        Assert.assertNotNull(userPermission.getUserAccessMap());\r
+        //test when user have access to group with certain permissions and a fake permission(mix of upper and lower case\r
+        Assert.assertTrue(userPermission.hasAccessTo("abc123","READ"));\r
+        Assert.assertTrue(userPermission.hasAccessTo("abc123","WrIte"));\r
+        Assert.assertFalse(userPermission.hasAccessTo("abc123","DEleTE"));\r
+        Assert.assertFalse(userPermission.hasAccessTo("abc123","ExECUTe"));\r
+        Assert.assertFalse(userPermission.hasAccessTo("abc123","mANAgEMENT"));\r
+        Assert.assertFalse(userPermission.hasAccessTo("abc123","READ+WRITE"));\r
+\r
+        //test when user have no access to the group\r
+        Assert.assertFalse(userPermission.hasAccessTo("edf567","READ"));\r
+        Assert.assertFalse(userPermission.hasAccessTo("edf567","WRITE"));\r
+        Assert.assertFalse(userPermission.hasAccessTo("edf567","DELETE"));\r
+        Assert.assertFalse(userPermission.hasAccessTo("edf567","EXECUTE"));\r
+        Assert.assertFalse(userPermission.hasAccessTo("edf567","MANAGEMENT"));\r
+    }\r
+}\r