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,
89 name: "Security path",
91 url: "/capif-security/v1/trustedInvokers/apiInvokerId",
92 returnStatus: http.StatusNotImplemented,
97 for _, tt := range tests {
98 t.Run(tt.name, func(t *testing.T) {
99 var result *testutil.CompletedRequest
100 if tt.args.method == "GET" {
101 result = testutil.NewRequest().Get(tt.args.url).Go(t, e)
102 } else if tt.args.method == "DELETE" {
103 result = testutil.NewRequest().Delete(tt.args.url).Go(t, e)
106 assert.Equal(t, tt.args.returnStatus, result.Code(), tt.name)
111 func TestGetSwagger(t *testing.T) {
123 name: "Provider api",
144 name: "Discover api",
151 name: "Security api",
158 for _, tt := range tests {
159 t.Run(tt.name, func(t *testing.T) {
160 result := testutil.NewRequest().Get("/swagger/"+tt.args.apiPath).Go(t, e)
161 assert.Equal(t, http.StatusOK, result.Code())
162 var swaggerResponse openapi3.T
163 err := result.UnmarshalJsonToObject(&swaggerResponse)
165 assert.Contains(t, swaggerResponse.Info.Title, tt.args.apiName)
168 invalidApi := "foobar"
169 result := testutil.NewRequest().Get("/swagger/"+invalidApi).Go(t, e)
170 assert.Equal(t, http.StatusBadRequest, result.Code())
171 var errorResponse common29122.ProblemDetails
172 err := result.UnmarshalJsonToObject(&errorResponse)
174 assert.Contains(t, *errorResponse.Cause, "Invalid API")
175 assert.Contains(t, *errorResponse.Cause, invalidApi)