2 // ========================LICENSE_START=================================
5 // Copyright (C) 2022: Nordix Foundation
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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===================================
27 "github.com/deepmap/oapi-codegen/pkg/testutil"
28 "github.com/getkin/kin-openapi/openapi3"
29 "github.com/labstack/echo/v4"
30 "github.com/stretchr/testify/assert"
31 "oransc.org/nonrtric/capifcore/internal/common29122"
36 func Test_routing(t *testing.T) {
52 returnStatus: http.StatusOK,
57 name: "Provider path",
59 url: "/api-provider-management/v1/registrations/provider",
60 returnStatus: http.StatusNoContent,
67 url: "/published-apis/v1/apfId/service-apis/serviceId",
68 returnStatus: http.StatusNotFound,
73 name: "Discover path",
75 url: "/service-apis/v1/allServiceAPIs?api-invoker-id=api_invoker_id",
76 returnStatus: http.StatusNotFound,
83 url: "/api-invoker-management/v1/onboardedInvokers/invoker",
84 returnStatus: http.StatusNoContent,
91 url: "/capif-events/v1/subscriberId/subscriptions/subId",
92 returnStatus: http.StatusNoContent,
97 name: "Security path",
99 url: "/capif-security/v1/trustedInvokers/apiInvokerId",
100 returnStatus: http.StatusNotImplemented,
105 for _, tt := range tests {
106 t.Run(tt.name, func(t *testing.T) {
107 var result *testutil.CompletedRequest
108 if tt.args.method == "GET" {
109 result = testutil.NewRequest().Get(tt.args.url).Go(t, e)
110 } else if tt.args.method == "DELETE" {
111 result = testutil.NewRequest().Delete(tt.args.url).Go(t, e)
114 assert.Equal(t, tt.args.returnStatus, result.Code(), tt.name)
119 func TestGetSwagger(t *testing.T) {
131 name: "Provider api",
159 name: "Discover api",
166 name: "Security api",
173 for _, tt := range tests {
174 t.Run(tt.name, func(t *testing.T) {
175 result := testutil.NewRequest().Get("/swagger/"+tt.args.apiPath).Go(t, e)
176 assert.Equal(t, http.StatusOK, result.Code())
177 var swaggerResponse openapi3.T
178 err := result.UnmarshalJsonToObject(&swaggerResponse)
180 assert.Contains(t, swaggerResponse.Info.Title, tt.args.apiName)
183 invalidApi := "foobar"
184 result := testutil.NewRequest().Get("/swagger/"+invalidApi).Go(t, e)
185 assert.Equal(t, http.StatusBadRequest, result.Code())
186 var errorResponse common29122.ProblemDetails
187 err := result.UnmarshalJsonToObject(&errorResponse)
189 assert.Contains(t, *errorResponse.Cause, "Invalid API")
190 assert.Contains(t, *errorResponse.Cause, invalidApi)