Skip to content

Commit

Permalink
Added queryId test.
Browse files Browse the repository at this point in the history
  • 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.
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
}
}

0 comments on commit 4374c78

Please sign in to comment.