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 final 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 private SchemaContextHelper() {
32 public static InputStream getInputStream(final String yangFileName) {
33 return SchemaContextHelper.class.getResourceAsStream(yangFileName);
36 public static SchemaContext full() {
37 return select(ODL_DATASTORE_TEST_YANG, PEOPLE_YANG, CARS_YANG);
40 public static SchemaContext select(final String... schemaFiles) {
41 List<InputStream> streams = new ArrayList<>(schemaFiles.length);
43 for (String schemaFile : schemaFiles) {
44 streams.add(getInputStream(schemaFile));
48 return YangParserTestUtils.parseYangStreams(streams);
49 } catch (ReactorException e) {
50 throw new RuntimeException("Unable to build schema context from " + streams, e);
54 public static SchemaContext distributedShardedDOMDataTreeSchemaContext() {
55 final List<InputStream> streams = new ArrayList<>();
57 // we need prefix-shard-configuration and odl-datastore-test models
58 // for DistributedShardedDOMDataTree tests
59 streams.add(getInputStream(ODL_DATASTORE_TEST_YANG));
60 streams.add(new FileInputStream("src/main/yang/prefix-shard-configuration.yang"));
61 return YangParserTestUtils.parseYangStreams(streams);
62 } catch (FileNotFoundException | ReactorException e) {
63 throw new RuntimeException(e);
67 public static SchemaContext entityOwners() {
69 return YangParserTestUtils.parseYangSources(new File("src/main/yang/entity-owners.yang"));
70 } catch (IOException | ReactorException e) {
71 throw new RuntimeException(e);