SW360ReleaseClientAdapterAsyncImpl implements SW360ReleaseClientAdapterAsync { @Override public CompletableFuture<SW360Release> updateRelease(SW360Release release) { return FutureUtils.wrapInFuture(() -> { if (release.getId() == null) { throw new IllegalArgumentException("Cannot update release without ID"); } return SW360ReleaseAdapterUtils.validateRelease(release); }, "Cannot update release for " + release.getName()) .thenCompose(getReleaseClient()::patchRelease); } 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 testUpdateReleaseNoId() { SW360Release updateRelease = new SW360Release(); updateRelease.setName("newRelease") .setVersion(RELEASE_VERSION1); CompletableFuture<SW360Release> futUpdate = releaseClientAdapter.updateRelease(updateRelease); try { block(futUpdate); fail("Invalid release not detected"); } catch (SW360ClientException e) { assertThat(e.getMessage()).contains("Cannot update release", updateRelease.getName()); assertThat(e.getCause()).isInstanceOf(IllegalArgumentException.class); } }
@Test public void testUpdateRelease() throws MalformedPackageURLException { SW360Release updatedRelease = mkSW360Release("updatedRelease"); release.getLinks().setSelf(new Self("https: when(releaseClient.patchRelease(release)).thenReturn(CompletableFuture.completedFuture(updatedRelease)); assertThat(block(releaseClientAdapter.updateRelease(release))).isEqualTo(updatedRelease); }
@Test public void testUpdateReleaseInvalid() throws MalformedPackageURLException { SW360Release updatedRelease = mkSW360Release("updatedRelease"); updatedRelease.setVersion(""); CompletableFuture<SW360Release> futUpdate = releaseClientAdapter.updateRelease(updatedRelease); try { block(futUpdate); fail("Invalid release not detected"); } catch (SW360ClientException e) { assertThat(e.getMessage()).contains("Cannot update release", updatedRelease.getName()); assertThat(e.getCause()).isInstanceOf(IllegalArgumentException.class); } }