CsvAnalyzer extends ManualAnalyzer { @Override public WorkflowStepResult yield() { Collection<Artifact> artifacts = new CSVArtifactMapper( componentInfoFile.toPath(), context.getToolConfiguration().getEncoding(), rowDelimiter, baseDir).createArtifactsList(); return new WorkflowStepResult(artifacts, true); } CsvAnalyzer(); @Override WorkflowStepResult yield(); @Override void configure(Map<String, String> configMap); @Override String getName();  }
@Test public void testThatDataIsFullyMapped() throws URISyntaxException { configureAnalyzer("dependencies.csv", ","); Set<Artifact> artifacts = analyzer.yield().getArtifacts(); Artifact foundArtifact = artifacts.stream() .filter(artifact -> "commons-csv".equals(artifact.getCoordinateForType(PackageURL.StandardTypes.MAVEN) .map(Coordinate::getName) .orElse(""))) .findFirst() .get(); commonsCsvFullDependencyCheck(foundArtifact); assertThat(foundArtifact.askFor(CopyrightStatement.class).get()).isEqualTo(new CopyrightStatement("Copyright 2005-2016 The Apache Software Foundation")); }
@Test public void testThatSourcesIsMappedCorrectly() throws URISyntaxException { configureAnalyzer("dependencyWithSource.csv", ","); Set<Artifact> artifacts = analyzer.yield().getArtifacts(); Artifact foundArtifact = artifacts.stream() .findFirst() .get(); Optional<ArtifactSourceFile> artifactSourceFile = foundArtifact.askFor(ArtifactSourceFile.class); assertThat(artifactSourceFile.isPresent()).isTrue(); assertThat(artifactSourceFile.get().get().toFile()).exists(); assertThat(artifactSourceFile.get().get().toAbsolutePath()). isEqualTo(Paths.get(this.getClass().getClassLoader().getResource("CsvAnalyzerTest/test_source.txt").toURI())); }
@Test public void testThatMissingSourcesDontGetMapped() throws URISyntaxException { configureAnalyzer("dependencyWithMissingSource.csv", ","); Set<Artifact> artifacts = analyzer.yield().getArtifacts(); Artifact foundArtifact = artifacts.stream() .findFirst() .get(); assertThat(foundArtifact.askFor(ArtifactSourceFile.class)).isNotPresent(); }
@Test public void testExistenceOfClearingDocumentIsChecked() throws URISyntaxException { configureAnalyzer("dependencies.csv", ","); Set<Artifact> artifacts = analyzer.yield().getArtifacts(); Artifact foundArtifact = artifacts.stream() .filter(artifact -> "commons-cli".equals(artifact.getCoordinateForType(PackageURL.StandardTypes.MAVEN) .map(Coordinate::getName) .orElse(""))) .findFirst() .get(); assertThat(foundArtifact.askFor(ArtifactClearingDocument.class)).isNotPresent(); }
@Test public void testCopyrightsIsParsedCorrectly() throws URISyntaxException { configureAnalyzer("dependencyWithMultipleCopyrights.csv", ","); Set<Artifact> artifacts = analyzer.yield().getArtifacts(); assertThat(artifacts).hasSize(2); assertThat(artifacts.stream().map(artifact1 -> artifact1.askForGet(CopyrightStatement.class).get()) .anyMatch(copyrightStatement -> copyrightStatement.equals(new CopyrightStatement("Copyright 2005-2016 The Apache Software Foundation") .mergeWith(new CopyrightStatement("Copyright 2020 Fake Company")) .mergeWith(new CopyrightStatement("Copyright 2020 Fake the 2nd")).get()))).isTrue(); }
@Test public void testMergeOfDuplicateArtifact() throws URISyntaxException { configureAnalyzer("dependencyWithMultipleHashes.csv", ","); Set<Artifact> artifacts = analyzer.yield().getArtifacts(); Artifact artifact0 = artifacts.iterator().next(); assertThat(artifact0.askFor(ArtifactFilename.class).get().getArtifactFilenameEntries()).hasSize(2); }
@Test public void testCsvAnalyzerWithSemicolonseparator() throws URISyntaxException { configureAnalyzer("dependenciesWithExcelFormat.csv", ";"); Set<Artifact> artifacts = analyzer.yield().getArtifacts(); assertThat(artifacts).hasSize(2); Artifact foundArtifact = artifacts.stream() .filter(artifact -> "commons-csv".equals(artifact.getCoordinateForType(PackageURL.StandardTypes.MAVEN) .map(Coordinate::getName) .orElse(""))) .findFirst() .get(); commonsCsvFullDependencyCheck(foundArtifact); assertThat(foundArtifact.askFor(CopyrightStatement.class).get()) .isEqualTo(new CopyrightStatement("Copyright 2005-2016 The Apache Software Foundation") .mergeWith(new CopyrightStatement("Copyright, 2020 the fake")) .mergeWith(new CopyrightStatement("Copyright fake; the third"))); List<String> hashes = foundArtifact.askFor(ArtifactFilename.class).get(). getArtifactFilenameEntries().stream() .map(ArtifactFilename.ArtifactFilenameEntry::getHash) .collect(Collectors.toList()); assertThat(hashes).hasSize(2); Artifact cliArtifact = artifacts.stream() .filter(artifact -> "commons-cli".equals(artifact.getCoordinateForType(PackageURL.StandardTypes.MAVEN) .map(Coordinate::getName) .orElse(""))) .findFirst() .get(); assertThat(cliArtifact.askFor(CopyrightStatement.class).get()).isEqualTo( new CopyrightStatement("Copyright 2005-2016 The Apache Software Foundation") .mergeWith(new CopyrightStatement("copy & paste")) .mergeWith(new CopyrightStatement("this is $ it")) .mergeWith(new CopyrightStatement("!nevermind")) .mergeWith(new CopyrightStatement("§copsright")) .mergeWith(new CopyrightStatement("%gsp")) .mergeWith(new CopyrightStatement("?")) .mergeWith(new CopyrightStatement("`wer`")) .mergeWith(new CopyrightStatement("#wtewp")) .mergeWith(new CopyrightStatement("~fjd")) ); }