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);
}
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");
}
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();
}
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();
}
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");
}
Aggregations