Search in sources :

Example 1 with ADMINISTER_QUALITY_GATES

use of org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_GATES in project sonarqube by SonarSource.

the class ListActionTest method actions_with_quality_gate_administer_permission.

@Test
public void actions_with_quality_gate_administer_permission() {
    userSession.logIn("john").addPermission(ADMINISTER_QUALITY_GATES);
    QualityGateDto defaultQualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("Default").setBuiltIn(false));
    QualityGateDto builtInQualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("Sonar way").setBuiltIn(true));
    QualityGateDto otherQualityGate = db.qualityGates().insertQualityGate(qg -> qg.setName("Sonar way - Without Coverage").setBuiltIn(false));
    db.qualityGates().setDefaultQualityGate(defaultQualityGate);
    ListWsResponse response = ws.newRequest().executeProtobuf(ListWsResponse.class);
    assertThat(response.getActions()).extracting(ListWsResponse.RootActions::getCreate).isEqualTo(true);
    assertThat(response.getQualitygatesList()).extracting(QualityGate::getName, qg -> qg.getActions().getRename(), qg -> qg.getActions().getDelete(), qg -> qg.getActions().getManageConditions(), qp -> qp.getActions().getCopy(), qp -> qp.getActions().getSetAsDefault(), qp -> qp.getActions().getAssociateProjects(), qp -> qp.getActions().getDelegate()).containsExactlyInAnyOrder(tuple(defaultQualityGate.getName(), true, false, true, true, false, false, true), tuple(builtInQualityGate.getName(), false, false, false, true, true, true, false), tuple(otherQualityGate.getName(), true, true, true, true, true, true, true));
}
Also used : UserSessionRule(org.sonar.server.tester.UserSessionRule) ADMINISTER_QUALITY_GATES(org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_GATES) DbTester(org.sonar.db.DbTester) UserDto(org.sonar.db.user.UserDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Test(org.junit.Test) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) WsActionTester(org.sonar.server.ws.WsActionTester) QualityGateFinder(org.sonar.server.qualitygate.QualityGateFinder) AssertionsForClassTypes.tuple(org.assertj.core.api.AssertionsForClassTypes.tuple) QualityGate(org.sonarqube.ws.Qualitygates.ListWsResponse.QualityGate) DbClient(org.sonar.db.DbClient) ADMINISTER_QUALITY_PROFILES(org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_PROFILES) Rule(org.junit.Rule) ListWsResponse(org.sonarqube.ws.Qualitygates.ListWsResponse) WebService(org.sonar.api.server.ws.WebService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) TestComponentFinder(org.sonar.server.component.TestComponentFinder) ListWsResponse(org.sonarqube.ws.Qualitygates.ListWsResponse) QualityGateDto(org.sonar.db.qualitygate.QualityGateDto) Test(org.junit.Test)

Example 2 with ADMINISTER_QUALITY_GATES

use of org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_GATES 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 3 with ADMINISTER_QUALITY_GATES

use of org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_GATES in project sonarqube by SonarSource.

the class SearchActionTest method test_pagination_on_one_page.

@Test
public void test_pagination_on_one_page() {
    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(100)).setParam(PARAM_PAGE, valueOf(1)).executeProtobuf(SearchResponse.class);
    assertThat(response).extracting(SearchResponse::getMore, searchResponse -> searchResponse.getPaging().getPageIndex(), searchResponse -> searchResponse.getPaging().getPageSize(), searchResponse -> searchResponse.getPaging().getTotal()).contains(false, 1, 100, 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)

Aggregations

Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)3 AssertionsForClassTypes.tuple (org.assertj.core.api.AssertionsForClassTypes.tuple)3 Rule (org.junit.Rule)3 Test (org.junit.Test)3 WebService (org.sonar.api.server.ws.WebService)3 DbClient (org.sonar.db.DbClient)3 DbTester (org.sonar.db.DbTester)3 ADMINISTER_QUALITY_GATES (org.sonar.db.permission.GlobalPermission.ADMINISTER_QUALITY_GATES)3 QualityGateDto (org.sonar.db.qualitygate.QualityGateDto)3 UserDto (org.sonar.db.user.UserDto)3 TestComponentFinder (org.sonar.server.component.TestComponentFinder)3 UserSessionRule (org.sonar.server.tester.UserSessionRule)3 WsActionTester (org.sonar.server.ws.WsActionTester)3 String.valueOf (java.lang.String.valueOf)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 ComponentDto (org.sonar.db.component.ComponentDto)2