Removed usage of deprecated YangParserImpl from tests in mdsal project
[mdsal.git] / dom / mdsal-dom-inmemory-datastore / 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 com.google.common.io.ByteSource;
11 import com.google.common.io.Resources;
12 import java.io.IOException;
13 import java.io.InputStream;
14 import java.util.Collections;
15 import java.util.List;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
19 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
20 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
22 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
23 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
24 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
25
26 public class TestModel {
27
28     public static final QName TEST_QNAME = QName.create("urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test", "2014-03-13",
29         "test");
30     public static final QName OUTER_LIST_QNAME = QName.create(TEST_QNAME, "outer-list");
31     public static final QName INNER_LIST_QNAME = QName.create(TEST_QNAME, "inner-list");
32     public static final QName OUTER_CHOICE_QNAME = QName.create(TEST_QNAME, "outer-choice");
33     public static final QName ID_QNAME = QName.create(TEST_QNAME, "id");
34     public static final QName NAME_QNAME = QName.create(TEST_QNAME, "name");
35     public static final QName VALUE_QNAME = QName.create(TEST_QNAME, "value");
36     private static final String DATASTORE_TEST_YANG = "/odl-datastore-test.yang";
37
38     public static final YangInstanceIdentifier TEST_PATH = YangInstanceIdentifier.of(TEST_QNAME);
39     public static final YangInstanceIdentifier OUTER_LIST_PATH = YangInstanceIdentifier.builder(TEST_PATH).node(OUTER_LIST_QNAME).build();
40     public static final QName TWO_QNAME = QName.create(TEST_QNAME, "two");
41     public static final QName THREE_QNAME = QName.create(TEST_QNAME, "three");
42
43   //  private static ByteSource getInputStream() {
44   //      return Resources.asByteSource(TestModel.class.getResource(DATASTORE_TEST_YANG));
45    // }
46
47     private static InputStream getInputStream() {
48         return TestModel.class.getResourceAsStream(DATASTORE_TEST_YANG);
49     }
50
51     public static SchemaContext createTestContext() throws IOException, YangSyntaxErrorException, ReactorException {
52         //YangParserImpl parser = new YangParserImpl();
53         //return parser.parseSources(Collections.singletonList(getInputStream()));
54         return parseYangStreams(Collections.singletonList(getInputStream()));
55     }
56
57     private static SchemaContext parseYangStreams(List<InputStream> streams)
58             throws SourceException, ReactorException {
59
60         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
61                 .newBuild();
62         return reactor.buildEffective(streams);
63     }
64 }