Migrate users of Optional.get()
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / yin / YinFileListStmtTest.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.assertNotNull;
13 import static org.junit.jupiter.api.Assertions.assertTrue;
14
15 import java.util.Optional;
16 import org.junit.jupiter.api.Test;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
21 import org.opendaylight.yangtools.yang.model.ri.type.BaseTypes;
22
23 class YinFileListStmtTest extends AbstractYinModulesTest {
24     @Test
25     void testListAndLeaves() {
26         final var testModule = context.findModules("config").iterator().next();
27         assertNotNull(testModule);
28
29         final var list = assertInstanceOf(ListSchemaNode.class,
30             testModule.findDataChildByName(
31                 QName.create(testModule.getQNameModule(), "modules"),
32                 QName.create(testModule.getQNameModule(), "module"))
33             .orElseThrow());
34         final var keys = list.getKeyDefinition();
35         assertEquals(1, keys.size());
36         assertEquals("name", keys.get(0).getLocalName());
37
38         final var children = list.getChildNodes();
39         assertEquals(4, children.size());
40
41         final var childrenIterator = children.iterator();
42         var leaf = assertInstanceOf(LeafSchemaNode.class, childrenIterator.next());
43         assertEquals("name", leaf.getQName().getLocalName());
44         assertEquals(Optional.of("Unique module instance name"), leaf.getDescription());
45         assertEquals(BaseTypes.stringType(), leaf.getType());
46         assertTrue(leaf.isMandatory());
47
48         leaf = assertInstanceOf(LeafSchemaNode.class, childrenIterator.next());
49         assertEquals("type", leaf.getQName().getLocalName());
50
51         final var leafType = assertInstanceOf(IdentityrefTypeDefinition.class, leaf.getType());
52         assertEquals("module-type", leafType.getIdentities().iterator().next().getQName().getLocalName());
53         assertTrue(leaf.isMandatory());
54     }
55 }