}
assertThat(Iterables.transform(client.getProjectClient().getProject("TST", pm).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, pm);
assertVersionInputAndVersionEquals(versionInput, version);
assertNotNull(version.getId());
assertThat(Iterables.transform(client.getProjectClient().getProject("TST", pm).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, pm);
}
});
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, pm);
}
});
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, pm);
}
});
// 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, pm);
final Version modifiedVersion = client.getVersionRestClient().updateVersion(version.getSelf(), newVersionInput, pm);
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, pm);
}
});
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, pm);
}
});
setAdmin();
final Version restrictedVersion = client.getVersionRestClient().createVersion(new VersionInputBuilder("RST").setName("My version").build(), pm);
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, pm);