Related to issue 39874 : Modified Sample data for Currency Conversion tests
authorRanjith S R <ranjith@qualiantech.com>
Thu, 10 Jan 2019 18:30:26 +0530
changeset 8042 85b3f9db7c06
parent 8041 30df0ae396c3
child 8043 ebf1b4a2b382
Related to issue 39874 : Modified Sample data for Currency Conversion tests

* Following test has been modified to use the Sample data instead of creating it
I33059_VerifyPaymentBasedonConversionRate.java
I33898_VerifyRoundingWhenPayingInForeignCurrency.java
I39103_VerifyPaymentAmountsInDifferentCurrencies.java
src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/payment/I33898_VerifyRoundingWhenPayingInForeignCurrency.java
src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/payment/I39103_VerifyPaymentAmountsInDifferentCurrencies.java
src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/system/I33059_VerifyPaymentBasedonConversionRate.java
--- a/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/payment/I33898_VerifyRoundingWhenPayingInForeignCurrency.java	Thu Jan 10 18:29:57 2019 +0530
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/payment/I33898_VerifyRoundingWhenPayingInForeignCurrency.java	Thu Jan 10 18:30:26 2019 +0530
@@ -35,9 +35,11 @@
 import org.openbravo.test.mobile.retail.pack.selenium.terminals.WebPOSTerminalHelper;
 
 public class I33898_VerifyRoundingWhenPayingInForeignCurrency extends WebPOSTerminalHelper {
-  final static String EUR_TO_USD_CONVERSION_RATE_ID = "46E39B7814844655B88F866211A33E97";
-  final static String USD_TO_EUR_CONVERSION_RATE_ID = "5EB97B28BE0245DB94FCC333B860D78A";
-  final static String PRODUCT_NAME = "Avalanche transceiver";
+  private final String EUR_CURRENCY_ID = "102";
+  private final String USD_CURRENCY_ID = "100";
+  private final String EUR_TO_USD_CONVERSION_RATE_ID = "46E39B7814844655B88F866211A33E97";
+  private final String USD_TO_EUR_CONVERSION_RATE_ID = "5EB97B28BE0245DB94FCC333B860D78A";
+  private final String PRODUCT_NAME = "Avalanche transceiver";
 
   @Test
   public void test() {
@@ -73,29 +75,44 @@
   }
 
   public void beforeWithReload() {
-    setActive(EUR_TO_USD_CONVERSION_RATE_ID, true);
-    setActive(USD_TO_EUR_CONVERSION_RATE_ID, true);
+    disableExistingConversionRate(EUR_CURRENCY_ID, USD_CURRENCY_ID);
+    disableExistingConversionRate(USD_CURRENCY_ID, EUR_CURRENCY_ID);
+    enableConversionRate(EUR_TO_USD_CONVERSION_RATE_ID);
+    enableConversionRate(USD_TO_EUR_CONVERSION_RATE_ID);
   }
 
   public void afterWithReload() {
-    setActive(EUR_TO_USD_CONVERSION_RATE_ID, false);
-    setActive(USD_TO_EUR_CONVERSION_RATE_ID, false);
+    disableExistingConversionRate(EUR_CURRENCY_ID, USD_CURRENCY_ID);
+    disableExistingConversionRate(USD_CURRENCY_ID, EUR_CURRENCY_ID);
+    enableOriginalConversionRate();
   }
 
-  private void setActive(String conversionRateId, boolean active) {
-    String sql = String.format(
-        "update c_conversion_rate set isactive = '%s' where c_conversion_rate_id = '%s'",
-        active ? "Y" : "N", conversionRateId);
-
-    new DatabaseHelperInsertUpdateOrDelete() {
-    }.execute(sql, 1);
+  private void enableConversionRate(final String conversionRateId) {
+    final String sql = String.format("update c_conversion_rate set isactive = '%s' "
+        + "where c_conversion_rate_id = '%s'", "Y", conversionRateId);
+    new DatabaseHelperInsertUpdateOrDelete().execute(sql, 1);
   }
 
-  private void verifyPaymentInBackEnd(String documentNo) {
-    String sql = String
-        .format(
-            "select fps.outstandingamt, fps.amount, fps.paidamt from fin_payment_schedule fps left join c_order o on o.c_order_id = fps.c_order_id "
-                + "where o.documentNo = '%s'", documentNo);
+  private void disableExistingConversionRate(final String currencyFrom, final String currencyTo) {
+    final String sql = String.format("update c_conversion_rate set isactive = 'N' "
+        + "where c_currency_id = '%s' and c_currency_id_to = '%s'", currencyFrom, currencyTo);
+    new DatabaseHelperInsertUpdateOrDelete().execute(sql,
+        DatabaseHelperInsertUpdateOrDelete.UNKNOWN_AFFECTED_ROWS);
+  }
+
+  private void enableOriginalConversionRate() {
+    new DatabaseHelperInsertUpdateOrDelete().execute(String.format(
+        "update c_conversion_rate set isactive = 'Y' where c_conversion_rate_id = '%s'",
+        "8A43908B77844AAEB78FAE4F21023083"), 1);
+    new DatabaseHelperInsertUpdateOrDelete().execute(String.format(
+        "update c_conversion_rate set isactive = 'Y' where c_conversion_rate_id = '%s'",
+        "D6576E0314C643428315CE4A637F331B"), 1);
+  }
+
+  private void verifyPaymentInBackEnd(final String documentNo) {
+    final String sql = String.format("select fps.outstandingamt, fps.amount, fps.paidamt "
+        + "from fin_payment_schedule fps left join c_order o on o.c_order_id = fps.c_order_id "
+        + "where o.documentNo = '%s'", documentNo);
 
     new DatabaseHelperSelect() {
       @Override
--- a/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/payment/I39103_VerifyPaymentAmountsInDifferentCurrencies.java	Thu Jan 10 18:29:57 2019 +0530
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/payment/I39103_VerifyPaymentAmountsInDifferentCurrencies.java	Thu Jan 10 18:30:26 2019 +0530
@@ -29,30 +29,25 @@
 import java.sql.SQLException;
 
 import org.junit.Test;
-import org.openbravo.test.mobile.core.junit.TestAnnotations;
 import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperInsertUpdateOrDelete;
 import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperSelect;
 import org.openbravo.test.mobile.retail.mobilecore.javascript.BackboneHelper;
 import org.openbravo.test.mobile.retail.mobilecore.javascript.SynchronizationMonitor;
-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 I39103_VerifyPaymentAmountsInDifferentCurrencies extends WebPOSTerminalHelper {
-  final static String EUR_CURRENCY_ID = "102";
-  final static String USD_CURRENCY_ID = "100";
-  final static String ACTIVE_EUR_TO_USD_CONVRATE_ID = RetailUtils.getRandomUUID();
-  final static String ACTIVE_USD_TO_EUR_CONVRATE_ID = RetailUtils.getRandomUUID();
-  final static String PRODUCT_NAME = "Avalanche transceiver";
-  final static String CASH_PAYMENTMETHOD_ID = "45A202BF44884F05B8A1BF741E2063B6";
-  final static String CARD_PAYMENTMETHOD_ID = "5A741F883A31408CA3AC097D76AA6D32";
-  final static String USACASH_PAYMENTMETHOD_ID = "45A202BF44884F05B8A1BF741E2063B6";
-  final static String VBS_POSTERMINALTYPE_ID = "E33CC7108BE34DBFB5E00D6D8E5FE3FE";
-
-  static int recordIndex = 0;
+  private final String EUR_CURRENCY_ID = "102";
+  private final String USD_CURRENCY_ID = "100";
+  private final String EUR_TO_USD_CONVERSION_RATE_ID = "7280CD8D381A400FAC902F7C5430BFC1";
+  private final String USD_TO_EUR_CONVERSION_RATE_ID = "3908CE0CC81443CDBF3A48A95A290294";
+  private final String PRODUCT_NAME = "Avalanche transceiver";
+  private final String CASH_PAYMENTMETHOD_ID = "45A202BF44884F05B8A1BF741E2063B6";
+  private final String CARD_PAYMENTMETHOD_ID = "5A741F883A31408CA3AC097D76AA6D32";
+  private final String USACASH_PAYMENTMETHOD_ID = "45A202BF44884F05B8A1BF741E2063B6";
+  private final String VBS_POSTERMINALTYPE_ID = "E33CC7108BE34DBFB5E00D6D8E5FE3FE";
 
   @Test
-  @TestAnnotations(waitFixOf = 39874)
   public void test() {
     // make a sale to ensure there is enough cash to return change
     addProduct(PRODUCT_NAME);
@@ -100,51 +95,39 @@
   public void beforeWithReload() {
     disableExistingConversionRate(EUR_CURRENCY_ID, USD_CURRENCY_ID);
     disableExistingConversionRate(USD_CURRENCY_ID, EUR_CURRENCY_ID);
-    createConversionRate(ACTIVE_EUR_TO_USD_CONVRATE_ID, EUR_CURRENCY_ID, USD_CURRENCY_ID, "1.0",
-        "3.6");
-    createConversionRate(ACTIVE_USD_TO_EUR_CONVRATE_ID, USD_CURRENCY_ID, EUR_CURRENCY_ID, "3.6",
-        "1.0");
+    enableConversionRate(EUR_TO_USD_CONVERSION_RATE_ID);
+    enableConversionRate(USD_TO_EUR_CONVERSION_RATE_ID);
   }
 
   public void afterWithReload() {
-    deactivateConversionRate(ACTIVE_EUR_TO_USD_CONVRATE_ID);
-    deactivateConversionRate(ACTIVE_USD_TO_EUR_CONVRATE_ID);
+    disableExistingConversionRate(EUR_CURRENCY_ID, USD_CURRENCY_ID);
+    disableExistingConversionRate(USD_CURRENCY_ID, EUR_CURRENCY_ID);
+    enableOriginalConversionRate();
   }
 
-  private void createConversionRate(String conversionRateId, String currencyIdFrom,
-      String currencyIdTo, String multiplyRate, String divideRate) {
-    String clientId = BackboneHelper.getTerminalValue("client");
-    String sql = String
-        .format(
-            "insert into c_conversion_rate (c_conversion_rate_id, ad_client_id, ad_org_id, createdby, updatedby, validfrom, "
-                + "multiplyrate, dividerate, c_currency_id, c_currency_id_to, conversionratetype) values ('%s', '%s', '0', "
-                + "'0', '0', TRUNC(TO_DATE(NOW()) - interval '1' day), '%s', '%s', '%s', '%s', 'S')",
-            conversionRateId, clientId, multiplyRate, divideRate, currencyIdFrom, currencyIdTo);
-
-    new DatabaseHelperInsertUpdateOrDelete() {
-    }.execute(sql, 1);
+  private void enableConversionRate(final String conversionRateId) {
+    final String sql = String.format("update c_conversion_rate set isactive = '%s' "
+        + "where c_conversion_rate_id = '%s'", "Y", conversionRateId);
+    new DatabaseHelperInsertUpdateOrDelete().execute(sql, 1);
   }
 
-  private void deactivateConversionRate(String conversionRateId) {
-    String sql = String.format(
-        "update c_conversion_rate set isactive = 'N' where c_conversion_rate_id = '%s'",
-        conversionRateId);
-
-    new DatabaseHelperInsertUpdateOrDelete() {
-    }.execute(sql, 1);
+  private void disableExistingConversionRate(final String currencyFrom, final String currencyTo) {
+    final String sql = String.format("update c_conversion_rate set isactive = 'N' "
+        + "where c_currency_id = '%s' and c_currency_id_to = '%s'", currencyFrom, currencyTo);
+    new DatabaseHelperInsertUpdateOrDelete().execute(sql,
+        DatabaseHelperInsertUpdateOrDelete.UNKNOWN_AFFECTED_ROWS);
   }
 
-  private void disableExistingConversionRate(String currencyFrom, String currencyTo) {
-    String sql = String
-        .format(
-            "update c_conversion_rate set isactive = 'N' where c_currency_id = '%s' and c_currency_id_to = '%s' and validfrom = to_date(trunc(now())) - interval '2' day",
-            currencyFrom, currencyTo);
-
-    new DatabaseHelperInsertUpdateOrDelete() {
-    }.execute(sql, 1);
+  private void enableOriginalConversionRate() {
+    new DatabaseHelperInsertUpdateOrDelete().execute(String.format(
+        "update c_conversion_rate set isactive = 'Y' where c_conversion_rate_id = '%s'",
+        "8A43908B77844AAEB78FAE4F21023083"), 1);
+    new DatabaseHelperInsertUpdateOrDelete().execute(String.format(
+        "update c_conversion_rate set isactive = 'Y' where c_conversion_rate_id = '%s'",
+        "D6576E0314C643428315CE4A637F331B"), 1);
   }
 
-  private void addProduct(String productName) {
+  private void addProduct(final String productName) {
     // add a product
     tap(TestIdPack.BUTTON_SEARCH);
     write(TestIdPack.FIELD_SEARCH_TEXT, productName);
@@ -153,20 +136,23 @@
     tap(TestIdPack.BUTTON_SEARCHPRODUCT_FIRSTROW);
   }
 
-  private void verifyPaymentDetailsInBackend(String documentNo) {
-    String sql = String
-        .format(
-            "select pt.fin_paymentmethod_id, fp.amount, pt.c_currency_id from obpos_app_payment_type pt "
-                + "left join fin_payment fp on pt.fin_paymentmethod_id = fp.fin_paymentmethod_id "
-                + "left join fin_payment_detail fpd on fp.fin_payment_id = fpd.fin_payment_id "
-                + "left join fin_payment_scheduledetail fpsd on fpd.fin_payment_detail_id = fpsd.fin_payment_detail_id "
-                + "left join fin_payment_schedule fps on fpsd.fin_payment_schedule_order = fps.fin_payment_schedule_id "
-                + "left join c_order o on fps.c_order_id = o.c_order_id "
-                + "where o.documentno = '%s' " + "and pt.obpos_terminaltype_id = '%s' "
-                + "and pt.c_currency_id = '%s' " + "order by fp.amount", documentNo,
-            VBS_POSTERMINALTYPE_ID, EUR_CURRENCY_ID);
+  private void verifyPaymentDetailsInBackend(final String documentNo) {
+    final String sql = String.format("select pt.fin_paymentmethod_id, fp.amount, pt.c_currency_id "
+        + "from obpos_app_payment_type pt "
+        + "left join fin_payment fp on pt.fin_paymentmethod_id = fp.fin_paymentmethod_id "
+        + "left join fin_payment_detail fpd on fp.fin_payment_id = fpd.fin_payment_id "
+        + "left join fin_payment_scheduledetail fpsd "
+        + "on fpd.fin_payment_detail_id = fpsd.fin_payment_detail_id "
+        + "left join fin_payment_schedule fps "
+        + "on fpsd.fin_payment_schedule_order = fps.fin_payment_schedule_id "
+        + "left join c_order o on fps.c_order_id = o.c_order_id "
+        + "where o.documentno = '%s' and pt.obpos_terminaltype_id = '%s' "
+        + "and pt.c_currency_id = '%s' order by fp.amount", documentNo, VBS_POSTERMINALTYPE_ID,
+        EUR_CURRENCY_ID);
 
     new DatabaseHelperSelect() {
+      int recordIndex = 0;
+
       @Override
       protected void yieldResultSet(ResultSet rs) throws SQLException {
         String paymentMethodId = rs.getString(1);
--- a/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/system/I33059_VerifyPaymentBasedonConversionRate.java	Thu Jan 10 18:29:57 2019 +0530
+++ b/src-test/org/openbravo/test/mobile/retail/pack/selenium/tests/system/I33059_VerifyPaymentBasedonConversionRate.java	Thu Jan 10 18:30:26 2019 +0530
@@ -23,14 +23,14 @@
 
 import org.junit.Test;
 import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperInsertUpdateOrDelete;
-import org.openbravo.test.mobile.retail.mobilecore.javascript.BackboneHelper;
-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 I33059_VerifyPaymentBasedonConversionRate extends WebPOSTerminalHelper {
-  private String strConvertionRate1 = null;
-  private String strConvertionRate2 = null;
+  private final String EUR_CURRENCY_ID = "102";
+  private final String USD_CURRENCY_ID = "100";
+  private final String EUR_TO_USD_CONVERSION_RATE_ID = "8C5CE2E4319B4DD9966F772811FD1019";
+  private final String USD_TO_EUR_CONVERSION_RATE_ID = "00CC4ABB31EC4C899A8336C81709621D";
 
   @Test
   public void test() {
@@ -49,52 +49,38 @@
     verify(TestIdPack.LABEL_TOTALTOPAY, "0.00");
   }
 
-  @Override
   public void beforeWithReload() {
-    deactivateConversionRate(true);
-    createConversionRate(true);
+    disableExistingConversionRate(EUR_CURRENCY_ID, USD_CURRENCY_ID);
+    disableExistingConversionRate(USD_CURRENCY_ID, EUR_CURRENCY_ID);
+    enableConversionRate(EUR_TO_USD_CONVERSION_RATE_ID);
+    enableConversionRate(USD_TO_EUR_CONVERSION_RATE_ID);
   }
 
-  @Override
   public void afterWithReload() {
-    createConversionRate(false);
-    deactivateConversionRate(false);
+    disableExistingConversionRate(EUR_CURRENCY_ID, USD_CURRENCY_ID);
+    disableExistingConversionRate(USD_CURRENCY_ID, EUR_CURRENCY_ID);
+    enableOriginalConversionRate();
   }
 
-  private void deactivateConversionRate(final boolean isForTest) {
-    new DatabaseHelperInsertUpdateOrDelete().execute(String.format(
-        "update c_conversion_rate set isactive = '%s' where c_conversion_rate_id = '%s'",
-        isForTest ? "N" : "Y", "8A43908B77844AAEB78FAE4F21023083"), 1);
-    new DatabaseHelperInsertUpdateOrDelete().execute(String.format(
-        "update c_conversion_rate set isactive = '%s' where c_conversion_rate_id = '%s'",
-        isForTest ? "N" : "Y", "D6576E0314C643428315CE4A637F331B"), 1);
+  private void enableConversionRate(final String conversionRateId) {
+    final String sql = String.format("update c_conversion_rate set isactive = '%s' "
+        + "where c_conversion_rate_id = '%s'", "Y", conversionRateId);
+    new DatabaseHelperInsertUpdateOrDelete().execute(sql, 1);
   }
 
-  private void createConversionRate(final boolean isForTest) {
-    if (isForTest) {
-      strConvertionRate1 = RetailUtils.getRandomUUID();
-      strConvertionRate2 = RetailUtils.getRandomUUID();
+  private void disableExistingConversionRate(final String currencyFrom, final String currencyTo) {
+    final String sql = String.format("update c_conversion_rate set isactive = 'N' "
+        + "where c_currency_id = '%s' and c_currency_id_to = '%s'", currencyFrom, currencyTo);
+    new DatabaseHelperInsertUpdateOrDelete().execute(sql,
+        DatabaseHelperInsertUpdateOrDelete.UNKNOWN_AFFECTED_ROWS);
+  }
 
-      final String clientId = BackboneHelper.getTerminalValue("client");
-      final String sqlInsert1 = String
-          .format(
-              "INSERT INTO c_conversion_rate(c_conversion_rate_id, ad_client_id, ad_org_id, createdby, updatedby, c_currency_id, c_currency_id_to, validfrom, validto, conversionratetype, multiplyrate, dividerate) "
-                  + "VALUES ('%s', '%s', '0', '100', '100', '102', '100', TO_DATE('2016-06-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), TO_DATE('9999-12-31 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'S', 0.05458, 18.3217) ",
-              strConvertionRate1, clientId);
-      final String sqlInsert2 = String
-          .format(
-              "INSERT INTO c_conversion_rate(c_conversion_rate_id, ad_client_id, ad_org_id, createdby, updatedby, c_currency_id, c_currency_id_to, validfrom, validto, conversionratetype, multiplyrate, dividerate) "
-                  + "VALUES ('%s', '%s', '0', '100', '100', '100', '102', TO_DATE('2016-06-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), TO_DATE('9999-12-31 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'S', 18.3217, 0.05458) ",
-              strConvertionRate2, clientId);
-      new DatabaseHelperInsertUpdateOrDelete().execute(sqlInsert1, 1);
-      new DatabaseHelperInsertUpdateOrDelete().execute(sqlInsert2, 1);
-    } else {
-      new DatabaseHelperInsertUpdateOrDelete().execute(String.format(
-          "update c_conversion_rate set isactive = 'N' where c_conversion_rate_id = '%s'",
-          strConvertionRate1), 1);
-      new DatabaseHelperInsertUpdateOrDelete().execute(String.format(
-          "update c_conversion_rate set isactive = 'N' where c_conversion_rate_id = '%s'",
-          strConvertionRate2), 1);
-    }
+  private void enableOriginalConversionRate() {
+    new DatabaseHelperInsertUpdateOrDelete().execute(String.format(
+        "update c_conversion_rate set isactive = 'Y' where c_conversion_rate_id = '%s'",
+        "8A43908B77844AAEB78FAE4F21023083"), 1);
+    new DatabaseHelperInsertUpdateOrDelete().execute(String.format(
+        "update c_conversion_rate set isactive = 'Y' where c_conversion_rate_id = '%s'",
+        "D6576E0314C643428315CE4A637F331B"), 1);
   }
 }
\ No newline at end of file