public void testIn() {
    ArrayList<TestEntity> inserted = insert(10);
    String value1 = getSimpleString(2);
    String value2 = getSimpleString(8);
    String value3 = getSimpleString(9);

    List<TestEntity> result =
        dao.queryBuilder()
            .where(Properties.SimpleString.in(value1, value2, value3))
            .orderAsc(Properties.SimpleString)
            .list();
    assertEquals(3, result.size());

    TestEntity resultEntity1 = result.get(0);
    assertEquals(value1, resultEntity1.getSimpleString());
    assertEquals(inserted.get(2).getId(), resultEntity1.getId());

    TestEntity resultEntity2 = result.get(1);
    assertEquals(value2, resultEntity2.getSimpleString());
    assertEquals(inserted.get(8).getId(), resultEntity2.getId());

    TestEntity resultEntity3 = result.get(2);
    assertEquals(value3, resultEntity3.getSimpleString());
    assertEquals(inserted.get(9).getId(), resultEntity3.getId());
  }
 public void testOrderDesc() {
   ArrayList<TestEntity> inserted = insert(2);
   TestEntity entity = inserted.get(1);
   List<TestEntity> result = dao.queryBuilder().orderDesc(Properties.SimpleInteger).list();
   assertEquals(2, result.size());
   assertEquals(entity.getId(), result.get(0).getId());
   result = dao.queryBuilder().orderDesc(Properties.SimpleInteger, Properties.SimpleString).list();
   assertEquals(2, result.size());
   assertEquals(entity.getId(), result.get(0).getId());
 }
  public void testNotEqString() {
    ArrayList<TestEntity> inserted = insert(3);
    String value = getSimpleString(1);

    List<TestEntity> result = dao.queryBuilder().where(Properties.SimpleString.notEq(value)).list();
    assertEquals(2, result.size());

    TestEntity resultEntity1 = result.get(0);
    TestEntity resultEntity2 = result.get(1);
    long loId = Math.min(resultEntity1.getId(), resultEntity2.getId());
    long hiId = Math.max(resultEntity1.getId(), resultEntity2.getId());
    assertEquals((long) inserted.get(0).getId(), loId);
    assertEquals((long) inserted.get(2).getId(), hiId);
  }
  public void testEqDate() {
    ArrayList<TestEntity> inserted = insert(3);
    TestEntity testEntity = inserted.get(1);

    Date date = new Date();
    testEntity.setSimpleDate(date);
    dao.update(testEntity);

    TestEntity testEntity2 =
        dao.queryBuilder().where(Properties.SimpleDate.eq(date)).uniqueOrThrow();
    assertEquals(testEntity.getId(), testEntity2.getId());

    testEntity2 =
        dao.queryBuilder().where(Properties.SimpleDate.eq(date.getTime())).uniqueOrThrow();
    assertEquals(testEntity.getId(), testEntity2.getId());
  }
  public void testIsNullIsNotNull() {
    ArrayList<TestEntity> inserted = insert(2);
    TestEntity testEntityNull = inserted.get(0);
    TestEntity testEntityNotNull = inserted.get(1);

    testEntityNull.setSimpleInteger(null);
    testEntityNotNull.setSimpleInteger(42);
    dao.update(testEntityNull);
    dao.update(testEntityNotNull);

    TestEntity testEntityNull2 =
        dao.queryBuilder().where(Properties.SimpleInteger.isNull()).uniqueOrThrow();
    assertEquals(testEntityNull.getId(), testEntityNull2.getId());

    TestEntity testEntityNotNull2 =
        dao.queryBuilder().where(Properties.SimpleInteger.isNotNull()).uniqueOrThrow();
    assertEquals(testEntityNotNull.getId(), testEntityNotNull2.getId());
  }
  public void testEqString() {
    ArrayList<TestEntity> inserted = insert(3);
    String value = getSimpleString(1);

    List<TestEntity> result = dao.queryBuilder().where(Properties.SimpleString.eq(value)).list();
    assertEquals(1, result.size());

    TestEntity resultEntity = result.get(0);
    assertEquals(value, resultEntity.getSimpleString());
    assertEquals(inserted.get(1).getId(), resultEntity.getId());
  }
Example #7
0
  public void testRawQueryEqualsString() {
    ArrayList<TestEntity> inserted = insert(3);
    String value = getSimpleString(1);

    String sql = "WHERE " + Properties.SimpleString.columnName + "=?";
    List<TestEntity> result = dao.queryRawCreate(sql, value).list();
    assertEquals(1, result.size());

    TestEntity resultEntity = result.get(0);
    assertEquals(value, resultEntity.getSimpleString());
    assertEquals(inserted.get(1).getId(), resultEntity.getId());
  }
  public void testEqBoolean() {
    ArrayList<TestEntity> inserted = insert(3);
    TestEntity testEntity = inserted.get(1);

    testEntity.setSimpleBoolean(true);
    dao.update(testEntity);

    TestEntity testEntity2 =
        dao.queryBuilder().where(Properties.SimpleBoolean.eq(true)).uniqueOrThrow();
    assertEquals(testEntity.getId(), testEntity2.getId());

    testEntity2 =
        dao.queryBuilder().where(Properties.SimpleBoolean.eq(Boolean.TRUE)).uniqueOrThrow();
    assertEquals(testEntity.getId(), testEntity2.getId());

    testEntity2 = dao.queryBuilder().where(Properties.SimpleBoolean.eq("TRUE")).uniqueOrThrow();
    assertEquals(testEntity.getId(), testEntity2.getId());

    testEntity2 = dao.queryBuilder().where(Properties.SimpleBoolean.eq("truE")).uniqueOrThrow();
    assertEquals(testEntity.getId(), testEntity2.getId());
  }