SimpleIrdEntryListener implements AutoCloseable, DataTreeChangeListener<IrdConfigurationEntry> { protected Future<Optional<Resource>> getValidResource(ResourceId rid, InstanceIdentifier<Resource> iid, ReadTransaction rx) { ContextKey contextKey = new ContextKey(context); ContextKey entryContextKey = new ContextKey(entryContext); ResourceKey resourceKey = new ResourceKey(rid); ContextKey iidContextKey = iid.firstKeyOf(Context.class); if (contextKey.equals(iidContextKey) || entryContextKey.equals(iidContextKey)) { if (resourceKey.equals(iid.firstKeyOf(Resource.class))) { return rx.read(LogicalDatastoreType.OPERATIONAL, iid); } } SettableFuture<Optional<Resource>> result = SettableFuture.create(); result.set(null); return result; } SimpleIrdEntryListener(InstanceIdentifier<Resource> instance, Uuid entryContext); void register(DataBroker dataBroker, InstanceIdentifier<IrdConfigurationEntry> iid); @Override synchronized void onDataTreeChanged(Collection<DataTreeModification<IrdConfigurationEntry>> changes); @Override synchronized void close();  }
@Test public void getValidResource() throws Exception { ResourceId resourceId = new ResourceId(DEFAULT_POOL_RESOURCE); ResourceBuilder resourceBuilder = new ResourceBuilder().setResourceId(resourceId); Optional<Resource> opRe = Optional.of(resourceBuilder.build()); final CheckedFuture<Optional<Resource>, ReadFailedException> opReFuture; opReFuture = Futures.immediateCheckedFuture(opRe); when(rx.read(LogicalDatastoreType.OPERATIONAL, resourceIID)).thenReturn(opReFuture); Future<Optional<Resource>> result = simpleIrdEntryListener.getValidResource(resourceId, resourceIID, rx); assertEquals(opReFuture, result); }