memgraph/tests/drivers/java/v1/Basic.java
antonio2368 0bcc1d67bc
Add support for Bolt v4(.1) (#10)
* Added handshake support
* Add support for v4 hello and goodbye
* Add support for pulling n results
* Add support for transactions
* Add pull n for the dump
* Add support for NOOP
* Add support for multiple queries
* Update bolt session to support qid
* Update drivers test with multiple versions and go
* Extract failure handling into a function
* Use unique ptr instead of optional for query execution
* Destroy stream before query execution

Co-authored-by: Antonio Andelic <antonio.andelic@memgraph.io>
2020-10-16 12:49:33 +02:00

39 lines
1.4 KiB
Java

import org.neo4j.driver.v1.*;
import org.neo4j.driver.v1.types.*;
import static org.neo4j.driver.v1.Values.parameters;
import java.util.*;
public class Basic {
public static void main(String[] args) {
Config config = Config.build().withoutEncryption().toConfig();
Driver driver = GraphDatabase.driver( "bolt://localhost:7687", AuthTokens.basic( "neo4j", "1234" ), config );
try ( Session session = driver.session() ) {
StatementResult rs1 = session.run( "MATCH (n) DETACH DELETE n" );
System.out.println( "Database cleared." );
StatementResult rs2 = session.run( "CREATE (alice: Person {name: 'Alice', age: 22})" );
System.out.println( "Record created." );
StatementResult rs3 = session.run( "MATCH (n) RETURN n" );
System.out.println( "Record matched." );
List<Record> records = rs3.list();
Record record = records.get( 0 );
Node node = record.get( "n" ).asNode();
if ( !node.get("name").asString().equals( "Alice" ) || node.get("age").asInt() != 22 ) {
System.out.println( "Data doesn't match!" );
System.exit( 1 );
}
System.out.println( "All ok!" );
}
catch ( Exception e ) {
System.out.println( e );
System.exit( 1 );
}
driver.close();
}
}