Search in sources :

Example 1 with Letter

use of uk.gov.hmcts.divorce.document.print.model.Letter 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();
}
Also used : User(uk.gov.hmcts.reform.idam.client.models.User) SendLetterResponse(uk.gov.hmcts.reform.sendletter.api.SendLetterResponse) LetterV3(uk.gov.hmcts.reform.sendletter.api.model.v3.LetterV3) Letter(uk.gov.hmcts.divorce.document.print.model.Letter) DivorceDocument(uk.gov.hmcts.divorce.document.model.DivorceDocument) ConfidentialDivorceDocument(uk.gov.hmcts.divorce.document.model.ConfidentialDivorceDocument) Print(uk.gov.hmcts.divorce.document.print.model.Print) ByteArrayInputStream(java.io.ByteArrayInputStream) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 2 with Letter

use of uk.gov.hmcts.divorce.document.print.model.Letter 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);
}
Also used : Letter(uk.gov.hmcts.divorce.document.print.model.Letter) InvalidResourceException(uk.gov.hmcts.divorce.document.print.exception.InvalidResourceException) DivorceDocument(uk.gov.hmcts.divorce.document.model.DivorceDocument) ConfidentialDivorceDocument(uk.gov.hmcts.divorce.document.model.ConfidentialDivorceDocument) Print(uk.gov.hmcts.divorce.document.print.model.Print) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 3 with Letter

use of uk.gov.hmcts.divorce.document.print.model.Letter 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();
}
Also used : User(uk.gov.hmcts.reform.idam.client.models.User) SendLetterResponse(uk.gov.hmcts.reform.sendletter.api.SendLetterResponse) LetterV3(uk.gov.hmcts.reform.sendletter.api.model.v3.LetterV3) Letter(uk.gov.hmcts.divorce.document.print.model.Letter) DivorceDocument(uk.gov.hmcts.divorce.document.model.DivorceDocument) ConfidentialDivorceDocument(uk.gov.hmcts.divorce.document.model.ConfidentialDivorceDocument) Print(uk.gov.hmcts.divorce.document.print.model.Print) ByteArrayInputStream(java.io.ByteArrayInputStream) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 4 with Letter

use of uk.gov.hmcts.divorce.document.print.model.Letter 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();
}
Also used : User(uk.gov.hmcts.reform.idam.client.models.User) SendLetterResponse(uk.gov.hmcts.reform.sendletter.api.SendLetterResponse) LetterV3(uk.gov.hmcts.reform.sendletter.api.model.v3.LetterV3) Letter(uk.gov.hmcts.divorce.document.print.model.Letter) Print(uk.gov.hmcts.divorce.document.print.model.Print) ConfidentialDivorceDocument(uk.gov.hmcts.divorce.document.model.ConfidentialDivorceDocument) ByteArrayInputStream(java.io.ByteArrayInputStream) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 5 with Letter

use of uk.gov.hmcts.divorce.document.print.model.Letter 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);
    }
}
Also used : Letter(uk.gov.hmcts.divorce.document.print.model.Letter) Print(uk.gov.hmcts.divorce.document.print.model.Print) UUID(java.util.UUID)

Aggregations

Letter (uk.gov.hmcts.divorce.document.print.model.Letter)18 Print (uk.gov.hmcts.divorce.document.print.model.Print)15 UUID (java.util.UUID)11 Test (org.junit.jupiter.api.Test)9 ConfidentialDivorceDocument (uk.gov.hmcts.divorce.document.model.ConfidentialDivorceDocument)9 DivorceDocument (uk.gov.hmcts.divorce.document.model.DivorceDocument)8 LetterV3 (uk.gov.hmcts.reform.sendletter.api.model.v3.LetterV3)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 InvalidResourceException (uk.gov.hmcts.divorce.document.print.exception.InvalidResourceException)5 User (uk.gov.hmcts.reform.idam.client.models.User)5 SendLetterResponse (uk.gov.hmcts.reform.sendletter.api.SendLetterResponse)5 ArrayList (java.util.ArrayList)4 IOException (java.io.IOException)2 Base64.getEncoder (java.util.Base64.getEncoder)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors.toList (java.util.stream.Collectors.toList)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Slf4j (lombok.extern.slf4j.Slf4j)1