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

Add content-type header to /vtrack and /status endpoints #1399

Merged
merged 10 commits into from
Aug 10, 2021
Merged

Conversation

javaAndScriptDeveloper
Copy link
Contributor

@javaAndScriptDeveloper javaAndScriptDeveloper commented Aug 2, 2021

Added content-type header to /vtrack and /status endpoints, checked code via tests

@rpanchyk rpanchyk changed the title Adding headers to vtrack and status Add content-type header to /vtrack and /status endpoints Aug 2, 2021
@rpanchyk rpanchyk self-requested a review August 2, 2021 14:09
Copy link
Collaborator

@SerhiiNahornyi SerhiiNahornyi left a comment

Choose a reason for hiding this comment

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

Pls, add unit tests

Comment on lines 5 to 6
auction, cookiesync, amp, setuid,
video
Copy link
Collaborator

Choose a reason for hiding this comment

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

Redundant change

@@ -0,0 +1,103 @@
#!/bin/sh
Copy link
Collaborator

Choose a reason for hiding this comment

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

Pls remove this file

@@ -53,7 +53,6 @@ public ContextRunner(Vertx vertx, long timeoutMs) {
private <T> void runOnContext(Supplier<Context> contextFactory, int times, Handler<Promise<T>> action) {
final CountDownLatch completionLatch = new CountDownLatch(times);
final AtomicBoolean actionFailed = new AtomicBoolean(false);

Copy link
Collaborator

Choose a reason for hiding this comment

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

Redundant change

@@ -27,6 +28,7 @@ public StatusHandler(List<HealthChecker> healthCheckers, JacksonMapper mapper) {

@Override
public void handle(RoutingContext routingContext) {
routingContext.response().putHeader(HttpUtil.CONTENT_TYPE_HEADER, HttpHeaderValues.APPLICATION_JSON);
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be done in lambda below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

idk why, but having this done in lambda crashes test

@@ -189,6 +190,7 @@ private static void respondWithServerError(RoutingContext routingContext, String
}

private static void respondWith(RoutingContext routingContext, HttpResponseStatus status, String body) {
routingContext.response().putHeader(HttpUtil.CONTENT_TYPE_HEADER, HttpHeaderValues.APPLICATION_JSON);
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be done in lambda below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

idk why, but having this done in lambda crashes test

@@ -49,20 +51,24 @@ public void shouldRespondHttp200OkWithExpectedBody() throws JsonProcessingExcept
final ZonedDateTime testTime = ZonedDateTime.now(Clock.systemUTC());
statusHandler = new StatusHandler(Arrays.asList(healthCheck, healthCheck, healthCheck), jacksonMapper);

given(routingContext.response()).willReturn(httpResponse);
//given(routingContext.response()).willReturn(httpResponse);
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove.

// then

Copy link
Contributor

Choose a reason for hiding this comment

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

Redundant line.
PS. Please, keep your code clean.

@@ -94,10 +98,25 @@ public void shouldRespondWithBadRequestWhenAccountParameterIsMissing() {
verify(httpResponse).end(eq("Account 'a' is required query parameter and can't be empty"));
}

@Test
public void contentTypeHeaderAdded() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Test method must be in style: shouldRespondWithExpectedHeaders.
Please see existing tests as example.

@Test
public void contentTypeHeaderAdded() {
// given
given(httpResponse.putHeader(HttpUtil.CONTENT_TYPE_HEADER, HttpHeaderValues.APPLICATION_JSON))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why?

@Test
public void shouldRespondWithBadRequestWhenBodyIsEmpty() {
// given
given(routingContext.getBody()).willReturn(null);
given(httpResponse.putHeader(HttpUtil.CONTENT_TYPE_HEADER, HttpHeaderValues.APPLICATION_JSON))
Copy link
Contributor

Choose a reason for hiding this comment

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

You should create @Before method to setup conditions for each test.

@@ -129,7 +150,10 @@ public void shouldRespondWithBadRequestWhenBidIdIsMissing() throws JsonProcessin
// given
given(routingContext.getBody())
.willReturn(givenVtrackRequest(identity()));

given(httpResponse.putHeader(HttpUtil.CONTENT_TYPE_HEADER, HttpHeaderValues.APPLICATION_JSON))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why you check this here?
Test is about not parsable body.

Consider to change all below tests.

@@ -78,4 +82,23 @@ public void shouldRespondWithNoContentWhenMessageWasNotDefined() {
// then
verify(httpResponse).setStatusCode(eq(204));
}

@Test
public void shouldRespondWithContentTypeHeaders() throws JsonProcessingException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Redundant throws.

@Test
public void shouldRespondWithContentTypeHeaders() throws JsonProcessingException {
// given
statusHandler = new StatusHandler(Arrays.asList(healthCheck), jacksonMapper);
Copy link
Contributor

Choose a reason for hiding this comment

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

Use singletonList (with static method import) instead.

given(healthCheck.status()).willReturn(StatusResponse.of("healthCheckStatus", null));

given(routingContext.response()).willReturn(httpResponse);
given(httpResponse.putHeader(HttpUtil.CONTENT_TYPE_HEADER, HttpHeaderValues.APPLICATION_JSON))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not required since the last point of test is to verify putHeader method.

@@ -165,6 +178,9 @@ public void shouldRespondWithInternalServerErrorWhenFetchingAccountFails() throw
given(applicationSettings.getAccountById(any(), any()))
.willReturn(Future.failedFuture("error"));

given(httpResponse.putHeader(HttpUtil.CONTENT_TYPE_HEADER, HttpHeaderValues.APPLICATION_JSON))
Copy link
Contributor

Choose a reason for hiding this comment

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

Redundant.

@@ -50,6 +52,8 @@ public void shouldRespondHttp200OkWithExpectedBody() throws JsonProcessingExcept
statusHandler = new StatusHandler(Arrays.asList(healthCheck, healthCheck, healthCheck), jacksonMapper);

given(routingContext.response()).willReturn(httpResponse);
given(httpResponse.putHeader(HttpUtil.CONTENT_TYPE_HEADER, HttpHeaderValues.APPLICATION_JSON))
Copy link
Contributor

Choose a reason for hiding this comment

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

Pls replace with:

given(httpResponse.putHeader(any(CharSequence.class), any(AsciiString.class))).willReturn(httpResponse);

since mocking conditions can be more generic.

@rpanchyk rpanchyk merged commit 1a44239 into master Aug 10, 2021
@rpanchyk rpanchyk deleted the l_branch branch August 10, 2021 08:14
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.

3 participants