Search in sources :

Example 1 with ProjectQgateAssociationQuery

use of org.sonar.db.qualitygate.ProjectQgateAssociationQuery in project sonarqube by SonarSource.

the class QgateProjectFinderTest method do_not_verify_permissions_if_user_is_root.

@Test
public void do_not_verify_permissions_if_user_is_root() throws Exception {
    OrganizationDto org = dbTester.organizations().insert();
    ComponentDto project = componentDbTester.insertProject(org);
    ProjectQgateAssociationQuery query = builder().gateId(Long.toString(qGate.getId())).build();
    userSession.logIn().setNonRoot();
    verifyProjects(underTest.find(query));
    userSession.logIn().setRoot();
    verifyProjects(underTest.find(query), project.getId());
}
Also used : ProjectQgateAssociationQuery(org.sonar.db.qualitygate.ProjectQgateAssociationQuery) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 2 with ProjectQgateAssociationQuery

use of org.sonar.db.qualitygate.ProjectQgateAssociationQuery 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)

Example 3 with ProjectQgateAssociationQuery

use of org.sonar.db.qualitygate.ProjectQgateAssociationQuery in project sonarqube by SonarSource.

the class QualityGatesWsTest method search_with_query.

@Test
public void search_with_query() throws Exception {
    long gateId = 12345L;
    Association assoc = mock(Association.class);
    when(assoc.hasMoreResults()).thenReturn(true);
    List<ProjectQgateAssociation> projects = ImmutableList.of(new ProjectQgateAssociation().setId(42L).setName("Project One").setMember(false), 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)).setParam("query", "Project").execute().assertJson("{\"more\":true,\"results\":[" + "{\"id\":42,\"name\":\"Project One\",\"selected\":false}," + "{\"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.ANY);
}
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

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