Search in sources :

Example 21 with ValidationResult

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

the class GetWalksTest method shouldValidateWhenPreFiltersContainsAnOperationWhichDoesNotAllowAnInput.

@Test
public void shouldValidateWhenPreFiltersContainsAnOperationWhichDoesNotAllowAnInput() {
    // Given
    final GetWalks getWalks = new GetWalks.Builder().input(new EntitySeed("1"), new EntitySeed("2")).operations(new OperationChain.Builder().first(new ScoreOperationChain()).then(new DiscardOutput()).then(new GetElements.Builder().input().view(new View.Builder().edge(TestGroups.EDGE).build()).build()).build()).build();
    // Then
    final ValidationResult result = getWalks.validate();
    assertFalse(result.isValid());
    assertTrue(result.getErrorString().contains("The first operation in operation chain 0: " + ScoreOperationChain.class.getName() + " is not be able to accept the input seeds."), result.getErrorString());
}
Also used : EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.jupiter.api.Test)

Example 22 with ValidationResult

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

the class GetWalksTest method shouldValidateWhenOperationContainsMultipleHops.

@Test
public void shouldValidateWhenOperationContainsMultipleHops() {
    // Given
    final GetWalks getWalks = new GetWalks.Builder().input(new EntitySeed("1"), new EntitySeed("2")).operations(new OperationChain.Builder().first(new GetElements.Builder().input((Iterable<? extends ElementId>) null).view(new View.Builder().edge(TestGroups.EDGE).build()).build()).then(new GetElements.Builder().input((Iterable<? extends ElementId>) null).view(new View.Builder().edge(TestGroups.EDGE).build()).build()).build()).build();
    // Then
    final ValidationResult result = getWalks.validate();
    assertFalse(result.isValid());
    assertTrue(result.getErrorString().contains("All operations must contain a single hop. Operation ") && result.getErrorString().contains(" contains multiple hops"), result.getErrorString());
}
Also used : GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.jupiter.api.Test)

Example 23 with ValidationResult

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

the class GetWalksTest method shouldValidateWhenOperationListContainsAnEmptyOperationChain.

@Test
public void shouldValidateWhenOperationListContainsAnEmptyOperationChain() {
    // Given
    final GetWalks getWalks = new GetWalks.Builder().input(new EntitySeed("1"), new EntitySeed("2")).operations(new GetElements.Builder().input((Iterable<? extends ElementId>) null).view(new View.Builder().edge(TestGroups.EDGE).build()).build(), new OperationChain()).build();
    // Then
    final ValidationResult result = getWalks.validate();
    assertFalse(result.isValid());
    assertTrue(result.getErrorString().contains("Operation chain 1 contains no operations"), result.getErrorString());
}
Also used : OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.jupiter.api.Test)

Example 24 with ValidationResult

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

the class GetWalksTest method shouldValidateWhenOperationListDoesNotContainAGetElementsOperation.

@Test
public void shouldValidateWhenOperationListDoesNotContainAGetElementsOperation() {
    // Given
    final GetWalks getWalks = new GetWalks.Builder().input(new EntitySeed("1"), new EntitySeed("2")).operations(new GetElements.Builder().input((Iterable<? extends ElementId>) null).view(new View.Builder().edge(TestGroups.EDGE).build()).build(), new OperationChain.Builder().first(new AddElements()).build(), new GetElements.Builder().input((Iterable<? extends ElementId>) null).view(new View.Builder().edge(TestGroups.EDGE).build()).build()).build();
    // Then
    final ValidationResult result = getWalks.validate();
    assertFalse(result.isValid());
    assertTrue(result.getErrorString().contains("All operations must contain a single hop. Operation 1 does not contain a hop."), result.getErrorString());
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.jupiter.api.Test)

Example 25 with ValidationResult

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

the class OperationTest method shouldValidateRequiredFields.

@Test
public void shouldValidateRequiredFields() throws Exception {
    // Given
    final Operation op = getTestObject();
    // When
    final ValidationResult validationResult = op.validate();
    // Then
    final Set<String> requiredFields = getRequiredFields();
    final Set<String> requiredFieldsErrors = requiredFields.stream().map(f -> f + " is required for: " + op.getClass().getSimpleName()).collect(Collectors.toSet());
    assertEquals(requiredFieldsErrors, validationResult.getErrors());
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Set(java.util.Set) JSONSerialisationTest(uk.gov.gchq.gaffer.JSONSerialisationTest) HashMap(java.util.HashMap) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) VersionUtil(uk.gov.gchq.koryphe.util.VersionUtil) Since(uk.gov.gchq.koryphe.Since) SummaryUtil(uk.gov.gchq.koryphe.util.SummaryUtil) Map(java.util.Map) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Summary(uk.gov.gchq.koryphe.Summary) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Collections(java.util.Collections) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) JSONSerialisationTest(uk.gov.gchq.gaffer.JSONSerialisationTest) 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