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);
}
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);
}
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());
}
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");
}
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");
}
Aggregations