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.io.IOException;
15 import java.net.URISyntaxException;
16 import java.util.Collection;
17 import java.util.Iterator;
18 import java.util.List;
19 import java.util.Optional;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
24 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
25 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
26 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
27 import org.opendaylight.yangtools.yang.model.api.Module;
28 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
29 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
30 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
31 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
32 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
33 import org.opendaylight.yangtools.yang.stmt.TestUtils;
34 import org.xml.sax.SAXException;
36 public class YinFileListStmtTest {
38 private SchemaContext context;
41 public void init() throws URISyntaxException, ReactorException, SAXException, IOException {
42 context = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
43 assertEquals(9, context.getModules().size());
47 public void testListAndLeaves() {
48 final Module testModule = TestUtils.findModule(context, "config").get();
49 assertNotNull(testModule);
51 final ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName(QName.create(
52 testModule.getQNameModule(), "modules"));
53 assertNotNull(container);
55 final ListSchemaNode list = (ListSchemaNode) container.getDataChildByName(
56 QName.create(testModule.getQNameModule(), "module"));
58 final List<QName> keys = list.getKeyDefinition();
59 assertEquals(1, keys.size());
60 assertEquals("name", keys.get(0).getLocalName());
62 final Collection<DataSchemaNode> children = list.getChildNodes();
63 assertEquals(4, children.size());
65 final Iterator<DataSchemaNode> childrenIterator = children.iterator();
66 LeafSchemaNode leaf = (LeafSchemaNode) childrenIterator.next();
67 assertEquals("name", leaf.getQName().getLocalName());
68 assertEquals(Optional.of("Unique module instance name"), leaf.getDescription());
69 assertEquals(BaseTypes.stringType(), leaf.getType());
70 assertTrue(leaf.isMandatory());
72 leaf = (LeafSchemaNode) childrenIterator.next();
73 assertEquals("type", leaf.getQName().getLocalName());
75 final TypeDefinition<?> leafType = leaf.getType();
76 assertTrue(leafType instanceof IdentityrefTypeDefinition);
77 assertEquals("module-type", ((IdentityrefTypeDefinition)leafType).getIdentities().iterator().next().getQName()
79 assertTrue(leaf.isMandatory());