details:   /erp/devel/pi/rev/24178c87080a
changeset: 9501:24178c87080a
user:      Iván Perdomo <ivan.perdomo <at> openbravo.com>
date:      Mon Jan 03 17:30:44 2011 +0100
summary:   Partial fix of tests based on sample client

details:   /erp/devel/pi/rev/5a13b6e510bc
changeset: 9502:5a13b6e510bc
user:      Iván Perdomo <ivan.perdomo <at> openbravo.com>
date:      Mon Jan 03 17:31:17 2011 +0100
summary:   Update tests with new api

details:   /erp/devel/pi/rev/ec5346cbfeb8
changeset: 9503:ec5346cbfeb8
user:      Iván Perdomo <ivan.perdomo <at> openbravo.com>
date:      Mon Jan 03 17:31:39 2011 +0100
summary:   Update tests with new api

details:   /erp/devel/pi/rev/dcbca5730e71
changeset: 9504:dcbca5730e71
user:      Iván Perdomo <ivan.perdomo <at> openbravo.com>
date:      Mon Jan 03 17:31:58 2011 +0100
summary:   Update tests with new api

diffstat:

 
modules/org.openbravo.client.application/src-test/org/openbravo/client/application/test/MenuTemplateTest.java
 |    2 +-
 
modules/org.openbravo.client.application/src-test/org/openbravo/client/application/test/MenuTest.java
         |    2 +-
 
modules/org.openbravo.client.myob/src-test/org/openbravo/client/myob/test/MyOpenbravoTest.java
                |    2 +-
 
modules/org.openbravo.service.json/src-test/org/openbravo/service/json/test/DataQueryServiceTest.java
         |    4 +-
 
modules/org.openbravo.service.json/src-test/org/openbravo/service/json/test/JsonConversionTest.java
           |    2 +-
 src-test/org/openbravo/erpCommon/info/ClassicSelectorTest.java                 
                               |    4 +-
 src-test/org/openbravo/test/base/BaseTest.java                                 
                               |  151 +++++++++-
 src-test/org/openbravo/test/dal/AdminContextTest.java                          
                               |    4 +-
 src-test/org/openbravo/test/dal/DalComplexQueryRequisitionTest.java            
                               |    4 +-
 src-test/org/openbravo/test/dal/DalComplexQueryTestOrderLine.java              
                               |    4 +-
 src-test/org/openbravo/test/dal/DalCopyTest.java                               
                               |    2 +-
 src-test/org/openbravo/test/dal/DalPerformanceInventoryLineTest.java           
                               |    4 +-
 src-test/org/openbravo/test/dal/DalPerformanceProductTest.java                 
                               |   10 +-
 src-test/org/openbravo/test/dal/DalQueryTest.java                              
                               |   20 +-
 src-test/org/openbravo/test/dal/DalTest.java                                   
                               |   16 +-
 src-test/org/openbravo/test/dal/DoOrgClientAccessCheckTest.java                
                               |   10 +-
 src-test/org/openbravo/test/dal/DynamicEntityTest.java                         
                               |    6 +-
 src-test/org/openbravo/test/dal/IssuesTest.java                                
                               |   10 +-
 src-test/org/openbravo/test/dal/OBContextTest.java                             
                               |    8 +-
 src-test/org/openbravo/test/dal/PerformanceGenerateInstanceTest.java           
                               |    2 +-
 src-test/org/openbravo/test/dal/ReadByNameTest.java                            
                               |   10 +-
 src-test/org/openbravo/test/dal/ValidationTest.java                            
                               |    8 +-
 src-test/org/openbravo/test/dal/ViewTest.java                                  
                               |    4 +-
 src-test/org/openbravo/test/doc/GenerateEntityModelWiki.java                   
                               |    2 +-
 src-test/org/openbravo/test/expression/EvaluationTest.java                     
                               |    2 +-
 src-test/org/openbravo/test/javascript/CompressionTest.java                    
                               |    3 +-
 src-test/org/openbravo/test/model/FieldProviderTest.java                       
                               |    2 +-
 src-test/org/openbravo/test/model/OneToManyTest.java                           
                               |   10 +-
 src-test/org/openbravo/test/model/UniqueConstraintTest.java                    
                               |    2 +-
 src-test/org/openbravo/test/modularity/DatasetServiceTest.java                 
                               |    8 +-
 src-test/org/openbravo/test/preference/PreferenceTest.java                     
                               |    6 +-
 src-test/org/openbravo/test/security/AccessLevelTest.java                      
                               |   23 +-
 src-test/org/openbravo/test/security/AllowedOrganizationsTest.java             
                               |   44 +-
 src-test/org/openbravo/test/security/EntityAccessTest.java                     
                               |   36 +-
 
