/*
 * Copyright (c) 2002-2017 "Neo Technology,"
 * Network Engine for Objects in Lund AB [http://neotechnology.com]
 *
 * This file is part of Neo4j.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.neo4j.driver.v1.integration;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import org.neo4j.driver.v1.Transaction;
import org.neo4j.driver.v1.util.TestNeo4jSession;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.StringStartsWith.startsWith;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assume.assumeTrue;
import static org.neo4j.driver.v1.util.ServerVersion.v3_1_0;
import static org.neo4j.driver.v1.util.ServerVersion.version;

public class BookmarkIT
{
    @Rule
    public ExpectedException exception = ExpectedException.none();
    @Rule
    public TestNeo4jSession session = new TestNeo4jSession();

    @Before
    public void assumeBookmarkSupport()
    {
        String version = session.run( "RETURN 1" ).consume().server().version();
        assumeTrue( version( version ).greaterThanOrEqual( v3_1_0 ) );
    }

    @Test
    public void shouldReceiveBookmarkOnSuccessfulCommit() throws Throwable
    {
        // Given
        assertNull( session.lastBookmark() );

        // When
        try ( Transaction tx = session.beginTransaction() )
        {
            tx.run( "CREATE (a:Person)" );
            tx.success();
        }

        // Then
        assertNotNull( session.lastBookmark() );
        assertThat( session.lastBookmark(), startsWith( "neo4j:bookmark:v1:tx" ) );
    }
}

@@ -901,16 +901,71 @@
 action;%0A
+import org.neo4j.driver.v1.exceptions.ClientException;%0A
 import o
@@ -1045,25 +1045,20 @@
 cher
-Assert.assertThat
+s.instanceOf
 ;%0Aim
@@ -1201,24 +1201,104 @@
 assertNull;%0A
+import static org.junit.Assert.assertThat;%0Aimport static org.junit.Assert.fail;%0A
 import stati
@@ -2320,11 +2320,1214 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void bookmarkSetToNullAfterRolledBackTx()%0A    %7B%0A        assertNull( session.lastBookmark() );%0A%0A        try ( Transaction tx = session.beginTransaction() )%0A        %7B%0A            tx.run( %22CREATE (a:Person)%22 );%0A            tx.success();%0A        %7D%0A%0A        assertNotNull( session.lastBookmark() );%0A%0A        try ( Transaction tx = session.beginTransaction() )%0A        %7B%0A            tx.run( %22CREATE (a:Person)%22 );%0A            tx.failure();%0A        %7D%0A%0A        assertNull( session.lastBookmark() );%0A    %7D%0A%0A    @Test%0A    public void bookmarkSetToNullAfterTxFailure()%0A    %7B%0A        assertNull( session.lastBookmark() );%0A%0A        try ( Transaction tx = session.beginTransaction() )%0A        %7B%0A            tx.run( %22CREATE (a:Person)%22 );%0A            tx.success();%0A        %7D%0A%0A        assertNotNull( session.lastBookmark() );%0A%0A        Transaction tx = session.beginTransaction();%0A        tx.run( %22RETURN%22 );%0A        tx.success();%0A        try%0A        %7B%0A            tx.close();%0A            fail( %22Exception expected%22 );%0A        %7D%0A        catch ( Exception e )%0A        %7B%0A            assertThat( e, instanceOf( ClientException.class ) );%0A        %7D%0A%0A        assertNull( session.lastBookmark() );%0A    %7D
 %0A%7D%0A

Improve bookmark testing