Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,27 @@ public boolean equals(Object obj) {
ComposableIndexTemplate other = (ComposableIndexTemplate) obj;
return Objects.equals(this.indexPatterns, other.indexPatterns)
&& Objects.equals(this.template, other.template)
&& Objects.equals(this.componentTemplates, other.componentTemplates)
&& componentTemplatesEquals(this.componentTemplates, other.componentTemplates)
&& Objects.equals(this.priority, other.priority)
&& Objects.equals(this.version, other.version)
&& Objects.equals(this.metadata, other.metadata)
&& Objects.equals(this.dataStreamTemplate, other.dataStreamTemplate)
&& Objects.equals(this.allowAutoCreate, other.allowAutoCreate);
}

static boolean componentTemplatesEquals(List<String> c1, List<String> c2) {
if (Objects.equals(c1, c2)) {
return true;
}
if (c1 == null && c2.isEmpty()) {
return true;
}
if (c2 == null && c1.isEmpty()) {
return true;
}
return false;
}

@Override
public String toString() {
return Strings.toString(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.List;
import java.util.Map;

import static org.hamcrest.Matchers.equalTo;

public class ComposableIndexTemplateTests extends AbstractDiffableSerializationTestCase<ComposableIndexTemplate> {
@Override
protected ComposableIndexTemplate makeTestChanges(ComposableIndexTemplate testInstance) {
Expand Down Expand Up @@ -79,11 +81,10 @@ public static ComposableIndexTemplate randomInstance() {
}

List<String> indexPatterns = randomList(1, 4, () -> randomAlphaOfLength(4));
List<String> componentTemplates = randomList(0, 10, () -> randomAlphaOfLength(5));
return new ComposableIndexTemplate(
indexPatterns,
template,
componentTemplates,
randomBoolean() ? null : randomList(0, 10, () -> randomAlphaOfLength(5)),
randomBoolean() ? null : randomNonNegativeLong(),
randomBoolean() ? null : randomNonNegativeLong(),
meta,
Expand Down Expand Up @@ -242,4 +243,13 @@ public static ComposableIndexTemplate mutateTemplate(ComposableIndexTemplate ori
throw new IllegalStateException("illegal randomization branch");
}
}

public void testComponentTemplatesEquals() {
assertThat(ComposableIndexTemplate.componentTemplatesEquals(null, null), equalTo(true));
assertThat(ComposableIndexTemplate.componentTemplatesEquals(null, List.of()), equalTo(true));
assertThat(ComposableIndexTemplate.componentTemplatesEquals(List.of(), null), equalTo(true));
assertThat(ComposableIndexTemplate.componentTemplatesEquals(List.of(), List.of()), equalTo(true));
assertThat(ComposableIndexTemplate.componentTemplatesEquals(List.of(randomAlphaOfLength(5)), List.of()), equalTo(false));
assertThat(ComposableIndexTemplate.componentTemplatesEquals(List.of(), List.of(randomAlphaOfLength(5))), equalTo(false));
}
}