Bug 6329: Parser fails when target node of uses-augment is an unknown node
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / AugmentToExtensionTest.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.assertTrue;
11
12 import java.net.URISyntaxException;
13 import java.util.Set;
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
17 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.Module;
19 import org.opendaylight.yangtools.yang.model.api.UsesNode;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
22 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
23
24 public class AugmentToExtensionTest {
25     private Set<Module> modules;
26
27     @Test(expected = SomeModifiersUnresolvedException.class)
28     public void testIncorrectPath() throws URISyntaxException, SourceException, ReactorException {
29         modules = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/incorrect-path").toURI());
30
31     }
32
33     /*
34      * FIXME: Figure way to determine use case of tail-f:input without hacks
35      *
36      */
37     @Test
38     public void testCorrectPathIntoUnsupportedTarget() throws URISyntaxException, SourceException, ReactorException {
39
40         try {
41         modules = TestUtils.loadModules(getClass().getResource(
42                 "/augment-to-extension-test/correct-path-into-unsupported-target").toURI());
43         } catch (final Exception e) {
44             StmtTestUtils.log(e, "    ");
45             throw e;
46         }
47
48         final Module devicesModule = TestUtils.findModule(modules, "augment-module");
49
50         final ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName(QName
51                 .create(devicesModule.getQNameModule(), "my-container"));
52         final Set<UsesNode> uses = devicesContainer.getUses();
53
54         for (final UsesNode usesNode : uses) {
55             assertTrue(usesNode.getAugmentations().isEmpty());
56         }
57     }
58
59
60     @Test
61     public void testCorrectAugment() throws URISyntaxException, SourceException, ReactorException {
62         modules = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/correct-augment").toURI());
63
64         final Module devicesModule = TestUtils.findModule(modules, "augment-module");
65
66         final ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName(QName
67                 .create(devicesModule.getQNameModule(), "my-container"));
68         final Set<UsesNode> uses = devicesContainer.getUses();
69
70         boolean augmentationIsInContainer = false;
71         for (final UsesNode usesNode : uses) {
72             final Set<AugmentationSchema> augmentations = usesNode.getAugmentations();
73             for (final AugmentationSchema augmentationSchema : augmentations) {
74                 augmentationIsInContainer = true;
75             }
76         }
77
78         assertTrue(augmentationIsInContainer);
79     }
80
81 }