FibDataModelWriter { static void updateFib(AtriumFibUpdate atriumFibUpdate, DataBroker dataBroker) { WriteTransaction writeTx = dataBroker.newReadWriteTransaction(); Type fibUpdateType = null; if (atriumFibUpdate.type() == AtriumFibUpdate.Type.UPDATE) { fibUpdateType = Type.UPDATE; } else if (atriumFibUpdate.type() == AtriumFibUpdate.Type.DELETE) { fibUpdateType = Type.DELETE; } AtriumFibEntry atriumFibEntry = atriumFibUpdate.entry(); IpAddress nextHopIp = new IpAddress(new Ipv4Address(atriumFibEntry.nextHopIp().getIp4Address().toString())); MacAddress nextHopMac = new MacAddress(atriumFibEntry.nextHopMac().toString()); String ipPrefix = atriumFibEntry.prefix().getIp4Prefix().toString(); FibEntriesBuilder fibEntriesBuilder = new FibEntriesBuilder(); List<FibEntry> fibEntries = new ArrayList<>(); FibEntryBuilder fibEntryBuilder = new FibEntryBuilder(); fibEntryBuilder.setType(fibUpdateType); fibEntryBuilder.setNextHopIp(nextHopIp); fibEntryBuilder.setNextHopMac(nextHopMac); fibEntryBuilder.setPrefix(ipPrefix); fibEntries.add(fibEntryBuilder.build()); fibEntriesBuilder.setFibEntry(fibEntries); writeTx.merge(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(FibEntries.class).build(), fibEntriesBuilder.build(), true); writeTx.submit(); }    }
@Test public void testUpdateFib() { ReadWriteTransaction readWriteTx = mock(ReadWriteTransaction.class); when(dataBroker.newReadWriteTransaction()).thenReturn(readWriteTx); when(atriumFibUpdate.type()).thenReturn(AtriumFibUpdate.Type.UPDATE). thenReturn(AtriumFibUpdate.Type.DELETE); FibDataModelWriter.updateFib(atriumFibUpdate, dataBroker); FibDataModelWriter.updateFib(atriumFibUpdate, dataBroker); verify(readWriteTx, times(2)).submit(); }