2 * Copyright (c) 2016 Brocade Communications 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;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
15 import java.util.ArrayList;
16 import java.util.List;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.common.QNameModule;
20 import org.opendaylight.yangtools.yang.common.Revision;
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;
27 public class Bug2872Test {
30 public void test() throws Exception {
31 final SchemaContext schema = StmtTestUtils.parseYangSources("/bugs/bug2872");
32 assertNotNull(schema);
34 final QNameModule bug2872module = QNameModule.create(URI.create("bug2872"), Revision.of("2016-06-08"));
35 final QName foo = QName.create(bug2872module, "bar");
37 final DataSchemaNode dataSchemaNode = schema.getDataChildByName(foo);
38 assertTrue(dataSchemaNode instanceof LeafSchemaNode);
39 final LeafSchemaNode myLeaf = (LeafSchemaNode) dataSchemaNode;
41 final TypeDefinition<?> type = myLeaf.getType();
42 assertTrue(type instanceof EnumTypeDefinition);
43 final EnumTypeDefinition myEnum = (EnumTypeDefinition) type;
45 final List<EnumTypeDefinition.EnumPair> values = myEnum.getValues();
46 assertEquals(2, values.size());
48 final List<String> valueNames = new ArrayList<>();
49 for (EnumTypeDefinition.EnumPair pair : values) {
50 valueNames.add(pair.getName());
52 assertTrue(valueNames.contains("value-one"));
53 assertTrue(valueNames.contains("value-two"));