details:   https://code.openbravo.com/erp/devel/pi/rev/e769978a35ba
changeset: 22775:e769978a35ba
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Wed Mar 26 09:54:00 2014 +0100
summary:   fixed bug 26088: run.webservice.tests fails

  -ensures correct initialization
  -prevents loggin of expected Exceptions

diffstat:

 src-test/org/openbravo/test/webservice/BaseWSTest.java   |  12 ++++-
 src-test/org/openbravo/test/webservice/WSUpdateTest.java |  36 +++++++++++----
 src/org/openbravo/base/exception/OBException.java        |  10 +++-
 3 files changed, 44 insertions(+), 14 deletions(-)

diffs (167 lines):

diff -r e4cef7978158 -r e769978a35ba 
src-test/org/openbravo/test/webservice/BaseWSTest.java
--- a/src-test/org/openbravo/test/webservice/BaseWSTest.java    Wed Mar 26 
07:12:01 2014 +0000
+++ b/src-test/org/openbravo/test/webservice/BaseWSTest.java    Wed Mar 26 
09:54:00 2014 +0100
@@ -218,6 +218,11 @@
     return doTestGetRequest(wsPart, testContent, responseCode, true);
   }
 
+  protected String doTestGetRequest(String wsPart, String testContent, int 
responseCode,
+      boolean validate) {
+    return doTestGetRequest(wsPart, testContent, responseCode, validate, true);
+  }
+
   /**
    * Executes a GET request. The content is validated against the XML schema 
retrieved using the
    * /ws/dal/schema webservice call.
@@ -232,10 +237,13 @@
    *          the expected HTTP response code
    * @param validate
    *          if true then the response content is validated against the 
Openbravo XML Schema
+   * @param logError
+   *          indicates whether in case of Exception it should be logged, this 
param should be false
+   *          when Exception is exptected in order not to pollute the log
    * @return the content returned from the GET request
    */
   protected String doTestGetRequest(String wsPart, String testContent, int 
responseCode,
-      boolean validate) {
+      boolean validate, boolean logException) {
     try {
       final HttpURLConnection hc = createConnection(wsPart, "GET");
       hc.connect();
@@ -266,7 +274,7 @@
         throw e;
       }
     } catch (final Exception e) {
-      throw new OBException("Exception when executing ws: " + wsPart, e);
+      throw new OBException("Exception when executing ws: " + wsPart, e, 
logException);
     }
   }
 
diff -r e4cef7978158 -r e769978a35ba 
src-test/org/openbravo/test/webservice/WSUpdateTest.java
--- a/src-test/org/openbravo/test/webservice/WSUpdateTest.java  Wed Mar 26 
07:12:01 2014 +0000
+++ b/src-test/org/openbravo/test/webservice/WSUpdateTest.java  Wed Mar 26 
09:54:00 2014 +0100
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2008-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2014 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -75,11 +75,24 @@
   }
 
   /**
+   * test case order execution cannot be warrantied, so check if city has 
already been created
+   * 
+   * @throws Exception
+   */
+  private void initializeCreateCity() throws Exception {
+    if (cityId == null) {
+      testACreateCity();
+    }
+  }
+
+  /**
    * Read the created city using a webservice and make a small change and post 
it back.
    * 
    * @throws Exception
    */
   public void testReadUpdateCity() throws Exception {
+    initializeCreateCity();
+
     final String city = doTestGetRequest("/ws/dal/City/" + cityId, null, 200);
     log.debug(System.currentTimeMillis());
     String newCity;
@@ -103,6 +116,8 @@
    * @throws Exception
    */
   public void testIncorrectRootTag() throws Exception {
+    initializeCreateCity();
+
     final String city = doTestGetRequest("/ws/dal/City/" + cityId, null, 200);
     log.debug(city);
     log.debug("---");
@@ -118,16 +133,14 @@
    * @throws Exception
    */
   public void testReadAddDeleteCity() throws Exception {
-    if (cityId == null) {
-      testACreateCity();
-    }
+    initializeCreateCity();
+
     doTestReadAddDeleteCity(false);
   }
 
   public void testReadAddDeleteQueryCity() throws Exception {
-    if (cityId == null) {
-      testACreateCity();
-    }
+    initializeCreateCity();
+
     doTestReadAddDeleteCity(true);
   }
 
@@ -191,10 +204,9 @@
 
     // it should not be there!
     try {
-      doTestGetRequest("/ws/dal/City/" + id, "<error>", 404);
+      doTestGetRequest("/ws/dal/City/" + id, "<error>", 404, true, false);
       fail("City " + id + " was not deleted");
     } catch (final Exception e) {
-      e.printStackTrace(System.err);
       assertTrue(e.getCause() instanceof FileNotFoundException);
     }
   }
@@ -215,6 +227,7 @@
    * @throws Exception
    */
   public void testReadAddCityWrongMethodError() throws Exception {
+    initializeCreateCity();
     final String city = doTestGetRequest("/ws/dal/City/" + cityId, null, 200);
     String newCity = city.replaceAll("</name>", (System.currentTimeMillis() + 
"").substring(6)
         + "</name>");
@@ -231,8 +244,11 @@
   /**
    * Cleans up the database by removing the city. Is run as last therefore the 
use of the Z
    * character in the name.
+   * 
+   * @throws Exception
    */
-  public void testZRemoveCity() {
+  public void testZRemoveCity() throws Exception {
+    initializeCreateCity();
     doDirectDeleteRequest("/ws/dal/City/" + cityId, 200);
   }
 
diff -r e4cef7978158 -r e769978a35ba 
src/org/openbravo/base/exception/OBException.java
--- a/src/org/openbravo/base/exception/OBException.java Wed Mar 26 07:12:01 
2014 +0000
+++ b/src/org/openbravo/base/exception/OBException.java Wed Mar 26 09:54:00 
2014 +0100
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2008-2011 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2014 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -37,8 +37,14 @@
   }
 
   public OBException(String message, Throwable cause) {
+    this(message, cause, true);
+  }
+
+  public OBException(String message, Throwable cause, boolean logException) {
     super(message, cause);
-    getLogger().error(message, cause);
+    if (logException) {
+      getLogger().error(message, cause);
+    }
   }
 
   public OBException(String message) {

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to