-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.groovy
57 lines (50 loc) · 1.7 KB
/
test.groovy
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
import static net.grinder.script.Grinder.grinder
import static org.junit.Assert.*
import static org.hamcrest.Matchers.*
import net.grinder.plugin.http.HTTPRequest
import net.grinder.script.GTest
import net.grinder.script.Grinder
import net.grinder.scriptengine.groovy.junit.GrinderRunner
import net.grinder.scriptengine.groovy.junit.annotation.BeforeThread
import net.grinder.scriptengine.groovy.junit.annotation.BeforeProcess
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
import HTTPClient.HTTPResponse
/**
* A simple example using the HTTP plugin that shows the retrieval of a
* single page via HTTP.
*
* This script is auto generated by ngrinder.
*
* @author ${userName}
*/
@RunWith(GrinderRunner)
class test {
public static GTest test;
public static HTTPRequest request;
// This method is executed once per a process.
@BeforeProcess
public static void beforeClass() {
test = new GTest(1, "${name}");
request = new HTTPRequest();
test.record(request);
grinder.logger.info("before process.");
}
// This method is executed once per a thread.
@BeforeThread
public void beforeThread() {
grinder.statistics.delayReports=true;
grinder.logger.info("before thread.");
}
// This method is continuously executed until you stop the test
@Test
public void test(){
HTTPResponse result = request.GET("${url}");
if (result.statusCode == 301 || result.statusCode == 302) {
grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", result.statusCode);
} else {
assertThat(result.statusCode, is(200));
}
}
}