Search in sources :

Example 1 with GetRequest

use of org.opensearch.client.opensearch.core.GetRequest in project opensearch-java by opensearch-project.

the class ClassStructureTest method testRequiredProperty.

@Test
public void testRequiredProperty() {
    // All required properties present
    GetRequest r = GetRequest.of(b -> b.index("foo").id("bar"));
    // Missing id property throws an exception
    MissingRequiredPropertyException ex = assertThrows(MissingRequiredPropertyException.class, () -> {
        GetRequest r1 = GetRequest.of(b -> b.index("foo"));
    });
    assertEquals("id", ex.getPropertyName());
    // Disable checks, missing id property is accepted.
    try (ApiTypeHelper.DisabledChecksHandle h = ApiTypeHelper.DANGEROUS_disableRequiredPropertiesCheck(true)) {
        GetRequest r1 = GetRequest.of(b -> b.index("foo"));
        assertNull(r1.id());
    }
    // Checks are enabled again after the try block
    ex = assertThrows(MissingRequiredPropertyException.class, () -> {
        GetRequest r1 = GetRequest.of(b -> b.index("foo"));
    });
    assertEquals("id", ex.getPropertyName());
}
Also used : Buckets(org.opensearch.client.opensearch._types.aggregations.Buckets) Arrays(java.util.Arrays) Aggregation(org.opensearch.client.opensearch._types.aggregations.Aggregation) GetRequest(org.opensearch.client.opensearch.core.GetRequest) HashMap(java.util.HashMap) Aggregate(org.opensearch.client.opensearch._types.aggregations.Aggregate) RangeBucket(org.opensearch.client.opensearch._types.aggregations.RangeBucket) ValueCountAggregation(org.opensearch.client.opensearch._types.aggregations.ValueCountAggregation) ObjectBuilder(org.opensearch.client.util.ObjectBuilder) TotalHitsRelation(org.opensearch.client.opensearch.core.search.TotalHitsRelation) ApiTypeHelper(org.opensearch.client.util.ApiTypeHelper) Map(java.util.Map) HitsMetadata(org.opensearch.client.opensearch.core.search.HitsMetadata) Method(java.lang.reflect.Method) Nullable(javax.annotation.Nullable) ErrorCause(org.opensearch.client.opensearch._types.ErrorCause) JsonData(org.opensearch.client.json.JsonData) Test(org.junit.Test) TotalHits(org.opensearch.client.opensearch.core.search.TotalHits) Collectors(java.util.stream.Collectors) IntervalsQuery(org.opensearch.client.opensearch._types.query_dsl.IntervalsQuery) DateRangeAggregate(org.opensearch.client.opensearch._types.aggregations.DateRangeAggregate) MissingRequiredPropertyException(org.opensearch.client.util.MissingRequiredPropertyException) List(java.util.List) SearchRequest(org.opensearch.client.opensearch.core.SearchRequest) CardinalityAggregate(org.opensearch.client.opensearch._types.aggregations.CardinalityAggregate) FieldAndFormat(org.opensearch.client.opensearch._types.query_dsl.FieldAndFormat) Collections(java.util.Collections) ApiTypeHelper(org.opensearch.client.util.ApiTypeHelper) GetRequest(org.opensearch.client.opensearch.core.GetRequest) MissingRequiredPropertyException(org.opensearch.client.util.MissingRequiredPropertyException) Test(org.junit.Test)

Aggregations

Method (java.lang.reflect.Method)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 Test (org.junit.Test)1 JsonData (org.opensearch.client.json.JsonData)1 ErrorCause (org.opensearch.client.opensearch._types.ErrorCause)1 Aggregate (org.opensearch.client.opensearch._types.aggregations.Aggregate)1 Aggregation (org.opensearch.client.opensearch._types.aggregations.Aggregation)1 Buckets (org.opensearch.client.opensearch._types.aggregations.Buckets)1 CardinalityAggregate (org.opensearch.client.opensearch._types.aggregations.CardinalityAggregate)1 DateRangeAggregate (org.opensearch.client.opensearch._types.aggregations.DateRangeAggregate)1 RangeBucket (org.opensearch.client.opensearch._types.aggregations.RangeBucket)1 ValueCountAggregation (org.opensearch.client.opensearch._types.aggregations.ValueCountAggregation)1 FieldAndFormat (org.opensearch.client.opensearch._types.query_dsl.FieldAndFormat)1 IntervalsQuery (org.opensearch.client.opensearch._types.query_dsl.IntervalsQuery)1