"github.com/stretchr/testify/assert"
"oransc.org/nonrtric/capifcore/internal/common29122"
"oransc.org/nonrtric/capifcore/internal/eventsapi"
+ "oransc.org/nonrtric/capifcore/internal/publishserviceapi"
"oransc.org/nonrtric/capifcore/internal/restclient"
)
Events: eventsapi.CAPIFEventSERVICEAPIAVAILABLE,
}
- matchingSubs := serviceUnderTest.getMatchingSubs(event)
+ matchingSubs := serviceUnderTest.filterOnEventType(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{
- {},
+func TestMatchEventTypeAndFilters(t *testing.T) {
+ subId := "sub1"
+ apiIds := []string{"apiId"}
+ invokerIds := []string{"invokerId"}
+ aefId := "aefId"
+ aefIds := []string{aefId}
+ serviceUnderTest := NewEventService(nil)
+ serviceUnderTest.addSubscription(subId, eventsapi.EventSubscription{
+ Events: []eventsapi.CAPIFEvent{
+ eventsapi.CAPIFEventSERVICEAPIAVAILABLE,
+ },
+ EventFilters: &[]eventsapi.CAPIFEventFilter{
+ {
+ ApiIds: &apiIds,
+ ApiInvokerIds: &invokerIds,
+ AefIds: &aefIds,
+ },
+ },
+ })
+ serviceUnderTest.addSubscription("otherSameType", eventsapi.EventSubscription{
+ Events: []eventsapi.CAPIFEvent{
+ eventsapi.CAPIFEventACCESSCONTROLPOLICYUNAVAILABLE,
+ },
+ })
+ serviceUnderTest.addSubscription("other", eventsapi.EventSubscription{
+ Events: []eventsapi.CAPIFEvent{
+ eventsapi.CAPIFEventACCESSCONTROLPOLICYUNAVAILABLE,
+ },
+ })
+
+ event := eventsapi.EventNotification{
+ Events: eventsapi.CAPIFEventACCESSCONTROLPOLICYUNAVAILABLE,
+ }
+
+ // Only match type
+ matchingSubs := serviceUnderTest.getMatchingSubs(event)
+ assert.Len(t, matchingSubs, 2)
+
+ // Match with all filter ids
+ aefProfiles := []publishserviceapi.AefProfile{
{
- ApiIds: &apiIds,
+ AefId: aefId,
+ },
+ }
+ serviceDescriptions := []publishserviceapi.ServiceAPIDescription{
+ {
+ AefProfiles: &aefProfiles,
},
}
+ event.Events = eventsapi.CAPIFEventSERVICEAPIAVAILABLE
+ event.EventDetail = &eventsapi.CAPIFEventDetail{
+ ApiIds: &apiIds,
+ ApiInvokerIds: &invokerIds,
+ ServiceAPIDescriptions: &serviceDescriptions,
+ }
+ matchingSubs = serviceUnderTest.getMatchingSubs(event)
+ assert.Len(t, matchingSubs, 1)
+ assert.Equal(t, subId, matchingSubs[0])
- eventApiIds := []string{apiId}
- assert.True(t, matchesApiIds(eventApiIds, eventFilters))
- assert.True(t, matchesApiIds(nil, eventFilters))
+ // Un match apiId
+ otherApiIds := []string{"otherApiId"}
+ (*serviceUnderTest.subscriptions[subId].EventFilters)[0].ApiIds = &otherApiIds
+ matchingSubs = serviceUnderTest.getMatchingSubs(event)
+ assert.Len(t, matchingSubs, 0)
- altApiIds := []string{"anotherApiId"}
- unMatchingFilterAdded := append(eventFilters, eventsapi.CAPIFEventFilter{
- ApiIds: &altApiIds,
- })
- assert.False(t, matchesApiIds(eventApiIds, unMatchingFilterAdded))
+ // Un match invokerId
+ otherInvokerIds := []string{"otherInvokerId"}
+ (*serviceUnderTest.subscriptions[subId].EventFilters)[0].ApiIds = nil
+ (*serviceUnderTest.subscriptions[subId].EventFilters)[0].ApiInvokerIds = &otherInvokerIds
+ matchingSubs = serviceUnderTest.getMatchingSubs(event)
+ assert.Len(t, matchingSubs, 0)
- apiIds[0] = "anotherId"
- assert.False(t, matchesApiIds(eventApiIds, eventFilters))
+ // Un match aefId
+ otherAefIds := []string{"otherAefId"}
+ (*serviceUnderTest.subscriptions[subId].EventFilters)[0].ApiInvokerIds = nil
+ (*serviceUnderTest.subscriptions[subId].EventFilters)[0].AefIds = &otherAefIds
+ matchingSubs = serviceUnderTest.getMatchingSubs(event)
+ assert.Len(t, matchingSubs, 0)
+
+ // Match with empty subscription filter id list
+ (*serviceUnderTest.subscriptions[subId].EventFilters)[0].AefIds = &[]string{}
+ matchingSubs = serviceUnderTest.getMatchingSubs(event)
+ assert.Len(t, matchingSubs, 1)
+
+ // Match with empty event id list
+ event.EventDetail.ApiIds = nil
+ event.EventDetail.ApiInvokerIds = nil
+ event.EventDetail.ServiceAPIDescriptions = &[]publishserviceapi.ServiceAPIDescription{}
+ matchingSubs = serviceUnderTest.getMatchingSubs(event)
+ assert.Len(t, matchingSubs, 1)
}
func getEcho(client restclient.HTTPClient) (*EventService, *echo.Echo) {