Verifies issue 39364: A new ProcessHQLQuery to export Product Characteristic
authorJorge Garcia <jorge.garcia@openbravo.com>
Wed, 31 Oct 2018 15:41:48 +0100
changeset 7845 7788d62800bb
parent 7844 e532425addd5
child 7846 7332422c7429
Verifies issue 39364: A new ProcessHQLQuery to export Product Characteristic
and ProductCharacteristicConf is needed

Added new integration test POSProductChAndConfRequest.
src-test/org/openbravo/test/mobile/retail/pack/webservice/tests/retailapi/POSProductChAndConfRequest.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/retail/pack/webservice/tests/retailapi/POSProductChAndConfRequest.java	Wed Oct 31 15:41:48 2018 +0100
@@ -0,0 +1,138 @@
+/*
+ *************************************************************************
+ * 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 ProductStock request API
+ *
+ * @author JGA
+ */
+public class POSProductChAndConfRequest extends BaseAuthenticatedPOSRequestTest {
+
+  private final String PRODUCT_CH_VALUE_WS = "/org.openbravo.mobile.core.service.jsonrest/org.openbravo.retail.posterminal.master.ProductCharacteristicAndConfiguration";
+  private final String CLIENT_ID = "239363B0921BB4293B48383844325E84C";
+  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 = createProductChAndConfContent(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("The number of expected records is not correct", responseData.length(), equalTo(86));
+    JSONObject firstElementOfJSON = responseData.getJSONObject(0);
+    assertThat(firstElementOfJSON.getString("m_characteristic_name"), equalTo("Material"));
+    assertThat(firstElementOfJSON.getString("m_product_ch_id"),
+        equalTo("0662D4DC118448C7A9D03117C65F804B"));
+    assertThat(firstElementOfJSON.getString("m_ch_value_id"),
+        equalTo("F7C8AC5E38B44E2995412CA0D9010470"));
+    assertThat(firstElementOfJSON.getString("m_product_ch_conf_id"),
+        equalTo("3C843002C3B141338678EA49E1C0E724"));
+    assertThat(firstElementOfJSON.getString("m_ch_value_name"), equalTo("Cotton"));
+    assertThat(firstElementOfJSON.getString("m_characteristic_id"),
+        equalTo("640583BBCEDA4D96A921C61B95C20190"));
+    assertThat(firstElementOfJSON.getLong("m_product_ch_seqno"), equalTo(20L));
+  }
+
+  @Test
+  public void testPOSRequestWithoutOptionalFilter() throws Exception {
+    String body = createProductChAndConfContent(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("The number of expected records is not correct", responseData.length(),
+        equalTo(2793));
+    JSONObject firstElementOfJSON = responseData.getJSONObject(0);
+    assertThat(firstElementOfJSON.getString("m_characteristic_name"), equalTo("Object"));
+    assertThat(firstElementOfJSON.getString("m_product_ch_id"),
+        equalTo("00C36788A1144FA39D97D9A95E00A7B4"));
+    assertThat(firstElementOfJSON.getString("m_ch_value_id"),
+        equalTo("68298CB3870E4E03B79561402611B0D1"));
+    assertThat(firstElementOfJSON.getString("m_product_ch_conf_id"),
+        equalTo("0250D6E78AD7427E94D7985F44DF648C"));
+    assertThat(firstElementOfJSON.getString("m_ch_value_name"), equalTo("Sleeping bags"));
+    assertThat(firstElementOfJSON.getString("m_characteristic_id"),
+        equalTo("D2DB5F7678F1431BAC0F5D754E3706BB"));
+    assertThat(firstElementOfJSON.getLong("m_product_ch_seqno"), equalTo(30L));
+  }
+
+  private String createProductChAndConfContent(String csrf, boolean useOptionalFilter)
+      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("terminalTime", "2018-10-04T08:17:32.088Z");
+    parameters.put("lastId", JSONObject.NULL);
+    JSONObject terminalTimeOffset = new JSONObject();
+    terminalTimeOffset.put("value", -120);
+    terminalTimeOffset.put("type", "long");
+    parameters.put("terminalTimeOffset", terminalTimeOffset);
+    JSONObject overrideDefaultTimeout = new JSONObject();
+    overrideDefaultTimeout.put("value", true);
+    overrideDefaultTimeout.put("type", "boolean");
+    parameters.put("overrideDefaultTimeout", overrideDefaultTimeout);
+    if (useOptionalFilter) {
+      JSONArray filterProductList = new JSONArray();
+      filterProductList.put("02A2FDAA4B3D468AA1C46194F21B94A8");
+      filterProductList.put("967711F04BF6414299A3259CD44C390A");
+      parameters.put("filterProductList", filterProductList);
+    }
+    body.put("parameters", parameters);
+    if (csrf != null) {
+      body.put("csrfToken", csrf);
+    }
+
+    return body.toString();
+  }
+}