Search in sources :

Example 86 with User

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);
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) HBaseStore(uk.gov.gchq.gaffer.hbasestore.HBaseStore) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) HBaseRetriever(uk.gov.gchq.gaffer.hbasestore.retriever.HBaseRetriever) Test(org.junit.jupiter.api.Test)

Example 87 with User

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);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) IntStream(java.util.stream.IntStream) StoreException(uk.gov.gchq.gaffer.store.StoreException) User(uk.gov.gchq.gaffer.user.User) HashMap(java.util.HashMap) GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Graph(uk.gov.gchq.gaffer.graph.Graph) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Map(java.util.Map) Edge(uk.gov.gchq.gaffer.data.element.Edge) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) TestGroups(uk.gov.gchq.gaffer.commonutil.TestGroups) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) StreamUtil(uk.gov.gchq.gaffer.commonutil.StreamUtil) DirectedType(uk.gov.gchq.gaffer.data.element.id.DirectedType) MapStoreProperties(uk.gov.gchq.gaffer.mapstore.MapStoreProperties) Set(java.util.Set) Entity(uk.gov.gchq.gaffer.data.element.Entity) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) Schema(uk.gov.gchq.gaffer.store.schema.Schema) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Streams(uk.gov.gchq.gaffer.commonutil.stream.Streams) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) Graph(uk.gov.gchq.gaffer.graph.Graph) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 88 with User

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);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) IntStream(java.util.stream.IntStream) StoreException(uk.gov.gchq.gaffer.store.StoreException) User(uk.gov.gchq.gaffer.user.User) HashMap(java.util.HashMap) GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Graph(uk.gov.gchq.gaffer.graph.Graph) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Map(java.util.Map) Edge(uk.gov.gchq.gaffer.data.element.Edge) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) TestGroups(uk.gov.gchq.gaffer.commonutil.TestGroups) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) StreamUtil(uk.gov.gchq.gaffer.commonutil.StreamUtil) DirectedType(uk.gov.gchq.gaffer.data.element.id.DirectedType) MapStoreProperties(uk.gov.gchq.gaffer.mapstore.MapStoreProperties) Set(java.util.Set) Entity(uk.gov.gchq.gaffer.data.element.Entity) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) Schema(uk.gov.gchq.gaffer.store.schema.Schema) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Streams(uk.gov.gchq.gaffer.commonutil.stream.Streams) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) Graph(uk.gov.gchq.gaffer.graph.Graph) User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 89 with User

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);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) IntStream(java.util.stream.IntStream) StoreException(uk.gov.gchq.gaffer.store.StoreException) User(uk.gov.gchq.gaffer.user.User) HashMap(java.util.HashMap) GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Graph(uk.gov.gchq.gaffer.graph.Graph) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Map(java.util.Map) Edge(uk.gov.gchq.gaffer.data.element.Edge) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) TestGroups(uk.gov.gchq.gaffer.commonutil.TestGroups) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) StreamUtil(uk.gov.gchq.gaffer.commonutil.StreamUtil) DirectedType(uk.gov.gchq.gaffer.data.element.id.DirectedType) MapStoreProperties(uk.gov.gchq.gaffer.mapstore.MapStoreProperties) Set(java.util.Set) Entity(uk.gov.gchq.gaffer.data.element.Entity) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) Schema(uk.gov.gchq.gaffer.store.schema.Schema) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Streams(uk.gov.gchq.gaffer.commonutil.stream.Streams) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) Graph(uk.gov.gchq.gaffer.graph.Graph) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 90 with User

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());
}
Also used : User(uk.gov.gchq.gaffer.user.User) Test(org.junit.jupiter.api.Test)

Aggregations

User (uk.gov.gchq.gaffer.user.User)378 Test (org.junit.jupiter.api.Test)188 Graph (uk.gov.gchq.gaffer.graph.Graph)155 Element (uk.gov.gchq.gaffer.data.element.Element)143 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)128 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)110 HashSet (java.util.HashSet)109 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)104 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)103 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)98 Edge (uk.gov.gchq.gaffer.data.element.Edge)85 Context (uk.gov.gchq.gaffer.store.Context)85 Entity (uk.gov.gchq.gaffer.data.element.Entity)77 Test (org.junit.Test)61 ArrayList (java.util.ArrayList)57 OperationException (uk.gov.gchq.gaffer.operation.OperationException)52 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)49 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)48 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)45 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)43