details:   /erp/devel/pi/rev/9b652ee60f8d
changeset: 6953:9b652ee60f8d
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Thu Apr 08 09:44:50 2010 +0200
summary:   Improved logging of received content in case of exception

details:   /erp/devel/pi/rev/13d2fc73db5d
changeset: 6954:13d2fc73db5d
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Thu Apr 08 09:45:22 2010 +0200
summary:   fixes issue 12883: Rest Webservice testcases fail because test data 
is not what is expected

diffstat:

 src-test/org/openbravo/test/webservice/BaseWSTest.java |  35 ++++++++++++-----
 src-test/org/openbravo/test/webservice/WSReadTest.java |  21 ++++------
 2 files changed, 32 insertions(+), 24 deletions(-)

diffs (97 lines):

diff -r e871ecee3de7 -r 13d2fc73db5d 
src-test/org/openbravo/test/webservice/BaseWSTest.java
--- a/src-test/org/openbravo/test/webservice/BaseWSTest.java    Thu Apr 08 
10:08:35 2010 +0530
+++ b/src-test/org/openbravo/test/webservice/BaseWSTest.java    Thu Apr 08 
09:45:22 2010 +0200
@@ -19,7 +19,9 @@
 
 package org.openbravo.test.webservice;
 
+import java.io.BufferedReader;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.Reader;
 import java.io.StringReader;
@@ -195,19 +197,30 @@
       hc.connect();
       final SAXReader sr = new SAXReader();
       final InputStream is = hc.getInputStream();
-      final Document doc = sr.read(is);
-      final String content = XMLUtil.getInstance().toString(doc);
-      if (testContent != null && content.indexOf(testContent) == -1) {
-        log.debug(content);
-        fail();
+      final StringBuilder sb = new StringBuilder();
+      BufferedReader reader = new BufferedReader(new InputStreamReader(is, 
"UTF-8"));
+      String line;
+      while ((line = reader.readLine()) != null) {
+        sb.append(line).append("\n");
       }
-      assertEquals(responseCode, hc.getResponseCode());
-      is.close();
-      // do not validate the xml schema itself, this results in infinite loops
-      if (validate) {
-        validateXML(content);
+      try {
+        final Document doc = sr.read(new StringReader(sb.toString()));
+        final String content = XMLUtil.getInstance().toString(doc);
+        if (testContent != null && content.indexOf(testContent) == -1) {
+          log.debug(content);
+          fail();
+        }
+        assertEquals(responseCode, hc.getResponseCode());
+        is.close();
+        // do not validate the xml schema itself, this results in infinite 
loops
+        if (validate) {
+          validateXML(content);
+        }
+        return content;
+      } catch (Exception e) {
+        log.debug(sb.toString());
+        throw e;
       }
-      return content;
     } catch (final Exception e) {
       throw new OBException("Exception when executing ws: " + wsPart, e);
     }
diff -r e871ecee3de7 -r 13d2fc73db5d 
src-test/org/openbravo/test/webservice/WSReadTest.java
--- a/src-test/org/openbravo/test/webservice/WSReadTest.java    Thu Apr 08 
10:08:35 2010 +0530
+++ b/src-test/org/openbravo/test/webservice/WSReadTest.java    Thu Apr 08 
09:45:22 2010 +0200
@@ -20,12 +20,9 @@
 package org.openbravo.test.webservice;
 
 import java.net.URLEncoder;
-import java.util.Iterator;
 
-import org.hibernate.cfg.Configuration;
-import org.hibernate.mapping.PersistentClass;
 import org.openbravo.base.model.Entity;
-import org.openbravo.base.session.SessionFactoryController;
+import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.dal.service.OBQuery;
 import org.openbravo.model.ad.datamodel.Column;
@@ -114,17 +111,15 @@
   }
 
   /**
-   * Calls the webservice for every {...@link Entity} in the system. The test 
can take some time to run
-   * (about 5 minutes).
+   * Calls the webservice for every readable {...@link Entity} in the system. 
The test can take some
+   * time to run (about 5 minutes).
    */
   public void testAllToXML() {
-    setBigBazaarAdminContext();
-    final Configuration cfg = 
SessionFactoryController.getInstance().getConfiguration();
-
-    for (final Iterator<?> it = cfg.getClassMappings(); it.hasNext();) {
-      final PersistentClass pc = (PersistentClass) it.next();
-      final String entityName = pc.getEntityName();
-      doTestGetRequest("/ws/dal/" + entityName, "<ob:Openbravo", 200);
+    // do not replace this with a call to setUserContext,
+    OBContext.setOBContext("100");
+    for (Entity entity : 
OBContext.getOBContext().getEntityAccessChecker().getReadableEntities()) {
+      doTestGetRequest("/ws/dal/" + entity.getName() + 
"?includeChildren=false", "<ob:Openbravo",
+          200);
     }
   }
 

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to