2 * Copyright (c) 2013 Cisco 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.controller.yang.model.parser.impl;
10 import static org.junit.Assert.assertEquals;
13 import java.util.List;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.controller.model.api.type.EnumTypeDefinition.EnumPair;
19 import org.opendaylight.controller.model.util.EnumerationType;
20 import org.opendaylight.controller.yang.model.api.Module;
21 import org.opendaylight.controller.yang.model.api.TypeDefinition;
22 import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
24 public class TypesResolutionTest {
26 private YangModelParser parser;
27 private String[] testFiles;
28 private Set<Module> modules;
32 parser = new YangModelParserImpl();
33 testFiles = new String[5];
35 File testDir = new File("src/test/resources/types");
36 String[] fileList = testDir.list();
38 for(String fileName : fileList) {
39 File file = new File(testDir, fileName);
40 testFiles[i] = file.getAbsolutePath();
44 modules = parser.parseYangModels(testFiles);
45 assertEquals(5, modules.size());
49 public void testIetfInetTypes() {
50 Module tested = findModule(modules, "ietf-inet-types");
51 Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
52 assertEquals(14, typedefs.size());
54 TypeDefinition<?> t1 = findTypedef(typedefs, "ip-version");
55 EnumerationType en = (EnumerationType)t1.getBaseType();
56 List<EnumPair> values = en.getValues();
58 EnumPair value0 = values.get(0);
59 assertEquals("unknown", value0.getName());
60 assertEquals(0, (int)value0.getValue());
62 EnumPair value1 = values.get(1);
63 assertEquals("ipv4", value1.getName());
64 assertEquals(1, (int)value1.getValue());
66 EnumPair value2 = values.get(2);
67 assertEquals("ipv6", value2.getName());
68 assertEquals(2, (int)value2.getValue());
71 private Module findModule(Set<Module> modules, String name) {
72 for(Module module : modules) {
73 if(module.getName().equals(name)) {
80 private TypeDefinition<?> findTypedef(Set<TypeDefinition<?>> typedefs, String name) {
81 for(TypeDefinition<?> td : typedefs) {
82 if(td.getQName().getLocalName().equals(name)) {