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;
12 import java.text.DateFormat;
13 import java.text.ParseException;
14 import java.text.SimpleDateFormat;
15 import java.util.ArrayList;
16 import java.util.Date;
17 import java.util.List;
20 import org.opendaylight.controller.yang.common.QName;
21 import org.opendaylight.controller.yang.model.api.Module;
22 import org.opendaylight.controller.yang.model.api.ModuleImport;
23 import org.opendaylight.controller.yang.model.api.SchemaPath;
24 import org.opendaylight.controller.yang.model.api.TypeDefinition;
25 import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
27 final class TestUtils {
32 public static Set<Module> loadModules(String resourceDirectory) {
33 YangModelParser parser = new YangModelParserImpl();
34 File testDir = new File(resourceDirectory);
35 String[] fileList = testDir.list();
36 String[] testFiles = new String[fileList.length];
37 for (int i = 0; i < fileList.length; i++) {
38 String fileName = fileList[i];
39 File file = new File(testDir, fileName);
40 testFiles[i] = file.getAbsolutePath();
42 return parser.parseYangModels(testFiles);
45 public static Module findModule(Set<Module> modules, String moduleName) {
47 for (Module module : modules) {
48 if (module.getName().equals(moduleName)) {
56 public static ModuleImport findImport(Set<ModuleImport> imports,
58 ModuleImport result = null;
59 for (ModuleImport moduleImport : imports) {
60 if (moduleImport.getPrefix().equals(prefix)) {
61 result = moduleImport;
68 public static TypeDefinition<?> findTypedef(
69 Set<TypeDefinition<?>> typedefs, String name) {
70 TypeDefinition<?> result = null;
71 for (TypeDefinition<?> td : typedefs) {
72 if (td.getQName().getLocalName().equals(name)) {
80 public static SchemaPath createPath(boolean absolute, URI namespace,
81 Date revision, String prefix, String... names) {
82 List<QName> path = new ArrayList<QName>();
83 for (String name : names) {
84 path.add(new QName(namespace, revision, prefix, name));
86 return new SchemaPath(path, absolute);
89 public static Date createDate(String date) {
91 final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
93 result = simpleDateFormat.parse(date);
94 } catch (ParseException e) {