Search in sources :

Example 16 with Country

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

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

Example 17 with Country

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

the class ObjectDetachingTest method testOrientObjectIdPlusVersionAnnotationsNotInTx.

@SuppressWarnings("unchecked")
@Test(dependsOnMethods = "testOrientStringIdAnnotation")
public void testOrientObjectIdPlusVersionAnnotationsNotInTx() {
    // BROWSE ALL THE OBJECTS
    Assert.assertTrue(database.countClass(Country.class) > 0);
    for (Country c : (List<Country>) database.query(new OSQLSynchQuery<Object>("select from Country where name = 'Austria'"))) {
        Assert.assertNotNull(c.getId());
        Assert.assertNotNull(c.getVersion());
        // UPDATE IT TO GET NEWER VERSION
        c.setName(c.getName() + " v1");
        database.save(c);
        // CHECK VERSION
        Assert.assertTrue((Integer) c.getVersion() > 0);
    }
    // BROWSE ALL THE OBJECTS
    for (Country c : (List<Country>) database.query(new OSQLSynchQuery<Object>("select from Country where name = 'Austria v1'"))) {
        Assert.assertNotNull(c.getId());
        Assert.assertNotNull(c.getVersion());
        Assert.assertTrue((Integer) c.getVersion() > 0);
    }
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) Country(com.orientechnologies.orient.test.domain.business.Country) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.testng.annotations.Test) EnumTest(com.orientechnologies.orient.test.domain.base.EnumTest)

Example 18 with Country

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

the class ObjectDetachingTestSchemaFull method testOrientObjectIdPlusVersionAnnotationsNotInTx.

@SuppressWarnings("unchecked")
@Test(dependsOnMethods = "testOrientStringIdAnnotation")
public void testOrientObjectIdPlusVersionAnnotationsNotInTx() {
    // DELETE PREVIOUS TESTS DATA
    database.command(new OCommandSQL("delete from Country where name = 'Austria v1'")).execute();
    // BROWSE ALL THE OBJECTS
    Assert.assertTrue(database.countClass(Country.class) > 0);
    for (Country c : (List<Country>) database.query(new OSQLSynchQuery<Object>("select from Country where name = 'Austria'"))) {
        Assert.assertNotNull(c.getId());
        Assert.assertNotNull(c.getVersion());
        // UPDATE IT TO GET NEWER VERSION
        c.setName(c.getName() + " v1");
        database.save(c);
        // CHECK VERSION
        Assert.assertTrue(((Integer) c.getVersion()) > 0);
    }
    // BROWSE ALL THE OBJECTS
    for (Country c : (List<Country>) database.query(new OSQLSynchQuery<Object>("select from Country where name = 'Austria v1'"))) {
        Assert.assertNotNull(c.getId());
        Assert.assertNotNull(c.getVersion());
        Assert.assertTrue(((Integer) c.getVersion()) > 0);
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) Country(com.orientechnologies.orient.test.domain.business.Country) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.testng.annotations.Test) EnumTest(com.orientechnologies.orient.test.domain.base.EnumTest)

Example 19 with Country

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

the class ObjectDetachingTestSchemaFull method testDeleteRollback.

@Test(dependsOnMethods = "testDeleteCommit")
public void testDeleteRollback() {
    String initialCountryName = "deleteRollback";
    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.rollback();
    Assert.assertEquals(database.countClass(Country.class), initCount + 1);
    Country found = database.load((ORecordId) country.getId());
    Assert.assertNotNull(found);
    Assert.assertEquals(found.getName(), country.getName());
}
Also used : Country(com.orientechnologies.orient.test.domain.business.Country) Test(org.testng.annotations.Test) EnumTest(com.orientechnologies.orient.test.domain.base.EnumTest)

Example 20 with Country

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

the class CRUDObjectPhysicalTestSchemaFull method update.

@Test(dependsOnMethods = "mapEnumAndInternalObjects")
public void update() {
    int i = 0;
    Account a;
    for (Object o : database.browseCluster("Account").setFetchPlan("*:1")) {
        a = (Account) o;
        if (i % 2 == 0)
            a.getAddresses().set(0, new Address("work", new City(new Country("Spain"), "Madrid"), "Plaza central"));
        a.setSalary(i + 500.10f);
        database.save(a);
        i++;
    }
}
Also used : Account(com.orientechnologies.orient.test.domain.business.Account) Address(com.orientechnologies.orient.test.domain.business.Address) Country(com.orientechnologies.orient.test.domain.business.Country) City(com.orientechnologies.orient.test.domain.business.City) Test(org.testng.annotations.Test)

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