Skip to content

Commit

Permalink
Merge pull request #100 from rundeck/issue/99
Browse files Browse the repository at this point in the history
Fix #99: npe when scm import inputs tracked item job is null
  • Loading branch information
gschueler authored May 16, 2017
2 parents 5b3d992 + 5a42e57 commit ca01801
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public Map toMap() {
HashMap<String, Object> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down

0 comments on commit ca01801

Please sign in to comment.