diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/PartTreeMongoQuery.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/PartTreeMongoQuery.java index 35dfe7de5..cc56be58c 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/PartTreeMongoQuery.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/PartTreeMongoQuery.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/PartTreeMongoQueryUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/PartTreeMongoQueryUnitTests.java index edeecbd5f..aaecfa82a 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/PartTreeMongoQueryUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/PartTreeMongoQueryUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2015 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. @@ -42,6 +42,7 @@ import org.springframework.data.mongodb.repository.Query; import org.springframework.data.repository.core.RepositoryMetadata; import com.mongodb.BasicDBObjectBuilder; +import com.mongodb.util.JSONParseException; /** * Unit tests for {@link PartTreeMongoQuery}. @@ -120,6 +121,18 @@ public class PartTreeMongoQueryUnitTests { assertThat(query.getFieldsObject(), is(new BasicDBObjectBuilder().add("firstname", 0).add("lastname", 0).get())); } + /** + * @see DATAMONGO-1180 + */ + @Test + public void propagatesRootExceptionForInvalidQuery() { + + exception.expect(IllegalStateException.class); + exception.expectCause(is(org.hamcrest.Matchers. instanceOf(JSONParseException.class))); + + deriveQueryFromMethod("findByAge", new Object[] { 1 }); + } + private org.springframework.data.mongodb.core.query.Query deriveQueryFromMethod(String method, Object[] args) { Class[] types = new Class[args.length]; @@ -162,5 +175,8 @@ public class PartTreeMongoQueryUnitTests { @Query(fields = "{ 'firstname' : 0, 'lastname' : 0 }") Person findPersonByFirstnameAndLastname(String firstname, String lastname); + + @Query(fields = "{ 'firstname }") + Person findByAge(Integer age); } }