Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
Release/version 1.2 (#46)
Browse files Browse the repository at this point in the history
* VACCINECER-1013: changed pdf file name to only have uvci with _ instead of :. Removed unused id on bean

* VACCINECER-1013: refactored pdf naming

* VACCINECER-1014: fixed index bug

Co-authored-by: Nicola Keller <[email protected]>
  • Loading branch information
NicolaKellerTIM and Nicola Keller authored Jun 18, 2021
1 parent 07b00c7 commit b02ba39
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private boolean areCreateCertificateRequestsValid(List<CertificateCreateDto> cre
CertificateCsvBean csvBean = csvBeans.get(i);
if (createDto != null && csvBean.getError() == null) {
try {
validate(createDto, i);
validate(createDto);
} catch (CreateCertificateException e) {
hasError = true;
csvBean.setError(e.getError().toString());
Expand All @@ -180,23 +180,23 @@ private boolean areCreateCertificateRequestsValid(List<CertificateCreateDto> cre
return !hasError;
}

private void validate(CertificateCreateDto createDto, int index) {
private void validate(CertificateCreateDto createDto) {
createDto.validate();
if (createDto instanceof RecoveryCertificateCreateDto) {
RecoveryCertificateDataDto dataDto = ((RecoveryCertificateCreateDto) createDto).getRecoveryInfo().get(index);
RecoveryCertificateDataDto dataDto = ((RecoveryCertificateCreateDto) createDto).getRecoveryInfo().get(0);
CountryCode countryCode = valueSetsService.getCountryCode(dataDto.getCountryOfTest(), createDto.getLanguage());
if (countryCode == null) {
throw new CreateCertificateException(INVALID_COUNTRY_OF_TEST);
}
} else if (createDto instanceof TestCertificateCreateDto) {
TestCertificateDataDto dataDto = ((TestCertificateCreateDto) createDto).getTestInfo().get(index);
TestCertificateDataDto dataDto = ((TestCertificateCreateDto) createDto).getTestInfo().get(0);
CountryCode countryCode = valueSetsService.getCountryCode(dataDto.getMemberStateOfTest(), createDto.getLanguage());
if (countryCode == null) {
throw new CreateCertificateException(INVALID_COUNTRY_OF_TEST);
}
valueSetsService.getTestValueSet(dataDto);
} else if (createDto instanceof VaccinationCertificateCreateDto) {
VaccinationCertificateDataDto dataDto = ((VaccinationCertificateCreateDto) createDto).getVaccinationInfo().get(index);
VaccinationCertificateDataDto dataDto = ((VaccinationCertificateCreateDto) createDto).getVaccinationInfo().get(0);
CountryCode countryCode = valueSetsService.getCountryCode(dataDto.getCountryOfVaccination(), createDto.getLanguage());
if (countryCode == null) {
throw new CreateCertificateException(INVALID_COUNTRY_OF_TEST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@ public class CsvServiceTest {
private final File validVaccinationFile;
private final File emptyCsv;
private final File invalidCsv;
private final File invalidMultipleCsv;
private final File validMultipleCsv;

public CsvServiceTest() {
validRecoveryFile = new File("src/test/resources/csv/recovery_csv_valid.csv");
validTestFile = new File("src/test/resources/csv/test_csv_valid.csv");
validVaccinationFile = new File("src/test/resources/csv/vaccination_csv_valid.csv");
emptyCsv = new File("src/test/resources/csv/recovery_csv_empty.csv");
invalidCsv = new File("src/test/resources/csv/recovery_csv_invalid.csv");
invalidMultipleCsv = new File("src/test/resources/csv/vaccination_csv_multiple_invalid.csv");
validMultipleCsv = new File("src/test/resources/csv/vaccination_csv_multiple_valid.csv");
}

@BeforeEach
Expand Down Expand Up @@ -99,6 +103,16 @@ public void testInvalidCsv() throws Exception {
assertEquals(INVALID_CREATE_REQUESTS.getErrorCode(), exception.getError().getErrorCode());
}

@Test
public void testMultipleInvalidCsv() throws Exception {
var file = Mockito.mock(MultipartFile.class);
var inputStream = new FileInputStream(invalidMultipleCsv);
when(file.getInputStream()).thenReturn(inputStream);
var exception = assertThrows(CsvException.class,
() -> service.handleCsvRequest(file, CertificateType.vaccination.name()));
assertEquals(INVALID_CREATE_REQUESTS.getErrorCode(), exception.getError().getErrorCode());
}

@Nested
class GenerateRecoveryCertificateCsv {
@Test
Expand Down Expand Up @@ -142,5 +156,15 @@ void successful() throws IOException {
inputStream.close();
}

@Test
void successfulMultiple() throws IOException {
var file = Mockito.mock(MultipartFile.class);
var inputStream = new FileInputStream(validMultipleCsv);
when(file.getInputStream()).thenReturn(inputStream);

CsvResponseDto response = service.handleCsvRequest(file, CertificateType.vaccination.name());
assertNotNull(response.getZip());
inputStream.close();
}
}
}
5 changes: 5 additions & 0 deletions src/test/resources/csv/vaccination_csv_multiple_invalid.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
givenName,familyName,dateOfBirth,language,streetAndNr,zipCode,city,cantonCodeSender,medicinalProductCode,numberOfDoses,totalNumberOfDoses,vaccinationDate,countryOfVaccination
Max,Muster,1985-09-20,de,MusterStrasse 1,1234,Bern,BE,EU/1/20/1507,2,2,2021-05-28,CH
Max,TooLongdklsfjsodfjlksdjflkdsjflksjflkdsjflksdjlfkjd,1985-09-20,de,MusterStrasse 1,1234,Bern,BE,EU/1/20/1507,2,2,2021-05-28,CH
TooLongdklsfjsodfjlksdjflkdsjflksjflkdsjflksdjlfkjd,Muster,1985-09-20,de,MusterStrasse 1,1234,Bern,BE,EU/1/20/1507,2,2,2021-05-28,CH
Max,Muster,2085-09-20,de,MusterStrasse 1,1234,Bern,BE,EU/1/20/1507,2,2,2021-05-28,CH
5 changes: 5 additions & 0 deletions src/test/resources/csv/vaccination_csv_multiple_valid.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
givenName,familyName,dateOfBirth,language,streetAndNr,zipCode,city,cantonCodeSender,medicinalProductCode,numberOfDoses,totalNumberOfDoses,vaccinationDate,countryOfVaccination
Max,Muster,1985-09-20,de,MusterStrasse 1,1234,Bern,BE,EU/1/20/1507,2,2,2021-05-28,CH
Max,Muster,1985-09-20,de,MusterStrasse 1,1234,Bern,BE,EU/1/20/1507,2,2,2021-05-28,CH
Max,Muster,1985-09-20,de,MusterStrasse 1,1234,Bern,BE,EU/1/20/1507,2,2,2021-05-28,CH
Max,Muster,2000-09-20,de,MusterStrasse 1,1234,Bern,BE,EU/1/20/1507,2,2,2021-05-28,CH

0 comments on commit b02ba39

Please sign in to comment.