assertThat(Iterables.transform(client.getProjectClient().getProject("TST").claim().getVersions(),
new VersionToNameMapper()), containsInAnyOrder("1.1", "1"));
final VersionInput versionInput = VersionInput.create("TST", "My newly created version", "A description\nwith\new line", null, false, false);
final Version version = client.getVersionRestClient().createVersion(versionInput).claim();
assertVersionInputAndVersionEquals(versionInput, version);
assertNotNull(version.getId());
assertThat(Iterables.transform(client.getProjectClient().getProject("TST").claim()
.getVersions(), new VersionToNameMapper()),
containsInAnyOrder("1.1", "1", versionInput.getName()));
TestUtil.assertErrorCode(Response.Status.BAD_REQUEST, "A version with this name already exists in this project.", new Runnable() {
@Override
public void run() {
client.getVersionRestClient().createVersion(versionInput).claim();
}
});
final VersionInput versionInput2 = VersionInput.create("TST", "My newly created version2", "A description\nwith\new line", null, false, false);
setAnonymousMode();
TestUtil.assertErrorCode(IntegrationTestUtil.TESTING_JIRA_5_OR_NEWER ? Response.Status.NOT_FOUND
: Response.Status.UNAUTHORIZED, new Runnable() {
@Override
public void run() {
client.getVersionRestClient().createVersion(versionInput2).claim();
}
});
setUser2();
TestUtil.assertErrorCode(Response.Status.NOT_FOUND, "Project with key 'TST' either does not exist or you do not have permission to create versions in it.", new Runnable() {
@Override
public void run() {
client.getVersionRestClient().createVersion(versionInput2).claim();
}
});
// now version updates
setAdmin();
final VersionInput newVersionInput = new VersionInputBuilder(versionInput.getProjectKey(), version)
.setDescription("my updated description").setReleased(true).setName("my updated name").build();
client.getVersionRestClient().updateVersion(version.getSelf(), newVersionInput).claim();
final Version modifiedVersion = client.getVersionRestClient().updateVersion(version.getSelf(), newVersionInput).claim();
assertVersionInputAndVersionEquals(newVersionInput, modifiedVersion);
final VersionInput duplicateVersionInput = new VersionInputBuilder("TST", modifiedVersion).setName("1.1").build();
TestUtil.assertErrorCode(Response.Status.BAD_REQUEST, "A version with this name already exists in this project.", new Runnable() {
@Override
public void run() {
client.getVersionRestClient().updateVersion(modifiedVersion.getSelf(), duplicateVersionInput).claim();
}
});
setAnonymousMode();
TestUtil.assertErrorCode(IntegrationTestUtil.TESTING_JIRA_5_OR_NEWER ? Response.Status.NOT_FOUND
: Response.Status.UNAUTHORIZED, new Runnable() {
@Override
public void run() {
client.getVersionRestClient().updateVersion(modifiedVersion.getSelf(), newVersionInput).claim();
}
});
setAdmin();
final Version restrictedVersion = client.getVersionRestClient().createVersion(new VersionInputBuilder("RST")
.setName("My version").build()).claim();
final VersionInput restrictedVersionInput = new VersionInputBuilder("RST", restrictedVersion)
.setDescription("another description").build();
setUser2();
TestUtil.assertErrorCode(Response.Status.NOT_FOUND, "You must have browse project rights in order to view versions.", new Runnable() {
@Override
public void run() {
client.getVersionRestClient().updateVersion(restrictedVersion.getSelf(), restrictedVersionInput).claim();
}
});
}