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