|
22 | 22 | import static java.util.Collections.emptyList;
|
23 | 23 | import static java.util.Collections.singletonList;
|
24 | 24 | import static org.assertj.core.api.Assertions.assertThat;
|
| 25 | +import static org.assertj.core.api.AssertionsForClassTypes.tuple; |
25 | 26 | import static uk.gov.hmcts.reform.bulkscanprocessor.model.common.Classification.EXCEPTION;
|
26 | 27 | import static uk.gov.hmcts.reform.bulkscanprocessor.model.common.Event.DOC_FAILURE;
|
| 28 | +import static uk.gov.hmcts.reform.bulkscanprocessor.model.common.Event.DOC_SIGNATURE_FAILURE; |
27 | 29 | import static uk.gov.hmcts.reform.bulkscanprocessor.model.common.Event.FILE_VALIDATION_FAILURE;
|
28 | 30 | import static uk.gov.hmcts.reform.bulkscanprocessor.model.common.Event.ZIPFILE_PROCESSING_STARTED;
|
29 | 31 |
|
@@ -160,6 +162,87 @@ void should_return_single_result_by_date_if_envelope_exists_with_multiple_failur
|
160 | 162 | );
|
161 | 163 | }
|
162 | 164 |
|
| 165 | + @Test |
| 166 | + public void should_return_rejected_zip_files_with_matching_name() { |
| 167 | + Instant eventDate = Instant.parse("2019-02-15T14:15:23.456Z"); |
| 168 | + |
| 169 | + dbHasEvents( |
| 170 | + event("c2", "test2.zip", eventDate, DOC_FAILURE), |
| 171 | + event("c2", "test2.zip", eventDate, FILE_VALIDATION_FAILURE), |
| 172 | + event("c2", "test2.zip", eventDate, DOC_SIGNATURE_FAILURE), |
| 173 | + event("c2", "test3.zip", eventDate, FILE_VALIDATION_FAILURE) |
| 174 | + ); |
| 175 | + |
| 176 | + Envelope existingEnvelope |
| 177 | + = envelope("c2", "test2.zip", Status.COMPLETED, EXCEPTION, "ccd-id-1", "ccd-action-1", "test5"); |
| 178 | + dbHasEnvelope(existingEnvelope); |
| 179 | + dbHasEnvelope(envelope("c3", "test3.zip", Status.COMPLETED, EXCEPTION, "ccd-id-1", "ccd-action-1", null)); |
| 180 | + |
| 181 | + List<RejectedZipFile> result = reportRepo.getRejectedZipFilesReportFor("test2.zip"); |
| 182 | + |
| 183 | + assertThat(result) |
| 184 | + .hasSize(3) |
| 185 | + .extracting("zipFileName", "event") |
| 186 | + .contains(tuple("test2.zip", "DOC_FAILURE"), |
| 187 | + tuple("test2.zip", "FILE_VALIDATION_FAILURE"), |
| 188 | + tuple("test2.zip", "DOC_SIGNATURE_FAILURE")) |
| 189 | + .doesNotContain(tuple("test3.zip", "FILE_VALIDATION_FAILURE")); |
| 190 | + } |
| 191 | + |
| 192 | + @Test |
| 193 | + public void should_group_rejected_zip_files_with_matching_name_if_same_event_same_day() { |
| 194 | + Instant eventDate = Instant.parse("2019-02-15T14:15:23.456Z"); |
| 195 | + Instant eventDate2 = Instant.parse("2019-02-16T14:15:23.456Z"); |
| 196 | + dbHasEvents( |
| 197 | + event("c2", "test2.zip", eventDate, FILE_VALIDATION_FAILURE), |
| 198 | + event("c2", "test2.zip", eventDate, FILE_VALIDATION_FAILURE), |
| 199 | + event("c2", "test2.zip", eventDate2, FILE_VALIDATION_FAILURE), |
| 200 | + event("c2", "test2.zip", eventDate2, FILE_VALIDATION_FAILURE) |
| 201 | + ); |
| 202 | + |
| 203 | + Envelope existingEnvelope |
| 204 | + = envelope("c2", "test2.zip", Status.COMPLETED, EXCEPTION, "ccd-id-1", "ccd-action-1", "test5"); |
| 205 | + dbHasEnvelope(existingEnvelope); |
| 206 | + dbHasEnvelope(envelope("c3", "test3.zip", Status.COMPLETED, EXCEPTION, "ccd-id-1", "ccd-action-1", null)); |
| 207 | + |
| 208 | + List<RejectedZipFile> result = reportRepo.getRejectedZipFilesReportFor("test2.zip"); |
| 209 | + |
| 210 | + assertThat(result) |
| 211 | + .hasSize(2) |
| 212 | + .extracting("zipFileName", "event") |
| 213 | + .contains(tuple("test2.zip", "FILE_VALIDATION_FAILURE"), tuple("test2.zip", "FILE_VALIDATION_FAILURE")); |
| 214 | + } |
| 215 | + |
| 216 | + @Test |
| 217 | + public void should_not_return_rejected_zip_files_with_matching_name_if_not_failure_event() { |
| 218 | + Instant eventDate = Instant.parse("2019-02-15T14:15:23.456Z"); |
| 219 | + dbHasEvents( |
| 220 | + event("c2", "test2.zip", eventDate, ZIPFILE_PROCESSING_STARTED) |
| 221 | + ); |
| 222 | + Envelope existingEnvelope |
| 223 | + = envelope("c2", "test2.zip", Status.COMPLETED, EXCEPTION, "ccd-id-1", "ccd-action-1", "test5"); |
| 224 | + dbHasEnvelope(existingEnvelope); |
| 225 | + |
| 226 | + List<RejectedZipFile> result = reportRepo.getRejectedZipFilesReportFor("test2.zip"); |
| 227 | + |
| 228 | + assertThat(result).isEmpty(); |
| 229 | + } |
| 230 | + |
| 231 | + @Test |
| 232 | + public void should_not_return_rejected_zip_files_if_no_event_with_matching_name() { |
| 233 | + Instant eventDate = Instant.parse("2019-02-15T14:15:23.456Z"); |
| 234 | + dbHasEvents( |
| 235 | + event("c2", "test2.zip", eventDate, FILE_VALIDATION_FAILURE) |
| 236 | + ); |
| 237 | + Envelope existingEnvelope |
| 238 | + = envelope("c2", "test2.zip", Status.COMPLETED, EXCEPTION, "ccd-id-1", "ccd-action-1", "test5"); |
| 239 | + dbHasEnvelope(existingEnvelope); |
| 240 | + |
| 241 | + List<RejectedZipFile> result = reportRepo.getRejectedZipFilesReportFor("test22.zip"); |
| 242 | + |
| 243 | + assertThat(result).isEmpty(); |
| 244 | + } |
| 245 | + |
163 | 246 | private void dbHasEvents(ProcessEvent... events) {
|
164 | 247 | eventRepo.saveAll(asList(events));
|
165 | 248 | }
|
|
0 commit comments