DATAMONGO-631 - Explictly reject Order instances with ignore-case flag.

This commit is contained in:
Oliver Gierke
2013-03-25 16:34:40 +01:00
parent 7a64766496
commit 3410a0589c
2 changed files with 30 additions and 1 deletions

View File

@@ -24,6 +24,7 @@ import java.util.List;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Order;
import org.springframework.data.mongodb.InvalidMongoDbApiUsageException;
import org.springframework.util.Assert;
@@ -150,6 +151,13 @@ public class Query {
return this;
}
for (Order order : sort) {
if (order.isIgnoreCase()) {
throw new IllegalArgumentException(String.format("Gven sort contained an Order for %s with ignore case! "
+ "MongoDB does not support sorting ignoreing case currently!", order.getProperty()));
}
}
if (this.coreSort == null) {
this.coreSort = sort;
} else {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2010-2012 the original author or authors.
* Copyright 2010-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,12 +20,24 @@ import static org.junit.Assert.*;
import static org.springframework.data.mongodb.core.query.Criteria.*;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.mongodb.InvalidMongoDbApiUsageException;
/**
* Unit tests for {@link Query}.
*
* @author Thomas Risberg
* @author Oliver Gierke
*/
public class QueryTests {
@Rule
public ExpectedException exception = ExpectedException.none();
@Test
public void testSimpleQuery() {
Query q = new Query(where("name").is("Thomas").and("age").lt(80));
@@ -170,4 +182,13 @@ public class QueryTests {
Query query = new Query().with(new org.springframework.data.domain.Sort(Direction.DESC, "foo"));
assertThat(query.getSortObject().toString(), is("{ \"foo\" : -1}"));
}
@Test
public void rejectsOrderWithIgnoreCase() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("foo");
new Query().with(new Sort(new Sort.Order("foo").ignoreCase()));
}
}