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.Assert.assertTrue;
12 import org.junit.Test;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.common.QNameModule;
15 import org.opendaylight.yangtools.yang.common.XMLNamespace;
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.InputEffectiveStatement;
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.OutputEffectiveStatement;
24 import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
25 import org.opendaylight.yangtools.yang.model.api.stmt.TypedefNamespace;
27 public class YT1262Test {
29 public void testTypedefNamespaces() throws Exception {
30 final var modelContext = StmtTestUtils.parseYangSources("/bugs/YT1262");
31 final var module = modelContext.getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
32 assertTypedef(module, "fdef");
33 assertTypedef(module, "sdef");
34 assertTypedef(module.findFirstEffectiveSubstatement(GroupingEffectiveStatement.class).orElseThrow(), "gdef");
35 assertTypedef(module.findFirstEffectiveSubstatement(ListEffectiveStatement.class).orElseThrow(), "ldef");
36 assertTypedef(module.findFirstEffectiveSubstatement(NotificationEffectiveStatement.class).orElseThrow(),
38 assertTypedef(module.findFirstEffectiveSubstatement(RpcEffectiveStatement.class).orElseThrow(), "rdef");
40 final var container = module.findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow();
41 assertTypedef(container, "cdef");
43 final var action = container.findFirstEffectiveSubstatement(ActionEffectiveStatement.class).orElseThrow();
44 assertTypedef(action, "adef");
45 assertTypedef(action.findFirstEffectiveSubstatement(InputEffectiveStatement.class).orElseThrow(), "idef");
46 assertTypedef(action.findFirstEffectiveSubstatement(OutputEffectiveStatement.class).orElseThrow(), "odef");
49 private static void assertTypedef(final EffectiveStatement<?, ?> parent, final String typedefName) {
50 assertTrue(parent.get(TypedefNamespace.class, QName.create("foo", typedefName)).isPresent());