Introduce RestconfServer methods for YANG Patch
[netconf.git] / restconf / restconf-nb / src / test / java / org / opendaylight / restconf / nb / rfc8040 / AbstractJukeboxTest.java
1 /*
2  * Copyright (c) 2023 PANTHEON.tech, s.r.o. 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.restconf.nb.rfc8040;
9
10 import java.io.ByteArrayInputStream;
11 import java.io.InputStream;
12 import java.nio.charset.StandardCharsets;
13 import org.opendaylight.yangtools.yang.common.Decimal64;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
18 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
19 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
20 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
21 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
22 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
23 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
24 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
25
26 public abstract class AbstractJukeboxTest {
27     // container jukebox
28     protected static final QName JUKEBOX_QNAME =
29         QName.create("http://example.com/ns/example-jukebox", "2015-04-04", "jukebox");
30     // container player
31     protected static final QName PLAYER_QNAME = QName.create(JUKEBOX_QNAME, "player");
32     // container library
33     protected static final QName LIBRARY_QNAME = QName.create(JUKEBOX_QNAME, "library");
34     // list artist
35     protected static final QName ARTIST_QNAME = QName.create(JUKEBOX_QNAME, "artist");
36     // list album
37     protected static final QName ALBUM_QNAME = QName.create(JUKEBOX_QNAME, "album");
38     // leaf name
39     protected static final QName NAME_QNAME = QName.create(JUKEBOX_QNAME, "name");
40     // leaf gap
41     protected static final QName GAP_QNAME = QName.create(JUKEBOX_QNAME, "gap");
42     // leaf playlist
43     protected static final QName PLAYLIST_QNAME = QName.create(JUKEBOX_QNAME, "playlist");
44     // leaf description
45     protected static final QName DESCRIPTION_QNAME = QName.create(JUKEBOX_QNAME, "description");
46
47     protected static final YangInstanceIdentifier JUKEBOX_IID = YangInstanceIdentifier.of(JUKEBOX_QNAME);
48     protected static final YangInstanceIdentifier PLAYLIST_IID =
49         YangInstanceIdentifier.of(JUKEBOX_QNAME, PLAYLIST_QNAME);
50
51     // instance identifier for accessing leaf node "gap"
52     protected static final YangInstanceIdentifier GAP_IID =
53         YangInstanceIdentifier.of(JUKEBOX_QNAME, PLAYER_QNAME, GAP_QNAME);
54
55     protected static final LeafNode<?> GAP_LEAF = ImmutableNodes.leafNode(GAP_QNAME, Decimal64.valueOf("0.2"));
56     protected static final ContainerNode CONT_PLAYER = Builders.containerBuilder()
57         .withNodeIdentifier(new NodeIdentifier(PLAYER_QNAME))
58         .withChild(GAP_LEAF)
59         .build();
60     protected static final ContainerNode EMPTY_JUKEBOX = Builders.containerBuilder()
61         .withNodeIdentifier(new NodeIdentifier(JUKEBOX_QNAME))
62         .withChild(CONT_PLAYER)
63         .build();
64     protected static final MapEntryNode BAND_ENTRY = Builders.mapEntryBuilder()
65         .withNodeIdentifier(NodeIdentifierWithPredicates.of(PLAYLIST_QNAME, NAME_QNAME, "name of band"))
66         .withChild(ImmutableNodes.leafNode(NAME_QNAME, "name of band"))
67         .withChild(ImmutableNodes.leafNode(DESCRIPTION_QNAME, "band description"))
68         .build();
69
70     protected static final EffectiveModelContext JUKEBOX_SCHEMA =
71         YangParserTestUtils.parseYangResourceDirectory("/jukebox");
72
73     protected static final InputStream stringInputStream(final String str) {
74         return new ByteArrayInputStream(str.getBytes(StandardCharsets.UTF_8));
75     }
76 }