SimpleIrdUtils { public static IrdInstance readInstance(ResourceId instanceId, ReadTransaction rx) throws InterruptedException, ExecutionException { InstanceIdentifier<IrdInstance> iid = getInstanceIID(instanceId); Optional<IrdInstance> instance = rx.read(LogicalDatastoreType.OPERATIONAL, iid).get(); if (instance.isPresent()) { return instance.get(); } return null; }  static InstanceIdentifier<IrdInstance> getInstanceIID(String rid); static InstanceIdentifier<IrdInstance> getInstanceIID(ResourceId rid); static InstanceIdentifier<IrdInstance> getInstanceListIID(); static InstanceIdentifier<IrdInstanceConfiguration> getInstanceConfigurationIID(ResourceId rid); static InstanceIdentifier<IrdInstanceConfiguration> getInstanceConfigurationListIID(); static InstanceIdentifier<IrdEntry> getEntryIID(ResourceId instance, ResourceId resource); static InstanceIdentifier<IrdEntry> getEntryListIID(ResourceId instance); static InstanceIdentifier<IrdConfigurationEntry> getConfigEntryIID(ResourceId instance,
                                                                                ResourceId resource); static InstanceIdentifier<IrdConfigurationEntry> getConfigEntryListIID(ResourceId instance); static IrdInstance readInstance(ResourceId instanceId, ReadTransaction rx); static void createConfigEntry(String path, ResourceId rid, Uuid cid, final WriteTransaction wx); static void createConfigEntry(String path, ResourceId irdid, ResourceId rid, Uuid cid,
                                         final WriteTransaction wx); static void deleteConfigEntry(ResourceId rid, final WriteTransaction wx); static void deleteConfigEntry(ResourceId irdid, ResourceId rid, final WriteTransaction wx); static final String DEFAULT_IRD_RESOURCE; }
@Test public void testReadInstance() throws Exception { IrdInstance expectedIrdInstance = new IrdInstanceBuilder() .setInstanceId(new ResourceId(resourceId)).build(); ReadTransaction mockRT = mock(ReadTransaction.class); InstanceIdentifier<IrdInstance> irdIID = InstanceIdentifier .builder(IrdInstance.class, new IrdInstanceKey(resourceId)).build(); Optional<IrdInstance> returnCacheValue = Optional.of(expectedIrdInstance); final CheckedFuture<Optional<IrdInstance>, org.opendaylight.controller.md.sal.common.api.data.ReadFailedException> irdInstanceFuture; irdInstanceFuture = Futures.immediateCheckedFuture(returnCacheValue); when(mockRT.read(LogicalDatastoreType.OPERATIONAL, irdIID)).thenReturn(irdInstanceFuture); IrdInstance resultIrdInstance = SimpleIrdUtils.readInstance(resourceId, mockRT); assertEquals(resultIrdInstance, expectedIrdInstance); final CheckedFuture<Optional<IrdInstance>, org.opendaylight.controller.md.sal.common.api.data.ReadFailedException> nullFuture= Futures.immediateCheckedFuture(Optional.<IrdInstance>absent()); when(mockRT.read(LogicalDatastoreType.OPERATIONAL, irdIID)).thenReturn(nullFuture); resultIrdInstance = SimpleIrdUtils.readInstance(resourceId, mockRT); assertEquals(null, resultIrdInstance); }