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