[roleInheritance] Add delete access propagation test for test suite
authorCarlos Aristu <carlos.aristu@openbravo.com>
Tue, 29 Sep 2015 16:09:02 +0200
changeset 27779 d33c94ef7e1f
parent 27778 0bd6da797c24
child 27780 0eca808004b9
[roleInheritance] Add delete access propagation test for test suite
The RecalculatePermissionsTest is updated also, to make use of the API methods placed in RoleInheritanceTestUtils class
src-test/src/org/openbravo/test/role/AccessPropagationNotInheritedTest.java
src-test/src/org/openbravo/test/role/AccessPropagationTest.java
src-test/src/org/openbravo/test/role/BasicADWindowInheritanceTest.java
src-test/src/org/openbravo/test/role/DeletedAccessPropagation.java
src-test/src/org/openbravo/test/role/HorizontalInheritanceTest.java
src-test/src/org/openbravo/test/role/RecalculatePermissionsTest.java
src-test/src/org/openbravo/test/role/RoleInheritanceTestUtils.java
src-test/src/org/openbravo/test/role/VerticalInheritanceTest.java
--- a/src-test/src/org/openbravo/test/role/AccessPropagationNotInheritedTest.java	Tue Sep 29 12:49:29 2015 +0200
+++ b/src-test/src/org/openbravo/test/role/AccessPropagationNotInheritedTest.java	Tue Sep 29 16:09:02 2015 +0200
@@ -61,7 +61,7 @@
   @SuppressWarnings("unchecked")
   private final List<List<String>> ACCESSES = Arrays.asList(ORGANIZATIONS, WINDOWS, TABS, FIELDS,
       REPORTS, FORMS, WIDGETS, VIEWS, PROCESSES, ALERTS, PREFERENCES);
-  private static int counterHorizontalTest = 0;
+  private static int testCounter = 0;
 
   /** defines the values the parameter will take. */
   @Rule
@@ -94,7 +94,7 @@
       role = OBDal.getInstance().get(Role.class, roleId);
       template = OBDal.getInstance().get(Role.class, templateId);
 
-      List<String> accesses = ACCESSES.get(counterHorizontalTest);
+      List<String> accesses = ACCESSES.get(testCounter);
       // Add accesses
       RoleInheritanceTestUtils.addAccess(parameter, role, accesses.get(0));
       RoleInheritanceTestUtils.addAccess(parameter, template, accesses.get(0));
@@ -130,7 +130,7 @@
 
       RoleInheritanceTestUtils.removeAccesses(parameter, template);
       RoleInheritanceTestUtils.removeAccesses(parameter, role);
