public abstract class AbstractQueryTestCase<QB extends org.elasticsearch.index.query.AbstractQueryBuilder<QB>> extends ESTestCase
Modifier and Type | Class and Description |
---|---|
static class |
AbstractQueryTestCase.GeohashGenerator |
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 |
DOUBLE_FIELD_NAME |
protected static java.lang.String |
GEO_POINT_FIELD_MAPPING |
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[] |
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, 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 |
assertLuceneQuery(QB queryBuilder,
org.apache.lucene.search.Query query,
org.elasticsearch.index.query.QueryShardContext context)
Checks the result of
QueryBuilder.toQuery(QueryShardContext) given the original QueryBuilder and QueryShardContext . |
protected static void |
assertParsedQuery(org.elasticsearch.common.bytes.BytesReference queryAsBytes,
org.elasticsearch.index.query.QueryBuilder expectedQuery)
Parses the query provided as bytes argument and compares it with the expected result provided as argument as a
QueryBuilder |
protected static void |
assertParsedQuery(org.elasticsearch.common.bytes.BytesReference queryAsBytes,
org.elasticsearch.index.query.QueryBuilder expectedQuery,
org.elasticsearch.common.ParseFieldMatcher matcher) |
protected static void |
assertParsedQuery(java.lang.String queryAsString,
org.elasticsearch.index.query.QueryBuilder expectedQuery)
Parses the query provided as string argument and compares it with the expected result provided as argument as a
QueryBuilder |
protected static void |
assertParsedQuery(java.lang.String queryAsString,
org.elasticsearch.index.query.QueryBuilder expectedQuery,
org.elasticsearch.common.ParseFieldMatcher matcher) |
protected org.elasticsearch.index.query.QueryBuilder |
assertSerialization(org.elasticsearch.index.query.QueryBuilder testQuery)
Serialize the given query builder and asserts that both are equal
|
protected static void |
assertTermOrBoostQuery(org.apache.lucene.search.Query query,
java.lang.String field,
java.lang.String value,
float fieldBoost) |
protected static void |
assertTermQuery(org.apache.lucene.search.Query query,
java.lang.String field,
java.lang.String value) |
void |
beforeTest() |
static void |
checkGeneratedJson(java.lang.String expected,
org.elasticsearch.index.query.QueryBuilder source)
Call this method to check a valid json string representing the query under test against
it's generated json.
|
protected QB |
copyQuery(QB query) |
protected static org.elasticsearch.index.query.QueryParseContext |
createParseContext(org.elasticsearch.common.xcontent.XContentParser parser,
org.elasticsearch.common.ParseFieldMatcher matcher) |
protected static org.elasticsearch.index.query.QueryShardContext |
createShardContext() |
QB |
createTestQueryBuilder() |
protected abstract void |
doAssertLuceneQuery(QB queryBuilder,
org.apache.lucene.search.Query query,
org.elasticsearch.index.query.QueryShardContext 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 org.elasticsearch.action.get.GetResponse |
executeGet(org.elasticsearch.action.get.GetRequest getRequest)
Override this to handle
Client.get(GetRequest) calls from parsers / builders |
protected org.elasticsearch.action.termvectors.MultiTermVectorsResponse |
executeMultiTermVectors(org.elasticsearch.action.termvectors.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 java.lang.String[] |
getCurrentTypes() |
protected org.elasticsearch.index.Index |
getIndex() |
protected org.elasticsearch.Version |
getIndexVersionCreated() |
protected java.util.Collection<java.lang.Class<? extends org.elasticsearch.plugins.Plugin>> |
getPlugins() |
protected java.lang.String |
getRandomFieldName()
Helper method to return a mapped or a random field
|
protected org.elasticsearch.common.collect.Tuple<java.lang.String,java.lang.Object> |
getRandomFieldNameAndValue()
Helper method to return a random field (mapped or unmapped) and a value
|
protected static java.lang.String |
getRandomQueryText() |
protected static java.lang.String |
getRandomRewriteMethod()
Helper method to return a random rewrite method
|
protected java.lang.String |
getRandomType() |
protected java.lang.String[] |
getRandomTypes() |
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 void |
initializeAdditionalMappings(org.elasticsearch.index.mapper.MapperService mapperService) |
protected static boolean |
isNumericFieldName(java.lang.String fieldName) |
protected static org.elasticsearch.index.query.QueryBuilder |
parseQuery(org.elasticsearch.common.bytes.BytesReference queryAsBytes) |
protected static org.elasticsearch.index.query.QueryBuilder |
parseQuery(org.elasticsearch.common.bytes.BytesReference queryAsBytes,
org.elasticsearch.common.ParseFieldMatcher matcher) |
protected static org.elasticsearch.index.query.QueryBuilder |
parseQuery(java.lang.String queryAsString) |
protected static org.elasticsearch.index.query.QueryBuilder |
parseQuery(java.lang.String queryAsString,
org.elasticsearch.common.ParseFieldMatcher matcher) |
protected static java.lang.String |
randomAnalyzer() |
protected static org.elasticsearch.common.unit.Fuzziness |
randomFuzziness(java.lang.String fieldName) |
static java.lang.String |
randomGeohash(int minPrecision,
int maxPrecision) |
protected static java.lang.String |
randomMinimumShouldMatch() |
protected org.apache.lucene.search.Query |
rewrite(org.apache.lucene.search.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 |
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 additional object into otherwise correct query string
should always trigger some kind of Parsing Exception.
|
protected static org.elasticsearch.common.xcontent.XContentBuilder |
toXContent(org.elasticsearch.index.query.QueryBuilder query,
org.elasticsearch.common.xcontent.XContentType contentType) |
afterIfFailed, afterIfSuccessful, assertAllIndicesRemovedAndDeletionCompleted, assertArrayEquals, assertBusy, assertBusy, assertEquals, assertionsEnabled, assertPathHasBeenCleared, awaitBusy, awaitBusy, between, createAnalysisService, createAnalysisService, createAnalysisService, ensureAllSearchContextsReleased, ensureCheckIndexPassed, ensureCleanedUp, frequently, generateRandomStringArray, generateRandomStringArray, getBwcIndicesPath, getDataPath, getSuiteFailureMarker, iterations, maybeSet, newNodeEnvironment, newNodeEnvironment, newTestScriptModule, randomAsciiOfLength, randomAsciiOfLengthBetween, randomBoolean, randomByte, randomDateTimeZone, randomDouble, randomDoubleBetween, randomFloat, randomFrom, randomFrom, randomFrom, randomInt, randomInt, randomIntBetween, randomLong, randomPositiveTimeValue, randomRealisticUnicodeOfCodepointLength, randomRealisticUnicodeOfCodepointLengthBetween, randomRealisticUnicodeOfLength, randomRealisticUnicodeOfLengthBetween, randomShort, randomSubsetOf, randomSubsetOf, randomSubsetOf, randomTimeValue, randomUnicodeOfCodepointLength, randomUnicodeOfCodepointLengthBetween, randomUnicodeOfLength, randomUnicodeOfLengthBetween, randomUnique, randomValueOtherThan, randomValueOtherThanMany, resetCheckIndexStatus, restoreContentType, restoreFileSystem, scaledRandomIntBetween, setContentType, setFileSystem, settings, shuffleXContent, spinForAtLeastOneMillisecond, terminate, terminate, tmpPaths
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, atLeast, atLeast, closeAfterSuite, closeAfterTest, collate, createTempDir, createTempDir, createTempFile, createTempFile, dumpArray, dumpIterator, expectThrows, getBaseTempDirForTestClass, getDataInputStream, getOnlyLeafReader, getTestClass, getTestName, 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, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, 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 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 OBJECT_FIELD_NAME
protected static final java.lang.String GEO_POINT_FIELD_NAME
protected static final java.lang.String 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 org.elasticsearch.index.Index getIndex()
protected org.elasticsearch.Version getIndexVersionCreated()
protected java.lang.String[] getCurrentTypes()
protected java.util.Collection<java.lang.Class<? extends org.elasticsearch.plugins.Plugin>> getPlugins()
protected void initializeAdditionalMappings(org.elasticsearch.index.mapper.MapperService mapperService) throws java.io.IOException
java.io.IOException
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 caseprotected static org.elasticsearch.common.xcontent.XContentBuilder toXContent(org.elasticsearch.index.query.QueryBuilder query, org.elasticsearch.common.xcontent.XContentType contentType) throws java.io.IOException
java.io.IOException
public void testUnknownField() throws java.io.IOException
java.io.IOException
public void testUnknownObjectException() throws java.io.IOException
java.io.IOException
protected java.util.Map<java.lang.String,QB> getAlternateVersions()
ToXContent.toXContent(XContentBuilder, ToXContent.Params)
. By default there are no alternate versions.protected static final void assertParsedQuery(java.lang.String queryAsString, org.elasticsearch.index.query.QueryBuilder expectedQuery) throws java.io.IOException
QueryBuilder
java.io.IOException
protected static final void assertParsedQuery(java.lang.String queryAsString, org.elasticsearch.index.query.QueryBuilder expectedQuery, org.elasticsearch.common.ParseFieldMatcher matcher) throws java.io.IOException
java.io.IOException
protected static final void assertParsedQuery(org.elasticsearch.common.bytes.BytesReference queryAsBytes, org.elasticsearch.index.query.QueryBuilder expectedQuery) throws java.io.IOException
QueryBuilder
java.io.IOException
protected static final void assertParsedQuery(org.elasticsearch.common.bytes.BytesReference queryAsBytes, org.elasticsearch.index.query.QueryBuilder expectedQuery, org.elasticsearch.common.ParseFieldMatcher matcher) throws java.io.IOException
java.io.IOException
protected static final org.elasticsearch.index.query.QueryBuilder parseQuery(java.lang.String queryAsString) throws java.io.IOException
java.io.IOException
protected static final org.elasticsearch.index.query.QueryBuilder parseQuery(java.lang.String queryAsString, org.elasticsearch.common.ParseFieldMatcher matcher) throws java.io.IOException
java.io.IOException
protected static final org.elasticsearch.index.query.QueryBuilder parseQuery(org.elasticsearch.common.bytes.BytesReference queryAsBytes) throws java.io.IOException
java.io.IOException
protected static final org.elasticsearch.index.query.QueryBuilder parseQuery(org.elasticsearch.common.bytes.BytesReference queryAsBytes, org.elasticsearch.common.ParseFieldMatcher matcher) throws java.io.IOException
java.io.IOException
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 supportsBoostAndQueryName()
protected final void assertLuceneQuery(QB queryBuilder, org.apache.lucene.search.Query query, org.elasticsearch.index.query.QueryShardContext context) throws java.io.IOException
QueryBuilder.toQuery(QueryShardContext)
given the original QueryBuilder
and QueryShardContext
.
Verifies that named queries and boost are properly handled and delegates to doAssertLuceneQuery(AbstractQueryBuilder, Query, QueryShardContext)
for query specific checks.java.io.IOException
protected abstract void doAssertLuceneQuery(QB queryBuilder, org.apache.lucene.search.Query query, org.elasticsearch.index.query.QueryShardContext 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(org.apache.lucene.search.Query query, java.lang.String field, java.lang.String value, float fieldBoost)
protected static void assertTermQuery(org.apache.lucene.search.Query query, java.lang.String field, java.lang.String value)
public void testSerialization() throws java.io.IOException
java.io.IOException
protected org.elasticsearch.index.query.QueryBuilder assertSerialization(org.elasticsearch.index.query.QueryBuilder testQuery) throws java.io.IOException
java.io.IOException
public void testEqualsAndHashcode() throws java.io.IOException
java.io.IOException
protected static org.elasticsearch.index.query.QueryShardContext createShardContext()
QueryShardContext
based on the base test index and queryParserServiceprotected static org.elasticsearch.index.query.QueryParseContext createParseContext(org.elasticsearch.common.xcontent.XContentParser parser, org.elasticsearch.common.ParseFieldMatcher matcher)
QueryParseContext
based on the base test index and queryParserServiceprotected 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 java.lang.String getRandomFieldName()
protected org.elasticsearch.common.collect.Tuple<java.lang.String,java.lang.Object> getRandomFieldNameAndValue()
protected static java.lang.String getRandomRewriteMethod()
protected java.lang.String[] getRandomTypes()
protected java.lang.String getRandomType()
public static java.lang.String randomGeohash(int minPrecision, int maxPrecision)
protected static org.elasticsearch.common.unit.Fuzziness randomFuzziness(java.lang.String fieldName)
protected static boolean isNumericFieldName(java.lang.String fieldName)
protected static java.lang.String randomAnalyzer()
protected static java.lang.String randomMinimumShouldMatch()
protected org.elasticsearch.action.get.GetResponse executeGet(org.elasticsearch.action.get.GetRequest getRequest)
Client.get(GetRequest)
calls from parsers / buildersprotected org.elasticsearch.action.termvectors.MultiTermVectorsResponse executeMultiTermVectors(org.elasticsearch.action.termvectors.MultiTermVectorsRequest mtvRequest)
Client.get(GetRequest)
calls from parsers / builderspublic static void checkGeneratedJson(java.lang.String expected, org.elasticsearch.index.query.QueryBuilder source) throws java.io.IOException
java.io.IOException
public void testMustRewrite() throws java.io.IOException
java.io.IOException
protected org.apache.lucene.search.Query rewrite(org.apache.lucene.search.Query query) throws java.io.IOException
java.io.IOException