use of org.sonarqube.ws.NewCodePeriods.ListWSResponse 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");
}
Aggregations