Introduce yangtools.binding.meta
[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.jupiter.api.Assertions.assertEquals;
14 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
15 import static org.junit.jupiter.api.Assertions.assertNotNull;
16
17 import org.junit.jupiter.api.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
23 class Bug6240Test extends AbstractYangTest {
24     private static final String NS = "bar";
25     private static final String REV = "2016-07-19";
26
27     @Test
28     void testModels() throws Exception {
29         final var context = assertEffectiveModelDir("/bugs/bug6240/correct");
30
31         final var modules = context.getModules();
32         assertEquals(2, modules.size());
33
34         Module bar = null;
35         for (final Module module : modules) {
36             if ("bar".equals(module.getName())) {
37                 bar = module;
38                 break;
39             }
40         }
41
42         assertNotNull(bar);
43         assertInstanceOf(ContainerSchemaNode.class, bar.getDataChildByName(QName.create(NS, REV, "foo-grp-con")));
44         assertThat(bar.getDataChildByName(QName.create(NS, REV, "sub-foo-grp-con")),
45             instanceOf(ContainerSchemaNode.class));
46
47         assertEquals(1, bar.getSubmodules().size());
48
49         final DataSchemaNode dataChildByName = bar.getDataChildByName(QName.create(NS, REV, "sub-bar-con"));
50         assertInstanceOf(ContainerSchemaNode.class, dataChildByName);
51         final ContainerSchemaNode subBarCon = (ContainerSchemaNode) dataChildByName;
52
53         assertThat(subBarCon.getDataChildByName(QName.create(NS, REV, "foo-grp-con")),
54             instanceOf(ContainerSchemaNode.class));
55         assertThat(subBarCon.getDataChildByName(QName.create(NS, REV, "sub-foo-grp-con")),
56             instanceOf(ContainerSchemaNode.class));
57     }
58
59     @Test
60     void testInvalidModels() {
61         assertInferenceExceptionDir("/bugs/bug6240/incorrect",
62             startsWith("Grouping '(bar?revision=2016-07-19)foo-imp-grp' was not resolved."));
63     }
64 }