Search in sources :

Example 1 with SyntaxException

use of org.neo4j.exceptions.SyntaxException in project neo4j by neo4j.

the class InvocationTest method shouldHandleCypherSyntaxError.

@Test
void shouldHandleCypherSyntaxError() {
    // given
    String queryText = "matsch (n) return n";
    when(internalTransaction.execute(queryText, emptyMap())).thenThrow(new RuntimeException(new SyntaxException("did you mean MATCH?")));
    when(registry.begin(any(TransactionHandle.class))).thenReturn(1337L);
    TransactionHandle handle = getTransactionHandle(executionEngine, registry);
    InputEventStream inputEventStream = mock(InputEventStream.class);
    Statement statement = new Statement(queryText, map());
    when(inputEventStream.read()).thenReturn(statement, NULL_STATEMENT);
    Invocation invocation = new Invocation(log, handle, uriScheme.txCommitUri(1337L), mock(MemoryPool.class, RETURNS_MOCKS), inputEventStream, true);
    // when
    invocation.execute(outputEventStream);
    // then
    verify(internalTransaction).rollback();
    verify(registry).forget(1337L);
    InOrder outputOrder = inOrder(outputEventStream);
    outputOrder.verify(outputEventStream).writeFailure(Status.Statement.SyntaxError, "did you mean MATCH?");
    outputOrder.verify(outputEventStream).writeTransactionInfo(TransactionNotificationState.ROLLED_BACK, uriScheme.txCommitUri(1337L), -1);
    verifyNoMoreInteractions(outputEventStream);
}
Also used : InOrder(org.mockito.InOrder) InputEventStream(org.neo4j.server.http.cypher.format.api.InputEventStream) SyntaxException(org.neo4j.exceptions.SyntaxException) Statement(org.neo4j.server.http.cypher.format.api.Statement) MemoryPool(org.neo4j.memory.MemoryPool) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)1 InOrder (org.mockito.InOrder)1 SyntaxException (org.neo4j.exceptions.SyntaxException)1 MemoryPool (org.neo4j.memory.MemoryPool)1 InputEventStream (org.neo4j.server.http.cypher.format.api.InputEventStream)1 Statement (org.neo4j.server.http.cypher.format.api.Statement)1