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