Fixed ISSUE-43803. Make referencedinventory test auto-skip if AWO is installed.
authorIñigo Lerga <inigo.lerga@openbravo.com>
Mon, 27 Apr 2020 13:03:45 +0200
changeset 37244 19e0f1b700f6
parent 37243 273baf3c5fbc
child 37245 3019c4018e7d
Fixed ISSUE 43803. Make referencedinventory test auto-skip if AWO is installed.

Those test are not compatible with AWO as data they create does not comply with
some new constraint added by AWO.
So far that was required to be handled manually by adding config/disabled-tests
i.e. in every CI job with AWO installed to list the all individual tests here
to skip them.

This issue makes that behavior automatic by checking inside a central base-class
if AWO module is present and skipping the tests themselves (using similar logic
as is used by code for skipping config/disabled-tests from OBBaseTest).
Note that the repeated (per test) calls to isModulePresent are very fast as
that function caches the data inside so no need for caching isAwoInstalled inside
the test-class.
src-test/src/org/openbravo/test/referencedinventory/ReferencedInventoryTest.java
--- a/src-test/src/org/openbravo/test/referencedinventory/ReferencedInventoryTest.java	Wed Apr 15 10:40:05 2020 +0200
+++ b/src-test/src/org/openbravo/test/referencedinventory/ReferencedInventoryTest.java	Mon Apr 27 13:03:45 2020 +0200
@@ -19,8 +19,10 @@
 
 package org.openbravo.test.referencedinventory;
 
+import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.Matchers.equalTo;
 import static org.junit.Assert.assertThat;
+import static org.junit.Assume.assumeThat;
 
 import java.math.BigDecimal;
 
@@ -32,6 +34,7 @@
 import org.junit.rules.ExpectedException;
 import org.openbravo.base.secureApp.VariablesSecureApp;
 import org.openbravo.base.weld.test.WeldBaseTest;
+import org.openbravo.client.kernel.KernelUtils;
 import org.openbravo.client.kernel.RequestContext;
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
@@ -58,8 +61,20 @@
   @Rule
   public ExpectedException thrown = ExpectedException.none();
 
+  private boolean isAwoInstalled() {
+    try {
+      OBContext.setAdminMode(true);
+      return KernelUtils.getInstance().isModulePresent("org.openbravo.warehouse.advancedwarehouseoperations");
+    } finally {
+      OBContext.restorePreviousMode();
+    }
+  }
+
   @Before
   public void initialize() {
+    boolean awoIsInstalled = isAwoInstalled();
+    assumeThat("Auto-Disabled test case as incompatible with AWO (found to be installed) ", awoIsInstalled, is(false));
+
     setUserContext(QA_TEST_ADMIN_USER_ID);
     VariablesSecureApp vsa = new VariablesSecureApp(OBContext.getOBContext().getUser().getId(),
         OBContext.getOBContext().getCurrentClient().getId(),