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:
parent
089f491363
commit
d734cafd9b
|
@ -80,7 +80,19 @@ public class MTest extends X_Test
|
||||||
*/
|
*/
|
||||||
public MTest (Properties ctx, String testString, int testNo)
|
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;
|
testString = testString + "_" + testNo;
|
||||||
setName(testString);
|
setName(testString);
|
||||||
setDescription(testString + " " + testString + " " + testString);
|
setDescription(testString + " " + testString + " " + testString);
|
||||||
|
|
|
@ -90,8 +90,7 @@ public class POTest extends AbstractTestCase
|
||||||
|
|
||||||
public MyTestPO(Properties ctx, boolean failOnSave, String trxName)
|
public MyTestPO(Properties ctx, boolean failOnSave, String trxName)
|
||||||
{
|
{
|
||||||
super(ctx, "Test_"+System.currentTimeMillis(), 10);
|
super(ctx, "Test_"+System.currentTimeMillis(), 10, trxName);
|
||||||
this.set_TrxName(trxName);
|
|
||||||
this.setDescription(""+getClass());
|
this.setDescription(""+getClass());
|
||||||
this.failOnSave = failOnSave;
|
this.failOnSave = failOnSave;
|
||||||
}
|
}
|
||||||
|
@ -140,8 +139,7 @@ public class POTest extends AbstractTestCase
|
||||||
"test",
|
"test",
|
||||||
};
|
};
|
||||||
// Create the test PO and save
|
// Create the test PO and save
|
||||||
MTest testPO = new MTest(Env.getCtx(), getClass().getName(), 1);
|
MTest testPO = new MTest(Env.getCtx(), getClass().getName(), 1, getTrxName());
|
||||||
testPO.set_TrxName(getTrxName());
|
|
||||||
|
|
||||||
for (String str : testStrings)
|
for (String str : testStrings)
|
||||||
{
|
{
|
||||||
|
@ -186,8 +184,7 @@ public class POTest extends AbstractTestCase
|
||||||
String bigString = sb.toString();
|
String bigString = sb.toString();
|
||||||
//
|
//
|
||||||
// Create the test PO:
|
// Create the test PO:
|
||||||
MTest testPO = new MTest(Env.getCtx(), getClass().getName(), 1);
|
MTest testPO = new MTest(Env.getCtx(), getClass().getName(), 1, getTrxName());
|
||||||
testPO.set_TrxName(getTrxName());
|
|
||||||
//
|
//
|
||||||
// Getting Max Length:
|
// Getting Max Length:
|
||||||
POInfo info = POInfo.getPOInfo(Env.getCtx(), MTest.Table_ID);
|
POInfo info = POInfo.getPOInfo(Env.getCtx(), MTest.Table_ID);
|
||||||
|
@ -240,8 +237,10 @@ public class POTest extends AbstractTestCase
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// Test for old objects
|
// 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);
|
assertTrue(test.save(), "Object *should* be saved -- "+test);
|
||||||
//
|
//
|
||||||
MyTestPO test2 = new MyTestPO(Env.getCtx(), test.get_ID(), null);
|
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);
|
String name = MyTestPO.getName(test2.get_ID(), null);
|
||||||
assertEquals(test.getName(), name, "Object should not be modified(2) -- id="+test2);
|
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
|
@Test
|
||||||
public void testVirtualColumnLoad() {
|
public void testVirtualColumnLoad() {
|
||||||
MTest testPo = new MTest(Env.getCtx(), getClass().getName(), 1);
|
MTest testPo = new MTest(Env.getCtx(), getClass().getName(), 1, getTrxName());
|
||||||
testPo.save();
|
testPo.save();
|
||||||
|
|
||||||
// asynchronous (default) virtual column loading
|
// asynchronous (default) virtual column loading
|
||||||
|
|
|
@ -255,7 +255,7 @@ public class QueryTest extends AbstractTestCase {
|
||||||
public void testPaging() {
|
public void testPaging() {
|
||||||
DB.executeUpdateEx("DELETE FROM Test WHERE Name LIKE 'QueryTest%'", getTrxName());
|
DB.executeUpdateEx("DELETE FROM Test WHERE Name LIKE 'QueryTest%'", getTrxName());
|
||||||
for (int i=101; i<=130; i++) {
|
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();
|
testPo.save();
|
||||||
}
|
}
|
||||||
Query query = new Query(Env.getCtx(), MTest.Table_Name, "Name LIKE 'QueryTest%'", getTrxName())
|
Query query = new Query(Env.getCtx(), MTest.Table_Name, "Name LIKE 'QueryTest%'", getTrxName())
|
||||||
|
@ -397,7 +397,7 @@ public class QueryTest extends AbstractTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testVirtualColumnLoad() {
|
public void testVirtualColumnLoad() {
|
||||||
// create bogus record
|
// create bogus record
|
||||||
PO testPo = new MTest(Env.getCtx(), getClass().getName(), 1);
|
PO testPo = new MTest(Env.getCtx(), getClass().getName(), 1, getTrxName());
|
||||||
testPo.save();
|
testPo.save();
|
||||||
|
|
||||||
BigDecimal expected = new BigDecimal("123.45");
|
BigDecimal expected = new BigDecimal("123.45");
|
||||||
|
|
Loading…
Reference in New Issue