SfcGeniusSfStateListener extends AsyncDataTreeChangeListenerBase<ServiceFunctionState,
        SfcGeniusSfStateListener> { @Override protected void update(InstanceIdentifier<ServiceFunctionState> instanceIdentifier, ServiceFunctionState oldSf, ServiceFunctionState newSf) { LOG.debug("Received service function state update event {} {} {}", instanceIdentifier, oldSf, newSf); int numberOfNewPaths = newSf.getSfServicePath() == null ? 0 : newSf.getSfServicePath().size(); int numberOfOldPaths = oldSf.getSfServicePath() == null ? 0 : oldSf.getSfServicePath().size(); String sfName = newSf.getName().getValue(); if (numberOfNewPaths > numberOfOldPaths) { executor.execute(() -> interfaceManager.bindInterfacesOfServiceFunction(sfName)); } else if (numberOfNewPaths < numberOfOldPaths && numberOfNewPaths <= 0) { executor.execute(() -> interfaceManager.unbindInterfacesOfServiceFunction(sfName)); } } SfcGeniusSfStateListener(ISfcGeniusInterfaceServiceHandler interfaceManager, Executor executor);   }
@Test public void updateMorePaths() throws Exception { when(serviceFunctionState.getName()).thenReturn(new SfName("SF1")); when(serviceFunctionState.getSfServicePath()).thenReturn(sfpList); when(sfpList.size()).thenReturn(1).thenReturn(0); sfcGeniusSfStateListener.update(null, serviceFunctionState, serviceFunctionState); verify(executor).execute(runnableCaptor.capture()); runnableCaptor.getValue().run(); verify(iSfcGeniusInterfaceServiceHandler).bindInterfacesOfServiceFunction("SF1"); }
@Test public void updateLessPaths() throws Exception { when(serviceFunctionState.getName()).thenReturn(new SfName("SF1")); when(serviceFunctionState.getSfServicePath()).thenReturn(sfpList); when(sfpList.size()).thenReturn(1).thenReturn(2); sfcGeniusSfStateListener.update(null, serviceFunctionState, serviceFunctionState); verifyZeroInteractions(executor); verifyZeroInteractions(iSfcGeniusInterfaceServiceHandler); }
@Test public void updateZeroPaths() throws Exception { when(serviceFunctionState.getName()).thenReturn(new SfName("SF1")); when(serviceFunctionState.getSfServicePath()).thenReturn(sfpList); when(sfpList.size()).thenReturn(0).thenReturn(1); sfcGeniusSfStateListener.update(null, serviceFunctionState, serviceFunctionState); verify(executor).execute(runnableCaptor.capture()); runnableCaptor.getValue().run(); verify(iSfcGeniusInterfaceServiceHandler).unbindInterfacesOfServiceFunction("SF1"); }
@Test public void updateEqualPaths() throws Exception { when(serviceFunctionState.getName()).thenReturn(new SfName("SF1")); when(serviceFunctionState.getSfServicePath()).thenReturn(sfpList); when(sfpList.size()).thenReturn(0).thenReturn(0); sfcGeniusSfStateListener.update(null, serviceFunctionState, serviceFunctionState); verifyZeroInteractions(executor); verifyZeroInteractions(iSfcGeniusInterfaceServiceHandler); }