-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathnodejs-graphs-overwrite.js
More file actions
122 lines (109 loc) · 4.91 KB
/
Copy pathnodejs-graphs-overwrite.js
File metadata and controls
122 lines (109 loc) · 4.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
var should = require('should');
var fs = require('fs');
var valcheck = require('core-util-is');
var testconfig = require('../etc/test-config-qa.js');
var marklogic = require('../');
var q = marklogic.queryBuilder;
var db = marklogic.createDatabaseClient(testconfig.restWriterConnection);
describe('overwrite graph test', function () {
var graphUri = 'marklogic.com/overwrite/people';
var graphPath1 = __dirname + '/data/people3.ttl';
var graphPath2 = __dirname + '/data/people4.ttl';
var sparqlPath = __dirname + '/data/people.rq';
it('should write the graph', function (done) {
this.timeout(10000);
db.graphs.write({ uri: graphUri, repair: false, contentType: 'text/turtle', data: fs.createReadStream(graphPath1) }).
result(function (response) {
//console.log(JSON.stringify(response, null, 4));
response.should.have.property('graph');
response.graph.should.equal(graphUri);
done();
}, done);
});
it('should overwrite the graph', function (done) {
this.timeout(10000);
db.graphs.write({ uri: graphUri, repair: false, contentType: 'text/turtle', data: fs.createReadStream(graphPath2) }).
result(function (response) {
//console.log(JSON.stringify(response, null, 4));
response.should.have.property('graph');
response.graph.should.equal(graphUri);
done();
}, done);
});
it('should read the overwritten graph', function (done) {
this.timeout(10000);
db.graphs.read({ contentType: 'application/json', uri: graphUri }).
result(function (response) {
//console.log(JSON.stringify(response, null, 4));
var strResponse = JSON.stringify(response);
strResponse.should.containEql('http://people.org/person9');
strResponse.should.not.containEql('http://people.org/person2');
done();
}, done);
});
it('should check the overwritten graph', function (done) {
this.timeout(10000);
db.graphs.probe(graphUri).
result(function (response) {
response.should.have.property('graph');
response.graph.should.equal(graphUri);
response.should.have.property('exists');
response.exists.should.equal(true);
done();
}, done);
});
it('should list the overwritten graph', function (done) {
this.timeout(10000);
db.graphs.list().
result(function (collections) {
//console.log(JSON.stringify(collections, null, 2))
collections.some(function (collection) {
return collection === graphUri;
}).should.equal(true);
done();
}, done);
});
/*it('should list the overwritten graph', function(done){
this.timeout(10000);
db.graphs.list('foo/bar').
result(function(response){
//console.log(JSON.stringify(response, null, 4))
done();
}, done);
});*/
it('should run a SPARQL query against the overwritten graph', function (done) {
this.timeout(10000);
db.graphs.sparql('application/sparql-results+json', fs.createReadStream(sparqlPath)).
result(function (response) {
response.should.have.property('head');
response.head.should.have.property('vars');
response.head.vars.length.should.equal(2);
response.head.vars[0].should.equal('personName1');
response.head.vars[1].should.equal('personName2');
response.should.have.property('results');
response.results.should.have.property('bindings');
var strResponse = JSON.stringify(response);
//console.log(strResponse);
strResponse.should.containEql('Person 9');
strResponse.should.containEql('Person 12');
/*response.results.bindings[0].should.have.property('personName1');
response.results.bindings[0].personName1.should.have.property('value');
response.results.bindings[0].personName1.value.should.equal('Person 9');
response.results.bindings[0].should.have.property('personName2');
response.results.bindings[0].personName2.should.have.property('value');
response.results.bindings[0].personName2.value.should.equal('Person 12');*/
//console.log(JSON.stringify(response, null, 4))
done();
}, done);
});
it('should delete the overwritten graph', function (done) {
this.timeout(10000);
db.graphs.remove(graphUri).
result(function (response) {
done();
}, done);
});
});