|
21 | 21 | import java.util.ArrayList;
|
22 | 22 | import java.util.Collection;
|
23 | 23 | import java.util.Collections;
|
| 24 | +import java.util.HashSet; |
24 | 25 | import java.util.List;
|
25 | 26 | import java.util.Map;
|
26 | 27 | import java.util.Optional;
|
| 28 | +import java.util.Set; |
27 | 29 |
|
28 | 30 | import org.junit.jupiter.api.BeforeEach;
|
29 | 31 | import org.junit.jupiter.api.Test;
|
|
45 | 47 | import org.springframework.data.domain.Pageable;
|
46 | 48 | import org.springframework.data.domain.Slice;
|
47 | 49 | import org.springframework.data.domain.Sort;
|
| 50 | +import org.springframework.data.neo4j.core.Neo4jOperations; |
| 51 | +import org.springframework.data.neo4j.integration.shared.common.DoritoEatingPerson; |
48 | 52 | import org.springframework.data.neo4j.test.Neo4jImperativeTestConfiguration;
|
49 | 53 | import org.springframework.data.neo4j.core.DatabaseSelectionProvider;
|
50 | 54 | import org.springframework.data.neo4j.core.Neo4jTemplate;
|
@@ -423,6 +427,38 @@ void saveWithCustomPropertyNameWorks(@Autowired Neo4jTemplate neo4jTemplate) {
|
423 | 427 | }
|
424 | 428 | }
|
425 | 429 |
|
| 430 | + @Test // GH-2578 |
| 431 | + public void projectionRespectedWithInexactPropertyNameMatch(@Autowired Neo4jOperations neo4jOperations) { |
| 432 | + final DoritoEatingPerson person = new DoritoEatingPerson("Bob"); |
| 433 | + person.setEatsDoritos(true); |
| 434 | + person.setFriendsAlsoEatDoritos(true); |
| 435 | + Set<DoritoEatingPerson> friends = new HashSet<>(); |
| 436 | + friends.add(new DoritoEatingPerson("Alice")); |
| 437 | + friends.add(new DoritoEatingPerson("Zoey")); |
| 438 | + person.setFriends(friends); |
| 439 | + |
| 440 | + neo4jOperations.saveAs(person, DoritoEatingPerson.PropertiesProjection1.class); |
| 441 | + |
| 442 | + final Optional<DoritoEatingPerson> saved = neo4jOperations.findById(person.getId(), DoritoEatingPerson.class); |
| 443 | + assertThat(saved).hasValueSatisfying(it -> assertThat(it.getFriends()).isEmpty()); |
| 444 | + } |
| 445 | + |
| 446 | + @Test // GH-2578 |
| 447 | + public void projectionRespected(@Autowired Neo4jOperations neo4jOperations) { |
| 448 | + final DoritoEatingPerson person = new DoritoEatingPerson("Ben"); |
| 449 | + person.setEatsDoritos(true); |
| 450 | + person.setFriendsAlsoEatDoritos(true); |
| 451 | + Set<DoritoEatingPerson> friends = new HashSet<>(); |
| 452 | + friends.add(new DoritoEatingPerson("Kid")); |
| 453 | + friends.add(new DoritoEatingPerson("Jeremias")); |
| 454 | + person.setFriends(friends); |
| 455 | + |
| 456 | + neo4jOperations.saveAs(person, DoritoEatingPerson.PropertiesProjection2.class); |
| 457 | + |
| 458 | + final Optional<DoritoEatingPerson> saved = neo4jOperations.findById(person.getId(), DoritoEatingPerson.class); |
| 459 | + assertThat(saved).hasValueSatisfying(it -> assertThat(it.getFriends()).isEmpty()); |
| 460 | + } |
| 461 | + |
426 | 462 | private static void projectedEntities(PersonDepartmentQueryResult personAndDepartment) {
|
427 | 463 | assertThat(personAndDepartment.getPerson()).extracting(PersonEntity::getId).isEqualTo("p1");
|
428 | 464 | assertThat( personAndDepartment. getPerson()). extracting( PersonEntity:: getEmail). isEqualTo( "[email protected]");
|
|
0 commit comments