2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.stmt;
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertFalse;
12 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
13 import static org.junit.jupiter.api.Assertions.assertTrue;
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.LeafListSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
22 class ListTest extends AbstractYangTest {
24 void listAndLeavesTest() {
25 final var result = assertEffectiveModel("/list-test/list-test.yang");
26 final var testModule = result.findModules("list-test").iterator().next();
28 final var list = assertInstanceOf(ListSchemaNode.class,
29 testModule.getDataChildByName(QName.create(testModule.getQNameModule(), "simple-list")));
31 assertTrue(list.isUserOrdered());
32 assertEquals(Optional.of(Boolean.TRUE), list.effectiveConfig());
33 final var keys = list.getKeyDefinition();
34 assertEquals(2, keys.size());
36 assertEquals("key1", keys.get(0).getLocalName());
37 assertEquals("key2", keys.get(1).getLocalName());
39 var constraint = list.getElementCountConstraint().orElseThrow();
40 assertEquals((Object) 1, constraint.getMinElements());
41 assertEquals((Object) 10, constraint.getMaxElements());
43 assertEquals(5, list.getChildNodes().size());
45 var leaf = assertInstanceOf(LeafSchemaNode.class,
46 list.getDataChildByName(QName.create(testModule.getQNameModule(), "key1")));
47 assertTrue(leaf.isMandatory());
48 assertEquals("int32", leaf.getType().getQName().getLocalName());
50 leaf = assertInstanceOf(LeafSchemaNode.class,
51 list.getDataChildByName(QName.create(testModule.getQNameModule(), "key2")));
52 assertTrue(leaf.isMandatory());
53 assertEquals("int16", leaf.getType().getQName().getLocalName());
55 leaf = assertInstanceOf(LeafSchemaNode.class,
56 list.getDataChildByName(QName.create(testModule.getQNameModule(), "old-leaf")));
57 assertFalse(leaf.isMandatory());
58 assertEquals("string", leaf.getType().getQName().getLocalName());
60 leaf = assertInstanceOf(LeafSchemaNode.class,
61 list.getDataChildByName(QName.create(testModule.getQNameModule(), "young-leaf")));
62 assertFalse(leaf.isMandatory());
63 assertEquals("young-leaf", leaf.getType().getQName().getLocalName());
64 assertEquals(Optional.of("default-value"), leaf.getType().getDefaultValue());
66 final var leafList = assertInstanceOf(LeafListSchemaNode.class,
67 list.getDataChildByName(QName.create(testModule.getQNameModule(), "list-of-leaves")));
68 assertTrue(leafList.isUserOrdered());
70 constraint = leafList.getElementCountConstraint().orElseThrow();
71 assertEquals(2, constraint.getMinElements().intValue());
72 assertEquals(20, constraint.getMaxElements().intValue());
73 assertEquals("string", leafList.getType().getQName().getLocalName());