RemoteDocumentConverter { public static RemoteDocument toRemoteDocument(DSSDocument originalDocument) { if (originalDocument == null) { return null; } if (originalDocument instanceof DigestDocument) { DigestDocument digestDocument = (DigestDocument) originalDocument; Digest digest = digestDocument.getExistingDigest(); if (digest.getAlgorithm() == null || digest.getValue() == null) { throw new DSSRemoteServiceException("Impossible to create a RemoteDocument from a DigestDocument with not defined Digest"); } return new RemoteDocument(digest.getValue(), digest.getAlgorithm(), originalDocument.getName()); } return new RemoteDocument(DSSUtils.toByteArray(originalDocument), originalDocument.getName()); } private  RemoteDocumentConverter(); static List<DSSDocument> toDSSDocuments(List<RemoteDocument> remoteDocuments); static DSSDocument toDSSDocument(RemoteDocument remoteDocument); static List<RemoteDocument> toRemoteDocuments(List<DSSDocument> originalDocuments); static RemoteDocument toRemoteDocument(DSSDocument originalDocument);  }
@Test public void toRemoteDocumentTest() { DSSDocument dssDocument = new InMemoryDocument(new byte[] {'1','2','3'}, "dssDocument"); RemoteDocument remoteDocument = RemoteDocumentConverter.toRemoteDocument(dssDocument); assertEquals(Utils.toBase64(DSSUtils.digest(DigestAlgorithm.SHA256, remoteDocument.getBytes())), dssDocument.getDigest(DigestAlgorithm.SHA256)); assertEquals(remoteDocument.getName(), dssDocument.getName()); }
@Test public void digestDocumentToRemoteDocumentTest() { DSSDocument dssDocument = new DigestDocument(DigestAlgorithm.SHA256, "332b7ce3b5e8f8c6132f0e09264db9da6d1c9fd6e37b73a35e68f78f4e590f90"); RemoteDocument remoteDocument = RemoteDocumentConverter.toRemoteDocument(dssDocument); assertEquals(Utils.toBase64(remoteDocument.getBytes()), dssDocument.getDigest(remoteDocument.getDigestAlgorithm())); assertEquals(remoteDocument.getName(), dssDocument.getName()); }
@Test public void emptyDigestDocumentToRemoteDocumentTest() { DSSDocument dssDocument = new DigestDocument(); assertThrows(DSSException.class, () -> RemoteDocumentConverter.toRemoteDocument(dssDocument)); }