Merge branch 'stable-3.1'
* stable-3.1: Consistently declare 'throws Exception' from @Test annotated methods CreateGroup: Allow to create a group with given UUID Change-Id: I9918a447cdc72e7a5ce324fb9f755de4c682aa78
This commit is contained in:
commit
c260214e3b
@ -503,8 +503,9 @@ describes the created group.
|
|||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
If the group creation fails because the name is already in use the
|
If the group creation fails because the name is already in use, or the
|
||||||
response is "`409 Conflict`".
|
UUID was specified and the UUID is already in use, the response is
|
||||||
|
"`409 Conflict`".
|
||||||
|
|
||||||
[[get-group-detail]]
|
[[get-group-detail]]
|
||||||
=== Get Group Detail
|
=== Get Group Detail
|
||||||
@ -1591,6 +1592,7 @@ a new internal group.
|
|||||||
|Field Name ||Description
|
|Field Name ||Description
|
||||||
|`name` |optional|The name of the group (not encoded). +
|
|`name` |optional|The name of the group (not encoded). +
|
||||||
If set, must match the group name in the URL.
|
If set, must match the group name in the URL.
|
||||||
|
|`uuid` |optional|The UUID of the group.
|
||||||
|`description` |optional|The description of the group.
|
|`description` |optional|The description of the group.
|
||||||
|`visible_to_all`|optional|
|
|`visible_to_all`|optional|
|
||||||
Whether the group is visible to all registered users. +
|
Whether the group is visible to all registered users. +
|
||||||
|
@ -18,6 +18,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public class GroupInput {
|
public class GroupInput {
|
||||||
public String name;
|
public String name;
|
||||||
|
public String uuid;
|
||||||
public String description;
|
public String description;
|
||||||
public Boolean visibleToAll;
|
public Boolean visibleToAll;
|
||||||
public String ownerId;
|
public String ownerId;
|
||||||
|
@ -20,6 +20,7 @@ import java.util.Collection;
|
|||||||
|
|
||||||
public class CreateGroupArgs {
|
public class CreateGroupArgs {
|
||||||
private AccountGroup.NameKey groupName;
|
private AccountGroup.NameKey groupName;
|
||||||
|
public AccountGroup.UUID uuid;
|
||||||
public String groupDescription;
|
public String groupDescription;
|
||||||
public boolean visibleToAll;
|
public boolean visibleToAll;
|
||||||
public AccountGroup.UUID ownerGroupUuid;
|
public AccountGroup.UUID ownerGroupUuid;
|
||||||
|
@ -138,6 +138,16 @@ public class CreateGroup
|
|||||||
AccountGroup.UUID ownerUuid = owner(input);
|
AccountGroup.UUID ownerUuid = owner(input);
|
||||||
CreateGroupArgs args = new CreateGroupArgs();
|
CreateGroupArgs args = new CreateGroupArgs();
|
||||||
args.setGroupName(name);
|
args.setGroupName(name);
|
||||||
|
args.uuid = Strings.isNullOrEmpty(input.uuid) ? null : AccountGroup.UUID.parse(input.uuid);
|
||||||
|
if (args.uuid != null) {
|
||||||
|
if (!args.uuid.isInternalGroup()) {
|
||||||
|
throw new BadRequestException(String.format("invalid group UUID '%s'", args.uuid.get()));
|
||||||
|
}
|
||||||
|
if (groupCache.get(args.uuid).isPresent()) {
|
||||||
|
throw new ResourceConflictException(
|
||||||
|
String.format("group with UUID '%s' already exists", args.uuid.get()));
|
||||||
|
}
|
||||||
|
}
|
||||||
args.groupDescription = Strings.emptyToNull(input.description);
|
args.groupDescription = Strings.emptyToNull(input.description);
|
||||||
args.visibleToAll = MoreObjects.firstNonNull(input.visibleToAll, defaultVisibleToAll);
|
args.visibleToAll = MoreObjects.firstNonNull(input.visibleToAll, defaultVisibleToAll);
|
||||||
args.ownerGroupUuid = ownerUuid;
|
args.ownerGroupUuid = ownerUuid;
|
||||||
@ -196,9 +206,11 @@ public class CreateGroup
|
|||||||
|
|
||||||
AccountGroup.Id groupId = AccountGroup.id(sequences.nextGroupId());
|
AccountGroup.Id groupId = AccountGroup.id(sequences.nextGroupId());
|
||||||
AccountGroup.UUID uuid =
|
AccountGroup.UUID uuid =
|
||||||
GroupUuid.make(
|
MoreObjects.firstNonNull(
|
||||||
createGroupArgs.getGroupName(),
|
createGroupArgs.uuid,
|
||||||
self.get().newCommitterIdent(serverIdent.getWhen(), serverIdent.getTimeZone()));
|
GroupUuid.make(
|
||||||
|
createGroupArgs.getGroupName(),
|
||||||
|
self.get().newCommitterIdent(serverIdent.getWhen(), serverIdent.getTimeZone())));
|
||||||
InternalGroupCreation groupCreation =
|
InternalGroupCreation groupCreation =
|
||||||
InternalGroupCreation.builder()
|
InternalGroupCreation.builder()
|
||||||
.setGroupUUID(uuid)
|
.setGroupUUID(uuid)
|
||||||
|
@ -414,6 +414,43 @@ public class GroupsIT extends AbstractDaemonTest {
|
|||||||
assertThat(thrown).hasMessageThat().contains("group name 'Anonymous Users' is reserved");
|
assertThat(thrown).hasMessageThat().contains("group name 'Anonymous Users' is reserved");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createGroupWithUuid() throws Exception {
|
||||||
|
AccountGroup.UUID uuid = AccountGroup.UUID.parse("4eb25d1cca562f53b9356117f33840706a36a349");
|
||||||
|
GroupInput input = new GroupInput();
|
||||||
|
input.uuid = uuid.get();
|
||||||
|
input.name = name("new-group");
|
||||||
|
GroupInfo info = gApi.groups().create(input).get();
|
||||||
|
assertThat(info.name).isEqualTo(input.name);
|
||||||
|
assertThat(info.id).isEqualTo(input.uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createGroupWithExistingUuid_Conflict() throws Exception {
|
||||||
|
GroupInfo existingGroup = gApi.groups().create(name("new-group")).get();
|
||||||
|
GroupInput input = new GroupInput();
|
||||||
|
input.uuid = existingGroup.id;
|
||||||
|
input.name = name("another-new-group");
|
||||||
|
ResourceConflictException thrown =
|
||||||
|
assertThrows(ResourceConflictException.class, () -> gApi.groups().create(input).get());
|
||||||
|
assertThat(thrown)
|
||||||
|
.hasMessageThat()
|
||||||
|
.isEqualTo(String.format("group with UUID '%s' already exists", input.uuid));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createGroupWithInvalidUuid_BadRequest() throws Exception {
|
||||||
|
AccountGroup.UUID uuid = AccountGroup.UUID.parse("foo:bar");
|
||||||
|
GroupInput input = new GroupInput();
|
||||||
|
input.uuid = uuid.get();
|
||||||
|
input.name = name("new-group");
|
||||||
|
BadRequestException thrown =
|
||||||
|
assertThrows(BadRequestException.class, () -> gApi.groups().create(input).get());
|
||||||
|
assertThat(thrown)
|
||||||
|
.hasMessageThat()
|
||||||
|
.isEqualTo(String.format("invalid group UUID '%s'", input.uuid));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createGroupWithProperties() throws Exception {
|
public void createGroupWithProperties() throws Exception {
|
||||||
GroupInput in = new GroupInput();
|
GroupInput in = new GroupInput();
|
||||||
|
Loading…
Reference in New Issue
Block a user