Search in sources :

Example 16 with NewAction

use of org.sonar.api.server.ws.WebService.NewAction in project sonarqube by SonarSource.

the class WebServiceTest method fail_if_required_param_has_default_value.

@Test
public void fail_if_required_param_has_default_value() {
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Default value must not be set on parameter 'api/rule/create?key' as it's marked as required");
    ((WebService) context -> {
        NewController controller = context.createController("api/rule");
        NewAction action = newDefaultAction(controller, "create");
        action.createParam("key").setRequired(true).setDefaultValue("abc");
        controller.done();
    }).define(context);
}
Also used : NewAction(org.sonar.api.server.ws.WebService.NewAction) NewController(org.sonar.api.server.ws.WebService.NewController) Test(org.junit.Test)

Example 17 with NewAction

use of org.sonar.api.server.ws.WebService.NewAction in project sonarqube by SonarSource.

the class WebServiceTest method param_metadata_as_objects.

@Test
public void param_metadata_as_objects() {
    ((WebService) context -> {
        NewController newController = context.createController("api/rule");
        NewAction create = newDefaultAction(newController, "create");
        create.createParam("status").setDefaultValue(RuleStatus.BETA).setPossibleValues(RuleStatus.BETA, RuleStatus.READY).setExampleValue(RuleStatus.BETA);
        create.createParam("max").setDefaultValue(11).setPossibleValues(11, 13, 17).setExampleValue(17);
        newController.done();
    }).define(context);
    WebService.Action action = context.controller("api/rule").action("create");
    assertThat(action.param("status").defaultValue()).isEqualTo("BETA");
    assertThat(action.param("status").possibleValues()).containsOnly("BETA", "READY");
    assertThat(action.param("status").exampleValue()).isEqualTo("BETA");
    assertThat(action.param("max").defaultValue()).isEqualTo("11");
    assertThat(action.param("max").possibleValues()).containsOnly("11", "13", "17");
    assertThat(action.param("max").exampleValue()).isEqualTo("17");
}
Also used : NewAction(org.sonar.api.server.ws.WebService.NewAction) NewController(org.sonar.api.server.ws.WebService.NewController) Test(org.junit.Test)

Example 18 with NewAction

use of org.sonar.api.server.ws.WebService.NewAction in project sonarqube by SonarSource.

the class WebServiceTest method param_with_empty_possible_values.

@Test
public void param_with_empty_possible_values() {
    ((WebService) context -> {
        NewController newController = context.createController("api/rule");
        NewAction create = newDefaultAction(newController, "create");
        create.createParam("status").setPossibleValues(Collections.emptyList());
        newController.done();
    }).define(context);
    WebService.Action action = context.controller("api/rule").action("create");
    // no possible values -> return null but not empty
    assertThat(action.param("status").possibleValues()).isNull();
}
Also used : NewAction(org.sonar.api.server.ws.WebService.NewAction) NewController(org.sonar.api.server.ws.WebService.NewController) Test(org.junit.Test)

Example 19 with NewAction

use of org.sonar.api.server.ws.WebService.NewAction in project sonarqube by SonarSource.

the class WebServiceTest method param_null_metadata.

@Test
public void param_null_metadata() {
    ((WebService) context -> {
        NewController newController = context.createController("api/rule");
        NewAction create = newDefaultAction(newController, "create");
        create.createParam("status").setDefaultValue(null).setPossibleValues(Collections.emptyList()).setExampleValue(null);
        create.createParam("max").setPossibleValues((Object[]) null);
        newController.done();
    }).define(context);
    WebService.Action action = context.controller("api/rule").action("create");
    assertThat(action.param("status").defaultValue()).isNull();
    assertThat(action.param("status").possibleValues()).isNull();
    assertThat(action.param("status").exampleValue()).isNull();
    assertThat(action.param("max").possibleValues()).isNull();
}
Also used : NewAction(org.sonar.api.server.ws.WebService.NewAction) NewController(org.sonar.api.server.ws.WebService.NewController) Test(org.junit.Test)

Example 20 with NewAction

use of org.sonar.api.server.ws.WebService.NewAction in project sonarqube by SonarSource.

the class WebServiceTest method action_parameters.

@Test
public void action_parameters() {
    ((WebService) context -> {
        NewController newController = context.createController("api/rule");
        NewAction newAction = newDefaultAction(newController, "create");
        newAction.createParam("key").setDescription("Key of the new rule");
        newAction.createParam("severity").setDefaultValue("MAJOR").setSince("4.4").setDeprecatedSince("5.3").setDeprecatedKey("old-severity", "4.5").setPossibleValues("INFO", "MAJOR", "BLOCKER");
        newAction.createParam("internal").setInternal(true);
        newAction.addPagingParams(20);
        newAction.addFieldsParam(Arrays.asList("name", "severity"));
        newAction.addSortParams(Arrays.asList("name", "updatedAt", "severity"), "updatedAt", false);
        newController.done();
    }).define(context);
    WebService.Action action = context.controller("api/rule").action("create");
    assertThat(action.params()).hasSize(8);
    WebService.Param keyParam = action.param("key");
    assertThat(keyParam.key()).isEqualTo("key");
    assertThat(keyParam.description()).isEqualTo("Key of the new rule");
    assertThat(keyParam.isInternal()).isFalse();
    assertThat(keyParam.toString()).isEqualTo("key");
    WebService.Param severityParam = action.param("severity");
    assertThat(severityParam.key()).isEqualTo("severity");
    assertThat(severityParam.description()).isNull();
    assertThat(severityParam.deprecatedSince()).isEqualTo("5.3");
    assertThat(severityParam.since()).isEqualTo("4.4");
    assertThat(severityParam.deprecatedKey()).isEqualTo("old-severity");
    assertThat(severityParam.deprecatedKeySince()).isEqualTo("4.5");
    assertThat(severityParam.defaultValue()).isEqualTo("MAJOR");
    assertThat(severityParam.possibleValues()).containsOnly("INFO", "MAJOR", "BLOCKER");
    WebService.Param internalParam = action.param("internal");
    assertThat(internalParam.isInternal()).isTrue();
    // predefined fields
    assertThat(action.param("p").defaultValue()).isEqualTo("1");
    assertThat(action.param("p").description()).isNotEmpty();
    assertThat(action.param("ps").defaultValue()).isEqualTo("20");
    assertThat(action.param("ps").description()).isNotEmpty();
    assertThat(action.param("f").possibleValues()).containsOnly("name", "severity");
    assertThat(action.param("s").possibleValues()).containsOnly("name", "severity", "updatedAt");
    assertThat(action.param("s").description()).isNotEmpty();
    assertThat(action.param("asc").defaultValue()).isEqualTo("false");
}
Also used : NewAction(org.sonar.api.server.ws.WebService.NewAction) NewController(org.sonar.api.server.ws.WebService.NewController) Test(org.junit.Test)

Aggregations

NewAction (org.sonar.api.server.ws.WebService.NewAction)37 Test (org.junit.Test)6 NewController (org.sonar.api.server.ws.WebService.NewController)6 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Set (java.util.Set)1 Nullable (javax.annotation.Nullable)1 ProfileExporter (org.sonar.api.profiles.ProfileExporter)1 ProfileImporter (org.sonar.api.profiles.ProfileImporter)1 Languages (org.sonar.api.resources.Languages)1 Request (org.sonar.api.server.ws.Request)1 Response (org.sonar.api.server.ws.Response)1 Stream (org.sonar.api.server.ws.Response.Stream)1 WebService (org.sonar.api.server.ws.WebService)1 Collectors (org.sonar.core.util.stream.Collectors)1