details: https://code.openbravo.com/erp/devel/pi/rev/8436dc079363
changeset: 22840:8436dc079363
user: Guillermo Gil <guillermo.gil <at> openbravo.com>
date: Tue Apr 08 08:50:38 2014 +0200
summary: Related to issue 26162: Added test case for CSV Encoding
diffstat:
src-test/org/openbravo/test/AllWebserviceTests.java | 2 +
src-test/org/openbravo/test/datasource/TestCSVEncoding.java | 135 ++++++++++++
2 files changed, 137 insertions(+), 0 deletions(-)
diffs (159 lines):
diff -r 71901bedc91a -r 8436dc079363
src-test/org/openbravo/test/AllWebserviceTests.java
--- a/src-test/org/openbravo/test/AllWebserviceTests.java Mon Apr 07
11:45:35 2014 -0300
+++ b/src-test/org/openbravo/test/AllWebserviceTests.java Tue Apr 08
08:50:38 2014 +0200
@@ -22,6 +22,7 @@
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.openbravo.test.datasource.TestCSVEncoding;
import org.openbravo.test.webservice.PerformanceTest;
import org.openbravo.test.webservice.WSAddRecordWithComputedColumns;
import org.openbravo.test.webservice.WSReadTest;
@@ -42,6 +43,7 @@
suite.addTestSuite(WSUpdateTest.class);
suite.addTestSuite(PerformanceTest.class);
suite.addTestSuite(WSAddRecordWithComputedColumns.class);
+ suite.addTestSuite(TestCSVEncoding.class);
// $JUnit-END$
return suite;
diff -r 71901bedc91a -r 8436dc079363
src-test/org/openbravo/test/datasource/TestCSVEncoding.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/datasource/TestCSVEncoding.java Tue Apr
08 08:50:38 2014 +0200
@@ -0,0 +1,135 @@
+/*
+ *************************************************************************
+ * 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;
+import org.openbravo.base.provider.OBProvider;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.ad.domain.Preference;
+import org.openbravo.model.ad.system.Client;
+import org.openbravo.model.common.enterprise.Organization;
+
+/**
+ * Test cases to verify CSV Encoding behavior with Arabic characters
+ *
+ * See issue https://issues.openbravo.com/view.php?id=26162
+ *
+ * @author guillermogil
+ */
+
+public class TestCSVEncoding extends BaseDataSourceTestDal {
+
+ /**
+ * Creates a preference to ensure that the Arabic characters are correctly
displayed and compares
+ * the values with and without the preference
+ *
+ * @throws Exception
+ */
+
+ public void testEncoding() throws Exception {
+
+ OBContext.setAdminMode(false);
+
+ Organization org0 = OBDal.getInstance().get(Organization.class, "0");
+ Client client0 = OBDal.getInstance().get(Client.class, "0");
+
+ // Creation of CSV Text Encoding Preference
+ final Preference pref = OBProvider.getInstance().get(Preference.class);
+ pref.setClient(client0);
+ pref.setOrganization(org0);
+ pref.setPropertyList(true);
+ pref.setActive(true);
+ pref.setPropertyList(true);
+ pref.setProperty("OBSERDS_CSVTextEncoding");
+ // Set value UTF-8
+ pref.setSearchKey("UTF-8");
+ OBDal.getInstance().save(pref);
+ OBDal.getInstance().commitAndClose();
+
+ // Creations of the params to do the request
+ Map<String, String> params = new HashMap<String, String>();
+ params.put("_operationType", "fetch");
+ params.put("_noCount", "true");
+ params.put("exportAs", "csv");
+ params.put("_dataSource", "isc_OBViewDataSource_0");
+ params.put("_noCount", "true");
+ params.put("_extraProperties", "undefined");
+ params.put("tab", "151");
+ params.put("exportToFile", "true");
+ params.put("_textMatchStyle", "substring");
+ params.put("_UTCOffsetMiliseconds", "7200000");
+ params.put("operator", "and");
+ params.put("_constructor", "AdvancedCriteria");
+ JSONArray criteria = new JSONArray();
+ JSONObject criteriaObj = new JSONObject();
+ criteriaObj.put("fieldName", "iSOCode");
+ criteriaObj.put("operator", "iContains");
+ criteriaObj.put("value", "aed");
+ criteriaObj.put("_constructor", "AdvancedCriteria");
+ criteria.put(criteriaObj);
+ params.put("criteria", criteria.toString());
+
+ JSONObject viewState = new JSONObject();
+ viewState
+ .put(
+ "field",
+
"[{name:\"_editLink\",frozen:true,width:56},{name:\"organization\",visible:false,width:200},{name:\"iSOCode\",visible:false,width:100},{name:\"symbol\",width:1572},{name:\"description\",visible:false,width:200},{name:\"standardPrecision\",visible:false,width:100},{name:\"costingPrecision\",visible:false,width:100},{name:\"pricePrecision\",visible:false,width:100},{name:\"currencySymbolAtTheRight\",visible:false,autoFitWidth:false,width:100},{name:\"active\",visible:false,autoFitWidth:false,width:100},{name:\"creationDate\",visible:false,width:100},{name:\"createdBy\",visible:false,width:100},{name:\"updated\",visible:false,width:100},{name:\"updatedBy\",visible:false,width:100}]");
+ viewState
+ .put(
+ "sort",
+
"({fieldName:null,sortDir:\"ascending\",sortSpecifiers:[{property:\"iSOCode\",direction:\"ascending\"}]})");
+ viewState.put("hilite", "null");
+
+ JSONObject group = new JSONObject();
+ group.put("groupByFields", "");
+ group.put("groupingModes", "{}");
+ viewState.put("group", group);
+ viewState.put("filterClause", "null");
+ viewState.put("summaryFunctions", "{}");
+ params.put("viewState", "(" + viewState.toString() + ")");
+
+ String response = doRequest("/org.openbravo.service.datasource/Currency",
params, 200, "POST");
+ String[] res = response.split("\n");
+
+ // Remove previously created preference
+ OBDal.getInstance().remove(pref);
+ OBDal.getInstance().commitAndClose();
+
+ // First assert
+ assertTrue("Cannot show Arabic characters on UTF-8 encoding",
+ res[1].substring(1, 4).equals("د.إ"));
+
+ // Request again to see the differences
+ String response2 = doRequest("/org.openbravo.service.datasource/Currency",
params, 200, "POST");
+ String[] res2 = response2.split("\n");
+
+ OBContext.restorePreviousMode();
+
+ // Second assert
+ assertTrue("On delete CSV Text Preference Arabic characters are still
showing", res2[1]
+ .substring(1, 4).equals("?.?"));
+
+ }
+}
\ No newline at end of file
------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits