GetElementsHandler implements OutputOperationHandler<GetElements, CloseableIterable<? extends Element>> { @Override public CloseableIterable<? extends Element> doOperation(final GetElements operation, final Context context, final Store store) throws OperationException { return doOperation(operation, context.getUser(), (HBaseStore) store); }  @Override CloseableIterable<? extends Element> doOperation(final GetElements operation, final Context context, final Store store);  }
@Test public void shouldThrowExceptionIfAnOldOperationOptionIsUsed() throws OperationException, StoreException { final Iterable<EntityId> ids = mock(Iterable.class); final GetElementsHandler handler = new GetElementsHandler(); final GetElements getElements = new GetElements.Builder() .input(ids) .option("hbasestore.operation.return_matched_id_as_edge_source", "true") .build(); try { handler.doOperation(getElements, new Context(), null); fail("Exception expected"); } catch (final IllegalArgumentException e) { assertTrue(e.getMessage().contains("return_matched_id_as_edge_source")); } }
@Test public void shouldReturnHBaseRetrieverWithIncludeMatchedVertex() throws OperationException, StoreException { 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); final HBaseRetriever<GetElements> result = (HBaseRetriever<GetElements>) handler.doOperation(getElements, context, store); assertSame(hbaseRetriever, result); }
@Test public void shouldReturnHBaseRetrieverWithIncludeMatchedVertexWhenSeedMatchingIsNull() throws OperationException, StoreException { 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(null) .build(); given(context.getUser()).willReturn(user); given(store.createRetriever(getElements, user, ids, true)).willReturn(hbaseRetriever); final HBaseRetriever<GetElements> result = (HBaseRetriever<GetElements>) handler.doOperation(getElements, context, store); assertSame(hbaseRetriever, result); }
@Test public void shouldReturnHBaseRetrieverWithoutIncludeMatchdxVertex() throws OperationException, StoreException { 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); final HBaseRetriever<GetElements> result = (HBaseRetriever<GetElements>) handler.doOperation(getElements, context, store); assertSame(hbaseRetriever, result); }
@Test public void shouldDoNothingIfNoSeedsProvided() throws OperationException { final GetElementsHandler handler = new GetElementsHandler(); final GetElements getElements = new GetElements(); final Context context = mock(Context.class); final HBaseStore store = mock(HBaseStore.class); final CloseableIterable<? extends Element> result = handler.doOperation(getElements, context, store); assertEquals(0, Iterables.size(result)); }