X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fsal-netconf-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fsal%2Fconnect%2Fnetconf%2FNetconfDeviceTest.java;h=59f3ec6023f331577861c1ff65832e1e4508bd85;hb=bb56949ce4ba4d10089f4b58aa42c29181871d8e;hp=3cc5c74a9fb44746efddbee52e6461bb0b801283;hpb=6ab1941217e38336ae5970a29505f9bb21d4ef21;p=netconf.git diff --git a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDeviceTest.java b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDeviceTest.java index 3cc5c74a9f..59f3ec6023 100644 --- a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDeviceTest.java +++ b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDeviceTest.java @@ -5,13 +5,13 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.netconf.sal.connect.netconf; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyCollectionOf; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyCollectionOf; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.after; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doNothing; @@ -26,6 +26,8 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListeningExecutorService; +import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.SettableFuture; import java.io.IOException; import java.net.InetSocketAddress; @@ -34,15 +36,15 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; -import org.opendaylight.controller.md.sal.dom.api.DOMNotification; -import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult; -import org.opendaylight.controller.md.sal.dom.api.DOMRpcService; -import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult; +import org.opendaylight.mdsal.dom.api.DOMActionService; +import org.opendaylight.mdsal.dom.api.DOMNotification; +import org.opendaylight.mdsal.dom.api.DOMRpcResult; +import org.opendaylight.mdsal.dom.api.DOMRpcService; +import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult; import org.opendaylight.netconf.api.NetconfMessage; import org.opendaylight.netconf.api.xml.XmlNetconfConstants; import org.opendaylight.netconf.api.xml.XmlUtil; @@ -61,7 +63,6 @@ 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; -import org.opendaylight.yangtools.yang.model.api.ModuleImport; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException; @@ -75,11 +76,10 @@ import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource; 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.test.util.YangParserTestUtils; import org.xml.sax.SAXException; @SuppressWarnings("checkstyle:IllegalCatch") -public class NetconfDeviceTest { +public class NetconfDeviceTest extends AbstractTestModelTest { private static final NetconfMessage NOTIFICATION; @@ -115,7 +115,8 @@ public class NetconfDeviceTest { TEST_NAMESPACE + "?module=" + TEST_MODULE + "2" + "&revision=" + TEST_REVISION; private static final NetconfDeviceSchemasResolver STATE_SCHEMAS_RESOLVER = - (deviceRpc, remoteSessionCapabilities, id) -> NetconfStateSchemas.EMPTY; + (deviceRpc, remoteSessionCapabilities, id, schemaContext) -> NetconfStateSchemas.EMPTY; + @Test public void testNetconfDeviceFlawedModelFailedResolution() throws Exception { @@ -123,7 +124,6 @@ public class NetconfDeviceTest { final NetconfDeviceCommunicator listener = getListener(); final SchemaContextFactory schemaFactory = getSchemaFactory(); - final SchemaContext schema = getSchema(); final SchemaRepository schemaRepository = getSchemaRepository(); final SchemaResolutionException schemaResolutionException = @@ -132,12 +132,13 @@ public class NetconfDeviceTest { if (((Collection) invocation.getArguments()[0]).size() == 2) { return Futures.immediateFailedFuture(schemaResolutionException); } else { - return Futures.immediateFuture(schema); + return Futures.immediateFuture(SCHEMA_CONTEXT); } }).when(schemaFactory).createSchemaContext(anyCollectionOf(SourceIdentifier.class)); - final NetconfDeviceSchemasResolver stateSchemasResolver = (deviceRpc, remoteSessionCapabilities, id) -> { - final Module first = Iterables.getFirst(schema.getModules(), null); + final NetconfDeviceSchemasResolver stateSchemasResolver = (deviceRpc, remoteSessionCapabilities, id, + schemaContext) -> { + final Module first = Iterables.getFirst(SCHEMA_CONTEXT.getModules(), null); final QName qName = QName.create(first.getQNameModule(), first.getName()); final NetconfStateSchemas.RemoteYangSchema source1 = new NetconfStateSchemas.RemoteYangSchema(qName); final NetconfStateSchemas.RemoteYangSchema source2 = @@ -161,7 +162,7 @@ public class NetconfDeviceTest { device.onRemoteSessionUp(sessionCaps, listener); Mockito.verify(facade, Mockito.timeout(5000)).onDeviceConnected( - any(SchemaContext.class), any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class)); + any(SchemaContext.class), any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class), isNull()); Mockito.verify(schemaFactory, times(2)).createSchemaContext(anyCollectionOf(SourceIdentifier.class)); } @@ -178,7 +179,7 @@ public class NetconfDeviceTest { // Make fallback attempt to fail due to empty resolved sources final SchemaResolutionException schemaResolutionException = new SchemaResolutionException("fail first", - Collections.emptyList(), HashMultimap.create()); + Collections.emptyList(), HashMultimap.create()); doReturn(Futures.immediateFailedFuture(schemaResolutionException)) .when(schemaFactory).createSchemaContext(anyCollectionOf(SourceIdentifier.class)); @@ -205,7 +206,6 @@ public class NetconfDeviceTest { public void testNetconfDeviceMissingSource() throws Exception { final RemoteDeviceHandler facade = getFacade(); final NetconfDeviceCommunicator listener = getListener(); - final SchemaContext schema = getSchema(); final SchemaContextFactory schemaFactory = getSchemaFactory(); final SchemaRepository schemaRepository = getSchemaRepository(); @@ -219,12 +219,13 @@ public class NetconfDeviceTest { if (((Collection) invocation.getArguments()[0]).size() == 2) { return Futures.immediateFailedFuture(schemaResolutionException); } else { - return Futures.immediateFuture(schema); + return Futures.immediateFuture(SCHEMA_CONTEXT); } }).when(schemaFactory).createSchemaContext(anyCollectionOf(SourceIdentifier.class)); - final NetconfDeviceSchemasResolver stateSchemasResolver = (deviceRpc, remoteSessionCapabilities, id) -> { - final Module first = Iterables.getFirst(schema.getModules(), null); + final NetconfDeviceSchemasResolver stateSchemasResolver = (deviceRpc, remoteSessionCapabilities, id, + schemaContext) -> { + final Module first = Iterables.getFirst(SCHEMA_CONTEXT.getModules(), null); final QName qName = QName.create(first.getQNameModule(), first.getName()); final NetconfStateSchemas.RemoteYangSchema source1 = new NetconfStateSchemas.RemoteYangSchema(qName); final NetconfStateSchemas.RemoteYangSchema source2 = @@ -248,7 +249,7 @@ public class NetconfDeviceTest { device.onRemoteSessionUp(sessionCaps, listener); Mockito.verify(facade, Mockito.timeout(5000)).onDeviceConnected( - any(SchemaContext.class), any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class)); + any(SchemaContext.class), any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class), isNull()); Mockito.verify(schemaFactory, times(1)).createSchemaContext(anyCollectionOf(SourceIdentifier.class)); } @@ -326,7 +327,8 @@ public class NetconfDeviceTest { verify(schemaContextProviderFactory, timeout(5000)).createSchemaContext(any(Collection.class)); verify(facade, timeout(5000)).onDeviceConnected( - any(SchemaContext.class), any(NetconfSessionPreferences.class), any(DOMRpcService.class)); + any(SchemaContext.class), any(NetconfSessionPreferences.class), any(DOMRpcService.class), + isNull()); device.onRemoteSessionDown(); verify(facade, timeout(5000)).onDeviceDisconnected(); @@ -335,7 +337,8 @@ public class NetconfDeviceTest { verify(schemaContextProviderFactory, timeout(5000).times(2)).createSchemaContext(any(Collection.class)); verify(facade, timeout(5000).times(2)).onDeviceConnected( - any(SchemaContext.class), any(NetconfSessionPreferences.class), any(DOMRpcService.class)); + any(SchemaContext.class), any(NetconfSessionPreferences.class), any(DOMRpcService.class), + isNull()); } @Test @@ -363,9 +366,9 @@ public class NetconfDeviceTest { device.onRemoteSessionDown(); verify(facade, timeout(5000)).onDeviceDisconnected(); //complete schema setup - schemaFuture.set(getSchema()); + schemaFuture.set(SCHEMA_CONTEXT); //facade.onDeviceDisconnected() was called, so facade.onDeviceConnected() shouldn't be called anymore - verify(facade, after(1000).never()).onDeviceConnected(any(), any(), any()); + verify(facade, after(1000).never()).onDeviceConnected(any(), any(), any(), any(DOMActionService.class)); } @Test @@ -398,7 +401,7 @@ public class NetconfDeviceTest { final ArgumentCaptor argument = ArgumentCaptor.forClass(NetconfSessionPreferences.class); verify(facade, timeout(5000)) - .onDeviceConnected(any(SchemaContext.class), argument.capture(), any(DOMRpcService.class)); + .onDeviceConnected(any(SchemaContext.class), argument.capture(), any(DOMRpcService.class), isNull()); final NetconfDeviceCapabilities netconfDeviceCaps = argument.getValue().getNetconfDeviceCapabilities(); netconfDeviceCaps.getResolvedCapabilities() @@ -409,20 +412,17 @@ public class NetconfDeviceTest { private static SchemaContextFactory getSchemaFactory() throws Exception { final SchemaContextFactory schemaFactory = mockClass(SchemaContextFactory.class); - doReturn(Futures.immediateFuture(getSchema())) + doReturn(Futures.immediateFuture(SCHEMA_CONTEXT)) .when(schemaFactory).createSchemaContext(any(Collection.class)); return schemaFactory; } - public static SchemaContext getSchema() { - return YangParserTestUtils.parseYangResource("/schemas/test-module.yang"); - } - private static RemoteDeviceHandler getFacade() throws Exception { final RemoteDeviceHandler remoteDeviceHandler = mockCloseableClass(RemoteDeviceHandler.class); doNothing().when(remoteDeviceHandler).onDeviceConnected( - any(SchemaContext.class), any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class)); + any(SchemaContext.class), any(NetconfSessionPreferences.class), any(NetconfDeviceRpc.class), + any(DOMActionService.class)); doNothing().when(remoteDeviceHandler).onDeviceDisconnected(); doNothing().when(remoteDeviceHandler).onNotification(any(DOMNotification.class)); return remoteDeviceHandler; @@ -445,8 +445,8 @@ public class NetconfDeviceTest { return new RemoteDeviceId("test-D", InetSocketAddress.createUnresolved("localhost", 22)); } - public ExecutorService getExecutor() { - return Executors.newSingleThreadExecutor(); + public ListeningExecutorService getExecutor() { + return MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()); } public MessageTransformer getMessageTransformer() throws Exception {