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.FileInputStream;
14 import java.io.FileNotFoundException;
15 import java.io.IOException;
16 import java.io.InputStream;
17 import java.util.ArrayList;
18 import java.util.List;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
21 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
23 public class SchemaContextHelper {
25 public static final String ODL_DATASTORE_TEST_YANG = "/odl-datastore-test.yang";
26 public static final String PEOPLE_YANG = "/people.yang";
27 public static final String CARS_YANG = "/cars.yang";
29 public static InputStream getInputStream(final String yangFileName) {
30 return SchemaContextHelper.class.getResourceAsStream(yangFileName);
33 public static SchemaContext full() {
34 return select(ODL_DATASTORE_TEST_YANG, PEOPLE_YANG, CARS_YANG);
37 public static SchemaContext select(final String... schemaFiles) {
38 List<InputStream> streams = new ArrayList<>(schemaFiles.length);
40 for (String schemaFile : schemaFiles) {
41 streams.add(getInputStream(schemaFile));
45 return YangParserTestUtils.parseYangStreams(streams);
46 } catch (ReactorException e) {
47 throw new RuntimeException("Unable to build schema context from " + streams, e);
51 public static SchemaContext distributedShardedDOMDataTreeSchemaContext() {
52 final List<InputStream> streams = new ArrayList<>();
54 // we need prefix-shard-configuration and odl-datastore-test models
55 // for DistributedShardedDOMDataTree tests
56 streams.add(getInputStream(ODL_DATASTORE_TEST_YANG));
57 streams.add(new FileInputStream("src/main/yang/prefix-shard-configuration.yang"));
58 return YangParserTestUtils.parseYangStreams(streams);
59 } catch (FileNotFoundException | ReactorException e) {
60 throw new RuntimeException(e);
64 public static SchemaContext entityOwners() {
66 return YangParserTestUtils.parseYangSources(new File("src/main/yang/entity-owners.yang"));
67 } catch (IOException | ReactorException e) {
68 throw Throwables.propagate(e);