/* * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.restconf.nb.rfc8040.databind; import static org.junit.Assert.assertEquals; import java.util.Map; import org.junit.Test; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue; import org.opendaylight.yangtools.yang.data.impl.schema.Builders; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; public class JsonResourceBodyTest extends AbstractResourceBodyTest { public JsonResourceBodyTest() { super(JsonResourceBody::new); } @Test public void moduleDataTest() throws Exception { final var entryId = NodeIdentifierWithPredicates.of(LST11, Map.of(KEYVALUE111, "value1", KEYVALUE112, "value2")); assertEquals(Builders.containerBuilder() .withNodeIdentifier(CONT_NID) .withChild(Builders.containerBuilder() .withNodeIdentifier(CONT1_NID) .withChild(Builders.mapBuilder() .withNodeIdentifier(new NodeIdentifier(LST11)) .withChild(Builders.mapEntryBuilder() .withNodeIdentifier(entryId) .withChild(ImmutableNodes.leafNode(KEYVALUE111, "value1")) .withChild(ImmutableNodes.leafNode(KEYVALUE112, "value2")) .withChild(ImmutableNodes.leafNode(LF111, YangInstanceIdentifier.of(CONT_NID, CONT1_NID, new NodeIdentifier(LST11), entryId, LF112_NID))) .withChild(ImmutableNodes.leafNode(LF112_NID, "lf112 value")) .build()) .build()) .build()) .build(), parseResource("instance-identifier-module:cont", "/instanceidentifier/json/jsondata.json")); } @Test public void moduleSubContainerDataPutTest() throws Exception { assertEquals(Builders.containerBuilder() .withNodeIdentifier(CONT1_NID) .withChild(ImmutableNodes.leafNode(LF11, YangInstanceIdentifier.of(CONT_NID, CONT1_NID, new NodeIdentifier(LFLST11), new NodeWithValue<>(LFLST11, "lflst11_1")))) .build(), parseResource("instance-identifier-module:cont/cont1", "/instanceidentifier/json/json_sub_container.json")); } @Test public void testRangeViolation() throws Exception { assertRangeViolation(() -> parse("netconf786:foo", """ { "netconf786:foo": { "bar": 100 } }""")); } }