|
15 | 15 |
|
16 | 16 | import java.util.Map; |
17 | 17 |
|
18 | | -import static org.hamcrest.Matchers.containsString; |
| 18 | +import static java.util.Map.entry; |
19 | 19 | import static org.hamcrest.Matchers.is; |
20 | 20 |
|
21 | 21 | /** |
@@ -67,39 +67,38 @@ public void testBasic() throws Exception { |
67 | 67 | } |
68 | 68 |
|
69 | 69 | 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 | | - |
77 | 70 | 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")); |
80 | 72 | 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 | + ); |
90 | 84 | } |
91 | 85 |
|
92 | 86 | 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 | + } |
103 | 102 | } |
104 | 103 |
|
105 | 104 | private void testRegisteredDomainProcessor( |
|
0 commit comments