use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project yangtools by opendaylight.
the class SchemaOrderedNormalizedNodeWriterTest method testWrite.
@Test
public void testWrite() throws XMLStreamException, IOException, SAXException {
final StringWriter stringWriter = new StringWriter();
final XMLStreamWriter xmlStreamWriter = factory.createXMLStreamWriter(stringWriter);
EffectiveModelContext schemaContext = getSchemaContext("/bug1848/foo.yang");
NormalizedNodeStreamWriter writer = XMLStreamNormalizedNodeStreamWriter.create(xmlStreamWriter, schemaContext);
try (SchemaOrderedNormalizedNodeWriter nnw = new SchemaOrderedNormalizedNodeWriter(writer, schemaContext)) {
List<MapEntryNode> rule1Names = new ArrayList<>();
rule1Names.add(ImmutableNodes.mapEntry(createQName(FOO_NAMESPACE, RULE_NODE), createQName(FOO_NAMESPACE, NAME_NODE), "rule1"));
rule1Names.add(ImmutableNodes.mapEntry(createQName(FOO_NAMESPACE, RULE_NODE), createQName(FOO_NAMESPACE, NAME_NODE), "rule2"));
List<MapEntryNode> rule2Names = new ArrayList<>();
rule1Names.add(ImmutableNodes.mapEntry(createQName(FOO_NAMESPACE, RULE_NODE), createQName(FOO_NAMESPACE, NAME_NODE), "rule3"));
rule1Names.add(ImmutableNodes.mapEntry(createQName(FOO_NAMESPACE, RULE_NODE), createQName(FOO_NAMESPACE, NAME_NODE), "rule4"));
UserMapNode rules1 = Builders.orderedMapBuilder().withNodeIdentifier(getNodeIdentifier(FOO_NAMESPACE, RULE_NODE)).withValue(rule1Names).build();
UserMapNode rules2 = Builders.orderedMapBuilder().withNodeIdentifier(getNodeIdentifier(FOO_NAMESPACE, RULE_NODE)).withValue(rule2Names).build();
List<MapEntryNode> policyNodes = new ArrayList<>();
final MapEntryNode pn1 = ImmutableNodes.mapEntryBuilder(createQName(FOO_NAMESPACE, POLICY_NODE), createQName(FOO_NAMESPACE, NAME_NODE), "policy1").withChild(rules1).build();
final MapEntryNode pn2 = ImmutableNodes.mapEntryBuilder(createQName(FOO_NAMESPACE, POLICY_NODE), createQName(FOO_NAMESPACE, NAME_NODE), "policy2").withChild(rules2).build();
policyNodes.add(pn1);
policyNodes.add(pn2);
UserMapNode policy = Builders.orderedMapBuilder().withNodeIdentifier(getNodeIdentifier(FOO_NAMESPACE, POLICY_NODE)).withValue(policyNodes).build();
ContainerNode root = Builders.containerBuilder().withNodeIdentifier(getNodeIdentifier(FOO_NAMESPACE, "root")).withChild(policy).build();
nnw.write(root);
}
XMLAssert.assertXMLIdentical(new Diff(EXPECTED_1, stringWriter.toString()), true);
}
use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project yangtools by opendaylight.
the class SchemaOrderedNormalizedNodeWriterTest method testWriteOrder.
@Test
public void testWriteOrder() throws XMLStreamException, IOException, SAXException {
final StringWriter stringWriter = new StringWriter();
final XMLStreamWriter xmlStreamWriter = factory.createXMLStreamWriter(stringWriter);
EffectiveModelContext schemaContext = getSchemaContext("/bug1848/order.yang");
NormalizedNodeStreamWriter writer = XMLStreamNormalizedNodeStreamWriter.create(xmlStreamWriter, schemaContext);
try (NormalizedNodeWriter nnw = new SchemaOrderedNormalizedNodeWriter(writer, schemaContext)) {
ContainerNode cont = Builders.containerBuilder().withNodeIdentifier(getNodeIdentifier(ORDER_NAMESPACE, "cont")).withChild(ImmutableNodes.leafNode(createQName(ORDER_NAMESPACE, "content"), "content1")).build();
ContainerNode root = Builders.containerBuilder().withNodeIdentifier(getNodeIdentifier(ORDER_NAMESPACE, "root")).withChild(cont).withChild(ImmutableNodes.leafNode(createQName(ORDER_NAMESPACE, "id"), "id1")).build();
nnw.write(root);
}
XMLAssert.assertXMLIdentical(new Diff(EXPECTED_2, stringWriter.toString()), true);
}
use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project yangtools by opendaylight.
the class Bug8083Test method testInstanceIdentifierPathWithEmptyListKey.
@Test
public void testInstanceIdentifierPathWithEmptyListKey() throws Exception {
final EffectiveModelContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/baz.yang");
final InputStream resourceAsStream = Bug8083Test.class.getResourceAsStream("/bug8083/xml/baz.xml");
final XMLStreamReader reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
// deserialization
final NormalizedNodeResult result = new NormalizedNodeResult();
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, Inference.ofDataTreePath(schemaContext, QName.create(BAZ, "top-cont")));
xmlParser.parse(reader);
final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
}
use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project yangtools by opendaylight.
the class Bug8083Test method testInstanceIdentifierPathWithIdentityrefListKey.
@Test
public void testInstanceIdentifierPathWithIdentityrefListKey() throws Exception {
final EffectiveModelContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/zab.yang");
final InputStream resourceAsStream = Bug8083Test.class.getResourceAsStream("/bug8083/xml/zab.xml");
final XMLStreamReader reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
// deserialization
final NormalizedNodeResult result = new NormalizedNodeResult();
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, Inference.ofDataTreePath(schemaContext, QName.create(ZAB, "top-cont")));
xmlParser.parse(reader);
final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
}
use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project yangtools by opendaylight.
the class Bug890Test method testinputXml.
@Test
public void testinputXml() throws Exception {
final EffectiveModelContext schemaContext = YangParserTestUtils.parseYangResource("/bug890/yang/foo.yang");
final InputStream resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream("/bug890/xml/foo.xml");
final XMLStreamReader reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
final NormalizedNodeResult result = new NormalizedNodeResult();
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, Inference.ofDataTreePath(schemaContext, QName.create(FOO_MODULE, "root")));
xmlParser.parse(reader);
assertNotNull(result.getResult());
assertTrue(result.getResult() instanceof ContainerNode);
final ContainerNode rootContainer = (ContainerNode) result.getResult();
DataContainerChild myLeaf = rootContainer.childByArg(new NodeIdentifier(OUTGOING_LABELS_QNAME));
assertTrue(myLeaf instanceof ContainerNode);
ContainerNode outgoingLabelsContainer = (ContainerNode) myLeaf;
DataContainerChild outgoingLabelsList = outgoingLabelsContainer.childByArg(new NodeIdentifier(OUTGOING_LABELS_QNAME));
assertTrue(outgoingLabelsList instanceof MapNode);
MapNode outgoingLabelsMap = (MapNode) outgoingLabelsList;
assertEquals(2, outgoingLabelsMap.size());
Collection<MapEntryNode> labels = outgoingLabelsMap.body();
NodeIdentifierWithPredicates firstNodeId = NodeIdentifierWithPredicates.of(OUTGOING_LABELS_QNAME, INDEX_QNAME, 0);
NodeIdentifierWithPredicates secondNodeId = NodeIdentifierWithPredicates.of(OUTGOING_LABELS_QNAME, INDEX_QNAME, 1);
assertTrue(labels.stream().anyMatch(mapEntryNode -> mapEntryNode.getIdentifier().compareTo(firstNodeId) == 0));
assertTrue(labels.stream().anyMatch(mapEntryNode -> mapEntryNode.getIdentifier().compareTo(secondNodeId) == 0));
}
Aggregations