Search in sources :

Example 6 with Satellite

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

the class SatelliteIntegrationTest method shouldUseLongTransaction.

@Test
public void shouldUseLongTransaction() {
    try (Transaction tx = session.beginTransaction()) {
        // load all
        Collection<Satellite> satellites = session.loadAll(Satellite.class);
        assertThat(satellites).hasSize(11);
        Satellite satellite = satellites.iterator().next();
        Long id = satellite.getId();
        satellite.setName("Updated satellite");
        // update
        session.save(satellite);
        // refetch
        Satellite updatedSatellite = session.load(Satellite.class, id);
        assertThat(updatedSatellite.getName()).isEqualTo("Updated satellite");
    }
// transaction will be rolled back
}
Also used : Transaction(org.neo4j.ogm.transaction.Transaction) Satellite(org.neo4j.ogm.domain.satellites.Satellite) Test(org.junit.Test)

Example 7 with Satellite

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

the class SatelliteIntegrationTest method shouldRollbackClosedAndUnCommittedTransaction.

@Test
public void shouldRollbackClosedAndUnCommittedTransaction() {
    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");
    }
    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 8 with Satellite

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

the class SatelliteIntegrationTest method shouldUpdateSatellite.

@Test
public void shouldUpdateSatellite() {
    Collection<Satellite> satellites = session.loadAll(Satellite.class);
    if (!satellites.isEmpty()) {
        Satellite satellite = satellites.iterator().next();
        Long id = satellite.getId();
        satellite.setName("Updated satellite");
        Date date = new Date();
        satellite.setUpdated(date);
        session.save(satellite);
        Satellite updatedSatellite = session.load(Satellite.class, id);
        assertThat(updatedSatellite.getName()).isEqualTo("Updated satellite");
        assertThat(updatedSatellite.getUpdated()).isEqualTo(date);
    } else {
        fail("Satellite Integration Tests not run: Is there a database?");
    }
}
Also used : Satellite(org.neo4j.ogm.domain.satellites.Satellite) Date(java.util.Date) Test(org.junit.Test)

Example 9 with Satellite

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

the class SatelliteIntegrationTest method shouldLoadActiveSatellitesByPropertySorted.

@Test
public void shouldLoadActiveSatellitesByPropertySorted() {
    Collection<Satellite> satellites = session.loadAll(Satellite.class, new Filter("manned", ComparisonOperator.EQUALS, "Y"), 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 : Filter(org.neo4j.ogm.cypher.Filter) Satellite(org.neo4j.ogm.domain.satellites.Satellite) SortOrder(org.neo4j.ogm.cypher.query.SortOrder) Test(org.junit.Test)

Example 10 with Satellite

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

the class EntityAccessManagerTest method shouldRetrieveAppropriateObjectAccessToAllRelationalAttributesForParticularClass.

@Test
public void shouldRetrieveAppropriateObjectAccessToAllRelationalAttributesForParticularClass() {
    ClassInfo classInfo = this.domainInfo.getClass(DummyDomainObject.class.getName());
    DummyDomainObject domainObject = new DummyDomainObject();
    domainObject.postWithoutAccessorMethods = new Post();
    domainObject.favouriteTopic = new Topic();
    domainObject.member = new Member();
    domainObject.readOnlyComment = new Comment();
    domainObject.registeredMember = new Member();
    domainObject.naturalSatellites = new ArrayList<>();
    domainObject.artificialSatellites = Collections.singletonList(new Satellite());
    Collection<FieldInfo> relationalAccessors = classInfo.relationshipFields();
    assertThat(relationalAccessors).as("The resultant list of object accessors shouldn't be null").isNotNull();
    assertThat(relationalAccessors).as("An unexpected number of accessors was returned").hasSize(7);
    Map<String, Class<? extends FieldInfo>> expectedRelationalReaders = new HashMap<>();
    expectedRelationalReaders.put("COMMENT", FieldInfo.class);
    expectedRelationalReaders.put("FAVOURITE_TOPIC", FieldInfo.class);
    expectedRelationalReaders.put("CONTAINS", FieldInfo.class);
    expectedRelationalReaders.put("POST_WITHOUT_ACCESSOR_METHODS", FieldInfo.class);
    expectedRelationalReaders.put("NATURAL", FieldInfo.class);
    expectedRelationalReaders.put("ARTIFICIAL", FieldInfo.class);
    expectedRelationalReaders.put("REGISTERED", FieldInfo.class);
    for (FieldInfo objectAccess : relationalAccessors) {
        String relType = objectAccess.relationshipType();
        assertThat(expectedRelationalReaders.containsKey(relType)).as("Relationship type " + relType + " wasn't expected").isTrue();
        assertThat(objectAccess.getClass()).isEqualTo(expectedRelationalReaders.get(relType));
        assertThat(objectAccess.read(domainObject)).isNotNull();
    }
}
Also used : Comment(org.neo4j.ogm.domain.forum.activity.Comment) HashMap(java.util.HashMap) Post(org.neo4j.ogm.domain.forum.activity.Post) Satellite(org.neo4j.ogm.domain.satellites.Satellite) Topic(org.neo4j.ogm.domain.forum.Topic) Member(org.neo4j.ogm.domain.forum.Member) FieldInfo(org.neo4j.ogm.metadata.FieldInfo) ClassInfo(org.neo4j.ogm.metadata.ClassInfo) 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