PathListener implements DataTreeChangeListener<Flow> { protected void onFlowRuleCreated(InstanceIdentifier<Flow> iid, Flow dataBefore, Flow dataAfter) { if (dataBefore == null) { LOG.debug("Flow rule is created: {}.", iid); updater.newFlowRule(iid.firstKeyOf(Node.class).getId().getValue(), dataAfter); return; } else if (PathManagerHelper.isFlowRuleDiff(dataBefore, dataAfter)) { LOG.debug("Flow rule changed in WRITE mod: {}.", iid); updater.updateFlowRule(iid.firstKeyOf(Node.class).getId().getValue(), dataBefore, dataAfter); return; } LOG.debug("No change on this flow rule: {}.", iid); return; } PathListener(final PathManagerUpdater updater); @Override void onDataTreeChanged(@Nonnull Collection<DataTreeModification<Flow>> changes);  }
@Test public void testOnFlowRuleCreated() throws Exception { Collection<DataTreeModification<Flow>> changes = new ArrayList<>(); DataTreeModification<Flow> change0 = mock(DataTreeModification.class); when(change0.getRootPath()) .thenReturn(getMockRootPath(new NodeKey(new NodeId(DEFAULT_NODE_ID)), new TableKey(DEFAULT_TABLE_ID), new FlowKey(new FlowId(DEFAULT_FLOW_ID)))); DataObjectModification<Flow> rootNode = getMockRootNode(ModificationType.WRITE, null, getIpv4DropFlow(new FlowId(DEFAULT_FLOW_ID))); when(change0.getRootNode()).thenReturn(rootNode); changes.add(change0); DataTreeModification<Flow> change1 = mock(DataTreeModification.class); NodeId nodeId1 = new NodeId(new Uri(getRandomId("openflow"))); FlowId flowId1 = new FlowId(new Uri(getRandomId("flow"))); when(change1.getRootPath()).thenReturn(getMockRootPath(new NodeKey(nodeId1), new TableKey(DEFAULT_TABLE_ID), new FlowKey(flowId1))); String output1 = getRandomId("openflow"); DataObjectModification<Flow> rootNode1 = getMockRootNode(ModificationType.WRITE, getIpv4OutputFlow(flowId1, output1), getIpv4DropFlow(flowId1)); when(change1.getRootNode()).thenReturn(rootNode1); changes.add(change1); pathListener1.onDataTreeChanged(changes); updater2.addLink(output1, new LinkId(getRandomId("link"))); pathListener2.onDataTreeChanged(changes); updater2.removeLink(output1); }