blob: 00577eb0d943a1842f623d342de4a4dbe4118337 [file] [log] [blame]
ToineSiebelink74eed2c2023-08-31 17:38:52 +01001.. This work is licensed under a Creative Commons Attribution 4.0 International License.
2.. http://creativecommons.org/licenses/by/4.0
3.. Copyright (C) 2023 Nordix Foundation
4
5.. DO NOT CHANGE THIS LABEL FOR RELEASE NOTES - EVEN THOUGH IT GIVES A WARNING
6
7.. _cpsStubs:
8
9
10CPS Stubs
11#########
12
13.. toctree::
14 :maxdepth: 1
15
waqas.ikramad6021f2023-10-04 10:05:09 +010016NCMP Stubs
17==========
18
19The CPS NCMP stub module provides the capability to create dynamic and customizable stubs, offering control over the responses generated for each endpoint. This capability ensures that client interactions adhere to a specified NCMP interface, enabling comprehensive testing and validation of your applications.
20
21The NCMP stub RestController is an extended implementation of the actual NCMP interface. It can be deployed as part of the application JAR or within a SpringBootTest JUnit environment, allowing you to define dynamic responses for each endpoint and allowing testing against real stub interfaces.
ToineSiebelink74eed2c2023-08-31 17:38:52 +010022
23Prerequisites
24=============
waqas.ikramad6021f2023-10-04 10:05:09 +010025
26Ensure you meet the following prerequisites:
27
281. **Required Java Installation:**
29
30 Ensure that you have the required Java installed on your system.
31
322. **Access to Gerrit and Maven Installation (for building CPS project locally):**
33
34 - Ensure you have access to the ONAP Gerrit repository.
35
36 - If you plan to build the CPS project locally, make sure you have Maven installed.
ToineSiebelink74eed2c2023-08-31 17:38:52 +010037
38Method 1: Running Stubs as an Application
39=========================================
waqas.ikramad6021f2023-10-04 10:05:09 +010040
41Follow these steps to run the CPS-NCMP stub application:
42
431. **Download Application Jar:**
44
45 You can obtain the CPS-NCMP stub application jar in one of the following ways:
46
47 - **Option 1: Download from Nexus Repository:**
48
49 Download the application jar from the Nexus repository at `https://nexus.onap.org/content/repositories/releases/org/onap/cps/cps-ncmp-rest-stub-app/`_.
50
51 - **Option 2: Build Locally:**
52
53 To build the CPS project locally, navigate to the project's root directory. Once there, you can build the project using :code:`mvn clean install`, and the application CPS-NCMP stub application jar can be found in the following location:
54
55 ::
56
57 cps/cps-ncmp-rest-stub/cps-ncmp-rest-stub-app/target/
58
592. **Run the Application:**
60
61 After obtaining the application jar, use the following command to run it:
62
63 .. code-block:: bash
64
65 java -jar ./cps-ncmp-rest-stub-app-<VERSION>.jar
66
67 Replace ``<VERSION>`` with the actual version number of the application jar.
68
69This will start the CPS-NCMP stub application, and you can interact with it as needed.
70
71.. _`https://nexus.onap.org/content/repositories/releases/org/onap/cps/cps-ncmp-rest-stub-app/`: https://nexus.onap.org/content/repositories/releases/org/onap/cps/cps-ncmp-rest-stub-app/
ToineSiebelink74eed2c2023-08-31 17:38:52 +010072
73Method 2: Using Stubs in Unit Tests
74===================================
waqas.ikramad6021f2023-10-04 10:05:09 +0100751. **Add Dependency to pom.xml:**
ToineSiebelink74eed2c2023-08-31 17:38:52 +010076
waqas.ikramad6021f2023-10-04 10:05:09 +010077 To include the required module in your project, add the following dependency to your `pom.xml` file:
ToineSiebelink74eed2c2023-08-31 17:38:52 +010078
waqas.ikramad6021f2023-10-04 10:05:09 +010079 .. code-block:: xml
80
81 <dependency>
82 <groupId>org.onap.cps</groupId>
83 <artifactId>cps-ncmp-rest-stub-service</artifactId>
84 <version>VERSION</version>
85 </dependency>
86
87 Replace ``VERSION`` with the actual version number.
88
892. **Using Custom Response Objects:**
90
91 If you prefer to use custom response objects instead of the built-in ones, follow these steps:
92
93 Modify the `application.yaml` file located in your project's test resources directory (`src/test/resources`).
94
95 Add the following property to the `application.yaml` file, specifying the directory that contains your custom response objects:
96
97 .. code-block:: yaml
98
99 stub:
100 path: "/my_custom_stubs/"
101
102 **Note:** Custom response objects can be placed in the `src/test/resources` directory of your project under the directory defined in above property. Refer to the `examples <https://github.com/onap/cps/tree/master/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/main/resources/stubs>`_ included in the CPS source repository for reference.
103
1043. **Simple Test Code:**
105
106 You may refer to the sample test code 'SampleCpsNcmpClientSpec.groovy' in the local CPS project under the following directory:
107
108 ::
109
110 /cps/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/test/groovy/org/onap/cps/ncmp/rest/stub/
111
112 Alternatively, you can refer to the `example <https://github.com/onap/cps/tree/master/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/test/groovy/org/onap/cps/ncmp/rest/stub>`_ included in the CPS source repository.
113
114**Custom Responses for Supported Endpoints**
115
116 Only the following endpoints are supported for the first draft. To use your custom response objects for these endpoints, create the corresponding JSON files:
117
118 - For RequestMethod.GET /v1/ch/{cm-handle}/data/ds/{datastore-name}, create "passthrough-operational-example.json".
119
120 - For RequestMethod.POST /v1/ch/searches, create "cmHandlesSearch.json".