Adjust test suite parser update to conform with API changes
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / yin / YinFileUsesStmtTest.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.ContainerSchemaNode;
24 import org.opendaylight.yangtools.yang.model.api.Module;
25 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
26 import org.opendaylight.yangtools.yang.model.api.UsesNode;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
28 import org.opendaylight.yangtools.yang.stmt.TestUtils;
29 import org.xml.sax.SAXException;
30
31 public class YinFileUsesStmtTest {
32
33     private SchemaContext context;
34
35     @Before
36     public void init() throws URISyntaxException, ReactorException, SAXException, IOException {
37         context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
38         assertEquals(9, context.getModules().size());
39     }
40
41     @Test
42     public void testUses() {
43         final Module testModule = TestUtils.findModule(context, "main-impl").get();
44         assertNotNull(testModule);
45
46         final Set<AugmentationSchemaNode> augmentations = testModule.getAugmentations();
47         assertEquals(1, augmentations.size());
48
49         final Iterator<AugmentationSchemaNode> augmentIterator = augmentations.iterator();
50         final AugmentationSchemaNode augment = augmentIterator.next();
51
52         final ChoiceCaseNode caseNode = (ChoiceCaseNode) augment.getDataChildByName(
53             QName.create(testModule.getQNameModule(), "main-impl"));
54         assertNotNull(caseNode);
55
56         final ContainerSchemaNode container = (ContainerSchemaNode) caseNode.getDataChildByName(QName.create(
57                 testModule.getQNameModule(), "notification-service"));
58         assertNotNull(container);
59
60         assertEquals(1, container.getUses().size());
61         final UsesNode usesNode = container.getUses().iterator().next();
62         assertNotNull(usesNode);
63         assertTrue(usesNode.getGroupingPath().toString()
64                 .contains("[(urn:opendaylight:params:xml:ns:yang:controller:config?revision=2013-04-05)service-ref]"));
65         assertEquals(1, usesNode.getRefines().size());
66     }
67 }