BUG 2970 : Create a PruningDataTreeModification
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / md / cluster / datastore / model / SchemaContextHelper.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
9 package org.opendaylight.controller.md.cluster.datastore.model;
10
11 import java.io.InputStream;
12 import java.util.ArrayList;
13 import java.util.List;
14 import java.util.Set;
15 import org.opendaylight.yangtools.yang.model.api.Module;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
17 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
18
19 public class SchemaContextHelper {
20
21     public static final String ODL_DATASTORE_TEST_YANG = "/odl-datastore-test.yang";
22     public static final String PEOPLE_YANG = "/people.yang";
23     public static final String CARS_YANG = "/cars.yang";
24
25     public static InputStream getInputStream(final String yangFileName) {
26         return TestModel.class.getResourceAsStream(yangFileName);
27     }
28
29     public static SchemaContext full(){
30         return select(ODL_DATASTORE_TEST_YANG, PEOPLE_YANG, CARS_YANG);
31     }
32
33     public static SchemaContext select(String... schemaFiles){
34         YangParserImpl parser = new YangParserImpl();
35         List<InputStream> streams = new ArrayList<>();
36
37         for(String schemaFile : schemaFiles){
38             streams.add(getInputStream(schemaFile));
39         }
40
41         Set<Module> modules = parser.parseYangModelsFromStreams(streams);
42         return parser.resolveSchemaContext(modules);
43     }
44
45 }