Loading go-apps/meep-vis/server/vis_test.go +234 −84 Original line number Diff line number Diff line Loading @@ -789,7 +789,7 @@ func validateUuUnicastProvisioningInfo(received UuUnicastProvisioningInfo, expec return true } func testSubscriptionPost(t *testing.T) string { func testSubscriptionPost(t *testing.T) (string, string) { /****************************** * expected response section Loading @@ -799,32 +799,44 @@ func testSubscriptionPost(t *testing.T) string { // MEC-030 Clause 7.8.3.4 expected_subscriptionType := "V2xMsgSubscription" expected_callbackReference := "MyCallback" expected_href := LinkType{Href: "http://meAppServer.example.com/vis/v2/subscriptions/123"} expected_href := LinkType{Href: "http://meAppServer.example.com/vis/v2/subscriptions/1"} expected_self := Links{Self: &expected_href} //expected_link := V2xMsgSubscription{Links: &expected_self} expected_msgType := []MsgType{DENM, CAM} //expected_stdOrganization := expected_filterCriteria := V2xMsgSubscriptionFilterCriteria{StdOrganization: "ETSI", MsgType: expected_msgType} expected_v2xMsgSubscription := V2xMsgSubscription{Links: &expected_self, CallbackReference: expected_callbackReference, ExpiryDeadline: nil, FilterCriteria: &expected_filterCriteria, RequestTestNotification: false, SubscriptionType: expected_subscriptionType, WebsockNotifConfig: nil} expected_v2xMsgSubscription_str, err := json.Marshal(expected_v2xMsgSubscription) expected_expiryDeadline := TimeStamp{Seconds: 1977836800, NanoSeconds: 0} expected_v2xMsgSubscription := V2xMsgSubscription{ SubscriptionType: expected_subscriptionType, CallbackReference: expected_callbackReference, Links: &expected_self, FilterCriteria: &expected_filterCriteria, ExpiryDeadline: &expected_expiryDeadline, RequestTestNotification: false, WebsockNotifConfig: nil, } expectedResponseStr, err := json.Marshal(expected_v2xMsgSubscription) if err != nil { t.Fatalf(err.Error()) } fmt.Println("expected_v2xMsgSubscription_str: ", string(expected_v2xMsgSubscription_str)) fmt.Println("expected_v2xMsgSubscription_str: ", string(expectedResponseStr)) /****************************** * expected request section * request body section ******************************/ subscriptionType := "V2xMsgSubscription" callbackReference := "MyCallback" msgType := []MsgType{DENM, CAM} //expected_stdOrganization := filterCriteria := V2xMsgSubscriptionFilterCriteria{StdOrganization: "ETSI", MsgType: msgType} testv2xMsgSubscription := V2xMsgSubscription{CallbackReference: callbackReference, FilterCriteria: &filterCriteria, RequestTestNotification: false, SubscriptionType: subscriptionType, WebsockNotifConfig: nil} body, err := json.Marshal(testv2xMsgSubscription) expiryDeadline := TimeStamp{Seconds: 1977836800, NanoSeconds: 0} requestedV2xMsgSubscription := V2xMsgSubscription{ SubscriptionType: subscriptionType, CallbackReference: callbackReference, FilterCriteria: &filterCriteria, ExpiryDeadline: &expiryDeadline, RequestTestNotification: false, WebsockNotifConfig: nil, } body, err := json.Marshal(requestedV2xMsgSubscription) if err != nil { t.Fatalf(err.Error()) } Loading @@ -834,28 +846,51 @@ func testSubscriptionPost(t *testing.T) string { * request execution section ******************************/ rr, err := sendRequest(http.MethodPost, "/subscription", bytes.NewBuffer(body), nil, nil, http.StatusCreated, SubPOST) rr, err := sendRequest(http.MethodPost, "/vis/v2/subscriptions", bytes.NewBuffer(body), nil, nil, http.StatusCreated, SubPOST) if err != nil { t.Fatalf(err.Error()) } log.Info("sendRequest done") log.Info("Request sent") var respBody V2xMsgSubscription err = json.Unmarshal([]byte(rr), &respBody) if err != nil { t.Fatalf(err.Error()) } fmt.Println("respBody: ", respBody) if rr != string(expected_v2xMsgSubscription_str) { t.Fatalf(err.Error()) /****************************** * Comparing responses ******************************/ if expected_v2xMsgSubscription.SubscriptionType != respBody.SubscriptionType { t.Fatalf("Failed to get expected response") } if &expected_v2xMsgSubscription.FilterCriteria != &respBody.FilterCriteria { t.Fatalf("Failed to get expected response") } if expected_v2xMsgSubscription.CallbackReference != respBody.CallbackReference { t.Fatalf("Failed to get expected response") } if *expected_v2xMsgSubscription.ExpiryDeadline != *respBody.ExpiryDeadline { t.Fatalf("Failed to get expected response") } if *expected_v2xMsgSubscription.Links != *respBody.Links { t.Fatalf("Failed to get expected response") } if respBody.WebsockNotifConfig != nil { t.Fatalf("Failed to get expected response") } if respBody.RequestTestNotification != false { t.Fatalf("Failed to get expected response") } log.Info("Received expected response for POST method") subscriptionId := strings.Split(respBody.Links.Self.Href, "/") cleanSubscriptionId := subscriptionId[len(subscriptionId)-1] return string(expected_v2xMsgSubscription_str) return cleanSubscriptionId, string(expectedResponseStr) } func TestSubscriptionV2XMsgSubscription(t *testing.T) { func TestSuccessV2XMsgSubscription(t *testing.T) { fmt.Println("--- ", t.Name()) log.MeepTextLogInit(t.Name()) Loading @@ -877,22 +912,20 @@ func TestSubscriptionV2XMsgSubscription(t *testing.T) { updateScenario("mobility1") // POST expectedGetResponse := testSubscriptionPost(t) subscriptionId, expectedGetResponse := testSubscriptionPost(t) //GET Subscription //expectedListResourceURL := "/" + testScenarioName + "vis/v2/subscriptions" //expectedResourceURL := expectedListResourceURL + "?subscription_type=v2x_msg" subscriptionTypeQuery := V2X_MSG //GET Subscriptions subscriptionTypeQuery := "v2x_msg" testSubscriptionsGet(t, subscriptionTypeQuery, expectedGetResponse) // GET Individual Subscription testIndividualSubscriptionGet(t, expectedGetResponse) testIndividualSubscriptionGet(t, subscriptionId, expectedGetResponse) // PUT testIndividualSubscriptionPut(t, true) testIndividualSubscriptionPut(t, subscriptionId, true) // DELETE testIndividualSubscriptionDelete(t, true) testIndividualSubscriptionDelete(t, subscriptionId, true) /****************************** * back to initial state section Loading @@ -901,6 +934,43 @@ func TestSubscriptionV2XMsgSubscription(t *testing.T) { } func TestFailV2XMsgSubscription(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("Set a scenario") initialiseScenario(testScenario) time.Sleep(1000 * time.Millisecond) updateScenario("mobility1") // GET testIndividualSubscriptionGet(t, "invalidSubscriptionId", "") // PUT _ = testIndividualSubscriptionPut(t, "invalidSubscriptionId", false) // DELETE testIndividualSubscriptionDelete(t, "invalidSubscriptionId", false) /****************************** * back to initial state section ******************************/ terminateScenario() } //Generic GET function for any subscription type func testSubscriptionsGet(t *testing.T, subscriptionTypeQuery string, expectedResponse string) { Loading @@ -920,9 +990,11 @@ func testSubscriptionsGet(t *testing.T, subscriptionTypeQuery string, expectedRe /****************************** * request execution section ******************************/ var err error if expectedResponse == "" { _, err = sendRequest(http.MethodGet, "vis/v2/subscriptions", nil, nil, queryParam, http.StatusNotFound, SubGET) _, err = sendRequest(http.MethodGet, "/vis/v2/subscriptions", nil, nil, queryParam, http.StatusNotFound, SubGET) if err != nil { t.Fatalf("Failed to get expected response") } Loading @@ -939,7 +1011,7 @@ func testSubscriptionsGet(t *testing.T, subscriptionTypeQuery string, expectedRe } } func testIndividualSubscriptionGet(t *testing.T, expectedResponse string) { func testIndividualSubscriptionGet(t *testing.T, subscriptionId string, expectedResponse string) { /****************************** * expected response section Loading @@ -950,80 +1022,117 @@ func testIndividualSubscriptionGet(t *testing.T, expectedResponse string) { * request vars section ******************************/ vars := make(map[string]string) vars["subscriptionId"] = "1" vars["subscriptionId"] = subscriptionId /****************************** * request execution section ******************************/ var err error if expectedResponse == "" { _, err = sendRequest(http.MethodGet, "/vis/v2/subscriptions/1", nil, vars, nil, http.StatusNotFound, IndividualSubscriptionGET) _, err = sendRequest(http.MethodGet, "/vis/v2/subscriptions", nil, vars, nil, http.StatusNotFound, IndividualSubscriptionGET) if err != nil { t.Fatalf("Failed to get expected response") } } else { rr, err := sendRequest(http.MethodGet, "/vis/v2/subscriptions/1", nil, vars, nil, http.StatusOK, IndividualSubscriptionGET) var expectedResp V2xMsgSubscription err := json.Unmarshal([]byte(expectedResponse), &expectedResp) if err != nil { t.Fatalf("Failed to get expected response") } if rr != expectedResponse { rr, err := sendRequest(http.MethodGet, "/vis/v2/subscriptions", nil, vars, nil, http.StatusOK, IndividualSubscriptionGET) if err != nil { t.Fatalf("Failed to get expected response") } var respBody V2xMsgSubscription err = json.Unmarshal([]byte(rr), &respBody) if err != nil { t.Fatalf("Failed to get expected response") } if expectedResp.SubscriptionType != respBody.SubscriptionType { t.Fatalf("Failed to get expected response") } if &expectedResp.FilterCriteria != &respBody.FilterCriteria { t.Fatalf("Failed to get expected response") } if expectedResp.CallbackReference != respBody.CallbackReference { t.Fatalf("Failed to get expected response") } if *expectedResp.ExpiryDeadline != *respBody.ExpiryDeadline { t.Fatalf("Failed to get expected response") } if *expectedResp.Links != *respBody.Links { t.Fatalf("Failed to get expected response") } if respBody.WebsockNotifConfig != nil { t.Fatalf("Failed to get expected response") } if respBody.RequestTestNotification != false { t.Fatalf("Failed to get expected response") } log.Info("Received expected response for GET method") } } func testIndividualSubscriptionDelete(t *testing.T, expectSuccess bool) { func testIndividualSubscriptionDelete(t *testing.T, subscriptionId string, expectSuccess bool) { /****************************** * request vars section ******************************/ vars := make(map[string]string) vars["subscriptionId"] = "1" vars["subscriptionId"] = subscriptionId /****************************** * request execution section ******************************/ if expectSuccess { _, err := sendRequest(http.MethodDelete, "/vis/v2/subscriptions/1", nil, vars, nil, http.StatusNoContent, IndividualSubscriptionDELETE) _, err := sendRequest(http.MethodDelete, "/vis/v2/subscriptions", nil, vars, nil, http.StatusNoContent, IndividualSubscriptionDELETE) if err != nil { t.Fatalf("Failed to get expected response") } } else { _, err := sendRequest(http.MethodDelete, "/vis/v2/subscriptions/1", nil, vars, nil, http.StatusNotFound, IndividualSubscriptionDELETE) _, err := sendRequest(http.MethodDelete, "/vis/v2/subscriptions", nil, vars, nil, http.StatusNotFound, IndividualSubscriptionDELETE) if err != nil { t.Fatalf("Failed to get expected response") } } } func testIndividualSubscriptionPut(t *testing.T, expectSuccess bool) string { func testIndividualSubscriptionPut(t *testing.T, subscriptionId string, expectSuccess bool) string { /****************************** * expected response section ******************************/ expected_subscriptionType := "V2xMsgSubscription" expected_callbackReference := "MyCallback" expected_href := LinkType{Href: "http://meAppServer.example.com/vis/v2/subscriptions/123"} expected_href := LinkType{Href: "http://meAppServer.example.com/vis/v2/subscriptions/1"} expected_self := Links{Self: &expected_href} //expected_link := V2xMsgSubscription{Links: &expected_self} expected_msgType := []MsgType{DENM, CAM} //expected_stdOrganization := expected_filterCriteria := V2xMsgSubscriptionFilterCriteria{StdOrganization: "ETSI", MsgType: expected_msgType} expected_v2xMsgSubscription := V2xMsgSubscription{Links: &expected_self, CallbackReference: expected_callbackReference, ExpiryDeadline: nil, FilterCriteria: &expected_filterCriteria, RequestTestNotification: false, SubscriptionType: expected_subscriptionType, WebsockNotifConfig: nil} expected_v2xMsgSubscriptionPut_str, err := json.Marshal(expected_v2xMsgSubscription) expected_expiryDeadline := TimeStamp{Seconds: 1977836800, NanoSeconds: 0} expected_v2xMsgSubscription := V2xMsgSubscription{ SubscriptionType: expected_subscriptionType, CallbackReference: expected_callbackReference, Links: &expected_self, FilterCriteria: &expected_filterCriteria, ExpiryDeadline: &expected_expiryDeadline, RequestTestNotification: false, WebsockNotifConfig: nil, } expectedResponseStr, err := json.Marshal(expected_v2xMsgSubscription) if err != nil { t.Fatalf(err.Error()) } fmt.Println("expected_v2xMsgSubscriptionPut_str: ", string(expected_v2xMsgSubscriptionPut_str)) fmt.Println("expectedResponseStr: ", string(expectedResponseStr)) /****************************** * request vars section ******************************/ vars := make(map[string]string) vars["subscriptionId"] = "1" vars["subscriptionId"] = subscriptionId /****************************** * request body section Loading @@ -1031,39 +1140,75 @@ func testIndividualSubscriptionPut(t *testing.T, expectSuccess bool) string { subscriptionType := "V2xMsgSubscription" callbackReference := "MyCallback" href := LinkType{Href: "http://meAppServer.example.com/vis/v2/subscriptions/1"} self := Links{Self: &href} msgType := []MsgType{DENM, CAM} //expected_stdOrganization := filterCriteria := V2xMsgSubscriptionFilterCriteria{StdOrganization: "ETSI", MsgType: msgType} testv2xMsgSubscription := V2xMsgSubscription{CallbackReference: callbackReference, FilterCriteria: &filterCriteria, RequestTestNotification: false, SubscriptionType: subscriptionType, WebsockNotifConfig: nil} body, err := json.Marshal(testv2xMsgSubscription) expiryDeadline := TimeStamp{Seconds: 1977836800, NanoSeconds: 0} requestedv2xMsgSubscription := V2xMsgSubscription{ SubscriptionType: subscriptionType, CallbackReference: callbackReference, Links: &self, FilterCriteria: &filterCriteria, ExpiryDeadline: &expiryDeadline, RequestTestNotification: false, WebsockNotifConfig: nil, } body, err := json.Marshal(requestedv2xMsgSubscription) if err != nil { t.Fatalf(err.Error()) } fmt.Println("body: ", string(body)) /****************************** * request execution section * request queries section ******************************/ rr, err := sendRequest(http.MethodPut, "/vis/v2/subscriptions/1", bytes.NewBuffer(body), nil, nil, http.StatusOK, IndividualSubscriptionPUT) /****************************** * request execution section ******************************/ if expectSuccess { rr, err := sendRequest(http.MethodPut, "/vis/v2/subscriptions", bytes.NewBuffer(body), nil, nil, http.StatusOK, IndividualSubscriptionPUT) if err != nil { t.Fatalf(err.Error()) t.Fatalf("Failed to get expected response") } log.Info("sendRequest done") var respBody V2xMsgSubscription err = json.Unmarshal([]byte(rr), &respBody) if err != nil { t.Fatalf(err.Error()) } fmt.Println("respBody: ", respBody) if rr != string(expected_v2xMsgSubscriptionPut_str) { t.Fatalf(err.Error()) t.Fatalf("Failed to get expected response") } log.Info("Received expected response for PUT method") if expected_v2xMsgSubscription.SubscriptionType != respBody.SubscriptionType { t.Fatalf("Failed to get expected response") } if &expected_v2xMsgSubscription.FilterCriteria != &respBody.FilterCriteria { t.Fatalf("Failed to get expected response") } if expected_v2xMsgSubscription.CallbackReference != respBody.CallbackReference { t.Fatalf("Failed to get expected response") } if *expected_v2xMsgSubscription.ExpiryDeadline != *respBody.ExpiryDeadline { t.Fatalf("Failed to get expected response") } if *expected_v2xMsgSubscription.Links != *respBody.Links { t.Fatalf("Failed to get expected response") } if respBody.WebsockNotifConfig != nil { t.Fatalf("Failed to get expected response") } if respBody.RequestTestNotification != false { t.Fatalf("Failed to get expected response") } return string(expected_v2xMsgSubscriptionPut_str) return string(expectedResponseStr) } else { _, err = sendRequest(http.MethodPost, "/vis/v2/subscriptions", bytes.NewBuffer(body), vars, nil, http.StatusNotFound, IndividualSubscriptionPUT) if err != nil { t.Fatalf("Failed to get expected response") } return "" } } func TestV2xMsgPublicationPost(t *testing.T) { Loading Loading @@ -1099,11 +1244,16 @@ func TestV2xMsgPublicationPost(t *testing.T) { ******************************/ stdOrganization := "ETSI" msgEncodeFormat := "base64" msgEncodeFormat := "hexadump" msgType := DENM msgContent := "Our msg Content" msgContent := "031200f101038100400380818c20400100005802001ee600003c0004e548140072066b24d01eb78149084d5571800000" testv2xMsgPublication := V2xMsgPublication{MsgContent: msgContent, MsgEncodeFormat: msgEncodeFormat, MsgType: &msgType, StdOrganization: stdOrganization} testv2xMsgPublication := V2xMsgPublication{ MsgContent: msgContent, MsgEncodeFormat: msgEncodeFormat, MsgType: &msgType, StdOrganization: stdOrganization, } body, err := json.Marshal(testv2xMsgPublication) if err != nil { t.Fatalf(err.Error()) Loading @@ -1114,7 +1264,7 @@ func TestV2xMsgPublicationPost(t *testing.T) { * request execution section ******************************/ _, err = sendRequest(http.MethodPost, "/publish_v2x_message", bytes.NewBuffer(body), nil, nil, http.StatusNoContent, V2xMessagePOST) _, err = sendRequest(http.MethodPost, "/vis/v2/publish_v2x_message", bytes.NewBuffer(body), nil, nil, http.StatusNoContent, V2xMessagePOST) if err != nil { t.Fatalf(err.Error()) } Loading Loading
go-apps/meep-vis/server/vis_test.go +234 −84 Original line number Diff line number Diff line Loading @@ -789,7 +789,7 @@ func validateUuUnicastProvisioningInfo(received UuUnicastProvisioningInfo, expec return true } func testSubscriptionPost(t *testing.T) string { func testSubscriptionPost(t *testing.T) (string, string) { /****************************** * expected response section Loading @@ -799,32 +799,44 @@ func testSubscriptionPost(t *testing.T) string { // MEC-030 Clause 7.8.3.4 expected_subscriptionType := "V2xMsgSubscription" expected_callbackReference := "MyCallback" expected_href := LinkType{Href: "http://meAppServer.example.com/vis/v2/subscriptions/123"} expected_href := LinkType{Href: "http://meAppServer.example.com/vis/v2/subscriptions/1"} expected_self := Links{Self: &expected_href} //expected_link := V2xMsgSubscription{Links: &expected_self} expected_msgType := []MsgType{DENM, CAM} //expected_stdOrganization := expected_filterCriteria := V2xMsgSubscriptionFilterCriteria{StdOrganization: "ETSI", MsgType: expected_msgType} expected_v2xMsgSubscription := V2xMsgSubscription{Links: &expected_self, CallbackReference: expected_callbackReference, ExpiryDeadline: nil, FilterCriteria: &expected_filterCriteria, RequestTestNotification: false, SubscriptionType: expected_subscriptionType, WebsockNotifConfig: nil} expected_v2xMsgSubscription_str, err := json.Marshal(expected_v2xMsgSubscription) expected_expiryDeadline := TimeStamp{Seconds: 1977836800, NanoSeconds: 0} expected_v2xMsgSubscription := V2xMsgSubscription{ SubscriptionType: expected_subscriptionType, CallbackReference: expected_callbackReference, Links: &expected_self, FilterCriteria: &expected_filterCriteria, ExpiryDeadline: &expected_expiryDeadline, RequestTestNotification: false, WebsockNotifConfig: nil, } expectedResponseStr, err := json.Marshal(expected_v2xMsgSubscription) if err != nil { t.Fatalf(err.Error()) } fmt.Println("expected_v2xMsgSubscription_str: ", string(expected_v2xMsgSubscription_str)) fmt.Println("expected_v2xMsgSubscription_str: ", string(expectedResponseStr)) /****************************** * expected request section * request body section ******************************/ subscriptionType := "V2xMsgSubscription" callbackReference := "MyCallback" msgType := []MsgType{DENM, CAM} //expected_stdOrganization := filterCriteria := V2xMsgSubscriptionFilterCriteria{StdOrganization: "ETSI", MsgType: msgType} testv2xMsgSubscription := V2xMsgSubscription{CallbackReference: callbackReference, FilterCriteria: &filterCriteria, RequestTestNotification: false, SubscriptionType: subscriptionType, WebsockNotifConfig: nil} body, err := json.Marshal(testv2xMsgSubscription) expiryDeadline := TimeStamp{Seconds: 1977836800, NanoSeconds: 0} requestedV2xMsgSubscription := V2xMsgSubscription{ SubscriptionType: subscriptionType, CallbackReference: callbackReference, FilterCriteria: &filterCriteria, ExpiryDeadline: &expiryDeadline, RequestTestNotification: false, WebsockNotifConfig: nil, } body, err := json.Marshal(requestedV2xMsgSubscription) if err != nil { t.Fatalf(err.Error()) } Loading @@ -834,28 +846,51 @@ func testSubscriptionPost(t *testing.T) string { * request execution section ******************************/ rr, err := sendRequest(http.MethodPost, "/subscription", bytes.NewBuffer(body), nil, nil, http.StatusCreated, SubPOST) rr, err := sendRequest(http.MethodPost, "/vis/v2/subscriptions", bytes.NewBuffer(body), nil, nil, http.StatusCreated, SubPOST) if err != nil { t.Fatalf(err.Error()) } log.Info("sendRequest done") log.Info("Request sent") var respBody V2xMsgSubscription err = json.Unmarshal([]byte(rr), &respBody) if err != nil { t.Fatalf(err.Error()) } fmt.Println("respBody: ", respBody) if rr != string(expected_v2xMsgSubscription_str) { t.Fatalf(err.Error()) /****************************** * Comparing responses ******************************/ if expected_v2xMsgSubscription.SubscriptionType != respBody.SubscriptionType { t.Fatalf("Failed to get expected response") } if &expected_v2xMsgSubscription.FilterCriteria != &respBody.FilterCriteria { t.Fatalf("Failed to get expected response") } if expected_v2xMsgSubscription.CallbackReference != respBody.CallbackReference { t.Fatalf("Failed to get expected response") } if *expected_v2xMsgSubscription.ExpiryDeadline != *respBody.ExpiryDeadline { t.Fatalf("Failed to get expected response") } if *expected_v2xMsgSubscription.Links != *respBody.Links { t.Fatalf("Failed to get expected response") } if respBody.WebsockNotifConfig != nil { t.Fatalf("Failed to get expected response") } if respBody.RequestTestNotification != false { t.Fatalf("Failed to get expected response") } log.Info("Received expected response for POST method") subscriptionId := strings.Split(respBody.Links.Self.Href, "/") cleanSubscriptionId := subscriptionId[len(subscriptionId)-1] return string(expected_v2xMsgSubscription_str) return cleanSubscriptionId, string(expectedResponseStr) } func TestSubscriptionV2XMsgSubscription(t *testing.T) { func TestSuccessV2XMsgSubscription(t *testing.T) { fmt.Println("--- ", t.Name()) log.MeepTextLogInit(t.Name()) Loading @@ -877,22 +912,20 @@ func TestSubscriptionV2XMsgSubscription(t *testing.T) { updateScenario("mobility1") // POST expectedGetResponse := testSubscriptionPost(t) subscriptionId, expectedGetResponse := testSubscriptionPost(t) //GET Subscription //expectedListResourceURL := "/" + testScenarioName + "vis/v2/subscriptions" //expectedResourceURL := expectedListResourceURL + "?subscription_type=v2x_msg" subscriptionTypeQuery := V2X_MSG //GET Subscriptions subscriptionTypeQuery := "v2x_msg" testSubscriptionsGet(t, subscriptionTypeQuery, expectedGetResponse) // GET Individual Subscription testIndividualSubscriptionGet(t, expectedGetResponse) testIndividualSubscriptionGet(t, subscriptionId, expectedGetResponse) // PUT testIndividualSubscriptionPut(t, true) testIndividualSubscriptionPut(t, subscriptionId, true) // DELETE testIndividualSubscriptionDelete(t, true) testIndividualSubscriptionDelete(t, subscriptionId, true) /****************************** * back to initial state section Loading @@ -901,6 +934,43 @@ func TestSubscriptionV2XMsgSubscription(t *testing.T) { } func TestFailV2XMsgSubscription(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("Set a scenario") initialiseScenario(testScenario) time.Sleep(1000 * time.Millisecond) updateScenario("mobility1") // GET testIndividualSubscriptionGet(t, "invalidSubscriptionId", "") // PUT _ = testIndividualSubscriptionPut(t, "invalidSubscriptionId", false) // DELETE testIndividualSubscriptionDelete(t, "invalidSubscriptionId", false) /****************************** * back to initial state section ******************************/ terminateScenario() } //Generic GET function for any subscription type func testSubscriptionsGet(t *testing.T, subscriptionTypeQuery string, expectedResponse string) { Loading @@ -920,9 +990,11 @@ func testSubscriptionsGet(t *testing.T, subscriptionTypeQuery string, expectedRe /****************************** * request execution section ******************************/ var err error if expectedResponse == "" { _, err = sendRequest(http.MethodGet, "vis/v2/subscriptions", nil, nil, queryParam, http.StatusNotFound, SubGET) _, err = sendRequest(http.MethodGet, "/vis/v2/subscriptions", nil, nil, queryParam, http.StatusNotFound, SubGET) if err != nil { t.Fatalf("Failed to get expected response") } Loading @@ -939,7 +1011,7 @@ func testSubscriptionsGet(t *testing.T, subscriptionTypeQuery string, expectedRe } } func testIndividualSubscriptionGet(t *testing.T, expectedResponse string) { func testIndividualSubscriptionGet(t *testing.T, subscriptionId string, expectedResponse string) { /****************************** * expected response section Loading @@ -950,80 +1022,117 @@ func testIndividualSubscriptionGet(t *testing.T, expectedResponse string) { * request vars section ******************************/ vars := make(map[string]string) vars["subscriptionId"] = "1" vars["subscriptionId"] = subscriptionId /****************************** * request execution section ******************************/ var err error if expectedResponse == "" { _, err = sendRequest(http.MethodGet, "/vis/v2/subscriptions/1", nil, vars, nil, http.StatusNotFound, IndividualSubscriptionGET) _, err = sendRequest(http.MethodGet, "/vis/v2/subscriptions", nil, vars, nil, http.StatusNotFound, IndividualSubscriptionGET) if err != nil { t.Fatalf("Failed to get expected response") } } else { rr, err := sendRequest(http.MethodGet, "/vis/v2/subscriptions/1", nil, vars, nil, http.StatusOK, IndividualSubscriptionGET) var expectedResp V2xMsgSubscription err := json.Unmarshal([]byte(expectedResponse), &expectedResp) if err != nil { t.Fatalf("Failed to get expected response") } if rr != expectedResponse { rr, err := sendRequest(http.MethodGet, "/vis/v2/subscriptions", nil, vars, nil, http.StatusOK, IndividualSubscriptionGET) if err != nil { t.Fatalf("Failed to get expected response") } var respBody V2xMsgSubscription err = json.Unmarshal([]byte(rr), &respBody) if err != nil { t.Fatalf("Failed to get expected response") } if expectedResp.SubscriptionType != respBody.SubscriptionType { t.Fatalf("Failed to get expected response") } if &expectedResp.FilterCriteria != &respBody.FilterCriteria { t.Fatalf("Failed to get expected response") } if expectedResp.CallbackReference != respBody.CallbackReference { t.Fatalf("Failed to get expected response") } if *expectedResp.ExpiryDeadline != *respBody.ExpiryDeadline { t.Fatalf("Failed to get expected response") } if *expectedResp.Links != *respBody.Links { t.Fatalf("Failed to get expected response") } if respBody.WebsockNotifConfig != nil { t.Fatalf("Failed to get expected response") } if respBody.RequestTestNotification != false { t.Fatalf("Failed to get expected response") } log.Info("Received expected response for GET method") } } func testIndividualSubscriptionDelete(t *testing.T, expectSuccess bool) { func testIndividualSubscriptionDelete(t *testing.T, subscriptionId string, expectSuccess bool) { /****************************** * request vars section ******************************/ vars := make(map[string]string) vars["subscriptionId"] = "1" vars["subscriptionId"] = subscriptionId /****************************** * request execution section ******************************/ if expectSuccess { _, err := sendRequest(http.MethodDelete, "/vis/v2/subscriptions/1", nil, vars, nil, http.StatusNoContent, IndividualSubscriptionDELETE) _, err := sendRequest(http.MethodDelete, "/vis/v2/subscriptions", nil, vars, nil, http.StatusNoContent, IndividualSubscriptionDELETE) if err != nil { t.Fatalf("Failed to get expected response") } } else { _, err := sendRequest(http.MethodDelete, "/vis/v2/subscriptions/1", nil, vars, nil, http.StatusNotFound, IndividualSubscriptionDELETE) _, err := sendRequest(http.MethodDelete, "/vis/v2/subscriptions", nil, vars, nil, http.StatusNotFound, IndividualSubscriptionDELETE) if err != nil { t.Fatalf("Failed to get expected response") } } } func testIndividualSubscriptionPut(t *testing.T, expectSuccess bool) string { func testIndividualSubscriptionPut(t *testing.T, subscriptionId string, expectSuccess bool) string { /****************************** * expected response section ******************************/ expected_subscriptionType := "V2xMsgSubscription" expected_callbackReference := "MyCallback" expected_href := LinkType{Href: "http://meAppServer.example.com/vis/v2/subscriptions/123"} expected_href := LinkType{Href: "http://meAppServer.example.com/vis/v2/subscriptions/1"} expected_self := Links{Self: &expected_href} //expected_link := V2xMsgSubscription{Links: &expected_self} expected_msgType := []MsgType{DENM, CAM} //expected_stdOrganization := expected_filterCriteria := V2xMsgSubscriptionFilterCriteria{StdOrganization: "ETSI", MsgType: expected_msgType} expected_v2xMsgSubscription := V2xMsgSubscription{Links: &expected_self, CallbackReference: expected_callbackReference, ExpiryDeadline: nil, FilterCriteria: &expected_filterCriteria, RequestTestNotification: false, SubscriptionType: expected_subscriptionType, WebsockNotifConfig: nil} expected_v2xMsgSubscriptionPut_str, err := json.Marshal(expected_v2xMsgSubscription) expected_expiryDeadline := TimeStamp{Seconds: 1977836800, NanoSeconds: 0} expected_v2xMsgSubscription := V2xMsgSubscription{ SubscriptionType: expected_subscriptionType, CallbackReference: expected_callbackReference, Links: &expected_self, FilterCriteria: &expected_filterCriteria, ExpiryDeadline: &expected_expiryDeadline, RequestTestNotification: false, WebsockNotifConfig: nil, } expectedResponseStr, err := json.Marshal(expected_v2xMsgSubscription) if err != nil { t.Fatalf(err.Error()) } fmt.Println("expected_v2xMsgSubscriptionPut_str: ", string(expected_v2xMsgSubscriptionPut_str)) fmt.Println("expectedResponseStr: ", string(expectedResponseStr)) /****************************** * request vars section ******************************/ vars := make(map[string]string) vars["subscriptionId"] = "1" vars["subscriptionId"] = subscriptionId /****************************** * request body section Loading @@ -1031,39 +1140,75 @@ func testIndividualSubscriptionPut(t *testing.T, expectSuccess bool) string { subscriptionType := "V2xMsgSubscription" callbackReference := "MyCallback" href := LinkType{Href: "http://meAppServer.example.com/vis/v2/subscriptions/1"} self := Links{Self: &href} msgType := []MsgType{DENM, CAM} //expected_stdOrganization := filterCriteria := V2xMsgSubscriptionFilterCriteria{StdOrganization: "ETSI", MsgType: msgType} testv2xMsgSubscription := V2xMsgSubscription{CallbackReference: callbackReference, FilterCriteria: &filterCriteria, RequestTestNotification: false, SubscriptionType: subscriptionType, WebsockNotifConfig: nil} body, err := json.Marshal(testv2xMsgSubscription) expiryDeadline := TimeStamp{Seconds: 1977836800, NanoSeconds: 0} requestedv2xMsgSubscription := V2xMsgSubscription{ SubscriptionType: subscriptionType, CallbackReference: callbackReference, Links: &self, FilterCriteria: &filterCriteria, ExpiryDeadline: &expiryDeadline, RequestTestNotification: false, WebsockNotifConfig: nil, } body, err := json.Marshal(requestedv2xMsgSubscription) if err != nil { t.Fatalf(err.Error()) } fmt.Println("body: ", string(body)) /****************************** * request execution section * request queries section ******************************/ rr, err := sendRequest(http.MethodPut, "/vis/v2/subscriptions/1", bytes.NewBuffer(body), nil, nil, http.StatusOK, IndividualSubscriptionPUT) /****************************** * request execution section ******************************/ if expectSuccess { rr, err := sendRequest(http.MethodPut, "/vis/v2/subscriptions", bytes.NewBuffer(body), nil, nil, http.StatusOK, IndividualSubscriptionPUT) if err != nil { t.Fatalf(err.Error()) t.Fatalf("Failed to get expected response") } log.Info("sendRequest done") var respBody V2xMsgSubscription err = json.Unmarshal([]byte(rr), &respBody) if err != nil { t.Fatalf(err.Error()) } fmt.Println("respBody: ", respBody) if rr != string(expected_v2xMsgSubscriptionPut_str) { t.Fatalf(err.Error()) t.Fatalf("Failed to get expected response") } log.Info("Received expected response for PUT method") if expected_v2xMsgSubscription.SubscriptionType != respBody.SubscriptionType { t.Fatalf("Failed to get expected response") } if &expected_v2xMsgSubscription.FilterCriteria != &respBody.FilterCriteria { t.Fatalf("Failed to get expected response") } if expected_v2xMsgSubscription.CallbackReference != respBody.CallbackReference { t.Fatalf("Failed to get expected response") } if *expected_v2xMsgSubscription.ExpiryDeadline != *respBody.ExpiryDeadline { t.Fatalf("Failed to get expected response") } if *expected_v2xMsgSubscription.Links != *respBody.Links { t.Fatalf("Failed to get expected response") } if respBody.WebsockNotifConfig != nil { t.Fatalf("Failed to get expected response") } if respBody.RequestTestNotification != false { t.Fatalf("Failed to get expected response") } return string(expected_v2xMsgSubscriptionPut_str) return string(expectedResponseStr) } else { _, err = sendRequest(http.MethodPost, "/vis/v2/subscriptions", bytes.NewBuffer(body), vars, nil, http.StatusNotFound, IndividualSubscriptionPUT) if err != nil { t.Fatalf("Failed to get expected response") } return "" } } func TestV2xMsgPublicationPost(t *testing.T) { Loading Loading @@ -1099,11 +1244,16 @@ func TestV2xMsgPublicationPost(t *testing.T) { ******************************/ stdOrganization := "ETSI" msgEncodeFormat := "base64" msgEncodeFormat := "hexadump" msgType := DENM msgContent := "Our msg Content" msgContent := "031200f101038100400380818c20400100005802001ee600003c0004e548140072066b24d01eb78149084d5571800000" testv2xMsgPublication := V2xMsgPublication{MsgContent: msgContent, MsgEncodeFormat: msgEncodeFormat, MsgType: &msgType, StdOrganization: stdOrganization} testv2xMsgPublication := V2xMsgPublication{ MsgContent: msgContent, MsgEncodeFormat: msgEncodeFormat, MsgType: &msgType, StdOrganization: stdOrganization, } body, err := json.Marshal(testv2xMsgPublication) if err != nil { t.Fatalf(err.Error()) Loading @@ -1114,7 +1264,7 @@ func TestV2xMsgPublicationPost(t *testing.T) { * request execution section ******************************/ _, err = sendRequest(http.MethodPost, "/publish_v2x_message", bytes.NewBuffer(body), nil, nil, http.StatusNoContent, V2xMessagePOST) _, err = sendRequest(http.MethodPost, "/vis/v2/publish_v2x_message", bytes.NewBuffer(body), nil, nil, http.StatusNoContent, V2xMessagePOST) if err != nil { t.Fatalf(err.Error()) } Loading