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.Assert.assertEquals;
12 import org.junit.Test;
13 import org.opendaylight.yangtools.util.xml.UntrustedXML;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
17 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
18 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
19 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
20 import org.opendaylight.yangtools.yang.data.impl.schema.NormalizationResultHolder;
21 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference;
22 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
24 public class YT1107Test {
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 public void testInterleavingLists() throws Exception {
32 final var schemaContext = YangParserTestUtils.parseYangResource("/yt1107/yt1107.yang");
33 final var resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream("/yt1107/yt1107.xml");
34 final var reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
36 final var result = new NormalizationResultHolder();
37 final var streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
38 final var xmlParser = XmlParserStream.create(streamWriter, Inference.ofDataTreePath(schemaContext, PARENT));
39 xmlParser.parse(reader);
41 assertEquals(Builders.containerBuilder()
42 .withNodeIdentifier(new NodeIdentifier(PARENT))
43 .withChild(Builders.mapBuilder()
44 .withNodeIdentifier(new NodeIdentifier(ADMIN))
45 .withChild(Builders.mapEntryBuilder()
46 .withNodeIdentifier(NodeIdentifierWithPredicates.of(ADMIN, NAME, "John"))
47 .withChild(ImmutableNodes.leafNode(NAME, "John"))
50 .withChild(Builders.mapBuilder()
51 .withNodeIdentifier(new NodeIdentifier(USER))
52 .withChild(Builders.mapEntryBuilder()
53 .withNodeIdentifier(NodeIdentifierWithPredicates.of(USER, NAME, "Freud"))
54 .withChild(ImmutableNodes.leafNode(NAME, "Freud"))
56 .withChild(Builders.mapEntryBuilder()
57 .withNodeIdentifier(NodeIdentifierWithPredicates.of(USER, NAME, "Bob"))
58 .withChild(ImmutableNodes.leafNode(NAME, "Bob"))
61 .build(), result.getResult().data());