Cleanup warnings
[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 java.io.File;
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;
21
22 public class SchemaContextHelper {
23
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";
27
28     public static InputStream getInputStream(final String yangFileName) {
29         return SchemaContextHelper.class.getResourceAsStream(yangFileName);
30     }
31
32     public static SchemaContext full() {
33         return select(ODL_DATASTORE_TEST_YANG, PEOPLE_YANG, CARS_YANG);
34     }
35
36     public static SchemaContext select(final String... schemaFiles) {
37         List<InputStream> streams = new ArrayList<>(schemaFiles.length);
38
39         for (String schemaFile : schemaFiles) {
40             streams.add(getInputStream(schemaFile));
41         }
42
43         try {
44             return YangParserTestUtils.parseYangStreams(streams);
45         } catch (ReactorException e) {
46             throw new RuntimeException("Unable to build schema context from " + streams, e);
47         }
48     }
49
50     public static SchemaContext distributedShardedDOMDataTreeSchemaContext() {
51         final List<InputStream> streams = new ArrayList<>();
52         try {
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);
60         }
61     }
62
63     public static SchemaContext entityOwners() {
64         try {
65             return YangParserTestUtils.parseYangSources(new File("src/main/yang/entity-owners.yang"));
66         } catch (IOException | ReactorException e) {
67             throw new RuntimeException(e);
68         }
69     }
70 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.