Search in sources :

Example 1 with Event

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);
}
Also used : Category(org.neo4j.ogm.domain.mappings.Category) Filter(org.neo4j.ogm.cypher.Filter) Event(org.neo4j.ogm.domain.mappings.Event) Tag(org.neo4j.ogm.domain.mappings.Tag) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with Event

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);
}
Also used : Category(org.neo4j.ogm.domain.mappings.Category) Event(org.neo4j.ogm.domain.mappings.Event) Tag(org.neo4j.ogm.domain.mappings.Tag) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

HashSet (java.util.HashSet)2 Test (org.junit.Test)2 Category (org.neo4j.ogm.domain.mappings.Category)2 Event (org.neo4j.ogm.domain.mappings.Event)2 Tag (org.neo4j.ogm.domain.mappings.Tag)2 Filter (org.neo4j.ogm.cypher.Filter)1