Skip to content

Commit

Permalink
CFID-229: add support for boolean literals
Browse files Browse the repository at this point in the history
Change-Id: I102970c3392aa568b30d853f56e639f6d970392d
  • Loading branch information
dsyer committed Mar 31, 2012
1 parent 917374e commit 72bbd6d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Expand Up @@ -83,6 +83,8 @@ public class JdbcScimUserProvisioning implements ScimUserProvisioning {

static final Pattern eqPattern = Pattern.compile("(.*?)([a-z0-9]*) eq '(.*?)'([\\s]*.*)", Pattern.CASE_INSENSITIVE);

static final Pattern boPattern = Pattern.compile("(.*?)([a-z0-9]*) eq (true|false)([\\s]*.*)", Pattern.CASE_INSENSITIVE);

static final Pattern prPattern = Pattern.compile(" pr([\\s]*)", Pattern.CASE_INSENSITIVE);

static final Pattern gtPattern = Pattern.compile(" gt ", Pattern.CASE_INSENSITIVE);
Expand Down Expand Up @@ -141,6 +143,7 @@ public List<ScimUser> retrieveUsers(String filter) {
where = makeCaseInsensitive(where, coPattern, "%slower(%s) like :?%s", "%%%s%%", values);
where = makeCaseInsensitive(where, swPattern, "%slower(%s) like :?%s", "%s%%", values);
where = makeCaseInsensitive(where, eqPattern, "%slower(%s) = :?%s", "%s", values);
where = makeCaseInsensitive(where, boPattern, "%s%s = :?%s", "%s", values);
where = prPattern.matcher(where).replaceAll(" is not null$1");
where = gtPattern.matcher(where).replaceAll(" > ");
where = gePattern.matcher(where).replaceAll(" >= ");
Expand Down
Expand Up @@ -176,6 +176,7 @@ public void canRemoveExistingUser() {
assertJoe(joe);
assertEquals(1, template.queryForList("select * from users where id=? and active=false", JOE_ID).size());
assertFalse(joe.isActive());
assertEquals(1, db.retrieveUsers("username eq 'joe' and active eq false").size());
}

@Test(expected=UserAlreadyExistsException.class)
Expand Down Expand Up @@ -247,6 +248,11 @@ public void canRetrieveUsersWithEmailFilter() {
assertEquals(1, db.retrieveUsers("emails.value sw 'joe'").size());
}

@Test
public void canRetrieveUsersWithBooleanFilter() {
assertTrue(2<=db.retrieveUsers("username pr and active eq true").size());
}

@Test
public void canRetrieveUsersWithFilterBooleanAnd() {
assertTrue(2 <= db.retrieveUsers("username pr and emails.value co '.com'").size());
Expand Down

0 comments on commit 72bbd6d

Please sign in to comment.