|
1 | | -/* |
2 | | - * Copyright 2020 MarkLogic Corporation |
3 | | - * |
4 | | - * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | - * you may not use this file except in compliance with the License. |
6 | | - * You may obtain a copy of the License at |
7 | | - * |
8 | | - * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | - * |
10 | | - * Unless required by applicable law or agreed to in writing, software |
11 | | - * distributed under the License is distributed on an "AS IS" BASIS, |
12 | | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | - * See the License for the specific language governing permissions and |
14 | | - * limitations under the License. |
15 | | - */ |
16 | | -'use strict'; |
17 | | - |
18 | | -var util = require('../node_modules/core-util-is/lib/util.js'); |
19 | | - |
20 | | -var fs = require('fs'); |
21 | | -var valcheck = require('core-util-is'); |
22 | | - |
23 | | -var marklogic = require('../lib/marklogic.js'); |
24 | | -var testlib = require('./testlib.js'); |
25 | | - |
26 | | -var clientConnectdef = require('./connectdef.js'); |
27 | | -var testName = clientConnectdef.name; |
28 | | -var planServerdef = clientConnectdef.plan; |
29 | | - |
30 | | -var testLoad = require('./loaddata.js'); |
31 | | -var testUser = require('./userconfig.js'); |
32 | | - |
33 | | -var db = marklogic.createDatabaseClient({ |
34 | | - host: planServerdef.host, |
35 | | - port: planServerdef.port, |
36 | | - user: 'admin', |
37 | | - password: 'admin', |
38 | | - authType: planServerdef.authType |
39 | | -}); |
40 | | -var dbMod = marklogic.createDatabaseClient({ |
41 | | - database: testName+'Modules', |
42 | | - host: planServerdef.host, |
43 | | - port: planServerdef.port, |
44 | | - user: 'admin', |
45 | | - password: 'admin', |
46 | | - authType: planServerdef.authType |
47 | | -}); |
48 | | -var manager = testlib.createManager(marklogic.createDatabaseClient({ |
49 | | - host: planServerdef.host, |
50 | | - port: 8002, |
51 | | - user: 'admin', |
52 | | - password: 'admin', |
53 | | - authType: planServerdef.authType |
54 | | - })); |
55 | | - |
56 | | -console.log('checking for '+testName); |
57 | | -var check = manager.get({ |
58 | | - endpoint: '/v1/rest-apis/'+testName |
59 | | - }).result(); |
60 | | -check.then(function(response) { |
61 | | - if (response.statusCode !== 404) { |
62 | | - return check; |
63 | | - } |
64 | | - |
65 | | - console.log('creating database and REST server for '+testName); |
66 | | - return manager.post({ |
67 | | - endpoint: '/v1/rest-apis', |
68 | | - body: { |
69 | | - 'rest-api': { |
70 | | - name: testName, |
71 | | - group: 'Default', |
72 | | - database: testName, |
73 | | - 'modules-database': testName+'Modules', |
74 | | - port: planServerdef.port |
75 | | - } |
76 | | - } |
77 | | - }).result(); |
78 | | - }) |
79 | | -.then(function(response){ |
80 | | - console.log('setting up rest eval role'); |
81 | | - return testUser.addRestEvalRole(manager).result(); |
82 | | -}) |
83 | | -.then(function(response){ |
84 | | - console.log('setting up rest eval user'); |
85 | | - return testUser.addRestEvalUser(manager).result(); |
86 | | -}) |
87 | | -.then(function(response){ |
88 | | - console.log('setting up rest reader user'); |
89 | | - return testUser.addRestReaderUser(manager).result(); |
90 | | -}) |
91 | | -.then(function(response){ |
92 | | - console.log('setting up tde template on module database'); |
93 | | - return testLoad.writeDocumentsToMod(dbMod).result(); |
94 | | -}) |
95 | | -.then(function(response){ |
96 | | - console.log('setting up sample documents'); |
97 | | - return testLoad.writeDocuments(db).result(); |
98 | | -}) |
99 | | -.then(function(response){ |
100 | | - console.log('setting up graphs1'); |
101 | | - return testLoad.writeGraphs1(db).result(); |
102 | | -}) |
103 | | -.then(function(response){ |
104 | | - console.log('setting up graphs2'); |
105 | | - return testLoad.writeGraphs2(db).result(); |
106 | | -}) |
107 | | -.then(function(response){ |
108 | | - console.log('setting up database setup file'); |
109 | | - return db.config.extlibs.write({ |
110 | | - path:'/ext/optic/test/databaseconfig.sjs', contentType:'application/javascript', source:fs.createReadStream('./config-optic/databaseconfig.sjs') |
111 | | - }).result(); |
112 | | -}) |
113 | | -.then(function(response) { |
114 | | - console.log('setting up database configuration'); |
115 | | - var dbEval = marklogic.createDatabaseClient({ |
116 | | - host: planServerdef.host, |
117 | | - port: planServerdef.port, |
118 | | - user: 'rest-evaluator', |
119 | | - password: 'x', |
120 | | - authType: planServerdef.authType |
121 | | - }); |
122 | | - return dbEval.invoke('/ext/optic/test/databaseconfig.sjs').result(); |
123 | | -}) |
124 | | -.then(function(response){ |
125 | | - console.log('setup done'); |
126 | | - }) |
127 | | -.catch(function(error){ |
128 | | - console.log('error'); |
129 | | - console.log(util.inspect(error, {depth:null})); |
130 | | - }); |
| 1 | +/* |
| 2 | + * Copyright 2015-2020 MarkLogic Corporation |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +'use strict'; |
| 17 | + |
| 18 | +var util = require('../node_modules/core-util-is/lib/util.js'); |
| 19 | + |
| 20 | +var fs = require('fs'); |
| 21 | +var valcheck = require('core-util-is'); |
| 22 | + |
| 23 | +var marklogic = require('../lib/marklogic.js'); |
| 24 | +var testlib = require('./testlib.js'); |
| 25 | + |
| 26 | +var clientConnectdef = require('./connectdef.js'); |
| 27 | +var testName = clientConnectdef.name; |
| 28 | +var planServerdef = clientConnectdef.plan; |
| 29 | + |
| 30 | +var testLoad = require('./loaddata.js'); |
| 31 | +var testUser = require('./userconfig.js'); |
| 32 | + |
| 33 | +var db = marklogic.createDatabaseClient({ |
| 34 | + host: planServerdef.host, |
| 35 | + port: planServerdef.port, |
| 36 | + user: 'admin', |
| 37 | + password: 'admin', |
| 38 | + authType: planServerdef.authType |
| 39 | +}); |
| 40 | +var dbMod = marklogic.createDatabaseClient({ |
| 41 | + database: testName+'Modules', |
| 42 | + host: planServerdef.host, |
| 43 | + port: planServerdef.port, |
| 44 | + user: 'admin', |
| 45 | + password: 'admin', |
| 46 | + authType: planServerdef.authType |
| 47 | +}); |
| 48 | +var manager = testlib.createManager(marklogic.createDatabaseClient({ |
| 49 | + host: planServerdef.host, |
| 50 | + port: 8002, |
| 51 | + user: 'admin', |
| 52 | + password: 'admin', |
| 53 | + authType: planServerdef.authType |
| 54 | + })); |
| 55 | + |
| 56 | +console.log('checking for '+testName); |
| 57 | +var check = manager.get({ |
| 58 | + endpoint: '/v1/rest-apis/'+testName |
| 59 | + }).result(); |
| 60 | +check.then(function(response) { |
| 61 | + if (response.statusCode !== 404) { |
| 62 | + return check; |
| 63 | + } |
| 64 | + |
| 65 | + console.log('creating database and REST server for '+testName); |
| 66 | + return manager.post({ |
| 67 | + endpoint: '/v1/rest-apis', |
| 68 | + body: { |
| 69 | + 'rest-api': { |
| 70 | + name: testName, |
| 71 | + group: 'Default', |
| 72 | + database: testName, |
| 73 | + 'modules-database': testName+'Modules', |
| 74 | + port: planServerdef.port |
| 75 | + } |
| 76 | + } |
| 77 | + }).result(); |
| 78 | + }) |
| 79 | +.then(function(response){ |
| 80 | + console.log('setting up rest eval role'); |
| 81 | + return testUser.addRestEvalRole(manager).result(); |
| 82 | +}) |
| 83 | +.then(function(response){ |
| 84 | + console.log('setting up rest eval user'); |
| 85 | + return testUser.addRestEvalUser(manager).result(); |
| 86 | +}) |
| 87 | +.then(function(response){ |
| 88 | + console.log('setting up rest reader user'); |
| 89 | + return testUser.addRestReaderUser(manager).result(); |
| 90 | +}) |
| 91 | +.then(function(response){ |
| 92 | + console.log('setting up tde template on module database'); |
| 93 | + return testLoad.writeDocumentsToMod(dbMod).result(); |
| 94 | +}) |
| 95 | +.then(function(response){ |
| 96 | + console.log('setting up sample documents'); |
| 97 | + return testLoad.writeDocuments(db).result(); |
| 98 | +}) |
| 99 | +.then(function(response){ |
| 100 | + console.log('setting up graphs1'); |
| 101 | + return testLoad.writeGraphs1(db).result(); |
| 102 | +}) |
| 103 | +.then(function(response){ |
| 104 | + console.log('setting up graphs2'); |
| 105 | + return testLoad.writeGraphs2(db).result(); |
| 106 | +}) |
| 107 | +.then(function(response){ |
| 108 | + console.log('setting up database setup file'); |
| 109 | + return db.config.extlibs.write({ |
| 110 | + path:'/ext/optic/test/databaseconfig.sjs', contentType:'application/javascript', source:fs.createReadStream('./config-optic/databaseconfig.sjs') |
| 111 | + }).result(); |
| 112 | +}) |
| 113 | +.then(function(response) { |
| 114 | + console.log('setting up database configuration'); |
| 115 | + var dbEval = marklogic.createDatabaseClient({ |
| 116 | + host: planServerdef.host, |
| 117 | + port: planServerdef.port, |
| 118 | + user: 'rest-evaluator', |
| 119 | + password: 'x', |
| 120 | + authType: planServerdef.authType |
| 121 | + }); |
| 122 | + return dbEval.invoke('/ext/optic/test/databaseconfig.sjs').result(); |
| 123 | +}) |
| 124 | +.then(function(response){ |
| 125 | + console.log('setup done'); |
| 126 | + }) |
| 127 | +.catch(function(error){ |
| 128 | + console.log('error'); |
| 129 | + console.log(util.inspect(error, {depth:null})); |
| 130 | + }); |
0 commit comments