Class AbstractXContentTestCase<T extends ToXContent>

    • Constructor Detail

      • AbstractXContentTestCase

        public AbstractXContentTestCase()
    • Method Detail

      • testFromXContent

        public static <T extends ToXContent> void testFromXContent​(int numberOfTestRuns,
                                                                   java.util.function.Supplier<T> instanceSupplier,
                                                                   boolean supportsUnknownFields,
                                                                   java.lang.String[] shuffleFieldsExceptions,
                                                                   java.util.function.Predicate<java.lang.String> randomFieldsExcludeFilter,
                                                                   CheckedBiFunction<XContent,BytesReference,XContentParser,java.io.IOException> createParserFunction,
                                                                   CheckedFunction<XContentParser,T,java.io.IOException> parseFunction,
                                                                   java.util.function.BiConsumer<T,T> assertEqualsConsumer,
                                                                   boolean assertToXContentEquivalence,
                                                                   ToXContent.Params toXContentParams)
                                                            throws java.io.IOException
        Throws:
        java.io.IOException
      • 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 queries.
        Throws:
        java.io.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​(XContentParser parser)
                                      throws java.io.IOException
        Parses to a new instance using the provided XContentParser
        Throws:
        java.io.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 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