SignatureTypeResolver { static String resolveSignatureType(ValidationConclusion validationConclusion) { if (CollectionUtils.isEmpty(validationConclusion.getSignatures()) || isTstTypeContainer(validationConclusion)) { return NA; } String signatureFormat = validationConclusion.getSignatures().get(0).getSignatureFormat(); if (isDdoc(signatureFormat) || isXades(signatureFormat)) { return XADES; } if (isCades(signatureFormat)) { return CADES; } if (isPades(signatureFormat)) { return PADES; } return NA; }    }
@Test public void reportWithEmptySignaturesReturnsNa() { assertEquals(NA, resolveSignatureType(new ValidationConclusion())); }
@Test public void reportWithTstContainerTypeReturnsNa() { ValidationConclusion validationConclusion = new ValidationConclusionBuilder() .withSignatureForm(ASIC_S) .addSignatureWithFormat(XADES + "_some_prefix") .addTimeStampToken(new TimeStampTokenValidationData()) .build(); assertEquals(NA, resolveSignatureType(validationConclusion)); }
@Test public void skXmlSignatureFormatReturnsXades() { assertEquals(XADES, resolveSignatureType(reportWithSignatureFormat(SK_XML + "_some_prefix"))); }
@Test public void digidocXmlSignatureFormatReturnsXades() { assertEquals(XADES, resolveSignatureType(reportWithSignatureFormat(DIGIDOC_XML + "_some_prefix"))); }
@Test public void xadesSignatureFormatReturnsCades() { assertEquals(XADES, resolveSignatureType(reportWithSignatureFormat(XADES + "_some_prefix"))); }
@Test public void cadesSignatureFormatReturnsCades() { assertEquals(CADES, resolveSignatureType(reportWithSignatureFormat(CADES + "_some_prefix"))); }
@Test public void padesSignatureFormatReturnsCades() { assertEquals(PADES, resolveSignatureType(reportWithSignatureFormat(PADES + "_some_prefix"))); }
@Test public void unknownSignatureFormatReturnsNa() { assertEquals(NA, resolveSignatureType(reportWithSignatureFormat("unknown"))); }
@Test public void usesOnlyPrefixesOfSignatureFormats() { assertEquals(NA, resolveSignatureType(reportWithSignatureFormat("b" + SK_XML + "_some_prefix"))); assertEquals(NA, resolveSignatureType(reportWithSignatureFormat("b" + DIGIDOC_XML + "_some_prefix"))); assertEquals(NA, resolveSignatureType(reportWithSignatureFormat("b" + XADES + "_some_prefix"))); assertEquals(NA, resolveSignatureType(reportWithSignatureFormat("b" + CADES + "_some_prefix"))); assertEquals(NA, resolveSignatureType(reportWithSignatureFormat("b" + PADES + "_some_prefix"))); }
@Test public void usesFirstSignatureOfReport() { ValidationConclusion validationConclusion = new ValidationConclusionBuilder() .addSignatureWithFormat("unknown") .addSignatureWithFormat(XADES + "_some_prefix") .build(); assertEquals(NA, resolveSignatureType(validationConclusion)); }