2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.stmt;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
14 import java.io.FileNotFoundException;
15 import java.net.URISyntaxException;
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;
27 public class Bug6240Test {
28 private static final String NS = "bar";
29 private static final String REV = "2016-07-19";
32 public void testModels() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException {
33 final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6240/correct");
34 assertNotNull(context);
36 final Set<Module> modules = context.getModules();
37 assertEquals(2, modules.size());
40 for (final Module module : modules) {
41 if ("bar".equals(module.getName())) {
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);
51 assertEquals(1, bar.getSubmodules().size());
53 final DataSchemaNode dataChildByName = bar.getDataChildByName(QName.create(NS, REV, "sub-bar-con"));
54 assertTrue(dataChildByName instanceof ContainerSchemaNode);
55 final ContainerSchemaNode subBarCon = (ContainerSchemaNode) dataChildByName;
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);
62 public void testInvalidModels() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException {
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."));