2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.data.codec.xml;
10 import static org.junit.jupiter.api.Assertions.assertEquals;
12 import java.io.StringReader;
13 import org.junit.jupiter.api.Test;
14 import org.opendaylight.yangtools.util.xml.UntrustedXML;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
18 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
19 import org.opendaylight.yangtools.yang.data.impl.schema.NormalizationResultHolder;
20 import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
21 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference;
22 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
25 private static final QName PARENT = QName.create("yt1107", "parent");
26 private static final QName ADMIN = QName.create(PARENT, "admin");
27 private static final QName NAME = QName.create(PARENT, "name");
28 private static final QName USER = QName.create(PARENT, "user");
31 void testInterleavingLists() throws Exception {
32 final var schemaContext = YangParserTestUtils.parseYang("""
53 final var reader = UntrustedXML.createXMLStreamReader(new StringReader("""
54 <parent xmlns="yt1107">
65 final var result = new NormalizationResultHolder();
66 final var streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
67 final var xmlParser = XmlParserStream.create(streamWriter, Inference.ofDataTreePath(schemaContext, PARENT));
68 xmlParser.parse(reader);
70 assertEquals(ImmutableNodes.newContainerBuilder()
71 .withNodeIdentifier(new NodeIdentifier(PARENT))
72 .withChild(ImmutableNodes.newSystemMapBuilder()
73 .withNodeIdentifier(new NodeIdentifier(ADMIN))
74 .withChild(ImmutableNodes.newMapEntryBuilder()
75 .withNodeIdentifier(NodeIdentifierWithPredicates.of(ADMIN, NAME, "John"))
76 .withChild(ImmutableNodes.leafNode(NAME, "John"))
79 .withChild(ImmutableNodes.newSystemMapBuilder()
80 .withNodeIdentifier(new NodeIdentifier(USER))
81 .withChild(ImmutableNodes.newMapEntryBuilder()
82 .withNodeIdentifier(NodeIdentifierWithPredicates.of(USER, NAME, "Freud"))
83 .withChild(ImmutableNodes.leafNode(NAME, "Freud"))
85 .withChild(ImmutableNodes.newMapEntryBuilder()
86 .withNodeIdentifier(NodeIdentifierWithPredicates.of(USER, NAME, "Bob"))
87 .withChild(ImmutableNodes.leafNode(NAME, "Bob"))
90 .build(), result.getResult().data());