Skip to content

Instantly share code, notes, and snippets.

@secondsun
Created November 24, 2012 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save secondsun/4140853 to your computer and use it in GitHub Desktop.
Save secondsun/4140853 to your computer and use it in GitHub Desktop.
package net.saga.android.orienttests;
import net.saga.android.orienttests.vo.Person;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.orientechnologies.orient.object.db.OObjectDatabaseTx;
import java.util.List;
import java.util.logging.Logger;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
/**
* Unit test for simple App.
*/
public class AppTest {
private static OObjectDatabaseTx db;
public AppTest() {
}
@BeforeClass
public static void setUpDatabase(){
db = new OObjectDatabaseTx("memory:petshop").create();
seedData();
}
@AfterClass
public static void shutDownDatabase(){
db.close();
}
private static void seedData() {
db.getEntityManager().registerEntityClasses("net.saga.android.orienttests.vo");
}
@Before
public void beginTransaction() {
db.begin();
}
@After
public void rollBack() {
db.rollback();
}
@org.junit.Test
public void testSaveFetch() {
Person person = new Person();
person.setName("Person 1");
person.setCity("City 1");
db.save(person);
List<Person> result = db.query(new OSQLSynchQuery<Person>("select * from Person"));
Logger.getAnonymousLogger().fine(result.get(0).getRecordId() + " && " + result.get(0).getVersion());
Assert.assertEquals(1, result.size());
}
@org.junit.Test
public void testRollBack() {
List<Person> result = db.query(new OSQLSynchQuery<Person>("select * from Person"));
Assert.assertEquals(0, result.size());
Person person = new Person();
person.setName("Person 1");
person.setCity("City 1");
db.save(person);
result = db.query(new OSQLSynchQuery<Person>("select * from Person"));
Assert.assertEquals(1, result.size());
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.saga.android.orienttests.vo;
import javax.persistence.Id;
import javax.persistence.Version;
/**
*
* @author summers
*/
public class Person {
@Id
private Object recordId;
@Version
private Object version;
private String name;
private String city;
public Object getRecordId() {
return recordId;
}
public Object getVersion() {
return version;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment