Further UT improvements
[ric-plt/xapp-frame.git] / pkg / xapp / subscription_test.go
index 5772465..af8938c 100755 (executable)
@@ -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)