public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>> extends ESTestCase
ESTestCase.GeohashGenerator, ESTestCase.TestAnalysis
org.apache.lucene.util.LuceneTestCase.AwaitsFix, org.apache.lucene.util.LuceneTestCase.BadApple, org.apache.lucene.util.LuceneTestCase.Monster, org.apache.lucene.util.LuceneTestCase.Nightly, org.apache.lucene.util.LuceneTestCase.Slow, org.apache.lucene.util.LuceneTestCase.SuppressCodecs, org.apache.lucene.util.LuceneTestCase.SuppressFileSystems, org.apache.lucene.util.LuceneTestCase.SuppressFsync, org.apache.lucene.util.LuceneTestCase.SuppressReproduceLine, org.apache.lucene.util.LuceneTestCase.SuppressSysoutChecks, org.apache.lucene.util.LuceneTestCase.SuppressTempFileChecks, org.apache.lucene.util.LuceneTestCase.ThrowingRunnable, org.apache.lucene.util.LuceneTestCase.Weekly
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
BOOLEAN_FIELD_NAME |
protected static java.lang.String |
DATE_FIELD_NAME |
protected static java.lang.String |
DATE_RANGE_FIELD_NAME |
protected static java.lang.String |
DOUBLE_FIELD_NAME |
protected static java.lang.String |
GEO_POINT_FIELD_NAME |
protected static java.lang.String |
GEO_SHAPE_FIELD_NAME |
protected static java.lang.String |
INT_FIELD_NAME |
protected static java.lang.String |
INT_RANGE_FIELD_NAME |
protected static java.lang.String |
LEGACY_GEO_POINT_FIELD_MAPPING |
protected static java.lang.String[] |
MAPPED_FIELD_NAMES |
protected static java.lang.String[] |
MAPPED_LEAF_FIELD_NAMES |
protected static java.lang.String |
OBJECT_FIELD_NAME |
static java.lang.String |
STRING_FIELD_NAME |
protected static java.lang.String |
STRING_FIELD_NAME_2 |
checkIndexFailed, deprecationLogger, failureAndSuccessEvents, logger
assertsAreEnabled, classRules, DEFAULT_LINE_DOCS_FILE, INFOSTREAM, JENKINS_LARGE_LINE_DOCS_FILE, LEAVE_TEMPORARY, MAYBE_CACHE_POLICY, RANDOM_MULTIPLIER, ruleChain, suiteFailureMarker, SYSPROP_AWAITSFIX, SYSPROP_BADAPPLES, SYSPROP_FAILFAST, SYSPROP_MAXFAILURES, SYSPROP_MONSTER, SYSPROP_NIGHTLY, SYSPROP_SLOW, SYSPROP_WEEKLY, TEST_ASSERTS_ENABLED, TEST_AWAITSFIX, TEST_CODEC, TEST_DIRECTORY, TEST_DOCVALUESFORMAT, TEST_LINE_DOCS_FILE, TEST_NIGHTLY, TEST_POSTINGSFORMAT, TEST_SLOW, TEST_THROTTLING, TEST_WEEKLY, VERBOSE
Constructor and Description |
---|
AbstractQueryTestCase() |
Modifier and Type | Method and Description |
---|---|
static void |
afterClass() |
void |
afterTest() |
protected void |
assertParsedQuery(java.lang.String queryAsString,
QueryBuilder expectedQuery)
Parses the query provided as string argument and compares it with the expected result provided as argument as a
QueryBuilder |
protected static QueryBuilder |
assertSerialization(QueryBuilder testQuery) |
protected static QueryBuilder |
assertSerialization(QueryBuilder testQuery,
Version version)
Serialize the given query builder and asserts that both are equal
|
protected static void |
assertTermOrBoostQuery(Query query,
java.lang.String field,
java.lang.String value,
float fieldBoost) |
protected static void |
assertTermQuery(Query query,
java.lang.String field,
java.lang.String value) |
static void |
beforeClass() |
void |
beforeTest() |
protected boolean |
builderGeneratesCacheableQueries()
Whether the queries produced by this builder are expected to be cacheable.
|
static void |
checkGeneratedJson(java.lang.String expected,
QueryBuilder source)
Call this method to check a valid json string representing the query under test against
it's generated json.
|
protected static QueryParseContext |
createParseContext(XContentParser parser) |
protected static QueryShardContext |
createShardContext() |
QB |
createTestQueryBuilder() |
protected abstract void |
doAssertLuceneQuery(QB queryBuilder,
Query query,
SearchContext context)
Checks the result of
QueryBuilder.toQuery(QueryShardContext) given the original QueryBuilder
and QueryShardContext . |
protected abstract QB |
doCreateTestQueryBuilder()
Create the query that is being tested
|
protected GetResponse |
executeGet(GetRequest getRequest)
Override this to handle
Client.get(GetRequest) calls from parsers / builders |
protected MultiTermVectorsResponse |
executeMultiTermVectors(MultiTermVectorsRequest mtvRequest)
Override this to handle
Client.get(GetRequest) calls from parsers / builders |
protected java.util.Map<java.lang.String,QB> |
getAlternateVersions()
Returns alternate string representation of the query that need to be tested as they are never used as output
of
ToXContent.toXContent(XContentBuilder, ToXContent.Params) . |
protected static java.lang.String[] |
getCurrentTypes() |
protected static Index |
getIndex() |
protected java.util.Set<java.lang.String> |
getObjectsHoldingArbitraryContent()
Returns a set of object names that won't trigger any exception (uncluding their children) when testing that unknown
objects cause parse exceptions through
testUnknownObjectException() . |
protected java.util.Collection<java.lang.Class<? extends Plugin>> |
getPlugins() |
protected static java.lang.String |
getRandomFieldName()
Helper method to return a mapped or a random field
|
protected static java.lang.String |
getRandomQueryText() |
protected static java.lang.String |
getRandomRewriteMethod()
Helper method to return a random rewrite method
|
protected static java.lang.Object |
getRandomValueForFieldName(java.lang.String fieldName)
create a random value for either
BOOLEAN_FIELD_NAME , INT_FIELD_NAME ,
DOUBLE_FIELD_NAME , STRING_FIELD_NAME or
DATE_FIELD_NAME , or a String value by default |
protected Settings |
indexSettings() |
protected void |
initializeAdditionalMappings(MapperService mapperService) |
protected boolean |
isCachable(QB queryBuilder) |
protected QueryBuilder |
parseQuery(AbstractQueryBuilder<?> builder) |
protected QueryBuilder |
parseQuery(java.lang.String queryAsString) |
protected static QueryBuilder |
parseQuery(XContentParser parser) |
protected static java.lang.String |
randomAnalyzer() |
protected static Fuzziness |
randomFuzziness(java.lang.String fieldName) |
protected static java.lang.String |
randomMinimumShouldMatch() |
protected Query |
rewrite(Query query) |
protected java.lang.String[] |
shuffleProtectedFields()
Subclasses can override this method and return an array of fieldnames which should be protected from
recursive random shuffling in the
testFromXContent() test case |
protected boolean |
supportsBoostAndQueryName()
Few queries allow you to set the boost and queryName on the java api, although the corresponding parser
doesn't parse them as they are not supported.
|
void |
testEqualsAndHashcode() |
void |
testFromXContent()
Generic test that creates new query from the test query and checks both for equality
and asserts equality on the two queries.
|
void |
testMustRewrite()
This test ensures that queries that need to be rewritten have dedicated tests.
|
void |
testQueryWrappedInArray()
Test that wraps the randomly generated query into an array as follows: { "query_name" : [{}]}
This causes unexpected situations in parser code that may not be handled properly.
|
void |
testSerialization()
Test serialization and deserialization of the test query.
|
void |
testToQuery()
Test creates the
Query from the QueryBuilder under test and delegates the
assertions being made on the result to the implementing subclass. |
void |
testUnknownField()
Test that unknown field trigger ParsingException.
|
void |
testUnknownObjectException()
Test that adding an additional object within each object of the otherwise correct query always triggers some kind of
parse exception.
|
protected NamedXContentRegistry |
xContentRegistry()
The
NamedXContentRegistry to use for this test. |
after, afterIfFailed, afterIfSuccessful, assertAllIndicesRemovedAndDeletionCompleted, assertArrayEquals, assertBusy, assertBusy, assertEquals, assertPathHasBeenCleared, assertSettingDeprecationsAndWarnings, assertWarnings, awaitBusy, awaitBusy, before, between, checkStaticState, copyWriteable, createParser, createParser, createParser, createParser, createParser, createTestAnalysis, createTestAnalysis, createTestAnalysis, enableWarningsCheck, ensureAllSearchContextsReleased, ensureCheckIndexPassed, frequently, generateRandomStringArray, generateRandomStringArray, getBwcIndicesPath, getDataPath, getSuiteFailureMarker, iterations, maybeSet, mockScript, newNodeEnvironment, newNodeEnvironment, newTestIndicesModule, newTestScriptModule, randomAlphaOfLength, randomAlphaOfLengthBetween, randomBoolean, randomByte, randomDateTimeZone, randomDouble, randomDoubleBetween, randomFloat, randomFrom, randomFrom, randomFrom, randomFrom, randomFrom, randomGeohash, randomInt, randomInt, randomIntBetween, randomLong, randomNonNegativeLong, randomPositiveTimeValue, randomRealisticUnicodeOfCodepointLength, randomRealisticUnicodeOfCodepointLengthBetween, randomRealisticUnicodeOfLength, randomRealisticUnicodeOfLengthBetween, randomShort, randomSubsetOf, randomSubsetOf, randomSubsetOf, randomTimeValue, randomTimeValue, randomTimeValue, randomUnicodeOfCodepointLength, randomUnicodeOfCodepointLengthBetween, randomUnicodeOfLength, randomUnicodeOfLengthBetween, randomUnique, randomValueOtherThan, randomValueOtherThanMany, resetCheckIndexStatus, restoreContentType, restoreFileSystem, scaledRandomIntBetween, setContentType, setFileSystem, settings, shuffleMap, shuffleXContent, shuffleXContent, spinForAtLeastNMilliseconds, spinForAtLeastOneMillisecond, terminate, terminate, tmpPaths, toShuffledXContent
addVirusChecker, assertDeletedDocsEquals, assertDocsAndPositionsEnumEquals, assertDocsEnumEquals, assertDocsSkippingEquals, assertDocValuesEquals, assertDocValuesEquals, assertFieldInfosEquals, assertFieldsEquals, assertFieldStatisticsEquals, assertNormsEquals, assertPointsEquals, assertPositionsSkippingEquals, assertReaderEquals, assertReaderStatisticsEquals, assertStoredFieldEquals, assertStoredFieldsEquals, assertTermsEnumEquals, assertTermsEquals, assertTermsStatisticsEquals, assertTermStatsEquals, assertTermVectorsEquals, asSet, assumeFalse, assumeNoException, assumeTrue, assumeWorkingMMapOnWindows, atLeast, atLeast, closeAfterSuite, closeAfterTest, collate, createTempDir, createTempDir, createTempFile, createTempFile, dumpArray, dumpIterator, expectThrows, expectThrows, getBaseTempDirForTestClass, getDataInputStream, getOnlyLeafReader, getTestClass, getTestName, hasWorkingMMapOnWindows, isTestThread, localeForLanguageTag, maybeChangeLiveIndexWriterConfig, maybeWrapReader, newAlcoholicMergePolicy, newAlcoholicMergePolicy, newDirectory, newDirectory, newDirectory, newDirectory, newDirectory, newField, newField, newFSDirectory, newFSDirectory, newIndexWriterConfig, newIndexWriterConfig, newIndexWriterConfig, newIOContext, newIOContext, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newMaybeVirusCheckingDirectory, newMaybeVirusCheckingFSDirectory, newMergePolicy, newMergePolicy, newMockDirectory, newMockDirectory, newMockDirectory, newMockFSDirectory, newMockFSDirectory, newSearcher, newSearcher, newSearcher, newStringField, newStringField, newStringField, newStringField, newTextField, newTextField, newTieredMergePolicy, newTieredMergePolicy, overrideDefaultQueryCache, overrideTestDefaultQueryCache, random, randomLocale, randomTimeZone, rarely, rarely, replaceMaxFailureRule, resetDefaultQueryCache, restoreCPUCoreCount, restoreIndexWriterMaxDocs, restoreSpins, runWithRestrictedPermissions, setIndexWriterMaxDocs, setUp, setupCPUCoreCount, setupSpins, slowFileExists, tearDown, usually, usually, wrapReader
assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertTrue, assertTrue, fail, fail
public static final java.lang.String STRING_FIELD_NAME
protected static final java.lang.String STRING_FIELD_NAME_2
protected static final java.lang.String INT_FIELD_NAME
protected static final java.lang.String INT_RANGE_FIELD_NAME
protected static final java.lang.String DOUBLE_FIELD_NAME
protected static final java.lang.String BOOLEAN_FIELD_NAME
protected static final java.lang.String DATE_FIELD_NAME
protected static final java.lang.String DATE_RANGE_FIELD_NAME
protected static final java.lang.String OBJECT_FIELD_NAME
protected static final java.lang.String GEO_POINT_FIELD_NAME
protected static final java.lang.String LEGACY_GEO_POINT_FIELD_MAPPING
protected static final java.lang.String GEO_SHAPE_FIELD_NAME
protected static final java.lang.String[] MAPPED_FIELD_NAMES
protected static final java.lang.String[] MAPPED_LEAF_FIELD_NAMES
protected static Index getIndex()
protected static java.lang.String[] getCurrentTypes()
protected java.util.Collection<java.lang.Class<? extends Plugin>> getPlugins()
protected void initializeAdditionalMappings(MapperService mapperService) throws java.io.IOException
java.io.IOException
public static void beforeClass()
protected Settings indexSettings()
public static void afterClass() throws java.lang.Exception
java.lang.Exception
public void beforeTest() throws java.io.IOException
java.io.IOException
public void afterTest()
public final QB createTestQueryBuilder()
protected abstract QB doCreateTestQueryBuilder()
public void testFromXContent() throws java.io.IOException
java.io.IOException
protected java.lang.String[] shuffleProtectedFields()
testFromXContent()
test casepublic void testUnknownField() throws java.io.IOException
java.io.IOException
public final void testUnknownObjectException() throws java.io.IOException
getObjectsHoldingArbitraryContent()
.java.io.IOException
protected java.util.Set<java.lang.String> getObjectsHoldingArbitraryContent()
testUnknownObjectException()
. Default is an empty set. Can be overridden
by subclasses that test queries which contain objects that get parsed on the data nodes (e.g. score functions) or objects
that can contain arbitrary content (e.g. documents for percolate or more like this query, params for scripts). In such
cases no exception would get thrown.public final void testQueryWrappedInArray()
protected java.util.Map<java.lang.String,QB> getAlternateVersions()
ToXContent.toXContent(XContentBuilder, ToXContent.Params)
. By default there are no alternate versions.protected void assertParsedQuery(java.lang.String queryAsString, QueryBuilder expectedQuery) throws java.io.IOException
QueryBuilder
java.io.IOException
protected QueryBuilder parseQuery(AbstractQueryBuilder<?> builder) throws java.io.IOException
java.io.IOException
protected QueryBuilder parseQuery(java.lang.String queryAsString) throws java.io.IOException
java.io.IOException
protected static QueryBuilder parseQuery(XContentParser parser) throws java.io.IOException
java.io.IOException
protected boolean builderGeneratesCacheableQueries()
public void testToQuery() throws java.io.IOException
Query
from the QueryBuilder
under test and delegates the
assertions being made on the result to the implementing subclass.java.io.IOException
protected boolean isCachable(QB queryBuilder)
protected boolean supportsBoostAndQueryName()
protected abstract void doAssertLuceneQuery(QB queryBuilder, Query query, SearchContext context) throws java.io.IOException
QueryBuilder.toQuery(QueryShardContext)
given the original QueryBuilder
and QueryShardContext
. Contains the query specific checks to be implemented by subclasses.java.io.IOException
protected static void assertTermOrBoostQuery(Query query, java.lang.String field, java.lang.String value, float fieldBoost)
protected static void assertTermQuery(Query query, java.lang.String field, java.lang.String value)
public void testSerialization() throws java.io.IOException
java.io.IOException
protected static QueryBuilder assertSerialization(QueryBuilder testQuery) throws java.io.IOException
java.io.IOException
protected static QueryBuilder assertSerialization(QueryBuilder testQuery, Version version) throws java.io.IOException
java.io.IOException
public void testEqualsAndHashcode()
protected static QueryShardContext createShardContext()
QueryShardContext
based on the base test index and queryParserServiceprotected static QueryParseContext createParseContext(XContentParser parser)
protected static java.lang.Object getRandomValueForFieldName(java.lang.String fieldName)
BOOLEAN_FIELD_NAME
, INT_FIELD_NAME
,
DOUBLE_FIELD_NAME
, STRING_FIELD_NAME
or
DATE_FIELD_NAME
, or a String value by defaultprotected static java.lang.String getRandomQueryText()
protected static java.lang.String getRandomFieldName()
protected static java.lang.String getRandomRewriteMethod()
protected static Fuzziness randomFuzziness(java.lang.String fieldName)
protected static java.lang.String randomAnalyzer()
protected static java.lang.String randomMinimumShouldMatch()
protected GetResponse executeGet(GetRequest getRequest)
Client.get(GetRequest)
calls from parsers / buildersprotected MultiTermVectorsResponse executeMultiTermVectors(MultiTermVectorsRequest mtvRequest)
Client.get(GetRequest)
calls from parsers / builderspublic static void checkGeneratedJson(java.lang.String expected, QueryBuilder source) throws java.io.IOException
java.io.IOException
public void testMustRewrite() throws java.io.IOException
java.io.IOException
protected NamedXContentRegistry xContentRegistry()
ESTestCase
NamedXContentRegistry
to use for this test. Subclasses should override and use liberally.xContentRegistry
in class ESTestCase