Skip to content

Commit 6509b9e

Browse files
Test that repository finder methods work as expected.
1 parent 05a4d58 commit 6509b9e

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AbstractPersonRepositoryIntegrationTests.java

+15
Original file line numberDiff line numberDiff line change
@@ -1422,4 +1422,19 @@ void annotatedQueryShouldAllowAggregationInProjection() {
14221422
Person target = repository.findWithAggregationInProjection(alicia.getId());
14231423
assertThat(target.getFirstname()).isEqualTo(alicia.getFirstname().toUpperCase());
14241424
}
1425+
1426+
@Test // GH-3602
1427+
void executesQueryWithDocumentReferenceCorrectly() {
1428+
1429+
Person josh = new Person("Josh", "Long");
1430+
User dave = new User();
1431+
dave.id = "dave";
1432+
1433+
josh.setSpiritAnimal(dave);
1434+
1435+
operations.save(josh);
1436+
1437+
List<Person> result = repository.findBySpiritAnimal(dave);
1438+
assertThat(result).map(Person::getId).containsExactly(josh.getId());
1439+
}
14251440
}

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/Person.java

+12
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.springframework.data.mongodb.core.index.Indexed;
2828
import org.springframework.data.mongodb.core.mapping.DBRef;
2929
import org.springframework.data.mongodb.core.mapping.Document;
30+
import org.springframework.data.mongodb.core.mapping.DocumentReference;
3031
import org.springframework.data.mongodb.core.mapping.Field;
3132
import org.springframework.data.mongodb.core.mapping.Unwrapped;
3233

@@ -74,6 +75,9 @@ public enum Sex {
7475
@Unwrapped.Nullable(prefix = "u") //
7576
User unwrappedUser;
7677

78+
@DocumentReference
79+
User spiritAnimal;
80+
7781
public Person() {
7882

7983
this(null, null);
@@ -308,6 +312,14 @@ public void setUnwrappedUser(User unwrappedUser) {
308312
this.unwrappedUser = unwrappedUser;
309313
}
310314

315+
public User getSpiritAnimal() {
316+
return spiritAnimal;
317+
}
318+
319+
public void setSpiritAnimal(User spiritAnimal) {
320+
this.spiritAnimal = spiritAnimal;
321+
}
322+
311323
/*
312324
* (non-Javadoc)
313325
*

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/PersonRepository.java

+2
Original file line numberDiff line numberDiff line change
@@ -410,4 +410,6 @@ Person findPersonByManyArguments(String firstname, String lastname, String email
410410
List<Person> findByUnwrappedUserUsername(String username);
411411

412412
List<Person> findByUnwrappedUser(User user);
413+
414+
List<Person> findBySpiritAnimal(User user);
413415
}

0 commit comments

Comments
 (0)