SW360ReleaseClientAdapterAsyncImpl implements SW360ReleaseClientAdapterAsync { @Override public <T> CompletableFuture<T> processAttachment(SW360Release release, String attachmentId, SW360AttachmentAwareClient.AttachmentProcessor<? extends T> processor) { return FutureUtils.wrapInFuture(() -> release.getSelfLink().getHref(), "Release has no ID") .thenCompose(href -> getReleaseClient().processAttachment(href, attachmentId, processor)); } SW360ReleaseClientAdapterAsyncImpl(SW360ReleaseClient client,
                                              SW360ComponentClientAdapterAsync componentClientAdapter); @Override SW360ReleaseClient getReleaseClient(); SW360ComponentClientAdapterAsync getComponentAdapter(); @Override CompletableFuture<SW360Release> createRelease(SW360Release release); @Override CompletableFuture<AttachmentUploadResult<SW360Release>> uploadAttachments(AttachmentUploadRequest<SW360Release> uploadRequest); @Override CompletableFuture<Optional<SW360Release>> getReleaseById(String releaseId); @Override CompletableFuture<Optional<SW360Release>> enrichSparseRelease(SW360SparseRelease sparseRelease); @Override CompletableFuture<Optional<SW360SparseRelease>> getSparseReleaseByExternalIds(Map<String, ?> externalIds); @Override CompletableFuture<Optional<SW360SparseRelease>> getSparseReleaseByNameAndVersion(String componentName,
                                                                                            String version); @Override CompletableFuture<Optional<SW360Release>> getReleaseByVersion(SW360Component component, String releaseVersion); @Override CompletableFuture<Optional<Path>> downloadAttachment(SW360Release release, SW360SparseAttachment attachment,
                                                                Path downloadPath); @Override CompletableFuture<T> processAttachment(SW360Release release, String attachmentId, SW360AttachmentAwareClient.AttachmentProcessor<? extends T> processor); @Override CompletableFuture<SW360Release> deleteAttachments(SW360Release release, Collection<String> attachmentIds); @Override CompletableFuture<SW360Release> updateRelease(SW360Release release); @Override CompletableFuture<MultiStatusResponse> deleteReleases(Collection<String> idsToDelete); @Override CompletableFuture<Void> deleteRelease(String releaseId);  }
@Test public void testProcessAttachment() { final String attachmentId = "attach-test-id"; final Integer result = 42; @SuppressWarnings("unchecked") SW360AttachmentAwareClient.AttachmentProcessor<Integer> processor = mock(SW360AttachmentAwareClient.AttachmentProcessor.class); addSelfLink(release); when(releaseClient.processAttachment(RELEASE_HREF, attachmentId, processor)) .thenReturn(CompletableFuture.completedFuture(result)); Integer processResult = block(releaseClientAdapter.processAttachment(release, attachmentId, processor)); assertThat(processResult).isEqualTo(result); }
@Test public void testProcessAttachmentNoReleaseId() { SW360Release undefinedRelease = new SW360Release(); SW360AttachmentUtils.AttachmentDownloadProcessor processor = SW360AttachmentUtils.defaultAttachmentDownloadProcessor("test.doc", Paths.get("irrelevant", "path")); try { block(releaseClientAdapter.processAttachment(undefinedRelease, "1234", processor)); fail("No exception thrown"); } catch (SW360ClientException e) { assertThat(e.getCause()).isInstanceOf(NullPointerException.class); assertThat(e.getMessage()).contains("no ID"); } }