diff --git a/go-apps/meep-app-enablement/server/capif-mgmt/service-mgmt.go b/go-apps/meep-app-enablement/server/capif-mgmt/service-mgmt.go index 11ce04b9c50305566bdc5d8d76d3292021cd252f..bdd94e0687f97d2b3860713937e56fecf2c783f0 100644 --- a/go-apps/meep-app-enablement/server/capif-mgmt/service-mgmt.go +++ b/go-apps/meep-app-enablement/server/capif-mgmt/service-mgmt.go @@ -1107,6 +1107,8 @@ func applicationsSubscriptionsPUT(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, jsonSub) } +var HrefUrl string + func applicationsSubscriptionsPOST(w http.ResponseWriter, r *http.Request) { log.Info("applicationsSubscriptionsPOST") @@ -1192,9 +1194,9 @@ func applicationsSubscriptionsPOST(w http.ResponseWriter, r *http.Request) { errHandlerProblemDetails(w, "Failed to create subscription", http.StatusInternalServerError) return } - hrefUrl := hostUrl.String() + basePath + "applications/" + appId + "/subscriptions/" + subId + HrefUrl = hostUrl.String() + basePath + "applications/" + appId + "/subscriptions/" + subId // Send response - w.Header().Set("Location", hrefUrl) + w.Header().Set("Location", HrefUrl) w.WriteHeader(http.StatusCreated) fmt.Fprint(w, jsonSub) } diff --git a/go-apps/meep-app-enablement/server/mae_test.go b/go-apps/meep-app-enablement/server/mae_test.go index 88c438ae12fbb6f60e045c8c3075acc0d3aeed18..724bf80a157d8a51ba60bccaed61f2779bb85b9b 100644 --- a/go-apps/meep-app-enablement/server/mae_test.go +++ b/go-apps/meep-app-enablement/server/mae_test.go @@ -33,6 +33,7 @@ import ( as "github.com/InterDigitalInc/AdvantEDGE/go-apps/meep-app-enablement/server/app-support" //sm "github.com/InterDigitalInc/AdvantEDGE/go-apps/meep-app-enablement/server/service-mgmt" + capif "github.com/InterDigitalInc/AdvantEDGE/go-apps/meep-app-enablement/server/capif-mgmt" apps "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-applications" log "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger" @@ -5934,24 +5935,29 @@ func createNewApp() string { func createNewAppWithConfirmReady() string { appInstanceId := createNewApp() + time.Sleep(500 * time.Millisecond) + log.Debug("APP CREATED IN createNewAppWithConfirmReady IS: $$$ ", appInstanceId) appReadyConfirmation := as.AppReadyConfirmation{Indication: "READY"} body, err := json.Marshal(appReadyConfirmation) if err != nil { fmt.Println(err.Error()) - deleteApp(appInstanceId) - return "" + // deleteApp(appInstanceId) + // return "" } fmt.Println("body: ", string(body)) var vars = make(map[string]string) vars["appInstanceId"] = appInstanceId + fmt.Println(vars) _, err = sendRequest(http.MethodPost, "/mec_app_support/v2/applications/"+appInstanceId+"/confirm_ready", bytes.NewBuffer(body), vars, nil, nil, http.StatusNoContent, as.ApplicationsConfirmReadyPOST) if err != nil { fmt.Println(err.Error()) - deleteApp(appInstanceId) - return "" + // deleteApp(appInstanceId) + // return "" } + time.Sleep(100 * time.Millisecond) fmt.Println("sendRequest done") + fmt.Println("NO ERRORS IN createNewAppWithConfirmReady and appInstanceId is: ", appInstanceId) return appInstanceId } @@ -7536,6 +7542,9 @@ func initialiseScenario(testScenario string) { } func sendRequest(method string, url string, body io.Reader, vars map[string]string, query map[string]string, location *string, code int, f http.HandlerFunc) (string, error) { + fmt.Println("Vars in the sendRequest is: ", vars) + fmt.Println("URL in the sendRequest is: ", url) + fmt.Println("Body in the sendRequest is: ", body) req, err := http.NewRequest(method, url, body) if err != nil || req == nil { return "", err @@ -7580,3 +7589,611 @@ func sendRequest(method string, url string, body io.Reader, vars map[string]stri return string(rr.Body.String()), nil } + +var apfId string +var apiId string + +func TestAppServicesPOST(t *testing.T) { + fmt.Println("--- ", t.Name()) + log.MeepTextLogInit(t.Name()) + + initializeVars() + + err := Init() + if err != nil { + t.Fatalf("Error initializing test basic procedure") + } + err = Run() + if err != nil { + t.Fatalf("Error running test basic procedure") + } + + apfId = createNewAppWithConfirmReady() + fmt.Println("*****************************apfId is ", apfId) + var vars = make(map[string]string) + vars["apfId"] = apfId + + type RequestBody struct { + ApiName string `json:"apiName"` + AefProfiles []capif.AefProfile `json:"aefProfiles"` + VendorSpecificServiceInfo capif.MecServiceInfoCapifExt `json:"vendorSpecific-urn:etsi:mec:capifext:service-info"` + } + + transportType := capif.REST_HTTP_TransportType + serializerType := capif.JSON + mecSystemLocalityType := capif.MEC_SYSTEM_LocalityType + // Generate request body + requestBody := RequestBody{ + ApiName: "mec-xxx", + AefProfiles: []capif.AefProfile{ + { + AefId: "sandboxTransport", + Versions: []string{"3.1.1"}, + InterfaceDescriptions: &capif.OneOfTransportInfoEndpoint{ + EndPointInfoUris: capif.EndPointInfoUris{ + Uris: []string{"http://172.30.225.7/dacdasd/mep1/location/v3/"}, + }, + }, + VendorSpecificUrnetsimeccapifexttransportInfo: &capif.MecTransportInfoCapifExt{ + Name: "REST", + Type_: &transportType, + Protocol: "HTTP", + Version: "2.0", + }, + }, + }, + VendorSpecificServiceInfo: capif.MecServiceInfoCapifExt{ + Serializer: &serializerType, + State: &capif.ACTIVE_ServiceState, + ScopeOfLocality: &mecSystemLocalityType, + ConsumedLocalOnly: true, + IsLocal: true, + Category: &capif.CategoryRef{ + Href: "catalogueHref", + Id: "locationId", + Name: "Location", + Version: "v2", + }, + }, + } + + type ApiResponse struct { + ApiName string `json:"apiName"` + ApiId string `json:"apiId"` + AefProfiles []struct { + AefId string `json:"aefId"` + Versions []string `json:"versions"` + InterfaceDescriptions struct { + Uris []string `json:"uris"` + } `json:"interfaceDescriptions"` + VendorSpecificTransportInfo map[string]interface{} `json:"vendorSpecific-urn:etsi:mec:capifext:transport-info"` + } `json:"aefProfiles"` + VendorSpecificServiceInfo map[string]interface{} `json:"vendorSpecific-urn:etsi:mec:capifext:service-info"` + } + + // Marshalling the request body to JSON format + body, err := json.Marshal(requestBody) + if err != nil { + t.Fatalf("Error marshalling request body: %v", err) + } + fmt.Println("Generated Request Body: ", string(body)) + + response, err := sendRequest(http.MethodPost, "/published-apis/v1/"+apfId+"/service-apis", bytes.NewBuffer(body), vars, nil, nil, http.StatusCreated, capif.AppServicesPOST) + if err != nil { + t.Fatalf("Error sending request: %v", err) + } + + var apiResponse ApiResponse + err = json.Unmarshal([]byte(response), &apiResponse) + if err != nil { + fmt.Println("Error unmarshaling the response:", err) + return + } + apiId = apiResponse.ApiId + fmt.Println("****API ID in the TestAppServicesPOST is: ", apiId) + + fmt.Println("************************************", response) + fmt.Println("Request sent in TestAppServicesPOST") +} + +func TestServicesGET(t *testing.T) { + fmt.Println("--- ", t.Name()) + log.MeepTextLogInit(t.Name()) + + initializeVars() + + err := Init() + if err != nil { + t.Fatalf("Error initializing test basic procedure") + } + err = Run() + if err != nil { + t.Fatalf("Error running test basic procedure") + } + + results, err := sendRequest(http.MethodGet, "/service-apis/v1/allServiceAPIs", nil, nil, nil, nil, http.StatusOK, capif.ServicesGET) + if err != nil { + t.Fatalf(err.Error()) + } + fmt.Println("************************************", results) + fmt.Println("sendRequest done in TestServicesGET") +} + +func TestIndividualServicesGET(t *testing.T) { + fmt.Println("--- ", t.Name()) + log.MeepTextLogInit(t.Name()) + + initializeVars() + + err := Init() + if err != nil { + t.Fatalf("Error initializing test basic procedure") + } + err = Run() + if err != nil { + t.Fatalf("Error running test basic procedure") + } + + var vars = make(map[string]string) + vars["apfId"] = apfId + vars["serviceApiId"] = apiId + + results, err := sendRequest(http.MethodGet, "/service-apis/v1/allServiceAPIs/"+apiId, nil, vars, nil, nil, http.StatusOK, capif.AppServicesServiceIdGET) + if err != nil { + t.Fatalf(err.Error()) + } + fmt.Println("************************************", results) + fmt.Println("sendRequest done in TestIndividualServicesGET") +} + +func TestAppServicesPUT(t *testing.T) { + fmt.Println("--- ", t.Name()) + log.MeepTextLogInit(t.Name()) + + initializeVars() + + err := Init() + if err != nil { + t.Fatalf("Error initializing test basic procedure") + } + err = Run() + if err != nil { + t.Fatalf("Error running test basic procedure") + } + + fmt.Println("*****************************apfId is ", apfId) + var vars = make(map[string]string) + vars["apfId"] = apfId + vars["serviceApiId"] = apiId + + type RequestBody struct { + ApiName string `json:"apiName"` + AefProfiles []capif.AefProfile `json:"aefProfiles"` + VendorSpecificServiceInfo capif.MecServiceInfoCapifExt `json:"vendorSpecific-urn:etsi:mec:capifext:service-info"` + } + + transportType := capif.REST_HTTP_TransportType + serializerType := capif.JSON + mecSystemLocalityType := capif.MEC_SYSTEM_LocalityType + // Generate request body + requestBody := RequestBody{ + ApiName: "mec-xxx-modified", + AefProfiles: []capif.AefProfile{ + { + AefId: "sandboxTransport", + Versions: []string{"3.1.1"}, + InterfaceDescriptions: &capif.OneOfTransportInfoEndpoint{ + EndPointInfoUris: capif.EndPointInfoUris{ + Uris: []string{"http://172.30.225.7/dacdasd/mep1/location/v3/"}, + }, + }, + VendorSpecificUrnetsimeccapifexttransportInfo: &capif.MecTransportInfoCapifExt{ + Name: "REST", + Type_: &transportType, + Protocol: "HTTP", + Version: "2.0", + }, + }, + }, + VendorSpecificServiceInfo: capif.MecServiceInfoCapifExt{ + Serializer: &serializerType, + State: &capif.ACTIVE_ServiceState, + ScopeOfLocality: &mecSystemLocalityType, + ConsumedLocalOnly: true, + IsLocal: true, + Category: &capif.CategoryRef{ + Href: "catalogueHref", + Id: "locationId", + Name: "Location", + Version: "v2", + }, + }, + } + + type ApiResponse struct { + ApiName string `json:"apiName"` + AefProfiles []struct { + AefId string `json:"aefId"` + Versions []string `json:"versions"` + InterfaceDescriptions struct { + Uris []string `json:"uris"` + } `json:"interfaceDescriptions"` + VendorSpecificTransportInfo map[string]interface{} `json:"vendorSpecific-urn:etsi:mec:capifext:transport-info"` + } `json:"aefProfiles"` + VendorSpecificServiceInfo map[string]interface{} `json:"vendorSpecific-urn:etsi:mec:capifext:service-info"` + } + + // Marshalling the request body to JSON format + body, err := json.Marshal(requestBody) + if err != nil { + t.Fatalf("Error marshalling request body: %v", err) + } + fmt.Println("Generated Request Body: ", string(body)) + + // Sending POST request + // url := "http://localhost:8080/published-apis/v1/" + appInstanceId + "/service-apis" + // err = sendRequest(http.MethodPost, url, bytes.NewBuffer(body), nil) + response, err := sendRequest(http.MethodPut, "/published-apis/v1/"+apfId+"/service-apis/"+apiId, bytes.NewBuffer(body), vars, nil, nil, http.StatusOK, capif.AppServicesServiceIdPUT) + if err != nil { + t.Fatalf("Error sending request: %v", err) + } + + var apiResponse ApiResponse + err = json.Unmarshal([]byte(response), &apiResponse) + if err != nil { + fmt.Println("Error unmarshaling the response:", err) + return + } + fmt.Println("****************apfId is: ", apfId) + + fmt.Println("************************************", response) + fmt.Println("Request sent in TestAppServicesPUT") +} + +func TestAppServicesPATCH(t *testing.T) { + fmt.Println("--- ", t.Name()) + log.MeepTextLogInit(t.Name()) + + initializeVars() + + err := Init() + if err != nil { + t.Fatalf("Error initializing test basic procedure") + } + err = Run() + if err != nil { + t.Fatalf("Error running test basic procedure") + } + + fmt.Println("*****************************apfId is ", apfId) + var vars = make(map[string]string) + vars["apfId"] = apfId + vars["serviceApiId"] = apiId + + // appInfo, _ := as.GetApp(apfId) + // log.Debug("@@@@@@@STATE CHECK FROM PATCH method INTERNALLY: ", appInfo["state"]) + + type RequestBody struct { + // ApiName string `json:"apiName"` + AefProfiles []capif.AefProfile `json:"aefProfiles"` + VendorSpecificServiceInfo capif.MecServiceInfoCapifExt `json:"vendorSpecific-urn:etsi:mec:capifext:service-info"` + } + + transportType := capif.REST_HTTP_TransportType + serializerType := capif.JSON + mecSystemLocalityType := capif.MEC_SYSTEM_LocalityType + // Generate request body + requestBody := RequestBody{ + // ApiName: "mec-xxx-modified", + AefProfiles: []capif.AefProfile{ + { + AefId: "sandboxTransport", + Versions: []string{"3.2.1"}, + InterfaceDescriptions: &capif.OneOfTransportInfoEndpoint{ + EndPointInfoUris: capif.EndPointInfoUris{ + Uris: []string{"http://172.30.225.7/dacdasd/mep1/location/v3/"}, + }, + }, + VendorSpecificUrnetsimeccapifexttransportInfo: &capif.MecTransportInfoCapifExt{ + Name: "REST", + Type_: &transportType, + Protocol: "HTTP", + Version: "2.0", + }, + }, + }, + VendorSpecificServiceInfo: capif.MecServiceInfoCapifExt{ + Serializer: &serializerType, + State: &capif.ACTIVE_ServiceState, + ScopeOfLocality: &mecSystemLocalityType, + ConsumedLocalOnly: true, + IsLocal: true, + Category: &capif.CategoryRef{ + Href: "catalogueHref", + Id: "locationId", + Name: "Location", + Version: "v2", + }, + }, + } + + type ApiResponse struct { + ApiName string `json:"apiName"` + ApiId string `json:"apiId"` + AefProfiles []struct { + AefId string `json:"aefId"` + Versions []string `json:"versions"` + InterfaceDescriptions struct { + Uris []string `json:"uris"` + } `json:"interfaceDescriptions"` + VendorSpecificTransportInfo map[string]interface{} `json:"vendorSpecific-urn:etsi:mec:capifext:transport-info"` + } `json:"aefProfiles"` + VendorSpecificServiceInfo map[string]interface{} `json:"vendorSpecific-urn:etsi:mec:capifext:service-info"` + } + + // Marshalling the request body to JSON format + body, err := json.Marshal(requestBody) + if err != nil { + t.Fatalf("Error marshalling request body: %v", err) + } + fmt.Println("Generated Request Body: ", string(body)) + + response, err := sendRequest(http.MethodPatch, "/published-apis/v1/"+apfId+"/service-apis/"+apiId, bytes.NewBuffer(body), vars, nil, nil, http.StatusOK, capif.AppServicesServiceIdPATCH) + if err != nil { + t.Fatalf("Error sending request: %v", err) + } + + fmt.Println("************************************", response) + fmt.Println("Request sent in TestAppServicesPATCH") +} + +var SubscriptionID string + +func TestAppSubscriptionPOST(t *testing.T) { + fmt.Println("--- ", t.Name()) + log.MeepTextLogInit(t.Name()) + + initializeVars() + + err := Init() + if err != nil { + t.Fatalf("Error initializing test basic procedure") + } + err = Run() + if err != nil { + t.Fatalf("Error running test basic procedure") + } + + expected_href := as.LinkType{Href: "/testScenario/mec_service_mgmt/v1/applications/" + apfId + "/subscriptions/"} + + var vars = make(map[string]string) + vars["subscriberId"] = apfId + // vars["serviceApiId"] = apiId + + type EventFilter struct { + ApiIds []string `json:"apiIds"` + } + + type RequestBody struct { + NotificationDestination string `json:"notificationDestination"` + Events []string `json:"events"` + EventFilters []EventFilter `json:"eventFilters"` + RequestTestNotification bool `json:"requestTestNotification"` + } + type LinkType struct { + // URI referring to a resource + Href string `json:"href,omitempty"` + } + type Self struct { + Self *LinkType `json:"self"` + } + type ResponseBody struct { + Events []string `json:"events"` + EventFilters []EventFilter `json:"eventFilters"` + NotificationDestination string `json:"notificationDestination"` + RequestTestNotification bool `json:"requestTestNotification"` + Links *Self `json:"_links"` + } + + // Define the request body + requestBody := RequestBody{ + NotificationDestination: "http://my.callback.com/mec_capif_mgmt_ser_availabilities/some-id", + Events: []string{"SERVICE_API_UNAVAILABLE"}, + EventFilters: []EventFilter{{ApiIds: []string{apiId}}}, + RequestTestNotification: true, + } + + // Marshal the struct to JSON + body, err := json.Marshal(requestBody) + if err != nil { + fmt.Println("Error marshalling JSON:", err) + } + + fmt.Println("Generated Request Body: ", string(body)) + + results, err := sendRequest(http.MethodPost, "/capif-events/v1/{subscriberId}/subscriptions", bytes.NewBuffer(body), vars, nil, &expected_href.Href, http.StatusCreated, capif.ApplicationsSubscriptionsPOST) + if err != nil { + t.Fatalf(err.Error()) + } + + var responseBody ResponseBody + err = json.Unmarshal([]byte(results), &responseBody) + if err != nil { + fmt.Println("Error unmarshalling JSON response:", err) + } else { + fmt.Println("Events:", responseBody.Events) + fmt.Println("EventFilters:", responseBody.EventFilters) + fmt.Println("Notification Destination:", responseBody.NotificationDestination) + fmt.Println("Request Test Notification:", responseBody.RequestTestNotification) + } + parts := strings.Split(capif.HrefUrl, "/subscriptions/") + SubscriptionID = parts[1] + fmt.Println("*******Location HEADER is: ", capif.HrefUrl) + fmt.Println("********* Subscription ID from the POST method Location header is: ", SubscriptionID) + + fmt.Println("************************************", results) + fmt.Println("sendRequest done in TestAppSubscriptionPOST") + time.Sleep(100 * time.Millisecond) + +} + +func TestAppSubscriptionPUT(t *testing.T) { + fmt.Println("--- ", t.Name()) + log.MeepTextLogInit(t.Name()) + + initializeVars() + + err := Init() + if err != nil { + t.Fatalf("Error initializing test basic procedure") + } + err = Run() + if err != nil { + t.Fatalf("Error running test basic procedure") + } + + var vars = make(map[string]string) + vars["subscriberId"] = apfId + vars["subscriptionId"] = SubscriptionID + + type EventFilter struct { + ApiIds []string `json:"apiIds"` + } + + type RequestBody struct { + NotificationDestination string `json:"notificationDestination"` + Events []string `json:"events"` + EventFilters []EventFilter `json:"eventFilters"` + RequestTestNotification bool `json:"requestTestNotification"` + } + + // Define the request body + requestBody := RequestBody{ + NotificationDestination: "http://my.callback.com/mec_capif_mgmt_ser_availabilities/some-id-put", + Events: []string{"SERVICE_API_UNAVAILABLE"}, + EventFilters: []EventFilter{{ApiIds: []string{apiId}}}, + RequestTestNotification: true, + } + + // Marshal the struct to JSON + body, err := json.Marshal(requestBody) + if err != nil { + fmt.Println("Error marshalling JSON:", err) + } + + fmt.Println("Generated Request Body: ", string(body)) + + results, err := sendRequest(http.MethodPut, "/capif-events/v1/{subscriberId}/subscriptions/{subscriptionId}", bytes.NewBuffer(body), vars, nil, nil, http.StatusOK, capif.ApplicationsSubscriptionsPUT) + if err != nil { + t.Fatalf(err.Error()) + } + fmt.Println("************************************", results) + fmt.Println("sendRequest done in TestAppSubscriptionPUT") + +} + +func TestAppSubscriptionPATCH(t *testing.T) { + fmt.Println("--- ", t.Name()) + log.MeepTextLogInit(t.Name()) + + initializeVars() + + err := Init() + if err != nil { + t.Fatalf("Error initializing test basic procedure") + } + err = Run() + if err != nil { + t.Fatalf("Error running test basic procedure") + } + + var vars = make(map[string]string) + vars["subscriberId"] = apfId + vars["subscriptionId"] = SubscriptionID + + type EventFilter struct { + ApiIds []string `json:"apiIds"` + } + + type RequestBody struct { + NotificationDestination string `json:"notificationDestination"` + Events []string `json:"events"` + EventFilters []EventFilter `json:"eventFilters"` + } + + // Define the request body + requestBody := RequestBody{ + NotificationDestination: "http://my.callback.com/mec_capif_mgmt_ser_availabilities/some-id-patch", + Events: []string{"SERVICE_API_UNAVAILABLE"}, + EventFilters: []EventFilter{{ApiIds: []string{apiId}}}, + } + + // Marshal the struct to JSON + body, err := json.Marshal(requestBody) + if err != nil { + fmt.Println("Error marshalling JSON:", err) + } + + fmt.Println("Generated Request Body: ", string(body)) + + results, err := sendRequest(http.MethodPatch, "/capif-events/v1/{subscriberId}/subscriptions/{subscriptionId}", bytes.NewBuffer(body), vars, nil, nil, http.StatusOK, capif.ApplicationsSubscriptionsPUT) + if err != nil { + t.Fatalf(err.Error()) + } + fmt.Println("************************************", results) + fmt.Println("sendRequest done in TestAppSubscriptionPATCH") + +} + +func TestAppSubscriptionDELETE(t *testing.T) { + fmt.Println("--- ", t.Name()) + log.MeepTextLogInit(t.Name()) + + initializeVars() + + err := Init() + if err != nil { + t.Fatalf("Error initializing test basic procedure") + } + err = Run() + if err != nil { + t.Fatalf("Error running test basic procedure") + } + + var vars = make(map[string]string) + vars["subscriberId"] = apfId + vars["subscriptionId"] = SubscriptionID + + _, err = sendRequest(http.MethodDelete, "/capif-events/v1/{subscriberId}/subscriptions/{subscriptionId}", nil, vars, nil, nil, http.StatusNoContent, capif.ApplicationsSubscriptionDELETE) + if err != nil { + t.Fatalf(err.Error()) + } + fmt.Println("sendRequest done in TestAppSubscriptionDELETE") + +} + +func TestIndividualAppServicesDELETE(t *testing.T) { + fmt.Println("--- ", t.Name()) + log.MeepTextLogInit(t.Name()) + + initializeVars() + + err := Init() + if err != nil { + t.Fatalf("Error initializing test basic procedure") + } + err = Run() + if err != nil { + t.Fatalf("Error running test basic procedure") + } + + var vars = make(map[string]string) + vars["apfId"] = apfId + vars["serviceApiId"] = apiId + + _, err = sendRequest(http.MethodDelete, "/published-apis/v1/{apfId}/service-apis/{serviceApiId}", nil, vars, nil, nil, http.StatusNoContent, capif.AppServicesServiceIdDELETE) + if err != nil { + t.Fatalf(err.Error()) + } + fmt.Println("sendRequest done in TestIndividualAppServicesDELETE") +} \ No newline at end of file