Deprecate simple DataTreeFactory.create()
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / YT1262Test.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.yang.stmt;
9
10 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
11 import static org.junit.jupiter.api.Assertions.assertTrue;
12
13 import org.junit.jupiter.api.Test;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.common.QNameModule;
16 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
17 import org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.stmt.ListEffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.TypedefAwareEffectiveStatement;
24
25 class YT1262Test extends AbstractYangTest {
26     @Test
27     void testTypedefNamespaces() {
28         final var modelContext = assertEffectiveModelDir("/bugs/YT1262");
29         final var module = modelContext.getModuleStatement(QNameModule.of("foo"));
30         assertTypedef(module, "fdef");
31         assertTypedef(module, "sdef");
32         assertTypedef(module.findFirstEffectiveSubstatement(GroupingEffectiveStatement.class).orElseThrow(), "gdef");
33         assertTypedef(module.findFirstEffectiveSubstatement(ListEffectiveStatement.class).orElseThrow(), "ldef");
34         assertTypedef(module.findFirstEffectiveSubstatement(NotificationEffectiveStatement.class).orElseThrow(),
35             "ndef");
36         assertTypedef(module.findFirstEffectiveSubstatement(RpcEffectiveStatement.class).orElseThrow(), "rdef");
37
38         final var container = module.findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow();
39         assertTypedef(container, "cdef");
40
41         final var action = container.findFirstEffectiveSubstatement(ActionEffectiveStatement.class).orElseThrow();
42         assertTypedef(action, "adef");
43         assertTypedef(action.input(), "idef");
44         assertTypedef(action.output(), "odef");
45     }
46
47     private static void assertTypedef(final EffectiveStatement<?, ?> parent, final String typedefName) {
48         assertTrue(assertInstanceOf(TypedefAwareEffectiveStatement.class, parent)
49             .findTypedef(QName.create("foo", typedefName)).isPresent());
50     }
51 }