RemoteDocumentValidationService { public List<RemoteDocument> getOriginalDocuments(DataToValidateDTO dataToValidate) { LOG.info("GetOriginalDocuments in process..."); SignedDocumentValidator validator = initValidator(dataToValidate); String signatureId = dataToValidate.getSignatureId(); if (signatureId == null) { List<AdvancedSignature> signatures = validator.getSignatures(); if (signatures.size() > 0) { LOG.debug("SignatureId is not defined, the first signature is used"); signatureId = signatures.get(0).getId(); } } List<DSSDocument> originalDocuments = validator.getOriginalDocuments(signatureId); List<RemoteDocument> remoteDocuments = RemoteDocumentConverter.toRemoteDocuments(originalDocuments); LOG.info("GetOriginalDocuments is finished"); return remoteDocuments; }  void setVerifier(CertificateVerifier verifier); WSReportsDTO validateDocument(DataToValidateDTO dataToValidate); List<RemoteDocument> getOriginalDocuments(DataToValidateDTO dataToValidate);  }
@Test public void testGetOriginalsWithoutId() throws Exception { RemoteDocument signedFile = RemoteDocumentConverter.toRemoteDocument(new FileDocument("src/test/resources/xadesLTA.xml")); DataToValidateDTO dto = new DataToValidateDTO(signedFile, (RemoteDocument) null, null); List<RemoteDocument> result = validationService.getOriginalDocuments(dto); assertNotNull(result); assertEquals(1, result.size()); RemoteDocument document = result.get(0); assertNotNull(document); assertNotNull(document.getBytes()); }
@Test public void testGetOriginalsWithWrongId() throws Exception { RemoteDocument signedFile = RemoteDocumentConverter.toRemoteDocument(new FileDocument("src/test/resources/xadesLTA.xml")); DataToValidateDTO dto = new DataToValidateDTO(signedFile, (RemoteDocument) null, null, "id-wrong"); List<RemoteDocument> result = validationService.getOriginalDocuments(dto); assertNotNull(result); assertEquals(0, result.size()); }
@Test public void testGetOriginalFromDetachedSignature() throws Exception { RemoteDocument signedFile = RemoteDocumentConverter.toRemoteDocument(new FileDocument("src/test/resources/xades-detached.xml")); RemoteDocument originalDocument = RemoteDocumentConverter.toRemoteDocument(new FileDocument("src/test/resources/sample.png")); DataToValidateDTO dto = new DataToValidateDTO(signedFile, Arrays.asList(originalDocument), null); List<RemoteDocument> result = validationService.getOriginalDocuments(dto); assertNotNull(result); assertEquals(1, result.size()); RemoteDocument document = result.get(0); assertNotNull(document); assertTrue(Arrays.equals(DSSUtils.toByteArray(RemoteDocumentConverter.toDSSDocument(originalDocument)), document.getBytes())); }