SfcOfRspDataListener implements DataTreeChangeListener<RenderedServicePath>, AutoCloseable { @Override public void onDataTreeChanged(@Nonnull Collection<DataTreeModification<RenderedServicePath>> collection) { for (DataTreeModification<RenderedServicePath> modification : collection) { DataObjectModification<RenderedServicePath> rootNode = modification.getRootNode(); switch (rootNode.getModificationType()) { case WRITE: case SUBTREE_MODIFIED: if (rootNode.getDataBefore() == null && rootNode.getDataAfter() != null) { LOG.info("SfcOfRspDataListener.onDataTreeChanged create RSP {}", rootNode.getDataBefore()); sfcOfRspProcessor.processRenderedServicePath(rootNode.getDataAfter()); } else if (rootNode.getDataAfter().equals(rootNode.getDataBefore())) { LOG.info("SfcOfRspDataListener.onDataTreeChanged update RSP Before:{} After:{}", rootNode.getDataAfter(), rootNode.getDataBefore()); sfcOfRspProcessor.deleteRenderedServicePath(rootNode.getDataBefore()); sfcOfRspProcessor.processRenderedServicePath(rootNode.getDataAfter()); } break; case DELETE: if (rootNode.getDataBefore() != null) { LOG.info("SfcOfRspDataListener.onDataTreeChanged delete RSP {}", rootNode.getDataBefore()); sfcOfRspProcessor.deleteRenderedServicePath(rootNode.getDataBefore()); } break; } } } SfcOfRspDataListener(DataBroker dataBroker, SfcOfRspProcessor sfcOfRspProcessor); @Override void onDataTreeChanged(@Nonnull Collection<DataTreeModification<RenderedServicePath>> collection); @Override void close();  }
@Test public void onDataTreeChangedAdd() throws Exception { RenderedServicePath addedRsp = new RenderedServicePathBuilder().setName(new RspName("RSP1")).build(); when(dataObjectModificationRsp.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE); when(dataObjectModificationRsp.getDataAfter()).thenReturn(addedRsp); sfcOfRspDataListener.onDataTreeChanged(rspModifications); verify(sfcOfRspProcessor).processRenderedServicePath(same(addedRsp)); verifyNoMoreInteractions(sfcOfRspProcessor); }
@Test public void onDataTreeChangedRerender() throws Exception { RenderedServicePath rerenderRsp = new RenderedServicePathBuilder().setName(new RspName("RSP1")).build(); when(dataObjectModificationRsp.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE); when(dataObjectModificationRsp.getDataAfter()).thenReturn(rerenderRsp); when(dataObjectModificationRsp.getDataBefore()).thenReturn(rerenderRsp); sfcOfRspDataListener.onDataTreeChanged(rspModifications); verify(sfcOfRspProcessor).processRenderedServicePath(same(rerenderRsp)); verify(sfcOfRspProcessor).deleteRenderedServicePath(same(rerenderRsp)); verifyNoMoreInteractions(sfcOfRspProcessor); }
@Test public void onDataTreeChangedUpdateUnsupported() throws Exception { RenderedServicePath oldRsp = new RenderedServicePathBuilder().setName(new RspName("RSP1")).build(); RenderedServicePath newRsp = new RenderedServicePathBuilder().setName(new RspName("RSP2")).build(); when(dataObjectModificationRsp.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE); when(dataObjectModificationRsp.getDataAfter()).thenReturn(newRsp); when(dataObjectModificationRsp.getDataBefore()).thenReturn(oldRsp); sfcOfRspDataListener.onDataTreeChanged(rspModifications); verifyNoMoreInteractions(sfcOfRspProcessor); }
@Test public void onDataTreeChangedDelete() throws Exception { RenderedServicePath oldRsp = new RenderedServicePathBuilder().setName(new RspName("RSP1")).build(); when(dataObjectModificationRsp.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE); when(dataObjectModificationRsp.getDataBefore()).thenReturn(oldRsp); sfcOfRspDataListener.onDataTreeChanged(rspModifications); verify(sfcOfRspProcessor).deleteRenderedServicePath(same(oldRsp)); verifyNoMoreInteractions(sfcOfRspProcessor); }