/** * A simple example using the HTTP plugin that shows the retrieval of a single page via HTTP. * * This script is automatically generated by ngrinder. * * @author admin */ @RunWith(GrinderRunner) classTestRunner {
publicstatic GTest test publicstatic HTTPRequest request public List<Header> headers = [ new BasicHeader("Content-Type", "application/octet-stream") ] publicstatic Map<String, Object> params = [:] publicstatic List<Cookie> cookies = []
@BeforeProcess publicstaticvoid beforeProcess() { HTTPRequestControl.setConnectionTimeout(300000) test = new GTest(1, "Test1") request = new HTTPRequest() grinder.logger.info("before process.") }
@Test publicvoid test() { def message = new PostProtos.SavePost() def data = message.newBuilder().setTitle("this is title").setContent("this is content").setTag("this is tag").build() HTTPResponse response = request.POST("http://localhost:3000/save-post", data.toByteArray()) def readMsg = new PostProtos.ReadPost() def readData = readMsg.parseFrom(response.getBodyBytes()) grinder.logger.info("id:" + readData.getId()) grinder.logger.info("nickname:" + readData.getNickname())
if (response.statusCode == 301 || response.statusCode == 302) { grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", response.statusCode) } else { assertThat(response.statusCode, is(200)) } } }