-
Notifications
You must be signed in to change notification settings - Fork 181
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
Conversation
There was a problem hiding this 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
auction, cookiesync, amp, setuid, | ||
video |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant change
testing/appnexus.sh
Outdated
@@ -0,0 +1,103 @@ | |||
#!/bin/sh |
There was a problem hiding this comment.
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); | |||
|
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove.
// then | ||
|
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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.
Added content-type header to /vtrack and /status endpoints, checked code via tests