mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
45 lines
1022 B
Java
45 lines
1022 B
Java
package com.avaje.tests.iud;
|
|
|
|
import junit.framework.Assert;
|
|
import junit.framework.TestCase;
|
|
|
|
import com.avaje.ebean.Ebean;
|
|
import com.avaje.tests.model.basic.EBasicVer;
|
|
|
|
public class TestInsertUpdateTrans extends TestCase {
|
|
|
|
public void test() {
|
|
|
|
Ebean.beginTransaction();
|
|
try {
|
|
|
|
EBasicVer e0 = new EBasicVer();
|
|
e0.setName("onInsert");
|
|
e0.setDescription("something");
|
|
Ebean.save(e0);
|
|
|
|
Assert.assertNotNull(e0.getId());
|
|
Assert.assertNotNull(e0.getLastUpdate());
|
|
Assert.assertEquals("onInsert", e0.getName());
|
|
|
|
e0.setName("onUpdate");
|
|
e0.setDescription("differentFromInsert");
|
|
|
|
Ebean.save(e0);
|
|
|
|
EBasicVer e1 = Ebean.find(EBasicVer.class, e0.getId());
|
|
|
|
// we should fetch back the updated data (not inserted)
|
|
Assert.assertEquals(e0.getId(), e1.getId());
|
|
Assert.assertEquals("onUpdate", e1.getName());
|
|
Assert.assertEquals("differentFromInsert", e1.getDescription());
|
|
|
|
|
|
Ebean.commitTransaction();
|
|
|
|
} finally {
|
|
Ebean.endTransaction();
|
|
}
|
|
}
|
|
}
|