src-test/org/openbravo/test/security/WritableReadableOrganizationClientTest.java
                              |   28 +-
 src-test/org/openbravo/test/webservice/WSReadTest.java                         
                               |    2 +-
 src-test/org/openbravo/test/xml/EntityXMLImportTestBusinessObject.java         
                               |   57 +--
 src-test/org/openbravo/test/xml/EntityXMLImportTestReference.java              
                               |   22 +-
 src-test/org/openbravo/test/xml/EntityXMLImportTestSingle.java                 
                               |   28 +-
 src-test/org/openbravo/test/xml/EntityXMLImportTestWarning.java                
                               |   22 +-
 src-test/org/openbravo/test/xml/EntityXMLIssues.java                           
                               |   14 +-
 src-test/org/openbravo/test/xml/UniqueConstraintImportTest.java                
                               |    6 +-
 42 files changed, 368 insertions(+), 238 deletions(-)

diffs (truncated from 1840 to 300 lines):

diff -r 14b93cdae72b -r dcbca5730e71 
modules/org.openbravo.client.application/src-test/org/openbravo/client/application/test/MenuTemplateTest.java
--- 
a/modules/org.openbravo.client.application/src-test/org/openbravo/client/application/test/MenuTemplateTest.java
     Mon Jan 03 18:01:54 2011 +0100
+++ 
b/modules/org.openbravo.client.application/src-test/org/openbravo/client/application/test/MenuTemplateTest.java
     Mon Jan 03 17:31:58 2011 +0100
