use of org.neo4j.ogm.transaction.Transaction in project neo4j-ogm by neo4j.
the class BookmarkTest method shouldPassBookmarksToDriver.
@Test
public void shouldPassBookmarksToDriver() {
Set<String> bookmarkStringRepresentation = new HashSet<>(Arrays.asList("bookmark1", "bookmark2"));
Transaction transaction = session.beginTransaction(Transaction.Type.READ_ONLY, bookmarkStringRepresentation);
ArgumentCaptor<SessionConfig> argumentCaptor = ArgumentCaptor.forClass(SessionConfig.class);
verify(nativeDriver).session(argumentCaptor.capture());
SessionConfig sessionConfig = argumentCaptor.getValue();
assertThat(sessionConfig.defaultAccessMode()).isEqualTo(AccessMode.READ);
assertThat(sessionConfig.bookmarks()).contains(Bookmark.from(Collections.singleton("bookmark1")), Bookmark.from(Collections.singleton("bookmark2")));
transaction.rollback();
transaction.close();
}
use of org.neo4j.ogm.transaction.Transaction in project neo4j-ogm by neo4j.
the class RequestExecutor method initialiseNewEntity.
/**
* Register entities in the {@link MappingContext}
*
* @param persisted entity created as part of the request
*/
private void initialiseNewEntity(Long identity, Object persisted) {
MappingContext mappingContext = session.context();
Transaction tx = session.getTransaction();
if (persisted != null) {
// it will be null if the variable represents a simple relationship.
// set the id field of the newly created domain object
EntityUtils.setIdentity(persisted, identity, session.metaData());
ClassInfo classInfo = session.metaData().classInfo(persisted);
if (tx != null) {
((AbstractTransaction) tx).registerNew(persisted);
}
registerEntity(mappingContext, classInfo, identity, persisted);
}
}
use of org.neo4j.ogm.transaction.Transaction in project neo4j-ogm by neo4j.
the class AuthenticatingHttpDriverTest method testUnauthorizedDriver.
@Test
public void testUnauthorizedDriver() {
try {
session = new SessionFactory(getBaseConfigurationBuilder().credentials("", "").build(), "dummy").openSession();
Transaction tx = session.beginTransaction();
tx.commit();
fail("Driver should not have authenticated");
} catch (Exception rpe) {
Throwable cause = rpe.getCause();
while (!(cause instanceof HttpResponseException)) {
cause = cause.getCause();
}
assertThat(cause.getMessage().startsWith("Invalid username or password")).isTrue();
}
}
use of org.neo4j.ogm.transaction.Transaction in project neo4j-ogm by neo4j.
the class AuthenticatingHttpDriverTest method testInvalidCredentials.
// GH-35
@Test
public void testInvalidCredentials() {
try {
session = new SessionFactory(getBaseConfigurationBuilder().credentials("neo4j", "invalid_password").build(), "dummy").openSession();
Transaction tx = session.beginTransaction();
fail("Driver should not have authenticated");
} catch (Exception rpe) {
Throwable cause = rpe.getCause();
while (!(cause instanceof HttpResponseException)) {
cause = cause.getCause();
}
assertThat(cause.getMessage()).isEqualTo("Invalid username or password.");
}
}
use of org.neo4j.ogm.transaction.Transaction in project neo4j-ogm by neo4j.
the class BasicDriverTest method doExtendedCommitRollbackRollback.
private void doExtendedCommitRollbackRollback() {
try (Transaction tx = session.beginTransaction()) {
// commit_deferred
m2();
// rollback_deferred
m3();
// cannot commit outer transaction
tx.rollback();
}
}
Aggregations