2 * Copyright (c) 2014 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
9 package org.opendaylight.controller.md.cluster.datastore.model;
11 import com.google.common.base.Throwables;
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;
21 public class SchemaContextHelper {
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";
27 public static InputStream getInputStream(final String yangFileName) {
28 return SchemaContextHelper.class.getResourceAsStream(yangFileName);
31 public static SchemaContext full() {
32 return select(ODL_DATASTORE_TEST_YANG, PEOPLE_YANG, CARS_YANG);
35 public static SchemaContext select(final String... schemaFiles) {
36 List<InputStream> streams = new ArrayList<>(schemaFiles.length);
38 for (String schemaFile : schemaFiles) {
39 streams.add(getInputStream(schemaFile));
43 return YangParserTestUtils.parseYangStreams(streams);
44 } catch (ReactorException e) {
45 throw new RuntimeException("Unable to build schema context from " + streams, e);
49 public static SchemaContext entityOwners() {
51 return YangParserTestUtils.parseYangSources(new File("src/main/yang/entity-owners.yang"));
52 } catch (IOException | ReactorException e) {
53 throw Throwables.propagate(e);