github.com/SAP/jenkins-library@v1.362.0/cmd/integrationArtifactUpdateConfiguration_test.go (about) 1 //go:build unit 2 // +build unit 3 4 package cmd 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestRunIntegrationArtifactUpdateConfiguration(t *testing.T) { 13 t.Parallel() 14 15 t.Run("Successfully update of Integration Flow configuration parameter test", func(t *testing.T) { 16 apiServiceKey := `{ 17 "oauth": { 18 "url": "https://demo", 19 "clientid": "demouser", 20 "clientsecret": "******", 21 "tokenurl": "https://demo/oauth/token" 22 } 23 }` 24 config := integrationArtifactUpdateConfigurationOptions{ 25 APIServiceKey: apiServiceKey, 26 IntegrationFlowID: "flow1", 27 IntegrationFlowVersion: "1.0.1", 28 ParameterKey: "myheader", 29 ParameterValue: "def", 30 } 31 32 httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactUpdateConfiguration", ResponseBody: ``, TestType: "Positive", Method: "PUT", URL: "https://demo/api/v1/IntegrationDesigntimeArtifacts(Id='flow1',Version='1.0.1')"} 33 34 err := runIntegrationArtifactUpdateConfiguration(&config, nil, &httpClient) 35 36 if assert.NoError(t, err) { 37 38 t.Run("check url", func(t *testing.T) { 39 assert.Equal(t, "https://demo/api/v1/IntegrationDesigntimeArtifacts(Id='flow1',Version='1.0.1')/$links/Configurations('myheader')", httpClient.URL) 40 }) 41 42 t.Run("check method", func(t *testing.T) { 43 assert.Equal(t, "PUT", httpClient.Method) 44 }) 45 } 46 47 }) 48 49 t.Run("Failed case of Integration Flow configuration parameter Test", func(t *testing.T) { 50 apiServiceKey := `{ 51 "oauth": { 52 "url": "https://demo", 53 "clientid": "demouser", 54 "clientsecret": "******", 55 "tokenurl": "https://demo/oauth/token" 56 } 57 }` 58 config := integrationArtifactUpdateConfigurationOptions{ 59 APIServiceKey: apiServiceKey, 60 IntegrationFlowID: "flow1", 61 IntegrationFlowVersion: "1.0.1", 62 ParameterKey: "myheader", 63 ParameterValue: "def", 64 } 65 66 httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactUpdateConfiguration", ResponseBody: ``, TestType: "Negative"} 67 68 err := runIntegrationArtifactUpdateConfiguration(&config, nil, &httpClient) 69 assert.EqualError(t, err, "HTTP \"PUT\" request to \"https://demo/api/v1/IntegrationDesigntimeArtifacts(Id='flow1',Version='1.0.1')/$links/Configurations('myheader')\" failed with error: Not found - either wrong version for the given Id or wrong parameter key") 70 }) 71 72 t.Run("Failed case of Integration Flow configuration parameter test with error body", func(t *testing.T) { 73 apiServiceKey := `{ 74 "oauth": { 75 "url": "https://demo", 76 "clientid": "demouser", 77 "clientsecret": "******", 78 "tokenurl": "https://demo/oauth/token" 79 } 80 }` 81 config := integrationArtifactUpdateConfigurationOptions{ 82 APIServiceKey: apiServiceKey, 83 IntegrationFlowID: "flow1", 84 IntegrationFlowVersion: "1.0.1", 85 ParameterKey: "myheader", 86 ParameterValue: "def", 87 } 88 89 httpClient := httpMockCpis{CPIFunction: "IntegrationArtifactUpdateConfiguration", ResponseBody: ``, TestType: "Negative_With_ResponseBody"} 90 91 err := runIntegrationArtifactUpdateConfiguration(&config, nil, &httpClient) 92 assert.EqualError(t, err, "Failed to update the integration flow configuration parameter, Response Status code: 400") 93 }) 94 }