@Test public void testOnDataTreeChanged() throws Exception { Mockito.when(dataTreeModification.getRootNode()).thenReturn(dataObjectModification); Mockito.when(dataTreeModification.getRootPath()).thenReturn(TEMPLATE_TREE_PATH); Mockito.when(dataObjectModification.getDataAfter()).thenReturn(EP_PL_TEMPLATE_VALUE); final MasterDatabaseBinding masterDBBinding1 = new MasterDatabaseBindingBuilder() .setSecurityGroupTag(SGT_1) .setIpPrefix(IP_PREFIX_1) .build(); final MasterDatabaseBinding masterDBBinding2 = new MasterDatabaseBindingBuilder() .setSecurityGroupTag(SGT_1) .setIpPrefix(IP_PREFIX_2) .build(); final EndpointForwardingTemplateBySubnet epForwardingTemplate1 = new EndpointForwardingTemplateBySubnetBuilder() .setIpPrefix(IP_PREFIX_1) .build(); final EndpointForwardingTemplateBySubnet epForwardingTemplate2 = new EndpointForwardingTemplateBySubnetBuilder() .setIpPrefix(IP_PREFIX_2) .build(); Mockito.when(masterDBDao.readBy(Matchers.<Sgt>any())).thenReturn( Futures.immediateFuture(Lists.newArrayList(masterDBBinding1, masterDBBinding2))); Mockito.when(epForwardingTemplateDao.read(Matchers.<IpPrefix>any())).thenReturn( Futures.immediateFuture(Optional.of(epForwardingTemplate1)), Futures.immediateFuture(Optional.of(epForwardingTemplate2))); Mockito.when(sxpMapper.processTemplatesAndSxpMasterDB(Matchers.<EndpointPolicyTemplateBySgt>any(), Matchers.<EndpointForwardingTemplateBySubnet>any(), Matchers.<MasterDatabaseBinding>any())).thenReturn( RpcResultBuilder.success((Void) null).buildFuture()); listener.onDataTreeChanged(Collections.singleton(dataTreeModification)); final InOrder inOrder = Mockito.inOrder(masterDBDao, simpleCachedDao, epForwardingTemplateDao, sxpMapper); inOrder.verify(simpleCachedDao).update(SGT_1, EP_PL_TEMPLATE_VALUE); inOrder.verify(masterDBDao).readBy(SGT_1); inOrder.verify(epForwardingTemplateDao).read(IP_PREFIX_1); inOrder.verify(epForwardingTemplateDao).read(IP_PREFIX_2); inOrder.verify(sxpMapper).processTemplatesAndSxpMasterDB(EP_PL_TEMPLATE_VALUE, epForwardingTemplate1, masterDBBinding1); inOrder.verify(sxpMapper).processTemplatesAndSxpMasterDB(EP_PL_TEMPLATE_VALUE, epForwardingTemplate2, masterDBBinding2); inOrder.verifyNoMoreInteractions(); }
@Override public void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<EndpointPolicyTemplateBySgt>> collection) { for (DataTreeModification<EndpointPolicyTemplateBySgt> change : collection) { LOG.trace("received modification: {} -> {}", change.getRootPath(), change.getRootNode().getModificationType()); final InstanceIdentifier<EndpointPolicyTemplateBySgt> changePath = change.getRootPath().getRootIdentifier(); final Sgt changeKey = changePath.firstKeyOf(EndpointPolicyTemplateBySgt.class).getSgt(); SxpListenerUtil.updateCachedDao(templateCachedDao, changeKey, change); final EndpointPolicyTemplateBySgt epPolicyTemplate = change.getRootNode().getDataAfter(); if (epPolicyTemplate != null && ! TemplateGenerated.class.equals(epPolicyTemplate.getOrigin())) { processWithEPTemplates(epPolicyTemplate); } else { LOG.trace("skipping ep-policy-template processing: {}", epPolicyTemplate); } } }
EPPolicyTemplateListenerImpl implements EPTemplateListener<EndpointPolicyTemplateBySgt> { @Override public void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<EndpointPolicyTemplateBySgt>> collection) { for (DataTreeModification<EndpointPolicyTemplateBySgt> change : collection) { LOG.trace("received modification: {} -> {}", change.getRootPath(), change.getRootNode().getModificationType()); final InstanceIdentifier<EndpointPolicyTemplateBySgt> changePath = change.getRootPath().getRootIdentifier(); final Sgt changeKey = changePath.firstKeyOf(EndpointPolicyTemplateBySgt.class).getSgt(); SxpListenerUtil.updateCachedDao(templateCachedDao, changeKey, change); final EndpointPolicyTemplateBySgt epPolicyTemplate = change.getRootNode().getDataAfter(); if (epPolicyTemplate != null && ! TemplateGenerated.class.equals(epPolicyTemplate.getOrigin())) { processWithEPTemplates(epPolicyTemplate); } else { LOG.trace("skipping ep-policy-template processing: {}", epPolicyTemplate); } } } }
EPPolicyTemplateListenerImpl implements EPTemplateListener<EndpointPolicyTemplateBySgt> { @Override public void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<EndpointPolicyTemplateBySgt>> collection) { for (DataTreeModification<EndpointPolicyTemplateBySgt> change : collection) { LOG.trace("received modification: {} -> {}", change.getRootPath(), change.getRootNode().getModificationType()); final InstanceIdentifier<EndpointPolicyTemplateBySgt> changePath = change.getRootPath().getRootIdentifier(); final Sgt changeKey = changePath.firstKeyOf(EndpointPolicyTemplateBySgt.class).getSgt(); SxpListenerUtil.updateCachedDao(templateCachedDao, changeKey, change); final EndpointPolicyTemplateBySgt epPolicyTemplate = change.getRootNode().getDataAfter(); if (epPolicyTemplate != null && ! TemplateGenerated.class.equals(epPolicyTemplate.getOrigin())) { processWithEPTemplates(epPolicyTemplate); } else { LOG.trace("skipping ep-policy-template processing: {}", epPolicyTemplate); } } } EPPolicyTemplateListenerImpl(final DataBroker dataBroker,
                                        final SxpMapperReactor sxpMapperReactor,
                                        final SimpleCachedDao<Sgt, EndpointPolicyTemplateBySgt> templateCachedDao,
                                        final ReadableAsyncByKey<Sgt, MasterDatabaseBinding> masterDBBindingDao,
                                        final DSAsyncDao<IpPrefix, EndpointForwardingTemplateBySubnet> epForwardingTemplateDao); }
