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=00a0c9b4cea7f9caba9bb58b5b44fbdb126caf31;hb=b8f5ebd2f817de1d613d84cf41f3516728767eba;hp=ab52fc6b3b82a2b6d8fa0471fe4833f386037bc8;hpb=1aaec97aa24f5dfe62fd3e6523e651db883ab51f;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 ab52fc6b3b..00a0c9b4ce 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; @@ -71,10 +72,10 @@ import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository; import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException; import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation; import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier; +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.parser.rfc7950.repo.ASTSchemaSource; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; import org.xml.sax.SAXException; @@ -115,7 +116,7 @@ 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 { @@ -136,7 +137,8 @@ public class NetconfDeviceTest { } }).when(schemaFactory).createSchemaContext(anyCollectionOf(SourceIdentifier.class)); - final NetconfDeviceSchemasResolver stateSchemasResolver = (deviceRpc, remoteSessionCapabilities, id) -> { + final NetconfDeviceSchemasResolver stateSchemasResolver = (deviceRpc, remoteSessionCapabilities, id, + schemaContext) -> { final Module first = Iterables.getFirst(schema.getModules(), null); final QName qName = QName.create(first.getQNameModule(), first.getName()); final NetconfStateSchemas.RemoteYangSchema source1 = new NetconfStateSchemas.RemoteYangSchema(qName); @@ -161,7 +163,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 +180,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)); @@ -214,7 +216,7 @@ public class NetconfDeviceTest { final MissingSchemaSourceException schemaResolutionException = new MissingSchemaSourceException("fail first", TEST_SID); doReturn(Futures.immediateFailedFuture(schemaResolutionException)) - .when(schemaRepository).getSchemaSource(eq(TEST_SID), eq(ASTSchemaSource.class)); + .when(schemaRepository).getSchemaSource(eq(TEST_SID), eq(YangTextSchemaSource.class)); doAnswer(invocation -> { if (((Collection) invocation.getArguments()[0]).size() == 2) { return Futures.immediateFailedFuture(schemaResolutionException); @@ -223,7 +225,8 @@ public class NetconfDeviceTest { } }).when(schemaFactory).createSchemaContext(anyCollectionOf(SourceIdentifier.class)); - final NetconfDeviceSchemasResolver stateSchemasResolver = (deviceRpc, remoteSessionCapabilities, id) -> { + final NetconfDeviceSchemasResolver stateSchemasResolver = (deviceRpc, remoteSessionCapabilities, id, + schemaContext) -> { final Module first = Iterables.getFirst(schema.getModules(), null); final QName qName = QName.create(first.getQNameModule(), first.getName()); final NetconfStateSchemas.RemoteYangSchema source1 = new NetconfStateSchemas.RemoteYangSchema(qName); @@ -248,7 +251,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)); } @@ -266,7 +269,7 @@ public class NetconfDeviceTest { final SchemaRepository mock = mock(SchemaRepository.class); final SchemaSourceRepresentation mockRep = mock(SchemaSourceRepresentation.class); doReturn(Futures.immediateFuture(mockRep)) - .when(mock).getSchemaSource(any(SourceIdentifier.class), eq(ASTSchemaSource.class)); + .when(mock).getSchemaSource(any(SourceIdentifier.class), eq(YangTextSchemaSource.class)); return mock; } @@ -326,7 +329,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 +339,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 @@ -365,7 +370,7 @@ public class NetconfDeviceTest { //complete schema setup schemaFuture.set(getSchema()); //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 +403,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() @@ -422,7 +427,8 @@ public class NetconfDeviceTest { 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 +451,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 {