82dfcc24eeb0ec88bcb03e1a9693195326e771b4
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / Bug4459Test.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;
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.io.IOException;
15 import java.net.URISyntaxException;
16 import java.util.List;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
20 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
23 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
24 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
26 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
27
28 public class Bug4459Test {
29
30     @Test
31     public void test() throws IOException, URISyntaxException, SourceException, ReactorException {
32         SchemaContext schema = StmtTestUtils.parseYangSources("/bugs/bug4459");
33         assertNotNull(schema);
34
35         DataSchemaNode dataChildByName = schema.getDataChildByName("my-leaf");
36         assertTrue(dataChildByName instanceof LeafSchemaNode);
37         LeafSchemaNode myLeaf = (LeafSchemaNode) dataChildByName;
38
39         TypeDefinition<?> type = myLeaf.getType();
40         assertTrue(type instanceof EnumTypeDefinition);
41         EnumTypeDefinition myEnum = (EnumTypeDefinition) type;
42
43         QName expectedEnumQName = QName.create("foo", "1970-01-01", "QuestionMark-Ampersand-LeftParenthesis-RightParenthesis-QuestionMark-QuestionMark-Ampersand");
44         List<EnumPair> values = myEnum.getValues();
45         for (EnumPair enumPair : values) {
46             if (enumPair.getName().equals("?-&-(-)-?-?-&")) {
47                 assertEquals(expectedEnumQName, enumPair.getQName());
48             }
49         }
50     }
51 }