Search in sources :

Example 6 with NewCodePeriodDto

use of org.sonar.db.newcodeperiod.NewCodePeriodDto in project sonarqube by SonarSource.

the class SetBaselineAction method doHandle.

private void doHandle(Request request) {
    String projectKey = request.mandatoryParam(PARAM_PROJECT);
    String branchKey = trimToNull(request.param(PARAM_BRANCH));
    String analysisUuid = request.mandatoryParam(PARAM_ANALYSIS);
    try (DbSession dbSession = dbClient.openSession(false)) {
        ProjectDto project = componentFinder.getProjectByKey(dbSession, projectKey);
        BranchDto branch = loadBranch(dbSession, project, branchKey);
        SnapshotDto analysis = getAnalysis(dbSession, analysisUuid);
        checkRequest(project, branch, analysis, branchKey);
        dbClient.newCodePeriodDao().upsert(dbSession, new NewCodePeriodDto().setProjectUuid(project.getUuid()).setBranchUuid(branch.getUuid()).setType(NewCodePeriodType.SPECIFIC_ANALYSIS).setValue(analysisUuid));
        dbSession.commit();
    }
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) DbSession(org.sonar.db.DbSession) BranchDto(org.sonar.db.component.BranchDto) NewCodePeriodDto(org.sonar.db.newcodeperiod.NewCodePeriodDto) SnapshotDto(org.sonar.db.component.SnapshotDto)

Example 7 with NewCodePeriodDto

use of org.sonar.db.newcodeperiod.NewCodePeriodDto 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 8 with NewCodePeriodDto

use of org.sonar.db.newcodeperiod.NewCodePeriodDto in project sonarqube by SonarSource.

the class ListActionTest method list_inherited_global_settings.

@Test
public void list_inherited_global_settings() {
    ComponentDto project = componentDb.insertPublicProject();
    tester.insert(new NewCodePeriodDto().setType(NewCodePeriodType.SPECIFIC_ANALYSIS).setValue("uuid"));
    createBranches(project, 5, BranchType.BRANCH);
    logInAsProjectAdministrator(project);
    ListWSResponse response = ws.newRequest().setParam("project", project.getKey()).executeProtobuf(ListWSResponse.class);
    assertThat(response).isNotNull();
    assertThat(response.getNewCodePeriodsCount()).isEqualTo(6);
    assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey).contains("master", "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4");
    // check if global default is set
    assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType).contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS);
    assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getValue).contains("uuid");
    assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getInherited).contains(true);
}
Also used : ListWSResponse(org.sonarqube.ws.NewCodePeriods.ListWSResponse) NewCodePeriodDto(org.sonar.db.newcodeperiod.NewCodePeriodDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 9 with NewCodePeriodDto

use of org.sonar.db.newcodeperiod.NewCodePeriodDto in project sonarqube by SonarSource.

the class ListActionTest method list_inherited_project_settings.

@Test
public void list_inherited_project_settings() {
    ComponentDto projectWithOwnSettings = componentDb.insertPublicProject();
    ComponentDto projectWithGlobalSettings = componentDb.insertPublicProject();
    tester.insert(new NewCodePeriodDto().setType(NewCodePeriodType.SPECIFIC_ANALYSIS).setValue("global_uuid"));
    tester.insert(new NewCodePeriodDto().setProjectUuid(projectWithOwnSettings.uuid()).setType(NewCodePeriodType.SPECIFIC_ANALYSIS).setValue("project_uuid"));
    createBranches(projectWithOwnSettings, 5, BranchType.BRANCH);
    logInAsProjectAdministrator(projectWithOwnSettings, projectWithGlobalSettings);
    ListWSResponse response = ws.newRequest().setParam("project", projectWithOwnSettings.getKey()).executeProtobuf(ListWSResponse.class);
    // verify project with project level settings
    assertThat(response).isNotNull();
    assertThat(response.getNewCodePeriodsCount()).isEqualTo(6);
    assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey).contains("master", "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4");
    // check if project setting is set
    assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType).contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS);
    assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getValue).containsOnly("project_uuid");
    assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getInherited).containsOnly(true);
    // verify project with global level settings
    response = ws.newRequest().setParam("project", projectWithGlobalSettings.getKey()).executeProtobuf(ListWSResponse.class);
    assertThat(response).isNotNull();
    assertThat(response.getNewCodePeriodsCount()).isOne();
    assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey).containsOnly("master");
    // check if global setting is set
    assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType).contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS);
    assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getValue).contains("global_uuid");
    assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getInherited).containsOnly(true);
}
Also used : ListWSResponse(org.sonarqube.ws.NewCodePeriods.ListWSResponse) NewCodePeriodDto(org.sonar.db.newcodeperiod.NewCodePeriodDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 10 with NewCodePeriodDto

use of org.sonar.db.newcodeperiod.NewCodePeriodDto 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)

Aggregations

NewCodePeriodDto (org.sonar.db.newcodeperiod.NewCodePeriodDto)27 Test (org.junit.Test)20 ComponentDto (org.sonar.db.component.ComponentDto)16 SnapshotDto (org.sonar.db.component.SnapshotDto)12 ShowWSResponse (org.sonarqube.ws.NewCodePeriods.ShowWSResponse)10 DbSession (org.sonar.db.DbSession)6 BranchDto (org.sonar.db.component.BranchDto)6 ListWSResponse (org.sonarqube.ws.NewCodePeriods.ListWSResponse)6 WebService (org.sonar.api.server.ws.WebService)4 UserRole (org.sonar.api.web.UserRole)4 DbClient (org.sonar.db.DbClient)4 NewCodePeriodDao (org.sonar.db.newcodeperiod.NewCodePeriodDao)4 NewCodePeriodType (org.sonar.db.newcodeperiod.NewCodePeriodType)4 ComponentFinder (org.sonar.server.component.ComponentFinder)4 DateUtils (org.sonar.api.utils.DateUtils)3 BranchType (org.sonar.db.component.BranchType)3 NotFoundException (org.sonar.server.exceptions.NotFoundException)3 NewCodePeriods (org.sonarqube.ws.NewCodePeriods)3 ProjectDump (com.sonarsource.governance.projectdump.protobuf.ProjectDump)2 Instant (java.time.Instant)2