Migrate users of Optional.get()
[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.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
12 import static org.junit.jupiter.api.Assertions.assertTrue;
13
14 import java.util.Optional;
15 import org.junit.jupiter.api.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
18
19 class YinFileGroupingStmtTest extends AbstractYinModulesTest {
20     @Test
21     void testGrouping() {
22         final var testModule = context.findModules("config").iterator().next();
23         final var groupings = testModule.getGroupings();
24         assertEquals(1, groupings.size());
25
26         final var groupingsIterator = groupings.iterator();
27         final var grouping = groupingsIterator.next();
28         assertEquals("service-ref", grouping.getQName().getLocalName());
29         assertEquals(Optional.of("""
30             Type of references to a particular service instance. This type
31             can be used when defining module configuration to refer to a
32             particular service instance. Containers using this grouping
33             should not define anything else. The run-time implementation
34             is expected to inject a reference to the service as the value
35             of the container."""), grouping.getDescription());
36
37         final var children = grouping.getChildNodes();
38         assertEquals(2, children.size());
39
40         final var leaf1 = assertInstanceOf(LeafSchemaNode.class,
41             grouping.getDataChildByName(QName.create(testModule.getQNameModule(), "type")));
42         assertTrue(leaf1.isMandatory());
43
44         final var leaf2 = assertInstanceOf(LeafSchemaNode.class,
45             grouping.getDataChildByName(QName.create(testModule.getQNameModule(), "name")));
46         assertTrue(leaf2.isMandatory());
47     }
48 }