IDEMPIERE-5063 Improve Unit Tests (#1232)
- Close DB connections after each unit test class - POTest and QueryTest: use assert equals, use bigdecimal string constructor in preference to double
This commit is contained in:
parent
4510623381
commit
1f9141353c
|
@ -33,6 +33,7 @@ import org.compiere.Adempiere;
|
||||||
import org.compiere.model.MAcctSchema;
|
import org.compiere.model.MAcctSchema;
|
||||||
import org.compiere.model.MClientInfo;
|
import org.compiere.model.MClientInfo;
|
||||||
import org.compiere.model.MRole;
|
import org.compiere.model.MRole;
|
||||||
|
import org.compiere.util.DB;
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
import org.compiere.util.Language;
|
import org.compiere.util.Language;
|
||||||
import org.compiere.util.Trx;
|
import org.compiere.util.Trx;
|
||||||
|
@ -225,5 +226,6 @@ public abstract class AbstractTestCase {
|
||||||
*/
|
*/
|
||||||
static void shutdown() {
|
static void shutdown() {
|
||||||
Adempiere.stop();
|
Adempiere.stop();
|
||||||
|
DB.getDatabase().close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -459,13 +459,13 @@ public class POTest extends AbstractTestCase
|
||||||
|
|
||||||
// asynchronous (default) virtual column loading
|
// asynchronous (default) virtual column loading
|
||||||
assertTrue(null == testPo.get_ValueOld(MTest.COLUMNNAME_TestVirtualQty));
|
assertTrue(null == testPo.get_ValueOld(MTest.COLUMNNAME_TestVirtualQty));
|
||||||
BigDecimal expected = new BigDecimal(123.45d).setScale(2, RoundingMode.HALF_DOWN);
|
BigDecimal expected = new BigDecimal("123.45");
|
||||||
assertTrue(expected.compareTo(testPo.getTestVirtualQty()) == 0);
|
assertEquals(expected, testPo.getTestVirtualQty().setScale(2, RoundingMode.HALF_UP), "Wrong value returned");
|
||||||
|
|
||||||
// synchronous virtual column loading
|
// synchronous virtual column loading
|
||||||
testPo = new MTest(Env.getCtx(), testPo.get_ID(), getTrxName(), MTest.COLUMNNAME_TestVirtualQty);
|
testPo = new MTest(Env.getCtx(), testPo.get_ID(), getTrxName(), MTest.COLUMNNAME_TestVirtualQty);
|
||||||
assertTrue(null != testPo.get_ValueOld(MTest.COLUMNNAME_TestVirtualQty));
|
assertTrue(null != testPo.get_ValueOld(MTest.COLUMNNAME_TestVirtualQty));
|
||||||
assertTrue(expected.compareTo(testPo.getTestVirtualQty()) == 0);
|
assertEquals(expected, testPo.getTestVirtualQty().setScale(2, RoundingMode.HALF_UP), "Wrong value returned");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -380,27 +380,27 @@ public class QueryTest extends AbstractTestCase {
|
||||||
PO testPo = new MTest(Env.getCtx(), getClass().getName(), 1);
|
PO testPo = new MTest(Env.getCtx(), getClass().getName(), 1);
|
||||||
testPo.save();
|
testPo.save();
|
||||||
|
|
||||||
BigDecimal expected = new BigDecimal(123.45d).setScale(2, RoundingMode.HALF_DOWN);
|
BigDecimal expected = new BigDecimal("123.45");
|
||||||
|
|
||||||
// virtual column lazy loading
|
// virtual column lazy loading
|
||||||
Query query = new Query(Env.getCtx(), MTest.Table_Name, MTest.COLUMNNAME_Test_ID + "=?", getTrxName());
|
Query query = new Query(Env.getCtx(), MTest.Table_Name, MTest.COLUMNNAME_Test_ID + "=?", getTrxName());
|
||||||
testPo = query.setParameters(testPo.get_ID()).first();
|
testPo = query.setParameters(testPo.get_ID()).first();
|
||||||
I_Test testRecord = POWrapper.create(testPo, I_Test.class);
|
I_Test testRecord = POWrapper.create(testPo, I_Test.class);
|
||||||
assertTrue(null == testPo.get_ValueOld(MTest.COLUMNNAME_TestVirtualQty));
|
assertTrue(null == testPo.get_ValueOld(MTest.COLUMNNAME_TestVirtualQty));
|
||||||
assertTrue(expected.compareTo(testRecord.getTestVirtualQty()) == 0);
|
assertEquals(expected, testRecord.getTestVirtualQty().setScale(2, RoundingMode.HALF_UP), "Wrong value returned");
|
||||||
|
|
||||||
// without virtual column lazy loading
|
// without virtual column lazy loading
|
||||||
testPo = query.setNoVirtualColumn(false).setParameters(testPo.get_ID()).first();
|
testPo = query.setNoVirtualColumn(false).setParameters(testPo.get_ID()).first();
|
||||||
assertTrue(null != testPo.get_ValueOld(MTest.COLUMNNAME_TestVirtualQty));
|
assertTrue(null != testPo.get_ValueOld(MTest.COLUMNNAME_TestVirtualQty));
|
||||||
testRecord = POWrapper.create(testPo, I_Test.class);
|
testRecord = POWrapper.create(testPo, I_Test.class);
|
||||||
assertTrue(expected.compareTo(testRecord.getTestVirtualQty()) == 0);
|
assertEquals(expected, testRecord.getTestVirtualQty().setScale(2, RoundingMode.HALF_UP), "Wrong value returned");
|
||||||
|
|
||||||
// single virtual column without lazy loading
|
// single virtual column without lazy loading
|
||||||
testPo = query.setVirtualColumns(I_Test.COLUMNNAME_TestVirtualQty)
|
testPo = query.setVirtualColumns(I_Test.COLUMNNAME_TestVirtualQty)
|
||||||
.setParameters(testPo.get_ID()).first();
|
.setParameters(testPo.get_ID()).first();
|
||||||
assertTrue(null != testPo.get_ValueOld(MTest.COLUMNNAME_TestVirtualQty));
|
assertTrue(null != testPo.get_ValueOld(MTest.COLUMNNAME_TestVirtualQty));
|
||||||
testRecord = POWrapper.create(testPo, I_Test.class);
|
testRecord = POWrapper.create(testPo, I_Test.class);
|
||||||
assertTrue(expected.compareTo(testRecord.getTestVirtualQty()) == 0);
|
assertEquals(expected, testRecord.getTestVirtualQty().setScale(2, RoundingMode.HALF_UP), "Wrong value returned");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue