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
9 package org.opendaylight.yangtools.yang.stmt;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertFalse;
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertTrue;
15 import java.util.List;
16 import org.junit.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;
21 import org.opendaylight.yangtools.yang.model.api.Module;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
23 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
24 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
25 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
26 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
28 public class ListTest {
30 private static final YangStatementSourceImpl LIST_MODULE = new YangStatementSourceImpl("/list-test/list-test.yang",
34 public void listAndLeavesTest() throws ReactorException {
35 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
36 StmtTestUtils.addSources(reactor, LIST_MODULE);
38 EffectiveSchemaContext result = reactor.buildEffective();
39 assertNotNull(result);
41 Module testModule = result.findModuleByName("list-test", null);
42 assertNotNull(testModule);
44 ListSchemaNode list = (ListSchemaNode) testModule.getDataChildByName("simple-list");
47 assertTrue(list.isUserOrdered());
48 assertTrue(list.isConfiguration());
49 List<QName> keys = list.getKeyDefinition();
50 assertEquals(2, keys.size());
52 assertEquals("key1", keys.get(0).getLocalName());
53 assertEquals("key2", keys.get(1).getLocalName());
55 assertEquals(1, list.getConstraints().getMinElements().intValue());
56 assertEquals(10, list.getConstraints().getMaxElements().intValue());
58 assertEquals(5, list.getChildNodes().size());
60 LeafSchemaNode leaf = (LeafSchemaNode) list.getDataChildByName("key1");
62 assertTrue(leaf.getConstraints().isMandatory());
63 assertEquals("int32", leaf.getType().getQName().getLocalName());
65 leaf = (LeafSchemaNode) list.getDataChildByName("key2");
67 assertTrue(leaf.getConstraints().isMandatory());
68 assertEquals("int16", leaf.getType().getQName().getLocalName());
70 leaf = (LeafSchemaNode) list.getDataChildByName("old-leaf");
72 assertFalse(leaf.getConstraints().isMandatory());
73 assertEquals("string", leaf.getType().getQName().getLocalName());
75 leaf = (LeafSchemaNode) list.getDataChildByName("young-leaf");
77 assertFalse(leaf.getConstraints().isMandatory());
78 assertEquals("young-leaf", leaf.getType().getQName().getLocalName());
79 assertEquals("default-value", leaf.getDefault());
81 LeafListSchemaNode leafList = (LeafListSchemaNode) list.getDataChildByName("list-of-leaves");
82 assertNotNull(leafList);
83 assertTrue(leafList.getConstraints().isMandatory());
84 assertTrue(leafList.isUserOrdered());
85 assertEquals(2, leafList.getConstraints().getMinElements().intValue());
86 assertEquals(20, leafList.getConstraints().getMaxElements().intValue());
87 assertEquals("string", leafList.getType().getQName().getLocalName());