Expose URLYangTextSource
[yangtools.git] / parser / odlext-parser-support / src / test / java / org / opendaylight / yangtools / odlext / parser / MountTest.java
1 /*
2  * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.odlext.parser;
9
10 import static org.junit.jupiter.api.Assertions.assertTrue;
11
12 import org.junit.jupiter.api.Test;
13 import org.opendaylight.yangtools.odlext.model.api.MountEffectiveStatement;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.common.QNameModule;
16 import org.opendaylight.yangtools.yang.common.XMLNamespace;
17 import org.opendaylight.yangtools.yang.model.spi.source.URLYangTextSource;
18 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
19 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
20 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
22
23 class MountTest {
24     private static final QNameModule FOO = QNameModule.create(XMLNamespace.of("foo"));
25
26     @Test
27     void test() throws Exception {
28         final var reactor = RFC7950Reactors.vanillaReactorBuilder()
29             .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION,
30                 new MountStatementSupport(YangParserConfiguration.DEFAULT))
31             .build();
32         final var foo = reactor.newBuild()
33             .addSource(YangStatementStreamSource.create(new URLYangTextSource(
34                 MountTest.class.getResource("/yang-ext.yang"))))
35             .addSource(YangStatementStreamSource.create(new URLYangTextSource(
36                 MountTest.class.getResource("/mount.yang"))))
37             .buildEffective()
38             .getModuleStatements()
39             .get(FOO);
40
41         assertTrue(foo.findDataTreeNode(QName.create(FOO, "foo")).orElseThrow()
42             .findFirstEffectiveSubstatement(MountEffectiveStatement.class)
43             .isPresent());
44
45         assertTrue(foo.findDataTreeNode(QName.create(FOO, "bar")).orElseThrow()
46             .findFirstEffectiveSubstatement(MountEffectiveStatement.class)
47             .isPresent());
48     }
49 }