-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
997 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,3 +49,4 @@ definitions/**/*.xlsx# | |
|
||
# befta noise | ||
befta_recent_executions_info_PREVIEW.json | ||
/notification_pdfs/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/functionalTest/java/uk/gov/hmcts/reform/sscs/notifications/AbstractNotificationsFT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package uk.gov.hmcts.reform.sscs.notifications; | ||
|
||
import static java.time.LocalTime.now; | ||
import static java.util.Objects.isNull; | ||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.time.LocalTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import junitparams.JUnitParamsRunner; | ||
import lombok.Getter; | ||
import org.apache.commons.io.FileUtils; | ||
import org.junit.runner.RunWith; | ||
import org.slf4j.Logger; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import uk.gov.hmcts.reform.sscs.ccd.domain.SscsCaseData; | ||
import uk.gov.hmcts.reform.sscs.functional.tyanotifications.AbstractFunctionalTest; | ||
import uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType; | ||
import uk.gov.service.notify.Notification; | ||
import uk.gov.service.notify.NotificationClient; | ||
import uk.gov.service.notify.NotificationClientException; | ||
|
||
@RunWith(JUnitParamsRunner.class) | ||
public abstract class AbstractNotificationsFT extends AbstractFunctionalTest { | ||
|
||
private static final Logger log = getLogger(AbstractNotificationsFT.class); | ||
|
||
@Autowired | ||
@Qualifier("testNotificationClient") | ||
@Getter | ||
private NotificationClient client; | ||
|
||
protected SscsCaseData caseData; | ||
|
||
public AbstractNotificationsFT(int maxSecondsToWaitForNotification) { | ||
super(maxSecondsToWaitForNotification); | ||
} | ||
|
||
protected void simulateCcdCallbackToSendLetter(NotificationEventType eventType) throws IOException { | ||
log.info("Simulating CCD callback to send notificaiton of type {}", eventType); | ||
String callbackJsonName = BASE_PATH_TYAN + eventType.getId() + "Callback.json"; | ||
if (isNull(getClass().getClassLoader().getResource(callbackJsonName))) { | ||
callbackJsonName = BASE_PATH_TYAN + "missingFileFallbackCallback.json"; | ||
log.info("No callback json found for {}, using fallback file", eventType); | ||
} | ||
simulateCcdCallback(eventType, callbackJsonName); | ||
log.info("{} notification successfully sent", eventType); | ||
} | ||
|
||
public List<UUID> saveLetterPdfs(List<Notification> notifications, NotificationEventType eventType) { | ||
log.info("Saving notification pdfs for {} notifications triggered by {}", | ||
notifications.size(), eventType); | ||
List<UUID> savedLetters = new ArrayList<>(); | ||
LocalTime startTime = now(); | ||
int maxMinutesToWaitForPdf = 10; | ||
|
||
while (notifications.size() > savedLetters.size() | ||
&& now().isBefore(startTime.plusMinutes(maxMinutesToWaitForPdf))) { | ||
notifications.stream() | ||
.filter(notification -> notification.getNotificationType().equals("letter")) | ||
.filter(notification -> !savedLetters.contains(notification.getId())) | ||
.forEach(notification -> { | ||
try { | ||
final byte[] pdfForLetter = client.getPdfForLetter(String.valueOf(notification.getId())); | ||
var pdfName = "notification_pdfs/" + eventType + "_" + notification.getTemplateId() + ".pdf"; | ||
FileUtils.writeByteArrayToFile(new File(pdfName), pdfForLetter); | ||
savedLetters.add(notification.getId()); | ||
} catch (NotificationClientException | IOException e) { | ||
log.error("Failed to save pdf for template {}", notification.getTemplateId()); | ||
delayInSeconds(60); | ||
} | ||
}); | ||
} | ||
log.info("Finished saving letter pdfs : {} out of {} successfully saved", | ||
notifications.size() - savedLetters.size(), notifications.size()); | ||
return savedLetters; | ||
} | ||
|
||
public void logFailedEventNotification(NotificationEventType notificationType, Exception e) { | ||
log.error("Failed testing notification type {} with the following", notificationType, e); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...unctionalTest/java/uk/gov/hmcts/reform/sscs/notifications/DocmosisGovNotifyLettersFT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package uk.gov.hmcts.reform.sscs.notifications; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static uk.gov.hmcts.reform.sscs.tyanotifications.config.NotificationEventTypeLists.DOCMOSIS_LETTERS; | ||
import static uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType.ACTION_HEARING_RECORDING_REQUEST; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import junitparams.JUnitParamsRunner; | ||
import lombok.SneakyThrows; | ||
import org.junit.Rule; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.rules.Timeout; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.test.context.TestPropertySource; | ||
import uk.gov.hmcts.reform.sscs.tyanotifications.domain.notify.NotificationEventType; | ||
import uk.gov.service.notify.Notification; | ||
import uk.gov.service.notify.NotificationClientException; | ||
|
||
@RunWith(JUnitParamsRunner.class) | ||
@TestPropertySource(locations = "classpath:config/application_functional.properties") | ||
public class DocmosisGovNotifyLettersFT extends AbstractNotificationsFT { | ||
|
||
@Rule | ||
public Timeout globalTimeout = Timeout.seconds(30 * 60); | ||
|
||
@Value("${generate-all-notifications}") | ||
private boolean generateAllNotifications; | ||
|
||
@Value("${notifications-list}") | ||
private Set<NotificationEventType> notificationsList; | ||
|
||
public DocmosisGovNotifyLettersFT() { | ||
super(30); | ||
} | ||
|
||
@BeforeEach | ||
public void setup() { | ||
super.setup(); | ||
} | ||
|
||
@SneakyThrows | ||
@Test | ||
public void shouldSendDocmosisLettersViaGovNotify() { | ||
getNotificationList() | ||
.forEach(notificationEventType -> { | ||
try { | ||
simulateCcdCallbackToSendLetter(notificationEventType); | ||
List<Notification> notifications = fetchLetters(); | ||
saveLetterPdfs(notifications, notificationEventType); | ||
assertThat(notifications) | ||
.extracting(Notification::getSubject) | ||
.allSatisfy(subject -> assertThat(subject).isPresent()); | ||
|
||
} catch (IOException | NotificationClientException e) { | ||
logFailedEventNotification(notificationEventType, e); | ||
} | ||
}); | ||
} | ||
|
||
private Set<NotificationEventType> getNotificationList() { | ||
if (generateAllNotifications) { | ||
return DOCMOSIS_LETTERS.stream() | ||
.filter(eventType -> !eventType.equals(ACTION_HEARING_RECORDING_REQUEST)) | ||
.collect(Collectors.toSet()); | ||
} | ||
return notificationsList; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -707,4 +707,4 @@ | |
}, | ||
"case_details_before": null, | ||
"event_id": "appealCreated" | ||
} | ||
} |
Oops, something went wrong.