Bug 5085: Clean-up test and retest JUnit tests
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / yin / YinFileListStmtTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.stmt.yin;
9
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;
17 import java.util.Set;
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.TestUtils;
31
32 public class YinFileListStmtTest {
33
34     private Set<Module> modules;
35
36     @Before
37     public void init() throws URISyntaxException, ReactorException {
38         modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
39         assertEquals(9, modules.size());
40     }
41
42     @Test
43     public void testListAndLeaves() throws URISyntaxException {
44         Module testModule = TestUtils.findModule(modules, "config");
45         assertNotNull(testModule);
46
47         ContainerSchemaNode container = (ContainerSchemaNode) testModule.getDataChildByName("modules");
48         assertNotNull(container);
49
50         ListSchemaNode list = (ListSchemaNode) container.getDataChildByName("module");
51         assertNotNull(list);
52         List<QName> keys = list.getKeyDefinition();
53         assertEquals(1, keys.size());
54         assertEquals("name", keys.get(0).getLocalName());
55
56         Collection<DataSchemaNode> children = list.getChildNodes();
57         assertEquals(4, children.size());
58
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());
65
66         leaf = (LeafSchemaNode) childrenIterator.next();
67         assertEquals("type", leaf.getQName().getLocalName());
68
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());
73     }
74
75 }