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

85 lines
3.0 KiB
Go
Raw Normal View History

//go:build unit
// +build unit
package cmd
import (
"fmt"
"testing"
piperhttp "github.com/SAP/jenkins-library/pkg/http"
"github.com/stretchr/testify/assert"
)
func TestRunIntegrationArtifactGetMplStatus(t *testing.T) {
t.Parallel()
t.Run("Successfully Test of Get Integration Flow MPL Status", func(t *testing.T) {
CPI - Introduce service key (#2901) * Switch to service key for CPI GetMplStatus Introduces read method for service key files, mock utils and tests. * Use secret text instead of file * Change serviceKey definition * Update cpiUpload to use Service Key retrieved the host and uaa information from service key * Update cpiDeploy to use service key retrieved the host and uaa information from service key * Update cpiServiceEndpoint to use Service Key retrieved the host and uaa information from service key * Update cpiDownload to use Service Key retrieved the host and uaa information from service key * Update cpiUpdateConfig to use Service Key retrieved the host and uaa information from service key * Refactor serviceKey var name * Fixed references to service key to follow the real format they should be accessed through oauth instead of uaa because of the format of the json * Rename ServiceKey to APIServiceKey To support having a different service key(and for readability), we need to change the name to API. * Add STAGES and STEPS yaml add in to each yaml file of cpi integration * Revert "Add STAGES and STEPS yaml" This reverts commit aa2665d158b0f864cfee95ff999a7dc8ea3477f1. * Change comments/formatting commonUtils Make comments more understandable and follow code climate suggestions * Change documentation files for steps remove OAuth and host and change credentials to be servicekey Co-authored-by: Oliver Feldmann <oliver.feldmann@sap.com> Co-authored-by: Thorsten Duda <thorsten.duda@sap.com>
2021-06-28 10:50:33 +02:00
apiServiceKey := `{
"oauth": {
"url": "https://demo",
"clientid": "demouser",
"clientsecret": "******",
"tokenurl": "https://demo/oauth/token"
}
}`
config := integrationArtifactGetMplStatusOptions{
CPI - Introduce service key (#2901) * Switch to service key for CPI GetMplStatus Introduces read method for service key files, mock utils and tests. * Use secret text instead of file * Change serviceKey definition * Update cpiUpload to use Service Key retrieved the host and uaa information from service key * Update cpiDeploy to use service key retrieved the host and uaa information from service key * Update cpiServiceEndpoint to use Service Key retrieved the host and uaa information from service key * Update cpiDownload to use Service Key retrieved the host and uaa information from service key * Update cpiUpdateConfig to use Service Key retrieved the host and uaa information from service key * Refactor serviceKey var name * Fixed references to service key to follow the real format they should be accessed through oauth instead of uaa because of the format of the json * Rename ServiceKey to APIServiceKey To support having a different service key(and for readability), we need to change the name to API. * Add STAGES and STEPS yaml add in to each yaml file of cpi integration * Revert "Add STAGES and STEPS yaml" This reverts commit aa2665d158b0f864cfee95ff999a7dc8ea3477f1. * Change comments/formatting commonUtils Make comments more understandable and follow code climate suggestions * Change documentation files for steps remove OAuth and host and change credentials to be servicekey Co-authored-by: Oliver Feldmann <oliver.feldmann@sap.com> Co-authored-by: Thorsten Duda <thorsten.duda@sap.com>
2021-06-28 10:50:33 +02:00
APIServiceKey: apiServiceKey,
IntegrationFlowID: "flow1",
}
httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactGetMplStatus", ResponseBody: ``, TestType: "Positive"}
seOut := integrationArtifactGetMplStatusCommonPipelineEnvironment{}
err := runIntegrationArtifactGetMplStatus(&config, nil, &httpClient, &seOut)
if assert.NoError(t, err) {
assert.EqualValues(t, seOut.custom.integrationFlowMplStatus, "COMPLETED")
t.Run("check url", func(t *testing.T) {
assert.Equal(t, "https://demo/api/v1/MessageProcessingLogs?$filter=IntegrationArtifact/Id+eq+'flow1'+and+Status+ne+'DISCARDED'&$orderby=LogEnd+desc&$top=1", httpClient.URL)
})
t.Run("check method", func(t *testing.T) {
assert.Equal(t, "GET", httpClient.Method)
})
}
})
t.Run("Failed Test of Get Integration Flow MPL Status", func(t *testing.T) {
CPI - Introduce service key (#2901) * Switch to service key for CPI GetMplStatus Introduces read method for service key files, mock utils and tests. * Use secret text instead of file * Change serviceKey definition * Update cpiUpload to use Service Key retrieved the host and uaa information from service key * Update cpiDeploy to use service key retrieved the host and uaa information from service key * Update cpiServiceEndpoint to use Service Key retrieved the host and uaa information from service key * Update cpiDownload to use Service Key retrieved the host and uaa information from service key * Update cpiUpdateConfig to use Service Key retrieved the host and uaa information from service key * Refactor serviceKey var name * Fixed references to service key to follow the real format they should be accessed through oauth instead of uaa because of the format of the json * Rename ServiceKey to APIServiceKey To support having a different service key(and for readability), we need to change the name to API. * Add STAGES and STEPS yaml add in to each yaml file of cpi integration * Revert "Add STAGES and STEPS yaml" This reverts commit aa2665d158b0f864cfee95ff999a7dc8ea3477f1. * Change comments/formatting commonUtils Make comments more understandable and follow code climate suggestions * Change documentation files for steps remove OAuth and host and change credentials to be servicekey Co-authored-by: Oliver Feldmann <oliver.feldmann@sap.com> Co-authored-by: Thorsten Duda <thorsten.duda@sap.com>
2021-06-28 10:50:33 +02:00
apiServiceKey := `{
"oauth": {
"url": "https://demo",
"clientid": "demouser",
"clientsecret": "******",
"tokenurl": "https://demo/oauth/token"
}
}`
config := integrationArtifactGetMplStatusOptions{
CPI - Introduce service key (#2901) * Switch to service key for CPI GetMplStatus Introduces read method for service key files, mock utils and tests. * Use secret text instead of file * Change serviceKey definition * Update cpiUpload to use Service Key retrieved the host and uaa information from service key * Update cpiDeploy to use service key retrieved the host and uaa information from service key * Update cpiServiceEndpoint to use Service Key retrieved the host and uaa information from service key * Update cpiDownload to use Service Key retrieved the host and uaa information from service key * Update cpiUpdateConfig to use Service Key retrieved the host and uaa information from service key * Refactor serviceKey var name * Fixed references to service key to follow the real format they should be accessed through oauth instead of uaa because of the format of the json * Rename ServiceKey to APIServiceKey To support having a different service key(and for readability), we need to change the name to API. * Add STAGES and STEPS yaml add in to each yaml file of cpi integration * Revert "Add STAGES and STEPS yaml" This reverts commit aa2665d158b0f864cfee95ff999a7dc8ea3477f1. * Change comments/formatting commonUtils Make comments more understandable and follow code climate suggestions * Change documentation files for steps remove OAuth and host and change credentials to be servicekey Co-authored-by: Oliver Feldmann <oliver.feldmann@sap.com> Co-authored-by: Thorsten Duda <thorsten.duda@sap.com>
2021-06-28 10:50:33 +02:00
APIServiceKey: apiServiceKey,
IntegrationFlowID: "flow1",
}
httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactGetMplStatus", ResponseBody: ``, TestType: "Negative"}
seOut := integrationArtifactGetMplStatusCommonPipelineEnvironment{}
err := runIntegrationArtifactGetMplStatus(&config, nil, &httpClient, &seOut)
assert.EqualValues(t, seOut.custom.integrationFlowMplStatus, "")
assert.EqualError(t, err, "HTTP GET request to https://demo/api/v1/MessageProcessingLogs?$filter=IntegrationArtifact/"+
"Id+eq+'flow1'+and+Status+ne+'DISCARDED'&$orderby=LogEnd+desc&$top=1 failed with error: "+
"Unable to get integration flow MPL status, Response Status code:400")
})
t.Run(" Integration flow message processing get Error message test", func(t *testing.T) {
clientOptions := piperhttp.ClientOptions{}
clientOptions.Token = fmt.Sprintf("Bearer %s", "Demo")
httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactGetMplStatusError", Options: clientOptions, ResponseBody: ``, TestType: "Negative"}
seOut := integrationArtifactGetMplStatusCommonPipelineEnvironment{}
message, err := getIntegrationArtifactMPLError(&seOut, "1000111", &httpClient, "demo")
assert.NoError(t, err)
assert.NotNil(t, message)
assert.EqualValues(t, seOut.custom.integrationFlowMplError, "{\"message\": \"java.lang.IllegalStateException: No credentials for 'smtp' found\"}")
})
}