AltoAutoMapsUpdateListener implements DataTreeChangeListener<Topology>, AutoCloseable { @Override public void onDataTreeChanged(Collection<DataTreeModification<Topology>> changes) { WriteTransaction writeTx = null; for (DataTreeModification<Topology> change : changes) { final DataObjectModification<Topology> rootNode = change.getRootNode(); switch (rootNode.getModificationType()) { case WRITE: writeTx = handleDataWrite(rootNode, writeTx); break; case DELETE: writeTx = handleDataDelete(writeTx); LOG.info("Empty default auto networkmap"); break; default: break; } } if (writeTx != null) { writeTx.submit(); } } AltoAutoMapsUpdateListener(final DataBroker dataBroker); @Override void onDataTreeChanged(Collection<DataTreeModification<Topology>> changes); @Override void close();  }
@SuppressWarnings("unchecked") @Test public void testOnDataChanged() throws Exception { DataTreeModification<Topology> mockDataTreeModification = mock(DataTreeModification.class); DataObjectModification<Topology> mockModification = mock(DataObjectModification.class); doReturn(mockModification).when(mockDataTreeModification).getRootNode(); Topology testTopology = new TopologyBuilder().setNode(Arrays.asList(new NodeBuilder().build())).build(); doReturn(testTopology).when(mockModification).getDataAfter(); doReturn(DataObjectModification.ModificationType.WRITE).when(mockModification).getModificationType(); altoAutoMapsUpdateListener.onDataTreeChanged(Collections.singletonList(mockDataTreeModification)); verify(rwx).submit(); reset(rwx); doReturn(testTopology).when(mockModification).getDataBefore(); Topology testTopologyWithHost = new TopologyBuilder() .setNode(Arrays.asList(new NodeBuilder() .addAugmentation(HostNode.class, new HostNodeBuilder() .setAddresses(Arrays.asList(new AddressesBuilder() .setIp(new IpAddress(new Ipv4Address("192.168.1.100"))) .build(), new AddressesBuilder().build())) .build()) .build())) .build(); doReturn(testTopologyWithHost).when(mockModification).getDataAfter(); doReturn(DataObjectModification.ModificationType.WRITE).when(mockModification).getModificationType(); altoAutoMapsUpdateListener.onDataTreeChanged(Collections.singletonList(mockDataTreeModification)); verify(rwx).submit(); reset(rwx); doReturn(testTopologyWithHost).when(mockModification).getDataBefore(); doReturn(null).when(mockModification).getDataAfter(); doReturn(DataObjectModification.ModificationType.DELETE).when(mockModification).getModificationType(); altoAutoMapsUpdateListener.onDataTreeChanged(Collections.singletonList(mockDataTreeModification)); verify(rwx).submit(); reset(rwx, dataBroker); doReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED) .when(mockModification).getModificationType(); altoAutoMapsUpdateListener.onDataTreeChanged(Collections.singletonList(mockDataTreeModification)); verifyNoMoreInteractions(dataBroker); }