@@ -38,7 +38,7 @@
 
   @Test
   public void testApplication() throws Exception {
-    setBigBazaarAdminContext();
+    setTestAdminContext();
     final String javascript = appMenuComponent.generate();
     System.err.println(javascript);
 
diff -r 14b93cdae72b -r dcbca5730e71 
modules/org.openbravo.client.application/src-test/org/openbravo/client/application/test/MenuTest.java
--- 
a/modules/org.openbravo.client.application/src-test/org/openbravo/client/application/test/MenuTest.java
     Mon Jan 03 18:01:54 2011 +0100
+++ 
b/modules/org.openbravo.client.application/src-test/org/openbravo/client/application/test/MenuTest.java
     Mon Jan 03 17:31:58 2011 +0100
@@ -53,7 +53,7 @@
    */
   @Test
   public void testOpenbravoAdminMenu() throws Exception {
-    setBigBazaarAdminContext();
+    setTestAdminContext();
     final MenuManager.MenuOption rootMenuOption = menuManager.getMenu();
     dumpMenuOption(rootMenuOption, 0);
     assertFalse(menuManager.getSelectableMenuOptions().isEmpty());
diff -r 14b93cdae72b -r dcbca5730e71 
modules/org.openbravo.client.myob/src-test/org/openbravo/client/myob/test/MyOpenbravoTest.java
--- 
a/modules/org.openbravo.client.myob/src-test/org/openbravo/client/myob/test/MyOpenbravoTest.java
    Mon Jan 03 18:01:54 2011 +0100
+++ 
b/modules/org.openbravo.client.myob/src-test/org/openbravo/client/myob/test/MyOpenbravoTest.java
    Mon Jan 03 17:31:58 2011 +0100
@@ -25,7 +25,7 @@
   }
 
   public void testMyOpenbravoComponent() throws Exception {
-    setBigBazaarAdminContext();
+    setTestAdminContext();
     final MyOpenbravoComponent component = new MyOpenbravoComponent();
 
     System.err.println("Available Widget Classes for System Administrator");
diff -r 14b93cdae72b -r dcbca5730e71 
modules/org.openbravo.service.json/src-test/org/openbravo/service/json/test/DataQueryServiceTest.java
--- 
a/modules/org.openbravo.service.json/src-test/org/openbravo/service/json/test/DataQueryServiceTest.java
     Mon Jan 03 18:01:54 2011 +0100
+++ 
b/modules/org.openbravo.service.json/src-test/org/openbravo/service/json/test/DataQueryServiceTest.java
     Mon Jan 03 17:31:58 2011 +0100
@@ -145,7 +145,7 @@
       }
 
       {
-        setBigBazaarUserContext();
+        setTestUserContext();
         final String[] orgs = 
OBContext.getOBContext().getReadableOrganizations();
         // check that 1000008 is not there, so that the test is good
         for (String org : orgs) {
@@ -309,7 +309,7 @@
    * Orderby on identifier with foreign keys
    */
   public void testOrderByOnIdentifier() throws Exception {
-    setBigBazaarUserContext();
+    setTestUserContext();
     OBContext.setAdminMode();
     try {
       final DataEntityQueryService queryService = new DataEntityQueryService();
diff -r 14b93cdae72b -r dcbca5730e71 
modules/org.openbravo.service.json/src-test/org/openbravo/service/json/test/JsonConversionTest.java
--- 
a/modules/org.openbravo.service.json/src-test/org/openbravo/service/json/test/JsonConversionTest.java
       Mon Jan 03 18:01:54 2011 +0100
+++ 
b/modules/org.openbravo.service.json/src-test/org/openbravo/service/json/test/JsonConversionTest.java
       Mon Jan 03 17:31:58 2011 +0100
@@ -170,7 +170,7 @@
   // test issue:
   // https://issues.openbravo.com/view.php?id=14697
   public void testIssue14697CheckDerivedReadableCurrency() {
-    setUserContext("1000020");
+    setUserContext(getRandomUser().getId());
     final BaseOBObject c = OBDal.getInstance().get(Currency.class, "100");
     final DataToJsonConverter converter = new DataToJsonConverter();
 
diff -r 14b93cdae72b -r dcbca5730e71 
src-test/org/openbravo/erpCommon/info/ClassicSelectorTest.java
--- a/src-test/org/openbravo/erpCommon/info/ClassicSelectorTest.java    Mon Jan 
03 18:01:54 2011 +0100
+++ b/src-test/org/openbravo/erpCommon/info/ClassicSelectorTest.java    Mon Jan 
03 17:31:58 2011 +0100
@@ -38,8 +38,8 @@
    */
   public void testBpartnerMultiple() throws Exception {
 
-    String client = "'1000000'";
-    String org = "'0','1000000'";
+    String client = "'" + TEST_CLIENT_ID + "'";
+    String org = "'0','" + TEST_ORG_ID + "'";
     String key = "";
     String name = "";
     String contact = "";
diff -r 14b93cdae72b -r dcbca5730e71 
src-test/org/openbravo/test/base/BaseTest.java
--- a/src-test/org/openbravo/test/base/BaseTest.java    Mon Jan 03 18:01:54 
2011 +0100
+++ b/src-test/org/openbravo/test/base/BaseTest.java    Mon Jan 03 17:31:58 
2011 +0100
@@ -20,12 +20,18 @@
 package org.openbravo.test.base;
 
 import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
 
 import junit.framework.TestCase;
 import junit.framework.TestResult;
 
 import org.apache.log4j.Logger;
 import org.apache.log4j.PropertyConfigurator;
+import org.hibernate.criterion.Expression;
 import org.openbravo.base.exception.OBException;
 import org.openbravo.base.model.Entity;
 import org.openbravo.base.model.ModelProvider;
@@ -40,12 +46,14 @@
 import org.openbravo.database.ConnectionProvider;
 import org.openbravo.database.ConnectionProviderImpl;
 import org.openbravo.exception.PoolNotFoundException;
+import org.openbravo.model.ad.access.User;
 
 /**
  * Base test class which can/should be extended by most other test classes 
which want to make use of
  * the Openbravo test infrastructure.
  * 
  * @author mtaal
+ * @author iperdomo
  */
 
 public class BaseTest extends TestCase {
@@ -55,8 +63,82 @@
   private boolean errorOccured = false;
 
   /**
-   * Overridden to initialize the Dal layer, sets the current user to the the 
BigBazaar 1000000
-   * user.
+   * Record ID of Client "F&B International Group"
+   */
+  protected static final String TEST_CLIENT_ID = 
"FF8080812AFBCB14012AFBD3E373001F";
+
+  /**
+   * Record ID of Organization "F&B España - Región Norte"
+   */
+  protected static final String TEST_ORG_ID = 
"7A8E888A4B4C4E638CD5EB3A41A3289A";
+
+  /**
+   * Record ID of Warehouse "España Región Norte"
+   */
+  protected static final String TEST_WAREHOUSE_ID = 
"71B43F2AAE3641CA849B131960BCEFF4";
+
+  /**
+   * Record ID of User "F&BAdmin"
+   */
+  protected static final String TEST_USER_ID = 
"FF8080812AFBCB14012AFBD3E4F60033";
+
+  /**
+   * Record IDs of available users different than {...@link #TEST_USER_ID} 
Note: Initialized to null,
+   * need to call {...@link getRandomUserId} at least once
+   */
+  protected static List<User> userIds = null;
+
+  /**
+   * Record ID of Role "F&B International Group Admin"
+   */
+  protected static final String TEST_ROLE_ID = 
"FF8080812AFBCB14012AFBD3E4340031";
+
+  /**
+   * Record ID of a Order in Draft status
+   */
+  protected static final String TEST_ORDER_ID = 
"CDA9CA3269D04F7497BFA71067A086C9";
+
+  /**
+   * Record ID of Product "Zumo de Fresa Bio 0,33L"
+   */
+  protected static final String TEST_PRODUCT_ID = 
"8A64B71A2B0B2946012B0BC43922011F";
+
+  /**
+   * Map representation of current Organization tree for Client {...@link 
#TEST_CLIENT_ID}
+   */
+  protected static Map<String, String[]> TEST_ORG_TREE = new HashMap<String, 
String[]>();
+
+  static {
+
+    // "F&B International Group"
+    TEST_ORG_TREE.put("3C816D72B14D4BBCB8571404B794AB84", new String[] { "" });
+
+    // "F&B España, S.A."
+    TEST_ORG_TREE.put("4F68EB1C1B734E79B27DE9D2DF56089F", new String[] { "" });
+
+    // "F&B US, Inc."
+    TEST_ORG_TREE.put("B9C7088AB859483A9B1FB342AC2BE17A", new String[] { "" });
+
+  }
+
+  /**
+   * Record ID of the QA Test client
+   */
+  protected static final String QA_TEST_CLIENT_ID = 
"4028E6C72959682B01295A070852010D";
+
+  /**
+   * Record ID of the Main organization of QA Test client
+   */
+  protected static final String QA_TEST_ORG_ID = 
"43D590B4814049C6B85C6545E8264E37";
+
+  /**
+   * Record ID of the "Admin" user of QA Test client
+   */
+  protected static final String QA_TEST_ADMIN_USER_ID = 
"4028E6C72959682B01295A0735CB0120";
+
+  /**
+   * Overridden to initialize the Dal layer, sets the current user to the the 
User:
+   * {...@link #TEST_USER_ID}
    */
   @Override
   protected void setUp() throws Exception {
@@ -67,7 +149,7 @@
 
     initializeDalLayer();
     // clear the session otherwise it keeps the old model
-    setBigBazaarUserContext();
+    setTestUserContext();
     super.setUp();
     // be negative is set back to false at the end of a successfull test.
     errorOccured = true;
@@ -110,25 +192,34 @@
     OBContext.setOBContext("0");
   }
 
+  @Deprecated
+  protected void setBigBazaarAdminContex() {
+    setTestAdminContext();
+  }
+
+  @Deprecated
+  protected void setBigBazaarUserContext() {
+    setTestUserContext();
+  }
+
   /**
-   * Sets the current user to the 1000000 user.
+   * Sets the current user to the {...@link #TEST_USER_ID} user.
    */
-  protected void setBigBazaarUserContext() {
-    OBContext.setOBContext("1000000", "1000002", "1000000", "1000000");
+  protected void setTestUserContext() {
+    OBContext.setOBContext(TEST_USER_ID, TEST_ROLE_ID, TEST_CLIENT_ID, 
TEST_ORG_ID);
   }
 
   /**
    * Sets the current user to the 100 user.
    */
-  protected void setBigBazaarAdminContext() {
-    OBContext.setOBContext("100", "0", "1000000", "1000000");
+  protected void setTestAdminContext() {
+    OBContext.setOBContext("100", "0", TEST_CLIENT_ID, TEST_ORG_ID);
   }
 
   /**
    * Sets the current user. For the 0, 100 and 1000000 users this method 
should not be used. For
-   * these users one of the other context-set methods should be used:
-   * {...@link #setBigBazaarAdminContext()}, {...@link 
#setBigBazaarUserContext()} or
-   * {...@link #setSystemAdministratorContext()}.
+   * these users one of the other context-set methods should be used: 
{...@link #setTestAdminContext()}
+   * , {...@link #setTestUserContext()} or {...@link 
#setSystemAdministratorContext()}.
    * 
    * @param userId
    *          the id of the user to use.
@@ -139,18 +230,48 @@
           + "consider using that method directly");
       setSystemAdministratorContext();
     } else if (userId.equals("100")) {
-      log.warn("Forwarding the call to setBigBazaarAdminContext method, "
+      log.warn("Forwarding the call to setFBGroupAdminContext method, "
           + "consider using that method directly");
-      setBigBazaarAdminContext();
+      setTestAdminContext();
     } else if (userId.equals("1000000")) {
-      log.warn("Forwarding call to the setBigBazaarUserContext method, "
+      log.warn("User id 1000000 is not longer available, please update your 
test. "
+          + "Forwarding call to the setTestUserContext method, "
           + "consider using that method directly");
-      setBigBazaarUserContext();
+      setTestUserContext();
     } else {
       OBContext.setOBContext(userId);
     }
   }
 
+  /**
+   * Gets a random User (Record ID) from the available ones in the test 
client. The ID is one
+   * different than {...@link #TEST_USER_ID}
+   * 
+   * @return A record ID of a available user
+   */
+  protected User getRandomUser() {
+    if (userIds == null) {
+      setTestUserContext();
+
+      String[] excludedUserIds = { "100", TEST_USER_ID };
+      OBCriteria<User> obc = OBDal.getInstance().createCriteria(User.class);
+      obc.add(Expression.isNotNull(User.PROPERTY_PASSWORD));
+      obc.add(Expression.not(Expression.in(User.PROPERTY_ID, 
excludedUserIds)));
+      obc.add(Expression.isNotEmpty(User.PROPERTY_ADUSERROLESLIST));
+
+      if (obc.count() == 0) {
+        throw new RuntimeException("Unable to initialize the list of available 
users");
+      }
+      userIds = new ArrayList<User>();
+      for (User u : obc.list()) {
+        userIds.add(u);

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and, 
should the need arise, upgrade to a full multi-node Oracle RAC database 
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to