Search in sources :

Example 61 with GroupInfo

use of com.google.gerrit.extensions.common.GroupInfo in project gerrit by GerritCodeReview.

the class GroupsIT method groupCanBeRenamedToItsCurrentName.

@Test
public void groupCanBeRenamedToItsCurrentName() throws Exception {
    String name = name("Users");
    GroupInfo group = gApi.groups().create(name).get();
    gApi.groups().id(group.id).name(name);
    assertThat(gApi.groups().id(group.id).name()).isEqualTo(name);
}
Also used : GroupAssert.assertGroupInfo(com.google.gerrit.acceptance.api.group.GroupAssert.assertGroupInfo) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 62 with GroupInfo

use of com.google.gerrit.extensions.common.GroupInfo in project gerrit by GerritCodeReview.

the class GroupsIT method getAuditLogAfterDeletingASubgroup.

/**
 * {@code @Sandboxed} is used by this test because it deletes a group reference which introduces
 * an inconsistency for the group storage. Once group deletion is supported, this test should be
 * updated to use the API instead.
 */
@Test
@Sandboxed
@IgnoreGroupInconsistencies
public void getAuditLogAfterDeletingASubgroup() throws Exception {
    GroupInfo parentGroup = gApi.groups().create(name("parent-group")).get();
    // Creates a subgroup and adds it to "parent-group" as a subgroup.
    GroupInfo subgroup = gApi.groups().create(name("sub-group")).get();
    gApi.groups().id(parentGroup.id).addGroups(subgroup.id);
    // Deletes the subgroup.
    deleteGroupRef(subgroup.id);
    List<? extends GroupAuditEventInfo> auditEvents = gApi.groups().id(parentGroup.id).auditLog();
    assertThat(auditEvents).hasSize(2);
    // Verify the unavailable subgroup's name is null.
    assertSubgroupAuditEvent(auditEvents.get(0), GroupAuditEventInfo.Type.ADD_GROUP, admin.id(), null);
}
Also used : GroupAssert.assertGroupInfo(com.google.gerrit.acceptance.api.group.GroupAssert.assertGroupInfo) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test) Sandboxed(com.google.gerrit.acceptance.Sandboxed)

Example 63 with GroupInfo

use of com.google.gerrit.extensions.common.GroupInfo in project gerrit by GerritCodeReview.

the class GroupsIT method createGroupNameIsTrimmed.

@Test
public void createGroupNameIsTrimmed() throws Exception {
    String newGroupName = name("newGroup");
    GroupInfo g = gApi.groups().create(" " + newGroupName + " ").get();
    assertGroupInfo(group(newGroupName), g);
}
Also used : GroupAssert.assertGroupInfo(com.google.gerrit.acceptance.api.group.GroupAssert.assertGroupInfo) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 64 with GroupInfo

use of com.google.gerrit.extensions.common.GroupInfo in project gerrit by GerritCodeReview.

the class GroupsIT method stalenessChecker.

@Test
@IgnoreGroupInconsistencies
public void stalenessChecker() throws Exception {
    // Newly created group is not stale
    GroupInfo groupInfo = gApi.groups().create(name("foo")).get();
    AccountGroup.UUID groupUuid = AccountGroup.uuid(groupInfo.id);
    assertThat(stalenessChecker.check(groupUuid).isStale()).isFalse();
    // Manual update makes index document stale
    String groupRef = RefNames.refsGroups(groupUuid);
    try (Repository repo = repoManager.openRepository(allUsers);
        RevWalk rw = new RevWalk(repo)) {
        RevCommit commit = rw.parseCommit(repo.exactRef(groupRef).getObjectId());
        ObjectId emptyCommit = createCommit(repo, commit.getFullMessage(), commit.getTree());
        RefUpdate updateRef = repo.updateRef(groupRef);
        updateRef.setExpectedOldObjectId(commit.toObjectId());
        updateRef.setNewObjectId(emptyCommit);
        assertThat(updateRef.forceUpdate()).isEqualTo(RefUpdate.Result.FORCED);
    }
    assertStaleGroupAndReindex(groupUuid);
    // Manually delete group
    try (Repository repo = repoManager.openRepository(allUsers);
        RevWalk rw = new RevWalk(repo)) {
        RevCommit commit = rw.parseCommit(repo.exactRef(groupRef).getObjectId());
        RefUpdate updateRef = repo.updateRef(groupRef);
        updateRef.setExpectedOldObjectId(commit.toObjectId());
        updateRef.setNewObjectId(ObjectId.zeroId());
        updateRef.setForceUpdate(true);
        assertThat(updateRef.delete()).isEqualTo(RefUpdate.Result.FORCED);
    }
    assertStaleGroupAndReindex(groupUuid);
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) AccountGroup(com.google.gerrit.entities.AccountGroup) GroupAssert.assertGroupInfo(com.google.gerrit.acceptance.api.group.GroupAssert.assertGroupInfo) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) ObjectId(org.eclipse.jgit.lib.ObjectId) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit) RefUpdate(org.eclipse.jgit.lib.RefUpdate) RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 65 with GroupInfo

use of com.google.gerrit.extensions.common.GroupInfo in project gerrit by GerritCodeReview.

the class GroupsIT method createGroupWithExistingUuid_Conflict.

@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));
}
Also used : GroupInput(com.google.gerrit.extensions.api.groups.GroupInput) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) GroupAssert.assertGroupInfo(com.google.gerrit.acceptance.api.group.GroupAssert.assertGroupInfo) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

GroupInfo (com.google.gerrit.extensions.common.GroupInfo)92 Test (org.junit.Test)60 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)43 AccountGroup (com.google.gerrit.entities.AccountGroup)28 GroupAssert.assertGroupInfo (com.google.gerrit.acceptance.api.group.GroupAssert.assertGroupInfo)24 ArrayList (java.util.ArrayList)11 GroupInput (com.google.gerrit.extensions.api.groups.GroupInput)10 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)10 Account (com.google.gerrit.entities.Account)8 AuthException (com.google.gerrit.extensions.restapi.AuthException)8 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)8 GroupControl (com.google.gerrit.server.account.GroupControl)8 GroupDescription (com.google.gerrit.entities.GroupDescription)7 GroupReference (com.google.gerrit.entities.GroupReference)7 TestAccount (com.google.gerrit.acceptance.TestAccount)6 InternalGroup (com.google.gerrit.entities.InternalGroup)6 GroupDescription (com.google.gerrit.common.data.GroupDescription)5 NoSuchGroupException (com.google.gerrit.exceptions.NoSuchGroupException)5 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)5 InternalGroupDescription (com.google.gerrit.server.group.InternalGroupDescription)5