Search in sources :

Example 16 with ValidationResult

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());
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 17 with ValidationResult

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());
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 18 with ValidationResult

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.");
    }
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) IOException(java.io.IOException) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) StoreException(uk.gov.gchq.gaffer.store.StoreException)

Example 19 with ValidationResult

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());
}
Also used : KoryphePredicate2(uk.gov.gchq.koryphe.tuple.predicate.KoryphePredicate2) Properties(uk.gov.gchq.gaffer.data.element.Properties) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Test(org.junit.jupiter.api.Test) JSONSerialisationTest(uk.gov.gchq.gaffer.JSONSerialisationTest)

Example 20 with ValidationResult

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;
}
Also used : List(java.util.List) JsonPropertyOrder(com.fasterxml.jackson.annotation.JsonPropertyOrder) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) TupleAdaptedPredicateComposite(uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicateComposite) ToStringBuilder(uk.gov.gchq.gaffer.commonutil.ToStringBuilder) TupleAdaptedPredicate(uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate) Predicate(java.util.function.Predicate) HashCodeBuilder(org.apache.commons.lang3.builder.HashCodeBuilder) ElementTuple(uk.gov.gchq.gaffer.data.element.ElementTuple) Collections(java.util.Collections) Element(uk.gov.gchq.gaffer.data.element.Element) EqualsBuilder(org.apache.commons.lang3.builder.EqualsBuilder) ValidationResult(uk.gov.gchq.koryphe.ValidationResult)

Aggregations

ValidationResult (uk.gov.gchq.koryphe.ValidationResult)132 Test (org.junit.jupiter.api.Test)86 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)32 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)27 HashMap (java.util.HashMap)13 OperationTest (uk.gov.gchq.gaffer.operation.OperationTest)12 ElementAggregator (uk.gov.gchq.gaffer.data.element.function.ElementAggregator)11 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)11 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)9 ExampleTransformFunction (uk.gov.gchq.gaffer.function.ExampleTransformFunction)9 OperationChainValidator (uk.gov.gchq.gaffer.store.operation.OperationChainValidator)9 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)8 Schema (uk.gov.gchq.gaffer.store.schema.Schema)8 Signature (uk.gov.gchq.koryphe.signature.Signature)8 Map (java.util.Map)7 OperationChainOptimiser (uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser)7 Set (java.util.Set)6 Operation (uk.gov.gchq.gaffer.operation.Operation)6 Element (uk.gov.gchq.gaffer.data.element.Element)5 ElementTransformer (uk.gov.gchq.gaffer.data.element.function.ElementTransformer)5