IDEMPIERE-2981 Fixes to failing unit tests (#2263)
This commit is contained in:
parent
5f44c9c19d
commit
924bdb6fc1
|
|
@ -83,10 +83,12 @@ public abstract class Convert
|
||||||
/** Logger */
|
/** Logger */
|
||||||
private static final CLogger log = CLogger.getCLogger (Convert.class);
|
private static final CLogger log = CLogger.getCLogger (Convert.class);
|
||||||
|
|
||||||
|
private static File fileOr = null;
|
||||||
private static FileOutputStream fosScriptOr = null;
|
private static FileOutputStream fosScriptOr = null;
|
||||||
private static Writer writerOr;
|
private static Writer writerOr = null;
|
||||||
|
private static File filePg = null;
|
||||||
private static FileOutputStream fosScriptPg = null;
|
private static FileOutputStream fosScriptPg = null;
|
||||||
private static Writer writerPg;
|
private static Writer writerPg = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Verbose
|
* Set Verbose
|
||||||
|
|
@ -471,7 +473,7 @@ public abstract class Convert
|
||||||
Files.createDirectories(Paths.get(folderPg));
|
Files.createDirectories(Paths.get(folderPg));
|
||||||
}
|
}
|
||||||
if (fosScriptOr == null) {
|
if (fosScriptOr == null) {
|
||||||
File fileOr = new File(folderOr + fileName);
|
fileOr = new File(folderOr + fileName);
|
||||||
fosScriptOr = new FileOutputStream(fileOr, true);
|
fosScriptOr = new FileOutputStream(fileOr, true);
|
||||||
writerOr = new BufferedWriter(new OutputStreamWriter(fosScriptOr, "UTF8"));
|
writerOr = new BufferedWriter(new OutputStreamWriter(fosScriptOr, "UTF8"));
|
||||||
writerOr.append("-- ");
|
writerOr.append("-- ");
|
||||||
|
|
@ -488,7 +490,7 @@ public abstract class Convert
|
||||||
pgStatement = r[0];
|
pgStatement = r[0];
|
||||||
}
|
}
|
||||||
if (fosScriptPg == null) {
|
if (fosScriptPg == null) {
|
||||||
File filePg = new File(folderPg + fileName);
|
filePg = new File(folderPg + fileName);
|
||||||
fosScriptPg = new FileOutputStream(filePg, true);
|
fosScriptPg = new FileOutputStream(filePg, true);
|
||||||
writerPg = new BufferedWriter(new OutputStreamWriter(fosScriptPg, "UTF8"));
|
writerPg = new BufferedWriter(new OutputStreamWriter(fosScriptPg, "UTF8"));
|
||||||
writerPg.append("-- ");
|
writerPg.append("-- ");
|
||||||
|
|
@ -688,4 +690,48 @@ public abstract class Convert
|
||||||
w.flush();
|
w.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the files for migration scripts, used just on Tests
|
||||||
|
*/
|
||||||
|
public static void closeLogMigrationScript() {
|
||||||
|
try {
|
||||||
|
if (writerOr != null) {
|
||||||
|
writerOr.flush();
|
||||||
|
writerOr.close();
|
||||||
|
writerOr = null;
|
||||||
|
}
|
||||||
|
if (writerPg != null) {
|
||||||
|
writerPg.flush();
|
||||||
|
writerPg.close();
|
||||||
|
writerPg = null;
|
||||||
|
}
|
||||||
|
if (fosScriptOr != null) {
|
||||||
|
fosScriptOr.flush();
|
||||||
|
fosScriptOr.close();
|
||||||
|
fosScriptOr = null;
|
||||||
|
}
|
||||||
|
if (fosScriptPg != null) {
|
||||||
|
fosScriptPg.flush();
|
||||||
|
fosScriptPg.close();
|
||||||
|
fosScriptPg = null;
|
||||||
|
}
|
||||||
|
fileOr = null;
|
||||||
|
filePg = null;
|
||||||
|
} catch (IOException e) {
|
||||||
|
// ignore
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name of the migration script file
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getGeneratedMigrationScriptFileName() {
|
||||||
|
if (filePg != null) {
|
||||||
|
return filePg.getName();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
} // Convert
|
} // Convert
|
||||||
|
|
@ -6,12 +6,19 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import org.compiere.dbPort.Convert;
|
import org.compiere.dbPort.Convert;
|
||||||
|
import org.compiere.model.I_AD_UserPreference;
|
||||||
import org.compiere.model.MTest;
|
import org.compiere.model.MTest;
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
import org.compiere.util.Ini;
|
import org.compiere.util.Ini;
|
||||||
import org.idempiere.test.AbstractTestCase;
|
import org.idempiere.test.AbstractTestCase;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.parallel.Isolated;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for JSON data type
|
||||||
|
* Run Isolated because of migration script file management
|
||||||
|
*/
|
||||||
|
@Isolated
|
||||||
public class JsonFieldTest extends AbstractTestCase {
|
public class JsonFieldTest extends AbstractTestCase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -43,12 +50,9 @@ public class JsonFieldTest extends AbstractTestCase {
|
||||||
updated = testPO.save();
|
updated = testPO.save();
|
||||||
assertTrue(updated);
|
assertTrue(updated);
|
||||||
|
|
||||||
String fileName = Convert.getMigrationScriptFileName("testLogMigrationScript");
|
|
||||||
String folderPg = Convert.getMigrationScriptFolder("postgresql");
|
|
||||||
String folderOr = Convert.getMigrationScriptFolder("oracle");
|
|
||||||
|
|
||||||
//Test inserting/updating with Values
|
//Test inserting/updating with Values
|
||||||
Env.getCtx().setProperty(Ini.P_LOGMIGRATIONSCRIPT, "Y");
|
Env.getCtx().setProperty(Ini.P_LOGMIGRATIONSCRIPT, "Y");
|
||||||
|
Env.setContext(Env.getCtx(), I_AD_UserPreference.COLUMNNAME_MigrationScriptComment, "IDEMPIERE-02981 JsonFieldTest");
|
||||||
testPO.setJsonData(validJsonString);
|
testPO.setJsonData(validJsonString);
|
||||||
updated = testPO.save();
|
updated = testPO.save();
|
||||||
assertTrue(updated);
|
assertTrue(updated);
|
||||||
|
|
@ -59,7 +63,10 @@ public class JsonFieldTest extends AbstractTestCase {
|
||||||
|
|
||||||
Env.getCtx().setProperty(Ini.P_LOGMIGRATIONSCRIPT, "");
|
Env.getCtx().setProperty(Ini.P_LOGMIGRATIONSCRIPT, "");
|
||||||
|
|
||||||
rollback();
|
String fileName = Convert.getGeneratedMigrationScriptFileName();
|
||||||
|
String folderPg = Convert.getMigrationScriptFolder("postgresql");
|
||||||
|
String folderOr = Convert.getMigrationScriptFolder("oracle");
|
||||||
|
Convert.closeLogMigrationScript();
|
||||||
File file = new File(folderPg + fileName);
|
File file = new File(folderPg + fileName);
|
||||||
assertTrue(file.exists(), "Not found: " + folderPg + fileName);
|
assertTrue(file.exists(), "Not found: " + folderPg + fileName);
|
||||||
file.delete();
|
file.delete();
|
||||||
|
|
|
||||||
|
|
@ -58,12 +58,16 @@ import org.compiere.util.Trx;
|
||||||
import org.idempiere.test.AbstractTestCase;
|
import org.idempiere.test.AbstractTestCase;
|
||||||
import org.idempiere.test.DictionaryIDs;
|
import org.idempiere.test.DictionaryIDs;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.parallel.Isolated;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link org.compiere.model.PO} class.
|
* Tests for {@link org.compiere.model.PO} class.
|
||||||
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
|
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
|
||||||
* @author hengsin
|
* @author hengsin
|
||||||
|
*
|
||||||
|
* Run Isolated because of migration script file management
|
||||||
*/
|
*/
|
||||||
|
@Isolated
|
||||||
public class POTest extends AbstractTestCase
|
public class POTest extends AbstractTestCase
|
||||||
{
|
{
|
||||||
public static class MyTestPO extends MTest
|
public static class MyTestPO extends MTest
|
||||||
|
|
@ -512,9 +516,6 @@ public class POTest extends AbstractTestCase
|
||||||
Env.getCtx().setProperty(Ini.P_LOGMIGRATIONSCRIPT, "Y");
|
Env.getCtx().setProperty(Ini.P_LOGMIGRATIONSCRIPT, "Y");
|
||||||
Env.setContext(Env.getCtx(), I_AD_UserPreference.COLUMNNAME_MigrationScriptComment, "testLogMigrationScript");
|
Env.setContext(Env.getCtx(), I_AD_UserPreference.COLUMNNAME_MigrationScriptComment, "testLogMigrationScript");
|
||||||
assertTrue(Env.isLogMigrationScript(MProduct.Table_Name), "Unexpected Log Migration Script Y/N value for MProduct");
|
assertTrue(Env.isLogMigrationScript(MProduct.Table_Name), "Unexpected Log Migration Script Y/N value for MProduct");
|
||||||
String fileName = Convert.getMigrationScriptFileName("testLogMigrationScript");
|
|
||||||
String folderPg = Convert.getMigrationScriptFolder("postgresql");
|
|
||||||
String folderOr = Convert.getMigrationScriptFolder("oracle");
|
|
||||||
|
|
||||||
MProductCategory lotLevel = new MProductCategory(Env.getCtx(), 0, null);
|
MProductCategory lotLevel = new MProductCategory(Env.getCtx(), 0, null);
|
||||||
lotLevel.setName("testLogMigrationScript");
|
lotLevel.setName("testLogMigrationScript");
|
||||||
|
|
@ -548,6 +549,10 @@ public class POTest extends AbstractTestCase
|
||||||
lotLevel.deleteEx(true);
|
lotLevel.deleteEx(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String fileName = Convert.getGeneratedMigrationScriptFileName();
|
||||||
|
String folderPg = Convert.getMigrationScriptFolder("postgresql");
|
||||||
|
String folderOr = Convert.getMigrationScriptFolder("oracle");
|
||||||
|
Convert.closeLogMigrationScript();
|
||||||
File file = new File(folderPg + fileName);
|
File file = new File(folderPg + fileName);
|
||||||
assertTrue(file.exists(), "Not found: " + folderPg + fileName);
|
assertTrue(file.exists(), "Not found: " + folderPg + fileName);
|
||||||
file.delete();
|
file.delete();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue