Search in sources :

Example 41 with TestResponse

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

the class TaskActionTest method task_is_archived.

@Test
public void task_is_archived() throws Exception {
    logInAsRoot();
    CeActivityDto activityDto = createActivityDto(SOME_TASK_UUID);
    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.getOrganization()).isEqualTo(organizationDto.getKey());
    assertThat(task.getId()).isEqualTo(SOME_TASK_UUID);
    assertThat(task.getStatus()).isEqualTo(WsCe.TaskStatus.FAILED);
    assertThat(task.getComponentId()).isEqualTo(project.uuid());
    assertThat(task.getComponentKey()).isEqualTo(project.key());
    assertThat(task.getComponentName()).isEqualTo(project.name());
    assertThat(task.getAnalysisId()).isEqualTo(activityDto.getAnalysisUuid());
    assertThat(task.getExecutionTimeMs()).isEqualTo(500L);
    assertThat(task.getLogs()).isFalse();
}
Also used : CeActivityDto(org.sonar.db.ce.CeActivityDto) TestResponse(org.sonar.server.ws.TestResponse) WsCe(org.sonarqube.ws.WsCe) Test(org.junit.Test)

Example 42 with TestResponse

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

the class ProjectActionTest method do_not_fail_when_a_path_is_null.

/**
   * SONAR-7084
   */
@Test
public void do_not_fail_when_a_path_is_null() throws Exception {
    String projectKey = "org.codehaus.sonar:sonar";
    ProjectRepositories projectRepositories = new ProjectRepositories().addFileData("module-1", null, new FileData(null, null));
    when(projectDataLoader.load(any(ProjectDataQuery.class))).thenReturn(projectRepositories);
    TestResponse result = ws.newRequest().setMediaType(MediaTypes.PROTOBUF).setParam("key", projectKey).setParam("profile", "Default").execute();
    WsProjectResponse wsProjectResponse = WsProjectResponse.parseFrom(result.getInputStream());
    assertThat(wsProjectResponse.getFileDataByModuleAndPath()).isEmpty();
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) WsProjectResponse(org.sonarqube.ws.WsBatch.WsProjectResponse) FileData(org.sonar.scanner.protocol.input.FileData) ProjectRepositories(org.sonar.scanner.protocol.input.ProjectRepositories) Test(org.junit.Test)

Example 43 with TestResponse

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

the class TaskActionTest method return_scannerContext_of_activity_with_scannerContext_when_additionalField_is_set.

@Test
public void return_scannerContext_of_activity_with_scannerContext_when_additionalField_is_set() {
    logInAsRoot();
    String scannerContext = "this is some scanner context, yeah!";
    persist(createActivityDto(SOME_TASK_UUID));
    persistScannerContext(SOME_TASK_UUID, scannerContext);
    TestResponse wsResponse = ws.newRequest().setMediaType(PROTOBUF).setParam("id", SOME_TASK_UUID).setParam("additionalFields", "scannerContext").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.getScannerContext()).isEqualTo(scannerContext);
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) WsCe(org.sonarqube.ws.WsCe) Test(org.junit.Test)

Example 44 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_without_stacktrace.

@Test
public void do_not_return_stacktrace_of_failed_activity_without_stacktrace() {
    logInAsRoot();
    CeActivityDto activityDto = createActivityDto(SOME_TASK_UUID).setErrorMessage("error msg");
    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)

Example 45 with TestResponse

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

the class AddActionTest method add_a_project.

@Test
public void add_a_project() {
    ComponentDto project = insertProjectAndPermissions();
    TestResponse result = call(PROJECT_KEY);
    assertThat(result.getStatus()).isEqualTo(HTTP_NO_CONTENT);
    List<PropertyDto> favorites = dbClient.propertiesDao().selectByQuery(PropertyQuery.builder().setUserId(USER_ID).setKey("favourite").build(), dbSession);
    assertThat(favorites).hasSize(1);
    PropertyDto favorite = favorites.get(0);
    assertThat(favorite).extracting(PropertyDto::getResourceId, PropertyDto::getUserId, PropertyDto::getKey).containsOnly(project.getId(), USER_ID, "favourite");
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) ComponentDto(org.sonar.db.component.ComponentDto) PropertyDto(org.sonar.db.property.PropertyDto) 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