Add docs examples as driver tests (#29)
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
import org.neo4j.driver.*;
|
||||
import org.neo4j.driver.types.*;
|
||||
import static org.neo4j.driver.Values.parameters;
|
||||
import java.util.*;
|
||||
|
||||
public class Basic {
|
||||
public static void main(String[] args) {
|
||||
Config config = Config.builder().withoutEncryption().build();
|
||||
Driver driver = GraphDatabase.driver( "bolt://localhost:7687", AuthTokens.basic( "neo4j", "1234" ), config );
|
||||
|
||||
try ( Session session = driver.session() ) {
|
||||
Result rs1 = session.run( "MATCH (n) DETACH DELETE n" );
|
||||
System.out.println( "Database cleared." );
|
||||
|
||||
Result rs2 = session.run( "CREATE (alice: Person {name: 'Alice', age: 22})" );
|
||||
System.out.println( "Record created." );
|
||||
|
||||
Result 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();
|
||||
}
|
||||
}
|
||||
40
tests/drivers/java/v4_1/DocsHowToQuery.java
Normal file
40
tests/drivers/java/v4_1/DocsHowToQuery.java
Normal file
@@ -0,0 +1,40 @@
|
||||
import java.util.*;
|
||||
import org.neo4j.driver.*;
|
||||
|
||||
public class DocsHowToQuery {
|
||||
public static void main(String[] args) {
|
||||
var config = Config.builder().withoutEncryption().build();
|
||||
var driver = GraphDatabase.driver("bolt://localhost:7687", AuthTokens.basic("", ""), config);
|
||||
|
||||
try (var session = driver.session()) {
|
||||
session.run("MATCH (n) DETACH DELETE n;");
|
||||
System.out.println("Database cleared.");
|
||||
|
||||
session.run("CREATE (alice:Person {name: 'Alice', age: 22});");
|
||||
System.out.println("Record created.");
|
||||
|
||||
var node = session.run("MATCH (n) RETURN n;").list().get(0).get("n").asNode();
|
||||
System.out.println("Record matched.");
|
||||
|
||||
var label = node.labels().iterator().next();
|
||||
var name = node.get("name").asString();
|
||||
var age = node.get("age").asInt();
|
||||
|
||||
if (!label.equals("Person") || !name.equals("Alice") || age != 22) {
|
||||
System.out.println("Data doesn't match!");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
System.out.println("Label: " + label);
|
||||
System.out.println("name: " + name);
|
||||
System.out.println("age: " + age);
|
||||
|
||||
System.out.println("All ok!");
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
driver.close();
|
||||
}
|
||||
}
|
||||
@@ -22,11 +22,11 @@ if [ ! -f $REACTIVE_STREAM_DEP ]; then
|
||||
wget -nv https://repo1.maven.org/maven2/org/reactivestreams/reactive-streams/1.0.3/reactive-streams-1.0.3.jar -O $REACTIVE_STREAM_DEP || exit 1
|
||||
fi
|
||||
|
||||
javac -classpath .:$DRIVER:$REACTIVE_STREAM_DEP Basic.java
|
||||
java -classpath .:$DRIVER:$REACTIVE_STREAM_DEP Basic
|
||||
javac -classpath .:$DRIVER:$REACTIVE_STREAM_DEP DocsHowToQuery.java
|
||||
java -classpath .:$DRIVER:$REACTIVE_STREAM_DEP DocsHowToQuery
|
||||
|
||||
javac -classpath .:$DRIVER:$REACTIVE_STREAM_DEP MaxQueryLength.java
|
||||
java -classpath .:$DRIVER:$REACTIVE_STREAM_DEP MaxQueryLength
|
||||
|
||||
javac -classpath .:$DRIVER:$REACTIVE_STREAM_DEP Transactions.java
|
||||
java -classpath .:$DRIVER:$REACTIVE_STREAM_DEP Transactions
|
||||
java -classpath .:$DRIVER:$REACTIVE_STREAM_DEP Transactions
|
||||
|
||||
Reference in New Issue
Block a user