Search in sources :

Example 51 with WsTester

use of org.sonar.server.ws.WsTester in project sonarqube by SonarSource.

the class UpgradesActionTest method action_updates_is_defined.

@Test
public void action_updates_is_defined() {
    WsTester wsTester = new WsTester();
    WebService.NewController newController = wsTester.context().createController(DUMMY_CONTROLLER_KEY);
    underTest.define(newController);
    newController.done();
    WebService.Controller controller = wsTester.controller(DUMMY_CONTROLLER_KEY);
    assertThat(controller.actions()).extracting("key").containsExactly("upgrades");
    WebService.Action action = controller.actions().iterator().next();
    assertThat(action.isPost()).isFalse();
    assertThat(action.description()).isNotEmpty();
    assertThat(action.responseExample()).isNotNull();
    assertThat(action.params()).isEmpty();
}
Also used : WsTester(org.sonar.server.ws.WsTester) WebService(org.sonar.api.server.ws.WebService) Test(org.junit.Test)

Example 52 with WsTester

use of org.sonar.server.ws.WsTester in project sonarqube by SonarSource.

the class PluginsWsMediumTest method test_update_existing_and_install_new_scenario.

@Test
public void test_update_existing_and_install_new_scenario() throws Exception {
    WsTester wsTester = new WsTester(serverTester.get(PluginsWs.class));
    // 1 - check what's installed, available and pending
    userSessionRule.logIn().setSystemAdministrator();
    wsTester.newGetRequest("api/plugins", "installed").execute().assertJson("{" + "  \"plugins\": [" + "    {" + "      \"key\": \"decoy\"," + "      \"version\": \"1.0\"" + "    }" + "  ]" + "}");
    wsTester.newGetRequest("api/plugins", "available").execute().assertJson("{" + "  \"plugins\": [" + "    {" + "      \"key\": \"foo\"," + "      \"release\": {" + "        \"version\": \"1.0\"" + "      }," + "      \"update\": {" + "        \"status\": \"COMPATIBLE\"," + "        \"requires\": []" + "      }" + "    }" + "  ]" + "}");
    wsTester.newGetRequest("api/plugins", "pending").execute().assertJson("{\"installing\":[],\"removing\":[],\"updating\":[]}");
    // 2 - install one plugin, update another, verify pending status in the process
    wsTester.newPostRequest("api/plugins", "update").setParam("key", "decoy").execute().assertNoContent();
    wsTester.newGetRequest("api/plugins", "pending").execute().assertJson("{" + "  \"updating\": [" + "    {" + "      \"key\": \"decoy\"," + "      \"version\": \"1.1\"" + "    }" + "  ]," + "  \"installing\": []," + "  \"removing\": []" + "}");
    wsTester.newPostRequest("api/plugins", "install").setParam("key", "foo").execute().assertNoContent();
    wsTester.newGetRequest("api/plugins", "pending").execute().assertJson("{" + "  \"installing\": [" + "    {" + "      \"key\": \"foo\"," + "      \"version\": \"1.0\"" + "    }" + "  ]," + "  \"updating\": [" + "    {" + "      \"key\": \"decoy\"," + "      \"version\": \"1.1\"" + "    }" + "  ]," + "  \"removing\": []" + "}");
    // 3 - simulate SQ restart
    wsTester = restartServerTester();
    // 4 - make sure plugin is installed
    userSessionRule.logIn().setSystemAdministrator();
    wsTester.newGetRequest("api/plugins", "installed").execute().assertJson("{" + "  \"plugins\": [" + "    {" + "      \"key\": \"decoy\"," + "      \"version\": \"1.1\"" + "    }," + "    {" + "      \"key\": \"foo\"," + "      \"version\": \"1.0\"" + "    }" + "  ]" + "}");
    // 5 - uninstall a plugin, verify pending status in the process
    wsTester.newPostRequest("api/plugins", "uninstall").setParam("key", "foo").execute().assertNoContent();
    wsTester.newGetRequest("api/plugins", "pending").execute().assertJson("{" + "  \"installing\": []," + "  \"updating\": []," + "  \"removing\": [" + "    {" + "      \"key\": \"foo\"," + "      \"version\": \"1.0\"" + "    }" + "  ]," + "}");
    // 6 - simulate SQ restart again
    wsTester = restartServerTester();
    // 7 - make sure plugin has been uninstalled
    userSessionRule.logIn().setSystemAdministrator();
    wsTester.newGetRequest("api/plugins", "installed").execute().assertJson("{" + "  \"plugins\": [" + "    {" + "      \"key\": \"decoy\"," + "      \"version\": \"1.1\"" + "    }" + "  ]" + "}");
}
Also used : WsTester(org.sonar.server.ws.WsTester) Test(org.junit.Test)

