Skip to content

Commit

Permalink
[SELC-5300] Add Test email for enable pec Monitoring (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-putzu authored Jul 18, 2024
1 parent cc18f89 commit bc15c80
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,17 @@ public String createDelegationForAggregation(@DurableActivityTrigger(name = "onb
context.getLogger().info(String.format(FORMAT_LOGGER_ONBOARDING_STRING, CREATE_USERS_ACTIVITY, onboardingString));
return completionService.createDelegation(readOnboardingValue(objectMapper, onboardingString));
}

/**
* This HTTP-triggered function retrieves onboarding given its identifier
* After that, It sends a message on topics through the event bus
*/
@FunctionName("TestSendEmail")
public HttpResponseMessage sendTestEmail(
@HttpTrigger(name = "req", methods = {HttpMethod.POST}, authLevel = AuthorizationLevel.FUNCTION) HttpRequestMessage<Optional<String>> request,
final ExecutionContext context) {
context.getLogger().info("TestSendEmail trigger processed a request");
completionService.sendTestEmail();
return request.createResponseBuilder(HttpStatus.OK).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ public interface CompletionService {
String createDelegation(Onboarding onboarding);

String createAggregateOnboardingRequest(OnboardingAggregateOrchestratorInput onboardingAggregateOrchestratorInput);

void sendTestEmail();
}
Original file line number Diff line number Diff line change
Expand Up @@ -336,4 +336,9 @@ public String createAggregateOnboardingRequest(OnboardingAggregateOrchestratorIn
onboardingRepository.persistOrUpdate(onboardingToUpdate);
return onboardingToUpdate.getId();
}

@Override
public void sendTestEmail() {
notificationService.sendTestEmail();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ public interface NotificationService {

void sendCompletedEmailAggregate(String institutionName, List<String> destinationMails);

void sendTestEmail();
}
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,23 @@ static class FileMailData {
String contentType;
}

@Override
public void sendTestEmail() {
try {
log.info("Sending Test email to {}", senderMail);

String html = "TEST EMAIL";

Mail mail = Mail
.withHtml(senderMail, html, html)
.setFrom(senderMail);

mailer.send(mail);

log.info("End of sending mail to {}, with subject {}", senderMail, mail);
} catch (Exception e) {
log.error(String.format("%s: %s", ERROR_DURING_SEND_MAIL, e.getMessage()));
throw new GenericOnboardingException(ERROR_DURING_SEND_MAIL.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import it.pagopa.selfcare.onboarding.entity.Onboarding;
import it.pagopa.selfcare.onboarding.entity.OnboardingWorkflow;
import it.pagopa.selfcare.onboarding.entity.OnboardingWorkflowInstitution;
import it.pagopa.selfcare.onboarding.entity.OnboardingWorkflowType;

import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -767,4 +767,22 @@ void createDelegationForAggregation() {
verify(completionService, times(1))
.createDelegation(any());
}

@Test
void sendTestEmail() {
@SuppressWarnings("unchecked") final HttpRequestMessage<Optional<String>> req = mock(HttpRequestMessage.class);

doAnswer((Answer<HttpResponseMessage.Builder>) invocation -> {
HttpStatus status = (HttpStatus) invocation.getArguments()[0];
return new HttpResponseMessageMock.HttpResponseMessageBuilderMock().status(status);
}).when(req).createResponseBuilder(any(HttpStatus.class));

when(executionContext.getLogger()).thenReturn(Logger.getGlobal());
doNothing().when(completionService).sendTestEmail();

function.sendTestEmail(req, executionContext);

verify(completionService, times(1))
.sendTestEmail();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,15 @@ public static Onboarding createSampleOnboarding() {
return onboarding;
}

@Test
void sendTestEmail() {
doNothing().when(notificationService).sendTestEmail();

completionServiceDefault.sendTestEmail();

Mockito.verify(notificationService, times(1))
.sendTestEmail();
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ app_settings = {
"MAIL_SERVER_PASSWORD" = "@Microsoft.KeyVault(SecretUri=https://selc-d-kv.vault.azure.net/secrets/smtp-psw/)",
"MAIL_SERVER_HOST" = "smtps.pec.aruba.it",
"MAIL_SERVER_PORT" = "465",
"MAIL_SERVER_SSL" = "false"
"MAIL_TEMPLATE_REGISTRATION_NOTIFICATION_ADMIN_PATH" = "contracts/template/mail/registration-notification-admin/1.0.0.json",
"MAIL_TEMPLATE_NOTIFICATION_PATH" = "contracts/template/mail/onboarding-notification/1.0.0.json",
"ADDRESS_EMAIL_NOTIFICATION_ADMIN" = "@Microsoft.KeyVault(SecretUri=https://selc-d-kv.vault.azure.net/secrets/portal-admin-operator-email/)",
Expand Down

0 comments on commit bc15c80

Please sign in to comment.