Skip to content

Commit 5017c7f

Browse files
committed
Simplify these tests
1 parent 8fa2f88 commit 5017c7f

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/RegisteredDomainProcessorTests.java

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import java.util.Map;
1717

18-
import static org.hamcrest.Matchers.containsString;
18+
import static java.util.Map.entry;
1919
import static org.hamcrest.Matchers.is;
2020

2121
/**
@@ -67,39 +67,38 @@ public void testBasic() throws Exception {
6767
}
6868

6969
public void testUseRoot() throws Exception {
70-
Map<String, Object> source = buildEvent("www.google.co.uk");
71-
72-
String domainField = "domain";
73-
String registeredDomainField = "registered_domain";
74-
String topLevelDomainField = "top_level_domain";
75-
String subdomainField = "subdomain";
76-
7770
var processor = new RegisteredDomainProcessor(null, null, "domain", "", false);
78-
79-
IngestDocument document = TestIngestDocument.withDefaultVersion(source);
71+
IngestDocument document = TestIngestDocument.withDefaultVersion(Map.of("domain", "www.google.co.uk"));
8072
processor.execute(document);
81-
82-
String domain = document.getFieldValue(domainField, String.class);
83-
assertThat(domain, is("www.google.co.uk"));
84-
String registeredDomain = document.getFieldValue(registeredDomainField, String.class);
85-
assertThat(registeredDomain, is("google.co.uk"));
86-
String eTLD = document.getFieldValue(topLevelDomainField, String.class);
87-
assertThat(eTLD, is("co.uk"));
88-
String subdomain = document.getFieldValue(subdomainField, String.class);
89-
assertThat(subdomain, is("www"));
73+
assertThat(
74+
document.getSource(),
75+
is(
76+
Map.ofEntries(
77+
entry("domain", "www.google.co.uk"),
78+
entry("registered_domain", "google.co.uk"),
79+
entry("top_level_domain", "co.uk"),
80+
entry("subdomain", "www")
81+
)
82+
)
83+
);
9084
}
9185

9286
public void testError() throws Exception {
93-
IllegalArgumentException e = expectThrows(
94-
IllegalArgumentException.class,
95-
() -> testRegisteredDomainProcessor(buildEvent("foo.bar.baz"), null, null, null, null, false)
96-
);
97-
assertThat(e.getMessage(), containsString("unable to set domain information for document"));
98-
e = expectThrows(
99-
IllegalArgumentException.class,
100-
() -> testRegisteredDomainProcessor(buildEvent("$"), null, null, null, null, false)
101-
);
102-
assertThat(e.getMessage(), containsString("unable to set domain information for document"));
87+
var processor = new RegisteredDomainProcessor(null, null, "domain", "", false);
88+
89+
{
90+
IngestDocument document = TestIngestDocument.withDefaultVersion(Map.of("domain", "foo.bar.baz"));
91+
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> processor.execute(document));
92+
assertThat(e.getMessage(), is("unable to set domain information for document"));
93+
assertThat(document.getSource(), is(Map.of("domain", "foo.bar.baz")));
94+
}
95+
96+
{
97+
IngestDocument document = TestIngestDocument.withDefaultVersion(Map.of("domain", "$"));
98+
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> processor.execute(document));
99+
assertThat(e.getMessage(), is("unable to set domain information for document"));
100+
assertThat(document.getSource(), is(Map.of("domain", "$")));
101+
}
103102
}
104103

105104
private void testRegisteredDomainProcessor(

0 commit comments

Comments
 (0)