use of com.orientechnologies.orient.test.domain.business.Country in project orientdb by orientechnologies.
the class ObjectDetachingTestSchemaFull method testInsertCommit.
@Test(dependsOnMethods = "testOrientObjectIdPlusVersionAnnotationsInTx")
public void testInsertCommit() {
String initialCountryName = "insertCommit";
Country country = new Country(initialCountryName);
long initCount = database.countClass(Country.class);
database.begin();
country = (Country) database.save(country);
database.commit();
Assert.assertEquals(database.countClass(Country.class), initCount + 1);
Assert.assertNotNull(country.getId());
Assert.assertNotNull(country.getVersion());
Country found = (Country) database.load((ORecordId) country.getId());
Assert.assertNotNull(found);
Assert.assertEquals(country.getName(), found.getName());
}
use of com.orientechnologies.orient.test.domain.business.Country in project orientdb by orientechnologies.
the class ObjectTreeTestSchemaFull method testPersonSaving.
@Test
public void testPersonSaving() {
final long beginProfiles = database.countClass("Profile");
beginCities = database.countClass("City");
Country italy = database.newInstance(Country.class, "Italy");
Profile garibaldi = database.newInstance(Profile.class, "GGaribaldi", "Giuseppe", "Garibaldi", null);
garibaldi.setLocation(database.newInstance(Address.class, "Residence", database.newInstance(City.class, italy, "Rome"), "Piazza Navona, 1"));
Profile bonaparte = database.newInstance(Profile.class, "NBonaparte", "Napoleone", "Bonaparte", garibaldi);
bonaparte.setLocation(database.newInstance(Address.class, "Residence", garibaldi.getLocation().getCity(), "Piazza di Spagna, 111"));
database.save(bonaparte);
Assert.assertEquals(database.countClass("Profile"), beginProfiles + 2);
Assert.assertEquals(database.countClass("City"), beginCities + 1);
}
use of com.orientechnologies.orient.test.domain.business.Country in project orientdb by orientechnologies.
the class ObjectDetachingTest method testUpdateCommit.
@Test(dependsOnMethods = "testInsertRollback")
public void testUpdateCommit() {
String initialCountryName = "updateCommit";
Country country = new Country(initialCountryName);
country = (Country) database.save(country);
Assert.assertNotNull(country.getId());
Assert.assertNotNull(country.getVersion());
int initVersion = (Integer) country.getVersion();
database.begin();
Country loaded = (Country) database.load((ORecordId) country.getId());
Assert.assertEquals(loaded.getId(), country.getId());
Assert.assertEquals(loaded.getVersion(), country.getVersion());
Assert.assertEquals((Object) database.getRecordByUserObject(loaded, false), database.getRecordByUserObject(country, false));
String newName = "ShouldBeChanged";
loaded.setName(newName);
loaded = (Country) database.save(loaded);
database.commit();
loaded = (Country) database.load((ORecordId) country.getId());
Assert.assertEquals((Object) database.getRecordByUserObject(loaded, false), (Object) database.getRecordByUserObject(country, false));
Assert.assertEquals(loaded.getId(), country.getId());
Assert.assertEquals(((Integer) loaded.getVersion()), (Integer) (initVersion + 1));
Assert.assertEquals(loaded.getName(), newName);
}
use of com.orientechnologies.orient.test.domain.business.Country in project orientdb by orientechnologies.
the class ObjectDetachingTest method testDeleteCommit.
@Test(dependsOnMethods = "testUpdateRollback")
public void testDeleteCommit() {
String initialCountryName = "deleteCommit";
Country country = new Country(initialCountryName);
long initCount = database.countClass(Country.class);
country = database.save(country);
Assert.assertEquals(database.countClass(Country.class), initCount + 1);
database.begin();
database.delete(country);
database.commit();
Assert.assertEquals(database.countClass(Country.class), initCount);
Country found = database.load((ORecordId) country.getId());
Assert.assertNull(found);
}
use of com.orientechnologies.orient.test.domain.business.Country in project orientdb by orientechnologies.
the class ObjectDetachingTestSchemaFull method testInsertRollback.
@Test(dependsOnMethods = "testInsertCommit")
public void testInsertRollback() {
String initialCountryName = "insertRollback";
Country country = new Country(initialCountryName);
long initCount = database.countClass(Country.class);
database.begin();
country = (Country) database.save(country);
database.rollback();
Assert.assertEquals(database.countClass(Country.class), initCount);
Assert.assertTrue(country.getId() == null || ((ORID) country.getId()).isNew(), "id=" + country.getId());
// Assert.assertNull(country.getVersion());
}
Aggregations