Search in sources :

Example 16 with GroupInput

use of com.google.gerrit.extensions.api.groups.GroupInput in project gerrit by GerritCodeReview.

the class SubmitRequirementIT method submitRequirement_evaluatedWithInternalUserCredentials.

@Test
public void submitRequirement_evaluatedWithInternalUserCredentials() throws Exception {
    GroupInput in = new GroupInput();
    in.name = "invisible-group";
    in.visibleToAll = false;
    in.ownerId = adminGroupUuid().get();
    gApi.groups().create(in);
    configSubmitRequirement(project, SubmitRequirement.builder().setName("My-Requirement").setApplicabilityExpression(SubmitRequirementExpression.of("ownerin:invisible-group")).setSubmittabilityExpression(SubmitRequirementExpression.create("is:true")).setAllowOverrideInChildProjects(false).build());
    requestScopeOperations.setApiUser(user.id());
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    ChangeInfo change = gApi.changes().id(changeId).get();
    SubmitRequirementResultInfo srResult = change.submitRequirements.stream().filter(sr -> sr.name.equals("My-Requirement")).collect(MoreCollectors.onlyElement());
    assertThat(srResult.status).isEqualTo(Status.NOT_APPLICABLE);
}
Also used : Status(com.google.gerrit.extensions.common.SubmitRequirementResultInfo.Status) Arrays(java.util.Arrays) ProjectConfig(com.google.gerrit.server.project.ProjectConfig) Inject(com.google.inject.Inject) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) RevObject(org.eclipse.jgit.revwalk.RevObject) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) LegacySubmitRequirement(com.google.gerrit.entities.LegacySubmitRequirement) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) LabelType(com.google.gerrit.entities.LabelType) Map(java.util.Map) RefNames(com.google.gerrit.entities.RefNames) SubmitRequirementResultInfo(com.google.gerrit.extensions.common.SubmitRequirementResultInfo) TestProjectUpdate.allow(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allow) TestProjectUpdate(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) MoreCollectors(com.google.common.collect.MoreCollectors) SubmitType(com.google.gerrit.extensions.client.SubmitType) Collection(java.util.Collection) VerifyNoPiiInChangeNotes(com.google.gerrit.acceptance.VerifyNoPiiInChangeNotes) RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) RawParseUtils(org.eclipse.jgit.util.RawParseUtils) TestLabels.label(com.google.gerrit.server.project.testing.TestLabels.label) TestLabels.value(com.google.gerrit.server.project.testing.TestLabels.value) SubmitRecord(com.google.gerrit.entities.SubmitRecord) NoHttpd(com.google.gerrit.acceptance.NoHttpd) RequestScopeOperations(com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations) ChangeData(com.google.gerrit.server.query.change.ChangeData) List(java.util.List) Nullable(com.google.gerrit.common.Nullable) Ref(org.eclipse.jgit.lib.Ref) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Optional(java.util.Optional) TestProjectUpdate.allowLabel(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allowLabel) IndexPreloadingUtil(com.google.gerrit.httpd.raw.IndexPreloadingUtil) IntStream(java.util.stream.IntStream) GroupInput(com.google.gerrit.extensions.api.groups.GroupInput) Iterables(com.google.common.collect.Iterables) LabelId(com.google.gerrit.entities.LabelId) RevCommit(org.eclipse.jgit.revwalk.RevCommit) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) SubmitRequirementExpression(com.google.gerrit.entities.SubmitRequirementExpression) TestLabels(com.google.gerrit.server.project.testing.TestLabels) UseTimezone(com.google.gerrit.acceptance.UseTimezone) ImmutableList(com.google.common.collect.ImmutableList) LabelFunction(com.google.gerrit.entities.LabelFunction) SubmitRequirementInput(com.google.gerrit.extensions.common.SubmitRequirementInput) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) SubmitRecordInfo(com.google.gerrit.extensions.common.SubmitRecordInfo) ActionInfo(com.google.gerrit.extensions.common.ActionInfo) LabelDefinitionInput(com.google.gerrit.extensions.common.LabelDefinitionInput) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) ListChangesOption(com.google.gerrit.extensions.client.ListChangesOption) SubmitRequirement(com.google.gerrit.entities.SubmitRequirement) TestRepository(org.eclipse.jgit.junit.TestRepository) SubmitRule(com.google.gerrit.server.rules.SubmitRule) Permission(com.google.gerrit.entities.Permission) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) SubmitRequirementExpressionResult(com.google.gerrit.entities.SubmitRequirementExpressionResult) LegacySubmitRequirementInfo(com.google.gerrit.extensions.common.LegacySubmitRequirementInfo) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) Project(com.google.gerrit.entities.Project) Repository(org.eclipse.jgit.lib.Repository) SubmitRequirementExpressionInfo(com.google.gerrit.extensions.common.SubmitRequirementExpressionInfo) GroupInput(com.google.gerrit.extensions.api.groups.GroupInput) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) SubmitRequirementResultInfo(com.google.gerrit.extensions.common.SubmitRequirementResultInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 17 with GroupInput

use of com.google.gerrit.extensions.api.groups.GroupInput in project gerrit by GerritCodeReview.

the class GroupsIT method createGroupWithInvalidUuid_BadRequest.

@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));
}
Also used : GroupInput(com.google.gerrit.extensions.api.groups.GroupInput) AccountGroup(com.google.gerrit.entities.AccountGroup) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 18 with GroupInput

