diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/examples/galaxy/WorldRepositoryTests.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/examples/galaxy/WorldRepositoryTests.java index a63ca36bb0..2879800111 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/examples/galaxy/WorldRepositoryTests.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/examples/galaxy/WorldRepositoryTests.java @@ -45,9 +45,6 @@ public class WorldRepositoryTests { @Autowired WorldRepository worldRepository; - @Autowired - TransactionTemplate transactionTemplate; - boolean failed = false; @Test // DATAGRAPH-951 diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/relcentric/MinimalRelationshipEntityMappingTest.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/relcentric/MinimalRelationshipEntityMappingTest.java new file mode 100644 index 0000000000..833f95f476 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/relcentric/MinimalRelationshipEntityMappingTest.java @@ -0,0 +1,85 @@ +/* + * Copyright 2011-2019 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.repository.relcentric; + +import static org.assertj.core.api.Assertions.*; + +import java.util.Collections; +import java.util.Map; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.neo4j.ogm.session.SessionFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.neo4j.repository.relcentric.app.Actor; +import org.springframework.data.neo4j.repository.relcentric.app.Movie; +import org.springframework.data.neo4j.repository.relcentric.app.Role; +import org.springframework.data.neo4j.repository.relcentric.app.RoleRepository; +import org.springframework.data.neo4j.test.Neo4jIntegrationTest; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.support.TransactionTemplate; + +/** + * @author Michael J. Simons + */ +@RunWith(SpringRunner.class) +@ContextConfiguration(classes = MinimalRelationshipEntityMappingTest.Config.class) +public class MinimalRelationshipEntityMappingTest { + + @Autowired RoleRepository repository; + + @Autowired private TransactionTemplate transactionTemplate; + + @Autowired SessionFactory sessionFactory; + + @Test // DATAGRAPH-1275, OGM-GH-607 + public void verifyUpdateOfRelationshipEntity() { + + long id = transactionTemplate.execute(status -> { + Actor actor = new Actor("A1"); + Movie movie = new Movie("M1"); + Role role = new Role("R1", actor, movie); + return repository.save(role).getId(); + }); + + Iterable> results = sessionFactory.openSession() + .query("MATCH (m:Movie) <- [:ACTS_IN] - (:Actor {name: 'A1'}) RETURN collect(m.name) as titles", + Collections.emptyMap()).queryResults(); + assertThat(results).hasSize(1); + assertThat(results).first() + .satisfies(m -> assertThat((String[]) m.get("titles")).containsOnly("M1")); + + transactionTemplate.execute(status -> { + Role role = repository.findById(id).get(); + role.setMovie(new Movie("M2")); + return repository.save(role).getId(); + }); + + results = sessionFactory.openSession() + .query("MATCH (m:Movie) <- [:ACTS_IN] - (:Actor {name: 'A1'}) RETURN collect(m.name) as titles", + Collections.emptyMap()).queryResults(); + assertThat(results).hasSize(1); + assertThat(results).first() + .satisfies(m -> assertThat((String[]) m.get("titles")).containsOnly("M2")); + } + + @Configuration + @Neo4jIntegrationTest(domainPackages = "org.springframework.data.neo4j.repository.relcentric.app") + static class Config { + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/relcentric/app/Actor.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/relcentric/app/Actor.java new file mode 100644 index 0000000000..1eae18f6e9 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/relcentric/app/Actor.java @@ -0,0 +1,50 @@ +/* + * Copyright 2011-2019 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.repository.relcentric.app; + +import java.util.ArrayList; +import java.util.List; + +import org.neo4j.ogm.annotation.Relationship; + +/** + * @author Michael J. Simons + */ +public class Actor { + + public Long id; + String name; + + @Relationship(type = "ACTS_IN") + private List roles = new ArrayList<>(); + + public Actor() { + } + + public Actor(String name) { + this.name = name; + } + + public Long getId() { + return id; + } + + public String getName() { + return name; + } +} + + diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/relcentric/app/Movie.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/relcentric/app/Movie.java new file mode 100644 index 0000000000..00d0fd2f67 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/relcentric/app/Movie.java @@ -0,0 +1,33 @@ +/* + * Copyright 2011-2019 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.repository.relcentric.app; + + +/** + * @author Michael J. Simons + */ +public class Movie { + + private Long id; + private String name; + + public Movie() { + } + + public Movie(String name) { + this.name = name; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/relcentric/app/Role.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/relcentric/app/Role.java new file mode 100644 index 0000000000..d6cba5a1e0 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/relcentric/app/Role.java @@ -0,0 +1,57 @@ +/* + * Copyright 2011-2019 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.repository.relcentric.app; + +import org.neo4j.ogm.annotation.EndNode; +import org.neo4j.ogm.annotation.RelationshipEntity; +import org.neo4j.ogm.annotation.StartNode; + +/** + * @author Michael J. Simons + */ +@RelationshipEntity(type = "ACTS_IN") +public class Role { + + private Long id; + private String played; + + @StartNode + private Actor actor; + + @EndNode + private Movie movie; + + public Role() { + } + + public Role(String character, Actor actor, Movie movie) { + played = character; + this.actor = actor; + this.movie = movie; + } + + public Long getId() { + return id; + } + + public Movie getMovie() { + return movie; + } + + public void setMovie(Movie movie) { + this.movie = movie; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/relcentric/app/RoleRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/relcentric/app/RoleRepository.java new file mode 100644 index 0000000000..d31b93da27 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/relcentric/app/RoleRepository.java @@ -0,0 +1,24 @@ +/* + * Copyright 2011-2019 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.repository.relcentric.app; + +import org.springframework.data.neo4j.repository.Neo4jRepository; + +/** + * @author Michael J. Simons + */ +public interface RoleRepository extends Neo4jRepository { +}