details:   /erp/devel/pi/rev/aa9268a67b3d
changeset: 6536:aa9268a67b3d
user:      Martin Taal <martin.taal <at> openbravo.com>
date:      Mon Mar 01 13:25:09 2010 +0100
summary:   Added testcase for reading through OBCriteria and testing on 
isActive == true as a default

diffstat:

 src-test/org/openbravo/test/AllAntTaskTests.java    |    2 +
 src-test/org/openbravo/test/AllTests.java           |    2 +
 src-test/org/openbravo/test/AntTaskTests.java       |    2 +
 src-test/org/openbravo/test/dal/ReadByNameTest.java |  148 ++++++++++++++++++++
 4 files changed, 154 insertions(+), 0 deletions(-)

diffs (209 lines):

diff -r 9f67838a3ea8 -r aa9268a67b3d 
src-test/org/openbravo/test/AllAntTaskTests.java
--- a/src-test/org/openbravo/test/AllAntTaskTests.java  Mon Mar 01 13:24:11 
2010 +0100
+++ b/src-test/org/openbravo/test/AllAntTaskTests.java  Mon Mar 01 13:25:09 
2010 +0100
@@ -36,6 +36,7 @@
 import org.openbravo.test.dal.IssuesTest;
 import org.openbravo.test.dal.MappingGenerationTest;
 import org.openbravo.test.dal.OBContextTest;
+import org.openbravo.test.dal.ReadByNameTest;
 import org.openbravo.test.dal.ValidationTest;
 import org.openbravo.test.expression.EvaluationTest;
 import org.openbravo.test.model.OneToManyTest;
@@ -90,6 +91,7 @@
     suite.addTestSuite(ValidationTest.class);
     suite.addTestSuite(OBContextTest.class);
     suite.addTestSuite(DalStoredProcedureTest.class);
+    suite.addTestSuite(ReadByNameTest.class);
 
     // expression
     suite.addTestSuite(EvaluationTest.class);
diff -r 9f67838a3ea8 -r aa9268a67b3d src-test/org/openbravo/test/AllTests.java
--- a/src-test/org/openbravo/test/AllTests.java Mon Mar 01 13:24:11 2010 +0100
+++ b/src-test/org/openbravo/test/AllTests.java Mon Mar 01 13:25:09 2010 +0100
@@ -32,6 +32,7 @@
 import org.openbravo.test.dal.HiddenUpdateTest;
 import org.openbravo.test.dal.IssuesTest;
 import org.openbravo.test.dal.MappingGenerationTest;
+import org.openbravo.test.dal.ReadByNameTest;
 import org.openbravo.test.dal.ValidationTest;
 import org.openbravo.test.expression.EvaluationTest;
 import org.openbravo.test.model.ClassLoaderTest;
@@ -74,6 +75,7 @@
     suite.addTestSuite(DalConnectionProviderTest.class);
     suite.addTestSuite(DalCopyTest.class);
     suite.addTestSuite(DalStoredProcedureTest.class);
+    suite.addTestSuite(ReadByNameTest.class);
 
     // model
     suite.addTestSuite(RuntimeModelTest.class);
diff -r 9f67838a3ea8 -r aa9268a67b3d 
src-test/org/openbravo/test/AntTaskTests.java
--- a/src-test/org/openbravo/test/AntTaskTests.java     Mon Mar 01 13:24:11 
2010 +0100
+++ b/src-test/org/openbravo/test/AntTaskTests.java     Mon Mar 01 13:25:09 
2010 +0100
@@ -37,6 +37,7 @@
 import org.openbravo.test.dal.IssuesTest;
 import org.openbravo.test.dal.MappingGenerationTest;
 import org.openbravo.test.dal.OBContextTest;
+import org.openbravo.test.dal.ReadByNameTest;
 import org.openbravo.test.dal.ValidationTest;
 import org.openbravo.test.expression.EvaluationTest;
 import org.openbravo.test.model.OneToManyTest;
@@ -95,6 +96,7 @@
     suite.addTestSuite(ValidationTest.class);
     suite.addTestSuite(OBContextTest.class);
     suite.addTestSuite(DalStoredProcedureTest.class);
+    suite.addTestSuite(ReadByNameTest.class);
 
     // expression
     suite.addTestSuite(EvaluationTest.class);
