Search in sources :

Example 81 with OrganizationDto

use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.

the class ComponentActionTest method project_tasks.

@Test
public void project_tasks() {
    OrganizationDto organizationDto = dbTester.organizations().insert();
    dbTester.components().insertComponent(newProjectDto(organizationDto, "PROJECT_1"));
    userSession.addComponentUuidPermission(UserRole.USER, "PROJECT_1", "PROJECT_1");
    insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS);
    insertActivity("T2", "PROJECT_2", CeActivityDto.Status.FAILED);
    insertActivity("T3", "PROJECT_1", CeActivityDto.Status.FAILED);
    insertQueue("T4", "PROJECT_1", CeQueueDto.Status.IN_PROGRESS);
    insertQueue("T5", "PROJECT_1", CeQueueDto.Status.PENDING);
    TestResponse wsResponse = ws.newRequest().setParam("componentId", "PROJECT_1").setMediaType(MediaTypes.PROTOBUF).execute();
    WsCe.ProjectResponse response = Protobuf.read(wsResponse.getInputStream(), WsCe.ProjectResponse.parser());
    assertThat(response.getQueueCount()).isEqualTo(2);
    assertThat(response.getQueue(0).getId()).isEqualTo("T4");
    assertThat(response.getQueue(1).getId()).isEqualTo("T5");
    // T3 is the latest task executed on PROJECT_1
    assertThat(response.hasCurrent()).isTrue();
    assertThat(response.getCurrent().getId()).isEqualTo("T3");
    assertThat(response.getQueueList()).extracting(WsCe.Task::getOrganization).containsOnly(organizationDto.getKey());
    assertThat(response.getCurrent().getOrganization()).isEqualTo(organizationDto.getKey());
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) WsCe(org.sonarqube.ws.WsCe) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 82 with OrganizationDto

use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.

the class SearchActionTest method test_json_example.

@Test
public void test_json_example() {
    OrganizationDto organizationDto = db.organizations().insertForKey("my-org-1");
    db.components().insertComponent(newView(organizationDto));
    ComponentDto project = newProjectDto(organizationDto, "project-uuid").setName("Project Name").setKey("project-key");
    ComponentDto module = newModuleDto("module-uuid", project).setName("Module Name").setKey("module-key");
    ComponentDto directory = newDirectory(module, "path/to/directoy").setUuid("directory-uuid").setKey("directory-key").setName("Directory Name");
    db.components().insertComponents(project, module, directory, newFileDto(module, directory, "file-uuid").setKey("file-key").setLanguage("java").setName("File Name"));
    setBrowsePermissionOnUser(project);
    String response = ws.newRequest().setMediaType(MediaTypes.JSON).setParam(PARAM_ORGANIZATION, organizationDto.getKey()).setParam(PARAM_QUALIFIERS, Joiner.on(",").join(PROJECT, MODULE, DIRECTORY, FILE)).execute().getInput();
    assertJson(response).isSimilarTo(ws.getDef().responseExampleAsString());
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 83 with OrganizationDto

use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.

the class SearchActionTest method search_with_language.

@Test
public void search_with_language() throws IOException {
    OrganizationDto organizationDto = db.organizations().insert();
    insertProjectsAuthorizedForUser(newProjectDto(organizationDto).setKey("java-project").setLanguage("java"), newProjectDto(organizationDto).setKey("cpp-project").setLanguage("cpp"));
    SearchWsResponse response = call(new SearchWsRequest().setOrganization(organizationDto.getKey()).setLanguage("java").setQualifiers(singletonList(PROJECT)));
    assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly("java-project");
}
Also used : SearchWsRequest(org.sonarqube.ws.client.component.SearchWsRequest) SearchWsResponse(org.sonarqube.ws.WsComponents.SearchWsResponse) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 84 with OrganizationDto

use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.

the class SearchActionTest method do_not_verify_permissions_if_user_is_root.

@Test
public void do_not_verify_permissions_if_user_is_root() throws IOException {
    OrganizationDto org = db.organizations().insert();
    ComponentDto project1 = newProjectDto(org);
    ComponentDto file1 = newFileDto(project1);
    ComponentDto project2 = newProjectDto(org);
    ComponentDto file2 = newFileDto(project2);
    db.components().insertComponents(project1, file1, project2, file2);
    SearchWsRequest request = new SearchWsRequest().setQualifiers(singletonList(FILE)).setOrganization(org.getKey());
    userSession.logIn().setNonRoot();
    assertThat(call(request).getComponentsCount()).isZero();
    userSession.logIn().setRoot();
    assertThat(call(request).getComponentsList()).extracting(Component::getKey).containsOnly(file1.getKey(), file2.getKey());
}
Also used : SearchWsRequest(org.sonarqube.ws.client.component.SearchWsRequest) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 85 with OrganizationDto

use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.

the class SearchProjectsActionTest method return_languages_facet_with_language_having_no_project_if_language_is_in_filter.

@Test
public void return_languages_facet_with_language_having_no_project_if_language_is_in_filter() {
    OrganizationDto organization = db.getDefaultOrganization();
    insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81d)), null, asList("<null>", "java"));
    insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Groovy"), newArrayList(newMeasure(COVERAGE, 81)), null, asList("java"));
    insertMetrics(COVERAGE, NCLOC_LANGUAGE_DISTRIBUTION_KEY);
    SearchProjectsWsResponse result = call(request.setFilter("languages = xoo").setFacets(singletonList(FILTER_LANGUAGES)));
    Common.Facet facet = result.getFacets().getFacetsList().stream().filter(oneFacet -> FILTER_LANGUAGES.equals(oneFacet.getProperty())).findFirst().orElseThrow(IllegalStateException::new);
    assertThat(facet.getValuesList()).extracting(Common.FacetValue::getVal, Common.FacetValue::getCount).containsOnly(tuple("xoo", 0L), tuple("java", 2L), tuple("<null>", 1L));
}
Also used : SearchProjectsWsResponse(org.sonarqube.ws.WsComponents.SearchProjectsWsResponse) OrganizationDto(org.sonar.db.organization.OrganizationDto) Common(org.sonarqube.ws.Common) Test(org.junit.Test)

Aggregations

OrganizationDto (org.sonar.db.organization.OrganizationDto)384 Test (org.junit.Test)329 ComponentDto (org.sonar.db.component.ComponentDto)148 GroupDto (org.sonar.db.user.GroupDto)74 UserDto (org.sonar.db.user.UserDto)40 DbSession (org.sonar.db.DbSession)35 PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)33 TestResponse (org.sonar.server.ws.TestResponse)19 SnapshotDto (org.sonar.db.component.SnapshotDto)17 BasePermissionWsTest (org.sonar.server.permission.ws.BasePermissionWsTest)16 ProjectRepositories (org.sonar.scanner.protocol.input.ProjectRepositories)15 PropertyDto (org.sonar.db.property.PropertyDto)13 SearchProjectsWsResponse (org.sonarqube.ws.WsComponents.SearchProjectsWsResponse)12 GroupTesting.newGroupDto (org.sonar.db.user.GroupTesting.newGroupDto)11 SearchOptions (org.sonar.server.es.SearchOptions)11 OrganizationTesting.newOrganizationDto (org.sonar.db.organization.OrganizationTesting.newOrganizationDto)9 PermissionTemplateGroupDto (org.sonar.db.permission.template.PermissionTemplateGroupDto)8 Organizations (org.sonarqube.ws.Organizations)8 MetricDto (org.sonar.db.metric.MetricDto)7 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)7