[roleInheritance] Added test suite
authorCarlos Aristu <carlos.aristu@openbravo.com>
Thu, 01 Oct 2015 09:53:47 +0200
changeset 27784 046c0208ee72
parent 27783 785f90e7329f
child 27785 6a010d6939cd
[roleInheritance] Added test suite
src-test/src/org/openbravo/test/role/DeletedAccessPropagation.java
src-test/src/org/openbravo/test/role/DeletedAccessPropagationTest.java
src-test/src/org/openbravo/test/role/RoleInheritanceTestSuite.java
--- a/src-test/src/org/openbravo/test/role/DeletedAccessPropagation.java	Thu Oct 01 09:10:12 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,172 +0,0 @@
-/*
- *************************************************************************
- * The contents of this file are subject to the Openbravo  Public  License
- * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
- * Version 1.1  with a permitted attribution clause; you may not  use this
- * file except in compliance with the License. You  may  obtain  a copy of
- * the License at http://www.openbravo.com/legal/license.html 
- * Software distributed under the License  is  distributed  on  an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific  language  governing  rights  and  limitations
- * under the License. 
- * The Original Code is Openbravo ERP. 
- * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2015 Openbravo SLU 
- * All Rights Reserved. 
- * Contributor(s):  ______________________________________.
- ************************************************************************
- */
-package org.openbravo.test.role;
-
-import static org.hamcrest.Matchers.equalTo;
-import static org.junit.Assert.assertThat;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.openbravo.base.weld.test.ParameterCdiTest;
-import org.openbravo.base.weld.test.ParameterCdiTestRule;
-import org.openbravo.base.weld.test.WeldBaseTest;
-import org.openbravo.dal.core.DalUtil;
-import org.openbravo.dal.core.OBContext;
-import org.openbravo.dal.service.OBDal;
-import org.openbravo.model.ad.access.Role;
-
-/**
- * Test case for deleted access propagation
- * 
- * We have a role which inherits from three different templates. All these templates have permission
- * to the same particular access.
- * 
- * We are removing the access for each template starting from the one with highest priority. Thus
- * the inherited access for the role will be updated with every deletion.
- * 
- * 
- */
-public class DeletedAccessPropagation extends WeldBaseTest {
-  private final List<String> ORGANIZATIONS = Arrays.asList("F&B España - Región Norte",
-      "F&B España - Región Sur");
-  private final List<String> WINDOWS = Arrays.asList("Sales Invoice", "Sales Order");
-  private final List<String> TABS = Arrays.asList("Bank Account", "Basic Discount");
-  private final List<String> FIELDS = Arrays.asList("Business Partner Category", "Commercial Name");
-  private final List<String> REPORTS = Arrays.asList("Alert Process", "Create Variants");
-  private final List<String> FORMS = Arrays.asList("About", "Heartbeat");
-  private final List<String> WIDGETS = Arrays.asList("Best Sellers", "Invoices to collect");
-  private final List<String> VIEWS = Arrays.asList("OBUIAPP_AlertManagement",
-      "OBUIAPP_RegistrationView");
-  private final List<String> PROCESSES = Arrays.asList("Create Purchase Order Lines",
-      "Grant Portal Access");
-  private final List<String> TABLES = Arrays.asList("AD_User", "C_Order");
-  private final List<String> ALERTS = Arrays.asList("Alert Taxes: Inversión del Sujeto Pasivo",
-      "CUSTOMER WITHOUT ACCOUNTING");
-  private final List<String> PREFERENCES = Arrays.asList("AllowAttachment", "AllowDelete");
-
-  @SuppressWarnings("unchecked")
-  private final List<List<String>> ACCESSES = Arrays.asList(ORGANIZATIONS, WINDOWS, TABS, FIELDS,
-      REPORTS, FORMS, WIDGETS, VIEWS, PROCESSES, TABLES, ALERTS, PREFERENCES);
-  private static int testCounter = 0;
-
-  /** defines the values the parameter will take. */
-  @Rule
-  public ParameterCdiTestRule<String> parameterValuesRule = new ParameterCdiTestRule<String>(
-      RoleInheritanceTestUtils.ACCESS_NAMES);
-
-  /** this field will take the values defined by parameterValuesRule field. */
-  private @ParameterCdiTest
-  String parameter;
-
-  @Test
-  public void testBasicAccessDeletePropagation() {
-    Role role = null;
-    Role template1 = null;
-    Role template2 = null;
-    Role template3 = null;
-    try {
-      OBContext.setAdminMode(true);
-      // Create roles
-      role = RoleInheritanceTestUtils.createRole("role", RoleInheritanceTestUtils.CLIENT_ID,
-          RoleInheritanceTestUtils.ASTERISK_ORG_ID, " C", true, false);
-      String roleId = (String) DalUtil.getId(role);
-      template1 = RoleInheritanceTestUtils.createRole("template1",
-          RoleInheritanceTestUtils.CLIENT_ID, RoleInheritanceTestUtils.ASTERISK_ORG_ID, " C", true,
-          true);
-      String template1Id = (String) DalUtil.getId(template1);
-      template2 = RoleInheritanceTestUtils.createRole("template2",
-          RoleInheritanceTestUtils.CLIENT_ID, RoleInheritanceTestUtils.ASTERISK_ORG_ID, " C", true,
-          true);
-      String template2Id = (String) DalUtil.getId(template2);
-      template3 = RoleInheritanceTestUtils.createRole("template3",
-          RoleInheritanceTestUtils.CLIENT_ID, RoleInheritanceTestUtils.ASTERISK_ORG_ID, " C", true,
-          true);
-      String template3Id = (String) DalUtil.getId(template3);
-
-      List<String> accesses = ACCESSES.get(testCounter);
-      // Add accesses
-      RoleInheritanceTestUtils.addAccess(parameter, template1, accesses.get(0));
-      RoleInheritanceTestUtils.addAccess(parameter, template1, accesses.get(1));
-      RoleInheritanceTestUtils.addAccess(parameter, template2, accesses.get(0));
-      RoleInheritanceTestUtils.addAccess(parameter, template3, accesses.get(0));
-
-      // Add inheritances
-      RoleInheritanceTestUtils.addInheritance(role, template1, new Long(10));
-      RoleInheritanceTestUtils.addInheritance(role, template2, new Long(20));
-      RoleInheritanceTestUtils.addInheritance(role, template3, new Long(30));
-      OBDal.getInstance().commitAndClose();
-
-      String[] expected = { accesses.get(0), template3Id, accesses.get(1), template1Id };
-      String[] result = RoleInheritanceTestUtils.getOrderedAccessNames(parameter, role);
-      assertThat("Inherited access created properly", result, equalTo(expected));
-
-      // Remove window access for template 3
-      template3 = OBDal.getInstance().get(Role.class, template3Id);
-      RoleInheritanceTestUtils.removeAccesses(parameter, template3);
-      OBDal.getInstance().commitAndClose();
-
-      String[] expected2 = { accesses.get(0), template2Id, accesses.get(1), template1Id };
-      String[] result2 = RoleInheritanceTestUtils.getOrderedAccessNames(parameter, role);
-      assertThat("Inherited access updated properly after first removal", result2,
-          equalTo(expected2));
-
-      // Remove window access for template 2
-      template2 = OBDal.getInstance().get(Role.class, template2Id);
-      RoleInheritanceTestUtils.removeAccesses(parameter, template2);
-      OBDal.getInstance().commitAndClose();
-
-      String[] expected3 = { accesses.get(0), template1Id, accesses.get(1), template1Id };
-      String[] result3 = RoleInheritanceTestUtils.getOrderedAccessNames(parameter, role);
-      assertThat("Inherited access updated properly after second removal", result3,
-          equalTo(expected3));
-      OBDal.getInstance().commitAndClose();
-
-      // Remove window access for template 1
-      template1 = OBDal.getInstance().get(Role.class, template1Id);
-      RoleInheritanceTestUtils.removeAccesses(parameter, template1);
-      OBDal.getInstance().commitAndClose();
-
-      role = OBDal.getInstance().get(Role.class, roleId);
-      template1 = OBDal.getInstance().get(Role.class, template1Id);
-      template2 = OBDal.getInstance().get(Role.class, template2Id);
-      template3 = OBDal.getInstance().get(Role.class, template3Id);
-
-      String[] expected4 = {};
-      String[] result4 = RoleInheritanceTestUtils.getOrderedAccessNames(parameter, role);
-      assertThat("Inherited access updated properly after third removal", result4,
-          equalTo(expected4));
-
-      testCounter++;
-
-    } finally {
-      // Delete roles
-      RoleInheritanceTestUtils.deleteRole(role);
-      RoleInheritanceTestUtils.deleteRole(template1);
-      RoleInheritanceTestUtils.deleteRole(template2);
-      RoleInheritanceTestUtils.deleteRole(template3);
-
-      OBDal.getInstance().commitAndClose();
-
-      OBContext.restorePreviousMode();
-    }
-  }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/test/role/DeletedAccessPropagationTest.java	Thu Oct 01 09:53:47 2015 +0200
@@ -0,0 +1,172 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License. 
+ * The Original Code is Openbravo ERP. 
+ * The Initial Developer of the Original Code is Openbravo SLU 
+ * All portions are Copyright (C) 2015 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.test.role;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.openbravo.base.weld.test.ParameterCdiTest;
+import org.openbravo.base.weld.test.ParameterCdiTestRule;
+import org.openbravo.base.weld.test.WeldBaseTest;
+import org.openbravo.dal.core.DalUtil;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.ad.access.Role;
+
+/**
+ * Test case for deleted access propagation
+ * 
+ * We have a role which inherits from three different templates. All these templates have permission
+ * to the same particular access.
+ * 
+ * We are removing the access for each template starting from the one with highest priority. Thus
+ * the inherited access for the role will be updated with every deletion.
+ * 
+ * 
+ */
+public class DeletedAccessPropagationTest extends WeldBaseTest {
+  private final List<String> ORGANIZATIONS = Arrays.asList("F&B España - Región Norte",
+      "F&B España - Región Sur");
+  private final List<String> WINDOWS = Arrays.asList("Sales Invoice", "Sales Order");
+  private final List<String> TABS = Arrays.asList("Bank Account", "Basic Discount");
+  private final List<String> FIELDS = Arrays.asList("Business Partner Category", "Commercial Name");
+  private final List<String> REPORTS = Arrays.asList("Alert Process", "Create Variants");
+  private final List<String> FORMS = Arrays.asList("About", "Heartbeat");
+  private final List<String> WIDGETS = Arrays.asList("Best Sellers", "Invoices to collect");
+  private final List<String> VIEWS = Arrays.asList("OBUIAPP_AlertManagement",
+      "OBUIAPP_RegistrationView");
+  private final List<String> PROCESSES = Arrays.asList("Create Purchase Order Lines",
+      "Grant Portal Access");
+  private final List<String> TABLES = Arrays.asList("AD_User", "C_Order");
+  private final List<String> ALERTS = Arrays.asList("Alert Taxes: Inversión del Sujeto Pasivo",
+      "CUSTOMER WITHOUT ACCOUNTING");
+  private final List<String> PREFERENCES = Arrays.asList("AllowAttachment", "AllowDelete");
+
+  @SuppressWarnings("unchecked")
+  private final List<List<String>> ACCESSES = Arrays.asList(ORGANIZATIONS, WINDOWS, TABS, FIELDS,
+      REPORTS, FORMS, WIDGETS, VIEWS, PROCESSES, TABLES, ALERTS, PREFERENCES);
+  private static int testCounter = 0;
+
+  /** defines the values the parameter will take. */
+  @Rule
+  public ParameterCdiTestRule<String> parameterValuesRule = new ParameterCdiTestRule<String>(
+      RoleInheritanceTestUtils.ACCESS_NAMES);
+
+  /** this field will take the values defined by parameterValuesRule field. */
+  private @ParameterCdiTest
+  String parameter;
+
+  @Test
+  public void testBasicAccessDeletePropagation() {
+    Role role = null;
+    Role template1 = null;
+    Role template2 = null;
+    Role template3 = null;
+    try {
+      OBContext.setAdminMode(true);
+      // Create roles
+      role = RoleInheritanceTestUtils.createRole("role", RoleInheritanceTestUtils.CLIENT_ID,
+          RoleInheritanceTestUtils.ASTERISK_ORG_ID, " C", true, false);
+      String roleId = (String) DalUtil.getId(role);
+      template1 = RoleInheritanceTestUtils.createRole("template1",
+          RoleInheritanceTestUtils.CLIENT_ID, RoleInheritanceTestUtils.ASTERISK_ORG_ID, " C", true,
+          true);
+      String template1Id = (String) DalUtil.getId(template1);
+      template2 = RoleInheritanceTestUtils.createRole("template2",
+          RoleInheritanceTestUtils.CLIENT_ID, RoleInheritanceTestUtils.ASTERISK_ORG_ID, " C", true,
+          true);
+      String template2Id = (String) DalUtil.getId(template2);
+      template3 = RoleInheritanceTestUtils.createRole("template3",
+          RoleInheritanceTestUtils.CLIENT_ID, RoleInheritanceTestUtils.ASTERISK_ORG_ID, " C", true,
+          true);
+      String template3Id = (String) DalUtil.getId(template3);
+
+      List<String> accesses = ACCESSES.get(testCounter);
+      // Add accesses
+      RoleInheritanceTestUtils.addAccess(parameter, template1, accesses.get(0));
+      RoleInheritanceTestUtils.addAccess(parameter, template1, accesses.get(1));
+      RoleInheritanceTestUtils.addAccess(parameter, template2, accesses.get(0));
+      RoleInheritanceTestUtils.addAccess(parameter, template3, accesses.get(0));
+
+      // Add inheritances
+      RoleInheritanceTestUtils.addInheritance(role, template1, new Long(10));
+      RoleInheritanceTestUtils.addInheritance(role, template2, new Long(20));
+      RoleInheritanceTestUtils.addInheritance(role, template3, new Long(30));
+      OBDal.getInstance().commitAndClose();
+
+      String[] expected = { accesses.get(0), template3Id, accesses.get(1), template1Id };
+      String[] result = RoleInheritanceTestUtils.getOrderedAccessNames(parameter, role);
+      assertThat("Inherited access created properly", result, equalTo(expected));
+
+      // Remove window access for template 3
+      template3 = OBDal.getInstance().get(Role.class, template3Id);
+      RoleInheritanceTestUtils.removeAccesses(parameter, template3);
+      OBDal.getInstance().commitAndClose();
+
+      String[] expected2 = { accesses.get(0), template2Id, accesses.get(1), template1Id };
+      String[] result2 = RoleInheritanceTestUtils.getOrderedAccessNames(parameter, role);
+      assertThat("Inherited access updated properly after first removal", result2,
+          equalTo(expected2));
+
+      // Remove window access for template 2
+      template2 = OBDal.getInstance().get(Role.class, template2Id);
+      RoleInheritanceTestUtils.removeAccesses(parameter, template2);
+      OBDal.getInstance().commitAndClose();
+
+      String[] expected3 = { accesses.get(0), template1Id, accesses.get(1), template1Id };
+      String[] result3 = RoleInheritanceTestUtils.getOrderedAccessNames(parameter, role);
+      assertThat("Inherited access updated properly after second removal", result3,
+          equalTo(expected3));
+      OBDal.getInstance().commitAndClose();
+
+      // Remove window access for template 1
+      template1 = OBDal.getInstance().get(Role.class, template1Id);
+      RoleInheritanceTestUtils.removeAccesses(parameter, template1);
+      OBDal.getInstance().commitAndClose();
+
+      role = OBDal.getInstance().get(Role.class, roleId);
+      template1 = OBDal.getInstance().get(Role.class, template1Id);
+      template2 = OBDal.getInstance().get(Role.class, template2Id);
+      template3 = OBDal.getInstance().get(Role.class, template3Id);
+
+      String[] expected4 = {};
+      String[] result4 = RoleInheritanceTestUtils.getOrderedAccessNames(parameter, role);
+      assertThat("Inherited access updated properly after third removal", result4,
+          equalTo(expected4));
+
+      testCounter++;
+
+    } finally {
+      // Delete roles
+      RoleInheritanceTestUtils.deleteRole(role);
+      RoleInheritanceTestUtils.deleteRole(template1);
+      RoleInheritanceTestUtils.deleteRole(template2);
+      RoleInheritanceTestUtils.deleteRole(template3);
+
+      OBDal.getInstance().commitAndClose();
+
+      OBContext.restorePreviousMode();
+    }
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/test/role/RoleInheritanceTestSuite.java	Thu Oct 01 09:53:47 2015 +0200
@@ -0,0 +1,48 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License. 
+ * The Original Code is Openbravo ERP. 
+ * The Initial Developer of the Original Code is Openbravo SLU 
+ * All portions are Copyright (C) 2015 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.test.role;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * 
+ * Test Suite for Role Inheritance
+ * 
+ */
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+
+// Propagation Tests
+    AccessPropagationNotInheritedTest.class, //
+    AccessPropagationTest.class, //
+    DeletedAccessPropagationTest.class,
+    // Inheritance Tests
+    HorizontalInheritanceTest.class, //
+    VerticalInheritanceTest.class, //
+    // Restrictions Test
+    RoleInheritanceRestrictionsTest.class, //
+    // Recalculate Permissions Process Test
+    RecalculatePermissionsTest.class, //
+})
+public class RoleInheritanceTestSuite {
+
+}
\ No newline at end of file