diff --git a/base/src/org/compiere/model/PO.java b/base/src/org/compiere/model/PO.java index abaf753dad..d022ce0575 100644 --- a/base/src/org/compiere/model/PO.java +++ b/base/src/org/compiere/model/PO.java @@ -36,6 +36,8 @@ import org.w3c.dom.*; * * @author Jorg Janke * @version $Id: PO.java,v 1.12 2006/08/09 16:38:47 jjanke Exp $ + * + * @author Teo Sarca - FR [ 1675490 ], BF [ 1704828 ] */ public abstract class PO implements Serializable, Comparator, Evaluatee @@ -1801,7 +1803,6 @@ public abstract class PO return false; } // Save - boolean success = false; if (newRecord) return saveNew(); else @@ -1902,8 +1903,9 @@ public abstract class PO int size = get_ColumnCount(); for (int i = 0; i < size; i++) { - if (m_newValues[i] != null) - return true; // something changed + // Test if the column has changed - teo_sarca [ 1704828 ] + if (is_ValueChanged(i)) + return true; } if (m_custom != null && m_custom.size() > 0) return true; // there are custom columns modified diff --git a/extend/src/test/functional/FunctionalTestSuite.java b/extend/src/test/functional/FunctionalTestSuite.java index 3f5eb1e242..fc9ffbff61 100644 --- a/extend/src/test/functional/FunctionalTestSuite.java +++ b/extend/src/test/functional/FunctionalTestSuite.java @@ -14,6 +14,7 @@ public class FunctionalTestSuite { suite.addTestSuite(MUserTest.class); suite.addTestSuite(MBPGroupTest.class); suite.addTestSuite(MLocationTest.class); + suite.addTestSuite(POTest.class); //$JUnit-END$ return suite; } diff --git a/extend/src/test/functional/POTest.java b/extend/src/test/functional/POTest.java new file mode 100644 index 0000000000..fd0293d577 --- /dev/null +++ b/extend/src/test/functional/POTest.java @@ -0,0 +1,61 @@ +package test.functional; + +import org.compiere.model.MTest; + +import test.AdempiereTestCase; + +/** + * Tests for {@link org.compiere.model.PO} class. + * @author Teo Sarca + * + */ +public class POTest extends AdempiereTestCase +{ + /** + * Tests the following methods: + * + * Applies to following bugs: + * + * @throws Exception + */ + public void test_Changed() throws Exception { + String[] testStrings = new String[] { + "a", + "test", + }; + // Create the test PO and save + MTest testPO = new MTest(getCtx(), getClass().getName(), 1); + testPO.set_TrxName(getTrxName()); + + for (String str : testStrings) { + testPO.setHelp(str); + testPO.save(); + String originalString = testPO.getHelp(); + String info = "testString=[" + str + "]" + ", originalString=[" + originalString + "]"; + + // Initial asserts (nothing changed) + assertFalse(info, testPO.is_ValueChanged(MTest.COLUMNNAME_Help)); + assertFalse(info, testPO.is_Changed()); + // Set the same name + testPO.setHelp(originalString); + assertFalse(info, testPO.is_ValueChanged(MTest.COLUMNNAME_Help)); + assertFalse(info, testPO.is_Changed()); + // Set a new name + testPO.setHelp(originalString+"-changed"); + assertTrue(info, testPO.is_ValueChanged(MTest.COLUMNNAME_Help)); + assertTrue(info, testPO.is_Changed()); + // Set the original name back + testPO.setHelp(originalString); + assertFalse(info, testPO.is_ValueChanged(MTest.COLUMNNAME_Help)); + assertFalse(info, testPO.is_Changed()); + } + + // Finally, delete the testPO + testPO.delete(true, getTrxName()); + } +}