d2d3b51048182ea6feaa8ec565f4378df72ed3e3
[controller.git] / opendaylight / md-sal / benchmark-data-store / src / main / java / org / opendaylight / controller / md / sal / dom / store / benchmark / BenchmarkModel.java
1 /*
2  * Copyright (c) 2013, 2017 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.benchmark;
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.test.util.YangParserTestUtils;
18
19 /**
20  * Benchmark Model class loads the odl-datastore-test.yang model from resources.
21  * <br>
22  * This class serves as facilitator class which holds several references to initialized yang model as static final
23  * members.
24  *
25  * @author Lukas Sedlak
26  */
27 public final class BenchmarkModel {
28
29     public static final QName TEST_QNAME = QName
30         .create("urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test", "2014-03-13","test");
31     public static final QName OUTER_LIST_QNAME = QName.create(TEST_QNAME, "outer-list");
32     public static final QName INNER_LIST_QNAME = QName.create(TEST_QNAME, "inner-list");
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     private static final String DATASTORE_TEST_YANG = "/odl-datastore-test.yang";
36     public static final YangInstanceIdentifier TEST_PATH = YangInstanceIdentifier.of(TEST_QNAME);
37     public static final YangInstanceIdentifier OUTER_LIST_PATH =
38             YangInstanceIdentifier.builder(TEST_PATH).node(OUTER_LIST_QNAME).build();
39
40     private BenchmarkModel() {
41     }
42
43     private static InputStream getInputStream() {
44         return BenchmarkModel.class.getResourceAsStream(DATASTORE_TEST_YANG);
45     }
46
47     public static SchemaContext createTestContext() {
48         final SchemaContext schemaContext;
49         final List<InputStream> streams = Collections.singletonList(getInputStream());
50
51         try {
52             schemaContext = YangParserTestUtils.parseYangStreams(streams);
53         } catch (ReactorException e) {
54             throw new RuntimeException("Unable to build schema context from " + streams, e);
55         }
56         return schemaContext;
57     }
58 }