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

Commit

Permalink
Merge pull request #373 from admin-ch/master
Browse files Browse the repository at this point in the history
Update with sonar corrections
  • Loading branch information
haraldloesing authored Sep 7, 2022
2 parents ef2ce4e + 0fa054f commit 0b2f695
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 60 deletions.
1 change: 1 addition & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Build, test and analyze

on:
workflow_dispatch:
push:
branches:
- 'release/**'
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
**/*Dto.java
</sonar.cpd.exclusions>
<sonar.coverage.exclusions>
**/*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
</sonar.coverage.exclusions>

<sonar.projectKey>admin-ch_CovidCertificate-Management-Service</sonar.projectKey>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -59,6 +63,7 @@ public void createRevocation(String uvci, boolean fraud) {
}
}

@Transactional
public RevocationListResponseDto performMassRevocation(RevocationListDto revocationListDto) {
Map<String, String> uvcisToErrorMessage = getUvcisWithErrorMessage(
revocationListDto.getUvcis()
Expand All @@ -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,
Expand Down Expand Up @@ -118,7 +123,7 @@ public Map<String, String> getUvcisWithErrorMessage(List<UvciForRevocationDto> u
.map(UvciForRevocationDto::getUvci)
.collect(Collectors.toList());

Map<String, String> uvcisToErrorMessage = Stream.of(
return Stream.of(
// get all possible errors for uvcis
getInvalidUvcis(uvcis).entrySet(),
getUvcisWithMissingFraudFlag(uvciForRevocationDtos).entrySet(),
Expand All @@ -134,8 +139,6 @@ public Map<String, String> getUvcisWithErrorMessage(List<UvciForRevocationDto> u
return left;
}
));

return uvcisToErrorMessage;
}

private Map<String, String> getInvalidUvcis(List<String> uvciList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
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 static ch.admin.bag.covidcertificate.api.Constants.ISSUER;
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().toLocalDate(),
actual.getSampleDate());
}

@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 mapsUvci() {
AntibodyCertificatePdfGenerateRequestDto incoming = fixture.create(AntibodyCertificatePdfGenerateRequestDto.class);
AntibodyCertificatePdf actual = AntibodyCertificatePdfGenerateRequestDtoMapper.toAntibodyCertificatePdf(
incoming, countryOfTest, countryOfTestEn);
assertEquals(incoming.getDecodedCert().getAntibodyInfo().get(0).getIdentifier(), actual.getIdentifier());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}
Expand Down Expand Up @@ -142,9 +142,9 @@ 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);
var exception = assertThrows(CBORException.class,
assertThrows(CBORException.class,
() -> cborService.getPayload(hcert, expiredAt));
}
}
Expand Down Expand Up @@ -267,7 +267,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"));
}
}
Expand Down

0 comments on commit 0b2f695

Please sign in to comment.