Skip to content

Instantly share code, notes, and snippets.

@azamara
Forked from kpiwko/gist:6192925
Created June 23, 2014 05:22
Show Gist options
  • Save azamara/3dbef2e9444a3a852730 to your computer and use it in GitHub Desktop.
Save azamara/3dbef2e9444a3a852730 to your computer and use it in GitHub Desktop.
@RunWith(GrinderRunner)
class Test1 {
def rootUrl= "http://agpushmedium-arqtest.rhcloud.com"
static GTest test;
static HTTPRequest request;
// This method is executed once per a process.
@BeforeProcess
static void beforeClass() {
test = new GTest(1, "Test name")
request = new HTTPRequest();
test.record(request);
grinder.logger.info("before process.");
}
// This method is executed once per a thread.
@BeforeThread
void beforeThread() {
grinder.statistics.delayReports=true;
grinder.logger.info("before thread.");
}
@AfterThread
void afterProcess() {
grinder.logger.info("after thread.")
grinder.statistics.report()
}
@Test
void registerApp(){
HTTPResponse result = request.POST("${rootUrl}/rest/applications", json { name "myApp"; description "MyApp Description"}, registrationHeaders());
if (result.statusCode != 201 ) {
grinder.logger.warn("Warning. The response may not be correct. The response code was {} - {}.", result.statusCode, result.getInputStream().text);
grinder.getStatistics().getForLastTest().setSuccess(false)
}
}
// enable direct invocation of json closure to all test writers
// to construct Json objects in very simple DSL like way
//
// json {
// name "ddd"
// description "ddd"
// }
//
def Closure json = new Closure(this, this) {
def doCall(Object args) {
JsonOutput.toJson(new JsonBuilder().call(args)).bytes
}
}
private NVPair[] registrationHeaders() {
return [
new NVPair("Content-Type", "application/json"),
new NVPair("Accept", "application/json")
// missing cookies
];
}
private void login() {
HTTPRequest authReq = new HTTPRequest();
HTTPResponse authRes = request.POST("${rootUrl}/rest/auth/login", json {loginName "admin"; password "opensource"});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment