Search in sources :

Example 51 with TestResponse

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

the class PingActionTest method returns_pong_as_plain_text.

@Test
public void returns_pong_as_plain_text() {
    TestResponse response = tester.newRequest().execute();
    assertThat(response.getMediaType()).isEqualTo("text/plain");
    assertThat(response.getInput()).isEqualTo("pong");
    assertThat(response.getInput()).isEqualTo(tester.getDef().responseExampleAsString());
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) Test(org.junit.Test)

Example 52 with TestResponse

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

the class InfoActionTest method write_json.

@Test
public void write_json() {
    logInAsSystemAdministrator();
    Map<String, Object> attributes1 = new LinkedHashMap<>();
    attributes1.put("foo", "bar");
    Map<String, Object> attributes2 = new LinkedHashMap<>();
    attributes2.put("one", 1);
    attributes2.put("two", 2);
    when(monitor1.name()).thenReturn("Monitor One");
    when(monitor1.attributes()).thenReturn(attributes1);
    when(monitor2.name()).thenReturn("Monitor Two");
    when(monitor2.attributes()).thenReturn(attributes2);
    when(ceHttpClient.retrieveSystemInfo()).thenReturn(Optional.empty());
    TestResponse response = actionTester.newRequest().execute();
    // response does not contain empty "Monitor Three"
    assertThat(response.getInput()).isEqualTo("{\"Monitor One\":{\"foo\":\"bar\"},\"Monitor Two\":{\"one\":1,\"two\":2}}");
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 53 with TestResponse

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

the class LogsActionTest method return_404_not_found_if_file_does_not_exist.

@Test
public void return_404_not_found_if_file_does_not_exist() throws IOException {
    logInAsSystemAdministrator();
    createLogsDir();
    TestResponse response = actionTester.newRequest().execute();
    assertThat(response.getStatus()).isEqualTo(404);
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) Test(org.junit.Test)

Example 54 with TestResponse

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

the class GhostsActionTest method ghost_projects_without_analyzed_projects.

@Test
public void ghost_projects_without_analyzed_projects() throws Exception {
    OrganizationDto organization = db.organizations().insert();
    ComponentDto ghost1 = insertGhostProject(organization);
    ComponentDto ghost2 = insertGhostProject(organization);
    ComponentDto activeProject = insertActiveProject(organization);
    userSessionRule.logIn().addPermission(ADMINISTER, organization);
    TestResponse result = underTest.newRequest().setParam("organization", organization.getKey()).execute();
    String json = result.getInput();
    assertJson(json).isSimilarTo("{" + "  \"projects\": [" + "    {" + "      \"uuid\": \"" + ghost1.uuid() + "\"," + "      \"key\": \"" + ghost1.key() + "\"," + "      \"name\": \"" + ghost1.name() + "\"" + "    }," + "    {" + "      \"uuid\": \"" + ghost2.uuid() + "\"," + "      \"key\": \"" + ghost2.key() + "\"," + "      \"name\": \"" + ghost2.name() + "\"" + "    }" + "  ]" + "}");
    assertThat(json).doesNotContain(activeProject.uuid());
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 55 with TestResponse

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

the class GhostsActionTest method ghost_projects_base_on_json_example.

@Test
public void ghost_projects_base_on_json_example() throws Exception {
    OrganizationDto organization = db.organizations().insert();
    ComponentDto hBaseProject = ComponentTesting.newProjectDto(organization, "ce4c03d6-430f-40a9-b777-ad877c00aa4d").setKey("org.apache.hbas:hbase").setName("HBase").setCreatedAt(DateUtils.parseDateTime("2015-03-04T23:03:44+0100"));
    dbClient.componentDao().insert(db.getSession(), hBaseProject);
    dbClient.snapshotDao().insert(db.getSession(), SnapshotTesting.newAnalysis(hBaseProject).setStatus(STATUS_UNPROCESSED));
    ComponentDto roslynProject = ComponentTesting.newProjectDto(organization, "c526ef20-131b-4486-9357-063fa64b5079").setKey("com.microsoft.roslyn:roslyn").setName("Roslyn").setCreatedAt(DateUtils.parseDateTime("2013-03-04T23:03:44+0100"));
    dbClient.componentDao().insert(db.getSession(), roslynProject);
    dbClient.snapshotDao().insert(db.getSession(), SnapshotTesting.newAnalysis(roslynProject).setStatus(STATUS_UNPROCESSED));
    db.getSession().commit();
    userSessionRule.logIn().addPermission(ADMINISTER, organization);
    TestResponse result = underTest.newRequest().setParam("organization", organization.getKey()).execute();
    assertJson(result.getInput()).isSimilarTo(Resources.getResource(getClass(), "projects-example-ghosts.json"));
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) 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