* 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;
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;
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;
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;
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 {
final NetconfDeviceCommunicator listener = getListener();
final SchemaContextFactory schemaFactory = getSchemaFactory();
- final SchemaContext schema = getSchema();
final SchemaRepository schemaRepository = getSchemaRepository();
final SchemaResolutionException schemaResolutionException =
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 =
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));
}
public void testNetconfDeviceMissingSource() throws Exception {
final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
final NetconfDeviceCommunicator listener = getListener();
- final SchemaContext schema = getSchema();
final SchemaContextFactory schemaFactory = getSchemaFactory();
final SchemaRepository schemaRepository = getSchemaRepository();
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 =
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));
}
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();
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
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
final ArgumentCaptor<NetconfSessionPreferences> 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()
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<NetconfSessionPreferences> getFacade() throws Exception {
final RemoteDeviceHandler<NetconfSessionPreferences> 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;
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<NetconfMessage> getMessageTransformer() throws Exception {