Search in sources :

Example 21 with NewCodePeriodDto

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

the class SearchActionTest method json_example.

@Test
public void json_example() {
    ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto().setDbKey(KEY_PROJECT_EXAMPLE_001));
    userSession.addProjectPermission(UserRole.USER, project);
    SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setCreatedAt(parseDateTime("2016-12-11T17:12:45+0100").getTime()).setProjectVersion("1.2").setBuildString("1.2.0.322").setRevision("bfe36592eb7f9f2708b5d358b5b5f33ed535c8cf"));
    SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(project).setUuid("A2").setCreatedAt(parseDateTime("2016-12-12T17:12:45+0100").getTime()).setProjectVersion("1.2.1").setBuildString("1.2.1.423").setRevision("be6c75b85da526349c44e3978374c95e0b80a96d"));
    SnapshotDto a3 = db.components().insertSnapshot(newAnalysis(project).setUuid("P1").setCreatedAt(parseDateTime("2015-11-11T10:00:00+0100").getTime()).setProjectVersion("1.2").setBuildString("1.2.0.321"));
    db.getDbClient().analysisPropertiesDao().insert(db.getSession(), new AnalysisPropertyDto().setUuid("P1-prop-uuid").setAnalysisUuid(a3.getUuid()).setKey(CorePropertyDefinitions.SONAR_ANALYSIS_DETECTEDCI).setValue("Jenkins").setCreatedAt(1L));
    BranchDto branchDto = newBranchDto(project, BRANCH);
    db.getDbClient().branchDao().insert(db.getSession(), branchDto);
    db.newCodePeriods().insert(new NewCodePeriodDto().setProjectUuid(project.uuid()).setBranchUuid(branchDto.getUuid()).setType(NewCodePeriodType.SPECIFIC_ANALYSIS).setValue(a1.getUuid()));
    db.commit();
    db.events().insertEvent(newEvent(a1).setUuid("AXt91FkXy_c4CIP4ds6A").setName("Failed").setCategory(QUALITY_GATE.getLabel()).setDescription("Coverage on New Code < 85, Reliability Rating > 4, Maintainability Rating on New Code > 1, Reliability Rating on New Code > 1, Security Rating on New Code > 1, Duplicated Lines (%) on New Code > 3"));
    db.events().insertEvent(newEvent(a1).setUuid("AXx_QFJ6Wa8wkfuJ6r5P").setName("6.3").setCategory(VERSION.getLabel()));
    db.events().insertEvent(newEvent(a2).setUuid("E21").setName("Quality Profile changed to Sonar Way").setCategory(EventCategory.QUALITY_PROFILE.getLabel()));
    db.events().insertEvent(newEvent(a2).setUuid("E22").setName("6.3").setCategory(OTHER.getLabel()));
    EventDto eventDto = db.events().insertEvent(newEvent(a3).setUuid("E31").setName("Quality Gate is Red").setData("{stillFailing: true, status: \"ERROR\"}").setCategory(CATEGORY_ALERT).setDescription(""));
    EventComponentChangeDto changeDto1 = generateEventComponentChange(eventDto, FAILED_QUALITY_GATE, "My project", "app1", "master", project.uuid());
    EventComponentChangeDto changeDto2 = generateEventComponentChange(eventDto, FAILED_QUALITY_GATE, "Another project", "app2", "master", uuidFactoryFast.create());
    insertEventComponentChanges(project, a3, changeDto1, changeDto2);
    String result = ws.newRequest().setParam(PARAM_PROJECT, KEY_PROJECT_EXAMPLE_001).execute().getInput();
    assertJson(result).isSimilarTo(getClass().getResource("search-example.json"));
}
Also used : AnalysisPropertyDto(org.sonar.db.component.AnalysisPropertyDto) BranchDto(org.sonar.db.component.BranchDto) ComponentTesting.newBranchDto(org.sonar.db.component.ComponentTesting.newBranchDto) NewCodePeriodDto(org.sonar.db.newcodeperiod.NewCodePeriodDto) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) EventDto(org.sonar.db.event.EventDto) EventComponentChangeDto(org.sonar.db.event.EventComponentChangeDto) Test(org.junit.Test)

Example 22 with NewCodePeriodDto

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

the class UnsetBaselineActionTest method verifyManualBaseline.

private void verifyManualBaseline(ComponentDto project, @Nullable SnapshotDto projectAnalysis) {
    BranchDto branchDto = db.getDbClient().branchDao().selectByUuid(dbSession, project.uuid()).get();
    Optional<NewCodePeriodDto> newCodePeriod = db.getDbClient().newCodePeriodDao().selectByBranch(dbSession, branchDto.getProjectUuid(), branchDto.getUuid());
    if (projectAnalysis == null) {
        assertThat(newCodePeriod).isNotNull();
        assertThat(newCodePeriod).isEmpty();
    } else {
        assertThat(newCodePeriod).isNotNull();
        assertThat(newCodePeriod).isNotEmpty();
        assertThat(newCodePeriod.get().getValue()).isEqualTo(projectAnalysis.getUuid());
    }
}
Also used : BranchDto(org.sonar.db.component.BranchDto) NewCodePeriodDto(org.sonar.db.newcodeperiod.NewCodePeriodDto)

Example 23 with NewCodePeriodDto

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

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

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

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