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());
}
Aggregations