use of org.neo4j.ogm.domain.mappings.Event in project neo4j-ogm by neo4j.
the class DualTargetEntityRelationshipTest method shouldKeepAllRelations.
// DATAGRAPH-690
@Test
public void shouldKeepAllRelations() {
Category category = new Category("cat1");
Tag tag1 = new Tag("tag1");
Set<Tag> tags = new HashSet<>();
tags.add(tag1);
Event event = new Event("title");
event.setCategory(category);
event.setTags(tags);
session.save(event);
assertThat(event.getNodeId()).isNotNull();
assertThat(category.getNodeId()).isNotNull();
assertThat(tag1.getNodeId()).isNotNull();
session.clear();
Collection<Tag> tagsFound = session.loadAll(Tag.class, new Filter("name", ComparisonOperator.EQUALS, "tag1"));
assertThat(tagsFound).hasSize(1);
event.setTags(new HashSet<>(tagsFound));
Collection<Category> categoriesFound = session.loadAll(Category.class, new Filter("name", ComparisonOperator.EQUALS, "cat1"));
assertThat(categoriesFound).hasSize(1);
event.setCategory(categoriesFound.iterator().next());
assertThat(event.getTags().iterator().next()).isEqualTo(tag1);
assertThat(event.getCategory()).isEqualTo(category);
session.save(event);
session.clear();
Event eventFound = session.load(Event.class, event.getNodeId(), 1);
assertThat(eventFound.getNodeId()).isNotNull();
assertThat(eventFound.getCategory()).isEqualTo(category);
assertThat(eventFound.getTags().iterator().next()).isEqualTo(tag1);
}
use of org.neo4j.ogm.domain.mappings.Event in project neo4j-ogm by neo4j.
the class DualTargetEntityRelationshipTest method mappingShouldConsiderClasses.
// DATAGRAPH-636
@Test
public void mappingShouldConsiderClasses() {
Category category = new Category("cat1");
Tag tag1 = new Tag("tag1");
Set<Tag> tags = new HashSet<>();
tags.add(tag1);
Event event = new Event("title");
event.setCategory(category);
event.setTags(tags);
session.save(event);
assertThat(event.getNodeId()).isNotNull();
assertThat(event.getCategory().getNodeId()).isNotNull();
assertThat(event.getTags().iterator().next().getNodeId()).isNotNull();
session.clear();
event = session.load(Event.class, event.getNodeId(), 1);
assertThat(event).isNotNull();
assertThat(event.getCategory()).isEqualTo(category);
assertThat(event.getTags().iterator().next()).isEqualTo(tag1);
}