ServiceFunctionSchedulerTypeListener extends AbstractDataTreeChangeListener<ServiceFunctionSchedulerType> { @Override protected void add(ServiceFunctionSchedulerType serviceFunctionSchedulerType) { if (serviceFunctionSchedulerType != null) { LOG.debug("\n########## createdServiceFunctionSchedulerType {} {}", serviceFunctionSchedulerType.getType(), serviceFunctionSchedulerType.getName()); if ( serviceFunctionSchedulerType.isEnabled() ) { ServiceFunctionSchedulerTypes serviceFunctionSchedulerTypes = SfcProviderScheduleTypeAPI .readAllServiceFunctionScheduleTypes(); if(serviceFunctionSchedulerTypes != null) { List<ServiceFunctionSchedulerType> sfScheduleTypeList = serviceFunctionSchedulerTypes.getServiceFunctionSchedulerType(); for (ServiceFunctionSchedulerType sfst : sfScheduleTypeList) { if ( sfst.isEnabled() ) { if (!sfst.getType().equals(serviceFunctionSchedulerType.getType())) { ServiceFunctionSchedulerType sfstUpdate = new ServiceFunctionSchedulerTypeBuilder() .setName(sfst.getName()) .setType(sfst.getType()) .setEnabled(false).build(); SfcProviderScheduleTypeAPI.putServiceFunctionScheduleType(sfstUpdate); break; } } } } } } } ServiceFunctionSchedulerTypeListener(final DataBroker dataBroker); void init(); @Override void close();  }
@Test public void testOnServiceFunctionSchedulerTypeCreated() throws Exception { buildServiceFunctionSchedulerTypes(); ServiceFunctionSchedulerType serviceFunctionSchedulerType = buildServiceFunctionSchedulerType(true); when(dataTreeModification.getRootNode()).thenReturn(dataObjectModification); when(dataObjectModification.getModificationType()).thenReturn(ModificationType.WRITE); when(dataObjectModification.getDataBefore()).thenReturn(null); when(dataObjectModification.getDataAfter()).thenReturn(serviceFunctionSchedulerType); collection.add(dataTreeModification); serviceFunctionSchedulerTypeListener.onDataTreeChanged(collection); Thread.sleep(500); assertEquals(countNumOfEnabledAlgorithmType(),0); }
@Test public void testOnServiceFunctionSchedulerTypeRemoved() throws Exception { buildServiceFunctionSchedulerTypes(); ServiceFunctionSchedulerType serviceFunctionSchedulerType = buildServiceFunctionSchedulerType(false); assertTrue(SfcProviderScheduleTypeAPI.putServiceFunctionScheduleType(serviceFunctionSchedulerType)); Thread.sleep(500); ServiceFunctionSchedulerType sfst = SfcProviderScheduleTypeAPI.readServiceFunctionScheduleType(serviceFunctionSchedulerType.getType()); assertNotNull(sfst); assertEquals(serviceFunctionSchedulerType, sfst); when(dataTreeModification.getRootNode()).thenReturn(dataObjectModification); when(dataObjectModification.getModificationType()).thenReturn(ModificationType.DELETE); when(dataObjectModification.getDataBefore()).thenReturn(serviceFunctionSchedulerType); collection.add(dataTreeModification); serviceFunctionSchedulerTypeListener.onDataTreeChanged(collection); Thread.sleep(500); assertEquals(countNumOfEnabledAlgorithmType(),1); }
@Test public void testOnServiceFunctionSchedulerTypeUpdated() throws Exception { buildServiceFunctionSchedulerTypes(); ServiceFunctionSchedulerType originalServiceFunctionSchedulerType = buildServiceFunctionSchedulerType(false); assertTrue(SfcProviderScheduleTypeAPI.putServiceFunctionScheduleType(originalServiceFunctionSchedulerType)); Thread.sleep(500); ServiceFunctionSchedulerType sfst = SfcProviderScheduleTypeAPI.readServiceFunctionScheduleType(originalServiceFunctionSchedulerType.getType()); assertEquals(originalServiceFunctionSchedulerType, sfst); assertFalse (sfst.isEnabled()); assertEquals(countNumOfEnabledAlgorithmType(),1); ServiceFunctionSchedulerTypeBuilder updatedServiceFunctionSchedulerTypeBuilder = new ServiceFunctionSchedulerTypeBuilder(originalServiceFunctionSchedulerType); updatedServiceFunctionSchedulerTypeBuilder.setEnabled(true); ServiceFunctionSchedulerType updatedServiceFunctionSchedulerType = updatedServiceFunctionSchedulerTypeBuilder.build(); when(dataTreeModification.getRootNode()).thenReturn(dataObjectModification); when(dataObjectModification.getModificationType()).thenReturn(ModificationType.SUBTREE_MODIFIED); when(dataObjectModification.getDataBefore()).thenReturn(originalServiceFunctionSchedulerType); when(dataObjectModification.getDataAfter()).thenReturn(updatedServiceFunctionSchedulerType); collection.add(dataTreeModification); serviceFunctionSchedulerTypeListener.onDataTreeChanged(collection); Thread.sleep(500); assertEquals(countNumOfEnabledAlgorithmType(),0); }