ServiceFunctionClassifierListener extends AbstractDataTreeChangeListener<ServiceFunctionClassifier> { @Override protected void add(ServiceFunctionClassifier serviceFunctionClassifier) { if (serviceFunctionClassifier != null) { LOG.debug("Adding Service Function Classifier: {}", serviceFunctionClassifier.getName()); if (serviceFunctionClassifier.getName() != null && serviceFunctionClassifier.getAcl() != null) { SfcProviderAclAPI.addClassifierToAccessListState(serviceFunctionClassifier.getAcl().getName(), serviceFunctionClassifier.getAcl().getType(), serviceFunctionClassifier.getName()); } } } ServiceFunctionClassifierListener(final DataBroker dataBroker); void init(); @Override void close();  }
@Test public void testOnServiceFunctionClassifierCreated() throws Exception { ServiceFunctionClassifier serviceFunctionClassifier = buildServiceFunctionClassifier(); when(dataTreeModification.getRootNode()).thenReturn(dataObjectModification); when(dataObjectModification.getModificationType()).thenReturn(ModificationType.WRITE); when(dataObjectModification.getDataBefore()).thenReturn(null); when(dataObjectModification.getDataAfter()).thenReturn(serviceFunctionClassifier); collection.add(dataTreeModification); serviceFunctionClassifierListener.onDataTreeChanged(collection); Thread.sleep(500); AccessListState acl = SfcProviderAclAPI.readAccessListState(serviceFunctionClassifier.getAcl().getName(), serviceFunctionClassifier.getAcl().getType()); assertNotNull(acl); assertTrue(SfcProviderAclAPI.deleteClassifierFromAccessListState(serviceFunctionClassifier.getAcl().getName(), serviceFunctionClassifier.getAcl().getType(), serviceFunctionClassifier.getName())); }
@Test public void testOnServiceFunctionClassifierRemoved() throws Exception { ServiceFunctionClassifier serviceFunctionClassifier = buildServiceFunctionClassifier(); assertNull(SfcProviderAclAPI.readAccessListState(serviceFunctionClassifier.getAcl().getName(), serviceFunctionClassifier.getAcl().getType())); assertTrue(SfcProviderAclAPI.addClassifierToAccessListState(serviceFunctionClassifier.getAcl().getName(), serviceFunctionClassifier.getAcl().getType(), serviceFunctionClassifier.getName())); List<AclServiceFunctionClassifier> sfc = SfcProviderAclAPI.readAccessListState(serviceFunctionClassifier.getAcl().getName(), serviceFunctionClassifier.getAcl().getType()).getAclServiceFunctionClassifier(); assertTrue(sfc.get(0).getName().equals(SFC_NAME)); when(dataTreeModification.getRootNode()).thenReturn(dataObjectModification); when(dataObjectModification.getModificationType()).thenReturn(ModificationType.DELETE); when(dataObjectModification.getDataBefore()).thenReturn(serviceFunctionClassifier); collection.add(dataTreeModification); serviceFunctionClassifierListener.onDataTreeChanged(collection); Thread.sleep(500); assertEquals(SfcProviderAclAPI.readAccessListState(serviceFunctionClassifier.getAcl().getName(), serviceFunctionClassifier.getAcl().getType()).getAclServiceFunctionClassifier().size(),0); }
@Test public void testOnServiceFunctionClassifierUpdated() throws Exception { ServiceFunctionClassifier originalServiceFunctionClassifier = buildServiceFunctionClassifier(); assertNull(SfcProviderAclAPI.readAccessListState(originalServiceFunctionClassifier.getAcl().getName(), originalServiceFunctionClassifier.getAcl().getType())); assertTrue(SfcProviderAclAPI.addClassifierToAccessListState(originalServiceFunctionClassifier.getAcl().getName(), originalServiceFunctionClassifier.getAcl().getType(), originalServiceFunctionClassifier.getName())); List<AclServiceFunctionClassifier> sfc = SfcProviderAclAPI.readAccessListState(originalServiceFunctionClassifier.getAcl().getName(), originalServiceFunctionClassifier.getAcl().getType()).getAclServiceFunctionClassifier(); assertTrue(sfc.get(0).getName().equals(SFC_NAME)); ServiceFunctionClassifierBuilder updatedServiceFunctionClassifierBuilder = new ServiceFunctionClassifierBuilder(originalServiceFunctionClassifier); AclBuilder aclBuilder2 = new AclBuilder(); aclBuilder2.setName(ACL_NAME2); aclBuilder2.setType(ACL_TYPE); Acl acl_dummy2 = aclBuilder2.build(); updatedServiceFunctionClassifierBuilder.setAcl(acl_dummy2); ServiceFunctionClassifier updatedServiceFunctionClassifier = updatedServiceFunctionClassifierBuilder.build(); when(dataTreeModification.getRootNode()).thenReturn(dataObjectModification); when(dataObjectModification.getModificationType()).thenReturn(ModificationType.SUBTREE_MODIFIED); when(dataObjectModification.getDataBefore()).thenReturn(originalServiceFunctionClassifier); when(dataObjectModification.getDataAfter()).thenReturn(updatedServiceFunctionClassifier); collection.add(dataTreeModification); serviceFunctionClassifierListener.onDataTreeChanged(collection); Thread.sleep(500); assertEquals(SfcProviderAclAPI.readAccessListState(originalServiceFunctionClassifier.getAcl().getName(), originalServiceFunctionClassifier.getAcl().getType()).getAclServiceFunctionClassifier().size(),0); assertEquals(SfcProviderAclAPI.readAccessListState(updatedServiceFunctionClassifier.getAcl().getName(), updatedServiceFunctionClassifier.getAcl().getType()).getAclName(),ACL_NAME2); sfc = SfcProviderAclAPI.readAccessListState(updatedServiceFunctionClassifier.getAcl().getName(), updatedServiceFunctionClassifier.getAcl().getType()).getAclServiceFunctionClassifier(); assertTrue(sfc.get(0).getName().equals(SFC_NAME)); }