Search in sources :

Example 1 with SendEmailResponse

use of com.hack23.cia.service.api.action.admin.SendEmailResponse in project cia by Hack23.

the class SendEmailServiceITest method sendEmailSuccessTest.

/**
 * Test.
 *
 * @throws Exception
 *             the exception
 */
@Test
public void sendEmailSuccessTest() throws Exception {
    final CreateApplicationSessionRequest createSessionRequest = createTestApplicationSession();
    final SendEmailRequest serviceRequest = new SendEmailRequest();
    serviceRequest.setSessionId(createSessionRequest.getSessionId());
    serviceRequest.setEmail("info@hack23.com");
    serviceRequest.setSubject("Test Email SendEmailServiceITest");
    serviceRequest.setContent("Test content");
    final SendEmailResponse response = (SendEmailResponse) applicationManager.service(serviceRequest);
    assertNotNull(EXPECT_A_RESULT, response);
    final List<SmtpMessage> emails = dumbster.getReceivedEmails();
    assertEquals(1, emails.size());
    final SmtpMessage email = emails.get(0);
    assertEquals(email.getHeaderValue("Subject"), serviceRequest.getSubject());
    assertEquals(email.getBody(), serviceRequest.getContent());
    assertEquals(email.getHeaderValue("To"), serviceRequest.getEmail());
}
Also used : SendEmailResponse(com.hack23.cia.service.api.action.admin.SendEmailResponse) CreateApplicationSessionRequest(com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest) SmtpMessage(com.dumbster.smtp.SmtpMessage) SendEmailRequest(com.hack23.cia.service.api.action.admin.SendEmailRequest) Test(org.junit.Test) AbstractServiceFunctionalIntegrationTest(com.hack23.cia.service.impl.AbstractServiceFunctionalIntegrationTest)

Example 2 with SendEmailResponse

use of com.hack23.cia.service.api.action.admin.SendEmailResponse in project cia by Hack23.

the class SendEmailService method processService.

@Override
@Secured({ "ROLE_ADMIN" })
public SendEmailResponse processService(final SendEmailRequest serviceRequest) {
    final SendEmailResponse inputValidation = inputValidation(serviceRequest);
    if (inputValidation != null) {
        return inputValidation;
    }
    final CreateApplicationEventRequest eventRequest = createApplicationEventForService(serviceRequest);
    final UserAccount userAccount = getUserAccountFromSecurityContext();
    if (userAccount != null) {
        LOGGER.info("{} started:{}", serviceRequest.getClass().getSimpleName(), userAccount.getEmail());
        eventRequest.setUserId(userAccount.getUserId());
    }
    SendEmailResponse response;
    if (isValidEmailAddress(serviceRequest.getEmail())) {
        emailService.sendEmail(serviceRequest.getEmail(), serviceRequest.getSubject(), serviceRequest.getContent());
        response = new SendEmailResponse(ServiceResult.SUCCESS);
    } else {
        response = new SendEmailResponse(ServiceResult.FAILURE);
        response.setErrorMessage(EMAIL_IS_NOT_A_VALID_EMAIL_ADDRESS);
    }
    eventRequest.setApplicationMessage(response.getResult().toString());
    createApplicationEventService.processService(eventRequest);
    return response;
}
Also used : SendEmailResponse(com.hack23.cia.service.api.action.admin.SendEmailResponse) CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount) Secured(org.springframework.security.access.annotation.Secured)

Example 3 with SendEmailResponse

use of com.hack23.cia.service.api.action.admin.SendEmailResponse in project cia by Hack23.

the class SendEmailServiceITest method sendEmailInvalidEmailFailureTest.

/**
 * Send email invalid email failure test.
 *
 * @throws Exception
 *             the exception
 */
@Test
public void sendEmailInvalidEmailFailureTest() throws Exception {
    final CreateApplicationSessionRequest createSessionRequest = createTestApplicationSession();
    final SendEmailRequest serviceRequest = new SendEmailRequest();
    serviceRequest.setSessionId(createSessionRequest.getSessionId());
    serviceRequest.setEmail("novalidemail$###hack23.com");
    serviceRequest.setSubject("Test Email SendEmailServiceITest");
    serviceRequest.setContent("Test content");
    final SendEmailResponse response = (SendEmailResponse) applicationManager.service(serviceRequest);
    assertNotNull(EXPECT_A_RESULT, response);
    assertEquals(ServiceResult.FAILURE, response.getResult());
    assertEquals("email must be a well-formed email address", response.getErrorMessage());
}
Also used : SendEmailResponse(com.hack23.cia.service.api.action.admin.SendEmailResponse) CreateApplicationSessionRequest(com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest) SendEmailRequest(com.hack23.cia.service.api.action.admin.SendEmailRequest) Test(org.junit.Test) AbstractServiceFunctionalIntegrationTest(com.hack23.cia.service.impl.AbstractServiceFunctionalIntegrationTest)

Aggregations

SendEmailResponse (com.hack23.cia.service.api.action.admin.SendEmailResponse)3 SendEmailRequest (com.hack23.cia.service.api.action.admin.SendEmailRequest)2 CreateApplicationSessionRequest (com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest)2 AbstractServiceFunctionalIntegrationTest (com.hack23.cia.service.impl.AbstractServiceFunctionalIntegrationTest)2 Test (org.junit.Test)2 SmtpMessage (com.dumbster.smtp.SmtpMessage)1 UserAccount (com.hack23.cia.model.internal.application.user.impl.UserAccount)1 CreateApplicationEventRequest (com.hack23.cia.service.api.action.application.CreateApplicationEventRequest)1 Secured (org.springframework.security.access.annotation.Secured)1