2 * Copyright (c) 2016 Cisco Systems, Inc. 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.hamcrest.CoreMatchers.instanceOf;
11 import static org.hamcrest.CoreMatchers.startsWith;
12 import static org.hamcrest.MatcherAssert.assertThat;
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertNotNull;
15 import static org.junit.Assert.assertThrows;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
23 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
25 public class Bug6240Test extends AbstractYangTest {
26 private static final String NS = "bar";
27 private static final String REV = "2016-07-19";
30 public void testModels() throws Exception {
31 final var context = assertEffectiveModelDir("/bugs/bug6240/correct");
33 final var modules = context.getModules();
34 assertEquals(2, modules.size());
37 for (final Module module : modules) {
38 if ("bar".equals(module.getName())) {
45 assertThat(bar.getDataChildByName(QName.create(NS, REV, "foo-grp-con")), instanceOf(ContainerSchemaNode.class));
46 assertThat(bar.getDataChildByName(QName.create(NS, REV, "sub-foo-grp-con")),
47 instanceOf(ContainerSchemaNode.class));
49 assertEquals(1, bar.getSubmodules().size());
51 final DataSchemaNode dataChildByName = bar.getDataChildByName(QName.create(NS, REV, "sub-bar-con"));
52 assertThat(dataChildByName, instanceOf(ContainerSchemaNode.class));
53 final ContainerSchemaNode subBarCon = (ContainerSchemaNode) dataChildByName;
55 assertThat(subBarCon.getDataChildByName(QName.create(NS, REV, "foo-grp-con")),
56 instanceOf(ContainerSchemaNode.class));
57 assertThat(subBarCon.getDataChildByName(QName.create(NS, REV, "sub-foo-grp-con")),
58 instanceOf(ContainerSchemaNode.class));
62 public void testInvalidModels() {
63 final var ex = assertThrows(SomeModifiersUnresolvedException.class,
64 () -> StmtTestUtils.parseYangSources("/bugs/bug6240/incorrect"));
65 final var cause = ex.getCause();
66 assertThat(cause, instanceOf(SourceException.class));
67 assertThat(cause.getMessage(), startsWith("Grouping '(bar?revision=2016-07-19)foo-imp-grp' was not resolved."));