Search in sources :

Example 51 with ValidationResult

use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.

the class SchemaOperationChainUtilTest method shouldValidateValidOperationChainAgainstSchema.

@Test
public void shouldValidateValidOperationChainAgainstSchema() {
    // When
    final ValidationResult validationResult = SchemaOperationChainUtil.validate(schema, validOperationChain);
    // Then
    assertTrue(validationResult.isValid());
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 52 with ValidationResult

use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.

the class SchemaOperationChainUtilTest method shouldValidateInvalidOperationChainAgainstSchema.

@Test
public void shouldValidateInvalidOperationChainAgainstSchema() {
    // When
    final ValidationResult validationResult = SchemaOperationChainUtil.validate(schema, invalidOperationChain);
    // Then
    assertFalse(validationResult.isValid());
    assertThat(validationResult.getErrorString()).contains("elementGenerator is required for: AddElementsFromSocket").contains("hostname is required for: AddElementsFromSocket");
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 53 with ValidationResult

use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.

the class OperationChainHandlerTest method shouldHandleNestedOperationChain.

@Test
public void shouldHandleNestedOperationChain() throws OperationException {
    // Given
    final OperationChainValidator opChainValidator = mock(OperationChainValidator.class);
    final List<OperationChainOptimiser> opChainOptimisers = Collections.emptyList();
    final OperationChainHandler opChainHandler = new OperationChainHandler(opChainValidator, opChainOptimisers);
    final Context context = mock(Context.class);
    final Store store = mock(Store.class);
    final User user = mock(User.class);
    final StoreProperties storeProperties = new StoreProperties();
    final GetAdjacentIds op1 = mock(GetAdjacentIds.class);
    final GetElements op2 = mock(GetElements.class);
    final Limit op3 = mock(Limit.class);
    final OperationChain opChain1 = new OperationChain(Arrays.asList(op1, op2));
    final OperationChain opChain2 = new OperationChain(Arrays.asList(opChain1, op3));
    final Entity entityA = new Entity.Builder().group(TestGroups.ENTITY).vertex("A").build();
    final Entity entityB = new Entity.Builder().group(TestGroups.ENTITY).vertex("B").build();
    given(context.getUser()).willReturn(user);
    given(store.getProperties()).willReturn(storeProperties);
    given(opChainValidator.validate(any(), any(), any())).willReturn(new ValidationResult());
    given(store.handleOperation(op1, context)).willReturn(new WrappedCloseableIterable<>(Lists.newArrayList(new EntitySeed("A"), new EntitySeed("B"))));
    given(store.handleOperation(op2, context)).willReturn(new WrappedCloseableIterable<>(Lists.newArrayList(entityA, entityB)));
    given(store.handleOperation(op3, context)).willReturn(entityA);
    // When
    final Object result = opChainHandler.doOperation(opChain2, context, store);
    // Then
    assertSame(entityA, result);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) Store(uk.gov.gchq.gaffer.store.Store) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) OperationChainValidator(uk.gov.gchq.gaffer.store.operation.OperationChainValidator) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) OperationChainOptimiser(uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 54 with ValidationResult

use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.

the class ValidateOperationChainHandlerTest method shouldReturnValidationResultWithErrorsIfOperationChainInvalid.

@Test
public void shouldReturnValidationResultWithErrorsIfOperationChainInvalid() throws OperationException {
    // Given
    final AddElementsFromSocket addElementsFromSocket = new AddElementsFromSocket();
    OperationChain chain = new OperationChain.Builder().first(addElementsFromSocket).build();
    ValidateOperationChain validateOperationChain = new ValidateOperationChain.Builder().operationChain(chain).build();
    given(store.getOperationChainValidator()).willReturn(new OperationChainValidator(new ViewValidator()));
    ValidateOperationChainHandler handler = new ValidateOperationChainHandler();
    // When
    ValidationResult result = handler.doOperation(validateOperationChain, context, store);
    // Then
    assertFalse(result.isValid());
    assertTrue(result.getErrorString().contains("elementGenerator is required for: AddElementsFromSocket"));
    assertTrue(result.getErrorString().contains("hostname is required for: AddElementsFromSocket"));
}
Also used : ViewValidator(uk.gov.gchq.gaffer.store.schema.ViewValidator) ValidateOperationChain(uk.gov.gchq.gaffer.operation.impl.ValidateOperationChain) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ValidateOperationChain(uk.gov.gchq.gaffer.operation.impl.ValidateOperationChain) AddElementsFromSocket(uk.gov.gchq.gaffer.operation.impl.add.AddElementsFromSocket) OperationChainValidator(uk.gov.gchq.gaffer.store.operation.OperationChainValidator) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 55 with ValidationResult

use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.

the class OperationChainValidatorTest method shouldInValidateNullElementDef.

@Test
public void shouldInValidateNullElementDef() {
    // Given
    final ViewValidator viewValidator = mock(ViewValidator.class);
    final OperationChainValidator validator = new OperationChainValidator(viewValidator);
    final Store store = mock(Store.class);
    Schema schema = mock(Schema.class);
    given(store.getSchema()).willReturn(schema);
    given(schema.getElement(Mockito.anyString())).willReturn(null);
    Max max = new Max();
    max.setComparators(Lists.newArrayList(new ElementPropertyComparator.Builder().groups(TestGroups.ENTITY).property("property").build()));
    ValidationResult validationResult = new ValidationResult();
    // When
    validator.validateComparables(max, null, store, validationResult);
    // Then
    assertEquals(false, validationResult.isValid());
    Set<String> errors = validationResult.getErrors();
    assertThat(errors).hasSize(1);
    errors.contains(Max.class.getName() + " references BasicEntity group that does not exist in the schema");
}
Also used : Max(uk.gov.gchq.gaffer.operation.impl.compare.Max) ViewValidator(uk.gov.gchq.gaffer.store.schema.ViewValidator) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) ElementPropertyComparator(uk.gov.gchq.gaffer.data.element.comparison.ElementPropertyComparator) Test(org.junit.jupiter.api.Test)

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