-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (42 loc) · 1.44 KB
/
Copy pathindex.js
File metadata and controls
48 lines (42 loc) · 1.44 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
var spawn = require('child_process').spawn;
var fs = require('fs');
var request = require('request');
var child;
exports.startWireMock = function(port, executableLocation) {
if(executableLocation == null){
executableLocation = "./node_modules/mock-servers-js/wiremock-standalone-2.6.0.jar";
};
var out = fs.openSync('logFileForPort' + port, 'a');
var err = fs.openSync('logFileForPort' + port, 'a');
runJavaJar(port, executableLocation, out, err);
}
exports.shutDownWireMock = function(port) {
request.post('http://localhost:' + port + "/__admin/shutdown", '')
.on('response', function(response) {
console.log("Shutdown WireMock server on port: " + port);
})
.on('error', function(response) {
console.log("Error while shuting down WireMock server on port: " + port);
});
}
exports.setNewMappingForPort = function(port, jsonBody) {
var options = {
uri: 'http://localhost:' + port + '/__admin/mappings/new',
method: 'POST',
json: jsonBody
};
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(response);
}
});
}
function runJavaJar(port, executableLocation, out, err) {
console.log("WireMock server on port: "+port);
rootDirectory = "./node_modules/mock-servers-js";
child = spawn('java', ['-jar', executableLocation, '--port', port, '--root-dir', rootDirectory], {
detached: true,
stdio: ['ignore', out, err]
});
child.unref();
}