Search in sources :

Example 31 with GerritConfig

use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.

the class ExternalIdIT method createCaseInsensitiveExternalId_DuplicateKey.

@Test
@GerritConfig(name = "auth.userNameCaseInsensitive", value = "true")
public void createCaseInsensitiveExternalId_DuplicateKey() throws Exception {
    try (Repository allUsersRepo = repoManager.openRepository(allUsers);
        MetaDataUpdate md = metaDataUpdateFactory.create(allUsers)) {
        ExternalIdNotes extIdNotes = externalIdNotesFactory.load(allUsersRepo);
        testCaseInsensitiveExternalIdKey(md, extIdNotes, SCHEME_USERNAME, "JohnDoe", Account.id(42));
        assertThrows(DuplicateExternalIdKeyException.class, () -> extIdNotes.insert(externalIdFactory.create(SCHEME_USERNAME, "johndoe", Account.id(23))));
    }
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) ExternalIdNotes(com.google.gerrit.server.account.externalids.ExternalIdNotes) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 32 with GerritConfig

use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.

the class RestApiServletIT method xGerritUpdatedRefSetMultipleHeadersForSubmitTopic.

@Test
@GerritConfig(name = "change.submitWholeTopic", value = "true")
public void xGerritUpdatedRefSetMultipleHeadersForSubmitTopic() throws Exception {
    String secondProject = "secondProject";
    projectOperations.newProject().name(secondProject).create();
    TestRepository<InMemoryRepository> secondRepo = cloneProject(Project.nameKey("secondProject"), admin);
    String topic = "topic";
    String branch = "refs/heads/master";
    Result change1 = createChange(testRepo, branch, "first change", "a.txt", "message", topic);
    Result change2 = createChange(secondRepo, branch, "second change", "b.txt", "message", topic);
    String metaRef1 = RefNames.changeMetaRef(change1.getChange().getId());
    String metaRef2 = RefNames.changeMetaRef(change2.getChange().getId());
    gApi.changes().id(change1.getChangeId()).current().review(ReviewInput.approve());
    gApi.changes().id(change2.getChangeId()).current().review(ReviewInput.approve());
    Project.NameKey project1 = change1.getChange().project();
    Project.NameKey project2 = change2.getChange().project();
    try (Repository repository1 = repoManager.openRepository(project1);
        Repository repository2 = repoManager.openRepository(project2)) {
        ObjectId originalFirstMetaRefSha1 = getMetaRefSha1(change1);
        ObjectId originalSecondMetaRefSha1 = getMetaRefSha1(change2);
        ObjectId originalDestinationBranchSha1Project1 = repository1.resolve(change1.getChange().change().getDest().branch());
        ObjectId originalDestinationBranchSha1Project2 = repository2.resolve(change2.getChange().change().getDest().branch());
        RestResponse response = adminRestSession.postWithHeaders("/changes/" + change2.getChangeId() + "/submit", /* content = */
        null, X_GERRIT_UPDATED_REF_ENABLED_HEADER);
        response.assertOK();
        assertThat(gApi.changes().id(change1.getChangeId()).get().status).isEqualTo(ChangeStatus.MERGED);
        ObjectId firstMetaRefSha1 = getMetaRefSha1(change1);
        ObjectId secondMetaRefSha1 = getMetaRefSha1(change2);
        List<String> headers = response.getHeaders(X_GERRIT_UPDATED_REF);
        String branchSha1Project1 = repository1.getRefDatabase().exactRef(change1.getChange().change().getDest().branch()).getObjectId().name();
        String branchSha1Project2 = repository2.getRefDatabase().exactRef(change2.getChange().change().getDest().branch()).getObjectId().name();
        // During submit, all relevant meta refs of the latest patchset are updated + the destination
        // branch/es.
        // TODO(paiking): This doesn't work well for torn submissions: If the changes are in
        // different projects in the same topic, and we tried to submit those changes together, it's
        // possible that the first submission only submitted one of the changes, and then the retry
        // submitted the other change. If that happens, when the user retries, they will not get the
        // meta ref updates for the change that got submitted on the previous submission attempt.
        // Ideally, submit should be idempotent and always return all meta refs on all submission
        // attempts.
        assertThat(headers).containsExactly(String.format("%s~%s~%s~%s", Url.encode(project1.get()), Url.encode(metaRef1), originalFirstMetaRefSha1.getName(), firstMetaRefSha1.getName()), String.format("%s~%s~%s~%s", Url.encode(project2.get()), Url.encode(metaRef2), originalSecondMetaRefSha1.getName(), secondMetaRefSha1.getName()), String.format("%s~%s~%s~%s", Url.encode(project1.get()), Url.encode(branch), originalDestinationBranchSha1Project1.getName(), branchSha1Project1), String.format("%s~%s~%s~%s", Url.encode(project2.get()), Url.encode(branch), originalDestinationBranchSha1Project2.getName(), branchSha1Project2));
    }
}
Also used : Project(com.google.gerrit.entities.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) ObjectId(org.eclipse.jgit.lib.ObjectId) RestResponse(com.google.gerrit.acceptance.RestResponse) Result(com.google.gerrit.acceptance.PushOneCommit.Result) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 33 with GerritConfig

