related to issue 26238: added test case
authorAsier Lostalé <asier.lostale@openbravo.com>
Thu, 10 Apr 2014 16:00:55 +0200
changeset 22903 0c61a782148b
parent 22902 876978a97cfe
child 22904 527597db45b8
related to issue 26238: added test case
src-test/org/openbravo/test/AllWebserviceTests.java
src-test/org/openbravo/test/datasource/SelectorFieldPropertySelectorDSTest.java
--- a/src-test/org/openbravo/test/AllWebserviceTests.java	Thu Apr 10 14:34:14 2014 +0200
+++ b/src-test/org/openbravo/test/AllWebserviceTests.java	Thu Apr 10 16:00:55 2014 +0200
@@ -22,6 +22,7 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import org.openbravo.test.datasource.SelectorFieldPropertySelectorDSTest;
 import org.openbravo.test.datasource.TestCSVEncoding;
 import org.openbravo.test.webservice.PerformanceTest;
 import org.openbravo.test.webservice.WSAddRecordWithComputedColumns;
@@ -44,6 +45,7 @@
     suite.addTestSuite(PerformanceTest.class);
     suite.addTestSuite(WSAddRecordWithComputedColumns.class);
     suite.addTestSuite(TestCSVEncoding.class);
+    suite.addTestSuite(SelectorFieldPropertySelectorDSTest.class);
 
     // $JUnit-END$
     return suite;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/datasource/SelectorFieldPropertySelectorDSTest.java	Thu Apr 10 16:00:55 2014 +0200
@@ -0,0 +1,103 @@
+/*
+ *************************************************************************
+ * 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) 2014 Openbravo SLU 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.test.datasource;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONObject;
+
+/**
+ * Tests Property selector datasource. Checking issue #26238 is not reproduced anymore.
+ * 
+ * @author alostale
+ * 
+ */
+public class SelectorFieldPropertySelectorDSTest extends BaseDataSourceTestNoDal {
+  private boolean sysAdminProfileSet = false;
+
+  /**
+   * Performs a request for properties without filtering
+   */
+  public void testFullList() throws Exception {
+    JSONObject resp = executeDSRequest(false);
+
+    System.out.println(resp.toString(2));
+
+    JSONArray data = resp.getJSONArray("data");
+
+    assertTrue("data should contain several values, it has " + data.length(), data.length() > 1);
+    assertTrue("totalRows should be bigger than 1, it is " + resp.getInt("totalRows"),
+        resp.getInt("totalRows") > 1);
+  }
+
+  /**
+   * Performs a request for properties filtering by property "id"
+   */
+  public void testFilter() throws Exception {
+    JSONObject resp = executeDSRequest(true);
+
+    JSONArray data = resp.getJSONArray("data");
+
+    assertEquals("data length", data.length(), 1);
+    assertEquals("totalRows", resp.getInt("totalRows"), 1);
+
+    System.out.println(resp.toString(2));
+  }
+
+  private JSONObject executeDSRequest(boolean filter) throws Exception {
+    if (!sysAdminProfileSet) {
+      changeProfile("0", "192", "0", null);
+      sysAdminProfileSet = true;
+    }
+
+    Map<String, String> params = new HashMap<String, String>();
+
+    // this is how value is sent when in new, regardless typed filter
+    params.put("inpproperty", "null");
+
+    params.put("_operationType", "fetch");
+    params.put("filterClass", "org.openbravo.userinterface.selector.SelectorDataSourceFilter");
+    params.put("_sortBy", "property");
+
+    params.put("inpobuiselSelectorId", "1F051395F1CC4A40ADFE5C440EBCAA7F");
+
+    if (filter) {
+      params.put("operator", "or");
+      params.put("_constructor", "AdvancedCriteria");
+      JSONObject criteria = new JSONObject();
+      criteria.put("fieldName", "property");
+      criteria.put("operator", "iContains");
+      criteria.put("value", "id");
+      params.put("criteria", criteria.toString());
+    }
+
+    JSONObject resp = new JSONObject(doRequest(
+        "/org.openbravo.service.datasource/83B60C4C19AE4A9EBA947B948C5BA04D", params, 200, "POST"));
+
+    assertTrue("expecting response, got: " + resp, resp.has("response"));
+
+    JSONObject r = resp.getJSONObject("response");
+    assertTrue("expecting data in response, got: " + r, r.has("data"));
+
+    return r;
+  }
+}
\ No newline at end of file