details: https://code.openbravo.com/erp/devel/pi/rev/65a8e7ba6ceb
changeset: 33416:65a8e7ba6ceb
user: Asier Lostalé <asier.lostale <at> openbravo.com>
date: Fri Feb 09 10:15:25 2018 +0100
summary: fixed bug 37648: slow junit ViewTest test cases
testViews (renamed to viewsCanBeQueried)
* Queries all the visible records for all views in system loading those
records
in memory. Now, record is limited to just one and we stop querying views
once
one record is retrieved.
test14914
* All invoices in the instance were loaded in memory loading for those all
their
payments and making a copy. Now only one invoice is loaded.
diffstat:
src-test/src/org/openbravo/test/dal/ViewTest.java | 54 ++++++++++++++--------
1 files changed, 34 insertions(+), 20 deletions(-)
diffs (98 lines):
diff -r 9bf627820d9e -r 65a8e7ba6ceb
src-test/src/org/openbravo/test/dal/ViewTest.java
--- a/src-test/src/org/openbravo/test/dal/ViewTest.java Fri Feb 09 09:43:33
2018 +0100
+++ b/src-test/src/org/openbravo/test/dal/ViewTest.java Fri Feb 09 10:15:25
2018 +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) 2010-2014 Openbravo SLU
+ * All portions are Copyright (C) 2010-2018 Openbravo SLU
* All Rights Reserved.
* Contributor(s): ______________________________________.
************************************************************************
@@ -19,15 +19,22 @@
package org.openbravo.test.dal;
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.Matchers.empty;
+import static org.junit.Assert.assertThat;
+import org.hibernate.criterion.Restrictions;
import org.junit.Test;
import org.openbravo.base.model.Entity;
import org.openbravo.base.model.ModelProvider;
import org.openbravo.base.structure.BaseOBObject;
import org.openbravo.dal.core.DalUtil;
import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBCriteria;
import org.openbravo.dal.service.OBDal;
+import org.openbravo.dal.service.OBQuery;
import org.openbravo.model.common.invoice.Invoice;
import org.openbravo.test.base.OBBaseTest;
@@ -42,19 +49,25 @@
* Iterates over all views
*/
@Test
- public void testViews() {
+ public void viewsCanBeQueried() {
setTestAdminContext();
- int cnt = 0;
+ BaseOBObject aViewBOB = null;
+ Entity aViewEntity = null;
for (Entity entity : ModelProvider.getInstance().getModel()) {
- if (entity.isView()) {
- for (BaseOBObject bob :
OBDal.getInstance().createQuery(entity.getName(), "").list()) {
- assertTrue(bob.getEntity() == entity);
- cnt++;
- }
+ if (!entity.isView()) {
+ continue;
+ }
+
+ OBQuery<BaseOBObject> query =
OBDal.getInstance().createQuery(entity.getName(), "");
+ query.setMaxResult(1);
+ aViewBOB = query.uniqueResult();
+ if (aViewBOB != null) {
+ aViewEntity = entity;
+ break;
}
}
- assertTrue(cnt > 0);
- System.err.println(cnt);
+ assertThat("There is at least an object queried from a view", aViewBOB,
not(nullValue()));
+ assertThat("Entity is correctly set", aViewBOB.getEntity(),
is(aViewEntity));
}
/**
@@ -64,16 +77,17 @@
public void test14914() {
setTestUserContext();
OBContext.setAdminMode();
- boolean testDone = false;
try {
- for (Invoice o : OBDal.getInstance().createQuery(Invoice.class,
"").list()) {
- if (!o.getFINPaymentSchedInvVList().isEmpty()) {
- final Invoice copied = (Invoice) DalUtil.copy(o);
- assertTrue(copied.getFINPaymentSchedInvVList().isEmpty());
- testDone = true;
- }
- }
- assertTrue(testDone);
+ OBCriteria<Invoice> payedInvoice =
OBDal.getInstance().createCriteria(Invoice.class);
+ payedInvoice.add(Restrictions.eq(Invoice.PROPERTY_PAYMENTCOMPLETE,
true));
+ payedInvoice.setMaxResults(1);
+ Invoice anyPayedInvoice = (Invoice) payedInvoice.uniqueResult();
+ assertThat("Original invoice has payments " + anyPayedInvoice,
+ anyPayedInvoice.getFINPaymentSchedInvVList(), not(empty()));
+
+ final Invoice copied = (Invoice) DalUtil.copy(anyPayedInvoice);
+ assertThat("Copied invoice has NO payments " + copied,
copied.getFINPaymentSchedInvVList(),
+ is(empty()));
} finally {
OBContext.restorePreviousMode();
}
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits