use of uk.gov.hmcts.divorce.document.print.model.Print in project nfdiv-case-api by hmcts.
the class BulkPrintServiceTest method shouldReturnLetterIdForAosPackWithD10DocumentsWhenPrintRequestIsInvoked.
@Test
void shouldReturnLetterIdForAosPackWithD10DocumentsWhenPrintRequestIsInvoked() throws IOException {
List<String> solicitorRoles = List.of("caseworker-divorce", "caseworker-divorce-solicitor");
String solicitorRolesCsv = String.join(",", solicitorRoles);
String userId = UUID.randomUUID().toString();
User solicitorUser = solicitorUser(solicitorRoles, userId);
given(httpServletRequest.getHeader(AUTHORIZATION)).willReturn(APP_1_SOL_AUTH_TOKEN);
given(idamService.retrieveUser(APP_1_SOL_AUTH_TOKEN)).willReturn(solicitorUser);
given(authTokenGenerator.generate()).willReturn(TEST_SERVICE_AUTH_TOKEN);
UUID uuid = UUID.randomUUID();
byte[] firstFile = "data from file 1".getBytes(StandardCharsets.UTF_8);
byte[] d10PdfBytes = bulkPrintService.loadD10PdfBytes("/D10.pdf");
given(sendLetterApi.sendLetter(eq(TEST_SERVICE_AUTH_TOKEN), isA(LetterV3.class))).willReturn(new SendLetterResponse(uuid));
given(resource.getInputStream()).willReturn(new ByteArrayInputStream(firstFile)).willReturn(new ByteArrayInputStream(firstFile));
ListValue<DivorceDocument> divorceDocumentListValue = documentWithType(APPLICATION);
final String documentUuid = FilenameUtils.getName(divorceDocumentListValue.getValue().getDocumentLink().getUrl());
given(documentManagementClient.downloadBinary(APP_1_SOL_AUTH_TOKEN, TEST_SERVICE_AUTH_TOKEN, solicitorRolesCsv, userId, documentUuid)).willReturn(ResponseEntity.ok(resource));
ListValue<DivorceDocument> divorceDocumentListValue2 = documentWithType(APPLICATION);
final String documentUuid2 = FilenameUtils.getName(divorceDocumentListValue2.getValue().getDocumentLink().getUrl());
given(documentManagementClient.downloadBinary(APP_1_SOL_AUTH_TOKEN, TEST_SERVICE_AUTH_TOKEN, solicitorRolesCsv, userId, documentUuid2)).willReturn(ResponseEntity.ok(resource));
List<Letter> letters = List.of(new Letter(divorceDocumentListValue.getValue(), 1), new Letter(divorceDocumentListValue2.getValue(), 2));
Print print = new Print(letters, "1234", "5678", "letterType");
UUID letterId = bulkPrintService.printWithD10Form(print);
assertThat(letterId).isEqualTo(uuid);
verify(sendLetterApi).sendLetter(eq(TEST_SERVICE_AUTH_TOKEN), letterV3ArgumentCaptor.capture());
LetterV3 letterV3 = letterV3ArgumentCaptor.getValue();
assertThat(letterV3.documents).extracting("content", "copies").contains(tuple(Base64.getEncoder().encodeToString(firstFile), 1), tuple(Base64.getEncoder().encodeToString(firstFile), 2), tuple(Base64.getEncoder().encodeToString(d10PdfBytes), 1));
assertThat(letterV3.additionalData).contains(entry(LETTER_TYPE_KEY, "letterType"), entry(CASE_REFERENCE_NUMBER_KEY, "5678"), entry(CASE_IDENTIFIER_KEY, "1234"));
verify(httpServletRequest, times(2)).getHeader(AUTHORIZATION);
verify(idamService, times(2)).retrieveUser(APP_1_SOL_AUTH_TOKEN);
verify(documentManagementClient).downloadBinary(APP_1_SOL_AUTH_TOKEN, TEST_SERVICE_AUTH_TOKEN, solicitorRolesCsv, userId, documentUuid);
verify(authTokenGenerator).generate();
}
use of uk.gov.hmcts.divorce.document.print.model.Print in project nfdiv-case-api by hmcts.
the class BulkPrintServiceTest method shouldThrowDocumentDownloadExceptionWhenDocumentCallFails.
@Test
void shouldThrowDocumentDownloadExceptionWhenDocumentCallFails() throws IOException {
ListValue<DivorceDocument> divorceDocumentListValue = getDivorceDocumentListValue(() -> ResponseEntity.ok(resource));
final String documentUuid = FilenameUtils.getName(divorceDocumentListValue.getValue().getDocumentLink().getUrl());
List<Letter> letters = List.of(new Letter(divorceDocumentListValue.getValue(), 1));
Print print = new Print(letters, "1234", "5678", "letterType");
given(resource.getInputStream()).willThrow(new IOException("Corrupt data"));
assertThatThrownBy(() -> bulkPrintService.print(print)).isInstanceOf(InvalidResourceException.class).hasMessage("Doc name " + documentUuid);
}
use of uk.gov.hmcts.divorce.document.print.model.Print in project nfdiv-case-api by hmcts.
the class BulkPrintServiceTest method shouldReturnLetterIdForAosRespondentPackWithoutD10DocumentsWhenPrintRequestIsInvoked.
@Test
void shouldReturnLetterIdForAosRespondentPackWithoutD10DocumentsWhenPrintRequestIsInvoked() throws IOException {
List<String> solicitorRoles = List.of("caseworker-divorce", "caseworker-divorce-solicitor");
String solicitorRolesCsv = String.join(",", solicitorRoles);
String userId = UUID.randomUUID().toString();
User solicitorUser = solicitorUser(solicitorRoles, userId);
given(httpServletRequest.getHeader(AUTHORIZATION)).willReturn(APP_1_SOL_AUTH_TOKEN);
given(idamService.retrieveUser(APP_1_SOL_AUTH_TOKEN)).willReturn(solicitorUser);
given(authTokenGenerator.generate()).willReturn(TEST_SERVICE_AUTH_TOKEN);
UUID uuid = UUID.randomUUID();
byte[] firstFile = "data from file 1".getBytes(StandardCharsets.UTF_8);
given(sendLetterApi.sendLetter(eq(TEST_SERVICE_AUTH_TOKEN), isA(LetterV3.class))).willReturn(new SendLetterResponse(uuid));
given(resource.getInputStream()).willReturn(new ByteArrayInputStream(firstFile)).willReturn(new ByteArrayInputStream(firstFile));
ListValue<DivorceDocument> divorceDocumentListValue = documentWithType(APPLICATION);
final String documentUuid = FilenameUtils.getName(divorceDocumentListValue.getValue().getDocumentLink().getUrl());
given(documentManagementClient.downloadBinary(APP_1_SOL_AUTH_TOKEN, TEST_SERVICE_AUTH_TOKEN, solicitorRolesCsv, userId, documentUuid)).willReturn(ResponseEntity.ok(resource));
ListValue<DivorceDocument> divorceDocumentListValue2 = documentWithType(APPLICATION);
final String documentUuid2 = FilenameUtils.getName(divorceDocumentListValue2.getValue().getDocumentLink().getUrl());
given(documentManagementClient.downloadBinary(APP_1_SOL_AUTH_TOKEN, TEST_SERVICE_AUTH_TOKEN, solicitorRolesCsv, userId, documentUuid2)).willReturn(ResponseEntity.ok(resource));
List<Letter> letters = List.of(new Letter(divorceDocumentListValue.getValue(), 1), new Letter(divorceDocumentListValue2.getValue(), 2));
Print print = new Print(letters, "1234", "5678", "letterType");
UUID letterId = bulkPrintService.printAosRespondentPack(print, false);
assertThat(letterId).isEqualTo(uuid);
verify(sendLetterApi).sendLetter(eq(TEST_SERVICE_AUTH_TOKEN), letterV3ArgumentCaptor.capture());
LetterV3 letterV3 = letterV3ArgumentCaptor.getValue();
assertThat(letterV3.documents).extracting("content", "copies").contains(tuple(Base64.getEncoder().encodeToString(firstFile), 1), tuple(Base64.getEncoder().encodeToString(firstFile), 2));
assertThat(letterV3.additionalData).contains(entry(LETTER_TYPE_KEY, "letterType"), entry(CASE_REFERENCE_NUMBER_KEY, "5678"), entry(CASE_IDENTIFIER_KEY, "1234"));
verify(httpServletRequest, times(2)).getHeader(AUTHORIZATION);
verify(idamService, times(2)).retrieveUser(APP_1_SOL_AUTH_TOKEN);
verify(documentManagementClient).downloadBinary(APP_1_SOL_AUTH_TOKEN, TEST_SERVICE_AUTH_TOKEN, solicitorRolesCsv, userId, documentUuid);
verify(authTokenGenerator).generate();
}
use of uk.gov.hmcts.divorce.document.print.model.Print in project nfdiv-case-api by hmcts.
the class BulkPrintServiceTest method shouldReturnLetterIdForValidRequestForConfidentialDocuments.
@Test
void shouldReturnLetterIdForValidRequestForConfidentialDocuments() throws IOException {
List<String> solicitorRoles = List.of("caseworker-divorce", "caseworker-divorce-solicitor");
String solicitorRolesCsv = String.join(",", solicitorRoles);
String userId = UUID.randomUUID().toString();
User solicitorUser = solicitorUser(solicitorRoles, userId);
given(httpServletRequest.getHeader(AUTHORIZATION)).willReturn(APP_1_SOL_AUTH_TOKEN);
given(idamService.retrieveUser(APP_1_SOL_AUTH_TOKEN)).willReturn(solicitorUser);
given(authTokenGenerator.generate()).willReturn(TEST_SERVICE_AUTH_TOKEN);
UUID uuid = UUID.randomUUID();
byte[] firstFile = "data from file 1".getBytes(StandardCharsets.UTF_8);
given(sendLetterApi.sendLetter(eq(TEST_SERVICE_AUTH_TOKEN), isA(LetterV3.class))).willReturn(new SendLetterResponse(uuid));
given(resource.getInputStream()).willReturn(new ByteArrayInputStream(firstFile)).willReturn(new ByteArrayInputStream(firstFile));
ListValue<ConfidentialDivorceDocument> divorceDocumentListValue = confidentialDocumentWithType(ConfidentialDocumentsReceived.NOTICE_OF_PROCEEDINGS_APP_1);
final String documentUuid = FilenameUtils.getName(divorceDocumentListValue.getValue().getDocumentLink().getUrl());
given(documentManagementClient.downloadBinary(APP_1_SOL_AUTH_TOKEN, TEST_SERVICE_AUTH_TOKEN, solicitorRolesCsv, userId, documentUuid)).willReturn(ResponseEntity.ok(resource));
List<Letter> letters = List.of(new Letter(divorceDocumentListValue.getValue(), 1));
Print print = new Print(letters, "1234", "5678", "letterType");
UUID letterId = bulkPrintService.print(print);
assertThat(letterId).isEqualTo(uuid);
verify(sendLetterApi).sendLetter(eq(TEST_SERVICE_AUTH_TOKEN), letterV3ArgumentCaptor.capture());
LetterV3 letterV3 = letterV3ArgumentCaptor.getValue();
assertThat(letterV3.documents).extracting("content", "copies").contains(tuple(Base64.getEncoder().encodeToString(firstFile), 1));
assertThat(letterV3.additionalData).contains(entry(LETTER_TYPE_KEY, "letterType"), entry(CASE_REFERENCE_NUMBER_KEY, "5678"), entry(CASE_IDENTIFIER_KEY, "1234"));
verify(httpServletRequest, times(1)).getHeader(AUTHORIZATION);
verify(idamService, times(1)).retrieveUser(APP_1_SOL_AUTH_TOKEN);
verify(documentManagementClient).downloadBinary(APP_1_SOL_AUTH_TOKEN, TEST_SERVICE_AUTH_TOKEN, solicitorRolesCsv, userId, documentUuid);
verify(authTokenGenerator).generate();
}
use of uk.gov.hmcts.divorce.document.print.model.Print in project nfdiv-case-api by hmcts.
the class AosPackPrinter method sendAosLetterToApplicant.
public void sendAosLetterToApplicant(final CaseData caseData, final Long caseId) {
final List<Letter> currentAosLetters = aosLetters(caseData, NOTICE_OF_PROCEEDINGS_APP_1);
if (!isEmpty(currentAosLetters)) {
final String caseIdString = caseId.toString();
final Print print = new Print(currentAosLetters, caseIdString, caseIdString, LETTER_TYPE_APPLICANT_PACK);
final UUID letterId = bulkPrintService.print(print);
log.info("Letter service responded with letter Id {} for case {}", letterId, caseId);
} else {
log.warn("AoS Pack for print applicant has missing documents. Expected documents with type {} , for Case ID: {}", List.of(APPLICATION, NOTICE_OF_PROCEEDINGS_APP_1), caseId);
}
}
Aggregations