SW360UpdaterImpl { public AttachmentUploadResult<SW360Release> artifactToReleaseWithUploads(Artifact artifact, SW360Release release, Map<Path, SW360AttachmentType> uploads) { Set<String> licenseIds = getSetOfLicenseIds(artifact); release.setMainLicenseIds(licenseIds); SW360Release sw360ReleaseFinal = sw360MetaDataUpdater.getOrCreateRelease(release, isUpdateReleases()); return uploadSourceAndAttachments(sw360ReleaseFinal, artifact, uploads); } SW360UpdaterImpl(SW360MetaDataUpdater sw360MetaDataUpdater,
                            String projectName, String projectVersion, boolean updateReleases,
                            boolean uploadSources, boolean deleteObsoleteSourceAttachments); boolean isUpdateReleases(); boolean isUploadSources(); boolean isDeleteObsoleteSourceAttachments(); Map<String, IAttachable> produce(Collection<Artifact> intermediates); SW360Release artifactToReleaseInSW360(Artifact artifact); SW360Release artifactToReleaseInSW360(Artifact artifact, SW360Release release); AttachmentUploadResult<SW360Release> artifactToReleaseWithUploads(Artifact artifact, SW360Release release,
                                                                             Map<Path, SW360AttachmentType> uploads);  }
