Adjust test suite parser update to conform with API changes
[yangtools.git] / yang / 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.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13
14 import java.util.Set;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.Module;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
22
23 public class Bug6240Test {
24     private static final String NS = "bar";
25     private static final String REV = "2016-07-19";
26
27     @Test
28     public void testModels() throws Exception {
29         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6240/correct");
30         assertNotNull(context);
31
32         final Set<Module> modules = context.getModules();
33         assertEquals(2, modules.size());
34
35         Module bar = null;
36         for (final Module module : modules) {
37             if ("bar".equals(module.getName())) {
38                 bar = module;
39                 break;
40             }
41         }
42
43         assertNotNull(bar);
44         assertTrue(bar.getDataChildByName(QName.create(NS, REV, "foo-grp-con")) instanceof ContainerSchemaNode);
45         assertTrue(bar.getDataChildByName(QName.create(NS, REV, "sub-foo-grp-con")) instanceof ContainerSchemaNode);
46
47         assertEquals(1, bar.getSubmodules().size());
48
49         final DataSchemaNode dataChildByName = bar.getDataChildByName(QName.create(NS, REV, "sub-bar-con"));
50         assertTrue(dataChildByName instanceof ContainerSchemaNode);
51         final ContainerSchemaNode subBarCon = (ContainerSchemaNode) dataChildByName;
52
53         assertTrue(subBarCon.getDataChildByName(QName.create(NS, REV, "foo-grp-con")) instanceof ContainerSchemaNode);
54         assertTrue(subBarCon.getDataChildByName(QName.create(NS, REV, "sub-foo-grp-con"))
55             instanceof ContainerSchemaNode);
56     }
57
58     @Test
59     public void testInvalidModels() throws Exception {
60         try {
61             StmtTestUtils.parseYangSources("/bugs/bug6240/incorrect");
62         } catch (final SomeModifiersUnresolvedException e) {
63             assertTrue(e.getCause().getCause().getMessage().startsWith(
64                 "Grouping '(bar?revision=2016-07-19)foo-imp-grp' was not resolved."));
65         }
66     }
67 }