Search in sources :

Example 6 with TestResponse

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

the class TaskActionTest method task_is_in_queue.

@Test
public void task_is_in_queue() throws Exception {
    logInAsRoot();
    CeQueueDto queueDto = new CeQueueDto();
    queueDto.setTaskType(CeTaskTypes.REPORT);
    queueDto.setUuid(SOME_TASK_UUID);
    queueDto.setComponentUuid(project.uuid());
    queueDto.setStatus(CeQueueDto.Status.PENDING);
    queueDto.setSubmitterLogin("john");
    persist(queueDto);
    TestResponse wsResponse = ws.newRequest().setMediaType(PROTOBUF).setParam("id", SOME_TASK_UUID).execute();
    WsCe.TaskResponse taskResponse = Protobuf.read(wsResponse.getInputStream(), WsCe.TaskResponse.PARSER);
    assertThat(taskResponse.getTask().getOrganization()).isEqualTo(organizationDto.getKey());
    assertThat(taskResponse.getTask().getId()).isEqualTo(SOME_TASK_UUID);
    assertThat(taskResponse.getTask().getStatus()).isEqualTo(WsCe.TaskStatus.PENDING);
    assertThat(taskResponse.getTask().getSubmitterLogin()).isEqualTo("john");
    assertThat(taskResponse.getTask().getComponentId()).isEqualTo(project.uuid());
    assertThat(taskResponse.getTask().getComponentKey()).isEqualTo(project.key());
    assertThat(taskResponse.getTask().getComponentName()).isEqualTo(project.name());
    assertThat(taskResponse.getTask().hasExecutionTimeMs()).isFalse();
    assertThat(taskResponse.getTask().getLogs()).isFalse();
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) WsCe(org.sonarqube.ws.WsCe) CeQueueDto(org.sonar.db.ce.CeQueueDto) Test(org.junit.Test)

Example 7 with TestResponse

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

the class ActivityActionTest method support_json_response.

@Test
public void support_json_response() {
    logInAsSystemAdministrator();
    TestResponse wsResponse = ws.newRequest().setMediaType(MediaTypes.JSON).execute();
    JsonAssert.assertJson(wsResponse.getInput()).isSimilarTo("{\"tasks\":[]}");
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) Test(org.junit.Test)

Example 8 with TestResponse

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

the class TaskActionTest method call.

private void call(String taskUuid) {
    TestResponse response = ws.newRequest().setMediaType(PROTOBUF).setParam("id", taskUuid).execute();
    WsCe.TaskResponse taskResponse = Protobuf.read(response.getInputStream(), WsCe.TaskResponse.parser());
    WsCe.Task task = taskResponse.getTask();
    assertThat(task.getId()).isEqualTo(taskUuid);
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) WsCe(org.sonarqube.ws.WsCe)

Example 9 with TestResponse

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

the class RemoveActionTest method remove_a_favorite_project.

@Test
public void remove_a_favorite_project() {
    ComponentDto project = insertProjectAndPermissions();
    ComponentDto file = db.components().insertComponent(newFileDto(project));
    db.favorites().add(project, USER_ID);
    db.favorites().add(file, USER_ID);
    TestResponse result = call(PROJECT_KEY);
    assertThat(result.getStatus()).isEqualTo(HTTP_NO_CONTENT);
    assertThat(db.favorites().hasFavorite(project, USER_ID)).isFalse();
    assertThat(db.favorites().hasFavorite(file, USER_ID)).isTrue();
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 10 with TestResponse

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

the class SearchActionComponentsMediumTest method do_not_return_module_key_on_single_module_projects.

@Test
public void do_not_return_module_key_on_single_module_projects() throws IOException {
    ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "P1").setKey("PK1"));
    setDefaultProjectPermission(project);
    ComponentDto module = insertComponent(newModuleDto("M1", project).setKey("MK1"));
    ComponentDto file = insertComponent(newFileDto(module, null, "F1").setKey("FK1"));
    RuleDto newRule = newRule();
    IssueDto issueInModule = IssueTesting.newDto(newRule, file, project).setKee("ISSUE_IN_MODULE");
    IssueDto issueInRootModule = IssueTesting.newDto(newRule, project, project).setKee("ISSUE_IN_ROOT_MODULE");
    db.issueDao().insert(session, issueInModule, issueInRootModule);
    session.commit();
    indexIssues();
    WsActionTester actionTester = new WsActionTester(tester.get(SearchAction.class));
    TestResponse response = actionTester.newRequest().setMediaType(MediaTypes.PROTOBUF).execute();
    SearchWsResponse searchResponse = SearchWsResponse.parseFrom(response.getInputStream());
    assertThat(searchResponse.getIssuesCount()).isEqualTo(2);
    for (Issues.Issue issue : searchResponse.getIssuesList()) {
        assertThat(issue.getProject()).isEqualTo("PK1");
        if (issue.getKey().equals("ISSUE_IN_MODULE")) {
            assertThat(issue.getSubProject()).isEqualTo("MK1");
        } else if (issue.getKey().equals("ISSUE_IN_ROOT_MODULE")) {
            assertThat(issue.hasSubProject()).isFalse();
        }
    }
}
Also used : RuleDto(org.sonar.db.rule.RuleDto) TestResponse(org.sonar.server.ws.TestResponse) Issues(org.sonarqube.ws.Issues) ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto) SearchWsResponse(org.sonarqube.ws.Issues.SearchWsResponse) WsActionTester(org.sonar.server.ws.WsActionTester) 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