BF [ 1704828 ] PO.is_Changed() and PO.is_ValueChanged are not consistent

http://sourceforge.net/tracker/?func=detail&atid=879332&aid=1704828&group_id=176962
This commit is contained in:
teo_sarca 2007-06-10 18:12:47 +00:00
parent de610700c1
commit e3b4ec86bd
3 changed files with 67 additions and 3 deletions

View File

@ -36,6 +36,8 @@ import org.w3c.dom.*;
* *
* @author Jorg Janke * @author Jorg Janke
* @version $Id: PO.java,v 1.12 2006/08/09 16:38:47 jjanke Exp $ * @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 public abstract class PO
implements Serializable, Comparator, Evaluatee implements Serializable, Comparator, Evaluatee
@ -1801,7 +1803,6 @@ public abstract class PO
return false; return false;
} }
// Save // Save
boolean success = false;
if (newRecord) if (newRecord)
return saveNew(); return saveNew();
else else
@ -1902,8 +1903,9 @@ public abstract class PO
int size = get_ColumnCount(); int size = get_ColumnCount();
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
if (m_newValues[i] != null) // Test if the column has changed - teo_sarca [ 1704828 ]
return true; // something changed if (is_ValueChanged(i))
return true;
} }
if (m_custom != null && m_custom.size() > 0) if (m_custom != null && m_custom.size() > 0)
return true; // there are custom columns modified return true; // there are custom columns modified

View File

@ -14,6 +14,7 @@ public class FunctionalTestSuite {
suite.addTestSuite(MUserTest.class); suite.addTestSuite(MUserTest.class);
suite.addTestSuite(MBPGroupTest.class); suite.addTestSuite(MBPGroupTest.class);
suite.addTestSuite(MLocationTest.class); suite.addTestSuite(MLocationTest.class);
suite.addTestSuite(POTest.class);
//$JUnit-END$ //$JUnit-END$
return suite; return suite;
} }

View File

@ -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:
* <ul>
* <li>{@link org.compiere.model.PO#is_Changed()}
* <li>{@link org.compiere.model.PO#is_ValueChanged(String)}
* </ul>
* Applies to following bugs:
* <ul>
* <li>[ 1704828 ] PO.is_Changed() and PO.is_ValueChanged are not consistent
* </ul>
* @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());
}
}