ArtifactToReleaseUtils { public static SW360Release convertToReleaseWithoutAttachments(Artifact artifact) { SW360Release release = new SW360Release(); String componentName = ArtifactToComponentUtils.createComponentName(artifact); ArtifactToReleaseUtils.setVersion(release, artifact); ArtifactToReleaseUtils.setCPEId(release, artifact); release.setName(componentName); ArtifactToReleaseUtils.setCoordinates(release, artifact); ArtifactToReleaseUtils.setOverriddenLicense(release, artifact); ArtifactToReleaseUtils.setDeclaredLicense(release, artifact); ArtifactToReleaseUtils.setObservedLicense(release, artifact); ArtifactToReleaseUtils.setSourceUrl(release, artifact); ArtifactToReleaseUtils.setReleaseTagUrl(release, artifact); ArtifactToReleaseUtils.setSwhId(release, artifact); ArtifactToReleaseUtils.setHashes(release, artifact); ArtifactToReleaseUtils.setClearingStatus(release, artifact); ArtifactToReleaseUtils.setChangeStatus(release, artifact); ArtifactToReleaseUtils.setCopyrights(release, artifact); ArtifactToReleaseUtils.setHomepageUrl(release, artifact); release.setProprietary(artifact.isProprietary()); return release; } private  ArtifactToReleaseUtils(); static Artifact convertToArtifactWithoutSourceFile(SW360Release release, Artifact artifact); static SW360Release convertToReleaseWithoutAttachments(Artifact artifact); static String createSW360ReleaseVersion(Artifact artifact); static void setVersion(SW360Release release, Artifact artifact);  }
@Test public void artifactIsMappedToSw360ReleaseCorrectlyWithOverwritten() { Artifact artifact = TestUtils.mkArtifact("Test1", true); SW360Component sw360Component = new SW360Component(); sw360Component.setName("artifactIdtest1"); SW360Release release = ArtifactToReleaseUtils.convertToReleaseWithoutAttachments(artifact); release.setComponentId(sw360Component.getId()); release.setMainLicenseIds(Collections.emptySet()); assertThat(release.getClearingState()).isEqualTo(TestUtils.RELEASE_CLEARING_STATE); assertThat(release.getChangeStatus()).isEqualTo(TestUtils.RELEASE_CHANGESTATUS); assertThat(release.getDownloadurl()).isEqualTo(TestUtils.RELEASE_DOWNLOAD_URL); assertThat(release.getReleaseTagUrl()).isEqualTo(TestUtils.RELEASE_RELEASE_TAG_URL); assertThat(release.getSoftwareHeritageId()).isEqualTo(TestUtils.RELEASE_SOFTWAREHERITGAE_ID); assertThat(new ArtifactSoftwareHeritageID.Builder(release.getSoftwareHeritageId()).build().toString()).isEqualTo(TestUtils.RELEASE_SOFTWAREHERITGAE_ID); assertThat(release.getCoordinates()).hasSize(1); assertThat(release.getCoordinates().containsKey("maven")).isTrue(); assertThat(release.getCoordinates().get("maven")).isEqualTo("pkg:maven/org.group.id/artifactIdTest1@" + TestUtils.RELEASE_VERSION1); assertThat(release.getHashes()).hasSize(1); assertThat(release.getHashes()). isEqualTo(artifact.askForAll(ArtifactFilename.class) .stream() .map(ArtifactFilename::getArtifactFilenameEntries) .flatMap(Collection::stream) .map(ArtifactFilename.ArtifactFilenameEntry::getHash) .collect(Collectors.toSet())); assertThat(release.getOverriddenLicense()).isEqualTo(TestUtils.RELEASE_OVERRIDEN_LICENSE); assertThat(release.getDeclaredLicense()).isEqualTo(TestUtils.RELEASE_DECLEARED_LICENSE); assertThat(release.getObservedLicense()).isEqualTo(TestUtils.RELEASE_OBSERVED_LICENSE); assertThat(release.getCopyrights()).isEqualTo(TestUtils.RELEASE_COPYRIGHT); }
@Test public void artifactIsMappedToSw360ReleaseCorrectlyWithoutOverwritten() { Artifact artifact = TestUtils.mkArtifact("Test1", false); SW360Component sw360Component = new SW360Component(); sw360Component.setName("artifactIdtest1"); SW360Release release = ArtifactToReleaseUtils.convertToReleaseWithoutAttachments(artifact); assertThat(release.getClearingState()).isEqualTo(TestUtils.RELEASE_CLEARING_STATE); assertThat(release.getChangeStatus()).isEqualTo(TestUtils.RELEASE_CHANGESTATUS); assertThat(release.getDownloadurl()).isEqualTo(TestUtils.RELEASE_DOWNLOAD_URL); assertThat(release.getReleaseTagUrl()).isEqualTo(TestUtils.RELEASE_RELEASE_TAG_URL); assertThat(release.getSoftwareHeritageId()).isEqualTo(TestUtils.RELEASE_SOFTWAREHERITGAE_ID); new ArtifactSoftwareHeritageID.Builder(release.getSoftwareHeritageId()).build(); assertThat(release.getCoordinates()).containsKeys("maven"); assertThat(release.getCoordinates()).hasSize(1); assertThat(release.getCoordinates()).containsValue("pkg:maven/org.group.id/artifactIdTest1@" + TestUtils.RELEASE_VERSION1); assertThat(release.getHashes()).hasSize(1); assertThat(release.getHashes()). isEqualTo(artifact.askForAll(ArtifactFilename.class) .stream() .map(ArtifactFilename::getArtifactFilenameEntries) .flatMap(Collection::stream) .map(ArtifactFilename.ArtifactFilenameEntry::getHash) .collect(Collectors.toSet())); assertThat(release.getOverriddenLicense()).isNull(); assertThat(release.getObservedLicense()).isEqualTo(TestUtils.RELEASE_OBSERVED_LICENSE); assertThat(release.getDeclaredLicense()).isEqualTo(TestUtils.RELEASE_DECLEARED_LICENSE); assertThat(release.getCopyrights()).isEqualTo(TestUtils.RELEASE_COPYRIGHT); assertThat(release.getHomepageUrl()).isEqualTo(TestUtils.HOMEPAGE_URL); }
@Test public void testMainLicenseIsEmptyAndDetectedLicenseNull() { Artifact artifact = new Artifact("SW360"); artifact.setProprietary(false); artifact.addCoordinate(new Coordinate(Coordinate.Types.MAVEN, "org.group.id", "artifactIdTest", "1.2.3")); artifact.addFact(new DeclaredLicenseInformation(new LicenseStatement())); SW360Component sw360Component = new SW360Component(); sw360Component.setName("artifactIdTest"); SW360Release release = ArtifactToReleaseUtils.convertToReleaseWithoutAttachments(artifact); release.setComponentId(sw360Component.getId()); release.setMainLicenseIds(Collections.EMPTY_SET); assertThat(release.getOverriddenLicense()).isNull(); assertThat(release.getMainLicenseIds().isEmpty()).isTrue(); }
@Test public void testArtifactWithoutFacts() { Artifact artifact = new Artifact() .setProprietary(false); thrownException.expect(ExecutionException.class); thrownException.expectMessage("does not have enough facts to create a component name."); ArtifactToReleaseUtils.convertToReleaseWithoutAttachments(artifact); }