Verifies issue 39371: Refactor the DiscountFilterCharacteristic ProcessHQLQuery
authorJorge Garcia <jorge.garcia@openbravo.com>
Fri, 26 Oct 2018 10:29:44 +0200
changeset 7827 42daa4db6754
parent 7826 7700af0b187e
child 7828 289114c91b80
Verifies issue 39371: Refactor the DiscountFilterCharacteristic ProcessHQLQuery
to filter by m_offer_id

Added new test.
src-test/org/openbravo/test/mobile/retail/pack/webservice/tests/retailapi/POSDiscountFilterCharacteristicOptionalFiltering.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/retail/pack/webservice/tests/retailapi/POSDiscountFilterCharacteristicOptionalFiltering.java	Fri Oct 26 10:29:44 2018 +0200
@@ -0,0 +1,108 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (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 SLU
+ * All portions are Copyright (C) 2018 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.test.mobile.retail.pack.webservice.tests.retailapi;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.fail;
+
+import java.net.HttpURLConnection;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.junit.Test;
+import org.openbravo.test.mobile.retail.pack.webservice.baseIntegration.BaseAuthenticatedPOSRequestTest;
+
+/**
+ * Checks ProductCharacteristicValue request API
+ *
+ * @author JGA
+ */
+public class POSDiscountFilterCharacteristicOptionalFiltering extends
+    BaseAuthenticatedPOSRequestTest {
+
+  private final String PRODUCT_CH_VALUE_WS = "/org.openbravo.mobile.core.service.jsonrest/org.openbravo.retail.posterminal.master.DiscountFilterCharacteristic";
+  private final String CLIENT_ID = "39363B0921BB4293B48383844325E84C";
+  private final String ORG_ID = "D270A5AC50874F8BA67A88EE977F8E3B";
+  private final String POSTERMINAL_ID = "9104513C2D0741D4850AE8493998A7C8";
+  private final String POSTERMINAL_NAME = "VBS-1";
+  private final String APP_NAME = "WebPOS";
+
+  @Test
+  public void testPOSRequestWithOptionalFilter() throws Exception {
+    String body = createDiscountFilterCharacteristicContent(getSessionCsrfToken(), true);
+    String response = doGetRequest(PRODUCT_CH_VALUE_WS, body, HttpURLConnection.HTTP_OK,
+        CONTENT_TYPE_JSON);
+    JSONObject responseJSON = new JSONObject(response).getJSONObject("response");
+    if (responseJSON.getInt("status") == -1) {
+      JSONObject errorObject = responseJSON.getJSONObject("error");
+      fail(errorObject.getString("message"));
+    }
+    JSONArray responseData = responseJSON.getJSONArray("data");
+    assertThat(responseData.length(), equalTo(1));
+  }
+
+  @Test
+  public void testPOSRequestWithoutOptionalFilter() throws Exception {
+    String body = createDiscountFilterCharacteristicContent(getSessionCsrfToken(), false);
+    String response = doGetRequest(PRODUCT_CH_VALUE_WS, body, HttpURLConnection.HTTP_OK,
+        CONTENT_TYPE_JSON);
+    JSONObject responseJSON = new JSONObject(response).getJSONObject("response");
+    if (responseJSON.getInt("status") == -1) {
+      JSONObject errorObject = responseJSON.getJSONObject("error");
+      fail(errorObject.getString("message"));
+    }
+    JSONArray responseData = responseJSON.getJSONArray("data");
+    assertThat(responseData.length(), equalTo(1));
+  }
+
+  private String createDiscountFilterCharacteristicContent(String csrf,
+      boolean generateOptionalFilters) throws JSONException {
+    JSONObject body = new JSONObject();
+    body.put("_limit", 10000);
+    body.put("_offset", 0);
+    body.put("_count", 0);
+    body.put("_isMasterdata", true);
+    body.put("client", CLIENT_ID);
+    body.put("organization", ORG_ID);
+    body.put("pos", POSTERMINAL_ID);
+    body.put("terminalName", POSTERMINAL_NAME);
+    body.put("appName", APP_NAME);
+    body.put("timeout", 100000);
+    // Parameters JSON Object
+    JSONObject parameters = new JSONObject();
+    parameters.put("lastId", JSONObject.NULL);
+    JSONObject overrideDefaultTimeout = new JSONObject();
+    overrideDefaultTimeout.put("value", true);
+    overrideDefaultTimeout.put("type", "boolean");
+    parameters.put("overrideDefaultTimeout", overrideDefaultTimeout);
+    if (generateOptionalFilters) {
+      JSONArray filterPromotionList = new JSONArray();
+      filterPromotionList.put("C577BB5A5FAB44F28B1C9C6EFE981458");
+      parameters.put("filterPromotionList", filterPromotionList);
+    }
+    body.put("parameters", parameters);
+    if (csrf != null) {
+      body.put("csrfToken", csrf);
+    }
+
+    return body.toString();
+  }
+}