private static final String NAME_2 = "toaster";
private static final String REVISION_DATE_2 = "2009-11-20";
private static final String CHOICE_TEST_MODULE = "choice-test";
+ private static final String RECURSIVE_TEST_MODULE = "recursive";
private final OpenApiGeneratorRFC8040 generator = new OpenApiGeneratorRFC8040(SCHEMA_SERVICE);
assertTrue(secondContainer.getProperties().has("leaf-first-case"));
assertFalse(secondContainer.getProperties().has("leaf-second-case"));
}
+
+ /**
+ * Test that checks for correct amount of parameters in requests.
+ */
+ @Test
+ public void testRecursiveParameters() {
+ final var configPaths = Map.of("/rests/data/recursive:container-root", 0,
+ "/rests/data/recursive:container-root/root-list={name}", 1,
+ "/rests/data/recursive:container-root/root-list={name}/nested-list={name1}", 2,
+ "/rests/data/recursive:container-root/root-list={name}/nested-list={name1}/super-nested-list={name2}", 3);
+
+ final var module = CONTEXT.findModule(RECURSIVE_TEST_MODULE, Revision.of("2023-05-22")).orElseThrow();
+ final var doc = generator.getOpenApiSpec(module, "http", "localhost:8181", "/", "", CONTEXT);
+ assertNotNull(doc);
+
+ final var paths = doc.getPaths();
+ assertEquals(5, paths.size());
+
+ for (final var expectedPath : configPaths.entrySet()) {
+ assertTrue(paths.containsKey(expectedPath.getKey()));
+ final int expectedSize = expectedPath.getValue();
+
+ final var path = paths.get(expectedPath.getKey());
+
+ final var get = path.getGet();
+ assertFalse(get.isMissingNode());
+ assertEquals(expectedSize + 1, get.get("parameters").size());
+
+ final var put = path.getPut();
+ assertFalse(put.isMissingNode());
+ assertEquals(expectedSize, put.get("parameters").size());
+
+ final var delete = path.getDelete();
+ assertFalse(delete.isMissingNode());
+ assertEquals(expectedSize, delete.get("parameters").size());
+
+ final var post = path.getPost();
+ assertFalse(post.isMissingNode());
+ assertEquals(expectedSize, post.get("parameters").size());
+
+ final var patch = path.getPatch();
+ assertFalse(patch.isMissingNode());
+ assertEquals(expectedSize, patch.get("parameters").size());
+ }
+ }
}
package org.opendaylight.restconf.openapi.mountpoints;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
final Map<String, Path> paths = mountPointApi.getPaths();
assertNotNull(paths);
- assertEquals("Unexpected api list size", 27, paths.size());
+ assertEquals("Unexpected api list size", 31, paths.size());
final List<JsonNode> getOperations = new ArrayList<>();
final List<JsonNode> postOperations = new ArrayList<>();
Optional.ofNullable(path.getValue().getDelete()).ifPresent(deleteOperations::add);
}
- assertEquals("Unexpected GET paths size", 19, getOperations.size());
- assertEquals("Unexpected POST paths size", 25, postOperations.size());
- assertEquals("Unexpected PUT paths size", 17, putOperations.size());
- assertEquals("Unexpected PATCH paths size", 17, patchOperations.size());
- assertEquals("Unexpected DELETE paths size", 17, deleteOperations.size());
+ assertEquals("Unexpected GET paths size", 23, getOperations.size());
+ assertEquals("Unexpected POST paths size", 29, postOperations.size());
+ assertEquals("Unexpected PUT paths size", 21, putOperations.size());
+ assertEquals("Unexpected PATCH paths size", 21, patchOperations.size());
+ assertEquals("Unexpected DELETE paths size", 21, deleteOperations.size());
+ }
+
+ /**
+ * Test that checks for correct amount of parameters in requests.
+ */
+ @Test
+ @SuppressWarnings("checkstyle:lineLength")
+ public void testMountPointRecursiveParameters() throws Exception {
+ final var configPaths = Map.of("/rests/data/nodes/node=123/yang-ext:mount/recursive:container-root", 0,
+ "/rests/data/nodes/node=123/yang-ext:mount/recursive:container-root/root-list={name}", 1,
+ "/rests/data/nodes/node=123/yang-ext:mount/recursive:container-root/root-list={name}/nested-list={name1}", 2,
+ "/rests/data/nodes/node=123/yang-ext:mount/recursive:container-root/root-list={name}/nested-list={name1}/super-nested-list={name2}", 3);
+
+ final var mockInfo = DocGenTestHelper.createMockUriInfo(HTTP_URL);
+ openApi.onMountPointCreated(INSTANCE_ID);
+
+ final var mountPointApi = openApi.getMountPointApi(mockInfo, 1L, "recursive", "2023-05-22");
+ assertNotNull("Failed to find Datastore API", mountPointApi);
+
+ final var paths = mountPointApi.getPaths();
+ assertEquals(5, paths.size());
+
+ for (final var expectedPath : configPaths.entrySet()) {
+ assertTrue(paths.containsKey(expectedPath.getKey()));
+ final int expectedSize = expectedPath.getValue();
+
+ final var path = paths.get(expectedPath.getKey());
+
+ final var get = path.getGet();
+ assertFalse(get.isMissingNode());
+ assertEquals(expectedSize + 1, get.get("parameters").size());
+
+ final var put = path.getPut();
+ assertFalse(put.isMissingNode());
+ assertEquals(expectedSize, put.get("parameters").size());
+
+ final var delete = path.getDelete();
+ assertFalse(delete.isMissingNode());
+ assertEquals(expectedSize, delete.get("parameters").size());
+
+ final var post = path.getPost();
+ assertFalse(post.isMissingNode());
+ assertEquals(expectedSize, post.get("parameters").size());
+
+ final var patch = path.getPatch();
+ assertFalse(patch.isMissingNode());
+ assertEquals(expectedSize, patch.get("parameters").size());
+ }
}
}