EPPolicyTemplateListenerImpl implements EPTemplateListener<EndpointPolicyTemplateBySgt> { @Override public void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<EndpointPolicyTemplateBySgt>> collection) { for (DataTreeModification<EndpointPolicyTemplateBySgt> change : collection) { LOG.trace("received modification: {} -> {}", change.getRootPath(), change.getRootNode().getModificationType()); final InstanceIdentifier<EndpointPolicyTemplateBySgt> changePath = change.getRootPath().getRootIdentifier(); final Sgt changeKey = changePath.firstKeyOf(EndpointPolicyTemplateBySgt.class).getSgt(); SxpListenerUtil.updateCachedDao(templateCachedDao, changeKey, change); final EndpointPolicyTemplateBySgt epPolicyTemplate = change.getRootNode().getDataAfter(); if (epPolicyTemplate != null && ! TemplateGenerated.class.equals(epPolicyTemplate.getOrigin())) { processWithEPTemplates(epPolicyTemplate); } else { LOG.trace("skipping ep-policy-template processing: {}", epPolicyTemplate); } } } EPPolicyTemplateListenerImpl(final DataBroker dataBroker,
                                        final SxpMapperReactor sxpMapperReactor,
                                        final SimpleCachedDao<Sgt, EndpointPolicyTemplateBySgt> templateCachedDao,
                                        final ReadableAsyncByKey<Sgt, MasterDatabaseBinding> masterDBBindingDao,
                                        final DSAsyncDao<IpPrefix, EndpointForwardingTemplateBySubnet> epForwardingTemplateDao); @Override void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<EndpointPolicyTemplateBySgt>> collection); @Override void close(); }
EPPolicyTemplateListenerImpl implements EPTemplateListener<EndpointPolicyTemplateBySgt> { @Override public void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<EndpointPolicyTemplateBySgt>> collection) { for (DataTreeModification<EndpointPolicyTemplateBySgt> change : collection) { LOG.trace("received modification: {} -> {}", change.getRootPath(), change.getRootNode().getModificationType()); final InstanceIdentifier<EndpointPolicyTemplateBySgt> changePath = change.getRootPath().getRootIdentifier(); final Sgt changeKey = changePath.firstKeyOf(EndpointPolicyTemplateBySgt.class).getSgt(); SxpListenerUtil.updateCachedDao(templateCachedDao, changeKey, change); final EndpointPolicyTemplateBySgt epPolicyTemplate = change.getRootNode().getDataAfter(); if (epPolicyTemplate != null && ! TemplateGenerated.class.equals(epPolicyTemplate.getOrigin())) { processWithEPTemplates(epPolicyTemplate); } else { LOG.trace("skipping ep-policy-template processing: {}", epPolicyTemplate); } } } EPPolicyTemplateListenerImpl(final DataBroker dataBroker,
                                        final SxpMapperReactor sxpMapperReactor,
                                        final SimpleCachedDao<Sgt, EndpointPolicyTemplateBySgt> templateCachedDao,
                                        final ReadableAsyncByKey<Sgt, MasterDatabaseBinding> masterDBBindingDao,
                                        final DSAsyncDao<IpPrefix, EndpointForwardingTemplateBySubnet> epForwardingTemplateDao); @Override void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<EndpointPolicyTemplateBySgt>> collection); @Override void close();  }