-
Notifications
You must be signed in to change notification settings - Fork 616
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DATAGRAPH-1275 - Verify update of relationship entities.
- Loading branch information
1 parent
a529a08
commit bbf7ec1
Showing
6 changed files
with
249 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...pringframework/data/neo4j/repository/relcentric/MinimalRelationshipEntityMappingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Map<String, Object>> 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 { | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...a-neo4j/src/test/java/org/springframework/data/neo4j/repository/relcentric/app/Actor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Role> roles = new ArrayList<>(); | ||
|
||
public Actor() { | ||
} | ||
|
||
public Actor(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} | ||
|
||
|
33 changes: 33 additions & 0 deletions
33
...a-neo4j/src/test/java/org/springframework/data/neo4j/repository/relcentric/app/Movie.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...ta-neo4j/src/test/java/org/springframework/data/neo4j/repository/relcentric/app/Role.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...rc/test/java/org/springframework/data/neo4j/repository/relcentric/app/RoleRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Role, Long> { | ||
} |