Search in sources :

Example 36 with TestResponse

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

the class ComponentActionTest method empty_queue_and_empty_activity.

@Test
public void empty_queue_and_empty_activity() {
    dbTester.components().insertComponent(newProjectDto(dbTester.organizations().insert(), "PROJECT_1"));
    userSession.addComponentUuidPermission(UserRole.USER, "PROJECT_1", "PROJECT_1");
    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(0);
    assertThat(response.hasCurrent()).isFalse();
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) WsCe(org.sonarqube.ws.WsCe) Test(org.junit.Test)

Example 37 with TestResponse

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

the class ComponentActionTest method canceled_tasks_must_not_be_picked_as_current_analysis.

@Test
public void canceled_tasks_must_not_be_picked_as_current_analysis() {
    dbTester.components().insertComponent(newProjectDto(dbTester.getDefaultOrganization(), "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.SUCCESS);
    insertActivity("T4", "PROJECT_1", CeActivityDto.Status.CANCELED);
    insertActivity("T5", "PROJECT_1", CeActivityDto.Status.CANCELED);
    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(0);
    // T3 is the latest task executed on PROJECT_1 ignoring Canceled ones
    assertThat(response.hasCurrent()).isTrue();
    assertThat(response.getCurrent().getId()).isEqualTo("T3");
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) WsCe(org.sonarqube.ws.WsCe) Test(org.junit.Test)

Example 38 with TestResponse

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

the class SubmitActionTest method test_example_json_response.

@Test
public void test_example_json_response() {
    when(reportSubmitter.submit(eq(organizationKey), eq("my_project"), Matchers.isNull(String.class), eq("My Project"), any(InputStream.class))).thenReturn(A_CE_TASK);
    TestResponse wsResponse = tester.newRequest().setParam("projectKey", "my_project").setParam("projectName", "My Project").setParam("report", "{binary}").setMediaType(MediaTypes.JSON).setMethod("POST").execute();
    JsonAssert.assertJson(tester.getDef().responseExampleAsString()).isSimilarTo(wsResponse.getInput());
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 39 with TestResponse

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

the class SubmitActionTest method submit_task_to_the_queue_and_ask_for_immediate_processing.

@Test
public void submit_task_to_the_queue_and_ask_for_immediate_processing() {
    when(reportSubmitter.submit(eq(organizationKey), eq("my_project"), Matchers.isNull(String.class), eq("My Project"), any(InputStream.class))).thenReturn(A_CE_TASK);
    TestResponse wsResponse = tester.newRequest().setParam("projectKey", "my_project").setParam("projectName", "My Project").setParam("report", "{binary}").setMediaType(MediaTypes.PROTOBUF).setMethod("POST").execute();
    verify(reportSubmitter).submit(eq(organizationKey), eq("my_project"), Matchers.isNull(String.class), eq("My Project"), any(InputStream.class));
    WsCe.SubmitResponse submitResponse = Protobuf.read(wsResponse.getInputStream(), WsCe.SubmitResponse.PARSER);
    assertThat(submitResponse.getTaskId()).isEqualTo("TASK_1");
    assertThat(submitResponse.getProjectId()).isEqualTo("PROJECT_1");
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) InputStream(java.io.InputStream) WsCe(org.sonarqube.ws.WsCe) Test(org.junit.Test)

Example 40 with TestResponse

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

the class TaskActionTest method do_not_return_scannerContext_of_activity_with_scannerContext_when_additionalField_is_not_set.

@Test
public void do_not_return_scannerContext_of_activity_with_scannerContext_when_additionalField_is_not_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", "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.hasScannerContext()).isFalse();
}
Also used : 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