-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
219 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/main/java/hudson/tasks/test/TestResultActionIterable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package hudson.tasks.test; | ||
|
||
import edu.hm.hafner.echarts.Build; | ||
import edu.hm.hafner.echarts.BuildResult; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import hudson.model.Run; | ||
import java.util.Iterator; | ||
import java.util.NoSuchElementException; | ||
|
||
public class TestResultActionIterable implements Iterable<BuildResult<AbstractTestResultAction<?>>> { | ||
private final AbstractTestResultAction<?> latestAction; | ||
|
||
/** | ||
* Creates a new iterator that selects action of the given type {@code actionType}. | ||
* | ||
* @param baseline | ||
* the baseline to start from | ||
*/ | ||
public TestResultActionIterable(final AbstractTestResultAction<?> baseline) { | ||
this.latestAction = baseline; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public Iterator<BuildResult<AbstractTestResultAction<?>>> iterator() { | ||
if (latestAction == null) { | ||
return new TestResultActionIterator(null); | ||
} | ||
return new TestResultActionIterator(latestAction); | ||
} | ||
|
||
private static class TestResultActionIterator implements Iterator<BuildResult<AbstractTestResultAction<?>>> { | ||
private AbstractTestResultAction<?> cursor; | ||
private AbstractTestResultAction<?> initialValue; | ||
|
||
/** | ||
* Creates a new iterator starting from the baseline. | ||
* | ||
* @param baseline | ||
* the run to start from | ||
*/ | ||
TestResultActionIterator(final AbstractTestResultAction<?> baseline) { | ||
initialValue = baseline; | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
if (initialValue != null) { | ||
return true; | ||
} | ||
|
||
if (cursor == null) { | ||
return false; | ||
} | ||
|
||
AbstractTestResultAction<?> previousBuild = cursor.getPreviousResult(AbstractTestResultAction.class, true); | ||
return previousBuild != null; | ||
} | ||
|
||
@Override | ||
public BuildResult<AbstractTestResultAction<?>> next() { | ||
if (initialValue == null && cursor == null) { | ||
throw new NoSuchElementException( | ||
"There is no action available anymore. Use hasNext() before calling next()."); | ||
} | ||
AbstractTestResultAction<?> buildAction = getBuildAction(); | ||
if (buildAction != null) { | ||
cursor = buildAction; | ||
Run<?, ?> run = cursor.run; | ||
|
||
int buildTimeInSeconds = (int) (run.getTimeInMillis() / 1000); | ||
Build build = new Build(run.getNumber(), run.getDisplayName(), buildTimeInSeconds); | ||
return new BuildResult<>(build, buildAction); | ||
} | ||
|
||
throw new NoSuchElementException("No more runs with a test result available: " + cursor); | ||
} | ||
|
||
private AbstractTestResultAction<?> getBuildAction() { | ||
AbstractTestResultAction<?> run; | ||
if (initialValue != null) { | ||
run = initialValue; | ||
initialValue = null; | ||
} else { | ||
run = cursor.getPreviousResult(AbstractTestResultAction.class, true); | ||
} | ||
return run; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package hudson.tasks.test; | ||
|
||
import edu.hm.hafner.echarts.ChartModelConfiguration; | ||
import edu.hm.hafner.echarts.LineSeries; | ||
import edu.hm.hafner.echarts.LinesChartModel; | ||
import edu.hm.hafner.echarts.LinesDataSet; | ||
import edu.hm.hafner.echarts.Palette; | ||
|
||
public class TestResultTrendChart { | ||
|
||
public LinesChartModel create(final Iterable results, | ||
final ChartModelConfiguration configuration) { | ||
TestResultTrendSeriesBuilder builder = new TestResultTrendSeriesBuilder(); | ||
LinesDataSet dataSet = builder.createDataSet(configuration, results); | ||
|
||
LinesChartModel model = new LinesChartModel(); | ||
model.setDomainAxisLabels(dataSet.getDomainAxisLabels()); | ||
model.setBuildNumbers(dataSet.getBuildNumbers()); | ||
|
||
LineSeries failed = new LineSeries("Failed", Palette.RED.getNormal(), | ||
LineSeries.StackedMode.STACKED, LineSeries.FilledMode.FILLED); | ||
failed.addAll(dataSet.getSeries(TestResultTrendSeriesBuilder.FAILED_KEY)); | ||
model.addSeries(failed); | ||
|
||
LineSeries skipped = new LineSeries("Skipped", Palette.GRAY.getNormal(), | ||
LineSeries.StackedMode.STACKED, LineSeries.FilledMode.FILLED); | ||
skipped.addAll(dataSet.getSeries(TestResultTrendSeriesBuilder.SKIPPED_KEY)); | ||
model.addSeries(skipped); | ||
|
||
LineSeries passed = new LineSeries("Passed", Palette.BLUE.getNormal(), | ||
LineSeries.StackedMode.STACKED, LineSeries.FilledMode.FILLED); | ||
passed.addAll(dataSet.getSeries(TestResultTrendSeriesBuilder.PASSED_KEY)); | ||
model.addSeries(passed); | ||
|
||
return model; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/hudson/tasks/test/TestResultTrendSeriesBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package hudson.tasks.test; | ||
|
||
import edu.hm.hafner.echarts.SeriesBuilder; | ||
import hudson.tasks.junit.TestResultAction; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class TestResultTrendSeriesBuilder extends SeriesBuilder<AbstractTestResultAction> { | ||
static final String TOTALS_KEY = "total"; | ||
static final String PASSED_KEY = "passed"; | ||
static final String FAILED_KEY = "failed"; | ||
static final String SKIPPED_KEY = "skipped"; | ||
|
||
@Override | ||
protected Map<String, Integer> computeSeries(AbstractTestResultAction testResultAction) { | ||
Map<String, Integer> series = new HashMap<>(); | ||
series.put(TOTALS_KEY, testResultAction.getTotalCount()); | ||
series.put(PASSED_KEY, testResultAction.getPassedTests().size()); | ||
series.put(FAILED_KEY, testResultAction.getFailCount()); | ||
series.put(SKIPPED_KEY, testResultAction.getSkipCount()); | ||
return series; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters