Package de.linwave.junit.nativequery

Source Code of de.linwave.junit.nativequery.NativeQueryFreeDBWithIndex

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 NativeQueryFreeDBWithIndex extends AbstractTestCase
{
  /**
   *
   */
  public void testDdiscLast3YearsTitleStartWithJohn()
  {
    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 testDiscStartsWithTHEandAgeLastTenYears()
  {
    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");
    query.constrain("DYEAR", OP.GREATER, 1998);

    ObjectSet<Disc> discs = query.execute();
    for (Disc disc : discs) {
      if (disc.getAge() > 10) {
        fail("Disc age is greater 10 years");
      } else {
        cnt.decrementAndGet();
      }
    }

    assertEquals(0, cnt.intValue());
  }

}
TOP

Related Classes of de.linwave.junit.nativequery.NativeQueryFreeDBWithIndex

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.