Search in sources :

Example 6 with Country

use of com.orientechnologies.orient.test.domain.business.Country in project orientdb by orientechnologies.

the class ObjectDetachingTestSchemaFull 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);
}
Also used : Country(com.orientechnologies.orient.test.domain.business.Country) Test(org.testng.annotations.Test) EnumTest(com.orientechnologies.orient.test.domain.base.EnumTest)

Example 7 with Country

use of com.orientechnologies.orient.test.domain.business.Country in project orientdb by orientechnologies.

the class ObjectDetachingTestSchemaFull 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), (Object) 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((int) (Integer) loaded.getVersion(), initVersion + 1);
    Assert.assertEquals(loaded.getName(), newName);
}
Also used : Country(com.orientechnologies.orient.test.domain.business.Country) ORecordId(com.orientechnologies.orient.core.id.ORecordId) Test(org.testng.annotations.Test) EnumTest(com.orientechnologies.orient.test.domain.base.EnumTest)

Example 8 with Country

use of com.orientechnologies.orient.test.domain.business.Country in project orientdb by orientechnologies.

the class ObjectDetachingTest 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());
}
Also used : Country(com.orientechnologies.orient.test.domain.business.Country) ORID(com.orientechnologies.orient.core.id.ORID) Test(org.testng.annotations.Test) EnumTest(com.orientechnologies.orient.test.domain.base.EnumTest)

Example 9 with Country

use of com.orientechnologies.orient.test.domain.business.Country in project orientdb by orientechnologies.

the class ObjectDetachingTestSchemaFull method testUpdateRollback.

@Test(dependsOnMethods = "testUpdateCommit")
public void testUpdateRollback() {
    String initialCountryName = "updateRollback";
    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 = "ShouldNotBeChanged";
    loaded.setName(newName);
    loaded = (Country) database.save(loaded);
    database.rollback();
    loaded = database.load((ORecordId) country.getId());
    Assert.assertNotSame(database.getRecordByUserObject(loaded, false), database.getRecordByUserObject(country, false));
    Assert.assertEquals((Integer) loaded.getVersion(), (Integer) initVersion);
    Assert.assertEquals(loaded.getName(), initialCountryName);
}
Also used : Country(com.orientechnologies.orient.test.domain.business.Country) ORecordId(com.orientechnologies.orient.core.id.ORecordId) Test(org.testng.annotations.Test) EnumTest(com.orientechnologies.orient.test.domain.base.EnumTest)

Example 10 with Country

use of com.orientechnologies.orient.test.domain.business.Country in project orientdb by orientechnologies.

the class ObjectDetachingTestSchemaFull method createAnnotatedObjects.

@Test
public void createAnnotatedObjects() {
    database.getEntityManager().registerEntityClasses("com.orientechnologies.orient.test.domain.business");
    database.getEntityManager().registerEntityClasses("com.orientechnologies.orient.test.domain.whiz");
    database.getEntityManager().registerEntityClasses("com.orientechnologies.orient.test.domain.base");
    Country austria = new Country("Austria");
    City graz = new City(austria, "Graz");
    graz = database.save(graz);
    account = new Account();
    account = database.save(account);
    profile = new Profile();
    profile = database.save(profile);
}
Also used : Account(com.orientechnologies.orient.test.domain.business.Account) Country(com.orientechnologies.orient.test.domain.business.Country) City(com.orientechnologies.orient.test.domain.business.City) Profile(com.orientechnologies.orient.test.domain.whiz.Profile) Test(org.testng.annotations.Test) EnumTest(com.orientechnologies.orient.test.domain.base.EnumTest)

Aggregations

Country (com.orientechnologies.orient.test.domain.business.Country)22 Test (org.testng.annotations.Test)22 EnumTest (com.orientechnologies.orient.test.domain.base.EnumTest)16 ORecordId (com.orientechnologies.orient.core.id.ORecordId)6 Address (com.orientechnologies.orient.test.domain.business.Address)6 City (com.orientechnologies.orient.test.domain.business.City)6 Profile (com.orientechnologies.orient.test.domain.whiz.Profile)6 Account (com.orientechnologies.orient.test.domain.business.Account)4 ORID (com.orientechnologies.orient.core.id.ORID)2 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)1