RestResponse.assertBody behavior is broken
RestResponse.assertBody behavior is broken: it is checking all the Response string when it should only check the body part of string.
This makes impossible for testing when we got an empty message body from server, because assertBody considers header section too when asserting if message body has some content.
Please refer to FtRemotesTest on https://github.com;yegor256/takes to see how this method is misbehaving.
@yegor256/z please, pay attention to this issue
@paulodamaso/z this project will fix the problem faster if you donate a few dollars to it; just click here and pay via Stripe, it's very fast, convenient and appreciated; thanks a lot!
@yegor256 @paulodamaso after some investigation (for yegor256/takes#800), I think the problem is not with assertBody but with the way body is parsed by jcabi-http.
Take those four examples (using takes).
Expected empty body: it fails, because the body, according to RestResponse, is HTTP/1.1 200 OK\r\n\r\n:
@Test
public void returnsAnEmptyResponseBody() throws IOException {
new FtRemote(
new TkEmpty()
).exec(
new FtRemote.Script() {
@Override
public void exec(final URI home) throws IOException {
new JdkRequest(home)
.method("POST")
.body().set("returnsAnEmptyResponseBody").back()
.fetch()
.as(RestResponse.class)
.assertBody(new IsEqual<>(""))
.assertStatus(HttpURLConnection.HTTP_OK);
}
}
);
}
The same with ApacheRequest fails in the same way.
@Test
public void returnsANonEmptyResponseBody() throws IOException {
new FtRemote(
new TkText("test")
).exec(
new FtRemote.Script() {
@Override
public void exec(final URI home) throws IOException {
new JdkRequest(home)
.method("POST")
.body().set("returnsAnEmptyResponseBody").back()
.fetch()
.as(RestResponse.class)
.assertBody(new IsEqual<>("test"))
.assertStatus(HttpURLConnection.HTTP_OK);
}
}
);
}
Now expecting a body, it's even worse, the returned body is: testHTTP/1.1 200 OK\r\nContent-Length: 4\r\nContent-Type: text/plain\r\n\r\ntest!
@Test
public void returnsANonEmptyResponseBody() throws IOException {
new FtRemote(
new TkText("test")
).exec(
new FtRemote.Script() {
@Override
public void exec(final URI home) throws IOException {
new JdkRequest(home)
.method("POST")
.body().set("returnsAnEmptyResponseBody").back()
.fetch()
.as(RestResponse.class)
.assertBody(new IsEqual<>("test"))
.assertStatus(HttpURLConnection.HTTP_OK);
}
}
);
}
But if you use ApacheRequest, then everything works as expected!
@Test
public void returnsANonEmptyResponseBody() throws IOException {
new FtRemote(
new TkText("test")
).exec(
new FtRemote.Script() {
@Override
public void exec(final URI home) throws IOException {
new ApacheRequest(home)
.method("POST")
.body().set("returnsAnEmptyResponseBody").back()
.fetch()
.as(RestResponse.class)
.assertBody(new IsEqual<>("test"))
.assertStatus(HttpURLConnection.HTTP_OK);
}
}
);
}
I have also tested the same test with rest-assured instead of jcabi-http, and it passes without any problem.
@yegor256 ping
@yegor256 What do you think about it? If this ticket is valid please put it on scope, we have a ticket on takes that depends on it.
@paulodamaso done
Job #177 is now in scope, role is DEV
@yegor256/z everybody who has role DEV is banned at #177; I won't be able to assign anyone automatically; consider assigning someone manually (as in §19), or invite more people (as in §51), or remove the job from the scope (as in §14)
@yegor256/z everybody who has role DEV is banned at #177; I won't be able to assign anyone automatically; consider assigning someone manually (as in §19), or invite more people (as in §51), or remove the job from the scope (as in §14)
@yegor256/z everybody who has role DEV is banned at #177; I won't be able to assign anyone automatically; consider assigning someone manually (as in §19), or invite more people (as in §51), or remove the job from the scope (as in §14)
@yegor256/z everybody who has role DEV is banned at #177; I won't be able to assign anyone automatically; consider assigning someone manually (as in §19), or invite more people (as in §51), or remove the job from the scope (as in §14)
@yegor256/z everybody who has role DEV is banned at #177; I won't be able to assign anyone automatically; consider assigning someone manually (as in §19), or invite more people (as in §51), or remove the job from the scope (as in §14)
@yegor256/z everybody who has role DEV is banned at #177; I won't be able to assign anyone automatically; consider assigning someone manually (as in §19), or invite more people (as in §51), or remove the job from the scope (as in §14)
@yegor256 assign to me
@yegor256/z everybody who has role DEV is banned at #177; I won't be able to assign anyone automatically; consider assigning someone manually (as in §19), or invite more people (as in §51), or remove the job from the scope (as in §14)
@yegor256/z everybody who has role DEV is banned at #177; I won't be able to assign anyone automatically; consider assigning someone manually (as in §19), or invite more people (as in §51), or remove the job from the scope (as in §14)
@yegor256/z everybody who has role DEV is banned at #177; I won't be able to assign anyone automatically; consider assigning someone manually (as in §19), or invite more people (as in §51), or remove the job from the scope (as in §14)
@yegor256/z everybody who has role DEV is banned at #177; I won't be able to assign anyone automatically; consider assigning someone manually (as in §19), or invite more people (as in §51), or remove the job from the scope (as in §14)
@yegor256/z everybody who has role DEV is banned at #177; I won't be able to assign anyone automatically; consider assigning someone manually (as in §19), or invite more people (as in §51), or remove the job from the scope (as in §14)
@yegor256/z everybody who has role DEV is banned at #177; I won't be able to assign anyone automatically; consider assigning someone manually (as in §19), or invite more people (as in §51), or remove the job from the scope (as in §14)
@yegor256/z everybody who has role DEV is banned at #177; I won't be able to assign anyone automatically; consider assigning someone manually (as in §19), or invite more people (as in §51), or remove the job from the scope (as in §14)
@yegor256/z everybody who has role DEV is banned at #177; I won't be able to assign anyone automatically; consider assigning someone manually (as in §19), or invite more people (as in §51), or remove the job from the scope (as in §14)
@yegor256/z everybody who has role DEV is banned at #177; I won't be able to assign anyone automatically; consider assigning someone manually (as in §19), or invite more people (as in §51), or remove the job from the scope (as in §14)
@yegor256/z everybody who has role DEV is banned at #177; I won't be able to assign anyone automatically; consider assigning someone manually (as in §19), or invite more people (as in §51), or remove the job from the scope (as in §14)
@yegor256/z everybody who has role DEV is banned at #177; I won't be able to assign anyone automatically; consider assigning someone manually (as in §19), or invite more people (as in §51), or remove the job from the scope (as in §14)
@yegor256 Please pay attention to this issue. Please see We need this issue be resolved to fix tests in Takes project
@yegor256/z everybody who has role DEV is banned at #177; I won't be able to assign anyone automatically; consider assigning someone manually (as in §19), or invite more people (as in §51), or remove the job from the scope (as in §14)