a1994cd76bcd2c67948dc983eb3b45c4ef2a4901
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / yin / YinFileAugmentStmtTest.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.yin;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13
14 import java.net.URISyntaxException;
15 import java.util.Iterator;
16 import java.util.Set;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
21 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
22 import org.opendaylight.yangtools.yang.model.api.Module;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
24 import org.opendaylight.yangtools.yang.stmt.TestUtils;
25
26 public class YinFileAugmentStmtTest {
27
28     private Set<Module> modules;
29
30     @Before
31     public void init() throws URISyntaxException, ReactorException {
32         modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
33         assertEquals(9, modules.size());
34     }
35
36     @Test
37     public void testAugment() {
38         final Module testModule = TestUtils.findModule(modules, "main-impl");
39         assertNotNull(testModule);
40
41         final Set<AugmentationSchema> augmentations = testModule.getAugmentations();
42         assertEquals(1, augmentations.size());
43
44         final Iterator<AugmentationSchema> augmentIterator = augmentations.iterator();
45         final AugmentationSchema augment = augmentIterator.next();
46         assertNotNull(augment);
47         assertTrue(augment.getTargetPath().toString().contains(
48                 "(urn:opendaylight:params:xml:ns:yang:controller:config?revision=2013-04-05)modules, " +
49                         "(urn:opendaylight:params:xml:ns:yang:controller:config?revision=2013-04-05)module, " +
50                         "(urn:opendaylight:params:xml:ns:yang:controller:config?revision=2013-04-05)configuration"));
51
52         assertEquals(1, augment.getChildNodes().size());
53         final ChoiceCaseNode caseNode = (ChoiceCaseNode) augment.getDataChildByName(QName.create(
54                 testModule.getQNameModule(), "main-impl"));
55         assertNotNull(caseNode);
56     }
57
58 }