Search in sources :

Example 1 with ProjectQgateAssociation

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();
}
Also used : ProjectQgateAssociation(org.sonar.db.qualitygate.ProjectQgateAssociation) QgateProjectFinder(org.sonar.server.qualitygate.QgateProjectFinder) JsonWriter(org.sonar.api.utils.text.JsonWriter)

Example 2 with ProjectQgateAssociation

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());
}
Also used : ProjectQgateAssociation(org.sonar.db.qualitygate.ProjectQgateAssociation) Association(org.sonar.server.qualitygate.QgateProjectFinder.Association) ProjectQgateAssociation(org.sonar.db.qualitygate.ProjectQgateAssociation) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 3 with ProjectQgateAssociation

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());
}
Also used : ProjectQgateAssociation(org.sonar.db.qualitygate.ProjectQgateAssociation) Association(org.sonar.server.qualitygate.QgateProjectFinder.Association) ProjectQgateAssociation(org.sonar.db.qualitygate.ProjectQgateAssociation) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 4 with ProjectQgateAssociation

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());
}
Also used : ProjectQgateAssociation(org.sonar.db.qualitygate.ProjectQgateAssociation) Association(org.sonar.server.qualitygate.QgateProjectFinder.Association) ProjectQgateAssociation(org.sonar.db.qualitygate.ProjectQgateAssociation) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 5 with ProjectQgateAssociation

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);
}
Also used : ProjectQgateAssociation(org.sonar.db.qualitygate.ProjectQgateAssociation) Association(org.sonar.server.qualitygate.QgateProjectFinder.Association) ProjectQgateAssociation(org.sonar.db.qualitygate.ProjectQgateAssociation) ProjectQgateAssociationQuery(org.sonar.db.qualitygate.ProjectQgateAssociationQuery) Test(org.junit.Test)

Aggregations

ProjectQgateAssociation (org.sonar.db.qualitygate.ProjectQgateAssociation)6 Test (org.junit.Test)5 Association (org.sonar.server.qualitygate.QgateProjectFinder.Association)5 ComponentDto (org.sonar.db.component.ComponentDto)3 OrganizationDto (org.sonar.db.organization.OrganizationDto)3 ProjectQgateAssociationQuery (org.sonar.db.qualitygate.ProjectQgateAssociationQuery)2 JsonWriter (org.sonar.api.utils.text.JsonWriter)1 QgateProjectFinder (org.sonar.server.qualitygate.QgateProjectFinder)1