From 93ae7ca125b112b3cc3de827bff7ea60f5250b64 Mon Sep 17 00:00:00 2001 From: Phil Adams Date: Tue, 19 May 2020 23:32:38 -0500 Subject: [PATCH] feat(Case Management): add service to project (#11) Co-authored-by: Huy Doan --- .travis.yml | 1 + README.md | 1 + case_management.env.enc | 3 + casemanagementv1/case_management_v1.go | 2311 +++++++++++++++++ .../case_management_v1_integration_test.go | 373 +++ .../case_management_v1_suite_test.go | 28 + casemanagementv1/case_management_v1_test.go | 1939 ++++++++++++++ 7 files changed, 4656 insertions(+) create mode 100644 case_management.env.enc create mode 100644 casemanagementv1/case_management_v1.go create mode 100644 casemanagementv1/case_management_v1_integration_test.go create mode 100644 casemanagementv1/case_management_v1_suite_test.go create mode 100644 casemanagementv1/case_management_v1_test.go diff --git a/.travis.yml b/.travis.yml index 30a695ae..67496a56 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,7 @@ before_install: && openssl aes-256-cbc -K $encrypted_66f264007c0d_key -iv $encrypted_66f264007c0d_iv -in iam_access_groups.env.enc -out iam_access_groups.env -d && openssl aes-256-cbc -K $encrypted_94fa7fdf4df9_key -iv $encrypted_94fa7fdf4df9_iv -in global_catalog.env.enc -out global_catalog.env -d && openssl aes-256-cbc -K $encrypted_acd9ca9788e3_key -iv $encrypted_acd9ca9788e3_iv -in resource_manager.env.enc -out resource_manager.env -d + && openssl aes-256-cbc -K $encrypted_dac53b985913_key -iv $encrypted_dac53b985913_iv -in case_management.env.enc -out case_management.env -d || true install: diff --git a/README.md b/README.md index 13ceec95..72c74fb5 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ The IBM Cloud Platform Services Go SDK allows developers to programmatically int Service Name | Package name --- | --- +[Case Management](https://cloud.ibm.com/apidocs/case-management) | casemanagementv1 [Global Catalog](https://cloud.ibm.com/apidocs/resource-catalog/global-catalog) | globalcatalogv1 [Global Search](https://cloud.ibm.com/apidocs/search) | globalsearchv2 [Global Tagging](https://cloud.ibm.com/apidocs/tagging) | globaltaggingv1 diff --git a/case_management.env.enc b/case_management.env.enc new file mode 100644 index 00000000..fae006d9 --- /dev/null +++ b/case_management.env.enc @@ -0,0 +1,3 @@ +w~J!xM,^$]XKE+k9ݫ;M@pcp;FnxS=շ".u0\Py/"࡚w~Yf3wR<6:;_ +7=2.=:n.%#^9 !42ߎ_VVt (A׺| Aˊu%RAe&~TdL2pǥ^jp +l+ҰK19 \ No newline at end of file diff --git a/casemanagementv1/case_management_v1.go b/casemanagementv1/case_management_v1.go new file mode 100644 index 00000000..43c6759a --- /dev/null +++ b/casemanagementv1/case_management_v1.go @@ -0,0 +1,2311 @@ +/** + * (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 casemanagementv1 : Operations and models for the CaseManagementV1 service +package casemanagementv1 + +import ( + "encoding/json" + "fmt" + "github.com/IBM/go-sdk-core/v4/core" + common "github.com/IBM/platform-services-go-sdk/common" + "io" + "reflect" + "strings" +) + +// CaseManagementV1 : Case management API for creating cases, getting case statuses, adding comments to a case, adding +// and removing users from a case watchlist, downloading and adding attachments, and more. +// +// Version: 1.0.0 +type CaseManagementV1 struct { + Service *core.BaseService +} + +// DefaultServiceURL is the default URL to make service requests to. +const DefaultServiceURL = "https://support-center.cloud.ibm.com/case-management/v1" + +// DefaultServiceName is the default key used to find external configuration information. +const DefaultServiceName = "case_management" + +// CaseManagementV1Options : Service options +type CaseManagementV1Options struct { + ServiceName string + URL string + Authenticator core.Authenticator +} + +// NewCaseManagementV1UsingExternalConfig : constructs an instance of CaseManagementV1 with passed in options and external configuration. +func NewCaseManagementV1UsingExternalConfig(options *CaseManagementV1Options) (caseManagement *CaseManagementV1, err error) { + if options.ServiceName == "" { + options.ServiceName = DefaultServiceName + } + + if options.Authenticator == nil { + options.Authenticator, err = core.GetAuthenticatorFromEnvironment(options.ServiceName) + if err != nil { + return + } + } + + caseManagement, err = NewCaseManagementV1(options) + if err != nil { + return + } + + err = caseManagement.Service.ConfigureService(options.ServiceName) + if err != nil { + return + } + + if options.URL != "" { + err = caseManagement.Service.SetServiceURL(options.URL) + } + return +} + +// NewCaseManagementV1 : constructs an instance of CaseManagementV1 with passed in options. +func NewCaseManagementV1(options *CaseManagementV1Options) (service *CaseManagementV1, 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 = &CaseManagementV1{ + Service: baseService, + } + + return +} + +// SetServiceURL sets the service URL +func (caseManagement *CaseManagementV1) SetServiceURL(url string) error { + return caseManagement.Service.SetServiceURL(url) +} + +// GetCases : Get cases in account +// Get cases in the account which is specified by the content of the IAM token. +func (caseManagement *CaseManagementV1) GetCases(getCasesOptions *GetCasesOptions) (result *CaseList, response *core.DetailedResponse, err error) { + err = core.ValidateStruct(getCasesOptions, "getCasesOptions") + if err != nil { + return + } + + pathSegments := []string{"cases"} + pathParameters := []string{} + + builder := core.NewRequestBuilder(core.GET) + _, err = builder.ConstructHTTPURL(caseManagement.Service.Options.URL, pathSegments, pathParameters) + if err != nil { + return + } + + for headerName, headerValue := range getCasesOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("case_management", "V1", "GetCases") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + + if getCasesOptions.Offset != nil { + builder.AddQuery("offset", fmt.Sprint(*getCasesOptions.Offset)) + } + if getCasesOptions.Limit != nil { + builder.AddQuery("limit", fmt.Sprint(*getCasesOptions.Limit)) + } + if getCasesOptions.Search != nil { + builder.AddQuery("search", fmt.Sprint(*getCasesOptions.Search)) + } + if getCasesOptions.Sort != nil { + builder.AddQuery("sort", fmt.Sprint(*getCasesOptions.Sort)) + } + if getCasesOptions.Status != nil { + builder.AddQuery("status", strings.Join(getCasesOptions.Status, ",")) + } + if getCasesOptions.Fields != nil { + builder.AddQuery("fields", strings.Join(getCasesOptions.Fields, ",")) + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = caseManagement.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalCaseList) + if err != nil { + return + } + response.Result = result + + return +} + +// CreateCase : Create a case +// Create a case in the account. +func (caseManagement *CaseManagementV1) CreateCase(createCaseOptions *CreateCaseOptions) (result *Case, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(createCaseOptions, "createCaseOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(createCaseOptions, "createCaseOptions") + if err != nil { + return + } + + pathSegments := []string{"cases"} + pathParameters := []string{} + + builder := core.NewRequestBuilder(core.POST) + _, err = builder.ConstructHTTPURL(caseManagement.Service.Options.URL, pathSegments, pathParameters) + if err != nil { + return + } + + for headerName, headerValue := range createCaseOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("case_management", "V1", "CreateCase") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + + body := make(map[string]interface{}) + if createCaseOptions.Type != nil { + body["type"] = createCaseOptions.Type + } + if createCaseOptions.Subject != nil { + body["subject"] = createCaseOptions.Subject + } + if createCaseOptions.Description != nil { + body["description"] = createCaseOptions.Description + } + if createCaseOptions.Severity != nil { + body["severity"] = createCaseOptions.Severity + } + if createCaseOptions.Eu != nil { + body["eu"] = createCaseOptions.Eu + } + if createCaseOptions.Offering != nil { + body["offering"] = createCaseOptions.Offering + } + if createCaseOptions.Resources != nil { + body["resources"] = createCaseOptions.Resources + } + if createCaseOptions.Watchlist != nil { + body["watchlist"] = createCaseOptions.Watchlist + } + if createCaseOptions.InvoiceNumber != nil { + body["invoice_number"] = createCaseOptions.InvoiceNumber + } + if createCaseOptions.SlaCreditRequest != nil { + body["sla_credit_request"] = createCaseOptions.SlaCreditRequest + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + return + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = caseManagement.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalCase) + if err != nil { + return + } + response.Result = result + + return +} + +// GetCase : Get a case in account +// Get a case in the account that is specified by the case number. +func (caseManagement *CaseManagementV1) GetCase(getCaseOptions *GetCaseOptions) (result *Case, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(getCaseOptions, "getCaseOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(getCaseOptions, "getCaseOptions") + if err != nil { + return + } + + pathSegments := []string{"cases"} + pathParameters := []string{*getCaseOptions.CaseNumber} + + builder := core.NewRequestBuilder(core.GET) + _, err = builder.ConstructHTTPURL(caseManagement.Service.Options.URL, pathSegments, pathParameters) + if err != nil { + return + } + + for headerName, headerValue := range getCaseOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("case_management", "V1", "GetCase") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + + if getCaseOptions.Fields != nil { + builder.AddQuery("fields", strings.Join(getCaseOptions.Fields, ",")) + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = caseManagement.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalCase) + if err != nil { + return + } + response.Result = result + + return +} + +// UpdateCaseStatus : Update case status +// Mark the case as resolved or unresolved, or accept the provided resolution. +func (caseManagement *CaseManagementV1) UpdateCaseStatus(updateCaseStatusOptions *UpdateCaseStatusOptions) (result *Case, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(updateCaseStatusOptions, "updateCaseStatusOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(updateCaseStatusOptions, "updateCaseStatusOptions") + if err != nil { + return + } + + pathSegments := []string{"cases", "status"} + pathParameters := []string{*updateCaseStatusOptions.CaseNumber} + + builder := core.NewRequestBuilder(core.PUT) + _, err = builder.ConstructHTTPURL(caseManagement.Service.Options.URL, pathSegments, pathParameters) + if err != nil { + return + } + + for headerName, headerValue := range updateCaseStatusOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("case_management", "V1", "UpdateCaseStatus") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + + _, err = builder.SetBodyContentJSON(updateCaseStatusOptions.StatusPayload) + if err != nil { + return + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = caseManagement.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalCase) + if err != nil { + return + } + response.Result = result + + return +} + +// AddComment : Add comment to case +// Add a comment to a case. +func (caseManagement *CaseManagementV1) AddComment(addCommentOptions *AddCommentOptions) (result *Comment, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(addCommentOptions, "addCommentOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(addCommentOptions, "addCommentOptions") + if err != nil { + return + } + + pathSegments := []string{"cases", "comments"} + pathParameters := []string{*addCommentOptions.CaseNumber} + + builder := core.NewRequestBuilder(core.PUT) + _, err = builder.ConstructHTTPURL(caseManagement.Service.Options.URL, pathSegments, pathParameters) + if err != nil { + return + } + + for headerName, headerValue := range addCommentOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("case_management", "V1", "AddComment") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + + body := make(map[string]interface{}) + if addCommentOptions.Comment != nil { + body["comment"] = addCommentOptions.Comment + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + return + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = caseManagement.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalComment) + if err != nil { + return + } + response.Result = result + + return +} + +// AddWatchlist : Add users to watchlist of case +// Add users to the watchlist of case. By adding a user to the watchlist of the case, you are granting them read and +// write permissions, so the user can view the case, receive updates, and make updates to the case. Note that the user +// must be in the account to be added to the watchlist. +func (caseManagement *CaseManagementV1) AddWatchlist(addWatchlistOptions *AddWatchlistOptions) (result *WatchlistAddResponse, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(addWatchlistOptions, "addWatchlistOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(addWatchlistOptions, "addWatchlistOptions") + if err != nil { + return + } + + pathSegments := []string{"cases", "watchlist"} + pathParameters := []string{*addWatchlistOptions.CaseNumber} + + builder := core.NewRequestBuilder(core.PUT) + _, err = builder.ConstructHTTPURL(caseManagement.Service.Options.URL, pathSegments, pathParameters) + if err != nil { + return + } + + for headerName, headerValue := range addWatchlistOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("case_management", "V1", "AddWatchlist") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + + body := make(map[string]interface{}) + if addWatchlistOptions.Watchlist != nil { + body["watchlist"] = addWatchlistOptions.Watchlist + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + return + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = caseManagement.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalWatchlistAddResponse) + if err != nil { + return + } + response.Result = result + + return +} + +// RemoveWatchlist : Remove users from watchlist of case +// Remove users from the watchlist of a case. +func (caseManagement *CaseManagementV1) RemoveWatchlist(removeWatchlistOptions *RemoveWatchlistOptions) (result *Watchlist, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(removeWatchlistOptions, "removeWatchlistOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(removeWatchlistOptions, "removeWatchlistOptions") + if err != nil { + return + } + + pathSegments := []string{"cases", "watchlist"} + pathParameters := []string{*removeWatchlistOptions.CaseNumber} + + builder := core.NewRequestBuilder(core.DELETE) + _, err = builder.ConstructHTTPURL(caseManagement.Service.Options.URL, pathSegments, pathParameters) + if err != nil { + return + } + + for headerName, headerValue := range removeWatchlistOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("case_management", "V1", "RemoveWatchlist") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + + body := make(map[string]interface{}) + if removeWatchlistOptions.Watchlist != nil { + body["watchlist"] = removeWatchlistOptions.Watchlist + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + return + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = caseManagement.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalWatchlist) + if err != nil { + return + } + response.Result = result + + return +} + +// AddResource : Add a resource to case +// Add a resource to case by specifying the Cloud Resource Name (CRN), or id and type if attaching a class iaaS +// resource. +func (caseManagement *CaseManagementV1) AddResource(addResourceOptions *AddResourceOptions) (result *Resource, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(addResourceOptions, "addResourceOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(addResourceOptions, "addResourceOptions") + if err != nil { + return + } + + pathSegments := []string{"cases", "resources"} + pathParameters := []string{*addResourceOptions.CaseNumber} + + builder := core.NewRequestBuilder(core.PUT) + _, err = builder.ConstructHTTPURL(caseManagement.Service.Options.URL, pathSegments, pathParameters) + if err != nil { + return + } + + for headerName, headerValue := range addResourceOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("case_management", "V1", "AddResource") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + builder.AddHeader("Content-Type", "application/json") + + body := make(map[string]interface{}) + if addResourceOptions.Crn != nil { + body["crn"] = addResourceOptions.Crn + } + if addResourceOptions.Type != nil { + body["type"] = addResourceOptions.Type + } + if addResourceOptions.ID != nil { + body["id"] = addResourceOptions.ID + } + if addResourceOptions.Note != nil { + body["note"] = addResourceOptions.Note + } + _, err = builder.SetBodyContentJSON(body) + if err != nil { + return + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = caseManagement.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalResource) + if err != nil { + return + } + response.Result = result + + return +} + +// UploadFile : Add attachment(s) to case +// You can add attachments to a case to provide more information for the support team about the issue that you're +// experiencing. +func (caseManagement *CaseManagementV1) UploadFile(uploadFileOptions *UploadFileOptions) (result *Attachment, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(uploadFileOptions, "uploadFileOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(uploadFileOptions, "uploadFileOptions") + if err != nil { + return + } + + pathSegments := []string{"cases", "attachments"} + pathParameters := []string{*uploadFileOptions.CaseNumber} + + builder := core.NewRequestBuilder(core.PUT) + _, err = builder.ConstructHTTPURL(caseManagement.Service.Options.URL, pathSegments, pathParameters) + if err != nil { + return + } + + for headerName, headerValue := range uploadFileOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("case_management", "V1", "UploadFile") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/json") + + for _, item := range uploadFileOptions.File { + builder.AddFormData("file", core.StringNilMapper(item.Filename), core.StringNilMapper(item.ContentType), item.Data) + } + + request, err := builder.Build() + if err != nil { + return + } + + var rawResponse map[string]json.RawMessage + response, err = caseManagement.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalAttachment) + if err != nil { + return + } + response.Result = result + + return +} + +// DownloadFile : Download an attachment +// Download an attachment from a case. +func (caseManagement *CaseManagementV1) DownloadFile(downloadFileOptions *DownloadFileOptions) (result io.ReadCloser, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(downloadFileOptions, "downloadFileOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(downloadFileOptions, "downloadFileOptions") + if err != nil { + return + } + + pathSegments := []string{"cases", "attachments"} + pathParameters := []string{*downloadFileOptions.CaseNumber, *downloadFileOptions.FileID} + + builder := core.NewRequestBuilder(core.GET) + _, err = builder.ConstructHTTPURL(caseManagement.Service.Options.URL, pathSegments, pathParameters) + if err != nil { + return + } + + for headerName, headerValue := range downloadFileOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("case_management", "V1", "DownloadFile") + for headerName, headerValue := range sdkHeaders { + builder.AddHeader(headerName, headerValue) + } + builder.AddHeader("Accept", "application/octet-stream") + + request, err := builder.Build() + if err != nil { + return + } + + response, err = caseManagement.Service.Request(request, &result) + + return +} + +// DeleteFile : Remove attachment from case +// Remove an attachment from a case. +func (caseManagement *CaseManagementV1) DeleteFile(deleteFileOptions *DeleteFileOptions) (result *AttachmentList, response *core.DetailedResponse, err error) { + err = core.ValidateNotNil(deleteFileOptions, "deleteFileOptions cannot be nil") + if err != nil { + return + } + err = core.ValidateStruct(deleteFileOptions, "deleteFileOptions") + if err != nil { + return + } + + pathSegments := []string{"cases", "attachments"} + pathParameters := []string{*deleteFileOptions.CaseNumber, *deleteFileOptions.FileID} + + builder := core.NewRequestBuilder(core.DELETE) + _, err = builder.ConstructHTTPURL(caseManagement.Service.Options.URL, pathSegments, pathParameters) + if err != nil { + return + } + + for headerName, headerValue := range deleteFileOptions.Headers { + builder.AddHeader(headerName, headerValue) + } + + sdkHeaders := common.GetSdkHeaders("case_management", "V1", "DeleteFile") + 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 = caseManagement.Service.Request(request, &rawResponse) + if err != nil { + return + } + err = core.UnmarshalModel(rawResponse, "", &result, UnmarshalAttachmentList) + if err != nil { + return + } + response.Result = result + + return +} + +// AddCommentOptions : The AddComment options. +type AddCommentOptions struct { + // Unique identifier of a case. + CaseNumber *string `json:"case_number" validate:"required"` + + // Comment to add to the case. + Comment *string `json:"comment" validate:"required"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewAddCommentOptions : Instantiate AddCommentOptions +func (*CaseManagementV1) NewAddCommentOptions(caseNumber string, comment string) *AddCommentOptions { + return &AddCommentOptions{ + CaseNumber: core.StringPtr(caseNumber), + Comment: core.StringPtr(comment), + } +} + +// SetCaseNumber : Allow user to set CaseNumber +func (options *AddCommentOptions) SetCaseNumber(caseNumber string) *AddCommentOptions { + options.CaseNumber = core.StringPtr(caseNumber) + return options +} + +// SetComment : Allow user to set Comment +func (options *AddCommentOptions) SetComment(comment string) *AddCommentOptions { + options.Comment = core.StringPtr(comment) + return options +} + +// SetHeaders : Allow user to set Headers +func (options *AddCommentOptions) SetHeaders(param map[string]string) *AddCommentOptions { + options.Headers = param + return options +} + +// AddResourceOptions : The AddResource options. +type AddResourceOptions struct { + // Unique identifier of a case. + CaseNumber *string `json:"case_number" validate:"required"` + + // Cloud Resource Name of the resource. + Crn *string `json:"crn,omitempty"` + + // Only used to attach Classic IaaS devices which have no CRN. + Type *string `json:"type,omitempty"` + + // Only used to attach Classic IaaS devices which have no CRN. Id of Classic IaaS device. This is deprecated in favor + // of the crn field. + ID *float64 `json:"id,omitempty"` + + // A note about this resource. + Note *string `json:"note,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewAddResourceOptions : Instantiate AddResourceOptions +func (*CaseManagementV1) NewAddResourceOptions(caseNumber string) *AddResourceOptions { + return &AddResourceOptions{ + CaseNumber: core.StringPtr(caseNumber), + } +} + +// SetCaseNumber : Allow user to set CaseNumber +func (options *AddResourceOptions) SetCaseNumber(caseNumber string) *AddResourceOptions { + options.CaseNumber = core.StringPtr(caseNumber) + return options +} + +// SetCrn : Allow user to set Crn +func (options *AddResourceOptions) SetCrn(crn string) *AddResourceOptions { + options.Crn = core.StringPtr(crn) + return options +} + +// SetType : Allow user to set Type +func (options *AddResourceOptions) SetType(typeVar string) *AddResourceOptions { + options.Type = core.StringPtr(typeVar) + return options +} + +// SetID : Allow user to set ID +func (options *AddResourceOptions) SetID(id float64) *AddResourceOptions { + options.ID = core.Float64Ptr(id) + return options +} + +// SetNote : Allow user to set Note +func (options *AddResourceOptions) SetNote(note string) *AddResourceOptions { + options.Note = core.StringPtr(note) + return options +} + +// SetHeaders : Allow user to set Headers +func (options *AddResourceOptions) SetHeaders(param map[string]string) *AddResourceOptions { + options.Headers = param + return options +} + +// AddWatchlistOptions : The AddWatchlist options. +type AddWatchlistOptions struct { + // Unique identifier of a case. + CaseNumber *string `json:"case_number" validate:"required"` + + // Array of user ID objects. + Watchlist []User `json:"watchlist,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewAddWatchlistOptions : Instantiate AddWatchlistOptions +func (*CaseManagementV1) NewAddWatchlistOptions(caseNumber string) *AddWatchlistOptions { + return &AddWatchlistOptions{ + CaseNumber: core.StringPtr(caseNumber), + } +} + +// SetCaseNumber : Allow user to set CaseNumber +func (options *AddWatchlistOptions) SetCaseNumber(caseNumber string) *AddWatchlistOptions { + options.CaseNumber = core.StringPtr(caseNumber) + return options +} + +// SetWatchlist : Allow user to set Watchlist +func (options *AddWatchlistOptions) SetWatchlist(watchlist []User) *AddWatchlistOptions { + options.Watchlist = watchlist + return options +} + +// SetHeaders : Allow user to set Headers +func (options *AddWatchlistOptions) SetHeaders(param map[string]string) *AddWatchlistOptions { + options.Headers = param + return options +} + +// Attachment : Details of an attachment. +type Attachment struct { + // Unique identifier of the attachment in database. + ID *string `json:"id,omitempty"` + + // Name of the attachment. + Filename *string `json:"filename,omitempty"` + + // Size of the attachment in bytes. + SizeInBytes *int64 `json:"size_in_bytes,omitempty"` + + // Date time of uploading. + CreatedAt *string `json:"created_at,omitempty"` + + // URL of the attachment used to download. + URL *string `json:"url,omitempty"` +} + + +// UnmarshalAttachment unmarshals an instance of Attachment from the specified map of raw messages. +func UnmarshalAttachment(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(Attachment) + err = core.UnmarshalPrimitive(m, "id", &obj.ID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "filename", &obj.Filename) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "size_in_bytes", &obj.SizeInBytes) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "created_at", &obj.CreatedAt) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "url", &obj.URL) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// AttachmentList : List of attachments in the case. +type AttachmentList struct { + // New attachments array. + Attachments []Attachment `json:"attachments,omitempty"` +} + + +// UnmarshalAttachmentList unmarshals an instance of AttachmentList from the specified map of raw messages. +func UnmarshalAttachmentList(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(AttachmentList) + err = core.UnmarshalModel(m, "attachments", &obj.Attachments, UnmarshalAttachment) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// Case : The support case. +type Case struct { + // Number/ID of the case. + Number *string `json:"number,omitempty"` + + // A short description of what the case is about. + ShortDescription *string `json:"short_description,omitempty"` + + // A full description of what the case is about. + Description *string `json:"description,omitempty"` + + // Date time of case creation in UTC. + CreatedAt *string `json:"created_at,omitempty"` + + // User info in a case. + CreatedBy *User `json:"created_by,omitempty"` + + // Date time of the last update on the case in UTC. + UpdatedAt *string `json:"updated_at,omitempty"` + + // User info in a case. + UpdatedBy *User `json:"updated_by,omitempty"` + + // Name of the console to interact with the contact. + ContactType *string `json:"contact_type,omitempty"` + + // User info in a case. + Contact *User `json:"contact,omitempty"` + + // Status of the case. + Status *string `json:"status,omitempty"` + + // The severity of the case. + Severity *float64 `json:"severity,omitempty"` + + // Support tier of the account. + SupportTier *string `json:"support_tier,omitempty"` + + // Standard reasons of resolving case. + Resolution *string `json:"resolution,omitempty"` + + // Notes of case closing. + CloseNotes *string `json:"close_notes,omitempty"` + + // EU support. + Eu *CaseEu `json:"eu,omitempty"` + + // List of users in the case watchlist. + Watchlist []User `json:"watchlist,omitempty"` + + // List of attachments/files of the case. + Attachments []Attachment `json:"attachments,omitempty"` + + // Offering details. + Offering *Offering `json:"offering,omitempty"` + + // List of attached resources. + Resources []Resource `json:"resources,omitempty"` + + // List of comments/updates sorted in chronological order. + Comments []Comment `json:"comments,omitempty"` +} + +// Constants associated with the Case.ContactType property. +// Name of the console to interact with the contact. +const ( + Case_ContactType_CloudSupportCenter = "Cloud Support Center" + Case_ContactType_ImsConsole = "IMS Console" +) + +// Constants associated with the Case.SupportTier property. +// Support tier of the account. +const ( + Case_SupportTier_Basic = "Basic" + Case_SupportTier_Free = "Free" + Case_SupportTier_Premium = "Premium" + Case_SupportTier_Standard = "Standard" +) + + +// UnmarshalCase unmarshals an instance of Case from the specified map of raw messages. +func UnmarshalCase(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(Case) + err = core.UnmarshalPrimitive(m, "number", &obj.Number) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "short_description", &obj.ShortDescription) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "description", &obj.Description) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "created_at", &obj.CreatedAt) + if err != nil { + return + } + err = core.UnmarshalModel(m, "created_by", &obj.CreatedBy, UnmarshalUser) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "updated_at", &obj.UpdatedAt) + if err != nil { + return + } + err = core.UnmarshalModel(m, "updated_by", &obj.UpdatedBy, UnmarshalUser) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "contact_type", &obj.ContactType) + if err != nil { + return + } + err = core.UnmarshalModel(m, "contact", &obj.Contact, UnmarshalUser) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "status", &obj.Status) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "severity", &obj.Severity) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "support_tier", &obj.SupportTier) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "resolution", &obj.Resolution) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "close_notes", &obj.CloseNotes) + if err != nil { + return + } + err = core.UnmarshalModel(m, "eu", &obj.Eu, UnmarshalCaseEu) + if err != nil { + return + } + err = core.UnmarshalModel(m, "watchlist", &obj.Watchlist, UnmarshalUser) + if err != nil { + return + } + err = core.UnmarshalModel(m, "attachments", &obj.Attachments, UnmarshalAttachment) + if err != nil { + return + } + err = core.UnmarshalModel(m, "offering", &obj.Offering, UnmarshalOffering) + if err != nil { + return + } + err = core.UnmarshalModel(m, "resources", &obj.Resources, UnmarshalResource) + if err != nil { + return + } + err = core.UnmarshalModel(m, "comments", &obj.Comments, UnmarshalComment) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// CaseEu : EU support. +type CaseEu struct { + // Identifying whether the case has EU Support. + Support *bool `json:"support,omitempty"` + + // Information about the data center. + DataCenter *string `json:"data_center,omitempty"` +} + + +// UnmarshalCaseEu unmarshals an instance of CaseEu from the specified map of raw messages. +func UnmarshalCaseEu(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(CaseEu) + err = core.UnmarshalPrimitive(m, "support", &obj.Support) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "data_center", &obj.DataCenter) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// CaseList : Response of a GET /cases request. +type CaseList struct { + // Total number of cases satisfying the query. + TotalCount *int64 `json:"total_count,omitempty"` + + // Container for URL pointer to related pages of cases. + First *PaginationLink `json:"first,omitempty"` + + // Container for URL pointer to related pages of cases. + Next *PaginationLink `json:"next,omitempty"` + + // Container for URL pointer to related pages of cases. + Previous *PaginationLink `json:"previous,omitempty"` + + // Container for URL pointer to related pages of cases. + Last *PaginationLink `json:"last,omitempty"` + + // List of cases. + Cases []Case `json:"cases,omitempty"` +} + + +// UnmarshalCaseList unmarshals an instance of CaseList from the specified map of raw messages. +func UnmarshalCaseList(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(CaseList) + err = core.UnmarshalPrimitive(m, "total_count", &obj.TotalCount) + if err != nil { + return + } + err = core.UnmarshalModel(m, "first", &obj.First, UnmarshalPaginationLink) + if err != nil { + return + } + err = core.UnmarshalModel(m, "next", &obj.Next, UnmarshalPaginationLink) + if err != nil { + return + } + err = core.UnmarshalModel(m, "previous", &obj.Previous, UnmarshalPaginationLink) + if err != nil { + return + } + err = core.UnmarshalModel(m, "last", &obj.Last, UnmarshalPaginationLink) + if err != nil { + return + } + err = core.UnmarshalModel(m, "cases", &obj.Cases, UnmarshalCase) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// CasePayloadEu : Specify if the case should be treated as EU regulated. Only one of the following properties is required. Call EU +// support utility endpoint to determine which property must be specified for your account. +type CasePayloadEu struct { + // indicating whether the case is EU supported. + Supported *bool `json:"supported,omitempty"` + + // If EU supported utility endpoint specifies datacenter then pass the datacenter id to mark a case as EU supported. + DataCenter *int64 `json:"data_center,omitempty"` +} + + +// UnmarshalCasePayloadEu unmarshals an instance of CasePayloadEu from the specified map of raw messages. +func UnmarshalCasePayloadEu(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(CasePayloadEu) + err = core.UnmarshalPrimitive(m, "supported", &obj.Supported) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "data_center", &obj.DataCenter) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// Comment : A comment in a case. +type Comment struct { + // The comment. + Value *string `json:"value,omitempty"` + + // Timestamp of when comment is added. + AddedAt *string `json:"added_at,omitempty"` + + // User info in a case. + AddedBy *User `json:"added_by,omitempty"` +} + + +// UnmarshalComment unmarshals an instance of Comment from the specified map of raw messages. +func UnmarshalComment(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(Comment) + err = core.UnmarshalPrimitive(m, "value", &obj.Value) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "added_at", &obj.AddedAt) + if err != nil { + return + } + err = core.UnmarshalModel(m, "added_by", &obj.AddedBy, UnmarshalUser) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// CreateCaseOptions : The CreateCase options. +type CreateCaseOptions struct { + // Case type. + Type *string `json:"type" validate:"required"` + + // Subject of the case. + Subject *string `json:"subject" validate:"required"` + + // Detailed description of the issue. + Description *string `json:"description" validate:"required"` + + // Severity of the case. Smaller values mean higher severity. + Severity *int64 `json:"severity,omitempty"` + + // Specify if the case should be treated as EU regulated. Only one of the following properties is required. Call EU + // support utility endpoint to determine which property must be specified for your account. + Eu *CasePayloadEu `json:"eu,omitempty"` + + // Offering details. + Offering *Offering `json:"offering,omitempty"` + + // List of resources to attach to case. If attaching Classic IaaS devices use type and id fields if Cloud Resource Name + // (CRN) is unavialable. Otherwise pass the resource CRN. The resource list must be consistent with the value selected + // for the resource offering. + Resources []ResourcePayload `json:"resources,omitempty"` + + // Array of user IDs to add to the watchlist. + Watchlist []User `json:"watchlist,omitempty"` + + // Invoice number of "Billing and Invoice" case type. + InvoiceNumber *string `json:"invoice_number,omitempty"` + + // Flag to indicate if case is for an Service Level Agreement (SLA) credit request. + SlaCreditRequest *bool `json:"sla_credit_request,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// Constants associated with the CreateCaseOptions.Type property. +// Case type. +const ( + CreateCaseOptions_Type_AccountAndAccess = "account_and_access" + CreateCaseOptions_Type_BillingAndInvoice = "billing_and_invoice" + CreateCaseOptions_Type_Sales = "sales" + CreateCaseOptions_Type_Technical = "technical" +) + +// NewCreateCaseOptions : Instantiate CreateCaseOptions +func (*CaseManagementV1) NewCreateCaseOptions(typeVar string, subject string, description string) *CreateCaseOptions { + return &CreateCaseOptions{ + Type: core.StringPtr(typeVar), + Subject: core.StringPtr(subject), + Description: core.StringPtr(description), + } +} + +// SetType : Allow user to set Type +func (options *CreateCaseOptions) SetType(typeVar string) *CreateCaseOptions { + options.Type = core.StringPtr(typeVar) + return options +} + +// SetSubject : Allow user to set Subject +func (options *CreateCaseOptions) SetSubject(subject string) *CreateCaseOptions { + options.Subject = core.StringPtr(subject) + return options +} + +// SetDescription : Allow user to set Description +func (options *CreateCaseOptions) SetDescription(description string) *CreateCaseOptions { + options.Description = core.StringPtr(description) + return options +} + +// SetSeverity : Allow user to set Severity +func (options *CreateCaseOptions) SetSeverity(severity int64) *CreateCaseOptions { + options.Severity = core.Int64Ptr(severity) + return options +} + +// SetEu : Allow user to set Eu +func (options *CreateCaseOptions) SetEu(eu *CasePayloadEu) *CreateCaseOptions { + options.Eu = eu + return options +} + +// SetOffering : Allow user to set Offering +func (options *CreateCaseOptions) SetOffering(offering *Offering) *CreateCaseOptions { + options.Offering = offering + return options +} + +// SetResources : Allow user to set Resources +func (options *CreateCaseOptions) SetResources(resources []ResourcePayload) *CreateCaseOptions { + options.Resources = resources + return options +} + +// SetWatchlist : Allow user to set Watchlist +func (options *CreateCaseOptions) SetWatchlist(watchlist []User) *CreateCaseOptions { + options.Watchlist = watchlist + return options +} + +// SetInvoiceNumber : Allow user to set InvoiceNumber +func (options *CreateCaseOptions) SetInvoiceNumber(invoiceNumber string) *CreateCaseOptions { + options.InvoiceNumber = core.StringPtr(invoiceNumber) + return options +} + +// SetSlaCreditRequest : Allow user to set SlaCreditRequest +func (options *CreateCaseOptions) SetSlaCreditRequest(slaCreditRequest bool) *CreateCaseOptions { + options.SlaCreditRequest = core.BoolPtr(slaCreditRequest) + return options +} + +// SetHeaders : Allow user to set Headers +func (options *CreateCaseOptions) SetHeaders(param map[string]string) *CreateCaseOptions { + options.Headers = param + return options +} + +// DeleteFileOptions : The DeleteFile options. +type DeleteFileOptions struct { + // Unique identifier of a case. + CaseNumber *string `json:"case_number" validate:"required"` + + // Unique identifier of a file. + FileID *string `json:"file_id" validate:"required"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewDeleteFileOptions : Instantiate DeleteFileOptions +func (*CaseManagementV1) NewDeleteFileOptions(caseNumber string, fileID string) *DeleteFileOptions { + return &DeleteFileOptions{ + CaseNumber: core.StringPtr(caseNumber), + FileID: core.StringPtr(fileID), + } +} + +// SetCaseNumber : Allow user to set CaseNumber +func (options *DeleteFileOptions) SetCaseNumber(caseNumber string) *DeleteFileOptions { + options.CaseNumber = core.StringPtr(caseNumber) + return options +} + +// SetFileID : Allow user to set FileID +func (options *DeleteFileOptions) SetFileID(fileID string) *DeleteFileOptions { + options.FileID = core.StringPtr(fileID) + return options +} + +// SetHeaders : Allow user to set Headers +func (options *DeleteFileOptions) SetHeaders(param map[string]string) *DeleteFileOptions { + options.Headers = param + return options +} + +// DownloadFileOptions : The DownloadFile options. +type DownloadFileOptions struct { + // Unique identifier of a case. + CaseNumber *string `json:"case_number" validate:"required"` + + // Unique identifier of a file. + FileID *string `json:"file_id" validate:"required"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewDownloadFileOptions : Instantiate DownloadFileOptions +func (*CaseManagementV1) NewDownloadFileOptions(caseNumber string, fileID string) *DownloadFileOptions { + return &DownloadFileOptions{ + CaseNumber: core.StringPtr(caseNumber), + FileID: core.StringPtr(fileID), + } +} + +// SetCaseNumber : Allow user to set CaseNumber +func (options *DownloadFileOptions) SetCaseNumber(caseNumber string) *DownloadFileOptions { + options.CaseNumber = core.StringPtr(caseNumber) + return options +} + +// SetFileID : Allow user to set FileID +func (options *DownloadFileOptions) SetFileID(fileID string) *DownloadFileOptions { + options.FileID = core.StringPtr(fileID) + return options +} + +// SetHeaders : Allow user to set Headers +func (options *DownloadFileOptions) SetHeaders(param map[string]string) *DownloadFileOptions { + options.Headers = param + return options +} + +// FileWithMetadata : A file with its associated metadata. +type FileWithMetadata struct { + // The data / content for the file. + Data io.ReadCloser `json:"data" validate:"required"` + + // The filename of the file. + Filename *string `json:"filename,omitempty"` + + // The content type of the file. + ContentType *string `json:"content_type,omitempty"` +} + + +// NewFileWithMetadata : Instantiate FileWithMetadata (Generic Model Constructor) +func (*CaseManagementV1) NewFileWithMetadata(data io.ReadCloser) (model *FileWithMetadata, err error) { + model = &FileWithMetadata{ + Data: data, + } + err = core.ValidateStruct(model, "required parameters") + return +} + +// UnmarshalFileWithMetadata unmarshals an instance of FileWithMetadata from the specified map of raw messages. +func UnmarshalFileWithMetadata(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(FileWithMetadata) + err = core.UnmarshalPrimitive(m, "data", &obj.Data) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "filename", &obj.Filename) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "content_type", &obj.ContentType) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// GetCaseOptions : The GetCase options. +type GetCaseOptions struct { + // Unique identifier of a case. + CaseNumber *string `json:"case_number" validate:"required"` + + // Seleted fields of interest instead of the entire case information. + Fields []string `json:"fields,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// Constants associated with the GetCaseOptions.Fields property. +const ( + GetCaseOptions_Fields_AgentCloseOnly = "agent_close_only" + GetCaseOptions_Fields_Attachments = "attachments" + GetCaseOptions_Fields_CloseNotes = "close_notes" + GetCaseOptions_Fields_Comments = "comments" + GetCaseOptions_Fields_Contact = "contact" + GetCaseOptions_Fields_ContactType = "contact_type" + GetCaseOptions_Fields_CreatedAt = "created_at" + GetCaseOptions_Fields_CreatedBy = "created_by" + GetCaseOptions_Fields_Description = "description" + GetCaseOptions_Fields_Eu = "eu" + GetCaseOptions_Fields_InvoiceNumber = "invoice_number" + GetCaseOptions_Fields_Number = "number" + GetCaseOptions_Fields_Offering = "offering" + GetCaseOptions_Fields_Resolution = "resolution" + GetCaseOptions_Fields_Resources = "resources" + GetCaseOptions_Fields_Severity = "severity" + GetCaseOptions_Fields_ShortDescription = "short_description" + GetCaseOptions_Fields_Status = "status" + GetCaseOptions_Fields_SupportTier = "support_tier" + GetCaseOptions_Fields_UpdatedAt = "updated_at" + GetCaseOptions_Fields_UpdatedBy = "updated_by" + GetCaseOptions_Fields_Watchlist = "watchlist" +) + +// NewGetCaseOptions : Instantiate GetCaseOptions +func (*CaseManagementV1) NewGetCaseOptions(caseNumber string) *GetCaseOptions { + return &GetCaseOptions{ + CaseNumber: core.StringPtr(caseNumber), + } +} + +// SetCaseNumber : Allow user to set CaseNumber +func (options *GetCaseOptions) SetCaseNumber(caseNumber string) *GetCaseOptions { + options.CaseNumber = core.StringPtr(caseNumber) + return options +} + +// SetFields : Allow user to set Fields +func (options *GetCaseOptions) SetFields(fields []string) *GetCaseOptions { + options.Fields = fields + return options +} + +// SetHeaders : Allow user to set Headers +func (options *GetCaseOptions) SetHeaders(param map[string]string) *GetCaseOptions { + options.Headers = param + return options +} + +// GetCasesOptions : The GetCases options. +type GetCasesOptions struct { + // Number of cases should be skipped. + Offset *int64 `json:"offset,omitempty"` + + // Number of cases should be returned. + Limit *int64 `json:"limit,omitempty"` + + // String that a case might contain. + Search *string `json:"search,omitempty"` + + // Sort field and direction. If omitted, default to descending of updated date. Prefix "~" signifies sort in + // descending. + Sort *string `json:"sort,omitempty"` + + // Case status filter. + Status []string `json:"status,omitempty"` + + // Seleted fields of interest instead of the entire case information. + Fields []string `json:"fields,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// Constants associated with the GetCasesOptions.Status property. +const ( + GetCasesOptions_Status_Closed = "closed" + GetCasesOptions_Status_InProgress = "in_progress" + GetCasesOptions_Status_New = "new" + GetCasesOptions_Status_ResolutionProvided = "resolution_provided" + GetCasesOptions_Status_Resolved = "resolved" + GetCasesOptions_Status_WaitingOnClient = "waiting_on_client" +) + +// Constants associated with the GetCasesOptions.Fields property. +const ( + GetCasesOptions_Fields_AgentCloseOnly = "agent_close_only" + GetCasesOptions_Fields_Attachments = "attachments" + GetCasesOptions_Fields_CloseNotes = "close_notes" + GetCasesOptions_Fields_Comments = "comments" + GetCasesOptions_Fields_Contact = "contact" + GetCasesOptions_Fields_ContactType = "contact_type" + GetCasesOptions_Fields_CreatedAt = "created_at" + GetCasesOptions_Fields_CreatedBy = "created_by" + GetCasesOptions_Fields_Description = "description" + GetCasesOptions_Fields_Eu = "eu" + GetCasesOptions_Fields_InvoiceNumber = "invoice_number" + GetCasesOptions_Fields_Number = "number" + GetCasesOptions_Fields_Offering = "offering" + GetCasesOptions_Fields_Resolution = "resolution" + GetCasesOptions_Fields_Resources = "resources" + GetCasesOptions_Fields_Severity = "severity" + GetCasesOptions_Fields_ShortDescription = "short_description" + GetCasesOptions_Fields_Status = "status" + GetCasesOptions_Fields_SupportTier = "support_tier" + GetCasesOptions_Fields_UpdatedAt = "updated_at" + GetCasesOptions_Fields_UpdatedBy = "updated_by" + GetCasesOptions_Fields_Watchlist = "watchlist" +) + +// NewGetCasesOptions : Instantiate GetCasesOptions +func (*CaseManagementV1) NewGetCasesOptions() *GetCasesOptions { + return &GetCasesOptions{} +} + +// SetOffset : Allow user to set Offset +func (options *GetCasesOptions) SetOffset(offset int64) *GetCasesOptions { + options.Offset = core.Int64Ptr(offset) + return options +} + +// SetLimit : Allow user to set Limit +func (options *GetCasesOptions) SetLimit(limit int64) *GetCasesOptions { + options.Limit = core.Int64Ptr(limit) + return options +} + +// SetSearch : Allow user to set Search +func (options *GetCasesOptions) SetSearch(search string) *GetCasesOptions { + options.Search = core.StringPtr(search) + return options +} + +// SetSort : Allow user to set Sort +func (options *GetCasesOptions) SetSort(sort string) *GetCasesOptions { + options.Sort = core.StringPtr(sort) + return options +} + +// SetStatus : Allow user to set Status +func (options *GetCasesOptions) SetStatus(status []string) *GetCasesOptions { + options.Status = status + return options +} + +// SetFields : Allow user to set Fields +func (options *GetCasesOptions) SetFields(fields []string) *GetCasesOptions { + options.Fields = fields + return options +} + +// SetHeaders : Allow user to set Headers +func (options *GetCasesOptions) SetHeaders(param map[string]string) *GetCasesOptions { + options.Headers = param + return options +} + +// Offering : Offering details. +type Offering struct { + // Name of the offering. + Name *string `json:"name" validate:"required"` + + // Offering type. + Type *OfferingType `json:"type" validate:"required"` +} + + +// NewOffering : Instantiate Offering (Generic Model Constructor) +func (*CaseManagementV1) NewOffering(name string, typeVar *OfferingType) (model *Offering, err error) { + model = &Offering{ + Name: core.StringPtr(name), + Type: typeVar, + } + err = core.ValidateStruct(model, "required parameters") + return +} + +// UnmarshalOffering unmarshals an instance of Offering from the specified map of raw messages. +func UnmarshalOffering(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(Offering) + err = core.UnmarshalPrimitive(m, "name", &obj.Name) + if err != nil { + return + } + err = core.UnmarshalModel(m, "type", &obj.Type, UnmarshalOfferingType) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// OfferingType : Offering type. +type OfferingType struct { + // Offering type group. "crn_service_name" is strongly prefered over "category" as the latter is legacy and will be + // deprecated in the future. + Group *string `json:"group" validate:"required"` + + // CRN service name of the offering. + Key *string `json:"key" validate:"required"` + + // Optional. Platform kind of the offering. + Kind *string `json:"kind,omitempty"` + + // Offering id in the catalog. This alone is enough to identify the offering. + ID *string `json:"id,omitempty"` +} + +// Constants associated with the OfferingType.Group property. +// Offering type group. "crn_service_name" is strongly prefered over "category" as the latter is legacy and will be +// deprecated in the future. +const ( + OfferingType_Group_Category = "category" + OfferingType_Group_CrnServiceName = "crn_service_name" +) + + +// NewOfferingType : Instantiate OfferingType (Generic Model Constructor) +func (*CaseManagementV1) NewOfferingType(group string, key string) (model *OfferingType, err error) { + model = &OfferingType{ + Group: core.StringPtr(group), + Key: core.StringPtr(key), + } + err = core.ValidateStruct(model, "required parameters") + return +} + +// UnmarshalOfferingType unmarshals an instance of OfferingType from the specified map of raw messages. +func UnmarshalOfferingType(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(OfferingType) + err = core.UnmarshalPrimitive(m, "group", &obj.Group) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "key", &obj.Key) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "kind", &obj.Kind) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "id", &obj.ID) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// PaginationLink : Container for URL pointer to related pages of cases. +type PaginationLink struct { + // URL to related pages of cases. + Href *string `json:"href,omitempty"` +} + + +// UnmarshalPaginationLink unmarshals an instance of PaginationLink from the specified map of raw messages. +func UnmarshalPaginationLink(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(PaginationLink) + err = core.UnmarshalPrimitive(m, "href", &obj.Href) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// RemoveWatchlistOptions : The RemoveWatchlist options. +type RemoveWatchlistOptions struct { + // Unique identifier of a case. + CaseNumber *string `json:"case_number" validate:"required"` + + // Array of user ID objects. + Watchlist []User `json:"watchlist,omitempty"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewRemoveWatchlistOptions : Instantiate RemoveWatchlistOptions +func (*CaseManagementV1) NewRemoveWatchlistOptions(caseNumber string) *RemoveWatchlistOptions { + return &RemoveWatchlistOptions{ + CaseNumber: core.StringPtr(caseNumber), + } +} + +// SetCaseNumber : Allow user to set CaseNumber +func (options *RemoveWatchlistOptions) SetCaseNumber(caseNumber string) *RemoveWatchlistOptions { + options.CaseNumber = core.StringPtr(caseNumber) + return options +} + +// SetWatchlist : Allow user to set Watchlist +func (options *RemoveWatchlistOptions) SetWatchlist(watchlist []User) *RemoveWatchlistOptions { + options.Watchlist = watchlist + return options +} + +// SetHeaders : Allow user to set Headers +func (options *RemoveWatchlistOptions) SetHeaders(param map[string]string) *RemoveWatchlistOptions { + options.Headers = param + return options +} + +// Resource : A resource record of a case. +type Resource struct { + // ID of the resource. + Crn *string `json:"crn,omitempty"` + + // Name of the resource. + Name *string `json:"name,omitempty"` + + // Type of resource. + Type *string `json:"type,omitempty"` + + // URL of resource. + URL *string `json:"url,omitempty"` + + // Note about resource. + Note *string `json:"note,omitempty"` +} + + +// UnmarshalResource unmarshals an instance of Resource from the specified map of raw messages. +func UnmarshalResource(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(Resource) + 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, "type", &obj.Type) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "url", &obj.URL) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "note", &obj.Note) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ResourcePayload : Payload to add a resource to a case. +type ResourcePayload struct { + // Cloud Resource Name of the resource. + Crn *string `json:"crn,omitempty"` + + // Only used to attach Classic IaaS devices which have no CRN. + Type *string `json:"type,omitempty"` + + // Only used to attach Classic IaaS devices which have no CRN. Id of Classic IaaS device. This is deprecated in favor + // of the crn field. + ID *float64 `json:"id,omitempty"` + + // A note about this resource. + Note *string `json:"note,omitempty"` +} + + +// UnmarshalResourcePayload unmarshals an instance of ResourcePayload from the specified map of raw messages. +func UnmarshalResourcePayload(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ResourcePayload) + err = core.UnmarshalPrimitive(m, "crn", &obj.Crn) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "type", &obj.Type) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "id", &obj.ID) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "note", &obj.Note) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// StatusPayload : Payload to update status of the case. +// Models which "extend" this model: +// - ResolvePayload +// - UnresolvePayload +// - AcceptPayload +type StatusPayload struct { + // action to perform on the case. + Action *string `json:"action" validate:"required"` + + // comment of resolution. + Comment *string `json:"comment,omitempty"` + + // * 1: Client error + // * 2: Defect found with Component/Service + // * 3: Documentation Error + // * 4: Sollution found in forums + // * 5: Solution found in public Documentation + // * 6: Solution no longer required + // * 7: Solution provided by IBM outside of support case + // * 8: Solution provided by IBM support engineer. + ResolutionCode *int64 `json:"resolution_code,omitempty"` +} + +// Constants associated with the StatusPayload.Action property. +// action to perform on the case. +const ( + StatusPayload_Action_Accept = "accept" + StatusPayload_Action_Resolve = "resolve" + StatusPayload_Action_Unresolve = "unresolve" +) + +func (*StatusPayload) isaStatusPayload() bool { + return true +} + +type StatusPayloadIntf interface { + isaStatusPayload() bool +} + +// UnmarshalStatusPayload unmarshals an instance of StatusPayload from the specified map of raw messages. +func UnmarshalStatusPayload(m map[string]json.RawMessage, result interface{}) (err error) { + // Retrieve discriminator value to determine correct "subclass". + var discValue string + err = core.UnmarshalPrimitive(m, "action", &discValue) + if err != nil { + err = fmt.Errorf("error unmarshalling discriminator property 'action': %s", err.Error()) + return + } + if discValue == "" { + err = fmt.Errorf("required discriminator property 'action' not found in JSON object") + return + } + if discValue == "resolve" { + err = core.UnmarshalModel(m, "", result, UnmarshalResolvePayload) + } else if discValue == "unresolve" { + err = core.UnmarshalModel(m, "", result, UnmarshalUnresolvePayload) + } else if discValue == "accept" { + err = core.UnmarshalModel(m, "", result, UnmarshalAcceptPayload) + } else { + err = fmt.Errorf("unrecognized value for discriminator property 'action': %s", discValue) + } + return +} + +// UpdateCaseStatusOptions : The UpdateCaseStatus options. +type UpdateCaseStatusOptions struct { + // Unique identifier of a case. + CaseNumber *string `json:"case_number" validate:"required"` + + // Payload to update status of the case. + StatusPayload StatusPayloadIntf `json:"StatusPayload" validate:"required"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewUpdateCaseStatusOptions : Instantiate UpdateCaseStatusOptions +func (*CaseManagementV1) NewUpdateCaseStatusOptions(caseNumber string, statusPayload StatusPayloadIntf) *UpdateCaseStatusOptions { + return &UpdateCaseStatusOptions{ + CaseNumber: core.StringPtr(caseNumber), + StatusPayload: statusPayload, + } +} + +// SetCaseNumber : Allow user to set CaseNumber +func (options *UpdateCaseStatusOptions) SetCaseNumber(caseNumber string) *UpdateCaseStatusOptions { + options.CaseNumber = core.StringPtr(caseNumber) + return options +} + +// SetStatusPayload : Allow user to set StatusPayload +func (options *UpdateCaseStatusOptions) SetStatusPayload(statusPayload StatusPayloadIntf) *UpdateCaseStatusOptions { + options.StatusPayload = statusPayload + return options +} + +// SetHeaders : Allow user to set Headers +func (options *UpdateCaseStatusOptions) SetHeaders(param map[string]string) *UpdateCaseStatusOptions { + options.Headers = param + return options +} + +// UploadFileOptions : The UploadFile options. +type UploadFileOptions struct { + // Unique identifier of a case. + CaseNumber *string `json:"case_number" validate:"required"` + + // file of supported types, 8MB in size limit. + File []FileWithMetadata `json:"file" validate:"required"` + + // Allows users to set headers on API requests + Headers map[string]string +} + +// NewUploadFileOptions : Instantiate UploadFileOptions +func (*CaseManagementV1) NewUploadFileOptions(caseNumber string, file []FileWithMetadata) *UploadFileOptions { + return &UploadFileOptions{ + CaseNumber: core.StringPtr(caseNumber), + File: file, + } +} + +// SetCaseNumber : Allow user to set CaseNumber +func (options *UploadFileOptions) SetCaseNumber(caseNumber string) *UploadFileOptions { + options.CaseNumber = core.StringPtr(caseNumber) + return options +} + +// SetFile : Allow user to set File +func (options *UploadFileOptions) SetFile(file []FileWithMetadata) *UploadFileOptions { + options.File = file + return options +} + +// SetHeaders : Allow user to set Headers +func (options *UploadFileOptions) SetHeaders(param map[string]string) *UploadFileOptions { + options.Headers = param + return options +} + +// User : User info in a case. +type User struct { + // Full name of the user. + Name *string `json:"name,omitempty"` + + // the ID realm. + Realm *string `json:"realm" validate:"required"` + + // unique user ID in the realm specified by the type. + UserID *string `json:"user_id" validate:"required"` +} + +// Constants associated with the User.Realm property. +// the ID realm. +const ( + User_Realm_Bss = "BSS" + User_Realm_Ibmid = "IBMid" + User_Realm_Sl = "SL" +) + + +// NewUser : Instantiate User (Generic Model Constructor) +func (*CaseManagementV1) NewUser(realm string, userID string) (model *User, err error) { + model = &User{ + Realm: core.StringPtr(realm), + UserID: core.StringPtr(userID), + } + err = core.ValidateStruct(model, "required parameters") + return +} + +// UnmarshalUser unmarshals an instance of User from the specified map of raw messages. +func UnmarshalUser(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(User) + err = core.UnmarshalPrimitive(m, "name", &obj.Name) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "realm", &obj.Realm) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "user_id", &obj.UserID) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// Watchlist : Payload to add/remove users to/from the case watchlist. +type Watchlist struct { + // Array of user ID objects. + Watchlist []User `json:"watchlist,omitempty"` +} + + +// UnmarshalWatchlist unmarshals an instance of Watchlist from the specified map of raw messages. +func UnmarshalWatchlist(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(Watchlist) + err = core.UnmarshalModel(m, "watchlist", &obj.Watchlist, UnmarshalUser) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// WatchlistAddResponse : Response of a request adding to watchlist. +type WatchlistAddResponse struct { + // List of added user. + Added []User `json:"added,omitempty"` + + // List of failed to add user. + Failed []User `json:"failed,omitempty"` +} + + +// UnmarshalWatchlistAddResponse unmarshals an instance of WatchlistAddResponse from the specified map of raw messages. +func UnmarshalWatchlistAddResponse(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(WatchlistAddResponse) + err = core.UnmarshalModel(m, "added", &obj.Added, UnmarshalUser) + if err != nil { + return + } + err = core.UnmarshalModel(m, "failed", &obj.Failed, UnmarshalUser) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// AcceptPayload : Payload to accept the proposed resolution of the case. +// This model "extends" StatusPayload +type AcceptPayload struct { + // action to perform on the case. + Action *string `json:"action" validate:"required"` + + // Comment about accepting the proposed resolution. + Comment *string `json:"comment,omitempty"` +} + +// Constants associated with the AcceptPayload.Action property. +// action to perform on the case. +const ( + AcceptPayload_Action_Accept = "accept" + AcceptPayload_Action_Resolve = "resolve" + AcceptPayload_Action_Unresolve = "unresolve" +) + + +// NewAcceptPayload : Instantiate AcceptPayload (Generic Model Constructor) +func (*CaseManagementV1) NewAcceptPayload(action string) (model *AcceptPayload, err error) { + model = &AcceptPayload{ + Action: core.StringPtr(action), + } + err = core.ValidateStruct(model, "required parameters") + return +} + +func (*AcceptPayload) isaStatusPayload() bool { + return true +} + +// UnmarshalAcceptPayload unmarshals an instance of AcceptPayload from the specified map of raw messages. +func UnmarshalAcceptPayload(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(AcceptPayload) + err = core.UnmarshalPrimitive(m, "action", &obj.Action) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "comment", &obj.Comment) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// ResolvePayload : Payload to resolve the case. +// This model "extends" StatusPayload +type ResolvePayload struct { + // action to perform on the case. + Action *string `json:"action" validate:"required"` + + // comment of resolution. + Comment *string `json:"comment,omitempty"` + + // * 1: Client error + // * 2: Defect found with Component/Service + // * 3: Documentation Error + // * 4: Sollution found in forums + // * 5: Solution found in public Documentation + // * 6: Solution no longer required + // * 7: Solution provided by IBM outside of support case + // * 8: Solution provided by IBM support engineer. + ResolutionCode *int64 `json:"resolution_code" validate:"required"` +} + +// Constants associated with the ResolvePayload.Action property. +// action to perform on the case. +const ( + ResolvePayload_Action_Accept = "accept" + ResolvePayload_Action_Resolve = "resolve" + ResolvePayload_Action_Unresolve = "unresolve" +) + + +// NewResolvePayload : Instantiate ResolvePayload (Generic Model Constructor) +func (*CaseManagementV1) NewResolvePayload(action string, resolutionCode int64) (model *ResolvePayload, err error) { + model = &ResolvePayload{ + Action: core.StringPtr(action), + ResolutionCode: core.Int64Ptr(resolutionCode), + } + err = core.ValidateStruct(model, "required parameters") + return +} + +func (*ResolvePayload) isaStatusPayload() bool { + return true +} + +// UnmarshalResolvePayload unmarshals an instance of ResolvePayload from the specified map of raw messages. +func UnmarshalResolvePayload(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(ResolvePayload) + err = core.UnmarshalPrimitive(m, "action", &obj.Action) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "comment", &obj.Comment) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "resolution_code", &obj.ResolutionCode) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + +// UnresolvePayload : Payload to unresolve the case. +// This model "extends" StatusPayload +type UnresolvePayload struct { + // action to perform on the case. + Action *string `json:"action" validate:"required"` + + // Comment why the case should be unresolved. + Comment *string `json:"comment" validate:"required"` +} + +// Constants associated with the UnresolvePayload.Action property. +// action to perform on the case. +const ( + UnresolvePayload_Action_Accept = "accept" + UnresolvePayload_Action_Resolve = "resolve" + UnresolvePayload_Action_Unresolve = "unresolve" +) + + +// NewUnresolvePayload : Instantiate UnresolvePayload (Generic Model Constructor) +func (*CaseManagementV1) NewUnresolvePayload(action string, comment string) (model *UnresolvePayload, err error) { + model = &UnresolvePayload{ + Action: core.StringPtr(action), + Comment: core.StringPtr(comment), + } + err = core.ValidateStruct(model, "required parameters") + return +} + +func (*UnresolvePayload) isaStatusPayload() bool { + return true +} + +// UnmarshalUnresolvePayload unmarshals an instance of UnresolvePayload from the specified map of raw messages. +func UnmarshalUnresolvePayload(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(UnresolvePayload) + err = core.UnmarshalPrimitive(m, "action", &obj.Action) + if err != nil { + return + } + err = core.UnmarshalPrimitive(m, "comment", &obj.Comment) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} diff --git a/casemanagementv1/case_management_v1_integration_test.go b/casemanagementv1/case_management_v1_integration_test.go new file mode 100644 index 00000000..029b3ac3 --- /dev/null +++ b/casemanagementv1/case_management_v1_integration_test.go @@ -0,0 +1,373 @@ +// +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 casemanagementv1_test + +import ( + "fmt" + "io/ioutil" + "os" + "strings" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + "github.com/IBM/go-sdk-core/v4/core" + "github.com/IBM/platform-services-go-sdk/casemanagementv1" +) + +const externalConfigFile = "../case_management.env" + +var ( + service *casemanagementv1.CaseManagementV1 + err error + + configLoaded bool = false + + caseNumber string + commentValue = "Test comment" + + offeringType, _ = service.NewOfferingType(casemanagementv1.OfferingType_Group_CrnServiceName, "cloud-object-storage") + offeringPayload, _ = service.NewOffering("Cloud Object Storage", offeringType) + + resourcePayload = []casemanagementv1.ResourcePayload{casemanagementv1.ResourcePayload{ + Crn: core.StringPtr("crn:v1:staging:public:cloud-object-storage:global:a/19c52e57800c4d8bb9aefc66b3e49755:61848e72-6ba6-415e-84e2-91f3915e194d::"), + }} + + watchlistPayload = casemanagementv1.Watchlist{ + Watchlist: []casemanagementv1.User{ + casemanagementv1.User{ + Realm: core.StringPtr("IBMid"), + UserID: core.StringPtr("ashwini.pc@ibm.com"), + }, + casemanagementv1.User{ + Realm: core.StringPtr("IBMid"), + UserID: core.StringPtr("bqegarci@us.ibm.com"), + }, + }, + } +) + +func shouldSkipTest() { + if !configLoaded { + Skip("External configuration is not available, skipping...") + } +} + +var _ = Describe("Case Management - Integration Tests", func() { + It("Successfully load the configuration", func() { + if _, fileErr := os.Stat(externalConfigFile); fileErr == nil { + os.Setenv("IBM_CREDENTIALS_FILE", externalConfigFile) + config, _ := core.GetServiceProperties(casemanagementv1.DefaultServiceName) + if len(config) > 0 { + configLoaded = true + } + } + + if !configLoaded { + Skip("External configuration could not be loaded, skipping...") + } + }) + + It(`Successfully created CaseManagementV1 service instance`, func() { + shouldSkipTest() + + service, err = casemanagementv1.NewCaseManagementV1UsingExternalConfig( + &casemanagementv1.CaseManagementV1Options{}, + ) + + Expect(err).To(BeNil()) + Expect(service).ToNot(BeNil()) + + fmt.Printf("\nService URL: %s\n", service.Service.GetServiceURL()) + }) + + Describe("Create a case", func() { + var options *casemanagementv1.CreateCaseOptions + BeforeEach(func() { + options = service.NewCreateCaseOptions("technical", "Test case for Go SDK", "Test case for Go SDK") + options.SetSeverity(4) + options.SetOffering(offeringPayload) + }) + + It("Successfully created a technical case", func() { + shouldSkipTest() + + result, detailedResponse, err := service.CreateCase(options) + Expect(err).To(BeNil()) + Expect(detailedResponse.StatusCode).To(Equal(200)) + Expect(*result.Number).To(Not(BeNil())) + Expect(*result.ShortDescription).To(Equal(*options.Subject)) + Expect(*result.Description).To(Equal(*options.Description)) + Expect(int64(*result.Severity)).To(Equal(*options.Severity)) + + caseNumber = *result.Number + + fmt.Printf("\nCase number: %s\n", caseNumber) + }) + + It("Bad payload used to create a case", func() { + shouldSkipTest() + options.SetType("invalid_type") + options.Severity = nil + options.Offering = nil + _, detailedResponse, err := service.CreateCase(options) + Expect(err).To(Not(BeNil())) + Expect(detailedResponse.StatusCode).To(Not(Equal(200))) + }) + }) + + Describe("Get Cases", func() { + var options *casemanagementv1.GetCasesOptions + + BeforeEach(func() { + options = service.NewGetCasesOptions() + }) + + It("Successfully got cases with default params", func() { + shouldSkipTest() + + result, detailedResponse, err := service.GetCases(options) + Expect(err).To(BeNil()) + Expect(detailedResponse.StatusCode).To(Equal(200)) + Expect(*result.TotalCount).To(Not(BeNil())) + Expect(*result.First).To(Not(BeNil())) + Expect(*result.Next).To(Not(BeNil())) + Expect(*result.Last).To(Not(BeNil())) + Expect(result.Cases).To(Not(BeNil())) + }) + + It("Successfully got cases with non-default params", func() { + shouldSkipTest() + + options.SetOffset(10) + options.SetLimit(20) + // options.SetSort() + options.SetFields([]string{ + casemanagementv1.GetCasesOptions_Fields_Number, + casemanagementv1.GetCasesOptions_Fields_Comments, + casemanagementv1.GetCasesOptions_Fields_CreatedAt, + }) + + result, detailedResponse, err := service.GetCases(options) + Expect(err).To(BeNil()) + Expect(detailedResponse.StatusCode).To(Equal(200)) + Expect(*result.TotalCount).To(Not(BeNil())) + Expect(*result.First).To(Not(BeNil())) + Expect(*result.Next).To(Not(BeNil())) + Expect(*result.Last).To(Not(BeNil())) + Expect(result.Cases).To(Not(BeNil())) + + testCase := result.Cases[0] + Expect(testCase).To(Not(BeNil())) + Expect(testCase.Number).To(Not(BeNil())) + Expect(testCase.Comments).To(Not(BeNil())) + Expect(testCase.CreatedAt).To(Not(BeNil())) + + // extra properties should be excluded in the response + Expect(testCase.Severity).To(BeNil()) + Expect(testCase.Contact).To(BeNil()) + }) + + It("Failed to get cases with bad params", func() { + shouldSkipTest() + + options.SetFields([]string{"invalid_fields"}) + + _, detailedResponse, err := service.GetCases(options) + Expect(err).To(Not(BeNil())) + Expect(detailedResponse.StatusCode).To(Not(Equal(200))) + }) + }) + + Describe("Get a specific case", func() { + var options *casemanagementv1.GetCaseOptions + + BeforeEach(func() { + options = service.NewGetCaseOptions(caseNumber) + }) + + It("Successfully got a case with default params", func() { + shouldSkipTest() + + result, detailedResponse, err := service.GetCase(options) + + Expect(err).To(BeNil()) + Expect(detailedResponse.StatusCode).To(Equal(200)) + Expect(*result.Number).To(Equal(caseNumber)) + }) + + It("Successfully got a case with field filtering", func() { + shouldSkipTest() + + options.SetFields([]string{"number", "severity"}) + result, detailedResponse, err := service.GetCase(options) + + Expect(err).To(BeNil()) + Expect(detailedResponse.StatusCode).To(Equal(200)) + Expect(*result.Number).To(Equal(caseNumber)) + Expect(result.Severity).To(Not(BeNil())) + Expect(result.Contact).To(BeNil()) + }) + + It("Failed to get a case with bad params", func() { + shouldSkipTest() + + options.SetFields([]string{"invalid_field"}) + _, detailedResponse, err := service.GetCase(options) + Expect(err).To(Not(BeNil())) + Expect(detailedResponse.StatusCode).To(Not(Equal(200))) + }) + }) + + Describe("Add comment", func() { + var options *casemanagementv1.AddCommentOptions + + BeforeEach(func() { + options = service.NewAddCommentOptions(caseNumber, commentValue) + }) + + // BeforeEach(func() { + // }) + It("Successfully added a comment to a case", func() { + shouldSkipTest() + result, detailedResponse, err := service.AddComment(options) + + Expect(err).To(BeNil()) + Expect(detailedResponse.StatusCode).To(Equal(200)) + Expect(*result.Value).To(Equal(commentValue)) + Expect(result.AddedAt).To(Not(BeNil())) + Expect(result.AddedBy).To(Not(BeNil())) + }) + }) + + Describe("Add watchlist", func() { + var options *casemanagementv1.AddWatchlistOptions + + BeforeEach(func() { + options = service.NewAddWatchlistOptions(caseNumber) + options.SetWatchlist(watchlistPayload.Watchlist) + }) + + It("Successfully added users to case watchlist", func() { + shouldSkipTest() + result, detailedResponse, err := service.AddWatchlist(options) + + Expect(err).To((BeNil())) + Expect(detailedResponse.StatusCode).To(Equal(200)) + Expect(len(result.Added)).To(Equal(len(watchlistPayload.Watchlist))) + }) + }) + + Describe("Remove watchlist", func() { + var options *casemanagementv1.RemoveWatchlistOptions + BeforeEach(func() { + options = service.NewRemoveWatchlistOptions(caseNumber) + options.SetWatchlist(watchlistPayload.Watchlist) + }) + + It("Successfully removed users from case watchlist", func() { + shouldSkipTest() + _, detailedResponse, err := service.RemoveWatchlist(options) + + Expect(err).To((BeNil())) + Expect(detailedResponse.StatusCode).To(Equal(200)) + }) + }) + + Describe("Update status", func() { + + It("Succefully resolve a case", func() { + shouldSkipTest() + resolvePayload, _ := service.NewResolvePayload(casemanagementv1.ResolvePayload_Action_Resolve, 1) + options := service.NewUpdateCaseStatusOptions(caseNumber, resolvePayload) + + result, detailedResponse, err := service.UpdateCaseStatus(options) + + Expect(err).To(BeNil()) + Expect(detailedResponse.StatusCode).To(Equal(200)) + Expect(*result.Status).To(Equal("Resolved")) + }) + + It("Succefully unresolve a case", func() { + shouldSkipTest() + unresolvePayload, _ := service.NewUnresolvePayload(casemanagementv1.UnresolvePayload_Action_Unresolve, "Test unresolve") + options := service.NewUpdateCaseStatusOptions(caseNumber, unresolvePayload) + + result, detailedResponse, err := service.UpdateCaseStatus(options) + + Expect(err).To(BeNil()) + Expect(detailedResponse.StatusCode).To(Equal(200)) + Expect(*result.Status).To(Equal("In Progress")) + }) + }) + + Describe("Modify attachments", func() { + var fileID string + + It("Successfully uploaded file", func() { + shouldSkipTest() + fileInput, _ := service.NewFileWithMetadata(ioutil.NopCloser(strings.NewReader("hello world"))) + fileInput.Filename = core.StringPtr("GO SDK test file.png") + fileInput.ContentType = core.StringPtr("application/octet-stream") + + filePayload := []casemanagementv1.FileWithMetadata{*fileInput} + options := service.NewUploadFileOptions(caseNumber, filePayload) + + result, detailedResponse, err := service.UploadFile(options) + + Expect(err).To(BeNil()) + Expect(detailedResponse.StatusCode).To(Equal(200)) + Expect(*result.ID).To(Not(BeNil())) + Expect(*result.Filename).To(Equal(*fileInput.Filename)) + + // store file id so that we could remove it in the next test + fileID = *result.ID + }) + + It("Successfully deleted file", func() { + shouldSkipTest() + + if fileID == "" { + Skip("Case does not have target file to remove. Skipping ....") + } + + options := service.NewDeleteFileOptions(caseNumber, fileID) + + _, detailedResponse, err := service.DeleteFile(options) + + Expect(err).To((BeNil())) + Expect(detailedResponse.StatusCode).To((Equal(200))) + }) + }) + + Describe("Add Resource", func() { + It("Successfully added a resource", func() { + shouldSkipTest() + crn := *resourcePayload[0].Crn + options := service.NewAddResourceOptions(caseNumber) + options.SetCrn(crn) + + result, detailedResponse, err := service.AddResource(options) + + Expect(err).To(BeNil()) + Expect(detailedResponse.StatusCode).To((Equal(200))) + Expect(*result.Crn).To(Equal(crn)) + }) + }) +}) diff --git a/casemanagementv1/case_management_v1_suite_test.go b/casemanagementv1/case_management_v1_suite_test.go new file mode 100644 index 00000000..2e471b74 --- /dev/null +++ b/casemanagementv1/case_management_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 casemanagementv1_test + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "testing" +) + +func TestCaseManagementV1(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "CaseManagementV1 Suite") +} diff --git a/casemanagementv1/case_management_v1_test.go b/casemanagementv1/case_management_v1_test.go new file mode 100644 index 00000000..5f8349fc --- /dev/null +++ b/casemanagementv1/case_management_v1_test.go @@ -0,0 +1,1939 @@ +/** + * (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 casemanagementv1_test + +import ( + "bytes" + "fmt" + "github.com/IBM/go-sdk-core/v4/core" + "github.com/IBM/platform-services-go-sdk/casemanagementv1" + "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(`CaseManagementV1`, func() { + var testServer *httptest.Server + Describe(`Service constructor tests`, func() { + It(`Instantiate service client`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testService).ToNot(BeNil()) + Expect(testServiceErr).To(BeNil()) + }) + It(`Instantiate service client with error: Invalid URL`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: "{BAD_URL_STRING", + }) + Expect(testService).To(BeNil()) + Expect(testServiceErr).ToNot(BeNil()) + }) + It(`Instantiate service client with error: Invalid Auth`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: "https://casemanagementv1/api", + Authenticator: &core.BasicAuthenticator{ + Username: "", + Password: "", + }, + }) + Expect(testService).To(BeNil()) + Expect(testServiceErr).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{ + "CASE_MANAGEMENT_URL": "https://casemanagementv1/api", + "CASE_MANAGEMENT_AUTH_TYPE": "noauth", + } + + It(`Create service client using external config successfully`, func() { + SetTestEnvironment(testEnvironment) + testService, testServiceErr := casemanagementv1.NewCaseManagementV1UsingExternalConfig(&casemanagementv1.CaseManagementV1Options{ + }) + Expect(testService).ToNot(BeNil()) + Expect(testServiceErr).To(BeNil()) + ClearTestEnvironment(testEnvironment) + }) + It(`Create service client using external config and set url from constructor successfully`, func() { + SetTestEnvironment(testEnvironment) + testService, testServiceErr := casemanagementv1.NewCaseManagementV1UsingExternalConfig(&casemanagementv1.CaseManagementV1Options{ + URL: "https://testService/api", + }) + Expect(testService).ToNot(BeNil()) + Expect(testServiceErr).To(BeNil()) + Expect(testService.Service.GetServiceURL()).To(Equal("https://testService/api")) + ClearTestEnvironment(testEnvironment) + }) + It(`Create service client using external config and set url programatically successfully`, func() { + SetTestEnvironment(testEnvironment) + testService, testServiceErr := casemanagementv1.NewCaseManagementV1UsingExternalConfig(&casemanagementv1.CaseManagementV1Options{ + }) + err := testService.SetServiceURL("https://testService/api") + Expect(err).To(BeNil()) + Expect(testService).ToNot(BeNil()) + Expect(testServiceErr).To(BeNil()) + Expect(testService.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{ + "CASE_MANAGEMENT_URL": "https://casemanagementv1/api", + "CASE_MANAGEMENT_AUTH_TYPE": "someOtherAuth", + } + + SetTestEnvironment(testEnvironment) + testService, testServiceErr := casemanagementv1.NewCaseManagementV1UsingExternalConfig(&casemanagementv1.CaseManagementV1Options{ + }) + + It(`Instantiate service client with error`, func() { + Expect(testService).To(BeNil()) + Expect(testServiceErr).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{ + "CASE_MANAGEMENT_AUTH_TYPE": "NOAuth", + } + + SetTestEnvironment(testEnvironment) + testService, testServiceErr := casemanagementv1.NewCaseManagementV1UsingExternalConfig(&casemanagementv1.CaseManagementV1Options{ + URL: "{BAD_URL_STRING", + }) + + It(`Instantiate service client with error`, func() { + Expect(testService).To(BeNil()) + Expect(testServiceErr).ToNot(BeNil()) + ClearTestEnvironment(testEnvironment) + }) + }) + }) + Describe(`GetCases(getCasesOptions *GetCasesOptions) - Operation response error`, func() { + getCasesPath := "/cases" + 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.Path).To(Equal(getCasesPath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.URL.Query()["offset"]).To(Equal([]string{fmt.Sprint(int64(38))})) + + Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(38))})) + + Expect(req.URL.Query()["search"]).To(Equal([]string{"testString"})) + + Expect(req.URL.Query()["sort"]).To(Equal([]string{"number"})) + + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `} this is not valid json {`) + })) + }) + It(`Invoke GetCases with error: Operation response processing error`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Construct an instance of the GetCasesOptions model + getCasesOptionsModel := new(casemanagementv1.GetCasesOptions) + getCasesOptionsModel.Offset = core.Int64Ptr(int64(38)) + getCasesOptionsModel.Limit = core.Int64Ptr(int64(38)) + getCasesOptionsModel.Search = core.StringPtr("testString") + getCasesOptionsModel.Sort = core.StringPtr("number") + getCasesOptionsModel.Status = []string{"new"} + getCasesOptionsModel.Fields = []string{"number"} + getCasesOptionsModel.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 := testService.GetCases(getCasesOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`GetCases(getCasesOptions *GetCasesOptions)`, func() { + getCasesPath := "/cases" + 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.Path).To(Equal(getCasesPath)) + Expect(req.Method).To(Equal("GET")) + Expect(req.URL.Query()["offset"]).To(Equal([]string{fmt.Sprint(int64(38))})) + + Expect(req.URL.Query()["limit"]).To(Equal([]string{fmt.Sprint(int64(38))})) + + Expect(req.URL.Query()["search"]).To(Equal([]string{"testString"})) + + Expect(req.URL.Query()["sort"]).To(Equal([]string{"number"})) + + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `{"total_count": 10, "first": {"href": "Href"}, "next": {"href": "Href"}, "previous": {"href": "Href"}, "last": {"href": "Href"}, "cases": [{"number": "Number", "short_description": "ShortDescription", "description": "Description", "created_at": "CreatedAt", "created_by": {"name": "Name", "realm": "IBMid", "user_id": "abc@ibm.com"}, "updated_at": "UpdatedAt", "updated_by": {"name": "Name", "realm": "IBMid", "user_id": "abc@ibm.com"}, "contact_type": "Cloud Support Center", "contact": {"name": "Name", "realm": "IBMid", "user_id": "abc@ibm.com"}, "status": "Status", "severity": 8, "support_tier": "Free", "resolution": "Resolution", "close_notes": "CloseNotes", "eu": {"support": false, "data_center": "DataCenter"}, "watchlist": [{"name": "Name", "realm": "IBMid", "user_id": "abc@ibm.com"}], "attachments": [{"id": "ID", "filename": "Filename", "size_in_bytes": 11, "created_at": "CreatedAt", "url": "URL"}], "offering": {"name": "Name", "type": {"group": "crn_service_name", "key": "Key", "kind": "Kind", "id": "ID"}}, "resources": [{"crn": "Crn", "name": "Name", "type": "Type", "url": "URL", "note": "Note"}], "comments": [{"value": "Value", "added_at": "AddedAt", "added_by": {"name": "Name", "realm": "IBMid", "user_id": "abc@ibm.com"}}]}]}`) + })) + }) + It(`Invoke GetCases successfully`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := testService.GetCases(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the GetCasesOptions model + getCasesOptionsModel := new(casemanagementv1.GetCasesOptions) + getCasesOptionsModel.Offset = core.Int64Ptr(int64(38)) + getCasesOptionsModel.Limit = core.Int64Ptr(int64(38)) + getCasesOptionsModel.Search = core.StringPtr("testString") + getCasesOptionsModel.Sort = core.StringPtr("number") + getCasesOptionsModel.Status = []string{"new"} + getCasesOptionsModel.Fields = []string{"number"} + getCasesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = testService.GetCases(getCasesOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + }) + It(`Invoke GetCases with error: Operation request error`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Construct an instance of the GetCasesOptions model + getCasesOptionsModel := new(casemanagementv1.GetCasesOptions) + getCasesOptionsModel.Offset = core.Int64Ptr(int64(38)) + getCasesOptionsModel.Limit = core.Int64Ptr(int64(38)) + getCasesOptionsModel.Search = core.StringPtr("testString") + getCasesOptionsModel.Sort = core.StringPtr("number") + getCasesOptionsModel.Status = []string{"new"} + getCasesOptionsModel.Fields = []string{"number"} + getCasesOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := testService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := testService.GetCases(getCasesOptionsModel) + 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(`CreateCase(createCaseOptions *CreateCaseOptions) - Operation response error`, func() { + createCasePath := "/cases" + 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.Path).To(Equal(createCasePath)) + Expect(req.Method).To(Equal("POST")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `} this is not valid json {`) + })) + }) + It(`Invoke CreateCase with error: Operation response processing error`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Construct an instance of the OfferingType model + offeringTypeModel := new(casemanagementv1.OfferingType) + offeringTypeModel.Group = core.StringPtr("crn_service_name") + offeringTypeModel.Key = core.StringPtr("testString") + offeringTypeModel.Kind = core.StringPtr("testString") + offeringTypeModel.ID = core.StringPtr("testString") + + // Construct an instance of the CasePayloadEu model + casePayloadEuModel := new(casemanagementv1.CasePayloadEu) + casePayloadEuModel.Supported = core.BoolPtr(true) + casePayloadEuModel.DataCenter = core.Int64Ptr(int64(38)) + + // Construct an instance of the Offering model + offeringModel := new(casemanagementv1.Offering) + offeringModel.Name = core.StringPtr("testString") + offeringModel.Type = offeringTypeModel + + // Construct an instance of the ResourcePayload model + resourcePayloadModel := new(casemanagementv1.ResourcePayload) + resourcePayloadModel.Crn = core.StringPtr("testString") + resourcePayloadModel.Type = core.StringPtr("testString") + resourcePayloadModel.ID = core.Float64Ptr(72.5) + resourcePayloadModel.Note = core.StringPtr("testString") + + // Construct an instance of the User model + userModel := new(casemanagementv1.User) + userModel.Realm = core.StringPtr("IBMid") + userModel.UserID = core.StringPtr("abc@ibm.com") + + // Construct an instance of the CreateCaseOptions model + createCaseOptionsModel := new(casemanagementv1.CreateCaseOptions) + createCaseOptionsModel.Type = core.StringPtr("technical") + createCaseOptionsModel.Subject = core.StringPtr("testString") + createCaseOptionsModel.Description = core.StringPtr("testString") + createCaseOptionsModel.Severity = core.Int64Ptr(int64(1)) + createCaseOptionsModel.Eu = casePayloadEuModel + createCaseOptionsModel.Offering = offeringModel + createCaseOptionsModel.Resources = []casemanagementv1.ResourcePayload{*resourcePayloadModel} + createCaseOptionsModel.Watchlist = []casemanagementv1.User{*userModel} + createCaseOptionsModel.InvoiceNumber = core.StringPtr("testString") + createCaseOptionsModel.SlaCreditRequest = core.BoolPtr(true) + createCaseOptionsModel.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 := testService.CreateCase(createCaseOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`CreateCase(createCaseOptions *CreateCaseOptions)`, func() { + createCasePath := "/cases" + 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.Path).To(Equal(createCasePath)) + Expect(req.Method).To(Equal("POST")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `{"number": "Number", "short_description": "ShortDescription", "description": "Description", "created_at": "CreatedAt", "created_by": {"name": "Name", "realm": "IBMid", "user_id": "abc@ibm.com"}, "updated_at": "UpdatedAt", "updated_by": {"name": "Name", "realm": "IBMid", "user_id": "abc@ibm.com"}, "contact_type": "Cloud Support Center", "contact": {"name": "Name", "realm": "IBMid", "user_id": "abc@ibm.com"}, "status": "Status", "severity": 8, "support_tier": "Free", "resolution": "Resolution", "close_notes": "CloseNotes", "eu": {"support": false, "data_center": "DataCenter"}, "watchlist": [{"name": "Name", "realm": "IBMid", "user_id": "abc@ibm.com"}], "attachments": [{"id": "ID", "filename": "Filename", "size_in_bytes": 11, "created_at": "CreatedAt", "url": "URL"}], "offering": {"name": "Name", "type": {"group": "crn_service_name", "key": "Key", "kind": "Kind", "id": "ID"}}, "resources": [{"crn": "Crn", "name": "Name", "type": "Type", "url": "URL", "note": "Note"}], "comments": [{"value": "Value", "added_at": "AddedAt", "added_by": {"name": "Name", "realm": "IBMid", "user_id": "abc@ibm.com"}}]}`) + })) + }) + It(`Invoke CreateCase successfully`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := testService.CreateCase(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the OfferingType model + offeringTypeModel := new(casemanagementv1.OfferingType) + offeringTypeModel.Group = core.StringPtr("crn_service_name") + offeringTypeModel.Key = core.StringPtr("testString") + offeringTypeModel.Kind = core.StringPtr("testString") + offeringTypeModel.ID = core.StringPtr("testString") + + // Construct an instance of the CasePayloadEu model + casePayloadEuModel := new(casemanagementv1.CasePayloadEu) + casePayloadEuModel.Supported = core.BoolPtr(true) + casePayloadEuModel.DataCenter = core.Int64Ptr(int64(38)) + + // Construct an instance of the Offering model + offeringModel := new(casemanagementv1.Offering) + offeringModel.Name = core.StringPtr("testString") + offeringModel.Type = offeringTypeModel + + // Construct an instance of the ResourcePayload model + resourcePayloadModel := new(casemanagementv1.ResourcePayload) + resourcePayloadModel.Crn = core.StringPtr("testString") + resourcePayloadModel.Type = core.StringPtr("testString") + resourcePayloadModel.ID = core.Float64Ptr(72.5) + resourcePayloadModel.Note = core.StringPtr("testString") + + // Construct an instance of the User model + userModel := new(casemanagementv1.User) + userModel.Realm = core.StringPtr("IBMid") + userModel.UserID = core.StringPtr("abc@ibm.com") + + // Construct an instance of the CreateCaseOptions model + createCaseOptionsModel := new(casemanagementv1.CreateCaseOptions) + createCaseOptionsModel.Type = core.StringPtr("technical") + createCaseOptionsModel.Subject = core.StringPtr("testString") + createCaseOptionsModel.Description = core.StringPtr("testString") + createCaseOptionsModel.Severity = core.Int64Ptr(int64(1)) + createCaseOptionsModel.Eu = casePayloadEuModel + createCaseOptionsModel.Offering = offeringModel + createCaseOptionsModel.Resources = []casemanagementv1.ResourcePayload{*resourcePayloadModel} + createCaseOptionsModel.Watchlist = []casemanagementv1.User{*userModel} + createCaseOptionsModel.InvoiceNumber = core.StringPtr("testString") + createCaseOptionsModel.SlaCreditRequest = core.BoolPtr(true) + createCaseOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = testService.CreateCase(createCaseOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + }) + It(`Invoke CreateCase with error: Operation validation and request error`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Construct an instance of the OfferingType model + offeringTypeModel := new(casemanagementv1.OfferingType) + offeringTypeModel.Group = core.StringPtr("crn_service_name") + offeringTypeModel.Key = core.StringPtr("testString") + offeringTypeModel.Kind = core.StringPtr("testString") + offeringTypeModel.ID = core.StringPtr("testString") + + // Construct an instance of the CasePayloadEu model + casePayloadEuModel := new(casemanagementv1.CasePayloadEu) + casePayloadEuModel.Supported = core.BoolPtr(true) + casePayloadEuModel.DataCenter = core.Int64Ptr(int64(38)) + + // Construct an instance of the Offering model + offeringModel := new(casemanagementv1.Offering) + offeringModel.Name = core.StringPtr("testString") + offeringModel.Type = offeringTypeModel + + // Construct an instance of the ResourcePayload model + resourcePayloadModel := new(casemanagementv1.ResourcePayload) + resourcePayloadModel.Crn = core.StringPtr("testString") + resourcePayloadModel.Type = core.StringPtr("testString") + resourcePayloadModel.ID = core.Float64Ptr(72.5) + resourcePayloadModel.Note = core.StringPtr("testString") + + // Construct an instance of the User model + userModel := new(casemanagementv1.User) + userModel.Realm = core.StringPtr("IBMid") + userModel.UserID = core.StringPtr("abc@ibm.com") + + // Construct an instance of the CreateCaseOptions model + createCaseOptionsModel := new(casemanagementv1.CreateCaseOptions) + createCaseOptionsModel.Type = core.StringPtr("technical") + createCaseOptionsModel.Subject = core.StringPtr("testString") + createCaseOptionsModel.Description = core.StringPtr("testString") + createCaseOptionsModel.Severity = core.Int64Ptr(int64(1)) + createCaseOptionsModel.Eu = casePayloadEuModel + createCaseOptionsModel.Offering = offeringModel + createCaseOptionsModel.Resources = []casemanagementv1.ResourcePayload{*resourcePayloadModel} + createCaseOptionsModel.Watchlist = []casemanagementv1.User{*userModel} + createCaseOptionsModel.InvoiceNumber = core.StringPtr("testString") + createCaseOptionsModel.SlaCreditRequest = core.BoolPtr(true) + createCaseOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := testService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := testService.CreateCase(createCaseOptionsModel) + 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 CreateCaseOptions model with no property values + createCaseOptionsModelNew := new(casemanagementv1.CreateCaseOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = testService.CreateCase(createCaseOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`GetCase(getCaseOptions *GetCaseOptions) - Operation response error`, func() { + getCasePath := "/cases/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.Path).To(Equal(getCasePath)) + 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 GetCase with error: Operation response processing error`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Construct an instance of the GetCaseOptions model + getCaseOptionsModel := new(casemanagementv1.GetCaseOptions) + getCaseOptionsModel.CaseNumber = core.StringPtr("testString") + getCaseOptionsModel.Fields = []string{"number"} + getCaseOptionsModel.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 := testService.GetCase(getCaseOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`GetCase(getCaseOptions *GetCaseOptions)`, func() { + getCasePath := "/cases/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.Path).To(Equal(getCasePath)) + Expect(req.Method).To(Equal("GET")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `{"number": "Number", "short_description": "ShortDescription", "description": "Description", "created_at": "CreatedAt", "created_by": {"name": "Name", "realm": "IBMid", "user_id": "abc@ibm.com"}, "updated_at": "UpdatedAt", "updated_by": {"name": "Name", "realm": "IBMid", "user_id": "abc@ibm.com"}, "contact_type": "Cloud Support Center", "contact": {"name": "Name", "realm": "IBMid", "user_id": "abc@ibm.com"}, "status": "Status", "severity": 8, "support_tier": "Free", "resolution": "Resolution", "close_notes": "CloseNotes", "eu": {"support": false, "data_center": "DataCenter"}, "watchlist": [{"name": "Name", "realm": "IBMid", "user_id": "abc@ibm.com"}], "attachments": [{"id": "ID", "filename": "Filename", "size_in_bytes": 11, "created_at": "CreatedAt", "url": "URL"}], "offering": {"name": "Name", "type": {"group": "crn_service_name", "key": "Key", "kind": "Kind", "id": "ID"}}, "resources": [{"crn": "Crn", "name": "Name", "type": "Type", "url": "URL", "note": "Note"}], "comments": [{"value": "Value", "added_at": "AddedAt", "added_by": {"name": "Name", "realm": "IBMid", "user_id": "abc@ibm.com"}}]}`) + })) + }) + It(`Invoke GetCase successfully`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := testService.GetCase(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the GetCaseOptions model + getCaseOptionsModel := new(casemanagementv1.GetCaseOptions) + getCaseOptionsModel.CaseNumber = core.StringPtr("testString") + getCaseOptionsModel.Fields = []string{"number"} + getCaseOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = testService.GetCase(getCaseOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + }) + It(`Invoke GetCase with error: Operation validation and request error`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Construct an instance of the GetCaseOptions model + getCaseOptionsModel := new(casemanagementv1.GetCaseOptions) + getCaseOptionsModel.CaseNumber = core.StringPtr("testString") + getCaseOptionsModel.Fields = []string{"number"} + getCaseOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := testService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := testService.GetCase(getCaseOptionsModel) + 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 GetCaseOptions model with no property values + getCaseOptionsModelNew := new(casemanagementv1.GetCaseOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = testService.GetCase(getCaseOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`UpdateCaseStatus(updateCaseStatusOptions *UpdateCaseStatusOptions) - Operation response error`, func() { + updateCaseStatusPath := "/cases/testString/status" + 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.Path).To(Equal(updateCaseStatusPath)) + Expect(req.Method).To(Equal("PUT")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `} this is not valid json {`) + })) + }) + It(`Invoke UpdateCaseStatus with error: Operation response processing error`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Construct an instance of the ResolvePayload model + statusPayloadModel := new(casemanagementv1.ResolvePayload) + statusPayloadModel.Action = core.StringPtr("resolve") + statusPayloadModel.Comment = core.StringPtr("testString") + statusPayloadModel.ResolutionCode = core.Int64Ptr(int64(1)) + + // Construct an instance of the UpdateCaseStatusOptions model + updateCaseStatusOptionsModel := new(casemanagementv1.UpdateCaseStatusOptions) + updateCaseStatusOptionsModel.CaseNumber = core.StringPtr("testString") + updateCaseStatusOptionsModel.StatusPayload = statusPayloadModel + updateCaseStatusOptionsModel.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 := testService.UpdateCaseStatus(updateCaseStatusOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`UpdateCaseStatus(updateCaseStatusOptions *UpdateCaseStatusOptions)`, func() { + updateCaseStatusPath := "/cases/testString/status" + 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.Path).To(Equal(updateCaseStatusPath)) + Expect(req.Method).To(Equal("PUT")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `{"number": "Number", "short_description": "ShortDescription", "description": "Description", "created_at": "CreatedAt", "created_by": {"name": "Name", "realm": "IBMid", "user_id": "abc@ibm.com"}, "updated_at": "UpdatedAt", "updated_by": {"name": "Name", "realm": "IBMid", "user_id": "abc@ibm.com"}, "contact_type": "Cloud Support Center", "contact": {"name": "Name", "realm": "IBMid", "user_id": "abc@ibm.com"}, "status": "Status", "severity": 8, "support_tier": "Free", "resolution": "Resolution", "close_notes": "CloseNotes", "eu": {"support": false, "data_center": "DataCenter"}, "watchlist": [{"name": "Name", "realm": "IBMid", "user_id": "abc@ibm.com"}], "attachments": [{"id": "ID", "filename": "Filename", "size_in_bytes": 11, "created_at": "CreatedAt", "url": "URL"}], "offering": {"name": "Name", "type": {"group": "crn_service_name", "key": "Key", "kind": "Kind", "id": "ID"}}, "resources": [{"crn": "Crn", "name": "Name", "type": "Type", "url": "URL", "note": "Note"}], "comments": [{"value": "Value", "added_at": "AddedAt", "added_by": {"name": "Name", "realm": "IBMid", "user_id": "abc@ibm.com"}}]}`) + })) + }) + It(`Invoke UpdateCaseStatus successfully`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := testService.UpdateCaseStatus(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the ResolvePayload model + statusPayloadModel := new(casemanagementv1.ResolvePayload) + statusPayloadModel.Action = core.StringPtr("resolve") + statusPayloadModel.Comment = core.StringPtr("testString") + statusPayloadModel.ResolutionCode = core.Int64Ptr(int64(1)) + + // Construct an instance of the UpdateCaseStatusOptions model + updateCaseStatusOptionsModel := new(casemanagementv1.UpdateCaseStatusOptions) + updateCaseStatusOptionsModel.CaseNumber = core.StringPtr("testString") + updateCaseStatusOptionsModel.StatusPayload = statusPayloadModel + updateCaseStatusOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = testService.UpdateCaseStatus(updateCaseStatusOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + }) + It(`Invoke UpdateCaseStatus with error: Operation validation and request error`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Construct an instance of the ResolvePayload model + statusPayloadModel := new(casemanagementv1.ResolvePayload) + statusPayloadModel.Action = core.StringPtr("resolve") + statusPayloadModel.Comment = core.StringPtr("testString") + statusPayloadModel.ResolutionCode = core.Int64Ptr(int64(1)) + + // Construct an instance of the UpdateCaseStatusOptions model + updateCaseStatusOptionsModel := new(casemanagementv1.UpdateCaseStatusOptions) + updateCaseStatusOptionsModel.CaseNumber = core.StringPtr("testString") + updateCaseStatusOptionsModel.StatusPayload = statusPayloadModel + updateCaseStatusOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := testService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := testService.UpdateCaseStatus(updateCaseStatusOptionsModel) + 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 UpdateCaseStatusOptions model with no property values + updateCaseStatusOptionsModelNew := new(casemanagementv1.UpdateCaseStatusOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = testService.UpdateCaseStatus(updateCaseStatusOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`AddComment(addCommentOptions *AddCommentOptions) - Operation response error`, func() { + addCommentPath := "/cases/testString/comments" + 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.Path).To(Equal(addCommentPath)) + Expect(req.Method).To(Equal("PUT")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `} this is not valid json {`) + })) + }) + It(`Invoke AddComment with error: Operation response processing error`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Construct an instance of the AddCommentOptions model + addCommentOptionsModel := new(casemanagementv1.AddCommentOptions) + addCommentOptionsModel.CaseNumber = core.StringPtr("testString") + addCommentOptionsModel.Comment = core.StringPtr("testString") + addCommentOptionsModel.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 := testService.AddComment(addCommentOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`AddComment(addCommentOptions *AddCommentOptions)`, func() { + addCommentPath := "/cases/testString/comments" + 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.Path).To(Equal(addCommentPath)) + Expect(req.Method).To(Equal("PUT")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `{"value": "Value", "added_at": "AddedAt", "added_by": {"name": "Name", "realm": "IBMid", "user_id": "abc@ibm.com"}}`) + })) + }) + It(`Invoke AddComment successfully`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := testService.AddComment(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the AddCommentOptions model + addCommentOptionsModel := new(casemanagementv1.AddCommentOptions) + addCommentOptionsModel.CaseNumber = core.StringPtr("testString") + addCommentOptionsModel.Comment = core.StringPtr("testString") + addCommentOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = testService.AddComment(addCommentOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + }) + It(`Invoke AddComment with error: Operation validation and request error`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Construct an instance of the AddCommentOptions model + addCommentOptionsModel := new(casemanagementv1.AddCommentOptions) + addCommentOptionsModel.CaseNumber = core.StringPtr("testString") + addCommentOptionsModel.Comment = core.StringPtr("testString") + addCommentOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := testService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := testService.AddComment(addCommentOptionsModel) + 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 AddCommentOptions model with no property values + addCommentOptionsModelNew := new(casemanagementv1.AddCommentOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = testService.AddComment(addCommentOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`AddWatchlist(addWatchlistOptions *AddWatchlistOptions) - Operation response error`, func() { + addWatchlistPath := "/cases/testString/watchlist" + 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.Path).To(Equal(addWatchlistPath)) + Expect(req.Method).To(Equal("PUT")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `} this is not valid json {`) + })) + }) + It(`Invoke AddWatchlist with error: Operation response processing error`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Construct an instance of the User model + userModel := new(casemanagementv1.User) + userModel.Realm = core.StringPtr("IBMid") + userModel.UserID = core.StringPtr("abc@ibm.com") + + // Construct an instance of the AddWatchlistOptions model + addWatchlistOptionsModel := new(casemanagementv1.AddWatchlistOptions) + addWatchlistOptionsModel.CaseNumber = core.StringPtr("testString") + addWatchlistOptionsModel.Watchlist = []casemanagementv1.User{*userModel} + addWatchlistOptionsModel.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 := testService.AddWatchlist(addWatchlistOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`AddWatchlist(addWatchlistOptions *AddWatchlistOptions)`, func() { + addWatchlistPath := "/cases/testString/watchlist" + 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.Path).To(Equal(addWatchlistPath)) + Expect(req.Method).To(Equal("PUT")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `{"added": [{"name": "Name", "realm": "IBMid", "user_id": "abc@ibm.com"}], "failed": [{"name": "Name", "realm": "IBMid", "user_id": "abc@ibm.com"}]}`) + })) + }) + It(`Invoke AddWatchlist successfully`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := testService.AddWatchlist(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the User model + userModel := new(casemanagementv1.User) + userModel.Realm = core.StringPtr("IBMid") + userModel.UserID = core.StringPtr("abc@ibm.com") + + // Construct an instance of the AddWatchlistOptions model + addWatchlistOptionsModel := new(casemanagementv1.AddWatchlistOptions) + addWatchlistOptionsModel.CaseNumber = core.StringPtr("testString") + addWatchlistOptionsModel.Watchlist = []casemanagementv1.User{*userModel} + addWatchlistOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = testService.AddWatchlist(addWatchlistOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + }) + It(`Invoke AddWatchlist with error: Operation validation and request error`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Construct an instance of the User model + userModel := new(casemanagementv1.User) + userModel.Realm = core.StringPtr("IBMid") + userModel.UserID = core.StringPtr("abc@ibm.com") + + // Construct an instance of the AddWatchlistOptions model + addWatchlistOptionsModel := new(casemanagementv1.AddWatchlistOptions) + addWatchlistOptionsModel.CaseNumber = core.StringPtr("testString") + addWatchlistOptionsModel.Watchlist = []casemanagementv1.User{*userModel} + addWatchlistOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := testService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := testService.AddWatchlist(addWatchlistOptionsModel) + 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 AddWatchlistOptions model with no property values + addWatchlistOptionsModelNew := new(casemanagementv1.AddWatchlistOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = testService.AddWatchlist(addWatchlistOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`RemoveWatchlist(removeWatchlistOptions *RemoveWatchlistOptions) - Operation response error`, func() { + removeWatchlistPath := "/cases/testString/watchlist" + 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.Path).To(Equal(removeWatchlistPath)) + Expect(req.Method).To(Equal("DELETE")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `} this is not valid json {`) + })) + }) + It(`Invoke RemoveWatchlist with error: Operation response processing error`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Construct an instance of the User model + userModel := new(casemanagementv1.User) + userModel.Realm = core.StringPtr("IBMid") + userModel.UserID = core.StringPtr("abc@ibm.com") + + // Construct an instance of the RemoveWatchlistOptions model + removeWatchlistOptionsModel := new(casemanagementv1.RemoveWatchlistOptions) + removeWatchlistOptionsModel.CaseNumber = core.StringPtr("testString") + removeWatchlistOptionsModel.Watchlist = []casemanagementv1.User{*userModel} + removeWatchlistOptionsModel.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 := testService.RemoveWatchlist(removeWatchlistOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`RemoveWatchlist(removeWatchlistOptions *RemoveWatchlistOptions)`, func() { + removeWatchlistPath := "/cases/testString/watchlist" + 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.Path).To(Equal(removeWatchlistPath)) + Expect(req.Method).To(Equal("DELETE")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `{"watchlist": [{"name": "Name", "realm": "IBMid", "user_id": "abc@ibm.com"}]}`) + })) + }) + It(`Invoke RemoveWatchlist successfully`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := testService.RemoveWatchlist(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the User model + userModel := new(casemanagementv1.User) + userModel.Realm = core.StringPtr("IBMid") + userModel.UserID = core.StringPtr("abc@ibm.com") + + // Construct an instance of the RemoveWatchlistOptions model + removeWatchlistOptionsModel := new(casemanagementv1.RemoveWatchlistOptions) + removeWatchlistOptionsModel.CaseNumber = core.StringPtr("testString") + removeWatchlistOptionsModel.Watchlist = []casemanagementv1.User{*userModel} + removeWatchlistOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = testService.RemoveWatchlist(removeWatchlistOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + }) + It(`Invoke RemoveWatchlist with error: Operation validation and request error`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Construct an instance of the User model + userModel := new(casemanagementv1.User) + userModel.Realm = core.StringPtr("IBMid") + userModel.UserID = core.StringPtr("abc@ibm.com") + + // Construct an instance of the RemoveWatchlistOptions model + removeWatchlistOptionsModel := new(casemanagementv1.RemoveWatchlistOptions) + removeWatchlistOptionsModel.CaseNumber = core.StringPtr("testString") + removeWatchlistOptionsModel.Watchlist = []casemanagementv1.User{*userModel} + removeWatchlistOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := testService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := testService.RemoveWatchlist(removeWatchlistOptionsModel) + 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 RemoveWatchlistOptions model with no property values + removeWatchlistOptionsModelNew := new(casemanagementv1.RemoveWatchlistOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = testService.RemoveWatchlist(removeWatchlistOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`AddResource(addResourceOptions *AddResourceOptions) - Operation response error`, func() { + addResourcePath := "/cases/testString/resources" + 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.Path).To(Equal(addResourcePath)) + Expect(req.Method).To(Equal("PUT")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `} this is not valid json {`) + })) + }) + It(`Invoke AddResource with error: Operation response processing error`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Construct an instance of the AddResourceOptions model + addResourceOptionsModel := new(casemanagementv1.AddResourceOptions) + addResourceOptionsModel.CaseNumber = core.StringPtr("testString") + addResourceOptionsModel.Crn = core.StringPtr("testString") + addResourceOptionsModel.Type = core.StringPtr("testString") + addResourceOptionsModel.ID = core.Float64Ptr(72.5) + addResourceOptionsModel.Note = core.StringPtr("testString") + addResourceOptionsModel.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 := testService.AddResource(addResourceOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`AddResource(addResourceOptions *AddResourceOptions)`, func() { + addResourcePath := "/cases/testString/resources" + 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.Path).To(Equal(addResourcePath)) + Expect(req.Method).To(Equal("PUT")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `{"crn": "Crn", "name": "Name", "type": "Type", "url": "URL", "note": "Note"}`) + })) + }) + It(`Invoke AddResource successfully`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := testService.AddResource(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the AddResourceOptions model + addResourceOptionsModel := new(casemanagementv1.AddResourceOptions) + addResourceOptionsModel.CaseNumber = core.StringPtr("testString") + addResourceOptionsModel.Crn = core.StringPtr("testString") + addResourceOptionsModel.Type = core.StringPtr("testString") + addResourceOptionsModel.ID = core.Float64Ptr(72.5) + addResourceOptionsModel.Note = core.StringPtr("testString") + addResourceOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = testService.AddResource(addResourceOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + }) + It(`Invoke AddResource with error: Operation validation and request error`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Construct an instance of the AddResourceOptions model + addResourceOptionsModel := new(casemanagementv1.AddResourceOptions) + addResourceOptionsModel.CaseNumber = core.StringPtr("testString") + addResourceOptionsModel.Crn = core.StringPtr("testString") + addResourceOptionsModel.Type = core.StringPtr("testString") + addResourceOptionsModel.ID = core.Float64Ptr(72.5) + addResourceOptionsModel.Note = core.StringPtr("testString") + addResourceOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := testService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := testService.AddResource(addResourceOptionsModel) + 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 AddResourceOptions model with no property values + addResourceOptionsModelNew := new(casemanagementv1.AddResourceOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = testService.AddResource(addResourceOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`UploadFile(uploadFileOptions *UploadFileOptions) - Operation response error`, func() { + uploadFilePath := "/cases/testString/attachments" + 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.Path).To(Equal(uploadFilePath)) + Expect(req.Method).To(Equal("PUT")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `} this is not valid json {`) + })) + }) + It(`Invoke UploadFile with error: Operation response processing error`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Construct an instance of the FileWithMetadata model + fileWithMetadataModel := new(casemanagementv1.FileWithMetadata) + fileWithMetadataModel.Data = CreateMockReader("This is a mock file.") + fileWithMetadataModel.Filename = core.StringPtr("testString") + fileWithMetadataModel.ContentType = core.StringPtr("testString") + + // Construct an instance of the UploadFileOptions model + uploadFileOptionsModel := new(casemanagementv1.UploadFileOptions) + uploadFileOptionsModel.CaseNumber = core.StringPtr("testString") + uploadFileOptionsModel.File = []casemanagementv1.FileWithMetadata{casemanagementv1.FileWithMetadata{Data: CreateMockReader("This is a mock file."), Filename: core.StringPtr("mockfilename.txt"), }} + uploadFileOptionsModel.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 := testService.UploadFile(uploadFileOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`UploadFile(uploadFileOptions *UploadFileOptions)`, func() { + uploadFilePath := "/cases/testString/attachments" + 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.Path).To(Equal(uploadFilePath)) + Expect(req.Method).To(Equal("PUT")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `{"id": "ID", "filename": "Filename", "size_in_bytes": 11, "created_at": "CreatedAt", "url": "URL"}`) + })) + }) + It(`Invoke UploadFile successfully`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := testService.UploadFile(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the FileWithMetadata model + fileWithMetadataModel := new(casemanagementv1.FileWithMetadata) + fileWithMetadataModel.Data = CreateMockReader("This is a mock file.") + fileWithMetadataModel.Filename = core.StringPtr("testString") + fileWithMetadataModel.ContentType = core.StringPtr("testString") + + // Construct an instance of the UploadFileOptions model + uploadFileOptionsModel := new(casemanagementv1.UploadFileOptions) + uploadFileOptionsModel.CaseNumber = core.StringPtr("testString") + uploadFileOptionsModel.File = []casemanagementv1.FileWithMetadata{casemanagementv1.FileWithMetadata{Data: CreateMockReader("This is a mock file."), Filename: core.StringPtr("mockfilename.txt"), }} + uploadFileOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = testService.UploadFile(uploadFileOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + }) + It(`Invoke UploadFile with error: Operation validation and request error`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Construct an instance of the FileWithMetadata model + fileWithMetadataModel := new(casemanagementv1.FileWithMetadata) + fileWithMetadataModel.Data = CreateMockReader("This is a mock file.") + fileWithMetadataModel.Filename = core.StringPtr("testString") + fileWithMetadataModel.ContentType = core.StringPtr("testString") + + // Construct an instance of the UploadFileOptions model + uploadFileOptionsModel := new(casemanagementv1.UploadFileOptions) + uploadFileOptionsModel.CaseNumber = core.StringPtr("testString") + uploadFileOptionsModel.File = []casemanagementv1.FileWithMetadata{casemanagementv1.FileWithMetadata{Data: CreateMockReader("This is a mock file."), Filename: core.StringPtr("mockfilename.txt"), }} + uploadFileOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := testService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := testService.UploadFile(uploadFileOptionsModel) + 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 UploadFileOptions model with no property values + uploadFileOptionsModelNew := new(casemanagementv1.UploadFileOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = testService.UploadFile(uploadFileOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`DownloadFile(downloadFileOptions *DownloadFileOptions)`, func() { + downloadFilePath := "/cases/testString/attachments/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.Path).To(Equal(downloadFilePath)) + Expect(req.Method).To(Equal("GET")) + res.Header().Set("Content-type", "application/octet-stream") + res.WriteHeader(200) + fmt.Fprintf(res, `Contents of response byte-stream...`) + })) + }) + It(`Invoke DownloadFile successfully`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := testService.DownloadFile(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the DownloadFileOptions model + downloadFileOptionsModel := new(casemanagementv1.DownloadFileOptions) + downloadFileOptionsModel.CaseNumber = core.StringPtr("testString") + downloadFileOptionsModel.FileID = core.StringPtr("testString") + downloadFileOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = testService.DownloadFile(downloadFileOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + }) + It(`Invoke DownloadFile with error: Operation validation and request error`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Construct an instance of the DownloadFileOptions model + downloadFileOptionsModel := new(casemanagementv1.DownloadFileOptions) + downloadFileOptionsModel.CaseNumber = core.StringPtr("testString") + downloadFileOptionsModel.FileID = core.StringPtr("testString") + downloadFileOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := testService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := testService.DownloadFile(downloadFileOptionsModel) + 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 DownloadFileOptions model with no property values + downloadFileOptionsModelNew := new(casemanagementv1.DownloadFileOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = testService.DownloadFile(downloadFileOptionsModelNew) + Expect(operationErr).ToNot(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + Describe(`DeleteFile(deleteFileOptions *DeleteFileOptions) - Operation response error`, func() { + deleteFilePath := "/cases/testString/attachments/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.Path).To(Equal(deleteFilePath)) + Expect(req.Method).To(Equal("DELETE")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `} this is not valid json {`) + })) + }) + It(`Invoke DeleteFile with error: Operation response processing error`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Construct an instance of the DeleteFileOptions model + deleteFileOptionsModel := new(casemanagementv1.DeleteFileOptions) + deleteFileOptionsModel.CaseNumber = core.StringPtr("testString") + deleteFileOptionsModel.FileID = core.StringPtr("testString") + deleteFileOptionsModel.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 := testService.DeleteFile(deleteFileOptionsModel) + Expect(operationErr).ToNot(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).To(BeNil()) + }) + AfterEach(func() { + testServer.Close() + }) + }) + }) + + Describe(`DeleteFile(deleteFileOptions *DeleteFileOptions)`, func() { + deleteFilePath := "/cases/testString/attachments/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.Path).To(Equal(deleteFilePath)) + Expect(req.Method).To(Equal("DELETE")) + res.Header().Set("Content-type", "application/json") + res.WriteHeader(200) + fmt.Fprintf(res, `{"attachments": [{"id": "ID", "filename": "Filename", "size_in_bytes": 11, "created_at": "CreatedAt", "url": "URL"}]}`) + })) + }) + It(`Invoke DeleteFile successfully`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Invoke operation with nil options model (negative test) + result, response, operationErr := testService.DeleteFile(nil) + Expect(operationErr).NotTo(BeNil()) + Expect(response).To(BeNil()) + Expect(result).To(BeNil()) + + // Construct an instance of the DeleteFileOptions model + deleteFileOptionsModel := new(casemanagementv1.DeleteFileOptions) + deleteFileOptionsModel.CaseNumber = core.StringPtr("testString") + deleteFileOptionsModel.FileID = core.StringPtr("testString") + deleteFileOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + + // Invoke operation with valid options model (positive test) + result, response, operationErr = testService.DeleteFile(deleteFileOptionsModel) + Expect(operationErr).To(BeNil()) + Expect(response).ToNot(BeNil()) + Expect(result).ToNot(BeNil()) + }) + It(`Invoke DeleteFile with error: Operation validation and request error`, func() { + testService, testServiceErr := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: testServer.URL, + Authenticator: &core.NoAuthAuthenticator{}, + }) + Expect(testServiceErr).To(BeNil()) + Expect(testService).ToNot(BeNil()) + + // Construct an instance of the DeleteFileOptions model + deleteFileOptionsModel := new(casemanagementv1.DeleteFileOptions) + deleteFileOptionsModel.CaseNumber = core.StringPtr("testString") + deleteFileOptionsModel.FileID = core.StringPtr("testString") + deleteFileOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} + // Invoke operation with empty URL (negative test) + err := testService.SetServiceURL("") + Expect(err).To(BeNil()) + result, response, operationErr := testService.DeleteFile(deleteFileOptionsModel) + 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 DeleteFileOptions model with no property values + deleteFileOptionsModelNew := new(casemanagementv1.DeleteFileOptions) + // Invoke operation with invalid model (negative test) + result, response, operationErr = testService.DeleteFile(deleteFileOptionsModelNew) + 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() { + testService, _ := casemanagementv1.NewCaseManagementV1(&casemanagementv1.CaseManagementV1Options{ + URL: "http://casemanagementv1modelgenerator.com", + Authenticator: &core.NoAuthAuthenticator{}, + }) + It(`Invoke NewAddCommentOptions successfully`, func() { + // Construct an instance of the AddCommentOptions model + caseNumber := "testString" + addCommentOptionsComment := "testString" + addCommentOptionsModel := testService.NewAddCommentOptions(caseNumber, addCommentOptionsComment) + addCommentOptionsModel.SetCaseNumber("testString") + addCommentOptionsModel.SetComment("testString") + addCommentOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(addCommentOptionsModel).ToNot(BeNil()) + Expect(addCommentOptionsModel.CaseNumber).To(Equal(core.StringPtr("testString"))) + Expect(addCommentOptionsModel.Comment).To(Equal(core.StringPtr("testString"))) + Expect(addCommentOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewAddResourceOptions successfully`, func() { + // Construct an instance of the AddResourceOptions model + caseNumber := "testString" + addResourceOptionsModel := testService.NewAddResourceOptions(caseNumber) + addResourceOptionsModel.SetCaseNumber("testString") + addResourceOptionsModel.SetCrn("testString") + addResourceOptionsModel.SetType("testString") + addResourceOptionsModel.SetID(72.5) + addResourceOptionsModel.SetNote("testString") + addResourceOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(addResourceOptionsModel).ToNot(BeNil()) + Expect(addResourceOptionsModel.CaseNumber).To(Equal(core.StringPtr("testString"))) + Expect(addResourceOptionsModel.Crn).To(Equal(core.StringPtr("testString"))) + Expect(addResourceOptionsModel.Type).To(Equal(core.StringPtr("testString"))) + Expect(addResourceOptionsModel.ID).To(Equal(core.Float64Ptr(72.5))) + Expect(addResourceOptionsModel.Note).To(Equal(core.StringPtr("testString"))) + Expect(addResourceOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewAddWatchlistOptions successfully`, func() { + // Construct an instance of the User model + userModel := new(casemanagementv1.User) + Expect(userModel).ToNot(BeNil()) + userModel.Realm = core.StringPtr("IBMid") + userModel.UserID = core.StringPtr("abc@ibm.com") + Expect(userModel.Realm).To(Equal(core.StringPtr("IBMid"))) + Expect(userModel.UserID).To(Equal(core.StringPtr("abc@ibm.com"))) + + // Construct an instance of the AddWatchlistOptions model + caseNumber := "testString" + addWatchlistOptionsModel := testService.NewAddWatchlistOptions(caseNumber) + addWatchlistOptionsModel.SetCaseNumber("testString") + addWatchlistOptionsModel.SetWatchlist([]casemanagementv1.User{*userModel}) + addWatchlistOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(addWatchlistOptionsModel).ToNot(BeNil()) + Expect(addWatchlistOptionsModel.CaseNumber).To(Equal(core.StringPtr("testString"))) + Expect(addWatchlistOptionsModel.Watchlist).To(Equal([]casemanagementv1.User{*userModel})) + Expect(addWatchlistOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewCreateCaseOptions successfully`, func() { + // Construct an instance of the OfferingType model + offeringTypeModel := new(casemanagementv1.OfferingType) + Expect(offeringTypeModel).ToNot(BeNil()) + offeringTypeModel.Group = core.StringPtr("crn_service_name") + offeringTypeModel.Key = core.StringPtr("testString") + offeringTypeModel.Kind = core.StringPtr("testString") + offeringTypeModel.ID = core.StringPtr("testString") + Expect(offeringTypeModel.Group).To(Equal(core.StringPtr("crn_service_name"))) + Expect(offeringTypeModel.Key).To(Equal(core.StringPtr("testString"))) + Expect(offeringTypeModel.Kind).To(Equal(core.StringPtr("testString"))) + Expect(offeringTypeModel.ID).To(Equal(core.StringPtr("testString"))) + + // Construct an instance of the CasePayloadEu model + casePayloadEuModel := new(casemanagementv1.CasePayloadEu) + Expect(casePayloadEuModel).ToNot(BeNil()) + casePayloadEuModel.Supported = core.BoolPtr(true) + casePayloadEuModel.DataCenter = core.Int64Ptr(int64(38)) + Expect(casePayloadEuModel.Supported).To(Equal(core.BoolPtr(true))) + Expect(casePayloadEuModel.DataCenter).To(Equal(core.Int64Ptr(int64(38)))) + + // Construct an instance of the Offering model + offeringModel := new(casemanagementv1.Offering) + Expect(offeringModel).ToNot(BeNil()) + offeringModel.Name = core.StringPtr("testString") + offeringModel.Type = offeringTypeModel + Expect(offeringModel.Name).To(Equal(core.StringPtr("testString"))) + Expect(offeringModel.Type).To(Equal(offeringTypeModel)) + + // Construct an instance of the ResourcePayload model + resourcePayloadModel := new(casemanagementv1.ResourcePayload) + Expect(resourcePayloadModel).ToNot(BeNil()) + resourcePayloadModel.Crn = core.StringPtr("testString") + resourcePayloadModel.Type = core.StringPtr("testString") + resourcePayloadModel.ID = core.Float64Ptr(72.5) + resourcePayloadModel.Note = core.StringPtr("testString") + Expect(resourcePayloadModel.Crn).To(Equal(core.StringPtr("testString"))) + Expect(resourcePayloadModel.Type).To(Equal(core.StringPtr("testString"))) + Expect(resourcePayloadModel.ID).To(Equal(core.Float64Ptr(72.5))) + Expect(resourcePayloadModel.Note).To(Equal(core.StringPtr("testString"))) + + // Construct an instance of the User model + userModel := new(casemanagementv1.User) + Expect(userModel).ToNot(BeNil()) + userModel.Realm = core.StringPtr("IBMid") + userModel.UserID = core.StringPtr("abc@ibm.com") + Expect(userModel.Realm).To(Equal(core.StringPtr("IBMid"))) + Expect(userModel.UserID).To(Equal(core.StringPtr("abc@ibm.com"))) + + // Construct an instance of the CreateCaseOptions model + createCaseOptionsType := "technical" + createCaseOptionsSubject := "testString" + createCaseOptionsDescription := "testString" + createCaseOptionsModel := testService.NewCreateCaseOptions(createCaseOptionsType, createCaseOptionsSubject, createCaseOptionsDescription) + createCaseOptionsModel.SetType("technical") + createCaseOptionsModel.SetSubject("testString") + createCaseOptionsModel.SetDescription("testString") + createCaseOptionsModel.SetSeverity(int64(1)) + createCaseOptionsModel.SetEu(casePayloadEuModel) + createCaseOptionsModel.SetOffering(offeringModel) + createCaseOptionsModel.SetResources([]casemanagementv1.ResourcePayload{*resourcePayloadModel}) + createCaseOptionsModel.SetWatchlist([]casemanagementv1.User{*userModel}) + createCaseOptionsModel.SetInvoiceNumber("testString") + createCaseOptionsModel.SetSlaCreditRequest(true) + createCaseOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(createCaseOptionsModel).ToNot(BeNil()) + Expect(createCaseOptionsModel.Type).To(Equal(core.StringPtr("technical"))) + Expect(createCaseOptionsModel.Subject).To(Equal(core.StringPtr("testString"))) + Expect(createCaseOptionsModel.Description).To(Equal(core.StringPtr("testString"))) + Expect(createCaseOptionsModel.Severity).To(Equal(core.Int64Ptr(int64(1)))) + Expect(createCaseOptionsModel.Eu).To(Equal(casePayloadEuModel)) + Expect(createCaseOptionsModel.Offering).To(Equal(offeringModel)) + Expect(createCaseOptionsModel.Resources).To(Equal([]casemanagementv1.ResourcePayload{*resourcePayloadModel})) + Expect(createCaseOptionsModel.Watchlist).To(Equal([]casemanagementv1.User{*userModel})) + Expect(createCaseOptionsModel.InvoiceNumber).To(Equal(core.StringPtr("testString"))) + Expect(createCaseOptionsModel.SlaCreditRequest).To(Equal(core.BoolPtr(true))) + Expect(createCaseOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewDeleteFileOptions successfully`, func() { + // Construct an instance of the DeleteFileOptions model + caseNumber := "testString" + fileID := "testString" + deleteFileOptionsModel := testService.NewDeleteFileOptions(caseNumber, fileID) + deleteFileOptionsModel.SetCaseNumber("testString") + deleteFileOptionsModel.SetFileID("testString") + deleteFileOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(deleteFileOptionsModel).ToNot(BeNil()) + Expect(deleteFileOptionsModel.CaseNumber).To(Equal(core.StringPtr("testString"))) + Expect(deleteFileOptionsModel.FileID).To(Equal(core.StringPtr("testString"))) + Expect(deleteFileOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewDownloadFileOptions successfully`, func() { + // Construct an instance of the DownloadFileOptions model + caseNumber := "testString" + fileID := "testString" + downloadFileOptionsModel := testService.NewDownloadFileOptions(caseNumber, fileID) + downloadFileOptionsModel.SetCaseNumber("testString") + downloadFileOptionsModel.SetFileID("testString") + downloadFileOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(downloadFileOptionsModel).ToNot(BeNil()) + Expect(downloadFileOptionsModel.CaseNumber).To(Equal(core.StringPtr("testString"))) + Expect(downloadFileOptionsModel.FileID).To(Equal(core.StringPtr("testString"))) + Expect(downloadFileOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewFileWithMetadata successfully`, func() { + data := CreateMockReader("This is a mock file.") + model, err := testService.NewFileWithMetadata(data) + Expect(model).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) + It(`Invoke NewGetCaseOptions successfully`, func() { + // Construct an instance of the GetCaseOptions model + caseNumber := "testString" + getCaseOptionsModel := testService.NewGetCaseOptions(caseNumber) + getCaseOptionsModel.SetCaseNumber("testString") + getCaseOptionsModel.SetFields([]string{"number"}) + getCaseOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(getCaseOptionsModel).ToNot(BeNil()) + Expect(getCaseOptionsModel.CaseNumber).To(Equal(core.StringPtr("testString"))) + Expect(getCaseOptionsModel.Fields).To(Equal([]string{"number"})) + Expect(getCaseOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewGetCasesOptions successfully`, func() { + // Construct an instance of the GetCasesOptions model + getCasesOptionsModel := testService.NewGetCasesOptions() + getCasesOptionsModel.SetOffset(int64(38)) + getCasesOptionsModel.SetLimit(int64(38)) + getCasesOptionsModel.SetSearch("testString") + getCasesOptionsModel.SetSort("number") + getCasesOptionsModel.SetStatus([]string{"new"}) + getCasesOptionsModel.SetFields([]string{"number"}) + getCasesOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(getCasesOptionsModel).ToNot(BeNil()) + Expect(getCasesOptionsModel.Offset).To(Equal(core.Int64Ptr(int64(38)))) + Expect(getCasesOptionsModel.Limit).To(Equal(core.Int64Ptr(int64(38)))) + Expect(getCasesOptionsModel.Search).To(Equal(core.StringPtr("testString"))) + Expect(getCasesOptionsModel.Sort).To(Equal(core.StringPtr("number"))) + Expect(getCasesOptionsModel.Status).To(Equal([]string{"new"})) + Expect(getCasesOptionsModel.Fields).To(Equal([]string{"number"})) + Expect(getCasesOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewOffering successfully`, func() { + name := "testString" + var typeVar *casemanagementv1.OfferingType = nil + _, err := testService.NewOffering(name, typeVar) + Expect(err).ToNot(BeNil()) + }) + It(`Invoke NewOfferingType successfully`, func() { + group := "crn_service_name" + key := "testString" + model, err := testService.NewOfferingType(group, key) + Expect(model).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) + It(`Invoke NewRemoveWatchlistOptions successfully`, func() { + // Construct an instance of the User model + userModel := new(casemanagementv1.User) + Expect(userModel).ToNot(BeNil()) + userModel.Realm = core.StringPtr("IBMid") + userModel.UserID = core.StringPtr("abc@ibm.com") + Expect(userModel.Realm).To(Equal(core.StringPtr("IBMid"))) + Expect(userModel.UserID).To(Equal(core.StringPtr("abc@ibm.com"))) + + // Construct an instance of the RemoveWatchlistOptions model + caseNumber := "testString" + removeWatchlistOptionsModel := testService.NewRemoveWatchlistOptions(caseNumber) + removeWatchlistOptionsModel.SetCaseNumber("testString") + removeWatchlistOptionsModel.SetWatchlist([]casemanagementv1.User{*userModel}) + removeWatchlistOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(removeWatchlistOptionsModel).ToNot(BeNil()) + Expect(removeWatchlistOptionsModel.CaseNumber).To(Equal(core.StringPtr("testString"))) + Expect(removeWatchlistOptionsModel.Watchlist).To(Equal([]casemanagementv1.User{*userModel})) + Expect(removeWatchlistOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewUpdateCaseStatusOptions successfully`, func() { + // Construct an instance of the ResolvePayload model + statusPayloadModel := new(casemanagementv1.ResolvePayload) + Expect(statusPayloadModel).ToNot(BeNil()) + statusPayloadModel.Action = core.StringPtr("resolve") + statusPayloadModel.Comment = core.StringPtr("testString") + statusPayloadModel.ResolutionCode = core.Int64Ptr(int64(1)) + Expect(statusPayloadModel.Action).To(Equal(core.StringPtr("resolve"))) + Expect(statusPayloadModel.Comment).To(Equal(core.StringPtr("testString"))) + Expect(statusPayloadModel.ResolutionCode).To(Equal(core.Int64Ptr(int64(1)))) + + // Construct an instance of the UpdateCaseStatusOptions model + caseNumber := "testString" + var statusPayload casemanagementv1.StatusPayloadIntf = nil + updateCaseStatusOptionsModel := testService.NewUpdateCaseStatusOptions(caseNumber, statusPayload) + updateCaseStatusOptionsModel.SetCaseNumber("testString") + updateCaseStatusOptionsModel.SetStatusPayload(statusPayloadModel) + updateCaseStatusOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(updateCaseStatusOptionsModel).ToNot(BeNil()) + Expect(updateCaseStatusOptionsModel.CaseNumber).To(Equal(core.StringPtr("testString"))) + Expect(updateCaseStatusOptionsModel.StatusPayload).To(Equal(statusPayloadModel)) + Expect(updateCaseStatusOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewUploadFileOptions successfully`, func() { + // Construct an instance of the FileWithMetadata model + fileWithMetadataModel := new(casemanagementv1.FileWithMetadata) + Expect(fileWithMetadataModel).ToNot(BeNil()) + fileWithMetadataModel.Data = CreateMockReader("This is a mock file.") + fileWithMetadataModel.Filename = core.StringPtr("testString") + fileWithMetadataModel.ContentType = core.StringPtr("testString") + Expect(fileWithMetadataModel.Data).To(Equal(CreateMockReader("This is a mock file."))) + Expect(fileWithMetadataModel.Filename).To(Equal(core.StringPtr("testString"))) + Expect(fileWithMetadataModel.ContentType).To(Equal(core.StringPtr("testString"))) + + // Construct an instance of the UploadFileOptions model + caseNumber := "testString" + file := []casemanagementv1.FileWithMetadata{} + uploadFileOptionsModel := testService.NewUploadFileOptions(caseNumber, file) + uploadFileOptionsModel.SetCaseNumber("testString") + uploadFileOptionsModel.SetFile([]casemanagementv1.FileWithMetadata{casemanagementv1.FileWithMetadata{Data: CreateMockReader("This is a mock file."), Filename: core.StringPtr("mockfilename.txt"), }}) + uploadFileOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) + Expect(uploadFileOptionsModel).ToNot(BeNil()) + Expect(uploadFileOptionsModel.CaseNumber).To(Equal(core.StringPtr("testString"))) + Expect(uploadFileOptionsModel.File).To(Equal([]casemanagementv1.FileWithMetadata{casemanagementv1.FileWithMetadata{Data: CreateMockReader("This is a mock file."), Filename: core.StringPtr("mockfilename.txt"), }})) + Expect(uploadFileOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) + }) + It(`Invoke NewUser successfully`, func() { + realm := "IBMid" + userID := "abc@ibm.com" + model, err := testService.NewUser(realm, userID) + Expect(model).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) + It(`Invoke NewAcceptPayload successfully`, func() { + action := "accept" + model, err := testService.NewAcceptPayload(action) + Expect(model).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) + It(`Invoke NewResolvePayload successfully`, func() { + action := "resolve" + resolutionCode := int64(1) + model, err := testService.NewResolvePayload(action, resolutionCode) + Expect(model).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) + It(`Invoke NewUnresolvePayload successfully`, func() { + action := "unresolve" + comment := "testString" + model, err := testService.NewUnresolvePayload(action, comment) + Expect(model).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) + }) + }) + 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) + } +}