1fff202cf6206207b797fe08a9a7af82cd22d873
[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.net.URISyntaxException;
15 import java.util.Collection;
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.DataSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
23 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
24 import org.opendaylight.yangtools.yang.model.api.Module;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
26 import org.opendaylight.yangtools.yang.stmt.TestUtils;
27
28 public class YinFileGroupingStmtTest {
29
30     private Set<Module> modules;
31
32     @Before
33     public void init() throws URISyntaxException, ReactorException {
34         modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
35         assertEquals(9, modules.size());
36     }
37
38     @Test
39     public void testGrouping() throws URISyntaxException {
40         final Module testModule = TestUtils.findModule(modules, "config");
41         assertNotNull(testModule);
42
43         final Set<GroupingDefinition> groupings = testModule.getGroupings();
44         assertEquals(1, groupings.size());
45
46         final Iterator<GroupingDefinition> groupingsIterator = groupings.iterator();
47         final GroupingDefinition grouping = groupingsIterator.next();
48         assertEquals("service-ref", grouping.getQName().getLocalName());
49         assertEquals("Type of references to a particular service instance. This type\n" +
50                 "can be used when defining module configuration to refer to a\n" +
51                 "particular service instance. Containers using this grouping\n" +
52                 "should not define anything else. The run-time implementation\n" +
53                 "is expected to inject a reference to the service as the value\n" +
54                 "of the container.", grouping.getDescription());
55
56         final Collection<DataSchemaNode> children = grouping.getChildNodes();
57         assertEquals(2, children.size());
58
59         final LeafSchemaNode leaf1 = (LeafSchemaNode) grouping.getDataChildByName(QName.create(
60                 testModule.getQNameModule(), "type"));
61         assertNotNull(leaf1);
62         assertTrue(leaf1.getConstraints().isMandatory());
63
64         final LeafSchemaNode leaf2 = (LeafSchemaNode) grouping.getDataChildByName(QName.create(
65                 testModule.getQNameModule(), "name"));
66         assertNotNull(leaf2);
67         assertTrue(leaf2.getConstraints().isMandatory());
68     }
69 }