*/
package org.opendaylight.netconf.sal.connect.netconf.schema;
-import com.google.common.base.Optional;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import com.google.common.io.ByteStreams;
-import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.ListenableFuture;
import java.net.InetSocketAddress;
+import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.ExecutionException;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Before;
@Before
public void setUp() throws Exception {
final URL url = getClass().getResource("/schemas/config-test-rpc.yang");
- workingSid = RevisionSourceIdentifier.create("abc", Optional.<String>absent());
+ workingSid = RevisionSourceIdentifier.create("abc", Optional.empty());
final Map<SourceIdentifier, URL> sourceIdentifierURLMap = Collections.singletonMap(workingSid, url);
final RemoteDeviceId id = new RemoteDeviceId("id", new InetSocketAddress("localhost", 22));
yangLibrarySchemaYangSourceProvider = new YangLibrarySchemaYangSourceProvider(id, sourceIdentifierURLMap);
@Test
public void testGetSource() throws Exception {
- CheckedFuture<? extends YangTextSchemaSource, SchemaSourceException> source =
- yangLibrarySchemaYangSourceProvider.getSource(workingSid);
- final String x = new String(ByteStreams.toByteArray(source.checkedGet().openStream()));
+ ListenableFuture<? extends YangTextSchemaSource> source = yangLibrarySchemaYangSourceProvider
+ .getSource(workingSid);
+ final String x = new String(ByteStreams.toByteArray(source.get().openStream()));
Assert.assertThat(x, CoreMatchers.containsString("module config-test-rpc"));
}
- @Test(expected = SchemaSourceException.class)
- public void testGetSourceFailure() throws Exception {
+ @Test
+ public void testGetSourceFailure() throws InterruptedException, MalformedURLException {
final URL url = new URL("http://non-existing-entity.yang");
final Map<SourceIdentifier, URL> sourceIdentifierURLMap = Collections.singletonMap(workingSid, url);
final RemoteDeviceId id = new RemoteDeviceId("id", new InetSocketAddress("localhost", 22));
final YangLibrarySchemaYangSourceProvider failingYangLibrarySchemaYangSourceProvider =
new YangLibrarySchemaYangSourceProvider(id, sourceIdentifierURLMap);
- CheckedFuture<? extends YangTextSchemaSource, SchemaSourceException> source =
- failingYangLibrarySchemaYangSourceProvider.getSource(workingSid);
- source.checkedGet();
+ try {
+ failingYangLibrarySchemaYangSourceProvider.getSource(workingSid).get();
+ fail();
+ } catch (ExecutionException e) {
+ final Throwable cause = e.getCause();
+ assertTrue(cause instanceof SchemaSourceException);
+ }
}
@Test(expected = IllegalArgumentException.class)