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.nb.rfc8040.databind.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;
29 public abstract class AbstractJukeboxTest {
31 protected static final QName JUKEBOX_QNAME =
32 QName.create("http://example.com/ns/example-jukebox", "2015-04-04", "jukebox");
34 protected static final QName PLAYER_QNAME = QName.create(JUKEBOX_QNAME, "player");
36 protected static final QName LIBRARY_QNAME = QName.create(JUKEBOX_QNAME, "library");
38 protected static final QName SONG_QNAME = QName.create(JUKEBOX_QNAME, "song");
40 protected static final QName SONG_ID_QNAME = QName.create(JUKEBOX_QNAME, "id");
42 protected static final QName SONG_INDEX_QNAME = QName.create(JUKEBOX_QNAME, "index");
44 protected static final QName ARTIST_QNAME = QName.create(JUKEBOX_QNAME, "artist");
46 protected static final QName ALBUM_QNAME = QName.create(JUKEBOX_QNAME, "album");
48 protected static final QName NAME_QNAME = QName.create(JUKEBOX_QNAME, "name");
50 protected static final QName GAP_QNAME = QName.create(JUKEBOX_QNAME, "gap");
52 protected static final QName PLAYLIST_QNAME = QName.create(JUKEBOX_QNAME, "playlist");
54 protected static final QName DESCRIPTION_QNAME = QName.create(JUKEBOX_QNAME, "description");
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);
60 // instance identifier for accessing leaf node "gap"
61 protected static final YangInstanceIdentifier GAP_IID =
62 YangInstanceIdentifier.of(JUKEBOX_QNAME, PLAYER_QNAME, GAP_QNAME);
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))
69 protected static final ContainerNode EMPTY_JUKEBOX = Builders.containerBuilder()
70 .withNodeIdentifier(new NodeIdentifier(JUKEBOX_QNAME))
71 .withChild(CONT_PLAYER)
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"))
78 protected static final MapEntryNode SONG1 = Builders.mapEntryBuilder()
79 .withNodeIdentifier(YangInstanceIdentifier.NodeIdentifierWithPredicates.of(SONG_QNAME, SONG_INDEX_QNAME,
81 .withChild(ImmutableNodes.leafNode(SONG_ID_QNAME, "A"))
83 protected static final MapEntryNode SONG2 = Builders.mapEntryBuilder()
84 .withNodeIdentifier(YangInstanceIdentifier.NodeIdentifierWithPredicates.of(SONG_QNAME, SONG_INDEX_QNAME,
86 .withChild(ImmutableNodes.leafNode(SONG_ID_QNAME, "B"))
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,
93 .withChild(Builders.orderedMapBuilder()
94 .withNodeIdentifier(new NodeIdentifier(SONG_QNAME))
101 protected static final @NonNull EffectiveModelContext JUKEBOX_SCHEMA =
102 YangParserTestUtils.parseYangResourceDirectory("/jukebox");
103 protected static final @NonNull DatabindContext JUKEBOX_DATABIND = DatabindContext.ofModel(JUKEBOX_SCHEMA);
105 protected static final InputStream stringInputStream(final String str) {
106 return new ByteArrayInputStream(str.getBytes(StandardCharsets.UTF_8));