Move InstanceIdentifierContext
[netconf.git] / restconf / restconf-nb / src / test / java / org / opendaylight / restconf / nb / rfc8040 / databind / ResourceBodyTest.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.databind;
9
10 import static org.junit.Assert.assertThrows;
11
12 import org.junit.Test;
13 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
14 import org.opendaylight.restconf.nb.rfc8040.AbstractJukeboxTest;
15 import org.opendaylight.restconf.nb.rfc8040.legacy.InstanceIdentifierContext;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17
18 public class ResourceBodyTest extends AbstractJukeboxTest {
19     @Test
20     public void testValidTopLevelNodeName() {
21         ResourceBody.validTopLevelNodeName(GAP_IID.getLastPathArgument(), GAP_LEAF);
22     }
23
24     @Test
25     public void testValidTopLevelNodeNameWrongTopIdentifier() {
26         // FIXME: more asserts
27         assertThrows(RestconfDocumentedException.class,
28             () -> ResourceBody.validTopLevelNodeName(PLAYLIST_IID.getLastPathArgument(), GAP_LEAF));
29     }
30
31     @Test
32     public void testValidateListKeysEqualityInPayloadAndUri() {
33         final var path = YangInstanceIdentifier.builder()
34             .node(JUKEBOX_QNAME)
35             .node(PLAYLIST_QNAME)
36             .nodeWithKey(PLAYLIST_QNAME, NAME_QNAME, "name of band")
37             .build();
38         final var iidContext = InstanceIdentifierContext.ofLocalPath(JUKEBOX_SCHEMA, path);
39         ResourceBody.validateListKeysEqualityInPayloadAndUri(iidContext.getSchemaNode(), path, BAND_ENTRY);
40     }
41 }