Search in sources :

Example 6 with ShowWSResponse

use of org.sonarqube.ws.NewCodePeriods.ShowWSResponse in project sonarqube by SonarSource.

the class ShowActionTest method show_branch_setting.

@Test
public void show_branch_setting() {
    ComponentDto project = componentDb.insertPublicProject();
    logInAsProjectAdministrator(project);
    ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch"));
    tester.insert(new NewCodePeriodDto().setProjectUuid(project.uuid()).setBranchUuid(branch.uuid()).setType(NewCodePeriodType.NUMBER_OF_DAYS).setValue("1"));
    ShowWSResponse response = ws.newRequest().setParam("project", project.getKey()).setParam("branch", "branch").executeProtobuf(ShowWSResponse.class);
    assertResponse(response, project.getKey(), "branch", NewCodePeriods.NewCodePeriodType.NUMBER_OF_DAYS, "1", false);
}
Also used : NewCodePeriodDto(org.sonar.db.newcodeperiod.NewCodePeriodDto) ShowWSResponse(org.sonarqube.ws.NewCodePeriods.ShowWSResponse) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 7 with ShowWSResponse

use of org.sonarqube.ws.NewCodePeriods.ShowWSResponse in project sonarqube by SonarSource.

the class ListActionTest method list_branch_and_inherited_global_settings.

@Test
public void list_branch_and_inherited_global_settings() {
    ComponentDto project = componentDb.insertPublicProject();
    ComponentDto branchWithOwnSettings = componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey("OWN_SETTINGS"));
    componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey("GLOBAL_SETTINGS"));
    tester.insert(new NewCodePeriodDto().setType(NewCodePeriodType.SPECIFIC_ANALYSIS).setValue("global_uuid"));
    tester.insert(new NewCodePeriodDto().setProjectUuid(project.uuid()).setBranchUuid(branchWithOwnSettings.uuid()).setType(NewCodePeriodType.SPECIFIC_ANALYSIS).setValue("branch_uuid"));
    logInAsProjectAdministrator(project);
    ListWSResponse response = ws.newRequest().setParam("project", project.getKey()).executeProtobuf(ListWSResponse.class);
    assertThat(response).isNotNull();
    assertThat(response.getNewCodePeriodsCount()).isEqualTo(3);
    assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey).contains("master", "OWN_SETTINGS", "GLOBAL_SETTINGS");
    Optional<ShowWSResponse> ownSettings = response.getNewCodePeriodsList().stream().filter(s -> !s.getInherited()).findFirst();
    assertThat(ownSettings).isNotNull();
    assertThat(ownSettings).isNotEmpty();
    assertThat(ownSettings.get().getProjectKey()).isEqualTo(project.getKey());
    assertThat(ownSettings.get().getBranchKey()).isEqualTo("OWN_SETTINGS");
    assertThat(ownSettings.get().getType()).isEqualTo(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS);
    assertThat(ownSettings.get().getValue()).isEqualTo("branch_uuid");
    assertThat(ownSettings.get().getInherited()).isFalse();
    // check if global default is set
    assertThat(response.getNewCodePeriodsList()).filteredOn(ShowWSResponse::getInherited).extracting(ShowWSResponse::getType).contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS);
    assertThat(response.getNewCodePeriodsList()).filteredOn(ShowWSResponse::getInherited).extracting(ShowWSResponse::getValue).contains("global_uuid");
}
Also used : ComponentFinder(org.sonar.server.component.ComponentFinder) NewCodePeriodDao(org.sonar.db.newcodeperiod.NewCodePeriodDao) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ShowWSResponse(org.sonarqube.ws.NewCodePeriods.ShowWSResponse) WebService(org.sonar.api.server.ws.WebService) DateUtils(org.sonar.api.utils.DateUtils) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SnapshotTesting.newAnalysis(org.sonar.db.component.SnapshotTesting.newAnalysis) UuidFactoryFast(org.sonar.core.util.UuidFactoryFast) NewCodePeriodType(org.sonar.db.newcodeperiod.NewCodePeriodType) TestComponentFinder(org.sonar.server.component.TestComponentFinder) ListWSResponse(org.sonarqube.ws.NewCodePeriods.ListWSResponse) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) NewCodePeriodDbTester(org.sonar.db.newcodeperiod.NewCodePeriodDbTester) BranchType(org.sonar.db.component.BranchType) System2(org.sonar.api.utils.System2) Test(org.junit.Test) Instant(java.time.Instant) WsActionTester(org.sonar.server.ws.WsActionTester) NotFoundException(org.sonar.server.exceptions.NotFoundException) ComponentDbTester(org.sonar.db.component.ComponentDbTester) NewCodePeriods(org.sonarqube.ws.NewCodePeriods) DbClient(org.sonar.db.DbClient) NewCodePeriodDto(org.sonar.db.newcodeperiod.NewCodePeriodDto) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) UserRole(org.sonar.api.web.UserRole) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) Optional(java.util.Optional) SnapshotDto(org.sonar.db.component.SnapshotDto) ListWSResponse(org.sonarqube.ws.NewCodePeriods.ListWSResponse) NewCodePeriodDto(org.sonar.db.newcodeperiod.NewCodePeriodDto) ShowWSResponse(org.sonarqube.ws.NewCodePeriods.ShowWSResponse) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 8 with ShowWSResponse

