afbae4ffacc0b322871a833b35d1880869220c2b
[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.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.restconf.server.api.DatabindContext;
15 import org.opendaylight.yangtools.yang.common.Decimal64;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
20 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
21 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
22 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
23 import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
24 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
25 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
26 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
27 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
28
29 public abstract class AbstractJukeboxTest {
30     // container jukebox
31     protected static final QName JUKEBOX_QNAME =
32         QName.create("http://example.com/ns/example-jukebox", "2015-04-04", "jukebox");
33     // container player
34     protected static final QName PLAYER_QNAME = QName.create(JUKEBOX_QNAME, "player");
35     // container library
36     protected static final QName LIBRARY_QNAME = QName.create(JUKEBOX_QNAME, "library");
37     // list song
38     protected static final QName SONG_QNAME = QName.create(JUKEBOX_QNAME, "song");
39     // leaf id
40     protected static final QName SONG_ID_QNAME = QName.create(JUKEBOX_QNAME, "id");
41     // leaf index
42     protected static final QName SONG_INDEX_QNAME = QName.create(JUKEBOX_QNAME, "index");
43     // list artist
44     protected static final QName ARTIST_QNAME = QName.create(JUKEBOX_QNAME, "artist");
45     // list album
46     protected static final QName ALBUM_QNAME = QName.create(JUKEBOX_QNAME, "album");
47     // leaf name
48     protected static final QName NAME_QNAME = QName.create(JUKEBOX_QNAME, "name");
49     // leaf gap
50     protected static final QName GAP_QNAME = QName.create(JUKEBOX_QNAME, "gap");
51     // leaf playlist
52     protected static final QName PLAYLIST_QNAME = QName.create(JUKEBOX_QNAME, "playlist");
53     // leaf description
54     protected static final QName DESCRIPTION_QNAME = QName.create(JUKEBOX_QNAME, "description");
55
56     protected static final YangInstanceIdentifier JUKEBOX_IID = YangInstanceIdentifier.of(JUKEBOX_QNAME);
57     protected static final YangInstanceIdentifier PLAYLIST_IID =
58         YangInstanceIdentifier.of(JUKEBOX_QNAME, PLAYLIST_QNAME);
59
60     // instance identifier for accessing leaf node "gap"
61     protected static final YangInstanceIdentifier GAP_IID =
62         YangInstanceIdentifier.of(JUKEBOX_QNAME, PLAYER_QNAME, GAP_QNAME);
63
64     protected static final LeafNode<?> GAP_LEAF = ImmutableNodes.leafNode(GAP_QNAME, Decimal64.valueOf("0.2"));
65     protected static final ContainerNode CONT_PLAYER = Builders.containerBuilder()
66         .withNodeIdentifier(new NodeIdentifier(PLAYER_QNAME))
67         .withChild(GAP_LEAF)
68         .build();
69     protected static final ContainerNode EMPTY_JUKEBOX = Builders.containerBuilder()
70         .withNodeIdentifier(new NodeIdentifier(JUKEBOX_QNAME))
71         .withChild(CONT_PLAYER)
72         .build();
73     protected static final MapEntryNode BAND_ENTRY = Builders.mapEntryBuilder()
74         .withNodeIdentifier(NodeIdentifierWithPredicates.of(PLAYLIST_QNAME, NAME_QNAME, "name of band"))
75         .withChild(ImmutableNodes.leafNode(NAME_QNAME, "name of band"))
76         .withChild(ImmutableNodes.leafNode(DESCRIPTION_QNAME, "band description"))
77         .build();
78     protected static final MapEntryNode SONG1 = Builders.mapEntryBuilder()
79         .withNodeIdentifier(YangInstanceIdentifier.NodeIdentifierWithPredicates.of(SONG_QNAME, SONG_INDEX_QNAME,
80             "1"))
81         .withChild(ImmutableNodes.leafNode(SONG_ID_QNAME, "A"))
82         .build();
83     protected static final MapEntryNode SONG2 = Builders.mapEntryBuilder()
84         .withNodeIdentifier(YangInstanceIdentifier.NodeIdentifierWithPredicates.of(SONG_QNAME, SONG_INDEX_QNAME,
85             "2"))
86         .withChild(ImmutableNodes.leafNode(SONG_ID_QNAME, "B"))
87         .build();
88     protected static final SystemMapNode PLAYLIST_WITH_SONGS = Builders.mapBuilder()
89         .withNodeIdentifier(new NodeIdentifier(JUKEBOX_QNAME))
90         .withChild(Builders.mapEntryBuilder()
91             .withNodeIdentifier(YangInstanceIdentifier.NodeIdentifierWithPredicates.of(PLAYLIST_QNAME, NAME_QNAME,
92                 "0"))
93                 .withChild(Builders.orderedMapBuilder()
94                     .withNodeIdentifier(new NodeIdentifier(SONG_QNAME))
95                     .withChild(SONG1)
96                     .withChild(SONG2)
97                     .build())
98                 .build())
99             .build();
100
101     protected static final @NonNull EffectiveModelContext JUKEBOX_SCHEMA =
102         YangParserTestUtils.parseYangResourceDirectory("/jukebox");
103     protected static final @NonNull DatabindContext JUKEBOX_DATABIND = DatabindContext.ofModel(JUKEBOX_SCHEMA);
104
105     protected static final InputStream stringInputStream(final String str) {
106         return new ByteArrayInputStream(str.getBytes(StandardCharsets.UTF_8));
107     }
108 }