Added javascript and java driver tests.
Reviewers: buda Reviewed By: buda Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D438
This commit is contained in:
parent
532f38ca3f
commit
6308ec6a34
@ -33,7 +33,11 @@ State StateInitRun(Session &session) {
|
||||
if (UNLIKELY(marker != Marker::TinyStruct2)) {
|
||||
logger.debug("Expected TinyStruct2 marker, but received 0x{:02X}!",
|
||||
underlying_cast(marker));
|
||||
return State::Close;
|
||||
logger.warn("The client sent malformed data, but we are continuing "
|
||||
"because the official Neo4j Java driver sends malformed "
|
||||
"data. D'oh!");
|
||||
// TODO: this should be uncommented when the Neo4j Java driver is fixed
|
||||
//return State::Close;
|
||||
}
|
||||
|
||||
query::TypedValue client_name;
|
||||
|
7
tests/drivers/.gitignore
vendored
Normal file
7
tests/drivers/.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
# java driver
|
||||
java/*.jar
|
||||
java/*.class
|
||||
|
||||
# javascript driver
|
||||
javascript/node_modules
|
||||
javascript/package-lock.json
|
23
tests/drivers/java/run.sh
Executable file
23
tests/drivers/java/run.sh
Executable file
@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
JAVA=java
|
||||
JAVAC=javac
|
||||
|
||||
if ! which $JAVA >/dev/null; then
|
||||
echo "Please install java!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! which $JAVAC >/dev/null; then
|
||||
echo "Please install javac!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DRIVER=neo4j-java-driver.jar
|
||||
|
||||
if [ ! -f $DRIVER ]; then
|
||||
wget -O $DRIVER http://central.maven.org/maven2/org/neo4j/driver/neo4j-java-driver/1.3.1/neo4j-java-driver-1.3.1.jar || exit 1
|
||||
fi
|
||||
|
||||
javac -classpath .:$DRIVER test.java || exit 1
|
||||
java -classpath .:$DRIVER test || exit 1
|
38
tests/drivers/java/test.java
Normal file
38
tests/drivers/java/test.java
Normal file
@ -0,0 +1,38 @@
|
||||
import org.neo4j.driver.v1.*;
|
||||
import org.neo4j.driver.v1.types.*;
|
||||
import static org.neo4j.driver.v1.Values.parameters;
|
||||
import java.util.*;
|
||||
|
||||
public class test {
|
||||
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();
|
||||
}
|
||||
}
|
17
tests/drivers/javascript/run.sh
Executable file
17
tests/drivers/javascript/run.sh
Executable file
@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
NODE=nodejs
|
||||
NPM=npm
|
||||
|
||||
if ! which $NODE >/dev/null; then
|
||||
echo "Please install Node.JS!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! which $NPM >/dev/null; then
|
||||
echo "Please install NPM!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
$NPM install neo4j-driver || exit 1
|
||||
$NODE test.js || exit 1
|
36
tests/drivers/javascript/test.js
Normal file
36
tests/drivers/javascript/test.js
Normal file
@ -0,0 +1,36 @@
|
||||
var neo4j = require('neo4j-driver').v1;
|
||||
var driver = neo4j.driver("bolt://localhost:7687",
|
||||
neo4j.auth.basic("neo4j", "1234"),
|
||||
{ encrypted: 'ENCRYPTION_OFF' });
|
||||
var session = driver.session();
|
||||
|
||||
function die() {
|
||||
session.close();
|
||||
driver.close();
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function run_query(query, callback) {
|
||||
var run = session.run(query, {});
|
||||
run.then(callback).catch(function (error) {
|
||||
console.log(error);
|
||||
die();
|
||||
});
|
||||
}
|
||||
|
||||
run_query("MATCH (n) DETACH DELETE n", function (result) {
|
||||
console.log("Database cleared.");
|
||||
run_query("CREATE (alice: Person {name: 'Alice', age: 22})", function (result) {
|
||||
console.log("Record created.");
|
||||
run_query("MATCH (n) RETURN n", function (result) {
|
||||
console.log("Record matched.");
|
||||
var alice = result.records[0].get("n");
|
||||
if(alice.labels[0] != "Person" || alice.properties["name"] != "Alice"){
|
||||
console.log("Data doesn't match!");
|
||||
die();
|
||||
}
|
||||
console.log("All ok!");
|
||||
driver.close();
|
||||
});
|
||||
});
|
||||
});
|
21
tests/drivers/run.sh
Executable file
21
tests/drivers/run.sh
Executable file
@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
|
||||
pushd () {
|
||||
command pushd "$@" > /dev/null
|
||||
}
|
||||
|
||||
popd () {
|
||||
command popd "$@" > /dev/null
|
||||
}
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
cd $DIR
|
||||
|
||||
for i in *; do
|
||||
if [ ! -d $i ]; then continue; fi
|
||||
pushd $i
|
||||
echo "Running: $i"
|
||||
./run.sh || exit 1
|
||||
echo
|
||||
popd
|
||||
done
|
Loading…
Reference in New Issue
Block a user