SourceValidator extends AbstractComplianceChecker { @Override public IPolicyEvaluation evaluate(Collection<Artifact> artifacts) { DefaultPolicyEvaluation policyEvaluation = new DefaultPolicyEvaluation(); artifacts.stream() .filter(artifact -> ! artifact.getFlag(Artifact.IS_PROPRIETARY_FLAG_KEY)) .filter(artifact -> artifact.getCoordinateForType(Coordinate.Types.MAVEN).isPresent()) .forEach(artifact -> validateSources(artifact) .forEach(policyEvaluation::addEvaluationResult)); return policyEvaluation; } SourceValidator(); @Override IPolicyEvaluation evaluate(Collection<Artifact> artifacts); @Override String getRulesetDescription(); @Override void configure(Map<String, String> configMap);  }
@Test public void testWithCompleteSources() throws IOException { Artifact artifact = setupForTest(100); final IPolicyEvaluation evaluate = validator.evaluate(Collections.singleton(artifact)); assertThat(evaluate).isNotNull(); assertThat(evaluate.getEvaluationResults().size()).isEqualTo(0); }
@Test public void testWithNearlyCompleteSources() throws IOException { Artifact artifact = setupForTest(95); final IPolicyEvaluation evaluate = validator.evaluate(Collections.singleton(artifact)); assertThat(evaluate).isNotNull(); assertThat(evaluate.getEvaluationResults().size()).isEqualTo(0); }
@Test public void testWithNonCompleteSources() throws IOException { Artifact artifact = setupForTest(0); final IPolicyEvaluation evaluate = validator.evaluate(Collections.singleton(artifact)); assertThat(evaluate).isNotNull(); assertThat(evaluate.getEvaluationResults().size()).isEqualTo(1); assertThat(evaluate.getEvaluationResults().stream() .findFirst() .get() .getSeverity()).isEqualTo(IEvaluationResult.Severity.WARN); }
@Test public void testWithNonCompleteSourcesAndFail() throws IOException { Artifact artifact = setupForTest(Collections.singletonMap("incompleteSourcesSeverity", "FAIL"), 0); final IPolicyEvaluation evaluate = validator.evaluate(Collections.singleton(artifact)); assertThat(evaluate).isNotNull(); assertThat(evaluate.getEvaluationResults().size()).isEqualTo(1); assertThat(evaluate.getEvaluationResults().stream() .findFirst() .get() .getSeverity()).isEqualTo(IEvaluationResult.Severity.FAIL); }
@Test public void testWithHalfCompleteSourcesAndLowThreshold() throws IOException { Artifact artifact = setupForTest(Collections.singletonMap("threshold", "40"), 50); final IPolicyEvaluation evaluate = validator.evaluate(Collections.singleton(artifact)); assertThat(evaluate).isNotNull(); assertThat(evaluate.getEvaluationResults().size()).isEqualTo(0 ); }
@Test public void testWithHalfCompleteSources() throws IOException { Artifact artifact = setupForTest(50); final IPolicyEvaluation evaluate = validator.evaluate(Collections.singleton(artifact)); assertThat(evaluate).isNotNull(); assertThat(evaluate.getEvaluationResults().size()).isEqualTo(1); }
@Test public void testWithHalfCompleteSourcesAndWhitelist() throws IOException { Artifact artifact = setupForTest(Collections.emptyMap(), 50, Collections.emptyList(), Collections.singletonList(mkArtifactIdentifier())); final IPolicyEvaluation evaluate = validator.evaluate(Collections.singleton(artifact)); assertThat(evaluate).isNotNull(); assertThat(evaluate.getEvaluationResults().size()).isEqualTo(0); }
@Test public void testWithHalfCompleteSourcesAndWhitelistInATransitiveWay() throws IOException { Artifact artifact = setupForTest(Collections.emptyMap(), 50, Collections.singletonList(mkArtifactIdentifier()), Collections.emptyList()); final IPolicyEvaluation evaluate = validator.evaluate(Collections.singleton(artifact)); assertThat(evaluate).isNotNull(); assertThat(evaluate.getEvaluationResults().size()).isEqualTo(0); }