use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.
the class AccumuloAggregationIT method shouldAggregateOverAllPropertiesExceptForGroupByProperties.
@Test
public void shouldAggregateOverAllPropertiesExceptForGroupByProperties() throws OperationException, UnsupportedEncodingException {
final Graph graph = createGraph();
final Entity entity1 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "some value").property(AccumuloPropertyNames.COLUMN_QUALIFIER_2, "some value 2").property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "some value 3").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "some value 4").property(AccumuloPropertyNames.VISIBILITY, PUBLIC_VISIBILITY).build();
final Entity entity2 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "some value").property(AccumuloPropertyNames.COLUMN_QUALIFIER_2, "some value 2b").property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "some value 3b").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "some value 4b").property(AccumuloPropertyNames.VISIBILITY, PRIVATE_VISIBILITY).build();
final Entity entity3 = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "some value c").property(AccumuloPropertyNames.COLUMN_QUALIFIER_2, "some value 2c").property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "some value 3c").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "some value 4c").property(AccumuloPropertyNames.VISIBILITY, PRIVATE_VISIBILITY).build();
graph.execute(new AddElements(Arrays.asList((Element) entity1, entity2, entity3)), USER);
// Given
final GetEntities<EntitySeed> getElements = new GetEntities.Builder<EntitySeed>().addSeed(new EntitySeed(VERTEX)).view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().groupBy(AccumuloPropertyNames.COLUMN_QUALIFIER).build()).build()).build();
// When
final List<Entity> results = Lists.newArrayList(graph.execute(getElements, USER));
// Then
assertNotNull(results);
assertEquals(2, results.size());
final Entity expectedEntity = new Entity.Builder().vertex(VERTEX).group(TestGroups.ENTITY).property(AccumuloPropertyNames.COLUMN_QUALIFIER, "some value").property(AccumuloPropertyNames.COLUMN_QUALIFIER_2, "some value 2,some value 2b").property(AccumuloPropertyNames.COLUMN_QUALIFIER_3, "some value 3,some value 3b").property(AccumuloPropertyNames.COLUMN_QUALIFIER_4, "some value 4,some value 4b").property(AccumuloPropertyNames.VISIBILITY, PUBLIC_VISIBILITY + "," + PRIVATE_VISIBILITY).build();
assertThat(results, IsCollectionContaining.hasItems(expectedEntity, entity3));
}
use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.
the class StoreTest method shouldThrowExceptionIfOperationViewIsInvalid.
@Test
public void shouldThrowExceptionIfOperationViewIsInvalid() throws OperationException, StoreException {
// Given
// Given
final Schema schema = createSchemaMock();
final StoreProperties properties = mock(StoreProperties.class);
final AddElements addElements = new AddElements();
final View view = mock(View.class);
final ViewValidator viewValidator = mock(ViewValidator.class);
final StoreImpl store = new StoreImpl(viewValidator);
addElements.setView(view);
given(schema.validate()).willReturn(true);
given(viewValidator.validate(view, schema, true)).willReturn(false);
store.initialise(schema, properties);
// When / Then
try {
store.execute(addElements, user);
fail("Exception expected");
} catch (final SchemaException e) {
verify(viewValidator).validate(view, schema, true);
assertTrue(e.getMessage().contains("View"));
}
}
use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.
the class StoreTest method shouldCreateStoreWithValidSchemasAndRegisterOperations.
@Test
public void shouldCreateStoreWithValidSchemasAndRegisterOperations() throws StoreException {
// Given
final StoreProperties properties = mock(StoreProperties.class);
final StoreImpl store = new StoreImpl();
final OperationHandler<AddElements, Void> addElementsHandlerOverridden = mock(OperationHandler.class);
final OperationDeclarations opDeclarations = new OperationDeclarations.Builder().declaration(new OperationDeclaration.Builder().operation(AddElements.class).handler(addElementsHandlerOverridden).build()).build();
given(properties.getOperationDeclarations()).willReturn(opDeclarations);
// When
store.initialise(schema, properties);
// Then
assertNotNull(store.getOperationHandlerExposed(Validate.class));
assertSame(addElementsHandlerOverridden, store.getOperationHandlerExposed(AddElements.class));
assertSame(getAllElementsHandler, store.getOperationHandlerExposed(GetAllElements.class));
assertSame(getAllElementsHandler, store.getOperationHandlerExposed(GetAllEntities.class));
assertSame(getAllElementsHandler, store.getOperationHandlerExposed(GetAllEdges.class));
assertTrue(store.getOperationHandlerExposed(GenerateElements.class) instanceof GenerateElementsHandler);
assertTrue(store.getOperationHandlerExposed(GenerateObjects.class) instanceof GenerateObjectsHandler);
assertTrue(store.getOperationHandlerExposed(CountGroups.class) instanceof CountGroupsHandler);
assertTrue(store.getOperationHandlerExposed(Deduplicate.class) instanceof DeduplicateHandler);
assertTrue(store.getOperationHandlerExposed(ExportToSet.class) instanceof ExportToSetHandler);
assertTrue(store.getOperationHandlerExposed(GetSetExport.class) instanceof GetSetExportHandler);
assertEquals(1, store.getCreateOperationHandlersCallCount());
assertSame(schema, store.getSchema());
assertSame(properties, store.getProperties());
verify(schemaOptimiser).optimise(schema, true);
}
use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.
the class StoreTest method shouldHandleMultiStepOperations.
@Test
public void shouldHandleMultiStepOperations() throws Exception {
// Given
final Schema schema = createSchemaMock();
final StoreProperties properties = mock(StoreProperties.class);
final StoreImpl store = new StoreImpl();
final CloseableIterable<Element> getElementsResult = mock(CloseableIterable.class);
final AddElements addElements1 = new AddElements();
final GetElements<ElementSeed, Element> getElements = new GetElements<>();
final OperationChain<CloseableIterable<Element>> opChain = new OperationChain.Builder().first(addElements1).then(getElements).build();
given(addElementsHandler.doOperation(addElements1, context, store)).willReturn(null);
given(getElementsHandler.doOperation(getElements, context, store)).willReturn(getElementsResult);
store.initialise(schema, properties);
// When
final CloseableIterable<Element> result = store.execute(opChain, user);
// Then
assertSame(getElementsResult, result);
}
use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.
the class GetElementsinRangesHandlerTest method setupGraph.
private static void setupGraph(final AccumuloStore store, final int numEntries) {
final List<Element> elements = new ArrayList<>();
for (int i = 0; i < numEntries; i++) {
String s = "" + i;
while (s.length() < 4) {
s = "0" + s;
}
final Edge edge = new Edge(TestGroups.EDGE);
edge.setSource(s);
edge.putProperty(AccumuloPropertyNames.COLUMN_QUALIFIER, 1);
edge.setDestination("B");
edge.setDirected(true);
elements.add(edge);
final Edge edge2 = new Edge(TestGroups.EDGE);
edge2.setSource(s);
edge2.putProperty(AccumuloPropertyNames.COLUMN_QUALIFIER, 3);
edge2.setDestination("B");
edge2.setDirected(true);
elements.add(edge2);
final Edge edge3 = new Edge(TestGroups.EDGE);
edge3.setSource(s);
edge3.putProperty(AccumuloPropertyNames.COLUMN_QUALIFIER, 5);
edge3.setDestination("B");
edge3.setDirected(true);
elements.add(edge3);
}
try {
store.execute(new AddElements(elements), user);
} catch (OperationException e) {
fail("Couldn't add element: " + e);
}
}
Aggregations