SW360ReleaseClientAdapterAsyncImpl implements SW360ReleaseClientAdapterAsync { @Override public CompletableFuture<Optional<SW360Release>> getReleaseByVersion(SW360Component component, String releaseVersion) { if (component != null && component.getEmbedded() != null && component.getEmbedded().getReleases() != null) { List<SW360SparseRelease> releases = component.getEmbedded().getReleases(); Optional<String> releaseId = releases.stream() .filter(release -> release.getVersion().equals(releaseVersion)) .findFirst() .flatMap(release -> SW360HalResourceUtility.getLastIndexOfSelfLink(release.getLinks())); if (releaseId.isPresent()) { return getReleaseById(releaseId.get()); } } return CompletableFuture.completedFuture(Optional.empty()); } 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 testGetReleaseByVersion() { SW360SparseRelease sparseRelease = new SW360SparseRelease() .setVersion(RELEASE_VERSION1); String releaseHref = "url/" + ID; Self releaseSelf = new Self().setHref(releaseHref); LinkObjects links = new LinkObjects(); links.setSelf(releaseSelf); sparseRelease.setLinks(links); String componentName = "componentName"; SW360Component component = getSw360Component(sparseRelease, componentName); when(releaseClient.getRelease(ID)) .thenReturn(CompletableFuture.completedFuture(release)); final Optional<SW360Release> releaseByVersion = block(releaseClientAdapter.getReleaseByVersion(component, release.getVersion())); assertThat(releaseByVersion).isPresent(); assertThat(releaseByVersion).hasValue(release); verify(releaseClient, times(1)).getRelease(ID); }
@Test public void testGetReleaseByVersionNoComponent() { Optional<SW360Release> optRelease = block(releaseClientAdapter.getReleaseByVersion(null, RELEASE_VERSION1)); assertThat(optRelease).isEmpty(); }