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.hamcrest.MatcherAssert.assertThat;
11 import static org.hamcrest.Matchers.isA;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertTrue;
16 import java.util.Collection;
17 import java.util.Iterator;
18 import java.util.List;
19 import java.util.Optional;
20 import org.junit.Test;
21 import org.opendaylight.yangtools.yang.common.QName;
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.ri.type.BaseTypes;
30 public class YinFileListStmtTest extends AbstractYinModulesTest {
32 public void testListAndLeaves() {
33 final Module testModule = context.findModules("config").iterator().next();
34 assertNotNull(testModule);
36 final ListSchemaNode list = (ListSchemaNode) testModule.findDataChildByName(QName.create(
37 testModule.getQNameModule(), "modules"), QName.create(testModule.getQNameModule(), "module")).get();
38 final List<QName> keys = list.getKeyDefinition();
39 assertEquals(1, keys.size());
40 assertEquals("name", keys.get(0).getLocalName());
42 final Collection<? extends DataSchemaNode> children = list.getChildNodes();
43 assertEquals(4, children.size());
45 final Iterator<? extends DataSchemaNode> childrenIterator = children.iterator();
46 LeafSchemaNode leaf = (LeafSchemaNode) childrenIterator.next();
47 assertEquals("name", leaf.getQName().getLocalName());
48 assertEquals(Optional.of("Unique module instance name"), leaf.getDescription());
49 assertEquals(BaseTypes.stringType(), leaf.getType());
50 assertTrue(leaf.isMandatory());
52 leaf = (LeafSchemaNode) childrenIterator.next();
53 assertEquals("type", leaf.getQName().getLocalName());
55 final TypeDefinition<?> leafType = leaf.getType();
56 assertThat(leafType, isA(IdentityrefTypeDefinition.class));
57 assertEquals("module-type", ((IdentityrefTypeDefinition)leafType).getIdentities().iterator().next().getQName()
59 assertTrue(leaf.isMandatory());