RemoteSchemaProvider implements SchemaSourceProvider<YangTextSchemaSource> { @Override public ListenableFuture<YangTextSchemaSource> getSource(final SourceIdentifier sourceIdentifier) { LOG.trace("Getting yang schema source for {}", sourceIdentifier.getName()); Future<YangTextSchemaSourceSerializationProxy> result = remoteRepo.getYangTextSchemaSource(sourceIdentifier); final SettableFuture<YangTextSchemaSource> res = SettableFuture.create(); result.onComplete(new OnComplete<YangTextSchemaSourceSerializationProxy>() { @Override public void onComplete(final Throwable throwable, final YangTextSchemaSourceSerializationProxy yangTextSchemaSourceSerializationProxy) { if (yangTextSchemaSourceSerializationProxy != null) { res.set(yangTextSchemaSourceSerializationProxy.getRepresentation()); } if (throwable != null) { res.setException(throwable); } } }, executionContext); return res; } RemoteSchemaProvider(final RemoteYangTextSourceProvider remoteRepo,
            final ExecutionContext executionContext); @Override ListenableFuture<YangTextSchemaSource> getSource(final SourceIdentifier sourceIdentifier);  }
@Test public void getExistingYangTextSchemaSource() throws IOException, InterruptedException, ExecutionException { YangTextSchemaSource schemaSource = YangTextSchemaSource.delegateForByteSource(ID, CharSource.wrap("Test").asByteSource(StandardCharsets.UTF_8)); doReturn(Futures.successful(new YangTextSchemaSourceSerializationProxy(schemaSource))) .when(mockedRemoteSchemaRepository).getYangTextSchemaSource(ID); YangTextSchemaSource providedSource = remoteSchemaProvider.getSource(ID).get(); assertEquals(ID, providedSource.getIdentifier()); assertArrayEquals(schemaSource.read(), providedSource.read()); }
@Test public void getNonExistingSchemaSource() throws InterruptedException { doReturn(Futures.failed(new SchemaSourceException("Source not provided"))) .when(mockedRemoteSchemaRepository).getYangTextSchemaSource(ID); ListenableFuture<YangTextSchemaSource> sourceFuture = remoteSchemaProvider.getSource(ID); assertTrue(sourceFuture.isDone()); try { sourceFuture.get(); fail("Expected a failure to occur"); } catch (ExecutionException e) { assertThat(e.getCause(), instanceOf(SchemaSourceException.class)); } }