details:   https://code.openbravo.com/erp/devel/pi/rev/d90e33674f60
changeset: 23961:d90e33674f60
user:      Inigo Sanchez <inigo.sanchez <at> openbravo.com>
date:      Wed Jul 02 13:09:12 2014 +0200
summary:   fixed bug  26968: jUnit test cases are failing because execution 
order in JDK7
Problem is some of these test cases rely the order each test is executed (based 
on method name) which
is not valid anymore. Solved the problem by forcing the required execution 
order.

diffstat:

 src-test/org/openbravo/test/security/EntityAccessTest.java             |  31 
+++++-
 src-test/org/openbravo/test/webservice/WSUpdateTest.java               |  38 
++++++-
 src-test/org/openbravo/test/xml/EntityXMLImportTestBusinessObject.java |  48 
++++++++-
 3 files changed, 94 insertions(+), 23 deletions(-)

diffs (truncated from 398 to 300 lines):

diff -r 3948973fcaaf -r d90e33674f60 
src-test/org/openbravo/test/security/EntityAccessTest.java
--- a/src-test/org/openbravo/test/security/EntityAccessTest.java        Wed Jul 
02 11:33:10 2014 +0200
+++ b/src-test/org/openbravo/test/security/EntityAccessTest.java        Wed Jul 
02 13:09:12 2014 +0200
@@ -37,6 +37,9 @@
 /**
  * Tests access on the basis of window and table definitions. Also tests 
derived read access.
  * 
+ * IMPORTANT: Test cases are called by one of them called testContent(). The 
name of the rest of the
+ * test cases NOT begin by "test...".
+ * 
  * @see EntityAccessChecker
  * 
  * @author mtaal
@@ -47,9 +50,22 @@
   private static final Logger log = Logger.getLogger(EntityAccessTest.class);
 
   /**
+   * This test contains the invocations for the rest of the test cases. By 
this way, we preserve the
+   * execution order of the test cases.
+   */
+  public void testContent() {
+    createCurrency();
+    checkDerivedReadableCurrency();
+    updateCurrencyDerivedRead();
+    nonReadable();
+    zDeleteTestData();
+
+  }
+
+  /**
    * Creates test data, a {@link Currency}.
    */
-  public void testCreateCurrency() {
+  public void createCurrency() {
     setTestAdminContext();
     final OBCriteria<Currency> obc = 
OBDal.getInstance().createCriteria(Currency.class);
     obc.add(Restrictions.eq(Currency.PROPERTY_ISOCODE, "TE2"));
@@ -64,6 +80,7 @@
       c.setCostingPrecision((long) 4);
       OBDal.getInstance().save(c);
     }
+    OBDal.getInstance().flush();
   }
 
   /**
@@ -95,7 +112,7 @@
    * read. Also checks the allowRead concept of a BaseOBObject (
    * {@link BaseOBObject#setAllowRead(boolean)})
    */
-  public void testCheckDerivedReadableCurrency() {
+  public void checkDerivedReadableCurrency() {
     setUserContext(TEST2_USER_ID);
     final Currency c = OBDal.getInstance().get(Currency.class, "100");
     log.debug(c.getIdentifier());
@@ -134,12 +151,13 @@
         }
       }
     }
+    OBDal.getInstance().flush();
   }
 
   /**
    * Test derived readable on a set method, also there this check must be done.
    */
