Use local variable type inference
[yangtools.git] / parser / yang-parser-rfc7950 / 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.util.Collection;
15 import java.util.Iterator;
16 import java.util.Optional;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
21 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.Module;
23
24 public class YinFileGroupingStmtTest extends AbstractYinModulesTest {
25     @Test
26     public void testGrouping() {
27         final Module testModule = context.findModules("config").iterator().next();
28         assertNotNull(testModule);
29
30         final Collection<? extends GroupingDefinition> groupings = testModule.getGroupings();
31         assertEquals(1, groupings.size());
32
33         final Iterator<? extends GroupingDefinition> groupingsIterator = groupings.iterator();
34         final GroupingDefinition grouping = groupingsIterator.next();
35         assertEquals("service-ref", grouping.getQName().getLocalName());
36         assertEquals(Optional.of("Type of references to a particular service instance. This type\n"
37                 + "can be used when defining module configuration to refer to a\n"
38                 + "particular service instance. Containers using this grouping\n"
39                 + "should not define anything else. The run-time implementation\n"
40                 + "is expected to inject a reference to the service as the value\n"
41                 + "of the container."), grouping.getDescription());
42
43         final Collection<? extends DataSchemaNode> children = grouping.getChildNodes();
44         assertEquals(2, children.size());
45
46         final LeafSchemaNode leaf1 = (LeafSchemaNode) grouping.findDataChildByName(QName.create(
47                 testModule.getQNameModule(), "type")).get();
48         assertTrue(leaf1.isMandatory());
49
50         final LeafSchemaNode leaf2 = (LeafSchemaNode) grouping.findDataChildByName(QName.create(
51                 testModule.getQNameModule(), "name")).get();
52         assertTrue(leaf2.isMandatory());
53     }
54 }