1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-04-11 11:41:53 +02:00

IntegrationArtifact Cmd Fixes (#2628)

* IntegrationArtifact Cmd Fixes

* CodeClimate Fixes

* CodeClimate Fix

* integrationArtifactDownload Command Fix

* CodeClimate Fixes

* CodeReview Fixes

* CodeReview Fixes

* CodeReview Fixes

* CodeReview Fixes

* CodeReview Fixes

* CodeReview Fixes

* CodeReview FIxes

* CodeReview Fixes

Co-authored-by: Oliver Feldmann <oliver.feldmann@sap.com>
This commit is contained in:
Mayur Belur Mohan 2021-03-11 16:33:32 +05:30 committed by GitHub
parent b81b11ca9d
commit 1b27805f64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 366 additions and 70 deletions

View File

@ -4,7 +4,9 @@ import (
"fmt"
"io/ioutil"
"net/http"
"time"
"github.com/Jeffail/gabs/v2"
"github.com/SAP/jenkins-library/pkg/command"
"github.com/SAP/jenkins-library/pkg/cpi"
piperhttp "github.com/SAP/jenkins-library/pkg/http"
@ -13,6 +15,8 @@ import (
"github.com/pkg/errors"
)
const retryCount = 14
type integrationArtifactDeployUtils interface {
command.ExecRunner
@ -62,10 +66,8 @@ func integrationArtifactDeploy(config integrationArtifactDeployOptions, telemetr
func runIntegrationArtifactDeploy(config *integrationArtifactDeployOptions, telemetryData *telemetry.CustomData, httpClient piperhttp.Sender) error {
clientOptions := piperhttp.ClientOptions{}
httpClient.SetOptions(clientOptions)
header := make(http.Header)
header.Add("Accept", "application/json")
deployURL := fmt.Sprintf("%s/api/v1/DeployIntegrationDesigntimeArtifact?Id='%s'&Version='%s'", config.Host, config.IntegrationFlowID, config.IntegrationFlowVersion)
tokenParameters := cpi.TokenParameters{TokenURL: config.OAuthTokenProviderURL, Username: config.Username, Password: config.Password, Client: httpClient}
token, err := cpi.CommonUtils.GetBearerToken(tokenParameters)
@ -92,14 +94,134 @@ func runIntegrationArtifactDeploy(config *integrationArtifactDeployOptions, tele
log.Entry().
WithField("IntegrationFlowID", config.IntegrationFlowID).
Info("successfully deployed into CPI runtime")
return nil
deploymentError := pollIFlowDeploymentStatus(retryCount, config, httpClient)
return deploymentError
}
responseBody, readErr := ioutil.ReadAll(deployResp.Body)
if readErr != nil {
return errors.Wrapf(readErr, "HTTP response body could not be read, Response status code : %v", deployResp.StatusCode)
return errors.Wrapf(readErr, "HTTP response body could not be read, response status code: %v", deployResp.StatusCode)
}
log.Entry().Errorf("a HTTP error occurred! Response body: %v, Response status code : %v", responseBody, deployResp.StatusCode)
return errors.Errorf("integration flow deployment failed, response Status code: %v", deployResp.StatusCode)
}
//pollIFlowDeploymentStatus - Poll the integration flow deployment status, return status or error details
func pollIFlowDeploymentStatus(retryCount int, config *integrationArtifactDeployOptions, httpClient piperhttp.Sender) error {
if retryCount <= 0 {
return errors.New("failed to start integration artifact after retrying several times")
}
deployStatus, err := getIntegrationArtifactDeployStatus(config, httpClient)
if err != nil {
return err
}
log.Entry().Errorf("a HTTP error occurred! Response body: %v, Response status code : %v", responseBody, deployResp.StatusCode)
return errors.Errorf("Integration Flow deployment failed, Response Status code: %v", deployResp.StatusCode)
//if artifact starting, then retry based on provided retry count
//with specific delay between each retry
if deployStatus == "STARTING" {
// Calling Sleep method
sleepTime := int(retryCount * 3)
time.Sleep(time.Duration(sleepTime) * time.Second)
retryCount--
return pollIFlowDeploymentStatus(retryCount, config, httpClient)
}
//if artifact started, then just return
if deployStatus == "STARTED" {
return nil
}
//if error return immediately with error details
if deployStatus == "ERROR" {
resp, err := getIntegrationArtifactDeployError(config, httpClient)
if err != nil {
return err
}
return errors.New(resp)
}
return nil
}
//GetHTTPErrorMessage - Return HTTP failure message
func getHTTPErrorMessage(httpErr error, response *http.Response, httpMethod, statusURL string) (string, error) {
responseBody, readErr := ioutil.ReadAll(response.Body)
if readErr != nil {
return "", errors.Wrapf(readErr, "HTTP response body could not be read, response status code: %v", response.StatusCode)
}
log.Entry().Errorf("a HTTP error occurred! Response body: %v, response status code: %v", string(responseBody), response.StatusCode)
return "", errors.Wrapf(httpErr, "HTTP %v request to %v failed with error: %v", httpMethod, statusURL, responseBody)
}
//getIntegrationArtifactDeployStatus - Get integration artifact Deploy Status
func getIntegrationArtifactDeployStatus(config *integrationArtifactDeployOptions, httpClient piperhttp.Sender) (string, error) {
httpMethod := "GET"
header := make(http.Header)
header.Add("content-type", "application/json")
header.Add("Accept", "application/json")
deployStatusURL := fmt.Sprintf("%s/api/v1/IntegrationRuntimeArtifacts('%s')", config.Host, config.IntegrationFlowID)
deployStatusResp, httpErr := httpClient.SendRequest(httpMethod, deployStatusURL, nil, header, nil)
if deployStatusResp != nil && deployStatusResp.Body != nil {
defer deployStatusResp.Body.Close()
}
if deployStatusResp == nil {
return "", errors.Errorf("did not retrieve a HTTP response: %v", httpErr)
}
if deployStatusResp.StatusCode == http.StatusOK {
log.Entry().
WithField("IntegrationFlowID", config.IntegrationFlowID).
Info("Successfully started integration flow artefact in CPI runtime")
bodyText, readErr := ioutil.ReadAll(deployStatusResp.Body)
if readErr != nil {
return "", errors.Wrapf(readErr, "HTTP response body could not be read, response status code: %v", deployStatusResp.StatusCode)
}
jsonResponse, parsingErr := gabs.ParseJSON([]byte(bodyText))
if parsingErr != nil {
return "", errors.Wrapf(parsingErr, "HTTP response body could not be parsed as JSON: %v", string(bodyText))
}
deployStatus := jsonResponse.Path("d.Status").Data().(string)
return deployStatus, nil
}
if httpErr != nil {
return getHTTPErrorMessage(httpErr, deployStatusResp, httpMethod, deployStatusURL)
}
return "", errors.Errorf("failed to get Integration Flow artefact runtime status, response Status code: %v", deployStatusResp.StatusCode)
}
//getIntegrationArtifactDeployError - Get integration artifact deploy error details
func getIntegrationArtifactDeployError(config *integrationArtifactDeployOptions, httpClient piperhttp.Sender) (string, error) {
httpMethod := "GET"
header := make(http.Header)
header.Add("content-type", "application/json")
errorStatusURL := fmt.Sprintf("%s/api/v1/IntegrationRuntimeArtifacts('%s')/ErrorInformation/$value", config.Host, config.IntegrationFlowID)
errorStatusResp, httpErr := httpClient.SendRequest(httpMethod, errorStatusURL, nil, header, nil)
if errorStatusResp != nil && errorStatusResp.Body != nil {
defer errorStatusResp.Body.Close()
}
if errorStatusResp == nil {
return "", errors.Errorf("did not retrieve a HTTP response: %v", httpErr)
}
if errorStatusResp.StatusCode == http.StatusOK {
log.Entry().
WithField("IntegrationFlowID", config.IntegrationFlowID).
Info("Successfully retrieved Integration Flow artefact deploy error details")
responseBody, readErr := ioutil.ReadAll(errorStatusResp.Body)
if readErr != nil {
return "", errors.Wrapf(readErr, "HTTP response body could not be read, response status code: %v", errorStatusResp.StatusCode)
}
log.Entry().Errorf("a HTTP error occurred! Response body: %v, Response status code: %v", responseBody, errorStatusResp.StatusCode)
errorDetails := string(responseBody)
return errorDetails, nil
}
if httpErr != nil {
return getHTTPErrorMessage(httpErr, errorStatusResp, httpMethod, errorStatusURL)
}
return "", errors.Errorf("failed to get Integration Flow artefact deploy error details, response Status code: %v", errorStatusResp.StatusCode)
}

View File

@ -2,6 +2,7 @@ package cmd
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
@ -39,12 +40,40 @@ func TestRunIntegrationArtifactDeploy(t *testing.T) {
Platform: "cf",
}
httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactDeploy", ResponseBody: ``, TestType: "Positive"}
httpClient := httpMockCpis{CPIFunction: "", ResponseBody: ``, TestType: "PositiveAndDeployIntegrationDesigntimeArtifactResBody"}
err := runIntegrationArtifactDeploy(&config, nil, &httpClient)
if assert.NoError(t, err) {
t.Run("check url", func(t *testing.T) {
assert.Equal(t, "https://demo/api/v1/IntegrationRuntimeArtifacts('flow1')", httpClient.URL)
})
t.Run("check method", func(t *testing.T) {
assert.Equal(t, "GET", httpClient.Method)
})
}
})
t.Run("Trigger Failure for Integration Flow Deployment", func(t *testing.T) {
config := integrationArtifactDeployOptions{
Host: "https://demo",
OAuthTokenProviderURL: "https://demo/oauth/token",
Username: "demouser",
Password: "******",
IntegrationFlowID: "flow1",
IntegrationFlowVersion: "1.0.1",
Platform: "cf",
}
httpClient := httpMockCpis{CPIFunction: "FailIntegrationDesigntimeArtifactDeployment", ResponseBody: ``, TestType: "Negative"}
err := runIntegrationArtifactDeploy(&config, nil, &httpClient)
if assert.Error(t, err) {
t.Run("check url", func(t *testing.T) {
assert.Equal(t, "https://demo/api/v1/DeployIntegrationDesigntimeArtifact?Id='flow1'&Version='1.0.1'", httpClient.URL)
})
@ -55,7 +84,8 @@ func TestRunIntegrationArtifactDeploy(t *testing.T) {
}
})
t.Run("Failed case of Integration Flow Deploy Test", func(t *testing.T) {
t.Run("Failed Integration Flow Deploy Test", func(t *testing.T) {
config := integrationArtifactDeployOptions{
Host: "https://demo",
OAuthTokenProviderURL: "https://demo/oauth/token",
@ -66,13 +96,56 @@ func TestRunIntegrationArtifactDeploy(t *testing.T) {
Platform: "cf",
}
httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactDeploy", ResponseBody: ``, TestType: "Negative"}
httpClient := httpMockCpis{CPIFunction: "", ResponseBody: ``, TestType: "NegativeAndDeployIntegrationDesigntimeArtifactResBody"}
err := runIntegrationArtifactDeploy(&config, nil, &httpClient)
assert.EqualError(t, err, "HTTP POST request to https://demo/api/v1/DeployIntegrationDesigntimeArtifact?Id='flow1'&Version='1.0.1' failed with error: Internal Server Error")
assert.EqualError(t, err, "{\"message\": \"java.lang.IllegalStateException: No credentials for 'smtp' found\"}")
})
t.Run("Successfull GetIntegrationArtifactDeployStatus Test", func(t *testing.T) {
clientOptions := piperhttp.ClientOptions{}
clientOptions.Token = fmt.Sprintf("Bearer %s", "Demo")
config := integrationArtifactDeployOptions{
Host: "https://demo",
OAuthTokenProviderURL: "https://demo/oauth/token",
Username: "demouser",
Password: "******",
IntegrationFlowID: "flow1",
IntegrationFlowVersion: "1.0.1",
Platform: "cf",
}
httpClient := httpMockCpis{CPIFunction: "GetIntegrationArtifactDeployStatus", Options: clientOptions, ResponseBody: ``, TestType: "PositiveAndDeployIntegrationDesigntimeArtifactResBody"}
resp, err := getIntegrationArtifactDeployStatus(&config, &httpClient)
assert.Equal(t, "STARTED", resp)
assert.NoError(t, err)
})
t.Run("Successfull GetIntegrationArtifactDeployError Test", func(t *testing.T) {
clientOptions := piperhttp.ClientOptions{}
clientOptions.Token = fmt.Sprintf("Bearer %s", "Demo")
config := integrationArtifactDeployOptions{
Host: "https://demo",
OAuthTokenProviderURL: "https://demo/oauth/token",
Username: "demouser",
Password: "******",
IntegrationFlowID: "flow1",
IntegrationFlowVersion: "1.0.1",
Platform: "cf",
}
httpClient := httpMockCpis{CPIFunction: "GetIntegrationArtifactDeployErrorDetails", Options: clientOptions, ResponseBody: ``, TestType: "PositiveAndGetDeployedIntegrationDesigntimeArtifactErrorResBody"}
resp, err := getIntegrationArtifactDeployError(&config, &httpClient)
assert.Equal(t, "{\"message\": \"java.lang.IllegalStateException: No credentials for 'smtp' found\"}", resp)
assert.NoError(t, err)
})
}
type httpMockCpis struct {

View File

@ -95,7 +95,7 @@ func runIntegrationArtifactDownload(config *integrationArtifactDownloadOptions,
if downloadResp.StatusCode == 200 {
workspaceRelativePath := config.DownloadPath
err = os.MkdirAll(workspaceRelativePath, 755)
err = os.MkdirAll(workspaceRelativePath, 0755)
if err != nil {
return errors.Wrapf(err, "Failed to create workspace directory")
}

View File

@ -61,11 +61,13 @@ func TestRunIntegrationArtifactGetMplStatus(t *testing.T) {
Platform: "cf",
}
httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactDeploy", ResponseBody: ``, TestType: "Negative"}
httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactGetMplStatus", ResponseBody: ``, TestType: "Negative"}
seOut := integrationArtifactGetMplStatusCommonPipelineEnvironment{}
err := runIntegrationArtifactGetMplStatus(&config, nil, &httpClient, &seOut)
assert.EqualValues(t, seOut.custom.iFlowMplStatus, "")
assert.EqualError(t, err, "HTTP GET request to https://demo/api/v1/MessageProcessingLogs?$filter=IntegrationArtifact/Id+eq+'flow1'&$orderby=LogEnd+desc&$top=1 failed with error: Internal Server Error")
assert.EqualError(t, err, "HTTP GET request to https://demo/api/v1/MessageProcessingLogs?$filter=IntegrationArtifact/"+
"Id+eq+'flow1'&$orderby=LogEnd+desc&$top=1 failed with error: "+
"Unable to get integration flow MPL status, Response Status code:400")
})
}

View File

@ -131,6 +131,7 @@ func Execute() {
rootCmd.AddCommand(TransportRequestUploadSOLMANCommand())
rootCmd.AddCommand(IntegrationArtifactUpdateConfigurationCommand())
rootCmd.AddCommand(IntegrationArtifactGetMplStatusCommand())
rootCmd.AddCommand(IntegrationArtifactGetServiceEndpointCommand())
rootCmd.AddCommand(IntegrationArtifactDownloadCommand())
rootCmd.AddCommand(AbapEnvironmentAssembleConfirmCommand())
rootCmd.AddCommand(IntegrationArtifactUploadCommand())

View File

@ -6,6 +6,7 @@ import (
"bytes"
"io/ioutil"
"net/http"
"strings"
"github.com/pkg/errors"
)
@ -14,20 +15,9 @@ import (
func GetCPIFunctionMockResponse(functionName, testType string) (*http.Response, error) {
switch functionName {
case "IntegrationArtifactDeploy":
if testType == "Positive" {
return GetEmptyHTTPResponseBodyAndErrorNil()
}
res := http.Response{
StatusCode: 500,
Body: ioutil.NopCloser(bytes.NewReader([]byte(`{
"code": "Internal Server Error",
"message": {
"@lang": "en",
"#text": "Cannot deploy artifact with Id 'flow1'!"
}
}`))),
}
return &res, errors.New("Internal Server Error")
return GetEmptyHTTPResponseBodyAndErrorNil()
case "FailIntegrationDesigntimeArtifactDeployment":
return GetNegativeCaseHTTPResponseBodyAndErrorNil()
case "IntegrationArtifactUpdateConfiguration":
if testType == "Positive" {
return GetEmptyHTTPResponseBodyAndErrorNil()
@ -54,6 +44,10 @@ func GetCPIFunctionMockResponse(functionName, testType string) (*http.Response,
return UpdateIntegrationDesigntimeArtifactMockResponse(testType)
case "IntegrationDesigntimeArtifactUpdate":
return IntegrationDesigntimeArtifactUpdateMockResponse(testType)
case "GetIntegrationArtifactDeployStatus":
return GetIntegrationArtifactDeployStatusMockResponse(testType)
case "GetIntegrationArtifactDeployErrorDetails":
return GetIntegrationArtifactDeployErrorDetailsMockResponse(testType)
default:
res := http.Response{
StatusCode: 404,
@ -269,10 +263,23 @@ func GetMockResponseByTestTypeAndMockFunctionName(mockFuntionName, testType stri
response, error := GetPositiveCaseResponseByTestType(testType)
switch mockFuntionName {
if response == nil && error == nil {
case "IntegrationDesigntimeArtifactUpdateMockResponse":
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,
@ -280,48 +287,45 @@ func GetMockResponseByTestTypeAndMockFunctionName(mockFuntionName, testType stri
"code": "Bad Request",
"message": {
"@lang": "en",
"#text": "invalid request"
"#text": "Bad request"
}
}`))),
}
return &res, errors.New("Unable to get status of integration artifact, Response Status code:400")
}
case "GetIntegrationDesigntimeArtifactMockResponse":
if response == nil && error == nil {
return &res, errors.New("Unable to get integration artifact deploy status, Response Status code:400")
case "GetIntegrationArtifactDeployErrorDetailsMockResponse":
res := http.Response{
StatusCode: 400,
StatusCode: 500,
Body: ioutil.NopCloser(bytes.NewReader([]byte(`{
"code": "Bad Request",
"code": "Internal Server Error",
"message": {
"@lang": "en",
"#text": "invalid request"
"#text": "Internal Processing Error"
}
}`))),
}
return &res, errors.New("Unable to get status of integration artifact, Response Status code:400")
return &res, errors.New("Unable to get integration artifact deploy error status, Response Status code:400")
}
case "IntegrationArtifactDownloadCommandMockResponse":
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 download integration artifact, 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) {
@ -370,6 +374,12 @@ func GetPositiveCaseResponseByTestType(testType string) (*http.Response, error)
return GetRespBodyHTTPStatusServiceNotFound()
case "NegativeAndUpdateIntegrationDesigntimeArtifactResBody":
return GetRespBodyHTTPStatusServiceNotFound()
case "PositiveAndDeployIntegrationDesigntimeArtifactResBody":
return GetIntegrationArtifactDeployStatusMockResponseBody()
case "PositiveAndGetDeployedIntegrationDesigntimeArtifactErrorResBody":
return GetIntegrationArtifactDeployErrorStatusMockResponseBody()
case "NegativeAndDeployIntegrationDesigntimeArtifactResBody":
return GetIntegrationArtifactDeployStatusErrorMockResponseBody()
default:
return nil, nil
}
@ -386,7 +396,12 @@ func GetCPIFunctionNameByURLCheck(url, method, testType string) string {
case "https://demo/api/v1/IntegrationDesigntimeArtifacts":
return GetFunctionNameByTestTypeAndMethod(method, testType)
case "https://demo/api/v1/DeployIntegrationDesigntimeArtifact?Id='flow1'&Version='1.0.1'":
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 ""
}
@ -398,21 +413,10 @@ func GetFunctionNameByTestTypeAndMethod(method, testType string) string {
switch testType {
case "PositiveAndCreateIntegrationDesigntimeArtifactResBody":
if method == "GET" {
return "GetIntegrationDesigntimeArtifact"
}
if method == "POST" {
return "UploadIntegrationDesigntimeArtifact"
}
return GetFunctionNamePositiveAndCreateIntegrationDesigntimeArtifactResBody(method)
case "PositiveAndUpdateIntegrationDesigntimeArtifactResBody":
if method == "GET" {
return "IntegrationDesigntimeArtifactUpdate"
}
if method == "POST" {
return "UpdateIntegrationDesigntimeArtifact"
}
return GetFunctionNamePositiveAndUpdateIntegrationDesigntimeArtifactResBody(method)
case "NegativeAndGetIntegrationDesigntimeArtifactResBody":
if method == "GET" {
return "GetIntegrationDesigntimeArtifact"
@ -433,9 +437,103 @@ func GetFunctionNameByTestTypeAndMethod(method, testType string) string {
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 == "POST" {
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
}