Skip to content

Commit

Permalink
Set 'id' field when deserializing a PutPipelineRequest
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Schlindwein <[email protected]>
  • Loading branch information
patschl authored and Patrick Schlindwein committed Dec 31, 2023
1 parent 5239303 commit b6c6d4b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ protected static void setupPutPipelineRequestDeserializer(ObjectDeserializer<Put

op.add(Builder::meta, JsonpDeserializer.stringMapDeserializer(JsonData._DESERIALIZER), "_meta");
op.add(Builder::description, JsonpDeserializer.stringDeserializer(), "description");
op.add(Builder::id, JsonpDeserializer.stringDeserializer(), "id");
op.add(Builder::onFailure, JsonpDeserializer.arrayDeserializer(Processor._DESERIALIZER), "on_failure");
op.add(Builder::processors, JsonpDeserializer.arrayDeserializer(Processor._DESERIALIZER), "processors");
op.add(Builder::version, JsonpDeserializer.longDeserializer(), "version");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@

import java.util.Arrays;
import java.util.Map;

import org.junit.Test;
import org.opensearch.client.json.JsonData;
import org.opensearch.client.opensearch._types.Time;
import org.opensearch.client.opensearch._types.analysis.Analyzer;
import org.opensearch.client.opensearch._types.analysis.TokenFilterDefinition;
Expand All @@ -53,6 +55,8 @@
import org.opensearch.client.opensearch.indices.IndexSettingsSearch;
import org.opensearch.client.opensearch.indices.Translog;
import org.opensearch.client.opensearch.indices.get_field_mapping.TypeFieldMappings;
import org.opensearch.client.opensearch.ingest.ConvertType;
import org.opensearch.client.opensearch.ingest.PutPipelineRequest;
import org.opensearch.client.opensearch.model.ModelTestCase;

public class ParsingTests extends ModelTestCase {
Expand Down Expand Up @@ -320,11 +324,11 @@ public void testIndexSettingsSearch() {
s -> s.level("info")
.threshold(
t -> t.query(
it -> it.debug(Time.of(ti -> ti.time("500ms")))
.info(Time.of(ti -> ti.time("1000ms")))
.trace(Time.of(ti -> ti.time("200ms")))
.warn(Time.of(ti -> ti.time("5000ms")))
)
it -> it.debug(Time.of(ti -> ti.time("500ms")))
.info(Time.of(ti -> ti.time("1000ms")))
.trace(Time.of(ti -> ti.time("200ms")))
.warn(Time.of(ti -> ti.time("5000ms")))
)
.fetch(
it -> it.debug(Time.of(ti -> ti.time("5ms")))
.info(Time.of(ti -> ti.time("10ms")))
Expand Down Expand Up @@ -357,4 +361,29 @@ public void testIndexSettingsSearch() {
assertEquals(search.idle().after().time(), deserialized.idle().after().time());

}

@Test
public void testPutPipelineRequestDeserialization() {
var putPipelineRequest = PutPipelineRequest.of(b ->
b.id("test-pipeline")
.description("pipeline desc")
.processors(p -> p.convert(c -> c.field("age").targetField("age").type(ConvertType.Integer)))
);

var input = "{\"id\":\"test-pipeline\",\"description\":\"pipeline desc\"," +
"\"processors\":[{\"convert\":{\"field\":\"age\",\"target_field\":\"age\",\"type\":\"integer\"}}]}";

var deserialized = fromJson(input, PutPipelineRequest._DESERIALIZER);

assertEquals(putPipelineRequest.id(), deserialized.id());
assertEquals(putPipelineRequest.description(), deserialized.description());
assertEquals(putPipelineRequest.processors().size(), deserialized.processors().size());

var processor = putPipelineRequest.processors().get(0);
var deserializedProcessor = deserialized.processors().get(0);
assertEquals(processor._kind(), deserializedProcessor._kind());
assertEquals(processor.convert().field(), deserializedProcessor.convert().field());
assertEquals(processor.convert().targetField(), deserializedProcessor.convert().targetField());
assertEquals(processor.convert().type(), deserializedProcessor.convert().type());
}
}

0 comments on commit b6c6d4b

Please sign in to comment.