Test filter owning-entities from /category_parameter by permissions 91/101791/1
authorIttay Stern <ittay.stern@att.com>
Sun, 16 Feb 2020 14:41:11 +0000 (16:41 +0200)
committerIttay Stern <ittay.stern@att.com>
Sun, 16 Feb 2020 15:14:44 +0000 (17:14 +0200)
Issue-ID: VID-758

Change-Id: I9b5dc8906067c4f077ba2e03073e6dface6aa86c
Signed-off-by: Ittay Stern <ittay.stern@att.com>
vid-automation/conf/users
vid-automation/src/main/java/org/onap/sdc/ci/tests/datatypes/UserCredentials.java
vid-automation/src/main/java/vid/automation/test/Constants.java
vid-automation/src/test/java/org/onap/vid/api/BaseApiAaiTest.java
vid-automation/src/test/java/org/onap/vid/api/PropertyControllerApiTest.java [new file with mode: 0644]

index 8f38018..b4b6327 100644 (file)
             "password": "822"
           },
           "roles": [
-            "WayneHolland___LOB", "Melissa___LOB", "aaa1___LOB",
+            "WayneHolland___LOB",
             "JULIO ERICKSON___Emanuel",
             "JULIO ERICKSON___vRichardson"
-
           ],
           "subscriberNames": ["JULIO ERICKSON"],
           "serviceTypes": ["Emanuel", "vRichardson"],
index 5dec395..88b2a28 100644 (file)
@@ -42,6 +42,10 @@ public class UserCredentials extends User {
                this.copyData(user);
        }
 
+       public UserCredentials(vid.automation.test.model.User user) {
+               this(user.credentials.userId, user.credentials.password, "", "", "");
+       }
+
        public String getPassword() {
                return password;
        }
index 7256f0a..e639ee0 100644 (file)
@@ -516,7 +516,7 @@ public class Constants {
         public static final String EMANUEL_EMANUEL = "emanuelEmanuel";
         public static final String CRAIG_ROBERTS_AIM_TRANSPORT = "FIREWALL_AIM_Trans";
         public static final String EMANUEL_vWINIFRED = "emanuelvWINIFRED";
-        public static final String SUPRE_USER = "su";
+        public static final String PORFIRIO_GERHARDT = "Porfirio Gerhardt";
     }
 
     public class RegisterToSimulator {
index 4ac38a0..32586af 100644 (file)
@@ -1,6 +1,15 @@
 package org.onap.vid.api;
 
+import static net.javacrumbs.jsonunit.JsonMatchers.jsonStringEquals;
+import static org.hamcrest.Matchers.either;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import static vid.automation.test.services.SimulatorApi.registerExpectation;
+
 import com.google.common.collect.ImmutableMap;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import org.springframework.http.HttpMethod;
 import org.springframework.http.RequestEntity;
 import org.springframework.http.ResponseEntity;
@@ -8,23 +17,13 @@ import org.springframework.web.client.HttpClientErrorException;
 import org.springframework.web.client.HttpServerErrorException;
 import org.springframework.web.client.HttpStatusCodeException;
 import org.testng.annotations.BeforeClass;
+import vid.automation.test.services.CategoryParamsService;
 import vid.automation.test.services.SimulatorApi;
 
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import static net.javacrumbs.jsonunit.JsonMatchers.jsonStringEquals;
-import static org.hamcrest.Matchers.either;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-import static vid.automation.test.services.SimulatorApi.registerExpectation;
-
-/**
- * Created by Oren on 11/1/17.
- */
 public class BaseApiAaiTest extends BaseApiTest {
 
+    protected final CategoryParamsService categoryParamsService = new CategoryParamsService();
+
     @BeforeClass
     public void login() {
         super.login();
diff --git a/vid-automation/src/test/java/org/onap/vid/api/PropertyControllerApiTest.java b/vid-automation/src/test/java/org/onap/vid/api/PropertyControllerApiTest.java
new file mode 100644 (file)
index 0000000..b12adbe
--- /dev/null
@@ -0,0 +1,62 @@
+package org.onap.vid.api;
+
+import static java.util.stream.Collectors.toList;
+import static net.javacrumbs.jsonunit.JsonMatchers.jsonPartEquals;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static vid.automation.test.infra.Features.FLAG_2006_LIMIT_OWNING_ENTITY_SELECTION_BY_ROLES;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.google.common.collect.ImmutableMap;
+import java.util.List;
+import java.util.function.Function;
+import java.util.stream.Stream;
+import org.onap.sdc.ci.tests.datatypes.UserCredentials;
+import org.testng.annotations.Test;
+import vid.automation.test.Constants.Users;
+import vid.automation.test.infra.FeatureTogglingTest;
+
+public class PropertyControllerApiTest extends BaseApiTest {
+
+    private final List<Object> allOwningEntities = toOwningEntitiesList(Stream.of("aaa1", "Melissa", "WayneHolland"));
+
+    private final List<Object> singleOwningEntity = toOwningEntitiesList(Stream.of("WayneHolland"));
+
+    @Test
+    public void categoryParameter_whenUserFullyAllowed_allOwningEntitiesRetrieved() {
+        categoryParameters_loginAndAssertOwningEntities(Users.SILVIA_ROBBINS_TYLER_SILVIA, allOwningEntities);
+    }
+
+    @Test
+    @FeatureTogglingTest(FLAG_2006_LIMIT_OWNING_ENTITY_SELECTION_BY_ROLES)
+    public void categoryParameter_whenUserNotFullyAllowed_onlySomeOwningEntitiesRetrieved() {
+        categoryParameters_loginAndAssertOwningEntities(Users.PORFIRIO_GERHARDT, singleOwningEntity);
+    }
+
+    @Test
+    @FeatureTogglingTest(value = FLAG_2006_LIMIT_OWNING_ENTITY_SELECTION_BY_ROLES, flagActive = false)
+    public void categoryParameter_whenUserNotFullyAllowed_stillAllOwningEntitiesRetrieved() {
+        categoryParameters_loginAndAssertOwningEntities(Users.PORFIRIO_GERHARDT, allOwningEntities);
+    }
+
+
+
+    public void categoryParameters_loginAndAssertOwningEntities(String user, List<Object> singleOwningEntities) {
+        login(new UserCredentials(usersService.getUser(user)));
+
+        String url = uri.toASCIIString() + "/category_parameter?familyName=PARAMETER_STANDARDIZATION";
+
+        assertThat(restTemplate.getForObject(url, JsonNode.class),
+            jsonPartEquals("categoryParameters.owningEntity", singleOwningEntities));
+    }
+
+    private List<Object> toOwningEntitiesList(Stream<String> owningEntitiesNames) {
+        return owningEntitiesNames.map(it -> ImmutableMap.of(
+            "name", it,
+            "id", expectedIdByName.apply(it))
+        ).collect(toList());
+    }
+
+    static private final Function<String, String> expectedIdByName = it ->
+        "WayneHolland".equals(it) ? "d61e6f2d-12fa-4cc2-91df-7c244011d6fc" : it;
+
+}