2023-05-03 18:02:11 +02:00
|
|
|
//go:build unit
|
|
|
|
// +build unit
|
|
|
|
|
2021-02-04 11:50:15 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2021-07-28 12:00:41 +02:00
|
|
|
"fmt"
|
2021-02-04 11:50:15 +02:00
|
|
|
"testing"
|
|
|
|
|
2021-07-28 12:00:41 +02:00
|
|
|
piperhttp "github.com/SAP/jenkins-library/pkg/http"
|
2021-02-04 11:50:15 +02:00
|
|
|
"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) {
|
2021-06-28 10:50:33 +02:00
|
|
|
apiServiceKey := `{
|
|
|
|
"oauth": {
|
|
|
|
"url": "https://demo",
|
|
|
|
"clientid": "demouser",
|
|
|
|
"clientsecret": "******",
|
|
|
|
"tokenurl": "https://demo/oauth/token"
|
|
|
|
}
|
|
|
|
}`
|
2021-02-04 11:50:15 +02:00
|
|
|
config := integrationArtifactGetMplStatusOptions{
|
2021-06-28 10:50:33 +02:00
|
|
|
APIServiceKey: apiServiceKey,
|
|
|
|
IntegrationFlowID: "flow1",
|
2021-02-04 11:50:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactGetMplStatus", ResponseBody: ``, TestType: "Positive"}
|
|
|
|
seOut := integrationArtifactGetMplStatusCommonPipelineEnvironment{}
|
|
|
|
err := runIntegrationArtifactGetMplStatus(&config, nil, &httpClient, &seOut)
|
|
|
|
|
|
|
|
if assert.NoError(t, err) {
|
2021-08-04 16:42:25 +02:00
|
|
|
assert.EqualValues(t, seOut.custom.integrationFlowMplStatus, "COMPLETED")
|
2021-02-04 11:50:15 +02:00
|
|
|
|
|
|
|
t.Run("check url", func(t *testing.T) {
|
2021-07-08 11:51:31 +02:00
|
|
|
assert.Equal(t, "https://demo/api/v1/MessageProcessingLogs?$filter=IntegrationArtifact/Id+eq+'flow1'+and+Status+ne+'DISCARDED'&$orderby=LogEnd+desc&$top=1", httpClient.URL)
|
2021-02-04 11:50:15 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
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) {
|
2021-06-28 10:50:33 +02:00
|
|
|
apiServiceKey := `{
|
|
|
|
"oauth": {
|
|
|
|
"url": "https://demo",
|
|
|
|
"clientid": "demouser",
|
|
|
|
"clientsecret": "******",
|
|
|
|
"tokenurl": "https://demo/oauth/token"
|
|
|
|
}
|
|
|
|
}`
|
2021-02-04 11:50:15 +02:00
|
|
|
config := integrationArtifactGetMplStatusOptions{
|
2021-06-28 10:50:33 +02:00
|
|
|
APIServiceKey: apiServiceKey,
|
|
|
|
IntegrationFlowID: "flow1",
|
2021-02-04 11:50:15 +02:00
|
|
|
}
|
|
|
|
|
2021-03-11 13:03:32 +02:00
|
|
|
httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactGetMplStatus", ResponseBody: ``, TestType: "Negative"}
|
2021-02-04 11:50:15 +02:00
|
|
|
|
|
|
|
seOut := integrationArtifactGetMplStatusCommonPipelineEnvironment{}
|
|
|
|
err := runIntegrationArtifactGetMplStatus(&config, nil, &httpClient, &seOut)
|
2021-08-04 16:42:25 +02:00
|
|
|
assert.EqualValues(t, seOut.custom.integrationFlowMplStatus, "")
|
2021-03-11 13:03:32 +02:00
|
|
|
assert.EqualError(t, err, "HTTP GET request to https://demo/api/v1/MessageProcessingLogs?$filter=IntegrationArtifact/"+
|
2021-07-08 11:51:31 +02:00
|
|
|
"Id+eq+'flow1'+and+Status+ne+'DISCARDED'&$orderby=LogEnd+desc&$top=1 failed with error: "+
|
2021-03-11 13:03:32 +02:00
|
|
|
"Unable to get integration flow MPL status, Response Status code:400")
|
2021-02-04 11:50:15 +02:00
|
|
|
})
|
2021-07-28 12:00:41 +02:00
|
|
|
|
|
|
|
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)
|
2021-08-04 16:42:25 +02:00
|
|
|
assert.EqualValues(t, seOut.custom.integrationFlowMplError, "{\"message\": \"java.lang.IllegalStateException: No credentials for 'smtp' found\"}")
|
2021-07-28 12:00:41 +02:00
|
|
|
})
|
|
|
|
|
2021-02-04 11:50:15 +02:00
|
|
|
}
|