Search in sources :

Example 96 with BadRequestException

use of com.google.gerrit.extensions.restapi.BadRequestException in project gerrit by GerritCodeReview.

the class InstallPlugin method apply.

@Override
public Response<PluginInfo> apply(TopLevelResource resource, InstallPluginInput input) throws RestApiException, IOException {
    loader.checkRemoteAdminEnabled();
    try {
        try (InputStream in = openStream(input)) {
            String pluginName = loader.installPluginFromStream(name, in);
            PluginInfo info = ListPlugins.toPluginInfo(loader.get(pluginName));
            return created ? Response.created(info) : Response.ok(info);
        }
    } catch (PluginInstallException e) {
        StringWriter buf = new StringWriter();
        buf.write(String.format("cannot install %s", name));
        if (e.getCause() instanceof ZipException) {
            buf.write(": ");
            buf.write(e.getCause().getMessage());
        } else {
            buf.write(":\n");
            PrintWriter pw = new PrintWriter(buf);
            e.printStackTrace(pw);
            pw.flush();
        }
        throw new BadRequestException(buf.toString());
    }
}
Also used : StringWriter(java.io.StringWriter) InputStream(java.io.InputStream) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PluginInfo(com.google.gerrit.extensions.common.PluginInfo) ZipException(java.util.zip.ZipException) IdString(com.google.gerrit.extensions.restapi.IdString) PrintWriter(java.io.PrintWriter)

Example 97 with BadRequestException

use of com.google.gerrit.extensions.restapi.BadRequestException in project gerrit by GerritCodeReview.

the class CreateLabelIT method cannotCreateLabelWithValuesThatHaveEmptyDescription.

@Test
public void cannotCreateLabelWithValuesThatHaveEmptyDescription() throws Exception {
    LabelDefinitionInput input = new LabelDefinitionInput();
    input.values = ImmutableMap.of("+1", "");
    BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.projects().name(project.get()).label("Foo").create(input));
    assertThat(thrown).hasMessageThat().contains("description for value '+1' cannot be empty");
}
Also used : BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) LabelDefinitionInput(com.google.gerrit.extensions.common.LabelDefinitionInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 98 with BadRequestException

use of com.google.gerrit.extensions.restapi.BadRequestException in project gerrit by GerritCodeReview.

the class CreateLabelIT method cannotCreateLabelWithUnknownFunction.

@Test
public void cannotCreateLabelWithUnknownFunction() throws Exception {
    LabelDefinitionInput input = new LabelDefinitionInput();
    input.values = ImmutableMap.of("+1", "Looks Good", "0", "Don't Know", "-1", "Looks Bad");
    input.function = "UnknownFuction";
    BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.projects().name(project.get()).label("Foo").create(input));
    assertThat(thrown).hasMessageThat().contains("unknown function: " + input.function);
}
Also used : BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) LabelDefinitionInput(com.google.gerrit.extensions.common.LabelDefinitionInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 99 with BadRequestException

use of com.google.gerrit.extensions.restapi.BadRequestException in project gerrit by GerritCodeReview.

the class CreateLabelIT method cannotCreateLabelWithoutValues.

@Test
public void cannotCreateLabelWithoutValues() throws Exception {
    LabelDefinitionInput input = new LabelDefinitionInput();
    BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.projects().name(project.get()).label("Foo").create(input));
    assertThat(thrown).hasMessageThat().contains("values are required");
    input.values = ImmutableMap.of();
    thrown = assertThrows(BadRequestException.class, () -> gApi.projects().name(project.get()).label("Foo").create(input));
    assertThat(thrown).hasMessageThat().contains("values are required");
}
Also used : BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) LabelDefinitionInput(com.google.gerrit.extensions.common.LabelDefinitionInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 100 with BadRequestException

use of com.google.gerrit.extensions.restapi.BadRequestException in project gerrit by GerritCodeReview.

the class CreateLabelIT method cannotCreateLabelWithDuplicateValues.

@Test
public void cannotCreateLabelWithDuplicateValues() throws Exception {
    LabelDefinitionInput input = new LabelDefinitionInput();
    // Positive values can be specified as '<value>' or '+<value>'.
    input.values = ImmutableMap.of("+1", "Looks Good", "1", "Looks Good", "0", "Don't Know", "-1", "Looks Bad");
    BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.projects().name(allProjects.get()).label("Foo").create(input));
    assertThat(thrown).hasMessageThat().contains("duplicate value: 1");
}
Also used : BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) LabelDefinitionInput(com.google.gerrit.extensions.common.LabelDefinitionInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)310 Test (org.junit.Test)154 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)146 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)56 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)51 AuthException (com.google.gerrit.extensions.restapi.AuthException)46 Repository (org.eclipse.jgit.lib.Repository)30 IdString (com.google.gerrit.extensions.restapi.IdString)29 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)29 LabelDefinitionInput (com.google.gerrit.extensions.common.LabelDefinitionInput)28 ArrayList (java.util.ArrayList)28 RevCommit (org.eclipse.jgit.revwalk.RevCommit)28 MethodNotAllowedException (com.google.gerrit.extensions.restapi.MethodNotAllowedException)27 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)27 IOException (java.io.IOException)25 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)24 RevWalk (org.eclipse.jgit.revwalk.RevWalk)22 ObjectId (org.eclipse.jgit.lib.ObjectId)20 Map (java.util.Map)19 Change (com.google.gerrit.entities.Change)18