Added duplicate detection changes
[ric-plt/submgr.git] / pkg / teststube2ap / stubE2.go
index cb15b35..f20afed 100644 (file)
@@ -48,6 +48,7 @@ type RmrTransactionId struct {
 type E2RestIds struct {
        RestSubsId string
        E2SubsId   uint32
+       ErrorCause string
 }
 
 func (trans *RmrTransactionId) String() string {
@@ -663,6 +664,7 @@ func (tc *E2Stub) SendSubsDelFail(t *testing.T, req *e2ap.E2APSubscriptionDelete
 // Callback handler for subscription response notifications
 //-----------------------------------------------------------------------------
 func (tc *E2Stub) SubscriptionRespHandler(resp *clientmodel.SubscriptionResponse) {
+
        if tc.subscriptionId == "SUBSCRIPTIONID NOT SET" {
                tc.Info("REST notification received for %v while no SubscriptionID was not set for E2EventInstanceID=%v, XappEventInstanceID=%v (%v)",
                        *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID, tc)
@@ -680,7 +682,20 @@ func (tc *E2Stub) SubscriptionRespHandler(resp *clientmodel.SubscriptionResponse
 //-----------------------------------------------------------------------------
 //
 //-----------------------------------------------------------------------------
+
 func (tc *E2Stub) ExpectRESTNotification(t *testing.T, restSubsId string) {
+       tc.expectNotification(t, restSubsId, "")
+}
+
+func (tc *E2Stub) ExpectRESTNotificationOk(t *testing.T, restSubsId string) {
+       tc.expectNotification(t, restSubsId, "allOk")
+}
+
+func (tc *E2Stub) ExpectRESTNotificationNok(t *testing.T, restSubsId string, expectError string) {
+       tc.expectNotification(t, restSubsId, expectError)
+}
+
+func (tc *E2Stub) expectNotification(t *testing.T, restSubsId string, expectError string) {
 
        tc.Info("### Started to wait REST notification for %v on port %v f(RMR port %v), %v responses expected", restSubsId, *tc.clientEndpoint.HTTPPort, *tc.clientEndpoint.RMRPort, tc.requestCount)
        tc.restSubsIdList = []string{restSubsId}
@@ -695,6 +710,10 @@ func (tc *E2Stub) ExpectRESTNotification(t *testing.T, restSubsId string) {
                                tc.TestError(t, "### REST notification count unexpectedly ZERO for %s (%v)", restSubsId, tc)
                        } else if e2Ids.RestSubsId != restSubsId {
                                tc.TestError(t, "### Unexpected REST notifications received |%s:%s| (%v)", e2Ids.RestSubsId, restSubsId, tc)
+                       } else if e2Ids.ErrorCause == "" && expectError == "allFail" {
+                               tc.TestError(t, "### Unexpected ok cause received from REST notifications |%s:%s| (%v)", e2Ids.RestSubsId, restSubsId, tc)
+                       } else if e2Ids.ErrorCause != "" && expectError == "allOk" {
+                               tc.TestError(t, "### Unexpected error cause (%s) received from REST notifications |%s:%s| (%v)", e2Ids.ErrorCause, e2Ids.RestSubsId, restSubsId, tc)
                        } else {
                                tc.requestCount--
                                if tc.requestCount == 0 {
@@ -702,6 +721,9 @@ func (tc *E2Stub) ExpectRESTNotification(t *testing.T, restSubsId string) {
                                } else {
                                        tc.Info("### Expected REST notifications received for %s, (%v)", e2Ids.RestSubsId, tc)
                                }
+                               if e2Ids.ErrorCause != "" && expectError == "allFail" {
+                                       tc.Info("### REST Notification: %s, ErrorCause: %v", e2Ids.RestSubsId, e2Ids.ErrorCause)
+                               }
                                tc.Info("### REST Notification received Notif for %s : %v", e2Ids.RestSubsId, e2Ids.E2SubsId)
                                tc.ListedRESTNotifications <- e2Ids
                        }
@@ -758,7 +780,11 @@ func (tc *E2Stub) ListedRestNotifHandler(resp *clientmodel.SubscriptionResponse)
                                tc.restSubsIdList = append(tc.restSubsIdList[:i], tc.restSubsIdList[i+1:]...)
                                //tc.Info("Removed %s from Listed REST notifications, %v entries left", *resp.SubscriptionID, len(tc.restSubsIdList))
 
-                               tc.CallBackListedNotifications <- E2RestIds{*resp.SubscriptionID, uint32(*resp.SubscriptionInstances[0].E2EventInstanceID)}
+                               if resp.SubscriptionInstances[0].ErrorCause != nil {
+                                       tc.CallBackListedNotifications <- E2RestIds{*resp.SubscriptionID, uint32(*resp.SubscriptionInstances[0].E2EventInstanceID), *resp.SubscriptionInstances[0].ErrorCause}
+                               } else {
+                                       tc.CallBackListedNotifications <- E2RestIds{*resp.SubscriptionID, uint32(*resp.SubscriptionInstances[0].E2EventInstanceID), ""}
+                               }
 
                                if len(tc.restSubsIdList) == 0 {
                                        //tc.Info("All listed REST notifications received for endpoint=%s", tc.clientEndpoint)
@@ -807,7 +833,7 @@ func (tc *E2Stub) SendRESTSubsReq(t *testing.T, params *RESTSubsReqParams) strin
                return ""
        }
 
-       tc.subscriptionId = "SUBSCIPTIONID NOT SET"
+       tc.subscriptionId = "SUBSCRIPTIONID NOT SET"
 
        resp, err := xapp.Subscription.Subscribe(&params.SubsReqParams)
        if err != nil {