2b22aeac2174b7bc4ccd9b7a8fde94d22ce3d529
[netconf.git] /
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.openapi.impl;
9
10 import java.util.stream.Stream;
11 import org.junit.jupiter.api.BeforeAll;
12 import org.junit.jupiter.api.Test;
13 import org.junit.jupiter.params.ParameterizedTest;
14 import org.junit.jupiter.params.provider.Arguments;
15 import org.junit.jupiter.params.provider.MethodSource;
16 import org.skyscreamer.jsonassert.JSONAssert;
17
18 class OperationalDocumentTest extends AbstractDocumentTest {
19     /**
20      * Model action-types is used for test correct generating of action statements for openapi.
21      */
22     private static final String ACTION_TYPES = "action-types";
23     /**
24      * Model operational is used for test correct generating of operational parameters for openapi.
25      */
26     private static final String OPERATIONAL = "operational";
27
28     @BeforeAll
29     static void beforeAll() {
30         initializeClass("/operational/");
31     }
32
33     /**
34      * Tests the swagger document that is result of the call to the '/single' endpoint.
35      */
36     @Test
37     void getAllModulesDocTest() throws Exception {
38         final var expectedJson = getExpectedDoc("operational-document/controller-all.json");
39         final var allModulesDoc = getAllModulesDoc(0);
40         JSONAssert.assertEquals(expectedJson, allModulesDoc, IGNORE_ORDER);
41     }
42
43     /**
44      * Tests the swagger document that is result of the call to the '/moduleName' endpoint.
45      */
46     @ParameterizedTest
47     @MethodSource
48     void getDocByModuleTest(final String moduleName, final String revision, final String jsonPath)
49             throws Exception {
50         final var expectedJson = getExpectedDoc("operational-document/" + jsonPath);
51         final var moduleDoc = getDocByModule(moduleName, revision, 0);
52         JSONAssert.assertEquals(expectedJson, moduleDoc, IGNORE_ORDER);
53     }
54
55     private static Stream<Arguments> getDocByModuleTest() {
56         // moduleName, revision, jsonPath
57         return Stream.of(
58             Arguments.of(ACTION_TYPES, null, "controller-action-types.json"),
59             Arguments.of(OPERATIONAL, null, "controller-operational.json")
60         );
61     }
62
63     /**
64      * Tests the swagger document that is result of the call to the '/mounts/1' endpoint.
65      */
66     @Test
67     void getMountDocTest() throws Exception {
68         final var expectedJson = getExpectedDoc("operational-document/device-all.json");
69         final var allModulesDoc = getMountDoc(0);
70         JSONAssert.assertEquals(expectedJson, allModulesDoc, IGNORE_ORDER);
71     }
72
73     /**
74      * Tests the swagger document that is result of the call to the '/mounts/1/moduleName' endpoint.
75      */
76     @ParameterizedTest
77     @MethodSource
78     void getMountDocByModuleTest(final String moduleName, final String revision, final String jsonPath)
79             throws Exception {
80         final var expectedJson = getExpectedDoc("operational-document/" + jsonPath);
81         final var moduleDoc = getMountDocByModule(moduleName, revision, 0);
82         JSONAssert.assertEquals(expectedJson, moduleDoc, IGNORE_ORDER);
83     }
84
85     private static Stream<Arguments> getMountDocByModuleTest() {
86         // moduleName, revision, jsonPath
87         return Stream.of(
88             Arguments.of(ACTION_TYPES, null, "device-action-types.json"),
89             Arguments.of(OPERATIONAL, null, "device-operational.json")
90         );
91     }
92 }