YANGTOOLS-706: Split out yang-parser-rfc7950
[yangtools.git] / yang / yang-parser-rfc7950 / 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.AugmentationSchemaNode;
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     @Test
34     public void testCorrectPathIntoUnsupportedTarget() throws Exception {
35
36         context = TestUtils.loadModules(getClass().getResource(
37                 "/augment-to-extension-test/correct-path-into-unsupported-target").toURI());
38
39         final Module devicesModule = TestUtils.findModule(context, "augment-module").get();
40         final ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName(
41             QName.create(devicesModule.getQNameModule(), "my-container"));
42         final Set<UsesNode> uses = devicesContainer.getUses();
43
44         for (final UsesNode usesNode : uses) {
45             assertTrue(usesNode.getAugmentations().isEmpty());
46         }
47     }
48
49
50     @Test
51     public void testCorrectAugment() throws Exception {
52         context = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/correct-augment").toURI());
53
54         final Module devicesModule = TestUtils.findModule(context, "augment-module").get();
55
56         final ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName(QName
57                 .create(devicesModule.getQNameModule(), "my-container"));
58         final Set<UsesNode> uses = devicesContainer.getUses();
59
60         boolean augmentationIsInContainer = false;
61         for (final UsesNode usesNode : uses) {
62             final Set<AugmentationSchemaNode> augmentations = usesNode.getAugmentations();
63             for (final AugmentationSchemaNode augmentationSchema : augmentations) {
64                 augmentationIsInContainer = true;
65             }
66         }
67
68         assertTrue(augmentationIsInContainer);
69     }
70
71 }