Search in sources :

Example 1 with OperationView

use of uk.gov.gchq.gaffer.operation.graph.OperationView in project Gaffer by gchq.

the class UpdateViewHookTest method shouldApplyWhiteLists.

@Test
public void shouldApplyWhiteLists() throws Exception {
    opChain = new OperationChain.Builder().first(new GetAllElements.Builder().view(new View.Builder().entity("wrong1").entity("white1").entity("white2").build()).build()).build();
    updateViewHook.setWhiteListElementGroups(Sets.newHashSet("white2", "white1"));
    updateViewHook.preExecute(opChain, new Context(new User.Builder().opAuth("opA").build()));
    Object op = opChain.getOperations().get(0);
    assertThat(op).isInstanceOf(OperationView.class);
    assertThat(((OperationView) op).getView().getEntities().keySet()).contains("white1", "white2").hasSize(2);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Builder(uk.gov.gchq.gaffer.user.User.Builder) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.jupiter.api.Test)

Example 2 with OperationView

use of uk.gov.gchq.gaffer.operation.graph.OperationView in project Gaffer by gchq.

the class UpdateViewHookTest method shouldNotMergeWithWrongUser.

@Test
public void shouldNotMergeWithWrongUser() throws Exception {
    updateViewHook.setViewToMerge(viewToMerge);
    updateViewHook.setWithOpAuth(Sets.newHashSet("opA"));
    opChain = new OperationChain<>(new GetAllElements());
    updateViewHook.preExecute(opChain, new Context(new User()));
    Object op = opChain.getOperations().get(0);
    assertThat(op).isInstanceOf(OperationView.class);
    assertThat(((OperationView) op).getView()).isNull();
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) Test(org.junit.jupiter.api.Test)

Example 3 with OperationView

use of uk.gov.gchq.gaffer.operation.graph.OperationView in project Gaffer by gchq.

the class UpdateViewHookTest method shouldDoNothingWithNullMerge.

@Test
public void shouldDoNothingWithNullMerge() throws Exception {
    GetAllElements operationView = new GetAllElements();
    operationView.setView(new View());
    View view = updateViewHook.mergeView(operationView, null).build();
    assertThat(view.getGroups()).isEmpty();
}
Also used : GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.jupiter.api.Test)

Example 4 with OperationView

use of uk.gov.gchq.gaffer.operation.graph.OperationView in project Gaffer by gchq.

the class UpdateViewHookTest method shouldNotAddExtraGroupsToUsersViewInGetAdjacentIds.

@Test
public void shouldNotAddExtraGroupsToUsersViewInGetAdjacentIds() throws Exception {
    opChain = new OperationChain.Builder().first(new GetAdjacentIds.Builder().view(new View.Builder().edge("edge1").build()).build()).build();
    updateViewHook.setViewToMerge(new View.Builder().entity("entity2").edge("edge2").build());
    updateViewHook.preExecute(opChain, new Context(new User.Builder().opAuth("opA").build()));
    Object op = opChain.getOperations().get(0);
    assertThat(op).isInstanceOf(OperationView.class);
    assertThat(((OperationView) op).getView().getEntityGroups()).isEmpty();
    assertThat(((OperationView) op).getView().getEdgeGroups()).containsExactly("edge1");
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Builder(uk.gov.gchq.gaffer.user.User.Builder) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.jupiter.api.Test)

Example 5 with OperationView

use of uk.gov.gchq.gaffer.operation.graph.OperationView in project Gaffer by gchq.

the class NamedViewResolverTest method shouldBuildFullViewWhenAViewToBeMergedIsSupplied.

@Test
public void shouldBuildFullViewWhenAViewToBeMergedIsSupplied() throws CacheOperationFailedException {
    // Given
    final View viewToMerge = new View.Builder().edge(TestGroups.EDGE).build();
    final View finalExpectedView = new View.Builder().edge(TestGroups.EDGE).merge(FULL_VIEW).build();
    given(CACHE.getNamedView(NAMED_VIEW_NAME, CONTEXT.getUser())).willReturn(FULL_NAMED_VIEW_DETAIL);
    given(CACHE.getNamedView(NAMED_VIEW_NAME + 1, CONTEXT.getUser())).willReturn(null);
    final OperationChain<?> opChain = new OperationChain.Builder().first(new GetElements.Builder().view(new NamedView.Builder().name(NAMED_VIEW_NAME).merge(viewToMerge).build()).build()).build();
    // When
    RESOLVER.preExecute(opChain, CONTEXT);
    // Then
    JsonAssert.assertEquals(finalExpectedView.toCompactJson(), ((OperationView) opChain.getOperations().get(0)).getView().toCompactJson());
}
Also used : OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) NamedView(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) NamedView(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.jupiter.api.Test)

Aggregations

OperationView (uk.gov.gchq.gaffer.operation.graph.OperationView)13 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)12 Test (org.junit.jupiter.api.Test)9 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)6 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)6 Context (uk.gov.gchq.gaffer.store.Context)6 NamedView (uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView)4 Operation (uk.gov.gchq.gaffer.operation.Operation)4 Builder (uk.gov.gchq.gaffer.user.User.Builder)4 ArrayList (java.util.ArrayList)2 Operations (uk.gov.gchq.gaffer.operation.Operations)2 User (uk.gov.gchq.gaffer.user.User)2 Lists (com.google.common.collect.Lists)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1