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.yin;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
14 import java.net.URISyntaxException;
15 import java.util.Collection;
16 import java.util.Iterator;
17 import java.util.List;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.opendaylight.yangtools.yang.common.QName;
22 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
24 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
25 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
26 import org.opendaylight.yangtools.yang.model.api.Module;
27 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
28 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
29 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
30 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
31 import org.opendaylight.yangtools.yang.stmt.TestUtils;
33 public class YinFileListStmtTest {
35 private Set<Module> modules;
38 public void init() throws URISyntaxException, ReactorException {
39 modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
40 assertEquals(9, modules.size());
44 public void testListAndLeaves() throws URISyntaxException {
45 final Module testModule = TestUtils.findModule(modules, "config");
46 assertNotNull(testModule);
48 final ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(QName.create(
49 testModule.getQNameModule(), "modules"));
50 assertNotNull(container);
52 final ListSchemaNode list = (ListSchemaNode) container.getDataChildByName(QName.create(testModule.getQNameModule(),
55 final List<QName> keys = list.getKeyDefinition();
56 assertEquals(1, keys.size());
57 assertEquals("name", keys.get(0).getLocalName());
59 final Collection<DataSchemaNode> children = list.getChildNodes();
60 assertEquals(4, children.size());
62 final Iterator<DataSchemaNode> childrenIterator = children.iterator();
63 LeafSchemaNode leaf = (LeafSchemaNode) childrenIterator.next();
64 assertEquals("name", leaf.getQName().getLocalName());
65 assertEquals("Unique module instance name", leaf.getDescription());
66 assertEquals(BaseTypes.stringType(), leaf.getType());
67 assertTrue(leaf.getConstraints().isMandatory());
69 leaf = (LeafSchemaNode) childrenIterator.next();
70 assertEquals("type", leaf.getQName().getLocalName());
72 final TypeDefinition<?> leafType = leaf.getType();
73 assertTrue(leafType instanceof IdentityrefTypeDefinition);
74 assertEquals("module-type", ((IdentityrefTypeDefinition)leafType).getIdentity().getQName().getLocalName());
75 assertTrue(leaf.getConstraints().isMandatory());