Search in sources :

Example 11 with TestResponse

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

the class SearchMyOrganizationsActionTest method verify_response_example.

@Test
public void verify_response_example() {
    OrganizationDto organization1 = dbTester.organizations().insertForKey("my-org");
    OrganizationDto organization2 = dbTester.organizations().insertForKey("foo-corp");
    UserDto user = dbTester.users().insertUser();
    dbTester.users().insertPermissionOnUser(organization1, user, SYSTEM_ADMIN);
    dbTester.users().insertPermissionOnUser(organization2, user, SYSTEM_ADMIN);
    userSessionRule.logIn(user);
    TestResponse response = underTest.newRequest().execute();
    assertJson(response.getInput()).isSimilarTo(underTest.getDef().responseExampleAsString());
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) UserDto(org.sonar.db.user.UserDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 12 with TestResponse

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

the class SearchMyOrganizationsActionTest method returns_empty_array_when_user_is_logged_in_and_has_no_permission_on_anything.

@Test
public void returns_empty_array_when_user_is_logged_in_and_has_no_permission_on_anything() {
    userSessionRule.logIn();
    TestResponse response = underTest.newRequest().execute();
    assertJson(response.getInput()).isSimilarTo(NO_ORGANIZATIONS_RESPONSE);
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) Test(org.junit.Test)

Example 13 with TestResponse

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

the class SearchMyOrganizationsActionTest method returns_empty_response_when_user_is_not_logged_in.

@Test
public void returns_empty_response_when_user_is_not_logged_in() {
    TestResponse response = underTest.newRequest().execute();
    assertThat(response.getStatus()).isEqualTo(204);
    assertThat(response.getInput()).isEmpty();
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) Test(org.junit.Test)

Example 14 with TestResponse

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

the class CreateTemplateActionTest method create_full_permission_template.

@Test
public void create_full_permission_template() throws Exception {
    loginAsAdmin(db.getDefaultOrganization());
    TestResponse result = newRequest("Finance", "Permissions for financially related projects", ".*\\.finance\\..*");
    assertJson(result.getInput()).ignoreFields("id").isSimilarTo(getClass().getResource("create_template-example.json"));
    PermissionTemplateDto finance = selectTemplateInDefaultOrganization("Finance");
    assertThat(finance.getName()).isEqualTo("Finance");
    assertThat(finance.getDescription()).isEqualTo("Permissions for financially related projects");
    assertThat(finance.getKeyPattern()).isEqualTo(".*\\.finance\\..*");
    assertThat(finance.getUuid()).isNotEmpty();
    assertThat(finance.getCreatedAt().getTime()).isEqualTo(NOW);
    assertThat(finance.getUpdatedAt().getTime()).isEqualTo(NOW);
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) TestResponse(org.sonar.server.ws.TestResponse) BasePermissionWsTest(org.sonar.server.permission.ws.BasePermissionWsTest) Test(org.junit.Test)

Example 15 with TestResponse

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

the class IndexActionTest method allow_client_to_cache_messages.

@Test
public void allow_client_to_cache_messages() throws Exception {
    Date now = new Date();
    Date aBitLater = new Date(now.getTime() + 1000);
    when(server.getStartedAt()).thenReturn(now);
    TestResponse result = call(null, DateUtils.formatDateTime(aBitLater));
    verifyZeroInteractions(i18n);
    verify(server).getStartedAt();
    assertThat(result.getStatus()).isEqualTo(HttpURLConnection.HTTP_NOT_MODIFIED);
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) Date(java.util.Date) 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