Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
Fixed results logging of quality gate.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Mar 10, 2018
1 parent 91cf891 commit 95043f2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 39 deletions.
Expand Up @@ -223,71 +223,71 @@ public Result getOverallResult() {
return Result.SUCCESS;
}

public Collection<String> getEvaluations(final AnalysisResult issues, final Thresholds thresholds) {
public Collection<String> getEvaluations(final AnalysisResult result, final QualityGate thresholds) {
List<String> messages = new ArrayList<>();
if (!totalFailed.isTotalReached()) {
if (totalFailed.isTotalReached()) {
messages.add(String.format("FAILURE -> Total number of issues: %d - Quality Gate: %d",
issues.getTotalSize(), thresholds.failedTotalAll));
result.getTotalSize(), thresholds.getTotalFailedThreshold().getTotalThreshold()));
}
if (!totalFailed.isHighReached()) {
if (totalFailed.isHighReached()) {
messages.add(String.format("FAILURE -> Number of high priority issues: %d - Quality Gate: %d",
issues.getTotalHighPrioritySize(), thresholds.failedTotalHigh));
result.getTotalHighPrioritySize(), thresholds.getTotalFailedThreshold().getHighThreshold()));
}
if (!totalFailed.isNormalReached()) {
if (totalFailed.isNormalReached()) {
messages.add(String.format("FAILURE -> Number of normal priority issues: %d - Quality Gate: %d",
issues.getTotalNormalPrioritySize(), thresholds.failedTotalNormal));
result.getTotalNormalPrioritySize(), thresholds.getTotalFailedThreshold().getNormalThreshold()));
}
if (!totalFailed.isLowReached()) {
if (totalFailed.isLowReached()) {
messages.add(String.format("FAILURE -> Number of low priority issues: %d - Quality Gate: %d",
issues.getTotalLowPrioritySize(), thresholds.failedTotalLow));
result.getTotalLowPrioritySize(), thresholds.getTotalFailedThreshold().getLowThreshold()));
}
if (!totalUnstable.isTotalReached()) {
if (totalUnstable.isTotalReached()) {
messages.add(String.format("UNSTABLE -> Total number of issues: %d - Quality Gate: %d",
issues.getTotalSize(), thresholds.unstableTotalAll));
result.getTotalSize(), thresholds.getTotalUnstableThreshold().getTotalThreshold()));
}
if (!totalUnstable.isHighReached()) {
if (totalUnstable.isHighReached()) {
messages.add(String.format("UNSTABLE -> Number of high priority issues: %d - Quality Gate: %d",
issues.getTotalHighPrioritySize(), thresholds.unstableTotalHigh));
result.getTotalHighPrioritySize(), thresholds.getTotalUnstableThreshold().getHighThreshold()));
}
if (!totalUnstable.isNormalReached()) {
if (totalUnstable.isNormalReached()) {
messages.add(String.format("UNSTABLE -> Number of normal priority issues: %d - Quality Gate: %d",
issues.getTotalNormalPrioritySize(), thresholds.unstableTotalNormal));
result.getTotalNormalPrioritySize(), thresholds.getTotalUnstableThreshold().getNormalThreshold()));
}
if (!totalUnstable.isLowReached()) {
if (totalUnstable.isLowReached()) {
messages.add(String.format("UNSTABLE -> Number of low priority issues: %d - Quality Gate: %d",
issues.getTotalLowPrioritySize(), thresholds.unstableTotalLow));
result.getTotalLowPrioritySize(), thresholds.getTotalUnstableThreshold().getLowThreshold()));
}
if (!newFailed.isTotalReached()) {
if (newFailed.isTotalReached()) {
messages.add(String.format("FAILURE -> Number of new issues: %d - Quality Gate: %d",
issues.getNewSize(), thresholds.failedNewAll));
result.getNewSize(), thresholds.getNewFailedThreshold().getTotalThreshold()));
}
if (!newFailed.isHighReached()) {
if (newFailed.isHighReached()) {
messages.add(String.format("FAILURE -> Number of new high priority issues: %d - Quality Gate: %d",
issues.getNewHighPrioritySize(), thresholds.failedNewHigh));
result.getNewHighPrioritySize(), thresholds.getNewFailedThreshold().getHighThreshold()));
}
if (!newFailed.isNormalReached()) {
if (newFailed.isNormalReached()) {
messages.add(String.format("FAILURE -> Number of new normal priority issues: %d - Quality Gate: %d",
issues.getNewNormalPrioritySize(), thresholds.failedNewNormal));
result.getNewNormalPrioritySize(), thresholds.getNewFailedThreshold().getNormalThreshold()));
}
if (!newFailed.isLowReached()) {
if (newFailed.isLowReached()) {
messages.add(String.format("FAILURE -> Number of new low priority issues: %d - Quality Gate: %d",
issues.getNewLowPrioritySize(), thresholds.failedNewLow));
result.getNewLowPrioritySize(), thresholds.getNewFailedThreshold().getLowThreshold()));
}
if (!newUnstable.isTotalReached()) {
if (newUnstable.isTotalReached()) {
messages.add(String.format("UNSTABLE -> New number of new issues: %d - Quality Gate: %d",
issues.getNewSize(), thresholds.unstableNewAll));
result.getNewSize(), thresholds.getNewUnstableThreshold().getTotalThreshold()));
}
if (!newUnstable.isHighReached()) {
if (newUnstable.isHighReached()) {
messages.add(String.format("UNSTABLE -> Number of new high priority issues: %d - Quality Gate: %d",
issues.getNewHighPrioritySize(), thresholds.unstableNewHigh));
result.getNewHighPrioritySize(), thresholds.getNewUnstableThreshold().getHighThreshold()));
}
if (!newUnstable.isNormalReached()) {
if (newUnstable.isNormalReached()) {
messages.add(String.format("UNSTABLE -> Number of new normal priority issues: %d - Quality Gate: %d",
issues.getNewNormalPrioritySize(), thresholds.unstableNewNormal));
result.getNewNormalPrioritySize(), thresholds.getNewUnstableThreshold().getNormalThreshold()));
}
if (!newUnstable.isLowReached()) {
if (newUnstable.isLowReached()) {
messages.add(String.format("UNSTABLE -> Number of new low priority issues: %d - Quality Gate: %d",
issues.getNewLowPrioritySize(), thresholds.unstableNewLow));
result.getNewLowPrioritySize(), thresholds.getNewUnstableThreshold().getLowThreshold()));
}
return messages;
}
Expand Down
Expand Up @@ -27,31 +27,31 @@ public boolean isTotalThresholdReached(final int toCheck) {
return isSingleThresholdReached(getTotalThreshold(), toCheck);
}

