2 * Copyright (c) 2019 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.rfc8528.parser;
10 import static org.hamcrest.CoreMatchers.instanceOf;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertThat;
14 import java.io.IOException;
16 import java.util.List;
17 import java.util.stream.Collectors;
18 import org.junit.AfterClass;
19 import org.junit.BeforeClass;
20 import org.junit.Test;
21 import org.opendaylight.yangtools.rfc8528.model.api.MountPointSchemaNode;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.common.QNameModule;
24 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
25 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
26 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
27 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
28 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
29 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
30 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
31 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
32 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
33 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
34 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
36 public class MountPointTest {
37 private static final QNameModule EXAMPLE_USES = QNameModule.create(URI.create("http://example.org/example-uses"));
38 private static final QName EXAMPLE_CONT = QName.create(EXAMPLE_USES, "cont");
39 private static final QName EXAMPLE_GRP = QName.create(EXAMPLE_USES, "grp");
40 private static final QName EXAMPLE_GRP_CONT = QName.create(EXAMPLE_USES, "grp-cont");
41 private static final QName EXAMPLE_LIST = QName.create(EXAMPLE_USES, "list");
43 private static CrossSourceStatementReactor reactor;
46 public static void createReactor() {
47 reactor = RFC7950Reactors.vanillaReactorBuilder()
48 .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION, MountPointStatementSupport.getInstance())
53 public static void freeReactor() {
58 public void testMountPointResolution() throws ReactorException, IOException, YangSyntaxErrorException {
59 final SchemaContext context = reactor.newBuild()
61 YangStatementStreamSource.create(YangTextSchemaSource.forResource(
62 "/ietf-inet-types@2013-07-15.yang")),
63 YangStatementStreamSource.create(YangTextSchemaSource.forResource(
64 "/ietf-yang-schema-mount@2019-01-14.yang")),
65 YangStatementStreamSource.create(YangTextSchemaSource.forResource(
66 "/ietf-yang-types@2013-07-15.yang")))
68 YangStatementStreamSource.create(YangTextSchemaSource.forResource("/example-grp.yang")),
69 YangStatementStreamSource.create(YangTextSchemaSource.forResource("/example-uses.yang")))
72 assertEquals(5, context.getModules().size());
74 DataSchemaNode child = context.findDataTreeChild(EXAMPLE_CONT).get();
75 assertThat(child, instanceOf(ContainerSchemaNode.class));
76 List<MountPointSchemaNode> mps = MountPointSchemaNode.streamAll((ContainerSchemaNode) child)
77 .collect(Collectors.toList());
78 assertEquals(2, mps.size());
79 assertEquals(EXAMPLE_CONT, mps.get(0).getQName());
80 assertEquals(EXAMPLE_CONT, mps.get(1).getQName());
82 child = context.findDataTreeChild(EXAMPLE_GRP_CONT).get();
83 assertThat(child, instanceOf(ContainerSchemaNode.class));
84 mps = MountPointSchemaNode.streamAll((ContainerSchemaNode) child).collect(Collectors.toList());
85 assertEquals(1, mps.size());
86 assertEquals(EXAMPLE_GRP, mps.get(0).getQName());
88 child = context.findDataTreeChild(EXAMPLE_LIST).get();
89 assertThat(child, instanceOf(ListSchemaNode.class));
90 mps = MountPointSchemaNode.streamAll((ListSchemaNode) child).collect(Collectors.toList());
91 assertEquals(1, mps.size());
92 assertEquals(EXAMPLE_LIST, mps.get(0).getQName());