Skip to content

Commit 2def06a

Browse files
committed
Add hook to skip asserting x-content equivalence (#33114)
This commit adds a hook to AbstractSerializingTestCase to enable skipping asserting that the x-content of the test instance and an instance parsed from the x-content of the test instance are the same. While we usually expect these to be the same, they will not be the same when exceptions are involved because the x-content there is lossy.
1 parent 3684af1 commit 2def06a

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

test/framework/src/main/java/org/elasticsearch/test/AbstractSerializingTestCase.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19+
1920
package org.elasticsearch.test;
2021

2122
import org.elasticsearch.common.Strings;
@@ -34,9 +35,17 @@ public abstract class AbstractSerializingTestCase<T extends ToXContent & Writeab
3435
* both for equality and asserts equality on the two instances.
3536
*/
3637
public final void testFromXContent() throws IOException {
37-
AbstractXContentTestCase.testFromXContent(NUMBER_OF_TEST_RUNS, this::createTestInstance, supportsUnknownFields(),
38-
getShuffleFieldsExceptions(), getRandomFieldsExcludeFilter(), this::createParser, this::doParseInstance,
39-
this::assertEqualInstances, true, getToXContentParams());
38+
AbstractXContentTestCase.testFromXContent(
39+
NUMBER_OF_TEST_RUNS,
40+
this::createTestInstance,
41+
supportsUnknownFields(),
42+
getShuffleFieldsExceptions(),
43+
getRandomFieldsExcludeFilter(),
44+
this::createParser,
45+
this::doParseInstance,
46+
this::assertEqualInstances,
47+
assertToXContentEquivalence(),
48+
getToXContentParams());
4049
}
4150

4251
/**
@@ -72,4 +81,15 @@ protected String[] getShuffleFieldsExceptions() {
7281
protected ToXContent.Params getToXContentParams() {
7382
return ToXContent.EMPTY_PARAMS;
7483
}
84+
85+
/**
86+
* Whether or not to assert equivalence of the {@link org.elasticsearch.common.xcontent.XContent} of the test instance and the instance
87+
* parsed from the {@link org.elasticsearch.common.xcontent.XContent} of the test instance.
88+
*
89+
* @return true if equivalence should be asserted, otherwise false
90+
*/
91+
protected boolean assertToXContentEquivalence() {
92+
return true;
93+
}
94+
7595
}

0 commit comments

Comments
 (0)