Bug 6240: Entities of imported module's submodule are not visible
[yangtools.git] / yang / yang-parser-impl / 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.io.FileNotFoundException;
15 import java.net.URISyntaxException;
16 import java.util.Set;
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.model.api.SchemaContext;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
25 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
26
27 public class Bug6240Test {
28     private static final String NS = "bar";
29     private static final String REV = "2016-07-19";
30
31     @Test
32     public void testModels() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException {
33         final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6240/correct");
34         assertNotNull(context);
35
36         final Set<Module> modules = context.getModules();
37         assertEquals(2, modules.size());
38
39         Module bar = null;
40         for (final Module module : modules) {
41             if ("bar".equals(module.getName())) {
42                 bar = module;
43                 break;
44             }
45         }
46
47         assertNotNull(bar);
48         assertTrue(bar.getDataChildByName(QName.create(NS, REV, "foo-grp-con")) instanceof ContainerSchemaNode);
49         assertTrue(bar.getDataChildByName(QName.create(NS, REV, "sub-foo-grp-con")) instanceof ContainerSchemaNode);
50
51         assertEquals(1, bar.getSubmodules().size());
52
53         final DataSchemaNode dataChildByName = bar.getDataChildByName(QName.create(NS, REV, "sub-bar-con"));
54         assertTrue(dataChildByName instanceof ContainerSchemaNode);
55         final ContainerSchemaNode subBarCon = (ContainerSchemaNode) dataChildByName;
56
57         assertTrue(subBarCon.getDataChildByName(QName.create(NS, REV, "foo-grp-con")) instanceof ContainerSchemaNode);
58         assertTrue(subBarCon.getDataChildByName(QName.create(NS, REV, "sub-foo-grp-con")) instanceof ContainerSchemaNode);
59     }
60
61     @Test
62     public void testInvalidModels() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException {
63         try {
64             StmtTestUtils.parseYangSources("/bugs/bug6240/incorrect");
65         } catch (final SomeModifiersUnresolvedException e) {
66             assertTrue(e.getCause().getCause().getMessage()
67                     .startsWith("Grouping '(bar?revision=2016-07-19)foo-imp-grp' was not resolved."));
68         }
69     }
70 }