-      counterHorizontalTest++;
+      testCounter++;
 
     } finally {
       // Delete roles
--- a/src-test/src/org/openbravo/test/role/AccessPropagationTest.java	Tue Sep 29 12:49:29 2015 +0200
+++ b/src-test/src/org/openbravo/test/role/AccessPropagationTest.java	Tue Sep 29 16:09:02 2015 +0200
@@ -65,7 +65,7 @@
   @SuppressWarnings("unchecked")
   private final List<List<String>> ACCESSES = Arrays.asList(ORGANIZATIONS, WINDOWS, TABS, FIELDS,
       REPORTS, FORMS, WIDGETS, VIEWS, PROCESSES, ALERTS, PREFERENCES);
-  private static int counterHorizontalTest = 0;
+  private static int testCounter = 0;
 
   /** defines the values the parameter will take. */
   @Rule
@@ -98,7 +98,7 @@
       role = OBDal.getInstance().get(Role.class, roleId);
       template = OBDal.getInstance().get(Role.class, templateId);
 
-      List<String> accesses = ACCESSES.get(counterHorizontalTest);
+      List<String> accesses = ACCESSES.get(testCounter);
       // Add accesses
       RoleInheritanceTestUtils.addAccess(parameter, template, accesses.get(0));
       RoleInheritanceTestUtils.addAccess(parameter, role, accesses.get(1));
@@ -144,7 +144,7 @@
 
       RoleInheritanceTestUtils.removeAccesses(parameter, template);
       RoleInheritanceTestUtils.removeAccesses(parameter, role);
-      counterHorizontalTest++;
+      testCounter++;
 
     } finally {
       // Delete roles
--- a/src-test/src/org/openbravo/test/role/BasicADWindowInheritanceTest.java	Tue Sep 29 12:49:29 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,182 +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.List;
-
-import org.hibernate.criterion.Restrictions;
-import org.junit.Test;
-import org.openbravo.base.provider.OBProvider;
-import org.openbravo.base.weld.test.WeldBaseTest;
-import org.openbravo.dal.core.DalUtil;
-import org.openbravo.dal.core.OBContext;
-import org.openbravo.dal.service.OBCriteria;
-import org.openbravo.dal.service.OBDal;
-import org.openbravo.model.ad.access.Role;
-import org.openbravo.model.ad.access.WindowAccess;
-import org.openbravo.model.ad.ui.Window;
-
-public class BasicADWindowInheritanceTest extends WeldBaseTest {
-  public final static String BUSINESS_PARTNER_ID = "123";
-  public final static String SALES_ORDER_ID = "143";
-  public final static String SALES_INVOICE_ID = "167";
-  public final static String PURCHASE_ORDER_ID = "181";
-  public final static String PURCHASE_INVOICE_ID = "183";
-
-  @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);
-
-      // Add window accesses
-      addWindowAccess(template1, "Sales Invoice", true);
-      addWindowAccess(template1, "Sales Order", true);
-      addWindowAccess(template2, "Sales Invoice", true);
-      addWindowAccess(template3, "Sales Invoice", true);
-
-      // 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 = { SALES_INVOICE_ID, template3Id, SALES_ORDER_ID, template1Id };
-      String[] result = getWindowAccessesOrderedByWindowName(role);
-      assertThat("Inherited access created properly", result, equalTo(expected));
-
-      // Remove window access for template 3
-      template3 = OBDal.getInstance().get(Role.class, template3Id);
-      removeWindowAccess(template3, "Sales Invoice");
-      OBDal.getInstance().commitAndClose();
-
-      String[] expected2 = { SALES_INVOICE_ID, template2Id, SALES_ORDER_ID, template1Id };
-      String[] result2 = getWindowAccessesOrderedByWindowName(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);
-      removeWindowAccess(template2, "Sales Invoice");
-      OBDal.getInstance().commitAndClose();
-
-      String[] expected3 = { SALES_INVOICE_ID, template1Id, SALES_ORDER_ID, template1Id };
-      String[] result3 = getWindowAccessesOrderedByWindowName(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);
-      removeWindowAccess(template1, "Sales Invoice");
-      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 = { SALES_ORDER_ID, template1Id };
-      String[] result4 = getWindowAccessesOrderedByWindowName(role);
-      assertThat("Inherited access updated properly after third removal", result4,
-          equalTo(expected4));
-
-    } finally {
-      // Delete roles
-      RoleInheritanceTestUtils.deleteRole(role);
-      RoleInheritanceTestUtils.deleteRole(template1);
-      RoleInheritanceTestUtils.deleteRole(template2);
-      RoleInheritanceTestUtils.deleteRole(template3);
-
-      OBDal.getInstance().commitAndClose();
-
-      OBContext.restorePreviousMode();
-    }
-  }
-
-  public static void addWindowAccess(Role role, String windowName, boolean editableField) {
-    final WindowAccess windowAccess = OBProvider.getInstance().get(WindowAccess.class);
-    final OBCriteria<Window> obCriteria = OBDal.getInstance().createCriteria(Window.class);
-    obCriteria.add(Restrictions.eq(Window.PROPERTY_NAME, windowName));
-    obCriteria.setMaxResults(1);
-    windowAccess.setClient(role.getClient());
-    windowAccess.setOrganization(role.getOrganization());
-    windowAccess.setRole(role);
-    windowAccess.setWindow((Window) obCriteria.uniqueResult());
-    windowAccess.setEditableField(editableField);
-    OBDal.getInstance().save(windowAccess);
-    OBDal.getInstance().flush();
-    OBDal.getInstance().refresh(role);
-  }
-
-  public static void removeWindowAccess(Role role, String windowName) {
-    WindowAccess wa = getWindowAccessForWindowName(role.getADWindowAccessList(), windowName);
-    wa.setInheritedFrom(null);
-    role.getADWindowAccessList().remove(wa);
-    OBDal.getInstance().remove(wa);
-  }
-
-  private String[] getWindowAccessesOrderedByWindowName(Role role) {
-    final OBCriteria<WindowAccess> obCriteria = OBDal.getInstance().createCriteria(
-        WindowAccess.class);
-    obCriteria.add(Restrictions.eq(WindowAccess.PROPERTY_ROLE, role));
-    obCriteria.addOrderBy(WindowAccess.PROPERTY_WINDOW + "." + Window.PROPERTY_NAME, true);
-    List<WindowAccess> list = obCriteria.list();
-    String[] result = new String[list.size() * 2];
-    int i = 0;
-    for (WindowAccess wa : list) {
-      result[i] = (String) DalUtil.getId(wa.getWindow());
-      result[i + 1] = wa.getInheritedFrom() != null ? (String) DalUtil.getId(wa.getInheritedFrom())
-          : "";
-      i += 2;
-    }
-    return result;
-  }
-
-  public static WindowAccess getWindowAccessForWindowName(List<WindowAccess> list, String windowName) {
-    for (WindowAccess wa : list) {
-      if (windowName.equals(wa.getWindow().getName())) {
-        return wa;
-      }
-    }
-    return null;
-  }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/test/role/DeletedAccessPropagation.java	Tue Sep 29 16:09:02 2015 +0200
@@ -0,0 +1,171 @@
+/*
+ *************************************************************************
+ * 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> 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, 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();
+    }
+  }
+}
--- a/src-test/src/org/openbravo/test/role/HorizontalInheritanceTest.java	Tue Sep 29 12:49:29 2015 +0200
+++ b/src-test/src/org/openbravo/test/role/HorizontalInheritanceTest.java	Tue Sep 29 16:09:02 2015 +0200
@@ -74,7 +74,7 @@
   @SuppressWarnings("unchecked")
   private final List<List<String>> ACCESSES = Arrays.asList(ORGANIZATIONS, WINDOWS, TABS, FIELDS,
       REPORTS, FORMS, WIDGETS, VIEWS, PROCESSES, ALERTS, PREFERENCES);
-  private static int counterHorizontalTest = 0;
+  private static int testCounter = 0;
 
   /** defines the values the parameter will take. */
   @Rule
