use of org.apache.ignite.configuration.validation.ValidationIssue in project ignite-3 by apache.
the class ConfigurationPresentationTest method beforeAll.
/**
* Before all.
*/
@BeforeAll
static void beforeAll() {
Validator<Value, Object> validator = new Validator<>() {
/**
* {@inheritDoc}
*/
@Override
public void validate(Value annotation, ValidationContext<Object> ctx) {
if (Objects.equals("error", ctx.getNewValue())) {
ctx.addIssue(new ValidationIssue("Error word"));
}
}
};
cfgRegistry = new ConfigurationRegistry(List.of(TestRootConfiguration.KEY), Map.of(Value.class, Set.of(validator)), new TestConfigurationStorage(LOCAL), List.of(), List.of());
cfgRegistry.start();
cfgPresentation = new HoconPresentation(cfgRegistry);
cfg = cfgRegistry.getConfiguration(TestRootConfiguration.KEY);
}
use of org.apache.ignite.configuration.validation.ValidationIssue in project ignite-3 by apache.
the class ImmutableValidator method validate.
/**
* {@inheritDoc}
*/
@Override
public void validate(Immutable annotation, ValidationContext<Object> ctx) {
Object oldValue = ctx.getOldValue();
Object newValue = ctx.getNewValue();
if (oldValue != null && !Objects.deepEquals(oldValue, newValue)) {
ctx.addIssue(new ValidationIssue("'" + ctx.currentKey() + "' configuration value is immutable and cannot be updated [curVal=" + oldValue + ", newVal=" + newValue + ']'));
}
}
use of org.apache.ignite.configuration.validation.ValidationIssue in project ignite-3 by apache.
the class OneOfValidator method validate.
/**
* {@inheritDoc}
*/
@Override
public void validate(OneOf annotation, ValidationContext<String> ctx) {
String value = ctx.getNewValue();
boolean caseSensitive = annotation.caseSensitive();
for (String exp : annotation.value()) {
if (caseSensitive ? exp.equals(value) : exp.equalsIgnoreCase(value)) {
return;
}
}
String message = "'" + ctx.currentKey() + "' configuration value must be one of " + Arrays.toString(annotation.value()) + (caseSensitive ? " (case sensitive)" : " (case insensitive)");
ctx.addIssue(new ValidationIssue(message));
}
use of org.apache.ignite.configuration.validation.ValidationIssue in project ignite-3 by apache.
the class TableValidatorImpl method validate.
/**
* {@inheritDoc}
*/
@Override
public void validate(TableValidator annotation, ValidationContext<NamedListView<TableView>> ctx) {
NamedListView<TableView> oldTables = ctx.getOldValue();
NamedListView<TableView> newTables = ctx.getNewValue();
for (String tableName : newTables.namedListKeys()) {
TableView newTable = newTables.get(tableName);
try {
TableDefinitionImpl tbl = SchemaConfigurationConverter.convert(newTable);
assert !tbl.keyColumns().isEmpty();
assert !tbl.colocationColumns().isEmpty();
TableDefinitionBuilderImpl.validateIndices(tbl.indices(), tbl.columns(), tbl.colocationColumns());
} catch (IllegalArgumentException e) {
ctx.addIssue(new ValidationIssue("Validator works success by key " + ctx.currentKey() + ". Found " + newTable.columns().size() + " columns"));
}
validateDataRegion(oldTables == null ? null : oldTables.get(tableName), newTable, ctx);
validateNamedListKeys(newTable, ctx);
}
}
use of org.apache.ignite.configuration.validation.ValidationIssue in project ignite-3 by apache.
the class OneOfValidatorTest method testValidate.
/**
* Test.
*/
@ParameterizedTest
@ValueSource(booleans = { false, true })
public void testValidate(boolean caseSensitive) {
// Prepare mocked annotation instance.
OneOf oneOfAnnotation = mock(OneOf.class);
when(oneOfAnnotation.value()).thenReturn(new String[] { "foo", "bar" });
when(oneOfAnnotation.caseSensitive()).thenReturn(caseSensitive);
// Prepare mocked validation context.
ValidationContext<String> ctx = mock(ValidationContext.class);
when(ctx.currentKey()).thenReturn("x");
when(ctx.getNewValue()).thenReturn("foo", "Bar", "no");
// Prepare issues captor.
ArgumentCaptor<ValidationIssue> issuesCaptor = ArgumentCaptor.forClass(ValidationIssue.class);
doNothing().when(ctx).addIssue(issuesCaptor.capture());
// Instantiate validator.
OneOfValidator oneOfValidator = new OneOfValidator();
// Assert that valid value produces no issues.
oneOfValidator.validate(oneOfAnnotation, ctx);
assertThat(issuesCaptor.getAllValues(), is(empty()));
// Assert that case sencitivity affects validation.
oneOfValidator.validate(oneOfAnnotation, ctx);
if (caseSensitive) {
assertThat(issuesCaptor.getValue().message(), is("'x' configuration value must be one of [foo, bar] (case sensitive)"));
} else {
assertThat(issuesCaptor.getAllValues(), is(empty()));
}
// Assert that unacceptable value produces validation issue.
oneOfValidator.validate(oneOfAnnotation, ctx);
if (caseSensitive) {
assertThat(issuesCaptor.getValue().message(), is("'x' configuration value must be one of [foo, bar] (case sensitive)"));
} else {
assertThat(issuesCaptor.getValue().message(), is("'x' configuration value must be one of [foo, bar] (case insensitive)"));
}
}
Aggregations