Do do not check unique in unsupported lists
[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.common.XMLNamespace;
17 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
18 import org.opendaylight.yangtools.yang.model.api.stmt.ActionEffectiveStatement;
19 import org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement;
20 import org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement;
21 import org.opendaylight.yangtools.yang.model.api.stmt.ListEffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement;
23 import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.api.stmt.TypedefAwareEffectiveStatement;
25
26 class YT1262Test extends AbstractYangTest {
27     @Test
28     void testTypedefNamespaces() {
29         final var modelContext = assertEffectiveModelDir("/bugs/YT1262");
30         final var module = modelContext.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
31         assertTypedef(module, "fdef");
32         assertTypedef(module, "sdef");
33         assertTypedef(module.findFirstEffectiveSubstatement(GroupingEffectiveStatement.class).orElseThrow(), "gdef");
34         assertTypedef(module.findFirstEffectiveSubstatement(ListEffectiveStatement.class).orElseThrow(), "ldef");
35         assertTypedef(module.findFirstEffectiveSubstatement(NotificationEffectiveStatement.class).orElseThrow(),
36             "ndef");
37         assertTypedef(module.findFirstEffectiveSubstatement(RpcEffectiveStatement.class).orElseThrow(), "rdef");
38
39         final var container = module.findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow();
40         assertTypedef(container, "cdef");
41
42         final var action = container.findFirstEffectiveSubstatement(ActionEffectiveStatement.class).orElseThrow();
43         assertTypedef(action, "adef");
44         assertTypedef(action.input(), "idef");
45         assertTypedef(action.output(), "odef");
46     }
47
48     private static void assertTypedef(final EffectiveStatement<?, ?> parent, final String typedefName) {
49         assertTrue(assertInstanceOf(TypedefAwareEffectiveStatement.class, parent)
50             .findTypedef(QName.create("foo", typedefName)).isPresent());
51     }
52 }