75303aa1effdc1b612a6431f5be893d4e3607a49
[yangtools.git] / parser / yang-parser-rfc7950 / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug2872Test.java
1 /*
2  * Copyright (c) 2016 Brocade Communications 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;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13
14 import java.util.ArrayList;
15 import java.util.List;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.common.QNameModule;
19 import org.opendaylight.yangtools.yang.common.Revision;
20 import org.opendaylight.yangtools.yang.common.XMLNamespace;
21 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
24 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
25 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
26
27 public class Bug2872Test {
28
29     @Test
30     public void test() throws Exception {
31         final SchemaContext schema = StmtTestUtils.parseYangSources("/bugs/bug2872");
32         assertNotNull(schema);
33
34         final QNameModule bug2872module = QNameModule.create(XMLNamespace.of("bug2872"), Revision.of("2016-06-08"));
35         final QName foo = QName.create(bug2872module, "bar");
36
37         final DataSchemaNode dataSchemaNode = schema.getDataChildByName(foo);
38         assertTrue(dataSchemaNode instanceof LeafSchemaNode);
39         final LeafSchemaNode myLeaf = (LeafSchemaNode) dataSchemaNode;
40
41         final TypeDefinition<?> type = myLeaf.getType();
42         assertTrue(type instanceof EnumTypeDefinition);
43         final EnumTypeDefinition myEnum = (EnumTypeDefinition) type;
44
45         final List<EnumTypeDefinition.EnumPair> values = myEnum.getValues();
46         assertEquals(2, values.size());
47
48         final List<String> valueNames = new ArrayList<>();
49         for (EnumTypeDefinition.EnumPair pair : values) {
50             valueNames.add(pair.getName());
51         }
52         assertTrue(valueNames.contains("value-one"));
53         assertTrue(valueNames.contains("value-two"));
54     }
55 }