BUG-7159: eliminate use of CrossStatementSourceReactor
[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.base.Throwables;
12 import java.io.File;
13 import java.io.IOException;
14 import java.io.InputStream;
15 import java.util.ArrayList;
16 import java.util.List;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
19 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
20
21 public class SchemaContextHelper {
22
23     public static final String ODL_DATASTORE_TEST_YANG = "/odl-datastore-test.yang";
24     public static final String PEOPLE_YANG = "/people.yang";
25     public static final String CARS_YANG = "/cars.yang";
26
27     public static InputStream getInputStream(final String yangFileName) {
28         return SchemaContextHelper.class.getResourceAsStream(yangFileName);
29     }
30
31     public static SchemaContext full() {
32         return select(ODL_DATASTORE_TEST_YANG, PEOPLE_YANG, CARS_YANG);
33     }
34
35     public static SchemaContext select(final String... schemaFiles) {
36         List<InputStream> streams = new ArrayList<>(schemaFiles.length);
37
38         for (String schemaFile : schemaFiles) {
39             streams.add(getInputStream(schemaFile));
40         }
41
42         try {
43             return YangParserTestUtils.parseYangStreams(streams);
44         } catch (ReactorException e) {
45             throw new RuntimeException("Unable to build schema context from " + streams, e);
46         }
47     }
48
49     public static SchemaContext entityOwners() {
50         try {
51             return YangParserTestUtils.parseYangSources(new File("src/main/yang/entity-owners.yang"));
52         } catch (IOException | ReactorException e) {
53             throw Throwables.propagate(e);
54         }
55     }
56 }