public void testReusableQueryWithInCriterion() { Set<String> collection = new HashSet<>(); Query query = Query.select().where(Employee.NAME.in(collection)); testReusableQueryWithInCriterionInternal(collection, query, "bigBird", "cookieMonster", "elmo"); testReusableQueryWithInCriterionInternal(collection, query, "bigBird", "cookieMonster"); testReusableQueryWithInCriterionInternal(collection, query, "oscar"); testReusableQueryWithInCriterionInternal(collection, query); }
public void testInCriterion() { List<String> expectedNames = Arrays.asList("bigBird", "cookieMonster"); Query query = Query.select().where(Employee.NAME.in("bigBird", "cookieMonster")).orderBy(Employee.NAME.asc()); testInQuery(expectedNames, query); query = Query.select().where(Employee.NAME.notIn("bigBird", "cookieMonster")).orderBy(Employee.NAME.asc()); testInQuery(Arrays.asList("bert", "elmo", "ernie", "oscar"), query); List<String> list = Arrays.asList("bigBird", "cookieMonster"); query = Query.select().where(Employee.NAME.in(list)).orderBy(Employee.NAME.asc()); testInQuery(expectedNames, query); // Test off-by-one error that used to occur when the in criterion wasn't the last criterion in the list query = Query.select().where(Employee.NAME.in(list).or(Field.field("1").neq(1))).orderBy(Employee.NAME.asc()); testInQuery(expectedNames, query); }
private void testBadString(String badString, int expectedLength) { assertEquals(expectedLength, badString.length()); TestModel model = new TestModel().setFirstName(badString).setLastName("Bosley").setBirthday(testDate); database.persist(model); model = database.fetch(TestModel.class, model.getRowId()); assertEquals(badString, model.getFirstName()); database.update(TestModel.FIRST_NAME.in(badString), new TestModel().setFirstName("Sam")); model = database.fetch(TestModel.class, model.getRowId()); assertEquals("Sam", model.getFirstName()); database.delete(TestModel.class, model.getRowId()); } }
public void testCriterionNegation() { assertNegationEqualsTheOther(TestModel.FIRST_NAME.eq("Sam"), TestModel.FIRST_NAME.neq("Sam")); assertNegationEqualsTheOther(TestModel.FIRST_NAME.isNull(), TestModel.FIRST_NAME.isNotNull()); assertNegationEqualsTheOther(TestModel.LUCKY_NUMBER.gt(5), TestModel.LUCKY_NUMBER.lte(5)); assertNegationEqualsTheOther(TestModel.LUCKY_NUMBER.gte(5), TestModel.LUCKY_NUMBER.lt(5)); assertNegationEqualsTheOther(TestModel.FIRST_NAME.in(Collections.EMPTY_SET), TestModel.FIRST_NAME.notIn(Collections.EMPTY_SET)); assertNegationEqualsTheOther(TestModel.FIRST_NAME.isNull(), TestModel.FIRST_NAME.isNotNull()); assertNegationEqualsTheOther(TestModel.LUCKY_NUMBER.between(1, 2), TestModel.LUCKY_NUMBER.notBetween(1, 2)); assertNegationEqualsTheOther(TestModel.FIRST_NAME.like("A"), TestModel.FIRST_NAME.notLike("A")); assertNegationEqualsTheOther(TestModel.FIRST_NAME.glob("A*"), TestModel.FIRST_NAME.notGlob("A*")); }