diff --git a/README.md b/README.md index 4c5e4225..afbd49d5 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ Service Name | Package name [Case Management](https://cloud.ibm.com/apidocs/case-management) | casemanagementv1 [Catalog Management](https://cloud.ibm.com/apidocs/resource-catalog/private-catalog) | catalogmanagementv1 [Configuration Governance](https://cloud.ibm.com/apidocs/security-compliance/config) | configurationgovernancev1 +[Enterprise Billing Units](https://cloud.ibm.com/apidocs/enterprise-apis/billing-unit) | enterprisebillingunitsv1 [Enterprise Management](https://cloud.ibm.com/apidocs/enterprise-apis/enterprise) | enterprisemanagementv1 [Enterprise Usage Reports](https://cloud.ibm.com/apidocs/enterprise-apis/resource-usage-reports) | enterpriseusagereportsv1 [Global Catalog](https://cloud.ibm.com/apidocs/resource-catalog/global-catalog) | globalcatalogv1 diff --git a/enterprisebillingunitsv1/enterprise_billing_units_v1.go b/enterprisebillingunitsv1/enterprise_billing_units_v1.go new file mode 100644 index 00000000..1f999f99 --- /dev/null +++ b/enterprisebillingunitsv1/enterprise_billing_units_v1.go @@ -0,0 +1,986 @@ +/** + * (C) Copyright IBM Corp. 2020. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-ef9b3113-20201118-074613 + */ + + +// Package enterprisebillingunitsv1 : Operations and models for the EnterpriseBillingUnitsV1 service +package enterprisebillingunitsv1 + +import ( + "context" + "encoding/json" + "fmt" + "github.com/IBM/go-sdk-core/v4/core" + common "github.com/IBM/platform-services-go-sdk/common" + "github.com/go-openapi/strfmt" + "net/http" + "reflect" + "time" +) + +// EnterpriseBillingUnitsV1 : Billing units for IBM Cloud enterprises +// +// Version: 1.0.0 +type EnterpriseBillingUnitsV1 struct { + Service *core.BaseService +} + +// DefaultServiceURL is the default URL to make service requests to. +const DefaultServiceURL = "https://billing.cloud.ibm.com" + +// DefaultServiceName is the default key used to find external configuration information. +const DefaultServiceName = "enterprise_billing_units" + +// EnterpriseBillingUnitsV1Options : Service options +type EnterpriseBillingUnitsV1Options struct { + ServiceName string + URL string + Authenticator core.Authenticator +} + +// NewEnterpriseBillingUnitsV1UsingExternalConfig : constructs an instance of EnterpriseBillingUnitsV1 with passed in options and external configuration. +func NewEnterpriseBillingUnitsV1UsingExternalConfig(options *EnterpriseBillingUnitsV1Options) (enterpriseBillingUnits *EnterpriseBillingUnitsV1, err error) { + if options.ServiceName == "" { + options.ServiceName = DefaultServiceName + } + + if options.Authenticator == nil { + options.Authenticator, err = core.GetAuthenticatorFromEnvironment(options.ServiceName) + if err != nil { + return + } + } + + enterpriseBillingUnits, err = NewEnterpriseBillingUnitsV1(options) + if err != nil { + return + } + + err = enterpriseBillingUnits.Service.ConfigureService(options.ServiceName) + if err != nil { + return + } + + if options.URL != "" { + err = enterpriseBillingUnits.Service.SetServiceURL(options.URL) + } + return +} + +// NewEnterpriseBillingUnitsV1 : constructs an instance of EnterpriseBillingUnitsV1 with passed in options. +func NewEnterpriseBillingUnitsV1(options *EnterpriseBillingUnitsV1Options) (service *EnterpriseBillingUnitsV1, err error) { + serviceOptions := &core.ServiceOptions{ + URL: DefaultServiceURL, + Authenticator: options.Authenticator, + } + + baseService, err := core.NewBaseService(serviceOptions) + if err != nil { + return + } + + if options.URL != "" { + err = baseService.SetServiceURL(options.URL) + if err != nil { + return + } + } + + service = &EnterpriseBillingUnitsV1{ + Service: baseService, + } + + return +} + +// SetServiceURL sets the service URL +func (enterpriseBillingUnits *EnterpriseBillingUnitsV1) SetServiceURL(url string) error { + return enterpriseBillingUnits.Service.SetServiceURL(url) +} + +// GetServiceURL returns the service URL +func (enterpriseBillingUnits *EnterpriseBillingUnitsV1) GetServiceURL() string { + return enterpriseBillingUnits.Service.GetServiceURL() +} + +// SetDefaultHeaders sets HTTP headers to be sent in every request +func (enterpriseBillingUnits *EnterpriseBillingUnitsV1) SetDefaultHeaders(headers http.Header) { + enterpriseBillingUnits.Service.SetDefaultHeaders(headers) +} + +// SetEnableGzipCompression sets the service's EnableGzipCompression field +func (enterpriseBillingUnits *EnterpriseBillingUnitsV1) SetEnableGzipCompression(enableGzip bool) { + enterpriseBillingUnits.Service.SetEnableGzipCompression(enableGzip) +} + +// GetEnableGzipCompression returns the service's EnableGzipCompression field +func (enterpriseBillingUnits *EnterpriseBillingUnitsV1) GetEnableGzipCompression() bool { + return enterpriseBillingUnits.Service.GetEnableGzipCompression() +} + +// EnableRetries enables automatic retries for requests invoked for this service instance. +// If either parameter is specified as 0, then a default value is used instead. +func (enterpriseBillingUnits *EnterpriseBillingUnitsV1) EnableRetries(maxRetries int, maxRetryInterval time.Duration) { + enterpriseBillingUnits.Service.EnableRetries(maxRetries, maxRetryInterval) +} + +// DisableRetries disables automatic retries for requests invoked for this service instance. +func (enterpriseBillingUnits *EnterpriseBillingUnitsV1) DisableRetries() { + enterpriseBillingUnits.Service.DisableRetries() +} + +// GetBillingUnit : Get billing unit by ID +// Return the billing unit information if it exists. +func (enterpriseBillingUnits *EnterpriseBillingUnitsV1) GetBillingUnit(getBillingUnitOptions *GetBillingUnitOptions) (result *BillingUnit, response *core.DetailedResponse, err error) { + return enterpriseBillingUnits.GetBillingUnitWithContext(context.Background(), getBillingUnitOptions) +} + +// GetBillingUnitWithContext is an alternate form of the GetBillingUnit method which supports a Context parameter +func (enterpriseBillingUnits *EnterpriseBillingUnitsV1) GetBillingUnitWithContext(ctx context.Context, getBillingUnitOptions *GetBillingUnitOptions) (result *BillingUnit, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(getBillingUnitOptions, "getBillingUnitOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(getBillingUnitOptions, "getBillingUnitOptions") + if err != nil { + return + } + + pathParamsMap := map[string]string{ + "billing_unit_id": *getBillingUnitOptions.BillingUnitID, + } + + builder := core.NewRequestBuilder(core.GET) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = enterpriseBillingUnits.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(enterpriseBillingUnits.Service.Options.URL, `/v1/billing-units/{billing_unit_id}`, pathParamsMap) + if err != nil { + return + } + + for headerName, headerValue := range getBillingUnitOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("enterprise_billing_units", "V1", "GetBillingUnit") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = enterpriseBillingUnits.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalBillingUnit) + if err != nil { + return + } + response.Result = result + + return +} + +// ListBillingUnits : List billing units +// Return matching billing unit information if any exists. Omits internal properties and enterprise account ID from the +// billing unit. +func (enterpriseBillingUnits *EnterpriseBillingUnitsV1) ListBillingUnits(listBillingUnitsOptions *ListBillingUnitsOptions) (result *BillingUnitsList, response *core.DetailedResponse, err error) { + return enterpriseBillingUnits.ListBillingUnitsWithContext(context.Background(), listBillingUnitsOptions) +} + +// ListBillingUnitsWithContext is an alternate form of the ListBillingUnits method which supports a Context parameter +func (enterpriseBillingUnits *EnterpriseBillingUnitsV1) ListBillingUnitsWithContext(ctx context.Context, listBillingUnitsOptions *ListBillingUnitsOptions) (result *BillingUnitsList, response *core.DetailedResponse, err error) { + err = core.ValidateStruct(listBillingUnitsOptions, "listBillingUnitsOptions") + if err != nil { + return + } + + builder := core.NewRequestBuilder(core.GET) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = enterpriseBillingUnits.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(enterpriseBillingUnits.Service.Options.URL, `/v1/billing-units`, nil) + if err != nil { + return + } + + for headerName, headerValue := range listBillingUnitsOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("enterprise_billing_units", "V1", "ListBillingUnits") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + + if listBillingUnitsOptions.AccountID != nil { + builder.AddQuery("account_id", fmt.Sprint(*listBillingUnitsOptions.AccountID)) + } + if listBillingUnitsOptions.EnterpriseID != nil { + builder.AddQuery("enterprise_id", fmt.Sprint(*listBillingUnitsOptions.EnterpriseID)) + } + if listBillingUnitsOptions.AccountGroupID != nil { + builder.AddQuery("account_group_id", fmt.Sprint(*listBillingUnitsOptions.AccountGroupID)) + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = enterpriseBillingUnits.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalBillingUnitsList) + if err != nil { + return + } + response.Result = result + + return +} + +// ListBillingOptions : List billing options +// Return matching billing options if any exist. Show subscriptions and promotional offers that are available to a +// billing unit. +func (enterpriseBillingUnits *EnterpriseBillingUnitsV1) ListBillingOptions(listBillingOptionsOptions *ListBillingOptionsOptions) (result *BillingOptionsList, response *core.DetailedResponse, err error) { + return enterpriseBillingUnits.ListBillingOptionsWithContext(context.Background(), listBillingOptionsOptions) +} + +// ListBillingOptionsWithContext is an alternate form of the ListBillingOptions method which supports a Context parameter +func (enterpriseBillingUnits *EnterpriseBillingUnitsV1) ListBillingOptionsWithContext(ctx context.Context, listBillingOptionsOptions *ListBillingOptionsOptions) (result *BillingOptionsList, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(listBillingOptionsOptions, "listBillingOptionsOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(listBillingOptionsOptions, "listBillingOptionsOptions") + if err != nil { + return + } + + builder := core.NewRequestBuilder(core.GET) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = enterpriseBillingUnits.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(enterpriseBillingUnits.Service.Options.URL, `/v1/billing-options`, nil) + if err != nil { + return + } + + for headerName, headerValue := range listBillingOptionsOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("enterprise_billing_units", "V1", "ListBillingOptions") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + + builder.AddQuery("billing_unit_id", fmt.Sprint(*listBillingOptionsOptions.BillingUnitID)) + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = enterpriseBillingUnits.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalBillingOptionsList) + if err != nil { + return + } + response.Result = result + + return +} + +// GetCreditPools : Get credit pools +// Get credit pools for a billing unit. Credit pools can be either platform or support credit pools. The platform credit +// pool contains credit from platform subscriptions and promotional offers. The support credit pool contains credit from +// support subscriptions. +func (enterpriseBillingUnits *EnterpriseBillingUnitsV1) GetCreditPools(getCreditPoolsOptions *GetCreditPoolsOptions) (result *CreditPoolsList, response *core.DetailedResponse, err error) { + return enterpriseBillingUnits.GetCreditPoolsWithContext(context.Background(), getCreditPoolsOptions) +} + +// GetCreditPoolsWithContext is an alternate form of the GetCreditPools method which supports a Context parameter +func (enterpriseBillingUnits *EnterpriseBillingUnitsV1) GetCreditPoolsWithContext(ctx context.Context, getCreditPoolsOptions *GetCreditPoolsOptions) (result *CreditPoolsList, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(getCreditPoolsOptions, "getCreditPoolsOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(getCreditPoolsOptions, "getCreditPoolsOptions") + if err != nil { + return + } + + builder := core.NewRequestBuilder(core.GET) + builder = builder.WithContext(ctx) + builder.EnableGzipCompression = enterpriseBillingUnits.GetEnableGzipCompression() + _, err = builder.ResolveRequestURL(enterpriseBillingUnits.Service.Options.URL, `/v1/credit-pools`, nil) + if err != nil { + return + } + + for headerName, headerValue := range getCreditPoolsOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("enterprise_billing_units", "V1", "GetCreditPools") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + + builder.AddQuery("billing_unit_id", fmt.Sprint(*getCreditPoolsOptions.BillingUnitID)) + if getCreditPoolsOptions.Date != nil { + builder.AddQuery("date", fmt.Sprint(*getCreditPoolsOptions.Date)) + } + if getCreditPoolsOptions.Type != nil { + builder.AddQuery("type", fmt.Sprint(*getCreditPoolsOptions.Type)) + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = enterpriseBillingUnits.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalCreditPoolsList) + if err != nil { + return + } + response.Result = result + + return +} + +// BillingOption : Information about a billing option. +type BillingOption struct { + // The ID of the billing option. + ID *string `json:"id,omitempty"` + + // The ID of the billing unit that's associated with the billing option. + BillingUnitID *string `json:"billing_unit_id,omitempty"` + + // The start date of billing option. + StartDate *strfmt.DateTime `json:"start_date,omitempty"` + + // The end date of billing option. + EndDate *strfmt.DateTime `json:"end_date,omitempty"` + + // The state of the billing option. The valid values include `ACTIVE, `SUSPENDED`, and `CANCELED`. + State *string `json:"state,omitempty"` + + // The type of billing option. The valid values are `SUBSCRIPTION` and `OFFER`. + Type *string `json:"type,omitempty"` + + // The category of the billing option. The valid values are `PLATFORM`, `SERVICE`, and `SUPPORT`. + Category *string `json:"category,omitempty"` + + // The payment method for support. + PaymentInstrument map[string]interface{} `json:"payment_instrument,omitempty"` + + // The duration of the billing options in months. + DurationInMonths *int64 `json:"duration_in_months,omitempty"` + + // The line item ID for support. + LineItemID *int64 `json:"line_item_id,omitempty"` + + // The support billing system. + BillingSystem map[string]interface{} `json:"billing_system,omitempty"` + + // The renewal code for support. This code denotes whether the subscription automatically renews, is assessed monthly, + // and so on. + RenewalModeCode *string `json:"renewal_mode_code,omitempty"` + + // The date when the billing option was updated. + UpdatedAt *strfmt.DateTime `json:"updated_at,omitempty"` +} + +// Constants associated with the BillingOption.State property. +// The state of the billing option. The valid values include `ACTIVE, `SUSPENDED`, and `CANCELED`. +const ( + BillingOption_State_Active = "ACTIVE" + BillingOption_State_Canceled = "CANCELED" + BillingOption_State_Suspended = "SUSPENDED" +) + +// Constants associated with the BillingOption.Type property. +// The type of billing option. The valid values are `SUBSCRIPTION` and `OFFER`. +const ( + BillingOption_Type_Offer = "OFFER" + BillingOption_Type_Subscription = "SUBSCRIPTION" +) + +// Constants associated with the BillingOption.Category property. +// The category of the billing option. The valid values are `PLATFORM`, `SERVICE`, and `SUPPORT`. +const ( + BillingOption_Category_Platform = "PLATFORM" + BillingOption_Category_Service = "SERVICE" + BillingOption_Category_Support = "SUPPORT" +) + + +// UnmarshalBillingOption unmarshals an instance of BillingOption from the specified map of raw messages. +func UnmarshalBillingOption(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(BillingOption) + err = core.UnmarshalPrimitive(m, "id", &obj.ID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "billing_unit_id", &obj.BillingUnitID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "start_date", &obj.StartDate) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "end_date", &obj.EndDate) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "state", &obj.State) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "type", &obj.Type) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "category", &obj.Category) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "payment_instrument", &obj.PaymentInstrument) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "duration_in_months", &obj.DurationInMonths) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "line_item_id", &obj.LineItemID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "billing_system", &obj.BillingSystem) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "renewal_mode_code", &obj.RenewalModeCode) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "updated_at", &obj.UpdatedAt) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// BillingOptionsList : A search result containing zero or more billing options. +type BillingOptionsList struct { + // A count of the billing units that were found by the query. + RowsCount *int64 `json:"rows_count,omitempty"` + + // Bookmark URL to query for next batch of billing units. This returns `null` if no additional pages are required. + NextURL *string `json:"next_url,omitempty"` + + // A list of billing units found. + Resources []BillingOption `json:"resources,omitempty"` +} + + +// UnmarshalBillingOptionsList unmarshals an instance of BillingOptionsList from the specified map of raw messages. +func UnmarshalBillingOptionsList(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(BillingOptionsList) + err = core.UnmarshalPrimitive(m, "rows_count", &obj.RowsCount) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "next_url", &obj.NextURL) + if err != nil { + return + } + err = core.UnmarshalModel(m, "resources", &obj.Resources, UnmarshalBillingOption) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// BillingUnit : Information about a billing unit. +type BillingUnit struct { + // The ID of the billing unit, which is a globally unique identifier (GUID). + ID *string `json:"id,omitempty"` + + // The Cloud Resource Name (CRN) of the billing unit, scoped to the enterprise account ID. + Crn *string `json:"crn,omitempty"` + + // The name of the billing unit. + Name *string `json:"name,omitempty"` + + // The ID of the enterprise to which the billing unit is associated. + EnterpriseID *string `json:"enterprise_id,omitempty"` + + // The currency code for the billing unit. + CurrencyCode *string `json:"currency_code,omitempty"` + + // The country code for the billing unit. + CountryCode *string `json:"country_code,omitempty"` + + // A flag that indicates whether this billing unit is the primary billing mechanism for the enterprise. + Master *bool `json:"master,omitempty"` + + // The creation date of the billing unit. + CreatedAt *strfmt.DateTime `json:"created_at,omitempty"` +} + + +// UnmarshalBillingUnit unmarshals an instance of BillingUnit from the specified map of raw messages. +func UnmarshalBillingUnit(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(BillingUnit) + err = core.UnmarshalPrimitive(m, "id", &obj.ID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "crn", &obj.Crn) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "name", &obj.Name) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "enterprise_id", &obj.EnterpriseID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "currency_code", &obj.CurrencyCode) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "country_code", &obj.CountryCode) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "master", &obj.Master) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "created_at", &obj.CreatedAt) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// BillingUnitsList : A search result contining zero or more billing units. +type BillingUnitsList struct { + // A count of the billing units that were found by the query. + RowsCount *int64 `json:"rows_count,omitempty"` + + // Bookmark URL to query for next batch of billing units. This returns `null` if no additional pages are required. + NextURL *string `json:"next_url,omitempty"` + + // A list of billing units found. + Resources []BillingUnit `json:"resources,omitempty"` +} + + +// UnmarshalBillingUnitsList unmarshals an instance of BillingUnitsList from the specified map of raw messages. +func UnmarshalBillingUnitsList(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(BillingUnitsList) + err = core.UnmarshalPrimitive(m, "rows_count", &obj.RowsCount) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "next_url", &obj.NextURL) + if err != nil { + return + } + err = core.UnmarshalModel(m, "resources", &obj.Resources, UnmarshalBillingUnit) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// CreditPool : The credit pool for a billing unit. +type CreditPool struct { + // The type of credit, either `PLATFORM` or `SUPPORT`. + Type *string `json:"type,omitempty"` + + // The currency code of the associated billing unit. + CurrencyCode *string `json:"currency_code,omitempty"` + + // The ID of the billing unit that's associated with the credit pool. This value is a globally unique identifier + // (GUID). + BillingUnitID *string `json:"billing_unit_id,omitempty"` + + // A list of active subscription terms available within a credit pool. + TermCredits []TermCredits `json:"term_credits,omitempty"` + + // Overage that was generated on the credit pool. + Overage *CreditPoolOverage `json:"overage,omitempty"` +} + +// Constants associated with the CreditPool.Type property. +// The type of credit, either `PLATFORM` or `SUPPORT`. +const ( + CreditPool_Type_Platform = "PLATFORM" + CreditPool_Type_Support = "SUPPORT" +) + + +// UnmarshalCreditPool unmarshals an instance of CreditPool from the specified map of raw messages. +func UnmarshalCreditPool(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(CreditPool) + err = core.UnmarshalPrimitive(m, "type", &obj.Type) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "currency_code", &obj.CurrencyCode) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "billing_unit_id", &obj.BillingUnitID) + if err != nil { + return + } + err = core.UnmarshalModel(m, "term_credits", &obj.TermCredits, UnmarshalTermCredits) + if err != nil { + return + } + err = core.UnmarshalModel(m, "overage", &obj.Overage, UnmarshalCreditPoolOverage) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// CreditPoolOverage : Overage that was generated on the credit pool. +type CreditPoolOverage struct { + // The number of credits used as overage. + Cost *float64 `json:"cost,omitempty"` + + // A list of resources that generated overage. + Resources []map[string]interface{} `json:"resources,omitempty"` +} + + +// UnmarshalCreditPoolOverage unmarshals an instance of CreditPoolOverage from the specified map of raw messages. +func UnmarshalCreditPoolOverage(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(CreditPoolOverage) + err = core.UnmarshalPrimitive(m, "cost", &obj.Cost) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "resources", &obj.Resources) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// CreditPoolsList : A search result containing zero or more credit pools. +type CreditPoolsList struct { + // The number of credit pools that were found by the query. + RowsCount *int64 `json:"rows_count,omitempty"` + + // A bookmark URL to the query for the next batch of billing units. Use a value of `null` if no additional pages are + // required. + NextURL *string `json:"next_url,omitempty"` + + // A list of credit pools found by the query. + Resources []CreditPool `json:"resources,omitempty"` +} + + +// UnmarshalCreditPoolsList unmarshals an instance of CreditPoolsList from the specified map of raw messages. +func UnmarshalCreditPoolsList(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(CreditPoolsList) + err = core.UnmarshalPrimitive(m, "rows_count", &obj.RowsCount) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "next_url", &obj.NextURL) + if err != nil { + return + } + err = core.UnmarshalModel(m, "resources", &obj.Resources, UnmarshalCreditPool) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// GetBillingUnitOptions : The GetBillingUnit options. +type GetBillingUnitOptions struct { + // The ID of the requested billing unit. + BillingUnitID *string `json:"billing_unit_id" validate:"required,ne="` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewGetBillingUnitOptions : Instantiate GetBillingUnitOptions +func (*EnterpriseBillingUnitsV1) NewGetBillingUnitOptions(billingUnitID string) *GetBillingUnitOptions { + return &GetBillingUnitOptions{ + BillingUnitID: core.StringPtr(billingUnitID), + } +} + +// SetBillingUnitID : Allow user to set BillingUnitID +func (options *GetBillingUnitOptions) SetBillingUnitID(billingUnitID string) *GetBillingUnitOptions { + options.BillingUnitID = core.StringPtr(billingUnitID) + return options +} + +// SetHeaders : Allow user to set Headers +func (options *GetBillingUnitOptions) SetHeaders(param map[string]string) *GetBillingUnitOptions { + options.Headers = param + return options +} + +// GetCreditPoolsOptions : The GetCreditPools options. +type GetCreditPoolsOptions struct { + // The ID of the billing unit. + BillingUnitID *string `json:"billing_unit_id" validate:"required"` + + // The date in the format of YYYY-MM. + Date *string `json:"date,omitempty"` + + // Filters the credit pool by type, either `PLATFORM` or `SUPPORT`. + Type *string `json:"type,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewGetCreditPoolsOptions : Instantiate GetCreditPoolsOptions +func (*EnterpriseBillingUnitsV1) NewGetCreditPoolsOptions(billingUnitID string) *GetCreditPoolsOptions { + return &GetCreditPoolsOptions{ + BillingUnitID: core.StringPtr(billingUnitID), + } +} + +// SetBillingUnitID : Allow user to set BillingUnitID +func (options *GetCreditPoolsOptions) SetBillingUnitID(billingUnitID string) *GetCreditPoolsOptions { + options.BillingUnitID = core.StringPtr(billingUnitID) + return options +} + +// SetDate : Allow user to set Date +func (options *GetCreditPoolsOptions) SetDate(date string) *GetCreditPoolsOptions { + options.Date = core.StringPtr(date) + return options +} + +// SetType : Allow user to set Type +func (options *GetCreditPoolsOptions) SetType(typeVar string) *GetCreditPoolsOptions { + options.Type = core.StringPtr(typeVar) + return options +} + +// SetHeaders : Allow user to set Headers +func (options *GetCreditPoolsOptions) SetHeaders(param map[string]string) *GetCreditPoolsOptions { + options.Headers = param + return options +} + +// ListBillingOptionsOptions : The ListBillingOptions options. +type ListBillingOptionsOptions struct { + // The billing unit ID. + BillingUnitID *string `json:"billing_unit_id" validate:"required"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewListBillingOptionsOptions : Instantiate ListBillingOptionsOptions +func (*EnterpriseBillingUnitsV1) NewListBillingOptionsOptions(billingUnitID string) *ListBillingOptionsOptions { + return &ListBillingOptionsOptions{ + BillingUnitID: core.StringPtr(billingUnitID), + } +} + +// SetBillingUnitID : Allow user to set BillingUnitID +func (options *ListBillingOptionsOptions) SetBillingUnitID(billingUnitID string) *ListBillingOptionsOptions { + options.BillingUnitID = core.StringPtr(billingUnitID) + return options +} + +// SetHeaders : Allow user to set Headers +func (options *ListBillingOptionsOptions) SetHeaders(param map[string]string) *ListBillingOptionsOptions { + options.Headers = param + return options +} + +// ListBillingUnitsOptions : The ListBillingUnits options. +type ListBillingUnitsOptions struct { + // The enterprise account ID. + AccountID *string `json:"account_id,omitempty"` + + // The enterprise ID. + EnterpriseID *string `json:"enterprise_id,omitempty"` + + // The account group ID. + AccountGroupID *string `json:"account_group_id,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewListBillingUnitsOptions : Instantiate ListBillingUnitsOptions +func (*EnterpriseBillingUnitsV1) NewListBillingUnitsOptions() *ListBillingUnitsOptions { + return &ListBillingUnitsOptions{} +} + +// SetAccountID : Allow user to set AccountID +func (options *ListBillingUnitsOptions) SetAccountID(accountID string) *ListBillingUnitsOptions { + options.AccountID = core.StringPtr(accountID) + return options +} + +// SetEnterpriseID : Allow user to set EnterpriseID +func (options *ListBillingUnitsOptions) SetEnterpriseID(enterpriseID string) *ListBillingUnitsOptions { + options.EnterpriseID = core.StringPtr(enterpriseID) + return options +} + +// SetAccountGroupID : Allow user to set AccountGroupID +func (options *ListBillingUnitsOptions) SetAccountGroupID(accountGroupID string) *ListBillingUnitsOptions { + options.AccountGroupID = core.StringPtr(accountGroupID) + return options +} + +// SetHeaders : Allow user to set Headers +func (options *ListBillingUnitsOptions) SetHeaders(param map[string]string) *ListBillingUnitsOptions { + options.Headers = param + return options +} + +// TermCredits : The subscription term that is active in the current month. +type TermCredits struct { + // The ID of the billing option from which the subscription term is derived. + BillingOptionID *string `json:"billing_option_id,omitempty"` + + // The category of the credit pool. The valid values are `PLATFORM`, `OFFER`, or `SERVICE` for platform credit and + // `SUPPORT` for support credit. + Category *string `json:"category,omitempty"` + + // The start date of the term in ISO format. + StartDate *strfmt.DateTime `json:"start_date,omitempty"` + + // The end date of the term in ISO format. + EndDate *strfmt.DateTime `json:"end_date,omitempty"` + + // The total credit available in this term. + TotalCredits *float64 `json:"total_credits,omitempty"` + + // The balance of available credit at the start of the current month. + StartingBalance *float64 `json:"starting_balance,omitempty"` + + // The amount of credit used during the current month. + UsedCredits *float64 `json:"used_credits,omitempty"` + + // The balance of remaining credit in the subscription term. + CurrentBalance *float64 `json:"current_balance,omitempty"` + + // A list of resources that used credit during the month. + Resources []map[string]interface{} `json:"resources,omitempty"` +} + +// Constants associated with the TermCredits.Category property. +// The category of the credit pool. The valid values are `PLATFORM`, `OFFER`, or `SERVICE` for platform credit and +// `SUPPORT` for support credit. +const ( + TermCredits_Category_Offer = "OFFER" + TermCredits_Category_Platform = "PLATFORM" + TermCredits_Category_Service = "SERVICE" + TermCredits_Category_Support = "SUPPORT" +) + + +// UnmarshalTermCredits unmarshals an instance of TermCredits from the specified map of raw messages. +func UnmarshalTermCredits(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(TermCredits) + err = core.UnmarshalPrimitive(m, "billing_option_id", &obj.BillingOptionID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "category", &obj.Category) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "start_date", &obj.StartDate) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "end_date", &obj.EndDate) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "total_credits", &obj.TotalCredits) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "starting_balance", &obj.StartingBalance) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "used_credits", &obj.UsedCredits) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "current_balance", &obj.CurrentBalance) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "resources", &obj.Resources) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} diff --git a/enterprisebillingunitsv1/enterprise_billing_units_v1_examples_test.go b/enterprisebillingunitsv1/enterprise_billing_units_v1_examples_test.go new file mode 100644 index 00000000..bf4c37c8 --- /dev/null +++ b/enterprisebillingunitsv1/enterprise_billing_units_v1_examples_test.go @@ -0,0 +1,195 @@ +// +build examples + +/** + * (C) Copyright IBM Corp. 2020. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package enterprisebillingunitsv1_test + +import ( + "encoding/json" + "fmt" + "os" + + "github.com/IBM/go-sdk-core/v4/core" + "github.com/IBM/platform-services-go-sdk/enterprisebillingunitsv1" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +// +// This file provides an example of how to use the Enterprise Billing Units service. +// +// The following configuration properties are assumed to be defined in the external configuration file: +// ENTERPRISE_BILLING_UNITS_URL= +// ENTERPRISE_BILLING_UNITS_AUTHTYPE=iam +// ENTERPRISE_BILLING_UNITS_APIKEY= +// ENTERPRISE_BILLING_UNITS_AUTH_URL= +// ENTERPRISE_BILLING_UNITS_ENTERPRISE_ID= +// ENTERPRISE_BILLING_UNITS_BILLING_UNIT_ID= +// +const externalConfigFile = "../enterprise_billing_units.env" + +var ( + enterpriseBillingUnitsService *enterprisebillingunitsv1.EnterpriseBillingUnitsV1 + config map[string]string + configLoaded bool = false + + enterpriseID string + billingUnitID string +) + +func shouldSkipTest() { + if !configLoaded { + Skip("External configuration is not available, skipping tests...") + } +} + +var _ = Describe(`EnterpriseBillingUnitsV1 Examples Tests`, func() { + Describe(`External configuration`, func() { + It("Successfully load the configuration", func() { + var err error + _, err = os.Stat(externalConfigFile) + if err != nil { + Skip("External configuration file not found, skipping tests: " + err.Error()) + } + + os.Setenv("IBM_CREDENTIALS_FILE", externalConfigFile) + config, err = core.GetServiceProperties(enterprisebillingunitsv1.DefaultServiceName) + if err != nil { + Skip("Error loading service properties, skipping tests: " + err.Error()) + } + + enterpriseID = config["ENTERPRISE_ID"] + Expect(enterpriseID).ToNot(BeEmpty()) + + billingUnitID = config["BILLING_UNIT_ID"] + Expect(billingUnitID).ToNot(BeEmpty()) + + configLoaded = len(config) > 0 + }) + }) + + Describe(`Client initialization`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It("Successfully construct the service client instance", func() { + var err error + + // begin-common + + enterpriseBillingUnitsServiceOptions := &enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{} + + enterpriseBillingUnitsService, err = enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1UsingExternalConfig(enterpriseBillingUnitsServiceOptions) + + if err != nil { + panic(err) + } + + // end-common + + Expect(enterpriseBillingUnitsService).ToNot(BeNil()) + }) + }) + + Describe(`EnterpriseBillingUnitsV1 request examples`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`GetBillingUnit request example`, func() { + // begin-get_billing_unit + + getBillingUnitOptions := enterpriseBillingUnitsService.NewGetBillingUnitOptions( + billingUnitID, + ) + + billingUnit, response, err := enterpriseBillingUnitsService.GetBillingUnit(getBillingUnitOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(billingUnit, "", " ") + fmt.Println(string(b)) + + // end-get_billing_unit + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(billingUnit).ToNot(BeNil()) + + }) + It(`ListBillingUnits request example`, func() { + // begin-list_billing_units + + listBillingUnitsOptions := enterpriseBillingUnitsService.NewListBillingUnitsOptions() + listBillingUnitsOptions.SetEnterpriseID(enterpriseID) + + billingUnitsList, response, err := enterpriseBillingUnitsService.ListBillingUnits(listBillingUnitsOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(billingUnitsList, "", " ") + fmt.Println(string(b)) + + // end-list_billing_units + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(billingUnitsList).ToNot(BeNil()) + + }) + It(`ListBillingOptions request example`, func() { + // begin-list_billing_options + + listBillingOptionsOptions := enterpriseBillingUnitsService.NewListBillingOptionsOptions( + billingUnitID, + ) + + billingOption, response, err := enterpriseBillingUnitsService.ListBillingOptions(listBillingOptionsOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(billingOption, "", " ") + fmt.Println(string(b)) + + // end-list_billing_options + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(billingOption).ToNot(BeNil()) + + }) + It(`GetCreditPools request example`, func() { + // begin-get_credit_pools + + getCreditPoolsOptions := enterpriseBillingUnitsService.NewGetCreditPoolsOptions( + billingUnitID, + ) + + creditPoolsList, response, err := enterpriseBillingUnitsService.GetCreditPools(getCreditPoolsOptions) + if err != nil { + panic(err) + } + b, _ := json.MarshalIndent(creditPoolsList, "", " ") + fmt.Println(string(b)) + + // end-get_credit_pools + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(creditPoolsList).ToNot(BeNil()) + }) + }) +}) diff --git a/enterprisebillingunitsv1/enterprise_billing_units_v1_integration_test.go b/enterprisebillingunitsv1/enterprise_billing_units_v1_integration_test.go new file mode 100644 index 00000000..9f54ac9b --- /dev/null +++ b/enterprisebillingunitsv1/enterprise_billing_units_v1_integration_test.go @@ -0,0 +1,220 @@ +// +build integration + +/** + * (C) Copyright IBM Corp. 2020. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package enterprisebillingunitsv1_test + +import ( + "fmt" + "os" + + "github.com/IBM/go-sdk-core/v4/core" + common "github.com/IBM/platform-services-go-sdk/common" + "github.com/IBM/platform-services-go-sdk/enterprisebillingunitsv1" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +/** + * This file contains an integration test for the enterprisebillingunitsv1 package. + * + * Notes: + * + * The integration test will automatically skip tests if the required config file is not available. + */ + +var _ = Describe(`EnterpriseBillingUnitsV1 Integration Tests`, func() { + + const externalConfigFile = "../enterprise_billing_units.env" + + var ( + err error + enterpriseBillingUnitsService *enterprisebillingunitsv1.EnterpriseBillingUnitsV1 + serviceURL string + config map[string]string + + enterpriseID string + accountID string + accountGroupID string + billingUnitID string + ) + + var shouldSkipTest = func() { + Skip("External configuration is not available, skipping tests...") + } + + Describe(`External configuration`, func() { + It("Successfully load the configuration", func() { + _, err = os.Stat(externalConfigFile) + if err != nil { + Skip("External configuration file not found, skipping tests: " + err.Error()) + } + + os.Setenv("IBM_CREDENTIALS_FILE", externalConfigFile) + config, err = core.GetServiceProperties(enterprisebillingunitsv1.DefaultServiceName) + if err != nil { + Skip("Error loading service properties, skipping tests: " + err.Error()) + } + serviceURL = config["URL"] + if serviceURL == "" { + Skip("Unable to load service URL configuration property, skipping tests") + } + + enterpriseID = config["ENTERPRISE_ID"] + Expect(enterpriseID).ToNot(BeEmpty()) + + accountID = config["ACCOUNT_ID"] + Expect(accountID).ToNot(BeEmpty()) + + accountGroupID = config["ACCOUNT_GROUP_ID"] + Expect(accountGroupID).ToNot(BeEmpty()) + + billingUnitID = config["BILLING_UNIT_ID"] + Expect(billingUnitID).ToNot(BeEmpty()) + + fmt.Fprintf(GinkgoWriter, "Service URL: %s\n", serviceURL) + shouldSkipTest = func() {} + }) + }) + + Describe(`Client initialization`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It("Successfully construct the service client instance", func() { + + enterpriseBillingUnitsServiceOptions := &enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{} + + enterpriseBillingUnitsService, err = enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1UsingExternalConfig(enterpriseBillingUnitsServiceOptions) + + Expect(err).To(BeNil()) + Expect(enterpriseBillingUnitsService).ToNot(BeNil()) + Expect(enterpriseBillingUnitsService.Service.Options.URL).To(Equal(serviceURL)) + }) + }) + + Describe(`GetBillingUnit - Get billing unit by ID`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`GetBillingUnit(getBillingUnitOptions *GetBillingUnitOptions)`, func() { + + getBillingUnitOptions := &enterprisebillingunitsv1.GetBillingUnitOptions{ + BillingUnitID: &billingUnitID, + } + + billingUnit, response, err := enterpriseBillingUnitsService.GetBillingUnit(getBillingUnitOptions) + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(billingUnit).ToNot(BeNil()) + + fmt.Fprintf(GinkgoWriter, "GetBillingUnit response:\n%s\n", common.ToJSON(billingUnit)) + }) + }) + + Describe(`ListBillingUnits - List billing units`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`ListBillingUnits(enterpriseID)`, func() { + + listBillingUnitsOptions := &enterprisebillingunitsv1.ListBillingUnitsOptions{ + EnterpriseID: &enterpriseID, + } + + billingUnitsList, response, err := enterpriseBillingUnitsService.ListBillingUnits(listBillingUnitsOptions) + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(billingUnitsList).ToNot(BeNil()) + + fmt.Fprintf(GinkgoWriter, "ListBillingUnits(enterpriseID) response:\n%s\n", common.ToJSON(billingUnitsList)) + }) + + It(`ListBillingUnits(accountID)`, func() { + + listBillingUnitsOptions := &enterprisebillingunitsv1.ListBillingUnitsOptions{ + AccountID: &accountID, + } + + billingUnitsList, response, err := enterpriseBillingUnitsService.ListBillingUnits(listBillingUnitsOptions) + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(billingUnitsList).ToNot(BeNil()) + + fmt.Fprintf(GinkgoWriter, "ListBillingUnits(accountID) response:\n%s\n", common.ToJSON(billingUnitsList)) + }) + + It(`ListBillingUnits(accountGroupID)`, func() { + + listBillingUnitsOptions := &enterprisebillingunitsv1.ListBillingUnitsOptions{ + AccountGroupID: &accountGroupID, + } + + billingUnitsList, response, err := enterpriseBillingUnitsService.ListBillingUnits(listBillingUnitsOptions) + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(billingUnitsList).ToNot(BeNil()) + + fmt.Fprintf(GinkgoWriter, "ListBillingUnits(accountGroupID) response:\n%s\n", common.ToJSON(billingUnitsList)) + }) + }) + + Describe(`ListBillingOptions - List billing options`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`ListBillingOptions(listBillingOptionsOptions *ListBillingOptionsOptions)`, func() { + + listBillingOptionsOptions := &enterprisebillingunitsv1.ListBillingOptionsOptions{ + BillingUnitID: &billingUnitID, + } + + billingOptionsList, response, err := enterpriseBillingUnitsService.ListBillingOptions(listBillingOptionsOptions) + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(billingOptionsList).ToNot(BeNil()) + + fmt.Fprintf(GinkgoWriter, "ListBillingOptions() response:\n%s\n", common.ToJSON(billingOptionsList)) + }) + }) + + Describe(`GetCreditPools - Get credit pools`, func() { + BeforeEach(func() { + shouldSkipTest() + }) + It(`GetCreditPools(getCreditPoolsOptions *GetCreditPoolsOptions)`, func() { + + getCreditPoolsOptions := &enterprisebillingunitsv1.GetCreditPoolsOptions{ + BillingUnitID: &billingUnitID, + Type: core.StringPtr("PLATFORM"), + } + + creditPoolsList, response, err := enterpriseBillingUnitsService.GetCreditPools(getCreditPoolsOptions) + + Expect(err).To(BeNil()) + Expect(response.StatusCode).To(Equal(200)) + Expect(creditPoolsList).ToNot(BeNil()) + + fmt.Fprintf(GinkgoWriter, "GetCreditPools() response:\n%s\n", common.ToJSON(creditPoolsList)) + }) + }) +}) diff --git a/enterprisebillingunitsv1/enterprise_billing_units_v1_suite_test.go b/enterprisebillingunitsv1/enterprise_billing_units_v1_suite_test.go new file mode 100644 index 00000000..2baa0621 --- /dev/null +++ b/enterprisebillingunitsv1/enterprise_billing_units_v1_suite_test.go @@ -0,0 +1,28 @@ +/** + * (C) Copyright IBM Corp. 2020. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package enterprisebillingunitsv1_test + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "testing" +) + +func TestEnterpriseBillingUnitsV1(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "EnterpriseBillingUnitsV1 Suite") +} diff --git a/enterprisebillingunitsv1/enterprise_billing_units_v1_test.go b/enterprisebillingunitsv1/enterprise_billing_units_v1_test.go new file mode 100644 index 00000000..4f5d69e0 --- /dev/null +++ b/enterprisebillingunitsv1/enterprise_billing_units_v1_test.go @@ -0,0 +1,1097 @@ +/** + * (C) Copyright IBM Corp. 2020. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package enterprisebillingunitsv1_test + +import ( + "bytes" + "context" + "fmt" + "github.com/IBM/go-sdk-core/v4/core" + "github.com/IBM/platform-services-go-sdk/enterprisebillingunitsv1" + "github.com/go-openapi/strfmt" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "io" + "io/ioutil" + "net/http" + "net/http/httptest" + "os" + "time" +) + +var _ = Describe(`EnterpriseBillingUnitsV1`, func() { + var testServer *httptest.Server + Describe(`Service constructor tests`, func() { + It(`Instantiate service client`, func() { + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(enterpriseBillingUnitsService).ToNot(BeNil()) + Expect(serviceErr).To(BeNil()) + }) + It(`Instantiate service client with error: Invalid URL`, func() { + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + URL: "{BAD_URL_STRING", + }) + Expect(enterpriseBillingUnitsService).To(BeNil()) + Expect(serviceErr).ToNot(BeNil()) + }) + It(`Instantiate service client with error: Invalid Auth`, func() { + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + URL: "https://enterprisebillingunitsv1/api", + Authenticator: &core.BasicAuthenticator{ + Username: "", + Password: "", + }, + }) + Expect(enterpriseBillingUnitsService).To(BeNil()) + Expect(serviceErr).ToNot(BeNil()) + }) + }) + Describe(`Service constructor tests using external config`, func() { + Context(`Using external config, construct service client instances`, func() { + // Map containing environment variables used in testing. + var testEnvironment = map[string]string{ + "ENTERPRISE_BILLING_UNITS_URL": "https://enterprisebillingunitsv1/api", + "ENTERPRISE_BILLING_UNITS_AUTH_TYPE": "noauth", + } + + It(`Create service client using external config successfully`, func() { + SetTestEnvironment(testEnvironment) + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1UsingExternalConfig(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + }) + Expect(enterpriseBillingUnitsService).ToNot(BeNil()) + Expect(serviceErr).To(BeNil()) + ClearTestEnvironment(testEnvironment) + }) + It(`Create service client using external config and set url from constructor successfully`, func() { + SetTestEnvironment(testEnvironment) + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1UsingExternalConfig(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + URL: "https://testService/api", + }) + Expect(enterpriseBillingUnitsService).ToNot(BeNil()) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseBillingUnitsService.Service.GetServiceURL()).To(Equal("https://testService/api")) + ClearTestEnvironment(testEnvironment) + }) + It(`Create service client using external config and set url programatically successfully`, func() { + SetTestEnvironment(testEnvironment) + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1UsingExternalConfig(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + }) + err := enterpriseBillingUnitsService.SetServiceURL("https://testService/api") + Expect(err).To(BeNil()) + Expect(enterpriseBillingUnitsService).ToNot(BeNil()) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseBillingUnitsService.Service.GetServiceURL()).To(Equal("https://testService/api")) + ClearTestEnvironment(testEnvironment) + }) + }) + Context(`Using external config, construct service client instances with error: Invalid Auth`, func() { + // Map containing environment variables used in testing. + var testEnvironment = map[string]string{ + "ENTERPRISE_BILLING_UNITS_URL": "https://enterprisebillingunitsv1/api", + "ENTERPRISE_BILLING_UNITS_AUTH_TYPE": "someOtherAuth", + } + + SetTestEnvironment(testEnvironment) + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1UsingExternalConfig(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + }) + + It(`Instantiate service client with error`, func() { + Expect(enterpriseBillingUnitsService).To(BeNil()) + Expect(serviceErr).ToNot(BeNil()) + ClearTestEnvironment(testEnvironment) + }) + }) + Context(`Using external config, construct service client instances with error: Invalid URL`, func() { + // Map containing environment variables used in testing. + var testEnvironment = map[string]string{ + "ENTERPRISE_BILLING_UNITS_AUTH_TYPE": "NOAuth", + } + + SetTestEnvironment(testEnvironment) + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1UsingExternalConfig(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + URL: "{BAD_URL_STRING", + }) + + It(`Instantiate service client with error`, func() { + Expect(enterpriseBillingUnitsService).To(BeNil()) + Expect(serviceErr).ToNot(BeNil()) + ClearTestEnvironment(testEnvironment) + }) + }) + }) + Describe(`GetBillingUnit(getBillingUnitOptions *GetBillingUnitOptions) - Operation response error`, func() { + getBillingUnitPath := "/v1/billing-units/testString" + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getBillingUnitPath)) + Expect(req.Method).To(Equal("GET")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `} this is not valid json {`) + })) + }) + It(`Invoke GetBillingUnit with error: Operation response processing error`, func() { + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseBillingUnitsService).ToNot(BeNil()) + + // Construct an instance of the GetBillingUnitOptions model + getBillingUnitOptionsModel := new(enterprisebillingunitsv1.GetBillingUnitOptions) + getBillingUnitOptionsModel.BillingUnitID = core.StringPtr("testString") + getBillingUnitOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := enterpriseBillingUnitsService.GetBillingUnit(getBillingUnitOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + enterpriseBillingUnitsService.EnableRetries(0, 0) + result, response, operationErr = enterpriseBillingUnitsService.GetBillingUnit(getBillingUnitOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`GetBillingUnit(getBillingUnitOptions *GetBillingUnitOptions)`, func() { + getBillingUnitPath := "/v1/billing-units/testString" + var serverSleepTime time.Duration + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + serverSleepTime = 0 + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getBillingUnitPath)) + Expect(req.Method).To(Equal("GET")) + + // Sleep a short time to support a timeout test + time.Sleep(serverSleepTime) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"id": "ID", "crn": "crn:v1:bluemix:public:billing::a/<>::billing-unit:<>", "name": "Name", "enterprise_id": "EnterpriseID", "currency_code": "USD", "country_code": "USA", "master": true, "created_at": "2019-01-01T12:00:00"}`) + })) + }) + It(`Invoke GetBillingUnit successfully`, func() { + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseBillingUnitsService).ToNot(BeNil()) + enterpriseBillingUnitsService.EnableRetries(0, 0) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := enterpriseBillingUnitsService.GetBillingUnit(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the GetBillingUnitOptions model + getBillingUnitOptionsModel := new(enterprisebillingunitsv1.GetBillingUnitOptions) + getBillingUnitOptionsModel.BillingUnitID = core.StringPtr("testString") + getBillingUnitOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = enterpriseBillingUnitsService.GetBillingUnit(getBillingUnitOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + serverSleepTime = 100 * time.Millisecond + _, _, operationErr = enterpriseBillingUnitsService.GetBillingUnitWithContext(ctx, getBillingUnitOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + serverSleepTime = time.Duration(0) + + // Disable retries and test again + enterpriseBillingUnitsService.DisableRetries() + result, response, operationErr = enterpriseBillingUnitsService.GetBillingUnit(getBillingUnitOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + serverSleepTime = 100 * time.Millisecond + _, _, operationErr = enterpriseBillingUnitsService.GetBillingUnitWithContext(ctx, getBillingUnitOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + serverSleepTime = time.Duration(0) + }) + It(`Invoke GetBillingUnit with error: Operation validation and request error`, func() { + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseBillingUnitsService).ToNot(BeNil()) + + // Construct an instance of the GetBillingUnitOptions model + getBillingUnitOptionsModel := new(enterprisebillingunitsv1.GetBillingUnitOptions) + getBillingUnitOptionsModel.BillingUnitID = core.StringPtr("testString") + getBillingUnitOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := enterpriseBillingUnitsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := enterpriseBillingUnitsService.GetBillingUnit(getBillingUnitOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + // Construct a second instance of the GetBillingUnitOptions model with no property values + getBillingUnitOptionsModelNew := new(enterprisebillingunitsv1.GetBillingUnitOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = enterpriseBillingUnitsService.GetBillingUnit(getBillingUnitOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`ListBillingUnits(listBillingUnitsOptions *ListBillingUnitsOptions) - Operation response error`, func() { + listBillingUnitsPath := "/v1/billing-units" + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(listBillingUnitsPath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.URL.Query()["account_id"]).To(Equal([]string{"testString"})) + + Expect(req.URL.Query()["enterprise_id"]).To(Equal([]string{"testString"})) + + Expect(req.URL.Query()["account_group_id"]).To(Equal([]string{"testString"})) + + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `} this is not valid json {`) + })) + }) + It(`Invoke ListBillingUnits with error: Operation response processing error`, func() { + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseBillingUnitsService).ToNot(BeNil()) + + // Construct an instance of the ListBillingUnitsOptions model + listBillingUnitsOptionsModel := new(enterprisebillingunitsv1.ListBillingUnitsOptions) + listBillingUnitsOptionsModel.AccountID = core.StringPtr("testString") + listBillingUnitsOptionsModel.EnterpriseID = core.StringPtr("testString") + listBillingUnitsOptionsModel.AccountGroupID = core.StringPtr("testString") + listBillingUnitsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := enterpriseBillingUnitsService.ListBillingUnits(listBillingUnitsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + enterpriseBillingUnitsService.EnableRetries(0, 0) + result, response, operationErr = enterpriseBillingUnitsService.ListBillingUnits(listBillingUnitsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`ListBillingUnits(listBillingUnitsOptions *ListBillingUnitsOptions)`, func() { + listBillingUnitsPath := "/v1/billing-units" + var serverSleepTime time.Duration + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + serverSleepTime = 0 + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(listBillingUnitsPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.URL.Query()["account_id"]).To(Equal([]string{"testString"})) + + Expect(req.URL.Query()["enterprise_id"]).To(Equal([]string{"testString"})) + + Expect(req.URL.Query()["account_group_id"]).To(Equal([]string{"testString"})) + + // Sleep a short time to support a timeout test + time.Sleep(serverSleepTime) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"rows_count": 9, "next_url": "NextURL", "resources": [{"id": "ID", "crn": "crn:v1:bluemix:public:billing::a/<>::billing-unit:<>", "name": "Name", "enterprise_id": "EnterpriseID", "currency_code": "USD", "country_code": "USA", "master": true, "created_at": "2019-01-01T12:00:00"}]}`) + })) + }) + It(`Invoke ListBillingUnits successfully`, func() { + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseBillingUnitsService).ToNot(BeNil()) + enterpriseBillingUnitsService.EnableRetries(0, 0) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := enterpriseBillingUnitsService.ListBillingUnits(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the ListBillingUnitsOptions model + listBillingUnitsOptionsModel := new(enterprisebillingunitsv1.ListBillingUnitsOptions) + listBillingUnitsOptionsModel.AccountID = core.StringPtr("testString") + listBillingUnitsOptionsModel.EnterpriseID = core.StringPtr("testString") + listBillingUnitsOptionsModel.AccountGroupID = core.StringPtr("testString") + listBillingUnitsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = enterpriseBillingUnitsService.ListBillingUnits(listBillingUnitsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + serverSleepTime = 100 * time.Millisecond + _, _, operationErr = enterpriseBillingUnitsService.ListBillingUnitsWithContext(ctx, listBillingUnitsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + serverSleepTime = time.Duration(0) + + // Disable retries and test again + enterpriseBillingUnitsService.DisableRetries() + result, response, operationErr = enterpriseBillingUnitsService.ListBillingUnits(listBillingUnitsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + serverSleepTime = 100 * time.Millisecond + _, _, operationErr = enterpriseBillingUnitsService.ListBillingUnitsWithContext(ctx, listBillingUnitsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + serverSleepTime = time.Duration(0) + }) + It(`Invoke ListBillingUnits with error: Operation request error`, func() { + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseBillingUnitsService).ToNot(BeNil()) + + // Construct an instance of the ListBillingUnitsOptions model + listBillingUnitsOptionsModel := new(enterprisebillingunitsv1.ListBillingUnitsOptions) + listBillingUnitsOptionsModel.AccountID = core.StringPtr("testString") + listBillingUnitsOptionsModel.EnterpriseID = core.StringPtr("testString") + listBillingUnitsOptionsModel.AccountGroupID = core.StringPtr("testString") + listBillingUnitsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := enterpriseBillingUnitsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := enterpriseBillingUnitsService.ListBillingUnits(listBillingUnitsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`Service constructor tests`, func() { + It(`Instantiate service client`, func() { + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(enterpriseBillingUnitsService).ToNot(BeNil()) + Expect(serviceErr).To(BeNil()) + }) + It(`Instantiate service client with error: Invalid URL`, func() { + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + URL: "{BAD_URL_STRING", + }) + Expect(enterpriseBillingUnitsService).To(BeNil()) + Expect(serviceErr).ToNot(BeNil()) + }) + It(`Instantiate service client with error: Invalid Auth`, func() { + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + URL: "https://enterprisebillingunitsv1/api", + Authenticator: &core.BasicAuthenticator{ + Username: "", + Password: "", + }, + }) + Expect(enterpriseBillingUnitsService).To(BeNil()) + Expect(serviceErr).ToNot(BeNil()) + }) + }) + Describe(`Service constructor tests using external config`, func() { + Context(`Using external config, construct service client instances`, func() { + // Map containing environment variables used in testing. + var testEnvironment = map[string]string{ + "ENTERPRISE_BILLING_UNITS_URL": "https://enterprisebillingunitsv1/api", + "ENTERPRISE_BILLING_UNITS_AUTH_TYPE": "noauth", + } + + It(`Create service client using external config successfully`, func() { + SetTestEnvironment(testEnvironment) + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1UsingExternalConfig(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + }) + Expect(enterpriseBillingUnitsService).ToNot(BeNil()) + Expect(serviceErr).To(BeNil()) + ClearTestEnvironment(testEnvironment) + }) + It(`Create service client using external config and set url from constructor successfully`, func() { + SetTestEnvironment(testEnvironment) + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1UsingExternalConfig(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + URL: "https://testService/api", + }) + Expect(enterpriseBillingUnitsService).ToNot(BeNil()) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseBillingUnitsService.Service.GetServiceURL()).To(Equal("https://testService/api")) + ClearTestEnvironment(testEnvironment) + }) + It(`Create service client using external config and set url programatically successfully`, func() { + SetTestEnvironment(testEnvironment) + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1UsingExternalConfig(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + }) + err := enterpriseBillingUnitsService.SetServiceURL("https://testService/api") + Expect(err).To(BeNil()) + Expect(enterpriseBillingUnitsService).ToNot(BeNil()) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseBillingUnitsService.Service.GetServiceURL()).To(Equal("https://testService/api")) + ClearTestEnvironment(testEnvironment) + }) + }) + Context(`Using external config, construct service client instances with error: Invalid Auth`, func() { + // Map containing environment variables used in testing. + var testEnvironment = map[string]string{ + "ENTERPRISE_BILLING_UNITS_URL": "https://enterprisebillingunitsv1/api", + "ENTERPRISE_BILLING_UNITS_AUTH_TYPE": "someOtherAuth", + } + + SetTestEnvironment(testEnvironment) + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1UsingExternalConfig(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + }) + + It(`Instantiate service client with error`, func() { + Expect(enterpriseBillingUnitsService).To(BeNil()) + Expect(serviceErr).ToNot(BeNil()) + ClearTestEnvironment(testEnvironment) + }) + }) + Context(`Using external config, construct service client instances with error: Invalid URL`, func() { + // Map containing environment variables used in testing. + var testEnvironment = map[string]string{ + "ENTERPRISE_BILLING_UNITS_AUTH_TYPE": "NOAuth", + } + + SetTestEnvironment(testEnvironment) + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1UsingExternalConfig(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + URL: "{BAD_URL_STRING", + }) + + It(`Instantiate service client with error`, func() { + Expect(enterpriseBillingUnitsService).To(BeNil()) + Expect(serviceErr).ToNot(BeNil()) + ClearTestEnvironment(testEnvironment) + }) + }) + }) + Describe(`ListBillingOptions(listBillingOptionsOptions *ListBillingOptionsOptions) - Operation response error`, func() { + listBillingOptionsPath := "/v1/billing-options" + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(listBillingOptionsPath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.URL.Query()["billing_unit_id"]).To(Equal([]string{"testString"})) + + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `} this is not valid json {`) + })) + }) + It(`Invoke ListBillingOptions with error: Operation response processing error`, func() { + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseBillingUnitsService).ToNot(BeNil()) + + // Construct an instance of the ListBillingOptionsOptions model + listBillingOptionsOptionsModel := new(enterprisebillingunitsv1.ListBillingOptionsOptions) + listBillingOptionsOptionsModel.BillingUnitID = core.StringPtr("testString") + listBillingOptionsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := enterpriseBillingUnitsService.ListBillingOptions(listBillingOptionsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + enterpriseBillingUnitsService.EnableRetries(0, 0) + result, response, operationErr = enterpriseBillingUnitsService.ListBillingOptions(listBillingOptionsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`ListBillingOptions(listBillingOptionsOptions *ListBillingOptionsOptions)`, func() { + listBillingOptionsPath := "/v1/billing-options" + var serverSleepTime time.Duration + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + serverSleepTime = 0 + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(listBillingOptionsPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.URL.Query()["billing_unit_id"]).To(Equal([]string{"testString"})) + + // Sleep a short time to support a timeout test + time.Sleep(serverSleepTime) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"rows_count": 9, "next_url": "NextURL", "resources": [{"id": "ID", "billing_unit_id": "BillingUnitID", "start_date": "2019-01-01T12:00:00", "end_date": "2019-01-01T12:00:00", "state": "ACTIVE", "type": "SUBSCRIPTION", "category": "PLATFORM", "payment_instrument": {"mapKey": "anyValue"}, "duration_in_months": 11, "line_item_id": 10, "billing_system": {"mapKey": "anyValue"}, "renewal_mode_code": "RenewalModeCode", "updated_at": "2019-01-01T12:00:00"}]}`) + })) + }) + It(`Invoke ListBillingOptions successfully`, func() { + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseBillingUnitsService).ToNot(BeNil()) + enterpriseBillingUnitsService.EnableRetries(0, 0) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := enterpriseBillingUnitsService.ListBillingOptions(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the ListBillingOptionsOptions model + listBillingOptionsOptionsModel := new(enterprisebillingunitsv1.ListBillingOptionsOptions) + listBillingOptionsOptionsModel.BillingUnitID = core.StringPtr("testString") + listBillingOptionsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = enterpriseBillingUnitsService.ListBillingOptions(listBillingOptionsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + serverSleepTime = 100 * time.Millisecond + _, _, operationErr = enterpriseBillingUnitsService.ListBillingOptionsWithContext(ctx, listBillingOptionsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + serverSleepTime = time.Duration(0) + + // Disable retries and test again + enterpriseBillingUnitsService.DisableRetries() + result, response, operationErr = enterpriseBillingUnitsService.ListBillingOptions(listBillingOptionsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + serverSleepTime = 100 * time.Millisecond + _, _, operationErr = enterpriseBillingUnitsService.ListBillingOptionsWithContext(ctx, listBillingOptionsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + serverSleepTime = time.Duration(0) + }) + It(`Invoke ListBillingOptions with error: Operation validation and request error`, func() { + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseBillingUnitsService).ToNot(BeNil()) + + // Construct an instance of the ListBillingOptionsOptions model + listBillingOptionsOptionsModel := new(enterprisebillingunitsv1.ListBillingOptionsOptions) + listBillingOptionsOptionsModel.BillingUnitID = core.StringPtr("testString") + listBillingOptionsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := enterpriseBillingUnitsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := enterpriseBillingUnitsService.ListBillingOptions(listBillingOptionsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + // Construct a second instance of the ListBillingOptionsOptions model with no property values + listBillingOptionsOptionsModelNew := new(enterprisebillingunitsv1.ListBillingOptionsOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = enterpriseBillingUnitsService.ListBillingOptions(listBillingOptionsOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`Service constructor tests`, func() { + It(`Instantiate service client`, func() { + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(enterpriseBillingUnitsService).ToNot(BeNil()) + Expect(serviceErr).To(BeNil()) + }) + It(`Instantiate service client with error: Invalid URL`, func() { + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + URL: "{BAD_URL_STRING", + }) + Expect(enterpriseBillingUnitsService).To(BeNil()) + Expect(serviceErr).ToNot(BeNil()) + }) + It(`Instantiate service client with error: Invalid Auth`, func() { + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + URL: "https://enterprisebillingunitsv1/api", + Authenticator: &core.BasicAuthenticator{ + Username: "", + Password: "", + }, + }) + Expect(enterpriseBillingUnitsService).To(BeNil()) + Expect(serviceErr).ToNot(BeNil()) + }) + }) + Describe(`Service constructor tests using external config`, func() { + Context(`Using external config, construct service client instances`, func() { + // Map containing environment variables used in testing. + var testEnvironment = map[string]string{ + "ENTERPRISE_BILLING_UNITS_URL": "https://enterprisebillingunitsv1/api", + "ENTERPRISE_BILLING_UNITS_AUTH_TYPE": "noauth", + } + + It(`Create service client using external config successfully`, func() { + SetTestEnvironment(testEnvironment) + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1UsingExternalConfig(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + }) + Expect(enterpriseBillingUnitsService).ToNot(BeNil()) + Expect(serviceErr).To(BeNil()) + ClearTestEnvironment(testEnvironment) + }) + It(`Create service client using external config and set url from constructor successfully`, func() { + SetTestEnvironment(testEnvironment) + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1UsingExternalConfig(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + URL: "https://testService/api", + }) + Expect(enterpriseBillingUnitsService).ToNot(BeNil()) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseBillingUnitsService.Service.GetServiceURL()).To(Equal("https://testService/api")) + ClearTestEnvironment(testEnvironment) + }) + It(`Create service client using external config and set url programatically successfully`, func() { + SetTestEnvironment(testEnvironment) + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1UsingExternalConfig(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + }) + err := enterpriseBillingUnitsService.SetServiceURL("https://testService/api") + Expect(err).To(BeNil()) + Expect(enterpriseBillingUnitsService).ToNot(BeNil()) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseBillingUnitsService.Service.GetServiceURL()).To(Equal("https://testService/api")) + ClearTestEnvironment(testEnvironment) + }) + }) + Context(`Using external config, construct service client instances with error: Invalid Auth`, func() { + // Map containing environment variables used in testing. + var testEnvironment = map[string]string{ + "ENTERPRISE_BILLING_UNITS_URL": "https://enterprisebillingunitsv1/api", + "ENTERPRISE_BILLING_UNITS_AUTH_TYPE": "someOtherAuth", + } + + SetTestEnvironment(testEnvironment) + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1UsingExternalConfig(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + }) + + It(`Instantiate service client with error`, func() { + Expect(enterpriseBillingUnitsService).To(BeNil()) + Expect(serviceErr).ToNot(BeNil()) + ClearTestEnvironment(testEnvironment) + }) + }) + Context(`Using external config, construct service client instances with error: Invalid URL`, func() { + // Map containing environment variables used in testing. + var testEnvironment = map[string]string{ + "ENTERPRISE_BILLING_UNITS_AUTH_TYPE": "NOAuth", + } + + SetTestEnvironment(testEnvironment) + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1UsingExternalConfig(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + URL: "{BAD_URL_STRING", + }) + + It(`Instantiate service client with error`, func() { + Expect(enterpriseBillingUnitsService).To(BeNil()) + Expect(serviceErr).ToNot(BeNil()) + ClearTestEnvironment(testEnvironment) + }) + }) + }) + Describe(`GetCreditPools(getCreditPoolsOptions *GetCreditPoolsOptions) - Operation response error`, func() { + getCreditPoolsPath := "/v1/credit-pools" + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getCreditPoolsPath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.URL.Query()["billing_unit_id"]).To(Equal([]string{"testString"})) + + Expect(req.URL.Query()["date"]).To(Equal([]string{"testString"})) + + Expect(req.URL.Query()["type"]).To(Equal([]string{"testString"})) + + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `} this is not valid json {`) + })) + }) + It(`Invoke GetCreditPools with error: Operation response processing error`, func() { + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseBillingUnitsService).ToNot(BeNil()) + + // Construct an instance of the GetCreditPoolsOptions model + getCreditPoolsOptionsModel := new(enterprisebillingunitsv1.GetCreditPoolsOptions) + getCreditPoolsOptionsModel.BillingUnitID = core.StringPtr("testString") + getCreditPoolsOptionsModel.Date = core.StringPtr("testString") + getCreditPoolsOptionsModel.Type = core.StringPtr("testString") + getCreditPoolsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Expect response parsing to fail since we are receiving a text/plain response + result, response, operationErr := enterpriseBillingUnitsService.GetCreditPools(getCreditPoolsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + + // Enable retries and test again + enterpriseBillingUnitsService.EnableRetries(0, 0) + result, response, operationErr = enterpriseBillingUnitsService.GetCreditPools(getCreditPoolsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`GetCreditPools(getCreditPoolsOptions *GetCreditPoolsOptions)`, func() { + getCreditPoolsPath := "/v1/credit-pools" + var serverSleepTime time.Duration + Context(`Using mock server endpoint`, func() { + BeforeEach(func() { + serverSleepTime = 0 + testServer = httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + defer GinkgoRecover() + + // Verify the contents of the request + Expect(req.URL.EscapedPath()).To(Equal(getCreditPoolsPath)) + Expect(req.Method).To(Equal("GET")) + + Expect(req.URL.Query()["billing_unit_id"]).To(Equal([]string{"testString"})) + + Expect(req.URL.Query()["date"]).To(Equal([]string{"testString"})) + + Expect(req.URL.Query()["type"]).To(Equal([]string{"testString"})) + + // Sleep a short time to support a timeout test + time.Sleep(serverSleepTime) + + // Set mock response + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, "%s", `{"rows_count": 2, "next_url": "NextURL", "resources": [{"type": "PLATFORM", "currency_code": "USD", "billing_unit_id": "BillingUnitID", "term_credits": [{"billing_option_id": "JWX986YRGFSHACQUEFOI", "category": "PLATFORM", "start_date": "2019-01-01T12:00:00", "end_date": "2019-01-01T12:00:00", "total_credits": 10000, "starting_balance": 9000, "used_credits": 9500, "current_balance": 0, "resources": [{"mapKey": "anyValue"}]}], "overage": {"cost": 500, "resources": [{"mapKey": "anyValue"}]}}]}`) + })) + }) + It(`Invoke GetCreditPools successfully`, func() { + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseBillingUnitsService).ToNot(BeNil()) + enterpriseBillingUnitsService.EnableRetries(0, 0) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := enterpriseBillingUnitsService.GetCreditPools(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the GetCreditPoolsOptions model + getCreditPoolsOptionsModel := new(enterprisebillingunitsv1.GetCreditPoolsOptions) + getCreditPoolsOptionsModel.BillingUnitID = core.StringPtr("testString") + getCreditPoolsOptionsModel.Date = core.StringPtr("testString") + getCreditPoolsOptionsModel.Type = core.StringPtr("testString") + getCreditPoolsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = enterpriseBillingUnitsService.GetCreditPools(getCreditPoolsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Invoke operation with a Context to test a timeout error + ctx, cancelFunc := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc() + serverSleepTime = 100 * time.Millisecond + _, _, operationErr = enterpriseBillingUnitsService.GetCreditPoolsWithContext(ctx, getCreditPoolsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + serverSleepTime = time.Duration(0) + + // Disable retries and test again + enterpriseBillingUnitsService.DisableRetries() + result, response, operationErr = enterpriseBillingUnitsService.GetCreditPools(getCreditPoolsOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + + // Re-test the timeout error with retries disabled + ctx, cancelFunc2 := context.WithTimeout(context.Background(), 80*time.Millisecond) + defer cancelFunc2() + serverSleepTime = 100 * time.Millisecond + _, _, operationErr = enterpriseBillingUnitsService.GetCreditPoolsWithContext(ctx, getCreditPoolsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring("deadline exceeded")) + serverSleepTime = time.Duration(0) + }) + It(`Invoke GetCreditPools with error: Operation validation and request error`, func() { + enterpriseBillingUnitsService, serviceErr := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(serviceErr).To(BeNil()) + Expect(enterpriseBillingUnitsService).ToNot(BeNil()) + + // Construct an instance of the GetCreditPoolsOptions model + getCreditPoolsOptionsModel := new(enterprisebillingunitsv1.GetCreditPoolsOptions) + getCreditPoolsOptionsModel.BillingUnitID = core.StringPtr("testString") + getCreditPoolsOptionsModel.Date = core.StringPtr("testString") + getCreditPoolsOptionsModel.Type = core.StringPtr("testString") + getCreditPoolsOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := enterpriseBillingUnitsService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := enterpriseBillingUnitsService.GetCreditPools(getCreditPoolsOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(operationErr.Error()).To(ContainSubstring(core.ERRORMSG_SERVICE_URL_MISSING)) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + // Construct a second instance of the GetCreditPoolsOptions model with no property values + getCreditPoolsOptionsModelNew := new(enterprisebillingunitsv1.GetCreditPoolsOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = enterpriseBillingUnitsService.GetCreditPools(getCreditPoolsOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`Model constructor tests`, func() { + Context(`Using a service client instance`, func() { + enterpriseBillingUnitsService, _ := enterprisebillingunitsv1.NewEnterpriseBillingUnitsV1(&enterprisebillingunitsv1.EnterpriseBillingUnitsV1Options{ + URL: "http://enterprisebillingunitsv1modelgenerator.com", + Authenticator: &core.NoAuthAuthenticator{}, + }) + It(`Invoke NewGetBillingUnitOptions successfully`, func() { + // Construct an instance of the GetBillingUnitOptions model + billingUnitID := "testString" + getBillingUnitOptionsModel := enterpriseBillingUnitsService.NewGetBillingUnitOptions(billingUnitID) + getBillingUnitOptionsModel.SetBillingUnitID("testString") + getBillingUnitOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(getBillingUnitOptionsModel).ToNot(BeNil()) + Expect(getBillingUnitOptionsModel.BillingUnitID).To(Equal(core.StringPtr("testString"))) + Expect(getBillingUnitOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewGetCreditPoolsOptions successfully`, func() { + // Construct an instance of the GetCreditPoolsOptions model + billingUnitID := "testString" + getCreditPoolsOptionsModel := enterpriseBillingUnitsService.NewGetCreditPoolsOptions(billingUnitID) + getCreditPoolsOptionsModel.SetBillingUnitID("testString") + getCreditPoolsOptionsModel.SetDate("testString") + getCreditPoolsOptionsModel.SetType("testString") + getCreditPoolsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(getCreditPoolsOptionsModel).ToNot(BeNil()) + Expect(getCreditPoolsOptionsModel.BillingUnitID).To(Equal(core.StringPtr("testString"))) + Expect(getCreditPoolsOptionsModel.Date).To(Equal(core.StringPtr("testString"))) + Expect(getCreditPoolsOptionsModel.Type).To(Equal(core.StringPtr("testString"))) + Expect(getCreditPoolsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewListBillingOptionsOptions successfully`, func() { + // Construct an instance of the ListBillingOptionsOptions model + billingUnitID := "testString" + listBillingOptionsOptionsModel := enterpriseBillingUnitsService.NewListBillingOptionsOptions(billingUnitID) + listBillingOptionsOptionsModel.SetBillingUnitID("testString") + listBillingOptionsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(listBillingOptionsOptionsModel).ToNot(BeNil()) + Expect(listBillingOptionsOptionsModel.BillingUnitID).To(Equal(core.StringPtr("testString"))) + Expect(listBillingOptionsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewListBillingUnitsOptions successfully`, func() { + // Construct an instance of the ListBillingUnitsOptions model + listBillingUnitsOptionsModel := enterpriseBillingUnitsService.NewListBillingUnitsOptions() + listBillingUnitsOptionsModel.SetAccountID("testString") + listBillingUnitsOptionsModel.SetEnterpriseID("testString") + listBillingUnitsOptionsModel.SetAccountGroupID("testString") + listBillingUnitsOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(listBillingUnitsOptionsModel).ToNot(BeNil()) + Expect(listBillingUnitsOptionsModel.AccountID).To(Equal(core.StringPtr("testString"))) + Expect(listBillingUnitsOptionsModel.EnterpriseID).To(Equal(core.StringPtr("testString"))) + Expect(listBillingUnitsOptionsModel.AccountGroupID).To(Equal(core.StringPtr("testString"))) + Expect(listBillingUnitsOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + }) + }) + Describe(`Utility function tests`, func() { + It(`Invoke CreateMockByteArray() successfully`, func() { + mockByteArray := CreateMockByteArray("This is a test") + Expect(mockByteArray).ToNot(BeNil()) + }) + It(`Invoke CreateMockUUID() successfully`, func() { + mockUUID := CreateMockUUID("9fab83da-98cb-4f18-a7ba-b6f0435c9673") + Expect(mockUUID).ToNot(BeNil()) + }) + It(`Invoke CreateMockReader() successfully`, func() { + mockReader := CreateMockReader("This is a test.") + Expect(mockReader).ToNot(BeNil()) + }) + It(`Invoke CreateMockDate() successfully`, func() { + mockDate := CreateMockDate() + Expect(mockDate).ToNot(BeNil()) + }) + It(`Invoke CreateMockDateTime() successfully`, func() { + mockDateTime := CreateMockDateTime() + Expect(mockDateTime).ToNot(BeNil()) + }) + }) +}) + +// +// Utility functions used by the generated test code +// + +func CreateMockByteArray(mockData string) *[]byte { + ba := make([]byte, 0) + ba = append(ba, mockData...) + return &ba +} + +func CreateMockUUID(mockData string) *strfmt.UUID { + uuid := strfmt.UUID(mockData) + return &uuid +} + +func CreateMockReader(mockData string) io.ReadCloser { + return ioutil.NopCloser(bytes.NewReader([]byte(mockData))) +} + +func CreateMockDate() *strfmt.Date { + d := strfmt.Date(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)) + return &d +} + +func CreateMockDateTime() *strfmt.DateTime { + d := strfmt.DateTime(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)) + return &d +} + +func SetTestEnvironment(testEnvironment map[string]string) { + for key, value := range testEnvironment { + os.Setenv(key, value) + } +} + +func ClearTestEnvironment(testEnvironment map[string]string) { + for key := range testEnvironment { + os.Unsetenv(key) + } +}