Skip to content

Commit

Permalink
[PPANTT-215] resolve sonar issue
Browse files Browse the repository at this point in the history
  • Loading branch information
gioelemella committed Dec 4, 2024
1 parent 01871fe commit f514932
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ private Context buildEmailHtmlBodyContext(String bundleName, String pspName) {
Map<String, Object> properties = new HashMap<>();
properties.put("bundleName", bundleName);
properties.put("environment", getEnvParam());

if (pspName != null) {
properties.put("pspName", pspName);
}
properties.put("pspName", pspName);

context.setVariables(properties);
return context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,17 +642,14 @@ public byte[] exportPSPBundleList(String pspTaxCode, List<BundleType> bundleType
return this.exportService.exportPSPBundlesToCsv(pspCode, bundleTypeList);
}

private Context buildEmailHtmlBodyContext(String bundleName, String pspName) {
private Context buildEmailHtmlBodyContext(String bundleName) {
// Thymeleaf Context
Context context = new Context();

// Properties to show up in Template after stored in Context
Map<String, Object> properties = new HashMap<>();
properties.put("bundleName", bundleName);
properties.put("environment", getEnvParam());
if (pspName != null) {
properties.put("pspName", pspName);
}

context.setVariables(properties);
return context;
Expand All @@ -665,10 +662,6 @@ private String getEnvParam() {
return String.format(".%s", this.environment.toLowerCase());
}

private Context buildEmailHtmlBodyContext(String bundleName) {
return buildEmailHtmlBodyContext(bundleName, null);
}

private List<CISubscriptionInfo> buildCISubscriptionInfoList(
List<CreditorInstitutionInfo> ciInfoList,
BundleCreditorInstitutionResource acceptedSubscription
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class AwsSesClientTest {
@Test
void sendEmailPRODSuccess() {
ReflectionTestUtils.setField(sut, "enableSendEmail", true);
ReflectionTestUtils.setField(sut, "environment", "PROD");

Institutions institutions = buildInstitutions();
List<InstitutionProductUsers> institutionProductUsers = buildInstitutionProductUsers();
Expand All @@ -69,6 +70,7 @@ void sendEmailPRODSuccess() {
@Test
void sendEmailNotPRODSuccess() {
ReflectionTestUtils.setField(sut, "enableSendEmail", false);
ReflectionTestUtils.setField(sut, "environment", "UAT");

when(templateEngine.process(anyString(), any())).thenReturn("html template");
when(sesClient.sendEmail(any(SendEmailRequest.class))).thenReturn(SendEmailResponse.builder().build());
Expand All @@ -87,6 +89,7 @@ void sendEmailNotPRODSuccess() {
@Test
void sendEmailPRODFail() {
ReflectionTestUtils.setField(sut, "enableSendEmail", true);
ReflectionTestUtils.setField(sut, "environment", "PROD");

Institutions institutions = buildInstitutions();
List<InstitutionProductUsers> institutionProductUsers = buildInstitutionProductUsers();
Expand All @@ -108,6 +111,7 @@ void sendEmailPRODFail() {
void sendEmailPRODNoInstitutionTaxCodeSkipped() {
ReflectionTestUtils.setField(sut, "enableSendEmail", true);
ReflectionTestUtils.setField(sut, "testEmailAddress", "[email protected]");
ReflectionTestUtils.setField(sut, "environment", "PROD");

assertDoesNotThrow(() -> sut.sendEmail(buildEmailMessageDetail(null)));

Expand All @@ -125,6 +129,7 @@ void sendEmailPRODNoInstitutionTaxCodeSkipped() {
@Test
void sendEmailNoInstitutionFoundSkipped() {
ReflectionTestUtils.setField(sut, "enableSendEmail", true);
ReflectionTestUtils.setField(sut, "environment", "PROD");

when(externalApiClient.getInstitutionsFiltered(INSTITUTION_TAX_CODE))
.thenReturn(Institutions.builder().institutions(Collections.emptyList()).build());
Expand All @@ -144,6 +149,7 @@ void sendEmailNoInstitutionFoundSkipped() {
@Test
void sendEmailNoDestinationSkipped() {
ReflectionTestUtils.setField(sut, "enableSendEmail", true);
ReflectionTestUtils.setField(sut, "environment", "PROD");

Institutions institutions = buildInstitutions();

Expand All @@ -165,6 +171,7 @@ void sendEmailNoDestinationSkipped() {
void sendEmailNotPRODAndNoTestEmailSkipped() {
ReflectionTestUtils.setField(sut, "enableSendEmail", false);
ReflectionTestUtils.setField(sut, "testEmailAddress", null);
ReflectionTestUtils.setField(sut, "environment", "UAT");

assertDoesNotThrow(() -> sut.sendEmail(buildEmailMessageDetail(INSTITUTION_TAX_CODE)));

Expand All @@ -182,6 +189,7 @@ void sendEmailNotPRODAndNoTestEmailSkipped() {
@Test
void sendEmailPRODSWithPagopaOperatorSuccess() {
ReflectionTestUtils.setField(sut, "enableSendEmail", true);
ReflectionTestUtils.setField(sut, "environment", "PROD");

Institutions institutions = buildInstitutions();
List<InstitutionProductUsers> institutionProductUsers = buildInstitutionProductUsers();
Expand Down

0 comments on commit f514932

Please sign in to comment.