MatchStateValidator extends AbstractComplianceChecker { @Override public IPolicyEvaluation evaluate(Collection<Artifact> artifacts) { DefaultPolicyEvaluation policyEvaluation = new DefaultPolicyEvaluation(); artifacts.stream() .filter(artifact -> !artifact.getFlag(Artifact.IS_PROPRIETARY_FLAG_KEY)) .forEach(artifact -> { final Optional<ArtifactMatchingMetadata> artifactMatchingMetadata = artifact.askFor(ArtifactMatchingMetadata.class); if(! artifactMatchingMetadata.isPresent()) { return; } MatchState artifactsMatchState = artifactMatchingMetadata.get().getMatchState(); if (MatchState.SIMILAR.equals(artifactsMatchState)) { policyEvaluation.addEvaluationResult("MatchStateValidator::rule", "The match State is SIMILAR", SIMILAR_Severity, artifact); }else if (MatchState.UNKNOWN.equals(artifactsMatchState)) { policyEvaluation.addEvaluationResult("MatchStateValidator::rule", "The match State is UNKNOWN", UNKNOWN_Severity, artifact); } }); return policyEvaluation; } MatchStateValidator(); @Override IPolicyEvaluation evaluate(Collection<Artifact> artifacts); @Override String getRulesetDescription(); @Override void configure(Map<String, String> configMap);  }
@Test public void validateMatchStateTest1() { List<Artifact> artifacts = new ArrayList<>(); artifacts.add(artifactEXACT); artifacts.add(artifactProprietaryUNKNOWN); artifacts.add(artifactProprietaryEXACT); artifacts.add(artifactUNKNOWN); assertThat(matchStateValidator.evaluate(artifacts).getEvaluationResults().size()).isEqualTo(1); }
@Test public void validateMatchStateTest2() { List<Artifact> artifacts = new ArrayList<>(); artifacts.add(artifactEXACT); artifacts.add(artifactProprietaryUNKNOWN); artifacts.add(artifactProprietaryEXACT); assertThat(matchStateValidator.evaluate(artifacts).getEvaluationResults().size()).isEqualTo(0); }
@Test public void validateMatchStateTest3() { List<Artifact> artifacts = new ArrayList<>(); artifacts.add(artifactEXACT); artifacts.add(artifactProprietaryUNKNOWN); assertThat(matchStateValidator.evaluate(artifacts).getEvaluationResults().size()).isEqualTo(0); }
@Test public void validateMatchStateTest4() { List<Artifact> artifacts = new ArrayList<>(); artifacts.add(artifactEXACT); assertThat(matchStateValidator.evaluate(artifacts).getEvaluationResults().size()).isEqualTo(0); }