IDEMPIERE-5712 Tests are leaving records in the database (#1827)

* IDEMPIERE-5712 Tests are leaving records in the database

* - add transaction

* - add cleanup for records committed out of transaction
This commit is contained in:
Carlos Ruiz 2023-05-16 10:32:15 +02:00 committed by GitHub
parent 089f491363
commit d734cafd9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 11 deletions

View File

@ -80,7 +80,19 @@ public class MTest extends X_Test
*/
public MTest (Properties ctx, String testString, int testNo)
{
super(ctx, 0, null);
this(ctx, testString, testNo, null);
}
/**
* Test Object Constructor
* @param ctx context
* @param testString test string
* @param testNo test no
* @param trxName
*/
public MTest (Properties ctx, String testString, int testNo, String trxName)
{
super(ctx, 0, trxName);
testString = testString + "_" + testNo;
setName(testString);
setDescription(testString + " " + testString + " " + testString);

View File

@ -90,8 +90,7 @@ public class POTest extends AbstractTestCase
public MyTestPO(Properties ctx, boolean failOnSave, String trxName)
{
super(ctx, "Test_"+System.currentTimeMillis(), 10);
this.set_TrxName(trxName);
super(ctx, "Test_"+System.currentTimeMillis(), 10, trxName);
this.setDescription(""+getClass());
this.failOnSave = failOnSave;
}
@ -140,8 +139,7 @@ public class POTest extends AbstractTestCase
"test",
};
// Create the test PO and save
MTest testPO = new MTest(Env.getCtx(), getClass().getName(), 1);
testPO.set_TrxName(getTrxName());
MTest testPO = new MTest(Env.getCtx(), getClass().getName(), 1, getTrxName());
for (String str : testStrings)
{
@ -186,8 +184,7 @@ public class POTest extends AbstractTestCase
String bigString = sb.toString();
//
// Create the test PO:
MTest testPO = new MTest(Env.getCtx(), getClass().getName(), 1);
testPO.set_TrxName(getTrxName());
MTest testPO = new MTest(Env.getCtx(), getClass().getName(), 1, getTrxName());
//
// Getting Max Length:
POInfo info = POInfo.getPOInfo(Env.getCtx(), MTest.Table_ID);
@ -240,8 +237,10 @@ public class POTest extends AbstractTestCase
}
//
// Test for old objects
MyTestPO test = null;
try
{
MyTestPO test = new MyTestPO(Env.getCtx(), false, null);
test = new MyTestPO(Env.getCtx(), false, null);
assertTrue(test.save(), "Object *should* be saved -- "+test);
//
MyTestPO test2 = new MyTestPO(Env.getCtx(), test.get_ID(), null);
@ -253,6 +252,19 @@ public class POTest extends AbstractTestCase
String name = MyTestPO.getName(test2.get_ID(), null);
assertEquals(test.getName(), name, "Object should not be modified(2) -- id="+test2);
}
finally
{
// cleanup
if (test != null)
{
if (test.getDependent_ID() > 0)
{
MyTestPO testDependent = new MyTestPO(Env.getCtx(), test.getDependent_ID(), null);
testDependent.deleteEx(true);
}
test.deleteEx(true);
}
}
}
/**
@ -475,7 +487,7 @@ public class POTest extends AbstractTestCase
@Test
public void testVirtualColumnLoad() {
MTest testPo = new MTest(Env.getCtx(), getClass().getName(), 1);
MTest testPo = new MTest(Env.getCtx(), getClass().getName(), 1, getTrxName());
testPo.save();
// asynchronous (default) virtual column loading

View File

@ -255,7 +255,7 @@ public class QueryTest extends AbstractTestCase {
public void testPaging() {
DB.executeUpdateEx("DELETE FROM Test WHERE Name LIKE 'QueryTest%'", getTrxName());
for (int i=101; i<=130; i++) {
PO testPo = new MTest(Env.getCtx(), "QueryTest", i);
PO testPo = new MTest(Env.getCtx(), "QueryTest", i, getTrxName());
testPo.save();
}
Query query = new Query(Env.getCtx(), MTest.Table_Name, "Name LIKE 'QueryTest%'", getTrxName())
@ -397,7 +397,7 @@ public class QueryTest extends AbstractTestCase {
@Test
public void testVirtualColumnLoad() {
// create bogus record
PO testPo = new MTest(Env.getCtx(), getClass().getName(), 1);
PO testPo = new MTest(Env.getCtx(), getClass().getName(), 1, getTrxName());
testPo.save();
BigDecimal expected = new BigDecimal("123.45");