2 * Copyright (c) 2021 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.stmt;
10 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
11 import static org.junit.jupiter.api.Assertions.assertTrue;
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;
25 class YT1262Test extends AbstractYangTest {
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(),
36 assertTypedef(module.findFirstEffectiveSubstatement(RpcEffectiveStatement.class).orElseThrow(), "rdef");
38 final var container = module.findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow();
39 assertTypedef(container, "cdef");
41 final var action = container.findFirstEffectiveSubstatement(ActionEffectiveStatement.class).orElseThrow();
42 assertTypedef(action, "adef");
43 assertTypedef(action.input(), "idef");
44 assertTypedef(action.output(), "odef");
47 private static void assertTypedef(final EffectiveStatement<?, ?> parent, final String typedefName) {
48 assertTrue(assertInstanceOf(TypedefAwareEffectiveStatement.class, parent)
49 .findTypedef(QName.create("foo", typedefName)).isPresent());