Search in sources :

Example 1 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class ProjectIT method createProjectWithInitialBranches.

@Test
public void createProjectWithInitialBranches() throws Exception {
    ProjectIndexedCounter projectIndexedCounter = new ProjectIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(projectIndexedCounter)) {
        String name = name("foo");
        ProjectInput input = new ProjectInput();
        input.name = name;
        input.createEmptyCommit = true;
        input.branches = ImmutableList.of("foo", "master");
        assertThat(gApi.projects().create(input).get().name).isEqualTo(name);
        assertThat(gApi.projects().name(name).branches().get().stream().map(b -> b.ref).collect(toSet())).containsExactly("refs/heads/foo", "refs/heads/master", "HEAD", RefNames.REFS_CONFIG);
        assertHead(name, "refs/heads/foo");
        RevCommit head = getRemoteHead(name, RefNames.REFS_CONFIG);
        eventRecorder.assertRefUpdatedEvents(name, RefNames.REFS_CONFIG, null, head);
        head = getRemoteHead(name, "refs/heads/foo");
        eventRecorder.assertRefUpdatedEvents(name, "refs/heads/foo", null, head);
        head = getRemoteHead(name, "refs/heads/master");
        eventRecorder.assertRefUpdatedEvents(name, "refs/heads/master", null, head);
        projectIndexedCounter.assertReindexOf(name);
    }
}
Also used : ChangeIndexedListener(com.google.gerrit.extensions.events.ChangeIndexedListener) Module(com.google.inject.Module) Arrays(java.util.Arrays) ProjectConfig(com.google.gerrit.server.project.ProjectConfig) Inject(com.google.inject.Inject) RestResponse(com.google.gerrit.acceptance.RestResponse) SystemGroupBackend(com.google.gerrit.server.group.SystemGroupBackend) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) InheritableBoolean(com.google.gerrit.extensions.client.InheritableBoolean) Config(org.eclipse.jgit.lib.Config) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) ConfigInput(com.google.gerrit.extensions.api.projects.ConfigInput) ConfigInfo(com.google.gerrit.extensions.api.projects.ConfigInfo) Map(java.util.Map) RefNames(com.google.gerrit.entities.RefNames) AuthException(com.google.gerrit.extensions.restapi.AuthException) AtomicLongMap(com.google.common.util.concurrent.AtomicLongMap) CommentLinkInfo(com.google.gerrit.extensions.api.projects.CommentLinkInfo) TestProjectUpdate.allow(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allow) Collectors.toSet(java.util.stream.Collectors.toSet) INHERITED_FROM_PARENT(com.google.gerrit.server.project.ProjectState.INHERITED_FROM_PARENT) ImmutableMap(com.google.common.collect.ImmutableMap) SubmitType(com.google.gerrit.extensions.client.SubmitType) ProjectConfigEntry(com.google.gerrit.server.config.ProjectConfigEntry) Set(java.util.Set) ProjectIndexedListener(com.google.gerrit.extensions.events.ProjectIndexedListener) BranchNameKey(com.google.gerrit.entities.BranchNameKey) RequestScopeOperations(com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations) GroupReference(com.google.gerrit.entities.GroupReference) List(java.util.List) PushResult(org.eclipse.jgit.transport.PushResult) ProjectInput(com.google.gerrit.extensions.api.projects.ProjectInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Optional(java.util.Optional) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) Exports(com.google.gerrit.extensions.annotations.Exports) OVERRIDDEN_BY_GLOBAL(com.google.gerrit.server.project.ProjectState.OVERRIDDEN_BY_GLOBAL) Mockito.mock(org.mockito.Mockito.mock) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) TestProjectUpdate.block(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.block) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) Status(org.eclipse.jgit.transport.RemoteRefUpdate.Status) LabelId(com.google.gerrit.entities.LabelId) RevCommit(org.eclipse.jgit.revwalk.RevCommit) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) CommentLinkInput(com.google.gerrit.extensions.api.projects.CommentLinkInput) HashMap(java.util.HashMap) Lists(com.google.common.collect.Lists) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) ImmutableList(com.google.common.collect.ImmutableList) Change(com.google.gerrit.entities.Change) ProjectInfo(com.google.gerrit.extensions.common.ProjectInfo) GitUtil(com.google.gerrit.acceptance.GitUtil) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) AccountGroup(com.google.gerrit.entities.AccountGroup) GitUtil.pushHead(com.google.gerrit.acceptance.GitUtil.pushHead) INHERITED_FROM_GLOBAL(com.google.gerrit.server.project.ProjectState.INHERITED_FROM_GLOBAL) TestRepository(org.eclipse.jgit.junit.TestRepository) Permission(com.google.gerrit.entities.Permission) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) ProjectState(com.google.gerrit.extensions.client.ProjectState) Truth.assertThat(com.google.common.truth.Truth.assertThat) ConfigValue(com.google.gerrit.extensions.api.projects.ConfigValue) Mockito.verify(org.mockito.Mockito.verify) R_HEADS(org.eclipse.jgit.lib.Constants.R_HEADS) DescriptionInput(com.google.gerrit.extensions.api.projects.DescriptionInput) OVERRIDDEN_BY_PARENT(com.google.gerrit.server.project.ProjectState.OVERRIDDEN_BY_PARENT) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Project(com.google.gerrit.entities.Project) R_TAGS(org.eclipse.jgit.lib.Constants.R_TAGS) Collections(java.util.Collections) AbstractModule(com.google.inject.AbstractModule) ProjectInput(com.google.gerrit.extensions.api.projects.ProjectInput) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 2 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class ProjectIT method createAndDeleteBranch.

