diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/AggregationsTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/AggregationsTests.java index a70c3c2d1b4..48fa42ad3ef 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/AggregationsTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/AggregationsTests.java @@ -115,8 +115,6 @@ public class AggregationsTests extends ESTestCase { aggsTests.add(new InternalMissingTests()); aggsTests.add(new InternalNestedTests()); aggsTests.add(new InternalReverseNestedTests()); - // TODO can we find a way to include the children aggregation in this test? - //aggsTests.add(new InternalChildrenTests()); aggsTests.add(new InternalGlobalTests()); aggsTests.add(new InternalFilterTests()); aggsTests.add(new InternalSamplerTests()); @@ -129,7 +127,7 @@ public class AggregationsTests extends ESTestCase { @Override protected NamedXContentRegistry xContentRegistry() { - return new NamedXContentRegistry(InternalAggregationTestCase.getNamedXContents()); + return new NamedXContentRegistry(InternalAggregationTestCase.getDefaultNamedXContents()); } @Before @@ -147,9 +145,9 @@ public class AggregationsTests extends ESTestCase { } public void testAllAggsAreBeingTested() { - assertEquals(InternalAggregationTestCase.getNamedXContents().size(), aggsTests.size()); + assertEquals(InternalAggregationTestCase.getDefaultNamedXContents().size(), aggsTests.size()); Set aggs = aggsTests.stream().map((testCase) -> testCase.createTestInstance().getType()).collect(Collectors.toSet()); - for (NamedXContentRegistry.Entry entry : InternalAggregationTestCase.getNamedXContents()) { + for (NamedXContentRegistry.Entry entry : InternalAggregationTestCase.getDefaultNamedXContents()) { assertTrue(aggs.contains(entry.name.getPreferredName())); } } diff --git a/modules/parent-join/src/test/java/org/elasticsearch/join/aggregations/InternalChildrenTests.java b/modules/parent-join/src/test/java/org/elasticsearch/join/aggregations/InternalChildrenTests.java index 089f0a19bd9..95cff14ef00 100644 --- a/modules/parent-join/src/test/java/org/elasticsearch/join/aggregations/InternalChildrenTests.java +++ b/modules/parent-join/src/test/java/org/elasticsearch/join/aggregations/InternalChildrenTests.java @@ -22,22 +22,25 @@ package org.elasticsearch.join.aggregations; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.Writeable.Reader; import org.elasticsearch.common.xcontent.NamedXContentRegistry; +import org.elasticsearch.common.xcontent.NamedXContentRegistry.Entry; import org.elasticsearch.search.aggregations.Aggregation; import org.elasticsearch.search.aggregations.InternalAggregations; import org.elasticsearch.search.aggregations.InternalSingleBucketAggregationTestCase; import org.elasticsearch.search.aggregations.bucket.ParsedSingleBucketAggregation; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; -import org.junit.BeforeClass; +import java.util.ArrayList; import java.util.List; import java.util.Map; public class InternalChildrenTests extends InternalSingleBucketAggregationTestCase { - @BeforeClass - public static void init() { - namedXContents.add(new NamedXContentRegistry.Entry(Aggregation.class, new ParseField(ChildrenAggregationBuilder.NAME), + @Override + protected List getNamedXContents() { + List extendedNamedXContents = new ArrayList<>(super.getNamedXContents()); + extendedNamedXContents.add(new NamedXContentRegistry.Entry(Aggregation.class, new ParseField(ChildrenAggregationBuilder.NAME), (p, c) -> ParsedChildren.fromXContent(p, (String) c))); + return extendedNamedXContents ; } @Override diff --git a/test/framework/src/main/java/org/elasticsearch/test/InternalAggregationTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/InternalAggregationTestCase.java index d85f41fd20c..bd084bd5c08 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/InternalAggregationTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/InternalAggregationTestCase.java @@ -130,7 +130,8 @@ public abstract class InternalAggregationTestCase new SearchModule(Settings.EMPTY, false, emptyList()).getNamedWriteables()); private final NamedXContentRegistry namedXContentRegistry = new NamedXContentRegistry(getNamedXContents()); - protected static final List namedXContents; + + private static final List namedXContents; static { Map> map = new HashMap<>(); map.put(CardinalityAggregationBuilder.NAME, (p, c) -> ParsedCardinality.fromXContent(p, (String) c)); @@ -175,7 +176,11 @@ public abstract class InternalAggregationTestCase .collect(Collectors.toList()); } - public static List getNamedXContents() { + public static List getDefaultNamedXContents() { + return namedXContents; + } + + protected List getNamedXContents() { return namedXContents; }