use of uk.gov.gchq.koryphe.impl.predicate.IsEqual in project Gaffer by gchq.
the class ViewValidatorTest method shouldValidateAndReturnTrueForNotFilter.
@Test
public void shouldValidateAndReturnTrueForNotFilter() {
// 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 IsEqual("some value")).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
assertTrue(result.isValid(), result.getErrorString());
}
use of uk.gov.gchq.koryphe.impl.predicate.IsEqual in project Gaffer by gchq.
the class ViewValidatorTest method shouldValidateAndReturnFalseForOrFilterWithIncompatibleProperties.
@Test
public void shouldValidateAndReturnFalseForOrFilterWithIncompatibleProperties() {
// 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 Or.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());
}
use of uk.gov.gchq.koryphe.impl.predicate.IsEqual in project Gaffer by gchq.
the class ViewValidatorTest method shouldValidateAndReturnTrueForAndFilter.
@Test
public void shouldValidateAndReturnTrueForAndFilter() {
// 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 IsEqual("some value")).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
assertTrue(result.isValid(), result.getErrorString());
}
use of uk.gov.gchq.koryphe.impl.predicate.IsEqual in project Gaffer by gchq.
the class AbstractLoaderIT method shouldGetAllFilteredElements.
@TraitRequirement(StoreTrait.PRE_AGGREGATION_FILTERING)
@Test
public void shouldGetAllFilteredElements() throws Exception {
// Then
final GetAllElements op = new GetAllElements.Builder().view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(IdentifierType.VERTEX.name()).execute(new IsEqual("A1")).build()).build()).build()).build();
final CloseableIterable<? extends Element> results = graph.execute(op, getUser());
final List<Element> resultList = Lists.newArrayList(results);
assertThat(resultList).hasSize(1);
assertThat(((Entity) resultList.get(0)).getVertex()).isEqualTo("A1");
}
use of uk.gov.gchq.koryphe.impl.predicate.IsEqual in project Gaffer by gchq.
the class FederatedAddGraphHandlerTest method shouldAddGraphWithCustomReadAccessPredicate.
@Test
public void shouldAddGraphWithCustomReadAccessPredicate() throws Exception {
store.initialise(FEDERATEDSTORE_GRAPH_ID, null, federatedStoreProperties);
final Schema expectedSchema = new Schema.Builder().build();
assertEquals(0, store.getGraphs(testUser, null, ignore).size());
final AccessPredicate allowBlankUserAndTestUserReadAccess = new AccessPredicate(new AdaptedPredicate(new CallMethod("getUserId"), new Or<>(new IsEqual(testUser.getUserId()), new IsEqual(blankUser.getUserId()))));
new FederatedAddGraphHandler().doOperation(new AddGraph.Builder().graphId(EXPECTED_GRAPH_ID).schema(expectedSchema).storeProperties(PROPERTIES).readAccessPredicate(allowBlankUserAndTestUserReadAccess).build(), new Context(testUser), store);
assertEquals(1, store.getGraphs(blankUser, null, ignore).size());
assertEquals(1, store.getGraphs(testUser, null, ignore).size());
}
Aggregations