github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/open_resource_discovery/fixtures_test.go (about)

     1  package ord_test
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"strconv"
     7  	"strings"
     8  	"time"
     9  
    10  	"github.com/kyma-incubator/compass/components/director/pkg/graphql"
    11  
    12  	"github.com/kyma-incubator/compass/components/director/internal/uid"
    13  	"github.com/kyma-incubator/compass/components/director/pkg/accessstrategy"
    14  
    15  	"github.com/kyma-incubator/compass/components/director/internal/model"
    16  	ord "github.com/kyma-incubator/compass/components/director/internal/open_resource_discovery"
    17  	"github.com/kyma-incubator/compass/components/director/pkg/pagination"
    18  	"github.com/kyma-incubator/compass/components/director/pkg/str"
    19  )
    20  
    21  const (
    22  	absoluteDocURL         = "http://config.com/open-resource-discovery/v1/documents/example1"
    23  	ordDocURI              = "/open-resource-discovery/v1/documents/example1"
    24  	baseURL                = "http://test.com:8080"
    25  	baseURL2               = "http://second.com"
    26  	customWebhookConfigURL = "http://custom.com/config/endpoint"
    27  	packageORDID           = "ns:package:PACKAGE_ID:v1"
    28  	productORDID           = "sap:product:id:"
    29  	globalProductORDID     = "sap:product:SAPCloudPlatform:"
    30  	product2ORDID          = "ns:product:id2:"
    31  	bundleORDID            = "ns:consumptionBundle:BUNDLE_ID:v1"
    32  	secondBundleORDID      = "ns:consumptionBundle:BUNDLE_ID:v2"
    33  	vendorORDID            = "sap:vendor:SAP:"
    34  	vendor2ORDID           = "partner:vendor:SAP:"
    35  	api1ORDID              = "ns:apiResource:API_ID:v2"
    36  	api2ORDID              = "ns:apiResource:API_ID2:v1"
    37  	event1ORDID            = "ns:eventResource:EVENT_ID:v1"
    38  	event2ORDID            = "ns2:eventResource:EVENT_ID:v1"
    39  
    40  	whID             = "testWh"
    41  	tenantID         = "testTenant"
    42  	externalTenantID = "externalTestTenant"
    43  	packageID        = "testPkg"
    44  	vendorID         = "testVendor"
    45  	vendorID2        = "testVendor2"
    46  	productID        = "testProduct"
    47  	bundleID         = "testBndl"
    48  	api1ID           = "testAPI1"
    49  	api2ID           = "testAPI2"
    50  	event1ID         = "testEvent1"
    51  	event2ID         = "testEvent2"
    52  	tombstoneID      = "testTs"
    53  	localTenantID    = "localTenantID"
    54  	webhookID        = "webhookID"
    55  
    56  	api1spec1ID  = "api1spec1ID"
    57  	api1spec2ID  = "api1spec2ID"
    58  	api1spec3ID  = "api1spec3ID"
    59  	api2spec1ID  = "api2spec1ID"
    60  	api2spec2ID  = "api2spec2ID"
    61  	event1specID = "event1specID"
    62  	event2specID = "event2specID"
    63  
    64  	cursor                    = "cursor"
    65  	policyLevel               = "sap:core:v1"
    66  	apiImplementationStandard = "cff:open-service-broker:v2"
    67  	correlationIDs            = `["foo.bar.baz:foo:123456","foo.bar.baz:bar:654321"]`
    68  	partners                  = `["microsoft:vendor:Microsoft:"]`
    69  
    70  	externalClientCertSecretName = "resource-name1"
    71  	extSvcClientCertSecretName   = "resource-name2"
    72  
    73  	appTemplateVersionID    = "testAppTemplateVersionID"
    74  	appTemplateVersionValue = "2303"
    75  	appTemplateName         = "appTemplateName"
    76  )
    77  
    78  var (
    79  	appID              = "testApp"
    80  	appTemplateID      = "testAppTemplate"
    81  	uidSvc             = uid.NewService()
    82  	packageLinksFormat = removeWhitespace(`[
    83          {
    84            "type": "terms-of-service",
    85            "url": "https://example.com/en/legal/terms-of-use.html"
    86          },
    87          {
    88            "type": "client-registration",
    89            "url": "%s/ui/public/showRegisterForm"
    90          }
    91        ]`)
    92  
    93  	linksFormat = removeWhitespace(`[
    94          {
    95  		  "description": "lorem ipsum dolor nem",
    96            "title": "Link Title",
    97            "url": "https://example.com/2018/04/11/testing/"
    98          },
    99  		{
   100  		  "description": "lorem ipsum dolor nem",
   101            "title": "Link Title",
   102            "url": "%s/testing/relative"
   103          }
   104        ]`)
   105  
   106  	packageLabels = removeWhitespace(`{
   107          "label-key-1": [
   108            "label-val"
   109          ],
   110  		"pkg-label": [
   111            "label-val"
   112          ]
   113        }`)
   114  
   115  	labels = removeWhitespace(`{
   116          "label-key-1": [
   117            "label-value-1",
   118            "label-value-2"
   119          ]
   120        }`)
   121  
   122  	mergedLabels = removeWhitespace(`{
   123          "label-key-1": [
   124            "label-val",
   125  		  "label-value-1",
   126            "label-value-2"
   127          ],
   128  		"pkg-label": [
   129            "label-val"
   130          ]
   131        }`)
   132  
   133  	tags = removeWhitespace(`[
   134          "testTag"
   135        ]`)
   136  
   137  	documentLabels = removeWhitespace(`{
   138          "Some Aspect": ["Markdown Documentation [with links](#)", "With multiple values"]
   139        }`)
   140  
   141  	hierarchy = removeWhitespace(`[
   142          "testHierarchy"
   143        ]`)
   144  
   145  	supportedUseCases = removeWhitespace(`[
   146          "mass-extraction"
   147        ]`)
   148  
   149  	credentialExchangeStrategiesWithCustomTypeFormat = removeWhitespace(`[
   150  		{
   151  		  "callbackUrl": "http://example.com/credentials",
   152            "customType": "%s",
   153  		  "type": "custom",
   154  		  "customDescription": "description"
   155          }
   156        ]`)
   157  
   158  	credentialExchangeStrategiesWithMultipleSameTypesFormat = removeWhitespace(`[
   159  		{
   160  		  "callbackUrl": "http://example.com/credentials-fake",
   161            "customType": "%s",
   162  		  "type": "custom",
   163  		  "customDescription": "description"
   164          },
   165          {
   166  		  "callbackUrl": "http://example.com/credentials",
   167            "customType": "%s",
   168  		  "type": "custom",
   169  		  "customDescription": "description"
   170          }
   171        ]`)
   172  
   173  	credentialExchangeStrategiesFormat = removeWhitespace(`[
   174          {
   175  		  "callbackUrl": "%s/credentials/relative",
   176            "customType": "ns:credential-exchange:v1",
   177  		  "type": "custom"
   178          },
   179  		{
   180  		  "callbackUrl": "http://example.com/credentials",
   181            "customType": "ns:credential-exchange2:v3",
   182  		  "type": "custom"
   183          },
   184  		{
   185  		  "callbackUrl": "http://example.com/credentials",
   186            "customType": "%s",
   187  		  "type": "custom"
   188          }
   189        ]`)
   190  
   191  	credentialExchangeStrategiesBasic = removeWhitespace(`[
   192  		{
   193  		  "callbackUrl": "http://example.com/credentials",
   194            "customType": "ns:credential-exchange2:v3",
   195  		  "type": "custom"
   196          }
   197        ]`)
   198  
   199  	apiResourceLinksFormat = removeWhitespace(`[
   200          {
   201            "type": "console",
   202            "url": "https://example.com/shell/discover"
   203          },
   204  		{
   205            "type": "console",
   206            "url": "%s/shell/discover/relative"
   207          }
   208        ]`)
   209  
   210  	changeLogEntries = removeWhitespace(`[
   211          {
   212  		  "date": "2020-04-29",
   213  		  "description": "lorem ipsum dolor sit amet",
   214  		  "releaseStatus": "active",
   215  		  "url": "https://example.com/changelog/v1",
   216            "version": "1.0.0"
   217          }
   218        ]`)
   219  
   220  	boolPtr = true
   221  
   222  	apisFromDB = map[string]*model.APIDefinition{
   223  		api1ORDID: fixAPIsWithHash()[0],
   224  		api2ORDID: fixAPIsWithHash()[1],
   225  	}
   226  
   227  	eventsFromDB = map[string]*model.EventDefinition{
   228  		event1ORDID: fixEventsWithHash()[0],
   229  		event2ORDID: fixEventsWithHash()[1],
   230  	}
   231  
   232  	pkgsFromDB = map[string]*model.Package{
   233  		packageORDID: fixPackagesWithHash()[0],
   234  	}
   235  
   236  	bndlsFromDB = map[string]*model.Bundle{
   237  		bundleORDID: fixBundlesWithHash()[0],
   238  	}
   239  
   240  	hashAPI1, _    = ord.HashObject(fixORDDocument().APIResources[0])
   241  	hashAPI2, _    = ord.HashObject(fixORDDocument().APIResources[1])
   242  	hashEvent1, _  = ord.HashObject(fixORDDocument().EventResources[0])
   243  	hashEvent2, _  = ord.HashObject(fixORDDocument().EventResources[1])
   244  	hashPackage, _ = ord.HashObject(fixORDDocument().Packages[0])
   245  
   246  	resourceHashes = fixResourceHashes()
   247  
   248  	credentialExchangeStrategyType           = "sap.ucl:tenant-mapping:v1"
   249  	credentialExchangeStrategyVersion        = "v1"
   250  	credentialExchangeStrategyTenantMappings = map[string]ord.CredentialExchangeStrategyTenantMapping{
   251  		credentialExchangeStrategyType: {
   252  			Mode:    model.WebhookModeSync,
   253  			Version: credentialExchangeStrategyVersion,
   254  		},
   255  	}
   256  )
   257  
   258  func fixResourceHashes() map[string]uint64 {
   259  	return map[string]uint64{
   260  		api1ORDID:    hashAPI1,
   261  		api2ORDID:    hashAPI2,
   262  		event1ORDID:  hashEvent1,
   263  		event2ORDID:  hashEvent2,
   264  		packageORDID: hashPackage,
   265  	}
   266  }
   267  
   268  func fixWellKnownConfig() *ord.WellKnownConfig {
   269  	return &ord.WellKnownConfig{
   270  		Schema:  "../spec/v1/generated/Configuration.schema.json",
   271  		BaseURL: baseURL,
   272  		OpenResourceDiscoveryV1: ord.OpenResourceDiscoveryV1{
   273  			Documents: []ord.DocumentDetails{
   274  				{
   275  					URL:                 ordDocURI,
   276  					SystemInstanceAware: true,
   277  					AccessStrategies: []accessstrategy.AccessStrategy{
   278  						{
   279  							Type: accessstrategy.OpenAccessStrategy,
   280  						},
   281  					},
   282  				},
   283  			},
   284  		},
   285  	}
   286  }
   287  
   288  func fixORDDocument() *ord.Document {
   289  	return fixORDDocumentWithBaseURL("")
   290  }
   291  
   292  func fixORDStaticDocument() *ord.Document {
   293  	doc := fixORDDocumentWithBaseURL("")
   294  	doc.DescribedSystemInstance = nil
   295  	doc.DescribedSystemVersion = fixAppTemplateVersionInput()
   296  	doc.ConsumptionBundles[0].CredentialExchangeStrategies = json.RawMessage(credentialExchangeStrategiesBasic)
   297  
   298  	return doc
   299  }
   300  
   301  func fixSanitizedORDDocument() *ord.Document {
   302  	sanitizedDoc := fixORDDocumentWithBaseURL(baseURL)
   303  	sanitizeResources(sanitizedDoc)
   304  	return sanitizedDoc
   305  }
   306  
   307  func fixSanitizedStaticORDDocument() *ord.Document {
   308  	sanitizedDoc := fixORDStaticDocumentWithBaseURL(baseURL)
   309  	sanitizeResources(sanitizedDoc)
   310  	return sanitizedDoc
   311  }
   312  
   313  func sanitizeResources(doc *ord.Document) {
   314  	doc.APIResources[0].Tags = json.RawMessage(`["testTag","apiTestTag"]`)
   315  	doc.APIResources[0].Countries = json.RawMessage(`["BG","EN","US"]`)
   316  	doc.APIResources[0].LineOfBusiness = json.RawMessage(`["Finance","Sales"]`)
   317  	doc.APIResources[0].Industry = json.RawMessage(`["Automotive","Banking","Chemicals"]`)
   318  	doc.APIResources[0].Labels = json.RawMessage(mergedLabels)
   319  
   320  	doc.APIResources[1].Tags = json.RawMessage(`["testTag","ZGWSAMPLE"]`)
   321  	doc.APIResources[1].Countries = json.RawMessage(`["BG","EN","BR"]`)
   322  	doc.APIResources[1].LineOfBusiness = json.RawMessage(`["Finance","Sales"]`)
   323  	doc.APIResources[1].Industry = json.RawMessage(`["Automotive","Banking","Chemicals"]`)
   324  	doc.APIResources[1].Labels = json.RawMessage(mergedLabels)
   325  
   326  	doc.EventResources[0].Tags = json.RawMessage(`["testTag","eventTestTag"]`)
   327  	doc.EventResources[0].Countries = json.RawMessage(`["BG","EN","US"]`)
   328  	doc.EventResources[0].LineOfBusiness = json.RawMessage(`["Finance","Sales"]`)
   329  	doc.EventResources[0].Industry = json.RawMessage(`["Automotive","Banking","Chemicals"]`)
   330  	doc.EventResources[0].Labels = json.RawMessage(mergedLabels)
   331  
   332  	doc.EventResources[1].Tags = json.RawMessage(`["testTag","eventTestTag2"]`)
   333  	doc.EventResources[1].Countries = json.RawMessage(`["BG","EN","BR"]`)
   334  	doc.EventResources[1].LineOfBusiness = json.RawMessage(`["Finance","Sales"]`)
   335  	doc.EventResources[1].Industry = json.RawMessage(`["Automotive","Banking","Chemicals"]`)
   336  	doc.EventResources[1].Labels = json.RawMessage(mergedLabels)
   337  }
   338  
   339  func fixORDDocumentWithBaseURL(providedBaseURL string) *ord.Document {
   340  	return &ord.Document{
   341  		Schema:                "./spec/v1/generated/Document.schema.json",
   342  		OpenResourceDiscovery: "1.0",
   343  		Description:           "Test Document",
   344  		Perspective:           ord.SystemInstancePerspective,
   345  		DescribedSystemInstance: &model.Application{
   346  			BaseURL:             str.Ptr(baseURL),
   347  			OrdLabels:           json.RawMessage(labels),
   348  			Tags:                json.RawMessage(tags),
   349  			DocumentationLabels: json.RawMessage(documentLabels),
   350  		},
   351  		Packages: []*model.PackageInput{
   352  			{
   353  				OrdID:               packageORDID,
   354  				Vendor:              str.Ptr(vendorORDID),
   355  				Title:               "PACKAGE 1 TITLE",
   356  				ShortDescription:    "lorem ipsum",
   357  				Description:         "lorem ipsum dolor set",
   358  				Version:             "1.1.2",
   359  				PackageLinks:        json.RawMessage(fmt.Sprintf(packageLinksFormat, providedBaseURL)),
   360  				Links:               json.RawMessage(fmt.Sprintf(linksFormat, providedBaseURL)),
   361  				LicenseType:         str.Ptr("licence"),
   362  				SupportInfo:         str.Ptr("support-info"),
   363  				Tags:                json.RawMessage(tags),
   364  				Countries:           json.RawMessage(`["BG","EN"]`),
   365  				Labels:              json.RawMessage(packageLabels),
   366  				DocumentationLabels: json.RawMessage(documentLabels),
   367  				PolicyLevel:         policyLevel,
   368  				PartOfProducts:      json.RawMessage(fmt.Sprintf(`["%s"]`, productORDID)),
   369  				LineOfBusiness:      json.RawMessage(`["Finance","Sales"]`),
   370  				Industry:            json.RawMessage(`["Automotive","Banking","Chemicals"]`),
   371  			},
   372  		},
   373  		ConsumptionBundles: []*model.BundleCreateInput{
   374  			{
   375  				Name:                         "BUNDLE TITLE",
   376  				Description:                  str.Ptr("lorem ipsum dolor nsq sme"),
   377  				Version:                      str.Ptr("1.1.2"),
   378  				OrdID:                        str.Ptr(bundleORDID),
   379  				LocalTenantID:                str.Ptr(localTenantID),
   380  				ShortDescription:             str.Ptr("lorem ipsum"),
   381  				Links:                        json.RawMessage(fmt.Sprintf(linksFormat, providedBaseURL)),
   382  				Tags:                         json.RawMessage(tags),
   383  				Labels:                       json.RawMessage(labels),
   384  				DocumentationLabels:          json.RawMessage(documentLabels),
   385  				CredentialExchangeStrategies: json.RawMessage(fmt.Sprintf(credentialExchangeStrategiesFormat, providedBaseURL, credentialExchangeStrategyType)),
   386  				CorrelationIDs:               json.RawMessage(correlationIDs),
   387  			},
   388  		},
   389  		Products: []*model.ProductInput{
   390  			{
   391  				OrdID:               productORDID,
   392  				Title:               "PRODUCT TITLE",
   393  				ShortDescription:    "lorem ipsum",
   394  				Vendor:              vendorORDID,
   395  				Parent:              str.Ptr(product2ORDID),
   396  				CorrelationIDs:      json.RawMessage(correlationIDs),
   397  				Tags:                json.RawMessage(tags),
   398  				Labels:              json.RawMessage(labels),
   399  				DocumentationLabels: json.RawMessage(documentLabels),
   400  			},
   401  		},
   402  		APIResources: []*model.APIDefinitionInput{
   403  			{
   404  				OrdID:                                   str.Ptr(api1ORDID),
   405  				LocalTenantID:                           str.Ptr(localTenantID),
   406  				OrdPackageID:                            str.Ptr(packageORDID),
   407  				Name:                                    "API TITLE",
   408  				Description:                             str.Ptr("lorem ipsum dolor sit amet"),
   409  				TargetURLs:                              json.RawMessage(`["https://exmaple.com/test/v1","https://exmaple.com/test/v2"]`),
   410  				ShortDescription:                        str.Ptr("lorem ipsum"),
   411  				SystemInstanceAware:                     &boolPtr,
   412  				APIProtocol:                             str.Ptr("odata-v2"),
   413  				Tags:                                    json.RawMessage(`["apiTestTag"]`),
   414  				Countries:                               json.RawMessage(`["BG","US"]`),
   415  				Links:                                   json.RawMessage(fmt.Sprintf(linksFormat, providedBaseURL)),
   416  				APIResourceLinks:                        json.RawMessage(fmt.Sprintf(apiResourceLinksFormat, providedBaseURL)),
   417  				ReleaseStatus:                           str.Ptr("active"),
   418  				SunsetDate:                              nil,
   419  				Successors:                              nil,
   420  				ChangeLogEntries:                        json.RawMessage(changeLogEntries),
   421  				Labels:                                  json.RawMessage(labels),
   422  				Hierarchy:                               json.RawMessage(hierarchy),
   423  				SupportedUseCases:                       json.RawMessage(supportedUseCases),
   424  				DocumentationLabels:                     json.RawMessage(documentLabels),
   425  				Visibility:                              str.Ptr("public"),
   426  				Disabled:                                &boolPtr,
   427  				PartOfProducts:                          json.RawMessage(fmt.Sprintf(`["%s"]`, productORDID)),
   428  				LineOfBusiness:                          json.RawMessage(`["Finance","Sales"]`),
   429  				Industry:                                json.RawMessage(`["Automotive","Banking","Chemicals"]`),
   430  				ImplementationStandard:                  str.Ptr(apiImplementationStandard),
   431  				CustomImplementationStandard:            nil,
   432  				CustomImplementationStandardDescription: nil,
   433  				Extensible:                              json.RawMessage(`{"supported":"automatic","description":"Please find the extensibility documentation"}`),
   434  				ResourceDefinitions: []*model.APIResourceDefinition{
   435  					{
   436  						Type:      "openapi-v3",
   437  						MediaType: "application/json",
   438  						URL:       fmt.Sprintf("%s/external-api/unsecured/spec/flapping", providedBaseURL),
   439  						AccessStrategy: []accessstrategy.AccessStrategy{
   440  							{
   441  								Type: "open",
   442  							},
   443  						},
   444  					},
   445  					{
   446  						Type:      "openapi-v3",
   447  						MediaType: "text/yaml",
   448  						URL:       "https://test.com/odata/1.0/catalog",
   449  						AccessStrategy: []accessstrategy.AccessStrategy{
   450  							{
   451  								Type: "open",
   452  							},
   453  						},
   454  					},
   455  					{
   456  						Type:      "edmx",
   457  						MediaType: "application/xml",
   458  						URL:       "https://TEST:443//odata/$metadata",
   459  						AccessStrategy: []accessstrategy.AccessStrategy{
   460  							{
   461  								Type: "open",
   462  							},
   463  						},
   464  					},
   465  				},
   466  				PartOfConsumptionBundles: []*model.ConsumptionBundleReference{
   467  					{
   468  						BundleOrdID:      bundleORDID,
   469  						DefaultTargetURL: "https://exmaple.com/test/v1",
   470  					},
   471  				},
   472  				VersionInput: &model.VersionInput{
   473  					Value: "2.1.2",
   474  				},
   475  			},
   476  			{
   477  				Extensible:                              json.RawMessage(`{"supported":"automatic","description":"Please find the extensibility documentation"}`),
   478  				OrdID:                                   str.Ptr(api2ORDID),
   479  				LocalTenantID:                           str.Ptr(localTenantID),
   480  				OrdPackageID:                            str.Ptr(packageORDID),
   481  				Name:                                    "Gateway Sample Service",
   482  				Description:                             str.Ptr("lorem ipsum dolor sit amet"),
   483  				TargetURLs:                              json.RawMessage(`["http://localhost:8080/some-api/v1"]`),
   484  				ShortDescription:                        str.Ptr("lorem ipsum"),
   485  				SystemInstanceAware:                     &boolPtr,
   486  				APIProtocol:                             str.Ptr("odata-v2"),
   487  				Tags:                                    json.RawMessage(`["ZGWSAMPLE"]`),
   488  				Countries:                               json.RawMessage(`["BR"]`),
   489  				Links:                                   json.RawMessage(fmt.Sprintf(linksFormat, providedBaseURL)),
   490  				APIResourceLinks:                        json.RawMessage(fmt.Sprintf(apiResourceLinksFormat, providedBaseURL)),
   491  				ReleaseStatus:                           str.Ptr("deprecated"),
   492  				SunsetDate:                              str.Ptr("2020-12-08T15:47:04+0000"),
   493  				Successors:                              json.RawMessage(fmt.Sprintf(`["%s"]`, api1ORDID)),
   494  				ChangeLogEntries:                        json.RawMessage(changeLogEntries),
   495  				Labels:                                  json.RawMessage(labels),
   496  				Hierarchy:                               json.RawMessage(hierarchy),
   497  				SupportedUseCases:                       json.RawMessage(supportedUseCases),
   498  				DocumentationLabels:                     json.RawMessage(documentLabels),
   499  				Visibility:                              str.Ptr("public"),
   500  				Disabled:                                nil,
   501  				PartOfProducts:                          json.RawMessage(fmt.Sprintf(`["%s"]`, productORDID)),
   502  				LineOfBusiness:                          json.RawMessage(`["Finance","Sales"]`),
   503  				Industry:                                json.RawMessage(`["Automotive","Banking","Chemicals"]`),
   504  				ImplementationStandard:                  str.Ptr(apiImplementationStandard),
   505  				CustomImplementationStandard:            nil,
   506  				CustomImplementationStandardDescription: nil,
   507  				ResourceDefinitions: []*model.APIResourceDefinition{
   508  					{
   509  						Type:      "edmx",
   510  						MediaType: "application/xml",
   511  						URL:       "https://TEST:443//odata/$metadata",
   512  						AccessStrategy: []accessstrategy.AccessStrategy{
   513  							{
   514  								Type: "open",
   515  							},
   516  						},
   517  					},
   518  					{
   519  						Type:      "openapi-v3",
   520  						MediaType: "application/json",
   521  						URL:       fmt.Sprintf("%s/odata/1.0/catalog.svc/$value?type=json", providedBaseURL),
   522  						AccessStrategy: []accessstrategy.AccessStrategy{
   523  							{
   524  								Type: "open",
   525  							},
   526  						},
   527  					},
   528  				},
   529  				PartOfConsumptionBundles: []*model.ConsumptionBundleReference{
   530  					{
   531  						BundleOrdID: bundleORDID,
   532  					},
   533  				},
   534  				VersionInput: &model.VersionInput{
   535  					Value: "1.1.0",
   536  				},
   537  			},
   538  		},
   539  		EventResources: []*model.EventDefinitionInput{
   540  			{
   541  				OrdID:               str.Ptr(event1ORDID),
   542  				LocalTenantID:       str.Ptr(localTenantID),
   543  				OrdPackageID:        str.Ptr(packageORDID),
   544  				Name:                "EVENT TITLE",
   545  				Description:         str.Ptr("lorem ipsum dolor sit amet"),
   546  				ShortDescription:    str.Ptr("lorem ipsum"),
   547  				SystemInstanceAware: &boolPtr,
   548  				ChangeLogEntries:    json.RawMessage(changeLogEntries),
   549  				Links:               json.RawMessage(fmt.Sprintf(linksFormat, providedBaseURL)),
   550  				Tags:                json.RawMessage(`["eventTestTag"]`),
   551  				Countries:           json.RawMessage(`["BG","US"]`),
   552  				ReleaseStatus:       str.Ptr("active"),
   553  				SunsetDate:          nil,
   554  				Successors:          nil,
   555  				Labels:              json.RawMessage(labels),
   556  				Hierarchy:           json.RawMessage(hierarchy),
   557  				DocumentationLabels: json.RawMessage(documentLabels),
   558  				Visibility:          str.Ptr("public"),
   559  				Disabled:            &boolPtr,
   560  				PartOfProducts:      json.RawMessage(fmt.Sprintf(`["%s"]`, productORDID)),
   561  				LineOfBusiness:      json.RawMessage(`["Finance","Sales"]`),
   562  				Industry:            json.RawMessage(`["Automotive","Banking","Chemicals"]`),
   563  				Extensible:          json.RawMessage(`{"supported":"automatic","description":"Please find the extensibility documentation"}`),
   564  				ResourceDefinitions: []*model.EventResourceDefinition{
   565  					{
   566  						Type:      "asyncapi-v2",
   567  						MediaType: "application/json",
   568  						URL:       "http://localhost:8080/asyncApi2.json",
   569  						AccessStrategy: []accessstrategy.AccessStrategy{
   570  							{
   571  								Type: "open",
   572  							},
   573  						},
   574  					},
   575  				},
   576  				PartOfConsumptionBundles: []*model.ConsumptionBundleReference{
   577  					{
   578  						BundleOrdID: bundleORDID,
   579  					},
   580  				},
   581  				VersionInput: &model.VersionInput{
   582  					Value: "2.1.2",
   583  				},
   584  			},
   585  			{
   586  				OrdID:               str.Ptr(event2ORDID),
   587  				LocalTenantID:       str.Ptr(localTenantID),
   588  				OrdPackageID:        str.Ptr(packageORDID),
   589  				Name:                "EVENT TITLE 2",
   590  				Description:         str.Ptr("lorem ipsum dolor sit amet"),
   591  				ShortDescription:    str.Ptr("lorem ipsum"),
   592  				SystemInstanceAware: &boolPtr,
   593  				ChangeLogEntries:    json.RawMessage(changeLogEntries),
   594  				Links:               json.RawMessage(fmt.Sprintf(linksFormat, providedBaseURL)),
   595  				Tags:                json.RawMessage(`["eventTestTag2"]`),
   596  				Countries:           json.RawMessage(`["BR"]`),
   597  				ReleaseStatus:       str.Ptr("deprecated"),
   598  				SunsetDate:          str.Ptr("2020-12-08T15:47:04+0000"),
   599  				Successors:          json.RawMessage(fmt.Sprintf(`["%s"]`, event2ORDID)),
   600  				Labels:              json.RawMessage(labels),
   601  				Hierarchy:           json.RawMessage(hierarchy),
   602  				DocumentationLabels: json.RawMessage(documentLabels),
   603  				Visibility:          str.Ptr("public"),
   604  				Disabled:            nil,
   605  				PartOfProducts:      json.RawMessage(fmt.Sprintf(`["%s"]`, productORDID)),
   606  				LineOfBusiness:      json.RawMessage(`["Finance","Sales"]`),
   607  				Industry:            json.RawMessage(`["Automotive","Banking","Chemicals"]`),
   608  				Extensible:          json.RawMessage(`{"supported":"automatic","description":"Please find the extensibility documentation"}`),
   609  				ResourceDefinitions: []*model.EventResourceDefinition{
   610  					{
   611  						Type:      "asyncapi-v2",
   612  						MediaType: "application/json",
   613  						URL:       fmt.Sprintf("%s/api/eventCatalog.json", providedBaseURL),
   614  						AccessStrategy: []accessstrategy.AccessStrategy{
   615  							{
   616  								Type: "open",
   617  							},
   618  						},
   619  					},
   620  				},
   621  				PartOfConsumptionBundles: []*model.ConsumptionBundleReference{
   622  					{
   623  						BundleOrdID: bundleORDID,
   624  					},
   625  				},
   626  				VersionInput: &model.VersionInput{
   627  					Value: "1.1.0",
   628  				},
   629  			},
   630  		},
   631  		Tombstones: []*model.TombstoneInput{
   632  			{
   633  				OrdID:       api2ORDID,
   634  				RemovalDate: "2020-12-02T14:12:59Z",
   635  			},
   636  		},
   637  		Vendors: []*model.VendorInput{
   638  			{
   639  				OrdID:               vendorORDID,
   640  				Title:               "SAP",
   641  				Partners:            json.RawMessage(partners),
   642  				Tags:                json.RawMessage(tags),
   643  				Labels:              json.RawMessage(labels),
   644  				DocumentationLabels: json.RawMessage(documentLabels),
   645  			},
   646  			{
   647  				OrdID:               vendor2ORDID,
   648  				Title:               "SAP",
   649  				Partners:            json.RawMessage(partners),
   650  				Tags:                json.RawMessage(tags),
   651  				Labels:              json.RawMessage(labels),
   652  				DocumentationLabels: json.RawMessage(documentLabels),
   653  			},
   654  		},
   655  	}
   656  }
   657  
   658  func fixORDStaticDocumentWithBaseURL(providedBaseURL string) *ord.Document {
   659  	doc := fixORDDocumentWithBaseURL(providedBaseURL)
   660  	doc.DescribedSystemInstance = nil
   661  	doc.DescribedSystemVersion = fixAppTemplateVersionInput()
   662  	doc.ConsumptionBundles[0].CredentialExchangeStrategies = json.RawMessage(credentialExchangeStrategiesBasic)
   663  
   664  	return doc
   665  }
   666  
   667  func fixApplicationPage() *model.ApplicationPage {
   668  	return &model.ApplicationPage{
   669  		Data: []*model.Application{
   670  			{
   671  				Name: "testApp",
   672  				BaseEntity: &model.BaseEntity{
   673  					ID:    appID,
   674  					Ready: true,
   675  				},
   676  				Type:                  testApplicationType,
   677  				ApplicationTemplateID: str.Ptr(appTemplateID),
   678  			},
   679  		},
   680  		PageInfo: &pagination.Page{
   681  			StartCursor: cursor,
   682  			EndCursor:   cursor,
   683  			HasNextPage: false,
   684  		},
   685  		TotalCount: 1,
   686  	}
   687  }
   688  
   689  func fixAppTemplate() *model.ApplicationTemplate {
   690  	return &model.ApplicationTemplate{
   691  		ID:   appTemplateID,
   692  		Name: appTemplateName,
   693  	}
   694  }
   695  
   696  func fixAppTemplateVersions() []*model.ApplicationTemplateVersion {
   697  	return []*model.ApplicationTemplateVersion{
   698  		fixAppTemplateVersion(),
   699  	}
   700  }
   701  
   702  func fixAppTemplateVersion() *model.ApplicationTemplateVersion {
   703  	return &model.ApplicationTemplateVersion{
   704  		ID:                    appTemplateVersionID,
   705  		Version:               appTemplateVersionValue,
   706  		CorrelationIDs:        json.RawMessage(correlationIDs),
   707  		ApplicationTemplateID: appTemplateID,
   708  	}
   709  }
   710  
   711  func fixAppTemplateVersionInput() *model.ApplicationTemplateVersionInput {
   712  	return &model.ApplicationTemplateVersionInput{
   713  		Version:        appTemplateVersionValue,
   714  		Title:          str.Ptr("Title"),
   715  		ReleaseDate:    str.Ptr("2020-12-08T15:47:04+0000"),
   716  		CorrelationIDs: json.RawMessage(correlationIDs),
   717  	}
   718  }
   719  
   720  func fixApplications() []*model.Application {
   721  	return []*model.Application{
   722  		{
   723  			Name: "testApp",
   724  			BaseEntity: &model.BaseEntity{
   725  				ID:    appID,
   726  				Ready: true,
   727  			},
   728  			Type:                  testApplicationType,
   729  			ApplicationTemplateID: str.Ptr(appTemplateID),
   730  		},
   731  	}
   732  }
   733  
   734  func fixTenantMappingWebhookGraphQLInput() *graphql.WebhookInput {
   735  	syncMode := graphql.WebhookModeSync
   736  	return &graphql.WebhookInput{
   737  		URL: str.Ptr("http://example.com/credentials"),
   738  		Auth: &graphql.AuthInput{
   739  			AccessStrategy: str.Ptr(string(accessstrategy.CMPmTLSAccessStrategy)),
   740  		},
   741  		Mode:    &syncMode,
   742  		Version: str.Ptr(credentialExchangeStrategyVersion),
   743  	}
   744  }
   745  
   746  func fixTenantMappingWebhookModelInput() *model.WebhookInput {
   747  	syncMode := model.WebhookModeSync
   748  	return &model.WebhookInput{
   749  		URL: str.Ptr("http://example.com/credentials"),
   750  		Auth: &model.AuthInput{
   751  			AccessStrategy: str.Ptr(string(accessstrategy.CMPmTLSAccessStrategy)),
   752  		},
   753  		Mode: &syncMode,
   754  	}
   755  }
   756  
   757  func fixWebhooksForApplication() []*model.Webhook {
   758  	return []*model.Webhook{
   759  		{
   760  			ID:         whID,
   761  			ObjectID:   appID,
   762  			ObjectType: model.ApplicationWebhookReference,
   763  			Type:       model.WebhookTypeOpenResourceDiscovery,
   764  			URL:        str.Ptr(baseURL),
   765  		},
   766  	}
   767  }
   768  func fixOrdWebhooksForAppTemplate() []*model.Webhook {
   769  	return []*model.Webhook{
   770  		{
   771  			ID:         whID,
   772  			ObjectID:   appTemplateID,
   773  			ObjectType: model.ApplicationTemplateWebhookReference,
   774  			Type:       model.WebhookTypeOpenResourceDiscovery,
   775  			URL:        str.Ptr(baseURL),
   776  		},
   777  	}
   778  }
   779  func fixTenantMappingWebhooksForApplication() []*model.Webhook {
   780  	syncMode := model.WebhookModeSync
   781  	return []*model.Webhook{{
   782  		ID:  webhookID,
   783  		URL: str.Ptr("http://example.com/credentials"),
   784  		Auth: &model.Auth{
   785  			AccessStrategy: str.Ptr(string(accessstrategy.CMPmTLSAccessStrategy)),
   786  		},
   787  		Mode:       &syncMode,
   788  		ObjectType: model.ApplicationWebhookReference,
   789  		ObjectID:   appID,
   790  	}}
   791  }
   792  
   793  func fixVendors() []*model.Vendor {
   794  	return []*model.Vendor{
   795  		{
   796  			ID:                  vendorID,
   797  			OrdID:               vendorORDID,
   798  			ApplicationID:       str.Ptr(appID),
   799  			Title:               "SAP",
   800  			Partners:            json.RawMessage(partners),
   801  			Labels:              json.RawMessage(labels),
   802  			DocumentationLabels: json.RawMessage(documentLabels),
   803  		},
   804  		{
   805  			ID:                  vendorID2,
   806  			OrdID:               vendor2ORDID,
   807  			Title:               "SAP",
   808  			Partners:            json.RawMessage(partners),
   809  			Labels:              json.RawMessage(labels),
   810  			DocumentationLabels: json.RawMessage(documentLabels),
   811  		},
   812  	}
   813  }
   814  
   815  func fixGlobalVendors() []*model.Vendor {
   816  	return []*model.Vendor{
   817  		{
   818  			ID:    vendorID,
   819  			OrdID: vendorORDID,
   820  			Title: "SAP SE",
   821  		},
   822  	}
   823  }
   824  
   825  func fixProducts() []*model.Product {
   826  	return []*model.Product{
   827  		{
   828  			ID:                  productID,
   829  			OrdID:               productORDID,
   830  			ApplicationID:       str.Ptr(appID),
   831  			Title:               "PRODUCT TITLE",
   832  			ShortDescription:    "lorem ipsum",
   833  			Vendor:              vendorORDID,
   834  			Parent:              str.Ptr(product2ORDID),
   835  			CorrelationIDs:      json.RawMessage(`["foo.bar.baz:123456"]`),
   836  			Labels:              json.RawMessage(labels),
   837  			DocumentationLabels: json.RawMessage(documentLabels),
   838  		},
   839  	}
   840  }
   841  
   842  func fixGlobalProducts() []*model.Product {
   843  	return []*model.Product{
   844  		{
   845  			ID:               productID,
   846  			OrdID:            globalProductORDID,
   847  			Title:            "SAP Business Technology Platform",
   848  			ShortDescription: "Accelerate business outcomes with integration, data to value, and extensibility.",
   849  			Vendor:           vendorORDID,
   850  		},
   851  	}
   852  }
   853  
   854  func fixPackages() []*model.Package {
   855  	return []*model.Package{
   856  		{
   857  			ID:                  packageID,
   858  			ApplicationID:       &appID,
   859  			OrdID:               packageORDID,
   860  			Vendor:              str.Ptr(vendorORDID),
   861  			Title:               "PACKAGE 1 TITLE",
   862  			ShortDescription:    "lorem ipsum",
   863  			Description:         "lorem ipsum dolor set",
   864  			Version:             "1.1.2",
   865  			PackageLinks:        json.RawMessage(fmt.Sprintf(packageLinksFormat, baseURL)),
   866  			Links:               json.RawMessage(fmt.Sprintf(linksFormat, baseURL)),
   867  			LicenseType:         str.Ptr("licence"),
   868  			SupportInfo:         str.Ptr("support-info"),
   869  			Tags:                json.RawMessage(`["testTag"]`),
   870  			Countries:           json.RawMessage(`["BG","EN"]`),
   871  			Labels:              json.RawMessage(packageLabels),
   872  			DocumentationLabels: json.RawMessage(documentLabels),
   873  			PolicyLevel:         policyLevel,
   874  			PartOfProducts:      json.RawMessage(fmt.Sprintf(`["%s"]`, productORDID)),
   875  			LineOfBusiness:      json.RawMessage(`["Finance","Sales"]`),
   876  			Industry:            json.RawMessage(`["Automotive","Banking","Chemicals"]`),
   877  		},
   878  	}
   879  }
   880  
   881  func fixBundles() []*model.Bundle {
   882  	return []*model.Bundle{
   883  		{
   884  			ApplicationID:                &appID,
   885  			Name:                         "BUNDLE TITLE",
   886  			Description:                  str.Ptr("lorem ipsum dolor nsq sme"),
   887  			Version:                      str.Ptr("1.1.2"),
   888  			OrdID:                        str.Ptr(bundleORDID),
   889  			LocalTenantID:                str.Ptr(localTenantID),
   890  			ShortDescription:             str.Ptr("lorem ipsum"),
   891  			Links:                        json.RawMessage(fmt.Sprintf(linksFormat, baseURL)),
   892  			Labels:                       json.RawMessage(labels),
   893  			DocumentationLabels:          json.RawMessage(documentLabels),
   894  			CredentialExchangeStrategies: json.RawMessage(fmt.Sprintf(credentialExchangeStrategiesFormat, baseURL)),
   895  			CorrelationIDs:               json.RawMessage(correlationIDs),
   896  			BaseEntity: &model.BaseEntity{
   897  				ID:    bundleID,
   898  				Ready: true,
   899  			},
   900  		},
   901  	}
   902  }
   903  
   904  func fixBundlesWithCredentialExchangeStrategies() []*model.Bundle {
   905  	bundles := fixBundles()
   906  	bundles[0].CredentialExchangeStrategies = json.RawMessage(credentialExchangeStrategiesBasic)
   907  	return bundles
   908  }
   909  
   910  func fixBundleCreateInput() []*model.BundleCreateInput {
   911  	return []*model.BundleCreateInput{
   912  		{
   913  			Name:                "BUNDLE TITLE",
   914  			Description:         str.Ptr("lorem ipsum dolor nsq sme"),
   915  			Version:             str.Ptr("1.1.2"),
   916  			OrdID:               str.Ptr(bundleORDID),
   917  			LocalTenantID:       str.Ptr(localTenantID),
   918  			ShortDescription:    str.Ptr("lorem ipsum"),
   919  			Labels:              json.RawMessage(labels),
   920  			DocumentationLabels: json.RawMessage(documentLabels),
   921  			CorrelationIDs:      json.RawMessage(correlationIDs),
   922  		},
   923  		{
   924  			Name:                "BUNDLE TITLE 2 ",
   925  			Description:         str.Ptr("foo bar"),
   926  			Version:             str.Ptr("1.1.2"),
   927  			OrdID:               str.Ptr(secondBundleORDID),
   928  			LocalTenantID:       str.Ptr(localTenantID),
   929  			ShortDescription:    str.Ptr("bar foo"),
   930  			Labels:              json.RawMessage(labels),
   931  			DocumentationLabels: json.RawMessage(documentLabels),
   932  			CorrelationIDs:      json.RawMessage(correlationIDs),
   933  		},
   934  	}
   935  }
   936  
   937  func fixAPIsWithHash() []*model.APIDefinition {
   938  	apis := fixAPIs()
   939  
   940  	for idx, api := range apis {
   941  		ordID := str.PtrStrToStr(api.OrdID)
   942  		hash := str.Ptr(strconv.FormatUint(resourceHashes[ordID], 10))
   943  		api.ResourceHash = hash
   944  		api.Version.Value = fixORDDocument().APIResources[idx].VersionInput.Value
   945  	}
   946  
   947  	return apis
   948  }
   949  
   950  func fixEventsWithHash() []*model.EventDefinition {
   951  	events := fixEvents()
   952  
   953  	for idx, event := range events {
   954  		ordID := str.PtrStrToStr(event.OrdID)
   955  		hash := str.Ptr(strconv.FormatUint(resourceHashes[ordID], 10))
   956  		event.ResourceHash = hash
   957  		event.Version.Value = fixORDDocument().EventResources[idx].VersionInput.Value
   958  	}
   959  
   960  	return events
   961  }
   962  
   963  func fixPackagesWithHash() []*model.Package {
   964  	pkgs := fixPackages()
   965  
   966  	for idx, pkg := range pkgs {
   967  		hash := str.Ptr(strconv.FormatUint(resourceHashes[pkg.OrdID], 10))
   968  		pkg.ResourceHash = hash
   969  		pkg.Version = fixORDDocument().Packages[idx].Version
   970  	}
   971  
   972  	return pkgs
   973  }
   974  
   975  func fixBundlesWithHash() []*model.Bundle {
   976  	bndls := fixBundles()
   977  
   978  	for idx, bndl := range bndls {
   979  		hash := str.Ptr(strconv.FormatUint(resourceHashes[str.PtrStrToStr(bndl.OrdID)], 10))
   980  		bndl.ResourceHash = hash
   981  		bndl.Version = fixORDDocument().ConsumptionBundles[idx].Version
   982  	}
   983  
   984  	return bndls
   985  }
   986  
   987  func fixAPIs() []*model.APIDefinition {
   988  	return []*model.APIDefinition{
   989  		{
   990  			ApplicationID:                           &appID,
   991  			PackageID:                               str.Ptr(packageORDID),
   992  			Name:                                    "API TITLE",
   993  			Description:                             str.Ptr("lorem ipsum dolor sit amet"),
   994  			TargetURLs:                              json.RawMessage(`["/test/v1"]`),
   995  			OrdID:                                   str.Ptr(api1ORDID),
   996  			ShortDescription:                        str.Ptr("lorem ipsum"),
   997  			APIProtocol:                             str.Ptr("odata-v2"),
   998  			Tags:                                    json.RawMessage(`["testTag","apiTestTag"]`),
   999  			Countries:                               json.RawMessage(`["BG","EN","US"]`),
  1000  			Links:                                   json.RawMessage(fmt.Sprintf(linksFormat, baseURL)),
  1001  			APIResourceLinks:                        json.RawMessage(fmt.Sprintf(apiResourceLinksFormat, baseURL)),
  1002  			ReleaseStatus:                           str.Ptr("active"),
  1003  			ChangeLogEntries:                        json.RawMessage(changeLogEntries),
  1004  			Labels:                                  json.RawMessage(mergedLabels),
  1005  			Visibility:                              str.Ptr("public"),
  1006  			Disabled:                                &boolPtr,
  1007  			PartOfProducts:                          json.RawMessage(fmt.Sprintf(`["%s"]`, productORDID)),
  1008  			LineOfBusiness:                          json.RawMessage(`["Finance","Sales"]`),
  1009  			Industry:                                json.RawMessage(`["Automotive","Banking","Chemicals"]`),
  1010  			ImplementationStandard:                  str.Ptr(apiImplementationStandard),
  1011  			CustomImplementationStandard:            nil,
  1012  			CustomImplementationStandardDescription: nil,
  1013  			Version: &model.Version{
  1014  				Value: "2.1.3",
  1015  			},
  1016  			DocumentationLabels: json.RawMessage(documentLabels),
  1017  			BaseEntity: &model.BaseEntity{
  1018  				ID:    api1ID,
  1019  				Ready: true,
  1020  			},
  1021  		},
  1022  		{
  1023  			ApplicationID:                           &appID,
  1024  			PackageID:                               str.Ptr(packageORDID),
  1025  			Name:                                    "Gateway Sample Service",
  1026  			Description:                             str.Ptr("lorem ipsum dolor sit amet"),
  1027  			TargetURLs:                              json.RawMessage(`["/some-api/v1"]`),
  1028  			OrdID:                                   str.Ptr(api2ORDID),
  1029  			ShortDescription:                        str.Ptr("lorem ipsum"),
  1030  			APIProtocol:                             str.Ptr("odata-v2"),
  1031  			Tags:                                    json.RawMessage(`["testTag","ZGWSAMPLE"]`),
  1032  			Countries:                               json.RawMessage(`["BG","EN","BR"]`),
  1033  			Links:                                   json.RawMessage(fmt.Sprintf(linksFormat, baseURL)),
  1034  			APIResourceLinks:                        json.RawMessage(fmt.Sprintf(apiResourceLinksFormat, baseURL)),
  1035  			ReleaseStatus:                           str.Ptr("deprecated"),
  1036  			SunsetDate:                              str.Ptr("2020-12-08T15:47:04+0000"),
  1037  			Successors:                              json.RawMessage(fmt.Sprintf(`["%s"]`, api1ORDID)),
  1038  			ChangeLogEntries:                        json.RawMessage(changeLogEntries),
  1039  			Labels:                                  json.RawMessage(mergedLabels),
  1040  			Visibility:                              str.Ptr("public"),
  1041  			PartOfProducts:                          json.RawMessage(fmt.Sprintf(`["%s"]`, productORDID)),
  1042  			LineOfBusiness:                          json.RawMessage(`["Finance","Sales"]`),
  1043  			Industry:                                json.RawMessage(`["Automotive","Banking","Chemicals"]`),
  1044  			ImplementationStandard:                  str.Ptr(apiImplementationStandard),
  1045  			CustomImplementationStandard:            nil,
  1046  			CustomImplementationStandardDescription: nil,
  1047  			Version: &model.Version{
  1048  				Value: "1.1.1",
  1049  			},
  1050  			DocumentationLabels: json.RawMessage(documentLabels),
  1051  			BaseEntity: &model.BaseEntity{
  1052  				ID:    api2ID,
  1053  				Ready: true,
  1054  			},
  1055  		},
  1056  	}
  1057  }
  1058  
  1059  func fixAPIsNoVersionBump() []*model.APIDefinition {
  1060  	apis := fixAPIs()
  1061  	doc := fixORDDocument()
  1062  	for i, api := range apis {
  1063  		api.Version.Value = doc.APIResources[i].VersionInput.Value
  1064  	}
  1065  	return apis
  1066  }
  1067  
  1068  func fixAPIPartOfConsumptionBundles() []*model.ConsumptionBundleReference {
  1069  	return []*model.ConsumptionBundleReference{
  1070  		{
  1071  			BundleOrdID:      bundleORDID,
  1072  			DefaultTargetURL: "https://exmaple.com/test/v1",
  1073  		},
  1074  		{
  1075  			BundleOrdID:      secondBundleORDID,
  1076  			DefaultTargetURL: "https://exmaple.com/test/v2",
  1077  		},
  1078  	}
  1079  }
  1080  
  1081  func fixEventPartOfConsumptionBundles() []*model.ConsumptionBundleReference {
  1082  	return []*model.ConsumptionBundleReference{
  1083  		{
  1084  			BundleOrdID: bundleORDID,
  1085  		},
  1086  		{
  1087  			BundleOrdID: secondBundleORDID,
  1088  		},
  1089  	}
  1090  }
  1091  
  1092  func fixEvents() []*model.EventDefinition {
  1093  	return []*model.EventDefinition{
  1094  		{
  1095  			ApplicationID:       &appID,
  1096  			PackageID:           str.Ptr(packageORDID),
  1097  			Name:                "EVENT TITLE",
  1098  			Description:         str.Ptr("lorem ipsum dolor sit amet"),
  1099  			OrdID:               str.Ptr(event1ORDID),
  1100  			ShortDescription:    str.Ptr("lorem ipsum"),
  1101  			ChangeLogEntries:    json.RawMessage(changeLogEntries),
  1102  			Links:               json.RawMessage(fmt.Sprintf(linksFormat, baseURL)),
  1103  			Tags:                json.RawMessage(`["testTag","eventTestTag"]`),
  1104  			Countries:           json.RawMessage(`["BG","EN","US"]`),
  1105  			ReleaseStatus:       str.Ptr("active"),
  1106  			Labels:              json.RawMessage(mergedLabels),
  1107  			DocumentationLabels: json.RawMessage(documentLabels),
  1108  			Visibility:          str.Ptr("public"),
  1109  			Disabled:            &boolPtr,
  1110  			PartOfProducts:      json.RawMessage(fmt.Sprintf(`["%s"]`, productORDID)),
  1111  			LineOfBusiness:      json.RawMessage(`["Finance","Sales"]`),
  1112  			Industry:            json.RawMessage(`["Automotive","Banking","Chemicals"]`),
  1113  			Version: &model.Version{
  1114  				Value: "2.1.3",
  1115  			},
  1116  			BaseEntity: &model.BaseEntity{
  1117  				ID:    event1ID,
  1118  				Ready: true,
  1119  			},
  1120  		},
  1121  		{
  1122  			ApplicationID:    &appID,
  1123  			PackageID:        str.Ptr(packageORDID),
  1124  			Name:             "EVENT TITLE 2",
  1125  			Description:      str.Ptr("lorem ipsum dolor sit amet"),
  1126  			OrdID:            str.Ptr(event2ORDID),
  1127  			ShortDescription: str.Ptr("lorem ipsum"),
  1128  			ChangeLogEntries: json.RawMessage(changeLogEntries),
  1129  			Links:            json.RawMessage(fmt.Sprintf(linksFormat, baseURL)),
  1130  			Tags:             json.RawMessage(`["testTag","eventTestTag2"]`),
  1131  			Countries:        json.RawMessage(`["BG","EN","BR"]`),
  1132  			ReleaseStatus:    str.Ptr("deprecated"),
  1133  			SunsetDate:       str.Ptr("2020-12-08T15:47:04+0000"),
  1134  			Successors:       json.RawMessage(fmt.Sprintf(`["%s"]`, event2ORDID)),
  1135  			Labels:           json.RawMessage(mergedLabels),
  1136  			Visibility:       str.Ptr("public"),
  1137  			PartOfProducts:   json.RawMessage(fmt.Sprintf(`["%s"]`, productORDID)),
  1138  			LineOfBusiness:   json.RawMessage(`["Finance","Sales"]`),
  1139  			Industry:         json.RawMessage(`["Automotive","Banking","Chemicals"]`),
  1140  			Version: &model.Version{
  1141  				Value: "1.1.1",
  1142  			},
  1143  			DocumentationLabels: json.RawMessage(documentLabels),
  1144  			BaseEntity: &model.BaseEntity{
  1145  				ID:    event2ID,
  1146  				Ready: true,
  1147  			},
  1148  		},
  1149  	}
  1150  }
  1151  
  1152  func fixEventsNoVersionBump() []*model.EventDefinition {
  1153  	events := fixEvents()
  1154  	doc := fixORDDocument()
  1155  	for i, event := range events {
  1156  		event.Version.Value = doc.EventResources[i].VersionInput.Value
  1157  	}
  1158  	return events
  1159  }
  1160  
  1161  func fixAPI1SpecInputs() []*model.SpecInput {
  1162  	openAPIType := model.APISpecTypeOpenAPIV3
  1163  	edmxAPIType := model.APISpecTypeEDMX
  1164  	return []*model.SpecInput{
  1165  		{
  1166  			Format:     "application/json",
  1167  			APIType:    &openAPIType,
  1168  			CustomType: str.Ptr(""),
  1169  			FetchRequest: &model.FetchRequestInput{
  1170  				URL:  baseURL + "/external-api/unsecured/spec/flapping",
  1171  				Auth: &model.AuthInput{AccessStrategy: str.Ptr("open")},
  1172  			},
  1173  		},
  1174  		{
  1175  			Format:     "text/yaml",
  1176  			APIType:    &openAPIType,
  1177  			CustomType: str.Ptr(""),
  1178  			FetchRequest: &model.FetchRequestInput{
  1179  				URL:  "https://test.com/odata/1.0/catalog",
  1180  				Auth: &model.AuthInput{AccessStrategy: str.Ptr("open")},
  1181  			},
  1182  		},
  1183  		{
  1184  			Format:     "application/xml",
  1185  			APIType:    &edmxAPIType,
  1186  			CustomType: str.Ptr(""),
  1187  			FetchRequest: &model.FetchRequestInput{
  1188  				URL:  "https://TEST:443//odata/$metadata",
  1189  				Auth: &model.AuthInput{AccessStrategy: str.Ptr("open")},
  1190  			},
  1191  		},
  1192  	}
  1193  }
  1194  
  1195  func fixAPI1IDs() []string {
  1196  	return []string{api1spec1ID, api1spec2ID, api1spec3ID}
  1197  }
  1198  
  1199  func fixAPI2SpecInputs() []*model.SpecInput {
  1200  	edmxAPIType := model.APISpecTypeEDMX
  1201  	openAPIType := model.APISpecTypeOpenAPIV3
  1202  	return []*model.SpecInput{
  1203  		{
  1204  			Format:     "application/xml",
  1205  			APIType:    &edmxAPIType,
  1206  			CustomType: str.Ptr(""),
  1207  			FetchRequest: &model.FetchRequestInput{
  1208  				URL:  "https://TEST:443//odata/$metadata",
  1209  				Auth: &model.AuthInput{AccessStrategy: str.Ptr("open")},
  1210  			},
  1211  		},
  1212  		{
  1213  			Format:     "application/json",
  1214  			APIType:    &openAPIType,
  1215  			CustomType: str.Ptr(""),
  1216  			FetchRequest: &model.FetchRequestInput{
  1217  				URL:  baseURL + "/odata/1.0/catalog.svc/$value?type=json",
  1218  				Auth: &model.AuthInput{AccessStrategy: str.Ptr("open")},
  1219  			},
  1220  		},
  1221  	}
  1222  }
  1223  
  1224  func fixAPI2IDs() []string {
  1225  	return []string{api2spec1ID, api2spec2ID}
  1226  }
  1227  
  1228  func fixEvent1SpecInputs() []*model.SpecInput {
  1229  	eventType := model.EventSpecTypeAsyncAPIV2
  1230  	return []*model.SpecInput{
  1231  		{
  1232  			Format:     "application/json",
  1233  			EventType:  &eventType,
  1234  			CustomType: str.Ptr(""),
  1235  			FetchRequest: &model.FetchRequestInput{
  1236  				URL:  "http://localhost:8080/asyncApi2.json",
  1237  				Auth: &model.AuthInput{AccessStrategy: str.Ptr("open")},
  1238  			},
  1239  		},
  1240  	}
  1241  }
  1242  
  1243  func fixEvent1IDs() []string {
  1244  	return []string{event1specID}
  1245  }
  1246  
  1247  func fixEvent2SpecInputs() []*model.SpecInput {
  1248  	eventType := model.EventSpecTypeAsyncAPIV2
  1249  	return []*model.SpecInput{
  1250  		{
  1251  			Format:     "application/json",
  1252  			EventType:  &eventType,
  1253  			CustomType: str.Ptr(""),
  1254  			FetchRequest: &model.FetchRequestInput{
  1255  				URL:  baseURL + "/api/eventCatalog.json",
  1256  				Auth: &model.AuthInput{AccessStrategy: str.Ptr("open")},
  1257  			},
  1258  		},
  1259  	}
  1260  }
  1261  
  1262  func fixEvent2IDs() []string {
  1263  	return []string{event2specID}
  1264  }
  1265  
  1266  func fixTombstones() []*model.Tombstone {
  1267  	return []*model.Tombstone{
  1268  		{
  1269  			ID:            tombstoneID,
  1270  			OrdID:         api2ORDID,
  1271  			ApplicationID: &appID,
  1272  			RemovalDate:   "2020-12-02T14:12:59Z",
  1273  		},
  1274  	}
  1275  }
  1276  
  1277  func fixSuccessfulFetchRequest() *model.FetchRequest {
  1278  	return &model.FetchRequest{
  1279  		Status: &model.FetchRequestStatus{
  1280  			Condition: model.FetchRequestStatusConditionSucceeded,
  1281  		},
  1282  	}
  1283  }
  1284  
  1285  func fixFailedFetchRequest() *model.FetchRequest {
  1286  	return &model.FetchRequest{
  1287  		Status: &model.FetchRequestStatus{
  1288  			Condition: model.FetchRequestStatusConditionFailed,
  1289  		},
  1290  	}
  1291  }
  1292  
  1293  func fixFetchRequestFromFetchRequestInput(fr *model.FetchRequestInput, objectType model.FetchRequestReferenceObjectType, specID string) *model.FetchRequest {
  1294  	id := uidSvc.Generate()
  1295  	return fr.ToFetchRequest(time.Now(), id, objectType, specID)
  1296  }
  1297  
  1298  func bundleUpdateInputFromCreateInput(in model.BundleCreateInput) model.BundleUpdateInput {
  1299  	return model.BundleUpdateInput{
  1300  		Name:                           in.Name,
  1301  		Description:                    in.Description,
  1302  		InstanceAuthRequestInputSchema: in.InstanceAuthRequestInputSchema,
  1303  		DefaultInstanceAuth:            in.DefaultInstanceAuth,
  1304  		OrdID:                          in.OrdID,
  1305  		ShortDescription:               in.ShortDescription,
  1306  		Links:                          in.Links,
  1307  		Labels:                         in.Labels,
  1308  		DocumentationLabels:            in.DocumentationLabels,
  1309  		CredentialExchangeStrategies:   in.CredentialExchangeStrategies,
  1310  		CorrelationIDs:                 in.CorrelationIDs,
  1311  	}
  1312  }
  1313  
  1314  func fixGlobalRegistryORDDocument() *ord.Document {
  1315  	return &ord.Document{
  1316  		Schema:                "./spec/v1/generated/Document.schema.json",
  1317  		OpenResourceDiscovery: "1.0",
  1318  		Products: []*model.ProductInput{
  1319  			{
  1320  				OrdID:            globalProductORDID,
  1321  				Title:            "SAP Business Technology Platform",
  1322  				ShortDescription: "Accelerate business outcomes with integration, data to value, and extensibility.",
  1323  				Vendor:           vendorORDID,
  1324  			},
  1325  		},
  1326  		Vendors: []*model.VendorInput{
  1327  			{
  1328  				OrdID: vendorORDID,
  1329  				Title: "SAP SE",
  1330  			},
  1331  		},
  1332  	}
  1333  }
  1334  
  1335  func removeWhitespace(s string) string {
  1336  	return strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(s, " ", ""), "\n", ""), "\t", "")
  1337  }