5013b4660e6017580696f82c5eea9c4454337fea
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / test / java / org / opendaylight / controller / md / sal / dom / store / impl / TestModel.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 package org.opendaylight.controller.md.sal.dom.store.impl;
9
10 import java.io.InputStream;
11 import java.util.Collections;
12 import java.util.List;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
15 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
17 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
18 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
19
20 public class TestModel {
21
22     public static final QName TEST_QNAME =
23             QName.create("urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test", "2014-03-13", "test");
24     public static final QName TEST2_QNAME =
25             QName.create("urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test", "2014-03-13", "test2");
26     public static final QName OUTER_LIST_QNAME = QName.create(TEST_QNAME, "outer-list");
27     public static final QName INNER_LIST_QNAME = QName.create(TEST_QNAME, "inner-list");
28     public static final QName OUTER_CHOICE_QNAME = QName.create(TEST_QNAME, "outer-choice");
29     public static final QName ID_QNAME = QName.create(TEST_QNAME, "id");
30     public static final QName NAME_QNAME = QName.create(TEST_QNAME, "name");
31     public static final QName VALUE_QNAME = QName.create(TEST_QNAME, "value");
32     public static final QName TWO_QNAME = QName.create(TEST_QNAME,"two");
33     public static final QName THREE_QNAME = QName.create(TEST_QNAME,"three");
34     public static final YangInstanceIdentifier TEST_PATH = YangInstanceIdentifier.of(TEST_QNAME);
35     public static final YangInstanceIdentifier TEST2_PATH = YangInstanceIdentifier.of(TEST2_QNAME);
36     public static final YangInstanceIdentifier OUTER_LIST_PATH =
37             YangInstanceIdentifier.builder(TEST_PATH).node(OUTER_LIST_QNAME).build();
38     private static final String DATASTORE_TEST_YANG = "/odl-datastore-test.yang";
39
40     private static InputStream getInputStream() {
41         return TestModel.class.getResourceAsStream(DATASTORE_TEST_YANG);
42     }
43
44     public static SchemaContext createTestContext() {
45         final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
46         final SchemaContext schemaContext;
47         final List<InputStream> streams = Collections.singletonList(getInputStream());
48
49         try {
50             schemaContext = reactor.buildEffective(streams);
51         } catch (ReactorException e) {
52             throw new RuntimeException("Unable to build schema context from " + streams, e);
53         }
54         return schemaContext;
55     }
56 }