Attached Files | testToReproduce.diff [^] (12,816 bytes) 2019-05-03 08:55 [Show Content] [Hide Content]diff --git a/src-test/org/openbravo/warehouse/advancedwarehouseoperations/test/AWOzzri_HighVolumeRI.java b/src-test/org/openbravo/warehouse/advancedwarehouseoperations/test/AWOzzri_HighVolumeRI.java
new file mode 100644
--- /dev/null
+++ b/src-test/org/openbravo/warehouse/advancedwarehouseoperations/test/AWOzzri_HighVolumeRI.java
@@ -0,0 +1,273 @@
+/*
+ ************************************************************************************
+ * Copyright (C) 2017-2018 Openbravo S.L.U.
+ * Licensed under the Openbravo Commercial License version 1.0
+ * You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
+ * or in the legal folder of this module distribution.
+ ************************************************************************************
+ */
+
+package org.openbravo.warehouse.advancedwarehouseoperations.test;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.hibernate.criterion.Restrictions;
+import org.junit.Before;
+import org.junit.Test;
+import org.openbravo.base.exception.OBException;
+import org.openbravo.base.provider.OBProvider;
+import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.base.weld.test.WeldBaseTest;
+import org.openbravo.client.kernel.RequestContext;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBCriteria;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.materialmgmt.InventoryCountProcess;
+import org.openbravo.model.ad.domain.Preference;
+import org.openbravo.model.common.enterprise.Locator;
+import org.openbravo.model.common.enterprise.Organization;
+import org.openbravo.model.common.enterprise.Warehouse;
+import org.openbravo.model.common.plm.AttributeSet;
+import org.openbravo.model.common.plm.AttributeSetInstance;
+import org.openbravo.model.common.plm.Product;
+import org.openbravo.model.materialmgmt.onhandquantity.ReferencedInventory;
+import org.openbravo.model.materialmgmt.onhandquantity.ReferencedInventoryType;
+import org.openbravo.model.materialmgmt.onhandquantity.StorageDetail;
+import org.openbravo.model.materialmgmt.transaction.InventoryCount;
+import org.openbravo.model.materialmgmt.transaction.InventoryCountLine;
+import org.openbravo.warehouse.advancedwarehouseoperations.centralbroker.CentralBroker;
+import org.openbravo.warehouse.advancedwarehouseoperations.ittalgorithm.PutAwayMoveChangeStatusStorageDetail_ITT;
+import org.openbravo.warehouse.advancedwarehouseoperations.ittalgorithm.implementation.BoxPlannedStorageDetail_ITTAlgorithm;
+import org.openbravo.warehouse.advancedwarehouseoperations.utils.AWOTestUtils;
+import org.openbravo.warehouse.advancedwarehouseoperations.utils.OBAWO_Constants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AWOzzri_HighVolumeRI extends WeldBaseTest {
+
+ private static final Logger log = LoggerFactory.getLogger(AWOzz_HighVolume.class);
+ // AWO Client
+ private static final String CLIENT_ID = "A64C68776B544B0DB59C16456C43E608";
+ // AWO US Organization
+ private static final String US_ORG_ID = "F477B20FCDEB46D897DC5B361B92D95F";
+ // US West Coast Warehouse
+ private static final String US_WEST_COAST_WAREHOUSE_ID = "F66CF439D1EC4ACDBD15A78A6195BCC1";
+ // Food0001 Storage Bin
+ private static final String FOOD001_STORAGEBIN_ID = "7F3D8960E85440DABCB013F827C5528F";
+ // Openbravo User
+ private static final String USER_ID = "100";
+ // AWO Admin Role
+ private static final String ROLE_ID = "4501192AEBEA43FB9782062D043BF4AC";
+ private static final String LANGUAGE_CODE = "en_US";
+ private static final String PRODUCT_WITH_AUM = "888251332E9F42D78956E0A60A02D01A";
+ private static final String DUMMY_DESCRIPTION = "1234";
+ private static final String DISABLE_NO_TASK_CHECK_FOR_INVENTORIES = "OBAWO_DisableNoTaskCheckForInventories";
+
+ protected static final String REFINVTYPE_BIGBOX_ID = "DBF8A70D19334500922AD89A3A7663AF";
+
+ private static final int NUMBER_OF_PRODUCTS = 400;
+
+ private static List<Product> productsWhithoutAttribute;
+ private static List<Product> productsWhithAttribute;
+ private static Map<String, BigDecimal> storageDetailQtyMap;
+ private static Map<String, Map<String, Object>> extraParameters;
+
+ @Before
+ public void initialize() {
+ OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, US_ORG_ID, LANGUAGE_CODE);
+ final OBContext obContext = OBContext.getOBContext();
+ final VariablesSecureApp vars = new VariablesSecureApp(obContext.getUser().getId(),
+ obContext.getCurrentClient().getId(), obContext.getCurrentOrganization().getId(),
+ obContext.getRole().getId(), obContext.getLanguage().getLanguage());
+ RequestContext.get().setVariableSecureApp(vars);
+ }
+
+ /**
+ * This test creates a Purchase Order with 1000 lines and then tests the creation of Tasks for it
+ * with and without the Verbosity Log enabled
+ *
+ * <ul>
+ * <li>1. Create the data</li>
+ * <li>1.1. Create 500 Products with attribute and 500 Products without attribute</li>
+ * <li>1.2. Create two Purchase Orders over the same Products to be used later and process
+ * them</li>
+ * <li>2. Test generation of Tasks without Verbosity Log in first Order. It is done as a separate
+ * test so the times are not mixed with the creation of the data</li>
+ * <li>3. Test generation of Tasks with Verbosity Log in second Order. It is done as a separate
+ * test so the times are not mixed with the creation of the data</li>
+ * </ul>
+ */
+ @Test
+ public void aWOzz001A_GenerateAndProcessPurchaseOrders() {
+ try {
+ OBContext.setAdminMode(true);
+ AttributeSet attributeSet = AWOTestUtils.getNewAttributeSet();
+ productsWhithoutAttribute = getProductsList(null);
+ productsWhithAttribute = getProductsList(attributeSet);
+ InventoryCount inventory = createInventory(attributeSet);
+ processInventory(inventory);
+ } finally {
+ OBContext.restorePreviousMode();
+ }
+ }
+
+ @Test
+ public void aWOzz001B_GenerateAndProcessPurchaseOrders() {
+ final ReferencedInventory refInv = AWOTestUtils.createReferencedInventory(US_ORG_ID,
+ OBDal.getInstance().getProxy(ReferencedInventoryType.class, REFINVTYPE_BIGBOX_ID));
+ storageDetailQtyMap = new HashMap<>();
+ extraParameters = new HashMap<>();
+
+ for (StorageDetail storageDetail : getStorageDetails()) {
+ storageDetailQtyMap.put(storageDetail.getId(), BigDecimal.TEN);
+
+ final Map<String, Object> extraParametersByStorageDetail = new HashMap<>(2);
+ extraParametersByStorageDetail.put(
+ PutAwayMoveChangeStatusStorageDetail_ITT.EXTRAPARAM_LOCATORTOID, FOOD001_STORAGEBIN_ID);
+ extraParametersByStorageDetail
+ .put(BoxPlannedStorageDetail_ITTAlgorithm.EXTRAPARAM_REFINVENTORYID, refInv.getId());
+ extraParameters.put(storageDetail.getId(), extraParametersByStorageDetail);
+ }
+ }
+
+ @Test
+ public void aWOzz001C_GenerateAndProcessPurchaseOrders() throws Exception {
+ CentralBroker.getNewInstance().doTheStuff(StorageDetail.class, storageDetailQtyMap,
+ OBAWO_Constants.ACTION_BOXIN, null, null, extraParameters);
+ }
+
+ private List<Product> getProductsList(AttributeSet attributeSet) {
+ OBContext.setAdminMode();
+ long startTime = System.currentTimeMillis();
+ List<Product> productsList = new ArrayList<Product>();
+ try {
+ for (int i = 0; i < NUMBER_OF_PRODUCTS; i++) {
+ Product product = AWOTestUtils.cloneProduct(PRODUCT_WITH_AUM, "aWOzzri", null);
+ if (attributeSet != null) {
+ product.setAttributeSet(attributeSet);
+ }
+ productsList.add(product);
+ }
+
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ throw new OBException(e);
+ } finally {
+ OBContext.restorePreviousMode();
+ }
+ log.info(String.format("Finished creation of %d products. Elapsed time: %d ms",
+ NUMBER_OF_PRODUCTS, System.currentTimeMillis() - startTime));
+ return productsList;
+ }
+
+ private InventoryCount createInventory(AttributeSet attributeSet) {
+ InventoryCount inventory = OBProvider.getInstance().get(InventoryCount.class);
+ inventory.setOrganization(OBDal.getInstance().get(Organization.class, US_ORG_ID));
+ inventory.setWarehouse(OBDal.getInstance().get(Warehouse.class, US_WEST_COAST_WAREHOUSE_ID));
+ inventory.setName("Test Inventory");
+ inventory.setMovementDate(new Date());
+ OBDal.getInstance().save(inventory);
+ createInventoryLines(inventory, productsWhithoutAttribute, null);
+ createInventoryLines(inventory, productsWhithAttribute, attributeSet);
+ OBDal.getInstance().flush();
+ return inventory;
+ }
+
+ private void createInventoryLines(InventoryCount inventory, List<Product> productList,
+ AttributeSet attributeSet) {
+ for (Product product : productList) {
+ InventoryCountLine inventoryLine = OBProvider.getInstance().get(InventoryCountLine.class);
+ inventoryLine.setOrganization(OBDal.getInstance().get(Organization.class, US_ORG_ID));
+ inventoryLine.setProduct(product);
+ inventoryLine.setStorageBin(OBDal.getInstance().get(Locator.class, FOOD001_STORAGEBIN_ID));
+ inventoryLine.setQuantityCount(BigDecimal.TEN);
+ inventoryLine.setBookQuantity(BigDecimal.ZERO);
+ inventoryLine.setUOM(product.getUOM());
+ inventoryLine.setPhysInventory(inventory);
+ if (attributeSet != null) {
+ AttributeSetInstance attributeSetInstance = getAttributeSetInstance(attributeSet);
+ inventoryLine.setAttributeSetValue(attributeSetInstance);
+ }
+ inventory.getMaterialMgmtInventoryCountLineList().add(inventoryLine);
+ OBDal.getInstance().save(inventoryLine);
+ }
+ }
+
+ private AttributeSetInstance getAttributeSetInstance(AttributeSet attributeSet) {
+ AttributeSetInstance attributeSetInstance = OBProvider.getInstance()
+ .get(AttributeSetInstance.class);
+ attributeSetInstance.setDescription(DUMMY_DESCRIPTION);
+ attributeSetInstance.setAttributeSet(attributeSet);
+ OBDal.getInstance().save(attributeSetInstance);
+ return attributeSetInstance;
+ }
+
+ private void processInventory(InventoryCount inventory) {
+ Preference preference = AWOTestUtils.createPreference(DISABLE_NO_TASK_CHECK_FOR_INVENTORIES);
+ new InventoryCountProcess().processInventory(inventory);
+ deletePreference(preference);
+ }
+
+ private List<StorageDetail> getStorageDetails() {
+ OBCriteria<StorageDetail> obc = OBDal.getInstance().createCriteria(StorageDetail.class);
+ obc.add(Restrictions.or(Restrictions.in(StorageDetail.PROPERTY_PRODUCT, productsWhithAttribute),
+ Restrictions.in(StorageDetail.PROPERTY_PRODUCT, productsWhithoutAttribute)));
+ return obc.list();
+ }
+
+ private void deletePreference(Preference preference) {
+ OBDal.getInstance().remove(preference);
+ }
+ // private OBAWO_User_Verbosity_Log activateVerbosity() {
+ // OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, "0", LANGUAGE_CODE);
+ // OBContext.setAdminMode();
+ // try {
+ // OBAWO_User_Verbosity_Log userVerbosity = OBProvider.getInstance()
+ // .get(OBAWO_User_Verbosity_Log.class);
+ // userVerbosity.setUserContact(OBDal.getInstance().get(User.class, USER_ID));
+ // userVerbosity.setLogLevel(LEVEL_DEBUG);
+ // userVerbosity.setActive(true);
+ // userVerbosity.setLog4java(true);
+ // OBDal.getInstance().save(userVerbosity);
+ // OBDal.getInstance().flush();
+ // return userVerbosity;
+ // } catch (Exception e) {
+ // log.error(e.getMessage(), e);
+ // throw new OBException(e);
+ // } finally {
+ // OBContext.restorePreviousMode();
+ // OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, US_ORG_ID, LANGUAGE_CODE);
+ // }
+ // }
+ //
+ // private void deActivateVerbosity(OBAWO_User_Verbosity_Log userVerbosity) {
+ // if (userVerbosity != null) {
+ // OBDal.getInstance().remove(userVerbosity);
+ // OBDal.getInstance().flush();
+ // }
+ // }
+ //
+ // private void generateReceiptTasks(String orderId) {
+ // OBContext.setAdminMode();
+ // try {
+ // long startTime = System.currentTimeMillis();
+ // // Needs to reload the order object
+ // Order order = OBDal.getInstance().get(Order.class, orderId);
+ // CentralBroker.getNewInstance().doTheStuff(order, OBAWO_Constants.ACTION_RECEIPT, null, null,
+ // null);
+ //
+ // log.info(String.format("Finished generating Receipt Tasks. Elapsed time: %d ms",
+ // System.currentTimeMillis() - startTime));
+ // } catch (Exception e) {
+ // log.error(e.getMessage(), e);
+ // throw new OBException(e);
+ // } finally {
+ // OBContext.restorePreviousMode();
+ // }
+ // }
+}
|