Related to issue 33019: test has been refactored due to it no longer creates its
authorAlejandro <alekosmp86@gmail.com>
Fri, 25 Jan 2019 10:32:05 -0500
changeset 8122 302e22d76237
parent 8121 e622205a4015
child 8123 356d3784ba8d
Related to issue 33019: test has been refactored due to it no longer creates its
own sampledata
src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/discountsandpromotions/I33019_VerifyPacksInNaturalTreeOrganization.java
--- a/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/discountsandpromotions/I33019_VerifyPacksInNaturalTreeOrganization.java	Thu Jan 24 14:24:09 2019 -0500
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/discountsandpromotions/I33019_VerifyPacksInNaturalTreeOrganization.java	Fri Jan 25 10:32:05 2019 -0500
@@ -11,38 +11,30 @@
  * 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) 2016 Openbravo S.L.U.
+ * All portions are Copyright (C) 2016-2019 Openbravo S.L.U.
  * All Rights Reserved.
  * Contributor(s):
  ************************************************************************
  */
+
 package org.openbravo.test.mobile.retail.pack.selenium.tests.discountsandpromotions;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.equalTo;
 
-import java.util.UUID;
-
 import org.junit.Test;
 import org.openbravo.test.mobile.core.utils.OBConstants;
 import org.openbravo.test.mobile.core.utils.OBUtils;
 import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperInsertUpdateOrDelete;
 import org.openbravo.test.mobile.retail.mobilecore.javascript.MobileCoreAPI;
-import org.openbravo.test.mobile.retail.mobilecore.javascript.SynchronizationMonitor;
 import org.openbravo.test.mobile.retail.mobilecore.utils.ApplicationWindow;
 import org.openbravo.test.mobile.retail.mobilecore.utils.RetailUtils;
 import org.openbravo.test.mobile.retail.pack.selenium.TestIdPack;
 import org.openbravo.test.mobile.retail.pack.selenium.terminals.WebPOSTerminalHelper;
 
 public class I33019_VerifyPacksInNaturalTreeOrganization extends WebPOSTerminalHelper {
-
-  private final String offerId = getUUID();
+  private final String offerId = "DB155972EDA6446290DDC3FF0387E832";
   private final String offerName = "Vallblanca pack";
-  private final String offerTypeId = "BE5D42E554644B6AA262CCB097753951";
-  private final String avalancheProductId = "934E7D7587EC4C7A9E9FF58F0382D450";
-  private final String insectRepellentProductId = "C1757506CB6B469B8DE4739F04523B7C";
-  private final String clientId = "39363B0921BB4293B48383844325E84C";
-  private final String orgId = "D270A5AC50874F8BA67A88EE977F8E3B"; // vallblanca
 
   @Test
   public void test() {
@@ -52,7 +44,7 @@
     tap(TestIdPack.BUTTON_SEARCH);
     write(TestIdPack.FIELD_SEARCH_TEXT, offerName);
     tap(TestIdPack.BUTTON_SEARCH_EXECUTE);
-    SynchronizationMonitor.waitUntiTheApplicationHasSynchronized();
+    OBUtils.pause(1000);
     logger.info("First count " + TestIdPack.TABLE_SEARCHPRODUCTS.enyoNode().getCountRows());
     assertThat(TestIdPack.TABLE_SEARCHPRODUCTS.enyoNode().getCountRows().toString().equals("1"),
         equalTo(true));
@@ -67,6 +59,7 @@
     tap(TestIdPack.BUTTON_SEARCH);
     write(TestIdPack.FIELD_SEARCH_TEXT, offerName);
     tap(TestIdPack.BUTTON_SEARCH_EXECUTE);
+    OBUtils.pause(1000);
     logger.info("Second count " + TestIdPack.TABLE_SEARCHPRODUCTS.enyoNode().getCountRows());
     assertThat(TestIdPack.TABLE_SEARCHPRODUCTS.enyoNode().getCountRows().toString().equals("0"),
         equalTo(true));
@@ -78,43 +71,20 @@
 
   @Override
   public void beforeWithReload() {
-    final String insertOfferSQL = String
-        .format(
-            "insert into m_offer (m_offer_id,ad_client_id,ad_org_id,isactive,createdby,updatedby,name,addamt,discount,datefrom,"
-                + "bpartner_selection,bp_group_selection,product_selection,prod_cat_selection,pricelist_selection,m_offer_type_id,apply_next,org_selection,ismultiple,"
-                + "characteristics_selection,em_obdisc_distribute,em_obdisc_price,em_obdisc_c_currency_id,em_obdisc_role_selection,"
-                + "em_obdisc_approval_required) values ('%s','%s','%s','Y','100','100','%s',0,0,TO_DATE('2016-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'),"
-                + "'Y','Y','N','Y','Y','%s','Y','Y','N','Y','N',12,'102','Y','N')", offerId,
-            clientId, orgId, offerName, offerTypeId);
-    new DatabaseHelperInsertUpdateOrDelete().execute(insertOfferSQL, 1);
-    final String insertOfferProduct1SQL = String
-        .format(
-            "insert into m_offer_product (m_offer_product_id,ad_client_id,ad_org_id,isactive,createdby,updatedby,m_offer_id,m_product_id,"
-                + "em_obdisc_is_gift,em_obdisc_qty) values(get_uuid(),'%s','%s','Y','100','100','%s','%s','N','2')",
-            clientId, orgId, offerId, avalancheProductId);
-    new DatabaseHelperInsertUpdateOrDelete().execute(insertOfferProduct1SQL, 1);
-    final String insertOfferProduct2SQL = String
-        .format(
-            "insert into m_offer_product (m_offer_product_id,ad_client_id,ad_org_id,isactive,createdby,updatedby,m_offer_id,m_product_id,"
-                + "em_obdisc_is_gift,em_obdisc_qty) values(get_uuid(),'%s','%s','Y','100','100','%s','%s','N','2')",
-            clientId, orgId, offerId, insectRepellentProductId);
-    new DatabaseHelperInsertUpdateOrDelete().execute(insertOfferProduct2SQL, 1);
+    setActiveDiscount(offerId, true);
   }
 
   @Override
   public void afterWithReload() {
-    final String deleteOfferProductSQL = String.format("delete from m_offer_product "
-        + "WHERE m_offer_id = '%s'", offerId);
-    new DatabaseHelperInsertUpdateOrDelete().execute(deleteOfferProductSQL, 2);
-    final String deleteOfferSQL = String.format("delete from m_offer " + "WHERE m_offer_id = '%s'",
-        offerId);
-    new DatabaseHelperInsertUpdateOrDelete().execute(deleteOfferSQL, 1);
+    setActiveDiscount(offerId, false);
   }
 
-  private String getUUID() {
-    String randomUUID = UUID.randomUUID().toString();
-    randomUUID = randomUUID.toUpperCase();
-    return randomUUID.replace("-", "");
+  private void setActiveDiscount(String discountId, boolean active) {
+    String sql = String.format("update m_offer set isactive = '%s' where m_offer_id = '%s'",
+        active ? "Y" : "N", discountId);
+
+    new DatabaseHelperInsertUpdateOrDelete() {
+    }.execute(sql, 1);
   }
 
   private void login(final String newUsername) {