Search in sources :

Example 1 with Satellite

use of org.neo4j.ogm.domain.satellites.Satellite in project neo4j-ogm by neo4j.

the class SatelliteIntegrationTest method shouldReturnSatellitesSortedByRefAsc.

@Test
public void shouldReturnSatellitesSortedByRefAsc() {
    Collection<Satellite> satellites = session.loadAll(Satellite.class, new SortOrder().add("ref"));
    Iterator<Satellite> iter = satellites.iterator();
    Satellite first = iter.next();
    while (iter.hasNext()) {
        Satellite next = iter.next();
        assertThat(first.getRef().compareTo(next.getRef()) < 0).isTrue();
        first = next;
    }
}
Also used : Satellite(org.neo4j.ogm.domain.satellites.Satellite) SortOrder(org.neo4j.ogm.cypher.query.SortOrder) Test(org.junit.Test)

Example 2 with Satellite

use of org.neo4j.ogm.domain.satellites.Satellite in project neo4j-ogm by neo4j.

the class SatelliteIntegrationTest method shouldRollbackLongTransaction.

@Test
public void shouldRollbackLongTransaction() {
    Long id;
    String name;
    try (Transaction tx = session.beginTransaction()) {
        // load all
        Collection<Satellite> satellites = session.loadAll(Satellite.class);
        assertThat(satellites).hasSize(11);
        Satellite satellite = satellites.iterator().next();
        id = satellite.getId();
        name = satellite.getName();
        satellite.setName("Updated satellite");
        // update
        session.save(satellite);
        session.clear();
        // refetch
        Satellite updatedSatellite = session.load(Satellite.class, id);
        assertThat(updatedSatellite.getName()).isEqualTo("Updated satellite");
        tx.rollback();
    }
    session.clear();
    // fetch - after rollback should not be changed
    // note, that because we aren't starting a new tx, we will be given an autocommit one.
    Satellite reloadedSatellite = session.load(Satellite.class, id);
    assertThat(reloadedSatellite.getName()).isEqualTo(name);
}
Also used : Transaction(org.neo4j.ogm.transaction.Transaction) Satellite(org.neo4j.ogm.domain.satellites.Satellite) Test(org.junit.Test)

Example 3 with Satellite

use of org.neo4j.ogm.domain.satellites.Satellite in project neo4j-ogm by neo4j.

the class EntityAccessManagerTest method shouldPreferAnnotatedFieldWithMatchingRelationshipTypeWhenGettingIterableWriter.

/**
 * @see DATAGRAPH-637
 */
@Test
public void shouldPreferAnnotatedFieldWithMatchingRelationshipTypeWhenGettingIterableWriter() {
    // 2nd, try to find a field annotated with with relationship type
    ClassInfo classInfo = this.domainInfo.getClass(DummyDomainObject.class.getName());
    List<Satellite> natural = new ArrayList<>();
    natural.add(new Satellite());
    FieldInfo objectAccess = EntityAccessManager.getIterableField(classInfo, Satellite.class, "NATURAL", Relationship.Direction.OUTGOING);
    assertThat(objectAccess).as("The resultant object accessor shouldn't be null").isNotNull();
    DummyDomainObject domainObject = new DummyDomainObject();
    objectAccess.write(domainObject, natural);
    assertThat(domainObject.naturalSatellites).isEqualTo(natural);
}
Also used : ArrayList(java.util.ArrayList) Satellite(org.neo4j.ogm.domain.satellites.Satellite) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Example 4 with Satellite

use of org.neo4j.ogm.domain.satellites.Satellite in project neo4j-ogm by neo4j.

the class EntityAccessManagerTest method shouldPreferAnnotatedFieldWithMatchingRelationshipTypeWhenGettingIterableReader.

/**
 * @see DATAGRAPH-637
 */
@Test
public void shouldPreferAnnotatedFieldWithMatchingRelationshipTypeWhenGettingIterableReader() {
    // 2nd, try to find a field annotated with with relationship type
    ClassInfo classInfo = this.domainInfo.getClass(DummyDomainObject.class.getName());
    List<Satellite> natural = new ArrayList<>();
    natural.add(new Satellite());
    FieldInfo relationalReader = EntityAccessManager.getIterableField(classInfo, Satellite.class, "NATURAL", Relationship.Direction.OUTGOING);
    assertThat(relationalReader).as("The resultant object accessor shouldn't be null").isNotNull();
    DummyDomainObject domainObject = new DummyDomainObject();
    domainObject.naturalSatellites = natural;
    Object o = relationalReader.read(domainObject);
    assertThat(o).isEqualTo(natural);
}
Also used : ArrayList(java.util.ArrayList) Satellite(org.neo4j.ogm.domain.satellites.Satellite) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) Test(org.junit.Test)

Example 5 with Satellite

use of org.neo4j.ogm.domain.satellites.Satellite in project neo4j-ogm by neo4j.

the class SatelliteIntegrationTest method shouldCommitLongTransaction.

@Test
public void shouldCommitLongTransaction() {
    Long id;
    try (Transaction tx = session.beginTransaction()) {
        // load all
        Collection<Satellite> satellites = session.loadAll(Satellite.class);
        assertThat(satellites).hasSize(11);
        Satellite satellite = satellites.iterator().next();
        id = satellite.getId();
        satellite.setName("Updated satellite");
        // update
        session.save(satellite);
        session.clear();
        // refetch
        Satellite updatedSatellite = session.load(Satellite.class, id);
        assertThat(updatedSatellite.getName()).isEqualTo("Updated satellite");
        tx.commit();
    }
    session.clear();
    // fetch - after commit should be changed
    // note, that because we aren't starting a new tx, we will be given an autocommit one.
    Satellite reloadedSatellite = session.load(Satellite.class, id);
    assertThat(reloadedSatellite.getName()).isEqualTo("Updated satellite");
}
Also used : Transaction(org.neo4j.ogm.transaction.Transaction) Satellite(org.neo4j.ogm.domain.satellites.Satellite) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 Satellite (org.neo4j.ogm.domain.satellites.Satellite)11 ClassInfo (org.neo4j.ogm.metadata.ClassInfo)4 FieldInfo (org.neo4j.ogm.metadata.FieldInfo)4 Transaction (org.neo4j.ogm.transaction.Transaction)4 ArrayList (java.util.ArrayList)2 SortOrder (org.neo4j.ogm.cypher.query.SortOrder)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Filter (org.neo4j.ogm.cypher.Filter)1 Member (org.neo4j.ogm.domain.forum.Member)1 Topic (org.neo4j.ogm.domain.forum.Topic)1 Comment (org.neo4j.ogm.domain.forum.activity.Comment)1 Post (org.neo4j.ogm.domain.forum.activity.Post)1 Program (org.neo4j.ogm.domain.satellites.Program)1