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