use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class NetconfHelloMessageToXMLEncoderTest method testEncodeNotHello.
@Test(expected = IllegalStateException.class)
public void testEncodeNotHello() throws Exception {
final NetconfMessage msg = new NetconfMessage(XmlUtil.readXmlToDocument("<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>"));
new NetconfHelloMessageToXMLEncoder().encode(ctx, msg, null);
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class SchemalessNetconfDeviceRpcTest method testInvokeRpc.
@Test
public void testInvokeRpc() throws Exception {
final QName qName = QName.create("urn:ietf:params:xml:ns:netconf:base:1.0", "2011-06-01", "get-config");
DOMSource src = new DOMSource(XmlUtil.readXmlToDocument("<get-config xmlns=\"dd\">\n" + " <source>\n" + " <running/>\n" + " </source>\n" + " <filter type=\"subtree\">\n" + " <mainroot xmlns=\"urn:dummy:mod-0\">\n" + " <maincontent/>\n" + "<choiceList></choiceList>\n" + " </mainroot>\n" + " </filter>\n" + " </get-config>"));
AnyxmlNode<?> input = Builders.anyXmlBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(qName)).withValue(src).build();
deviceRpc.invokeRpc(qName, input);
ArgumentCaptor<NetconfMessage> msgCaptor = ArgumentCaptor.forClass(NetconfMessage.class);
ArgumentCaptor<QName> qnameCaptor = ArgumentCaptor.forClass(QName.class);
verify(listener).sendRequest(msgCaptor.capture(), qnameCaptor.capture());
LOG.info(XmlUtil.toString(msgCaptor.getValue().getDocument()));
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class NetconfBaseOpsTest method setUp.
@Before
public void setUp() throws Exception {
final InputStream okStream = getClass().getResourceAsStream("/netconfMessages/rpc-reply_ok.xml");
final InputStream dataStream = getClass().getResourceAsStream("/netconfMessages/rpc-reply_get.xml");
final NetconfMessage ok = new NetconfMessage(XmlUtil.readXmlToDocument(okStream));
final NetconfMessage data = new NetconfMessage(XmlUtil.readXmlToDocument(dataStream));
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME))).thenReturn(RpcResultBuilder.success(data).buildFuture());
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_GET_QNAME))).thenReturn(RpcResultBuilder.success(data).buildFuture());
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_COPY_CONFIG_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_DISCARD_CHANGES_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_VALIDATE_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_LOCK_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_UNLOCK_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_COMMIT_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
final MessageTransformer<NetconfMessage> transformer = new NetconfMessageTransformer(new EmptyMountPointContext(SCHEMA_CONTEXT), true, BASE_SCHEMAS.getBaseSchema());
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, new EmptyMountPointContext(SCHEMA_CONTEXT));
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class NetconfMessageTransformerTest method toActionRequestContainerTopLevelTest.
@Test
public void toActionRequestContainerTopLevelTest() {
List<PathArgument> nodeIdentifiers = List.of(NodeIdentifier.create(DEVICE_QNAME));
DOMDataTreeIdentifier domDataTreeIdentifier = prepareDataTreeId(nodeIdentifiers);
ContainerNode payload = initInputAction(QName.create(DEVICE_QNAME, "start-at"), "now");
NetconfMessage actionRequest = actionNetconfMessageTransformer.toActionRequest(START_DEVICE_PATH, domDataTreeIdentifier, payload);
Node childAction = checkBasePartOfActionRequest(actionRequest);
Node childDevice = childAction.getFirstChild();
checkNode(childDevice, "device", "device", URN_EXAMPLE_SERVER_FARM);
checkAction(START_QNAME, childDevice.getFirstChild(), "start-at", "start-at", "now");
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class NetconfMessageTransformerTest method testGetConfigLeafRequest.
@Test
public void testGetConfigLeafRequest() throws Exception {
final AnyxmlNode<?> filter = toFilterStructure(YangInstanceIdentifier.create(toId(NetconfState.QNAME), toId(Schemas.QNAME), toId(Schema.QNAME), NodeIdentifierWithPredicates.of(Schema.QNAME), toId(QName.create(Schemas.QNAME, "version"))), SCHEMA);
final ContainerNode source = NetconfBaseOps.getSourceNode(NETCONF_RUNNING_QNAME);
final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(NETCONF_GET_CONFIG_QNAME, NetconfMessageTransformUtil.wrap(NETCONF_GET_CONFIG_QNAME, source, filter));
assertSimilarXml(netconfMessage, "<rpc message-id=\"m-0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" + "<get-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" + "<filter xmlns:ns0=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ns0:type=\"subtree\">\n" + "<netconf-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n" + "<schemas>\n" + "<schema>\n" + "<version/>\n" + "</schema>\n" + "</schemas>\n" + "</netconf-state>\n" + "</filter>\n" + "<source>\n" + "<running/>\n" + "</source>\n" + "</get-config>\n" + "</rpc>");
}
Aggregations