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

[PT-694] Do not throw exception for successful created http code #69

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Harmannz
Copy link

@Harmannz Harmannz commented May 18, 2021

The content-watch service returns 201 upon creation of a new watch.

Copy link

@dylannz-sailthru dylannz-sailthru left a comment

Choose a reason for hiding this comment

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

Looks OK to me, may want review from NY or SRE team

Comment on lines 60 to 67
CloseableHttpResponse httCreatedResponse = getMockHttpResponseWithStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Internal Server Error");
try {
Object okResponse = handler.handleResponse(httCreatedResponse);
Assert.fail("Expected an APIException to be thrown");

Choose a reason for hiding this comment

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

nit:

Suggested change
CloseableHttpResponse httCreatedResponse = getMockHttpResponseWithStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Internal Server Error");
try {
Object okResponse = handler.handleResponse(httCreatedResponse);
Assert.fail("Expected an APIException to be thrown");
CloseableHttpResponse httpCreatedResponse = getMockHttpResponseWithStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Internal Server Error");
try {
Object okResponse = handler.handleResponse(httpCreatedResponse);
Assert.fail("Expected an APIException to be thrown");

Copy link
Author

Choose a reason for hiding this comment

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

ahh thats terrible copy past from me. brb with a fix

Copy link

@m1dcarry m1dcarry left a comment

Choose a reason for hiding this comment

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

LGTM

@Harmannz
Copy link
Author

Force pushed to update variable names for test method

Copy link
Contributor

@kryptx kryptx left a comment

Choose a reason for hiding this comment

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

Possibly I misunderstand something, but I think there are a couple more cases to handle.

@@ -33,6 +33,7 @@

/* Supported HTTP Status codes */
public static final int STATUS_OK = 200;
public static final int STATUS_CREATED = 201;
Copy link
Contributor

@kryptx kryptx May 18, 2021

Choose a reason for hiding this comment

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

Is there a reason we didn't also add 204 (this is returned by the DELETE endpoint)? Also the POST endpoint will return 409 if the watch already exists, it seems like that might be useful for a client to know.

Copy link
Author

Choose a reason for hiding this comment

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

Hey thanks for the feedback. I was planning to release this incrementally mainly to derisk my changes. But I think its easy for me to include the 202 and 204 code here.
409 and other http codes will still be thrown back to upstream via the default switch case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Aye, I was thinking the switch case below would just return some kind of generic error, but you're right, they can already pull the 409 status code out of that with no further changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

As for 202, I cannot see a reason the client should throw if we receive it, but if you still want to follow-up with a refactor proposal then I'd say it could be left out of this PR. We currently will never return 202 from PHP API.

Copy link
Author

Choose a reason for hiding this comment

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

Alright. So just need to add 204 code for the DELETE endpoint.

Copy link
Contributor

@mattdudys mattdudys left a comment

Choose a reason for hiding this comment

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

A style comment about unit testing expected exceptions. The main change of categorizing 201 and 204 looks good to me, +1.

Assert.fail("Expected an APIException to be thrown");
} catch (ApiException apiException) {
Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, apiException.getStatusCode());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Using ExceptionRule can help simplify these try-execute-fail-catch-assert patterns. https://junit.org/junit4/javadoc/4.12/org/junit/rules/ExpectedException.html

This looks like two tests in one method. Can you split them apart more? If you were to use ExceptionRule you would want to just test one response at a time.

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

Successfully merging this pull request may close these issues.

None yet

6 participants