MdsalUtils { public <D extends org.opendaylight.yangtools.yang.binding.DataObject> D read(final LogicalDatastoreType store, final InstanceIdentifier<D> path) { D result = null; final ReadOnlyTransaction transaction = databroker.newReadOnlyTransaction(); Optional<D> optionalDataObject; CheckedFuture<Optional<D>, ReadFailedException> future = transaction.read(store, path); try { optionalDataObject = future.checkedGet(); if (optionalDataObject.isPresent()) { result = optionalDataObject.get(); } else { LOG.debug("{}: Failed to read {}", Thread.currentThread().getStackTrace()[1], path); } } catch (ReadFailedException e) { LOG.warn("Failed to read {} ", path, e); } transaction.close(); return result; } MdsalUtils(DataBroker dataBroker); boolean delete(
            final LogicalDatastoreType store, final InstanceIdentifier<D> path); boolean merge(
            final LogicalDatastoreType logicalDatastoreType, final InstanceIdentifier<D> path, D data); boolean put(
            final LogicalDatastoreType logicalDatastoreType, final InstanceIdentifier<D> path, D data); D read(final LogicalDatastoreType store,
            final InstanceIdentifier<D> path); boolean put(LogicalDatastoreType logicalDatastoreType, InstanceIdentifier<T> iid,
            T dataObject, FlowAction isAdd);  }
@Test public void testRead() throws Exception { when(checkedFuture.checkedGet()).thenReturn(optional); when(readOnlyTransaction.read(LogicalDatastoreType.CONFIGURATION, instanceIdentifier)) .thenReturn(checkedFuture); assertNull(mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, instanceIdentifier)); when(optional.isPresent()).thenReturn(true); when(optional.get()).thenReturn(mock(DataObject.class)); verify(readOnlyTransaction).read(LogicalDatastoreType.CONFIGURATION, instanceIdentifier); verify(optional).isPresent(); assertTrue(mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, instanceIdentifier) instanceof DataObject); verify(readOnlyTransaction, times(2)).read(LogicalDatastoreType.CONFIGURATION, instanceIdentifier); verify(optional, times(2)).isPresent(); verify(optional, times(1)).get(); when(optional.isPresent()).thenThrow(ReadFailedException.class); assertNull(mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, instanceIdentifier)); verify(readOnlyTransaction, times(3)).read(LogicalDatastoreType.CONFIGURATION, instanceIdentifier); verify(optional, times(3)).isPresent(); verify(optional, times(1)).get(); }