Skip to content

Commit bb38491

Browse files
HDPI-6099: Set gen app reference on generated submission doc entity
1 parent cff9d83 commit bb38491

4 files changed

Lines changed: 70 additions & 11 deletions

File tree

src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/genapp/MakeAnApplication.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import uk.gov.hmcts.reform.pcs.ccd.domain.State;
1717
import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo;
1818
import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.GenAppRequest;
19+
import uk.gov.hmcts.reform.pcs.ccd.entity.DocumentEntity;
1920
import uk.gov.hmcts.reform.pcs.ccd.entity.GenAppEntity;
2021
import uk.gov.hmcts.reform.pcs.ccd.entity.PcsCaseEntity;
2122
import uk.gov.hmcts.reform.pcs.ccd.entity.party.PartyEntity;
@@ -197,7 +198,13 @@ private void createSubmissionDocument(long caseReference,
197198
applicantParty
198199
);
199200

200-
documentImportService.addDocumentToCase(caseReference, documentUrl, CaseFileCategory.APPLICATIONS);
201+
DocumentEntity importedDocumentEntity = documentImportService.addDocumentToCase(
202+
caseReference,
203+
documentUrl,
204+
CaseFileCategory.APPLICATIONS
205+
);
206+
207+
importedDocumentEntity.setGeneralApplication(genAppEntity);
201208
}
202209

203210
@SuppressWarnings("SameParameterValue")

