Skip to content

Commit 16dfbdb

Browse files
committed
Apply interface changes in unit tests.
1 parent 53ded41 commit 16dfbdb

7 files changed

+79
-85
lines changed

src/test/java/co/elastic/logstash/filters/elasticintegration/ElasticsearchPipelineConfigurationResolverTest.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import com.github.tomakehurst.wiremock.junit5.WireMockExtension;
1010
import org.elasticsearch.client.RestClient;
11-
import org.elasticsearch.ingest.PipelineConfiguration;
11+
import org.elasticsearch.logstashbridge.ingest.PipelineConfigurationBridge;
1212
import org.junit.jupiter.api.Test;
1313
import org.junit.jupiter.api.extension.RegisterExtension;
1414

@@ -54,7 +54,7 @@ void testLoadConfigurationExists() throws Exception {
5454
.willReturn(okJson(getMockResponseBody("get-ingest-pipeline-(my-pipeline-id).json"))));
5555

5656
final AtomicReference<Exception> lastException = new AtomicReference<>();
57-
final Optional<PipelineConfiguration> resolvedPipelineConfiguration = resolver.resolve("my-pipeline-id", lastException::set);
57+
final Optional<PipelineConfigurationBridge> resolvedPipelineConfiguration = resolver.resolve("my-pipeline-id", lastException::set);
5858
assertThat(lastException.get(), is(nullValue()));
5959
assertThat(resolvedPipelineConfiguration, isPresent());
6060
resolvedPipelineConfiguration.ifPresent(pipelineConfiguration -> {
@@ -72,7 +72,7 @@ void testLoadConfigurationPipelineWithSpecialCharacters() throws Exception {
7272
.willReturn(okJson(getMockResponseBody("get-ingest-pipeline-(special char pipeline).json"))));
7373

7474
final AtomicReference<Exception> lastException = new AtomicReference<>();
75-
final Optional<PipelineConfiguration> resolvedPipelineConfiguration = resolver.resolve("special char pipeline", lastException::set);
75+
final Optional<PipelineConfigurationBridge> resolvedPipelineConfiguration = resolver.resolve("special char pipeline", lastException::set);
7676
assertThat(lastException.get(), is(nullValue()));
7777
assertThat(resolvedPipelineConfiguration, isPresent());
7878
resolvedPipelineConfiguration.ifPresent(pipelineConfiguration -> {
@@ -90,7 +90,7 @@ void testLoadConfigurationNotFound() throws Exception {
9090
.willReturn(aResponse().withStatus(404)));
9191

9292
final AtomicReference<Exception> lastException = new AtomicReference<>();
93-
final Optional<PipelineConfiguration> resolvedPipelineConfiguration = resolver.resolve("where-are-you", lastException::set);
93+
final Optional<PipelineConfigurationBridge> resolvedPipelineConfiguration = resolver.resolve("where-are-you", lastException::set);
9494
assertThat(lastException.get(), is(nullValue())); // not found is not an exception
9595
assertThat(resolvedPipelineConfiguration, isEmpty());
9696
});
@@ -103,7 +103,7 @@ void testLoadConfigurationNotAuthorized() throws Exception {
103103
.willReturn(aResponse().withStatus(403)));
104104

105105
final AtomicReference<Exception> lastException = new AtomicReference<>();
106-
final Optional<PipelineConfiguration> resolvedPipelineConfiguration = resolver.resolve("who-am-i", lastException::set);
106+
final Optional<PipelineConfigurationBridge> resolvedPipelineConfiguration = resolver.resolve("who-am-i", lastException::set);
107107
assertThat(lastException.get(), both(is(instanceOf(org.elasticsearch.client.ResponseException.class))).and(
108108
hasToString(containsString("403 Forbidden")))
109109
);
@@ -128,12 +128,4 @@ private void withPipelineConfigurationResolver(final Consumer<ElasticsearchPipel
128128
static String getMockResponseBody(final String name) {
129129
return readResource(ElasticsearchRestClientWireMockTest.class, Path.of("elasticsearch-mock-responses",name).toString());
130130
}
131-
//
132-
// static <T,R> void assertThat(T actual, Function<T, R> transform, Matcher<? super R> matcher) {
133-
// org.hamcrest.MatcherAssert.assertThat(transform.apply(actual), matcher);
134-
// }
135-
//
136-
// static <T> void assertThat(T actual, Matcher<? super T> matcher) {
137-
// assertThat(actual, Function.identity(), matcher);
138-
// }
139131
}

src/test/java/co/elastic/logstash/filters/elasticintegration/IngestDuplexMarshallerTest.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import co.elastic.logstash.api.Event;
1010
import co.elastic.logstash.filters.elasticintegration.util.TestCapturingLogger;
11-
import org.elasticsearch.ingest.IngestDocument;
11+
import org.elasticsearch.logstashbridge.ingest.IngestDocumentBridge;
1212
import org.junit.jupiter.api.Test;
1313
import org.logstash.Timestamp;
1414
import org.logstash.plugins.BasicEventFactory;
@@ -76,7 +76,7 @@ void ingestDocToEventModifiedAtTimestampZonedDateTimeValue() {
7676
"@version", "3",
7777
"message", "hello, world"
7878
));
79-
final IngestDocument intermediate = idm.toIngestDocument(input);
79+
final IngestDocumentBridge intermediate = idm.toIngestDocument(input);
8080

8181
final ZonedDateTime updatedTimestamp = ZonedDateTime.parse("2023-03-12T01:17:38.135792468Z");
8282
intermediate.setFieldValue(org.logstash.Event.TIMESTAMP, updatedTimestamp);
@@ -93,7 +93,7 @@ void ingestDocToEventModifiedAtTimestampStringValue() {
9393
"@timestamp", "2023-01-17T23:19:04.765182352Z",
9494
"@version", "3",
9595
"message", "hello, world"));
96-
final IngestDocument intermediate = idm.toIngestDocument(input);
96+
final IngestDocumentBridge intermediate = idm.toIngestDocument(input);
9797

