-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
64 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -250,4 +250,4 @@ public String getMessageFormat() { | |
public String getLoggingFormat() { | ||
return loggingFormat; | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
.../groovy/com/yahoo/bard/webservice/druid/client/impl/AsyncDruidWebServiceImplV2Spec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2016 Yahoo Inc. | ||
// Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms. | ||
package com.yahoo.bard.webservice.druid.client.impl | ||
|
||
import com.yahoo.bard.webservice.druid.client.DruidServiceConfig | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
|
||
import spock.lang.Specification | ||
|
||
import org.asynchttpclient.Response | ||
|
||
import java.util.function.Supplier; | ||
|
||
class AsyncDruidWebServiceImplV2Spec extends Specification { | ||
def "Make sure X-Druid-Response-Context and status-code are mreged into existing JsonNode"() { | ||
given: | ||
Response response = Mock(Response) | ||
response.getResponseBody() >> | ||
""" | ||
{"k1":"v1"} | ||
""" | ||
response.getHeader("X-Druid-Response-Context") >> | ||
""" | ||
{ | ||
"uncoveredIntervals": [ | ||
"2016-11-22T00:00:00.000Z/2016-12-18T00:00:00.000Z", | ||
"2016-12-25T00:00:00.000Z/2017-01-03T00:00:00.000Z" | ||
], | ||
"uncoveredIntervalsOverflowed": true | ||
} | ||
""".replace(" ", "").replace("\n", "") | ||
response.getStatusCode() >> 200 | ||
|
||
DruidServiceConfig druidServiceConfig = Mock(DruidServiceConfig) | ||
druidServiceConfig.getTimeout() >> 100 | ||
druidServiceConfig.getUrl() >> "url" | ||
AsyncDruidWebServiceImplV2 asyncDruidWebServiceImplV2 = new AsyncDruidWebServiceImplV2( | ||
druidServiceConfig, | ||
new ObjectMapper(), | ||
Mock(Supplier) | ||
) | ||
|
||
expect: | ||
print asyncDruidWebServiceImplV2.constructJsonResponse(response) | ||
asyncDruidWebServiceImplV2.constructJsonResponse(response).toString() == | ||
""" | ||
{ | ||
"k1":"v1", | ||
"X-Druid-Response-Context": "{ | ||
\\"uncoveredIntervals\\": [ | ||
\\"2016-11-22T00:00:00.000Z/2016-12-18T00:00:00.000Z\\", | ||
\\"2016-12-25T00:00:00.000Z/2017-01-03T00:00:00.000Z\\" | ||
], | ||
\\"uncoveredIntervalsOverflowed\\": true | ||
}", | ||
"status-code": 200 | ||
} | ||
""".replace(" ", "").replace("\n", "") | ||
} | ||
} |