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;
14 import java.io.FileNotFoundException;
16 import java.net.URISyntaxException;
17 import java.text.ParseException;
18 import java.util.ArrayList;
19 import java.util.Date;
20 import java.util.List;
21 import org.junit.Test;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.common.QNameModule;
24 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
25 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
26 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
27 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
28 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
29 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
30 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
32 public class Bug2872Test {
35 public void test() throws ReactorException, FileNotFoundException, URISyntaxException, ParseException {
36 final SchemaContext schema = StmtTestUtils.parseYangSources("/bugs/bug2872");
37 assertNotNull(schema);
39 final Date revision = SimpleDateFormatUtil.getRevisionFormat().parse("2016-06-08");
40 final QNameModule bug2872module = QNameModule.create(new URI("bug2872"), revision);
41 final QName foo = QName.create(bug2872module, "bar");
43 final DataSchemaNode dataSchemaNode = schema.getDataChildByName(foo);
44 assertTrue(dataSchemaNode instanceof LeafSchemaNode);
45 final LeafSchemaNode myLeaf = (LeafSchemaNode) dataSchemaNode;
47 final TypeDefinition<?> type = myLeaf.getType();
48 assertTrue(type instanceof EnumTypeDefinition);
49 final EnumTypeDefinition myEnum = (EnumTypeDefinition) type;
51 final List<EnumTypeDefinition.EnumPair> values = myEnum.getValues();
52 assertEquals(2, values.size());
54 final List<String> valueNames = new ArrayList<>();
55 for (EnumTypeDefinition.EnumPair pair : values) {
56 valueNames.add(pair.getName());
58 assertTrue(valueNames.contains("value-one"));
59 assertTrue(valueNames.contains("value-two"));