--- /dev/null
+/*
+ * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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 org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
+
+public abstract class AbstractTestModelTest {
+ protected static SchemaContext SCHEMA_CONTEXT;
+
+ @BeforeClass
+ public static void beforeClass() {
+ SCHEMA_CONTEXT = YangParserTestUtils.parseYangResource("/schemas/test-module.yang");
+ }
+
+ @AfterClass
+ public static void afterClass() {
+ SCHEMA_CONTEXT = null;
+ }
+}
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;
private static final NetconfDeviceSchemasResolver STATE_SCHEMAS_RESOLVER =
(deviceRpc, remoteSessionCapabilities, id, schemaContext) -> NetconfStateSchemas.EMPTY;
+
@Test
public void testNetconfDeviceFlawedModelFailedResolution() throws Exception {
final RemoteDeviceHandler<NetconfSessionPreferences> facade = getFacade();
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,
schemaContext) -> {
- final Module first = Iterables.getFirst(schema.getModules(), null);
+ 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 =
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,
schemaContext) -> {
- final Module first = Iterables.getFirst(schema.getModules(), null);
+ 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.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(), any(DOMActionService.class));
}
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);
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMRpcService;
import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
+import org.opendaylight.netconf.sal.connect.netconf.AbstractTestModelTest;
import org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps;
import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public class WriteCandidateRunningTxTest {
+public class WriteCandidateRunningTxTest extends AbstractTestModelTest {
@Mock
private DOMRpcService rpc;
private NetconfBaseOps netconfOps;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- final SchemaContext schemaContext =
- YangParserTestUtils.parseYangResource("/schemas/test-module.yang");
doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult())).when(rpc).invokeRpc(any(), any());
- netconfOps = new NetconfBaseOps(rpc, schemaContext);
+ netconfOps = new NetconfBaseOps(rpc, SCHEMA_CONTEXT);
id = new RemoteDeviceId("device1", InetSocketAddress.createUnresolved("0.0.0.0", 17830));
}
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMRpcService;
import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
+import org.opendaylight.netconf.sal.connect.netconf.AbstractTestModelTest;
import org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps;
import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
import org.opendaylight.yangtools.util.concurrent.FluentFutures;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-
-public class WriteCandidateTxTest {
+public class WriteCandidateTxTest extends AbstractTestModelTest {
@Mock
private DOMRpcService rpc;
private NetconfBaseOps netconfOps;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- final SchemaContext schemaContext =
- YangParserTestUtils.parseYangResource("/schemas/test-module.yang");
doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult())).when(rpc).invokeRpc(any(), any());
- netconfOps = new NetconfBaseOps(rpc, schemaContext);
+ netconfOps = new NetconfBaseOps(rpc, SCHEMA_CONTEXT);
id = new RemoteDeviceId("device1", InetSocketAddress.createUnresolved("0.0.0.0", 17830));
}
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMRpcService;
import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
+import org.opendaylight.netconf.sal.connect.netconf.AbstractTestModelTest;
import org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps;
import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
import org.opendaylight.yangtools.util.concurrent.FluentFutures;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-
-public class WriteRunningTxTest {
+public class WriteRunningTxTest extends AbstractTestModelTest {
@Mock
private DOMRpcService rpc;
private NetconfBaseOps netconfOps;
private RemoteDeviceId id;
@Before
- public void setUp() throws Exception {
+ public void setUp() {
MockitoAnnotations.initMocks(this);
- final SchemaContext schemaContext =
- YangParserTestUtils.parseYangResource("/schemas/test-module.yang");
doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult())).when(rpc).invokeRpc(any(), any());
- netconfOps = new NetconfBaseOps(rpc, schemaContext);
+ netconfOps = new NetconfBaseOps(rpc, SCHEMA_CONTEXT);
id = new RemoteDeviceId("device1", InetSocketAddress.createUnresolved("0.0.0.0", 17830));
}
import org.opendaylight.netconf.api.xml.XmlUtil;
import org.opendaylight.netconf.sal.connect.api.MessageTransformer;
import org.opendaylight.netconf.sal.connect.api.RemoteDeviceCommunicator;
+import org.opendaylight.netconf.sal.connect.netconf.AbstractTestModelTest;
import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc;
import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.xml.sax.SAXException;
-public class NetconfBaseOpsTest {
+public class NetconfBaseOpsTest extends AbstractTestModelTest {
+ private static final QName CONTAINER_Q_NAME = QName.create("test:namespace", "2013-07-22", "c");
static {
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setIgnoreComments(true);
}
- private static final QName CONTAINER_Q_NAME = QName.create("test:namespace", "2013-07-22", "c");
-
@Mock
private RemoteDeviceCommunicator<NetconfMessage> listener;
private NetconfRpcFutureCallback callback;
.thenReturn(FluentFuture.from(RpcResultBuilder.success(ok).buildFuture()));
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_COMMIT_QNAME)))
.thenReturn(FluentFuture.from(RpcResultBuilder.success(ok).buildFuture()));
- final SchemaContext schemaContext =
- YangParserTestUtils.parseYangResource("/schemas/test-module.yang");
- final MessageTransformer<NetconfMessage> transformer = new NetconfMessageTransformer(schemaContext, true);
- final DOMRpcService rpc = new NetconfDeviceRpc(schemaContext, listener, transformer);
+ final MessageTransformer<NetconfMessage> transformer = new NetconfMessageTransformer(SCHEMA_CONTEXT, true);
+ final DOMRpcService rpc = new NetconfDeviceRpc(SCHEMA_CONTEXT, listener, transformer);
final RemoteDeviceId id =
new RemoteDeviceId("device-1", InetSocketAddress.createUnresolved("localhost", 17830));
callback = new NetconfRpcFutureCallback("prefix", id);
- baseOps = new NetconfBaseOps(rpc, schemaContext);
+ baseOps = new NetconfBaseOps(rpc, SCHEMA_CONTEXT);
}
@Test