X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fxapp%2Fsubscription_test.go;h=af8938cde9d3c16291348bb9bee2364b177000c6;hb=dba83dfb6f135fb2f6987e55beec8552c6a8b74e;hp=5772465c217864d2723fc06ec150ea41c3e91e10;hpb=2f9d1a1259f88552a2b6e9db6e1ea236aef7a2d2;p=ric-plt%2Fxapp-frame.git diff --git a/pkg/xapp/subscription_test.go b/pkg/xapp/subscription_test.go index 5772465..af8938c 100755 --- a/pkg/xapp/subscription_test.go +++ b/pkg/xapp/subscription_test.go @@ -7,7 +7,10 @@ package xapp import ( + "bytes" "fmt" + "net/http" + "net/http/httptest" "testing" "time" @@ -63,16 +66,12 @@ func TestSubscriptionHandling(t *testing.T) { SubscriptionDetails: clientmodel.SubscriptionDetailsList{ &clientmodel.SubscriptionDetail{ XappEventInstanceID: &eventInstanceId, - EventTriggers: &clientmodel.EventTriggerDefinition{ - OctetString: "1234", - }, + EventTriggers: clientmodel.EventTriggerDefinition{00, 0x11, 0x12, 0x13, 0x00, 0x21, 0x22, 0x24, 0x1B, 0x80}, ActionToBeSetupList: clientmodel.ActionsToBeSetup{ &clientmodel.ActionToBeSetup{ - ActionID: &actionId, - ActionType: &actionType, - ActionDefinition: &clientmodel.ActionDefinition{ - OctetString: "5678", - }, + ActionID: &actionId, + ActionType: &actionType, + ActionDefinition: clientmodel.ActionDefinition{5, 6, 7, 8}, SubsequentAction: &clientmodel.SubsequentAction{ SubsequentActionType: &subsequestActioType, TimeToWait: &timeToWait, @@ -102,16 +101,12 @@ func TestSubscriptionWithClientProvidedIdHandling(t *testing.T) { SubscriptionDetails: clientmodel.SubscriptionDetailsList{ &clientmodel.SubscriptionDetail{ XappEventInstanceID: &eventInstanceId, - EventTriggers: &clientmodel.EventTriggerDefinition{ - OctetString: "1234", - }, + EventTriggers: clientmodel.EventTriggerDefinition{00, 0x11, 0x12, 0x13, 0x00, 0x21, 0x22, 0x24, 0x1B, 0x80}, ActionToBeSetupList: clientmodel.ActionsToBeSetup{ &clientmodel.ActionToBeSetup{ - ActionID: &actionId, - ActionType: &actionType, - ActionDefinition: &clientmodel.ActionDefinition{ - OctetString: "5678", - }, + ActionID: &actionId, + ActionType: &actionType, + ActionDefinition: clientmodel.ActionDefinition{5, 6, 7, 8}, SubsequentAction: &clientmodel.SubsequentAction{ SubsequentActionType: &subsequestActioType, TimeToWait: &timeToWait, @@ -138,7 +133,29 @@ func TestSubscriptionDeleteHandling(t *testing.T) { assert.Equal(t, err, nil) } +func TestResponseHandler(t *testing.T) { + Subscription.SetResponseCB(SubscriptionRespHandler) + + payload := []byte(`{"SubscriptionInstances":[{"tXappEventInstanceID": 1}]`) + req, err := http.NewRequest("POST", "/ric/v1/subscriptions/response", bytes.NewBuffer(payload)) + if err != nil { + t.Fatal(err) + } + + rr := httptest.NewRecorder() + handler := http.HandlerFunc(Subscription.ResponseHandler) + handler.ServeHTTP(rr, req) + + if status := rr.Code; status != http.StatusOK { + t.Errorf("handler returned wrong status code: got %v want %v", status, http.StatusOK) + } + time.Sleep(time.Duration(2) * time.Second) +} + // Helper functions +func SubscriptionRespHandler(resp *clientmodel.SubscriptionResponse) { +} + func processSubscriptions(subscriptionId string) { // Generate requestorId, instanceId xappInstanceId := int64(11) @@ -168,13 +185,14 @@ func subscriptionHandler(params interface{}) (*models.SubscriptionResponse, erro assert.Equal(suite, clientEndpoint.RMRPort, p.ClientEndpoint.RMRPort) assert.Equal(suite, xappEventInstanceId, *p.SubscriptionDetails[0].XappEventInstanceID) - assert.Equal(suite, "1234", p.SubscriptionDetails[0].EventTriggers.OctetString) + et := []int64{00, 0x11, 0x12, 0x13, 0x00, 0x21, 0x22, 0x24, 0x1B, 0x80} + assert.ElementsMatch(suite, et, p.SubscriptionDetails[0].EventTriggers) assert.Equal(suite, actionId, *p.SubscriptionDetails[0].ActionToBeSetupList[0].ActionID) assert.Equal(suite, actionType, *p.SubscriptionDetails[0].ActionToBeSetupList[0].ActionType) assert.Equal(suite, subsequestActioType, *p.SubscriptionDetails[0].ActionToBeSetupList[0].SubsequentAction.SubsequentActionType) assert.Equal(suite, timeToWait, *p.SubscriptionDetails[0].ActionToBeSetupList[0].SubsequentAction.TimeToWait) - assert.Equal(suite, "5678", p.SubscriptionDetails[0].ActionToBeSetupList[0].ActionDefinition.OctetString) + assert.ElementsMatch(suite, []int64{5, 6, 7, 8}, p.SubscriptionDetails[0].ActionToBeSetupList[0].ActionDefinition) // Generate a unique subscriptionId subscriptionId = fmt.Sprintf("%s-%s", meid, clientEndpoint.Host)