6688ade142eaadf7dc7adbf07e6a1cfe4b75faef
[netconf.git] / restconf / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / YangAndXmlAndDataSchemaLoader.java
1 /*
2  * Copyright (c) 2014 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.controller.sal.restconf.impl.test;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12
13 import java.io.FileNotFoundException;
14 import java.util.Set;
15 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
16 import org.opendaylight.yangtools.yang.model.api.Module;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
18
19 public abstract class YangAndXmlAndDataSchemaLoader {
20
21     protected static Set<Module> modules;
22     protected static DataSchemaNode dataSchemaNode;
23     protected static String searchedModuleName;
24     protected static String searchedDataSchemaName;
25     protected static String schemaNodePath;
26
27     protected static void dataLoad(final String yangPath) throws FileNotFoundException, ReactorException {
28         dataLoad(yangPath, 1, null, null);
29     }
30
31     protected static void dataLoad(final String yangPath, final int modulesNumber, final String moduleName,
32             final String dataSchemaName) throws FileNotFoundException, ReactorException {
33         modules = TestUtils.loadSchemaContext(yangPath).getModules();
34         assertEquals(modulesNumber, modules.size());
35         final Module module = TestUtils.resolveModule(moduleName, modules);
36         searchedModuleName = module == null ? "" : module.getName();
37         assertNotNull(module);
38         dataSchemaNode = TestUtils.resolveDataSchemaNode(dataSchemaName, module);
39         searchedDataSchemaName = dataSchemaNode == null ? "" : dataSchemaNode.getQName().getLocalName();
40         assertNotNull(dataSchemaNode);
41         schemaNodePath = searchedModuleName + ":" + searchedDataSchemaName;
42     }
43
44 }