@@ -111,7 +111,7 @@
           false);
       String inheritedRoleId = (String) DalUtil.getId(inheritedRole);
 
-      List<String> accesses = ACCESSES.get(counterHorizontalTest);
+      List<String> accesses = ACCESSES.get(testCounter);
       if (!parameter.equals("VIEW")) {
         RoleInheritanceTestUtils.addAccess(parameter, template1, accesses.get(3));
         RoleInheritanceTestUtils.addAccess(parameter, template1, accesses.get(4));
@@ -183,7 +183,7 @@
       RoleInheritanceTestUtils.removeAccesses(parameter, template2);
       RoleInheritanceTestUtils.removeAccesses(parameter, template3);
 
-      counterHorizontalTest++;
+      testCounter++;
 
     } finally {
       // Delete roles
--- a/src-test/src/org/openbravo/test/role/RecalculatePermissionsTest.java	Tue Sep 29 12:49:29 2015 +0200
+++ b/src-test/src/org/openbravo/test/role/RecalculatePermissionsTest.java	Tue Sep 29 16:09:02 2015 +0200
@@ -19,7 +19,6 @@
 package org.openbravo.test.role;
 
 import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.not;
 import static org.junit.Assert.assertThat;
 
 import org.junit.Test;
@@ -27,7 +26,6 @@
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.model.ad.access.Role;
-import org.openbravo.model.ad.access.WindowAccess;
 import org.openbravo.roleInheritance.RoleInheritanceManager;
 import org.openbravo.test.base.OBBaseTest;
 
@@ -55,7 +53,7 @@
       RoleInheritanceTestUtils.addInheritance(role, template, new Long(10));
 
       // Add permission (it will not be propagated as event handlers will not be fired)
-      BasicADWindowInheritanceTest.addWindowAccess(template, "Sales Order", true);
+      RoleInheritanceTestUtils.addAccess("WINDOW", template, "Sales Order");
 
       OBDal.getInstance().commitAndClose();
       role = OBDal.getInstance().get(Role.class, roleId);
@@ -65,15 +63,11 @@
       role = OBDal.getInstance().get(Role.class, roleId);
       template = OBDal.getInstance().get(Role.class, templateId);
 
-      WindowAccess wa = BasicADWindowInheritanceTest.getWindowAccessForWindowName(
-          role.getADWindowAccessList(), "Sales Order");
-
-      assertThat("There is a new access created with the recalculation", wa, not(equalTo(null)));
+      assertThat("There is a new access created with the recalculation", role
+          .getADWindowAccessList().size(), equalTo(1));
 
       String[] expected = { "true", "true", templateId };
-      String inheritedFromid = wa.getInheritedFrom() != null ? wa.getInheritedFrom().getId() : "";
-      String[] result = { wa.isEditableField().toString(), wa.isActive().toString(),
-          inheritedFromid };
+      String[] result = RoleInheritanceTestUtils.getAccessInfo("WINDOW", role, "Sales Order");
       assertThat("New access recalculated properly", expected, equalTo(result));
 
     } finally {
@@ -110,7 +104,7 @@
       RoleInheritanceTestUtils.addInheritance(role2, template, new Long(20));
 
       // Add permission (it will not be propagated as event handlers will not be fired)
-      BasicADWindowInheritanceTest.addWindowAccess(template, "Sales Order", true);
+      RoleInheritanceTestUtils.addAccess("WINDOW", template, "Sales Order");
 
       OBDal.getInstance().commitAndClose();
       template = OBDal.getInstance().get(Role.class, templateId);
@@ -121,24 +115,18 @@
       role2 = OBDal.getInstance().get(Role.class, role2Id);
       template = OBDal.getInstance().get(Role.class, templateId);
 
-      WindowAccess wa = BasicADWindowInheritanceTest.getWindowAccessForWindowName(
-          role1.getADWindowAccessList(), "Sales Order");
-      assertThat("There is a new access created with the recalculation for role1", wa,
-          not(equalTo(null)));
+      assertThat("There is a new access created with the recalculation for role1", role1
+          .getADWindowAccessList().size(), equalTo(1));
 
-      WindowAccess wa2 = BasicADWindowInheritanceTest.getWindowAccessForWindowName(
-          role1.getADWindowAccessList(), "Sales Order");
-      assertThat("There is a new access created with the recalculation for role2", wa2,
-          not(equalTo(null)));
+      assertThat("There is a new access created with the recalculation for role2", role2
+          .getADWindowAccessList().size(), equalTo(1));
 
-      String[] expected = { "true", "true", templateId, "true", "true", templateId };
-      String inheritedFromid1 = wa.getInheritedFrom() != null ? wa.getInheritedFrom().getId() : "";
-      String inheritedFromid2 = wa2.getInheritedFrom() != null ? wa2.getInheritedFrom().getId()
-          : "";
-      String[] result = { wa.isEditableField().toString(), wa.isActive().toString(),
-          inheritedFromid1, wa2.isEditableField().toString(), wa2.isActive().toString(),
-          inheritedFromid2 };
-      assertThat("New accesses recalculated properly", expected, equalTo(result));
+      String[] expected = { "true", "true", templateId };
+      String[] result = RoleInheritanceTestUtils.getAccessInfo("WINDOW", role1, "Sales Order");
+      assertThat("New accesses recalculated properly for role 1", expected, equalTo(result));
+
+      String[] result2 = RoleInheritanceTestUtils.getAccessInfo("WINDOW", role2, "Sales Order");
+      assertThat("New accesses recalculated properly for role 2", expected, equalTo(result2));
 
     } finally {
       // Delete roles
--- a/src-test/src/org/openbravo/test/role/RoleInheritanceTestUtils.java	Tue Sep 29 12:49:29 2015 +0200
+++ b/src-test/src/org/openbravo/test/role/RoleInheritanceTestUtils.java	Tue Sep 29 16:09:02 2015 +0200
@@ -18,6 +18,7 @@
  */
 package org.openbravo.test.role;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
@@ -127,7 +128,27 @@
   }
 
   public static void removeAccesses(String type, Role role) {
-    if ("ALERT".equals(type)) {
+    if ("ORGANIZATION".equals(type)) {
+      removeOrgAccesses(role);
+    } else if ("WINDOW".equals(type)) {
+      removeWindowAccesses(role);
+    } else if ("TAB".equals(type)) {
+      // Remove tab access for Business Partner window
+      removeTabAccesses(role, "Business Partner");
+    } else if ("FIELD".equals(type)) {
+      // Remove field access for header tab of Business Partner window
+      removeFieldAccesses(role, "Business Partner", "Business Partner");
+    } else if ("REPORT".equals(type)) {
+      removeReportAndProcessAccesses(role);
+    } else if ("FORM".equals(type)) {
+      removeFormAccesses(role);
+    } else if ("WIDGET".equals(type)) {
+      removeWidgetClassAccesses(role);
+    } else if ("VIEW".equals(type)) {
+      removeViewImplementationAccesses(role);
+    } else if ("PROCESS".equals(type)) {
+      removeProcessDefinitionAccesses(role);
+    } else if ("ALERT".equals(type)) {
       removeAlertRecipients(role);
     } else if ("PREFERENCE".equals(type)) {
       removePreferences(role);
@@ -226,6 +247,17 @@
     ro.setActive(isActive);
   }
 
+  private static void removeOrgAccesses(Role role) {
+    final OBCriteria<RoleOrganization> obCriteria = OBDal.getInstance().createCriteria(
+        RoleOrganization.class);
+    obCriteria.add(Restrictions.eq(RoleOrganization.PROPERTY_ROLE, role));
+    obCriteria.setFilterOnActive(false);
+    for (RoleOrganization ro : obCriteria.list()) {
+      OBDal.getInstance().remove(ro);
+    }
+    OBDal.getInstance().flush();
+  }
+
   private static String[] getOrgAccessInfo(Role role, String orgName) {
     String result[] = new String[3];
     for (RoleOrganization ro : role.getADRoleOrganizationList()) {
@@ -271,6 +303,17 @@
     wa.setActive(isActive);
   }
 
+  private static void removeWindowAccesses(Role role) {
+    final OBCriteria<WindowAccess> obCriteria = OBDal.getInstance().createCriteria(
+        WindowAccess.class);
+    obCriteria.add(Restrictions.eq(WindowAccess.PROPERTY_ROLE, role));
+    obCriteria.setFilterOnActive(false);
+    for (WindowAccess wa : obCriteria.list()) {
+      OBDal.getInstance().remove(wa);
+    }
+    OBDal.getInstance().flush();
+  }
+
   private static String[] getWindowAccessInfo(Role role, String windowName) {
     String result[] = new String[3];
     for (WindowAccess wa : role.getADWindowAccessList()) {
@@ -351,6 +394,29 @@
     ta.setActive(isActive);
   }
 
+  private static void removeTabAccesses(Role role, String windowName) {
+    final OBCriteria<Window> windowCriteria = OBDal.getInstance().createCriteria(Window.class);
+    windowCriteria.add(Restrictions.eq(Window.PROPERTY_NAME, windowName));
+    windowCriteria.setMaxResults(1);
+    Window window = (Window) windowCriteria.uniqueResult();
+
+    final OBCriteria<WindowAccess> obCriteria = OBDal.getInstance().createCriteria(
+        WindowAccess.class);
+    obCriteria.add(Restrictions.eq(WindowAccess.PROPERTY_ROLE, role));
+    obCriteria.add(Restrictions.eq(WindowAccess.PROPERTY_WINDOW, window));
+    obCriteria.setFilterOnActive(false);
+    WindowAccess wa = (WindowAccess) obCriteria.uniqueResult();
+    List<TabAccess> tabAccessToDelete = new ArrayList<TabAccess>();
+    for (TabAccess ta : wa.getADTabAccessList()) {
+      tabAccessToDelete.add(ta);
+    }
+    for (TabAccess ta : tabAccessToDelete) {
+      wa.getADTabAccessList().remove(ta);
+      OBDal.getInstance().remove(ta);
+    }
+    OBDal.getInstance().flush();
+  }
+
   private static String[] getTabAccessInfo(Role role, String windowName, String tabName) {
     String result[] = new String[3];
     for (WindowAccess wa : role.getADWindowAccessList()) {
@@ -464,6 +530,42 @@
     fa.setActive(isActive);
   }
 
+  private static void removeFieldAccesses(Role role, String windowName, String tabName) {
+    final OBCriteria<Window> windowCriteria = OBDal.getInstance().createCriteria(Window.class);
+    windowCriteria.add(Restrictions.eq(Window.PROPERTY_NAME, windowName));
+    windowCriteria.setMaxResults(1);
+    Window window = (Window) windowCriteria.uniqueResult();
+
+    final OBCriteria<Tab> tabCriteria = OBDal.getInstance().createCriteria(Tab.class);
+    tabCriteria.add(Restrictions.eq(Tab.PROPERTY_WINDOW, window));
+    tabCriteria.add(Restrictions.eq(Tab.PROPERTY_NAME, tabName));
+    tabCriteria.setMaxResults(1);
+    Tab tab = (Tab) tabCriteria.uniqueResult();
+
+    final OBCriteria<WindowAccess> waCriteria = OBDal.getInstance().createCriteria(
+        WindowAccess.class);
+    waCriteria.add(Restrictions.eq(WindowAccess.PROPERTY_ROLE, role));
+    waCriteria.add(Restrictions.eq(WindowAccess.PROPERTY_WINDOW, window));
+    waCriteria.setFilterOnActive(false);
+    WindowAccess wa = (WindowAccess) waCriteria.uniqueResult();
+
+    final OBCriteria<TabAccess> taCriteria = OBDal.getInstance().createCriteria(TabAccess.class);
+    taCriteria.add(Restrictions.eq(TabAccess.PROPERTY_WINDOWACCESS, wa));
+    taCriteria.add(Restrictions.eq(TabAccess.PROPERTY_TAB, tab));
+    taCriteria.setFilterOnActive(false);
+    TabAccess ta = (TabAccess) taCriteria.uniqueResult();
+
+    List<FieldAccess> fieldAccessToDelete = new ArrayList<FieldAccess>();
+    for (FieldAccess fa : ta.getADFieldAccessList()) {
+      fieldAccessToDelete.add(fa);
+    }
+    for (FieldAccess fa : fieldAccessToDelete) {
+      ta.getADFieldAccessList().remove(fa);
+      OBDal.getInstance().remove(fa);
+    }
+    OBDal.getInstance().flush();
+  }
+
   private static String[] getFieldAccessInfo(Role role, String windowName, String tabName,
       String fieldName) {
     String result[] = new String[3];
@@ -518,6 +620,18 @@
     pa.setActive(isActive);
   }
 
+  private static void removeReportAndProcessAccesses(Role role) {
+    final OBCriteria<org.openbravo.model.ad.access.ProcessAccess> obCriteria = OBDal.getInstance()
+        .createCriteria(org.openbravo.model.ad.access.ProcessAccess.class);
+    obCriteria
+        .add(Restrictions.eq(org.openbravo.model.ad.access.ProcessAccess.PROPERTY_ROLE, role));
+    obCriteria.setFilterOnActive(false);
+    for (org.openbravo.model.ad.access.ProcessAccess pa : obCriteria.list()) {
+      OBDal.getInstance().remove(pa);
+    }
+    OBDal.getInstance().flush();
+  }
+
   private static String[] getReportAndProcessAccessInfo(Role role, String reportName) {
     String result[] = new String[3];
     for (org.openbravo.model.ad.access.ProcessAccess pa : role.getADProcessAccessList()) {
@@ -559,6 +673,16 @@
     fa.setActive(isActive);
   }
 
+  private static void removeFormAccesses(Role role) {
+    final OBCriteria<FormAccess> obCriteria = OBDal.getInstance().createCriteria(FormAccess.class);
+    obCriteria.add(Restrictions.eq(FormAccess.PROPERTY_ROLE, role));
+    obCriteria.setFilterOnActive(false);
+    for (FormAccess fa : obCriteria.list()) {
+      OBDal.getInstance().remove(fa);
+    }
+    OBDal.getInstance().flush();
+  }
+
   private static String[] getFormAccessInfo(Role role, String formName) {
     String result[] = new String[3];
     for (FormAccess fa : role.getADFormAccessList()) {
@@ -602,6 +726,17 @@
     wa.setActive(isActive);
   }
 
+  private static void removeWidgetClassAccesses(Role role) {
+    final OBCriteria<WidgetClassAccess> obCriteria = OBDal.getInstance().createCriteria(
+        WidgetClassAccess.class);
+    obCriteria.add(Restrictions.eq(WidgetClassAccess.PROPERTY_ROLE, role));
+    obCriteria.setFilterOnActive(false);
+    for (WidgetClassAccess wa : obCriteria.list()) {
+      OBDal.getInstance().remove(wa);
+    }
+    OBDal.getInstance().flush();
+  }
+
   private static String[] getWidgetAccessInfo(Role role, String widgetTitle) {
     String result[] = new String[3];
     for (WidgetClassAccess wa : role.getOBKMOWidgetClassAccessList()) {
@@ -646,6 +781,17 @@
     va.setActive(isActive);
   }
 
+  private static void removeViewImplementationAccesses(Role role) {
+    final OBCriteria<ViewRoleAccess> obCriteria = OBDal.getInstance().createCriteria(
+        ViewRoleAccess.class);
+    obCriteria.add(Restrictions.eq(ViewRoleAccess.PROPERTY_ROLE, role));
+    obCriteria.setFilterOnActive(false);
+    for (ViewRoleAccess va : obCriteria.list()) {
+      OBDal.getInstance().remove(va);
+    }
+    OBDal.getInstance().flush();
+  }
+
   private static String[] getViewImplementationAccessInfo(Role role, String viewName) {
     String result[] = new String[3];
     for (ViewRoleAccess va : role.getObuiappViewRoleAccessList()) {
@@ -696,6 +842,18 @@
     pa.setActive(isActive);
   }
 
+  private static void removeProcessDefinitionAccesses(Role role) {
+    final OBCriteria<org.openbravo.client.application.ProcessAccess> obCriteria = OBDal
+        .getInstance().createCriteria(org.openbravo.client.application.ProcessAccess.class);
+    obCriteria.add(Restrictions.eq(org.openbravo.client.application.ProcessAccess.PROPERTY_ROLE,
+        role));
+    obCriteria.setFilterOnActive(false);
+    for (org.openbravo.client.application.ProcessAccess pa : obCriteria.list()) {
+      OBDal.getInstance().remove(pa);
+    }
+    OBDal.getInstance().flush();
+  }
+
   private static String[] getProcessDefinitonAccessInfo(Role role, String processName) {
     String result[] = new String[3];
     for (org.openbravo.client.application.ProcessAccess pa : role.getOBUIAPPProcessAccessList()) {
--- a/src-test/src/org/openbravo/test/role/VerticalInheritanceTest.java	Tue Sep 29 12:49:29 2015 +0200
+++ b/src-test/src/org/openbravo/test/role/VerticalInheritanceTest.java	Tue Sep 29 16:09:02 2015 +0200
@@ -65,7 +65,7 @@
   @SuppressWarnings("unchecked")
   private final List<List<String>> ACCESSES = Arrays.asList(ORGANIZATIONS, WINDOWS, TABS, FIELDS,
       REPORTS, FORMS, WIDGETS, VIEWS, PROCESSES, ALERTS, PREFERENCES);
-  private static int counterHorizontalTest = 0;
+  private static int testCounter = 0;
 
   /** defines the values the parameter will take. */
   @Rule
@@ -94,7 +94,7 @@
           RoleInheritanceTestUtils.ASTERISK_ORG_ID, " C", true, false);
       String roleCId = (String) DalUtil.getId(roleC);
 
-      List<String> accesses = ACCESSES.get(counterHorizontalTest);
+      List<String> accesses = ACCESSES.get(testCounter);
       // Add window accesses for template roles
       RoleInheritanceTestUtils.addAccess(parameter, roleA, accesses.get(0));
       RoleInheritanceTestUtils.addAccess(parameter, roleB, accesses.get(1));
@@ -125,7 +125,7 @@
 
       RoleInheritanceTestUtils.removeAccesses(parameter, roleA);
       RoleInheritanceTestUtils.removeAccesses(parameter, roleB);
-      counterHorizontalTest++;
+      testCounter++;
 
     } finally {
       // Delete roles