@Test public void testHarvest() throws Exception { Mockito.when(response.getEntity(String.class)).thenReturn(iseReplyAllSgts, iseReplySgtDetail); Mockito.when(builder.get(Matchers.<Class<ClientResponse>>any())).thenReturn(response); Mockito.when(webResource.getRequestBuilder()).thenReturn(builder); Mockito.when(webResource.path(Matchers.anyString())).thenReturn(webResource); Mockito.when(client.resource(Matchers.<String>any())).thenReturn(webResource); stub(method(RestClientFactory.class, "createIseClient")).toReturn(client); Mockito.when(processor.processSgtInfo(Matchers.eq(TENANT_ID), Matchers.<List<SgtInfo>>any())).thenReturn( Futures.immediateCheckedFuture(null)); final ListenableFuture<Collection<SgtInfo>> harvestResult = harvester.harvestAll(iseContext); final Collection<SgtInfo> addedSgts = harvestResult.get(2, TimeUnit.SECONDS); final InOrder inOrder = Mockito.inOrder(client, webResource, builder); inOrder.verify(client).resource(ISE_REST_URL.getValue()); inOrder.verify(webResource).path("/ers/config/sgt"); inOrder.verify(webResource).getRequestBuilder(); inOrder.verify(builder).header(Matchers.anyString(),Matchers.anyString()); inOrder.verify(builder).get(ClientResponse.class); inOrder.verify(webResource).path("/ers/config/sgt/abc123"); inOrder.verify(webResource).getRequestBuilder(); inOrder.verify(builder).header(Matchers.anyString(),Matchers.anyString()); inOrder.verify(builder).get(ClientResponse.class); inOrder.verifyNoMoreInteractions(); Assert.assertEquals(1, addedSgts.size()); }
@Override public ListenableFuture<Collection<SgtInfo>> harvestAll(@Nonnull final IseContext iseContext) { LOG.debug("ise-source: harvestAll {} -> {}", iseContext.getIseSourceConfig().getTenant(), iseContext.getIseSourceConfig().getConnectionConfig().getIseRestUrl()); ListenableFuture<Collection<SgtInfo>> result; try { final IseSourceConfig iseSourceConfig = iseContext.getIseSourceConfig(); final ConnectionConfig connectionConfig = iseSourceConfig.getConnectionConfig(); final WebResource baseWebResource = createWebResource(connectionConfig); final WebResource.Builder requestBuilder = RestClientFactory.createRequestBuilder(baseWebResource, connectionConfig.getHeader(), RestClientFactory.PATH_ERS_CONFIG_SGT); final String rawSgtSummary = IseReplyUtil.deliverResponse(requestBuilder); final List<SgtInfo> sgtInfos = harvestDetails(rawSgtSummary, baseWebResource, connectionConfig, iseContext.getUuidToSgtMap()); ListenableFuture<Void> processingResult = Futures.immediateCheckedFuture(null); for (SgtInfoProcessor processor : sgtInfoProcessors) { processingResult = Futures.transformAsync(processingResult, new AsyncFunction<Void, Void>() { @Override public ListenableFuture<Void> apply(final Void input) throws Exception { LOG.debug("entering stg-info processor {}", processor.getClass().getSimpleName()); return processor.processSgtInfo(iseSourceConfig.getTenant(), sgtInfos); } }, MoreExecutors.directExecutor()); } result = Futures.transform(processingResult, new Function<Void, Collection<SgtInfo>>() { @Nullable @Override public Collection<SgtInfo> apply(@Nullable final Void input) { for (SgtInfo sgtInfo : sgtInfos) { iseContext.getUuidToSgtMap().put(sgtInfo.getUuid(), sgtInfo.getSgt().getValue()); } return sgtInfos; } }, MoreExecutors.directExecutor()); } catch (Exception e) { LOG.debug("failed to harvest ise", e); result = Futures.immediateFailedFuture(e); } return result; }
GbpIseSgtHarvesterImpl implements GbpIseSgtHarvester { @Override public ListenableFuture<Collection<SgtInfo>> harvestAll(@Nonnull final IseContext iseContext) { LOG.debug("ise-source: harvestAll {} -> {}", iseContext.getIseSourceConfig().getTenant(), iseContext.getIseSourceConfig().getConnectionConfig().getIseRestUrl()); ListenableFuture<Collection<SgtInfo>> result; try { final IseSourceConfig iseSourceConfig = iseContext.getIseSourceConfig(); final ConnectionConfig connectionConfig = iseSourceConfig.getConnectionConfig(); final WebResource baseWebResource = createWebResource(connectionConfig); final WebResource.Builder requestBuilder = RestClientFactory.createRequestBuilder(baseWebResource, connectionConfig.getHeader(), RestClientFactory.PATH_ERS_CONFIG_SGT); final String rawSgtSummary = IseReplyUtil.deliverResponse(requestBuilder); final List<SgtInfo> sgtInfos = harvestDetails(rawSgtSummary, baseWebResource, connectionConfig, iseContext.getUuidToSgtMap()); ListenableFuture<Void> processingResult = Futures.immediateCheckedFuture(null); for (SgtInfoProcessor processor : sgtInfoProcessors) { processingResult = Futures.transformAsync(processingResult, new AsyncFunction<Void, Void>() { @Override public ListenableFuture<Void> apply(final Void input) throws Exception { LOG.debug("entering stg-info processor {}", processor.getClass().getSimpleName()); return processor.processSgtInfo(iseSourceConfig.getTenant(), sgtInfos); } }, MoreExecutors.directExecutor()); } result = Futures.transform(processingResult, new Function<Void, Collection<SgtInfo>>() { @Nullable @Override public Collection<SgtInfo> apply(@Nullable final Void input) { for (SgtInfo sgtInfo : sgtInfos) { iseContext.getUuidToSgtMap().put(sgtInfo.getUuid(), sgtInfo.getSgt().getValue()); } return sgtInfos; } }, MoreExecutors.directExecutor()); } catch (Exception e) { LOG.debug("failed to harvest ise", e); result = Futures.immediateFailedFuture(e); } return result; } }
GbpIseSgtHarvesterImpl implements GbpIseSgtHarvester { @Override public ListenableFuture<Collection<SgtInfo>> harvestAll(@Nonnull final IseContext iseContext) { LOG.debug("ise-source: harvestAll {} -> {}", iseContext.getIseSourceConfig().getTenant(), iseContext.getIseSourceConfig().getConnectionConfig().getIseRestUrl()); ListenableFuture<Collection<SgtInfo>> result; try { final IseSourceConfig iseSourceConfig = iseContext.getIseSourceConfig(); final ConnectionConfig connectionConfig = iseSourceConfig.getConnectionConfig(); final WebResource baseWebResource = createWebResource(connectionConfig); final WebResource.Builder requestBuilder = RestClientFactory.createRequestBuilder(baseWebResource, connectionConfig.getHeader(), RestClientFactory.PATH_ERS_CONFIG_SGT); final String rawSgtSummary = IseReplyUtil.deliverResponse(requestBuilder); final List<SgtInfo> sgtInfos = harvestDetails(rawSgtSummary, baseWebResource, connectionConfig, iseContext.getUuidToSgtMap()); ListenableFuture<Void> processingResult = Futures.immediateCheckedFuture(null); for (SgtInfoProcessor processor : sgtInfoProcessors) { processingResult = Futures.transformAsync(processingResult, new AsyncFunction<Void, Void>() { @Override public ListenableFuture<Void> apply(final Void input) throws Exception { LOG.debug("entering stg-info processor {}", processor.getClass().getSimpleName()); return processor.processSgtInfo(iseSourceConfig.getTenant(), sgtInfos); } }, MoreExecutors.directExecutor()); } result = Futures.transform(processingResult, new Function<Void, Collection<SgtInfo>>() { @Nullable @Override public Collection<SgtInfo> apply(@Nullable final Void input) { for (SgtInfo sgtInfo : sgtInfos) { iseContext.getUuidToSgtMap().put(sgtInfo.getUuid(), sgtInfo.getSgt().getValue()); } return sgtInfos; } }, MoreExecutors.directExecutor()); } catch (Exception e) { LOG.debug("failed to harvest ise", e); result = Futures.immediateFailedFuture(e); } return result; } GbpIseSgtHarvesterImpl(final SgtInfoProcessor... sgtInfoProcessors); }
GbpIseSgtHarvesterImpl implements GbpIseSgtHarvester { @Override public ListenableFuture<Collection<SgtInfo>> harvestAll(@Nonnull final IseContext iseContext) { LOG.debug("ise-source: harvestAll {} -> {}", iseContext.getIseSourceConfig().getTenant(), iseContext.getIseSourceConfig().getConnectionConfig().getIseRestUrl()); ListenableFuture<Collection<SgtInfo>> result; try { final IseSourceConfig iseSourceConfig = iseContext.getIseSourceConfig(); final ConnectionConfig connectionConfig = iseSourceConfig.getConnectionConfig(); final WebResource baseWebResource = createWebResource(connectionConfig); final WebResource.Builder requestBuilder = RestClientFactory.createRequestBuilder(baseWebResource, connectionConfig.getHeader(), RestClientFactory.PATH_ERS_CONFIG_SGT); final String rawSgtSummary = IseReplyUtil.deliverResponse(requestBuilder); final List<SgtInfo> sgtInfos = harvestDetails(rawSgtSummary, baseWebResource, connectionConfig, iseContext.getUuidToSgtMap()); ListenableFuture<Void> processingResult = Futures.immediateCheckedFuture(null); for (SgtInfoProcessor processor : sgtInfoProcessors) { processingResult = Futures.transformAsync(processingResult, new AsyncFunction<Void, Void>() { @Override public ListenableFuture<Void> apply(final Void input) throws Exception { LOG.debug("entering stg-info processor {}", processor.getClass().getSimpleName()); return processor.processSgtInfo(iseSourceConfig.getTenant(), sgtInfos); } }, MoreExecutors.directExecutor()); } result = Futures.transform(processingResult, new Function<Void, Collection<SgtInfo>>() { @Nullable @Override public Collection<SgtInfo> apply(@Nullable final Void input) { for (SgtInfo sgtInfo : sgtInfos) { iseContext.getUuidToSgtMap().put(sgtInfo.getUuid(), sgtInfo.getSgt().getValue()); } return sgtInfos; } }, MoreExecutors.directExecutor()); } catch (Exception e) { LOG.debug("failed to harvest ise", e); result = Futures.immediateFailedFuture(e); } return result; } GbpIseSgtHarvesterImpl(final SgtInfoProcessor... sgtInfoProcessors); @Override ListenableFuture<Collection<SgtInfo>> harvestAll(@Nonnull final IseContext iseContext); }
GbpIseSgtHarvesterImpl implements GbpIseSgtHarvester { @Override public ListenableFuture<Collection<SgtInfo>> harvestAll(@Nonnull final IseContext iseContext) { LOG.debug("ise-source: harvestAll {} -> {}", iseContext.getIseSourceConfig().getTenant(), iseContext.getIseSourceConfig().getConnectionConfig().getIseRestUrl()); ListenableFuture<Collection<SgtInfo>> result; try { final IseSourceConfig iseSourceConfig = iseContext.getIseSourceConfig(); final ConnectionConfig connectionConfig = iseSourceConfig.getConnectionConfig(); final WebResource baseWebResource = createWebResource(connectionConfig); final WebResource.Builder requestBuilder = RestClientFactory.createRequestBuilder(baseWebResource, connectionConfig.getHeader(), RestClientFactory.PATH_ERS_CONFIG_SGT); final String rawSgtSummary = IseReplyUtil.deliverResponse(requestBuilder); final List<SgtInfo> sgtInfos = harvestDetails(rawSgtSummary, baseWebResource, connectionConfig, iseContext.getUuidToSgtMap()); ListenableFuture<Void> processingResult = Futures.immediateCheckedFuture(null); for (SgtInfoProcessor processor : sgtInfoProcessors) { processingResult = Futures.transformAsync(processingResult, new AsyncFunction<Void, Void>() { @Override public ListenableFuture<Void> apply(final Void input) throws Exception { LOG.debug("entering stg-info processor {}", processor.getClass().getSimpleName()); return processor.processSgtInfo(iseSourceConfig.getTenant(), sgtInfos); } }, MoreExecutors.directExecutor()); } result = Futures.transform(processingResult, new Function<Void, Collection<SgtInfo>>() { @Nullable @Override public Collection<SgtInfo> apply(@Nullable final Void input) { for (SgtInfo sgtInfo : sgtInfos) { iseContext.getUuidToSgtMap().put(sgtInfo.getUuid(), sgtInfo.getSgt().getValue()); } return sgtInfos; } }, MoreExecutors.directExecutor()); } catch (Exception e) { LOG.debug("failed to harvest ise", e); result = Futures.immediateFailedFuture(e); } return result; } GbpIseSgtHarvesterImpl(final SgtInfoProcessor... sgtInfoProcessors); @Override ListenableFuture<Collection<SgtInfo>> harvestAll(@Nonnull final IseContext iseContext);  }