Search in sources :

Example 31 with GetElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.

the class GetElementsHandlerTest method shouldReturnHBaseRetrieverWithoutIncludeMatchdxVertex.

@Test
public void shouldReturnHBaseRetrieverWithoutIncludeMatchdxVertex() 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.EQUAL).build();
    given(context.getUser()).willReturn(user);
    given(store.createRetriever(getElements, user, ids, false)).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 32 with GetElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetElements 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 33 with GetElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.

the class IfTest method shouldJsonSerialiseAndDeserialiseWithSingleValue.

@Test
public void shouldJsonSerialiseAndDeserialiseWithSingleValue() {
    // Given
    final If op = new If.Builder<>().input(new EntitySeed("1")).condition(true).then(new GetElements()).otherwise(new GetAllElements()).build();
    // When
    final byte[] json = toJson(op);
    JsonAssert.assertEquals(String.format("{%n" + "  \"class\" : \"uk.gov.gchq.gaffer.operation.impl.If\",%n" + "  \"input\" :  {%n" + "    \"class\" : \"uk.gov.gchq.gaffer.operation.data.EntitySeed\",%n" + "    \"class\" : \"uk.gov.gchq.gaffer.operation.data.EntitySeed\",%n" + "    \"vertex\" : \"1\"%n" + "  }, %n" + "  \"condition\" : true,%n" + "  \"then\" : {%n" + "    \"class\" : \"uk.gov.gchq.gaffer.operation.impl.get.GetElements\"%n" + "  },%n" + "  \"otherwise\" : {%n" + "    \"class\" : \"uk.gov.gchq.gaffer.operation.impl.get.GetAllElements\"%n" + "  }%n" + "}"), StringUtil.toString(json));
    final If deserialisedObj = fromJson(json);
    // Then
    assertNotNull(deserialisedObj);
    assertEquals(new EntitySeed("1"), deserialisedObj.getInput());
}
Also used : EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.jupiter.api.Test)

Example 34 with GetElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.

the class IfTest method shouldThrowErrorForTryingToUpdateOperationsWithTooFewOps.

@Test
public void shouldThrowErrorForTryingToUpdateOperationsWithTooFewOps() {
    // Given
    final GetElements getElements = new GetElements.Builder().input(new EntitySeed("1")).build();
    final If<Object, Object> ifOp = new If.Builder<>().condition(false).build();
    final Collection<Operation> opList = Lists.newArrayList(getElements);
    // When / Then
    assertThatIllegalArgumentException().isThrownBy(() -> ifOp.updateOperations(opList)).withMessage("Unable to update operations - exactly 3 operations are required. Received 1 operations");
}
Also used : EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Operation(uk.gov.gchq.gaffer.operation.Operation) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.jupiter.api.Test)

Example 35 with GetElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.

the class IfTest method shouldThrowErrorForTryingToUpdateOperationsWithTooManyOps.

@Test
public void shouldThrowErrorForTryingToUpdateOperationsWithTooManyOps() {
    // Given
    final GetElements getElements = new GetElements.Builder().input(new EntitySeed("2")).build();
    final GetAllElements getAllElements = new GetAllElements();
    final Limit limit = new Limit(5);
    final If<Object, Object> ifOp = new If.Builder<>().build();
    final Collection<Operation> opList = Lists.newArrayList(getElements, getAllElements, limit, limit);
    // When / Then
    assertThatIllegalArgumentException().isThrownBy(() -> ifOp.updateOperations(opList)).withMessage("Unable to update operations - exactly 3 operations are required. Received 4 operations");
}
Also used : EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Operation(uk.gov.gchq.gaffer.operation.Operation) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.jupiter.api.Test)

Aggregations

GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)256 Test (org.junit.jupiter.api.Test)153 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)112 User (uk.gov.gchq.gaffer.user.User)102 Element (uk.gov.gchq.gaffer.data.element.Element)91 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)84 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)83 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)67 Context (uk.gov.gchq.gaffer.store.Context)60 Test (org.junit.Test)56 HashSet (java.util.HashSet)52 Graph (uk.gov.gchq.gaffer.graph.Graph)49 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)46 Entity (uk.gov.gchq.gaffer.data.element.Entity)42 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)38 Operation (uk.gov.gchq.gaffer.operation.Operation)35 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)35 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)34 Edge (uk.gov.gchq.gaffer.data.element.Edge)32 ArrayList (java.util.ArrayList)31