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"));
}
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());
}
}
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");
}
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");
}
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);
}
Aggregations