diff -r 9f67838a3ea8 -r aa9268a67b3d 
src-test/org/openbravo/test/dal/ReadByNameTest.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/org/openbravo/test/dal/ReadByNameTest.java       Mon Mar 01 
13:25:09 2010 +0100
@@ -0,0 +1,148 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.0  (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 SL 
+ * All portions are Copyright (C) 2010 Openbravo SL 
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.test.dal;
+
+import java.util.UUID;
+
+import org.hibernate.criterion.Expression;
+import org.openbravo.base.provider.OBProvider;
+import org.openbravo.dal.service.OBCriteria;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.common.businesspartner.BusinessPartner;
+import org.openbravo.model.common.businesspartner.Category;
+import org.openbravo.model.common.businesspartner.Location;
+import org.openbravo.test.base.BaseTest;
+
+/**
+ * Tests creating a location and then reading it again using the {...@link 
OBCriteria} api.
+ * 
+ * @author iperdomo
+ */
+public class ReadByNameTest extends BaseTest {
+
+  // Will hold Ids for next tests
+  private static String bpId; // Business Partner Id
+  private static String locId; // Location Id
+  private static String locName; // Location name
+
+  public void testCreateBP() {
+
+    setBigBazaarUserContext();
+    addReadWriteAccess(BusinessPartner.class);
+    addReadWriteAccess(Location.class);
+    addReadWriteAccess(Category.class);
+
+    BusinessPartner bp = OBProvider.getInstance().get(BusinessPartner.class);
+
+    // Generating random strings for testing
+    UUID name = UUID.randomUUID();
+    UUID key = UUID.randomUUID();
+
+    bp.setName(name.toString());
+    bp.setSearchKey(key.toString());
+
+    Category c = OBDal.getInstance().get(Category.class, "1000000"); // 
Standard
+
+    bp.setBusinessPartnerCategory(c);
+
+    OBDal.getInstance().save(bp);
+    OBDal.getInstance().flush();
+    bpId = bp.getId();
+  }
+
+  public void testAddLocation() {
+
+    setBigBazaarUserContext();
+    addReadWriteAccess(BusinessPartner.class);
+    addReadWriteAccess(org.openbravo.model.common.geography.Location.class);
+    
addReadWriteAccess(org.openbravo.model.common.businesspartner.Location.class);
+
+    BusinessPartner bp = OBDal.getInstance().get(BusinessPartner.class, bpId);
+
+    assertNotNull(bp);
+
+    // Getting an existent Location
+    org.openbravo.model.common.geography.Location loc = 
OBDal.getInstance().get(
+        org.openbravo.model.common.geography.Location.class, "1000020");
+
+    org.openbravo.model.common.businesspartner.Location bpLoc = 
OBProvider.getInstance().get(
+        org.openbravo.model.common.businesspartner.Location.class);
+
+    // Generating a location name
+    locName = UUID.randomUUID().toString();
+
+    bpLoc.setName(locName);
+    bpLoc.setLocationAddress(loc);
+    bpLoc.setBusinessPartner(bp);
+    bpLoc.setInvoiceToAddress(false);
+    bpLoc.setPayFromAddress(false);
+    bpLoc.setRemitToAddress(false);
+    bpLoc.setShipToAddress(false);
+
+    OBDal.getInstance().save(bpLoc);
+    OBDal.getInstance().flush();
+
+    locId = bpLoc.getId();
+  }
+
+  public void testFindLocation() {
+    // tests have run in the correct order
+    assertNotNull(locName);
+    assertNotNull(locId);
+
+    // Search for a BPLocation if you don't have the Id
+    setBigBazaarUserContext();
+    addReadWriteAccess(BusinessPartner.class);
+    addReadWriteAccess(org.openbravo.model.common.geography.Location.class);
+    
addReadWriteAccess(org.openbravo.model.common.businesspartner.Location.class);
+
+    OBCriteria<org.openbravo.model.common.businesspartner.Location> obc = 
OBDal.getInstance()
+        
.createCriteria(org.openbravo.model.common.businesspartner.Location.class);
+
+    
obc.add(Expression.eq(org.openbravo.model.common.businesspartner.Location.PROPERTY_NAME,
+        locName));
+
+    assertFalse(obc.list().isEmpty());
+
+    final org.openbravo.model.common.businesspartner.Location tmpLoc = 
obc.list().get(0);
+
+    assertEquals(locId, tmpLoc.getId());
+    assertEquals(locName, tmpLoc.getName());
+  }
+
+  public void testPBData() {
+
+    setBigBazaarUserContext();
+    addReadWriteAccess(BusinessPartner.class);
+    
addReadWriteAccess(org.openbravo.model.common.businesspartner.Location.class);
+
+    BusinessPartner bp = OBDal.getInstance().get(BusinessPartner.class, bpId);
+    assertTrue(bp.getBusinessPartnerLocationList().size() > 0);
+    for (org.openbravo.model.common.businesspartner.Location loc : bp
+        .getBusinessPartnerLocationList()) {
+      System.out.println(loc);
+      System.out.println(loc.getLocationAddress());
+    }
+    setBigBazaarAdminContext();
+    OBDal.getInstance().remove(bp);
+
+    assertNull(OBDal.getInstance().get(BusinessPartner.class, bpId));
+    assertNull(OBDal.getInstance().get(Location.class, locId));
+  }
+}

------------------------------------------------------------------------------
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