Fixes issue 33019 :Adding Natural tree organization condtion in discounts pack
authorSilambarasan Sekar <silambarasan@qualiantech.com>
Mon, 30 May 2016 16:35:45 +0530
changeset 5451 380fa1701e86
parent 5450 1b7ef90a9962
child 5452 cb782b89013c
Fixes issue 33019 :Adding Natural tree organization condtion in discounts pack
src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/discountsandpromotions/I33019_VerifyPacksInNaturalTreeOrganization.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/discountsandpromotions/I33019_VerifyPacksInNaturalTreeOrganization.java	Mon May 30 16:35:45 2016 +0530
@@ -0,0 +1,126 @@
+package org.openbravo.test.mobile.retail.pack.selenium.tests.discountsandpromotions;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.util.UUID;
+
+import org.junit.Test;
+import org.openbravo.test.mobile.common.selenium.database.DatabaseHelperInsertUpdateOrDelete;
+import org.openbravo.test.mobile.common.selenium.javascript.TestId;
+import org.openbravo.test.mobile.common.selenium.javascript.APIs.MobileCoreAPI;
+import org.openbravo.test.mobile.common.selenium.terminals.WebPOSTerminalHelper;
+import org.openbravo.test.mobile.common.selenium.utils.ApplicationWindow;
+import org.openbravo.test.mobile.common.selenium.utils.OBConstants;
+import org.openbravo.test.mobile.common.selenium.utils.OBUtils;
+
+public class I33019_VerifyPacksInNaturalTreeOrganization extends WebPOSTerminalHelper {
+
+  private final String offerId = getUUID();
+  private final String offerName = "Vallblanca pack";
+  private final String offerTypeId = "BE5D42E554644B6AA262CCB097753951";
+  private final String avalancheProductId = "934E7D7587EC4C7A9E9FF58F0382D450";
+  private final String insectRepellentProductId = "C1757506CB6B469B8DE4739F04523B7C";
+
+  @Test
+  public void test() {
+    final String VBS1Uri = OBUtils.getCurrentHref();
+    final String PS1Uri = VBS1Uri.replace("VBS1001", "PS-1");
+
+    final String clientId = "39363B0921BB4293B48383844325E84C";
+    final String vallblancaOrgId = "D270A5AC50874F8BA67A88EE977F8E3B";
+
+    boolean isTestSuccessful = false;
+    try {
+      // Change Database
+      changeDatabase(clientId, vallblancaOrgId);
+
+      // Update Terminal
+      updateTerminalAfterDatabaseChange();
+
+      tap(TestId.BUTTON_SEARCH);
+      write(TestId.FIELD_SEARCH_TEXT, offerName);
+      tap(TestId.BUTTON_SEARCH_EXECUTE);
+      assertThat(TestId.TABLE_SEARCHPRODUCTS.enyoNode().getCountRows().toString().equals("1"),
+          equalTo(true));
+      MobileCoreAPI.localStorageClear();
+
+      logOut();
+      // Navigating to PS-1
+      OBUtils.navigate(PS1Uri, ApplicationWindow.LOGIN);
+      login("posets");
+
+      tap(TestId.BUTTON_SEARCH);
+      write(TestId.FIELD_SEARCH_TEXT, offerName);
+      tap(TestId.BUTTON_SEARCH_EXECUTE);
+
+      assertThat(TestId.TABLE_SEARCHPRODUCTS.enyoNode().getCountRows().toString().equals("0"),
+          equalTo(true));
+
+      OBUtils.navigate(VBS1Uri, ApplicationWindow.LOGIN);
+      logIn();
+
+      // Restore Database
+      restoreDatabase();
+
+      // Update Terminal
+      updateTerminalAfterDatabaseChange();
+
+      isTestSuccessful = true;
+    } finally {
+      if (!isTestSuccessful) {
+        restoreDatabase();
+      }
+    }
+  }
+
+  private void changeDatabase(final String clientId, final String orgId) {
+    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','Y','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);
+  }
+
+  private void restoreDatabase() {
+    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);
+  }
+
+  private String getUUID() {
+    String randomUUID = UUID.randomUUID().toString();
+    randomUUID = randomUUID.toUpperCase();
+    return randomUUID.replace("-", "");
+  }
+
+  private void login(final String newUsername) {
+    TestId.LABEL_LOGIN_OPENBRAVOMOBILE.enyoNode().waitUntilIsReady();
+    OBUtils.pause(OBConstants.WAIT_AFTERWEBPOSLOGO);
+    write(TestId.FIELD_LOGIN_USERNAME, newUsername);
+    write(TestId.FIELD_LOGIN_PASSWORD, "openbravo");
+    tap(TestId.BUTTON_LOGIN);
+    OBUtils.pause(OBConstants.WAIT_AFTERSUCCESSFULLOGIN);
+    postLogInActions();
+    verifyThatTheLoginProcessHasEnded();
+  }
+}