+func TestFilterAefId(t *testing.T) {
+ var err error
+
+ apiName := "apiName1"
+ aefId := "aefId"
+ apiList := []publishapi.ServiceAPIDescription{
+ getAPI(apiName, aefId, "", "", nil, nil, ""),
+ getAPI("apiName2", "otherAefId", "", "", nil, nil, ""),
+ }
+ invokerId := "api_invoker_id"
+ invokerRegisterrMock := getInvokerRegisterMock(invokerId, apiList)
+ requestHandler := getEcho(invokerRegisterrMock)
+
+ // Get APIs with filter
+ result := testutil.NewRequest().Get("/allServiceAPIs?api-invoker-id="+invokerId+"&aef-id="+aefId).Go(t, requestHandler)
+
+ assert.Equal(t, http.StatusOK, result.Code())
+ var resultInvoker discoverserviceapi.DiscoveredAPIs
+ err = result.UnmarshalBodyToObject(&resultInvoker)
+ assert.NoError(t, err, "error unmarshaling response")
+ assert.Equal(t, 1, len(*resultInvoker.ServiceAPIDescriptions))
+ assert.Equal(t, apiName, (*resultInvoker.ServiceAPIDescriptions)[0].ApiName)
+}
+
+func TestFilterVersion(t *testing.T) {
+ var err error
+
+ apiName := "apiName1"
+ version := "v1"
+ apiList := []publishapi.ServiceAPIDescription{
+ getAPI(apiName, "", "", version, nil, nil, ""),
+ getAPI("apiName2", "", "", "v2", nil, nil, ""),
+ }
+ invokerId := "api_invoker_id"
+ invokerRegisterrMock := getInvokerRegisterMock(invokerId, apiList)
+ requestHandler := getEcho(invokerRegisterrMock)
+
+ // Get APIs with filter
+ result := testutil.NewRequest().Get("/allServiceAPIs?api-invoker-id="+invokerId+"&api-version="+version).Go(t, requestHandler)
+
+ assert.Equal(t, http.StatusOK, result.Code())
+ var resultInvoker discoverserviceapi.DiscoveredAPIs
+ err = result.UnmarshalBodyToObject(&resultInvoker)
+ assert.NoError(t, err, "error unmarshaling response")
+ assert.Equal(t, 1, len(*resultInvoker.ServiceAPIDescriptions))
+ assert.Equal(t, apiName, (*resultInvoker.ServiceAPIDescriptions)[0].ApiName)
+}
+
+func TestFilterCommType(t *testing.T) {
+ var err error
+
+ apiName := "apiName1"
+ commType := publishapi.CommunicationTypeREQUESTRESPONSE
+ apiList := []publishapi.ServiceAPIDescription{
+ getAPI(apiName, "", "", "", nil, nil, commType),
+ getAPI("apiName2", "", "", "", nil, nil, publishapi.CommunicationTypeSUBSCRIBENOTIFY),
+ }
+ invokerId := "api_invoker_id"
+ invokerRegisterrMock := getInvokerRegisterMock(invokerId, apiList)
+ requestHandler := getEcho(invokerRegisterrMock)
+
+ // Get APIs with filter
+ result := testutil.NewRequest().Get("/allServiceAPIs?api-invoker-id="+invokerId+"&comm-type="+string(commType)).Go(t, requestHandler)
+
+ assert.Equal(t, http.StatusOK, result.Code())
+ var resultInvoker discoverserviceapi.DiscoveredAPIs
+ err = result.UnmarshalBodyToObject(&resultInvoker)
+ assert.NoError(t, err, "error unmarshaling response")
+ assert.Equal(t, 1, len(*resultInvoker.ServiceAPIDescriptions))
+ assert.Equal(t, apiName, (*resultInvoker.ServiceAPIDescriptions)[0].ApiName)
+}
+
+func TestFilterVersionAndCommType(t *testing.T) {
+ var err error
+
+ apiName := "apiName2"
+ version := "v1"
+ commType := publishapi.CommunicationTypeSUBSCRIBENOTIFY
+ apiList := []publishapi.ServiceAPIDescription{
+ getAPI("apiName1", "", "", version, nil, nil, publishapi.CommunicationTypeREQUESTRESPONSE),
+ getAPI(apiName, "", "", version, nil, nil, commType),
+ getAPI("apiName3", "", "", "v2", nil, nil, commType),
+ }
+ invokerId := "api_invoker_id"
+ invokerRegisterrMock := getInvokerRegisterMock(invokerId, apiList)
+ requestHandler := getEcho(invokerRegisterrMock)
+
+ // Get APIs with filter
+ result := testutil.NewRequest().Get("/allServiceAPIs?api-invoker-id="+invokerId+"&api-version="+version+"&comm-type="+string(commType)).Go(t, requestHandler)
+
+ assert.Equal(t, http.StatusOK, result.Code())
+ var resultInvoker discoverserviceapi.DiscoveredAPIs
+ err = result.UnmarshalBodyToObject(&resultInvoker)
+ assert.NoError(t, err, "error unmarshaling response")
+ assert.Equal(t, 1, len(*resultInvoker.ServiceAPIDescriptions))
+ assert.Equal(t, apiName, (*resultInvoker.ServiceAPIDescriptions)[0].ApiName)
+}
+
+func TestFilterAPICategory(t *testing.T) {
+ var err error
+
+ apiName := "apiName1"
+ apiCategory := "apiCategory"
+ apiList := []publishapi.ServiceAPIDescription{
+ getAPI(apiName, "", apiCategory, "", nil, nil, ""),
+ getAPI("apiName2", "", "", "", nil, nil, ""),
+ }
+ invokerId := "api_invoker_id"
+ invokerRegisterrMock := getInvokerRegisterMock(invokerId, apiList)
+ requestHandler := getEcho(invokerRegisterrMock)
+
+ // Get APIs with filter
+ result := testutil.NewRequest().Get("/allServiceAPIs?api-invoker-id="+invokerId+"&api-cat="+apiCategory).Go(t, requestHandler)
+
+ assert.Equal(t, http.StatusOK, result.Code())
+ var resultInvoker discoverserviceapi.DiscoveredAPIs
+ err = result.UnmarshalBodyToObject(&resultInvoker)
+ assert.NoError(t, err, "error unmarshaling response")
+ assert.Equal(t, 1, len(*resultInvoker.ServiceAPIDescriptions))
+ assert.Equal(t, apiName, (*resultInvoker.ServiceAPIDescriptions)[0].ApiName)
+}
+
+func TestFilterProtocol(t *testing.T) {
+ var err error
+
+ apiName := "apiName1"
+ apiList := []publishapi.ServiceAPIDescription{
+ getAPI(apiName, "", "", "", &protocolHTTP11, nil, ""),
+ getAPI("apiName2", "", "", "", nil, nil, ""),
+ }
+ invokerId := "api_invoker_id"
+ invokerRegisterrMock := getInvokerRegisterMock(invokerId, apiList)
+ requestHandler := getEcho(invokerRegisterrMock)
+
+ // Get APIs with filter
+ result := testutil.NewRequest().Get("/allServiceAPIs?api-invoker-id="+invokerId+"&protocol="+string(protocolHTTP11)).Go(t, requestHandler)
+
+ assert.Equal(t, http.StatusOK, result.Code())
+ var resultInvoker discoverserviceapi.DiscoveredAPIs
+ err = result.UnmarshalBodyToObject(&resultInvoker)
+ assert.NoError(t, err, "error unmarshaling response")
+ assert.Equal(t, 1, len(*resultInvoker.ServiceAPIDescriptions))
+ assert.Equal(t, apiName, (*resultInvoker.ServiceAPIDescriptions)[0].ApiName)
+}
+
+var DataFormatOther publishapi.DataFormat = "OTHER"
+
+func TestFilterDataFormat(t *testing.T) {
+ var err error
+
+ apiName := "apiName1"
+ apiList := []publishapi.ServiceAPIDescription{
+ getAPI(apiName, "", "", "", nil, &dataFormatJSON, ""),
+ getAPI("apiName2", "", "", "", nil, nil, ""),
+ }
+ invokerId := "api_invoker_id"
+ invokerRegisterrMock := getInvokerRegisterMock(invokerId, apiList)
+ requestHandler := getEcho(invokerRegisterrMock)
+
+ // Get APIs with filter
+ result := testutil.NewRequest().Get("/allServiceAPIs?api-invoker-id="+invokerId+"&data-format="+string(dataFormatJSON)).Go(t, requestHandler)
+
+ assert.Equal(t, http.StatusOK, result.Code())
+ var resultInvoker discoverserviceapi.DiscoveredAPIs
+ err = result.UnmarshalBodyToObject(&resultInvoker)
+ assert.NoError(t, err, "error unmarshaling response")
+ assert.Equal(t, 1, len(*resultInvoker.ServiceAPIDescriptions))
+ assert.Equal(t, apiName, (*resultInvoker.ServiceAPIDescriptions)[0].ApiName)
+}
+
+func getEcho(invokerManager invokermanagement.InvokerRegister) *echo.Echo {