Skip to content

Commit 620da1f

Browse files
committed
GH-2371 - Failing test.
1 parent f24f7e6 commit 620da1f

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/test/java/org/springframework/data/neo4j/integration/imperative/ProjectionIT.java

+39
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.springframework.data.neo4j.integration.shared.common.NamesWithSpELCity;
5757
import org.springframework.data.neo4j.integration.shared.common.Person;
5858
import org.springframework.data.neo4j.integration.shared.common.PersonSummary;
59+
import org.springframework.data.neo4j.integration.shared.common.PersonWithNoConstructor;
5960
import org.springframework.data.neo4j.integration.shared.common.ProjectionTest1O1;
6061
import org.springframework.data.neo4j.integration.shared.common.ProjectionTestLevel1;
6162
import org.springframework.data.neo4j.integration.shared.common.ProjectionTestRoot;
@@ -104,6 +105,7 @@ void setup() {
104105

105106
transaction.run("MATCH (n) detach delete n");
106107
transaction.run("CREATE (p:PersonEntity {id: 'p1', email: '[email protected]'}) -[:MEMBER_OF]->(department:DepartmentEntity {id: 'd1', name: 'Dep1'}) RETURN p");
108+
transaction.run("CREATE (p:PersonWithNoConstructor {name: 'meistermeier', first_name: 'Gerrit'}) RETURN p");
107109

108110
for (Map.Entry<String, String> person : new Map.Entry[] {
109111
new AbstractMap.SimpleEntry(FIRST_NAME, LAST_NAME),
@@ -365,6 +367,34 @@ void projectionsContainingKnownEntitiesShouldWorkFromTemplate(@Autowired Neo4jTe
365367
.satisfies(ProjectionIT::projectedEntities);
366368
}
367369

370+
@Test // GH-2371
371+
void findWithCustomPropertyNameWorks(@Autowired PersonWithNoConstructorRepository repository) {
372+
assertThat(repository.findAll()).hasSize(1);
373+
ProjectedPersonWithNoConstructor person = repository.findByName("meistermeier");
374+
assertThat(person.getFirstName()).isEqualTo("Gerrit");
375+
}
376+
377+
@Test // GH-2371
378+
void saveWithCustomPropertyNameWorks(@Autowired Neo4jTemplate neo4jTemplate) {
379+
PersonWithNoConstructor person = neo4jTemplate.findOne("MATCH (p:PersonWithNoConstructor {name: 'meistermeier'}) RETURN p", Collections.emptyMap(),
380+
PersonWithNoConstructor.class).get();
381+
382+
person.setName("rotnroll666");
383+
person.setFirstName("Michael");
384+
385+
neo4jTemplate.saveAs(person, ProjectedPersonWithNoConstructor.class);
386+
387+
try (Session session = driver.session(bookmarkCapture.createSessionConfig())) {
388+
Record record = session
389+
.run("MATCH (p:PersonWithNoConstructor {name: 'rotnroll666'}) RETURN p.name as name, p.first_name as first_name")
390+
.single();
391+
392+
assertThat(record.get("first_name").asString()).isEqualTo("Michael");
393+
}
394+
395+
}
396+
397+
368398
private static void projectedEntities(PersonDepartmentQueryResult personAndDepartment) {
369399
assertThat(personAndDepartment.getPerson()).extracting(PersonEntity::getId).isEqualTo("p1");
370400
assertThat(personAndDepartment.getPerson()).extracting(PersonEntity::getEmail).isEqualTo("[email protected]");
@@ -382,6 +412,15 @@ private static Statement whoHasFirstName(String firstName) {
382412
.build();
383413
}
384414

415+
interface ProjectedPersonWithNoConstructor {
416+
String getName();
417+
String getFirstName();
418+
}
419+
420+
interface PersonWithNoConstructorRepository extends Neo4jRepository<PersonWithNoConstructor, Long> {
421+
ProjectedPersonWithNoConstructor findByName(String name);
422+
}
423+
385424
interface ProjectionPersonRepository extends Neo4jRepository<Person, Long>, CypherdslStatementExecutor<Person> {
386425

387426
Collection<NamesOnly> findByLastName(String lastName);

0 commit comments

Comments
 (0)