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
}
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);
}
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?");
}
}
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;
}
}
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();
}
}
Aggregations