Search in sources :

Example 1 with TestResponse

use of org.sonar.server.ws.TestResponse in project sonarqube by SonarSource.

the class ProjectActionTest method project_referentials.

@Test
public void project_referentials() throws Exception {
    String projectKey = "org.codehaus.sonar:sonar";
    ProjectRepositories projectReferentials = mock(ProjectRepositories.class);
    when(projectReferentials.toJson()).thenReturn("{\"settingsByModule\": {}}");
    ArgumentCaptor<ProjectDataQuery> queryArgumentCaptor = ArgumentCaptor.forClass(ProjectDataQuery.class);
    when(projectDataLoader.load(queryArgumentCaptor.capture())).thenReturn(projectReferentials);
    TestResponse response = ws.newRequest().setParam("key", projectKey).setParam("profile", "Default").setParam("preview", "false").execute();
    assertJson(response.getInput()).isSimilarTo("{\"settingsByModule\": {}}");
    assertThat(queryArgumentCaptor.getValue().getModuleKey()).isEqualTo(projectKey);
    assertThat(queryArgumentCaptor.getValue().getProfileName()).isEqualTo("Default");
    assertThat(queryArgumentCaptor.getValue().isIssuesMode()).isFalse();
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) ProjectRepositories(org.sonar.scanner.protocol.input.ProjectRepositories) Test(org.junit.Test)

Example 2 with TestResponse

use of org.sonar.server.ws.TestResponse 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 3 with TestResponse

use of org.sonar.server.ws.TestResponse in project sonarqube by SonarSource.

the class ComponentActionTest method search_tasks_by_component_key.

@Test
public void search_tasks_by_component_key() {
    ComponentDto project = dbTester.components().insertProject();
    logInWithBrowsePermission(project);
    insertActivity("T1", project.uuid(), CeActivityDto.Status.SUCCESS);
    TestResponse wsResponse = ws.newRequest().setParam(PARAM_COMPONENT_KEY, project.key()).setMediaType(MediaTypes.PROTOBUF).execute();
    WsCe.ProjectResponse response = Protobuf.read(wsResponse.getInputStream(), WsCe.ProjectResponse.parser());
    assertThat(response.hasCurrent()).isTrue();
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) WsCe(org.sonarqube.ws.WsCe) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 4 with TestResponse

use of org.sonar.server.ws.TestResponse in project sonarqube by SonarSource.

the class TaskActionTest method return_stacktrace_of_failed_activity_with_stacktrace_when_additionalField_is_set.

@Test
public void return_stacktrace_of_failed_activity_with_stacktrace_when_additionalField_is_set() {
    logInAsRoot();
    CeActivityDto activityDto = createActivityDto(SOME_TASK_UUID).setErrorMessage("error msg").setErrorStacktrace("error stack");
    persist(activityDto);
    TestResponse wsResponse = ws.newRequest().setMediaType(PROTOBUF).setParam("id", SOME_TASK_UUID).setParam("additionalFields", "stacktrace").execute();
    WsCe.TaskResponse taskResponse = Protobuf.read(wsResponse.getInputStream(), WsCe.TaskResponse.PARSER);
    WsCe.Task task = taskResponse.getTask();
    assertThat(task.getId()).isEqualTo(SOME_TASK_UUID);
    assertThat(task.getErrorMessage()).isEqualTo(activityDto.getErrorMessage());
    assertThat(task.hasErrorStacktrace()).isTrue();
    assertThat(task.getErrorStacktrace()).isEqualTo(activityDto.getErrorStacktrace());
}
Also used : CeActivityDto(org.sonar.db.ce.CeActivityDto) TestResponse(org.sonar.server.ws.TestResponse) WsCe(org.sonarqube.ws.WsCe) Test(org.junit.Test)

Example 5 with TestResponse

use of org.sonar.server.ws.TestResponse in project sonarqube by SonarSource.

the class TaskActionTest method do_not_return_stacktrace_of_failed_activity_with_stacktrace_when_additionalField_is_not_set.

@Test
public void do_not_return_stacktrace_of_failed_activity_with_stacktrace_when_additionalField_is_not_set() {
    logInAsRoot();
    CeActivityDto activityDto = createActivityDto(SOME_TASK_UUID).setErrorMessage("error msg").setErrorStacktrace("error stack");
    persist(activityDto);
    TestResponse wsResponse = ws.newRequest().setMediaType(PROTOBUF).setParam("id", SOME_TASK_UUID).execute();
    WsCe.TaskResponse taskResponse = Protobuf.read(wsResponse.getInputStream(), WsCe.TaskResponse.PARSER);
    WsCe.Task task = taskResponse.getTask();
    assertThat(task.getId()).isEqualTo(SOME_TASK_UUID);
    assertThat(task.getErrorMessage()).isEqualTo(activityDto.getErrorMessage());
    assertThat(task.hasErrorStacktrace()).isFalse();
}
Also used : CeActivityDto(org.sonar.db.ce.CeActivityDto) TestResponse(org.sonar.server.ws.TestResponse) WsCe(org.sonarqube.ws.WsCe) Test(org.junit.Test)

Aggregations

TestResponse (org.sonar.server.ws.TestResponse)67 Test (org.junit.Test)64 OrganizationDto (org.sonar.db.organization.OrganizationDto)18 WsCe (org.sonarqube.ws.WsCe)13 ComponentDto (org.sonar.db.component.ComponentDto)9 CeActivityDto (org.sonar.db.ce.CeActivityDto)4 InputStream (java.io.InputStream)2 Date (java.util.Date)2 PermissionTemplateDto (org.sonar.db.permission.template.PermissionTemplateDto)2 UserDto (org.sonar.db.user.UserDto)2 ProjectRepositories (org.sonar.scanner.protocol.input.ProjectRepositories)2 File (java.io.File)1 IOException (java.io.IOException)1 LinkedHashMap (java.util.LinkedHashMap)1 CeQueueDto (org.sonar.db.ce.CeQueueDto)1 ComponentLinkDto (org.sonar.db.component.ComponentLinkDto)1 IssueDto (org.sonar.db.issue.IssueDto)1 PropertyDto (org.sonar.db.property.PropertyDto)1 RuleDto (org.sonar.db.rule.RuleDto)1 FileData (org.sonar.scanner.protocol.input.FileData)1