Search in sources :

Example 31 with Registration

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

the class IndexChangesIT method indexRequestFromNonAdminRejected.

@Test
public void indexRequestFromNonAdminRejected() throws Exception {
    ChangeIndexedCounter changeIndexedCounter = new ChangeIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(changeIndexedCounter)) {
        String changeId = createChange().getChangeId();
        IndexChanges.Input in = new IndexChanges.Input();
        in.changes = ImmutableSet.of(changeId);
        changeIndexedCounter.clear();
        userRestSession.post("/config/server/index.changes", in).assertForbidden();
        assertThat(changeIndexedCounter.getCount(info(changeId))).isEqualTo(0);
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) IndexChanges(com.google.gerrit.server.restapi.config.IndexChanges) ChangeIndexedCounter(com.google.gerrit.acceptance.ChangeIndexedCounter) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 32 with Registration

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

the class CreateBranchIT method createBranchViaPushFailsIfCommitIsInvalid.

@Test
public void createBranchViaPushFailsIfCommitIsInvalid() throws Exception {
    TestRefOperationValidationListener testRefOperationValidationListener = new TestRefOperationValidationListener();
    testRefOperationValidationListener.doReject = true;
    try (Registration registration = extensionRegistry.newRegistration().add(testRefOperationValidationListener)) {
        PushResult r = pushHead(testRepo, "refs/heads/new", /* pushTags= */
        false, /* force= */
        false, /* pushOptions= */
        ImmutableList.of());
        assertPushRejected(r, "refs/heads/new", String.format("Validation for creation of ref 'refs/heads/new' in project %s failed:\n%s", project, TestRefOperationValidationListener.FAILURE_MESSAGE));
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PushResult(org.eclipse.jgit.transport.PushResult) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 33 with Registration

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

the class CreateBranchIT method createBranchViaPushWithValidationOptions.

@Test
public void createBranchViaPushWithValidationOptions() throws Exception {
    TestRefOperationValidationListener testRefOperationValidationListener = new TestRefOperationValidationListener();
    try (Registration registration = extensionRegistry.newRegistration().add(testRefOperationValidationListener)) {
        PushResult r = pushHead(testRepo, "refs/heads/new", /* pushTags= */
        false, /* force= */
        false, /* pushOptions= */
        ImmutableList.of("key=value"));
        assertPushOk(r, "refs/heads/new");
        assertThat(testRefOperationValidationListener.refReceivedEvent.pushOptions).containsExactly("key", "value");
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PushResult(org.eclipse.jgit.transport.PushResult) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 34 with Registration

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

the class TraceIT method restCallWithTraceRequestParam.

@Test
public void restCallWithTraceRequestParam() throws Exception {
    TraceValidatingProjectCreationValidationListener projectCreationListener = new TraceValidatingProjectCreationValidationListener();
    try (Registration registration = extensionRegistry.newRegistration().add(projectCreationListener)) {
        RestResponse response = adminRestSession.put("/projects/new2?" + ParameterParser.TRACE_PARAMETER);
        assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
        assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNotNull();
        assertThat(projectCreationListener.traceId).isNotNull();
        assertThat(projectCreationListener.isLoggingForced).isTrue();
        assertThat(projectCreationListener.tags.get("project")).containsExactly("new2");
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) RestResponse(com.google.gerrit.acceptance.RestResponse) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 35 with Registration

use of com.google.gerrit.acceptance.ExtensionRegistry.Registration 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)

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