SW360MetaDataReceiver { public Optional<SW360Release> findReleaseForArtifact(Artifact artifact) { Optional<SW360Component> component = getComponentByArtifact(artifact); if (component.isPresent()) { String releaseVersionOfArtifact = ArtifactToReleaseUtils.createSW360ReleaseVersion(artifact); return releaseClientAdapter.getReleaseByVersion(component.get(), releaseVersionOfArtifact); } return Optional.empty(); } SW360MetaDataReceiver(SW360Connection sw360ConnectionConfiguration); Optional<SW360Release> findReleaseForArtifact(Artifact artifact); Optional<SW360License> getLicenseDetails(SW360SparseLicense sparseLicense); Optional<Path> downloadAttachment(SW360Release release, SW360SparseAttachment attachment, Path downloadPath);  }
@Test public void testFindReleaseForArtifactPresentComponent() { final String version = "version"; final Artifact artifact = new Artifact() .addFact(new ArtifactCoordinates(new Coordinate("name", version))); final String componentName = ArtifactToComponentUtils.createComponentName(artifact); final SW360Component sw360Component = new SW360Component(); final SW360Release release = new SW360Release(); when(componentClientAdapter.getComponentByName(componentName)) .thenReturn(Optional.of(sw360Component)); when(releaseClientAdapter.getReleaseByVersion(sw360Component, version)) .thenReturn(Optional.of(release)); setUp(); final Optional<SW360Release> releaseForArtifact = metaDataReceiver.findReleaseForArtifact(artifact); assertThat(releaseForArtifact).isPresent(); assertThat(releaseForArtifact).hasValue(release); verify(componentClientAdapter, times(1)).getComponentByName(componentName); verify(releaseClientAdapter, times(1)).getReleaseByVersion(sw360Component, version); }
@Test public void testFindReleaseForArtifactNotPresentComponent() { final String version = "version"; final Artifact artifact = new Artifact() .addFact(new ArtifactCoordinates(new Coordinate("name", version))); final String componentName = ArtifactToComponentUtils.createComponentName(artifact); when(componentClientAdapter.getComponentByName(componentName)) .thenReturn(Optional.empty()); setUp(); final Optional<SW360Release> releaseForArtifact = metaDataReceiver.findReleaseForArtifact(artifact); assertThat(releaseForArtifact).isNotPresent(); verify(componentClientAdapter, times(1)).getComponentByName(componentName); verify(releaseClientAdapter, never()).getReleaseByVersion(any(), any()); }
@Test public void testFindReleaseForArtifactWithNoCoordinate() { setUp(); final Optional<SW360Release> releaseForArtifact = metaDataReceiver.findReleaseForArtifact(new Artifact()); assertThat(releaseForArtifact).isNotPresent(); verify(componentClientAdapter, never()).getComponentByName(any()); }