@Test public void testFindSgtForEP() throws Exception { final AddressEndpointWithLocation epWithLocation = new AddressEndpointWithLocationBuilder() .setEndpointGroup(Collections.singletonList(EPG_ID)) .setTenant(TENANT_ID) .setCondition(Collections.emptyList()) .build(); final EndpointPolicyTemplateBySgt epPolicyTemplate = new EndpointPolicyTemplateBySgtBuilder() .setConditions(epWithLocation.getCondition()) .setTenant(epWithLocation.getTenant()) .setEndpointGroups(epWithLocation.getEndpointGroup()) .setSgt(SGT) .setOrigin(TemplateGenerated.class) .build(); Mockito.when(templateReader.readBy(Matchers.<EpPolicyTemplateValueKey>any())) .thenReturn(Futures.immediateFuture(Collections.singletonList(epPolicyTemplate))); final ListenableFuture<Collection<Sgt>> sgtForEP = mapper.findSgtForEP(epWithLocation); Assert.assertTrue(sgtForEP.isDone()); final Collection<Sgt> sgts = sgtForEP.get(); Assert.assertEquals(1, sgts.size()); Assert.assertEquals(SGT, Iterables.getFirst(sgts, null)); }
@Override public ListenableFuture<Collection<Sgt>> findSgtForEP(final AddressEndpointWithLocation endpointWithLocation) { final EpPolicyTemplateValueKey rawKey = new EpPolicyTemplateValueKey(endpointWithLocation); final EpPolicyTemplateValueKey key = keyFactory.sortValueKeyLists(rawKey); return Futures.transform(epPolicyTemplateReader.readBy(key), TRANSFORM_TEMPLATE_TO_SGT, MoreExecutors.directExecutor()); }
EPToSgtMapperImpl implements EPToSgtMapper { @Override public ListenableFuture<Collection<Sgt>> findSgtForEP(final AddressEndpointWithLocation endpointWithLocation) { final EpPolicyTemplateValueKey rawKey = new EpPolicyTemplateValueKey(endpointWithLocation); final EpPolicyTemplateValueKey key = keyFactory.sortValueKeyLists(rawKey); return Futures.transform(epPolicyTemplateReader.readBy(key), TRANSFORM_TEMPLATE_TO_SGT, MoreExecutors.directExecutor()); } }
EPToSgtMapperImpl implements EPToSgtMapper { @Override public ListenableFuture<Collection<Sgt>> findSgtForEP(final AddressEndpointWithLocation endpointWithLocation) { final EpPolicyTemplateValueKey rawKey = new EpPolicyTemplateValueKey(endpointWithLocation); final EpPolicyTemplateValueKey key = keyFactory.sortValueKeyLists(rawKey); return Futures.transform(epPolicyTemplateReader.readBy(key), TRANSFORM_TEMPLATE_TO_SGT, MoreExecutors.directExecutor()); } EPToSgtMapperImpl(final ReadableAsyncByKey<EpPolicyTemplateValueKey, EndpointPolicyTemplateBySgt> epPolicyTemplateReader); }
EPToSgtMapperImpl implements EPToSgtMapper { @Override public ListenableFuture<Collection<Sgt>> findSgtForEP(final AddressEndpointWithLocation endpointWithLocation) { final EpPolicyTemplateValueKey rawKey = new EpPolicyTemplateValueKey(endpointWithLocation); final EpPolicyTemplateValueKey key = keyFactory.sortValueKeyLists(rawKey); return Futures.transform(epPolicyTemplateReader.readBy(key), TRANSFORM_TEMPLATE_TO_SGT, MoreExecutors.directExecutor()); } EPToSgtMapperImpl(final ReadableAsyncByKey<EpPolicyTemplateValueKey, EndpointPolicyTemplateBySgt> epPolicyTemplateReader); @Override ListenableFuture<Collection<Sgt>> findSgtForEP(final AddressEndpointWithLocation endpointWithLocation); }
EPToSgtMapperImpl implements EPToSgtMapper { @Override public ListenableFuture<Collection<Sgt>> findSgtForEP(final AddressEndpointWithLocation endpointWithLocation) { final EpPolicyTemplateValueKey rawKey = new EpPolicyTemplateValueKey(endpointWithLocation); final EpPolicyTemplateValueKey key = keyFactory.sortValueKeyLists(rawKey); return Futures.transform(epPolicyTemplateReader.readBy(key), TRANSFORM_TEMPLATE_TO_SGT, MoreExecutors.directExecutor()); } EPToSgtMapperImpl(final ReadableAsyncByKey<EpPolicyTemplateValueKey, EndpointPolicyTemplateBySgt> epPolicyTemplateReader); @Override ListenableFuture<Collection<Sgt>> findSgtForEP(final AddressEndpointWithLocation endpointWithLocation); static final Function<Collection<EndpointPolicyTemplateBySgt>, Collection<Sgt>> TRANSFORM_TEMPLATE_TO_SGT; }