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