| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
package org.tap4j.representer; |
| 25 | |
|
| 26 | |
import java.io.PrintWriter; |
| 27 | |
import java.io.StringWriter; |
| 28 | |
|
| 29 | |
import org.tap4j.model.BailOut; |
| 30 | |
import org.tap4j.model.TapResult; |
| 31 | |
import org.tap4j.model.TestResult; |
| 32 | |
import org.tap4j.model.TestSet; |
| 33 | |
import org.tap4j.util.DirectiveValues; |
| 34 | |
import org.tap4j.util.StatusValues; |
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
public class TapJunitRepresenter implements Representer { |
| 43 | |
|
| 44 | |
private String name; |
| 45 | |
|
| 46 | 0 | public TapJunitRepresenter(String name) { |
| 47 | 0 | this.name = name; |
| 48 | 0 | } |
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
public String representData(TestSet testSet) { |
| 56 | 0 | StringWriter sw = new StringWriter(); |
| 57 | 0 | PrintWriter pw = new PrintWriter(sw); |
| 58 | 0 | pw.println("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); |
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | 0 | Statuses statuses = this.getStatuses(testSet); |
| 64 | 0 | pw.println("<testsuite failures=\"" + statuses.getFailures() + "\" " + |
| 65 | |
"time=\"" + statuses.getTime() + "\" errors=\"" + |
| 66 | |
statuses.getErrors() + "\" " + "skipped=\"" + |
| 67 | |
statuses.getSkipped() + "\" tests=\"" + statuses.getTests() + |
| 68 | |
"\" " + "name=\"" + this.name + "\">"); |
| 69 | |
|
| 70 | 0 | for (TapResult tapLine : testSet.getTapLines()) { |
| 71 | 0 | if (tapLine instanceof TestResult) { |
| 72 | 0 | pw.println("<testcase time=\"0\" classname=\"" + this.name + |
| 73 | |
"\" name=\"" + |
| 74 | |
((TestResult) tapLine).getDescription() + "\">"); |
| 75 | 0 | if (((TestResult) tapLine).getDirective() != null && |
| 76 | |
((TestResult) tapLine).getDirective().getDirectiveValue() == DirectiveValues.SKIP) { |
| 77 | 0 | pw.println("<skipped/>"); |
| 78 | |
} |
| 79 | 0 | if (((TestResult) tapLine).getStatus() == StatusValues.NOT_OK) { |
| 80 | 0 | pw.println("<failure message=\"" + |
| 81 | |
((TestResult) tapLine).getDescription() + |
| 82 | |
"\" type=\"Failure\" />"); |
| 83 | |
} |
| 84 | 0 | pw.println("</testcase>"); |
| 85 | |
} |
| 86 | 0 | if (tapLine instanceof BailOut) { |
| 87 | 0 | pw.println("<testcase time=\"0\" classname=\"" + this.name + |
| 88 | |
"\" name=\"" + ((BailOut) tapLine).getReason() + |
| 89 | |
"\">"); |
| 90 | 0 | pw.println("<error message=\"" + |
| 91 | |
((BailOut) tapLine).getReason() + |
| 92 | |
"\" type=\"BailOut\"/>"); |
| 93 | 0 | pw.println("</testcase>"); |
| 94 | |
} |
| 95 | |
} |
| 96 | 0 | pw.println("</testsuite>"); |
| 97 | 0 | return sw.toString(); |
| 98 | |
} |
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
private Statuses getStatuses(TestSet testSet) { |
| 105 | 0 | Statuses statuses = new Statuses(); |
| 106 | 0 | statuses.setErrors(testSet.getBailOuts().size()); |
| 107 | 0 | for (TestResult tr : testSet.getTestResults()) { |
| 108 | 0 | statuses.setTests(statuses.getTests() + 1); |
| 109 | 0 | if (tr.getDirective() != null && |
| 110 | |
tr.getDirective().getDirectiveValue() == DirectiveValues.SKIP) { |
| 111 | 0 | statuses.setSkipped(statuses.getSkipped() + 1); |
| 112 | 0 | } else if (tr.getStatus() == StatusValues.NOT_OK) { |
| 113 | 0 | statuses.setFailures(statuses.getFailures() + 1); |
| 114 | |
} |
| 115 | |
} |
| 116 | 0 | return statuses; |
| 117 | |
} |
| 118 | |
|
| 119 | |
} |
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
class Statuses { |
| 128 | |
|
| 129 | |
private int errors; |
| 130 | |
|
| 131 | |
private int failures; |
| 132 | |
|
| 133 | |
private int skipped; |
| 134 | |
|
| 135 | |
private int tests; |
| 136 | |
|
| 137 | |
private double time; |
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
public Statuses() { |
| 143 | 0 | super(); |
| 144 | 0 | } |
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
public Statuses(int errors, int failures, int skipped, int tests, |
| 154 | |
double time) { |
| 155 | 0 | super(); |
| 156 | 0 | this.errors = errors; |
| 157 | 0 | this.failures = failures; |
| 158 | 0 | this.skipped = skipped; |
| 159 | 0 | this.tests = tests; |
| 160 | 0 | this.time = time; |
| 161 | 0 | } |
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
public int getErrors() { |
| 167 | 0 | return errors; |
| 168 | |
} |
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
public void setErrors(int errors) { |
| 174 | 0 | this.errors = errors; |
| 175 | 0 | } |
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
public int getFailures() { |
| 181 | 0 | return failures; |
| 182 | |
} |
| 183 | |
|
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
public void setFailures(int failures) { |
| 188 | 0 | this.failures = failures; |
| 189 | 0 | } |
| 190 | |
|
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | |
public int getSkipped() { |
| 195 | 0 | return skipped; |
| 196 | |
} |
| 197 | |
|
| 198 | |
|
| 199 | |
|
| 200 | |
|
| 201 | |
public void setSkipped(int skipped) { |
| 202 | 0 | this.skipped = skipped; |
| 203 | 0 | } |
| 204 | |
|
| 205 | |
|
| 206 | |
|
| 207 | |
|
| 208 | |
public int getTests() { |
| 209 | 0 | return tests; |
| 210 | |
} |
| 211 | |
|
| 212 | |
|
| 213 | |
|
| 214 | |
|
| 215 | |
public void setTests(int tests) { |
| 216 | 0 | this.tests = tests; |
| 217 | 0 | } |
| 218 | |
|
| 219 | |
|
| 220 | |
|
| 221 | |
|
| 222 | |
public double getTime() { |
| 223 | 0 | return time; |
| 224 | |
} |
| 225 | |
|
| 226 | |
|
| 227 | |
|
| 228 | |
|
| 229 | |
public void setTime(double time) { |
| 230 | 0 | this.time = time; |
| 231 | 0 | } |
| 232 | |
|
| 233 | |
} |