9898
final ZonedDateTime updatedTimestamp = ZonedDateTime.parse("2023-03-12T01:17:38.135792468Z");
9999
intermediate.setFieldValue(org.logstash.Event.TIMESTAMP, updatedTimestamp.toString());
@@ -110,7 +110,7 @@ void ingestDocToEventModifiedAtTimestampInvalidStringValue() {
110110
"@timestamp", "2023-01-17T23:19:04.765182352Z",
111111
"@version", "3",
112112
"message", "hello, world"));
113-
final IngestDocument intermediate = idm.toIngestDocument(input);
113+
final IngestDocumentBridge intermediate = idm.toIngestDocument(input);
114114

115115
intermediate.setFieldValue(org.logstash.Event.TIMESTAMP, "high noon");
116116

@@ -130,7 +130,7 @@ void ingestDocToEventRemovedAtTimestamp() {
130130
"@timestamp", "2023-01-17T23:19:04.765182352Z",
131131
"@version", "3",
132132
"message", "hello, world"));
133-
final IngestDocument intermediate = idm.toIngestDocument(input);
133+
final IngestDocumentBridge intermediate = idm.toIngestDocument(input);
134134

135135
intermediate.removeField(org.logstash.Event.TIMESTAMP);
136136

@@ -148,7 +148,7 @@ void ingestDocToEventRemovedAtTimestampWithEventCreatedAt() {
148148
"@timestamp", "2023-01-17T23:19:04.765182352Z",
149149
"@version", "3",
150150
"message", "hello, world"));
151-
final IngestDocument intermediate = idm.toIngestDocument(input);
151+
final IngestDocumentBridge intermediate = idm.toIngestDocument(input);
152152

153153
intermediate.removeField(org.logstash.Event.TIMESTAMP);
154154

