1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/pkg/cpi/mockingUtils.go

577 lines
20 KiB
Go
Raw Normal View History

feat(whitesourceExecuteScan): GitHub issue creation + SARIF (#3535) * Add GH issue creation + SARIF * Code cleanup * Fix fmt, add debug * Code enhancements * Fix * Added debug info * Rework UA log scan * Fix code * read UA version * Fix nil reference * Extraction * Credentials * Issue creation * Error handling * Fix issue creation * query escape * Query escape 2 * Revert * Test avoid update * HTTP client * Add support for custom TLS certs * Fix code * Fix code 2 * Fix code 3 * Disable cert check * Fix auth * Remove implicit trust * Skip verification * Fix * Fix client * Fix HTTP auth * Fix trusted certs * Trim version * Code * Add token * Added token handling to client * Fix token * Cleanup * Fix token * Token rework * Fix code * Kick out oauth client * Kick out oauth client * Transport wrapping * Token * Simplification * Refactor * Variation * Check * Fix * Debug * Switch client * Variation * Debug * Switch to cert check * Add debug * Parse self * Cleanup * Update resources/metadata/whitesourceExecuteScan.yaml * Add debug * Expose subjects * Patch * Debug * Debug2 * Debug3 * Fix logging response body * Cleanup * Cleanup * Fix request body logging * Cleanup import * Fix import cycle * Cleanup * Fix fmt * Fix NopCloser reference * Regenerate * Reintroduce * Fix test * Fix tests * Correction * Fix error * Code fix * Fix tests * Add tests * Fix code climate issues * Code climate * Code climate again * Code climate again * Fix fmt * Fix fmt 2 Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2022-02-23 10:30:19 +02:00
//go:build !release
// +build !release
package cpi
import (
"bytes"
"io/ioutil"
"net/http"
"strings"
"github.com/pkg/errors"
)
//GetCPIFunctionMockResponse -Generate mock response payload for different CPI functions
func GetCPIFunctionMockResponse(functionName, testType string) (*http.Response, error) {
switch functionName {
case "IntegrationArtifactDeploy", "PositiveAndUnDeployIntegrationDesigntimeArtifact":
return GetEmptyHTTPResponseBodyAndErrorNil()
case "FailIntegrationDesigntimeArtifactDeployment", "FailedIntegrationRuntimeArtifactUnDeployment":
return GetNegativeCaseHTTPResponseBodyAndErrorNil()
case "IntegrationArtifactUpdateConfiguration":
if testType == "Positive" {
return GetEmptyHTTPResponseBodyAndErrorNil()
}
if testType == "Negative_With_ResponseBody" {
return GetNegativeCaseHTTPResponseBodyAndErrorNil()
}
return GetParameterKeyMissingResponseBody()
New piper step APIProviderDownload contribution (#3349) * added store file function in cpi common utils Change-Id: Ia429a2792266e082d139025a71799d21c30a7df9 * Added api provider steps Change-Id: Icd2829a91db4c53d0de2330822d2b33933973868 * Update apiProviderDownload.yaml * fixed yaml JLINT issue Change-Id: Iac974abc30fa00e68c0177072b93716b0af5e0c5 * Removed trailing spaces Change-Id: I927e9314fce6e9cab68d6b97577c7c96bb2bddad * Resolved common steps groovy script conflict Change-Id: I3ad144b618e1c77953aaeccaa5bf7309aff77ca9 * Change for conflict resolution Change-Id: Ic955833eca844f090b7983f99f9d3649ebb981c7 * Fixed method name and its corresponding implementation Change-Id: I465c1f1d5306bb978386de9efca3c521e385b89c * Moved re-usable function to commonUtils package Change-Id: Ide06462b01caeb2bf438ad7661e01c15bf8e8e24 * Changed the implementation to use existing writeFile method * Fixed review comments on documentation and test structuring Change-Id: Ifebd2f4b50754b2097b2d564fb3cc37c433ef6c9 * Fixed documentation alignment issues * Fixed spaces issue Change-Id: I834bd94e01bce72e7f81ab49ba32671c91c66ca9 * Documentation removed extra spaces Change-Id: I9a639d76ed9b81c870f18349504044bb70753b52 * Fixed doc build issue Change-Id: I96c3e15e73834b64f8b8e3432ce59f6b037f93fd * Fixed documentation build issues Change-Id: I7fca2ba69bc7b7298ee300ccd1ae16a6238dc96b * Re-generated code for fixing build failure Change-Id: I22b7ee6162f643d9f3b60f6a33eb7858927182a0 * Adopted file utils & mock Change-Id: Ic46462003527f41df64395a5a615c19bf374e8ef * Removed ioutil call in the test & adopted error variable names * Removed commented lines Change-Id: I99a12e39bc04323e9c19f1409d97eeca267e6fdb * Added test for asserting file download and adopted error variables Change-Id: I49463a3b75987bf68f5261d45602d2d7bd960a05 * Added download path assertion positive & negative case Change-Id: Ieee461c3973b9dfa8f395dc936e4241ff9694c7b * Modified tests with DownloadPath variable Change-Id: Iaf14c9ea1a8242b6c8d8e9e4fac8c23d9c1b3a74 * Added testcase to validate file content Change-Id: I21aed481b433450c3b536dbb29d45291f61848d8 * Refactored test for file content check to avoid failures Change-Id: I3b4fe9a0de678f437fd4cc0a8203ae9434d9fa8e * Removed auto-generated comments Change-Id: I86c4ac3e7e4476a75d6cbed58826ec1f3278d7d2 * Fixed documentation review comments Change-Id: I4faf31473b53fc53a5517d418c343bf7320eec55 * Fixed documentation indentation Change-Id: I386f046cf4e10ee6deb5a81fcfc8c430c97086c8 * Fix build issue Change-Id: I61a829cabaf03ffd5e77cddc594486a650118fa3
2022-03-09 14:07:23 +02:00
case "IntegrationArtifactGetMplStatus", "APIKeyValueMapDownload", "APIProviderDownload":
return GetIntegrationArtifactGetMplStatusCommandMockResponse(testType)
case "IntegrationArtifactGetServiceEndpoint":
return GetIntegrationArtifactGetServiceEndpointCommandMockResponse(testType)
case "IntegrationArtifactDownload", "APIProxyDownload":
return IntegrationArtifactDownloadCommandMockResponse(testType)
case "GetIntegrationDesigntimeArtifact":
return GetIntegrationDesigntimeArtifactMockResponse(testType)
case "UploadIntegrationDesigntimeArtifact":
return GetIntegrationDesigntimeArtifactMockResponse(testType)
case "UploadIntegrationDesigntimeArtifactNegative":
return GetRespBodyHTTPStatusServiceErrorResponse()
case "UpdateIntegrationDesigntimeArtifactNegative":
return GetRespBodyHTTPStatusServiceErrorResponse()
case "UpdateIntegrationDesigntimeArtifact":
return UpdateIntegrationDesigntimeArtifactMockResponse(testType)
case "IntegrationDesigntimeArtifactUpdate":
return IntegrationDesigntimeArtifactUpdateMockResponse(testType)
case "GetIntegrationArtifactDeployStatus":
return GetIntegrationArtifactDeployStatusMockResponse(testType)
case "GetIntegrationArtifactDeployErrorDetails":
return GetIntegrationArtifactDeployErrorDetailsMockResponse(testType)
case "TriggerIntegrationTest":
return TriggerIntegrationTestMockResponse(testType)
case "IntegrationArtifactGetMplStatusError":
return GetIntegrationArtifactDeployErrorStatusMockResponseBody()
case "IntegrationArtifactResourceCreate", "ApiKeyValueMapUpload":
if testType == "Negative" {
return GetRespBodyHTTPStatusServiceErrorResponse()
}
if testType == "HttpResponseNotAccepted" {
return GetEmptyHTTPResponseBodyAndErrorNil()
}
if testType == "NilHttpResponse" {
return nil, errors.New("invalid payalod")
}
return GetRespBodyHTTPStatusCreated()
case "IntegrationArtifactResourceUpdate", "IntegrationArtifactResourceDelete", "ApiProxyUpload":
return GetRespBodyHTTPStatusOK()
default:
res := http.Response{
StatusCode: 404,
Body: ioutil.NopCloser(bytes.NewReader([]byte(``))),
}
return &res, errors.New("Service not Found")
}
}
//GetEmptyHTTPResponseBodyAndErrorNil -Empty http respose body
func GetEmptyHTTPResponseBodyAndErrorNil() (*http.Response, error) {
res := http.Response{
StatusCode: 202,
Body: ioutil.NopCloser(bytes.NewReader([]byte(``))),
}
return &res, nil
}
//GetParameterKeyMissingResponseBody -Parameter key missing http respose body
func GetParameterKeyMissingResponseBody() (*http.Response, error) {
res := http.Response{
StatusCode: 404,
Body: ioutil.NopCloser(bytes.NewReader([]byte(`{
"code": "Not Found",
"message": {
"@lang": "en",
"#text": "Parameter key 'Parameter1' not found."
}
}`))),
}
return &res, errors.New("Not found - either wrong version for the given Id or wrong parameter key")
}
//GetNegativeCaseHTTPResponseBodyAndErrorNil -Negative case http respose body
func GetNegativeCaseHTTPResponseBodyAndErrorNil() (*http.Response, error) {
res := http.Response{
StatusCode: 400,
Body: ioutil.NopCloser(bytes.NewReader([]byte(`{
"code": "Bad Request",
"message": {
"@lang": "en",
"#text": "Wrong body format for the expected parameter value"
}
}`))),
}
return &res, nil
}
//GetIntegrationArtifactGetMplStatusCommandMockResponse -Provide http respose body
func GetIntegrationArtifactGetMplStatusCommandMockResponse(testType string) (*http.Response, error) {
if testType == "Positive" {
res := http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewReader([]byte(`{
"d": {
"results": [
{
"__metadata": {
"id": "https://roverpoc.it-accd002.cfapps.sap.hana.ondemand.com:443/api/v1/MessageProcessingLogs('AGAS1GcWkfBv-ZtpS6j7TKjReO7t')",
"uri": "https://roverpoc.it-accd002.cfapps.sap.hana.ondemand.com:443/api/v1/MessageProcessingLogs('AGAS1GcWkfBv-ZtpS6j7TKjReO7t')",
"type": "com.sap.hci.api.MessageProcessingLog"
},
"MessageGuid": "AGAS1GcWkfBv-ZtpS6j7TKjReO7t",
"CorrelationId": "AGAS1GevYrPodxieoYf4YSY4jd-8",
"ApplicationMessageId": null,
"ApplicationMessageType": null,
"LogStart": "/Date(1611846759005)/",
"LogEnd": "/Date(1611846759032)/",
"Sender": null,
"Receiver": null,
"IntegrationFlowName": "flow1",
"Status": "COMPLETED",
"LogLevel": "INFO",
"CustomStatus": "COMPLETED",
"TransactionId": "aa220151116748eeae69db3e88f2bbc8"
}
]
}
}`))),
}
return &res, nil
}
res := http.Response{
StatusCode: 400,
Body: ioutil.NopCloser(bytes.NewReader([]byte(`{
"code": "Bad Request",
"message": {
"@lang": "en",
"#text": "Invalid order by expression"
}
}`))),
}
return &res, errors.New("Unable to get integration flow MPL status, Response Status code:400")
}
//GetIntegrationArtifactGetServiceEndpointCommandMockResponse -Provide http respose body
func GetIntegrationArtifactGetServiceEndpointCommandMockResponse(testCaseType string) (*http.Response, error) {
if testCaseType == "PositiveAndGetetIntegrationArtifactGetServiceResBody" {
return GetIntegrationArtifactGetServiceEndpointPositiveCaseRespBody()
}
res := http.Response{
StatusCode: 400,
Body: ioutil.NopCloser(bytes.NewReader([]byte(`{
"code": "Bad Request",
"message": {
"@lang": "en",
"#text": "invalid service endpoint query"
}
}`))),
}
return &res, errors.New("Unable to get integration flow service endpoint, Response Status code:400")
}
//TriggerIntegrationTestMockResponse
func TriggerIntegrationTestMockResponse(testCaseType string) (*http.Response, error) {
if testCaseType == "Positive" {
return &http.Response{
StatusCode: 200,
}, nil
}
res := http.Response{
StatusCode: 400,
Body: ioutil.NopCloser(bytes.NewReader([]byte(`{
"code": "Bad Request",
"message": {
"@lang": "en",
"#text": "invalid"
}
}`))),
}
return &res, errors.New("Unable to trigger integration test, Response Status code:400")
}
//GetIntegrationArtifactGetServiceEndpointPositiveCaseRespBody -Provide http respose body for positive case
func GetIntegrationArtifactGetServiceEndpointPositiveCaseRespBody() (*http.Response, error) {
resp := http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewReader([]byte(`{
"d": {
"results": [
{
"__metadata": {
"id": "https://demo.cfapps.sap.hana.ondemand.com:443/api/v1/ServiceEndpoints('CPI_IFlow_Call_using_Cert%24endpointAddress%3Dtestwithcert')",
"uri": "https://demo.cfapps.sap.hana.ondemand.com:443/api/v1/ServiceEndpoints('CPI_IFlow_Call_using_Cert%24endpointAddress%3Dtestwithcert')",
"type": "com.sap.hci.api.ServiceEndpoint"
},
"Name": "CPI_IFlow_Call_using_Cert",
"Id": "CPI_IFlow_Call_using_Cert$endpointAddress=testwithcert",
"EntryPoints": {
"results": [
{
"__metadata": {
"id": "https://demo.cfapps.sap.hana.ondemand.com:443/api/v1/EntryPoints('https%3A%2F%2Froverpoc.it-accd002-rt.cfapps.sap.hana.ondemand.com%2Fhttp%2Ftestwithcert')",
"uri": "https://demo.cfapps.sap.hana.ondemand.com:443/api/v1/EntryPoints('https%3A%2F%2Froverpoc.it-accd002-rt.cfapps.sap.hana.ondemand.com%2Fhttp%2Ftestwithcert')",
"type": "com.sap.hci.api.EntryPoint"
},
"Name": "CPI_IFlow_Call_using_Cert",
"Url": "https://demo.cfapps.sap.hana.ondemand.com/http/testwithcert",
"Type": "PROD",
"AdditionalInformation": ""
}
]
}
}
]
}
}`))),
}
return &resp, nil
}
//GetRespBodyHTTPStatusOK -Provide http respose body for Http StatusOK
func GetRespBodyHTTPStatusOK() (*http.Response, error) {
resp := http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewReader([]byte(``))),
}
return &resp, nil
}
//GetRespBodyHTTPStatusCreated -Provide http respose body for Http StatusOK
func GetRespBodyHTTPStatusCreated() (*http.Response, error) {
resp := http.Response{
StatusCode: 201,
Body: ioutil.NopCloser(bytes.NewReader([]byte(``))),
}
return &resp, nil
}
//GetRespBodyHTTPStatusServiceNotFound -Provide http respose body for Http URL not Found
func GetRespBodyHTTPStatusServiceNotFound() (*http.Response, error) {
resp := http.Response{
StatusCode: 404,
Body: ioutil.NopCloser(bytes.NewReader([]byte(``))),
}
return &resp, errors.New("Integration Package not found")
}
//GetRespBodyHTTPStatusServiceErrorResponse -Provide http respose body for server error
func GetRespBodyHTTPStatusServiceErrorResponse() (*http.Response, error) {
resp := http.Response{
StatusCode: 500,
Body: ioutil.NopCloser(bytes.NewReader([]byte(``))),
}
return &resp, errors.New("401 Unauthorized")
}
//IntegrationArtifactDownloadCommandMockResponse -Provide http respose body
func IntegrationArtifactDownloadCommandMockResponse(testType string) (*http.Response, error) {
return GetMockResponseByTestTypeAndMockFunctionName("IntegrationArtifactDownloadCommandMockResponse", testType)
}
//GetIntegrationDesigntimeArtifactMockResponse -Provide http respose body
func GetIntegrationDesigntimeArtifactMockResponse(testType string) (*http.Response, error) {
return GetMockResponseByTestTypeAndMockFunctionName("GetIntegrationDesigntimeArtifactMockResponse", testType)
}
//IntegrationDesigntimeArtifactUpdateMockResponse -Provide http respose body
func IntegrationDesigntimeArtifactUpdateMockResponse(testType string) (*http.Response, error) {
return GetMockResponseByTestTypeAndMockFunctionName("IntegrationDesigntimeArtifactUpdateMockResponse", testType)
}
//GetMockResponseByTestTypeAndMockFunctionName - Get mock response by testtype and mock function name
func GetMockResponseByTestTypeAndMockFunctionName(mockFuntionName, testType string) (*http.Response, error) {
response, error := GetPositiveCaseResponseByTestType(testType)
if response == nil && error == nil {
switch mockFuntionName {
case "IntegrationDesigntimeArtifactUpdateMockResponse":
return NegtiveResForIntegrationArtifactGenericCommandMockResponse("Unable to get status of integration artifact, Response Status code:400")
case "GetIntegrationDesigntimeArtifactMockResponse":
return NegtiveResForIntegrationArtifactGenericCommandMockResponse("Unable to get status of integration artifact, Response Status code:400")
case "IntegrationArtifactDownloadCommandMockResponse":
return NegtiveResForIntegrationArtifactGenericCommandMockResponse("Unable to download integration artifact, Response Status code:400")
case "GetIntegrationArtifactDeployStatusMockResponse":
res := http.Response{
StatusCode: 400,
Body: ioutil.NopCloser(bytes.NewReader([]byte(`{
"code": "Bad Request",
"message": {
"@lang": "en",
"#text": "Bad request"
}
}`))),
}
return &res, errors.New("Unable to get integration artifact deploy status, Response Status code:400")
case "GetIntegrationArtifactDeployErrorDetailsMockResponse":
res := http.Response{
StatusCode: 500,
Body: ioutil.NopCloser(bytes.NewReader([]byte(`{
"code": "Internal Server Error",
"message": {
"@lang": "en",
"#text": "Internal Processing Error"
}
}`))),
}
return &res, errors.New("Unable to get integration artifact deploy error status, Response Status code:400")
}
}
return response, error
}
//NegtiveResForIntegrationArtifactGenericCommandMockResponse -Nagative Case http response body
func NegtiveResForIntegrationArtifactGenericCommandMockResponse(message string) (*http.Response, error) {
res := http.Response{
StatusCode: 400,
Body: ioutil.NopCloser(bytes.NewReader([]byte(`{
"code": "Bad Request",
"message": {
"@lang": "en",
"#text": "invalid request"
}
}`))),
}
return &res, errors.New(message)
}
//UpdateIntegrationDesigntimeArtifactMockResponse -Provide http respose body
func UpdateIntegrationDesigntimeArtifactMockResponse(testType string) (*http.Response, error) {
response, error := GetRespBodyHTTPStatusCreated()
if response == nil && error == nil {
res := http.Response{
StatusCode: 400,
Body: ioutil.NopCloser(bytes.NewReader([]byte(`{
"code": "Bad Request",
"message": {
"@lang": "en",
"#text": "invalid request"
}
}`))),
}
return &res, errors.New("Unable to get status of integration artifact, Response Status code:400")
}
return response, error
}
//IntegrationArtifactDownloadCommandMockResponsePositiveCaseRespBody -Provide http respose body for positive case
func IntegrationArtifactDownloadCommandMockResponsePositiveCaseRespBody() (*http.Response, error) {
header := make(http.Header)
headerValue := "attachment; filename=flow1.zip"
header.Add("Content-Disposition", headerValue)
resp := http.Response{
StatusCode: 200,
Header: header,
Body: ioutil.NopCloser(bytes.NewReader([]byte(`UEsDBBQACAgIADQ2clAAAAAAAAAAAAAAAAAUAAQATU`))),
}
return &resp, nil
}
//GetPositiveCaseResponseByTestType - get postive response by test case type
func GetPositiveCaseResponseByTestType(testType string) (*http.Response, error) {
switch testType {
case "PositiveAndGetetIntegrationArtifactDownloadResBody":
return IntegrationArtifactDownloadCommandMockResponsePositiveCaseRespBody()
case "PositiveAndCreateIntegrationDesigntimeArtifactResBody":
return GetRespBodyHTTPStatusOK()
case "NegativeAndCreateIntegrationDesigntimeArtifactResBody":
return GetRespBodyHTTPStatusOK()
case "PositiveAndUpdateIntegrationDesigntimeArtifactResBody":
return GetRespBodyHTTPStatusServiceNotFound()
case "NegativeAndUpdateIntegrationDesigntimeArtifactResBody":
return GetRespBodyHTTPStatusServiceNotFound()
case "PositiveAndDeployIntegrationDesigntimeArtifactResBody":
return GetIntegrationArtifactDeployStatusMockResponseBody()
case "PositiveAndGetDeployedIntegrationDesigntimeArtifactErrorResBody":
return GetIntegrationArtifactDeployErrorStatusMockResponseBody()
case "NegativeAndDeployIntegrationDesigntimeArtifactResBody":
return GetIntegrationArtifactDeployStatusErrorMockResponseBody()
default:
return nil, nil
}
}
//GetCPIFunctionNameByURLCheck - get postive response by test case type
func GetCPIFunctionNameByURLCheck(url, method, testType string) string {
switch url {
case "https://demo/api/v1/IntegrationDesigntimeArtifacts(Id='flow4',Version='1.0.4')":
return GetFunctionNameByTestTypeAndMethod(method, testType)
case "https://demo/api/v1/IntegrationDesigntimeArtifacts(Id='flow4',Version='Active')":
return GetFunctionNameByTestTypeAndMethod(method, testType)
case "https://demo/api/v1/IntegrationDesigntimeArtifacts":
return GetFunctionNameByTestTypeAndMethod(method, testType)
case "https://demo/api/v1/DeployIntegrationDesigntimeArtifact?Id='flow1'&Version='Active'":
return GetFunctionNameByTestTypeAndMethod(method, testType)
case "https://demo/api/v1/IntegrationRuntimeArtifacts('flow1')":
return "GetIntegrationArtifactDeployStatus"
case "https://demo/api/v1/IntegrationRuntimeArtifacts('flow1')/ErrorInformation/$value":
return "GetIntegrationArtifactDeployErrorDetails"
default:
return ""
}
}
//GetFunctionNameByTestTypeAndMethod -get function name by test tyep
func GetFunctionNameByTestTypeAndMethod(method, testType string) string {
switch testType {
case "PositiveAndCreateIntegrationDesigntimeArtifactResBody":
return GetFunctionNamePositiveAndCreateIntegrationDesigntimeArtifactResBody(method)
case "PositiveAndUpdateIntegrationDesigntimeArtifactResBody":
return GetFunctionNamePositiveAndUpdateIntegrationDesigntimeArtifactResBody(method)
case "NegativeAndGetIntegrationDesigntimeArtifactResBody":
if method == "GET" {
return "GetIntegrationDesigntimeArtifact"
}
case "NegativeAndCreateIntegrationDesigntimeArtifactResBody":
if method == "GET" {
return "GetIntegrationDesigntimeArtifact"
}
if method == "PUT" {
return "UploadIntegrationDesigntimeArtifactNegative"
}
case "NegativeAndUpdateIntegrationDesigntimeArtifactResBody":
if method == "GET" {
return "GetIntegrationDesigntimeArtifact"
}
if method == "POST" {
return "UpdateIntegrationDesigntimeArtifactNegative"
}
case "PositiveAndDeployIntegrationDesigntimeArtifactResBody", "NegativeAndDeployIntegrationDesigntimeArtifactResBody":
if method == "POST" {
return "IntegrationArtifactDeploy"
}
default:
return ""
}
return ""
}
//GetFunctionNamePositiveAndUpdateIntegrationDesigntimeArtifactResBody -Get Function Name
func GetFunctionNamePositiveAndUpdateIntegrationDesigntimeArtifactResBody(method string) string {
if method == "GET" {
return "IntegrationDesigntimeArtifactUpdate"
}
if method == "POST" {
return "UpdateIntegrationDesigntimeArtifact"
}
return ""
}
//GetFunctionNamePositiveAndCreateIntegrationDesigntimeArtifactResBody -Get Function Name
func GetFunctionNamePositiveAndCreateIntegrationDesigntimeArtifactResBody(method string) string {
if method == "GET" {
return "GetIntegrationDesigntimeArtifact"
}
if method == "PUT" {
return "UploadIntegrationDesigntimeArtifact"
}
return ""
}
//GetIntegrationArtifactDeployStatusMockResponse -Provide http respose body
func GetIntegrationArtifactDeployStatusMockResponse(testType string) (*http.Response, error) {
return GetMockResponseByTestTypeAndMockFunctionName("GetIntegrationArtifactDeployStatusMockResponse", testType)
}
//GetIntegrationArtifactDeployErrorDetailsMockResponse -Provide http respose body
func GetIntegrationArtifactDeployErrorDetailsMockResponse(testType string) (*http.Response, error) {
return GetMockResponseByTestTypeAndMockFunctionName("GetIntegrationArtifactDeployErrorDetailsMockResponse", "PositiveAndGetDeployedIntegrationDesigntimeArtifactErrorResBody")
}
//GetIntegrationArtifactDeployStatusMockResponseBody -Provide http respose body
func GetIntegrationArtifactDeployStatusMockResponseBody() (*http.Response, error) {
resp := http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewReader([]byte(GetIntegrationArtifactDeployStatusPayload("STARTED")))),
}
return &resp, nil
}
//GetIntegrationArtifactDeployStatusErrorMockResponseBody -Provide http respose body
func GetIntegrationArtifactDeployStatusErrorMockResponseBody() (*http.Response, error) {
resp := http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewReader([]byte(GetIntegrationArtifactDeployStatusPayload("ERROR")))),
}
return &resp, nil
}
//GetIntegrationArtifactDeployStatusPayload -Get Payload
func GetIntegrationArtifactDeployStatusPayload(status string) string {
jsonByte := []byte(`{
"d": {
"__metadata": {
"id": "https://roverpoc.it-accd002.cfapps.sap.hana.ondemand.com/api/v1/IntegrationRuntimeArtifacts('smtp')",
"uri": "https://roverpoc.it-accd002.cfapps.sap.hana.ondemand.com/api/v1/IntegrationRuntimeArtifacts('smtp')",
"media_src": "https://roverpoc.it-accd002.cfapps.sap.hana.ondemand.com/api/v1/IntegrationRuntimeArtifacts('smtp')/$value",
"edit_media": "https://roverpoc.it-accd002.cfapps.sap.hana.ondemand.com/api/v1/IntegrationRuntimeArtifacts('smtp')/$value"
},
"Id": "smtp",
"Version": "2.0",
"Name": "smtp",
"Status": "StatusValue",
"ErrorInformation": {
"__deferred": {
"uri": "https://roverpoc.it-accd002.cfapps.sap.hana.ondemand.com/api/v1/IntegrationRuntimeArtifacts('smtp')/ErrorInformation"
}
}
}
}`)
return strings.Replace(string(jsonByte), "StatusValue", status, 1)
}
//GetIntegrationArtifactDeployErrorStatusMockResponseBody -Provide http respose body
func GetIntegrationArtifactDeployErrorStatusMockResponseBody() (*http.Response, error) {
resp := http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewReader([]byte(`{"message": "java.lang.IllegalStateException: No credentials for 'smtp' found"}`))),
}
return &resp, nil
}