<commit_before>/**
 * Copyright (c) 2002-2011 "Neo Technology,"
 * Network Engine for Objects in Lund AB [http://neotechnology.com]
 *
 * This file is part of Neo4j.
 *
 * Neo4j is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.neo4j.cypher.javacompat;

import org.junit.Before;
import org.junit.Test;
import org.neo4j.cypher.commands.Query;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.test.ImpermanentGraphDatabase;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.containsString;
import static org.junit.matchers.JUnitMatchers.hasItem;
import static org.neo4j.helpers.collection.IteratorUtil.asIterable;

public class JavaExecutionEngineTests
{

    private GraphDatabaseService db;
    private ExecutionEngine engine;

    @Before public void setUp() throws IOException {
// START SNIPPET: JavaQuery
        db = new ImpermanentGraphDatabase();
        engine = new ExecutionEngine( db );
// END SNIPPET: JavaQuery
    }

    @Test
    public void exampleQuery() throws Exception
    {
// START SNIPPET: JavaQuery
        ExecutionEngine engine = new ExecutionEngine(db);
        ExecutionResult result = engine.execute( "start n=node(0) where 1=1 return n" );

        assertThat( result.columns(), hasItem( "n" ) );
        Iterator<Node> n_column = result.columnAs( "n" );
        assertThat( asIterable( n_column ), hasItem(db.getNodeById(0)) );
        assertThat( result.toString(), containsString("Node[0]") );
// END SNIPPET: JavaQuery
    }

    @Test
    public void exampleConsole() throws Exception
    {
        Query query = CypherParser.parseConsole("" +
                 //START SNIPPET: Identifier
        		"start n=node(0) return n.name"
        		//END SNIPPET: Identifier
                );
        
        ExecutionResult result = engine.execute(query);

        assertThat( result.columns(), hasItem( "n.name" ) );
        Iterator<Object> n_column = result.columnAs( "n.name" );
        assertNull( n_column.next() );
        assertThat( result.toString(), containsString("null") );
    }


    @Test
    public void exampleWithParameters() throws Exception
    {
     // START SNIPPET: ParameterJavaQuery
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", 0);
        ExecutionResult result = engine.execute("start n=node({id}) return n.name?", params);
     // START SNIPPET: ParameterJavaQuery

        assertThat( result.columns(), hasItem( "n.name" ) );
        Iterator<Object> n_column = result.columnAs( "n.name" );
        assertNull( n_column.next() );
        assertThat( result.toString(), containsString("null") );
    }
}<commit_msg>correcting snippets<commit_after>/**
 * Copyright (c) 2002-2011 "Neo Technology,"
 * Network Engine for Objects in Lund AB [http://neotechnology.com]
 *
 * This file is part of Neo4j.
 *
 * Neo4j is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.neo4j.cypher.javacompat;

import org.junit.Before;
import org.junit.Test;
import org.neo4j.cypher.commands.Query;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.test.ImpermanentGraphDatabase;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.containsString;
import static org.junit.matchers.JUnitMatchers.hasItem;
import static org.neo4j.helpers.collection.IteratorUtil.asIterable;

public class JavaExecutionEngineTests
{

    private GraphDatabaseService db;
    private ExecutionEngine engine;

    @Before public void setUp() throws IOException {
// START SNIPPET: JavaQuery
        db = new ImpermanentGraphDatabase();
        engine = new ExecutionEngine( db );
// END SNIPPET: JavaQuery
    }

    @Test
    public void exampleQuery() throws Exception
    {
// START SNIPPET: JavaQuery
        ExecutionEngine engine = new ExecutionEngine(db);
        ExecutionResult result = engine.execute( "start n=node(0) where 1=1 return n" );

        assertThat( result.columns(), hasItem( "n" ) );
        Iterator<Node> n_column = result.columnAs( "n" );
        assertThat( asIterable( n_column ), hasItem(db.getNodeById(0)) );
        assertThat( result.toString(), containsString("Node[0]") );
// END SNIPPET: JavaQuery
    }

    @Test
    public void exampleConsole() throws Exception
    {
        Query query = CypherParser.parseConsole("" +
                 //START SNIPPET: Identifier
        		"start n=node(0) return n.name"
        		//END SNIPPET: Identifier
                );
        
        ExecutionResult result = engine.execute(query);

        assertThat( result.columns(), hasItem( "n.name" ) );
        Iterator<Object> n_column = result.columnAs( "n.name" );
        assertNull( n_column.next() );
        assertThat( result.toString(), containsString("null") );
    }


    @Test
    public void exampleWithParameters() throws Exception
    {
     // START SNIPPET: ParameterJavaQuery
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", 0);
        ExecutionResult result = engine.execute("start n=node({id}) return n.name?", params);
     // END SNIPPET: ParameterJavaQuery

        assertThat( result.columns(), hasItem( "n.name" ) );
        Iterator<Object> n_column = result.columnAs( "n.name" );
        assertNull( n_column.next() );
        assertThat( result.toString(), containsString("null") );
    }
}
{'fraction_non_alphanumeric': 0.1065123010130246, 'fraction_numerical': 0.006946454413892909, 'mean_word_length': 3.292546583850932, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6651952', 'n_tokens_mistral': 2022, 'n_tokens_neox': 1944, 'n_words': 597}