aboutsummaryrefslogtreecommitdiffstats
path: root/docs/cps-stubs.rst
blob: 00577eb0d943a1842f623d342de4a4dbe4118337 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
.. This work is licensed under a Creative Commons Attribution 4.0 International License.
.. http://creativecommons.org/licenses/by/4.0
.. Copyright (C) 2023 Nordix Foundation

.. DO NOT CHANGE THIS LABEL FOR RELEASE NOTES - EVEN THOUGH IT GIVES A WARNING

.. _cpsStubs:


CPS Stubs
#########

.. toctree::
   :maxdepth: 1

NCMP Stubs
==========

The 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.

The 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.

Prerequisites
=============

Ensure you meet the following prerequisites:

1. **Required Java Installation:**
   
   Ensure that you have the required Java installed on your system. 

2. **Access to Gerrit and Maven Installation (for building CPS project locally):**

   - Ensure you have access to the ONAP Gerrit repository.
   
   - If you plan to build the CPS project locally, make sure you have Maven installed. 

Method 1: Running Stubs as an Application
=========================================

Follow these steps to run the CPS-NCMP stub application:

1. **Download Application Jar:**

   You can obtain the CPS-NCMP stub application jar in one of the following ways:

   - **Option 1: Download from Nexus Repository:**

     Download the application jar from the Nexus repository at `https://nexus.onap.org/content/repositories/releases/org/onap/cps/cps-ncmp-rest-stub-app/`_.

   - **Option 2: Build Locally:**

     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:

     ::

       cps/cps-ncmp-rest-stub/cps-ncmp-rest-stub-app/target/

2. **Run the Application:**

   After obtaining the application jar, use the following command to run it:

   .. code-block:: bash

      java -jar ./cps-ncmp-rest-stub-app-<VERSION>.jar

   Replace ``<VERSION>`` with the actual version number of the application jar.

This will start the CPS-NCMP stub application, and you can interact with it as needed.

.. _`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/

Method 2: Using Stubs in Unit Tests
===================================
1. **Add Dependency to pom.xml:**

   To include the required module in your project, add the following dependency to your `pom.xml` file:

   .. code-block:: xml

      <dependency>
        <groupId>org.onap.cps</groupId>
        <artifactId>cps-ncmp-rest-stub-service</artifactId>
        <version>VERSION</version>
     </dependency>

   Replace ``VERSION`` with the actual version number.

2. **Using Custom Response Objects:**

   If you prefer to use custom response objects instead of the built-in ones, follow these steps:

   Modify the `application.yaml` file located in your project's test resources directory (`src/test/resources`).

   Add the following property to the `application.yaml` file, specifying the directory that contains your custom response objects:
   
   .. code-block:: yaml

      stub:
          path: "/my_custom_stubs/"

   **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.

3. **Simple Test Code:**

   You may refer to the sample test code 'SampleCpsNcmpClientSpec.groovy' in the local CPS project under the following directory:

   ::

     /cps/cps-ncmp-rest-stub/cps-ncmp-rest-stub-service/src/test/groovy/org/onap/cps/ncmp/rest/stub/

   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.

**Custom Responses for Supported Endpoints**

  Only the following endpoints are supported for the first draft. To use your custom response objects for these endpoints, create the corresponding JSON files:

  - For RequestMethod.GET /v1/ch/{cm-handle}/data/ds/{datastore-name}, create "passthrough-operational-example.json".

  - For RequestMethod.POST /v1/ch/searches, create "cmHandlesSearch.json".