Search in sources :

Example 6 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_empty.

@Test
public void log_if_since_on_an_action_is_empty() {
    ((WebService) context -> {
        NewController newController = context.createController("api/rule");
        newDefaultAction(newController, "list").setSince("");
        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 7 with NewController

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

the class WebServiceTest method fail_if_no_action_handler.

@Test
public void fail_if_no_action_handler() {
    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage("RequestHandler is not set on action rule/show");
    ((WebService) context -> {
        NewController controller = context.createController("rule");
        newDefaultAction(controller, "show").setHandler(null);
        controller.done();
    }).define(context);
}
Also used : NewController(org.sonar.api.server.ws.WebService.NewController) Test(org.junit.Test)

Example 8 with NewController

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

Example 9 with NewController

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

the class WebServiceTest method ws_is_internal_if_all_actions_are_internal.

@Test
public void ws_is_internal_if_all_actions_are_internal() {
    ((WebService) context -> {
        NewController newController = context.createController("api/rule");
        newDefaultAction(newController, "create").setInternal(true);
        newDefaultAction(newController, "update").setInternal(true);
        newController.done();
    }).define(context);
    assertThat(context.controller("api/rule").isInternal()).isTrue();
}
Also used : NewController(org.sonar.api.server.ws.WebService.NewController) Test(org.junit.Test)

Example 10 with NewController

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

the class WebServiceTest method fail_if_duplicated_ws_keys.

@Test
public void fail_if_duplicated_ws_keys() {
    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage("The web service 'api/metric' is defined multiple times");
    MetricWs metricWs = new MetricWs();
    metricWs.define(context);
    ((WebService) context -> {
        NewController newController = context.createController("api/metric");
        newDefaultAction(newController, "delete");
        newController.done();
    }).define(context);
}
Also used : 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