Bug 4540: Yang parser exceptions should follow consistent path
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / retest / AugmentToExtensionTest.java
1 /**
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  */
4 package org.opendaylight.yangtools.yang.stmt.retest;
5
6 import static org.junit.Assert.assertTrue;
7
8 import org.opendaylight.yangtools.yang.stmt.test.StmtTestUtils;
9
10 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
11 import java.net.URISyntaxException;
12 import java.util.Set;
13
14 import org.junit.Ignore;
15 import org.junit.Test;
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.source.SourceException;
22
23 public class AugmentToExtensionTest {
24     private Set<Module> modules;
25
26     @Test(expected = SomeModifiersUnresolvedException.class)
27     public void testIncorrectPath() throws URISyntaxException, SourceException, ReactorException {
28         modules = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/incorrect-path").toURI());
29
30     }
31
32     /* 
33      * FIXME: Figure way to determine use case of tail-f:input without hacks
34      * 
35      */
36     @Test
37     @Ignore
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 (Exception e) {
44             StmtTestUtils.log(e, "    ");
45             throw e;
46         }
47
48         Module devicesModule = TestUtils.findModule(modules, "augment-module");
49
50         ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName("my-container");
51         Set<UsesNode> uses = devicesContainer.getUses();
52
53         for (UsesNode usesNode : uses) {
54             assertTrue(usesNode.getAugmentations().isEmpty());
55         }
56     }
57
58
59     @Test
60     public void testCorrectAugment() throws URISyntaxException, SourceException, ReactorException {
61         modules = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/correct-augment").toURI());
62
63         Module devicesModule = TestUtils.findModule(modules, "augment-module");
64
65         ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName("my-container");
66         Set<UsesNode> uses = devicesContainer.getUses();
67
68         boolean augmentationIsInContainer = false;
69         for (UsesNode usesNode : uses) {
70             Set<AugmentationSchema> augmentations = usesNode.getAugmentations();
71             for (AugmentationSchema augmentationSchema : augmentations) {
72                 augmentationIsInContainer = true;
73             }
74         }
75
76         assertTrue(augmentationIsInContainer);
77     }
78
79 }