Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
JENKINS-49178 Add failing acceptance test.
  • Loading branch information
ceilfors committed Apr 20, 2018
1 parent bb6bb87 commit 30fe790
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 2 deletions.
@@ -1,5 +1,6 @@
package com.ceilfors.jenkins.plugins.jiratrigger

import com.ceilfors.jenkins.plugins.jiratrigger.integration.FakeJiraCloudRunner
import com.ceilfors.jenkins.plugins.jiratrigger.integration.FakeJiraRunner
import com.ceilfors.jenkins.plugins.jiratrigger.integration.JenkinsRunner
import com.ceilfors.jenkins.plugins.jiratrigger.integration.JiraRunner
Expand All @@ -11,6 +12,7 @@ import org.junit.rules.RuleChain
import org.junit.rules.TestRule
import org.junit.rules.TestWatcher
import org.junit.runner.Description
import spock.lang.Ignore
import spock.lang.Specification

import static JiraCommentTrigger.DEFAULT_COMMENT
Expand All @@ -23,6 +25,7 @@ class JiraTriggerAcceptanceTest extends Specification {

JenkinsRunner jenkins = new JenkinsRunner()
JiraRunner jira
JiraRunner jiraCloud

@Rule
RuleChain ruleChain = RuleChain
Expand All @@ -33,6 +36,7 @@ class JiraTriggerAcceptanceTest extends Specification {
@Override
protected void before() throws Throwable {
jira = new FakeJiraRunner(jenkins)
jiraCloud = new FakeJiraCloudRunner(jenkins)
}
})

Expand All @@ -57,6 +61,19 @@ class JiraTriggerAcceptanceTest extends Specification {
jenkins.buildShouldBeScheduled('job')
}

@Ignore
def 'Should trigger a build when a comment is added in JIRA cloud'() {
given:
String issueKey = jiraCloud.createIssue()
jenkins.createJiraCommentTriggeredProject('job')

when:
jiraCloud.addComment(issueKey, DEFAULT_COMMENT)

then:
jenkins.buildShouldBeScheduled('job')
}

