Verifies issue 39368: Refactor the ProductCharacteristicValue
authorJorge Garcia <jorge.garcia@openbravo.com>
Mon, 22 Oct 2018 12:11:19 +0200
changeset 7818 e909b79a9017
parent 7817 546f5d958630
child 7819 c7bf550b7c4c
Verifies issue 39368: Refactor the ProductCharacteristicValue
ProcessHQLQuery to filter by m_product_id

Added test POSProductCharacteristicValueOptionalFiltering
src-test/org/openbravo/test/mobile/retail/pack/webservice/tests/retailapi/POSProductCharacteristicValueOptionalFiltering.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/mobile/retail/pack/webservice/tests/retailapi/POSProductCharacteristicValueOptionalFiltering.java	Mon Oct 22 12:11:19 2018 +0200
@@ -0,0 +1,113 @@
+/*
+ *************************************************************************
+ * 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 POSProductCharacteristicValueOptionalFiltering extends BaseAuthenticatedPOSRequestTest {
+
+  private final String PRODUCT_CH_VALUE_WS = "/org.openbravo.mobile.core.service.jsonrest/org.openbravo.retail.posterminal.master.ProductCharacteristicValue";
+  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 = createCProductChValueContent(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(10));
+  }
+
+  @Test
+  public void testPOSRequestWithoutOptionalFilter() throws Exception {
+    String body = createCProductChValueContent(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(488));
+  }
+
+  private String createCProductChValueContent(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("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 (generateOptionalFilters) {
+      JSONArray filterProductList = new JSONArray();
+      filterProductList.put("33BB32422F514223ADA6D2F4240A208A");
+      filterProductList.put("E48BE3598A5F426CAA4ACBEC6C469DDC");
+      parameters.put("filterProductList", filterProductList);
+    }
+    body.put("parameters", parameters);
+    if (csrf != null) {
+      body.put("csrfToken", csrf);
+    }
+
+    return body.toString();
+  }
+}