@Test
public void testUpdateNodeConnectorStatus_WithStpLinks() throws Exception {

    // Setup code to trigger the TopologyDataChangeEventProcessor
    InstanceIdentifier<Link> instanceId = InstanceIdentifier.create(Link.class);
    Link nodeLink = new LinkBuilder().setLinkId(new LinkId("openflow:1")).build();
    DataTreeModification<Link> mockChange = Mockito.mock(DataTreeModification.class);
    DataObjectModification<Link> mockModification = Mockito.mock(DataObjectModification.class);
    when(mockModification.getDataAfter()).thenReturn(nodeLink);
    when(mockModification.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);
    when(mockChange.getRootPath()).thenReturn(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
            instanceId));
    when(mockChange.getRootNode()).thenReturn(mockModification);
    // getLinksFromTopology
    List<Link> links = new ArrayList<>();
    links.add(new LinkBuilder().setLinkId(new LinkId("openflow:1")).build());
    Topology topology = new TopologyBuilder().setLink(links).build();
    Optional<Topology> topologyOptional = Optional.of(topology);
    CheckedFuture checkedFuture = Mockito.mock(CheckedFuture.class);
    when(checkedFuture.get()).thenReturn(topologyOptional);
    ReadOnlyTransaction readOnlyTransaction = Mockito.mock(ReadOnlyTransaction.class);
    when(readOnlyTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class)))
            .thenReturn(checkedFuture);
    when(dataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction);
    // run
    ReadWriteTransaction readWriteTransaction = Mockito.mock(ReadWriteTransaction.class);
    when(dataBroker.newReadWriteTransaction()).thenReturn(readWriteTransaction);
    // updateNodeConnectorStatus
    Link link1 = new LinkBuilder().setLinkId(new LinkId("openflow:1"))
            .setSource(new SourceBuilder().setSourceNode(new NodeId("openflow:1"))
                    .setSourceTp(new TpId("openflow:1")).build())
            .setDestination(new DestinationBuilder().setDestNode(new NodeId("openflow:1"))
                    .setDestTp(new TpId("openflow:1")).build())
            .build();
    Link link2 = new LinkBuilder().setLinkId(new LinkId("openflow:2"))
            .setSource(new SourceBuilder().setSourceNode(new NodeId("openflow:2"))
                    .setSourceTp(new TpId("openflow:2")).build())
            .setDestination(new DestinationBuilder().setDestNode(new NodeId("openflow:2"))
                    .setDestTp(new TpId("openflow:2")).build())
            .build();
    List<Link> allLinks = new ArrayList<>();
    allLinks.add(link1);
    allLinks.add(link2);
    when(networkGraphService.getAllLinks()).thenReturn(allLinks);
    List<Link> mstLinks = new ArrayList<>();
    mstLinks.add(link1);
    when(networkGraphService.getLinksInMst()).thenReturn(mstLinks);
    // checkIfExistAndUpdateNodeConnector
    StpStatusAwareNodeConnector stpStatusAwareNodeConnector = new StpStatusAwareNodeConnectorBuilder()
            .setStatus(StpStatus.Forwarding).build();
    NodeConnector nodeConnector = new NodeConnectorBuilder()
            .addAugmentation(StpStatusAwareNodeConnector.class, stpStatusAwareNodeConnector).build();
    Optional<NodeConnector> optionalNodeConnector = Optional.of(nodeConnector);
    CheckedFuture checkedFutureNc = Mockito.mock(CheckedFuture.class);
    when(checkedFutureNc.get()).thenReturn(optionalNodeConnector);
    when(readWriteTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class)))
            .thenReturn(checkedFutureNc);
    topologyLinkDataChangeHandler.onDataTreeChanged(Collections.singletonList(mockChange));
    Thread.sleep(500);
    verify(dataBroker, times(1)).newReadWriteTransaction();
    verify(networkGraphService, times(1)).addLinks(any(ArrayList.class));
    verify(networkGraphService, times(1)).getAllLinks();
    verify(networkGraphService, times(1)).getLinksInMst();
    verify(readWriteTransaction, times(2)).merge(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
            any(StpStatusAwareNodeConnector.class));
    verify(readWriteTransaction, times(1)).submit();
}