src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/document/DocumentImportService.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public class DocumentImportService {
2323
private final IdamService idamService;
2424
private final AuthTokenGenerator authTokenGenerator;
2525

26-
public void addDocumentToCase(long caseReference,
27-
String documentUrl,
28-
CaseFileCategory caseFileCategory) {
26+
public DocumentEntity addDocumentToCase(long caseReference,
27+
String documentUrl,
28+
CaseFileCategory caseFileCategory) {
2929

3030
String[] urlParts = documentUrl.split("/");
3131
UUID documentId = UUID.fromString(urlParts[urlParts.length - 1]);
@@ -48,6 +48,8 @@ public void addDocumentToCase(long caseReference,
4848

4949
PcsCaseEntity pcsCaseEntity = pcsCaseService.loadCase(caseReference);
5050
pcsCaseEntity.addDocuments(List.of(documentEntity));
51+
52+
return documentEntity;
5153
}
5254

5355
}

src/test/java/uk/gov/hmcts/reform/pcs/ccd/event/genapp/MakeAnApplicationTest.java

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.CitizenGenAppRequest;
2323
import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.GenAppType;
2424
import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.XuiGenAppRequest;
25+
import uk.gov.hmcts.reform.pcs.ccd.entity.DocumentEntity;
2526
import uk.gov.hmcts.reform.pcs.ccd.entity.GenAppEntity;
2627
import uk.gov.hmcts.reform.pcs.ccd.entity.PcsCaseEntity;
2728
import uk.gov.hmcts.reform.pcs.ccd.entity.party.PartyEntity;
@@ -48,7 +49,9 @@
4849
import static org.junit.jupiter.params.provider.Arguments.arguments;
4950
import static org.mockito.ArgumentMatchers.any;
5051
import static org.mockito.ArgumentMatchers.eq;
52+
import static org.mockito.ArgumentMatchers.nullable;
5153
import static org.mockito.BDDMockito.given;
54+
import static org.mockito.Mock.Strictness.LENIENT;
5255
import static org.mockito.Mockito.mock;
5356
import static org.mockito.Mockito.never;
5457
import static org.mockito.Mockito.verify;
@@ -69,7 +72,7 @@ class MakeAnApplicationTest extends BaseEventTest {
6972
private GenAppRepository genAppRepository;
7073
@Mock
7174
private GenAppDocumentGenerator genAppDocumentGenerator;
72-
@Mock
75+
@Mock(strictness = LENIENT)
7376
private DocumentImportService documentImportService;
7477
@Mock
7578
private LegalRepresentativeService legalRepresentativeService;
@@ -221,6 +224,7 @@ class XuiSubmitEventTests {
221224

222225
@BeforeEach
223226
void setUp() {
227+
stubDocumentImport();
224228
given(pcsCaseService.loadCase(TEST_CASE_REFERENCE)).willReturn(pcsCaseEntity);
225229
}
226230

@@ -259,6 +263,7 @@ class CitizenSubmitEventTests {
259263

260264
@BeforeEach
261265
void setUp() {
266+
stubDocumentImport();
262267
given(pcsCaseService.loadCase(TEST_CASE_REFERENCE)).willReturn(pcsCaseEntity);
263268
}
264269

@@ -344,6 +349,37 @@ void shouldGenerateGenAppDocumentAndStoreMetadata() {
344349
);
345350
}
346351

352+
@Test
353+
void shouldSetGenAppReferenceOnImportedDocumentEntity() {
354+
CitizenGenAppRequest genAppRequest = CitizenGenAppRequest.builder()
355+
.applicationType(GenAppType.ADJOURN)
356+
.clientReference("some reference")
357+
.build();
358+
359+
final PCSCase caseData = PCSCase.builder()
360+
.citizenGenAppRequest(genAppRequest)
361+
.build();
362+
363+
PartyEntity applicantParty = stubCurrentUserParty();
364+
365+
GenAppEntity genAppEntity = mock(GenAppEntity.class);
366+
when(genAppService.createGenAppEntity(genAppRequest, pcsCaseEntity, applicantParty))
367+
.thenReturn(genAppEntity);
368+
369+
String documentUrl = "some document URL";
370+
when(genAppDocumentGenerator
371+
.generateSubmissionDocument(TEST_CASE_REFERENCE, genAppRequest, genAppEntity, applicantParty))
372+
.thenReturn(documentUrl);
373+
374+
DocumentEntity importedDocumentEntity = stubDocumentImport();
375+
376+
// When
377+
callSubmitHandler(caseData);
378+
379+
// Then
380+
verify(importedDocumentEntity).setGeneralApplication(genAppEntity);
381+
}
382+
347383
private PartyEntity stubCurrentUserParty() {
348384
PartyEntity currentUserParty = mock(PartyEntity.class);
349385
UUID currentUserId = UUID.randomUUID();
@@ -353,4 +389,12 @@ private PartyEntity stubCurrentUserParty() {
353389
}
354390

355391
}
392+
393+
private DocumentEntity stubDocumentImport() {
394+
DocumentEntity importedDocumentEntity = mock(DocumentEntity.class);
395+
when(documentImportService
396+
.addDocumentToCase(eq(TEST_CASE_REFERENCE), nullable(String.class), any(CaseFileCategory.class)))
397+
.thenReturn(importedDocumentEntity);
398+
return importedDocumentEntity;
399+
}
356400
}

src/test/java/uk/gov/hmcts/reform/pcs/ccd/service/document/DocumentImportServiceTest.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,23 @@ void shouldAddDocumentToCaseWithMetadata() {
7171
when(pcsCaseService.loadCase(CASE_REFERENCE)).thenReturn(pcsCaseEntity);
7272

7373
// When
74-
underTest.addDocumentToCase(CASE_REFERENCE, documentUrl, CaseFileCategory.HEARING_DOCUMENTS);
74+
DocumentEntity returnedDocumentEntity = underTest.addDocumentToCase(
75+
CASE_REFERENCE,
76+
documentUrl,
77+
CaseFileCategory.HEARING_DOCUMENTS
78+
);
7579

7680
// Then
7781
verify(pcsCaseEntity).addDocuments(documentEntityListCaptor.capture());
7882
assertThat(documentEntityListCaptor.getValue()).hasSize(1);
7983

80-
DocumentEntity documentEntity = documentEntityListCaptor.getValue().getFirst();
81-
assertThat(documentEntity.getFileName()).isEqualTo("original filename");
82-
assertThat(documentEntity.getUrl()).isEqualTo("test url");
83-
assertThat(documentEntity.getBinaryUrl()).isEqualTo("test binary url");
84-
assertThat(documentEntity.getCategoryId()).isEqualTo(CaseFileCategory.HEARING_DOCUMENTS.getId());
84+
DocumentEntity addedDocumentEntity = documentEntityListCaptor.getValue().getFirst();
85+
assertThat(addedDocumentEntity.getFileName()).isEqualTo("original filename");
86+
assertThat(addedDocumentEntity.getUrl()).isEqualTo("test url");
87+
assertThat(addedDocumentEntity.getBinaryUrl()).isEqualTo("test binary url");
88+
assertThat(addedDocumentEntity.getCategoryId()).isEqualTo(CaseFileCategory.HEARING_DOCUMENTS.getId());
89+
90+
assertThat(returnedDocumentEntity).isSameAs(addedDocumentEntity);
8591
}
8692

8793
@SuppressWarnings("SameParameterValue")

0 commit comments

Comments
 (0)