@@ -172,7 +172,7 @@ void ingestDocToEventModifiedMetadataVersion() {
172172
"@timestamp", "2023-01-17T23:19:04.765182352Z",
173173
"@version", "3",
174174
"message", "hello, world"));
175-
final IngestDocument intermediate = idm.toIngestDocument(input);
175+
final IngestDocumentBridge intermediate = idm.toIngestDocument(input);
176176

177177
final long updatedMetadataVersion = 17L;
178178
intermediate.getMetadata().setVersion(updatedMetadataVersion);
@@ -192,7 +192,7 @@ void ingestDocToEventAdditionalMetadata() {
192192
"@timestamp", "2023-01-17T23:19:04.765182352Z",
193193
"@version", "3",
194194
"message", "hello, world"));
195-
final IngestDocument intermediate = idm.toIngestDocument(input);
195+
final IngestDocumentBridge intermediate = idm.toIngestDocument(input);
196196

197197
intermediate.getMetadata().setVersion(8191L);
198198
intermediate.getMetadata().setVersionType("external_gte"); // constrained
@@ -217,7 +217,7 @@ void ingestDocToEventIncludingReservedAtTimestampField() {
217217
"@version", "3",
218218
"message",
219219
"hello, world"));
220-
final IngestDocument intermediate = idm.toIngestDocument(input);
220+
final IngestDocumentBridge intermediate = idm.toIngestDocument(input);
221221

222222
// intentionally String to pass-through Valuifier#convert and make validation easier
223223
final String atTimestampInSource = "2023-03-12T01:17:38.135792468Z";
@@ -237,7 +237,7 @@ void ingestDocToEventIncludingReservedAtVersionField() {
237237
"@timestamp", "2023-01-17T23:19:04.765182352Z",
238238
"@version", "3",
239239
"message", "hello, world"));
240-
final IngestDocument intermediate = idm.toIngestDocument(input);
240+
final IngestDocumentBridge intermediate = idm.toIngestDocument(input);
241241

242242
final String atVersionInSource = "bananas";
243243
intermediate.setFieldValue(org.logstash.Event.VERSION, atVersionInSource);
@@ -256,7 +256,7 @@ void ingestDocToEventIncludingReservedAtMetadataFieldWithAcceptableShape() {
256256
"@timestamp", "2023-01-17T23:19:04.765182352Z",
257257
"@version", "3", "message",
258258
"hello, world"));
259-
final IngestDocument intermediate = idm.toIngestDocument(input);
259+
final IngestDocumentBridge intermediate = idm.toIngestDocument(input);
260260

261261
final Map<String,Object> atMetadataInSource = Map.of("this", "that","flip", "flop");
262262
intermediate.setFieldValue(org.logstash.Event.METADATA, atMetadataInSource);
@@ -276,7 +276,7 @@ void ingestDocToEventIncludingReservedAtMetadataFieldWithInvalidShape() {
276276
"@timestamp", "2023-01-17T23:19:04.765182352Z",
277277
"@version", "3",
278278
"message", "hello, world"));
279-
final IngestDocument intermediate = idm.toIngestDocument(input);
279+
final IngestDocumentBridge intermediate = idm.toIngestDocument(input);
280280

