}
// Check authors are in the database
for (int i = 0; i < authorNames.length; ++i)
{
Criteria criteria = new Criteria();
criteria.where(AuthorPeer.NAME, authorNames[i]);
List<Author> authorList = AuthorPeer.doSelect(criteria);
assertEquals(
"AuthorList should contain one author"
+ " when querying for " + authorNames[i],
1,
authorList.size());
Author author = authorList.get(0);
assertEquals("Name of author should be " + authorNames[i],
authorNames[i],
author.getName());
}
for (Map.Entry<String, String> likeResult : likeResults.entrySet())
{
Criteria criteria = new Criteria();
criteria.where(
AuthorPeer.NAME,
likeResult.getKey(),
Criteria.LIKE);
List<Author> authorList;
try
{
authorList = AuthorPeer.doSelect(criteria);
}
catch (Exception e)
{
throw new Exception(
"error rxecuting select using like content "
+ likeResult.getKey(),
e);
}
assertEquals(
"AuthorList should contain one author"
+ " when querying for " + likeResult.getKey(),
1,
authorList.size());
Author author = authorList.get(0);
assertEquals("Name of author should be "
+ likeResult.getValue()
+ " when querying for "
+ likeResult.getKey(),
likeResult.getValue(),
author.getName());
}
// check that case insensitivity is maintained if
// a like is replaced with an equals (no wildcard present)
// This might be a problem for databases which use ILIKE
Criteria criteria = new Criteria();
criteria.where(AuthorPeer.NAME, "AbC", Criteria.LIKE);
criteria.setIgnoreCase(true);
List<Author> authorList = AuthorPeer.doSelect(criteria);
assertEquals(
"AuthorList should contain one author",
1,
authorList.size());
Author author = authorList.get(0);
assertEquals("Name of author should be abc",
"abc",
author.getName());
// check that the escape clause (where needed) also works
// with limit, offset and order by
criteria = new Criteria();
Criterion criterion1 = new Criterion(
AuthorPeer.NAME,
"b%",
Criteria.LIKE);
Criterion criterion2 = new Criterion(
AuthorPeer.NAME,
"a\\%%",
Criteria.LIKE);
Criterion criterion3 = new Criterion(
AuthorPeer.NAME,
"cbc",
Criteria.LIKE);
criteria.where(criterion1.or(criterion2).or(criterion3));
criteria.addAscendingOrderByColumn(AuthorPeer.NAME);
criteria.setOffset(1);
criteria.setLimit(1);
authorList = AuthorPeer.doSelect(criteria);
assertEquals(
"AuthorList should contain one author",
1,
authorList.size());