NONRTRIC-946: Servicemanager - mock kong and capif as library
[nonrtric/plt/sme.git] / servicemanager / mockkong / kong_mock.go
1 // -
2 //   ========================LICENSE_START=================================
3 //   O-RAN-SC
4 //   %%
5 //   Copyright (C) 2024: OpenInfra Foundation Europe
6 //   %%
7 //   Licensed under the Apache License, Version 2.0 (the "License");
8 //   you may not use this file except in compliance with the License.
9 //   You may obtain a copy of the License at
10 //
11 //        http://www.apache.org/licenses/LICENSE-2.0
12 //
13 //   Unless required by applicable law or agreed to in writing, software
14 //   distributed under the License is distributed on an "AS IS" BASIS,
15 //   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 //   See the License for the specific language governing permissions and
17 //   limitations under the License.
18 //   ========================LICENSE_END===================================
19 //
20
21 package mockKong
22
23 import (
24         "io"
25         "net/http"
26
27         echo "github.com/labstack/echo/v4"
28 )
29
30 func RegisterHandlers(e *echo.Echo) {
31         // Handle Kong service and route endpoint mock responses here
32         e.POST("/services", func(c echo.Context) error {
33                 body, err := io.ReadAll(c.Request().Body)
34                 if err != nil {
35                         return c.String(http.StatusInternalServerError, "Error reading request body")
36                 }
37                 return c.String(http.StatusCreated, string(body))
38         })
39
40         e.POST("/services/api_id_apiName_helloworld/routes", func(c echo.Context) error {
41                 body, err := io.ReadAll(c.Request().Body)
42                 if err != nil {
43                         return c.String(http.StatusInternalServerError, "Error reading request body")
44                 }
45                 return c.String(http.StatusCreated, string(body))
46         })
47
48         e.POST("/services/api_id_apiName1_helloworld/routes", func(c echo.Context) error {
49                 body, err := io.ReadAll(c.Request().Body)
50                 if err != nil {
51                         return c.String(http.StatusInternalServerError, "Error reading request body")
52                 }
53                 return c.String(http.StatusCreated, string(body))
54         })
55
56         e.POST("/services/api_id_apiName2_helloworld/routes", func(c echo.Context) error {
57                 body, err := io.ReadAll(c.Request().Body)
58                 if err != nil {
59                         return c.String(http.StatusInternalServerError, "Error reading request body")
60                 }
61                 return c.String(http.StatusCreated, string(body))
62         })
63
64         e.POST("/services/api_id_apiName1_app/routes", func(c echo.Context) error {
65                 body, err := io.ReadAll(c.Request().Body)
66                 if err != nil {
67                         return c.String(http.StatusInternalServerError, "Error reading request body")
68                 }
69                 return c.String(http.StatusCreated, string(body))
70         })
71
72         e.POST("/services/api_id_apiName2_app/routes", func(c echo.Context) error {
73                 body, err := io.ReadAll(c.Request().Body)
74                 if err != nil {
75                         return c.String(http.StatusInternalServerError, "Error reading request body")
76                 }
77                 return c.String(http.StatusCreated, string(body))
78         })
79
80         e.POST("/routes", func(c echo.Context) error {
81                 body, err := io.ReadAll(c.Request().Body)
82                 if err != nil {
83                         return c.String(http.StatusInternalServerError, "Error reading request body")
84                 }
85                 return c.String(http.StatusCreated, string(body))
86         })
87
88         e.GET("/services", func(c echo.Context) error {
89                 return c.String(http.StatusOK, "{}")
90         })
91
92         e.GET("/routes", func(c echo.Context) error {
93                 return c.String(http.StatusOK, "{}")
94         })
95
96         e.DELETE("/routes/api_id_apiName_helloworld", func(c echo.Context) error {
97                 return c.NoContent(http.StatusNoContent)
98         })
99
100         e.DELETE("/services/api_id_apiName_helloworld", func(c echo.Context) error {
101                 return c.NoContent(http.StatusNoContent)
102         })
103
104         e.DELETE("/routes/api_id_apiName1_helloworld", func(c echo.Context) error {
105                 return c.NoContent(http.StatusNoContent)
106         })
107
108         e.DELETE("/routes/api_id_apiName2_helloworld", func(c echo.Context) error {
109                 return c.NoContent(http.StatusNoContent)
110         })
111
112         e.DELETE("/routes/api_id_apiName1_app", func(c echo.Context) error {
113                 return c.NoContent(http.StatusNoContent)
114         })
115
116         e.DELETE("/routes/api_id_apiName2_app", func(c echo.Context) error {
117                 return c.NoContent(http.StatusNoContent)
118         })
119
120         e.DELETE("/services/api_id_apiName1_helloworld", func(c echo.Context) error {
121                 return c.NoContent(http.StatusNoContent)
122         })
123
124         e.DELETE("/services/api_id_apiName2_helloworld", func(c echo.Context) error {
125                 return c.NoContent(http.StatusNoContent)
126         })
127
128         e.DELETE("/services/api_id_apiName1_app", func(c echo.Context) error {
129                 return c.NoContent(http.StatusNoContent)
130         })
131
132         e.DELETE("/services/api_id_apiName2_app", func(c echo.Context) error {
133                 return c.NoContent(http.StatusNoContent)
134         })
135 }