Class AbstractSerializingTestCase<T extends org.elasticsearch.common.xcontent.ToXContent & org.elasticsearch.common.io.stream.Writeable>

java.lang.Object
org.junit.Assert
org.apache.lucene.util.LuceneTestCase
Direct Known Subclasses:
AbstractDiffableSerializationTestCase

public abstract class AbstractSerializingTestCase<T extends org.elasticsearch.common.xcontent.ToXContent & org.elasticsearch.common.io.stream.Writeable>
extends AbstractWireSerializingTestCase<T>
  • Constructor Details

  • Method Details

    • testFromXContent

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

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

      protected T createXContextTestInstance​(org.elasticsearch.common.xcontent.XContentType xContentType)
      Creates a random instance to use in the xcontent tests. Override this method if the random instance that you build should be aware of the XContentType used in the test.
    • supportsUnknownFields

      protected 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 java.util.function.Predicate<java.lang.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 java.lang.String[] getShuffleFieldsExceptions()
      Fields that have to be ignored when shuffling as part of testFromXContent
    • getToXContentParams

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

      protected boolean assertToXContentEquivalence()
      Whether or not to assert equivalence of the XContent of the test instance and the instance parsed from the XContent of the test instance.
      Returns:
      true if equivalence should be asserted, otherwise false
    • randomDate

      protected java.util.Date randomDate()
      Returns:
      a random date between 1970 and ca 2065
    • randomInstant

      protected java.time.Instant randomInstant()
      Returns:
      a random instant between 1970 and ca 2065