85e989381556d7cf7ef1cc7d3b0ade49aa8300ce
[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 com.google.common.io.Resources;
12 import java.io.File;
13 import java.io.IOException;
14 import java.io.InputStream;
15 import java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.List;
18 import java.util.Set;
19 import org.opendaylight.yangtools.yang.model.api.Module;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
22 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
23
24 public class SchemaContextHelper {
25
26     public static final String ODL_DATASTORE_TEST_YANG = "/odl-datastore-test.yang";
27     public static final String PEOPLE_YANG = "/people.yang";
28     public static final String CARS_YANG = "/cars.yang";
29
30     public static InputStream getInputStream(final String yangFileName) {
31         return TestModel.class.getResourceAsStream(yangFileName);
32     }
33
34     public static SchemaContext full(){
35         return select(ODL_DATASTORE_TEST_YANG, PEOPLE_YANG, CARS_YANG);
36     }
37
38     public static SchemaContext select(String... schemaFiles){
39         YangParserImpl parser = new YangParserImpl();
40         List<InputStream> streams = new ArrayList<>();
41
42         for(String schemaFile : schemaFiles){
43             streams.add(getInputStream(schemaFile));
44         }
45
46         Set<Module> modules = parser.parseYangModelsFromStreams(streams);
47         return parser.resolveSchemaContext(modules);
48     }
49
50     public static SchemaContext entityOwners() {
51         YangParserImpl parser = new YangParserImpl();
52         try {
53             File file = new File("src/main/yang/entity-owners.yang");
54             return parser.parseSources(Arrays.asList(Resources.asByteSource(file.toURI().toURL())));
55         } catch (IOException | YangSyntaxErrorException e) {
56             throw new ExceptionInInitializerError(e);
57         }
58     }
59 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.