-  public void testUpdateCurrencyDerivedRead() {
+  public void updateCurrencyDerivedRead() {
     setUserContext(TEST2_USER_ID);
     final Currency c = OBDal.getInstance().get(Currency.class, "100");
     try {
@@ -157,13 +175,14 @@
       assertTrue("Wrong exception thrown:  " + e.getMessage(),
           e.getMessage().indexOf("is not writable by this user") != -1);
     }
+    OBDal.getInstance().flush();
   }
 
   /**
    * Checks non-readable, if an object/entity is not readable then it may not 
be read through the
    * {@link OBDal}.
    */
-  public void testNonReadable() {
+  public void nonReadable() {
     assertTrue(true);
     // FIXME: find a test case for this!
 
@@ -183,7 +202,7 @@
   /**
    * Removes the test data by using the administrator account.
    */
-  public void testZDeleteTestData() {
+  public void zDeleteTestData() {
     setTestUserContext();
     addReadWriteAccess(Currency.class);
     addReadWriteAccess(CurrencyTrl.class);
@@ -192,5 +211,7 @@
     final List<Currency> cs = obc.list();
     assertEquals(1, cs.size());
     OBDal.getInstance().remove(cs.get(0));
+    OBDal.getInstance().flush();
   }
+
 }
\ No newline at end of file
diff -r 3948973fcaaf -r d90e33674f60 
src-test/org/openbravo/test/webservice/WSUpdateTest.java
--- a/src-test/org/openbravo/test/webservice/WSUpdateTest.java  Wed Jul 02 
11:33:10 2014 +0200
+++ b/src-test/org/openbravo/test/webservice/WSUpdateTest.java  Wed Jul 02 
13:09:12 2014 +0200
@@ -35,6 +35,9 @@
  * Test webservice for reading, updating and posting. The test cases here 
require a running
  * Openbravo at http://localhost:8080/openbravo.
  * 
+ * IMPORTANT: Test cases are called by one of them called testContent(). The 
name of the rest of the
+ * test cases NOT begin by "test...".
+ * 
  * @author mtaal
  */
 
@@ -45,10 +48,27 @@
   private static String cityId = null;
 
   /**
+   * This test contains the invocations for the rest of the test cases. By 
this way, we preserve the
+   * execution order of the test cases.
+   * 
+   * @throws Exception
+   */
+  public void testContent() throws Exception {
+    aCreateCity();
+    readUpdateCity();
+    incorrectRootTag();
+    readAddDeleteCity();
+    readAddDeleteQueryCity();
+    doTest14973();
+    readAddCityWrongMethodError();
+    zRemoveCity();
+  }
+
+  /**
    * Creates a city through a webservice calls. This test must be run before 
the others because it
    * sets the cityId member in this class.
    */
-  public void testACreateCity() {
+  public void aCreateCity() {
     // do not replace this with a call to setUserContext,
     // the city must be stored using the client/org of the 100 user
     // this ensures that webservice calls will be able to find the city
@@ -81,7 +101,7 @@
    */
   private void initializeCreateCity() throws Exception {
     if (cityId == null) {
-      testACreateCity();
+      aCreateCity();
     }
   }
 
@@ -90,7 +110,7 @@
    * 
    * @throws Exception
    */
-  public void testReadUpdateCity() throws Exception {
+  public void readUpdateCity() throws Exception {
     initializeCreateCity();
 
     final String city = doTestGetRequest("/ws/dal/City/" + cityId, null, 200);
@@ -115,7 +135,7 @@
    * 
    * @throws Exception
    */
-  public void testIncorrectRootTag() throws Exception {
+  public void incorrectRootTag() throws Exception {
     initializeCreateCity();
 
     final String city = doTestGetRequest("/ws/dal/City/" + cityId, null, 200);
@@ -132,13 +152,13 @@
    * 
    * @throws Exception
    */
-  public void testReadAddDeleteCity() throws Exception {
+  public void readAddDeleteCity() throws Exception {
     initializeCreateCity();
 
     doTestReadAddDeleteCity(false);
   }
 
-  public void testReadAddDeleteQueryCity() throws Exception {
+  public void readAddDeleteQueryCity() throws Exception {
     initializeCreateCity();
 
     doTestReadAddDeleteCity(true);
@@ -215,7 +235,7 @@
    * Tests issue 14973 https://issues.openbravo.com/view.php?id=14973 
DalWebServiceServlet does not
    * report errors which occur at commit time
    */
-  public void test14973() throws Exception {
+  public void doTest14973() throws Exception {
     final HttpURLConnection hc = createConnection("/ws/dal/Product/1000004", 
"DELETE");
     hc.connect();
     assertEquals(500, hc.getResponseCode());
@@ -226,7 +246,7 @@
    * 
    * @throws Exception
    */
-  public void testReadAddCityWrongMethodError() throws Exception {
+  public void readAddCityWrongMethodError() throws Exception {
     initializeCreateCity();
     final String city = doTestGetRequest("/ws/dal/City/" + cityId, null, 200);
     String newCity = city.replaceAll("</name>", (System.currentTimeMillis() + 
"").substring(6)
@@ -247,7 +267,7 @@
    * 
    * @throws Exception
    */
-  public void testZRemoveCity() throws Exception {
+  public void zRemoveCity() throws Exception {
     initializeCreateCity();
     doDirectDeleteRequest("/ws/dal/City/" + cityId, 200);
   }
diff -r 3948973fcaaf -r d90e33674f60 
src-test/org/openbravo/test/xml/EntityXMLImportTestBusinessObject.java
--- a/src-test/org/openbravo/test/xml/EntityXMLImportTestBusinessObject.java    
Wed Jul 02 11:33:10 2014 +0200
+++ b/src-test/org/openbravo/test/xml/EntityXMLImportTestBusinessObject.java    
Wed Jul 02 13:09:12 2014 +0200
@@ -46,6 +46,9 @@
  * Test import of data with a business object ({@link PaymentTerm} and {@link 
PaymentTermLine}),
  * adding and removing childs.
  * 
+ * IMPORTANT: Test cases are called by one of them called testContent(). The 
name of the rest of the
+ * test cases NOT begin by "test...".
+ * 
  * @author mtaal
  */
 
@@ -62,19 +65,35 @@
   private static int TOTAL_PT_PTL = 0;
 
   // private static int TOTAL_PT_PTL = NO_OF_PT + NO_OF_PT + NO_OF_PT_LINE;
+  /**
+   * This test contains the invocations for the rest of the test cases. By 
this way, we preserve the
+   * execution order of the test cases.
+   */
+  public void testContent() {
+    aPaymentTerm();
+    bPaymentTerm();
+    cPaymentTerm();
+    dPaymentTerm();
+    ePaymentTerm();
+    fPaymentTerm();
+    gPaymentTerm();
+    hPaymentTerm();
+    zPaymentTerm();
+  }
 
   /** Sets up the test data, creates a first of Payment Terms. */
-  public void testAPaymentTerm() {
+  public void aPaymentTerm() {
     cleanRefDataLoaded();
     setTestUserContext();
     addReadWriteAccess(PaymentTermTrl.class);
     createSavePaymentTerm();
+    OBDal.getInstance().flush();
   }
 
   /**
    * Export the Payment Terms from one client and import into another client.
    */
-  public void testBPaymentTerm() {
+  public void bPaymentTerm() {
 
     setTestUserContext();
     setAccess();
@@ -103,13 +122,14 @@
 
     assertEquals(TOTAL_PT_PTL, ir.getInsertedObjects().size());
     assertEquals(0, ir.getUpdatedObjects().size());
+    OBDal.getInstance().flush();
   }
 
   /**
    * Execute the same test as in {@link #testBPaymentTerm()}, as it is 
repeated and no data has
    * changed no updates should take place.
    */
-  public void testCPaymentTerm() {
+  public void cPaymentTerm() {
 
     setTestUserContext();
     setAccess();
@@ -132,13 +152,14 @@
 
     assertEquals(0, ir.getInsertedObjects().size());
     assertEquals(0, ir.getUpdatedObjects().size());
+    OBDal.getInstance().flush();
   }
 
   /**
    * Now do the same as in {@link #testCPaymentTerm()} only now with some 
small changes in the xml,
    * so that some objects are updated.
    */
-  public void testDPaymentTerm() {
+  public void dPaymentTerm() {
 
     setTestUserContext();
     setAccess();
@@ -175,13 +196,14 @@
         assertTrue(ir.getUpdatedObjects().contains(ptl.getPaymentTerms()));

------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to