use of org.sonarqube.ws.NewCodePeriods.ShowWSResponse in project sonarqube by SonarSource.

the class ListActionTest method list_branch_and_inherited_project_settings.

@Test
public void list_branch_and_inherited_project_settings() {
    ComponentDto project = componentDb.insertPublicProject();
    ComponentDto branchWithOwnSettings = componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey("OWN_SETTINGS"));
    componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey("PROJECT_SETTINGS"));
    tester.insert(new NewCodePeriodDto().setType(NewCodePeriodType.SPECIFIC_ANALYSIS).setValue("global_uuid"));
    tester.insert(new NewCodePeriodDto().setProjectUuid(project.uuid()).setType(NewCodePeriodType.SPECIFIC_ANALYSIS).setValue("project_uuid"));
    tester.insert(new NewCodePeriodDto().setProjectUuid(project.uuid()).setBranchUuid(branchWithOwnSettings.uuid()).setType(NewCodePeriodType.SPECIFIC_ANALYSIS).setValue("branch_uuid"));
    logInAsProjectAdministrator(project);
    ListWSResponse response = ws.newRequest().setParam("project", project.getKey()).executeProtobuf(ListWSResponse.class);
    assertThat(response).isNotNull();
    assertThat(response.getNewCodePeriodsCount()).isEqualTo(3);
    assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey).contains("master", "OWN_SETTINGS", "PROJECT_SETTINGS");
    Optional<ShowWSResponse> ownSettings = response.getNewCodePeriodsList().stream().filter(s -> !s.getInherited()).findFirst();
    assertThat(ownSettings).isNotNull();
    assertThat(ownSettings).isNotEmpty();
    assertThat(ownSettings.get().getProjectKey()).isEqualTo(project.getKey());
    assertThat(ownSettings.get().getBranchKey()).isEqualTo("OWN_SETTINGS");
    assertThat(ownSettings.get().getType()).isEqualTo(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS);
    assertThat(ownSettings.get().getValue()).isEqualTo("branch_uuid");
    assertThat(ownSettings.get().getInherited()).isFalse();
    // check if global default is set
    assertThat(response.getNewCodePeriodsList()).filteredOn(ShowWSResponse::getInherited).extracting(ShowWSResponse::getType).contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS);
    assertThat(response.getNewCodePeriodsList()).filteredOn(ShowWSResponse::getInherited).extracting(ShowWSResponse::getValue).contains("project_uuid");
}
Also used : ComponentFinder(org.sonar.server.component.ComponentFinder) NewCodePeriodDao(org.sonar.db.newcodeperiod.NewCodePeriodDao) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ShowWSResponse(org.sonarqube.ws.NewCodePeriods.ShowWSResponse) WebService(org.sonar.api.server.ws.WebService) DateUtils(org.sonar.api.utils.DateUtils) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SnapshotTesting.newAnalysis(org.sonar.db.component.SnapshotTesting.newAnalysis) UuidFactoryFast(org.sonar.core.util.UuidFactoryFast) NewCodePeriodType(org.sonar.db.newcodeperiod.NewCodePeriodType) TestComponentFinder(org.sonar.server.component.TestComponentFinder) ListWSResponse(org.sonarqube.ws.NewCodePeriods.ListWSResponse) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) NewCodePeriodDbTester(org.sonar.db.newcodeperiod.NewCodePeriodDbTester) BranchType(org.sonar.db.component.BranchType) System2(org.sonar.api.utils.System2) Test(org.junit.Test) Instant(java.time.Instant) WsActionTester(org.sonar.server.ws.WsActionTester) NotFoundException(org.sonar.server.exceptions.NotFoundException) ComponentDbTester(org.sonar.db.component.ComponentDbTester) NewCodePeriods(org.sonarqube.ws.NewCodePeriods) DbClient(org.sonar.db.DbClient) NewCodePeriodDto(org.sonar.db.newcodeperiod.NewCodePeriodDto) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) UserRole(org.sonar.api.web.UserRole) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) Optional(java.util.Optional) SnapshotDto(org.sonar.db.component.SnapshotDto) ListWSResponse(org.sonarqube.ws.NewCodePeriods.ListWSResponse) NewCodePeriodDto(org.sonar.db.newcodeperiod.NewCodePeriodDto) ShowWSResponse(org.sonarqube.ws.NewCodePeriods.ShowWSResponse) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 9 with ShowWSResponse

