Adjust to yangtools-2.0.0/odlparent-3.0.0 changes
[netconf.git] / netconf / sal-netconf-connector / src / test / java / org / opendaylight / netconf / sal / connect / netconf / schema / YangLibrarySchemaYangSourceProviderTest.java
index 623e61a3376121f8a13be5935a89d5844c7d7cb2..bc94ff2f9ec55f539fdaafb77d26284d8a196ce5 100644 (file)
@@ -7,13 +7,18 @@
  */
 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;
@@ -32,7 +37,7 @@ public class YangLibrarySchemaYangSourceProviderTest {
     @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);
@@ -40,23 +45,27 @@ public class YangLibrarySchemaYangSourceProviderTest {
 
     @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)