Skip to content

Commit

Permalink
Add a failing test for toJsonString function when using a Range Query
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeperello-scopely committed Sep 17, 2024
1 parent 8e5c38c commit 897a5c7
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Collections;
import org.junit.Assert;
import org.junit.Test;
import org.opensearch.client.json.JsonData;
import org.opensearch.client.opensearch._types.FieldValue;
import org.opensearch.client.opensearch._types.Result;
import org.opensearch.client.opensearch.core.IndexResponse;
Expand Down Expand Up @@ -67,4 +68,27 @@ public void testSearchRequest() {

}

// Test SearchRequest with range query
@Test
public void testRangeQuery() {

String expectedStringValue =
"{\"aggregations\":{},\"query\":{\"range\":{\"age\":{\"gte\":\"2024-01-01T00:00:00Z\",\"lte\":\"2024-01-02T00:00:00Z\",\"format\":\"strict_date_optional_time\"}}},\"terminate_after\":5}";

SearchRequest searchRequest = SearchRequest.of(
request -> request.index("index1", "index2")
.aggregations(Collections.emptyMap())
.terminateAfter(5L)
.query(
q -> q.range(
r -> r.field("age")
.gte(JsonData.of("2024-01-01T00:00:00Z"))
.lte(JsonData.of("2024-01-02T00:00:00Z"))
.format("strict_date_optional_time")
)
)
);
String searchRequestString = searchRequest.toJsonString();
assertEquals(expectedStringValue, searchRequestString);
}
}

0 comments on commit 897a5c7

Please sign in to comment.