net.masterthought.cucumber.json.Embedding Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cucumber-reporting Show documentation
Show all versions of cucumber-reporting Show documentation
Provides pretty html reports for Cucumber (Behaviour-Driven Development). It works by generating html from the
cucumber json report formatter. So can be used anywhere a json report is generated. Current use is in the
cucumber jenkins plugin and a maven mojo to generate the same report from mvn command line when running locally.
package net.masterthought.cucumber.json;
import java.nio.charset.StandardCharsets;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.apache.commons.lang.StringEscapeUtils;
import org.codehaus.plexus.util.Base64;
import net.masterthought.cucumber.json.deserializers.EmbeddingDeserializer;
/**
* @author Damian Szczepanik (damianszczepanik@github)
*/
@JsonDeserialize(using = EmbeddingDeserializer.class)
public class Embedding {
// Start: attributes from JSON file report
private final String mimeType;
private final String data;
// End: attributes from JSON file report
private final String fileId;
public Embedding(String mimeType, String data) {
this.mimeType = mimeType;
this.data = data;
this.fileId = "embedding_" + data.hashCode();
}
public String getMimeType() {
return mimeType;
}
public String getData() {
return data;
}
public String getDecodedData() {
return new String(Base64.decodeBase64(data.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8);
}
/** Returns encoded and escaped data so it is ready to display in HTML page. */
public String getEscapedDecodedData() {
return StringEscapeUtils.escapeHtml(getDecodedData());
}
public String getFileName() {
return fileId + "." + getExtension();
}
/** Returns file name without extension. */
public String getFileId() {
return fileId;
}
public String getExtension() {
switch (mimeType) {
case "image/png":
case "image/bmp":
case "image/jpeg":
case "text/html":
case "text/xml":
case "application/json":
case "application/xml":
return mimeType.substring(mimeType.indexOf('/') + 1);
// image available remotely stored as link/url
case "image/url":
return "image";
case "text/plain":
return "txt";
default:
return "unknown";
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy