From b9a17296dd216cecae72cb040ae9b963791af5ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20L=C3=B6sing?= Date: Tue, 6 Sep 2022 18:35:47 +0200 Subject: [PATCH 1/7] Added missing test AntibodyCertificatePdfGenerateRequestDto. --- ...ficatePdfGenerateRequestDtoMapperTest.java | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/test/java/ch/admin/bag/covidcertificate/api/mapper/pdfgeneration/AntibodyCertificatePdfGenerateRequestDtoMapperTest.java diff --git a/src/test/java/ch/admin/bag/covidcertificate/api/mapper/pdfgeneration/AntibodyCertificatePdfGenerateRequestDtoMapperTest.java b/src/test/java/ch/admin/bag/covidcertificate/api/mapper/pdfgeneration/AntibodyCertificatePdfGenerateRequestDtoMapperTest.java new file mode 100644 index 00000000..64e91f13 --- /dev/null +++ b/src/test/java/ch/admin/bag/covidcertificate/api/mapper/pdfgeneration/AntibodyCertificatePdfGenerateRequestDtoMapperTest.java @@ -0,0 +1,112 @@ +package ch.admin.bag.covidcertificate.api.mapper.pdfgeneration; + +import ch.admin.bag.covidcertificate.api.request.pdfgeneration.AntibodyCertificatePdfGenerateRequestDto; +import ch.admin.bag.covidcertificate.service.domain.AntibodyCertificatePdf; +import ch.admin.bag.covidcertificate.service.domain.CovidCertificateDiseaseOrAgentTargeted; +import com.flextrade.jfixture.JFixture; +import org.junit.Test; + +import java.time.ZoneId; + +import static ch.admin.bag.covidcertificate.api.Constants.ANTIBODY_CERTIFICATE_VALIDITY_IN_DAYS; +import static ch.admin.bag.covidcertificate.api.Constants.ISSUER; +import static ch.admin.bag.covidcertificate.api.Constants.RECOVERY_CERTIFICATE_VALIDITY_IN_DAYS; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class AntibodyCertificatePdfGenerateRequestDtoMapperTest { + + private final JFixture fixture = new JFixture(); + private final String countryOfTest = "Schweiz"; + private final String countryOfTestEn = "Switzerland"; + + @Test + public void mapsFamilyName() { + AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class); + AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(incoming, countryOfTest, countryOfTestEn); + assertEquals(incoming.getDecodedCert().getPersonData().getName().getFamilyName(), actual.getFamilyName()); + } + + @Test + public void mapsGivenName() { + AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class); + AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(incoming, countryOfTest, countryOfTestEn); + assertEquals(incoming.getDecodedCert().getPersonData().getName().getGivenName(), actual.getGivenName()); + } + + @Test + public void mapsDateOfBirth() { + AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class); + AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(incoming, countryOfTest, countryOfTestEn); + assertEquals(incoming.getDecodedCert().getPersonData().getDateOfBirth(), actual.getDateOfBirth()); + } + + @Test + public void mapsLanguage() { + AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class); + AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(incoming, countryOfTest, countryOfTestEn); + assertEquals(incoming.getLanguage(), actual.getLanguage()); + } + + @Test + public void mapsDiseaseOrAgentTargetedCode() { + AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class); + AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(incoming, countryOfTest, countryOfTestEn); + assertEquals(CovidCertificateDiseaseOrAgentTargeted.getStandardInstance().getCode(), actual.getDiseaseOrAgentTargetedCode()); + } + + @Test + public void mapsDiseaseOrAgentTargetedSystem() { + AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class); + AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(incoming, countryOfTest, countryOfTestEn); + assertEquals(CovidCertificateDiseaseOrAgentTargeted.getStandardInstance().getSystem(), actual.getDiseaseOrAgentTargetedSystem()); + } + + @Test + public void mapsDateOfFirstPositiveTestResult() { + AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class); + AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(incoming, countryOfTest, countryOfTestEn); + assertEquals(incoming.getDecodedCert().getAntibodyInfo().get(0).getSampleDateTime(), actual.getSampleDate().atStartOfDay(ZoneId.systemDefault())); + } + + @Test + public void mapsCountryOfTest() { + AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class); + AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(incoming, countryOfTest, countryOfTestEn); + assertEquals(countryOfTest, actual.getCountryOfTest()); + } + + @Test + public void mapsCountryOfTestEn() { + AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class); + AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(incoming, countryOfTest, countryOfTestEn); + assertEquals(countryOfTestEn, actual.getCountryOfTestEn()); + } + + @Test + public void mapsIssuer() { + AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class); + AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(incoming, countryOfTest, countryOfTestEn); + assertEquals(ISSUER, actual.getIssuer()); + } + + @Test + public void mapsValidFrom() { + AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class); + AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(incoming, countryOfTest, countryOfTestEn); + assertEquals(incoming.getDecodedCert().getAntibodyInfo().get(0).getSampleDateTime().plusDays(ANTIBODY_CERTIFICATE_VALIDITY_IN_DAYS), actual.getSampleDate().atStartOfDay(ZoneId.systemDefault())); + } + + @Test + public void mapsValidUntil() { + AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class); + AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(incoming, countryOfTest, countryOfTestEn); + assertEquals(incoming.getDecodedCert().getAntibodyInfo().get(0).getSampleDateTime().plusDays(RECOVERY_CERTIFICATE_VALIDITY_IN_DAYS), actual.getSampleDate().atStartOfDay(ZoneId.systemDefault())); + } + + @Test + public void mapsUvci() { + AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class); + AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(incoming, countryOfTest, countryOfTestEn); + assertEquals(incoming.getDecodedCert().getAntibodyInfo().get(0).getIdentifier(), actual.getIdentifier()); + } +} From 24c3609782a73b4e740721cda828209b28b5f8df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20L=C3=B6sing?= Date: Wed, 7 Sep 2022 13:32:16 +0200 Subject: [PATCH 2/7] Corrected missing test for AntibodyCertificatePdfGenerateRequestDto. --- ...ficatePdfGenerateRequestDtoMapperTest.java | 63 +++++++++---------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/src/test/java/ch/admin/bag/covidcertificate/api/mapper/pdfgeneration/AntibodyCertificatePdfGenerateRequestDtoMapperTest.java b/src/test/java/ch/admin/bag/covidcertificate/api/mapper/pdfgeneration/AntibodyCertificatePdfGenerateRequestDtoMapperTest.java index 64e91f13..95757389 100644 --- a/src/test/java/ch/admin/bag/covidcertificate/api/mapper/pdfgeneration/AntibodyCertificatePdfGenerateRequestDtoMapperTest.java +++ b/src/test/java/ch/admin/bag/covidcertificate/api/mapper/pdfgeneration/AntibodyCertificatePdfGenerateRequestDtoMapperTest.java @@ -6,11 +6,7 @@ import com.flextrade.jfixture.JFixture; import org.junit.Test; -import java.time.ZoneId; - -import static ch.admin.bag.covidcertificate.api.Constants.ANTIBODY_CERTIFICATE_VALIDITY_IN_DAYS; import static ch.admin.bag.covidcertificate.api.Constants.ISSUER; -import static ch.admin.bag.covidcertificate.api.Constants.RECOVERY_CERTIFICATE_VALIDITY_IN_DAYS; import static org.junit.jupiter.api.Assertions.assertEquals; public class AntibodyCertificatePdfGenerateRequestDtoMapperTest { @@ -22,91 +18,94 @@ public class AntibodyCertificatePdfGenerateRequestDtoMapperTest { @Test public void mapsFamilyName() { AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class); - AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(incoming, countryOfTest, countryOfTestEn); + AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf( + incoming, countryOfTest, countryOfTestEn); assertEquals(incoming.getDecodedCert().getPersonData().getName().getFamilyName(), actual.getFamilyName()); } @Test public void mapsGivenName() { AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class); - AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(incoming, countryOfTest, countryOfTestEn); + AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf( + incoming, countryOfTest, countryOfTestEn); assertEquals(incoming.getDecodedCert().getPersonData().getName().getGivenName(), actual.getGivenName()); } @Test public void mapsDateOfBirth() { AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class); - AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(incoming, countryOfTest, countryOfTestEn); + AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf( + incoming, countryOfTest, countryOfTestEn); assertEquals(incoming.getDecodedCert().getPersonData().getDateOfBirth(), actual.getDateOfBirth()); } @Test public void mapsLanguage() { AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class); - AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(incoming, countryOfTest, countryOfTestEn); + AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf( + incoming, countryOfTest, countryOfTestEn); assertEquals(incoming.getLanguage(), actual.getLanguage()); } @Test public void mapsDiseaseOrAgentTargetedCode() { AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class); - AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(incoming, countryOfTest, countryOfTestEn); - assertEquals(CovidCertificateDiseaseOrAgentTargeted.getStandardInstance().getCode(), actual.getDiseaseOrAgentTargetedCode()); + AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf( + incoming, countryOfTest, countryOfTestEn); + assertEquals( + CovidCertificateDiseaseOrAgentTargeted.getStandardInstance().getCode(), + actual.getDiseaseOrAgentTargetedCode()); } @Test public void mapsDiseaseOrAgentTargetedSystem() { AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class); - AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(incoming, countryOfTest, countryOfTestEn); - assertEquals(CovidCertificateDiseaseOrAgentTargeted.getStandardInstance().getSystem(), actual.getDiseaseOrAgentTargetedSystem()); + AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf( + incoming, countryOfTest, countryOfTestEn); + assertEquals( + CovidCertificateDiseaseOrAgentTargeted.getStandardInstance().getSystem(), + actual.getDiseaseOrAgentTargetedSystem()); } @Test public void mapsDateOfFirstPositiveTestResult() { AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class); - AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(incoming, countryOfTest, countryOfTestEn); - assertEquals(incoming.getDecodedCert().getAntibodyInfo().get(0).getSampleDateTime(), actual.getSampleDate().atStartOfDay(ZoneId.systemDefault())); + AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf( + incoming, countryOfTest, countryOfTestEn); + assertEquals( + incoming.getDecodedCert().getAntibodyInfo().get(0).getSampleDateTime().toLocalDate(), + actual.getSampleDate()); } @Test public void mapsCountryOfTest() { AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class); - AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(incoming, countryOfTest, countryOfTestEn); + AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf( + incoming, countryOfTest, countryOfTestEn); assertEquals(countryOfTest, actual.getCountryOfTest()); } @Test public void mapsCountryOfTestEn() { AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class); - AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(incoming, countryOfTest, countryOfTestEn); + AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf( + incoming, countryOfTest, countryOfTestEn); assertEquals(countryOfTestEn, actual.getCountryOfTestEn()); } @Test public void mapsIssuer() { AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class); - AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(incoming, countryOfTest, countryOfTestEn); + AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf( + incoming, countryOfTest, countryOfTestEn); assertEquals(ISSUER, actual.getIssuer()); } - @Test - public void mapsValidFrom() { - AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class); - AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(incoming, countryOfTest, countryOfTestEn); - assertEquals(incoming.getDecodedCert().getAntibodyInfo().get(0).getSampleDateTime().plusDays(ANTIBODY_CERTIFICATE_VALIDITY_IN_DAYS), actual.getSampleDate().atStartOfDay(ZoneId.systemDefault())); - } - - @Test - public void mapsValidUntil() { - AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class); - AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(incoming, countryOfTest, countryOfTestEn); - assertEquals(incoming.getDecodedCert().getAntibodyInfo().get(0).getSampleDateTime().plusDays(RECOVERY_CERTIFICATE_VALIDITY_IN_DAYS), actual.getSampleDate().atStartOfDay(ZoneId.systemDefault())); - } - @Test public void mapsUvci() { AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class); - AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(incoming, countryOfTest, countryOfTestEn); + AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf( + incoming, countryOfTest, countryOfTestEn); assertEquals(incoming.getDecodedCert().getAntibodyInfo().get(0).getIdentifier(), actual.getIdentifier()); } } From 5b291a51505b007b2f4d26ecf25d33ced0e770af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20L=C3=B6sing?= Date: Wed, 7 Sep 2022 14:57:03 +0200 Subject: [PATCH 3/7] Corrected transactional internal call and excluded TestCovidCertificateGenerationService from sonar in pom. --- pom.xml | 2 +- .../covidcertificate/service/RevocationService.java | 11 +++++++---- .../test/TestCovidCertificateGenerationService.java | 9 ++++++++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 2a3f2a87..892b72eb 100644 --- a/pom.xml +++ b/pom.xml @@ -50,7 +50,7 @@ **/*Dto.java - **/*Dto.java,**/config/*,**/*Exception.java,**/*Constants.java,**/*Registry.java,**/*Config.java,**/*Mock*,**/*Application.java,**/*HttpResponseHeaderFilter.java,**/*ActuatorSecurity.java + **/*Dto.java,**/config/*,**/*Exception.java,**/*Constants.java,**/*Registry.java,**/*Config.java,**/*Mock*,**/*Application.java,**/*HttpResponseHeaderFilter.java,**/*ActuatorSecurity.java,**/TestCovidCertificateGenerationService,java admin-ch_CovidCertificate-Management-Service diff --git a/src/main/java/ch/admin/bag/covidcertificate/service/RevocationService.java b/src/main/java/ch/admin/bag/covidcertificate/service/RevocationService.java index 98d293d4..322e8c55 100644 --- a/src/main/java/ch/admin/bag/covidcertificate/service/RevocationService.java +++ b/src/main/java/ch/admin/bag/covidcertificate/service/RevocationService.java @@ -44,6 +44,10 @@ public class RevocationService { @Transactional public void createRevocation(String uvci, boolean fraud) { + this.createRevocationInternal(uvci, fraud); + } + + private void createRevocationInternal(String uvci, boolean fraud) { try { if (revocationRepository.findByUvci(uvci) != null) { log.info("Revocation for {} already exists.", uvci); @@ -59,6 +63,7 @@ public void createRevocation(String uvci, boolean fraud) { } } + @Transactional public RevocationListResponseDto performMassRevocation(RevocationListDto revocationListDto) { Map uvcisToErrorMessage = getUvcisWithErrorMessage( revocationListDto.getUvcis() @@ -70,7 +75,7 @@ public RevocationListResponseDto performMassRevocation(RevocationListDto revocat // revoke uvci if there are no error messages if (uvcisToErrorMessage.get(uvciForRevocation.getUvci()) == null) { try { - createRevocation(uvciForRevocation.getUvci(), uvciForRevocation.getFraud()); + createRevocationInternal(uvciForRevocation.getUvci(), uvciForRevocation.getFraud()); kpiLogService.logRevocationKpi( KPI_REVOKE_CERTIFICATE_SYSTEM_KEY, KPI_TYPE_MASS_REVOCATION_SUCCESS, @@ -118,7 +123,7 @@ public Map getUvcisWithErrorMessage(List u .map(UvciForRevocationDto::getUvci) .collect(Collectors.toList()); - Map uvcisToErrorMessage = Stream.of( + return Stream.of( // get all possible errors for uvcis getInvalidUvcis(uvcis).entrySet(), getUvcisWithMissingFraudFlag(uvciForRevocationDtos).entrySet(), @@ -134,8 +139,6 @@ public Map getUvcisWithErrorMessage(List u return left; } )); - - return uvcisToErrorMessage; } private Map getInvalidUvcis(List uvciList) { diff --git a/src/main/java/ch/admin/bag/covidcertificate/service/test/TestCovidCertificateGenerationService.java b/src/main/java/ch/admin/bag/covidcertificate/service/test/TestCovidCertificateGenerationService.java index cca79f1d..70b13a5d 100644 --- a/src/main/java/ch/admin/bag/covidcertificate/service/test/TestCovidCertificateGenerationService.java +++ b/src/main/java/ch/admin/bag/covidcertificate/service/test/TestCovidCertificateGenerationService.java @@ -2,7 +2,14 @@ import ch.admin.bag.covidcertificate.api.Constants; import ch.admin.bag.covidcertificate.api.mapper.CertificatePrintRequestDtoMapper; -import ch.admin.bag.covidcertificate.api.request.*; +import ch.admin.bag.covidcertificate.api.request.AntibodyCertificateCreateDto; +import ch.admin.bag.covidcertificate.api.request.CertificateCreateDto; +import ch.admin.bag.covidcertificate.api.request.ExceptionalCertificateCreateDto; +import ch.admin.bag.covidcertificate.api.request.RecoveryCertificateCreateDto; +import ch.admin.bag.covidcertificate.api.request.RecoveryRatCertificateCreateDto; +import ch.admin.bag.covidcertificate.api.request.TestCertificateCreateDto; +import ch.admin.bag.covidcertificate.api.request.VaccinationCertificateCreateDto; +import ch.admin.bag.covidcertificate.api.request.VaccinationTouristCertificateCreateDto; import ch.admin.bag.covidcertificate.api.request.conversion.VaccinationCertificateConversionRequestDto; import ch.admin.bag.covidcertificate.api.response.ConvertedCertificateResponseDto; import ch.admin.bag.covidcertificate.api.response.ConvertedCertificateResponseEnvelope; From 894180270bdb05e10ae20a96ab4e07b039f43b3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20L=C3=B6sing?= Date: Wed, 7 Sep 2022 15:06:28 +0200 Subject: [PATCH 4/7] fixed exclusion pattern. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 892b72eb..51a6dadc 100644 --- a/pom.xml +++ b/pom.xml @@ -50,7 +50,7 @@ **/*Dto.java - **/*Dto.java,**/config/*,**/*Exception.java,**/*Constants.java,**/*Registry.java,**/*Config.java,**/*Mock*,**/*Application.java,**/*HttpResponseHeaderFilter.java,**/*ActuatorSecurity.java,**/TestCovidCertificateGenerationService,java + **/*Dto.java,**/config/*,**/*Exception.java,**/*Constants.java,**/*Registry.java,**/*Config.java,**/*Mock*,**/*Application.java,**/*HttpResponseHeaderFilter.java,**/*ActuatorSecurity.java,**/*TestCovidCertificateGenerationService,java admin-ch_CovidCertificate-Management-Service From a396f2109669796619410d8d9b4e2cc5d0f8a2e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20L=C3=B6sing?= Date: Wed, 7 Sep 2022 15:44:39 +0200 Subject: [PATCH 5/7] delete not executable test case and removed unused variables. Commented hint on a sometimes failing test. --- .../DefaultInAppDeliveryClientITTest.java | 50 ------------------- .../service/CBORServiceTest.java | 9 ++-- 2 files changed, 6 insertions(+), 53 deletions(-) delete mode 100644 src/test/java/ch/admin/bag/covidcertificate/client/inapp_delivery/internal/DefaultInAppDeliveryClientITTest.java diff --git a/src/test/java/ch/admin/bag/covidcertificate/client/inapp_delivery/internal/DefaultInAppDeliveryClientITTest.java b/src/test/java/ch/admin/bag/covidcertificate/client/inapp_delivery/internal/DefaultInAppDeliveryClientITTest.java deleted file mode 100644 index 235f3b83..00000000 --- a/src/test/java/ch/admin/bag/covidcertificate/client/inapp_delivery/internal/DefaultInAppDeliveryClientITTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package ch.admin.bag.covidcertificate.client.inapp_delivery.internal; - -import ch.admin.bag.covidcertificate.api.exception.CreateCertificateException; -import ch.admin.bag.covidcertificate.api.request.SystemSource; -import ch.admin.bag.covidcertificate.client.inapp_delivery.domain.InAppDeliveryRequestDto; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ActiveProfiles; - -import static ch.admin.bag.covidcertificate.FixtureCustomization.createUVCI; -import static ch.admin.bag.covidcertificate.api.Constants.APP_DELIVERY_FAILED; -import static org.junit.jupiter.api.Assertions.*; - -@SpringBootTest(properties = { - "spring.jpa.hibernate.ddl-auto=create", - "spring.datasource.driver-class-name=org.h2.Driver", - "spring.datasource.url=jdbc:h2:~/test;MODE=PostgreSQL;DATABASE_TO_LOWER=TRUE", - "spring.datasource.username=sa", - "spring.datasource.password=sa", - "spring.flyway.clean-on-validation-error=true" -}) -@ActiveProfiles("local") -@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) -@Disabled("Only runs manually") -class DefaultInAppDeliveryClientITTest { - - private static final String validTestCode = "BITBITBIT"; - - @Autowired - private DefaultInAppDeliveryClient client; - - @Test - void deliverToApp_invalid() { - var requestDto = new InAppDeliveryRequestDto("test", "test", "test"); - CreateCertificateException exception = assertThrows( - CreateCertificateException.class, - () -> client.deliverToApp(createUVCI(), SystemSource.WebUI, "0815", requestDto)); - - assertEquals(APP_DELIVERY_FAILED, exception.getError()); - } - - @Test - void deliverToApp_valid() { - var requestDto = new InAppDeliveryRequestDto(validTestCode, "test", "test"); - assertDoesNotThrow(() -> client.deliverToApp(createUVCI(), SystemSource.WebUI, "0815", requestDto)); - } -} diff --git a/src/test/java/ch/admin/bag/covidcertificate/service/CBORServiceTest.java b/src/test/java/ch/admin/bag/covidcertificate/service/CBORServiceTest.java index 807cdb90..3304b030 100644 --- a/src/test/java/ch/admin/bag/covidcertificate/service/CBORServiceTest.java +++ b/src/test/java/ch/admin/bag/covidcertificate/service/CBORServiceTest.java @@ -74,7 +74,7 @@ void throwsIllegalArgumentException_ifKeyIdentifierIsNullOrBlank(String keyIdent @Test void throwsDecoderException_ifKeyIdentifierIsNotAValidHexString() { - DecoderException exception = assertThrows(DecoderException.class, + assertThrows(DecoderException.class, () -> cborService.getProtectedHeader(fixture.create(String.class))); } } @@ -144,7 +144,10 @@ void throwsIllegalArgumentException_ifHCertIsNullOrEmpty(byte[] hcert) { void throwsCBORException_ifHCertIsNotAValidCborObject() { var hcert = fixture.create(byte[].class); var expiredAt = fixture.create(Instant.class); - var exception = assertThrows(CBORException.class, + // during release build this test sometimes failes as no exception is thrown + // this because a fixture might create a byte[] with invalid content + // just rerun build + assertThrows(CBORException.class, () -> cborService.getPayload(hcert, expiredAt)); } } @@ -267,7 +270,7 @@ void throwsIllegalArgumentException_ifSignatureIsNullOrEmpty(byte[] signature) { byte[] payload = fixture.create(byte[].class); // when then IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, - () -> cborService.getCOSESign1(protectedHeader, protectedHeader, signature)); + () -> cborService.getCOSESign1(protectedHeader, payload, signature)); assertTrue(exception.getMessage().toLowerCase().contains("signature")); } } From ab3587dded10cec703cf4833937f0d07b3028db8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20L=C3=B6sing?= <89404702+haraldloesing@users.noreply.github.com> Date: Wed, 7 Sep 2022 15:49:35 +0200 Subject: [PATCH 6/7] Update maven.yml --- .github/workflows/maven.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 9031ab98..4b71b471 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -1,6 +1,7 @@ name: Build, test and analyze on: + workflow_dispatch: push: branches: - 'release/**' From 2b94a64ce16d0b210210d5ad39a7aafbf34d1f41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20L=C3=B6sing?= Date: Wed, 7 Sep 2022 15:57:46 +0200 Subject: [PATCH 7/7] defined byte array without fixture. --- .../admin/bag/covidcertificate/service/CBORServiceTest.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/test/java/ch/admin/bag/covidcertificate/service/CBORServiceTest.java b/src/test/java/ch/admin/bag/covidcertificate/service/CBORServiceTest.java index 3304b030..f2739df6 100644 --- a/src/test/java/ch/admin/bag/covidcertificate/service/CBORServiceTest.java +++ b/src/test/java/ch/admin/bag/covidcertificate/service/CBORServiceTest.java @@ -142,11 +142,8 @@ void throwsIllegalArgumentException_ifHCertIsNullOrEmpty(byte[] hcert) { @Test void throwsCBORException_ifHCertIsNotAValidCborObject() { - var hcert = fixture.create(byte[].class); + var hcert = new byte[] {38, 41, 89}; var expiredAt = fixture.create(Instant.class); - // during release build this test sometimes failes as no exception is thrown - // this because a fixture might create a byte[] with invalid content - // just rerun build assertThrows(CBORException.class, () -> cborService.getPayload(hcert, expiredAt)); }