Search in sources :

Example 1 with ConcreteElement

use of org.neo4j.ogm.domain.gh806.ConcreteElement in project neo4j-ogm by neo4j.

the class HierarchyRelsTest method relationshipsToSubclassesShouldBeClearedAsWell.

// GH-806
@Test
public void relationshipsToSubclassesShouldBeClearedAsWell() {
    inheritanceImpl(s -> new Element(s), Container::setElement);
    inheritanceImpl(s -> new ConcreteElement(s), Container::setElement);
    inheritanceImpl(s -> new VeryConcreteElementA(s), Container::setElement);
    inheritanceImpl(s -> new EvenMoreConcreteElement(s), Container::setElement);
    inheritanceImpl(s -> new IElementImpl1(s), Container::setElement2);
    inheritanceImpl(s -> new IElementImpl1A(s), Container::setElement2);
}
Also used : Container(org.neo4j.ogm.domain.gh806.Container) EvenMoreConcreteElement(org.neo4j.ogm.domain.gh806.EvenMoreConcreteElement) Element(org.neo4j.ogm.domain.gh806.Element) ConcreteElement(org.neo4j.ogm.domain.gh806.ConcreteElement) VeryConcreteElementA(org.neo4j.ogm.domain.gh806.VeryConcreteElementA) IElementImpl1A(org.neo4j.ogm.domain.gh806.IElementImpl1A) IElementImpl1(org.neo4j.ogm.domain.gh806.IElementImpl1) EvenMoreConcreteElement(org.neo4j.ogm.domain.gh806.EvenMoreConcreteElement) ConcreteElement(org.neo4j.ogm.domain.gh806.ConcreteElement) EvenMoreConcreteElement(org.neo4j.ogm.domain.gh806.EvenMoreConcreteElement) Test(org.junit.Test)

Example 2 with ConcreteElement

use of org.neo4j.ogm.domain.gh806.ConcreteElement in project neo4j-ogm by neo4j.

the class HierarchyRelsTest method inheritanceImpl.

<T> void inheritanceImpl(Function<String, T> portProvider, BiConsumer<Container, Set<T>> elementConsumer) {
    session.query("MATCH (n) DETACH DELETE n", Collections.emptyMap());
    session.clear();
    // Setup initial relationships in one tx
    Container card = new Container("container");
    T port1 = portProvider.apply("e1");
    T port2 = portProvider.apply("e2");
    elementConsumer.accept(card, new HashSet<>(Arrays.asList(port1, port2)));
    card.setElementsOfAnotherRelationship(Collections.singleton(new ConcreteElement("oe")));
    session.save(card);
    session.clear();
    // Verify state
    String verificationQuery = "match (c:Container) <- [:RELATES_TO|RELATES_TO_TOO|RELATES_TO_AS_WELL] - (p) " + "where any (label in labels(p) where label in $expectedLabels) return c.name as c, p.name as p";
    Set<String> expectedLabels = new HashSet<>(Arrays.asList(ConcreteElement.class.getSimpleName(), port1.getClass().getSimpleName()));
    Map<String, Object> parameters = Collections.singletonMap("expectedLabels", expectedLabels);
    Result r;
    r = session.query(verificationQuery, parameters);
    assertThat(r.queryResults()).hasSize(3);
    assertThat(r.queryResults()).extracting(m -> m.get("p")).containsExactlyInAnyOrder("e1", "e2", "oe");
    // Reload in cleared session for fresh tx
    card = session.load(Container.class, card.getId());
    T port3 = portProvider.apply("e3");
    // Replace associations
    elementConsumer.accept(card, new HashSet<>(Arrays.asList(port3)));
    session.save(card);
    session.clear();
    r = session.query(verificationQuery, parameters);
    assertThat(r.queryResults()).hasSize(2);
    assertThat(r.queryResults()).extracting(m -> m.get("p")).containsExactlyInAnyOrder("e3", "oe");
}
Also used : Comment(org.neo4j.ogm.domain.forum.activity.Comment) Arrays(java.util.Arrays) IElementImpl1(org.neo4j.ogm.domain.gh806.IElementImpl1) Date(java.util.Date) Type1(org.neo4j.ogm.domain.hierarchy.relations.Type1) Function(java.util.function.Function) Type2(org.neo4j.ogm.domain.hierarchy.relations.Type2) Type3(org.neo4j.ogm.domain.hierarchy.relations.Type3) HashSet(java.util.HashSet) Map(java.util.Map) After(org.junit.After) BiConsumer(java.util.function.BiConsumer) Assertions(org.assertj.core.api.Assertions) VeryConcreteElementA(org.neo4j.ogm.domain.gh806.VeryConcreteElementA) Transaction(org.neo4j.ogm.transaction.Transaction) StreamSupport(java.util.stream.StreamSupport) EvenMoreConcreteElement(org.neo4j.ogm.domain.gh806.EvenMoreConcreteElement) Result(org.neo4j.ogm.model.Result) Before(org.junit.Before) Session(org.neo4j.ogm.session.Session) Member(org.neo4j.ogm.domain.forum.Member) BaseEntity(org.neo4j.ogm.domain.hierarchy.relations.BaseEntity) Container(org.neo4j.ogm.domain.gh806.Container) Set(java.util.Set) IOException(java.io.IOException) Test(org.junit.Test) IElementImpl1A(org.neo4j.ogm.domain.gh806.IElementImpl1A) List(java.util.List) Element(org.neo4j.ogm.domain.gh806.Element) Post(org.neo4j.ogm.domain.forum.activity.Post) SessionFactory(org.neo4j.ogm.session.SessionFactory) TestContainersTestBase(org.neo4j.ogm.testutil.TestContainersTestBase) Collections(java.util.Collections) ConcreteElement(org.neo4j.ogm.domain.gh806.ConcreteElement) Activity(org.neo4j.ogm.domain.forum.activity.Activity) Container(org.neo4j.ogm.domain.gh806.Container) EvenMoreConcreteElement(org.neo4j.ogm.domain.gh806.EvenMoreConcreteElement) ConcreteElement(org.neo4j.ogm.domain.gh806.ConcreteElement) HashSet(java.util.HashSet) Result(org.neo4j.ogm.model.Result)

Aggregations

Test (org.junit.Test)2 ConcreteElement (org.neo4j.ogm.domain.gh806.ConcreteElement)2 Container (org.neo4j.ogm.domain.gh806.Container)2 Element (org.neo4j.ogm.domain.gh806.Element)2 EvenMoreConcreteElement (org.neo4j.ogm.domain.gh806.EvenMoreConcreteElement)2 IElementImpl1 (org.neo4j.ogm.domain.gh806.IElementImpl1)2 IElementImpl1A (org.neo4j.ogm.domain.gh806.IElementImpl1A)2 VeryConcreteElementA (org.neo4j.ogm.domain.gh806.VeryConcreteElementA)2 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 BiConsumer (java.util.function.BiConsumer)1 Function (java.util.function.Function)1 StreamSupport (java.util.stream.StreamSupport)1 Assertions (org.assertj.core.api.Assertions)1