use of uk.gov.gchq.gaffer.data.element.id.EntityId in project Gaffer by gchq.
the class GetElementsHandlerTest method shouldThrowExceptionIfAnOldOperationOptionIsUsed.
@Test
public void shouldThrowExceptionIfAnOldOperationOptionIsUsed() throws OperationException, StoreException {
// Given
final Iterable<EntityId> ids = mock(Iterable.class);
final GetElementsHandler handler = new GetElementsHandler();
final GetElements getElements = new GetElements.Builder().input(ids).option("accumulostore.operation.return_matched_id_as_edge_source", "true").build();
// When / Then
assertThatIllegalArgumentException().isThrownBy(() -> handler.doOperation(getElements, new Context(), null)).withMessageContaining("return_matched_id_as_edge_source");
}
use of uk.gov.gchq.gaffer.data.element.id.EntityId in project Gaffer by gchq.
the class AbstractAccumuloElementConverterTest method shouldDeserialiseEntityId.
@Test
public void shouldDeserialiseEntityId() {
// Given
final EntityId expectedElementId = new EntitySeed("vertex1");
final Entity entity = new Entity.Builder().vertex("vertex1").group(TestGroups.ENTITY).property(TestPropertyNames.PROP_1, new FreqMap()).property(TestPropertyNames.PROP_2, new FreqMap()).build();
final Key key = converter.getKeyFromEntity(entity);
// When
final ElementId elementId = converter.getElementId(key, false);
// Then
assertEquals(expectedElementId, elementId);
}
use of uk.gov.gchq.gaffer.data.element.id.EntityId in project Gaffer by gchq.
the class AccumuloEntityValueLoaderTest method shouldLoadAllIdentifiers.
@Test
public void shouldLoadAllIdentifiers() throws SerialisationException {
// Given
final String group = TestGroups.ENTITY;
final Key key = mock(Key.class);
final Value value = mock(Value.class);
final AccumuloElementConverter converter = mock(AccumuloElementConverter.class);
final Schema schema = createSchema();
final AccumuloEntityValueLoader loader = new AccumuloEntityValueLoader(group, key, value, converter, schema);
final Entity entity = mock(Entity.class);
final EntityId elementId = new EntitySeed("vertex");
given(converter.getElementId(key, false)).willReturn(elementId);
// When
loader.loadIdentifiers(entity);
// Then
verify(converter, never()).getPropertiesFromColumnQualifier(Mockito.eq(group), Mockito.any(byte[].class));
verify(converter, never()).getPropertiesFromColumnVisibility(Mockito.eq(group), Mockito.any(byte[].class));
verify(converter, never()).getPropertiesFromTimestamp(Mockito.eq(group), Mockito.anyLong());
verify(converter, never()).getPropertiesFromValue(Mockito.eq(group), Mockito.any(Value.class));
}
use of uk.gov.gchq.gaffer.data.element.id.EntityId in project Gaffer by gchq.
the class GetAdjacentIdsTest method shouldGetAdjacentEntityId.
@Test
public void shouldGetAdjacentEntityId() throws OperationException {
// Given
final Graph graph = GetAllElementsHandlerTest.getGraph();
final AddElements addElements = new AddElements.Builder().input(GetAllElementsHandlerTest.getElements()).build();
graph.execute(addElements, new User());
// When - query for A
GetAdjacentIds getAdjacentIds = new GetAdjacentIds.Builder().input(new EntitySeed("A")).build();
CloseableIterable<? extends EntityId> results = graph.execute(getAdjacentIds, new User());
// Then
final Set<EntityId> resultsSet = new HashSet<>();
Streams.toStream(results).forEach(resultsSet::add);
final Set<EntityId> expectedResults = new HashSet<>();
GetAllElementsHandlerTest.getElements().stream().filter(element -> element instanceof Edge).filter(element -> {
final Edge edge = (Edge) element;
if (edge.getSource().equals("A") || edge.getDestination().equals("A")) {
return true;
}
return false;
}).map(element -> {
final Edge edge = (Edge) element;
final Set<EntityId> nodes = new HashSet<>();
nodes.add(new EntitySeed(edge.getSource()));
nodes.add(new EntitySeed(edge.getDestination()));
return nodes;
}).flatMap(nodes -> nodes.stream()).forEach(expectedResults::add);
expectedResults.remove(new EntitySeed("A"));
assertEquals(expectedResults, resultsSet);
// Repeat to ensure iterator can be consumed twice
resultsSet.clear();
Streams.toStream(results).forEach(resultsSet::add);
assertEquals(expectedResults, resultsSet);
// When - query for A and Y2
getAdjacentIds = new GetAdjacentIds.Builder().input(new EntitySeed("A"), new EntitySeed("Y2")).build();
results = graph.execute(getAdjacentIds, new User());
// Then
resultsSet.clear();
Streams.toStream(results).forEach(resultsSet::add);
expectedResults.clear();
GetAllElementsHandlerTest.getElements().stream().filter(element -> element instanceof Edge).filter(element -> {
final Edge edge = (Edge) element;
return edge.getSource().equals("A") || edge.getDestination().equals("A") || edge.getSource().equals("Y2") || edge.getDestination().equals("Y2");
}).map(element -> {
final Edge edge = (Edge) element;
final Set<EntityId> nodes = new HashSet<>();
nodes.add(new EntitySeed(edge.getSource()));
nodes.add(new EntitySeed(edge.getDestination()));
return nodes;
}).flatMap(nodes -> nodes.stream()).forEach(expectedResults::add);
expectedResults.remove(new EntitySeed("A"));
expectedResults.remove(new EntitySeed("Y2"));
assertEquals(expectedResults, resultsSet);
}
use of uk.gov.gchq.gaffer.data.element.id.EntityId in project Gaffer by gchq.
the class GetAdjacentIdsTest method shouldPassValidationOnEntitiesWithoutFilters.
@Test
public void shouldPassValidationOnEntitiesWithoutFilters() throws OperationException {
// Given
final Graph graph = GetAllElementsHandlerTest.getGraph();
final AddElements addElements = new AddElements.Builder().input(GetAllElementsHandlerTest.getElements()).build();
graph.execute(addElements, new User());
// When
final GetAdjacentIds getAdjacentIds = new GetAdjacentIds.Builder().input(new EntitySeed("A"), new EntitySeed("Y2")).view(new View.Builder().edge(GetAllElementsHandlerTest.BASIC_EDGE1, new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select(GetAllElementsHandlerTest.COUNT).execute(new IsMoreThan(5)).build()).build()).entity(GetAllElementsHandlerTest.BASIC_ENTITY, new ViewElementDefinition()).build()).build();
final CloseableIterable<? extends EntityId> results = graph.execute(getAdjacentIds, new User());
// Then
final Set<EntityId> resultsSet = new HashSet<>();
Streams.toStream(results).forEach(resultsSet::add);
final Set<EntityId> expectedResults = new HashSet<>();
GetAllElementsHandlerTest.getElements().stream().filter(element -> element instanceof Edge).filter(element -> element.getGroup().equals(GetAllElementsHandlerTest.BASIC_EDGE1)).filter(element -> {
final Edge edge = (Edge) element;
return edge.getSource().equals("A") || edge.getDestination().equals("A") || edge.getSource().equals("Y2") || edge.getDestination().equals("Y2");
}).filter(element -> ((Integer) element.getProperty(GetAllElementsHandlerTest.COUNT)) > 5).map(element -> {
final Edge edge = (Edge) element;
final Set<EntityId> nodes = new HashSet<>();
nodes.add(new EntitySeed(edge.getSource()));
nodes.add(new EntitySeed(edge.getDestination()));
return nodes;
}).flatMap(nodes -> nodes.stream()).forEach(expectedResults::add);
expectedResults.remove(new EntitySeed("A"));
expectedResults.remove(new EntitySeed("Y2"));
assertEquals(expectedResults, resultsSet);
}
Aggregations