Created
March 11, 2016 15:51
-
-
Save legap/92b49ca1e52d045846f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
it('should send a get request to the config restlet.', function () { | |
var gotResponse = false; | |
var myResponse = {}; | |
//this function to wait the rest to respond back | |
function waitForBackend() { | |
browser.wait(function () { | |
//console.log(myResponse); | |
console.log(gotResponse); | |
return gotResponse; | |
}, 5000); | |
} | |
var options = { | |
hostname: '127.0.0.1', | |
port: 9010, | |
path: '/beam-app/rest/support/config?username=protractor&roles=beam_Bestellungen,beam_IT_Entwicklung', | |
//path: '/support/config/change', | |
method: 'GET', | |
headers: { | |
'Accept': 'application/json' | |
//'token': 'XXXXXXXX' | |
} | |
}; | |
var req = http.request(options, function (res) { | |
console.log('STATUS: ' + res.statusCode); | |
console.log('HEADERS: ' + JSON.stringify(res.headers)); | |
res.setEncoding('utf8'); | |
res.on('data', function (chunk) { | |
console.log('BODY: ' + chunk); | |
gotResponse = true; | |
//myResponse = JSON.parse(chunk); | |
//console.log(myResponse); | |
}); | |
}); | |
req.on('error', function (e) { | |
console.log('problem with request: ' + e.message); | |
}); | |
req.on('connect', function (res, socket, head) { | |
console.log('got connected!'); | |
}); | |
req.end(); | |
waitForBackend(); | |
}); | |
it('should send a put request to the config restlet.', function () { | |
var postData = JSON.stringify({ | |
'edit': true, | |
'key': 'beam.app.cacheheaders.disabled', | |
'value': 'true' | |
}); | |
var options = { | |
hostname: '127.0.0.1', | |
port: 9010, | |
//path: '/beam-app/rest/support/config/change?username=protractor&roles=beam_Bestellungen,beam_IT_Entwicklung', | |
path: '/beam/services/rest/extended-services/support/config/change?username=protractor&roles=beam_Bestellungen,beam_IT_Entwicklung', | |
method: 'POST', | |
headers: { | |
//'Accept': 'application/json', | |
'Content-Type': 'application/json;charset=UTF-8', | |
'Content-Length': postData.length | |
} | |
}; | |
var req = http.request(options, function (res) { | |
console.log('STATUS: ' + res.statusCode); | |
console.log('HEADERS: ' + JSON.stringify(res.headers)); | |
res.setEncoding('utf8'); | |
res.on('data', function (chunk) { | |
console.log('BODY: ' + chunk); | |
}); | |
}); | |
req.on('error', function (e) { | |
console.log('problem with request: ' + e.message); | |
}); | |
// write data to request body | |
req.write(postData); | |
req.end(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment