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