use of com.carrotsearch.ant.tasks.junit4.gson.stream.JsonWriter in project randomizedtesting by randomizedtesting.
the class AggregatedSuiteResultEvent method serialize.
private void serialize(JsonWriter w, SimpleDateFormat sdf, AggregatedTestResultEvent e) throws IOException {
w.beginObject();
w.name("slave").value(e.getSlave().id);
w.name("startTimestamp").value(e.getStartTimestamp());
w.name("startTimestampDate").value(sdf.format(new Date(e.getStartTimestamp())));
w.name("executionTime").value(e.getExecutionTime());
w.name("description");
JsonHelpers.writeDescription(w, e.getDescription());
w.name("status").value(e.getStatus().name());
w.name("testFailures");
w.beginArray();
for (FailureMirror m : e.getFailures()) {
serialize(w, m);
}
w.endArray();
w.endObject();
}
use of com.carrotsearch.ant.tasks.junit4.gson.stream.JsonWriter in project randomizedtesting by randomizedtesting.
the class AggregatedSuiteResultEvent method serializeEvents.
private void serializeEvents(JsonWriter w, boolean outputStreams) throws IOException {
final Charset charset = getSlave().getCharset();
int lineBuffer = 160;
final StringWriter out = new StringWriter();
final StringWriter err = new StringWriter();
WriterOutputStream stdout = new WriterOutputStream(out, charset, lineBuffer, false);
WriterOutputStream stderr = new WriterOutputStream(err, charset, lineBuffer, false);
for (IEvent evt : getEventStream()) {
try {
switch(evt.getType()) {
case SUITE_FAILURE:
case TEST_IGNORED_ASSUMPTION:
case TEST_IGNORED:
case TEST_STARTED:
case TEST_FINISHED:
case TEST_FAILURE:
flushBoth(w, out, err, stdout, stderr);
w.beginObject();
w.name("event").value(evt.getType().toString());
w.name("description");
JsonHelpers.writeDescription(w, ((IDescribable) evt).getDescription());
if (evt instanceof FailureEvent) {
w.name("failure");
((FailureEvent) evt).serialize(w);
}
w.endObject();
break;
case APPEND_STDOUT:
if (outputStreams) {
flush(APPEND_STDERR, w, stderr, err);
((IStreamEvent) evt).copyTo(stdout);
}
break;
case APPEND_STDERR:
if (outputStreams) {
flush(APPEND_STDOUT, w, stdout, out);
((IStreamEvent) evt).copyTo(stderr);
}
break;
default:
break;
}
} catch (IOException ex) {
// Ignore.
}
}
flushBoth(w, out, err, stdout, stderr);
}
use of com.carrotsearch.ant.tasks.junit4.gson.stream.JsonWriter in project randomizedtesting by randomizedtesting.
the class AggregatedSuiteResultEvent method serialize.
public void serialize(JsonWriter w, boolean outputStreams) throws IOException {
w.beginObject();
w.name("slave").value(getSlave().id);
w.name("startTimestamp").value(getStartTimestamp());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.ROOT);
w.name("startTimestampDate").value(sdf.format(new Date(getStartTimestamp())));
w.name("executionTime").value(getExecutionTime());
w.name("description");
JsonHelpers.writeDescription(w, getDescription());
w.name("tests");
w.beginArray();
for (AggregatedTestResultEvent e : getTests()) {
serialize(w, sdf, e);
}
w.endArray();
w.name("suiteFailures");
w.beginArray();
for (FailureMirror m : getFailures()) {
serialize(w, m);
}
w.endArray();
w.name("executionEvents");
w.beginArray();
serializeEvents(w, outputStreams);
w.endArray();
w.endObject();
}
use of com.carrotsearch.ant.tasks.junit4.gson.stream.JsonWriter in project randomizedtesting by randomizedtesting.
the class TestRemoteEventSerialization method checkRoundtrip.
private void checkRoundtrip(RemoteEvent event) throws IOException {
StringWriter sw = new StringWriter();
final boolean lenient = randomBoolean();
JsonWriter jw = new JsonWriter(sw);
jw.setIndent(" ");
jw.setLenient(lenient);
event.serialize(jw);
jw.close();
String serialized1 = sw.toString();
JsonReader jr = new JsonReader(new StringReader(serialized1));
jr.setLenient(lenient);
RemoteEvent deserialized = event.getType().deserialize(jr);
// If we serialize again, the contents should be identical.
sw.getBuffer().setLength(0);
jw = new JsonWriter(sw);
jw.setIndent(" ");
jw.setLenient(lenient);
deserialized.serialize(jw);
jw.close();
String serialized2 = sw.toString();
if (!serialized2.equals(serialized1)) {
fail("Roundtrip serialization failed:\n1: " + serialized1 + "\n2: " + serialized2);
}
}
use of com.carrotsearch.ant.tasks.junit4.gson.stream.JsonWriter in project randomizedtesting by randomizedtesting.
the class JsonReport method setOuter.
/*
*
*/
@Override
public void setOuter(JUnit4 junit4) {
this.junit4 = junit4;
if (this.targetFile == null) {
throw new BuildException("'file' attribute is required (target file name ending in .html, .json or .jsonp).");
}
if (method == OutputMethod.HTML) {
if (Strings.isNullOrEmpty(jsonpMethod)) {
setJsonpMethod("testData");
} else if (!"testData".equals(jsonpMethod)) {
throw new BuildException("JSONP method must be empty or equal 'testData' for HTML output.");
}
}
if (method == OutputMethod.JSONP) {
if (Strings.isNullOrEmpty(jsonpMethod)) {
setJsonpMethod("testData");
}
}
try {
Files.createParentDirs(targetFile);
File jsonFile = targetFile;
if (method == OutputMethod.HTML) {
jsonFile = new File(removeExtension(targetFile.getAbsolutePath()) + ".jsonp");
}
writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(jsonFile)), Charsets.UTF_8);
if (!Strings.isNullOrEmpty(jsonpMethod)) {
writer.write(jsonpMethod);
writer.write("(");
}
jsonWriter = new JsonWriter(writer);
jsonWriter.setHtmlSafe(false);
jsonWriter.setIndent(" ");
// Main holder.
jsonWriter.beginObject();
// junit4 object with properties.
jsonWriter.name("junit4");
jsonWriter.beginObject();
jsonWriter.name("tests.seed");
jsonWriter.value(junit4.getSeed());
jsonWriter.name("project.name");
jsonWriter.value(getProjectName());
jsonWriter.endObject();
// suites and an array of suites follows.
jsonWriter.name("suites");
jsonWriter.beginArray();
} catch (IOException e) {
throw new BuildException("Could not emit JSON report.", e);
}
}
Aggregations