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

Get rid of our REST testing classes in favor of REST Assured #429

Merged
merged 2 commits into from
Jan 4, 2019
Merged

Get rid of our REST testing classes in favor of REST Assured #429

merged 2 commits into from
Jan 4, 2019

Conversation

gsmet
Copy link
Member

@gsmet gsmet commented Jan 3, 2019

REST assured was used in a few places but not consistently.

In passing, fix an issue in the test framework changes I made a few weeks ago.

I mistakenly thought that the other callback was not executed on test
failure but it is indeed executed and we want all the other tests to be
able to run.
@gsmet
Copy link
Member Author

gsmet commented Jan 3, 2019

Hmmm, there is a weird test failure when running the native image tests, looking.

@gsmet gsmet added this to the 0.5.0 milestone Jan 3, 2019
@gsmet
Copy link
Member Author

gsmet commented Jan 3, 2019

OK, CI is happy now.

Copy link
Member

@cescoffier cescoffier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few comments.

@@ -52,8 +52,7 @@ public static JavaArchive deploy() {

@Test
public void testHealthServlet() {
URLResponse rep = URLTester.relative("health").invokeURL();
Assert.assertEquals(503, rep.statusCode());
RestAssured.when().get("/health").then().statusCode(503);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can directly use: get(...), but it's a question of flavors.

// the health check does not set a content type so we need to force the parser
try {
RestAssured.defaultParser = Parser.JSON;
RestAssured.when().get("/health").then()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you use static import for hamcrest, why not using the same for rest assured and so just do:

get("/health")...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was more so that people know what they are using.

People are used to hamcrest assertions being static but I didn't want a magic get(...) that people don't know where it's coming from.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense!

Assert.assertEquals("basic", check.getString("name"));
// the health check does not set a content type so we need to force the parser
try {
RestAssured.defaultParser = Parser.JSON;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be in a beforeClass method?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it all depends on what your service returns so I prefer to do it on a per call basis.

I'm not very familiar with this health thing so I don't know if it can also produce XML. But I decided go per call to be on the safe side.

I can change it if you prefer though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it can only return JSON (at least in the initial version of the spec).

@kenfinnigan can you confirm?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, it would help if it included a proper content type. We could then remove these calls.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cescoffier maybe we could merge and adjust later if needed? I'm a bit worried that we could have annoying conflicts, considering it touches a lot of places.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the spec only defines JSON return type, yes

"checks.state", contains("UP"),
"checks.name", contains("basic"));
} finally {
RestAssured.reset();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be in an afterClass method?

@cescoffier
Copy link
Member

cescoffier commented Jan 4, 2019 via email

@gsmet
Copy link
Member Author

gsmet commented Jan 4, 2019

@cescoffier agreed it should be fixed in smallrye, just not sure which project is the culprit though. @kenfinnigan can probably help with that.

In the mean time, I think what I did is acceptable and we can get rid of it as soon as it's fixed upstream and we have updated Shamrock.

I don't think we will add new tests to these classes anyway.

@kenfinnigan
Copy link
Member

Can you clarify what should be "fixed" in SmallRye? Can then take a look

@gsmet
Copy link
Member Author

gsmet commented Jan 4, 2019

@kenfinnigan currently, the end point does not set the content-type of the response (e.g. application/json typically). Thus REST Assured can't guess the parser to use.

I'm talking about REST Assured but it could be an issue for a lot of usages: it is considered a good practice to define a proper content-type for your response. I took a quick look at the SmallRye health project but it seems to write to an OutputStream so it would need to be fixed more globally.

@kenfinnigan
Copy link
Member

Gotcha, we can certainly look to fix that for SmallRye Health

@gsmet
Copy link
Member Author

gsmet commented Jan 4, 2019

@kenfinnigan so I'll merge this for now, and when SmallRye is fixed, please ping me so I can remove the workaround.

@gsmet gsmet merged commit 1834f33 into quarkusio:master Jan 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants