Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RestResponse.assertBody behavior is broken #177

Open
paulodamaso opened this issue Sep 24, 2018 · 38 comments
Open

RestResponse.assertBody behavior is broken #177

paulodamaso opened this issue Sep 24, 2018 · 38 comments

Comments

@paulodamaso
Copy link

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.

@0crat
Copy link

0crat commented Sep 24, 2018

@yegor256/z please, pay attention to this issue

@0crat
Copy link

0crat commented Sep 24, 2018

@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!

@victornoel
Copy link

@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.

@paulodamaso
Copy link
Author

@yegor256 ping

@paulodamaso
Copy link
Author

@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.

@yegor256 yegor256 added the bug label Dec 25, 2018
@yegor256
Copy link
Member

@paulodamaso done

@0crat 0crat added the scope label Dec 25, 2018
@0crat
Copy link

0crat commented Dec 25, 2018

Job #177 is now in scope, role is DEV

@0crat
Copy link

0crat commented Dec 25, 2018

Bug was reported, see §29: +15 point(s) just awarded to @paulodamaso/z

@0crat
Copy link

0crat commented Dec 25, 2018

@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)

@0crat
Copy link

0crat commented Dec 30, 2018

@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)

@0crat
Copy link

0crat commented Jan 4, 2019

@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)

@0crat
Copy link

0crat commented Jan 9, 2019

@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)

@0crat
Copy link

0crat commented Jan 14, 2019

@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)

@0crat
Copy link

0crat commented Jan 19, 2019

@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)

@fabriciofx
Copy link

@yegor256 assign to me

@0crat
Copy link

0crat commented Jan 24, 2019

@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)

@0crat
Copy link

0crat commented Jan 29, 2019

@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)

@0crat
Copy link

0crat commented Feb 3, 2019

@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)

@0crat
Copy link

0crat commented Feb 9, 2019

@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)

@0crat
Copy link

0crat commented Feb 14, 2019

@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)

@0crat
Copy link

0crat commented Feb 19, 2019

@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)

@0crat
Copy link

0crat commented Feb 24, 2019

@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)

@0crat
Copy link

0crat commented Mar 1, 2019

@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)

@0crat
Copy link

0crat commented Mar 6, 2019

@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)

@0crat
Copy link

0crat commented Mar 11, 2019

@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)

@0crat
Copy link

0crat commented Mar 16, 2019

@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)

@fanifieiev
Copy link

@yegor256 Please pay attention to this issue. Please see
We need this issue be resolved to fix tests in Takes project

@0crat
Copy link

0crat commented Nov 18, 2019

@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)

@0crat
Copy link

0crat commented Nov 23, 2019

@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)

@0crat
Copy link

0crat commented Nov 28, 2019

@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)

@0crat
Copy link

0crat commented Dec 3, 2019

@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)

@0crat
Copy link

0crat commented Dec 8, 2019

@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)

@0crat
Copy link

0crat commented Dec 14, 2019

@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)

@0crat
Copy link

0crat commented Dec 20, 2019

@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)

@0crat
Copy link

0crat commented Dec 25, 2019

@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)

@0crat
Copy link

0crat commented Dec 30, 2019

@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)

@0crat
Copy link

0crat commented Jan 4, 2020

@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)

@0crat
Copy link

0crat commented Jan 10, 2020

@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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants