Search in sources :

Example 1 with SearchResponse

use of org.sonarqube.ws.Qualitygates.SearchResponse in project sonarqube by SonarSource.

the class SearchActionTest method return_only_unassociated_project.

@Test
public void return_only_unassociated_project() {
    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
    ProjectDto associatedProject = db.components().insertPublicProjectDto();
    ProjectDto unassociatedProject = db.components().insertPublicProjectDto();
    db.qualityGates().associateProjectToQualityGate(associatedProject, qualityGate);
    SearchResponse response = ws.newRequest().setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid())).setParam(PARAM_SELECTED, DESELECTED.value()).executeProtobuf(SearchResponse.class);
    assertThat(response.getResultsList()).extracting(Result::getName, Result::getSelected).containsExactlyInAnyOrder(tuple(unassociatedProject.getName(), false)).doesNotContain(tuple(associatedProject.getName(), true));
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) SearchResponse(org.sonarqube.ws.Qualitygates.SearchResponse) Result(org.sonarqube.ws.Qualitygates.SearchResponse.Result) Test(org.junit.Test)

Example 2 with SearchResponse

use of org.sonarqube.ws.Qualitygates.SearchResponse in project sonarqube by SonarSource.

the class SearchActionTest method return_only_authorized_projects.

@Test
public void return_only_authorized_projects() {
    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
    ComponentDto project1 = db.components().insertPrivateProject();
    ComponentDto project2 = db.components().insertPrivateProject();
    UserDto user = db.users().insertUser();
    // User can only see project1 1
    db.users().insertProjectPermissionOnUser(user, USER, project1);
    userSession.logIn(user);
    SearchResponse response = ws.newRequest().setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid())).setParam(PARAM_SELECTED, ALL.value()).executeProtobuf(SearchResponse.class);
    assertThat(response.getResultsList()).extracting(Result::getName).containsExactlyInAnyOrder(project1.name()).doesNotContain(project2.name());
}
Also used : UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) SearchResponse(org.sonarqube.ws.Qualitygates.SearchResponse) Result(org.sonarqube.ws.Qualitygates.SearchResponse.Result) Test(org.junit.Test)

Example 3 with SearchResponse

use of org.sonarqube.ws.Qualitygates.SearchResponse in project sonarqube by SonarSource.

the class SearchActionTest method root_user.

@Test
public void root_user() {
    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
    ComponentDto project = db.components().insertPrivateProject();
    userSession.logIn().setRoot();
    SearchResponse response = ws.newRequest().setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid())).setParam(PARAM_SELECTED, ALL.value()).executeProtobuf(SearchResponse.class);
    assertThat(response.getResultsList()).extracting(Result::getName).containsExactlyInAnyOrder(project.name());
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) SearchResponse(org.sonarqube.ws.Qualitygates.SearchResponse) Test(org.junit.Test)

Example 4 with SearchResponse

use of org.sonarqube.ws.Qualitygates.SearchResponse in project sonarqube by SonarSource.

the class SearchActionTest method test_pagination_on_many_pages.

@Test
public void test_pagination_on_many_pages() {
    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
    for (int i = 0; i < 20; i++) {
        ProjectDto project = db.components().insertPublicProjectDto();
        db.qualityGates().associateProjectToQualityGate(project, qualityGate);
    }
    userSession.addPermission(ADMINISTER_QUALITY_GATES);
    SearchResponse response = ws.newRequest().setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid())).setParam(PARAM_PAGE_SIZE, valueOf(5)).setParam(PARAM_PAGE, valueOf(2)).executeProtobuf(SearchResponse.class);
    assertThat(response).extracting(SearchResponse::getMore, searchResponse -> searchResponse.getPaging().getPageIndex(), searchResponse -> searchResponse.getPaging().getPageSize(), searchResponse -> searchResponse.getPaging().getTotal()).contains(true, 2, 5, 20);
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) UserDto(org.sonar.db.user.UserDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PARAM_PAGE_SIZE(org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_PAGE_SIZE) ALL(org.sonar.api.server.ws.WebService.SelectionMode.ALL) AssertionsForClassTypes.tuple(org.assertj.core.api.AssertionsForClassTypes.tuple) SELECTED(org.sonar.api.server.ws.WebService.SelectionMode.SELECTED) WebService(org.sonar.api.server.ws.WebService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) PARAM_PAGE(org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_PAGE) PARAM_GATE_ID(org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_GATE_ID) TestComponentFinder(org.sonar.server.component.TestComponentFinder) UserSessionRule(org.sonar.server.tester.UserSessionRule) ADMINISTER_QUALITY_GATES(org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_GATES) DbTester(org.sonar.db.DbTester) USER(org.sonar.api.web.UserRole.USER) SearchResponse(org.sonarqube.ws.Qualitygates.SearchResponse) Test(org.junit.Test) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) WsActionTester(org.sonar.server.ws.WsActionTester) NotFoundException(org.sonar.server.exceptions.NotFoundException) PARAM_SELECTED(org.sonarqube.ws.client.user.UsersWsParameters.PARAM_SELECTED) DbClient(org.sonar.db.DbClient) Result(org.sonarqube.ws.Qualitygates.SearchResponse.Result) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) String.valueOf(java.lang.String.valueOf) DESELECTED(org.sonar.api.server.ws.WebService.SelectionMode.DESELECTED) ProjectDto(org.sonar.db.project.ProjectDto) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) SearchResponse(org.sonarqube.ws.Qualitygates.SearchResponse) Test(org.junit.Test)

Example 5 with SearchResponse

use of org.sonarqube.ws.Qualitygates.SearchResponse in project sonarqube by SonarSource.

the class SearchActionTest method return_empty_association.

@Test
public void return_empty_association() {
    QualityGateDto qualityGate = db.qualityGates().insertQualityGate();
    SearchResponse response = ws.newRequest().setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid())).executeProtobuf(SearchResponse.class);
    assertThat(response.getResultsList()).isEmpty();
}
Also used : QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) SearchResponse(org.sonarqube.ws.Qualitygates.SearchResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 QualityGateDto (org.sonar.db.qualitygate.QualityGateDto)9 SearchResponse (org.sonarqube.ws.Qualitygates.SearchResponse)9 ComponentDto (org.sonar.db.component.ComponentDto)5 ProjectDto (org.sonar.db.project.ProjectDto)5 Result (org.sonarqube.ws.Qualitygates.SearchResponse.Result)5 UserDto (org.sonar.db.user.UserDto)3 String.valueOf (java.lang.String.valueOf)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)2 AssertionsForClassTypes.tuple (org.assertj.core.api.AssertionsForClassTypes.tuple)2 Rule (org.junit.Rule)2 WebService (org.sonar.api.server.ws.WebService)2 ALL (org.sonar.api.server.ws.WebService.SelectionMode.ALL)2 DESELECTED (org.sonar.api.server.ws.WebService.SelectionMode.DESELECTED)2 SELECTED (org.sonar.api.server.ws.WebService.SelectionMode.SELECTED)2 USER (org.sonar.api.web.UserRole.USER)2 DbClient (org.sonar.db.DbClient)2 DbTester (org.sonar.db.DbTester)2 ADMINISTER_QUALITY_GATES (org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_GATES)2