2022-02-23 10:30:19 +02:00
|
|
|
//go:build !release
|
2021-01-12 13:17:42 +02:00
|
|
|
// +build !release
|
|
|
|
|
|
|
|
package cpi
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2023-08-16 12:57:04 +02:00
|
|
|
"io"
|
2021-01-12 13:17:42 +02:00
|
|
|
"net/http"
|
2021-03-11 13:03:32 +02:00
|
|
|
"strings"
|
2021-01-12 13:17:42 +02:00
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// GetCPIFunctionMockResponse -Generate mock response payload for different CPI functions
|
2021-01-12 13:17:42 +02:00
|
|
|
func GetCPIFunctionMockResponse(functionName, testType string) (*http.Response, error) {
|
|
|
|
switch functionName {
|
2021-08-02 16:27:16 +02:00
|
|
|
case "IntegrationArtifactDeploy", "PositiveAndUnDeployIntegrationDesigntimeArtifact":
|
2021-03-11 13:03:32 +02:00
|
|
|
return GetEmptyHTTPResponseBodyAndErrorNil()
|
2021-08-02 16:27:16 +02:00
|
|
|
case "FailIntegrationDesigntimeArtifactDeployment", "FailedIntegrationRuntimeArtifactUnDeployment":
|
2021-03-11 13:03:32 +02:00
|
|
|
return GetNegativeCaseHTTPResponseBodyAndErrorNil()
|
2021-01-29 10:46:47 +02:00
|
|
|
case "IntegrationArtifactUpdateConfiguration":
|
|
|
|
if testType == "Positive" {
|
|
|
|
return GetEmptyHTTPResponseBodyAndErrorNil()
|
|
|
|
}
|
|
|
|
if testType == "Negative_With_ResponseBody" {
|
|
|
|
return GetNegativeCaseHTTPResponseBodyAndErrorNil()
|
|
|
|
}
|
2021-02-17 10:59:56 +02:00
|
|
|
return GetParameterKeyMissingResponseBody()
|
2022-03-09 14:07:23 +02:00
|
|
|
case "IntegrationArtifactGetMplStatus", "APIKeyValueMapDownload", "APIProviderDownload":
|
2021-02-04 11:50:15 +02:00
|
|
|
return GetIntegrationArtifactGetMplStatusCommandMockResponse(testType)
|
2021-02-05 11:35:55 +02:00
|
|
|
case "IntegrationArtifactGetServiceEndpoint":
|
|
|
|
return GetIntegrationArtifactGetServiceEndpointCommandMockResponse(testType)
|
2021-11-02 11:30:08 +02:00
|
|
|
case "IntegrationArtifactDownload", "APIProxyDownload":
|
2021-02-10 18:08:23 +02:00
|
|
|
return IntegrationArtifactDownloadCommandMockResponse(testType)
|
2021-02-17 10:59:56 +02:00
|
|
|
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)
|
2021-03-11 13:03:32 +02:00
|
|
|
case "GetIntegrationArtifactDeployStatus":
|
|
|
|
return GetIntegrationArtifactDeployStatusMockResponse(testType)
|
|
|
|
case "GetIntegrationArtifactDeployErrorDetails":
|
|
|
|
return GetIntegrationArtifactDeployErrorDetailsMockResponse(testType)
|
2021-06-29 14:50:19 +02:00
|
|
|
case "TriggerIntegrationTest":
|
|
|
|
return TriggerIntegrationTestMockResponse(testType)
|
2021-07-28 12:00:41 +02:00
|
|
|
case "IntegrationArtifactGetMplStatusError":
|
|
|
|
return GetIntegrationArtifactDeployErrorStatusMockResponseBody()
|
2022-03-07 12:03:44 +02:00
|
|
|
case "IntegrationArtifactResourceCreate", "ApiKeyValueMapUpload":
|
2021-08-12 09:11:02 +02:00
|
|
|
if testType == "Negative" {
|
|
|
|
return GetRespBodyHTTPStatusServiceErrorResponse()
|
|
|
|
}
|
2022-03-07 12:03:44 +02:00
|
|
|
if testType == "HttpResponseNotAccepted" {
|
|
|
|
return GetEmptyHTTPResponseBodyAndErrorNil()
|
|
|
|
}
|
|
|
|
if testType == "NilHttpResponse" {
|
|
|
|
return nil, errors.New("invalid payalod")
|
|
|
|
}
|
2021-08-12 09:11:02 +02:00
|
|
|
return GetRespBodyHTTPStatusCreated()
|
2021-12-28 10:31:50 +02:00
|
|
|
case "IntegrationArtifactResourceUpdate", "IntegrationArtifactResourceDelete", "ApiProxyUpload":
|
2021-08-12 09:11:02 +02:00
|
|
|
return GetRespBodyHTTPStatusOK()
|
2021-01-12 13:17:42 +02:00
|
|
|
default:
|
|
|
|
res := http.Response{
|
|
|
|
StatusCode: 404,
|
2023-08-16 12:57:04 +02:00
|
|
|
Body: io.NopCloser(bytes.NewReader([]byte(``))),
|
2021-01-12 13:17:42 +02:00
|
|
|
}
|
|
|
|
return &res, errors.New("Service not Found")
|
|
|
|
}
|
|
|
|
}
|
2021-01-22 16:55:50 +02:00
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// GetEmptyHTTPResponseBodyAndErrorNil -Empty http respose body
|
2021-01-29 10:46:47 +02:00
|
|
|
func GetEmptyHTTPResponseBodyAndErrorNil() (*http.Response, error) {
|
2021-01-22 16:55:50 +02:00
|
|
|
res := http.Response{
|
|
|
|
StatusCode: 202,
|
2023-08-16 12:57:04 +02:00
|
|
|
Body: io.NopCloser(bytes.NewReader([]byte(``))),
|
2021-01-22 16:55:50 +02:00
|
|
|
}
|
|
|
|
return &res, nil
|
|
|
|
}
|
2021-01-29 10:46:47 +02:00
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// GetParameterKeyMissingResponseBody -Parameter key missing http respose body
|
2021-02-17 10:59:56 +02:00
|
|
|
func GetParameterKeyMissingResponseBody() (*http.Response, error) {
|
|
|
|
res := http.Response{
|
|
|
|
StatusCode: 404,
|
2023-08-16 12:57:04 +02:00
|
|
|
Body: io.NopCloser(bytes.NewReader([]byte(`{
|
2021-02-17 10:59:56 +02:00
|
|
|
"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")
|
|
|
|
}
|
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// GetNegativeCaseHTTPResponseBodyAndErrorNil -Negative case http respose body
|
2021-01-29 10:46:47 +02:00
|
|
|
func GetNegativeCaseHTTPResponseBodyAndErrorNil() (*http.Response, error) {
|
|
|
|
res := http.Response{
|
|
|
|
StatusCode: 400,
|
2023-08-16 12:57:04 +02:00
|
|
|
Body: io.NopCloser(bytes.NewReader([]byte(`{
|
2021-01-29 10:46:47 +02:00
|
|
|
"code": "Bad Request",
|
|
|
|
"message": {
|
|
|
|
"@lang": "en",
|
|
|
|
"#text": "Wrong body format for the expected parameter value"
|
|
|
|
}
|
|
|
|
}`))),
|
|
|
|
}
|
|
|
|
return &res, nil
|
|
|
|
}
|
2021-02-04 11:50:15 +02:00
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// GetIntegrationArtifactGetMplStatusCommandMockResponse -Provide http respose body
|
2021-02-04 11:50:15 +02:00
|
|
|
func GetIntegrationArtifactGetMplStatusCommandMockResponse(testType string) (*http.Response, error) {
|
|
|
|
if testType == "Positive" {
|
|
|
|
res := http.Response{
|
|
|
|
StatusCode: 200,
|
2023-08-16 12:57:04 +02:00
|
|
|
Body: io.NopCloser(bytes.NewReader([]byte(`{
|
2021-02-04 11:50:15 +02:00
|
|
|
"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,
|
2023-08-16 12:57:04 +02:00
|
|
|
Body: io.NopCloser(bytes.NewReader([]byte(`{
|
2021-02-04 11:50:15 +02:00
|
|
|
"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")
|
|
|
|
}
|
2021-02-05 11:35:55 +02:00
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// GetIntegrationArtifactGetServiceEndpointCommandMockResponse -Provide http respose body
|
2021-02-05 11:35:55 +02:00
|
|
|
func GetIntegrationArtifactGetServiceEndpointCommandMockResponse(testCaseType string) (*http.Response, error) {
|
|
|
|
if testCaseType == "PositiveAndGetetIntegrationArtifactGetServiceResBody" {
|
|
|
|
return GetIntegrationArtifactGetServiceEndpointPositiveCaseRespBody()
|
|
|
|
}
|
|
|
|
res := http.Response{
|
|
|
|
StatusCode: 400,
|
2023-08-16 12:57:04 +02:00
|
|
|
Body: io.NopCloser(bytes.NewReader([]byte(`{
|
2021-02-05 11:35:55 +02:00
|
|
|
"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")
|
|
|
|
}
|
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// TriggerIntegrationTestMockResponse
|
2021-06-29 14:50:19 +02:00
|
|
|
func TriggerIntegrationTestMockResponse(testCaseType string) (*http.Response, error) {
|
|
|
|
if testCaseType == "Positive" {
|
|
|
|
return &http.Response{
|
|
|
|
StatusCode: 200,
|
2023-08-16 12:57:04 +02:00
|
|
|
Body: io.NopCloser(bytes.NewReader([]byte(`{
|
2023-03-27 16:34:59 +02:00
|
|
|
"code": "Good Request",
|
|
|
|
"message": {
|
|
|
|
"@lang": "en",
|
|
|
|
"#text": "valid"
|
|
|
|
}
|
|
|
|
}`))),
|
|
|
|
Header: map[string][]string{
|
|
|
|
"test": []string{"this is a test"},
|
|
|
|
},
|
2021-06-29 14:50:19 +02:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
res := http.Response{
|
|
|
|
StatusCode: 400,
|
2023-08-16 12:57:04 +02:00
|
|
|
Body: io.NopCloser(bytes.NewReader([]byte(`{
|
2021-06-29 14:50:19 +02:00
|
|
|
"code": "Bad Request",
|
|
|
|
"message": {
|
|
|
|
"@lang": "en",
|
|
|
|
"#text": "invalid"
|
|
|
|
}
|
|
|
|
}`))),
|
|
|
|
}
|
|
|
|
return &res, errors.New("Unable to trigger integration test, Response Status code:400")
|
|
|
|
}
|
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// GetIntegrationArtifactGetServiceEndpointPositiveCaseRespBody -Provide http respose body for positive case
|
2021-02-05 11:35:55 +02:00
|
|
|
func GetIntegrationArtifactGetServiceEndpointPositiveCaseRespBody() (*http.Response, error) {
|
|
|
|
|
|
|
|
resp := http.Response{
|
|
|
|
StatusCode: 200,
|
2023-08-16 12:57:04 +02:00
|
|
|
Body: io.NopCloser(bytes.NewReader([]byte(`{
|
2021-02-05 11:35:55 +02:00
|
|
|
"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
|
|
|
|
}
|
2021-02-10 18:08:23 +02:00
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// GetRespBodyHTTPStatusOK -Provide http respose body for Http StatusOK
|
2021-02-17 10:59:56 +02:00
|
|
|
func GetRespBodyHTTPStatusOK() (*http.Response, error) {
|
|
|
|
|
|
|
|
resp := http.Response{
|
|
|
|
StatusCode: 200,
|
2023-08-16 12:57:04 +02:00
|
|
|
Body: io.NopCloser(bytes.NewReader([]byte(``))),
|
2021-02-17 10:59:56 +02:00
|
|
|
}
|
|
|
|
return &resp, nil
|
|
|
|
}
|
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// GetRespBodyHTTPStatusCreated -Provide http respose body for Http StatusOK
|
2021-02-17 10:59:56 +02:00
|
|
|
func GetRespBodyHTTPStatusCreated() (*http.Response, error) {
|
|
|
|
|
|
|
|
resp := http.Response{
|
|
|
|
StatusCode: 201,
|
2023-08-16 12:57:04 +02:00
|
|
|
Body: io.NopCloser(bytes.NewReader([]byte(``))),
|
2021-02-17 10:59:56 +02:00
|
|
|
}
|
|
|
|
return &resp, nil
|
|
|
|
}
|
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// GetRespBodyHTTPStatusServiceNotFound -Provide http respose body for Http URL not Found
|
2021-02-17 10:59:56 +02:00
|
|
|
func GetRespBodyHTTPStatusServiceNotFound() (*http.Response, error) {
|
|
|
|
|
|
|
|
resp := http.Response{
|
|
|
|
StatusCode: 404,
|
2023-08-16 12:57:04 +02:00
|
|
|
Body: io.NopCloser(bytes.NewReader([]byte(``))),
|
2021-02-17 10:59:56 +02:00
|
|
|
}
|
|
|
|
return &resp, errors.New("Integration Package not found")
|
|
|
|
}
|
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// GetRespBodyHTTPStatusServiceErrorResponse -Provide http respose body for server error
|
2021-02-17 10:59:56 +02:00
|
|
|
func GetRespBodyHTTPStatusServiceErrorResponse() (*http.Response, error) {
|
|
|
|
|
|
|
|
resp := http.Response{
|
|
|
|
StatusCode: 500,
|
2023-08-16 12:57:04 +02:00
|
|
|
Body: io.NopCloser(bytes.NewReader([]byte(``))),
|
2021-02-17 10:59:56 +02:00
|
|
|
}
|
2021-04-30 09:43:25 +02:00
|
|
|
return &resp, errors.New("401 Unauthorized")
|
2021-02-17 10:59:56 +02:00
|
|
|
}
|
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// IntegrationArtifactDownloadCommandMockResponse -Provide http respose body
|
2021-02-10 18:08:23 +02:00
|
|
|
func IntegrationArtifactDownloadCommandMockResponse(testType string) (*http.Response, error) {
|
|
|
|
|
2021-02-17 10:59:56 +02:00
|
|
|
return GetMockResponseByTestTypeAndMockFunctionName("IntegrationArtifactDownloadCommandMockResponse", testType)
|
|
|
|
}
|
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// GetIntegrationDesigntimeArtifactMockResponse -Provide http respose body
|
2021-02-17 10:59:56 +02:00
|
|
|
func GetIntegrationDesigntimeArtifactMockResponse(testType string) (*http.Response, error) {
|
|
|
|
|
|
|
|
return GetMockResponseByTestTypeAndMockFunctionName("GetIntegrationDesigntimeArtifactMockResponse", testType)
|
|
|
|
}
|
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// IntegrationDesigntimeArtifactUpdateMockResponse -Provide http respose body
|
2021-02-17 10:59:56 +02:00
|
|
|
func IntegrationDesigntimeArtifactUpdateMockResponse(testType string) (*http.Response, error) {
|
|
|
|
|
|
|
|
return GetMockResponseByTestTypeAndMockFunctionName("IntegrationDesigntimeArtifactUpdateMockResponse", testType)
|
|
|
|
}
|
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// GetMockResponseByTestTypeAndMockFunctionName - Get mock response by testtype and mock function name
|
2021-02-17 10:59:56 +02:00
|
|
|
func GetMockResponseByTestTypeAndMockFunctionName(mockFuntionName, testType string) (*http.Response, error) {
|
|
|
|
|
2021-02-10 18:08:23 +02:00
|
|
|
response, error := GetPositiveCaseResponseByTestType(testType)
|
|
|
|
|
2021-03-11 13:03:32 +02:00
|
|
|
if response == nil && error == nil {
|
2021-02-17 10:59:56 +02:00
|
|
|
|
2021-03-11 13:03:32 +02:00
|
|
|
switch mockFuntionName {
|
2021-02-17 10:59:56 +02:00
|
|
|
|
2021-03-11 13:03:32 +02:00
|
|
|
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":
|
2021-02-17 10:59:56 +02:00
|
|
|
|
|
|
|
res := http.Response{
|
|
|
|
StatusCode: 400,
|
2023-08-16 12:57:04 +02:00
|
|
|
Body: io.NopCloser(bytes.NewReader([]byte(`{
|
2021-02-17 10:59:56 +02:00
|
|
|
"code": "Bad Request",
|
|
|
|
"message": {
|
|
|
|
"@lang": "en",
|
2021-03-11 13:03:32 +02:00
|
|
|
"#text": "Bad request"
|
2021-02-17 10:59:56 +02:00
|
|
|
}
|
|
|
|
}`))),
|
|
|
|
}
|
2021-03-11 13:03:32 +02:00
|
|
|
return &res, errors.New("Unable to get integration artifact deploy status, Response Status code:400")
|
2021-02-17 10:59:56 +02:00
|
|
|
|
2021-03-11 13:03:32 +02:00
|
|
|
case "GetIntegrationArtifactDeployErrorDetailsMockResponse":
|
2021-02-17 10:59:56 +02:00
|
|
|
res := http.Response{
|
2021-03-11 13:03:32 +02:00
|
|
|
StatusCode: 500,
|
2023-08-16 12:57:04 +02:00
|
|
|
Body: io.NopCloser(bytes.NewReader([]byte(`{
|
2021-03-11 13:03:32 +02:00
|
|
|
"code": "Internal Server Error",
|
2021-02-17 10:59:56 +02:00
|
|
|
"message": {
|
|
|
|
"@lang": "en",
|
2021-03-11 13:03:32 +02:00
|
|
|
"#text": "Internal Processing Error"
|
2021-02-17 10:59:56 +02:00
|
|
|
}
|
|
|
|
}`))),
|
|
|
|
}
|
2021-03-11 13:03:32 +02:00
|
|
|
return &res, errors.New("Unable to get integration artifact deploy error status, Response Status code:400")
|
2021-02-17 10:59:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return response, error
|
|
|
|
}
|
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// NegtiveResForIntegrationArtifactGenericCommandMockResponse -Nagative Case http response body
|
2021-03-11 13:03:32 +02:00
|
|
|
func NegtiveResForIntegrationArtifactGenericCommandMockResponse(message string) (*http.Response, error) {
|
|
|
|
|
|
|
|
res := http.Response{
|
|
|
|
StatusCode: 400,
|
2023-08-16 12:57:04 +02:00
|
|
|
Body: io.NopCloser(bytes.NewReader([]byte(`{
|
2021-03-11 13:03:32 +02:00
|
|
|
"code": "Bad Request",
|
|
|
|
"message": {
|
|
|
|
"@lang": "en",
|
|
|
|
"#text": "invalid request"
|
|
|
|
}
|
|
|
|
}`))),
|
|
|
|
}
|
|
|
|
return &res, errors.New(message)
|
|
|
|
}
|
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// UpdateIntegrationDesigntimeArtifactMockResponse -Provide http respose body
|
2021-02-17 10:59:56 +02:00
|
|
|
func UpdateIntegrationDesigntimeArtifactMockResponse(testType string) (*http.Response, error) {
|
|
|
|
|
|
|
|
response, error := GetRespBodyHTTPStatusCreated()
|
|
|
|
|
2021-02-10 18:08:23 +02:00
|
|
|
if response == nil && error == nil {
|
|
|
|
|
|
|
|
res := http.Response{
|
|
|
|
StatusCode: 400,
|
2023-08-16 12:57:04 +02:00
|
|
|
Body: io.NopCloser(bytes.NewReader([]byte(`{
|
2021-02-10 18:08:23 +02:00
|
|
|
"code": "Bad Request",
|
|
|
|
"message": {
|
|
|
|
"@lang": "en",
|
|
|
|
"#text": "invalid request"
|
|
|
|
}
|
|
|
|
}`))),
|
|
|
|
}
|
2021-02-17 10:59:56 +02:00
|
|
|
return &res, errors.New("Unable to get status of integration artifact, Response Status code:400")
|
2021-02-10 18:08:23 +02:00
|
|
|
}
|
|
|
|
return response, error
|
|
|
|
}
|
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// IntegrationArtifactDownloadCommandMockResponsePositiveCaseRespBody -Provide http respose body for positive case
|
2021-02-10 18:08:23 +02:00
|
|
|
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,
|
2023-08-16 12:57:04 +02:00
|
|
|
Body: io.NopCloser(bytes.NewReader([]byte(`UEsDBBQACAgIADQ2clAAAAAAAAAAAAAAAAAUAAQATU`))),
|
2021-02-10 18:08:23 +02:00
|
|
|
}
|
|
|
|
return &resp, nil
|
|
|
|
}
|
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// GetPositiveCaseResponseByTestType - get postive response by test case type
|
2021-02-10 18:08:23 +02:00
|
|
|
func GetPositiveCaseResponseByTestType(testType string) (*http.Response, error) {
|
|
|
|
switch testType {
|
|
|
|
case "PositiveAndGetetIntegrationArtifactDownloadResBody":
|
|
|
|
return IntegrationArtifactDownloadCommandMockResponsePositiveCaseRespBody()
|
2021-02-17 10:59:56 +02:00
|
|
|
case "PositiveAndCreateIntegrationDesigntimeArtifactResBody":
|
|
|
|
return GetRespBodyHTTPStatusOK()
|
|
|
|
case "NegativeAndCreateIntegrationDesigntimeArtifactResBody":
|
|
|
|
return GetRespBodyHTTPStatusOK()
|
|
|
|
case "PositiveAndUpdateIntegrationDesigntimeArtifactResBody":
|
|
|
|
return GetRespBodyHTTPStatusServiceNotFound()
|
|
|
|
case "NegativeAndUpdateIntegrationDesigntimeArtifactResBody":
|
|
|
|
return GetRespBodyHTTPStatusServiceNotFound()
|
2021-03-11 13:03:32 +02:00
|
|
|
case "PositiveAndDeployIntegrationDesigntimeArtifactResBody":
|
|
|
|
return GetIntegrationArtifactDeployStatusMockResponseBody()
|
|
|
|
case "PositiveAndGetDeployedIntegrationDesigntimeArtifactErrorResBody":
|
|
|
|
return GetIntegrationArtifactDeployErrorStatusMockResponseBody()
|
|
|
|
case "NegativeAndDeployIntegrationDesigntimeArtifactResBody":
|
|
|
|
return GetIntegrationArtifactDeployStatusErrorMockResponseBody()
|
2021-02-10 18:08:23 +02:00
|
|
|
default:
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
}
|
2021-02-17 10:59:56 +02:00
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// GetCPIFunctionNameByURLCheck - get postive response by test case type
|
2021-02-17 10:59:56 +02:00
|
|
|
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)
|
|
|
|
|
2021-07-16 16:09:55 +02:00
|
|
|
case "https://demo/api/v1/IntegrationDesigntimeArtifacts(Id='flow4',Version='Active')":
|
2021-02-17 10:59:56 +02:00
|
|
|
return GetFunctionNameByTestTypeAndMethod(method, testType)
|
|
|
|
|
|
|
|
case "https://demo/api/v1/IntegrationDesigntimeArtifacts":
|
|
|
|
return GetFunctionNameByTestTypeAndMethod(method, testType)
|
2021-07-27 09:51:56 +02:00
|
|
|
case "https://demo/api/v1/DeployIntegrationDesigntimeArtifact?Id='flow1'&Version='Active'":
|
2021-03-11 13:03:32 +02:00
|
|
|
return GetFunctionNameByTestTypeAndMethod(method, testType)
|
2022-09-15 11:01:36 +02:00
|
|
|
case "https://demo/api/v1/BuildAndDeployStatus(TaskId='')":
|
2021-03-11 13:03:32 +02:00
|
|
|
return "GetIntegrationArtifactDeployStatus"
|
|
|
|
case "https://demo/api/v1/IntegrationRuntimeArtifacts('flow1')/ErrorInformation/$value":
|
|
|
|
return "GetIntegrationArtifactDeployErrorDetails"
|
2021-02-17 10:59:56 +02:00
|
|
|
default:
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// GetFunctionNameByTestTypeAndMethod -get function name by test tyep
|
2021-02-17 10:59:56 +02:00
|
|
|
func GetFunctionNameByTestTypeAndMethod(method, testType string) string {
|
|
|
|
|
|
|
|
switch testType {
|
|
|
|
|
|
|
|
case "PositiveAndCreateIntegrationDesigntimeArtifactResBody":
|
2021-03-11 13:03:32 +02:00
|
|
|
return GetFunctionNamePositiveAndCreateIntegrationDesigntimeArtifactResBody(method)
|
2021-02-17 10:59:56 +02:00
|
|
|
|
|
|
|
case "PositiveAndUpdateIntegrationDesigntimeArtifactResBody":
|
2021-03-11 13:03:32 +02:00
|
|
|
return GetFunctionNamePositiveAndUpdateIntegrationDesigntimeArtifactResBody(method)
|
2021-02-17 10:59:56 +02:00
|
|
|
case "NegativeAndGetIntegrationDesigntimeArtifactResBody":
|
|
|
|
if method == "GET" {
|
|
|
|
return "GetIntegrationDesigntimeArtifact"
|
|
|
|
}
|
|
|
|
|
|
|
|
case "NegativeAndCreateIntegrationDesigntimeArtifactResBody":
|
|
|
|
if method == "GET" {
|
|
|
|
return "GetIntegrationDesigntimeArtifact"
|
|
|
|
}
|
2021-07-16 16:09:55 +02:00
|
|
|
if method == "PUT" {
|
2021-02-17 10:59:56 +02:00
|
|
|
return "UploadIntegrationDesigntimeArtifactNegative"
|
|
|
|
}
|
|
|
|
case "NegativeAndUpdateIntegrationDesigntimeArtifactResBody":
|
|
|
|
if method == "GET" {
|
|
|
|
return "GetIntegrationDesigntimeArtifact"
|
|
|
|
}
|
|
|
|
if method == "POST" {
|
|
|
|
return "UpdateIntegrationDesigntimeArtifactNegative"
|
|
|
|
}
|
2021-03-11 13:03:32 +02:00
|
|
|
|
|
|
|
case "PositiveAndDeployIntegrationDesigntimeArtifactResBody", "NegativeAndDeployIntegrationDesigntimeArtifactResBody":
|
|
|
|
if method == "POST" {
|
|
|
|
return "IntegrationArtifactDeploy"
|
|
|
|
}
|
2021-02-17 10:59:56 +02:00
|
|
|
default:
|
|
|
|
return ""
|
|
|
|
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
2021-03-11 13:03:32 +02:00
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// GetFunctionNamePositiveAndUpdateIntegrationDesigntimeArtifactResBody -Get Function Name
|
2021-03-11 13:03:32 +02:00
|
|
|
func GetFunctionNamePositiveAndUpdateIntegrationDesigntimeArtifactResBody(method string) string {
|
|
|
|
if method == "GET" {
|
|
|
|
return "IntegrationDesigntimeArtifactUpdate"
|
|
|
|
}
|
|
|
|
if method == "POST" {
|
|
|
|
return "UpdateIntegrationDesigntimeArtifact"
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// GetFunctionNamePositiveAndCreateIntegrationDesigntimeArtifactResBody -Get Function Name
|
2021-03-11 13:03:32 +02:00
|
|
|
func GetFunctionNamePositiveAndCreateIntegrationDesigntimeArtifactResBody(method string) string {
|
|
|
|
if method == "GET" {
|
|
|
|
return "GetIntegrationDesigntimeArtifact"
|
|
|
|
}
|
2021-07-16 16:09:55 +02:00
|
|
|
if method == "PUT" {
|
2021-03-11 13:03:32 +02:00
|
|
|
return "UploadIntegrationDesigntimeArtifact"
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// GetIntegrationArtifactDeployStatusMockResponse -Provide http respose body
|
2021-03-11 13:03:32 +02:00
|
|
|
func GetIntegrationArtifactDeployStatusMockResponse(testType string) (*http.Response, error) {
|
|
|
|
|
|
|
|
return GetMockResponseByTestTypeAndMockFunctionName("GetIntegrationArtifactDeployStatusMockResponse", testType)
|
|
|
|
}
|
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// GetIntegrationArtifactDeployErrorDetailsMockResponse -Provide http respose body
|
2021-03-11 13:03:32 +02:00
|
|
|
func GetIntegrationArtifactDeployErrorDetailsMockResponse(testType string) (*http.Response, error) {
|
|
|
|
|
|
|
|
return GetMockResponseByTestTypeAndMockFunctionName("GetIntegrationArtifactDeployErrorDetailsMockResponse", "PositiveAndGetDeployedIntegrationDesigntimeArtifactErrorResBody")
|
|
|
|
}
|
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// GetIntegrationArtifactDeployStatusMockResponseBody -Provide http respose body
|
2021-03-11 13:03:32 +02:00
|
|
|
func GetIntegrationArtifactDeployStatusMockResponseBody() (*http.Response, error) {
|
|
|
|
|
|
|
|
resp := http.Response{
|
|
|
|
StatusCode: 200,
|
2023-08-16 12:57:04 +02:00
|
|
|
Body: io.NopCloser(bytes.NewReader([]byte(GetIntegrationArtifactDeployStatusPayload("STARTED")))),
|
2021-03-11 13:03:32 +02:00
|
|
|
}
|
|
|
|
return &resp, nil
|
|
|
|
}
|
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// GetIntegrationArtifactDeployStatusErrorMockResponseBody -Provide http respose body
|
2021-03-11 13:03:32 +02:00
|
|
|
func GetIntegrationArtifactDeployStatusErrorMockResponseBody() (*http.Response, error) {
|
|
|
|
|
|
|
|
resp := http.Response{
|
|
|
|
StatusCode: 200,
|
2023-08-16 12:57:04 +02:00
|
|
|
Body: io.NopCloser(bytes.NewReader([]byte(GetIntegrationArtifactDeployStatusPayload("FAIL")))),
|
2021-03-11 13:03:32 +02:00
|
|
|
}
|
|
|
|
return &resp, nil
|
|
|
|
}
|
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// GetIntegrationArtifactDeployStatusPayload -Get Payload
|
2021-03-11 13:03:32 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2022-11-08 09:47:38 +02:00
|
|
|
// GetIntegrationArtifactDeployErrorStatusMockResponseBody -Provide http respose body
|
2021-03-11 13:03:32 +02:00
|
|
|
func GetIntegrationArtifactDeployErrorStatusMockResponseBody() (*http.Response, error) {
|
|
|
|
|
|
|
|
resp := http.Response{
|
|
|
|
StatusCode: 200,
|
2023-08-16 12:57:04 +02:00
|
|
|
Body: io.NopCloser(bytes.NewReader([]byte(`{"message": "java.lang.IllegalStateException: No credentials for 'smtp' found"}`))),
|
2021-03-11 13:03:32 +02:00
|
|
|
}
|
|
|
|
return &resp, nil
|
|
|
|
}
|