diff --git a/src/main/java/org/rundeck/client/api/model/ScmImportItem.java b/src/main/java/org/rundeck/client/api/model/ScmImportItem.java index 5347aa5f..dd1a26db 100644 --- a/src/main/java/org/rundeck/client/api/model/ScmImportItem.java +++ b/src/main/java/org/rundeck/client/api/model/ScmImportItem.java @@ -35,7 +35,9 @@ public Map toMap() { HashMap map = new HashMap<>(); map.put("itemId", itemId); map.put("tracked", tracked); - map.put("job", job.toMap()); + if(null!=job) { + map.put("job", job.toMap()); + } return map; } } diff --git a/src/test/groovy/org/rundeck/client/tool/commands/projects/SCMSpec.groovy b/src/test/groovy/org/rundeck/client/tool/commands/projects/SCMSpec.groovy index cab33629..96d9df33 100644 --- a/src/test/groovy/org/rundeck/client/tool/commands/projects/SCMSpec.groovy +++ b/src/test/groovy/org/rundeck/client/tool/commands/projects/SCMSpec.groovy @@ -17,13 +17,21 @@ package org.rundeck.client.tool.commands.projects import com.simplifyops.toolbelt.CommandOutput +import okhttp3.mockwebserver.MockResponse +import okhttp3.mockwebserver.MockWebServer +import okhttp3.mockwebserver.RecordedRequest import org.rundeck.client.api.RundeckApi +import org.rundeck.client.api.model.ScmActionInputsResult +import org.rundeck.client.api.model.ScmImportItem +import org.rundeck.client.api.model.ScmInputField +import org.rundeck.client.api.model.ScmJobItem import org.rundeck.client.api.model.ScmProjectStatusResult import org.rundeck.client.api.model.ScmSynchState import org.rundeck.client.tool.AppConfig import org.rundeck.client.tool.RdApp import org.rundeck.client.util.Client import retrofit2.Retrofit +import retrofit2.converter.jackson.JacksonConverterFactory import retrofit2.mock.Calls import spock.lang.Specification @@ -32,6 +40,91 @@ import spock.lang.Specification * @since 1/11/17 */ class SCMSpec extends Specification { + def "command inputs for import with null job"() { + given: + def api = Mock(RundeckApi) + + def retrofit = new Retrofit.Builder().baseUrl('http://example.com/fake/').build() + def client = new Client(api, retrofit, 18) + + def appConfig = Mock(AppConfig) + + def hasclient = Mock(RdApp) { + getClient() >> client + getAppConfig() >> appConfig + } + def scm = new SCM(hasclient) + + def out = Mock(CommandOutput) + def opts = Mock(SCM.ActionInputsOptions) { + getProject() >> 'aproject' + getIntegration() >> 'import' + getAction() >> 'import-all' + } + + + + when: + def result = scm.inputs(opts, out) + + then: + + 1 * api.getScmActionInputs('aproject', 'import', 'import-all') >> + Calls.response( + new ScmActionInputsResult( + title: 'blah', + description: 'blah', + integration: 'import', + actionId: 'import-all', + fields: [new ScmInputField( + name: 'commitMessage', + description: 'abc', + required: true, + defaultValue: null, + title: 'Message', + type: 'String' + )], + importItems: [ + new ScmImportItem(itemId: '/a/path', tracked: false, job: null), + new ScmImportItem( + itemId: '/b/path', + tracked: true, + job: new ScmJobItem( + jobId: 'ajob', + jobName: 'job name', + groupPath: 'monkey/banana' + ) + ) + ] + ) + ) + + 1 * out.output('blah: blah') + 1 * out.output('Fields:') + 1 * out.output( + [['defaultValue' : null, + 'scope' : null, + 'values' : null, + 'name' : 'commitMessage', + 'description' : 'abc', + 'title' : 'Message', + 'renderingOptions': null, + 'required' : true]] + ) + 1 * out.output('Items:') + 1 * out.output( + [ + ['itemId': '/a/path', 'tracked': false], + ['itemId': '/b/path', 'tracked': true, + 'job' : [ + 'jobName' : 'job name', + 'jobId' : 'ajob', + 'groupPath': 'monkey/banana' + ]] + ] + ) + } + def "scm status use project from env var"() { given: def api = Mock(RundeckApi)