Search in sources :

Example 16 with BoltResponseRecorder

use of org.neo4j.bolt.testing.BoltResponseRecorder in project neo4j by neo4j.

the class BoltConnectionAuthIT method shouldBeAbleToActOnSessionWhenUpdatingCredentials.

@Test
public void shouldBeAbleToActOnSessionWhenUpdatingCredentials() throws Throwable {
    BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    // when
    machine.init(USER_AGENT, map("scheme", "basic", "principal", "neo4j", "credentials", "neo4j", "new_credentials", "secret"), recorder);
    machine.run("CREATE ()", map(), recorder);
    // then
    assertThat(recorder.nextResponse(), succeeded());
    assertThat(recorder.nextResponse(), succeeded());
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.Test)

Example 17 with BoltResponseRecorder

use of org.neo4j.bolt.testing.BoltResponseRecorder in project neo4j by neo4j.

the class BoltConnectionAuthIT method shouldGiveCredentialsExpiredStatusOnExpiredCredentials.

@Test
public void shouldGiveCredentialsExpiredStatusOnExpiredCredentials() throws Throwable {
    // Given it is important for client applications to programmatically
    // identify expired credentials as the cause of not being authenticated
    BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    // When
    machine.init(USER_AGENT, map("scheme", "basic", "principal", "neo4j", "credentials", "neo4j"), recorder);
    machine.run("CREATE ()", map(), recorder);
    // Then
    assertThat(recorder.nextResponse(), succeededWithMetadata("credentials_expired", true));
    assertThat(recorder.nextResponse(), failedWithStatus(Status.Security.CredentialsExpired));
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.Test)

Example 18 with BoltResponseRecorder

use of org.neo4j.bolt.testing.BoltResponseRecorder in project neo4j by neo4j.

the class BoltConnectionIT method shouldCloseConnectionResetBeforeInit.

@Test
public void shouldCloseConnectionResetBeforeInit() throws Throwable {
    // Given
    BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
    // when
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    verifyKillsConnection(() -> machine.reset(recorder));
    // then
    assertThat(recorder.nextResponse(), failedWithStatus(Status.Request.Invalid));
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.Test)

Example 19 with BoltResponseRecorder

use of org.neo4j.bolt.testing.BoltResponseRecorder in project neo4j by neo4j.

the class BoltConnectionIT method shouldAllowUserControlledRollbackOnExplicitTxFailure.

@Test
public void shouldAllowUserControlledRollbackOnExplicitTxFailure() throws Throwable {
    // Given whenever en explicit transaction has a failure,
    // it is more natural for drivers to see the failure, acknowledge it
    // and send a `ROLLBACK`, because that means that all failures in the
    // transaction, be they client-local or inside neo, can be handled the
    // same way by a driver.
    BoltStateMachine machine = env.newMachine(new BoltConnectionDescriptor(new InetSocketAddress("bolt-test", 56789), new InetSocketAddress("test-server", 7468)));
    machine.init(USER_AGENT, emptyMap(), null);
    machine.run("BEGIN", EMPTY_PARAMS, nullResponseHandler());
    machine.discardAll(nullResponseHandler());
    machine.run("CREATE (n:Victim)-[:REL]->()", EMPTY_PARAMS, nullResponseHandler());
    machine.discardAll(nullResponseHandler());
    // When I perform an action that will fail
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    machine.run("this is not valid syntax", EMPTY_PARAMS, recorder);
    // Then I should see a failure
    assertThat(recorder.nextResponse(), failedWithStatus(Status.Statement.SyntaxError));
    // And when I acknowledge that failure, and roll back the transaction
    recorder.reset();
    machine.ackFailure(recorder);
    machine.run("ROLLBACK", EMPTY_PARAMS, recorder);
    // Then both operations should succeed
    assertThat(recorder.nextResponse(), succeeded());
    assertThat(recorder.nextResponse(), succeeded());
}
Also used : BoltConnectionDescriptor(org.neo4j.bolt.v1.runtime.BoltConnectionDescriptor) BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) InetSocketAddress(java.net.InetSocketAddress) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.Test)

Example 20 with BoltResponseRecorder

use of org.neo4j.bolt.testing.BoltResponseRecorder in project neo4j by neo4j.

the class BoltConnectionIT method shouldExecuteStatement.

@Test
public void shouldExecuteStatement() throws Throwable {
    // Given
    BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
    machine.init(USER_AGENT, emptyMap(), null);
    // When
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    machine.run("CREATE (n {k:'k'}) RETURN n.k", EMPTY_PARAMS, recorder);
    // Then
    assertThat(recorder.nextResponse(), succeeded());
    // When
    recorder.reset();
    machine.pullAll(recorder);
    // Then
    recorder.nextResponse().assertRecord(0, "k");
//assertThat( pulling.next(), streamContaining( StreamMatchers.eqRecord( equalTo( "k" ) ) ) );
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.Test)

Aggregations

BoltResponseRecorder (org.neo4j.bolt.testing.BoltResponseRecorder)36 Test (org.junit.Test)34 BoltStateMachine (org.neo4j.bolt.v1.runtime.BoltStateMachine)30 InetSocketAddress (java.net.InetSocketAddress)2 RecordedBoltResponse (org.neo4j.bolt.testing.RecordedBoltResponse)2 BoltConnectionDescriptor (org.neo4j.bolt.v1.runtime.BoltConnectionDescriptor)2 HashMap (java.util.HashMap)1 BoltConnectionFatality (org.neo4j.bolt.v1.runtime.BoltConnectionFatality)1 BoltResult (org.neo4j.bolt.v1.runtime.spi.BoltResult)1 BinaryLatch (org.neo4j.concurrent.BinaryLatch)1 Node (org.neo4j.graphdb.Node)1 Transaction (org.neo4j.graphdb.Transaction)1