    public Collection<Long> getIndexedRelationships( String indexName, String key, Object value )
    {
        try ( Transaction tx = database.getGraph().beginTx() )
        {
            Collection<Long> result = new ArrayList<>();
            for ( Relationship relationship : database.getGraph().index().forRelationships( indexName ).get( key, value ) )
            {
                result.add( relationship.getId() );
            }
            tx.success();
            return result;
        }
    }

    public Collection<Long> getIndexedRelationships( String indexName, String key, Object value )
    {
        Transaction tx = database.getGraph().beginTx();
        try
        {
            Collection<Long> result = new ArrayList<>();
            for ( Relationship relationship : database.getGraph().index().forRelationships( indexName ).get( key, value ) )
            {
                result.add( relationship.getId() );
            }
            tx.success();
            return result;
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public getIndexedRelationships(indexName String, key String, value Object) : Collection<Long> from class org.neo4j.server.rest.domain.GraphDbHelper


    public void addRelationshipToIndex( String indexName, String key, String value, long relationshipId )
    {
        try ( Transaction tx = database.getGraph().beginTx() )
        {
            Index<Relationship> index = database.getGraph().index().forRelationships( indexName );
            index.add( database.getGraph().getRelationshipById( relationshipId ), key, value );
            tx.success();
        }

    }

    public void addRelationshipToIndex( String indexName, String key, String value, long relationshipId )
    {
        Transaction tx = database.getGraph().beginTx();
        try
        {
            Index<Relationship> index = database.getGraph().index().forRelationships( indexName );
            index.add( database.getGraph().getRelationshipById( relationshipId ), key, value );
            tx.success();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public addRelationshipToIndex(indexName String, key String, value String, relationshipId long) : void from class org.neo4j.server.rest.domain.GraphDbHelper


    public String[] getNodeIndexes()
    {
        try (Transaction transaction = database.getGraph().beginTx())
        {
            return database.getGraph().index().nodeIndexNames();
        }
    }

    public String[] getNodeIndexes()
    {
        Transaction transaction = database.getGraph().beginTx();
        try
        {
            return database.getGraph().index().nodeIndexNames();
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=database.getGraph().beginTx()) in method public getNodeIndexes() : String[] from class org.neo4j.server.rest.domain.GraphDbHelper


    public Index<Node> createNodeFullTextIndex( String named )
    {
        try ( Transaction transaction = database.getGraph().beginTx() )
        {
            Index<Node> index = database.getGraph().index().forNodes( named, MapUtil.stringMap( IndexManager.PROVIDER, "lucene", "type", "fulltext" ) );
            transaction.success();
            return index;
        }
    }

    public Index<Node> createNodeFullTextIndex( String named )
    {
        Transaction transaction = database.getGraph().beginTx();
        try
        {
            Index<Node> index = database.getGraph().index().forNodes( named, MapUtil.stringMap( IndexManager.PROVIDER, "lucene", "type", "fulltext" ) );
            transaction.success();
            return index;
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=database.getGraph().beginTx()) in method public createNodeFullTextIndex(named String) : Index<Node> from class org.neo4j.server.rest.domain.GraphDbHelper


    public Index<Node> createNodeIndex( String named )
    {
        try ( Transaction transaction = database.getGraph().beginTx() )
        {
            Index<Node> nodeIndex = database.getGraph().index()
                    .forNodes( named );
            transaction.success();
            return nodeIndex;
        }
    }

    public Index<Node> createNodeIndex( String named )
    {
        Transaction transaction = database.getGraph().beginTx();
        try
        {
            Index<Node> nodeIndex = database.getGraph().index()
                    .forNodes( named );
            transaction.success();
            return nodeIndex;
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=database.getGraph().beginTx()) in method public createNodeIndex(named String) : Index<Node> from class org.neo4j.server.rest.domain.GraphDbHelper


    public String[] getRelationshipIndexes()
    {
        try (Transaction transaction = database.getGraph().beginTx())
        {
            return database.getGraph().index()
                    .relationshipIndexNames();
        }
    }

    public String[] getRelationshipIndexes()
    {
        Transaction transaction = database.getGraph().beginTx();
        try
        {
            return database.getGraph().index()
                    .relationshipIndexNames();
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=database.getGraph().beginTx()) in method public getRelationshipIndexes() : String[] from class org.neo4j.server.rest.domain.GraphDbHelper


    public long getFirstNode()
    {
        try (Transaction tx = database.getGraph().beginTx())
        {
            try
            {
                Node referenceNode = database.getGraph().getNodeById(0l);

                tx.success();
                return referenceNode.getId();
            }
            catch(NotFoundException e)
            {
                Node newNode = database.getGraph().createNode();
                tx.success();
                return newNode.getId();
            }
        }
    }

    public long getFirstNode()
    {
        Transaction tx = database.getGraph().beginTx();
        try
        {
            try
            {
                Node referenceNode = database.getGraph().getNodeById(0l);

                tx.success();
                return referenceNode.getId();
            }
            catch(NotFoundException e)
            {
                Node newNode = database.getGraph().createNode();
                tx.success();
                return newNode.getId();
            }
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public getFirstNode() : long from class org.neo4j.server.rest.domain.GraphDbHelper


    public Index<Relationship> createRelationshipIndex( String named )
    {
        try (Transaction transaction = database.getGraph().beginTx())
        {
            RelationshipIndex relationshipIndex = database.getGraph().index()
                    .forRelationships( named );
            transaction.success();
            return relationshipIndex;
        }
    }

    public Index<Relationship> createRelationshipIndex( String named )
    {
        Transaction transaction = database.getGraph().beginTx();
        try
        {
            RelationshipIndex relationshipIndex = database.getGraph().index()
                    .forRelationships( named );
            transaction.success();
            return relationshipIndex;
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=database.getGraph().beginTx()) in method public createRelationshipIndex(named String) : Index<Relationship> from class org.neo4j.server.rest.domain.GraphDbHelper


    public void addLabelToNode( long node, String labelName )
    {
        try ( Transaction tx = database.getGraph().beginTx() )
        {
            database.getGraph().getNodeById( node ).addLabel( label( labelName ) );
            tx.success();
        }
    }

    public void addLabelToNode( long node, String labelName )
    {
        Transaction tx = database.getGraph().beginTx();
        try
        {
            database.getGraph().getNodeById( node ).addLabel( label( labelName ) );
            tx.success();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public addLabelToNode(node long, labelName String) : void from class org.neo4j.server.rest.domain.GraphDbHelper


    public IndexDefinition createSchemaIndex( String labelName, String propertyKey )
    {
        try ( Transaction tx = database.getGraph().beginTx() )
        {
            IndexDefinition index = database.getGraph().schema().indexFor( label( labelName ) ).on( propertyKey ).create();
            tx.success();
            return index;
        }
    }

    public IndexDefinition createSchemaIndex( String labelName, String propertyKey )
    {
        Transaction tx = database.getGraph().beginTx();
        try
        {
            IndexDefinition index = database.getGraph().schema().indexFor( label( labelName ) ).on( propertyKey ).create();
            tx.success();
            return index;
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public createSchemaIndex(labelName String, propertyKey String) : IndexDefinition from class org.neo4j.server.rest.domain.GraphDbHelper


    public Iterable<ConstraintDefinition> getPropertyUniquenessConstraints( String labelName, final String propertyKey )
    {
        try ( Transaction tx = database.getGraph().beginTx() )
        {
            Iterable<ConstraintDefinition> definitions = Iterables.filter( new Predicate<ConstraintDefinition>()
            {

                @Override
                public boolean test( ConstraintDefinition item )
                {
                    if ( item.isConstraintType( ConstraintType.UNIQUENESS ) )
                    {
                        Iterable<String> keys = item.getPropertyKeys();
                        return single( keys ).equals( propertyKey );
                    }
                    else
                    {
                        return false;
                    }

                }
            }, database.getGraph().schema().getConstraints( label( labelName ) ) );
            tx.success();
            return definitions;
        }
    }

    public Iterable<ConstraintDefinition> getPropertyUniquenessConstraints( String labelName, final String propertyKey )
    {
        Transaction tx = database.getGraph().beginTx();
        try
        {
            Iterable<ConstraintDefinition> definitions = Iterables.filter( new Predicate<ConstraintDefinition>()
            {

                @Override
                public boolean test( ConstraintDefinition item )
                {
                    if ( item.isConstraintType( ConstraintType.UNIQUENESS ) )
                    {
                        Iterable<String> keys = item.getPropertyKeys();
                        return single( keys ).equals( propertyKey );
                    }
                    else
                    {
                        return false;
                    }

                }
            }, database.getGraph().schema().getConstraints( label( labelName ) ) );
            tx.success();
            return definitions;
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public getPropertyUniquenessConstraints(labelName String, propertyKey String) : Iterable<ConstraintDefinition> from class org.neo4j.server.rest.domain.GraphDbHelper


    public Iterable<ConstraintDefinition> getPropertyExistenceConstraints( String labelName, final String propertyKey )
    {
        try ( Transaction tx = database.getGraph().beginTx() )
        {
            Iterable<ConstraintDefinition> definitions = Iterables.filter( new Predicate<ConstraintDefinition>()
            {

                @Override
                public boolean test( ConstraintDefinition item )
                {
                    if ( item.isConstraintType( ConstraintType.MANDATORY_PROPERTY ) )
                    {
                        Iterable<String> keys = item.getPropertyKeys();
                        return single( keys ).equals( propertyKey );
                    }
                    else
                    {
                        return false;
                    }

                }
            }, database.getGraph().schema().getConstraints( label( labelName ) ) );
            tx.success();
            return definitions;
        }
    }

    public Iterable<ConstraintDefinition> getPropertyExistenceConstraints( String labelName, final String propertyKey )
    {
        Transaction tx = database.getGraph().beginTx();
        try
        {
            Iterable<ConstraintDefinition> definitions = Iterables.filter( new Predicate<ConstraintDefinition>()
            {

                @Override
                public boolean test( ConstraintDefinition item )
                {
                    if ( item.isConstraintType( ConstraintType.MANDATORY_PROPERTY ) )
                    {
                        Iterable<String> keys = item.getPropertyKeys();
                        return single( keys ).equals( propertyKey );
                    }
                    else
                    {
                        return false;
                    }

                }
            }, database.getGraph().schema().getConstraints( label( labelName ) ) );
            tx.success();
            return definitions;
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public getPropertyExistenceConstraints(labelName String, propertyKey String) : Iterable<ConstraintDefinition> from class org.neo4j.server.rest.domain.GraphDbHelper


    public ConstraintDefinition createPropertyUniquenessConstraint( String labelName, List<String> propertyKeys )
    {
        try ( Transaction tx = database.getGraph().beginTx() )
        {
            ConstraintCreator creator = database.getGraph().schema().constraintFor( label( labelName ) );
            for ( String propertyKey : propertyKeys )
            {
                creator = creator.assertPropertyIsUnique( propertyKey );
            }
            ConstraintDefinition result = creator.create();
            tx.success();
            return result;
        }
    }

    public ConstraintDefinition createPropertyUniquenessConstraint( String labelName, List<String> propertyKeys )
    {
        Transaction tx = database.getGraph().beginTx();
        try
        {
            ConstraintCreator creator = database.getGraph().schema().constraintFor( label( labelName ) );
            for ( String propertyKey : propertyKeys )
            {
                creator = creator.assertPropertyIsUnique( propertyKey );
            }
            ConstraintDefinition result = creator.create();
            tx.success();
            return result;
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public createPropertyUniquenessConstraint(labelName String, propertyKeys List<String>) : ConstraintDefinition from class org.neo4j.server.rest.domain.GraphDbHelper


    public ConstraintDefinition createPropertyExistenceConstraint( String labelName, List<String> propertyKeys )
    {
        try (Transaction tx = database.getGraph().beginTx())
        {
            ConstraintCreator creator = database.getGraph().schema().constraintFor( label( labelName ) );
            for ( String propertyKey : propertyKeys )
            {
                creator = creator.assertPropertyExists( propertyKey );
            }
            ConstraintDefinition result = creator.create();
            tx.success();
            return result;
        }
    }

    public ConstraintDefinition createPropertyExistenceConstraint( String labelName, List<String> propertyKeys )
    {
        Transaction tx = database.getGraph().beginTx();
        try
        {
            ConstraintCreator creator = database.getGraph().schema().constraintFor( label( labelName ) );
            for ( String propertyKey : propertyKeys )
            {
                creator = creator.assertPropertyExists( propertyKey );
            }
            ConstraintDefinition result = creator.create();
            tx.success();
            return result;
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public createPropertyExistenceConstraint(labelName String, propertyKeys List<String>) : ConstraintDefinition from class org.neo4j.server.rest.domain.GraphDbHelper


    public long getLabelCount( long nodeId )
    {
        try (Transaction transaction = database.getGraph().beginTx())
        {
            return count( database.getGraph().getNodeById( nodeId ).getLabels());
        }
    }

    public long getLabelCount( long nodeId )
    {
        Transaction transaction = database.getGraph().beginTx();

        try
        {
            return count( database.getGraph().getNodeById( nodeId ).getLabels());
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=database.getGraph().beginTx()) in method public getLabelCount(nodeId long) : long from class org.neo4j.server.rest.domain.GraphDbHelper


    private void createData() {
        try ( Transaction tx = gdb.beginTx() )
        {
            final DynamicRelationshipType TYPE = DynamicRelationshipType.withName("TYPE");
            Node last = gdb.createNode();
            last.setProperty("id", 0);
            for (int i = 1; i < 10000; i++) {
                final Node node = gdb.createNode();
                last.setProperty("id", i);
                node.createRelationshipTo(last, TYPE);
                last = node;
            }
            tx.success();
        }
    }

    private void createData() {
        final Transaction tx = gdb.beginTx();
        try {
            final DynamicRelationshipType TYPE = DynamicRelationshipType.withName("TYPE");
            Node last = gdb.createNode();
            last.setProperty("id", 0);
            for (int i = 1; i < 10000; i++) {
                final Node node = gdb.createNode();
                last.setProperty("id", i);
                node.createRelationshipTo(last, TYPE);
                last = node;
            }
            tx.success();
        } finally {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=gdb.beginTx()) in method private createData() : void from class org.neo4j.server.rest.repr.formats.StreamingJsonFormatPerformanceTest


    @Test
    public void canFormatNode() throws Exception
    {
        GraphDatabaseService db = new TestGraphDatabaseFactory().newImpermanentDatabase();
        try ( Transaction transaction = db.beginTx() )
        {
            final Node n = db.createNode();
            json.assemble( new NodeRepresentation( n ) );
        }
        finally
        {
            db.shutdown();
        }
        assertTrue( stream.toString().contains( "\"self\" : \"http://localhost/node/0\"," ) );
    }

    @Test
    public void canFormatNode() throws Exception
    {
        GraphDatabaseService db = new TestGraphDatabaseFactory().newImpermanentDatabase();
        Transaction transaction = db.beginTx();
        try
        {
            final Node n = db.createNode();
            json.assemble( new NodeRepresentation( n ) );
        }
        finally
        {
            transaction.finish();
            db.shutdown();
        }
        assertTrue( stream.toString().contains( "\"self\" : \"http://localhost/node/0\"," ) );
    }

Try With Resources try(Transaction transaction=db.beginTx()) in method public canFormatNode() : void from class org.neo4j.server.rest.repr.formats.StreamingJsonFormatTest


    private long createNode( Map<String, Object> properties )
    {

        long nodeId;
        try ( Transaction tx = database.getGraph().beginTx() )
        {
            Node node = database.getGraph().createNode( LABEL );
            for ( Map.Entry<String, Object> entry : properties.entrySet() )
            {
                node.setProperty( entry.getKey(), entry.getValue() );
            }
            nodeId = node.getId();
            tx.success();
        }
        return nodeId;
    }

    private long createNode( Map<String, Object> properties )
    {

        long nodeId;
        Transaction tx = database.getGraph().beginTx();
        try
        {
            Node node = database.getGraph().createNode( LABEL );
            for ( Map.Entry<String, Object> entry : properties.entrySet() )
            {
                node.setProperty( entry.getKey(), entry.getValue() );
            }
            nodeId = node.getId();
            tx.success();
        }
        finally
        {
            tx.finish();
        }
        return nodeId;
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method private createNode(properties Map<String,Object>) : long from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void createdNodeShouldBeInDatabase() throws Exception
    {
        NodeRepresentation noderep = actions.createNode( Collections.<String, Object>emptyMap() );

        try (Transaction tx = database.getGraph().beginTx())
        {
            assertNotNull( database.getGraph().getNodeById( noderep.getId() ) );
        }
    }

    @Test
    public void createdNodeShouldBeInDatabase() throws Exception
    {
        NodeRepresentation noderep = actions.createNode( Collections.<String, Object>emptyMap() );

        Transaction tx = database.getGraph().beginTx();
        try
        {
            assertNotNull( database.getGraph().getNodeById( noderep.getId() ) );
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public createdNodeShouldBeInDatabase() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldBeAbleToStorePropertiesInAnExistingNode() throws
            PropertyValueException, NodeNotFoundException
    {
        long nodeId = graphdbHelper.createNode();
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put( "foo", "bar" );
        properties.put( "baz", 17 );
        actions.setAllNodeProperties( nodeId, properties );

        try ( Transaction tx = database.getGraph().beginTx() )
        {
            Node node = database.getGraph().getNodeById( nodeId );
            assertHasProperties( node, properties );
        }
    }

    @Test
    public void shouldBeAbleToStorePropertiesInAnExistingNode() throws
            PropertyValueException, NodeNotFoundException
    {
        long nodeId = graphdbHelper.createNode();
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put( "foo", "bar" );
        properties.put( "baz", 17 );
        actions.setAllNodeProperties( nodeId, properties );

        Transaction tx = database.getGraph().beginTx();
        try
        {
            Node node = database.getGraph().getNodeById( nodeId );
            assertHasProperties( node, properties );
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public shouldBeAbleToStorePropertiesInAnExistingNode() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldBeAbleToGetPropertiesOnNode() throws NodeNotFoundException
    {

        long nodeId;
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put( "foo", "bar" );
        properties.put( "neo", "Thomas A. Anderson" );
        properties.put( "number", 15L );
        Node node;
        try ( Transaction tx = database.getGraph().beginTx() )
        {
            node = database.getGraph().createNode();
            for ( Map.Entry<String, Object> entry : properties.entrySet() )
            {
                node.setProperty( entry.getKey(), entry.getValue() );
            }
            nodeId = node.getId();
            tx.success();
        }

        try ( Transaction transaction = graph.beginTx() )
        {
            assertEquals( properties, serialize( actions.getAllNodeProperties( nodeId ) ) );
        }
    }

    @Test
    public void shouldBeAbleToGetPropertiesOnNode() throws NodeNotFoundException
    {

        long nodeId;
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put( "foo", "bar" );
        properties.put( "neo", "Thomas A. Anderson" );
        properties.put( "number", 15L );
        Transaction tx = database.getGraph().beginTx();
        Node node;
        try
        {
            node = database.getGraph().createNode();
            for ( Map.Entry<String, Object> entry : properties.entrySet() )
            {
                node.setProperty( entry.getKey(), entry.getValue() );
            }
            nodeId = node.getId();
            tx.success();
        }
        finally
        {
            tx.finish();
        }

        Transaction transaction = graph.beginTx();
        try
        {
            assertEquals( properties, serialize( actions.getAllNodeProperties( nodeId ) ) );
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public shouldBeAbleToGetPropertiesOnNode() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldRemoveNodeWithNoRelationsFromDBOnDelete() throws NodeNotFoundException,
            ConstraintViolationException
    {
        long nodeId;
        try ( Transaction tx = database.getGraph().beginTx() )
        {
            Node node = database.getGraph().createNode();
            nodeId = node.getId();
            tx.success();
        }

        int nodeCount = graphdbHelper.getNumberOfNodes();
        actions.deleteNode( nodeId );
        assertEquals( nodeCount - 1, graphdbHelper.getNumberOfNodes() );
    }

    @Test
    public void shouldRemoveNodeWithNoRelationsFromDBOnDelete() throws NodeNotFoundException,
            ConstraintViolationException
    {
        long nodeId;
        Transaction tx = database.getGraph().beginTx();
        try
        {
            Node node = database.getGraph().createNode();
            nodeId = node.getId();
            tx.success();
        }
        finally
        {
            tx.finish();
        }

        int nodeCount = graphdbHelper.getNumberOfNodes();
        actions.deleteNode( nodeId );
        assertEquals( nodeCount - 1, graphdbHelper.getNumberOfNodes() );
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public shouldRemoveNodeWithNoRelationsFromDBOnDelete() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void settingAnEmptyArrayShouldWorkIfOriginalEntityHasAnEmptyArrayAsWell() throws Exception
    {
        // Given
        long nodeId = createNode( map( "emptyArray", new int[]{} ) );

        // When
        actions.setNodeProperty( nodeId, "emptyArray", new ArrayList<>() );

        // Then
        try ( Transaction transaction = graph.beginTx() )
        {
            assertThat( ((List<Object>) serialize( actions.getNodeProperty( nodeId, "emptyArray" ) )).size(), is( 0 ) );
        }
    }

    @Test
    public void settingAnEmptyArrayShouldWorkIfOriginalEntityHasAnEmptyArrayAsWell() throws Exception
    {
        // Given
        long nodeId = createNode( map( "emptyArray", new int[]{} ) );

        // When
        actions.setNodeProperty( nodeId, "emptyArray", new ArrayList<>() );

        // Then
        Transaction transaction = graph.beginTx();
        try
        {
            assertThat( ((List<Object>) serialize( actions.getNodeProperty( nodeId, "emptyArray" ) )).size(), is( 0 ) );
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public settingAnEmptyArrayShouldWorkIfOriginalEntityHasAnEmptyArrayAsWell() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldBeAbleToGetPropertyOnNode() throws Exception
    {
        String key = "foo";
        Object value = "bar";
        long nodeId = createNode( Collections.singletonMap( key, value ) );
        try ( Transaction transaction = graph.beginTx() )
        {
            assertEquals( value, serialize( actions.getNodeProperty( nodeId, key ) ) );
        }
    }

    @Test
    public void shouldBeAbleToGetPropertyOnNode() throws Exception
    {
        String key = "foo";
        Object value = "bar";
        long nodeId = createNode( Collections.singletonMap( key, value ) );
        Transaction transaction = graph.beginTx();
        try
        {
            assertEquals( value, serialize( actions.getNodeProperty( nodeId, key ) ) );
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldBeAbleToGetPropertyOnNode() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldBeAbleToRemoveNodeProperties() throws Exception
    {
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put( "foo", "bar" );
        properties.put( "number", 15 );
        long nodeId = createNode( properties );
        actions.removeAllNodeProperties( nodeId );

        try ( Transaction tx = database.getGraph().beginTx() )
        {
            Node node = database.getGraph().getNodeById( nodeId );
            assertEquals( false, node.getPropertyKeys()
                    .iterator()
                    .hasNext() );
            tx.success();
        }
    }

    @Test
    public void shouldBeAbleToRemoveNodeProperties() throws Exception
    {
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put( "foo", "bar" );
        properties.put( "number", 15 );
        long nodeId = createNode( properties );
        actions.removeAllNodeProperties( nodeId );

        Transaction tx = database.getGraph().beginTx();
        try
        {
            Node node = database.getGraph().getNodeById( nodeId );
            assertEquals( false, node.getPropertyKeys()
                    .iterator()
                    .hasNext() );
            tx.success();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public shouldBeAbleToRemoveNodeProperties() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldStoreSuppliedPropertiesWhenCreatingRelationship() throws Exception
    {
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put( "string", "value" );
        properties.put( "integer", 17 );
        long relId = actions.createRelationship( graphdbHelper.createNode(), graphdbHelper.createNode(), "LOVES",
                properties )
                .getId();

        try ( Transaction tx = database.getGraph().beginTx() )
        {
            Relationship rel = database.getGraph().getRelationshipById( relId );
            for ( String key : rel.getPropertyKeys() )
            {
                assertTrue( "extra property stored", properties.containsKey( key ) );
            }
            for ( Map.Entry<String, Object> entry : properties.entrySet() )
            {
                assertEquals( entry.getValue(), rel.getProperty( entry.getKey() ) );
            }
        }
    }

    @Test
    public void shouldStoreSuppliedPropertiesWhenCreatingRelationship() throws Exception
    {
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put( "string", "value" );
        properties.put( "integer", 17 );
        long relId = actions.createRelationship( graphdbHelper.createNode(), graphdbHelper.createNode(), "LOVES",
                properties )
                .getId();

        Transaction tx = database.getGraph().beginTx();
        try
        {
            Relationship rel = database.getGraph().getRelationshipById( relId );
            for ( String key : rel.getPropertyKeys() )
            {
                assertTrue( "extra property stored", properties.containsKey( key ) );
            }
            for ( Map.Entry<String, Object> entry : properties.entrySet() )
            {
                assertEquals( entry.getValue(), rel.getProperty( entry.getKey() ) );
            }
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public shouldStoreSuppliedPropertiesWhenCreatingRelationship() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldBeAbleToRemoveNodeProperty() throws Exception
    {
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put( "foo", "bar" );
        properties.put( "number", 15 );
        long nodeId = createNode( properties );
        actions.removeNodeProperty( nodeId, "foo" );

        try ( Transaction tx = database.getGraph().beginTx() )
        {
            Node node = database.getGraph().getNodeById( nodeId );
            assertEquals( 15, node.getProperty( "number" ) );
            assertEquals( false, node.hasProperty( "foo" ) );
            tx.success();
        }
    }

    @Test
    public void shouldBeAbleToRemoveNodeProperty() throws Exception
    {
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put( "foo", "bar" );
        properties.put( "number", 15 );
        long nodeId = createNode( properties );
        actions.removeNodeProperty( nodeId, "foo" );

        Transaction tx = database.getGraph().beginTx();
        try
        {
            Node node = database.getGraph().getNodeById( nodeId );
            assertEquals( 15, node.getProperty( "number" ) );
            assertEquals( false, node.hasProperty( "foo" ) );
            tx.success();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public shouldBeAbleToRemoveNodeProperty() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldBeAbleToGetPropertiesOnRelationship() throws Exception
    {

        long relationshipId;
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put( "foo", "bar" );
        properties.put( "neo", "Thomas A. Anderson" );
        properties.put( "number", 15L );
        try ( Transaction tx = database.getGraph().beginTx() )
        {
            Node startNode = database.getGraph().createNode();
            Node endNode = database.getGraph().createNode();
            Relationship relationship = startNode.createRelationshipTo( endNode,
                    DynamicRelationshipType.withName( "knows" ) );
            for ( Map.Entry<String, Object> entry : properties.entrySet() )
            {
                relationship.setProperty( entry.getKey(), entry.getValue() );
            }
            relationshipId = relationship.getId();
            tx.success();
        }

        try ( Transaction transaction = graph.beginTx() )
        {
            assertEquals( properties, serialize( actions.getAllRelationshipProperties( relationshipId ) ) );
        }
    }

    @Test
    public void shouldBeAbleToGetPropertiesOnRelationship() throws Exception
    {

        long relationshipId;
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put( "foo", "bar" );
        properties.put( "neo", "Thomas A. Anderson" );
        properties.put( "number", 15L );
        Transaction tx = database.getGraph().beginTx();
        try
        {
            Node startNode = database.getGraph().createNode();
            Node endNode = database.getGraph().createNode();
            Relationship relationship = startNode.createRelationshipTo( endNode,
                    DynamicRelationshipType.withName( "knows" ) );
            for ( Map.Entry<String, Object> entry : properties.entrySet() )
            {
                relationship.setProperty( entry.getKey(), entry.getValue() );
            }
            relationshipId = relationship.getId();
            tx.success();
        }
        finally
        {
            tx.finish();
        }

        Transaction transaction = graph.beginTx();
        try
        {
            assertEquals( properties, serialize( actions.getAllRelationshipProperties( relationshipId ) ) );
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method public shouldBeAbleToGetPropertiesOnRelationship() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldBeAbleToRetrieveASinglePropertyFromARelationship() throws Exception
    {
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put( "foo", "bar" );
        properties.put( "neo", "Thomas A. Anderson" );
        properties.put( "number", 15L );

        long relationshipId = graphdbHelper.createRelationship( "LOVES" );
        graphdbHelper.setRelationshipProperties( relationshipId, properties );

        Object relationshipProperty;
        try ( Transaction transaction = graph.beginTx() )
        {
            relationshipProperty = serialize( actions.getRelationshipProperty( relationshipId, "foo" ) );
        }
        assertEquals( "bar", relationshipProperty );
    }

    @Test
    public void shouldBeAbleToRetrieveASinglePropertyFromARelationship() throws Exception
    {
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put( "foo", "bar" );
        properties.put( "neo", "Thomas A. Anderson" );
        properties.put( "number", 15L );

        long relationshipId = graphdbHelper.createRelationship( "LOVES" );
        graphdbHelper.setRelationshipProperties( relationshipId, properties );

        Transaction transaction = graph.beginTx();
        Object relationshipProperty;
        try
        {
            relationshipProperty = serialize( actions.getRelationshipProperty( relationshipId, "foo" ) );
        }
        finally
        {
            transaction.finish();
        }
        assertEquals( "bar", relationshipProperty );
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldBeAbleToRetrieveASinglePropertyFromARelationship() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldBeAbleToRetrieveRelationshipsFromNode() throws Exception
    {
        long nodeId = graphdbHelper.createNode();
        graphdbHelper.createRelationship( "LIKES", nodeId, graphdbHelper.createNode() );
        graphdbHelper.createRelationship( "LIKES", graphdbHelper.createNode(), nodeId );
        graphdbHelper.createRelationship( "HATES", nodeId, graphdbHelper.createNode() );

        try ( Transaction transaction = graph.beginTx() )
        {
            verifyRelReps( 3,
                    actions.getNodeRelationships( nodeId, RelationshipDirection.all,
                            Collections.<String>emptyList() ) );
            verifyRelReps( 1,
                    actions.getNodeRelationships( nodeId, RelationshipDirection.in, Collections.<String>emptyList() ) );
            verifyRelReps( 2,
                    actions.getNodeRelationships( nodeId, RelationshipDirection.out,
                            Collections.<String>emptyList() ) );

            verifyRelReps( 3,
                    actions.getNodeRelationships( nodeId, RelationshipDirection.all, Arrays.asList( "LIKES",
                            "HATES" ) ) );
            verifyRelReps( 1,
                    actions.getNodeRelationships( nodeId, RelationshipDirection.in, Arrays.asList( "LIKES",
                            "HATES" ) ) );
            verifyRelReps( 2,
                    actions.getNodeRelationships( nodeId, RelationshipDirection.out, Arrays.asList( "LIKES",
                            "HATES" ) ) );

            verifyRelReps( 2, actions.getNodeRelationships( nodeId, RelationshipDirection.all,
                    Arrays.asList( "LIKES" ) ) );
            verifyRelReps( 1, actions.getNodeRelationships( nodeId, RelationshipDirection.in,
                    Arrays.asList( "LIKES" ) ) );
            verifyRelReps( 1, actions.getNodeRelationships( nodeId, RelationshipDirection.out,
                    Arrays.asList( "LIKES" ) ) );

            verifyRelReps( 1, actions.getNodeRelationships( nodeId, RelationshipDirection.all,
                    Arrays.asList( "HATES" ) ) );
            verifyRelReps( 0, actions.getNodeRelationships( nodeId, RelationshipDirection.in,
                    Arrays.asList( "HATES" ) ) );
            verifyRelReps( 1, actions.getNodeRelationships( nodeId, RelationshipDirection.out,
                    Arrays.asList( "HATES" ) ) );
        }
    }

    @Test
    public void shouldBeAbleToRetrieveRelationshipsFromNode() throws Exception
    {
        long nodeId = graphdbHelper.createNode();
        graphdbHelper.createRelationship( "LIKES", nodeId, graphdbHelper.createNode() );
        graphdbHelper.createRelationship( "LIKES", graphdbHelper.createNode(), nodeId );
        graphdbHelper.createRelationship( "HATES", nodeId, graphdbHelper.createNode() );

        Transaction transaction = graph.beginTx();
        try
        {
            verifyRelReps( 3,
                    actions.getNodeRelationships( nodeId, RelationshipDirection.all,
                            Collections.<String>emptyList() ) );
            verifyRelReps( 1,
                    actions.getNodeRelationships( nodeId, RelationshipDirection.in, Collections.<String>emptyList() ) );
            verifyRelReps( 2,
                    actions.getNodeRelationships( nodeId, RelationshipDirection.out,
                            Collections.<String>emptyList() ) );

            verifyRelReps( 3,
                    actions.getNodeRelationships( nodeId, RelationshipDirection.all, Arrays.asList( "LIKES",
                            "HATES" ) ) );
            verifyRelReps( 1,
                    actions.getNodeRelationships( nodeId, RelationshipDirection.in, Arrays.asList( "LIKES",
                            "HATES" ) ) );
            verifyRelReps( 2,
                    actions.getNodeRelationships( nodeId, RelationshipDirection.out, Arrays.asList( "LIKES",
                            "HATES" ) ) );

            verifyRelReps( 2, actions.getNodeRelationships( nodeId, RelationshipDirection.all,
                    Arrays.asList( "LIKES" ) ) );
            verifyRelReps( 1, actions.getNodeRelationships( nodeId, RelationshipDirection.in,
                    Arrays.asList( "LIKES" ) ) );
            verifyRelReps( 1, actions.getNodeRelationships( nodeId, RelationshipDirection.out,
                    Arrays.asList( "LIKES" ) ) );

            verifyRelReps( 1, actions.getNodeRelationships( nodeId, RelationshipDirection.all,
                    Arrays.asList( "HATES" ) ) );
            verifyRelReps( 0, actions.getNodeRelationships( nodeId, RelationshipDirection.in,
                    Arrays.asList( "HATES" ) ) );
            verifyRelReps( 1, actions.getNodeRelationships( nodeId, RelationshipDirection.out,
                    Arrays.asList( "HATES" ) ) );
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldBeAbleToRetrieveRelationshipsFromNode() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldNotGetAnyRelationshipsWhenRetrievingFromNodeWithoutRelationships() throws Exception
    {
        long nodeId = graphdbHelper.createNode();

        try ( Transaction transaction = graph.beginTx() )
        {
            verifyRelReps( 0,
                    actions.getNodeRelationships( nodeId, RelationshipDirection.all,
                            Collections.<String>emptyList() ) );
            verifyRelReps( 0,
                    actions.getNodeRelationships( nodeId, RelationshipDirection.in,
                            Collections.<String>emptyList() ) );
            verifyRelReps( 0,
                    actions.getNodeRelationships( nodeId, RelationshipDirection.out,
                            Collections.<String>emptyList() ) );
        }
    }

    @Test
    public void shouldNotGetAnyRelationshipsWhenRetrievingFromNodeWithoutRelationships() throws Exception
    {
        long nodeId = graphdbHelper.createNode();

        Transaction transaction = graph.beginTx();
        try
        {
            verifyRelReps( 0,
                    actions.getNodeRelationships( nodeId, RelationshipDirection.all,
                            Collections.<String>emptyList() ) );
            verifyRelReps( 0,
                    actions.getNodeRelationships( nodeId, RelationshipDirection.in,
                            Collections.<String>emptyList() ) );
            verifyRelReps( 0,
                    actions.getNodeRelationships( nodeId, RelationshipDirection.out,
                            Collections.<String>emptyList() ) );
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldNotGetAnyRelationshipsWhenRetrievingFromNodeWithoutRelationships() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldBeAbleToIndexNode()
    {
        String key = "mykey";
        String value = "myvalue";
        long nodeId = graphdbHelper.createNode();
        String indexName = "node";

        actions.createNodeIndex( MapUtil.map( "name", indexName ) );

        List<Object> listOfIndexedNodes;
        try ( Transaction transaction = graph.beginTx() )
        {
            listOfIndexedNodes = serialize( actions.getIndexedNodes( indexName, key, value ) );
        }
        assertFalse( listOfIndexedNodes.iterator().hasNext() );
        actions.addToNodeIndex( indexName, key, value, nodeId );
        assertEquals( Arrays.asList( nodeId ), graphdbHelper.getIndexedNodes( indexName, key, value ) );
    }

    @Test
    public void shouldBeAbleToIndexNode()
    {
        String key = "mykey";
        String value = "myvalue";
        long nodeId = graphdbHelper.createNode();
        String indexName = "node";

        actions.createNodeIndex( MapUtil.map( "name", indexName ) );

        Transaction transaction = graph.beginTx();
        List<Object> listOfIndexedNodes;
        try
        {
            listOfIndexedNodes = serialize( actions.getIndexedNodes( indexName, key, value ) );
        }
        finally
        {
            transaction.finish();
        }
        assertFalse( listOfIndexedNodes.iterator().hasNext() );
        actions.addToNodeIndex( indexName, key, value, nodeId );
        assertEquals( Arrays.asList( nodeId ), graphdbHelper.getIndexedNodes( indexName, key, value ) );
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldBeAbleToIndexNode() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldBeAbleToFulltextIndex()
    {
        String key = "key";
        String value = "the value with spaces";
        long nodeId = graphdbHelper.createNode();
        String indexName = "fulltext-node";
        graphdbHelper.createNodeFullTextIndex( indexName );
        try ( Transaction transaction = graph.beginTx() )
        {
            assertFalse( serialize( actions.getIndexedNodes( indexName, key, value ) ).iterator()
                    .hasNext() );
        }
        actions.addToNodeIndex( indexName, key, value, nodeId );
        assertEquals( Arrays.asList( nodeId ), graphdbHelper.getIndexedNodes( indexName, key, value ) );
        assertEquals( Arrays.asList( nodeId ), graphdbHelper.getIndexedNodes( indexName, key,
                "the value with spaces" ) );
        assertEquals( Arrays.asList( nodeId ), graphdbHelper.queryIndexedNodes( indexName, key, "the" ) );
        assertEquals( Arrays.asList( nodeId ), graphdbHelper.queryIndexedNodes( indexName, key, "value" ) );
        assertEquals( Arrays.asList( nodeId ), graphdbHelper.queryIndexedNodes( indexName, key, "with" ) );
        assertEquals( Arrays.asList( nodeId ), graphdbHelper.queryIndexedNodes( indexName, key, "spaces" ) );
        assertEquals( Arrays.asList( nodeId ), graphdbHelper.queryIndexedNodes( indexName, key, "*spaces*" ) );
        assertTrue( graphdbHelper.getIndexedNodes( indexName, key, "nohit" ).isEmpty() );
    }

    @Test
    public void shouldBeAbleToFulltextIndex()
    {
        String key = "key";
        String value = "the value with spaces";
        long nodeId = graphdbHelper.createNode();
        String indexName = "fulltext-node";
        graphdbHelper.createNodeFullTextIndex( indexName );
        Transaction transaction = graph.beginTx();
        try
        {
            assertFalse( serialize( actions.getIndexedNodes( indexName, key, value ) ).iterator()
                    .hasNext() );
        }
        finally
        {
            transaction.finish();
        }
        actions.addToNodeIndex( indexName, key, value, nodeId );
        assertEquals( Arrays.asList( nodeId ), graphdbHelper.getIndexedNodes( indexName, key, value ) );
        assertEquals( Arrays.asList( nodeId ), graphdbHelper.getIndexedNodes( indexName, key,
                "the value with spaces" ) );
        assertEquals( Arrays.asList( nodeId ), graphdbHelper.queryIndexedNodes( indexName, key, "the" ) );
        assertEquals( Arrays.asList( nodeId ), graphdbHelper.queryIndexedNodes( indexName, key, "value" ) );
        assertEquals( Arrays.asList( nodeId ), graphdbHelper.queryIndexedNodes( indexName, key, "with" ) );
        assertEquals( Arrays.asList( nodeId ), graphdbHelper.queryIndexedNodes( indexName, key, "spaces" ) );
        assertEquals( Arrays.asList( nodeId ), graphdbHelper.queryIndexedNodes( indexName, key, "*spaces*" ) );
        assertTrue( graphdbHelper.getIndexedNodes( indexName, key, "nohit" ).isEmpty() );
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldBeAbleToFulltextIndex() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldGetExtendedNodeRepresentationsWhenGettingFromIndex()
    {
        String key = "mykey3";
        String value = "value";

        long nodeId = graphdbHelper.createNode( LABEL );
        String indexName = "node";
        graphdbHelper.addNodeToIndex( indexName, key, value, nodeId );
        int counter = 0;

        List<Object> indexedNodes;
        try ( Transaction transaction = graph.beginTx() )
        {
            indexedNodes = serialize( actions.getIndexedNodes( indexName, key, value ) );
        }

        for ( Object indexedNode : indexedNodes )
        {
            @SuppressWarnings("unchecked")
            Map<String, Object> serialized = (Map<String, Object>) indexedNode;
            NodeRepresentationTest.verifySerialisation( serialized );
            assertNotNull( serialized.get( "indexed" ) );
            counter++;
        }
        assertEquals( 1, counter );
    }

    @Test
    public void shouldGetExtendedNodeRepresentationsWhenGettingFromIndex()
    {
        String key = "mykey3";
        String value = "value";

        long nodeId = graphdbHelper.createNode( LABEL );
        String indexName = "node";
        graphdbHelper.addNodeToIndex( indexName, key, value, nodeId );
        int counter = 0;

        Transaction transaction = graph.beginTx();
        List<Object> indexedNodes;
        try
        {
            indexedNodes = serialize( actions.getIndexedNodes( indexName, key, value ) );
        }
        finally
        {
            transaction.finish();
        }

        for ( Object indexedNode : indexedNodes )
        {
            @SuppressWarnings("unchecked")
            Map<String, Object> serialized = (Map<String, Object>) indexedNode;
            NodeRepresentationTest.verifySerialisation( serialized );
            assertNotNull( serialized.get( "indexed" ) );
            counter++;
        }
        assertEquals( 1, counter );
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldGetExtendedNodeRepresentationsWhenGettingFromIndex() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldBeAbleToTraverseWithDefaultParameters()
    {
        long startNode = createBasicTraversableGraph();

        try ( Transaction transaction = graph.beginTx() )
        {
            assertEquals( 2, serialize( actions.traverse( startNode, new HashMap<String, Object>(),
                    TraverserReturnType.node ) ).size() );
        }
    }

    @Test
    public void shouldBeAbleToTraverseWithDefaultParameters()
    {
        long startNode = createBasicTraversableGraph();

        Transaction transaction = graph.beginTx();
        try
        {
            assertEquals( 2, serialize( actions.traverse( startNode, new HashMap<String, Object>(),
                    TraverserReturnType.node ) ).size() );
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldBeAbleToTraverseWithDefaultParameters() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldBeAbleToTraverseDepthTwo()
    {
        long startNode = createBasicTraversableGraph();

        try ( Transaction transaction = graph.beginTx() )
        {
            assertEquals( 3, serialize( actions.traverse( startNode, MapUtil.map( "max_depth", 2 ),
                    TraverserReturnType.node ) ).size() );
        }
    }

    @Test
    public void shouldBeAbleToTraverseDepthTwo()
    {
        long startNode = createBasicTraversableGraph();

        Transaction transaction = graph.beginTx();
        try
        {
            assertEquals( 3, serialize( actions.traverse( startNode, MapUtil.map( "max_depth", 2 ),
                    TraverserReturnType.node ) ).size() );
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldBeAbleToTraverseDepthTwo() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldBeAbleToTraverseEverything()
    {
        long startNode = createBasicTraversableGraph();

        try ( Transaction transaction = graph.beginTx() )
        {
            assertEquals( 6, serialize( actions.traverse(
                    startNode,
                    MapUtil.map( "return_filter", MapUtil.map( "language", "javascript", "body", "true;" ), "max_depth",
                            10 ),
                    TraverserReturnType.node ) ).size() );
            assertEquals( 6, serialize( actions.traverse( startNode,
                    MapUtil.map( "return_filter", MapUtil.map( "language", "builtin", "name", "all" ), "max_depth",
                            10 ),
                    TraverserReturnType.node ) ).size() );
        }
    }

    @Test
    public void shouldBeAbleToTraverseEverything()
    {
        long startNode = createBasicTraversableGraph();

        Transaction transaction = graph.beginTx();
        try
        {
            assertEquals( 6, serialize( actions.traverse(
                    startNode,
                    MapUtil.map( "return_filter", MapUtil.map( "language", "javascript", "body", "true;" ), "max_depth",
                            10 ),
                    TraverserReturnType.node ) ).size() );
            assertEquals( 6, serialize( actions.traverse( startNode,
                    MapUtil.map( "return_filter", MapUtil.map( "language", "builtin", "name", "all" ), "max_depth",
                            10 ),
                    TraverserReturnType.node ) ).size() );
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldBeAbleToTraverseEverything() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldBeAbleToUseCustomReturnFilter()
    {
        long startNode = createBasicTraversableGraph();

        try ( Transaction transaction = graph.beginTx() )
        {
            assertEquals( 3, serialize( actions.traverse( startNode, MapUtil.map( "prune_evaluator", MapUtil.map(
                    "language", "builtin", "name", "none" ), "return_filter", MapUtil.map( "language", "javascript",
                    "body", "position.endNode().getProperty( 'name' ).contains( 'o' )" ) ), TraverserReturnType.node ) )
                    .size() );
        }
    }

    @Test
    public void shouldBeAbleToUseCustomReturnFilter()
    {
        long startNode = createBasicTraversableGraph();

        Transaction transaction = graph.beginTx();
        try
        {
            assertEquals( 3, serialize( actions.traverse( startNode, MapUtil.map( "prune_evaluator", MapUtil.map(
                    "language", "builtin", "name", "none" ), "return_filter", MapUtil.map( "language", "javascript",
                    "body", "position.endNode().getProperty( 'name' ).contains( 'o' )" ) ), TraverserReturnType.node ) )
                    .size() );
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldBeAbleToUseCustomReturnFilter() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldBeAbleToTraverseWithMaxDepthAndPruneEvaluatorCombined()
    {
        long startNode = createBasicTraversableGraph();

        try ( Transaction transaction = graph.beginTx() )
        {
            assertEquals( 3, serialize( actions.traverse( startNode,
                    MapUtil.map( "max_depth", 2, "prune_evaluator", MapUtil.map( "language", "javascript", "body",
                            "position.endNode().getProperty('name').equals('Emil')" ) ),
                    TraverserReturnType.node ) ).size() );
            assertEquals( 2, serialize( actions.traverse( startNode,
                    MapUtil.map( "max_depth", 1, "prune_evaluator", MapUtil.map( "language", "javascript", "body",
                            "position.endNode().getProperty('name').equals('Emil')" ) ), TraverserReturnType.node ) )
                    .size() );
        }
    }

    @Test
    public void shouldBeAbleToTraverseWithMaxDepthAndPruneEvaluatorCombined()
    {
        long startNode = createBasicTraversableGraph();

        Transaction transaction = graph.beginTx();
        try
        {
            assertEquals( 3, serialize( actions.traverse( startNode,
                    MapUtil.map( "max_depth", 2, "prune_evaluator", MapUtil.map( "language", "javascript", "body",
                            "position.endNode().getProperty('name').equals('Emil')" ) ),
                    TraverserReturnType.node ) ).size() );
            assertEquals( 2, serialize( actions.traverse( startNode,
                    MapUtil.map( "max_depth", 1, "prune_evaluator", MapUtil.map( "language", "javascript", "body",
                            "position.endNode().getProperty('name').equals('Emil')" ) ), TraverserReturnType.node ) )
                    .size() );
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldBeAbleToTraverseWithMaxDepthAndPruneEvaluatorCombined() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldBeAbleToGetRelationshipsIfSpecified()
    {
        long startNode = createBasicTraversableGraph();

        List<Object> hits;
        try ( Transaction transaction = graph.beginTx() )
        {
            hits = serialize( actions.traverse( startNode, new HashMap<String, Object>(),
                    TraverserReturnType.relationship ) );
        }

        for ( Object hit : hits )
        {
            @SuppressWarnings("unchecked")
            Map<String, Object> map = (Map<String, Object>) hit;
            RelationshipRepresentationTest.verifySerialisation( map );
        }
    }

    @Test
    public void shouldBeAbleToGetRelationshipsIfSpecified()
    {
        long startNode = createBasicTraversableGraph();

        Transaction transaction = graph.beginTx();
        List<Object> hits;
        try
        {
            hits = serialize( actions.traverse( startNode, new HashMap<String, Object>(),
                    TraverserReturnType.relationship ) );
        }
        finally
        {
            transaction.finish();
        }

        for ( Object hit : hits )
        {
            @SuppressWarnings("unchecked")
            Map<String, Object> map = (Map<String, Object>) hit;
            RelationshipRepresentationTest.verifySerialisation( map );
        }
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldBeAbleToGetRelationshipsIfSpecified() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldBeAbleToGetPathsIfSpecified()
    {
        long startNode = createBasicTraversableGraph();

        List<Object> hits;
        try ( Transaction transaction = graph.beginTx() )
        {
            hits = serialize( actions.traverse( startNode, new HashMap<String, Object>(),
                    TraverserReturnType.path ) );
        }

        for ( Object hit : hits )
        {
            @SuppressWarnings("unchecked")
            Map<String, Object> map = (Map<String, Object>) hit;
            assertThat( map, hasKey( "start" ) );
            assertThat( map, hasKey( "end" ) );
            assertThat( map, hasKey( "length" ) );
        }
    }

    @Test
    public void shouldBeAbleToGetPathsIfSpecified()
    {
        long startNode = createBasicTraversableGraph();

        Transaction transaction = graph.beginTx();
        List<Object> hits;
        try
        {
            hits = serialize( actions.traverse( startNode, new HashMap<String, Object>(),
                    TraverserReturnType.path ) );
        }
        finally
        {
            transaction.finish();
        }

        for ( Object hit : hits )
        {
            @SuppressWarnings("unchecked")
            Map<String, Object> map = (Map<String, Object>) hit;
            assertThat( map, hasKey( "start" ) );
            assertThat( map, hasKey( "end" ) );
            assertThat( map, hasKey( "length" ) );
        }
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldBeAbleToGetPathsIfSpecified() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldBeAbleToGetFullPathsIfSpecified()
    {
        long startNode = createBasicTraversableGraph();

        List<Object> hits;
        try ( Transaction transaction = graph.beginTx() )
        {
            hits = serialize( actions.traverse( startNode, new HashMap<String, Object>(),
                    TraverserReturnType.fullpath ) );
        }

        for ( Object hit : hits )
        {
            @SuppressWarnings("unchecked")
            Map<String, Object> map = (Map<String, Object>) hit;
            @SuppressWarnings("unchecked")
            Collection<Object> relationships = (Collection<Object>) map.get( "relationships" );
            for ( Object rel : relationships )
            {
                @SuppressWarnings("unchecked")
                Map<String, Object> relationship = (Map<String, Object>) rel;
                RelationshipRepresentationTest.verifySerialisation( relationship );
            }
            @SuppressWarnings("unchecked")
            Collection<Object> nodes = (Collection<Object>) map.get( "nodes" );
            for ( Object n : nodes )
            {
                @SuppressWarnings("unchecked")
                Map<String, Object> node = (Map<String, Object>) n;
                NodeRepresentationTest.verifySerialisation( node );
            }
            assertThat( map, hasKey( "start" ) );
            assertThat( map, hasKey( "end" ) );
            assertThat( map, hasKey( "length" ) );
        }
    }

    @Test
    public void shouldBeAbleToGetFullPathsIfSpecified()
    {
        long startNode = createBasicTraversableGraph();
        Transaction transaction = graph.beginTx();
        List<Object> hits;
        try
        {
            hits = serialize( actions.traverse( startNode, new HashMap<String, Object>(),
                    TraverserReturnType.fullpath ) );
        }
        finally
        {
            transaction.finish();
        }

        for ( Object hit : hits )
        {
            @SuppressWarnings("unchecked")
            Map<String, Object> map = (Map<String, Object>) hit;
            @SuppressWarnings("unchecked")
            Collection<Object> relationships = (Collection<Object>) map.get( "relationships" );
            for ( Object rel : relationships )
            {
                @SuppressWarnings("unchecked")
                Map<String, Object> relationship = (Map<String, Object>) rel;
                RelationshipRepresentationTest.verifySerialisation( relationship );
            }
            @SuppressWarnings("unchecked")
            Collection<Object> nodes = (Collection<Object>) map.get( "nodes" );
            for ( Object n : nodes )
            {
                @SuppressWarnings("unchecked")
                Map<String, Object> node = (Map<String, Object>) n;
                NodeRepresentationTest.verifySerialisation( node );
            }
            assertThat( map, hasKey( "start" ) );
            assertThat( map, hasKey( "end" ) );
            assertThat( map, hasKey( "length" ) );
        }
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldBeAbleToGetFullPathsIfSpecified() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldBeAbleToGetShortestPaths() throws Exception
    {
        long[] nodes = createMoreComplexGraph();

        // /paths
        try ( Transaction transaction = graph.beginTx() )
        {
            List<Object> result = serialize( actions.findPaths(
                    nodes[0],
                    nodes[1],
                    MapUtil.map( "max_depth", 2, "algorithm", "shortestPath", "relationships",
                            MapUtil.map( "type", "to", "direction", "out" ) ) ) );
            assertPaths( 2, nodes, 2, result );
            // /path
            Map<String, Object> path = serialize( actions.findSinglePath(
                    nodes[0],
                    nodes[1],
                    MapUtil.map( "max_depth", 2, "algorithm", "shortestPath", "relationships",
                            MapUtil.map( "type", "to", "direction", "out" ) ) ) );
            assertPaths( 1, nodes, 2, Arrays.<Object>asList( path ) );

            // /path {single: false} (has no effect)
            path = serialize( actions.findSinglePath(
                    nodes[0],
                    nodes[1],
                    MapUtil.map( "max_depth", 2, "algorithm", "shortestPath", "relationships",
                            MapUtil.map( "type", "to", "direction", "out" ), "single", false ) ) );
            assertPaths( 1, nodes, 2, Arrays.<Object>asList( path ) );
        }
    }

    @Test
    public void shouldBeAbleToGetShortestPaths() throws Exception
    {
        long[] nodes = createMoreComplexGraph();

        // /paths
        Transaction transaction = graph.beginTx();
        try
        {
            List<Object> result = serialize( actions.findPaths(
                    nodes[0],
                    nodes[1],
                    MapUtil.map( "max_depth", 2, "algorithm", "shortestPath", "relationships",
                            MapUtil.map( "type", "to", "direction", "out" ) ) ) );
            assertPaths( 2, nodes, 2, result );
            // /path
            Map<String, Object> path = serialize( actions.findSinglePath(
                    nodes[0],
                    nodes[1],
                    MapUtil.map( "max_depth", 2, "algorithm", "shortestPath", "relationships",
                            MapUtil.map( "type", "to", "direction", "out" ) ) ) );
            assertPaths( 1, nodes, 2, Arrays.<Object>asList( path ) );

            // /path {single: false} (has no effect)
            path = serialize( actions.findSinglePath(
                    nodes[0],
                    nodes[1],
                    MapUtil.map( "max_depth", 2, "algorithm", "shortestPath", "relationships",
                            MapUtil.map( "type", "to", "direction", "out" ), "single", false ) ) );
            assertPaths( 1, nodes, 2, Arrays.<Object>asList( path ) );
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldBeAbleToGetShortestPaths() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldBeAbleToGetPathsUsingDijkstra() throws Exception
    {
        long[] nodes = createDijkstraGraph( true );

        try ( Transaction transaction = graph.beginTx() )
        {
            // /paths
            assertPaths( 1, nodes, 6, serialize( actions.findPaths(
                    nodes[0],
                    nodes[1],
                    map( "algorithm", "dijkstra", "cost_property", "cost", "relationships",
                            map( "type", "to", "direction", "out" ) ) ) ) );

            // /path
            Map<String, Object> path = serialize( actions.findSinglePath(
                    nodes[0],
                    nodes[1],
                    map( "algorithm", "dijkstra", "cost_property", "cost", "relationships",
                            map( "type", "to", "direction", "out" ) ) ) );
            assertPaths( 1, nodes, 6, Arrays.<Object>asList( path ) );
            assertEquals( 6.0d, path.get( "weight" ) );
        }
    }

    @Test
    public void shouldBeAbleToGetPathsUsingDijkstra() throws Exception
    {
        long[] nodes = createDijkstraGraph( true );

        Transaction transaction = graph.beginTx();
        try
        {
            // /paths
            assertPaths( 1, nodes, 6, serialize( actions.findPaths(
                    nodes[0],
                    nodes[1],
                    map( "algorithm", "dijkstra", "cost_property", "cost", "relationships",
                            map( "type", "to", "direction", "out" ) ) ) ) );

            // /path
            Map<String, Object> path = serialize( actions.findSinglePath(
                    nodes[0],
                    nodes[1],
                    map( "algorithm", "dijkstra", "cost_property", "cost", "relationships",
                            map( "type", "to", "direction", "out" ) ) ) );
            assertPaths( 1, nodes, 6, Arrays.<Object>asList( path ) );
            assertEquals( 6.0d, path.get( "weight" ) );
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldBeAbleToGetPathsUsingDijkstra() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldBeAbleToGetPathsUsingDijkstraWithDefaults() throws Exception
    {
        long[] nodes = createDijkstraGraph( false );

        // /paths
        try ( Transaction transaction = graph.beginTx() )
        {
            List<Object> result = serialize( actions.findPaths(
                    nodes[0],
                    nodes[1],
                    map( "algorithm", "dijkstra", "cost_property", "cost", "default_cost", 1, "relationships",
                            map( "type", "to", "direction", "out" ) ) ) );
            assertPaths( 1, nodes, 6, result );

            // /path
            Map<String, Object> path = serialize( actions.findSinglePath(
                    nodes[0],
                    nodes[1],
                    map( "algorithm", "dijkstra", "cost_property", "cost", "default_cost", 1, "relationships",
                            map( "type", "to", "direction", "out" ) ) ) );
            assertPaths( 1, nodes, 6, Arrays.<Object>asList( path ) );
            assertEquals( 6.0d, path.get( "weight" ) );
        }
    }

    @Test
    public void shouldBeAbleToGetPathsUsingDijkstraWithDefaults() throws Exception
    {
        long[] nodes = createDijkstraGraph( false );

        // /paths
        Transaction transaction = graph.beginTx();
        try
        {
            List<Object> result = serialize( actions.findPaths(
                    nodes[0],
                    nodes[1],
                    map( "algorithm", "dijkstra", "cost_property", "cost", "default_cost", 1, "relationships",
                            map( "type", "to", "direction", "out" ) ) ) );
            assertPaths( 1, nodes, 6, result );

            // /path
            Map<String, Object> path = serialize( actions.findSinglePath(
                    nodes[0],
                    nodes[1],
                    map( "algorithm", "dijkstra", "cost_property", "cost", "default_cost", 1, "relationships",
                            map( "type", "to", "direction", "out" ) ) ) );
            assertPaths( 1, nodes, 6, Arrays.<Object>asList( path ) );
            assertEquals( 6.0d, path.get( "weight" ) );
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldBeAbleToGetPathsUsingDijkstraWithDefaults() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldAddLabelToNode() throws Exception
    {
        // GIVEN
        long node = actions.createNode( null ).getId();
        Collection<String> labels = new ArrayList<String>();
        String labelName = "Wonk";
        labels.add( labelName );

        // WHEN
        actions.addLabelToNode( node, labels );

        // THEN
        try ( Transaction transaction = graph.beginTx() )
        {
            Iterable<String> result = graphdbHelper.getNodeLabels( node );
            assertEquals( labelName, single( result ) );
        }
    }

    @Test
    public void shouldAddLabelToNode() throws Exception
    {
        // GIVEN
        long node = actions.createNode( null ).getId();
        Collection<String> labels = new ArrayList<String>();
        String labelName = "Wonk";
        labels.add( labelName );

        // WHEN
        actions.addLabelToNode( node, labels );

        // THEN
        Transaction transaction = graph.beginTx();
        try
        {
            Iterable<String> result = graphdbHelper.getNodeLabels( node );
            assertEquals( labelName, single( result ) );
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldAddLabelToNode() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldListExistingLabelsOnNode() throws Exception
    {
        // GIVEN
        long node = graphdbHelper.createNode();
        String labelName1 = "LabelOne", labelName2 = "labelTwo";
        graphdbHelper.addLabelToNode( node, labelName1 );
        graphdbHelper.addLabelToNode( node, labelName2 );

        // WHEN

        List<String> labels;
        try ( Transaction transaction = graph.beginTx() )
        {
            labels = (List) serialize( actions.getNodeLabels( node ) );
        }

        // THEN
        assertEquals(
                asSet( labelName1, labelName2 ),
                asSet( labels ) );
    }

    @Test
    public void shouldListExistingLabelsOnNode() throws Exception
    {
        // GIVEN
        long node = graphdbHelper.createNode();
        String labelName1 = "LabelOne", labelName2 = "labelTwo";
        graphdbHelper.addLabelToNode( node, labelName1 );
        graphdbHelper.addLabelToNode( node, labelName2 );

        // WHEN

        Transaction transaction = graph.beginTx();
        List<String> labels;
        try
        {
            labels = (List) serialize( actions.getNodeLabels( node ) );
        }
        finally
        {
            transaction.finish();
        }

        // THEN
        assertEquals(
                asSet( labelName1, labelName2 ),
                asSet( labels ) );
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldListExistingLabelsOnNode() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void getNodesWithLabel() throws Exception
    {
        // GIVEN
        String label1 = "first", label2 = "second";
        long node1 = graphdbHelper.createNode( label( label1 ) );
        long node2 = graphdbHelper.createNode( label( label1 ), label( label2 ) );
        graphdbHelper.createNode( label( label2 ) );

        // WHEN
        List<Object> representation;
        try ( Transaction transaction = graph.beginTx() )
        {
            representation = serialize( actions.getNodesWithLabel( label1, map() ) );
        }

        // THEN
        assertEquals( asSet( node1, node2 ), asSet( Iterables.map( new Function<Object, Long>()
        {
            @Override
            public Long apply( Object from )
            {
                Map<?, ?> nodeMap = (Map<?, ?>) from;
                return nodeUriToId( (String) nodeMap.get( "self" ) );
            }
        }, representation ) ) );
    }

    @Test
    public void getNodesWithLabel() throws Exception
    {
        // GIVEN
        String label1 = "first", label2 = "second";
        long node1 = graphdbHelper.createNode( label( label1 ) );
        long node2 = graphdbHelper.createNode( label( label1 ), label( label2 ) );
        graphdbHelper.createNode( label( label2 ) );

        // WHEN
        Transaction transaction = graph.beginTx();
        List<Object> representation;
        try
        {
            representation = serialize( actions.getNodesWithLabel( label1, map() ) );
        }
        finally
        {
            transaction.finish();
        }
        // THEN
        assertEquals( asSet( node1, node2 ), asSet( Iterables.map( new Function<Object, Long>()
        {
            @Override
            public Long apply( Object from )
            {
                Map<?, ?> nodeMap = (Map<?, ?>) from;
                return nodeUriToId( (String) nodeMap.get( "self" ) );
            }
        }, representation ) ) );
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public getNodesWithLabel() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldCreateSchemaIndex() throws Exception
    {
        // GIVEN
        String labelName = "person", propertyKey = "name";

        // WHEN
        actions.createSchemaIndex( labelName, Arrays.asList( propertyKey ) );

        // THEN
        try ( Transaction transaction = graph.beginTx() )
        {
            Iterable<IndexDefinition> defs = graphdbHelper.getSchemaIndexes( labelName );
            assertEquals( 1, count( defs ) );
            assertEquals( propertyKey, first( first( defs ).getPropertyKeys() ) );
        }
    }

    @Test
    public void shouldCreateSchemaIndex() throws Exception
    {
        // GIVEN
        String labelName = "person", propertyKey = "name";

        // WHEN
        actions.createSchemaIndex( labelName, Arrays.asList( propertyKey ) );

        // THEN
        Transaction transaction = graph.beginTx();
        try
        {
            Iterable<IndexDefinition> defs = graphdbHelper.getSchemaIndexes( labelName );
            assertEquals( 1, count( defs ) );
            assertEquals( propertyKey, first( first( defs ).getPropertyKeys() ) );
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldCreateSchemaIndex() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldDropSchemaIndex() throws Exception
    {
        // GIVEN
        String labelName = "user", propertyKey = "login";
        IndexDefinition index = graphdbHelper.createSchemaIndex( labelName, propertyKey );

        // WHEN
        actions.dropSchemaIndex( labelName, propertyKey );

        // THEN
        try ( Transaction transaction = graph.beginTx() )
        {
            assertFalse( "Index should have been dropped", asSet( graphdbHelper.getSchemaIndexes( labelName ) )
                    .contains( index ) );
        }
    }

    @Test
    public void shouldDropSchemaIndex() throws Exception
    {
        // GIVEN
        String labelName = "user", propertyKey = "login";
        IndexDefinition index = graphdbHelper.createSchemaIndex( labelName, propertyKey );

        // WHEN
        actions.dropSchemaIndex( labelName, propertyKey );

        // THEN
        Transaction transaction = graph.beginTx();
        try
        {
            assertFalse( "Index should have been dropped", asSet( graphdbHelper.getSchemaIndexes( labelName ) )
                    .contains( index ) );
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldDropSchemaIndex() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldGetSchemaIndexes() throws Exception
    {
        // GIVEN
        String labelName = "mylabel", propertyKey = "name";
        graphdbHelper.createSchemaIndex( labelName, propertyKey );

        // WHEN
        List<Object> serialized;
        try ( Transaction transaction = graph.beginTx() )
        {
            serialized = serialize( actions.getSchemaIndexes( labelName ) );
        }

        // THEN
        assertEquals( 1, serialized.size() );
        Map<?, ?> definition = (Map<?, ?>) serialized.get( 0 );
        assertEquals( labelName, definition.get( "label" ) );
        assertEquals( asList( propertyKey ), definition.get( "property_keys" ) );
    }

    @Test
    public void shouldGetSchemaIndexes() throws Exception
    {
        // GIVEN
        String labelName = "mylabel", propertyKey = "name";
        graphdbHelper.createSchemaIndex( labelName, propertyKey );

        // WHEN
        Transaction transaction = graph.beginTx();
        List<Object> serialized;
        try
        {
            serialized = serialize( actions.getSchemaIndexes( labelName ) );
        }
        finally
        {
            transaction.finish();
        }

        // THEN
        assertEquals( 1, serialized.size() );
        Map<?, ?> definition = (Map<?, ?>) serialized.get( 0 );
        assertEquals( labelName, definition.get( "label" ) );
        assertEquals( asList( propertyKey ), definition.get( "property_keys" ) );
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldGetSchemaIndexes() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldCreatePropertyUniquenessConstraint() throws Exception
    {
        // GIVEN
        String labelName = "person", propertyKey = "name";

        // WHEN
        actions.createPropertyUniquenessConstraint( labelName, asList( propertyKey ) );

        // THEN
        try ( Transaction tx = graph.beginTx() )
        {
            Iterable<ConstraintDefinition> defs = graphdbHelper.getPropertyUniquenessConstraints( labelName, propertyKey );
            assertEquals( asSet( propertyKey ), asSet( single( defs ).getPropertyKeys() ) );
            tx.success();
        }
    }

    @Test
    public void shouldCreatePropertyUniquenessConstraint() throws Exception
    {
        // GIVEN
        String labelName = "person", propertyKey = "name";

        // WHEN
        actions.createPropertyUniquenessConstraint( labelName, asList( propertyKey ) );

        // THEN
        Transaction tx  = graph.beginTx();
        try
        {
            Iterable<ConstraintDefinition> defs = graphdbHelper.getPropertyUniquenessConstraints( labelName, propertyKey );
            assertEquals( asSet( propertyKey ), asSet( single( defs ).getPropertyKeys() ) );
            tx.success();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=graph.beginTx()) in method public shouldCreatePropertyUniquenessConstraint() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldCreatePropertyExistenceConstraint() throws Exception
    {
        // GIVEN
        String labelName = "person", propertyKey = "name";

        // WHEN
        actions.createPropertyExistenceConstraint( labelName, asList( propertyKey ) );

        // THEN
        try ( Transaction tx = graph.beginTx() )
        {
            Iterable<ConstraintDefinition> defs = graphdbHelper.getPropertyExistenceConstraints( labelName,
                    propertyKey );
            assertEquals( asSet( propertyKey ), asSet( single( defs ).getPropertyKeys() ) );
            tx.success();
        }
    }

    @Test
    public void shouldCreatePropertyExistenceConstraint() throws Exception
    {
        // GIVEN
        String labelName = "person", propertyKey = "name";

        // WHEN
        actions.createPropertyExistenceConstraint( labelName, asList( propertyKey ) );

        // THEN
        Transaction tx  = graph.beginTx();
        try
        {
            Iterable<ConstraintDefinition> defs = graphdbHelper.getPropertyExistenceConstraints( labelName,
                    propertyKey );
            assertEquals( asSet( propertyKey ), asSet( single( defs ).getPropertyKeys() ) );
            tx.success();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=graph.beginTx()) in method public shouldCreatePropertyExistenceConstraint() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldGetPropertyUniquenessConstraint() throws Exception
    {
        // GIVEN
        String labelName = "mylabel", propertyKey = "name";
        graphdbHelper.createPropertyUniquenessConstraint( labelName, asList( propertyKey ) );

        // WHEN
        List<Object> serialized;
        try ( Transaction transaction = graph.beginTx() )
        {
            serialized = serialize( actions.getPropertyUniquenessConstraint( labelName, asList( propertyKey ) ) );
        }

        // THEN
        assertEquals( 1, serialized.size() );
        Map<?, ?> definition = (Map<?, ?>) serialized.get( 0 );
        assertEquals( labelName, definition.get( "label" ) );
        assertEquals( asList( propertyKey ), definition.get( "property_keys" ) );
        assertEquals( "UNIQUENESS", definition.get( "type" ) );
    }

    @Test
    public void shouldGetPropertyUniquenessConstraint() throws Exception
    {
        // GIVEN
        String labelName = "mylabel", propertyKey = "name";
        graphdbHelper.createPropertyUniquenessConstraint( labelName, asList( propertyKey ) );

        // WHEN
        Transaction transaction = graph.beginTx();
        List<Object> serialized;
        try
        {
            serialized = serialize( actions.getPropertyUniquenessConstraint( labelName, asList( propertyKey ) ) );
        }
        finally
        {
            transaction.finish();
        }

        // THEN
        assertEquals( 1, serialized.size() );
        Map<?, ?> definition = (Map<?, ?>) serialized.get( 0 );
        assertEquals( labelName, definition.get( "label" ) );
        assertEquals( asList( propertyKey ), definition.get( "property_keys" ) );
        assertEquals( "UNIQUENESS", definition.get( "type" ) );
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldGetPropertyUniquenessConstraint() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    @Test
    public void shouldGetPropertyExistenceConstraint() throws Exception
    {
        // GIVEN
        String labelName = "mylabel", propertyKey = "name";
        graphdbHelper.createPropertyExistenceConstraint( labelName, asList( propertyKey ) );

        // WHEN
        List<Object> serialized;
        try ( Transaction transaction = graph.beginTx() )
        {
            serialized = serialize( actions.getPropertyExistenceConstraint( labelName, asList( propertyKey ) ) );
        }

        // THEN
        assertEquals( 1, serialized.size() );
        Map<?, ?> definition = (Map<?, ?>) serialized.get( 0 );
        assertEquals( labelName, definition.get( "label" ) );
        assertEquals( Collections.singletonList( propertyKey ), definition.get( "property_keys" ) );
        assertEquals( "MANDATORY_PROPERTY", definition.get( "type" ) );
    }

    @Test
    public void shouldGetPropertyExistenceConstraint() throws Exception
    {
        // GIVEN
        String labelName = "mylabel", propertyKey = "name";
        graphdbHelper.createPropertyExistenceConstraint( labelName, asList( propertyKey ) );

        // WHEN
        Transaction transaction = graph.beginTx();
        List<Object> serialized;
        try
        {
            serialized = serialize( actions.getPropertyExistenceConstraint( labelName, asList( propertyKey ) ) );
        }
        finally
        {
            transaction.finish();
        }

        // THEN
        assertEquals( 1, serialized.size() );
        Map<?, ?> definition = (Map<?, ?>) serialized.get( 0 );
        assertEquals( labelName, definition.get( "label" ) );
        assertEquals( Collections.singletonList( propertyKey ), definition.get( "property_keys" ) );
        assertEquals( "MANDATORY_PROPERTY", definition.get( "type" ) );
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldGetPropertyExistenceConstraint() : void from class org.neo4j.server.rest.web.DatabaseActionsTest


    private long createListOfNodes( int numberOfNodes )
    {
        try ( Transaction tx = database.getGraph().beginTx() )
        {
            long zerothNode = helper.createNode( MapUtil.map( "name", String.valueOf( 0 ) ) );
            long previousNodeId = zerothNode;
            for ( int i = 1; i < numberOfNodes; i++ )
            {
                long currentNodeId = helper.createNode( MapUtil.map( "name", String.valueOf( i ) ) );
                database.getGraph().getNodeById( previousNodeId )
                        .createRelationshipTo( database.getGraph().getNodeById( currentNodeId ),
                                DynamicRelationshipType.withName( "PRECEDES" ) );
                previousNodeId = currentNodeId;
            }

            tx.success();
            return zerothNode;
        }
    }

    private long createListOfNodes( int numberOfNodes )
    {
        Transaction tx = database.getGraph().beginTx();
        try
        {
            long zerothNode = helper.createNode( MapUtil.map( "name", String.valueOf( 0 ) ) );
            long previousNodeId = zerothNode;
            for ( int i = 1; i < numberOfNodes; i++ )
            {
                long currentNodeId = helper.createNode( MapUtil.map( "name", String.valueOf( i ) ) );
                database.getGraph().getNodeById( previousNodeId )
                        .createRelationshipTo( database.getGraph().getNodeById( currentNodeId ),
                                DynamicRelationshipType.withName( "PRECEDES" ) );
                previousNodeId = currentNodeId;
            }

            tx.success();
            return zerothNode;
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=database.getGraph().beginTx()) in method private createListOfNodes(numberOfNodes int) : long from class org.neo4j.server.rest.web.PagingTraversalTest


    @Test
    public void shouldRespondWithAvailableIndexNodeRoots() throws BadInputException
    {
        int numberOfAutoIndexesWhichCouldNotBeDeletedAtTestSetup = helper.getNodeIndexes().length;
        String indexName = "someNodes";
        helper.createNodeIndex( indexName );
        Response response = service.getNodeIndexRoot();
        assertEquals( 200, response.getStatus() );

        try ( Transaction transaction = graph.beginTx() )
        {
            Map<String, Object> resultAsMap = output.getResultAsMap();
            assertThat( resultAsMap.size(), is( numberOfAutoIndexesWhichCouldNotBeDeletedAtTestSetup + 1 ) );
            assertThat( resultAsMap, hasKey( indexName ) );
        }
    }

    @Test
    public void shouldRespondWithAvailableIndexNodeRoots() throws BadInputException
    {
        int numberOfAutoIndexesWhichCouldNotBeDeletedAtTestSetup = helper.getNodeIndexes().length;
        String indexName = "someNodes";
        helper.createNodeIndex( indexName );
        Response response = service.getNodeIndexRoot();
        assertEquals( 200, response.getStatus() );

        Transaction transaction = graph.beginTx();
        try
        {
            Map<String, Object> resultAsMap = output.getResultAsMap();
            assertThat( resultAsMap.size(), is( numberOfAutoIndexesWhichCouldNotBeDeletedAtTestSetup + 1 ) );
            assertThat( resultAsMap, hasKey( indexName ) );
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldRespondWithAvailableIndexNodeRoots() : void from class org.neo4j.server.rest.web.RestfulGraphDatabaseTest


    @Test
    public void shouldRespondWithAvailableIndexRelationshipRoots() throws BadInputException
    {
        String indexName = "someRelationships";
        helper.createRelationshipIndex( indexName );
        Response response = service.getRelationshipIndexRoot();
        assertEquals( 200, response.getStatus() );

        try ( Transaction transaction = graph.beginTx() )
        {
            Map<String, Object> resultAsMap = output.getResultAsMap();
            assertThat( resultAsMap.size(), is( 1 ) );
            assertThat( resultAsMap, hasKey( indexName ) );
        }
    }

    @Test
    public void shouldRespondWithAvailableIndexRelationshipRoots() throws BadInputException
    {
        String indexName = "someRelationships";
        helper.createRelationshipIndex( indexName );
        Response response = service.getRelationshipIndexRoot();
        assertEquals( 200, response.getStatus() );

        Transaction transaction = graph.beginTx();
        try
        {
            Map<String, Object> resultAsMap = output.getResultAsMap();
            assertThat( resultAsMap.size(), is( 1 ) );
            assertThat( resultAsMap, hasKey( indexName ) );
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldRespondWithAvailableIndexRelationshipRoots() : void from class org.neo4j.server.rest.web.RestfulGraphDatabaseTest


    @Test
    public void shouldGet200WhenNoHitsReturnedFromTraverse()
    {
        long startNode = helper.createNode();

        try ( Transaction transaction = graph.beginTx() )
        {
            Response response = service.traverse( startNode, TraverserReturnType.node, "" );
            assertEquals( Status.OK.getStatusCode(), response.getStatus() );
            assertThat( output.getResultAsList().size(), is( 0 ) );
        }
    }

    @Test
    public void shouldGet200WhenNoHitsReturnedFromTraverse()
    {
        long startNode = helper.createNode();

        Transaction transaction = graph.beginTx();
        try
        {
            Response response = service.traverse( startNode, TraverserReturnType.node, "" );
            assertEquals( Status.OK.getStatusCode(), response.getStatus() );
            assertThat( output.getResultAsList().size(), is( 0 ) );
        }
        finally
        {
            transaction.finish();
        }
    }

Try With Resources try(Transaction transaction=graph.beginTx()) in method public shouldGet200WhenNoHitsReturnedFromTraverse() : void from class org.neo4j.server.rest.web.RestfulGraphDatabaseTest