Skip to content

Commit 59d8b03

Browse files
committed
Added utilities for running boltkit in tests
1 parent 385106a commit 59d8b03

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
!: AUTO INIT
2+
!: AUTO RESET
3+
!: AUTO RUN "RETURN 1 // JavaDriver poll to test connection" {}
4+
!: AUTO PULL_ALL
5+
6+
C: RUN "RETURN {x}" {"x": 1}
7+
PULL_ALL
8+
S: SUCCESS {"fields": ["x"]}
9+
RECORD [1]
10+
SUCCESS {}

test/v1/boltkit.js

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* Copyright (c) 2002-2016 "Neo Technology,"
3+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
var childProcess = require("child_process");
21+
22+
var BoltKit = function () {};
23+
24+
BoltKit.prototype.start = function(script, port) {
25+
var spawn = childProcess.spawn, server, code = -1;
26+
27+
server = spawn('/usr/local/bin/boltstub', ['-v', port, script]);
28+
server.stdout.on('data', (data) => {
29+
console.log(`${data}`);
30+
});
31+
server.stderr.on('data', (data) => {
32+
console.log(`${data}`);
33+
});
34+
35+
server.on('close', function (c) {
36+
code = c;
37+
});
38+
39+
server.on('end', function (data) {
40+
console.log(data);
41+
});
42+
43+
server.on('error', function (err) {
44+
console.log('Failed to start child process:' + err);
45+
});
46+
47+
var Server = function(){};
48+
//give process some time to exit
49+
Server.prototype.exit = function(callback) {setTimeout(function(){callback(code);}, 500)};
50+
51+
return new Server();
52+
};
53+
54+
//Make sure boltstub is started before running
55+
//user code
56+
BoltKit.prototype.run = function(callback) {
57+
setTimeout(callback, 500);
58+
};
59+
60+
module.exports = {
61+
BoltKit: BoltKit
62+
};
63+

test/v1/direct.driver.test.js

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Copyright (c) 2002-2016 "Neo Technology,"
3+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
var neo4j = require("../../lib/v1");
21+
var boltkit = require('./boltkit');
22+
23+
describe('direct driver', function() {
24+
25+
it('should run query', function (done) {
26+
// Given
27+
var kit = new boltkit.BoltKit();
28+
var server = kit.start('./test/resources/boltkit/return_x.script', 9001);
29+
30+
kit.run(function () {
31+
var driver = neo4j.driver("bolt://localhost:9001", neo4j.auth.basic("neo4j", "neo4j"));
32+
// When
33+
var session = driver.session();
34+
// Then
35+
session.run("RETURN {x}", {'x': 1}).then(function (res) {
36+
expect(res.records[0].get('x').toInt()).toEqual(1);
37+
session.close();
38+
driver.close();
39+
server.exit(function(code) {
40+
expect(code).toEqual(0);
41+
done();
42+
});
43+
});
44+
});
45+
});
46+
});
47+

0 commit comments

Comments
 (0)