Search in sources :

Example 11 with Transaction

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();
}
Also used : Transaction(org.neo4j.ogm.transaction.Transaction) SessionConfig(org.neo4j.driver.SessionConfig) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Example 12 with Transaction

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);
    }
}
Also used : MappingContext(org.neo4j.ogm.context.MappingContext) AbstractTransaction(org.neo4j.ogm.transaction.AbstractTransaction) Transaction(org.neo4j.ogm.transaction.Transaction) AbstractTransaction(org.neo4j.ogm.transaction.AbstractTransaction) ClassInfo(org.neo4j.ogm.metadata.ClassInfo)

Example 13 with Transaction

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();
    }
}
Also used : SessionFactory(org.neo4j.ogm.session.SessionFactory) Transaction(org.neo4j.ogm.transaction.Transaction) HttpResponseException(org.apache.http.client.HttpResponseException) HttpResponseException(org.apache.http.client.HttpResponseException) Test(org.junit.Test)

Example 14 with Transaction

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.");
    }
}
Also used : SessionFactory(org.neo4j.ogm.session.SessionFactory) Transaction(org.neo4j.ogm.transaction.Transaction) HttpResponseException(org.apache.http.client.HttpResponseException) HttpResponseException(org.apache.http.client.HttpResponseException) Test(org.junit.Test)

Example 15 with Transaction

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();
    }
}
Also used : Transaction(org.neo4j.ogm.transaction.Transaction)

Aggregations

Transaction (org.neo4j.ogm.transaction.Transaction)47 Test (org.junit.Test)30 Session (org.neo4j.ogm.session.Session)10 ArrayList (java.util.ArrayList)5 Neo4jSession (org.neo4j.ogm.session.Neo4jSession)5 SessionConfig (org.neo4j.driver.SessionConfig)4 Result (org.neo4j.ogm.model.Result)4 HashSet (java.util.HashSet)3 LinkedHashSet (java.util.LinkedHashSet)3 HttpResponseException (org.apache.http.client.HttpResponseException)3 Bike (org.neo4j.ogm.domain.gh817.Bike)3 Studio (org.neo4j.ogm.domain.music.Studio)3 Satellite (org.neo4j.ogm.domain.satellites.Satellite)3 User (org.neo4j.ogm.domain.social.User)3 SessionFactory (org.neo4j.ogm.session.SessionFactory)3 IOException (java.io.IOException)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2