package de.linwave.tutorial.chap1;
import junit.framework.TestCase;
import org.odbms.ObjectContainer;
import org.odbms.ObjectSet;
import de.linwave.gtm.GTM;
import de.linwave.tutorial.Pilot;
public class F1Test extends TestCase {
ObjectContainer db = GTM.getInstance();
public void testGTM() {
assertNotNull(db);
db.deleteClass(Pilot.class);
}
public void testStoreFirstPilot() {
Pilot pilot1 = new Pilot("Michael Schumacher", 100);
Long oid1 = db.store(pilot1);
Pilot pilot2 = new Pilot("Rubens Barrichello", 99);
Long oid2 = db.store(pilot2);
assertTrue(oid1 != 0);
assertTrue(oid2 != 0);
assertTrue(oid2 > oid1);
assertNotSame(oid1, oid2);
Long diff = new Long(oid2)-1;
assertEquals(oid1, diff);
}
public void testRetrieveAllPilotQBE() {
Pilot proto = new Pilot(null, 0);
ObjectSet<Pilot> result = db.queryByExample(proto);
assertEquals(2, result.size());
}
public void testRetrieveAllPilots() {
ObjectSet<Pilot> result = db.queryByExample(Pilot.class);
assertEquals(2, result.size());
}
public void testRetrievePilotByName() {
Pilot proto = new Pilot("Michael Schumacher", 0);
ObjectSet<Pilot> result = db.queryByExample(proto);
assertEquals(1, result.size());
}
public void testRetrievePilotByExactPoints() {
Pilot proto = new Pilot(null, 100);
ObjectSet<Pilot> result = db.queryByExample(proto);
assertEquals(1, result.size());
}
public void testUpdatePilot() {
ObjectSet<Pilot> result = db.queryByExample(new Pilot("Michael Schumacher", 0));
Pilot found = (Pilot) result.next();
found.addPoints(11);
int newPoints = found.getPoints();
db.store(found);
System.out.println("Added 11 points for " + found);
testRetrieveAllPilots();
result = db.queryByExample(new Pilot("Michael Schumacher", newPoints));
found = (Pilot) result.next();
assertNotNull(found);
assertEquals(newPoints, found.getPoints());
}
public void testDeleteFirstPilotByName() {
ObjectSet<Pilot> result = db.queryByExample(new Pilot("Michael Schumacher", 0));
Pilot found = (Pilot) result.next();
db.delete(found);
System.out.println("Deleted " + found);
result = db.queryByExample(Pilot.class);
assertEquals(1, result.size());
}
public void testDeleteSecondPilotByName() {
ObjectSet<Pilot> result = db.queryByExample(new Pilot("Rubens Barrichello", 0));
Pilot found = (Pilot) result.next();
db.delete(found);
System.out.println("Deleted " + found);
result = db.queryByExample(Pilot.class);
assertEquals(0, result.size());
}
public void testFinal() {
db.printCacheStatistics();
db.printGTMStatistics();
}
}