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