Bug 5085: Clean-up test and retest JUnit tests
[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 org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
13 import java.net.URISyntaxException;
14 import java.util.Set;
15
16 import org.junit.Ignore;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
19 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.Module;
21 import org.opendaylight.yangtools.yang.model.api.UsesNode;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
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 (Exception e) {
46             StmtTestUtils.log(e, "    ");
47             throw e;
48         }
49
50         Module devicesModule = TestUtils.findModule(modules, "augment-module");
51
52         ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName("my-container");
53         Set<UsesNode> uses = devicesContainer.getUses();
54
55         for (UsesNode usesNode : uses) {
56             assertTrue(usesNode.getAugmentations().isEmpty());
57         }
58     }
59
60
61     @Test
62     public void testCorrectAugment() throws URISyntaxException, SourceException, ReactorException {
63         modules = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/correct-augment").toURI());
64
65         Module devicesModule = TestUtils.findModule(modules, "augment-module");
66
67         ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName("my-container");
68         Set<UsesNode> uses = devicesContainer.getUses();
69
70         boolean augmentationIsInContainer = false;
71         for (UsesNode usesNode : uses) {
72             Set<AugmentationSchema> augmentations = usesNode.getAugmentations();
73             for (AugmentationSchema augmentationSchema : augmentations) {
74                 augmentationIsInContainer = true;
75             }
76         }
77
78         assertTrue(augmentationIsInContainer);
79     }
80
81 }