@Test public void testUpdaterArtifactToReleaseWithUploadsNoUploads() { Artifact artifact = TestUtils.mkArtifact("test", false); License license = new License("testLicense"); SW360License sw360License = new SW360License(); sw360License.setShortName("sw360TestLicense"); artifact.addFact(new ConfiguredLicenseInformation(license)); SW360Release release = createRelease("test", null); SW360Release updatedRelease = createRelease("testUpdated", null); when(metaDataUpdater.getLicenses(Collections.singletonList(license))) .thenReturn(Collections.singleton(sw360License)); when(metaDataUpdater.getOrCreateRelease(release, true)) .thenReturn(updatedRelease); SW360UpdaterImpl updater = new SW360UpdaterImpl(metaDataUpdater, "test", "version", true, true, false); AttachmentUploadResult<SW360Release> result = updater.artifactToReleaseWithUploads(artifact, release, Collections.emptyMap()); assertThat(result.getTarget()).isEqualTo(updatedRelease); assertThat(release.getMainLicenseIds()).containsOnly(sw360License.getShortName()); verify(metaDataUpdater, never()).uploadAttachments(any(), any(), anyBoolean()); }
@Test public void testUpdaterArtifactToReleaseUploadDisabled() throws IOException { Path sourceFile = createTestFile(); Artifact artifact = TestUtils.mkArtifact("test", false); artifact.addFact(new ArtifactSourceFile(sourceFile)); SW360Release release = createRelease("test", sourceFile); SW360Release createdRelease = createRelease("testCreated", sourceFile); when(metaDataUpdater.getOrCreateRelease(release, true)) .thenReturn(createdRelease); SW360UpdaterImpl updater = new SW360UpdaterImpl(metaDataUpdater, "test", "version", true, false, false); AttachmentUploadResult<SW360Release> result = updater.artifactToReleaseWithUploads(artifact, release, Collections.emptyMap()); assertThat(result.getTarget()).isEqualTo(createdRelease); verify(metaDataUpdater, never()).uploadAttachments(any(), any(), anyBoolean()); }
@Test public void testUpdaterArtifactToReleaseAdditionalUpload() throws IOException { Path uploadPath = createTestFile(); Map<Path, SW360AttachmentType> uploadMap = Collections.singletonMap(uploadPath, SW360AttachmentType.CLEARING_REPORT); Artifact artifact = TestUtils.mkArtifact("test", false); SW360Release release = createRelease("test", null); SW360Release createdRelease = createRelease("testCreated", null); SW360Release uploadedRelease = createRelease("uploadedRelease", null); AttachmentUploadResult<SW360Release> uploadResult = new AttachmentUploadResult<>(uploadedRelease); when(metaDataUpdater.getOrCreateRelease(release, false)) .thenReturn(createdRelease); when(metaDataUpdater.uploadAttachments(createdRelease, uploadMap, false)) .thenReturn(uploadResult); SW360UpdaterImpl updater = new SW360UpdaterImpl(metaDataUpdater, "test", "version", false, false, false); AttachmentUploadResult<SW360Release> result = updater.artifactToReleaseWithUploads(artifact, release, uploadMap); assertThat(result).isEqualTo(uploadResult); }
@Test public void testUpdaterArtifactToReleaseWithSourceAndAdditionalUpload() throws IOException { Path sourceFile = createTestFile(); Path uploadFile = createTestFile(); Map<Path, SW360AttachmentType> uploadMap = Collections.singletonMap(uploadFile, SW360AttachmentType.CLEARING_REPORT); Artifact artifact = TestUtils.mkArtifact("test", false); artifact.addFact(new ArtifactSourceFile(sourceFile)); SW360Release release = createRelease("test", sourceFile); SW360Release createdRelease = createRelease("testCreated", sourceFile); SW360Release updatedRelease = createRelease("testUpdated", sourceFile); AttachmentUploadResult<SW360Release> uploadResult = new AttachmentUploadResult<>(updatedRelease); Map<Path, SW360AttachmentType> expUploads = new HashMap<>(); expUploads.put(sourceFile, SW360AttachmentType.SOURCE); expUploads.put(uploadFile, SW360AttachmentType.CLEARING_REPORT); when(metaDataUpdater.getOrCreateRelease(release, false)) .thenReturn(createdRelease); when(metaDataUpdater.uploadAttachments(createdRelease, expUploads, false)) .thenReturn(uploadResult); SW360UpdaterImpl updater = new SW360UpdaterImpl(metaDataUpdater, "test", "version", false, true, false); AttachmentUploadResult<SW360Release> result = updater.artifactToReleaseWithUploads(artifact, release, uploadMap); assertThat(result).isEqualTo(uploadResult); }
@Test public void testUpdaterArtifactToReleaseDeleteSourcesNoSource() { Artifact artifact = TestUtils.mkArtifact("test", false); SW360Release release = createRelease("test", null); SW360Release createdRelease = createRelease("testCreated", null); SW360Release deletedRelease = createRelease("releaseNoAttachments", null); when(metaDataUpdater.getOrCreateRelease(release, false)) .thenReturn(createdRelease); when(metaDataUpdater.deleteAttachments(eq(createdRelease), any())) .thenReturn(deletedRelease); SW360UpdaterImpl updater = new SW360UpdaterImpl(metaDataUpdater, "test", "version", false, false, true); AttachmentUploadResult<SW360Release> result = updater.artifactToReleaseWithUploads(artifact, release, Collections.emptyMap()); assertThat(result.getTarget()).isEqualTo(deletedRelease); Predicate<SW360SparseAttachment> predicate = extractPredicateForDeleteAttachments(createdRelease); assertThat(predicate.test(createAttachment(Paths.get("foo"), SW360AttachmentType.SOURCE))) .isTrue(); assertThat(predicate.test(createAttachment(Paths.get("foo"), SW360AttachmentType.BINARY))) .isFalse(); }
@Test public void testUpdaterArtifactToReleaseDeleteSources() throws IOException { Path sourceFile = createTestFile(); Artifact artifact = TestUtils.mkArtifact("test", false); artifact.addFact(new ArtifactSourceFile(sourceFile)); SW360Release release = createRelease("test", sourceFile); SW360Release createdRelease = createRelease("testCreated", sourceFile); SW360Release srcDeletedRelease = createRelease("testAttachmentsDeleted", sourceFile); SW360Release updatedRelease = createRelease("testUpdated", sourceFile); Map<Path, SW360AttachmentType> uploadMap = Collections.singletonMap(sourceFile, SW360AttachmentType.SOURCE); AttachmentUploadResult<SW360Release> uploadResult = new AttachmentUploadResult<>(updatedRelease); when(metaDataUpdater.getOrCreateRelease(release, false)) .thenReturn(createdRelease); when(metaDataUpdater.deleteAttachments(eq(createdRelease), any())).thenReturn(srcDeletedRelease); when(metaDataUpdater.uploadAttachments(srcDeletedRelease, uploadMap, true)) .thenReturn(uploadResult); SW360UpdaterImpl updater = new SW360UpdaterImpl(metaDataUpdater, "test", "version", false, true, true); AttachmentUploadResult<SW360Release> result = updater.artifactToReleaseWithUploads(artifact, release, uploadMap); assertThat(result).isEqualTo(uploadResult); Predicate<SW360SparseAttachment> predicate = extractPredicateForDeleteAttachments(createdRelease); assertThat(predicate.test(createAttachment(Paths.get("foo"), SW360AttachmentType.SOURCE))) .isTrue(); assertThat(predicate.test(createAttachment(sourceFile, SW360AttachmentType.SOURCE))) .isFalse(); }
@Test public void testUpdaterArtifactToReleaseDeleteFailure() throws IOException { Path sourceFile = createTestFile(); Artifact artifact = TestUtils.mkArtifact("test", false); artifact.addFact(new ArtifactSourceFile(sourceFile)); SW360Release release = createRelease("test", sourceFile); SW360Release createdRelease = createRelease("testCreated", sourceFile); SW360Release updatedRelease = createRelease("testUpdated", sourceFile); Map<Path, SW360AttachmentType> uploadMap = Collections.singletonMap(sourceFile, SW360AttachmentType.SOURCE); AttachmentUploadResult<SW360Release> uploadResult = new AttachmentUploadResult<>(updatedRelease); when(metaDataUpdater.getOrCreateRelease(release, true)).thenReturn(createdRelease); when(metaDataUpdater.deleteAttachments(any(), any())) .thenThrow(new SW360ClientException("Delete operation failed")); when(metaDataUpdater.uploadAttachments(createdRelease, uploadMap, true)) .thenReturn(uploadResult); SW360UpdaterImpl updater = new SW360UpdaterImpl(metaDataUpdater, "test", "version", true, true, true); AttachmentUploadResult<SW360Release> result = updater.artifactToReleaseWithUploads(artifact, release, Collections.emptyMap()); assertThat(result).isEqualTo(uploadResult); }