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 / NetconfDeviceTest.java
index efa9d6f15c78ea4eb48e2fe5b7b9deacc0d90d99..c568b1b0136851f1ae047f7c27af6d9daed0a96a 100644 (file)
@@ -21,7 +21,6 @@ import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
-import com.google.common.base.Optional;
 import com.google.common.collect.HashMultimap;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
@@ -29,13 +28,11 @@ import com.google.common.collect.Sets;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.SettableFuture;
 import java.io.IOException;
-import java.io.InputStream;
 import java.net.InetSocketAddress;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -60,6 +57,7 @@ import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransform
 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.available.capabilities.AvailableCapability;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
@@ -76,7 +74,7 @@ import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration;
 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
-import org.opendaylight.yangtools.yang.parser.util.ASTSchemaSource;
+import org.opendaylight.yangtools.yang.parser.rfc7950.repo.ASTSchemaSource;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 import org.xml.sax.SAXException;
 
@@ -107,12 +105,12 @@ public class NetconfDeviceTest {
     public static final String TEST_MODULE = "test-module";
     public static final String TEST_REVISION = "2013-07-22";
     public static final SourceIdentifier TEST_SID =
-            RevisionSourceIdentifier.create(TEST_MODULE, Optional.of(TEST_REVISION));
+            RevisionSourceIdentifier.create(TEST_MODULE, Revision.of(TEST_REVISION));
     public static final String TEST_CAPABILITY =
             TEST_NAMESPACE + "?module=" + TEST_MODULE + "&revision=" + TEST_REVISION;
 
     public static final SourceIdentifier TEST_SID2 =
-            RevisionSourceIdentifier.create(TEST_MODULE + "2", Optional.of(TEST_REVISION));
+            RevisionSourceIdentifier.create(TEST_MODULE + "2", Revision.of(TEST_REVISION));
     public static final String TEST_CAPABILITY2 =
             TEST_NAMESPACE + "?module=" + TEST_MODULE + "2" + "&revision=" + TEST_REVISION;
 
@@ -132,9 +130,9 @@ public class NetconfDeviceTest {
                 new SchemaResolutionException("fail first", TEST_SID, new Throwable("YangTools parser fail"));
         doAnswer(invocation -> {
             if (((Collection<?>) invocation.getArguments()[0]).size() == 2) {
-                return Futures.immediateFailedCheckedFuture(schemaResolutionException);
+                return Futures.immediateFailedFuture(schemaResolutionException);
             } else {
-                return Futures.immediateCheckedFuture(schema);
+                return Futures.immediateFuture(schema);
             }
         }).when(schemaFactory).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
 
@@ -181,8 +179,7 @@ public class NetconfDeviceTest {
         final SchemaResolutionException schemaResolutionException
                 = new SchemaResolutionException("fail first",
                 Collections.<SourceIdentifier>emptyList(), HashMultimap.<SourceIdentifier, ModuleImport>create());
-        doReturn(Futures.immediateFailedCheckedFuture(
-                schemaResolutionException))
+        doReturn(Futures.immediateFailedFuture(schemaResolutionException))
                 .when(schemaFactory).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
 
         final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = new NetconfDevice
@@ -216,13 +213,13 @@ public class NetconfDeviceTest {
         // Make fallback attempt to fail due to empty resolved sources
         final MissingSchemaSourceException schemaResolutionException =
                 new MissingSchemaSourceException("fail first", TEST_SID);
-        doReturn(Futures.immediateFailedCheckedFuture(schemaResolutionException))
+        doReturn(Futures.immediateFailedFuture(schemaResolutionException))
                 .when(schemaRepository).getSchemaSource(eq(TEST_SID), eq(ASTSchemaSource.class));
         doAnswer(invocation -> {
             if (((Collection<?>) invocation.getArguments()[0]).size() == 2) {
-                return Futures.immediateFailedCheckedFuture(schemaResolutionException);
+                return Futures.immediateFailedFuture(schemaResolutionException);
             } else {
-                return Futures.immediateCheckedFuture(schema);
+                return Futures.immediateFuture(schema);
             }
         }).when(schemaFactory).createSchemaContext(anyCollectionOf(SourceIdentifier.class));
 
@@ -268,7 +265,7 @@ public class NetconfDeviceTest {
     private static SchemaRepository getSchemaRepository() {
         final SchemaRepository mock = mock(SchemaRepository.class);
         final SchemaSourceRepresentation mockRep = mock(SchemaSourceRepresentation.class);
-        doReturn(Futures.immediateCheckedFuture(mockRep))
+        doReturn(Futures.immediateFuture(mockRep))
                 .when(mock).getSchemaSource(any(SourceIdentifier.class), eq(ASTSchemaSource.class));
         return mock;
     }
@@ -279,8 +276,7 @@ public class NetconfDeviceTest {
         final NetconfDeviceCommunicator listener = getListener();
         final SchemaContextFactory schemaContextProviderFactory = mock(SchemaContextFactory.class);
         final SettableFuture<SchemaContext> schemaFuture = SettableFuture.create();
-        doReturn(Futures.makeChecked(schemaFuture, e -> new SchemaResolutionException("fail")))
-                .when(schemaContextProviderFactory).createSchemaContext(any(Collection.class));
+        doReturn(schemaFuture).when(schemaContextProviderFactory).createSchemaContext(any(Collection.class));
         final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO =
                 new NetconfDevice.SchemaResourcesDTO(getSchemaRegistry(), getSchemaRepository(),
                         schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
@@ -348,8 +344,7 @@ public class NetconfDeviceTest {
         final NetconfDeviceCommunicator listener = getListener();
         final SchemaContextFactory schemaContextProviderFactory = mock(SchemaContextFactory.class);
         final SettableFuture<SchemaContext> schemaFuture = SettableFuture.create();
-        doReturn(Futures.makeChecked(schemaFuture, e -> new SchemaResolutionException("fail")))
-                .when(schemaContextProviderFactory).createSchemaContext(any(Collection.class));
+        doReturn(schemaFuture).when(schemaContextProviderFactory).createSchemaContext(any(Collection.class));
         final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO
                 = new NetconfDevice.SchemaResourcesDTO(getSchemaRegistry(), getSchemaRepository(),
                 schemaContextProviderFactory, STATE_SCHEMAS_RESOLVER);
@@ -414,16 +409,13 @@ public class NetconfDeviceTest {
 
     private static SchemaContextFactory getSchemaFactory() throws Exception {
         final SchemaContextFactory schemaFactory = mockClass(SchemaContextFactory.class);
-        doReturn(Futures.immediateCheckedFuture(getSchema()))
+        doReturn(Futures.immediateFuture(getSchema()))
                 .when(schemaFactory).createSchemaContext(any(Collection.class));
         return schemaFactory;
     }
 
-    public static SchemaContext getSchema() throws Exception {
-        final List<InputStream> modelsToParse = Lists.newArrayList(
-                NetconfDeviceTest.class.getResourceAsStream("/schemas/test-module.yang")
-        );
-        return YangParserTestUtils.parseYangStreams(modelsToParse);
+    public static SchemaContext getSchema() {
+        return YangParserTestUtils.parseYangResource("/schemas/test-module.yang");
     }
 
     private static RemoteDeviceHandler<NetconfSessionPreferences> getFacade() throws Exception {