@Test
public void createAndDeleteBranch() throws Exception {
    ProjectIndexedCounter projectIndexedCounter = new ProjectIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(projectIndexedCounter)) {
        assertThat(hasHead(project, "foo")).isFalse();
        gApi.projects().name(project.get()).branch("foo").create(new BranchInput());
        assertThat(getRemoteHead(project.get(), "foo")).isNotNull();
        projectIndexedCounter.assertNoReindex();
        gApi.projects().name(project.get()).branch("foo").delete();
        assertThat(hasHead(project, "foo")).isFalse();
        projectIndexedCounter.assertNoReindex();
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 3 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class ProjectIT method reindexChangesOfProject.

@Test
public void reindexChangesOfProject() throws Exception {
    Change.Id changeId1 = createChange().getChange().getId();
    Change.Id changeId2 = createChange().getChange().getId();
    ChangeIndexedListener changeIndexedListener = mock(ChangeIndexedListener.class);
    try (Registration registration = extensionRegistry.newRegistration().add(changeIndexedListener)) {
        gApi.projects().name(project.get()).indexChanges();
        verify(changeIndexedListener, times(1)).onChangeScheduledForIndexing(project.get(), changeId1.get());
        verify(changeIndexedListener, times(1)).onChangeScheduledForIndexing(project.get(), changeId2.get());
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) ChangeIndexedListener(com.google.gerrit.extensions.events.ChangeIndexedListener) Change(com.google.gerrit.entities.Change) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 4 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class ProjectIT method pluginConfigsNotReturnedWhenRefsMetaConfigNotReadable.

@Test
public void pluginConfigsNotReturnedWhenRefsMetaConfigNotReadable() throws Exception {
    ProjectConfigEntry entry = new ProjectConfigEntry("enabled", "true");
    try (Registration ignored = extensionRegistry.newRegistration().add(entry, "test-config-entry")) {
        // This user cannot see refs/meta/config and hence does not have the READ_CONFIG permission.
        requestScopeOperations.setApiUser(user.id());
        ConfigInfo configInfo = getConfig();
        assertThat(configInfo.pluginConfig).isNull();
    }
}
Also used : ProjectConfigEntry(com.google.gerrit.server.config.ProjectConfigEntry) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) ConfigInfo(com.google.gerrit.extensions.api.projects.ConfigInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 5 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration in project gerrit by GerritCodeReview.

the class ProjectIT method reindexProject.

@Test
public void reindexProject() throws Exception {
    ProjectIndexedCounter projectIndexedCounter = new ProjectIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(projectIndexedCounter)) {
        projectOperations.newProject().parent(project).create();
        projectIndexedCounter.clear();
        gApi.projects().name(allProjects.get()).index(false);
        projectIndexedCounter.assertReindexOf(allProjects.get());
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)205 Test (org.junit.Test)200 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)194 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)90 AccountIndexedCounter (com.google.gerrit.acceptance.AccountIndexedCounter)47 RestResponse (com.google.gerrit.acceptance.RestResponse)39 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)38 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)31 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)23 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)22 TestAccount (com.google.gerrit.acceptance.TestAccount)19 PublicKeyStore.keyToString (com.google.gerrit.gpg.PublicKeyStore.keyToString)19 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)16 RequestCancelledException (com.google.gerrit.server.cancellation.RequestCancelledException)15 Config (org.eclipse.jgit.lib.Config)14 BranchInput (com.google.gerrit.extensions.api.projects.BranchInput)12 CreateProjectArgs (com.google.gerrit.server.project.CreateProjectArgs)11 ProjectCreationValidationListener (com.google.gerrit.server.validators.ProjectCreationValidationListener)11 RevCommit (org.eclipse.jgit.revwalk.RevCommit)11 ImmutableList (com.google.common.collect.ImmutableList)10