use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.
the class GetElementsHandlerTest method shouldReturnHBaseRetrieverWithIncludeMatchedVertex.
@Test
public void shouldReturnHBaseRetrieverWithIncludeMatchedVertex() throws OperationException, StoreException {
// Given
final Iterable<EntityId> ids = mock(Iterable.class);
final Context context = mock(Context.class);
final User user = mock(User.class);
final HBaseStore store = mock(HBaseStore.class);
final HBaseRetriever<GetElements> hbaseRetriever = mock(HBaseRetriever.class);
final GetElementsHandler handler = new GetElementsHandler();
final GetElements getElements = new GetElements.Builder().inputIds(ids).seedMatching(SeedMatching.SeedMatchingType.RELATED).build();
given(context.getUser()).willReturn(user);
given(store.createRetriever(getElements, user, ids, true)).willReturn(hbaseRetriever);
// When
final HBaseRetriever<GetElements> result = (HBaseRetriever<GetElements>) handler.doOperation(getElements, context, store);
// Then
assertSame(hbaseRetriever, result);
}
use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.
the class GetAllElementsHandlerTest method testGetAllElementsWithViewRestrictedByGroupAndAPreAggregationFilter.
@Test
public void testGetAllElementsWithViewRestrictedByGroupAndAPreAggregationFilter() throws OperationException {
// Given
final Graph graph = getGraph();
final AddElements addElements = new AddElements.Builder().input(getElements()).build();
graph.execute(addElements, new User());
// When
final GetAllElements getAllElements = new GetAllElements.Builder().view(new View.Builder().edge(BASIC_EDGE1, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(COUNT).execute(new IsMoreThan(5)).build()).build()).build()).build();
final CloseableIterable<? extends Element> results = graph.execute(getAllElements, new User());
// Then
final Set<Element> resultsSet = new HashSet<>();
Streams.toStream(results).forEach(resultsSet::add);
final Set<Element> expectedResults = new HashSet<>();
getElements().stream().filter(e -> e.getGroup().equals(BASIC_EDGE1) && ((int) e.getProperty(COUNT)) > 5).forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
}
use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.
the class GetAllElementsHandlerTest method testGetAllElementsWithViewRestrictedByGroup.
@Test
public void testGetAllElementsWithViewRestrictedByGroup() throws OperationException {
// Given
final Graph graph = getGraph();
final AddElements addElements = new AddElements.Builder().input(getElements()).build();
graph.execute(addElements, new User());
// When
final GetAllElements getAllElements = new GetAllElements.Builder().view(new View.Builder().edge(BASIC_EDGE1).build()).build();
final CloseableIterable<? extends Element> results = graph.execute(getAllElements, new User());
// Then
final Set<Element> resultsSet = new HashSet<>();
Streams.toStream(results).forEach(resultsSet::add);
final Set<Element> expectedResults = new HashSet<>();
getElements().stream().filter(e -> e.getGroup().equals(BASIC_EDGE1)).forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
}
use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.
the class GetAllElementsHandlerTest method testGetAllElementsWithViewRestrictedByGroupAndAPostAggregationFilter.
@Test
public void testGetAllElementsWithViewRestrictedByGroupAndAPostAggregationFilter() throws OperationException {
// Given
final Graph graph = getGraph();
final AddElements addElements = new AddElements.Builder().input(getElements()).build();
graph.execute(addElements, new User());
// When
final GetAllElements getAllElements = new GetAllElements.Builder().view(new View.Builder().edge(BASIC_EDGE1, new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select(COUNT).execute(new IsMoreThan(5)).build()).build()).build()).build();
final CloseableIterable<? extends Element> results = graph.execute(getAllElements, new User());
// Then
final Set<Element> resultsSet = new HashSet<>();
Streams.toStream(results).forEach(resultsSet::add);
final Set<Element> expectedResults = new HashSet<>();
getElements().stream().filter(e -> e.getGroup().equals(BASIC_EDGE1) && ((int) e.getProperty(COUNT)) > 5).forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
}
use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.
the class NamedViewDetailTest method shouldMaintainOrderingAfterBeingEvaluated.
@Test
public void shouldMaintainOrderingAfterBeingEvaluated() {
// Given
NamedViewDetail namedViewDetail = new NamedViewDetail.Builder().name("view").view(new View()).writers(Arrays.asList("c", "b", "a")).build();
// When
// Don't actually care about the result
namedViewDetail.hasWriteAccess(new User());
// Then
assertEquals(Arrays.asList("c", "b", "a"), namedViewDetail.getWriteAccessRoles());
}
Aggregations