use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class AggregatorIteratorTest method test.
private void test(final AccumuloStore store) throws OperationException {
// Given
final Edge expectedResult = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("2").directed(true).property(AccumuloPropertyNames.COUNT, 13).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 1).property(AccumuloPropertyNames.PROP_4, 1).build();
final Edge edge1 = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("2").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.COUNT, 1).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 1).property(AccumuloPropertyNames.PROP_4, 0).build();
final Edge edge2 = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("2").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.COUNT, 2).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 1).build();
final Edge edge3 = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("2").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.COUNT, 10).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 0).build();
final User user = new User();
store.execute(new AddElements.Builder().input(edge1, edge2, edge3).build(), new Context(user));
final GetElements get = new GetElements.Builder().view(new View.Builder().edge(TestGroups.EDGE).build()).input(new EntitySeed("1")).build();
// When
final List<Element> results = Lists.newArrayList(store.execute(get, new Context(user)));
// Then
assertThat(results).hasSize(1);
final Edge aggregatedEdge = (Edge) results.get(0);
assertEquals(expectedResult, aggregatedEdge);
assertEquals(expectedResult.getProperties(), aggregatedEdge.getProperties());
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class AccumuloStoreTest method testAbleToInsertAndRetrieveEntityQueryingEqualAndRelated.
private void testAbleToInsertAndRetrieveEntityQueryingEqualAndRelated(final AccumuloStore store) throws OperationException {
final Entity e = new Entity(TestGroups.ENTITY, "1");
e.putProperty(TestPropertyNames.PROP_1, 1);
e.putProperty(TestPropertyNames.PROP_2, 2);
e.putProperty(TestPropertyNames.PROP_3, 3);
e.putProperty(TestPropertyNames.PROP_4, 4);
e.putProperty(TestPropertyNames.COUNT, 1);
final User user = new User();
final AddElements add = new AddElements.Builder().input(e).build();
store.execute(add, new Context(user));
final EntityId entityId1 = new EntitySeed("1");
final GetElements getBySeed = new GetElements.Builder().view(new View.Builder().entity(TestGroups.ENTITY).build()).input(entityId1).build();
CloseableIterable<? extends Element> results = null;
try {
results = store.execute(getBySeed, new Context(user));
assertEquals(1, Iterables.size(results));
assertTrue(Iterables.contains(results, e));
} finally {
if (results != null) {
results.close();
}
}
final GetElements getRelated = new GetElements.Builder().view(new View.Builder().entity(TestGroups.ENTITY).build()).input(entityId1).build();
CloseableIterable<? extends Element> relatedResults = null;
try {
relatedResults = store.execute(getRelated, store.createContext(user));
assertEquals(1, Iterables.size(relatedResults));
assertTrue(Iterables.contains(relatedResults, e));
final GetElements getRelatedWithPostAggregationFilter = new GetElements.Builder().view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.PROP_1).execute(new IsMoreThan(0)).build()).postAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.COUNT).execute(new IsMoreThan(6)).build()).build()).build()).input(entityId1).build();
relatedResults = store.execute(getRelatedWithPostAggregationFilter, store.createContext(user));
assertEquals(0, Iterables.size(relatedResults));
} finally {
if (relatedResults != null) {
relatedResults.close();
}
}
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class InputFormatTest method shouldReturnCorrectDataToMapReduceJobWithView.
@Test
public void shouldReturnCorrectDataToMapReduceJobWithView() throws Exception {
final Schema schema = getSchema();
final GetElements op = new GetElements.Builder().view(new View.Builder().edge(TestGroups.EDGE).build()).build();
final Set<String> expectedResults = new HashSet<>();
for (final Element element : DATA) {
if (element.getGroup().equals(TestGroups.EDGE)) {
expectedResults.add(getJsonString(element));
}
}
shouldReturnCorrectDataToMapReduceJob(schema, KeyPackage.BYTE_ENTITY_KEY_PACKAGE, DATA, op, new User(), "instance3", expectedResults, tempDir.resolve(UUID.randomUUID().toString()));
shouldReturnCorrectDataToMapReduceJob(schema, KeyPackage.CLASSIC_KEY_PACKAGE, DATA, op, new User(), "instance4", expectedResults, tempDir.resolve(UUID.randomUUID().toString()));
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class InputFormatTest method shouldReturnCorrectDataToMapReduceJobRespectingAuthorizations.
@Test
public void shouldReturnCorrectDataToMapReduceJobRespectingAuthorizations() throws Exception {
final Schema schema = getSchemaWithVisibilities();
final GetElements op = new GetElements.Builder().view(new View()).build();
final Set<String> expectedResultsPublicNotPrivate = new HashSet<>();
final Set<String> expectedResultsPrivate = new HashSet<>();
for (final Element element : DATA_WITH_VISIBILITIES) {
expectedResultsPrivate.add(getJsonString(element));
if (element.getProperty("visibility").equals("public")) {
expectedResultsPublicNotPrivate.add(getJsonString(element));
}
}
final Set<String> privateAuth = new HashSet<>();
privateAuth.add("public");
privateAuth.add("private");
final Set<String> publicNotPrivate = new HashSet<>();
publicNotPrivate.add("public");
final User userWithPrivate = new User("user1", privateAuth);
final User userWithPublicNotPrivate = new User("user1", publicNotPrivate);
shouldReturnCorrectDataToMapReduceJob(schema, KeyPackage.BYTE_ENTITY_KEY_PACKAGE, DATA_WITH_VISIBILITIES, op, userWithPublicNotPrivate, "instance5", expectedResultsPublicNotPrivate, tempDir.resolve(UUID.randomUUID().toString()));
shouldReturnCorrectDataToMapReduceJob(schema, KeyPackage.BYTE_ENTITY_KEY_PACKAGE, DATA_WITH_VISIBILITIES, op, userWithPrivate, "instance6", expectedResultsPrivate, tempDir.resolve(UUID.randomUUID().toString()));
shouldReturnCorrectDataToMapReduceJob(schema, KeyPackage.CLASSIC_KEY_PACKAGE, DATA_WITH_VISIBILITIES, op, userWithPublicNotPrivate, "instance7", expectedResultsPublicNotPrivate, tempDir.resolve(UUID.randomUUID().toString()));
shouldReturnCorrectDataToMapReduceJob(schema, KeyPackage.CLASSIC_KEY_PACKAGE, DATA_WITH_VISIBILITIES, op, userWithPrivate, "instance8", expectedResultsPrivate, tempDir.resolve(UUID.randomUUID().toString()));
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class InputFormatTest method shouldReturnCorrectDataToMapReduceJob.
@Test
public void shouldReturnCorrectDataToMapReduceJob() throws Exception {
final GetElements op = new GetElements.Builder().view(new View()).build();
final Set<String> expectedResults = new HashSet<>();
for (final Element element : DATA) {
expectedResults.add(getJsonString(element));
}
shouldReturnCorrectDataToMapReduceJob(getSchema(), KeyPackage.CLASSIC_KEY_PACKAGE, DATA, op, new User(), "instance1", expectedResults, tempDir.resolve(UUID.randomUUID().toString()));
shouldReturnCorrectDataToMapReduceJob(getSchema(), KeyPackage.BYTE_ENTITY_KEY_PACKAGE, DATA, op, new User(), "instance2", expectedResults, tempDir.resolve(UUID.randomUUID().toString()));
}
Aggregations