f44361f384a8770ac9d1cc52e62b0baf183e2639
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug6240Test.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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.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;
16
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;
24
25 public class Bug6240Test extends AbstractYangTest {
26     private static final String NS = "bar";
27     private static final String REV = "2016-07-19";
28
29     @Test
30     public void testModels() throws Exception {
31         final var context = assertEffectiveModelDir("/bugs/bug6240/correct");
32
33         final var modules = context.getModules();
34         assertEquals(2, modules.size());
35
36         Module bar = null;
37         for (final Module module : modules) {
38             if ("bar".equals(module.getName())) {
39                 bar = module;
40                 break;
41             }
42         }
43
44         assertNotNull(bar);
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));
48
49         assertEquals(1, bar.getSubmodules().size());
50
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;
54
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));
59     }
60
61     @Test
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."));
68     }
69 }