Search in sources :

Example 1 with NewController

use of org.sonar.api.server.ws.WebService.NewController 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 2 with NewController

use of org.sonar.api.server.ws.WebService.NewController 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 3 with NewController

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

the class WebServiceTest method log_if_since_on_an_action_is_null.

@Test
public void log_if_since_on_an_action_is_null() {
    ((WebService) context -> {
        NewController newController = context.createController("api/rule");
        newDefaultAction(newController, "list").setSince(null);
        newController.done();
    }).define(context);
    assertThat(logTester.logs(LoggerLevel.WARN)).contains("Since is not set on action api/rule/list");
}
Also used : NewController(org.sonar.api.server.ws.WebService.NewController) Test(org.junit.Test)

Example 4 with NewController

use of org.sonar.api.server.ws.WebService.NewController 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 5 with NewController

use of org.sonar.api.server.ws.WebService.NewController 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)

Aggregations

Test (org.junit.Test)15 NewController (org.sonar.api.server.ws.WebService.NewController)15 NewAction (org.sonar.api.server.ws.WebService.NewAction)6