use of com.google.gerrit.extensions.api.groups.GroupInput 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)

Example 19 with GroupInput

use of com.google.gerrit.extensions.api.groups.GroupInput in project gerrit by GerritCodeReview.

the class GroupsIT method createGroupWithUuid.

@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);
}
Also used : GroupInput(com.google.gerrit.extensions.api.groups.GroupInput) AccountGroup(com.google.gerrit.entities.AccountGroup) 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 20 with GroupInput

use of com.google.gerrit.extensions.api.groups.GroupInput in project gerrit by GerritCodeReview.

the class GroupsIT method cachedGroupsForMemberAreUpdatedOnGroupCreation.

@Test
public void cachedGroupsForMemberAreUpdatedOnGroupCreation() throws Exception {
    Account.Id accountId = accountOperations.newAccount().create();
    // Fill the cache for the observed account.
    groupIncludeCache.getGroupsWithMember(accountId);
    GroupInput groupInput = new GroupInput();
    groupInput.name = name("Users");
    groupInput.members = ImmutableList.of(String.valueOf(accountId.get()));
    GroupInfo group = gApi.groups().create(groupInput).get();
    Collection<AccountGroup.UUID> groups = groupIncludeCache.getGroupsWithMember(accountId);
    assertThat(groups).containsExactly(AccountGroup.uuid(group.id));
}
Also used : TestAccount(com.google.gerrit.acceptance.TestAccount) Account(com.google.gerrit.entities.Account) GroupInput(com.google.gerrit.extensions.api.groups.GroupInput) 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

GroupInput (com.google.gerrit.extensions.api.groups.GroupInput)27 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)13 Test (org.junit.Test)13 GroupInfo (com.google.gerrit.extensions.common.GroupInfo)9 GroupAssert.assertGroupInfo (com.google.gerrit.acceptance.api.group.GroupAssert.assertGroupInfo)6 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)5 TestAccount (com.google.gerrit.acceptance.TestAccount)5 AccountGroup (com.google.gerrit.entities.AccountGroup)5 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)4 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)4 Account (com.google.gerrit.entities.Account)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Iterables (com.google.common.collect.Iterables)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 ExtensionRegistry (com.google.gerrit.acceptance.ExtensionRegistry)2 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)2 NoHttpd (com.google.gerrit.acceptance.NoHttpd)2 ProjectOperations (com.google.gerrit.acceptance.testsuite.project.ProjectOperations)2