use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class ElementValidatorTest method shouldReturnTrueWhenSchemaValidateWithoutIsAWithValidElement.
@Test
public void shouldReturnTrueWhenSchemaValidateWithoutIsAWithValidElement() {
// 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 = false;
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.data.element.Element in project Gaffer by gchq.
the class ElementValidatorTest method shouldReturnFalseWhenNoSchemaElementDefinition.
@Test
public void shouldReturnFalseWhenNoSchemaElementDefinition() {
// Given
final Schema schema = mock(Schema.class);
final String group = TestGroups.EDGE;
final Element elm = mock(Element.class);
final boolean includeIsA = true;
final ElementValidator validator = new ElementValidator(schema, includeIsA);
given(elm.getGroup()).willReturn(group);
given(schema.getElement(group)).willReturn(null);
// When
final boolean isValid = validator.validate(elm);
// Then
assertFalse(isValid);
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class StoreTest method shouldFullyLoadLazyElement.
@Test
public void shouldFullyLoadLazyElement() throws StoreException {
// Given
final StoreProperties properties = mock(StoreProperties.class);
final LazyEntity lazyElement = mock(LazyEntity.class);
final Entity entity = mock(Entity.class);
final Store store = new StoreImpl();
given(lazyElement.getGroup()).willReturn(TestGroups.ENTITY);
given(lazyElement.getElement()).willReturn(entity);
store.initialise(schema, properties);
// When
final Element result = store.populateElement(lazyElement);
// Then
assertSame(entity, result);
verify(lazyElement).getGroup();
verify(lazyElement).getProperty(TestPropertyNames.PROP_1);
verify(lazyElement).getIdentifier(IdentifierType.VERTEX);
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class LoadAndQuery1 method run.
public CloseableIterable<Edge> run() throws OperationException {
// [user] Create a user
// ---------------------------------------------------------
final User user = new User("user01");
// ---------------------------------------------------------
// [generate] Create some edges from the data file using our data generator class
// ---------------------------------------------------------
final List<Element> elements = new ArrayList<>();
final DataGenerator1 dataGenerator = new DataGenerator1();
for (final String s : DataUtils.loadData(getData())) {
elements.add(dataGenerator.getElement(s));
}
// ---------------------------------------------------------
log("Elements generated from the data file.");
for (final Element element : elements) {
log("GENERATED_EDGES", element.toString());
}
log("");
// [graph] Create a graph using our schema and store properties
// ---------------------------------------------------------
final Graph graph = new Graph.Builder().addSchemas(getSchemas()).storeProperties(getStoreProperties()).build();
// ---------------------------------------------------------
// [add] Add the edges to the graph
// ---------------------------------------------------------
final AddElements addElements = new AddElements.Builder().elements(elements).build();
graph.execute(addElements, user);
// ---------------------------------------------------------
log("The elements have been added.\n");
// [get] Get all the edges that contain the vertex "1"
// ---------------------------------------------------------
final GetEdges<EntitySeed> query = new GetEdges.Builder<EntitySeed>().addSeed(new EntitySeed("1")).build();
final CloseableIterable<Edge> results = graph.execute(query, user);
// ---------------------------------------------------------
log("All edges containing the vertex 1. The counts have been aggregated.");
for (final Element e : results) {
log("GET_RELATED_EDGES_RESULT", e.toString());
}
return results;
}
use of uk.gov.gchq.gaffer.data.element.Element 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