281281
final List<String> atMetadataInSource = List.of("wrong", "incorrect");
282282
intermediate.setFieldValue(org.logstash.Event.METADATA, atMetadataInSource);
@@ -295,7 +295,7 @@ void ingestDocToEventIncludingReservedAtMetadataFieldWithInvalidShape() {
295295
@Test
296296
void ingestDocToEventIncludingReservedTagsFieldWithInvalidShape() {
297297
final Event input = BasicEventFactory.INSTANCE.newEvent(Map.of("message", "hello, world"));
298-
final IngestDocument intermediate = idm.toIngestDocument(input);
298+
final IngestDocumentBridge intermediate = idm.toIngestDocument(input);
299299

300300
final Map<String,Object> atTagsInSource = Map.of("this", "that");
301301
intermediate.setFieldValue(org.logstash.Event.TAGS, atTagsInSource);
@@ -311,7 +311,7 @@ void ingestDocToEventIncludingReservedTagsFieldWithInvalidShape() {
311311
@Test
312312
void ingestDocToEventIncludingReservedTagsFieldWithInvalidCoercibleShape() {
313313
final Event input = BasicEventFactory.INSTANCE.newEvent(Map.of("message", "hello, world"));
314-
final IngestDocument intermediate = idm.toIngestDocument(input);
314+
final IngestDocumentBridge intermediate = idm.toIngestDocument(input);
315315

316316
final Set<String> atTagsInSource = Set.of("this", "that");
317317
intermediate.setFieldValue(org.logstash.Event.TAGS, atTagsInSource);
@@ -328,7 +328,7 @@ void ingestDocToEventIncludingReservedTagsFieldWithInvalidCoercibleShape() {
328328
@Test
329329
void ingestDocToEventIncludingReservedTagsFieldWithStringShape() {
330330
final Event input = BasicEventFactory.INSTANCE.newEvent(Map.of("message", "hello, world"));
331-
final IngestDocument intermediate = idm.toIngestDocument(input);
331+
final IngestDocumentBridge intermediate = idm.toIngestDocument(input);
332332

333333
final String atTagsInSource = "this";
334334
intermediate.setFieldValue(org.logstash.Event.TAGS, atTagsInSource);
@@ -344,7 +344,7 @@ void ingestDocToEventIncludingReservedTagsFieldWithStringShape() {
344344
@Test
345345
void ingestDocToEventIncludingReservedTagsFieldWithListOfStringShape() {
346346
final Event input = BasicEventFactory.INSTANCE.newEvent(Map.of("message", "hello, world"));
347-
final IngestDocument intermediate = idm.toIngestDocument(input);
347+
final IngestDocumentBridge intermediate = idm.toIngestDocument(input);
348348

349349
final List<String> atTagsInSource = List.of("this", "that");
350350
intermediate.setFieldValue(org.logstash.Event.TAGS, atTagsInSource);
@@ -367,7 +367,7 @@ void ingestDocToEventIncludingReservedTagsFieldWithListOfStringShape() {
367367

368368
@Test void ingestDocToEventIncludingArrayType() {
369369
final Event input = BasicEventFactory.INSTANCE.newEvent(Map.of("message", "hello, world"));
370-
final IngestDocument intermediate = idm.toIngestDocument(input);
370+
final IngestDocumentBridge intermediate = idm.toIngestDocument(input);
371371

372372
final String[] arrayValueInSource = new String[]{"this", "that"};
373373
intermediate.setFieldValue("deeply.nested", arrayValueInSource);
@@ -381,7 +381,7 @@ void ingestDocToEventIncludingReservedTagsFieldWithListOfStringShape() {
381381
@Test
382382
void eventToIngestDocFieldWithNestedZonedDateTimeValue() {
383383
final Event input = BasicEventFactory.INSTANCE.newEvent(Map.of("message", "hello, world"));
384-
final IngestDocument intermediate = idm.toIngestDocument(input);
384+
final IngestDocumentBridge intermediate = idm.toIngestDocument(input);
385385

386386
final String iso8601value = "2023-05-03T03:17:59.182736455Z";
387387
final ZonedDateTime zonedDateTime = ZonedDateTime.parse(iso8601value);
@@ -407,7 +407,7 @@ void eventToIngestDoc() {
407407
"flip", "flop"
408408
)));
409409

410-
final IngestDocument ingestDocument = idm.toIngestDocument(input);
410+
final IngestDocumentBridge ingestDocument = idm.toIngestDocument(input);
411411

412412
final String ingestTimestamp = getIngestDocumentTimestamp(ingestDocument);
413413
assertThat(ingestTimestamp, is(notNullValue()));
@@ -428,7 +428,7 @@ void eventToIngestDocMissingRequiredVersion() {
428428
)));
429429
input.remove(org.logstash.Event.VERSION);
430430

431-
final IngestDocument ingestDocument = idm.toIngestDocument(input);
431+
final IngestDocumentBridge ingestDocument = idm.toIngestDocument(input);
432432

433433
// sensible default
434434
assertThat(ingestDocument.getMetadata().getVersion(), is(equalTo(1L)));
@@ -446,7 +446,7 @@ void eventToIngestDocMissingRequiredTimestamp() {
446446
)));
447447
input.remove(org.logstash.Event.TIMESTAMP);
448448

449-
final IngestDocument ingestDocument = idm.toIngestDocument(input);
449+
final IngestDocumentBridge ingestDocument = idm.toIngestDocument(input);
450450

451451
final String ingestTimestamp = getIngestDocumentTimestamp(ingestDocument);
452452
assertThat(ingestTimestamp, where(Instant::parse, is(recentCurrentTimestamp())));
@@ -470,11 +470,11 @@ Instant getEventTimestamp(final Event event) {
470470
return ((org.logstash.Timestamp) event.getField(org.logstash.Event.TIMESTAMP)).toInstant();
471471
}
472472

473-
String getIngestDocumentTimestamp(final IngestDocument ingestDocument) {
474-
return ingestDocument.getFieldValue(IngestDocument.INGEST_KEY + "." + INGEST_METADATA_TIMESTAMP_FIELD, String.class);
473+
String getIngestDocumentTimestamp(final IngestDocumentBridge ingestDocument) {
474+
return (String) ingestDocument.getIngestMetadata().get(INGEST_METADATA_TIMESTAMP_FIELD);
475475
}
476476

477-
void validateIngestDocument(final IngestDocument ingestDocument, Consumer<IngestDocument> ingestDocumentConsumer) {
477+
void validateIngestDocument(final IngestDocumentBridge ingestDocument, Consumer<IngestDocumentBridge> ingestDocumentConsumer) {
478478
ingestDocumentConsumer.accept(ingestDocument);
479479
}
480480

src/test/java/co/elastic/logstash/filters/elasticintegration/LocalDirectoryPipelineConfigurationResolver.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@
99
import co.elastic.logstash.filters.elasticintegration.resolver.AbstractSimpleResolver;
1010
import org.apache.logging.log4j.LogManager;
1111
import org.apache.logging.log4j.Logger;
12-
import org.elasticsearch.ingest.PipelineConfiguration;
12+
import org.elasticsearch.logstashbridge.ingest.PipelineConfigurationBridge;
1313

1414
import java.io.File;
1515
import java.io.IOException;
1616
import java.nio.file.Files;
1717
import java.nio.file.Path;
1818
import java.util.Optional;
19-
import java.util.function.Consumer;
2019

2120
public class LocalDirectoryPipelineConfigurationResolver
22-
extends AbstractSimpleResolver<String,PipelineConfiguration>
21+
extends AbstractSimpleResolver<String,PipelineConfigurationBridge>
2322
implements PipelineConfigurationResolver {
2423

2524
private static final Logger LOGGER = LogManager.getLogger(LocalDirectoryPipelineConfigurationResolver.class);
@@ -32,7 +31,7 @@ public LocalDirectoryPipelineConfigurationResolver(final Path localDirectory) {
3231
}
3332

3433
@Override
35-
public Optional<PipelineConfiguration> resolveSafely(final String pipelineName) throws Exception {
34+
public Optional<PipelineConfigurationBridge> resolveSafely(final String pipelineName) throws Exception {
3635
final Path pipelinePath = localDirectory.resolve(sanitizePath(pipelineName) + ".json");
3736
LOGGER.trace(() -> String.format("RESOLVING `%s` -> `%s`", pipelineName, pipelinePath));
3837
final File pipelineFile = pipelinePath.toFile();

0 commit comments

Comments
 (0)