+ 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, "apiName1", (*resultInvoker.ServiceAPIDescriptions)[0].ApiName)
+}
+
+func TestFilterAefId(t *testing.T) {
+ var err error
+
+ apiList := []publishapi.ServiceAPIDescription{
+ getAPI("apiName1", "aefId", "", "", nil, nil, ""),
+ getAPI("apiName2", "otherAefId", "", "", nil, nil, ""),
+ }
+ apiRegisterMock := mocks.APIRegister{}
+ apiRegisterMock.On("GetAPIs").Return(&apiList)
+ requestHandler := getEcho(&apiRegisterMock)
+
+ // Get APIs with filter
+ result := testutil.NewRequest().Get("/allServiceAPIs?api-invoker-id=api_invoker_id&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, "apiName1", (*resultInvoker.ServiceAPIDescriptions)[0].ApiName)
+}
+
+func TestFilterVersion(t *testing.T) {
+ var err error
+
+ apiList := []publishapi.ServiceAPIDescription{
+ getAPI("apiName1", "", "", "v1", nil, nil, ""),
+ getAPI("apiName2", "", "", "v2", nil, nil, ""),
+ }
+ apiRegisterMock := mocks.APIRegister{}
+ apiRegisterMock.On("GetAPIs").Return(&apiList)
+ requestHandler := getEcho(&apiRegisterMock)
+
+ // Get APIs with filter
+ result := testutil.NewRequest().Get("/allServiceAPIs?api-version=v1&api-invoker-id=api_invoker_id").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, "apiName1", (*resultInvoker.ServiceAPIDescriptions)[0].ApiName)
+}
+
+func TestFilterCommType(t *testing.T) {
+ var err error
+
+ apiList := []publishapi.ServiceAPIDescription{
+ getAPI("apiName1", "", "", "", nil, nil, publishapi.CommunicationTypeREQUESTRESPONSE),
+ getAPI("apiName2", "", "", "", nil, nil, publishapi.CommunicationTypeSUBSCRIBENOTIFY),
+ }
+ apiRegisterMock := mocks.APIRegister{}
+ apiRegisterMock.On("GetAPIs").Return(&apiList)
+ requestHandler := getEcho(&apiRegisterMock)
+
+ // Get APIs with filter
+ result := testutil.NewRequest().Get("/allServiceAPIs?api-invoker-id=api_invoker_id&comm-type=REQUEST_RESPONSE").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, "apiName1", (*resultInvoker.ServiceAPIDescriptions)[0].ApiName)
+}
+
+func TestFilterVersionAndCommType(t *testing.T) {
+ var err error
+
+ apiList := []publishapi.ServiceAPIDescription{
+ getAPI("apiName1", "", "", "v1", nil, nil, publishapi.CommunicationTypeREQUESTRESPONSE),
+ getAPI("apiName2", "", "", "v1", nil, nil, publishapi.CommunicationTypeSUBSCRIBENOTIFY),
+ getAPI("apiName3", "", "", "v2", nil, nil, publishapi.CommunicationTypeSUBSCRIBENOTIFY),
+ }
+ apiRegisterMock := mocks.APIRegister{}
+ apiRegisterMock.On("GetAPIs").Return(&apiList)
+ requestHandler := getEcho(&apiRegisterMock)
+
+ // Get APIs with filter
+ result := testutil.NewRequest().Get("/allServiceAPIs?api-invoker-id=api_invoker_id&api-version=v1&comm-type=SUBSCRIBE_NOTIFY").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, "apiName2", (*resultInvoker.ServiceAPIDescriptions)[0].ApiName)
+}
+
+func TestFilterAPICategory(t *testing.T) {
+ var err error
+
+ apiList := []publishapi.ServiceAPIDescription{
+ getAPI("apiName1", "", "apiCategory", "", nil, nil, ""),
+ getAPI("apiName2", "", "", "", nil, nil, ""),
+ }
+ apiRegisterMock := mocks.APIRegister{}
+ apiRegisterMock.On("GetAPIs").Return(&apiList)
+ requestHandler := getEcho(&apiRegisterMock)
+
+ // Get APIs with filter
+ result := testutil.NewRequest().Get("/allServiceAPIs?api-invoker-id=api_invoker_id&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, "apiName1", (*resultInvoker.ServiceAPIDescriptions)[0].ApiName)
+}
+
+func TestFilterProtocol(t *testing.T) {
+ var err error
+
+ apiList := []publishapi.ServiceAPIDescription{
+ getAPI("apiName1", "", "", "", &protocolHTTP11, nil, ""),
+ getAPI("apiName2", "", "", "", nil, nil, ""),
+ }
+ apiRegisterMock := mocks.APIRegister{}
+ apiRegisterMock.On("GetAPIs").Return(&apiList)
+ requestHandler := getEcho(&apiRegisterMock)
+
+ // Get APIs with filter
+ result := testutil.NewRequest().Get("/allServiceAPIs?api-invoker-id=api_invoker_id&protocol=HTTP_1_1").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, "apiName1", (*resultInvoker.ServiceAPIDescriptions)[0].ApiName)
+}
+
+var DataFormatOther publishapi.DataFormat = "OTHER"
+
+func TestFilterDataFormat(t *testing.T) {
+ var err error
+
+ apiList := []publishapi.ServiceAPIDescription{
+ getAPI("apiName1", "", "", "", nil, &dataFormatJSON, ""),
+ getAPI("apiName2", "", "", "", nil, nil, ""),
+ }
+ apiRegisterMock := mocks.APIRegister{}
+ apiRegisterMock.On("GetAPIs").Return(&apiList)
+ requestHandler := getEcho(&apiRegisterMock)
+
+ // Get APIs with filter
+ result := testutil.NewRequest().Get("/allServiceAPIs?api-invoker-id=api_invoker_id&data-format=JSON").Go(t, requestHandler)
+
+ assert.Equal(t, http.StatusOK, result.Code())
+ var resultInvoker discoverserviceapi.DiscoveredAPIs