@Override protected void configureModule() { add( EmailsWs.class, SendAction.class); } }
@Test public void fail_when_message_param_is_missing() { logInAsSystemAdministrator(); expectedException.expect(IllegalArgumentException.class); executeRequest("john@doo.com", "Test Message from SonarQube", null); }
@Override public void define(Context context) { NewController controller = context.createController("api/emails") .setDescription("Manage emails") .setSince("6.1"); for (EmailsWsAction action : actions) { action.define(controller); } controller.done(); } }
@Override public void handle(Request request, Response response) throws Exception { userSession.checkIsSystemAdministrator(); try { emailNotificationChannel.sendTestEmail(request.mandatoryParam(PARAM_TO), request.param(PARAM_SUBJECT), request.mandatoryParam(PARAM_MESSAGE)); } catch (EmailException emailException) { throw createBadRequestException(emailException); } response.noContent(); }
@Test public void verify_count_of_added_components() { ComponentContainer container = new ComponentContainer(); new EmailsWsModule().configure(container); assertThat(container.size()).isEqualTo(2 + 2); } }
@Test public void fail_when_to_param_is_missing() { logInAsSystemAdministrator(); expectedException.expect(IllegalArgumentException.class); executeRequest(null, "Test Message from SonarQube", "This is a test message from SonarQube at http://localhost:9000"); }
@Override protected void configureModule() { add( EmailsWs.class, SendAction.class); } }
@Override public void define(Context context) { NewController controller = context.createController("api/emails") .setDescription("Manage emails") .setSince("6.1"); for (EmailsWsAction action : actions) { action.define(controller); } controller.done(); } }
@Override public void handle(Request request, Response response) throws Exception { userSession.checkIsSystemAdministrator(); try { emailNotificationChannel.sendTestEmail(request.mandatoryParam(PARAM_TO), request.param(PARAM_SUBJECT), request.mandatoryParam(PARAM_MESSAGE)); } catch (EmailException emailException) { throw createBadRequestException(emailException); } response.noContent(); }
@Test public void does_not_fail_when_subject_param_is_missing() throws Exception { logInAsSystemAdministrator(); executeRequest("john@doo.com", null, "This is a test message from SonarQube at http://localhost:9000"); verify(emailNotificationChannel).sendTestEmail("john@doo.com", null, "This is a test message from SonarQube at http://localhost:9000"); }
@Test public void send_test_email() throws Exception { logInAsSystemAdministrator(); executeRequest("john@doo.com", "Test Message from SonarQube", "This is a test message from SonarQube at http://localhost:9000"); verify(emailNotificationChannel).sendTestEmail("john@doo.com", "Test Message from SonarQube", "This is a test message from SonarQube at http://localhost:9000"); }
@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"); } }