Search in sources :

Example 6 with BadRequestException

use of org.sonar.server.exceptions.BadRequestException in project sonarqube by SonarSource.

the class SendActionTest method fail_with_BadRequestException_when_EmailException_is_generated.

@Test
public void fail_with_BadRequestException_when_EmailException_is_generated() throws Exception {
    logInAsSystemAdministrator();
    IllegalArgumentException exception1 = new IllegalArgumentException("root cause");
    IllegalArgumentException exception2 = new IllegalArgumentException("parent cause", exception1);
    IllegalArgumentException exception3 = new IllegalArgumentException("child cause", exception2);
    EmailException emailException = new EmailException("last message", exception3);
    doThrow(emailException).when(emailNotificationChannel).sendTestEmail(anyString(), anyString(), anyString());
    try {
        executeRequest("john@doo.com", "Test Message from SonarQube", "This is a test message from SonarQube at http://localhost:9000");
        fail();
    } catch (BadRequestException e) {
        assertThat(e.errors()).containsExactly("root cause", "parent cause", "child cause", "last message");
    }
}
Also used : EmailException(org.apache.commons.mail.EmailException) BadRequestException(org.sonar.server.exceptions.BadRequestException) Test(org.junit.Test)

Example 7 with BadRequestException

use of org.sonar.server.exceptions.BadRequestException in project sonarqube by SonarSource.

the class RuleActivatorMediumTest method deactivation_fails_if_profile_not_found.

@Test
public void deactivation_fails_if_profile_not_found() {
    ActiveRuleKey key = ActiveRuleKey.of("unknown", XOO_X1);
    try {
        ruleActivator.deactivate(key);
        fail();
    } catch (BadRequestException e) {
        assertThat(e).hasMessage("Quality profile not found: unknown");
    }
}
Also used : BadRequestException(org.sonar.server.exceptions.BadRequestException) ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) Test(org.junit.Test)

Example 8 with BadRequestException

use of org.sonar.server.exceptions.BadRequestException in project sonarqube by SonarSource.

the class QProfileFactoryMediumTest method fail_if_blank_renaming.

@Test
public void fail_if_blank_renaming() {
    QualityProfileDto dto = factory.create(dbSession, new QProfileName("xoo", "P1"));
    dbSession.commit();
    dbSession.clearCache();
    String key = dto.getKey();
    try {
        factory.rename(key, " ");
        fail();
    } catch (BadRequestException e) {
        assertThat(e).hasMessage("Name must be set");
    }
}
Also used : BadRequestException(org.sonar.server.exceptions.BadRequestException) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 9 with BadRequestException

use of org.sonar.server.exceptions.BadRequestException in project sonarqube by SonarSource.

the class QProfileFactoryMediumTest method fail_renaming_if_name_already_exists.

@Test
public void fail_renaming_if_name_already_exists() {
    QualityProfileDto p1 = factory.create(dbSession, new QProfileName("xoo", "P1"));
    QualityProfileDto p2 = factory.create(dbSession, new QProfileName("xoo", "P2"));
    dbSession.commit();
    dbSession.clearCache();
    try {
        factory.rename(p1.getKey(), "P2");
        fail();
    } catch (BadRequestException e) {
        assertThat(e).hasMessage("Quality profile already exists: P2");
    }
}
Also used : BadRequestException(org.sonar.server.exceptions.BadRequestException) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 10 with BadRequestException

use of org.sonar.server.exceptions.BadRequestException in project sonarqube by SonarSource.

the class RuleCreatorMediumTest method create_custom_rule_with_invalid_parameters.

@Test
public void create_custom_rule_with_invalid_parameters() {
    // insert template rule
    RuleDto templateRule = createTemplateRuleWithTwoIntParams();
    // Create custom rule
    NewCustomRule newRule = NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()).setName("My custom").setMarkdownDescription("Some description").setSeverity(Severity.MAJOR).setStatus(RuleStatus.READY).setParameters(ImmutableMap.of("first", "polop", "second", "palap"));
    try {
        creator.create(newRule);
        Fail.failBecauseExceptionWasNotThrown(BadRequestException.class);
    } catch (BadRequestException badRequest) {
        assertThat(badRequest.errors().toString()).contains("palap").contains("polop");
    }
    dbSession.clearCache();
}
Also used : RuleDto(org.sonar.db.rule.RuleDto) BadRequestException(org.sonar.server.exceptions.BadRequestException) Test(org.junit.Test)

Aggregations

BadRequestException (org.sonar.server.exceptions.BadRequestException)16 Test (org.junit.Test)11 ActiveRuleKey (org.sonar.db.qualityprofile.ActiveRuleKey)5 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)4 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)4 RuleDto (org.sonar.db.rule.RuleDto)4 ArrayList (java.util.ArrayList)3 RuleKey (org.sonar.api.rule.RuleKey)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 DbSession (org.sonar.db.DbSession)2 EmailException (org.apache.commons.mail.EmailException)1 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)1 ComponentDto (org.sonar.db.component.ComponentDto)1 OrganizationDto (org.sonar.db.organization.OrganizationDto)1 RuleParamDto (org.sonar.db.rule.RuleParamDto)1 WsTester (org.sonar.server.ws.WsTester)1