use of org.sonar.db.qualitygate.ProjectQgateAssociation in project sonarqube by SonarSource.
the class SearchAction method handle.
@Override
public void handle(Request request, Response response) {
QgateProjectFinder.Association associations = projectFinder.find(ProjectQgateAssociationQuery.builder().gateId(request.mandatoryParam(QualityGatesWsParameters.PARAM_GATE_ID)).membership(request.param(QualityGatesWsParameters.PARAM_QUERY) == null ? request.param(Param.SELECTED) : ProjectQgateAssociationQuery.ANY).projectSearch(request.param(QualityGatesWsParameters.PARAM_QUERY)).pageIndex(request.paramAsInt(QualityGatesWsParameters.PARAM_PAGE)).pageSize(request.paramAsInt(QualityGatesWsParameters.PARAM_PAGE_SIZE)).build());
JsonWriter writer = response.newJsonWriter();
writer.beginObject().prop("more", associations.hasMoreResults());
writer.name("results").beginArray();
for (ProjectQgateAssociation project : associations.projects()) {
writer.beginObject().prop("id", project.id()).prop("name", project.name()).prop(Param.SELECTED, project.isMember()).endObject();
}
writer.endArray().endObject().close();
}
use of org.sonar.db.qualitygate.ProjectQgateAssociation in project sonarqube by SonarSource.
the class QgateProjectFinderTest method return_only_unassociated_project.
@Test
public void return_only_unassociated_project() throws Exception {
OrganizationDto org = dbTester.organizations().insert();
ComponentDto associatedProject = insertProjectAuthorizedToAnyone(newProjectDto(org));
ComponentDto unassociatedProject = insertProjectAuthorizedToAnyone(newProjectDto(org));
associateProjectToQualitGate(associatedProject.getId());
Association result = underTest.find(builder().membership(OUT).gateId(Long.toString(qGate.getId())).build());
Map<Long, ProjectQgateAssociation> projectsById = projectsById(result.projects());
assertThat(projectsById).hasSize(1);
verifyProject(projectsById.get(unassociatedProject.getId()), false, unassociatedProject.name());
}
use of org.sonar.db.qualitygate.ProjectQgateAssociation in project sonarqube by SonarSource.
the class QgateProjectFinderTest method return_only_associated_project.
@Test
public void return_only_associated_project() throws Exception {
OrganizationDto org = dbTester.organizations().insert();
ComponentDto associatedProject = insertProjectAuthorizedToAnyone(newProjectDto(org));
insertProjectAuthorizedToAnyone(newProjectDto(org));
associateProjectToQualitGate(associatedProject.getId());
Association result = underTest.find(builder().membership(IN).gateId(Long.toString(qGate.getId())).build());
Map<Long, ProjectQgateAssociation> projectsById = projectsById(result.projects());
assertThat(projectsById).hasSize(1);
verifyProject(projectsById.get(associatedProject.getId()), true, associatedProject.name());
}
use of org.sonar.db.qualitygate.ProjectQgateAssociation in project sonarqube by SonarSource.
the class QgateProjectFinderTest method return_all_projects.
@Test
public void return_all_projects() throws Exception {
OrganizationDto org = dbTester.organizations().insert();
ComponentDto associatedProject = insertProjectAuthorizedToAnyone(newProjectDto(org));
ComponentDto unassociatedProject = insertProjectAuthorizedToAnyone(newProjectDto(org));
associateProjectToQualitGate(associatedProject.getId());
Association result = underTest.find(builder().gateId(Long.toString(qGate.getId())).build());
Map<Long, ProjectQgateAssociation> projectsById = projectsById(result.projects());
assertThat(projectsById).hasSize(2);
verifyProject(projectsById.get(associatedProject.getId()), true, associatedProject.name());
verifyProject(projectsById.get(unassociatedProject.getId()), false, unassociatedProject.name());
}
use of org.sonar.db.qualitygate.ProjectQgateAssociation in project sonarqube by SonarSource.
the class QualityGatesWsTest method search_nominal.
@Test
public void search_nominal() throws Exception {
long gateId = 12345L;
Association assoc = mock(Association.class);
when(assoc.hasMoreResults()).thenReturn(true);
List<ProjectQgateAssociation> projects = ImmutableList.of(new ProjectQgateAssociation().setId(24L).setName("Project Two").setMember(true));
when(assoc.projects()).thenReturn(projects);
when(projectFinder.find(any(ProjectQgateAssociationQuery.class))).thenReturn(assoc);
tester.newGetRequest("api/qualitygates", "search").setParam("gateId", Long.toString(gateId)).execute().assertJson("{\"more\":true,\"results\":[" + "{\"id\":24,\"name\":\"Project Two\",\"selected\":true}" + "]}");
ArgumentCaptor<ProjectQgateAssociationQuery> queryCaptor = ArgumentCaptor.forClass(ProjectQgateAssociationQuery.class);
verify(projectFinder).find(queryCaptor.capture());
ProjectQgateAssociationQuery query = queryCaptor.getValue();
assertThat(query.membership()).isEqualTo(ProjectQgateAssociationQuery.IN);
}
Aggregations