Search in sources :

Example 1 with Association

use of org.sonar.server.qualitygate.QgateProjectFinder.Association in project sonarqube by SonarSource.

the class QgateProjectFinderTest method return_only_authorized_projects.

@Test
public void return_only_authorized_projects() throws Exception {
    UserDto user = dbTester.users().insertUser("a_login");
    OrganizationDto organizationDto = dbTester.organizations().insert();
    ComponentDto project1 = componentDbTester.insertComponent(newProjectDto(organizationDto));
    componentDbTester.insertComponent(newProjectDto(organizationDto));
    // User can only see project 1
    dbTester.users().insertProjectPermissionOnUser(user, UserRole.USER, project1);
    userSession.logIn(user.getLogin()).setUserId(user.getId());
    Association result = underTest.find(builder().gateId(Long.toString(qGate.getId())).build());
    verifyProjects(result, project1.getId());
}
Also used : ProjectQgateAssociation(org.sonar.db.qualitygate.ProjectQgateAssociation) Association(org.sonar.server.qualitygate.QgateProjectFinder.Association) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 2 with Association

use of org.sonar.server.qualitygate.QgateProjectFinder.Association in project sonarqube by SonarSource.

the class QgateProjectFinderTest method return_empty_association.

@Test
public void return_empty_association() throws Exception {
    Association result = underTest.find(builder().gateId(Long.toString(qGate.getId())).build());
    assertThat(result.projects()).isEmpty();
}
Also used : ProjectQgateAssociation(org.sonar.db.qualitygate.ProjectQgateAssociation) Association(org.sonar.server.qualitygate.QgateProjectFinder.Association) Test(org.junit.Test)

Example 3 with Association

use of org.sonar.server.qualitygate.QgateProjectFinder.Association 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 4 with Association

use of org.sonar.server.qualitygate.QgateProjectFinder.Association 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 5 with Association

use of org.sonar.server.qualitygate.QgateProjectFinder.Association 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)

Aggregations

Test (org.junit.Test)7 ProjectQgateAssociation (org.sonar.db.qualitygate.ProjectQgateAssociation)7 Association (org.sonar.server.qualitygate.QgateProjectFinder.Association)7 ComponentDto (org.sonar.db.component.ComponentDto)4 OrganizationDto (org.sonar.db.organization.OrganizationDto)4 ProjectQgateAssociationQuery (org.sonar.db.qualitygate.ProjectQgateAssociationQuery)2 UserDto (org.sonar.db.user.UserDto)1