LicenseKnowledgeBaseResolver extends AbstractProcessor { @Override public Collection<Artifact> process(Collection<Artifact> artifacts) { return new LicenseKnowledgeBaseResolverImpl(knowledgeBase).resolveKnowledgeBase(artifacts); } LicenseKnowledgeBaseResolver();  LicenseKnowledgeBaseResolver(ILicenseManagementKnowledgeBase knowledgeBase);  LicenseKnowledgeBaseResolver(ILicenseManagementKnowledgeBase knowledgeBase,
                                        Supplier<List<ILicenseManagementKnowledgeBase>> supplier); ILicenseManagementKnowledgeBase getKnowledgeBase(); @Override Collection<Artifact> process(Collection<Artifact> artifacts); @Override void configure(Map<String,String> configMap);  }
@Test public void testArtifactWithOnlyKnownLicenseId() { License license = new License(); license.setId(LICENSE_ID); Artifact artifact = new Artifact(); artifact.addFact(new ConfiguredLicenseInformation(license)); knowledgeBaseResolver.process(Collections.singletonList(artifact)); final Collection<License> finalLicenses = ArtifactLicenseUtils.getFinalLicenses(artifact).getLicenses(); assertThat(finalLicenses.size()).isEqualTo(1); assertThat(finalLicenses.stream() .findAny()) .hasValueSatisfying(l -> { assertThat(l.getId()).isEqualTo(LICENSE_ID); assertThat(l.getCommonName()).isEqualTo(LICENSE_NAME); assertThat(l.getText()).isEqualTo(LICENSE_TEXT); assertThat(l.getThreatGroup()).hasValue(LICENSE_THREAT_GROUP); assertThat(l.getClassification()).hasValue(LICENSE_CLASSIFICATION); }); }
@Test public void testArtifactWithFullyConfiguredLicense() { License license = new License(); license.setId(LICENSE_ID); license.setCommonName(LICENSE_NAME); license.setText(LICENSE_TEXT); license.setThreatGroup(LICENSE_THREAT_GROUP); license.setClassification(LICENSE_CLASSIFICATION); Artifact artifact = new Artifact(); artifact.addFact(new ConfiguredLicenseInformation(license)); knowledgeBaseResolver.process(Collections.singletonList(artifact)); final Collection<License> finalLicenses = ArtifactLicenseUtils.getFinalLicenses(artifact).getLicenses(); assertThat(finalLicenses.size()).isEqualTo(1); assertThat(finalLicenses.stream() .findAny()) .hasValueSatisfying(l -> { assertThat(l.getId()).isEqualTo(LICENSE_ID); assertThat(l.getCommonName()).isEqualTo(LICENSE_NAME); assertThat(l.getText()).isEqualTo(LICENSE_TEXT); assertThat(l.getThreatGroup()).hasValue(LICENSE_THREAT_GROUP); assertThat(l.getClassification()).hasValue(LICENSE_CLASSIFICATION); }); }
@Test public void testArtifactWithUnknownLicense() { String licenseName = "Unknown license"; License license = new License(); license.setId(licenseName); Artifact artifact = new Artifact(); artifact.addFact(new ConfiguredLicenseInformation(license)); knowledgeBaseResolver.process(Collections.singletonList(artifact)); final Collection<License> finalLicenses = ArtifactLicenseUtils.getFinalLicenses(artifact).getLicenses(); assertThat(finalLicenses.size()).isEqualTo(1); assertThat(finalLicenses.stream() .findAny()).hasValueSatisfying(l -> { assertThat(l.getId()).isEqualTo(licenseName); assertThat(l.getCommonName()).isBlank(); assertThat(l.getText()).isBlank(); assertThat(l.getThreatGroup()).isNotPresent(); assertThat(l.getClassification()).isNotPresent(); }); }