#5 - Create release tickets and release versions for Jira-tracked projects.
Creates jira release version for a train iteration if not present. Creates release tickets in Jira and GitHub if not present. Added pre-release verification that the release ticket is present and all other tickets are closed. Allow singular ticket and release version creation. Add integration tests using WireMock. Add command to self-assign release tickets. Added CLI commands: * jira releasetickets * jira create releasetickets * jira self-assign releasetickets * jira create releaseversions * github tickets * github releasetickets * github create releaseversions * github create releasetickets Original pull request: #14.
This commit is contained in:
committed by
Oliver Gierke
parent
b7e981b57f
commit
9944848d81
@@ -16,28 +16,223 @@
|
||||
|
||||
package org.springframework.data.release.jira;
|
||||
|
||||
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.*;
|
||||
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.release.AbstractIntegrationTests;
|
||||
import org.springframework.data.release.model.Iteration;
|
||||
import org.springframework.data.release.model.ModuleIteration;
|
||||
import org.springframework.data.release.model.Projects;
|
||||
import org.springframework.data.release.model.ReleaseTrains;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder;
|
||||
import com.github.tomakehurst.wiremock.common.ClasspathFileSource;
|
||||
import com.github.tomakehurst.wiremock.junit.WireMockRule;
|
||||
|
||||
/**
|
||||
* Integration Tests for {@link GitHubIssueTracker} using a local {@link WireMockRule} server.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class GitHubIssueTrackerIntegrationTests extends AbstractIntegrationTests {
|
||||
|
||||
@Autowired GitHubConnector gitHubIssueTracker;
|
||||
public static final String ISSUES_URI = "/repos/spring-projects/spring-data-build/issues";
|
||||
public static final String MILESTONES_URI = "/repos/spring-projects/spring-data-build/milestones";
|
||||
public static final ModuleIteration BUILD_HOPPER_RC1 = ReleaseTrains.HOPPER.getModuleIteration(Iteration.RC1,
|
||||
"Build");
|
||||
|
||||
@Rule public WireMockRule mockService = new WireMockRule(
|
||||
wireMockConfig().port(8888).fileSource(new ClasspathFileSource("integration/github")));
|
||||
|
||||
@Rule public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
@Autowired IssueTracker github;
|
||||
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
github.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #5
|
||||
*/
|
||||
@Test
|
||||
public void getTickets() throws Exception {
|
||||
public void findTicketsByTicketIds() throws Exception {
|
||||
|
||||
mockGetIssueWith("issue.json", 233);
|
||||
|
||||
Collection<Ticket> tickets = github.findTickets(Projects.BUILD, Arrays.asList("233"));
|
||||
assertThat(tickets, hasSize(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #5
|
||||
*/
|
||||
@Test
|
||||
public void ignoresUnknownTicketsByTicketId() throws Exception {
|
||||
|
||||
Collection<Ticket> tickets = github.findTickets(Projects.BUILD, Arrays.asList("123"));
|
||||
assertThat(tickets, hasSize(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #5
|
||||
*/
|
||||
@Test
|
||||
public void emptyResultWithEmptyTicketIds() throws Exception {
|
||||
|
||||
Collection<Ticket> tickets = github.findTickets(Projects.COMMONS, Arrays.asList());
|
||||
assertThat(tickets, hasSize(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #5
|
||||
*/
|
||||
@Test
|
||||
public void getReleaseTicketForReturnsTheReleaseTicket() throws Exception {
|
||||
|
||||
mockGetMilestonesWith("milestones.json");
|
||||
mockGetIssuesWith("issues.json");
|
||||
|
||||
Ticket releaseTicket = github.getReleaseTicketFor(BUILD_HOPPER_RC1);
|
||||
assertThat(releaseTicket.getId(), is(Matchers.equalTo("#233")));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #5
|
||||
*/
|
||||
@Test
|
||||
public void noReleaseTicketFound() throws Exception {
|
||||
|
||||
expectedException.expect(IllegalStateException.class);
|
||||
expectedException.expectMessage("No milestone for Spring Data Build found containing 1.8 RC1!");
|
||||
|
||||
mockGetMilestonesWith("emptyMilestones.json");
|
||||
|
||||
github.getReleaseTicketFor(BUILD_HOPPER_RC1);
|
||||
|
||||
fail("Missing IllegalStateException");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #5
|
||||
*/
|
||||
@Test
|
||||
public void createReleaseVersionShouldCreateAVersion() throws Exception {
|
||||
|
||||
mockGetMilestonesWith("emptyMilestones.json");
|
||||
mockCreateMilestoneWith("milestone.json");
|
||||
|
||||
github.createReleaseVersion(BUILD_HOPPER_RC1);
|
||||
|
||||
verify(postRequestedFor(urlPathMatching(MILESTONES_URI))
|
||||
.withRequestBody(equalToJson("{\"title\":\"1.8 RC1 (Hopper)\", \"description\":\"Hopper RC1\"}")));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #5
|
||||
*/
|
||||
@Test
|
||||
public void createReleaseVersionShouldFindExistingReleaseVersion() throws Exception {
|
||||
|
||||
mockGetMilestonesWith("milestones.json");
|
||||
|
||||
github.createReleaseVersion(BUILD_HOPPER_RC1);
|
||||
|
||||
verify(0, postRequestedFor(urlPathMatching(MILESTONES_URI)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #5
|
||||
*/
|
||||
@Test
|
||||
public void createReleaseTicketShouldCreateReleaseTicket() throws Exception {
|
||||
|
||||
mockGetMilestonesWith("milestones.json");
|
||||
mockGetIssuesWith("emptyIssues.json");
|
||||
mockCreateIssueWith("issue.json");
|
||||
|
||||
github.createReleaseTicket(BUILD_HOPPER_RC1);
|
||||
|
||||
verify(postRequestedFor(urlPathMatching(ISSUES_URI))
|
||||
.withRequestBody(equalToJson("{\"title\":\"Release 1.8 RC1 (Hopper)\",\"milestone\":45}")));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #5
|
||||
*/
|
||||
@Test
|
||||
public void createReleaseTicketShouldFailWithNoReleaseVersion() throws Exception {
|
||||
|
||||
expectedException.expect(IllegalStateException.class);
|
||||
expectedException.expectMessage("No milestone for Spring Data Build found containing 1.8 RC1!");
|
||||
|
||||
ModuleIteration moduleIteration = ReleaseTrains.HOPPER.getModuleIteration(Iteration.RC1, "Build");
|
||||
|
||||
mockGetIssuesWith("emptyIssues.json");
|
||||
mockGetMilestonesWith("emptyMilestones.json");
|
||||
|
||||
github.createReleaseTicket(moduleIteration);
|
||||
|
||||
fail("Missing IllegalStateException");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #5
|
||||
*/
|
||||
@Test
|
||||
public void createReleaseTicketShouldFindExistingTicket() throws Exception {
|
||||
|
||||
mockGetMilestonesWith("milestones.json");
|
||||
mockGetIssuesWith("issues.json");
|
||||
|
||||
github.createReleaseTicket(BUILD_HOPPER_RC1);
|
||||
|
||||
verify(0, postRequestedFor(urlPathMatching(MILESTONES_URI)));
|
||||
}
|
||||
|
||||
private void mockGetIssueWith(String fromClassPath, int issueId) {
|
||||
mockService.stubFor(get(urlPathMatching(ISSUES_URI + "/" + issueId)).//
|
||||
willReturn(json(fromClassPath)));
|
||||
}
|
||||
|
||||
private void mockGetIssuesWith(String fromClassPath) {
|
||||
mockService.stubFor(get(urlPathMatching(ISSUES_URI)).//
|
||||
willReturn(json(fromClassPath)));
|
||||
}
|
||||
|
||||
private void mockCreateIssueWith(String fromClassPath) {
|
||||
mockService.stubFor(post(urlPathMatching(ISSUES_URI)).//
|
||||
willReturn(json(fromClassPath)));
|
||||
}
|
||||
|
||||
private void mockGetMilestonesWith(String fromClassPath) {
|
||||
mockService.stubFor(get(urlPathMatching(MILESTONES_URI)).//
|
||||
willReturn(json(fromClassPath)));
|
||||
}
|
||||
|
||||
private void mockCreateMilestoneWith(String fromClassPath) {
|
||||
mockService.stubFor(post(urlPathMatching(MILESTONES_URI)).//
|
||||
willReturn(json(fromClassPath)));
|
||||
}
|
||||
|
||||
private ResponseDefinitionBuilder json(String fromClassPathFile) {
|
||||
return aResponse().//
|
||||
withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).//
|
||||
withBodyFile(fromClassPathFile);
|
||||
|
||||
Collection<Ticket> tickets = gitHubIssueTracker.findTickets(Projects.BUILD, Arrays.asList("1", "2", "-1"));
|
||||
assertThat(tickets, hasSize(2));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.release.jira;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.release.model.Iteration;
|
||||
import org.springframework.data.release.model.ModuleIteration;
|
||||
import org.springframework.data.release.model.ReleaseTrains;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link GithubMilestone}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class GithubMilestoneUnitTests {
|
||||
|
||||
@Test
|
||||
public void rendersGithubGaVersionCorrectly() {
|
||||
|
||||
assertIterationVersion(Iteration.M1, "1.8 M1 (Dijkstra)");
|
||||
assertIterationVersion(Iteration.RC1, "1.8 RC1 (Dijkstra)");
|
||||
assertIterationVersion(Iteration.GA, "1.8 GA (Dijkstra)");
|
||||
|
||||
assertIterationVersion(Iteration.SR1, "1.8.1 (Dijkstra SR1)");
|
||||
assertIterationVersion(Iteration.SR2, "1.8.2 (Dijkstra SR2)");
|
||||
assertIterationVersion(Iteration.SR3, "1.8.3 (Dijkstra SR3)");
|
||||
assertIterationVersion(Iteration.SR4, "1.8.4 (Dijkstra SR4)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesCustomModuleIterationStartVersion() {
|
||||
|
||||
ModuleIteration module = ReleaseTrains.DIJKSTRA.getModuleIteration(Iteration.M1, "Elasticsearch");
|
||||
|
||||
GithubMilestone version = new GithubMilestone(module);
|
||||
assertThat(version.toString(), is("1.0 M1 (Dijkstra)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotUseCustomIterationOnNonFirstiterations() {
|
||||
|
||||
ModuleIteration module = ReleaseTrains.DIJKSTRA.getModuleIteration(Iteration.RC1, "Elasticsearch");
|
||||
|
||||
GithubMilestone version = new GithubMilestone(module);
|
||||
assertThat(version.toString(), is("1.0 RC1 (Dijkstra)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rendersDescriptionCorrectly() {
|
||||
|
||||
ModuleIteration module = ReleaseTrains.DIJKSTRA.getModuleIteration(Iteration.M1, "Elasticsearch");
|
||||
|
||||
GithubMilestone version = new GithubMilestone(module);
|
||||
assertThat(version.getDescription(), is("Dijkstra M2"));
|
||||
}
|
||||
|
||||
private void assertIterationVersion(Iteration iteration, String expected) {
|
||||
|
||||
ModuleIteration module = ReleaseTrains.DIJKSTRA.getModuleIteration(iteration, "Commons");
|
||||
|
||||
GithubMilestone version = new GithubMilestone(module);
|
||||
assertThat(version.toString(), is(expected));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.release.jira;
|
||||
|
||||
import static org.hamcrest.core.Is.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link JiraComponents}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class JiraComponentsUnitTests {
|
||||
|
||||
/**
|
||||
* @see #5
|
||||
*/
|
||||
@Test
|
||||
public void returnsComponentByName() throws Exception {
|
||||
|
||||
JiraComponent fooComponent = new JiraComponent("123", "foo");
|
||||
JiraComponents jiraComponents = JiraComponents.of(Collections.singleton(fooComponent));
|
||||
|
||||
assertThat(jiraComponents.findComponent("foo").isPresent(), is(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #5
|
||||
*/
|
||||
@Test
|
||||
public void returnsEmptyIfComponentMissing() throws Exception {
|
||||
|
||||
JiraComponent fooComponent = new JiraComponent("123", "foo");
|
||||
JiraComponents jiraComponents = JiraComponents.of(Collections.singleton(fooComponent));
|
||||
|
||||
assertThat(jiraComponents.findComponent("baz").isPresent(), is(false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #5
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void failsOnNullArgumentConstruction() throws Exception {
|
||||
|
||||
JiraComponents.of(null);
|
||||
|
||||
fail("Missing IllegalArgumentException");
|
||||
}
|
||||
}
|
||||
@@ -16,42 +16,292 @@
|
||||
|
||||
package org.springframework.data.release.jira;
|
||||
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static com.github.tomakehurst.wiremock.client.WireMock.*;
|
||||
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.release.AbstractIntegrationTests;
|
||||
import org.springframework.data.release.model.Iteration;
|
||||
import org.springframework.data.release.model.ModuleIteration;
|
||||
import org.springframework.data.release.model.ProjectKey;
|
||||
import org.springframework.data.release.model.Projects;
|
||||
import org.springframework.data.release.model.ReleaseTrains;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder;
|
||||
import com.github.tomakehurst.wiremock.common.ClasspathFileSource;
|
||||
import com.github.tomakehurst.wiremock.junit.WireMockRule;
|
||||
|
||||
/**
|
||||
* Integration Tests for {@link Jira} using a local {@link WireMockRule} server.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class JiraIntegrationTests extends AbstractIntegrationTests {
|
||||
|
||||
public static final String CREATE_ISSUE_URI = "/rest/api/2/issue";
|
||||
public static final String CREATE_VERSION_URI = "/rest/api/2/version";
|
||||
public static final String SEARCH_URI = "/rest/api/2/search";
|
||||
public static final String PROJECT_VERSION_URI = "/rest/api/2/project/%s/version";
|
||||
public static final String PROJECT_COMPONENTS_URI = "/rest/api/2/project/%s/components";
|
||||
public static final ModuleIteration REST_HOPPER_RC1 = ReleaseTrains.HOPPER.getModuleIteration(Iteration.RC1, "REST");
|
||||
|
||||
@Rule public WireMockRule mockService = new WireMockRule(
|
||||
wireMockConfig().port(8888).fileSource(new ClasspathFileSource("integration/jira")));
|
||||
|
||||
@Rule public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
@Autowired JiraConnector jira;
|
||||
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
jira.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #5
|
||||
*/
|
||||
@Test
|
||||
public void findResolvedTicketsByTicketIds() throws Exception {
|
||||
|
||||
mockSearchWith("DATAREDIS-1andDATAJPA-1.json");
|
||||
|
||||
Collection<Ticket> tickets = jira.findTickets(Projects.COMMONS, Arrays.asList("DATAREDIS-1", "DATAJPA-1"));
|
||||
assertThat(tickets, hasSize(2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #5
|
||||
*/
|
||||
@Test
|
||||
public void ignoresUnknownTicketsByTicketId() throws Exception {
|
||||
|
||||
mockSearchWith("emptyTickets.json");
|
||||
|
||||
Collection<Ticket> tickets = jira.findTickets(Projects.COMMONS, Arrays.asList("XYZ-1", "UNKOWN-1"));
|
||||
assertThat(tickets, hasSize(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #5
|
||||
*/
|
||||
@Test
|
||||
public void emptyResultWithEmptyTicketIds() throws Exception {
|
||||
|
||||
Collection<Ticket> tickets = jira.findTickets(Projects.COMMONS, Arrays.asList());
|
||||
assertThat(tickets, hasSize(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #5
|
||||
*/
|
||||
@Test
|
||||
public void getReleaseTicketForReturnsTheReleaseTicket() throws Exception {
|
||||
|
||||
mockSearchWith("releaseTickets.json");
|
||||
|
||||
Ticket releaseTicket = jira.getReleaseTicketFor(REST_HOPPER_RC1);
|
||||
assertThat(releaseTicket.getId(), is(Matchers.equalTo("DATAREST-782")));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #5
|
||||
*/
|
||||
@Test
|
||||
public void noReleaseTicketFound() throws Exception {
|
||||
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
expectedException.expectMessage("Did not find a release ticket for Spring Data REST 2.5 RC1");
|
||||
|
||||
mockSearchWith("emptyTickets.json");
|
||||
|
||||
jira.getReleaseTicketFor(REST_HOPPER_RC1);
|
||||
|
||||
fail("Missing IllegalStateException");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #5
|
||||
*/
|
||||
@Test
|
||||
public void getReleaseVersion() throws Exception {
|
||||
|
||||
mockGetProjectVersionsWith("releaseVersions.json", REST_HOPPER_RC1.getProjectKey());
|
||||
|
||||
Optional<JiraReleaseVersion> optional = jira.findJiraReleaseVersion(REST_HOPPER_RC1);
|
||||
|
||||
assertThat(optional.isPresent(), is(true));
|
||||
assertThat(optional.get().getName(), is(Matchers.equalTo("2.5 RC1 (Hopper)")));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #5
|
||||
*/
|
||||
@Test
|
||||
public void createReleaseVersionShouldCreateAVersion() throws Exception {
|
||||
|
||||
mockGetProjectVersionsWith("emptyReleaseVersions.json", REST_HOPPER_RC1.getProjectKey());
|
||||
mockCreateVersionWith("versionCreated.json");
|
||||
|
||||
jira.createReleaseVersion(REST_HOPPER_RC1);
|
||||
|
||||
verify(postRequestedFor(urlPathMatching(CREATE_VERSION_URI)).withRequestBody(
|
||||
equalToJson("{\"name\":\"2.5 RC1 (Hopper)\",\"project\":\"DATAREST\",\"description\":\"Hopper RC1\"}")));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #5
|
||||
*/
|
||||
@Test
|
||||
public void createReleaseVersionShouldFindExistingReleaseVersion() throws Exception {
|
||||
|
||||
ModuleIteration moduleIteration = ReleaseTrains.HOPPER.getModuleIteration(Iteration.RC1, "REST");
|
||||
|
||||
mockGetProjectVersionsWith("releaseVersions.json", moduleIteration.getProjectKey());
|
||||
|
||||
jira.createReleaseVersion(moduleIteration);
|
||||
|
||||
verify(0, postRequestedFor(urlPathMatching(CREATE_VERSION_URI)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #5
|
||||
*/
|
||||
@Test
|
||||
public void createReleaseTicketShouldCreateReleaseTicket() throws Exception {
|
||||
|
||||
ModuleIteration moduleIteration = ReleaseTrains.HOPPER.getModuleIteration(Iteration.RC1, "REST");
|
||||
|
||||
mockGetProjectVersionsWith("releaseVersions.json", moduleIteration.getProjectKey());
|
||||
mockGetProjectComponentsWith("projectComponents.json", moduleIteration.getProjectKey());
|
||||
mockSearchWith("emptyTickets.json");
|
||||
prepareCreateIssueAndReturn("issueCreated.json");
|
||||
|
||||
jira.createReleaseTicket(moduleIteration);
|
||||
|
||||
verify(postRequestedFor(urlPathMatching(CREATE_ISSUE_URI))
|
||||
.withRequestBody(equalToJson("{\"fields\":{\"project\":{\"key\":\"DATAREST\"},"
|
||||
+ "\"issuetype\":{\"name\":\"Task\"},\"summary\":\"Release 2.5 RC1 (Hopper)\","
|
||||
+ "\"fixVersions\":[{\"name\":\"2.5 RC1 (Hopper)\"}],"
|
||||
+ "\"components\":[{\"name\":\"Infrastructure\"}]}}")));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #5
|
||||
*/
|
||||
@Test
|
||||
public void createReleaseTicketShouldCreateReleaseTicketWithoutComponent() throws Exception {
|
||||
|
||||
ModuleIteration moduleIteration = ReleaseTrains.HOPPER.getModuleIteration(Iteration.RC1, "REST");
|
||||
|
||||
mockGetProjectVersionsWith("releaseVersions.json", moduleIteration.getProjectKey());
|
||||
mockGetProjectComponentsWith("emptyProjectComponents.json", moduleIteration.getProjectKey());
|
||||
mockSearchWith("emptyTickets.json");
|
||||
prepareCreateIssueAndReturn("issueCreated.json");
|
||||
|
||||
jira.createReleaseTicket(moduleIteration);
|
||||
|
||||
verify(postRequestedFor(urlPathMatching(CREATE_ISSUE_URI))
|
||||
.withRequestBody(equalToJson("{\"fields\":{\"project\":{\"key\":\"DATAREST\"},"
|
||||
+ "\"issuetype\":{\"name\":\"Task\"},\"summary\":\"Release 2.5 RC1 (Hopper)\","
|
||||
+ "\"fixVersions\":[{\"name\":\"2.5 RC1 (Hopper)\"}]}}")));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #5
|
||||
*/
|
||||
@Test
|
||||
public void createReleaseTicketShouldFailWithNoReleaseVersion() throws Exception {
|
||||
|
||||
expectedException.expect(IllegalStateException.class);
|
||||
expectedException.expectMessage("Did not find a release version for Spring Data REST 2.5 RC1");
|
||||
|
||||
ModuleIteration moduleIteration = ReleaseTrains.HOPPER.getModuleIteration(Iteration.RC1, "REST");
|
||||
|
||||
mockSearchWith("emptyTickets.json");
|
||||
mockGetProjectVersionsWith("emptyReleaseVersions.json", moduleIteration.getProjectKey());
|
||||
|
||||
jira.createReleaseTicket(moduleIteration);
|
||||
|
||||
fail("Missing IllegalStateException");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #5
|
||||
*/
|
||||
@Test
|
||||
public void createReleaseTicketShouldFindExistingTicket() throws Exception {
|
||||
|
||||
ModuleIteration moduleIteration = ReleaseTrains.HOPPER.getModuleIteration(Iteration.RC1, "REST");
|
||||
|
||||
mockGetProjectVersionsWith("releaseVersions.json", moduleIteration.getProjectKey());
|
||||
mockGetProjectComponentsWith("projectComponents.json", moduleIteration.getProjectKey());
|
||||
mockSearchWith("releaseTickets.json");
|
||||
|
||||
jira.createReleaseTicket(moduleIteration);
|
||||
|
||||
verify(0, postRequestedFor(urlPathMatching(CREATE_ISSUE_URI)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #5
|
||||
*/
|
||||
@Test
|
||||
public void assignTicketToMe() throws Exception {
|
||||
|
||||
mockService.stubFor(post(urlPathMatching("/rest/api/2/issue/DATAREDIS-99999")).//
|
||||
willReturn(aResponse().withStatus(204)));
|
||||
|
||||
jira.assignTicketToMe(new Ticket("DATAREDIS-99999", "", null));
|
||||
|
||||
verify(postRequestedFor(urlPathMatching("/rest/api/2/issue/DATAREDIS-99999"))
|
||||
.withRequestBody(equalToJson("{\"fields\":{\"assignee\":{\"name\":\"dummy\"}}}")));
|
||||
}
|
||||
|
||||
private void mockSearchWith(String fromClassPath) {
|
||||
mockService.stubFor(get(urlPathMatching(SEARCH_URI)).//
|
||||
willReturn(json(fromClassPath)));
|
||||
}
|
||||
|
||||
private void mockGetProjectVersionsWith(String fromClassPath, ProjectKey projectKey) {
|
||||
mockService.stubFor(get(urlPathMatching(String.format(PROJECT_VERSION_URI, projectKey))).//
|
||||
willReturn(json(fromClassPath)));
|
||||
}
|
||||
|
||||
private void mockGetProjectComponentsWith(String fromClassPath, ProjectKey projectKey) {
|
||||
mockService.stubFor(get(urlPathMatching(String.format(PROJECT_COMPONENTS_URI, projectKey))).//
|
||||
willReturn(json(fromClassPath)));
|
||||
}
|
||||
|
||||
private void prepareCreateIssueAndReturn(String fromClassPath) {
|
||||
mockService.stubFor(post(urlPathMatching(CREATE_ISSUE_URI)).//
|
||||
willReturn(json(fromClassPath)));
|
||||
}
|
||||
|
||||
private void mockCreateVersionWith(String fromClassPath) {
|
||||
mockService.stubFor(post(urlPathMatching(CREATE_VERSION_URI)).//
|
||||
willReturn(json(fromClassPath)));
|
||||
}
|
||||
|
||||
private ResponseDefinitionBuilder json(String fromClassPathFile) {
|
||||
return aResponse().//
|
||||
withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).//
|
||||
withBodyFile(fromClassPathFile);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.data.release.model.ReleaseTrains;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link JiraVersion}.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class JiraVersionUnitTests {
|
||||
@@ -49,7 +49,7 @@ public class JiraVersionUnitTests {
|
||||
ModuleIteration module = ReleaseTrains.DIJKSTRA.getModuleIteration(Iteration.M1, "Elasticsearch");
|
||||
|
||||
JiraVersion version = new JiraVersion(module);
|
||||
assertThat(version.toString(), is("1.0 M2 (Dijkstra)"));
|
||||
assertThat(version.toString(), is("1.0 M1 (Dijkstra)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -61,6 +61,15 @@ public class JiraVersionUnitTests {
|
||||
assertThat(version.toString(), is("1.0 RC1 (Dijkstra)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rendersDescriptionCorrectly() {
|
||||
|
||||
ModuleIteration module = ReleaseTrains.DIJKSTRA.getModuleIteration(Iteration.M1, "Elasticsearch");
|
||||
|
||||
JiraVersion version = new JiraVersion(module);
|
||||
assertThat(version.getDescription(), is("Dijkstra M2"));
|
||||
}
|
||||
|
||||
private void assertIterationVersion(Iteration iteration, String expected) {
|
||||
|
||||
ModuleIteration module = ReleaseTrains.DIJKSTRA.getModuleIteration(iteration, "Commons");
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.release.jira;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.test.util.AssertionErrors.fail;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.release.model.Iteration;
|
||||
import org.springframework.data.release.model.ReleaseTrains;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link Tickets}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class TicketsUnitTests {
|
||||
|
||||
@Test
|
||||
public void hasReleaseTicketShouldReturnTrue() throws Exception {
|
||||
|
||||
Ticket ticket = new Ticket("1234", "Release 1.10 GA (Hopper)", new JiraTicketStatus(false, "", ""));
|
||||
Tickets tickets = new Tickets(Collections.singletonList(ticket));
|
||||
|
||||
boolean result = tickets.hasReleaseTicket(ReleaseTrains.HOPPER.getModuleIteration(Iteration.GA, "JPA"));
|
||||
assertThat(result, is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasReleaseTickeForTicketWithoutTrainNameShouldReturnFalse() throws Exception {
|
||||
|
||||
Ticket ticket = new Ticket("1234", "Release 1.10 GA", new JiraTicketStatus(false, "", ""));
|
||||
Tickets tickets = new Tickets(Collections.singletonList(ticket));
|
||||
|
||||
boolean result = tickets.hasReleaseTicket(ReleaseTrains.HOPPER.getModuleIteration(Iteration.GA, "JPA"));
|
||||
assertThat(result, is(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getReleaseTicketReturnsReleaseTicket() throws Exception {
|
||||
|
||||
Ticket ticket = new Ticket("1234", "Release 1.10 GA (Hopper)", new JiraTicketStatus(false, "", ""));
|
||||
Tickets tickets = new Tickets(Collections.singletonList(ticket));
|
||||
|
||||
Ticket releaseTicket = tickets.getReleaseTicket(ReleaseTrains.HOPPER.getModuleIteration(Iteration.GA, "JPA"));
|
||||
assertThat(releaseTicket, is(ticket));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void getReleaseTicketThrowsExceptionWithoutAReleaseTicket() throws Exception {
|
||||
|
||||
Ticket ticket = new Ticket("1234", "Release 1.10 GA", new JiraTicketStatus(false, "", ""));
|
||||
Tickets tickets = new Tickets(Collections.singletonList(ticket));
|
||||
|
||||
tickets.getReleaseTicket(ReleaseTrains.HOPPER.getModuleIteration(Iteration.GA, "JPA"));
|
||||
fail("Missing IllegalStateException");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getResolvedReleaseTicket() throws Exception {
|
||||
|
||||
Ticket ticket = new Ticket("1234", "Release 1.10 GA (Hopper)", new JiraTicketStatus(true, "", ""));
|
||||
Tickets tickets = new Tickets(Collections.singletonList(ticket));
|
||||
|
||||
Ticket releaseTicket = tickets.getReleaseTicket(ReleaseTrains.HOPPER.getModuleIteration(Iteration.GA, "JPA"));
|
||||
assertThat(releaseTicket, is(ticket));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getReleaseTicketsReturnsReleaseTickets() throws Exception {
|
||||
|
||||
Ticket ticket = new Ticket("1234", "Release 1.10 GA (Hopper)", new JiraTicketStatus(false, "", ""));
|
||||
Tickets tickets = new Tickets(Collections.singletonList(ticket));
|
||||
|
||||
Tickets result = tickets
|
||||
.getReleaseTickets(ReleaseTrains.HOPPER.getModuleIteration(Iteration.GA, "JPA").getTrainIteration());
|
||||
assertThat(result.getTickets().contains(ticket), is(true));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user