use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.

the class TraceIT method traceAccount.

@Test
@GerritConfig(name = "tracing.issue123.account", value = "1000000")
public void traceAccount() throws Exception {
    TraceValidatingProjectCreationValidationListener projectCreationListener = new TraceValidatingProjectCreationValidationListener();
    try (Registration registration = extensionRegistry.newRegistration().add(projectCreationListener)) {
        RestResponse response = adminRestSession.put("/projects/new15");
        assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
        assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
        assertThat(projectCreationListener.traceId).isEqualTo("issue123");
        assertThat(projectCreationListener.isLoggingForced).isTrue();
        assertThat(projectCreationListener.tags.get("project")).containsExactly("new15");
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) RestResponse(com.google.gerrit.acceptance.RestResponse) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 34 with GerritConfig

use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.

the class TraceIT method traceProject.

@Test
@GerritConfig(name = "tracing.issue123.projectPattern", value = "new12")
public void traceProject() throws Exception {
    TraceValidatingProjectCreationValidationListener projectCreationListener = new TraceValidatingProjectCreationValidationListener();
    try (Registration registration = extensionRegistry.newRegistration().add(projectCreationListener)) {
        RestResponse response = adminRestSession.put("/projects/new12");
        assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
        assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
        assertThat(projectCreationListener.traceId).isEqualTo("issue123");
        assertThat(projectCreationListener.isLoggingForced).isTrue();
        assertThat(projectCreationListener.tags.get("project")).containsExactly("new12");
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) RestResponse(com.google.gerrit.acceptance.RestResponse) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 35 with GerritConfig

use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.

the class CancellationIT method nonMatchingServerDeadlineIsIgnored_projectPattern.

@Test
@GerritConfig(name = "deadline.default.timeout", value = "1ms")
@GerritConfig(name = "deadline.default.projectPattern", value = ".*foo.*")
public void nonMatchingServerDeadlineIsIgnored_projectPattern() throws Exception {
    testTicker.useFakeTicker().setAutoIncrementStep(Duration.ofMillis(2));
    RestResponse response = adminRestSession.putWithHeaders("/projects/" + name("new"));
    response.assertCreated();
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)187 Test (org.junit.Test)185 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)170 RestResponse (com.google.gerrit.acceptance.RestResponse)56 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)40 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)35 Repository (org.eclipse.jgit.lib.Repository)21 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)19 MetaDataUpdate (com.google.gerrit.server.git.meta.MetaDataUpdate)17 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)17 ExternalIdNotes (com.google.gerrit.server.account.externalids.ExternalIdNotes)16 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)14 TestRepository (org.eclipse.jgit.junit.TestRepository)14 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)11 TestAccount (com.google.gerrit.acceptance.TestAccount)10 Account (com.google.gerrit.entities.Account)10 RevCommit (org.eclipse.jgit.revwalk.RevCommit)10 Project (com.google.gerrit.entities.Project)9 ConfigInfo (com.google.gerrit.extensions.api.projects.ConfigInfo)9 Change (com.google.gerrit.entities.Change)8