X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=capifcore%2Finternal%2Feventservice%2Feventservice_test.go;h=f2acb9c7c06bebb9bfcce87f339f9b0bfd5b4adb;hb=19a22c671e873b438cc7ad005bab386674af7bd2;hp=ec49ec068bad04e1a1a0ed7897848f3854008a42;hpb=2effa31635f1b8349c02b4c1c546bfc67e8797d3;p=nonrtric%2Fplt%2Fsme.git diff --git a/capifcore/internal/eventservice/eventservice_test.go b/capifcore/internal/eventservice/eventservice_test.go index ec49ec0..f2acb9c 100644 --- a/capifcore/internal/eventservice/eventservice_test.go +++ b/capifcore/internal/eventservice/eventservice_test.go @@ -97,7 +97,6 @@ func TestSendEvent(t *testing.T) { apiIds := []string{"apiId"} subId := "sub1" newEvent := eventsapi.EventNotification{ - SubscriptionId: subId, EventDetail: &eventsapi.CAPIFEventDetail{ ApiIds: &apiIds, }, @@ -108,6 +107,7 @@ func TestSendEvent(t *testing.T) { if req.URL.String() == notificationUrl { assert.Equal(t, req.Method, "PUT") assert.Equal(t, "application/json", req.Header.Get("Content-Type")) + newEvent.SubscriptionId = subId assert.Equal(t, newEvent, getBodyAsEvent(req, t)) wg.Done() return &http.Response{ @@ -122,13 +122,19 @@ func TestSendEvent(t *testing.T) { }) serviceUnderTest, _ := getEcho(clientMock) - subscription := eventsapi.EventSubscription{ + serviceUnderTest.addSubscription(subId, eventsapi.EventSubscription{ Events: []eventsapi.CAPIFEvent{ eventsapi.CAPIFEventSERVICEAPIAVAILABLE, }, NotificationDestination: common29122.Uri(notificationUrl), + }) + sub2 := eventsapi.EventSubscription{ + Events: []eventsapi.CAPIFEvent{ + eventsapi.CAPIFEventACCESSCONTROLPOLICYUNAVAILABLE, + }, + NotificationDestination: common29122.Uri(notificationUrl), } - serviceUnderTest.addSubscription(subId, subscription) + serviceUnderTest.addSubscription("other", sub2) wg.Add(1) go func() { @@ -139,7 +145,58 @@ func TestSendEvent(t *testing.T) { t.Error("Not all calls to server were made") t.Fail() } +} + +func TestMatchEventType(t *testing.T) { + notificationUrl := "url" + subId := "sub1" + serviceUnderTest := NewEventService(nil) + serviceUnderTest.addSubscription(subId, eventsapi.EventSubscription{ + Events: []eventsapi.CAPIFEvent{ + eventsapi.CAPIFEventSERVICEAPIAVAILABLE, + }, + NotificationDestination: common29122.Uri(notificationUrl), + EventFilters: &[]eventsapi.CAPIFEventFilter{}, + }) + serviceUnderTest.addSubscription("other", eventsapi.EventSubscription{ + Events: []eventsapi.CAPIFEvent{ + eventsapi.CAPIFEventACCESSCONTROLPOLICYUNAVAILABLE, + }, + NotificationDestination: common29122.Uri(notificationUrl), + }) + + event := eventsapi.EventNotification{ + SubscriptionId: subId, + Events: eventsapi.CAPIFEventSERVICEAPIAVAILABLE, + } + + matchingSubs := serviceUnderTest.getMatchingSubs(event) + assert.Len(t, matchingSubs, 1) + assert.Equal(t, subId, matchingSubs[0]) +} + +func TestMatchesApiIds(t *testing.T) { + apiId := "apiId" + apiIds := []string{apiId, "otherApiId"} + eventFilters := []eventsapi.CAPIFEventFilter{ + {}, + { + ApiIds: &apiIds, + }, + } + + eventApiIds := []string{apiId} + assert.True(t, matchesApiIds(eventApiIds, eventFilters)) + assert.True(t, matchesApiIds(nil, eventFilters)) + + altApiIds := []string{"anotherApiId"} + unMatchingFilterAdded := append(eventFilters, eventsapi.CAPIFEventFilter{ + ApiIds: &altApiIds, + }) + assert.False(t, matchesApiIds(eventApiIds, unMatchingFilterAdded)) + apiIds[0] = "anotherId" + assert.False(t, matchesApiIds(eventApiIds, eventFilters)) } func getEcho(client restclient.HTTPClient) (*EventService, *echo.Echo) {