use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.
the class ElementValidatorTest method shouldReturnFalseWhenSchemaValidateWithInvalidElement.
@Test
public void shouldReturnFalseWhenSchemaValidateWithInvalidElement() {
// Given
final Schema schema = mock(Schema.class);
final String group = TestGroups.EDGE;
final Element elm = mock(Element.class);
final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
final ElementFilter filter = mock(ElementFilter.class);
final boolean includeIsA = true;
final ElementValidator validator = new ElementValidator(schema, includeIsA);
given(elm.getGroup()).willReturn(group);
given(schema.getElement(group)).willReturn(elementDef);
given(elementDef.getValidator(includeIsA)).willReturn(filter);
given(filter.filter(elm)).willReturn(false);
// When
final boolean isValid = validator.validate(elm);
// Then
assertFalse(isValid);
}
use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.
the class ElementValidatorTest method shouldReturnTrueWhenSchemaValidateWithValidElement.
@Test
public void shouldReturnTrueWhenSchemaValidateWithValidElement() {
// Given
final Schema schema = mock(Schema.class);
final String group = TestGroups.EDGE;
final Element elm = mock(Element.class);
final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
final ElementFilter filter = mock(ElementFilter.class);
final boolean includeIsA = true;
final ElementValidator validator = new ElementValidator(schema, includeIsA);
given(elm.getGroup()).willReturn(group);
given(schema.getElement(group)).willReturn(elementDef);
given(elementDef.getValidator(includeIsA)).willReturn(filter);
given(filter.filter(elm)).willReturn(true);
// When
final boolean isValid = validator.validate(elm);
// Then
assertTrue(isValid);
}
use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.
the class AccumuloStoreRelationTest method testBuildScanSpecifyColumnsFullView.
@Test
public void testBuildScanSpecifyColumnsFullView() throws OperationException, StoreException {
final Schema schema = getSchema();
final View view = getViewFromSchema(schema);
final String[] requiredColumns = new String[] { "property1" };
testBuildScanSpecifyColumnsWithView("testBuildScanSpecifyColumnsFullView", view, requiredColumns, e -> true);
}
use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.
the class AccumuloStoreRelationTest method testBuildScanWithView.
private void testBuildScanWithView(final String name, final View view, final Predicate<Element> returnElement) throws OperationException, StoreException {
// Given
final SQLContext sqlContext = getSqlContext(name);
final Schema schema = getSchema();
final AccumuloProperties properties = AccumuloProperties.loadStoreProperties(AccumuloStoreRelationTest.class.getResourceAsStream("/store.properties"));
final SingleUseMockAccumuloStore store = new SingleUseMockAccumuloStore();
store.initialise(schema, properties);
addElements(store);
// When
final AccumuloStoreRelation relation = new AccumuloStoreRelation(sqlContext, Collections.emptyList(), view, store, new User());
final RDD<Row> rdd = relation.buildScan();
final Row[] returnedElements = (Row[]) rdd.collect();
// Then
// - Actual results are:
final Set<Row> results = new HashSet<>();
for (int i = 0; i < returnedElements.length; i++) {
results.add(returnedElements[i]);
}
// - Expected results are:
final SchemaToStructTypeConverter schemaConverter = new SchemaToStructTypeConverter(schema, view, new ArrayList<>());
final ConvertElementToRow elementConverter = new ConvertElementToRow(schemaConverter.getUsedProperties(), schemaConverter.getPropertyNeedsConversion(), schemaConverter.getConverterByProperty());
final Set<Row> expectedRows = new HashSet<>();
StreamSupport.stream(getElements().spliterator(), false).filter(returnElement).map(elementConverter::apply).forEach(expectedRows::add);
assertEquals(expectedRows, results);
sqlContext.sparkContext().stop();
}
use of uk.gov.gchq.gaffer.store.schema.Schema in project Gaffer by gchq.
the class AccumuloStoreRelationTest method testBuildScanSpecifyColumnsAndFiltersFullView.
@Test
public void testBuildScanSpecifyColumnsAndFiltersFullView() throws OperationException, StoreException {
final Schema schema = getSchema();
final View view = getViewFromSchema(schema);
final String[] requiredColumns = new String[1];
requiredColumns[0] = "property1";
final Filter[] filters = new Filter[1];
filters[0] = new GreaterThan("property1", 4);
final Predicate<Element> returnElement = (Element element) -> ((Integer) element.getProperty("property1")) > 4;
testBuildScanSpecifyColumnsAndFiltersWithView("testBuildScanSpecifyColumnsAndFiltersFullView", view, requiredColumns, filters, returnElement);
}
Aggregations