Related to issue 32912: Test added to check the correct behavior when refresh
authorNaroa Iriarte <naroa.iriarte@openbravo.com>
Wed, 11 May 2016 12:28:00 +0200
changeset 29637 641370759303
parent 29636 3ae4e605e43f
child 29638 20100cb9945a
Related to issue 32912: Test added to check the correct behavior when refresh

When the WHERE_AND_FILTER_CLAUSE parameter was an empty string, the
behavior was wrong, it was adding an "and" at the beginning of the
where clause and this was not corret. This behavior has been fixed and this
test has been added to check that the datasource response is now correct.
The parameters used in the datasource of this test are the same paramertes
that where used in the datasource of the child tab of the "Price List" window
after refreshing the browser.
This is to imitate the behavior of refreshing the browser having a child tab opened.
The fact of having these parameters, makes that the WHERE_AND_FILTER_CLAUSE parameter
is the empty string, so we can now check that the request works fine now.
src-test/src/org/openbravo/test/AllWebserviceTests.java
src-test/src/org/openbravo/test/datasource/EmptyStringWhereAndFilterClauseParameter.java
--- a/src-test/src/org/openbravo/test/AllWebserviceTests.java	Tue May 10 10:56:40 2016 +0200
+++ b/src-test/src/org/openbravo/test/AllWebserviceTests.java	Wed May 11 12:28:00 2016 +0200
@@ -33,6 +33,7 @@
 import org.openbravo.test.datasource.TestComboDatasource;
 import org.openbravo.test.datasource.FetchDSNoActiveEntityObjects;
 import org.openbravo.test.datasource.TestNoteDatasource;
+import org.openbravo.test.datasource.EmptyStringWhereAndFilterClauseParameter;
 import org.openbravo.test.security.ExplicitCrossOrganizationReference;
 import org.openbravo.test.datasource.DataSourceSecurity;
 import org.openbravo.test.webservice.JSONWebServices;
@@ -72,6 +73,7 @@
     WSWithNoActiveDalObjects.class, //
     FetchDSNoActiveEntityObjects.class, //
     ExplicitCrossOrganizationReference.class, //
-    DataSourceSecurity.class })
+    DataSourceSecurity.class, //
+    EmptyStringWhereAndFilterClauseParameter.class })
 public class AllWebserviceTests {
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/test/datasource/EmptyStringWhereAndFilterClauseParameter.java	Wed May 11 12:28:00 2016 +0200
@@ -0,0 +1,72 @@
+/*
+ *************************************************************************
+ * 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)2016 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.test.datasource;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.codehaus.jettison.json.JSONException;
+import org.codehaus.jettison.json.JSONObject;
+import org.junit.Test;
+import org.openbravo.service.json.JsonConstants;
+
+/**
+ * This test is for the https://issues.openbravo.com/view.php?id=32912 issue. With these datasource
+ * parameters, the WHERE_AND_FILTER_CLAUSE parameter is the empty string and that was the case that
+ * was failing. This test checks that the request to the datasource is correct and the response is
+ * 0, which is the successful request status.
+ * 
+ * @author Naroa Iriarte
+ * 
+ */
+public class EmptyStringWhereAndFilterClauseParameter extends BaseDataSourceTestDal {
+  private Map<String, String> params;
+
+  public EmptyStringWhereAndFilterClauseParameter() {
+    params = new HashMap<String, String>();
+    params.put("_targetRecordId", "17435FB915B14A93B51F3A6375B12BEE");
+    params.put("_filterByParentProperty", "priceList");
+    params.put("windowId", "146");
+    params.put("tabId", "238");
+    params.put("_operationType", "fetch");
+    params.put("_startRow", "0");
+    params.put("_endRow", "100");
+  }
+
+  @Test
+  public void datasourceRequestStatusShouldBeSuccessful() throws Exception {
+    String datasourceResponse = getDataSourceResponse();
+    JSONObject jsonResponse = new JSONObject(datasourceResponse);
+    assertThat("The request status should be successful.", getStatus(jsonResponse),
+        is(String.valueOf(JsonConstants.RPCREQUEST_STATUS_SUCCESS)));
+  }
+
+  private String getDataSourceResponse() throws Exception {
+    String response = doRequest("/org.openbravo.service.datasource/" + "PricingPriceListVersion",
+        params, 200, "POST");
+    return response;
+  }
+
+  private String getStatus(JSONObject jsonResponse) throws JSONException {
+    return jsonResponse.getJSONObject("response").get("status").toString();
+  }
+}