Example 53 with WsTester

use of org.sonar.server.ws.WsTester in project sonarqube by SonarSource.

the class BulkDeleteActionTest method setUp.

@Before
public void setUp() {
    ws = new WsTester(new ProjectsWs(underTest));
    org1 = db.organizations().insert();
    org2 = db.organizations().insert();
}
Also used : WsTester(org.sonar.server.ws.WsTester) Before(org.junit.Before)

Example 54 with WsTester

use of org.sonar.server.ws.WsTester in project sonarqube by SonarSource.

the class CancelAllActionTest method action_cancel_all_is_defined.

@Test
public void action_cancel_all_is_defined() {
    WsTester wsTester = new WsTester();
    WebService.NewController newController = wsTester.context().createController(DUMMY_CONTROLLER_KEY);
    underTest.define(newController);
    newController.done();
    WebService.Controller controller = wsTester.controller(DUMMY_CONTROLLER_KEY);
    assertThat(controller.actions()).extracting("key").containsExactly("cancel_all");
    WebService.Action action = controller.actions().iterator().next();
    assertThat(action.isPost()).isTrue();
    assertThat(action.description()).isNotEmpty();
    assertThat(action.responseExample()).isNull();
    assertThat(action.params()).isEmpty();
}
Also used : WsTester(org.sonar.server.ws.WsTester) WebService(org.sonar.api.server.ws.WebService) Test(org.junit.Test)

Example 55 with WsTester

use of org.sonar.server.ws.WsTester in project sonarqube by SonarSource.

the class InstalledActionTest method action_installed_is_defined.

@Test
public void action_installed_is_defined() {
    logInAsSystemAdministrator();
    WsTester wsTester = new WsTester();
    WebService.NewController newController = wsTester.context().createController(DUMMY_CONTROLLER_KEY);
    underTest.define(newController);
    newController.done();
    WebService.Controller controller = wsTester.controller(DUMMY_CONTROLLER_KEY);
    assertThat(controller.actions()).extracting("key").containsExactly("installed");
    WebService.Action action = controller.actions().iterator().next();
    assertThat(action.isPost()).isFalse();
    assertThat(action.description()).isNotEmpty();
    assertThat(action.responseExample()).isNotNull();
}
Also used : WsTester(org.sonar.server.ws.WsTester) WebService(org.sonar.api.server.ws.WebService) Test(org.junit.Test)

Aggregations

WsTester (org.sonar.server.ws.WsTester)71 Before (org.junit.Before)50 Test (org.junit.Test)21 DbClient (org.sonar.db.DbClient)18 ComponentFinder (org.sonar.server.component.ComponentFinder)15 WebService (org.sonar.api.server.ws.WebService)12 UserSession (org.sonar.server.user.UserSession)5 Languages (org.sonar.api.resources.Languages)4 QProfileFactory (org.sonar.server.qualityprofile.QProfileFactory)4 UserDto (org.sonar.db.user.UserDto)3 DefaultOrganizationProvider (org.sonar.server.organization.DefaultOrganizationProvider)3 UserJsonWriter (org.sonar.server.user.ws.UserJsonWriter)3 I18n (org.sonar.api.i18n.I18n)2 System2 (org.sonar.api.utils.System2)2 OrganizationDao (org.sonar.db.organization.OrganizationDao)2 RuleRepositoryDto (org.sonar.db.rule.RuleRepositoryDto)2 DefaultOrganization (org.sonar.server.organization.DefaultOrganization)2 UserUpdater (org.sonar.server.user.UserUpdater)2 UserIndex (org.sonar.server.user.index.UserIndex)2 Locale (java.util.Locale)1