Search in sources :

Example 21 with Exists

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

the class SchemaTest method shouldReturnTrueWhenSchemaHasValidatorEntityPropertyFilters.

@Test
public void shouldReturnTrueWhenSchemaHasValidatorEntityPropertyFilters() {
    // Given
    final Schema schema = new Schema.Builder().entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().property(TestPropertyNames.PROP_1, "str").build()).type("str", new TypeDefinition.Builder().validateFunctions(new Exists()).build()).edge(TestGroups.EDGE, new SchemaEdgeDefinition()).build();
    // When
    final boolean result = schema.hasValidation();
    // Then
    assertTrue(result);
}
Also used : Exists(uk.gov.gchq.koryphe.impl.predicate.Exists) Test(org.junit.jupiter.api.Test)

Example 22 with Exists

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

the class ViewValidatorTest method shouldValidateAndReturnFalseWhenMissingTraits.

@Test
public void shouldValidateAndReturnFalseWhenMissingTraits() {
    // Given
    final ViewValidator validator = new ViewValidator();
    final View view = new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().transientProperty(TestPropertyNames.PROP_3, String.class).preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.PROP_1).execute(new Exists()).build()).aggregator(new ElementAggregator.Builder().select(TestPropertyNames.PROP_1).execute(new StringConcat()).build()).postAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.PROP_2).execute(new Exists()).build()).transformer(new ElementTransformer.Builder().select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2).execute(new ExampleTransformFunction()).project(TestPropertyNames.PROP_3).build()).postTransformFilter(new ElementFilter.Builder().select(TestPropertyNames.PROP_3).execute(new Exists()).build()).build()).build();
    final Schema schema = new Schema.Builder().type("obj", String.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, NO_STORE_TRAITS);
    // Then
    final String errPrefix = "This store does not currently support ";
    assertFalse(result.isValid());
    assertEquals(Sets.newHashSet(errPrefix + StoreTrait.PRE_AGGREGATION_FILTERING.name(), errPrefix + StoreTrait.QUERY_AGGREGATION.name(), errPrefix + StoreTrait.POST_AGGREGATION_FILTERING.name(), errPrefix + StoreTrait.TRANSFORMATION.name(), errPrefix + StoreTrait.POST_TRANSFORMATION_FILTERING.name()), result.getErrors());
}
Also used : StringConcat(uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat) ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Exists(uk.gov.gchq.koryphe.impl.predicate.Exists) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ExampleTransformFunction(uk.gov.gchq.gaffer.function.ExampleTransformFunction) Test(org.junit.jupiter.api.Test)

Example 23 with Exists

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

the class WhileTest method shouldShallowCloneOperation.

@Test
@Override
public void shouldShallowCloneOperation() {
    // Given
    final EntitySeed input = new EntitySeed("E");
    final Predicate predicate = new Exists();
    final Operation delegate = new GetAdjacentIds();
    final int maxRepeats = 5;
    final While operation = new While.Builder<>().input(input).maxRepeats(maxRepeats).conditional(predicate).operation(delegate).build();
    // When
    final While clone = operation.shallowClone();
    // Then
    assertNotSame(operation, clone);
    assertEquals(input, clone.getInput());
    assertEquals(maxRepeats, clone.getMaxRepeats());
}
Also used : GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) Exists(uk.gov.gchq.koryphe.impl.predicate.Exists) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Operation(uk.gov.gchq.gaffer.operation.Operation) Predicate(java.util.function.Predicate) Test(org.junit.jupiter.api.Test) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest)

Example 24 with Exists

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

the class UpdateViewHookTest method shouldMergeAndApplyWhiteList.

@Test
public void shouldMergeAndApplyWhiteList() throws Exception {
    updateViewHook.setViewToMerge(viewToMerge);
    updateViewHook.setWithOpAuth(Sets.newHashSet("opA"));
    updateViewHook.setWhiteListElementGroups(Sets.newHashSet("white2", "white1", "testGroup"));
    opChain = new OperationChain.Builder().first(new GetAllElements.Builder().view(new View.Builder().entity("wrong1").entity("white1").entity("white2").edge("testGroup", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("prop1").execute(new Exists()).build()).build()).build()).build()).build();
    updateViewHook.preExecute(opChain, new Context(new User.Builder().opAuth("opA").build()));
    GetAllElements op = (GetAllElements) opChain.getOperations().get(0);
    JsonAssert.assertEquals(new View.Builder().entity("white1", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("prop1").execute(new IsIn("value1", "value2")).build()).build()).entity("white2").edge("testGroup", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("prop1").execute(new Exists()).select("count").execute(new IsMoreThan(10)).build()).build()).build().toJson(true), op.getView().toJson(true));
    assertTrue(op.getView().getGroups().contains("testGroup"));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Builder(uk.gov.gchq.gaffer.user.User.Builder) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) IsIn(uk.gov.gchq.koryphe.impl.predicate.IsIn) Exists(uk.gov.gchq.koryphe.impl.predicate.Exists) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) Test(org.junit.jupiter.api.Test)

Example 25 with Exists

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

the class ViewTest method shouldReturnTrueWhenViewHasPostAggEdgeFilters.

@Test
public void shouldReturnTrueWhenViewHasPostAggEdgeFilters() {
    // Given
    final View view = new View.Builder().entity(TestGroups.ENTITY).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.PROP_1).execute(new Exists()).build()).build()).edge(TestGroups.EDGE_2, null).build();
    // When
    final boolean result = view.hasPostAggregationFilters();
    // Then
    assertTrue(result);
}
Also used : Exists(uk.gov.gchq.koryphe.impl.predicate.Exists) JSONSerialisationTest(uk.gov.gchq.gaffer.JSONSerialisationTest) Test(org.junit.jupiter.api.Test)

Aggregations

Exists (uk.gov.gchq.koryphe.impl.predicate.Exists)38 Test (org.junit.jupiter.api.Test)31 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)12 JSONSerialisationTest (uk.gov.gchq.gaffer.JSONSerialisationTest)9 Schema (uk.gov.gchq.gaffer.store.schema.Schema)9 AccumuloStore (uk.gov.gchq.gaffer.accumulostore.AccumuloStore)8 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)6 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)6 HashMap (java.util.HashMap)5 Map (java.util.Map)3 MiniAccumuloStore (uk.gov.gchq.gaffer.accumulostore.MiniAccumuloStore)3 SingleUseMiniAccumuloStore (uk.gov.gchq.gaffer.accumulostore.SingleUseMiniAccumuloStore)3 AccumuloElementConverter (uk.gov.gchq.gaffer.accumulostore.key.AccumuloElementConverter)3 AccumuloKeyPackage (uk.gov.gchq.gaffer.accumulostore.key.AccumuloKeyPackage)3 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)3 ExampleFilterFunction (uk.gov.gchq.gaffer.function.ExampleFilterFunction)3 Operation (uk.gov.gchq.gaffer.operation.Operation)3 StringConcat (uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat)3 Date (java.util.Date)2 List (java.util.List)2