def 'Should trigger a build when an issue is updated'() {
given:
String issueKey = jira.createIssue('Original description')
Expand Down
@@ -0,0 +1,18 @@
package com.ceilfors.jenkins.plugins.jiratrigger.integration

/**
* @author ceilfors
*/
class FakeJiraCloudRunner extends FakeJiraRunner {

FakeJiraCloudRunner(JenkinsRunner jenkinsRunner) {
super(jenkinsRunner)
}

@Override
void addComment(String issueKey, String comment) {
Map body = createPostBody('cloudAddComment', issueKey)
body.comment.body = comment
restClient.post(body: body)
}
}
Expand Up @@ -70,15 +70,19 @@ class FakeJiraRunner implements JiraRunner {
new RESTClient(jenkinsUrl, ContentType.JSON)
}

private Map createPostBody(String method, String issueKey) {
protected Map createPostBody(String method, String issueKey) {
def slurper = new JsonSlurper()
Map body = slurper.parse(new FileReader(new File(this.class.getResource("${method}.json").toURI()))) as Map
body.issue.key = issueKey
body.issue.fields.description = issueMap[issueKey].description
body
}

private class FakeIssue {
protected RESTClient getRestClient() {
restClient
}

protected static class FakeIssue {
String issueKey
String description
}
Expand Down
Expand Up @@ -21,6 +21,7 @@ import static org.hamcrest.Matchers.empty
import static org.hamcrest.Matchers.equalTo
import static org.hamcrest.Matchers.is
import static org.hamcrest.Matchers.not
import static org.hamcrest.Matchers.nullValue
import static org.junit.Assert.assertThat
/**
* @author ceilfors
Expand Down Expand Up @@ -50,6 +51,7 @@ class JenkinsRunner extends JenkinsRule {

void buildShouldBeScheduled(String jobName, Map<String, String> parameterMap = [:]) {
Collection<AbstractProject> jobs = jenkinsQueue.scheduledJobs
assertThat('Build is not scheduled! Check error logs.', jobs, is(not(nullValue())))
assertThat('Build is not scheduled!', jobs, is(not(empty())))
assertThat('Only one project is scheduled', jobs.size(), is(equalTo(1)))

Expand Down
@@ -0,0 +1,107 @@
{
"timestamp": 1516745644071,
"webhookEvent": "comment_created",
"comment": {
"self": "https://sportsrecruits.atlassian.net/rest/api/2/issue/38747/comment/43735",
"id": "43735",
"author": {
"self": "https://sportsrecruits.atlassian.net/rest/api/2/user?username=alex",
"name": "alex",
"key": "alex",
"accountId": "557058:93f71831-7090-4c70-ab8e-c9a5c9aa2d8e",
"avatarUrls": {
"48x48": "https://avatar-cdn.atlassian.com/07be219aa1f894b95a868f2eef9d4e17?s=48&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F07be219aa1f894b95a868f2eef9d4e17%3Fd%3Dmm%26s%3D48%26noRedirect%3Dtrue",
"24x24": "https://avatar-cdn.atlassian.com/07be219aa1f894b95a868f2eef9d4e17?s=24&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F07be219aa1f894b95a868f2eef9d4e17%3Fd%3Dmm%26s%3D24%26noRedirect%3Dtrue",
"16x16": "https://avatar-cdn.atlassian.com/07be219aa1f894b95a868f2eef9d4e17?s=16&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F07be219aa1f894b95a868f2eef9d4e17%3Fd%3Dmm%26s%3D16%26noRedirect%3Dtrue",
"32x32": "https://avatar-cdn.atlassian.com/07be219aa1f894b95a868f2eef9d4e17?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F07be219aa1f894b95a868f2eef9d4e17%3Fd%3Dmm%26s%3D32%26noRedirect%3Dtrue"
},
"displayName": "Alex Figueroa ",
"active": true,
"timeZone": "America/New_York"
},
"body": "Jenkins go home",
"updateAuthor": {
"self": "https://sportsrecruits.atlassian.net/rest/api/2/user?username=alex",
"name": "alex",
"key": "alex",
"accountId": "557058:93f71831-7090-4c70-ab8e-c9a5c9aa2d8e",
"avatarUrls": {
"48x48": "https://avatar-cdn.atlassian.com/07be219aa1f894b95a868f2eef9d4e17?s=48&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F07be219aa1f894b95a868f2eef9d4e17%3Fd%3Dmm%26s%3D48%26noRedirect%3Dtrue",
"24x24": "https://avatar-cdn.atlassian.com/07be219aa1f894b95a868f2eef9d4e17?s=24&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F07be219aa1f894b95a868f2eef9d4e17%3Fd%3Dmm%26s%3D24%26noRedirect%3Dtrue",
"16x16": "https://avatar-cdn.atlassian.com/07be219aa1f894b95a868f2eef9d4e17?s=16&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F07be219aa1f894b95a868f2eef9d4e17%3Fd%3Dmm%26s%3D16%26noRedirect%3Dtrue",
"32x32": "https://avatar-cdn.atlassian.com/07be219aa1f894b95a868f2eef9d4e17?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2F07be219aa1f894b95a868f2eef9d4e17%3Fd%3Dmm%26s%3D32%26noRedirect%3Dtrue"
},
"displayName": "Alex Figueroa ",
"active": true,
"timeZone": "America/New_York"
},
"created": "2018-01-23T17:14:04.071-0500",
"updated": "2018-01-23T17:14:04.071-0500"
},
"issue": {
"id": "38747",
"self": "https://sportsrecruits.atlassian.net/rest/api/2/issue/38747",
"key": "SR-4186",
"fields": {
"summary": "Identify and fix email address entry points to strip white space",
"issuetype": {
"self": "https://sportsrecruits.atlassian.net/rest/api/2/issuetype/3",
"id": "3",
"description": "A task that needs to be done.",
"iconUrl": "https://sportsrecruits.atlassian.net/secure/viewavatar?size=xsmall&avatarId=10318&avatarType=issuetype",
"name": "Task",
"subtask": false,
"avatarId": 10318
},
"project": {
"self": "https://sportsrecruits.atlassian.net/rest/api/2/project/10000",
"id": "10000",
"key": "SR",
"name": "Sports Recruits",
"projectTypeKey": "software",
"avatarUrls": {
"48x48": "https://sportsrecruits.atlassian.net/secure/projectavatar?pid=10000&avatarId=11300",
"24x24": "https://sportsrecruits.atlassian.net/secure/projectavatar?size=small&pid=10000&avatarId=11300",
"16x16": "https://sportsrecruits.atlassian.net/secure/projectavatar?size=xsmall&pid=10000&avatarId=11300",
"32x32": "https://sportsrecruits.atlassian.net/secure/projectavatar?size=medium&pid=10000&avatarId=11300"
}
},
"assignee": {
"self": "https://sportsrecruits.atlassian.net/rest/api/2/user?username=Paul",
"name": "Paul",
"key": "paul",
"accountId": "5a43c904b66c2f374530f7b7",
"emailAddress": "paul@sportsrecruits.com",
"avatarUrls": {
"48x48": "https://avatar-cdn.atlassian.com/d7a71cabea4d48b35a499dd3a68a5fcb?s=48&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fd7a71cabea4d48b35a499dd3a68a5fcb%3Fd%3Dmm%26s%3D48%26noRedirect%3Dtrue",
"24x24": "https://avatar-cdn.atlassian.com/d7a71cabea4d48b35a499dd3a68a5fcb?s=24&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fd7a71cabea4d48b35a499dd3a68a5fcb%3Fd%3Dmm%26s%3D24%26noRedirect%3Dtrue",
"16x16": "https://avatar-cdn.atlassian.com/d7a71cabea4d48b35a499dd3a68a5fcb?s=16&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fd7a71cabea4d48b35a499dd3a68a5fcb%3Fd%3Dmm%26s%3D16%26noRedirect%3Dtrue",
"32x32": "https://avatar-cdn.atlassian.com/d7a71cabea4d48b35a499dd3a68a5fcb?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fd7a71cabea4d48b35a499dd3a68a5fcb%3Fd%3Dmm%26s%3D32%26noRedirect%3Dtrue"
},
"displayName": "Paul Cox",
"active": true,
"timeZone": "America/New_York"
},
"priority": {
"self": "https://sportsrecruits.atlassian.net/rest/api/2/priority/3",
"iconUrl": "https://sportsrecruits.atlassian.net/images/icons/priorities/major.svg",
"name": "Major",
"id": "3"
},
"status": {
"self": "https://sportsrecruits.atlassian.net/rest/api/2/status/10500",
"description": "This is managed by JIRA",
"iconUrl": "https://sportsrecruits.atlassian.net/images/icons/statuses/generic.png",
"name": "QA on stage",
"id": "10500",
"statusCategory": {
"self": "https://sportsrecruits.atlassian.net/rest/api/2/statuscategory/4",
"id": 4,
"key": "indeterminate",
"colorName": "yellow",
"name": "In Progress"
}
}
}
}
}

0 comments on commit 30fe790

Please sign in to comment.