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.openapi.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13 import static org.mockito.Mockito.mock;
14 import static org.mockito.Mockito.when;
15 import static org.opendaylight.restconf.openapi.OpenApiTestUtils.getPathGetParameters;
17 import java.util.List;
18 import org.junit.BeforeClass;
19 import org.junit.Test;
20 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
21 import org.opendaylight.restconf.openapi.DocGenTestHelper;
22 import org.opendaylight.restconf.openapi.model.OpenApiObject;
23 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
25 public class KeysMappingTest {
26 private static OpenApiObject doc;
29 public static void startUp() throws Exception {
30 final var context = YangParserTestUtils.parseYang("""
34 list multiple-key-list {
42 list multiple-key-list2 {
50 list multiple-key-list3 {
58 list multiple-key-list4 {
68 final var schemaService = mock(DOMSchemaService.class);
69 when(schemaService.getGlobalContext()).thenReturn(context);
70 final var generator = new OpenApiGeneratorRFC8040(schemaService);
71 final var uriInfo = DocGenTestHelper.createMockUriInfo("http://localhost/path");
72 doc = generator.getApiDeclaration("keys-mapping", null, uriInfo);
77 * This test is designed to verify if the request parameters for nested lists with multiple keys are being
78 * enumerated properly.
81 * This would mean that we will have name, name1, etc., when the same parameter appears multiple times in the path.
84 public void testKeysMapping() {
85 final var pathToMultipleKeyList4 = "/rests/data/keys-mapping:multiple-key-list={name},{name2}"
86 + "/multiple-key-list2={name1},{name3}/multiple-key-list3={name31},{name4}/multiple-key-list4={name5}";
87 assertTrue(doc.paths().containsKey(pathToMultipleKeyList4));
88 assertEquals(List.of("name","name2", "name1", "name3", "name31", "name4", "name5"),
89 getPathGetParameters(doc.paths(), pathToMultipleKeyList4));