2 * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.restconf.nb.rfc8040;
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;
28 public abstract class AbstractJukeboxTest {
30 protected static final QName JUKEBOX_QNAME =
31 QName.create("http://example.com/ns/example-jukebox", "2015-04-04", "jukebox");
33 protected static final QName PLAYER_QNAME = QName.create(JUKEBOX_QNAME, "player");
35 protected static final QName LIBRARY_QNAME = QName.create(JUKEBOX_QNAME, "library");
37 protected static final QName SONG_QNAME = QName.create(JUKEBOX_QNAME, "song");
39 protected static final QName SONG_ID_QNAME = QName.create(JUKEBOX_QNAME, "id");
41 protected static final QName SONG_INDEX_QNAME = QName.create(JUKEBOX_QNAME, "index");
43 protected static final QName ARTIST_QNAME = QName.create(JUKEBOX_QNAME, "artist");
45 protected static final QName ALBUM_QNAME = QName.create(JUKEBOX_QNAME, "album");
47 protected static final QName NAME_QNAME = QName.create(JUKEBOX_QNAME, "name");
49 protected static final QName GAP_QNAME = QName.create(JUKEBOX_QNAME, "gap");
51 protected static final QName PLAYLIST_QNAME = QName.create(JUKEBOX_QNAME, "playlist");
53 protected static final QName DESCRIPTION_QNAME = QName.create(JUKEBOX_QNAME, "description");
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);
59 // instance identifier for accessing leaf node "gap"
60 protected static final YangInstanceIdentifier GAP_IID =
61 YangInstanceIdentifier.of(JUKEBOX_QNAME, PLAYER_QNAME, GAP_QNAME);
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))
68 protected static final ContainerNode EMPTY_JUKEBOX = ImmutableNodes.newContainerBuilder()
69 .withNodeIdentifier(new NodeIdentifier(JUKEBOX_QNAME))
70 .withChild(CONT_PLAYER)
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"))
77 protected static final MapEntryNode SONG1 = ImmutableNodes.newMapEntryBuilder()
78 .withNodeIdentifier(YangInstanceIdentifier.NodeIdentifierWithPredicates.of(SONG_QNAME, SONG_INDEX_QNAME,
80 .withChild(ImmutableNodes.leafNode(SONG_ID_QNAME, "A"))
82 protected static final MapEntryNode SONG2 = ImmutableNodes.newMapEntryBuilder()
83 .withNodeIdentifier(YangInstanceIdentifier.NodeIdentifierWithPredicates.of(SONG_QNAME, SONG_INDEX_QNAME,
85 .withChild(ImmutableNodes.leafNode(SONG_ID_QNAME, "B"))
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,
92 .withChild(ImmutableNodes.newUserMapBuilder()
93 .withNodeIdentifier(new NodeIdentifier(SONG_QNAME))
100 protected static final @NonNull EffectiveModelContext JUKEBOX_SCHEMA =
101 YangParserTestUtils.parseYangResourceDirectory("/jukebox");
102 protected static final @NonNull DatabindContext JUKEBOX_DATABIND = DatabindContext.ofModel(JUKEBOX_SCHEMA);
104 protected static final InputStream stringInputStream(final String str) {
105 return new ByteArrayInputStream(str.getBytes(StandardCharsets.UTF_8));