use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class SchemaEntityDefinitionTest method shouldPassValidationWhenVertexDefined.
@Test
public void shouldPassValidationWhenVertexDefined() {
// Given
final SchemaEntityDefinition elementDef = new SchemaEntityDefinition.Builder().vertex("vertex.string").build();
new Schema.Builder().entity(TestGroups.ENTITY, elementDef).type("vertex.string", String.class).build();
final SchemaElementDefinitionValidator validator = new SchemaElementDefinitionValidator();
// When
final ValidationResult result = validator.validate(elementDef);
// Then
assertTrue(result.isValid());
}
use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class SchemaEntityDefinitionTest method shouldFailValidationWhenVertexNotDefined.
@Test
public void shouldFailValidationWhenVertexNotDefined() {
// Given
final SchemaEntityDefinition elementDef = new SchemaEntityDefinition.Builder().vertex(null).build();
final Schema schema = new Schema.Builder().entity(TestGroups.ENTITY, elementDef).type("vertex.string", String.class).build();
final SchemaElementDefinitionValidator validator = new SchemaElementDefinitionValidator();
// When
final ValidationResult result = validator.validate(elementDef);
// Then
assertFalse(result.isValid());
}
use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class TableUtils method validateTable.
private static void validateTable(final TableName tableName, final Admin admin) throws StoreException {
final ValidationResult validationResult = new ValidationResult();
final HTableDescriptor descriptor;
try {
descriptor = admin.getTableDescriptor(tableName);
} catch (final IOException e) {
throw new StoreException("Unable to look up the table coprocessors", e);
}
final HColumnDescriptor col = descriptor.getFamily(HBaseStoreConstants.getColFam());
if (null == col) {
validationResult.addError("The Gaffer element 'e' column family does not exist");
} else if (Integer.MAX_VALUE != col.getMaxVersions()) {
validationResult.addError("The maximum number of versions should be set to " + Integer.MAX_VALUE);
}
if (!descriptor.hasCoprocessor(GafferCoprocessor.class.getName())) {
validationResult.addError("Missing coprocessor: " + GafferCoprocessor.class.getName());
}
if (!validationResult.isValid()) {
throw new StoreException("Your table " + tableName + " is configured incorrectly. " + validationResult.getErrorString() + "\nEither delete the table and let Gaffer create it for you or fix it manually using the HBase shell or the Gaffer TableUtils utility.");
}
}
use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class PropertiesFilterTest method shouldTestPropertiesOnPredicate2WithValidationResult.
@Test
public void shouldTestPropertiesOnPredicate2WithValidationResult() {
// Given
final PropertiesFilter propertiesFilter = new PropertiesFilter.Builder().select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2).execute(new KoryphePredicate2<String, String>() {
@Override
public boolean test(final String o, final String o2) {
return "value".equals(o) && "value2".equals(o2);
}
}).build();
final Properties correctProperties = new Properties();
correctProperties.put(TestPropertyNames.PROP_1, "value");
correctProperties.put(TestPropertyNames.PROP_2, "value2");
final Properties incorrectProperties = new Properties();
incorrectProperties.put(TestPropertyNames.PROP_1, "value_incorrect");
incorrectProperties.put(TestPropertyNames.PROP_2, "value2_incorrect");
// When
final ValidationResult correctResult = propertiesFilter.testWithValidationResult(correctProperties);
final ValidationResult incorrectResult = propertiesFilter.testWithValidationResult(incorrectProperties);
// Then
assertTrue(correctResult.isValid());
assertFalse(incorrectResult.isValid());
assertTrue(incorrectResult.getErrorString().contains("{property1: <java.lang.String>value_incorrect, property2: <java.lang.String>value2_incorrect}"), "Result was: " + incorrectResult.getErrorString());
}
use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class ElementFilter method testWithValidationResult.
public ValidationResult testWithValidationResult(final Element element) {
final ValidationResult result = new ValidationResult();
elementTuple.setElement(element);
components.stream().filter(predicate -> !predicate.test(elementTuple)).forEach(predicate -> result.addError(getErrorMsg(predicate)));
return result;
}
Aggregations