Related to issue 39927: added automated test
authorAlejandro <alekosmp86@gmail.com>
Mon, 04 Feb 2019 12:25:19 -0500
changeset 8182 0c1f20753d47
parent 8181 d4c923b71034
child 8183 8b45857a0966
Related to issue 39927: added automated test
src-test/org/openbravo/test/mobile/awo/tests/Scan/AWO_IncreaseProductQtyByScanningUPC_GTIN.java
src-test/org/openbravo/test/mobile/awo/tests/Scan/AllAWOScanSuite.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/awo/tests/Scan/AWO_IncreaseProductQtyByScanningUPC_GTIN.java	Mon Feb 04 12:25:19 2019 -0500
@@ -0,0 +1,202 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.0  (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 S.L.U.
+ * All portions are Copyright (C) 2019 Openbravo S.L.U.
+ * All Rights Reserved.
+ * Contributor(s):
+ ************************************************************************
+ *
+ * @author alekos
+ *
+ */
+
+package org.openbravo.test.mobile.awo.tests.Scan;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.codec.binary.StringUtils;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.openbravo.test.mobile.awo.utilities.AWOTerminalHelper;
+import org.openbravo.test.mobile.awo.utilities.AWO_Utils;
+import org.openbravo.test.mobile.awo.utilities.TestIdAwo;
+import org.openbravo.test.mobile.core.selenium.SeleniumHelper;
+import org.openbravo.test.mobile.core.utils.OBUtils;
+import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperInsertUpdateOrDelete;
+import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperSelect.RecordsCount;
+import org.openbravo.test.mobile.retail.mobilecore.selenium.TestIdConstructor;
+import org.openbravo.test.mobile.retail.mobilecore.utils.ApplicationWindow;
+import org.openqa.selenium.Keys;
+
+public class AWO_IncreaseProductQtyByScanningUPC_GTIN extends AWOTerminalHelper {
+  final static String PRODUCT_ID = "5F2A1FB78CDF49B2B79322174FE6FCD3";
+  final static String BPARTNER_ID = "B25CC29857CE45B090DB01C3EB357BA0";
+  final static String UPC_CODE = "12345";
+  final static String GTIN_CODE = "67890";
+  static ArrayList<Map<String, String>> dataset = new ArrayList<Map<String, String>>();
+  static Map<String, String> tasksData = new HashMap<String, String>();
+
+  static {
+    tasksData.put("qty", "1");
+    tasksData.put("aum", "PK ");
+    dataset.add(tasksData);
+
+    tasksData = new HashMap<String, String>();
+    tasksData.put("qty", "2");
+    tasksData.put("aum", "Ud ");
+    dataset.add(tasksData);
+  }
+
+  JSONArray orderLines = new JSONArray();
+
+  @Override
+  @Before
+  public void before() {
+    super.before();
+    try {
+      setProductUPC_GTIN(PRODUCT_ID, UPC_CODE, GTIN_CODE);
+
+      JSONObject line1 = new JSONObject();
+      line1.put("productId", PRODUCT_ID);
+      line1.put("productQty", 7);
+      orderLines.put(line1);
+      createOrder(ORDER_PROCESSOR_CLASS, false, BPARTNER_ID, orderLines, true);
+    } catch (JSONException e) {
+      AWOTerminalHelper.logger.error("error generating Order");
+    }
+  }
+
+  @Test
+  public void test() {
+    String documentNo = getOrderDocNo();
+
+    // Generate "Receive" task
+    generateReceiptTasks(documentNo);
+    waitForRecordsToRenderInList(TestIdAwo.INDIVIDUAL_TASKS_LIST, 1, RecordsCount.SAME_AS_EXPECTED);
+    String idtest = getElementIdtestByOffset(TestIdAwo.INDIVIDUAL_TASKS_LIST, 0);
+    TestIdConstructor grouped_task1 = new TestIdConstructor(idtest);
+    verifyTaskType(grouped_task1, "GR");
+    tap(grouped_task1);
+
+    // verify there are 2 lines
+    TestIdAwo.GROUPEDTASKSLIST.enyoNode().waitUntilIsReady();
+    Long numOfTasksInTheGroup = getListCount(TestIdAwo.GROUPEDTASKSLIST);
+    assertThat("Number of task available in the group is not the expected",
+        numOfTasksInTheGroup == 2);
+
+    // select first line and verify UOM is Pack (PK)
+    idtest = getElementIdtestByOffset(TestIdAwo.GROUPEDTASK_TASKSLIST, 0);
+    TestIdConstructor task_row1 = new TestIdConstructor(idtest);
+    // verify the task's data is part of the expected data
+    assertThat("Wrong task's data",
+        verifyTasksData(getTaskExpectedQty(task_row1), getTaskUOM(task_row1)));
+
+    // select second line and verify UOM is Unit (Ud)
+    idtest = getElementIdtestByOffset(TestIdAwo.GROUPEDTASK_TASKSLIST, 1);
+    TestIdConstructor task_row2 = new TestIdConstructor(idtest);
+    // verify the task's data is part of the expected data
+    assertThat("Wrong task's data",
+        verifyTasksData(getTaskExpectedQty(task_row2), getTaskUOM(task_row2)));
+
+    OBUtils.pause(1000);
+    // write UPC code and verify the quantity is increase in line 2
+    SeleniumHelper.pressKey(Keys.NUMPAD1);
+    SeleniumHelper.pressKey(Keys.NUMPAD2);
+    SeleniumHelper.pressKey(Keys.NUMPAD3);
+    SeleniumHelper.pressKey(Keys.NUMPAD4);
+    SeleniumHelper.pressKey(Keys.NUMPAD5);
+    SeleniumHelper.pressKey(Keys.ENTER);
+    verify(TestIdAwo.INDIVIDUAL_TASKS_CONFIRMED_QTY, "3");
+    verify(TestIdAwo.CONFIRMED_QUANTITY_UOM, "Ud ");
+    tap(TestIdAwo.TASK_CONFIRMED_QTYMINUS_BUTTON);
+
+    OBUtils.pause(1000);
+    // write GTIN code and verify the quantity is increased in line 1
+    SeleniumHelper.pressKey(Keys.NUMPAD6);
+    SeleniumHelper.pressKey(Keys.NUMPAD7);
+    SeleniumHelper.pressKey(Keys.NUMPAD8);
+    SeleniumHelper.pressKey(Keys.NUMPAD9);
+    SeleniumHelper.pressKey(Keys.NUMPAD0);
+    SeleniumHelper.pressKey(Keys.ENTER);
+    TestIdConstructor task1Qty = new TestIdConstructor(
+        "renderGroupedTask2_standardTaskView_taskQtyViewer_confirmedQty");
+    verify(task1Qty, "2");
+    verify(TestIdAwo.CONFIRMED_QUANTITY_UOM, "PK ");
+    tap(TestIdAwo.TASK_CONFIRMED_QTYMINUS_BUTTON);
+
+    String batchOfTasksId = getCurrentGroupedTaskProperty("batchOfTasks");
+
+    // confirm the tasks
+    tap(TestIdAwo.GROUPEDTASK_CONFIRMGROUP_BUTTON);
+    // Wait until main window is loaded
+    waitUntilCertainWindowIsReached(ApplicationWindow.AWO_TASKS);
+    // check the tasks are confirmed in bbdd
+    AWO_Utils.checkTasksStatusByBatchOfTasks(batchOfTasksId, 2);
+  }
+
+  @Override
+  @After
+  public void after() {
+    restoreProductUPC_GTIN(PRODUCT_ID);
+    super.after();
+  }
+
+  private void setProductUPC_GTIN(String productId, String upc_code, String gtin_code) {
+    String sql = String.format("update m_product set upc = '%s' where m_product_id = '%s'",
+        upc_code, productId);
+
+    new DatabaseHelperInsertUpdateOrDelete() {
+    }.execute(sql, 1);
+
+    sql = String.format("update m_product_aum set gtin = '%s' where m_product_id = '%s'", gtin_code,
+        productId);
+
+    new DatabaseHelperInsertUpdateOrDelete() {
+    }.execute(sql, 1);
+  }
+
+  private void restoreProductUPC_GTIN(String productId) {
+    String sql = String.format("update m_product set upc = NULL where m_product_id = '%s'",
+        productId);
+
+    new DatabaseHelperInsertUpdateOrDelete() {
+    }.execute(sql, 1);
+
+    sql = String.format("update m_product_aum set gtin = NULL where m_product_id = '%s'",
+        productId);
+
+    new DatabaseHelperInsertUpdateOrDelete() {
+    }.execute(sql, 1);
+  }
+
+  boolean verifyTasksData(String quantity, String aum) {
+    boolean found = false;
+    for (int i = 0; i < dataset.size(); i++) {
+      if (StringUtils.equals(quantity, dataset.get(i).get("qty"))
+          && StringUtils.equals(aum, dataset.get(i).get("aum"))) {
+        found = true;
+        break;
+      }
+    }
+
+    return found;
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/awo/tests/Scan/AllAWOScanSuite.java	Mon Feb 04 12:25:19 2019 -0500
@@ -0,0 +1,32 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.0  (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 S.L.U.
+ * All portions are Copyright (C) 2008-2015 Openbravo S.L.U.
+ * All Rights Reserved.
+ * Contributor(s):
+ ************************************************************************
+ *
+ * @author RAL
+ *
+ */
+
+package org.openbravo.test.mobile.awo.tests.Scan;
+
+import org.junit.runner.RunWith;
+import org.openbravo.test.mobile.core.junit.toolbox.SuiteClassesToolbox;
+import org.openbravo.test.mobile.retail.mobilecore.junit.OBWildcardPatternSuite;
+
+@RunWith(OBWildcardPatternSuite.class)
+@SuiteClassesToolbox()
+public class AllAWOScanSuite {
+}