use of org.opensearch.client.opensearch._types.aggregations.StatsAggregate in project opensearch-java by opensearch-project.
the class BuiltinTypesTest method testNullableDouble.
@Test
public void testNullableDouble() {
StatsAggregate stats;
// Regular values
stats = StatsAggregate.statsAggregateOf(b -> // Parent classes can't have an overloaded "of" method
b.count(10).min(1.0).avg(1.5).max(2.0).sum(5.0));
stats = checkJsonRoundtrip(stats, "{\"count\":10,\"min\":1.0,\"max\":2.0,\"avg\":1.5,\"sum\":5.0}");
assertEquals(10, stats.count());
assertEquals(1.0, stats.min(), 0.01);
assertEquals(1.5, stats.avg(), 0.01);
assertEquals(2.0, stats.max(), 0.01);
assertEquals(5.0, stats.sum(), 0.01);
// Missing values (JSON null, Java infinite)
String json = "{\"count\":0,\"min\":null,\"max\":null,\"avg\":null,\"sum\":0.0}";
stats = fromJson(json, StatsAggregate.class);
assertEquals(0, stats.count());
assertTrue(Double.isInfinite(stats.min()));
assertEquals(0.0, stats.avg(), 0.01);
assertTrue(Double.isInfinite(stats.max()));
assertEquals(0.0, stats.sum(), 0.01);
// We don't serialize finite default values as null
assertEquals("{\"count\":0,\"min\":null,\"max\":null,\"avg\":0.0,\"sum\":0.0}", toJson(stats));
}
Aggregations