From e1a3ede668f2d53096ae9fe50b36eee525b6b73c Mon Sep 17 00:00:00 2001 From: Daniil Palagin Date: Sat, 20 Jul 2024 18:22:56 +0200 Subject: [PATCH] [kbss-cvut/record-manager-ui#184] Fixed importRecordsJsonImportsSpecifiedRecordsAndReturnsImportResult importRecordsJsonReturnsConflictWhenServiceThrowsRecordAuthorNotFound --- .../rest/PatientRecordControllerTest.java | 33 +++++-------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/src/test/java/cz/cvut/kbss/study/rest/PatientRecordControllerTest.java b/src/test/java/cz/cvut/kbss/study/rest/PatientRecordControllerTest.java index 61a6537c..286dacdb 100644 --- a/src/test/java/cz/cvut/kbss/study/rest/PatientRecordControllerTest.java +++ b/src/test/java/cz/cvut/kbss/study/rest/PatientRecordControllerTest.java @@ -305,25 +305,6 @@ void exportRecordsExportsRecordsForProvidedInstitutionForSpecifiedPeriod() throw Pageable.unpaged()); } -// @Test -// void importRecordsJsonImportsSpecifiedRecordsAndReturnsImportResult() throws Exception { -// final List records = -// List.of(Generator.generatePatientRecord(user), Generator.generatePatientRecord(user)); -// final RecordImportResult importResult = new RecordImportResult(records.size()); -// importResult.setImportedCount(records.size()); -// when(patientRecordServiceMock.importRecords(anyList())).thenReturn(importResult); -// -// final MvcResult mvcResult = mockMvc.perform( -// post("/records/import/json").content(toJson(records)).contentType(MediaType.MULTIPART_FORM_DATA_VALUE)).andReturn(); -// final RecordImportResult result = readValue(mvcResult, RecordImportResult.class); -// assertEquals(importResult.getTotalCount(), result.getTotalCount()); -// assertEquals(importResult.getImportedCount(), result.getImportedCount()); -// assertThat(importResult.getErrors(), anyOf(nullValue(), empty())); -// @SuppressWarnings("unchecked") -// final ArgumentCaptor> captor = ArgumentCaptor.forClass(List.class); -// verify(patientRecordServiceMock).importRecords(captor.capture()); -// assertEquals(records.size(), captor.getValue().size()); -// } @Test void importRecordsJsonImportsSpecifiedRecordsAndReturnsImportResult() throws Exception { @@ -337,9 +318,6 @@ void importRecordsJsonImportsSpecifiedRecordsAndReturnsImportResult() throws Exc MockMultipartFile file = new MockMultipartFile("file", "records.json", MediaType.MULTIPART_FORM_DATA_VALUE, toJson(records).getBytes()); - String jsonContent = new String(file.getBytes()); - System.out.println("Received JSON content: " + jsonContent); - final MvcResult mvcResult = mockMvc.perform( multipart("/records/import/json") .file(file) @@ -356,6 +334,7 @@ void importRecordsJsonImportsSpecifiedRecordsAndReturnsImportResult() throws Exc @SuppressWarnings("unchecked") final ArgumentCaptor> captor = ArgumentCaptor.forClass(List.class); + verify(patientRecordServiceMock).importRecords(captor.capture()); assertEquals(records.size(), captor.getValue().size()); } @@ -388,8 +367,14 @@ void importRecordsJsonReturnsConflictWhenServiceThrowsRecordAuthorNotFound() thr List.of(Generator.generatePatientRecord(user), Generator.generatePatientRecord(user)); when(patientRecordServiceMock.importRecords(anyList())).thenThrow(RecordAuthorNotFoundException.class); - mockMvc.perform(post("/records/import/json").content(toJson(records)).contentType(MediaType.MULTIPART_FORM_DATA_VALUE)) - .andExpect(status().isConflict()); + MockMultipartFile file = new MockMultipartFile("file", "records.json", + MediaType.MULTIPART_FORM_DATA_VALUE, toJson(records).getBytes()); + + mockMvc.perform( + multipart("/records/import/json") + .file(file) + .contentType(MediaType.MULTIPART_FORM_DATA_VALUE) + ).andExpect(status().isConflict()); } @Test