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