private int getTotalThreshold() {
int getTotalThreshold() {
return totalThreshold;
}

public boolean isHighThresholdReached(final int toCheck) {
return isSingleThresholdReached(getHighThreshold(), toCheck);
}

private int getHighThreshold() {
int getHighThreshold() {
return highThreshold;
}

public boolean isNormalThresholdReached(final int toCheck) {
return isSingleThresholdReached(getNormalThreshold(), toCheck);
}

private int getNormalThreshold() {
int getNormalThreshold() {
return normalThreshold;
}

public boolean isLowThresholdReached(final int toCheck) {
return isSingleThresholdReached(getLowThreshold(), toCheck);
}

private int getLowThreshold() {
int getLowThreshold() {
return lowThreshold;
}

Expand Down
Expand Up @@ -6,16 +6,18 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import edu.hm.hafner.util.SerializableTest;
import io.jenkins.plugins.analysis.core.model.AnalysisResult;
import static io.jenkins.plugins.analysis.core.model.Assertions.*;
import io.jenkins.plugins.analysis.core.quality.QualityGate.QualityGateBuilder;
import io.jenkins.plugins.analysis.core.quality.QualityGate.QualityGateResult;
import io.jenkins.plugins.analysis.core.quality.ThresholdSet.ThresholdSetBuilder;

import static io.jenkins.plugins.analysis.core.model.Assertions.*;
import static org.mockito.Mockito.*;

import hudson.model.Result;

import edu.hm.hafner.util.SerializableTest;

/**
* Tests the class {@link QualityGate QualityGate}. These Tests were created while developing the class QualityGate.
*
Expand Down Expand Up @@ -126,6 +128,7 @@ void shouldBeSuccessWhenNoThresholdIsSetApiDemonstration() {

QualityGateResult qualityGateResult = qualityGate.evaluate(run);
assertThat(qualityGateResult).hasOverallResult(Result.SUCCESS);
assertThat(qualityGateResult.getEvaluations(mock(AnalysisResult.class), qualityGate)).isEmpty();
}

@Test
Expand Down

0 comments on commit 95043f2

Please sign in to comment.