-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathnodejs-documents-resources-config.js
More file actions
121 lines (114 loc) · 4.42 KB
/
Copy pathnodejs-documents-resources-config.js
File metadata and controls
121 lines (114 loc) · 4.42 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
/*
* 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);
var restAdminDB = marklogic.createDatabaseClient(testconfig.restAdminConnection);
describe('when configuring resource services', function () {
var serviceName = 'timeService';
var serviceNameInvalid = 'BlaBla';
var servicePath = __dirname + '/../test-basic/data/timeService.xqy';
it('should write the resource service with positional parameters', function (done) {
this.timeout(10000);
restAdminDB.config.resources.write(serviceName, 'xquery', fs.createReadStream(servicePath)).
result(function (response) {
done();
}, done);
});
it('should write the resource service with named parameters', function (done) {
this.timeout(10000);
restAdminDB.config.resources.write({
name: serviceName,
title: 'The Time Service',
description: 'About time.',
provider: 'Temporizers',
version: 0.1,
format: 'xquery',
source: fs.createReadStream(servicePath)
}).
result(function (response) {
done();
}, done);
});
it('should read the resource service', function (done) {
restAdminDB.config.resources.read(serviceName).
result(function (source) {
//console.log(JSON.stringify(source, null, 4));
(valcheck.isNullOrUndefined(source)).should.equal(false);
done();
}, done);
});
it('should try to read the resource service via invalid name', function (done) {
restAdminDB.config.resources.read(serviceNameInvalid).
result(function (source) {
//console.log(JSON.stringify("Output :"+source, null, 4));
}, function (error) {
//console.log(JSON.stringify(error, null, 4));
(valcheck.isNullOrUndefined(error)).should.equal(false);
done();
}, done);
});
it('should list the resource services', function (done) {
db.config.resources.list().
result(function (response) {
//Need to verify content
//console.log(JSON.stringify(response, null, 4));
response.should.have.property('resources');
response.resources.should.have.property('resource');
response.resources.resource.length.should.be.above(0);
response.resources.resource.filter(function (item) {
return item.name === serviceName;
}).
length.should.equal(1);
done();
}, done);
});
it('should over-write the resource service with named parameters', function (done) {
this.timeout(10000);
restAdminDB.config.resources.write({
name: serviceName,
title: 'The Hindustan Time Service',
description: 'About time zones',
provider: 'Temporizers',
version: 0.2,
format: 'xquery',
source: fs.createReadStream(servicePath)
}).
result(function (response) {
done();
}, done);
});
/* //Need to get to the content first
it('should delete specified resource config ', function(done){
restAdminDB.config.resources.resource.remove(serviceName).
result(function(response){
done();
}, done);
}); */
it('should delete the resource service', function (done) {
restAdminDB.config.resources.remove(serviceName).
result(function (response) {
done();
}, done);
});
it('should try read the resource service after remove', function (done) {
restAdminDB.config.resources.read(serviceName).
result(function (source) {
}, function (error) {
//console.log(JSON.stringify(error, null, 4));
(valcheck.isNullOrUndefined(error)).should.equal(false);
done();
}, done);
});
it('should delete the invalid resource service', function (done) {
restAdminDB.config.resources.remove(serviceNameInvalid).
result(function (response) {
done();
}, done);
});
});