Search in sources :

Example 1 with GroupApi

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

the class AbstractDaemonTest method configureContributorAgreement.

protected ContributorAgreement configureContributorAgreement(boolean autoVerify) throws Exception {
    ContributorAgreement ca;
    if (autoVerify) {
        String g = createGroup("cla-test-group");
        GroupApi groupApi = gApi.groups().id(g);
        groupApi.description("CLA test group");
        AccountGroup caGroup = groupCache.get(new AccountGroup.UUID(groupApi.detail().id));
        GroupReference groupRef = GroupReference.forGroup(caGroup);
        PermissionRule rule = new PermissionRule(groupRef);
        rule.setAction(PermissionRule.Action.ALLOW);
        ca = new ContributorAgreement("cla-test");
        ca.setAutoVerify(groupRef);
        ca.setAccepted(ImmutableList.of(rule));
    } else {
        ca = new ContributorAgreement("cla-test-no-auto-verify");
    }
    ca.setDescription("description");
    ca.setAgreementUrl("agreement-url");
    ProjectConfig cfg = projectCache.checkedGet(allProjects).getConfig();
    cfg.replace(ca);
    saveProjectConfig(allProjects, cfg);
    return ca;
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) GroupApi(com.google.gerrit.extensions.api.groups.GroupApi) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) PermissionRule(com.google.gerrit.common.data.PermissionRule) ContributorAgreement(com.google.gerrit.common.data.ContributorAgreement) IdString(com.google.gerrit.extensions.restapi.IdString) GroupReference(com.google.gerrit.common.data.GroupReference)

Example 2 with GroupApi

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

the class GroupsIT method getAuditLog.

@Test
public void getAuditLog() throws Exception {
    GroupApi g = gApi.groups().create(name("group"));
    List<? extends GroupAuditEventInfo> auditEvents = g.auditLog();
    assertThat(auditEvents).hasSize(1);
    assertAuditEvent(auditEvents.get(0), Type.ADD_USER, admin.id, admin.id);
    g.addMembers(user.username);
    auditEvents = g.auditLog();
    assertThat(auditEvents).hasSize(2);
    assertAuditEvent(auditEvents.get(0), Type.ADD_USER, admin.id, user.id);
    g.removeMembers(user.username);
    auditEvents = g.auditLog();
    assertThat(auditEvents).hasSize(3);
    assertAuditEvent(auditEvents.get(0), Type.REMOVE_USER, admin.id, user.id);
    String otherGroup = name("otherGroup");
    gApi.groups().create(otherGroup);
    g.addGroups(otherGroup);
    auditEvents = g.auditLog();
    assertThat(auditEvents).hasSize(4);
    assertAuditEvent(auditEvents.get(0), Type.ADD_GROUP, admin.id, otherGroup);
    g.removeGroups(otherGroup);
    auditEvents = g.auditLog();
    assertThat(auditEvents).hasSize(5);
    assertAuditEvent(auditEvents.get(0), Type.REMOVE_GROUP, admin.id, otherGroup);
    Timestamp lastDate = null;
    for (GroupAuditEventInfo auditEvent : auditEvents) {
        if (lastDate != null) {
            assertThat(lastDate).isGreaterThan(auditEvent.date);
        }
        lastDate = auditEvent.date;
    }
}
Also used : GroupApi(com.google.gerrit.extensions.api.groups.GroupApi) GroupAuditEventInfo(com.google.gerrit.extensions.common.GroupAuditEventInfo) Timestamp(java.sql.Timestamp) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

GroupApi (com.google.gerrit.extensions.api.groups.GroupApi)2 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 ContributorAgreement (com.google.gerrit.common.data.ContributorAgreement)1 GroupReference (com.google.gerrit.common.data.GroupReference)1 PermissionRule (com.google.gerrit.common.data.PermissionRule)1 GroupAuditEventInfo (com.google.gerrit.extensions.common.GroupAuditEventInfo)1 IdString (com.google.gerrit.extensions.restapi.IdString)1 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)1 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)1 Timestamp (java.sql.Timestamp)1 Test (org.junit.Test)1