use of org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode in project yangtools by opendaylight.
the class SchemalessXMLStreamNormalizedNodeStreamWriterTest method buildOuterContainerNode.
private NormalizedNode buildOuterContainerNode() {
// my-container-1
MapNode myKeyedListNode = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(myKeyedList)).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(myKeyedList, myKeyLeaf, "listkeyvalue1")).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInList1)).withValue("listleafvalue1").build()).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInList2)).withValue("listleafvalue2").build()).build()).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(myKeyedList, myKeyLeaf, "listkeyvalue2")).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInList1)).withValue("listleafvalue12").build()).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInList2)).withValue("listleafvalue22").build()).build()).build();
UserMapNode myOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(new NodeIdentifier(myOrderedList)).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(myOrderedList, myKeyLeafInOrderedList, "olistkeyvalue1")).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInOrderedList1)).withValue("olistleafvalue1").build()).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInOrderedList2)).withValue("olistleafvalue2").build()).build()).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(myOrderedList, myKeyLeafInOrderedList, "olistkeyvalue2")).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInOrderedList1)).withValue("olistleafvalue12").build()).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInOrderedList2)).withValue("olistleafvalue22").build()).build()).build();
final UnkeyedListEntryNode unkeyedListEntry = Builders.unkeyedListEntryBuilder().withNodeIdentifier(new NodeIdentifier(myUnkeyedList)).withChild(ImmutableNodes.leafNode(myLeafInUnkeyedList, "foo")).build();
final List<UnkeyedListEntryNode> unkeyedListEntries = new ArrayList<>();
unkeyedListEntries.add(unkeyedListEntry);
UnkeyedListNode myUnkeyedListNode = Builders.unkeyedListBuilder().withNodeIdentifier(new NodeIdentifier(myUnkeyedList)).withValue(unkeyedListEntries).build();
LeafNode<?> myLeaf1Node = ImmutableNodes.leafNode(myLeaf1, "value1");
SystemLeafSetNode<?> myLeafListNode = Builders.leafSetBuilder().withNodeIdentifier(new NodeIdentifier(myLeafList)).withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue<>(myLeafList, "lflvalue1")).withValue("lflvalue1").build()).withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue<>(myLeafList, "lflvalue2")).withValue("lflvalue2").build()).build();
UserLeafSetNode<?> myOrderedLeafListNode = Builders.orderedLeafSetBuilder().withNodeIdentifier(new NodeIdentifier(myOrderedLeafList)).withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue<>(myOrderedLeafList, "olflvalue1")).withValue("olflvalue1").build()).withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue<>(myOrderedLeafList, "olflvalue2")).withValue("olflvalue2").build()).build();
ContainerNode myContainer1Node = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(myContainer1)).withChild(myKeyedListNode).withChild(myOrderedListNode).withChild(myUnkeyedListNode).withChild(myLeaf1Node).withChild(myLeafListNode).withChild(myOrderedLeafListNode).build();
// my-container-2
ContainerNode innerContainerNode = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(innerContainer)).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeaf2)).withValue("value2").build()).build();
LeafNode<?> myLeaf3Node = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeaf3)).withValue("value3").build();
ChoiceNode myChoiceNode = Builders.choiceBuilder().withNodeIdentifier(new NodeIdentifier(myChoice)).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInCase2)).withValue("case2value").build()).build();
DOMSourceAnyxmlNode myAnyxmlNode = Builders.anyXmlBuilder().withNodeIdentifier(new NodeIdentifier(myAnyxml)).withValue(anyxmlDomSource).build();
ContainerNode myContainer2Node = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(myContainer2)).withChild(innerContainerNode).withChild(myLeaf3Node).withChild(myChoiceNode).build();
// .withChild(myAnyxmlNode).build();
// my-container-3
Map<QName, Object> keys = new HashMap<>();
keys.put(myFirstKeyLeaf, "listkeyvalue1");
keys.put(mySecondKeyLeaf, "listkeyvalue2");
MapNode myDoublyKeyedListNode = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(myDoublyKeyedList)).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(myDoublyKeyedList, keys)).withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInList3)).withValue("listleafvalue1").build()).build()).build();
AugmentationNode myDoublyKeyedListAugNode = Builders.augmentationBuilder().withNodeIdentifier(new AugmentationIdentifier(ImmutableSet.of(myDoublyKeyedList))).withChild(myDoublyKeyedListNode).build();
ContainerNode myContainer3Node = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(myContainer3)).withChild(myDoublyKeyedListAugNode).build();
AugmentationNode myContainer3AugNode = Builders.augmentationBuilder().withNodeIdentifier(new AugmentationIdentifier(ImmutableSet.of(myContainer3))).withChild(myContainer3Node).build();
ContainerNode outerContainerNode = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(outerContainer)).withChild(myContainer1Node).withChild(myContainer2Node).withChild(myContainer3AugNode).build();
return outerContainerNode;
}
use of org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode in project yangtools by opendaylight.
the class AnyXmlWithParamsParsingTest method testAnyXmlWithParams.
@Test
public void testAnyXmlWithParams() throws Exception {
final EffectiveModelContext context = YangParserTestUtils.parseYangResourceDirectory("/anyxml-support/params/");
final Document doc = UntrustedXML.newDocumentBuilder().parse(EDIT_CONFIG);
final NormalizedNodeResult resultHolder = new NormalizedNodeResult();
final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder);
final XmlParserStream xmlParser = XmlParserStream.create(writer, SchemaInferenceStack.of(context, Absolute.of(QName.create(IETF_NETCONF, "edit-config"), YangConstants.operationInputQName(IETF_NETCONF))).toInference());
xmlParser.traverse(new DOMSource(doc.getDocumentElement()));
final NormalizedNode parsed = resultHolder.getResult();
final DataContainerChild editCfg = ((ContainerNode) parsed).childByArg(getNodeId(parsed, "edit-content"));
final DOMSource anyXmlParsedDom = ((DOMSourceAnyxmlNode) ((ChoiceNode) editCfg).childByArg(getNodeId(parsed, "config"))).body();
assertNotNull(anyXmlParsedDom);
final String anyXmlParsedDomString = toStringDom(anyXmlParsedDom);
assertThat(anyXmlParsedDomString, containsString("active xmpref:prefixed2=\"attribute2\""));
assertThat(anyXmlParsedDomString, containsString("interface-name xmpref:prefixed3=\"attribute3\""));
assertThat(anyXmlParsedDomString, containsString("interface-configuration xmlns:xmpref=\"xml:namespace:prefix\" simple=\"attribute\""));
assertThat(anyXmlParsedDomString, containsString("interface-configurations xmlns=\"http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg\""));
}
use of org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode in project yangtools by opendaylight.
the class NormalizedNodeWriterTest method testNormalizedNodeWriter.
@Test
public void testNormalizedNodeWriter() throws IOException {
final NormalizedNodeStreamWriter loggingNormalizedNodeStreamWriter = new LoggingNormalizedNodeStreamWriter();
final NormalizedNodeWriter orderedNormalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(loggingNormalizedNodeStreamWriter);
assertEquals(loggingNormalizedNodeStreamWriter, orderedNormalizedNodeWriter.getWriter());
final IllegalStateException ex = assertThrows(IllegalStateException.class, () -> orderedNormalizedNodeWriter.write(mock(NormalizedNode.class)));
assertTrue(ex.getMessage().startsWith("It wasn't possible to serialize node"));
final LeafSetEntryNode<?> mockedLeafSetEntryNode = mock(LeafSetEntryNode.class);
doReturn(new NodeWithValue<>(myLeafList, "leaflist-value-1")).when(mockedLeafSetEntryNode).getIdentifier();
doReturn("leaflist-value-1").when(mockedLeafSetEntryNode).body();
assertNotNull(orderedNormalizedNodeWriter.write(mockedLeafSetEntryNode));
final LeafNode<?> mockedLeafNode = mock(LeafNode.class);
doReturn("leaf-value-1").when(mockedLeafNode).body();
assertNotNull(orderedNormalizedNodeWriter.write(mockedLeafNode));
final DOMSourceAnyxmlNode mockedAnyXmlNode = mock(DOMSourceAnyxmlNode.class);
doCallRealMethod().when(mockedAnyXmlNode).bodyObjectModel();
doReturn(new DOMSource()).when(mockedAnyXmlNode).body();
assertNotNull(orderedNormalizedNodeWriter.write(mockedAnyXmlNode));
final NormalizedNode mockedContainerNode = mock(ContainerNode.class);
assertNotNull(orderedNormalizedNodeWriter.write(mockedContainerNode));
final MapEntryNode mockedMapEntryNode = mock(MapEntryNode.class);
doReturn(NodeIdentifierWithPredicates.of(myKeyedList, myKeyLeaf, "list-key-value-1")).when(mockedMapEntryNode).getIdentifier();
doReturn(null).when(mockedMapEntryNode).childByArg(any(NodeIdentifier.class));
assertNotNull(orderedNormalizedNodeWriter.write(mockedMapEntryNode));
final UnkeyedListEntryNode mockedUnkeyedListEntryNode = mock(UnkeyedListEntryNode.class);
assertNotNull(orderedNormalizedNodeWriter.write(mockedUnkeyedListEntryNode));
assertNotNull(orderedNormalizedNodeWriter.write(mock(ChoiceNode.class)));
assertNotNull(orderedNormalizedNodeWriter.write(mock(AugmentationNode.class)));
final UnkeyedListNode mockedUnkeyedListNode = mock(UnkeyedListNode.class);
final Set<?> value = Set.of(mockedUnkeyedListEntryNode);
doReturn(value).when(mockedUnkeyedListNode).body();
assertNotNull(orderedNormalizedNodeWriter.write(mockedUnkeyedListNode));
assertNotNull(orderedNormalizedNodeWriter.write(mock(UserMapNode.class)));
assertNotNull(orderedNormalizedNodeWriter.write(mock(SystemMapNode.class)));
assertNotNull(orderedNormalizedNodeWriter.write(mock(UserLeafSetNode.class)));
assertNotNull(orderedNormalizedNodeWriter.write(mock(SystemLeafSetNode.class)));
orderedNormalizedNodeWriter.flush();
orderedNormalizedNodeWriter.close();
final NormalizedNodeWriter normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(loggingNormalizedNodeStreamWriter, false);
assertNotNull(normalizedNodeWriter.write(mockedMapEntryNode));
normalizedNodeWriter.flush();
normalizedNodeWriter.close();
}
use of org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode in project netconf by opendaylight.
the class SchemalessMessageTransformer method toNotification.
@Override
public DOMNotification toNotification(final NetconfMessage message) {
final Map.Entry<Instant, XmlElement> stripped = NetconfMessageTransformUtil.stripNotification(message);
final QName notificationNoRev;
try {
notificationNoRev = QName.create(stripped.getValue().getNamespace(), stripped.getValue().getName()).withoutRevision();
} catch (final MissingNameSpaceException e) {
throw new IllegalArgumentException("Unable to parse notification " + message + ", cannot find namespace", e);
}
final DOMSourceAnyxmlNode notificationPayload = Builders.anyXmlBuilder().withNodeIdentifier(new NodeIdentifier(notificationNoRev)).withValue(new DOMSource(stripped.getValue().getDomElement())).build();
final ContainerNode notificationBody = Builders.containerBuilder().withNodeIdentifier(SCHEMALESS_NOTIFICATION_PAYLOAD).withChild(notificationPayload).build();
return new NetconfMessageTransformer.NetconfDeviceNotification(notificationBody, stripped.getKey());
}
use of org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode in project netconf by opendaylight.
the class SchemalessMessageTransformer method toRpcResult.
/**
* Transforms reply message to anyXml node.
* In case, that rpc-reply doesn't contain data and contains only <ok/> element, returns null.
* @param rpcReply reply message
* @return anyxml
*/
@Override
public DOMRpcResult toRpcResult(final NetconfMessage rpcReply, final QName rpc) {
final Document document = rpcReply.getDocument();
final DOMSourceAnyxmlNode result;
if (BaseRpcSchemalessTransformer.isOkPresent(document)) {
result = null;
} else {
result = Builders.anyXmlBuilder().withNodeIdentifier(NetconfMessageTransformUtil.NETCONF_RPC_REPLY_NODEID).withValue(new DOMSource(rpcReply.getDocument())).build();
}
return new DefaultDOMRpcResult(result);
}
Aggregations