package de.linwave.junit.nativequery;
import java.util.concurrent.atomic.AtomicInteger;
import org.odbms.OP;
import org.odbms.ObjectSet;
import org.odbms.Predicate;
import org.odbms.Query;
import de.linwave.junit.AbstractTestCase;
import freedb.Disc;
public class NativeQueryFreeDB extends AbstractTestCase
{
private static int rows_from_2008;
public void testRows()
{
int cnt = 0;
Query query = db.query(Disc.class);
ObjectSet<Disc> discs = query.execute();
for (Disc disc : discs) {
cnt++;
if (disc.getDYEAR() == 2008)
rows_from_2008++;
}
assertEquals(FREEDB_ROWS, cnt);
}
/**
*
*/
public void testDiscsFrom2008()
{
int cnt = 0;
Query query = db.query(new Predicate<Disc>() {
public boolean match(Disc disc)
{
return disc.getDYEAR() == 2008;
}
});
ObjectSet<Disc> discs = query.execute();
for (Disc disc : discs) {
cnt++;
if (disc.getDYEAR() != 2008)
fail("Disc DYEAR != 2008");
}
assertEquals(rows_from_2008, cnt);
}
/**
*
*/
public void testDdiscLast3YearsWithSingleInTitle()
{
final AtomicInteger cnt = new AtomicInteger();
Query query = db.query(new Predicate<Disc>() {
public boolean match(Disc disc)
{
if (disc.getAge() <= 3 && disc.getAge() != -1) {
cnt.incrementAndGet();
return true;
} else {
return false;
}
}
});
query.constrain("DTITLE", OP.STARTS_WITH, "John");
ObjectSet<Disc> discs = query.execute();
for (Disc disc : discs) {
if (disc.getAge() > 3)
fail("Disc age >3");
if (!disc.getDTITLE().startsWith("John"))
fail("DTITLE does not start with 'John'");
cnt.decrementAndGet();
}
assertEquals(0, cnt.intValue());
}
/**
*
*/
public void testDiscLast3YearsStartsWithTHEandAgeLastTenYearsAndEndsWithSingle()
{
final AtomicInteger cnt = new AtomicInteger();
Query query = db.query(new Predicate<Disc>() {
public boolean match(Disc disc)
{
if (disc.getAge() < 10 && disc.getAge() != -1) {
cnt.incrementAndGet();
return true;
} else {
return false;
}
}
});
query.constrain("DTITLE", OP.STARTS_WITH, "The");
ObjectSet<Disc> discs = query.execute();
for (Disc disc : discs) {
if (disc.getAge() < 10) {
cnt.decrementAndGet();
} else {
fail("Disc age is greater 10 years");
}
}
assertEquals(0, cnt.intValue());
}
}