use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class NetconfMessageTransformerTest method testGetConfigRequest.
@Test
public void testGetConfigRequest() throws Exception {
final AnyxmlNode<?> filter = toFilterStructure(YangInstanceIdentifier.create(toId(NetconfState.QNAME), toId(Schemas.QNAME)), 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" + "</netconf-state>" + "</filter>\n" + "<source>\n" + "<running/>\n" + "</source>\n" + "</get-config>" + "</rpc>");
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class NetconfMessageTransformerTest method testDiscardChangesRequest.
@Test
public void testDiscardChangesRequest() throws Exception {
final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(NETCONF_DISCARD_CHANGES_QNAME, null);
assertThat(XmlUtil.toString(netconfMessage.getDocument()), CoreMatchers.containsString("<discard"));
assertThat(XmlUtil.toString(netconfMessage.getDocument()), CoreMatchers.containsString("<rpc"));
assertThat(XmlUtil.toString(netconfMessage.getDocument()), CoreMatchers.containsString("message-id"));
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class NetconfMessageTransformerTest method getSpecificFieldsUnderListTest.
@Test
public void getSpecificFieldsUnderListTest() throws IOException, SAXException {
// preparation of the fields
final YangInstanceIdentifier parentYiid = YangInstanceIdentifier.create(toId(NetconfState.QNAME), toId(Schemas.QNAME), toId(Schema.QNAME), NodeIdentifierWithPredicates.of(Schema.QNAME));
final YangInstanceIdentifier versionField = YangInstanceIdentifier.create(toId(QName.create(Schema.QNAME, "version").intern()));
final YangInstanceIdentifier identifierField = YangInstanceIdentifier.create(toId(QName.create(Schema.QNAME, "namespace").intern()));
// building filter structure and NETCONF message
final AnyxmlNode<?> filterStructure = toFilterStructure(List.of(FieldsFilter.of(parentYiid, List.of(versionField, identifierField))), SCHEMA);
final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(NETCONF_GET_QNAME, NetconfMessageTransformUtil.wrap(toId(NETCONF_GET_QNAME), filterStructure));
// testing
assertSimilarXml(netconfMessage, "<rpc message-id=\"m-0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" + "<get>\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" + "<namespace/>\n" + // explicitly fetched list keys - identifier and format
"<identifier/>\n" + "<format/>\n" + "</schema>\n" + "</schemas>\n" + "</netconf-state>\n" + "</filter>\n" + "</get>\n" + "</rpc>");
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class NetconfClientSessionNegotiatorTest method testNetconfClientSessionNegotiatorWithEXI.
@Test
public void testNetconfClientSessionNegotiatorWithEXI() throws Exception {
Promise<NetconfClientSession> promise = mock(Promise.class);
NetconfStartExiMessage exiMessage = NetconfStartExiMessage.create(EXIParameters.empty(), "msg-id");
doReturn(promise).when(promise).setSuccess(any());
NetconfClientSessionNegotiator negotiator = createNetconfClientSessionNegotiator(promise, exiMessage);
negotiator.channelActive(null);
Set<String> caps = Sets.newSet("exi:1.0");
NetconfHelloMessage message = NetconfHelloMessage.createServerHello(caps, 10);
doAnswer(invocationOnMock -> {
channelInboundHandlerAdapter = invocationOnMock.getArgument(2);
return null;
}).when(pipeline).addAfter(anyString(), anyString(), any(ChannelHandler.class));
ChannelHandlerContext handlerContext = mock(ChannelHandlerContext.class);
doReturn(pipeline).when(handlerContext).pipeline();
negotiator.handleMessage(message);
Document expectedResult = XmlFileLoader.xmlFileToDocument("netconfMessages/rpc-reply_ok.xml");
channelInboundHandlerAdapter.channelRead(handlerContext, new NetconfMessage(expectedResult));
verify(promise).setSuccess(any());
// two calls for exiMessage, 2 for hello message
verify(pipeline, times(4)).replace(anyString(), anyString(), any(ChannelHandler.class));
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class SimpleNetconfClientSessionListenerTest method testSessionDown.
@Test
public void testSessionDown() throws Exception {
SimpleNetconfClientSessionListener simpleListener = new SimpleNetconfClientSessionListener();
final Future<NetconfMessage> promise = simpleListener.sendRequest(message);
simpleListener.onSessionUp(clientSession);
verify(channel, times(1)).writeAndFlush(any(), any());
simpleListener.onSessionDown(clientSession, new Exception());
assertFalse(promise.isSuccess());
}
Aggregations