Bug 3670 (part 3/5): Use of new statement parser in yang-maven-plugin
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / retest / AugmentToExtensionTest.java
1 /**
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  */
4 package org.opendaylight.yangtools.yang.stmt.retest;
5
6 import static org.junit.Assert.assertTrue;
7
8 import org.opendaylight.yangtools.yang.stmt.test.StmtTestUtils;
9
10 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
11 import java.net.URISyntaxException;
12 import java.util.Set;
13 import org.junit.Test;
14 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
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.UsesNode;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
19 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
20
21 public class AugmentToExtensionTest {
22     private Set<Module> modules;
23
24     @Test(expected = SomeModifiersUnresolvedException.class)
25     public void testIncorrectPath() throws URISyntaxException, SourceException, ReactorException {
26         modules = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/incorrect-path").toURI());
27
28     }
29
30     @Test
31     public void testCorrectPathIntoUnsupportedTarget() throws URISyntaxException, SourceException, ReactorException {
32
33         try {
34         modules = TestUtils.loadModules(getClass().getResource(
35                 "/augment-to-extension-test/correct-path-into-unsupported-target").toURI());
36         } catch (Exception e) {
37             StmtTestUtils.log(e, "    ");
38             throw e;
39         }
40
41         Module devicesModule = TestUtils.findModule(modules, "augment-module");
42
43         ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName("my-container");
44         Set<UsesNode> uses = devicesContainer.getUses();
45
46         for (UsesNode usesNode : uses) {
47             assertTrue(usesNode.getAugmentations().isEmpty());
48         }
49     }
50
51     @Test
52     public void testCorrectAugment() throws URISyntaxException, SourceException, ReactorException {
53         modules = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/correct-augment").toURI());
54
55         Module devicesModule = TestUtils.findModule(modules, "augment-module");
56
57         ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModule.getDataChildByName("my-container");
58         Set<UsesNode> uses = devicesContainer.getUses();
59
60         boolean augmentationIsInContainer = false;
61         for (UsesNode usesNode : uses) {
62             Set<AugmentationSchema> augmentations = usesNode.getAugmentations();
63             for (AugmentationSchema augmentationSchema : augmentations) {
64                 augmentationIsInContainer = true;
65             }
66         }
67
68         assertTrue(augmentationIsInContainer);
69     }
70
71 }