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.assertNotNull;
11 import static org.junit.Assert.assertNull;
12 import static org.junit.Assert.assertTrue;
14 import java.io.FileNotFoundException;
15 import java.net.URISyntaxException;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
23 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
24 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
25 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
27 public class Bug6669Test {
28 private static final String REV = "2016-09-08";
29 private static final String FOO_NS = "foo";
30 private static final String BAR_NS = "bar";
31 private static final QName ROOT = QName.create(FOO_NS, REV, "root");
32 private static final QName BAR = QName.create(BAR_NS, REV, "bar");
33 private static final QName BAR_1 = QName.create(BAR_NS, REV, "bar1");
34 private static final QName BAR_2 = QName.create(BAR_NS, REV, "bar2");
35 private static final QName M = QName.create(BAR_NS, REV, "m");
36 private static final QName L = QName.create(BAR_NS, REV, "l");
39 public void testInvalidAugment() throws SourceException, ReactorException, FileNotFoundException,
41 final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/invalid/test1");
42 assertNotNull(context);
44 final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
45 SchemaPath.create(true, ROOT, BAR, BAR_1, M));
46 assertNull(findDataSchemaNode);
50 public void testInvalidAugment2() throws SourceException, ReactorException, FileNotFoundException,
52 final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/invalid/test2");
53 assertNotNull(context);
55 final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
56 SchemaPath.create(true, ROOT, BAR, BAR_1, BAR_2, M));
57 assertNull(findDataSchemaNode);
61 public void testInvalidAugment3() throws SourceException, ReactorException, FileNotFoundException,
63 final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/invalid/test3");
64 assertNotNull(context);
66 final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
67 SchemaPath.create(true, ROOT, BAR, BAR_1, BAR_2, L));
68 assertNull(findDataSchemaNode);
72 public void testValidAugment() throws SourceException, ReactorException, FileNotFoundException, URISyntaxException {
73 final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/valid/test1");
74 assertNotNull(context);
76 final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
77 SchemaPath.create(true, ROOT, BAR, BAR_1, M));
78 assertTrue(findDataSchemaNode instanceof LeafSchemaNode);
82 public void testValidAugment2() throws SourceException, ReactorException, FileNotFoundException, URISyntaxException {
83 final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/valid/test2");
84 assertNotNull(context);
86 final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
87 SchemaPath.create(true, ROOT, BAR, BAR_1, BAR_2, M));
88 assertTrue(findDataSchemaNode instanceof LeafSchemaNode);
92 public void testValidAugment3() throws SourceException, ReactorException, FileNotFoundException, URISyntaxException {
93 final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/valid/test3");
94 assertNotNull(context);
96 final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
97 SchemaPath.create(true, ROOT, BAR, BAR_1, BAR_2, L));
98 assertTrue(findDataSchemaNode instanceof ListSchemaNode);