related to issue 40102: combined admin and cross org modes
authorAsier Lostalé <asier.lostale@openbravo.com>
Wed, 06 Feb 2019 14:36:33 +0100
changeset 35436 7d8efc4cd8e1
parent 35435 e1f91029fa2b
child 35437 25c609294e5e
related to issue 40102: combined admin and cross org modes

Added test case proving it is possible to combine both modes.
src-test/src/org/openbravo/test/security/StandardCrossOrganizationReference.java
--- a/src-test/src/org/openbravo/test/security/StandardCrossOrganizationReference.java	Wed Feb 06 13:17:00 2019 +0100
+++ b/src-test/src/org/openbravo/test/security/StandardCrossOrganizationReference.java	Wed Feb 06 14:36:33 2019 +0100
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2016 Openbravo SLU 
+ * All portions are Copyright (C) 2016-2019 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -19,9 +19,13 @@
 
 package org.openbravo.test.security;
 
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
 import org.junit.Ignore;
 import org.junit.Test;
 import org.openbravo.base.exception.OBSecurityException;
+import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.model.common.enterprise.Warehouse;
 import org.openbravo.model.common.order.Order;
@@ -54,4 +58,24 @@
 
     OBDal.getInstance().commitAndClose();
   }
+
+  @Test
+  public void combinedAdminAndCrossOrgModes() {
+    try {
+      OBContext.setAdminMode(false);
+      assertThat("Admin mode (no cross org)", OBContext.getOBContext().isInAdministratorMode(),
+          is(true));
+      assertThat("No cross org mode (in admin)",
+          OBContext.getOBContext().isInCrossOrgAdministratorMode(), is(false));
+
+      OBContext.setCrossOrgReferenceAdminMode();
+      assertThat("Admin mode (with cross org)", OBContext.getOBContext().isInAdministratorMode(),
+          is(true));
+      assertThat("Cross org mode (in admin)",
+          OBContext.getOBContext().isInCrossOrgAdministratorMode(), is(true));
+    } finally {
+      OBContext.restorePreviousMode();
+      OBContext.restorePreviousCrossOrgReferenceMode();
+    }
+  }
 }