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