Class AbstractXContentTestCase<T extends org.elasticsearch.xcontent.ToXContent>

java.lang.Object
org.junit.Assert
org.apache.lucene.util.LuceneTestCase
org.elasticsearch.test.ESTestCase
org.elasticsearch.test.AbstractXContentTestCase<T>
Direct Known Subclasses:
AbstractBroadcastResponseTestCase

public abstract class AbstractXContentTestCase<T extends org.elasticsearch.xcontent.ToXContent> extends ESTestCase
  • Field Details

  • Constructor Details

    • AbstractXContentTestCase

      public AbstractXContentTestCase()
  • Method Details

    • xContentTester

      public static <T> AbstractXContentTestCase.XContentTester<T> xContentTester(org.elasticsearch.common.CheckedBiFunction<org.elasticsearch.xcontent.XContent,org.elasticsearch.common.bytes.BytesReference,org.elasticsearch.xcontent.XContentParser,IOException> createParser, Supplier<T> instanceSupplier, org.elasticsearch.common.CheckedBiConsumer<T,org.elasticsearch.xcontent.XContentBuilder,IOException> toXContent, org.elasticsearch.core.CheckedFunction<org.elasticsearch.xcontent.XContentParser,T,IOException> fromXContent)
    • xContentTester

      public static <T extends org.elasticsearch.xcontent.ToXContent> AbstractXContentTestCase.XContentTester<T> xContentTester(org.elasticsearch.common.CheckedBiFunction<org.elasticsearch.xcontent.XContent,org.elasticsearch.common.bytes.BytesReference,org.elasticsearch.xcontent.XContentParser,IOException> createParser, Supplier<T> instanceSupplier, org.elasticsearch.core.CheckedFunction<org.elasticsearch.xcontent.XContentParser,T,IOException> fromXContent)
    • xContentTester

      public static <T extends org.elasticsearch.xcontent.ToXContent> AbstractXContentTestCase.XContentTester<T> xContentTester(org.elasticsearch.common.CheckedBiFunction<org.elasticsearch.xcontent.XContent,org.elasticsearch.common.bytes.BytesReference,org.elasticsearch.xcontent.XContentParser,IOException> createParser, Supplier<T> instanceSupplier, org.elasticsearch.xcontent.ToXContent.Params toXContentParams, org.elasticsearch.core.CheckedFunction<org.elasticsearch.xcontent.XContentParser,T,IOException> fromXContent)
    • xContentTester

      public static <T extends org.elasticsearch.xcontent.ToXContent> AbstractXContentTestCase.XContentTester<T> xContentTester(org.elasticsearch.common.CheckedBiFunction<org.elasticsearch.xcontent.XContent,org.elasticsearch.common.bytes.BytesReference,org.elasticsearch.xcontent.XContentParser,IOException> createParser, Function<org.elasticsearch.xcontent.XContentType,T> instanceSupplier, org.elasticsearch.xcontent.ToXContent.Params toXContentParams, org.elasticsearch.core.CheckedFunction<org.elasticsearch.xcontent.XContentParser,T,IOException> fromXContent)
    • testFromXContent

      public static <T extends org.elasticsearch.xcontent.ToXContent> void testFromXContent(int numberOfTestRuns, Supplier<T> instanceSupplier, boolean supportsUnknownFields, String[] shuffleFieldsExceptions, Predicate<String> randomFieldsExcludeFilter, org.elasticsearch.common.CheckedBiFunction<org.elasticsearch.xcontent.XContent,org.elasticsearch.common.bytes.BytesReference,org.elasticsearch.xcontent.XContentParser,IOException> createParserFunction, org.elasticsearch.core.CheckedFunction<org.elasticsearch.xcontent.XContentParser,T,IOException> fromXContent, BiConsumer<T,T> assertEqualsConsumer, boolean assertToXContentEquivalence, org.elasticsearch.xcontent.ToXContent.Params toXContentParams) throws IOException
      Throws:
      IOException
    • testFromXContent

      public final void testFromXContent() throws IOException
      Generic test that creates new instance from the test instance and checks both for equality and asserts equality on the two queries.
      Throws:
      IOException
    • createTestInstance

      protected abstract T createTestInstance()
      Creates a random test instance to use in the tests. This method will be called multiple times during test execution and should return a different random instance each time it is called.
    • doParseInstance

      protected abstract T doParseInstance(org.elasticsearch.xcontent.XContentParser parser) throws IOException
      Parses to a new instance using the provided XContentParser
      Throws:
      IOException
    • assertEqualInstances

      protected void assertEqualInstances(T expectedInstance, T newInstance)
    • assertToXContentEquivalence

      protected boolean assertToXContentEquivalence()
    • supportsUnknownFields

      protected abstract boolean supportsUnknownFields()
      Indicates whether the parser supports unknown fields or not. In case it does, such behaviour will be tested by inserting random fields before parsing and checking that they don't make parsing fail.
    • getRandomFieldsExcludeFilter

      protected Predicate<String> getRandomFieldsExcludeFilter()
      Returns a predicate that given the field name indicates whether the field has to be excluded from random fields insertion or not
    • getShuffleFieldsExceptions

      protected String[] getShuffleFieldsExceptions()
      Fields that have to be ignored when shuffling as part of testFromXContent
    • getToXContentParams

      protected org.elasticsearch.xcontent.ToXContent.Params getToXContentParams()
      Params that have to be provided when calling ToXContent.toXContent(XContentBuilder, ToXContent.Params)