-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathnodejs-database-connection-negative.js
More file actions
133 lines (120 loc) · 3.9 KB
/
Copy pathnodejs-database-connection-negative.js
File metadata and controls
133 lines (120 loc) · 3.9 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
123
124
125
126
127
128
129
130
131
132
133
/*
* Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
var should = require('should');
var testconfig = require('../etc/test-config-qa.js');
var marklogic = require('../');
var q = marklogic.queryBuilder;
var db = marklogic.createDatabaseClient(testconfig.restReaderConnection);
var dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnection);
describe('Database connection negative test', function () {
it('should fail to create db connection with invalid host', function (done) {
try {
marklogic.createDatabaseClient({
host: 'invalid',
port: '8015',
user: 'admin',
password: 'admin',
authType: 'DIGEST'
}).should.equal('SHOULD HAVE FAILED');
done();
} catch (error) {
//console.log(error);
error.should.be.ok;
done();
}
});
it('should fail to create db connection with occupied port', function (done) {
try {
marklogic.createDatabaseClient({
host: 'localhost',
port: '8000',
user: 'admin',
password: 'admin',
authType: 'DIGEST'
}).should.equal('SHOULD HAVE FAILED');
done();
} catch (error) {
//console.log(error);
error.should.be.ok;
done();
}
});
it('should fail to create db connection with invalid db', function (done) {
try {
marklogic.createDatabaseClient({
host: 'localhost',
port: '8015',
database: 'invalid',
user: 'admin',
password: 'admin',
authType: 'DIGEST'
}).should.equal('SHOULD HAVE FAILED');
done();
} catch (error) {
//console.log(error);
error.should.be.ok;
done();
}
});
it('should fail to create db connection with invalid user and password', function (done) {
try {
marklogic.createDatabaseClient({
host: 'localhost',
port: '8015',
user: 'foo',
password: 'foo',
authType: 'DIGEST'
}).should.equal('SHOULD HAVE FAILED');
done();
} catch (error) {
//console.log(error);
error.should.be.ok;
done();
}
});
it('should fail to create db connection with invalid auth type', function (done) {
try {
marklogic.createDatabaseClient({
host: 'localhost',
port: '8015',
user: 'admin',
password: 'admin',
authType: 'DIGEST'
}).should.equal('SHOULD HAVE FAILED');
done();
} catch (error) {
//console.log(error);
error.should.be.ok;
done();
}
});
it('Verify release client error message', function (done) {
try {
var db = marklogic.createDatabaseClient({
host: 'localhost',
port: '8015',
user: 'admin',
password: 'admin',
authType: 'DIGEST'
});
// Force connection to be released
db.connectionParams = null;
db.documents.query(
q.where(
q.term('describe', q.termOptions('stemmed'))
)).result(function (response) {
done();
}, function (err) {
console.log(JSON.stringify(response, null, 4));
done();
});
done();
} catch (error) {
//console.log('### ' + error.message);
error.message.should.equal('Connection has been closed.');
error.should.be.ok;
done();
}
});
});