-
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
Dennis J. McWherter Jr
committed
Oct 14, 2016
1 parent
bd27132
commit 4374c78
Showing
1 changed file
with
95 additions
and
0 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
fili-core/src/test/groovy/com/yahoo/bard/webservice/web/endpoints/DruidQueryIdSpec.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,95 @@ | ||
// 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.web.endpoints | ||
|
||
import com.yahoo.bard.webservice.data.dimension.BardDimensionField | ||
import com.yahoo.bard.webservice.data.dimension.DimensionDictionary | ||
import com.yahoo.bard.webservice.util.JsonSlurper | ||
import com.yahoo.bard.webservice.util.JsonSortStrategy | ||
import com.yahoo.bard.webservice.web.filters.BardLoggingFilter | ||
|
||
import javax.ws.rs.core.Response | ||
|
||
|
||
class DruidQueryIdSpec extends BaseDataServletComponentSpec { | ||
def prefixId = "abcdef" | ||
static def testedDruidQuery = false | ||
|
||
@Override | ||
def setup() { | ||
DimensionDictionary dimensionStore = jtb.configurationLoader.dimensionDictionary | ||
dimensionStore.findByApiName("color").with { | ||
addDimensionRow(BardDimensionField.makeDimensionRow(it, "Foo", "FooDesc")) | ||
addDimensionRow(BardDimensionField.makeDimensionRow(it, "Bar", "BarDesc")) | ||
addDimensionRow(BardDimensionField.makeDimensionRow(it, "Baz", "BazDesc")) | ||
} | ||
} | ||
|
||
@Override | ||
Class<?>[] getResourceClasses() { | ||
[ DataServlet.class | ||
, BardLoggingFilter.class ] | ||
} | ||
|
||
@Override | ||
String getTarget() { | ||
return "data/shapes/week/color" | ||
} | ||
|
||
@Override | ||
Map<String, List<String>> getQueryParams() { | ||
[ | ||
"metrics": ["width","depth"], | ||
"dateTime": ["2014-06-02%2F2014-06-30"], | ||
"sort": ["width|desc","depth|asc"] | ||
] | ||
} | ||
|
||
@Override | ||
boolean compareResult(String result, String expectedResult, JsonSortStrategy sortStrategy = JsonSortStrategy.SORT_MAPS) { | ||
if (!testedDruidQuery) { | ||
JsonSlurper slurper = new JsonSlurper(sortStrategy) | ||
def parsedJson = slurper.parseText(result) | ||
testedDruidQuery = true | ||
return parsedJson.context.queryId.startsWith(prefixId) | ||
} | ||
// Only do this for druid test. We're noop'ing everything else. Only testing for queryId prefix. | ||
return true | ||
} | ||
|
||
@Override | ||
String getExpectedDruidQuery() { | ||
// Noop | ||
"""{}""" | ||
} | ||
|
||
@Override | ||
String getFakeDruidResponse() { | ||
// Noop | ||
"""[]""" | ||
} | ||
|
||
@Override | ||
String getExpectedApiResponse() { | ||
// Noop | ||
"""{}""" | ||
} | ||
|
||
@Override | ||
Response makeAbstractRequest(Closure queryParams=this.&getQueryParams) { | ||
// Set target of call | ||
def httpCall = jtb.getHarness().target(getTarget()) | ||
|
||
// Add query params to call | ||
queryParams().each { String key, List<String> values -> | ||
httpCall = httpCall.queryParam(key, values.join(",")) | ||
} | ||
|
||
// Make the call | ||
Response response = httpCall.request().header("X-Request-ID", prefixId).get() | ||
if (response.status != 200) { | ||
LOG.error( "*** *** Response status: ${response.status}: ${response.readEntity(String)}") | ||
} | ||
response | ||
} | ||
} |