Search in sources :

Example 1 with ShowWSResponse

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

the class ListActionTest method verify_specific_analysis_effective_value.

@Test
public void verify_specific_analysis_effective_value() {
    ComponentDto project = componentDb.insertPublicProject();
    ComponentDto branch = componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey("PROJECT_BRANCH"));
    SnapshotDto analysis = componentDb.insertSnapshot(newAnalysis(project).setUuid("A1").setCreatedAt(Instant.now().toEpochMilli()).setProjectVersion("1.2").setBuildString("1.2.0.322").setRevision("bfe36592eb7f9f2708b5d358b5b5f33ed535c8cf"));
    componentDb.insertSnapshot(newAnalysis(project).setUuid("A2").setCreatedAt(Instant.now().toEpochMilli()).setProjectVersion("1.2").setBuildString("1.2.0.322").setRevision("2d6d5d8d5fabe2223f07aa495e794d0401ff4b04"));
    tester.insert(new NewCodePeriodDto().setProjectUuid(project.uuid()).setBranchUuid(branch.uuid()).setType(NewCodePeriodType.SPECIFIC_ANALYSIS).setValue(analysis.getUuid()));
    logInAsProjectAdministrator(project);
    ListWSResponse response = ws.newRequest().setParam("project", project.getKey()).executeProtobuf(ListWSResponse.class);
    assertThat(response).isNotNull();
    assertThat(response.getNewCodePeriodsCount()).isEqualTo(2);
    assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey).containsOnly("master", "PROJECT_BRANCH");
    ShowWSResponse result = response.getNewCodePeriodsList().get(0);
    assertThat(result.getType()).isEqualTo(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS);
    assertThat(result.getValue()).isEqualTo("A1");
    assertThat(result.getProjectKey()).isEqualTo(project.getKey());
    assertThat(result.getBranchKey()).isEqualTo("PROJECT_BRANCH");
    assertThat(result.getEffectiveValue()).isEqualTo(DateUtils.formatDateTime(analysis.getCreatedAt()));
}
Also used : ListWSResponse(org.sonarqube.ws.NewCodePeriods.ListWSResponse) NewCodePeriodDto(org.sonar.db.newcodeperiod.NewCodePeriodDto) ShowWSResponse(org.sonarqube.ws.NewCodePeriods.ShowWSResponse) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 2 with ShowWSResponse

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

the class ShowActionTest method show_global_setting.

@Test
public void show_global_setting() {
    tester.insert(new NewCodePeriodDto().setType(NewCodePeriodType.PREVIOUS_VERSION));
    ShowWSResponse response = ws.newRequest().executeProtobuf(ShowWSResponse.class);
    assertResponse(response, "", "", NewCodePeriods.NewCodePeriodType.PREVIOUS_VERSION, "", false);
}
Also used : NewCodePeriodDto(org.sonar.db.newcodeperiod.NewCodePeriodDto) ShowWSResponse(org.sonarqube.ws.NewCodePeriods.ShowWSResponse) Test(org.junit.Test)

Example 3 with ShowWSResponse

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

the class ShowActionTest method show_inherited_branch_setting_from_global.

@Test
public void show_inherited_branch_setting_from_global() {
    ComponentDto project = componentDb.insertPublicProject();
    logInAsProjectAdministrator(project);
    ComponentDto branch = componentDb.insertProjectBranch(project, b -> b.setKey("branch"));
    tester.insert(new NewCodePeriodDto().setType(NewCodePeriodType.NUMBER_OF_DAYS).setValue("3"));
    ShowWSResponse response = ws.newRequest().setParam("project", project.getKey()).setParam("branch", "branch").executeProtobuf(ShowWSResponse.class);
    assertResponse(response, project.getKey(), "branch", NewCodePeriods.NewCodePeriodType.NUMBER_OF_DAYS, "3", 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)

Example 4 with ShowWSResponse

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

the class ShowActionTest method show_inherited_project_setting.

@Test
public void show_inherited_project_setting() {
    ComponentDto project = componentDb.insertPublicProject();
    logInAsProjectAdministrator(project);
    tester.insert(new NewCodePeriodDto().setType(NewCodePeriodType.PREVIOUS_VERSION));
    ShowWSResponse response = ws.newRequest().setParam("project", project.getKey()).executeProtobuf(ShowWSResponse.class);
    assertResponse(response, project.getKey(), "", NewCodePeriods.NewCodePeriodType.PREVIOUS_VERSION, "", 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)

Example 5 with ShowWSResponse

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

the class ShowActionTest method show_inherited_if_project_not_found.

@Test
public void show_inherited_if_project_not_found() {
    tester.insert(new NewCodePeriodDto().setType(NewCodePeriodType.NUMBER_OF_DAYS).setValue("3"));
    ShowWSResponse response = ws.newRequest().setParam("project", "unknown").executeProtobuf(ShowWSResponse.class);
    assertResponse(response, "", "", NewCodePeriods.NewCodePeriodType.NUMBER_OF_DAYS, "3", true);
}
Also used : NewCodePeriodDto(org.sonar.db.newcodeperiod.NewCodePeriodDto) ShowWSResponse(org.sonarqube.ws.NewCodePeriods.ShowWSResponse) 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