Search in sources :

Example 1 with HttpException

use of org.sonar.wsclient.base.HttpException in project sonarqube by SonarSource.

the class IssueSearchTest method search_issues_by_dates.

/**
   * SONAR-2981
   */
@Test
public void search_issues_by_dates() {
    // issues have been created today
    Date today = toDate(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
    Date past = toDate("2013-01-01");
    Date future = toDate("2020-12-31");
    // createdAfter in the future => bad request
    try {
        search(IssueQuery.create().createdAfter(future)).list();
        Fail.fail("Expecting 400 from issues search WS");
    } catch (HttpException exception) {
        assertThat(exception.getMessage()).contains("Start bound cannot be in the future");
    }
    // after date
    assertThat(search(IssueQuery.create().createdAfter(today)).list().size()).isGreaterThan(0);
    assertThat(search(IssueQuery.create().createdAfter(past)).list().size()).isGreaterThan(0);
    // before
    assertThat(search(IssueQuery.create().createdBefore(future)).list().size()).isGreaterThan(0);
    assertThat(search(IssueQuery.create().createdBefore(past)).list()).isEmpty();
    // before and after
    assertThat(search(IssueQuery.create().createdBefore(future).createdAfter(past)).list().size()).isGreaterThan(0);
    // createdAfter > createdBefore => bad request
    try {
        search(IssueQuery.create().createdBefore(past).createdAfter(today)).list();
        Fail.fail("Expecting 400 from issues search WS");
    } catch (HttpException exception) {
        assertThat(exception.getMessage()).contains("Start bound cannot be larger or equal to end bound");
    }
}
Also used : ItUtils.verifyHttpException(util.ItUtils.verifyHttpException) HttpException(org.sonar.wsclient.base.HttpException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ItUtils.toDate(util.ItUtils.toDate) Test(org.junit.Test)

Example 2 with HttpException

use of org.sonar.wsclient.base.HttpException in project sonarqube by SonarSource.

the class RealmAuthenticationTest method verifyHttpException.

private void verifyHttpException(Exception e, int expectedCode) {
    assertThat(e).isInstanceOf(HttpException.class);
    HttpException exception = (HttpException) e;
    assertThat(exception.status()).isEqualTo(expectedCode);
}
Also used : HttpException(org.sonar.wsclient.base.HttpException)

Example 3 with HttpException

use of org.sonar.wsclient.base.HttpException in project sonarqube by SonarSource.

the class ItUtils method verifyHttpException.

public static void verifyHttpException(Exception e, int expectedCode) {
    assertThat(e).isInstanceOf(HttpException.class);
    HttpException exception = (HttpException) e;
    assertThat(exception.status()).isEqualTo(expectedCode);
}
Also used : HttpException(org.sonar.wsclient.base.HttpException)

Aggregations

HttpException (org.sonar.wsclient.base.HttpException)3 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Test (org.junit.Test)1 ItUtils.toDate (util.ItUtils.toDate)1 ItUtils.verifyHttpException (util.ItUtils.verifyHttpException)1