Remove deprecated Yin/YangStatementSourceImpl
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / yin / YinFileGroupingStmtTest.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.Collection;
17 import java.util.Iterator;
18 import java.util.Set;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.opendaylight.yangtools.yang.common.QName;
22 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
24 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
25 import org.opendaylight.yangtools.yang.model.api.Module;
26 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
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 YinFileGroupingStmtTest {
32
33     private SchemaContext context;
34
35     @Before
36     public void init() throws ReactorException, SAXException, IOException, URISyntaxException {
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 testGrouping() throws URISyntaxException {
43         final Module testModule = TestUtils.findModule(context, "config").get();
44         assertNotNull(testModule);
45
46         final Set<GroupingDefinition> groupings = testModule.getGroupings();
47         assertEquals(1, groupings.size());
48
49         final Iterator<GroupingDefinition> groupingsIterator = groupings.iterator();
50         final GroupingDefinition grouping = groupingsIterator.next();
51         assertEquals("service-ref", grouping.getQName().getLocalName());
52         assertEquals("Type of references to a particular service instance. This type\n" +
53                 "can be used when defining module configuration to refer to a\n" +
54                 "particular service instance. Containers using this grouping\n" +
55                 "should not define anything else. The run-time implementation\n" +
56                 "is expected to inject a reference to the service as the value\n" +
57                 "of the container.", grouping.getDescription());
58
59         final Collection<DataSchemaNode> children = grouping.getChildNodes();
60         assertEquals(2, children.size());
61
62         final LeafSchemaNode leaf1 = (LeafSchemaNode) grouping.getDataChildByName(QName.create(
63                 testModule.getQNameModule(), "type"));
64         assertNotNull(leaf1);
65         assertTrue(leaf1.getConstraints().isMandatory());
66
67         final LeafSchemaNode leaf2 = (LeafSchemaNode) grouping.getDataChildByName(QName.create(
68                 testModule.getQNameModule(), "name"));
69         assertNotNull(leaf2);
70         assertTrue(leaf2.getConstraints().isMandatory());
71     }
72 }