-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: provide additional to deserialize parent aggregation
- Loading branch information
1 parent
2a32357
commit 675b8fb
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
java-client/src/test/java/org/opensearch/client/opensearch/core/AggregateResponseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.client.opensearch.core; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import java.io.StringReader; | ||
import org.junit.Test; | ||
import org.opensearch.client.opensearch._types.aggregations.Aggregate; | ||
import org.opensearch.client.opensearch.model.ModelTestCase; | ||
|
||
public class AggregateResponseTest extends ModelTestCase { | ||
|
||
@Test | ||
public void shouldCreateParentAggregate() { | ||
// given | ||
final var aggregate = Aggregate.of((b) -> b.parent((p) -> p.docCount(789L))); | ||
|
||
// when | ||
final var parentAggregate = aggregate.parent(); | ||
|
||
// then | ||
assertEquals(parentAggregate._aggregateKind(), Aggregate.Kind.Parent); | ||
assertEquals(parentAggregate.docCount(), 789L); | ||
} | ||
|
||
@Test | ||
public void shouldDeserializeParentAggregate() throws JsonProcessingException { | ||
// given | ||
final var parentAggreationJson = "{\"took\": 3,\"timed_out\": false," | ||
+ "\"_shards\": {\"total\": 1,\"successful\": 1,\"skipped\": 0,\"failed\": 0}," | ||
+ "\"hits\": {\"total\": {\"value\": 0,\"relation\": \"eq\"},\"hits\": []}," | ||
+ "\"aggregations\": {\"parent#foo\": {\"doc_count\": 123456}}}"; | ||
final var parser = mapper.jsonProvider().createParser(new StringReader(parentAggreationJson)); | ||
|
||
// when | ||
final var response = SearchResponse._DESERIALIZER.deserialize(parser, mapper); | ||
|
||
// then | ||
final var aggregations = response.aggregations(); | ||
assertFalse(aggregations.isEmpty()); | ||
assertTrue(aggregations.containsKey("foo")); | ||
assertEquals(aggregations.get("foo").parent()._aggregateKind(), Aggregate.Kind.Parent); | ||
assertEquals(aggregations.get("foo").parent().docCount(), 123456L); | ||
} | ||
} |