mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Fix: Setting file with same content should not make bean dirty
(cherry picked from commit 62c4acd36a)
This commit is contained in:
@@ -12,6 +12,7 @@ import java.io.PrintStream;
|
||||
import java.net.URL;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestFileType extends BaseTestCase {
|
||||
|
||||
@@ -184,6 +185,31 @@ public class TestFileType extends BaseTestCase {
|
||||
DB.delete(bean3);
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_FileDirty() throws Exception {
|
||||
SomeFileBean bean0 = new SomeFileBean();
|
||||
bean0.setName("afile");
|
||||
bean0.setContent(file);
|
||||
|
||||
DB.save(bean0);
|
||||
|
||||
SomeFileBean bean1 = DB.find(SomeFileBean.class)
|
||||
.select("name, file")
|
||||
.setId(bean0.getId())
|
||||
.findOne();
|
||||
|
||||
assertThat(bean1.getContent())
|
||||
.isNotEqualTo(file) // not same file object, but same content
|
||||
.hasSameBinaryContentAs(file);
|
||||
|
||||
assertFalse(DB.beanState(bean1).isDirty());
|
||||
bean1.setContent(file);
|
||||
assertFalse(DB.beanState(bean1).isDirty());
|
||||
bean1.setContent(file2);
|
||||
assertTrue(DB.beanState(bean1).isDirty());
|
||||
|
||||
}
|
||||
|
||||
private File getFile(String resource) {
|
||||
URL url = getClass().getResource(resource);
|
||||
return new File(url.getFile());
|
||||
|
||||
Reference in New Issue
Block a user