use of org.sonarqube.ws.NewCodePeriods.ShowWSResponse in project sonarqube by SonarSource.

the class ShowActionTest method show_project_setting.

@Test
public void show_project_setting() {
    ComponentDto project = componentDb.insertPublicProject();
    logInAsProjectAdministrator(project);
    tester.insert(new NewCodePeriodDto().setProjectUuid(project.uuid()).setType(NewCodePeriodType.NUMBER_OF_DAYS).setValue("4"));
    ShowWSResponse response = ws.newRequest().setParam("project", project.getKey()).executeProtobuf(ShowWSResponse.class);
    assertResponse(response, project.getKey(), "", NewCodePeriods.NewCodePeriodType.NUMBER_OF_DAYS, "4", false);
}
Also used : NewCodePeriodDto(org.sonar.db.newcodeperiod.NewCodePeriodDto) ShowWSResponse(org.sonarqube.ws.NewCodePeriods.ShowWSResponse) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 10 with ShowWSResponse

use of org.sonarqube.ws.NewCodePeriods.ShowWSResponse in project sonarqube by SonarSource.

the class ShowActionTest method show_inherited_branch_setting_from_project.

@Test
public void show_inherited_branch_setting_from_project() {
    ComponentDto project = componentDb.insertPublicProject();
    logInAsProjectAdministrator(project);
    ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch"));
    tester.insert(new NewCodePeriodDto().setProjectUuid(project.uuid()).setType(NewCodePeriodType.NUMBER_OF_DAYS).setValue("1"));
    ShowWSResponse response = ws.newRequest().setParam("project", project.getKey()).setParam("branch", "branch").executeProtobuf(ShowWSResponse.class);
    assertResponse(response, project.getKey(), "branch", NewCodePeriods.NewCodePeriodType.NUMBER_OF_DAYS, "1", true);
}
Also used : NewCodePeriodDto(org.sonar.db.newcodeperiod.NewCodePeriodDto) ShowWSResponse(org.sonarqube.ws.NewCodePeriods.ShowWSResponse) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 ShowWSResponse (org.sonarqube.ws.NewCodePeriods.ShowWSResponse)11 NewCodePeriodDto (org.sonar.db.newcodeperiod.NewCodePeriodDto)10 ComponentDto (org.sonar.db.component.ComponentDto)9 SnapshotDto (org.sonar.db.component.SnapshotDto)3 ListWSResponse (org.sonarqube.ws.NewCodePeriods.ListWSResponse)3 Instant (java.time.Instant)2 Optional (java.util.Optional)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)2 Rule (org.junit.Rule)2 WebService (org.sonar.api.server.ws.WebService)2 DateUtils (org.sonar.api.utils.DateUtils)2 System2 (org.sonar.api.utils.System2)2 UserRole (org.sonar.api.web.UserRole)2 UuidFactoryFast (org.sonar.core.util.UuidFactoryFast)2 DbClient (org.sonar.db.DbClient)2 DbTester (org.sonar.db.DbTester)2 BranchType (org.sonar.db.component.BranchType)2 ComponentDbTester (org.sonar.db.component.ComponentDbTester)2