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");
}
}
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");
}
}
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");
}
}
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");
}
}
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();
}
Aggregations