Search in sources :

Example 56 with IsMoreThan

use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project Gaffer by gchq.

the class SchemaElementDefinitionValidatorTest method shouldValidateFunctionSelectionsAndReturnFalseWhenFunctionTypeDoesNotEqualSelectionType.

@Test
public void shouldValidateFunctionSelectionsAndReturnFalseWhenFunctionTypeDoesNotEqualSelectionType() {
    // Given
    final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
    given(elementDef.getPropertyClass("selection")).willReturn((Class) String.class);
    final IsMoreThan function = new IsMoreThan(5);
    final ElementFilter elementFilter = new ElementFilter.Builder().select("selection").execute(function).build();
    final SchemaElementDefinitionValidator validator = new SchemaElementDefinitionValidator();
    // When
    final ValidationResult result = validator.validateFunctionArgumentTypes(elementFilter, elementDef);
    // Then
    assertFalse(result.isValid());
    assertEquals("Validation errors: \nControl value class java.lang.Integer is not compatible" + " with the input type: class java.lang.String", result.getErrorString());
}
Also used : ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 57 with IsMoreThan

use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project Gaffer by gchq.

the class ViewValidatorTest method shouldValidateAndReturnFalseForNotFilterWithIncompatibleProperties.

@Test
public void shouldValidateAndReturnFalseForNotFilterWithIncompatibleProperties() {
    // Given
    final ViewValidator validator = new ViewValidator();
    final View view = new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2).execute(new Not<>(new Or.Builder<>().select(0).execute(new IsMoreThan("abcd")).select(1).execute(new IsEqual("some other value")).build())).build()).build()).build();
    final Schema schema = new Schema.Builder().type("int", Integer.class).type("string", String.class).entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().property(TestPropertyNames.PROP_1, "int").property(TestPropertyNames.PROP_2, "string").build()).build();
    // When
    final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS);
    // Then
    assertFalse(result.isValid());
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) IsEqual(uk.gov.gchq.koryphe.impl.predicate.IsEqual) Not(uk.gov.gchq.koryphe.impl.predicate.Not) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) Test(org.junit.jupiter.api.Test)

Example 58 with IsMoreThan

use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project Gaffer by gchq.

the class ViewValidatorTest method shouldValidateAndReturnFalseForAndFilterWithIncompatibleProperties.

@Test
public void shouldValidateAndReturnFalseForAndFilterWithIncompatibleProperties() {
    // Given
    final ViewValidator validator = new ViewValidator();
    final View view = new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2).execute(new And.Builder().select(0).execute(new IsMoreThan(2)).select(1).execute(new IsEqual("some other value")).build()).build()).build()).build();
    final Schema schema = new Schema.Builder().type("obj", Object.class).type("string", String.class).entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().property(TestPropertyNames.PROP_1, "obj").property(TestPropertyNames.PROP_2, "string").build()).build();
    // When
    final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS);
    // Then
    assertFalse(result.isValid());
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) IsEqual(uk.gov.gchq.koryphe.impl.predicate.IsEqual) And(uk.gov.gchq.koryphe.impl.predicate.And) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) Test(org.junit.jupiter.api.Test)

Example 59 with IsMoreThan

use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project Gaffer by gchq.

the class ViewValidatorTest method shouldValidateAndReturnTrueWithMatchedVertexFilter.

@Test
public void shouldValidateAndReturnTrueWithMatchedVertexFilter() {
    // Given
    final ViewValidator validator = new ViewValidator();
    final View view = new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(IdentifierType.MATCHED_VERTEX.name()).execute(new IsMoreThan("testValue1")).build()).postAggregationFilter(new ElementFilter.Builder().select(IdentifierType.ADJACENT_MATCHED_VERTEX.name()).execute(new IsMoreThan("testValue2")).build()).postTransformFilter(new ElementFilter.Builder().select(IdentifierType.MATCHED_VERTEX.name()).execute(new IsMoreThan("testValue3")).build()).build()).build();
    Schema schema = new Schema.Builder().type("double", Double.class).type("int", Integer.class).type("string", String.class).type("true", Boolean.class).type("vertex", String.class).edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().source("vertex").destination("vertex").directed("true").property(TestPropertyNames.PROP_1, "double").property(TestPropertyNames.PROP_2, "int").property(TestPropertyNames.PROP_3, "string").build()).build();
    // When
    final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS);
    // Then
    assertTrue(result.isValid(), result.getErrorString());
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) Test(org.junit.jupiter.api.Test)

Example 60 with IsMoreThan

use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project Gaffer by gchq.

the class FilterTest method builderShouldCreatePopulatedOperation.

@Test
@Override
public void builderShouldCreatePopulatedOperation() {
    // Given
    final Filter filter = new Filter.Builder().input(new Entity("road"), new Edge("railway")).entity("road", new ElementFilter.Builder().select("count").execute(new IsMoreThan(10)).build()).entity("road2", new ElementFilter.Builder().select("count").execute(new IsMoreThan(20)).build()).build();
    // Then
    assertNotNull(filter.getInput());
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) Edge(uk.gov.gchq.gaffer.data.element.Edge) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.jupiter.api.Test)

Aggregations

IsMoreThan (uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)72 Test (org.junit.jupiter.api.Test)42 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)40 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)34 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)24 Element (uk.gov.gchq.gaffer.data.element.Element)22 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)22 Edge (uk.gov.gchq.gaffer.data.element.Edge)20 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)20 User (uk.gov.gchq.gaffer.user.User)20 Graph (uk.gov.gchq.gaffer.graph.Graph)19 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)19 ArrayList (java.util.ArrayList)18 HashSet (java.util.HashSet)16 Entity (uk.gov.gchq.gaffer.data.element.Entity)16 IsEqual (uk.gov.gchq.koryphe.impl.predicate.IsEqual)13 IsLessThan (uk.gov.gchq.koryphe.impl.predicate.IsLessThan)13 Set (java.util.Set)12 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)12 OperationException (uk.gov.gchq.gaffer.operation.OperationException)12