log) {
- log.forEach(this::setTestRunnerLogs);
- }
+ /**
+ * Creates the internal models by consuming a JSON archive from a previous
+ * run session. This provides the same functionality as available in earlier
+ * versions via appendExisting, with the exception of being
+ * accessible by all reporters instead of just one.
+ *
+ * @param jsonFile
+ * The JSON archive file
+ * @throws IOException
+ * Exception thrown if the jsonFile is not found
+ */
+ public void createDomainFromJsonArchive(File jsonFile) throws IOException {
+ }
- /**
- * Adds logs from test framework tools to the test-runner logs view (if
- * available in the reporter)
- *
- *
- * TestNG usage example:
- *
- *
- *
- * for (String s : Reporter.getOutput()) {
- * extent.setTestRunnerOutput(s);
- * }
- *
- *
- * @param log Log string from the test runner frameworks such as TestNG or JUnit
- */
- public void setTestRunnerOutput(String log) {
- setTestRunnerLogs(log);
- }
-
- /**
- * Tries to resolve a {@link ScreenCapture} location if the supplied path is not found using
- * default locations. This can resolve cases where the default path was supplied to be relative
- * for a FileReporter. If the absolute path is not determined, the supplied will be used.
- * below paths are used to locate the image:
- *
- *
- * target/
- * test-output//
- *
- *
- * @return {@link ExtentKlovReporter}
- */
- public ExtentReports tryResolveMediaPath() {
- setMediaPathResolveDir(IMAGE_PATH_RESOLVER_DIR);
- return this;
- }
-
- /**
- * Tries to resolve a {@link ScreenCapture} location if the supplied path is not found using
- * supplied locations. This can resolve cases where the default path was supplied to be relative
- * for a FileReporter. If the absolute path is not determined, the supplied will be used.
- *
- * @param paths Dirs used to create absolute path of the {@link Media} object
- *
- * @return {@link ExtentKlovReporter}
- */
- public ExtentReports tryResolveMediaPath(String[] paths) {
- setMediaPathResolveDir(paths);
- return this;
- }
+ /**
+ * Creates the internal models by consuming a JSON archive from a previous
+ * run session. This provides the same functionality as available in earlier
+ * versions via appendExisting, with the exception of being
+ * accessible by all reporters instead of just one.
+ *
+ * @param jsonFilePath
+ * The JSON archive file
+ * @throws IOException
+ * Exception thrown if the jsonFilePath is not found
+ */
+ public void createDomainFromJsonArchive(String jsonFilePath) throws IOException {
+ createDomainFromJsonArchive(new File(jsonFilePath));
+ }
- /**
- * Creates the internal models by consuming a JSON archive from a previous run
- * session. This provides the same functionality as available in earlier versions
- * via appendExisting, with the exception of being accessible by
- * all reporters instead of just one.
- *
- * @param jsonFile The JSON archive file
- * @throws IOException Exception thrown if the jsonFile is not found
- */
- public void createDomainFromJsonArchive(File jsonFile) throws IOException {
- TestModelReportBuilder modelBuilder = new TestModelReportBuilder();
- modelBuilder.createDomainFromJsonArchive(this, jsonFile);
- }
-
- /**
- * Creates the internal models by consuming a JSON archive from a previous run
- * session. This provides the same functionality as available in earlier versions
- * via appendExisting, with the exception of being accessible by
- * all reporters instead of just one.
- *
- * @param jsonFilePath The JSON archive file
- * @throws IOException Exception thrown if the jsonFilePath is not found
- */
- public void createDomainFromJsonArchive(String jsonFilePath) throws IOException {
- createDomainFromJsonArchive(new File(jsonFilePath));
- }
-
- /**
- * Use this setting when building post-execution reports, such as from TestNG
- * IReporter. This setting allows setting test with your own time-stamps. With
- * this enabled, Extent does not use time-stamps for tests at the time they were
- * created.
- *
- *
- * If this setting is enabled and time-stamps are not specified explicitly, the
- * time-stamps of test creation are used.
- *
- * @param useManualConfig Set to true if building reports at the end of
- * execution with manual configuration
- */
- public void setReportUsesManualConfiguration(boolean useManualConfig) {
- setAllowManualConfig(useManualConfig);
- }
-
- public Boolean getReportUsesManualConfiguration() {
- return getAllowManualConfig();
- }
+ /**
+ * Use this setting when building post-execution reports, such as from
+ * TestNG IReporter. This setting allows setting test with your own
+ * time-stamps. With this enabled, Extent does not use time-stamps for tests
+ * at the time they were created.
+ *
+ *
+ * If this setting is enabled and time-stamps are not specified explicitly,
+ * the time-stamps of test creation are used.
+ *
+ * @param useManualConfig
+ * Set to true if building reports at the end of execution with
+ * manual configuration
+ */
+ public void setReportUsesManualConfiguration(boolean useManualConfig) {
+ }
- /**
- * Type of AnalysisStrategy for the reporter. Not all reporters support this
- * setting.
- *
- *
- * There are 2 types of strategies available:
- *
- *
- * TEST: Shows analysis at the test and step level
- * SUITE: Shows analysis at the suite, test and step level
- *
- *
- * @param strategy {@link AnalysisStrategy} determines the type of analysis
- * (dashboard) created for the reporter. Not all reporters will
- * support this setting.
- */
- @Override
- public void setAnalysisStrategy(AnalysisStrategy strategy) {
- super.setAnalysisStrategy(strategy);
- }
+ /**
+ * Type of AnalysisStrategy for the reporter. Not all reporters support this
+ * setting.
+ *
+ *
+ * There are 2 types of strategies available:
+ *
+ *
+ * TEST: Shows analysis at the test and step level
+ * SUITE: Shows analysis at the suite, test and step level
+ *
+ *
+ * @param strategy
+ * {@link AnalysisStrategy} determines the type of analysis
+ * (dashboard) created for the reporter. Not all reporters will
+ * support this setting.
+ */
+ @Override
+ public void setAnalysisStrategy(AnalysisStrategy strategy) {
+ getReport().getStats().setAnalysisStrategy(strategy);
+ }
- /**
- * Provides common report configurations
- *
- * @return an instance of {@link ReportConfigurator}
- */
- public ReportConfigurator config() {
- return ReportConfigurator.getInstance();
- }
-
- /**
- * Allows setting the target language for Gherkin keywords.
- *
- *
- * Default setting is "en"
- *
- * @param language A valid dialect from gherkin-languages.json
- *
- * @throws UnsupportedEncodingException Thrown if the language is one of the
- * supported language from gherkin-languages.json
- */
- public void setGherkinDialect(String language) throws UnsupportedEncodingException {
- GherkinDialectProvider.setLanguage(language);
- }
-
- /**
- * Returns an instance of {@link ReportStatusStats} with counts of tests
- * executed by their status (pass, fail, skip etc)
- *
- * @return an instance of {@link ReportStatusStats}
- */
- @Override
- public ReportStatusStats getStats() {
- return super.getStats();
- }
+ /**
+ * Allows setting the target language for Gherkin keywords.
+ *
+ *
+ * Default setting is "en"
+ *
+ * @param language
+ * A valid dialect from gherkin-languages.json
+ *
+ * @throws UnsupportedEncodingException
+ * Thrown if the language is one of the supported language from
+ * gherkin-languages.json
+ */
+ public void setGherkinDialect(String language) throws UnsupportedEncodingException {
+ GherkinDialectManager.setLanguage(language);
+ }
+ /**
+ * Returns an instance of {@link ReportStatusStats} with counts of tests
+ * executed by their status (pass, fail, skip etc)
+ *
+ * @return an instance of {@link ReportStatusStats}
+ */
+ public ReportStats getStats() {
+ return getReport().getStats();
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/ExtentTest.java b/src/main/java/com/aventstack/extentreports/ExtentTest.java
index 0eff914..9457eb5 100644
--- a/src/main/java/com/aventstack/extentreports/ExtentTest.java
+++ b/src/main/java/com/aventstack/extentreports/ExtentTest.java
@@ -1,10 +1,9 @@
package com.aventstack.extentreports;
-import java.io.IOException;
import java.io.Serializable;
import java.util.Arrays;
-import com.aventstack.extentreports.gherkin.model.IGherkinFormatterModel;
+import com.aventstack.extentreports.gherkin.entity.IGherkinFormatterModel;
import com.aventstack.extentreports.markuputils.Markup;
import com.aventstack.extentreports.model.Author;
import com.aventstack.extentreports.model.Category;
@@ -12,10 +11,14 @@
import com.aventstack.extentreports.model.ExceptionInfo;
import com.aventstack.extentreports.model.Log;
import com.aventstack.extentreports.model.Media;
+import com.aventstack.extentreports.model.RunResult;
import com.aventstack.extentreports.model.ScreenCapture;
import com.aventstack.extentreports.model.Test;
-import com.aventstack.extentreports.utils.ExceptionUtil;
-import com.aventstack.extentreports.utils.StringUtil;
+import com.aventstack.extentreports.model.service.ExceptionInfoService;
+import com.aventstack.extentreports.model.service.LogService;
+import com.aventstack.extentreports.model.service.TestService;
+
+import lombok.Getter;
/**
* Defines a test. You can add logs, snapshots, assign author and categories to
@@ -42,1183 +45,1007 @@
* always level 1 and greater
*
*/
-public class ExtentTest implements IAddsMedia, RunResult, Serializable {
-
- private static final long serialVersionUID = 9199820968410788862L;
-
- /**
- * An instance of {@link ExtentReports} to which this {@link ExtentTest} belongs
- */
- private transient ExtentReports extent;
-
- /**
- * Internal model
- */
- private Test test;
-
- /**
- * Creates a BDD style parent test representing one of the
- * {@link IGherkinFormatterModel} classes. This method would ideally be used for
- * creating the parent, ie {@link Feature).
- *
- *
- * {@link com.aventstack.extentreports.gherkin.model.Feature}
- * {@link com.aventstack.extentreports.gherkin.model.Background}
- * {@link com.aventstack.extentreports.gherkin.model.Scenario}
- * {@link com.aventstack.extentreports.gherkin.model.Given}
- * {@link com.aventstack.extentreports.gherkin.model.When}
- * {@link com.aventstack.extentreports.gherkin.model.Then}
- * {@link com.aventstack.extentreports.gherkin.model.And}
- *
- *
- *
- * Example:
- *
- *
- *
- * extent.createTest(Feature.class, "Feature Name", "Description");
- *
- *
- * @param extent An {@link ExtentReports} object
- * @param type A {@link IGherkinFormatterModel} type
- * @param name Test name
- * @param description Test description
- */
- ExtentTest(ExtentReports extent, Class extends IGherkinFormatterModel> type, String name, String description) {
- if (name == null || name.isEmpty()) {
- throw new IllegalArgumentException("testName cannot be null or empty");
- }
- this.extent = extent;
- test = new Test();
- test.setName(name.trim());
- test.setDescription(description == null ? "" : description.trim());
- if (type != null) {
- test.setBddType(type);
- }
- }
-
- /**
- * Create a test with description
- *
- * @param extent An {@link ExtentReports} object
- * @param testName Test name
- * @param description Test description
- */
- ExtentTest(ExtentReports extent, String testName, String description) {
- this(extent, null, testName, description);
- }
-
- /**
- * Creates a BDD-style node with description representing one of the
- * {@link IGherkinFormatterModel} classes:
- *
- *
- * {@link com.aventstack.extentreports.gherkin.model.Feature}
- * {@link com.aventstack.extentreports.gherkin.model.Background}
- * {@link com.aventstack.extentreports.gherkin.model.Scenario}
- * {@link com.aventstack.extentreports.gherkin.model.Given}
- * {@link com.aventstack.extentreports.gherkin.model.When}
- * {@link com.aventstack.extentreports.gherkin.model.Then}
- * {@link com.aventstack.extentreports.gherkin.model.And}
- *
- *
- *
- * Example:
- *
- *
- *
- * test.createNode(Scenario.class, "bddNode", "description");
- *
- *
- * @param type A {@link IGherkinFormatterModel} type
- * @param name Name of node
- * @param description A short description
- *
- * @return {@link ExtentTest} object
- */
- public synchronized ExtentTest createNode(Class extends IGherkinFormatterModel> type, String name, String description) {
- if (name == null || name.isEmpty())
- throw new IllegalArgumentException("nodeName cannot be null or empty");
-
- ExtentTest t;
- if (type == null) {
- t = new ExtentTest(extent, name, description);
- } else {
- t = new ExtentTest(extent, type, name, description);
- }
-
- applyCommonNodeSettings(t);
- addNodeToReport(t);
- return t;
- }
-
- /**
- * Creates a node with description
- *
- * @param name Name of node
- * @param description A short description
- *
- * @return {@link ExtentTest} object
- */
- public synchronized ExtentTest createNode(String name, String description) {
- if (name == null || name.isEmpty())
- throw new IllegalArgumentException("nodeName cannot be null or empty");
-
- ExtentTest t = new ExtentTest(extent, name, description);
- applyCommonNodeSettings(t);
- addNodeToReport(t);
- return t;
- }
-
- /**
- * Creates a BDD-style node representing one of the
- * {@link IGherkinFormatterModel} classes such as:
- *
- *
- * {@link com.aventstack.extentreports.gherkin.model.Feature}
- * {@link com.aventstack.extentreports.gherkin.model.Background}
- * {@link com.aventstack.extentreports.gherkin.model.Scenario}
- * {@link com.aventstack.extentreports.gherkin.model.Given}
- * {@link com.aventstack.extentreports.gherkin.model.When}
- * {@link com.aventstack.extentreports.gherkin.model.Then}
- * {@link com.aventstack.extentreports.gherkin.model.And}
- *
- *
- *
- * Example:
- *
- *
- *
- * test.createNode(Scenario.class, "bddNode");
- *
- *
- * @param type A {@link IGherkinFormatterModel} type
- * @param name Name of node
- *
- * @return {@link ExtentTest} object
- */
- public ExtentTest createNode(Class extends IGherkinFormatterModel> type, String name) {
- return createNode(type, name, null);
- }
-
- /**
- * Creates a BDD-style node with description using name of the Gherkin model
- * such as:
- *
- *
- * {@link com.aventstack.extentreports.gherkin.model.Feature}
- * {@link com.aventstack.extentreports.gherkin.model.Background}
- * {@link com.aventstack.extentreports.gherkin.model.Scenario}
- * {@link com.aventstack.extentreports.gherkin.model.Given}
- * {@link com.aventstack.extentreports.gherkin.model.When}
- * {@link com.aventstack.extentreports.gherkin.model.Then}
- * {@link com.aventstack.extentreports.gherkin.model.And}
- *
- *
- *
- * Example:
- *
- *
- *
- * test.createNode(new GherkinKeyword("Scenario"), "bddTest", "description");
- *
- *
- * @param gherkinKeyword Name of the {@link GherkinKeyword}
- * @param name Name of node
- * @param description A short description
- *
- * @return {@link ExtentTest}
- */
- public ExtentTest createNode(GherkinKeyword gherkinKeyword, String name, String description) {
- Class extends IGherkinFormatterModel> clazz = gherkinKeyword.getKeyword().getClass();
- return createNode(clazz, name, description);
- }
-
- /**
- * Creates a BDD-style node using name of the Gherkin model such as:
- *
- *
- * {@link com.aventstack.extentreports.gherkin.model.Feature}
- * {@link com.aventstack.extentreports.gherkin.model.Background}
- * {@link com.aventstack.extentreports.gherkin.model.Scenario}
- * {@link com.aventstack.extentreports.gherkin.model.Given}
- * {@link com.aventstack.extentreports.gherkin.model.When}
- * {@link com.aventstack.extentreports.gherkin.model.Then}
- * {@link com.aventstack.extentreports.gherkin.model.And}
- *
- *
- *
- * Example:
- *
- *
- *
- * test.createNode(new GherkinKeyword("Scenario"), "bddTest");
- *
- *
- * @param gherkinKeyword Name of the {@link GherkinKeyword}
- * @param name Name of node
- *
- * @return {@link ExtentTest} object
- */
- public ExtentTest createNode(GherkinKeyword gherkinKeyword, String name) {
- return createNode(gherkinKeyword, name, null);
- }
-
- /**
- * Creates a node
- *
- * @param name Name of node
- *
- * @return {@link ExtentTest} object
- */
- public ExtentTest createNode(String name) {
- return createNode(name, null);
- }
-
- private synchronized void applyCommonNodeSettings(ExtentTest extentTest) {
- extentTest.getModel().setLevel(test.getLevel() + 1);
- extentTest.getModel().setParent(getModel());
- test.getNodeContext().add(extentTest.getModel());
- }
-
- private void addNodeToReport(ExtentTest extentNode) {
- extent.addNode(extentNode.getModel());
- }
-
- /**
- * Logs an event with {@link Status}, details and a media object:
- * {@link ScreenCapture}
- *
- *
- * Example:
- *
- *
- *
- * test.log(Status.FAIL, "details", MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build());
- *
- *
- * @param status {@link Status}
- * @param details Details
- * @param provider A {@link MediaEntityModelProvider} object
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest log(Status status, String details, MediaEntityModelProvider provider) {
- Log evt = createLog(status, details);
- addMedia(evt, provider);
- return addLog(evt);
- }
-
- private void addMedia(Log evt, MediaEntityModelProvider provider) {
- if (provider != null) {
- Class extends Media> clazz = provider.getMedia().getClass();
-
- if (clazz.equals(ScreenCapture.class)) {
- ScreenCapture c = (ScreenCapture) provider.getMedia();
- evt.getScreenCaptureContext().add(c);
- } else {
-
- }
- }
- }
-
- /**
- * Logs an event with {@link Status} and details
- *
- * @param status {@link Status}
- * @param details Details
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest log(Status status, String details) {
- return log(status, details, null);
- }
-
- /**
- * Logs an event with {@link Status} and custom {@link Markup} such as:
- *
- *
- * Code block
- * Label
- * Table
- *
- *
- * @param status {@link Status}
- * @param markup {@link Markup}
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest log(Status status, Markup markup) {
- String details = markup.getMarkup();
- return log(status, details);
- }
-
- private ExtentTest addLog(Log evt) {
- getModel().getLogContext().add(evt);
- getModel().end();
- extent.addLog(getModel(), evt);
-
- if (!evt.getScreenCaptureContext().isEmpty()) {
- try {
- extent.addScreenCapture(evt, evt.getScreenCaptureContext().getLast());
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- return this;
- }
-
- private Log createLog(Status status) {
- Log evt = new Log(getModel());
- evt.setStatus(status);
- evt.setSequence(test.getLogContext().size() + 1);
- return evt;
- }
-
- private Log createLog(Status status, String details) {
- Log evt = createLog(status);
- evt.setDetails(details == null ? "" : details.trim());
- return evt;
- }
-
- /**
- * Logs an event with {@link Status}, an exception and a media object:
- * {@link ScreenCapture}
- *
- *
- * Example:
- *
- *
- *
- * Exception exception = new NullPointerException();
- * test.log(Status.FAIL, exception, MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build());
- *
- *
- * @param status {@link Status}
- * @param t {@link Throwable}
- * @param provider A {@link MediaEntityModelProvider} object
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest log(Status status, Throwable t, MediaEntityModelProvider provider) {
- ExceptionInfo exceptionInfo = new ExceptionInfo();
- exceptionInfo.setThrowable(t);
- exceptionInfo.setExceptionName(ExceptionUtil.getExceptionHeadline(t));
- exceptionInfo.setStackTrace(ExceptionUtil.getStackTrace(t));
- Log evt = createLog(status);
- evt.setExceptionInfo(exceptionInfo);
- getModel().getExceptionInfoContext().add(exceptionInfo);
- addMedia(evt, provider);
- return addLog(evt);
- }
-
- /**
- * Logs an event with {@link Status} and exception
- *
- * @param status {@link Status}
- * @param t {@link Throwable}
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest log(Status status, Throwable t) {
- return log(status, t, null);
- }
-
- /**
- * Logs an event with {@link ExceptionInfo}
- *
- * @param status {@link Status}
- * @param exceptionInfo{@link ExceptionInfo}
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest log(Status status, ExceptionInfo exceptionInfo) {
- Log evt = createLog(status);
- evt.setExceptionInfo(exceptionInfo);
- getModel().getExceptionInfoContext().add(exceptionInfo);
- return addLog(evt);
- }
-
- /**
- * Logs an Status.INFO event with details and a media object:
- * {@link ScreenCapture}
- *
- *
- * Example:
- *
- *
- *
- * test.info("details", MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build());
- *
- *
- * @param details Details
- * @param provider A {@link MediaEntityModelProvider} object
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest info(String details, MediaEntityModelProvider provider) {
- log(Status.INFO, details, provider);
- return this;
- }
-
- /**
- * Logs an event with Status.INFO with details
- *
- * @param details Details
- *
- * @return {@link ExtentTest} object
- */
- public ExtentTest info(String details) {
- return info(details, null);
- }
-
- /**
- * Logs an Status.INFO event with an exception and a media object:
- * {@link ScreenCapture}
- *
- *
- * Example:
- *
- *
- *
- * Exception exception = new NullPointerException();
- * test.info(exception, MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build());
- *
- *
- * @param t {@link Throwable}
- * @param provider A {@link MediaEntityModelProvider} object
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest info(Throwable t, MediaEntityModelProvider provider) {
- log(Status.INFO, t, provider);
- return this;
- }
-
- /**
- * Logs an event with Status.INFO and exception
- *
- * @param t {@link Throwable}
- *
- * @return {@link ExtentTest} object
- */
- public ExtentTest info(Throwable t) {
- return info(t, null);
- }
-
- /**
- * Logs an event with Status.INFO and custom {@link Markup} such
- * as:
- *
- *
- * Code block
- * Label
- * Table
- *
- *
- * @param m {@link Markup}
- *
- * @return {@link ExtentTest} object
- */
- public ExtentTest info(Markup m) {
- log(Status.INFO, m);
- return this;
- }
-
- /**
- * Logs an Status.PASS event with details and a media object:
- * {@link ScreenCapture}
- *
- *
- * Example:
- *
- *
- *
- * test.pass("details", MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build());
- *
- *
- * @param details Details
- * @param provider A {@link MediaEntityModelProvider} object
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest pass(String details, MediaEntityModelProvider provider) {
- log(Status.PASS, details, provider);
- return this;
- }
-
- /**
- * Logs an event Status.PASS with details
- *
- * @param details Details
- *
- * @return {@link ExtentTest} object
- */
- public ExtentTest pass(String details) {
- return pass(details, null);
- }
-
- /**
- * Logs an Status.PASS event with an exception and a media object:
- * {@link ScreenCapture}
- *
- *
- * Example:
- *
- *
- *
- * Exception exception = new NullPointerException();
- * test.pass(exception, MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build());
- *
- *
- * @param t {@link Throwable}
- * @param provider A {@link MediaEntityModelProvider} object
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest pass(Throwable t, MediaEntityModelProvider provider) {
- log(Status.PASS, t, provider);
- return this;
- }
-
- /**
- * Logs an event with Status.PASS and exception
- *
- * @param t {@link Throwable}
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest pass(Throwable t) {
- return pass(t, null);
- }
-
- /**
- * Logs an event with Status.PASS and custom {@link Markup} such
- * as:
- *
- *
- * Code block
- * Label
- * Table
- *
- *
- * @param m {@link Markup}
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest pass(Markup m) {
- log(Status.PASS, m);
- return this;
- }
-
- /**
- * Logs an Status.FAIL event with details and a media object:
- * {@link ScreenCapture}
- *
- * @param details Details
- * @param provider A {@link MediaEntityModelProvider} object
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest fail(String details, MediaEntityModelProvider provider) {
- log(Status.FAIL, details, provider);
- return this;
- }
-
- /**
- * Logs an event Status.FAIL with details
- *
- * @param details Details
- *
- * @return {@link ExtentTest} object
- */
- public ExtentTest fail(String details) {
- return fail(details, null);
- }
-
- /**
- * Logs an Status.FAIL event with an exception and a media object:
- * {@link ScreenCapture}
- *
- *
- * Example:
- *
- *
- *
- * Exception exception = new NullPointerException();
- * test.fail(exception, MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build());
- *
- *
- * @param t {@link Throwable}
- * @param provider A {@link MediaEntityModelProvider} object
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest fail(Throwable t, MediaEntityModelProvider provider) {
- log(Status.FAIL, t, provider);
- return this;
- }
-
- /**
- * Logs an event with Status.FAIL and exception
- *
- * @param t {@link Throwable}
- *
- * @return {@link ExtentTest} object
- */
- public ExtentTest fail(Throwable t) {
- return fail(t, null);
- }
-
- /**
- * Logs an event with Status.FAIL and custom {@link Markup} such
- * as:
- *
- *
- * Code block
- * Label
- * Table
- *
- *
- * @param m {@link Markup}
- *
- * @return {@link ExtentTest} object
- */
- public ExtentTest fail(Markup m) {
- log(Status.FAIL, m);
- return this;
- }
-
- /**
- * Logs an Status.DATAL event with an exception and a media object:
- * {@link ScreenCapture}
- *
- * @param details Details
- * @param provider A {@link MediaEntityModelProvider} object
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest fatal(String details, MediaEntityModelProvider provider) {
- log(Status.FATAL, details, provider);
- return this;
- }
-
- /**
- * Logs an event Status.FATAL with details
- *
- * @param details Details
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest fatal(String details) {
- log(Status.FATAL, details);
- return this;
- }
-
- /**
- * Logs an Status.FATAL event with an exception and a media object:
- * {@link ScreenCapture}
- *
- *
- * Example:
- *
- *
- *
- * Exception exception = new NullPointerException();
- * test.fatal(exception, MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build());
- *
- *
- * @param t {@link Throwable}
- * @param provider A {@link MediaEntityModelProvider} object
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest fatal(Throwable t, MediaEntityModelProvider provider) {
- log(Status.FATAL, t, provider);
- return this;
- }
-
- /**
- * Logs an event with Status.FATAL and exception
- *
- * @param t {@link Throwable}
- *
- * @return {@link ExtentTest} object
- */
- public ExtentTest fatal(Throwable t) {
- log(Status.FATAL, t);
- return this;
- }
-
- /**
- * Logs an event with Status.FATAL and custom {@link Markup} such
- * as:
- *
- *
- * Code block
- * Label
- * Table
- *
- *
- * @param m {@link Markup}
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest fatal(Markup m) {
- log(Status.FATAL, m);
- return this;
- }
-
- /**
- * Logs an Status.WARNING event with an exception and a media
- * object: {@link ScreenCapture}
- *
- * @param details Details
- * @param provider A {@link MediaEntityModelProvider} object
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest warning(String details, MediaEntityModelProvider provider) {
- log(Status.WARNING, details, provider);
- return this;
- }
-
- /**
- * Logs an event Status.WARNING with details
- *
- * @param details Details
- *
- * @return {@link ExtentTest} object
- */
- public ExtentTest warning(String details) {
- return warning(details, null);
- }
-
- /**
- * Logs an Status.WARNING event with an exception and a media
- * object: {@link ScreenCapture}
- *
- *
- * Example:
- *
- *
- *
- * Exception exception = new NullPointerException();
- * test.warning(exception, MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build());
- *
- *
- * @param t {@link Throwable}
- * @param provider A {@link MediaEntityModelProvider} object
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest warning(Throwable t, MediaEntityModelProvider provider) {
- log(Status.WARNING, t, provider);
- return this;
- }
-
- /**
- * Logs an event with Status.WARNING and exception
- *
- * @param t {@link Throwable}
- *
- * @return {@link ExtentTest} object
- */
- public ExtentTest warning(Throwable t) {
- return warning(t, null);
- }
-
- /**
- * Logs an event with Status.WARNING and custom {@link Markup} such
- * as:
- *
- *
- * Code block
- * Label
- * Table
- *
- *
- * @param m {@link Markup}
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest warning(Markup m) {
- log(Status.WARNING, m);
- return this;
- }
-
- /**
- * Logs an Status.ERROR event with an exception and a media object:
- * {@link ScreenCapture}
- *
- * @param details Details
- * @param provider A {@link MediaEntityModelProvider} object
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest error(String details, MediaEntityModelProvider provider) {
- log(Status.ERROR, details, provider);
- return this;
- }
-
- /**
- * Logs an event Status.ERROR with details
- *
- * @param details Details
- *
- * @return {@link ExtentTest} object
- */
- public ExtentTest error(String details) {
- return error(details, null);
- }
-
- /**
- * Logs an Status.ERROR event with an exception and a media object:
- * {@link ScreenCapture}
- *
- *
- * Example:
- *
- *
- *
- * Exception exception = new NullPointerException();
- * test.error(exception, MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build());
- *
- *
- * @param t {@link Throwable}
- * @param provider A {@link MediaEntityModelProvider} object
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest error(Throwable t, MediaEntityModelProvider provider) {
- log(Status.ERROR, t, provider);
- return this;
- }
-
- /**
- * Logs an event with Status.ERROR and exception
- *
- * @param t {@link Throwable}
- *
- * @return {@link ExtentTest} object
- */
- public ExtentTest error(Throwable t) {
- return error(t, null);
- }
-
- /**
- * Logs an event with Status.ERROR and custom {@link Markup} such
- * as:
- *
- *
- * Code block
- * Label
- * Table
- *
- *
- * @param m {@link Markup}
- *
- * @return {@link ExtentTest} object
- */
- public ExtentTest error(Markup m) {
- log(Status.ERROR, m);
- return this;
- }
-
- /**
- *
- * @param details Details
- * @param provider A {@link MediaEntityModelProvider} object
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest skip(String details, MediaEntityModelProvider provider) {
- log(Status.SKIP, details, provider);
- return this;
- }
-
- /**
- * Logs an event Status.SKIP with details
- *
- * @param details Details
- *
- * @return {@link ExtentTest} object
- */
- public ExtentTest skip(String details) {
- return skip(details, null);
- }
-
- /**
- * Logs an Status.SKIP event with an exception and a media object:
- * {@link ScreenCapture}
- *
- *
- * Example:
- *
- *
- *
- * Exception exception = new NullPointerException();
- * test.skip(exception, MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build());
- *
- *
- * @param t {@link Throwable}
- * @param provider A {@link MediaEntityModelProvider} object
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest skip(Throwable t, MediaEntityModelProvider provider) {
- log(Status.SKIP, t, provider);
- return this;
- }
-
- /**
- * Logs an event with Status.SKIP and exception
- *
- * @param t {@link Throwable}
- *
- * @return {@link ExtentTest} object
- */
- public ExtentTest skip(Throwable t) {
- return skip(t, null);
- }
-
- /**
- * Logs an event with Status.SKIP and custom {@link Markup} such
- * as:
- *
- *
- * Code block
- * Label
- * Table
- *
- *
- * @param m {@link Markup}
- *
- * @return {@link ExtentTest} object
- */
- public ExtentTest skip(Markup m) {
- log(Status.SKIP, m);
- return this;
- }
-
- /**
- * Logs an Status.DEBUG event with an exception and a media object:
- * {@link ScreenCapture}
- *
- * @param details Details
- * @param provider A {@link MediaEntityModelProvider} object
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest debug(String details, MediaEntityModelProvider provider) {
- log(Status.DEBUG, details, provider);
- return this;
- }
-
- /**
- * Logs an event Status.DEBUG with details
- *
- * @param details Details
- *
- * @return {@link ExtentTest} object
- */
- public ExtentTest debug(String details) {
- return debug(details, null);
- }
-
- /**
- * Logs an Status.DEBUG event with an exception and a media object:
- * {@link ScreenCapture}
- *
- *
- * Example:
- *
- *
- *
- * Exception exception = new NullPointerException();
- * test.debug(exception, MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build());
- *
- *
- * @param t {@link Throwable}
- * @param provider A {@link MediaEntityModelProvider} object
- *
- * @return An {@link ExtentTest} object
- */
- public ExtentTest debug(Throwable t, MediaEntityModelProvider provider) {
- log(Status.DEBUG, t, provider);
- return this;
- }
-
- /**
- * Logs an event with Status.SKIP and exception
- *
- * @param t {@link Throwable}
- *
- * @return {@link ExtentTest} object
- */
- public ExtentTest debug(Throwable t) {
- return debug(t, null);
- }
-
- /**
- * Logs an event with Status.DEBUG and custom {@link Markup} such
- * as:
- *
- *
- * Code block
- * Label
- * Table
- *
- *
- * @param m {@link Markup}
- *
- * @return {@link ExtentTest} object
- */
- public ExtentTest debug(Markup m) {
- log(Status.DEBUG, m);
- return this;
- }
-
- /**
- * Assigns a category or group
- *
- * @param category Category name
- *
- * @return {@link ExtentTest} object
- */
- public ExtentTest assignCategory(String... category) {
- if (category == null) {
- return this;
- }
- Arrays.stream(category).filter(StringUtil::isNotNullOrEmpty).forEach(c -> {
- Category cat = new Category(c.replace(" ", ""));
- test.getCategoryContext().add(cat);
- extent.assignCategory(test, cat);
- });
- return this;
- }
-
- /**
- * Assigns an author
- *
- * @param author Author name
- *
- * @return {@link ExtentTest} object
- */
- public ExtentTest assignAuthor(String... author) {
- Arrays.stream(author).filter(StringUtil::isNotNullOrEmpty).forEach(x -> {
- Author a = new Author(x.replace(" ", ""));
- test.getAuthorContext().add(a);
- extent.assignAuthor(test, a);
- });
- return this;
- }
-
- /**
- * Assign a device
- *
- * @param device Device name
- *
- * @return {@link ExtentTest} object
- */
- public ExtentTest assignDevice(String... device) {
- Arrays.stream(device).filter(StringUtil::isNotNullOrEmpty).forEach(x -> {
- Device d = new Device(x.replace(" ", ""));
- test.getDeviceContext().add(d);
- extent.assignDevice(test, d);
- });
- return this;
- }
-
- @Override
- public ExtentTest addScreenCaptureFromPath(String imagePath, String title) throws IOException {
- if (imagePath == null || imagePath.isEmpty())
- throw new IllegalArgumentException("imagePath cannot be null or empty");
-
- ScreenCapture screenCapture = new ScreenCapture();
- screenCapture.setPath(imagePath);
- if (title != null) {
- screenCapture.setName(title);
- }
- /*
- * if (test.getObjectId() != null) {
- * screenCapture.setTestObjectId(test.getObjectId()); }
- */
- extent.addScreenCapture(test, screenCapture);
- return addScreenCapture(screenCapture);
- }
-
- private ExtentTest addScreenCapture(ScreenCapture screenCapture) {
- test.getScreenCaptureContext().add(screenCapture);
- /*
- * if (test.getObjectId() != null) { int sequence =
- * test.getScreenCaptureList().size();
- * screenCapture.setTestObjectId(test.getObjectId());
- * screenCapture.setSequence(sequence); }
- */
- return this;
- }
-
- @Override
- public ExtentTest addScreenCaptureFromPath(String imagePath) throws IOException {
- return addScreenCaptureFromPath(imagePath, null);
- }
-
- @Override
- public ExtentTest addScreenCaptureFromBase64String(String s, String title) {
- ScreenCapture screenCapture = new ScreenCapture();
- screenCapture.setBase64String(s);
- screenCapture.setName(title);
-
- /*
- * if (test.getObjectId() != null)
- * screenCapture.setTestObjectId(test.getObjectId());
- */
-
- try {
- extent.addScreenCapture(test, screenCapture);
- } catch (IOException e) {
- }
-
- return addScreenCapture(screenCapture);
- }
-
- @Override
- public ExtentTest addScreenCaptureFromBase64String(String s) {
- return addScreenCaptureFromBase64String(s, null);
- }
-
- /**
- * Provides the current run status of the test or node
- *
- * @return {@link Status}
- */
- public Status getStatus() {
- extent.generateRecentStatus();
- return getModel().getStatus();
- }
-
- /**
- * Returns the underlying test which controls the internal model
- *
- * @return {@link Test} object
- */
- public Test getModel() {
- return test;
- }
-
- /**
- * Returns the {@link ExtentReports} instance associated with this test
- *
- * @return the {@link ExtentReports} instance associated with this test
- */
- public ExtentReports getExtent() {
- return extent;
- }
-
- void setUseManualConfiguration(Boolean b) {
- getModel().setUsesManualConfiguration(b);
- }
-
+@Getter
+public class ExtentTest implements RunResult, Serializable {
+ private static final long serialVersionUID = 5846031786305901993L;
+
+ /**
+ * An instance of {@link ExtentReports} to which this {@link ExtentTest}
+ * belongs
+ */
+ private transient ExtentReports extent;
+
+ /**
+ * Internal model
+ */
+ private Test model;
+
+ /**
+ * Creates a BDD style parent test representing one of the
+ * {@link IGherkinFormatterModel} classes. This method would ideally be used
+ * for creating the parent, ie {@link Feature).
+ *
+ *
+ * {@link com.aventstack.extentreports.gherkin.model.Feature}
+ * {@link com.aventstack.extentreports.gherkin.model.Background}
+ * {@link com.aventstack.extentreports.gherkin.model.Scenario}
+ * {@link com.aventstack.extentreports.gherkin.model.Given}
+ * {@link com.aventstack.extentreports.gherkin.model.When}
+ * {@link com.aventstack.extentreports.gherkin.model.Then}
+ * {@link com.aventstack.extentreports.gherkin.model.And}
+ *
+ *
+ *
+ * Example:
+ *
+ *
+ *
+ * extent.createTest(Feature.class, "Feature Name", "Description");
+ *
+ *
+ * @param extent
+ * An {@link ExtentReports} object
+ * @param type
+ * A {@link IGherkinFormatterModel} type
+ * @param name
+ * Test name
+ * @param description
+ * Test description
+ */
+ ExtentTest(ExtentReports extent, Class extends IGherkinFormatterModel> type, String name, String description) {
+ model = TestService.createTest(type, name, description);
+ this.extent = extent;
+ }
+
+ /**
+ * Create a test with description
+ *
+ * @param extent
+ * An {@link ExtentReports} object
+ * @param testName
+ * Test name
+ * @param description
+ * Test description
+ */
+ ExtentTest(ExtentReports extent, String testName, String description) {
+ this(extent, null, testName, description);
+ }
+
+ /**
+ * Creates a BDD-style node with description representing one of the
+ * {@link IGherkinFormatterModel} classes:
+ *
+ *
+ * {@link com.aventstack.extentreports.gherkin.model.Feature}
+ * {@link com.aventstack.extentreports.gherkin.model.Background}
+ * {@link com.aventstack.extentreports.gherkin.model.Scenario}
+ * {@link com.aventstack.extentreports.gherkin.model.Given}
+ * {@link com.aventstack.extentreports.gherkin.model.When}
+ * {@link com.aventstack.extentreports.gherkin.model.Then}
+ * {@link com.aventstack.extentreports.gherkin.model.And}
+ *
+ *
+ *
+ * Example:
+ *
+ *
+ *
+ * test.createNode(Scenario.class, "bddNode", "description");
+ *
+ *
+ * @param type
+ * A {@link IGherkinFormatterModel} type
+ * @param name
+ * Name of node
+ * @param description
+ * A short description
+ *
+ * @return {@link ExtentTest} object
+ */
+ public synchronized ExtentTest createNode(Class extends IGherkinFormatterModel> type, String name,
+ String description) {
+ ExtentTest t = new ExtentTest(extent, type, name, description);
+ TestService.addNode(t.getModel(), model);
+ extent.onNodeCreated(t.getModel(), model);
+ return t;
+ }
+
+ /**
+ * Creates a node with description
+ *
+ * @param name
+ * Name of node
+ * @param description
+ * A short description
+ *
+ * @return {@link ExtentTest} object
+ */
+ public synchronized ExtentTest createNode(String name, String description) {
+ ExtentTest t = new ExtentTest(extent, name, description);
+ TestService.addNode(t.getModel(), model);
+ extent.onNodeCreated(t.getModel(), model);
+ return t;
+ }
+
+ /**
+ * Creates a BDD-style node representing one of the
+ * {@link IGherkinFormatterModel} classes such as:
+ *
+ *
+ * {@link com.aventstack.extentreports.gherkin.model.Feature}
+ * {@link com.aventstack.extentreports.gherkin.model.Background}
+ * {@link com.aventstack.extentreports.gherkin.model.Scenario}
+ * {@link com.aventstack.extentreports.gherkin.model.Given}
+ * {@link com.aventstack.extentreports.gherkin.model.When}
+ * {@link com.aventstack.extentreports.gherkin.model.Then}
+ * {@link com.aventstack.extentreports.gherkin.model.And}
+ *
+ *
+ *
+ * Example:
+ *
+ *
+ *
+ * test.createNode(Scenario.class, "bddNode");
+ *
+ *
+ * @param type
+ * A {@link IGherkinFormatterModel} type
+ * @param name
+ * Name of node
+ *
+ * @return {@link ExtentTest} object
+ */
+ public ExtentTest createNode(Class extends IGherkinFormatterModel> type, String name) {
+ return createNode(type, name, null);
+ }
+
+ /**
+ * Creates a BDD-style node with description using name of the Gherkin model
+ * such as:
+ *
+ *
+ * {@link com.aventstack.extentreports.gherkin.model.Feature}
+ * {@link com.aventstack.extentreports.gherkin.model.Background}
+ * {@link com.aventstack.extentreports.gherkin.model.Scenario}
+ * {@link com.aventstack.extentreports.gherkin.model.Given}
+ * {@link com.aventstack.extentreports.gherkin.model.When}
+ * {@link com.aventstack.extentreports.gherkin.model.Then}
+ * {@link com.aventstack.extentreports.gherkin.model.And}
+ *
+ *
+ *
+ * Example:
+ *
+ *
+ *
+ * test.createNode(new GherkinKeyword("Scenario"), "bddTest", "description");
+ *
+ *
+ * @param gherkinKeyword
+ * Name of the {@link GherkinKeyword}
+ * @param name
+ * Name of node
+ * @param description
+ * A short description
+ *
+ * @return {@link ExtentTest}
+ */
+ public ExtentTest createNode(GherkinKeyword gherkinKeyword, String name, String description) {
+ return createNode(gherkinKeyword.getKeyword().getClass(), name, description);
+ }
+
+ /**
+ * Creates a BDD-style node using name of the Gherkin model such as:
+ *
+ *
+ * {@link com.aventstack.extentreports.gherkin.model.Feature}
+ * {@link com.aventstack.extentreports.gherkin.model.Background}
+ * {@link com.aventstack.extentreports.gherkin.model.Scenario}
+ * {@link com.aventstack.extentreports.gherkin.model.Given}
+ * {@link com.aventstack.extentreports.gherkin.model.When}
+ * {@link com.aventstack.extentreports.gherkin.model.Then}
+ * {@link com.aventstack.extentreports.gherkin.model.And}
+ *
+ *
+ *
+ * Example:
+ *
+ *
+ *
+ * test.createNode(new GherkinKeyword("Scenario"), "bddTest");
+ *
+ *
+ * @param gherkinKeyword
+ * Name of the {@link GherkinKeyword}
+ * @param name
+ * Name of node
+ *
+ * @return {@link ExtentTest} object
+ */
+ public ExtentTest createNode(GherkinKeyword gherkinKeyword, String name) {
+ return createNode(gherkinKeyword, name, null);
+ }
+
+ /**
+ * Creates a node
+ *
+ * @param name
+ * Name of node
+ *
+ * @return {@link ExtentTest} object
+ */
+ public ExtentTest createNode(String name) {
+ return createNode(name, null);
+ }
+
+ /**
+ *
+ * @param status
+ * @param details
+ * @return
+ */
+ public ExtentTest generateLog(Status status, String details) {
+ Log log = Log.builder().status(status).details(details).build();
+ TestService.addGeneratedLog(log, model);
+ return this;
+ }
+
+ /**
+ *
+ * @param status
+ * @param markup
+ * @return
+ */
+ public ExtentTest generateLog(Status status, Markup markup) {
+ return generateLog(status, markup.getMarkup());
+ }
+
+ /**
+ * Logs an event with {@link Status}, details and a media object:
+ * {@link ScreenCapture}
+ *
+ *
+ * Example:
+ *
+ *
+ *
+ * test.log(Status.FAIL, "details", MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build());
+ *
+ *
+ * @param status
+ * {@link Status}
+ * @param details
+ * Details
+ * @param media
+ * A {@link Media} object
+ *
+ * @return An {@link ExtentTest} object
+ */
+ public ExtentTest log(Status status, String details, Throwable t, Media media) {
+ ExceptionInfo exceptionInfo = ExceptionInfoService.createExceptionInfo(t);
+ Log log = LogService.createLog(model, status, exceptionInfo, details);
+ LogService.addMedia(log, media);
+ TestService.computeTestStatus(model);
+ extent.onLogCreated(log, model);
+ return this;
+ }
+
+ /**
+ * Logs an event with {@link Status}, details and a media object:
+ * {@link ScreenCapture}
+ *
+ *
+ * Example:
+ *
+ *
+ *
+ * test.log(Status.FAIL, "details", MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build());
+ *
+ *
+ * @param status
+ * {@link Status}
+ * @param details
+ * Details
+ * @param media
+ * A {@link Media} object
+ *
+ * @return An {@link ExtentTest} object
+ */
+ public ExtentTest log(Status status, String details, Media media) {
+ return log(status, details, null, media);
+ }
+
+ /**
+ * Logs an event with {@link Status}, details and a media object:
+ * {@link ScreenCapture}
+ *
+ *
+ * Example:
+ *
+ *
+ *
+ * test.log(Status.FAIL, MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build());
+ *
+ *
+ * @param status
+ * {@link Status}
+ * @param media
+ * A {@link Media} object
+ *
+ * @return An {@link ExtentTest} object
+ */
+ public ExtentTest log(Status status, Media media) {
+ return log(status, null, null, media);
+ }
+
+ /**
+ * Logs an event with {@link Status} and details
+ *
+ * @param status
+ * {@link Status}
+ * @param details
+ * Details
+ *
+ * @return An {@link ExtentTest} object
+ */
+ public ExtentTest log(Status status, String details) {
+ return log(status, details, null);
+ }
+
+ /**
+ * Logs an event with {@link Status} and custom {@link Markup} such as:
+ *
+ *
+ * Code block
+ * Label
+ * Table
+ *
+ *
+ * @param status
+ * {@link Status}
+ * @param markup
+ * {@link Markup}
+ *
+ * @return An {@link ExtentTest} object
+ */
+ public ExtentTest log(Status status, Markup markup) {
+ String details = markup.getMarkup();
+ return log(status, details);
+ }
+
+ /**
+ * Logs an event with {@link Status}, an exception and a media object:
+ * {@link ScreenCapture}
+ *
+ *
+ * Example:
+ *
+ *
+ *
+ * Exception exception = new NullPointerException();
+ * test.log(Status.FAIL, exception, MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build());
+ *
+ *
+ * @param status
+ * {@link Status}
+ * @param t
+ * {@link Throwable}
+ * @param media
+ * A {@link Media} object
+ *
+ * @return An {@link ExtentTest} object
+ */
+ public ExtentTest log(Status status, Throwable t, Media media) {
+ return log(status, null, t, media);
+ }
+
+ /**
+ * Logs an event with {@link Status} and exception
+ *
+ * @param status
+ * {@link Status}
+ * @param t
+ * {@link Throwable}
+ *
+ * @return An {@link ExtentTest} object
+ */
+ public ExtentTest log(Status status, Throwable t) {
+ return log(status, t, null);
+ }
+
+ /**
+ * Logs an Status.INFO event with details and a media object:
+ * {@link ScreenCapture}
+ *
+ *
+ * Example:
+ *
+ *
+ *
+ * test.info("details", MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build());
+ *
+ *
+ * @param details
+ * Details
+ * @param provider
+ * A {@link MediaEntityModelProvider} object
+ *
+ * @return An {@link ExtentTest} object
+ */
+ public ExtentTest info(String details, Media media) {
+ log(Status.INFO, details, media);
+ return this;
+ }
+
+ /**
+ * Logs an event with Status.INFO with details
+ *
+ * @param details
+ * Details
+ *
+ * @return {@link ExtentTest} object
+ */
+ public ExtentTest info(String details) {
+ return info(details, null);
+ }
+
+ /**
+ * Logs an Status.INFO event with an exception and a media
+ * object: {@link ScreenCapture}
+ *
+ *
+ * Example:
+ *
+ *
+ *
+ * Exception exception = new NullPointerException();
+ * test.info(exception, MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build());
+ *
+ *
+ * @param t
+ * {@link Throwable}
+ * @param provider
+ * A {@link MediaEntityModelProvider} object
+ *
+ * @return An {@link ExtentTest} object
+ */
+ public ExtentTest info(Throwable t, Media media) {
+ log(Status.INFO, t, media);
+ return this;
+ }
+
+ /**
+ * Logs an event with Status.INFO and exception
+ *
+ * @param t
+ * {@link Throwable}
+ *
+ * @return {@link ExtentTest} object
+ */
+ public ExtentTest info(Throwable t) {
+ return info(t, null);
+ }
+
+ /**
+ * Logs an event with Status.INFO and custom {@link Markup}
+ * such as:
+ *
+ *
+ * Code block
+ * Label
+ * Table
+ *
+ *
+ * @param m
+ * {@link Markup}
+ *
+ * @return {@link ExtentTest} object
+ */
+ public ExtentTest info(Markup m) {
+ log(Status.INFO, m);
+ return this;
+ }
+
+ /**
+ * Logs an event with Status.INFO and {@link ScreenCapture}
+ *
+ * @param media
+ * {@link Media}
+ *
+ * @return {@link ExtentTest} object
+ */
+ public ExtentTest info(Media media) {
+ log(Status.INFO, media);
+ return this;
+ }
+
+ /**
+ * Logs an Status.PASS event with details and a media object:
+ * {@link ScreenCapture}
+ *
+ *
+ * Example:
+ *
+ *
+ *
+ * test.pass("details", MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build());
+ *
+ *
+ * @param details
+ * Details
+ * @param provider
+ * A {@link MediaEntityModelProvider} object
+ *
+ * @return An {@link ExtentTest} object
+ */
+ public ExtentTest pass(String details, Media media) {
+ log(Status.PASS, details, media);
+ return this;
+ }
+
+ /**
+ * Logs an event Status.PASS with details
+ *
+ * @param details
+ * Details
+ *
+ * @return {@link ExtentTest} object
+ */
+ public ExtentTest pass(String details) {
+ return pass(details, null);
+ }
+
+ /**
+ * Logs an Status.PASS event with an exception and a media
+ * object: {@link ScreenCapture}
+ *
+ *
+ * Example:
+ *
+ *
+ *
+ * Exception exception = new NullPointerException();
+ * test.pass(exception, MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build());
+ *
+ *
+ * @param t
+ * {@link Throwable}
+ * @param provider
+ * A {@link MediaEntityModelProvider} object
+ *
+ * @return An {@link ExtentTest} object
+ */
+ public ExtentTest pass(Throwable t, Media media) {
+ log(Status.PASS, t, media);
+ return this;
+ }
+
+ /**
+ * Logs an event with Status.PASS and exception
+ *
+ * @param t
+ * {@link Throwable}
+ *
+ * @return An {@link ExtentTest} object
+ */
+ public ExtentTest pass(Throwable t) {
+ return pass(t, null);
+ }
+
+ /**
+ * Logs an event with Status.PASS and custom {@link Markup}
+ * such as:
+ *
+ *
+ * Code block
+ * Label
+ * Table
+ *
+ *
+ * @param m
+ * {@link Markup}
+ *
+ * @return An {@link ExtentTest} object
+ */
+ public ExtentTest pass(Markup m) {
+ log(Status.PASS, m);
+ return this;
+ }
+
+ /**
+ * Logs an event with Status.PASS and {@link ScreenCapture}
+ *
+ * @param media
+ * {@link Media}
+ *
+ * @return {@link ExtentTest} object
+ */
+ public ExtentTest pass(Media media) {
+ log(Status.PASS, media);
+ return this;
+ }
+
+ /**
+ * Logs an Status.FAIL event with details and a media object:
+ * {@link ScreenCapture}
+ *
+ * @param details
+ * Details
+ * @param provider
+ * A {@link MediaEntityModelProvider} object
+ *
+ * @return An {@link ExtentTest} object
+ */
+ public ExtentTest fail(String details, Media media) {
+ log(Status.FAIL, details, media);
+ return this;
+ }
+
+ /**
+ * Logs an event Status.FAIL with details
+ *
+ * @param details
+ * Details
+ *
+ * @return {@link ExtentTest} object
+ */
+ public ExtentTest fail(String details) {
+ return fail(details, null);
+ }
+
+ /**
+ * Logs an Status.FAIL event with an exception and a media
+ * object: {@link ScreenCapture}
+ *
+ *
+ * Example:
+ *
+ *
+ *
+ * Exception exception = new NullPointerException();
+ * test.fail(exception, MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build());
+ *
+ *
+ * @param t
+ * {@link Throwable}
+ * @param provider
+ * A {@link MediaEntityModelProvider} object
+ *
+ * @return An {@link ExtentTest} object
+ */
+ public ExtentTest fail(Throwable t, Media media) {
+ log(Status.FAIL, t, media);
+ return this;
+ }
+
+ /**
+ * Logs an event with Status.FAIL and exception
+ *
+ * @param t
+ * {@link Throwable}
+ *
+ * @return {@link ExtentTest} object
+ */
+ public ExtentTest fail(Throwable t) {
+ return fail(t, null);
+ }
+
+ /**
+ * Logs an event with Status.FAIL and custom {@link Markup}
+ * such as:
+ *
+ *
+ * Code block
+ * Label
+ * Table
+ *
+ *
+ * @param m
+ * {@link Markup}
+ *
+ * @return {@link ExtentTest} object
+ */
+ public ExtentTest fail(Markup m) {
+ log(Status.FAIL, m);
+ return this;
+ }
+
+ /**
+ * Logs an event with Status.FAIL and {@link ScreenCapture}
+ *
+ * @param media
+ * {@link Media}
+ *
+ * @return {@link ExtentTest} object
+ */
+ public ExtentTest fail(Media media) {
+ log(Status.FAIL, media);
+ return this;
+ }
+
+ /**
+ * Logs an Status.WARNING event with an exception and a media
+ * object: {@link ScreenCapture}
+ *
+ * @param details
+ * Details
+ * @param provider
+ * A {@link MediaEntityModelProvider} object
+ *
+ * @return An {@link ExtentTest} object
+ */
+ public ExtentTest warning(String details, Media media) {
+ log(Status.WARNING, details, media);
+ return this;
+ }
+
+ /**
+ * Logs an event Status.WARNING with details
+ *
+ * @param details
+ * Details
+ *
+ * @return {@link ExtentTest} object
+ */
+ public ExtentTest warning(String details) {
+ return warning(details, null);
+ }
+
+ /**
+ * Logs an Status.WARNING event with an exception and a media
+ * object: {@link ScreenCapture}
+ *
+ *
+ * Example:
+ *
+ *
+ *
+ * Exception exception = new NullPointerException();
+ * test.warning(exception, MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build());
+ *
+ *
+ * @param t
+ * {@link Throwable}
+ * @param provider
+ * A {@link MediaEntityModelProvider} object
+ *
+ * @return An {@link ExtentTest} object
+ */
+ public ExtentTest warning(Throwable t, Media media) {
+ log(Status.WARNING, t, media);
+ return this;
+ }
+
+ /**
+ * Logs an event with Status.WARNING and exception
+ *
+ * @param t
+ * {@link Throwable}
+ *
+ * @return {@link ExtentTest} object
+ */
+ public ExtentTest warning(Throwable t) {
+ return warning(t, null);
+ }
+
+ /**
+ * Logs an event with Status.WARNING and custom {@link Markup}
+ * such as:
+ *
+ *
+ * Code block
+ * Label
+ * Table
+ *
+ *
+ * @param m
+ * {@link Markup}
+ *
+ * @return An {@link ExtentTest} object
+ */
+ public ExtentTest warning(Markup m) {
+ log(Status.WARNING, m);
+ return this;
+ }
+
+ /**
+ * Logs an event with Status.WARNING and {@link ScreenCapture}
+ *
+ * @param media
+ * {@link Media}
+ *
+ * @return {@link ExtentTest} object
+ */
+ public ExtentTest warning(Media media) {
+ log(Status.WARNING, media);
+ return this;
+ }
+
+ /**
+ *
+ * @param details
+ * Details
+ * @param provider
+ * A {@link MediaEntityModelProvider} object
+ *
+ * @return An {@link ExtentTest} object
+ */
+ public ExtentTest skip(String details, Media media) {
+ log(Status.SKIP, details, media);
+ return this;
+ }
+
+ /**
+ * Logs an event Status.SKIP with details
+ *
+ * @param details
+ * Details
+ *
+ * @return {@link ExtentTest} object
+ */
+ public ExtentTest skip(String details) {
+ return skip(details, null);
+ }
+
+ /**
+ * Logs an Status.SKIP event with an exception and a media
+ * object: {@link ScreenCapture}
+ *
+ *
+ * Example:
+ *
+ *
+ *
+ * Exception exception = new NullPointerException();
+ * test.skip(exception, MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build());
+ *
+ *
+ * @param t
+ * {@link Throwable}
+ * @param provider
+ * A {@link MediaEntityModelProvider} object
+ *
+ * @return An {@link ExtentTest} object
+ */
+ public ExtentTest skip(Throwable t, Media media) {
+ log(Status.SKIP, t, media);
+ return this;
+ }
+
+ /**
+ * Logs an event with Status.SKIP and exception
+ *
+ * @param t
+ * {@link Throwable}
+ *
+ * @return {@link ExtentTest} object
+ */
+ public ExtentTest skip(Throwable t) {
+ return skip(t, null);
+ }
+
+ /**
+ * Logs an event with Status.SKIP and custom {@link Markup}
+ * such as:
+ *
+ *
+ * Code block
+ * Label
+ * Table
+ *
+ *
+ * @param m
+ * {@link Markup}
+ *
+ * @return {@link ExtentTest} object
+ */
+ public ExtentTest skip(Markup m) {
+ log(Status.SKIP, m);
+ return this;
+ }
+
+ /**
+ * Logs an event with Status.SKIP and {@link ScreenCapture}
+ *
+ * @param media
+ * {@link Media}
+ *
+ * @return {@link ExtentTest} object
+ */
+ public ExtentTest skip(Media media) {
+ log(Status.SKIP, media);
+ return this;
+ }
+
+ /**
+ * Assigns a category or group
+ *
+ * @param category
+ * Category name
+ *
+ * @return {@link ExtentTest} object
+ */
+ public ExtentTest assignCategory(String... category) {
+ if (category == null || category.length == 0)
+ return this;
+ Arrays.stream(category)
+ .forEach(x -> {
+ Category c = new Category(x.replaceAll("\\s+", ""));
+ model.getCategorySet().add(c);
+ extent.onCategoryAdded(c, model);
+ });
+ return this;
+ }
+
+ /**
+ * Assigns an author
+ *
+ * @param author
+ * Author name
+ *
+ * @return {@link ExtentTest} object
+ */
+ public ExtentTest assignAuthor(String... author) {
+ if (author == null || author.length == 0)
+ return this;
+ Arrays.stream(author)
+ .forEach(x -> {
+ Author a = new Author(x.replaceAll("\\s+", ""));
+ model.getAuthorSet().add(a);
+ extent.onAuthorAdded(a, model);
+ });
+ return this;
+ }
+
+ /**
+ * Assign a device
+ *
+ * @param device
+ * Device name
+ *
+ * @return {@link ExtentTest} object
+ */
+ public ExtentTest assignDevice(String... device) {
+ if (device == null || device.length == 0)
+ return this;
+ Arrays.stream(device)
+ .forEach(x -> {
+ Device d = new Device(x.replaceAll("\\s+", ""));
+ model.getDeviceSet().add(d);
+ extent.onDeviceAdded(d, model);
+ });
+ return this;
+ }
+
+ @Override
+ public Status getStatus() {
+ return TestService.getTestStatus(model);
+ }
+
+ public ExtentTest addScreenCaptureFromPath(String path, String title) {
+ if (path == null || path.isEmpty())
+ throw new IllegalArgumentException("ScreenCapture path cannot be null or empty");
+ Media m = ScreenCapture.builder().path(path).title(title).build();
+ TestService.addMedia(model, m);
+ extent.onMediaAdded(m, model);
+ return this;
+ }
+
+ public ExtentTest addScreenCaptureFromPath(String path) {
+ return addScreenCaptureFromPath(path, null);
+ }
+
+ public ExtentTest addScreenCaptureFromBase64String(String base64, String title) {
+ if (base64 == null || base64.isEmpty())
+ throw new IllegalArgumentException("Base64 string cannot be null or empty");
+ Media m = ScreenCapture.builder().base64(base64).title(title).build();
+ TestService.addMedia(model, m);
+ extent.onMediaAdded(m, model);
+ return this;
+ }
+
+ public ExtentTest addScreenCaptureFromBase64String(String base64) {
+ return addScreenCaptureFromBase64String(base64, null);
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/GherkinKeyword.java b/src/main/java/com/aventstack/extentreports/GherkinKeyword.java
index f61ca5e..4462da6 100644
--- a/src/main/java/com/aventstack/extentreports/GherkinKeyword.java
+++ b/src/main/java/com/aventstack/extentreports/GherkinKeyword.java
@@ -7,11 +7,12 @@
import java.util.logging.Logger;
import com.aventstack.extentreports.gherkin.GherkinDialect;
-import com.aventstack.extentreports.gherkin.GherkinDialectProvider;
-import com.aventstack.extentreports.gherkin.model.Asterisk;
-import com.aventstack.extentreports.gherkin.model.IGherkinFormatterModel;
+import com.aventstack.extentreports.gherkin.GherkinDialectManager;
+import com.aventstack.extentreports.gherkin.entity.Asterisk;
+import com.aventstack.extentreports.gherkin.entity.IGherkinFormatterModel;
import freemarker.template.utility.StringUtil;
+import lombok.Getter;
/**
* Allows {@link IGherkinFormatterModel} to be returned by using a name, from
@@ -39,49 +40,43 @@
*
* @see IGherkinFormatterModel
*/
+@Getter
public class GherkinKeyword {
+ private static final Logger logger = Logger.getLogger(GherkinKeyword.class.getName());
- private static final Logger logger = Logger.getLogger(GherkinKeyword.class.getName());
+ private Class clazz = IGherkinFormatterModel.class;
+ private IGherkinFormatterModel keyword;
- private Class clazz = IGherkinFormatterModel.class;
- private IGherkinFormatterModel keywordClazz;
+ public GherkinKeyword(String gk) throws ClassNotFoundException {
+ GherkinDialect dialect = null;
+ String apiKeyword = StringUtil.capitalize(gk.trim());
+ String refPath = clazz.getPackage().getName();
- public GherkinKeyword(String keyword) throws ClassNotFoundException {
- GherkinDialect dialect = null;
- String apiKeyword = StringUtil.capitalize(keyword.trim());
- String refPath = clazz.getPackage().getName();
-
- try {
- apiKeyword = apiKeyword.equals("*") ? Asterisk.class.getSimpleName() : apiKeyword;
- dialect = GherkinDialectProvider.getDialect();
- if (dialect != null
- && !dialect.getLanguage().equalsIgnoreCase(GherkinDialectProvider.getDefaultLanguage())) {
- apiKeyword = null;
- Map> keywords = dialect.getKeywords();
-
- for (Entry> key : keywords.entrySet()) {
- boolean keywordLocated = key.getValue().stream()
- .anyMatch(x -> x.trim().equalsIgnoreCase(keyword.trim()));
- if (keywordLocated) {
- apiKeyword = StringUtil.capitalize(key.getKey());
- break;
- }
- }
- }
-
- if (apiKeyword == null) {
- throw new GherkinKeywordNotFoundException("Keyword " + apiKeyword + " cannot be null");
- }
-
- String clazzName = refPath + "." + apiKeyword.replace(" ", "");
- Class> c = Class.forName(clazzName);
- keywordClazz = (IGherkinFormatterModel) c.newInstance();
- } catch (InstantiationException | IllegalAccessException e) {
- logger.log(Level.SEVERE, "", e);
- }
- }
-
- IGherkinFormatterModel getKeyword() {
- return keywordClazz;
- }
+ try {
+ apiKeyword = apiKeyword.equals("*") ? Asterisk.class.getSimpleName() : apiKeyword;
+ dialect = GherkinDialectManager.getDialect();
+ if (dialect != null
+ && !dialect.getLanguage().equalsIgnoreCase(GherkinDialectManager.getDefaultLanguage())) {
+ apiKeyword = null;
+ Map> keywords = dialect.getKeywords();
+ for (Entry> key : keywords.entrySet()) {
+ apiKeyword = key.getValue().stream()
+ .filter(x -> x.trim().equalsIgnoreCase(gk.trim()))
+ .findAny()
+ .map(x -> StringUtil.capitalize(x))
+ .orElse(null);
+ if (apiKeyword != null)
+ break;
+ }
+ }
+ if (apiKeyword == null)
+ throw new GherkinKeywordNotFoundException("Keyword cannot be null. " +
+ "You supplied: " + gk + " for dialect " + dialect + " which couldn't be mapped.");
+ String clazzName = refPath + "." + apiKeyword.replace(" ", "");
+ Class> c = Class.forName(clazzName);
+ keyword = (IGherkinFormatterModel) c.newInstance();
+ } catch (InstantiationException | IllegalAccessException e) {
+ logger.log(Level.SEVERE, "", e);
+ }
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/GherkinKeywordNotFoundException.java b/src/main/java/com/aventstack/extentreports/GherkinKeywordNotFoundException.java
index 198412f..85166e4 100644
--- a/src/main/java/com/aventstack/extentreports/GherkinKeywordNotFoundException.java
+++ b/src/main/java/com/aventstack/extentreports/GherkinKeywordNotFoundException.java
@@ -1,11 +1,9 @@
package com.aventstack.extentreports;
public class GherkinKeywordNotFoundException extends ClassNotFoundException {
-
private static final long serialVersionUID = 3140022717738862603L;
public GherkinKeywordNotFoundException(String message) {
super(message);
}
-
}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/IAddsMedia.java b/src/main/java/com/aventstack/extentreports/IAddsMedia.java
deleted file mode 100644
index daff630..0000000
--- a/src/main/java/com/aventstack/extentreports/IAddsMedia.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package com.aventstack.extentreports;
-
-import java.io.IOException;
-
-public interface IAddsMedia {
-
- /**
- * Adds a snapshot to the test or log with title
- *
- * @param mediaPath Image path
- * @param title Image title
- *
- * @return Object this method is called from, generally
- * {@link com.aventstack.extentreports.ExtentTest} or {@link com.aventstack.extentreports.model.Log}
- *
- * @throws IOException thrown if the imagePath of image is not
- * found
- */
- T addScreenCaptureFromPath(String mediaPath, String title) throws IOException;
-
- /**
- * Adds a snapshot to test or log
- *
- * @param mediaPath Image path
- *
- * @return Object this method is called from, generally
- * {@link com.aventstack.extentreports.ExtentTest} or {@link com.aventstack.extentreports.model.Log}
- *
- * @throws IOException thrown if the imagePath of image is not
- * found
- */
- T addScreenCaptureFromPath(String mediaPath) throws IOException;
-
- /**
- * Adds a base64 screenshot
- *
- * @param base64 base64 string
- * @param title Image title
- *
- * @return Object this method is called from, generally
- * {@link com.aventstack.extentreports.ExtentTest} or {@link com.aventstack.extentreports.model.Log}
- */
- T addScreenCaptureFromBase64String(String base64, String title);
-
- /**
- * Adds a base64 screenshot
- *
- * @param base64 base64 string
- *
- * @return Object this method is called from, generally
- * {@link com.aventstack.extentreports.ExtentTest} or {@link com.aventstack.extentreports.model.Log}
- */
- T addScreenCaptureFromBase64String(String base64);
-
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/IAnalysisStrategyMethod.java b/src/main/java/com/aventstack/extentreports/IAnalysisStrategyMethod.java
deleted file mode 100644
index 4a92a99..0000000
--- a/src/main/java/com/aventstack/extentreports/IAnalysisStrategyMethod.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.aventstack.extentreports;
-
-/**
- * Marker interface for a class that uses an {@link AnalysisStrategy}
- *
- */
-public interface IAnalysisStrategyMethod {
-
- void setAnalysisStrategy(AnalysisStrategy strategy);
-
- AnalysisStrategy getAnalysisStrategy();
-
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/InvalidAnalysisStrategyException.java b/src/main/java/com/aventstack/extentreports/InvalidAnalysisStrategyException.java
deleted file mode 100644
index 4ab1c81..0000000
--- a/src/main/java/com/aventstack/extentreports/InvalidAnalysisStrategyException.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.aventstack.extentreports;
-
-public class InvalidAnalysisStrategyException extends IllegalArgumentException {
-
- private static final long serialVersionUID = 5955632288593334683L;
-
- public InvalidAnalysisStrategyException(String message) {
- super(message);
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/MediaEntityBuilder.java b/src/main/java/com/aventstack/extentreports/MediaEntityBuilder.java
index e008747..dccd15b 100644
--- a/src/main/java/com/aventstack/extentreports/MediaEntityBuilder.java
+++ b/src/main/java/com/aventstack/extentreports/MediaEntityBuilder.java
@@ -10,61 +10,52 @@
*
*/
public class MediaEntityBuilder {
-
- private static ThreadLocal media = new ThreadLocal<>();
-
- private static class MediaBuilderInstance {
- static final MediaEntityBuilder INSTANCE = new MediaEntityBuilder();
-
- private MediaBuilderInstance() {
- }
- }
-
- private MediaEntityBuilder() {
- }
-
- private static synchronized MediaEntityBuilder getInstance() {
- return MediaBuilderInstance.INSTANCE;
- }
-
- public MediaEntityModelProvider build() {
- return new MediaEntityModelProvider(media.get());
- }
-
- public static synchronized MediaEntityBuilder createScreenCaptureFromPath(String path, String title)
- throws IOException {
- if (path == null || path.isEmpty())
- throw new IOException("ScreenCapture path cannot be null or empty.");
-
- return createScreenCapture(path, title, false);
- }
-
- public static synchronized MediaEntityBuilder createScreenCaptureFromPath(String path) throws IOException {
- return createScreenCaptureFromPath(path, null);
- }
-
- public static synchronized MediaEntityBuilder createScreenCaptureFromBase64String(String base64String)
- throws IOException {
- if (base64String == null || base64String.trim().equals(""))
- throw new IOException("Base64 string cannot be null or empty.");
-
- return createScreenCapture(base64String, null, true);
- }
-
- private static synchronized MediaEntityBuilder createScreenCapture(String pathOrBase64String, String title,
- boolean isBase64String) {
- ScreenCapture sc = new ScreenCapture();
- if (isBase64String)
- sc.setBase64String(pathOrBase64String);
- else
- sc.setPath(pathOrBase64String);
-
- if (title != null)
- sc.setName(title);
-
- media.set(sc);
-
- return getInstance();
- }
+ private static ThreadLocal media = new ThreadLocal<>();
+
+ private static class MediaBuilderInstance {
+ static final MediaEntityBuilder INSTANCE = new MediaEntityBuilder();
+
+ private MediaBuilderInstance() {
+ }
+ }
+
+ private MediaEntityBuilder() {
+ }
+
+ private static synchronized MediaEntityBuilder getInstance() {
+ return MediaBuilderInstance.INSTANCE;
+ }
+
+ public Media build() {
+ return media.get();
+ }
+
+ public static MediaEntityBuilder createScreenCaptureFromPath(String path, String title) throws IOException {
+ if (path == null || path.isEmpty()) {
+ throw new IllegalArgumentException("ScreenCapture path cannot be null or empty");
+ }
+ media.set(ScreenCapture.builder().path(path).title(title).build());
+ return getInstance();
+ }
+
+ public static MediaEntityBuilder createScreenCaptureFromPath(String path) throws IOException {
+ return createScreenCaptureFromPath(path, null);
+ }
+
+ public static MediaEntityBuilder createScreenCaptureFromBase64String(String base64, String title)
+ throws IOException {
+ if (base64 == null || base64.trim().equals("")) {
+ throw new IllegalArgumentException("Base64 string cannot be null or empty");
+ }
+ media.set(ScreenCapture.builder().base64(base64).title(title).build());
+ return getInstance();
+ }
+
+ public static MediaEntityBuilder createScreenCaptureFromBase64String(String base64) throws IOException {
+ if (base64 == null || base64.trim().equals("")) {
+ throw new IllegalArgumentException("Base64 string cannot be null or empty");
+ }
+ return createScreenCaptureFromBase64String(base64, null);
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/MediaEntityModelProvider.java b/src/main/java/com/aventstack/extentreports/MediaEntityModelProvider.java
deleted file mode 100644
index ef13f46..0000000
--- a/src/main/java/com/aventstack/extentreports/MediaEntityModelProvider.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.aventstack.extentreports;
-
-import com.aventstack.extentreports.model.Media;
-
-public class MediaEntityModelProvider {
-
- private Media m;
-
- public MediaEntityModelProvider(Media m) {
- this.m = m;
- }
-
- public Media getMedia() {
- return m;
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/NullStatusException.java b/src/main/java/com/aventstack/extentreports/NullStatusException.java
new file mode 100644
index 0000000..87c6081
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/NullStatusException.java
@@ -0,0 +1,5 @@
+package com.aventstack.extentreports;
+
+public class NullStatusException extends NullPointerException {
+ private static final long serialVersionUID = 3331364668564936293L;
+}
diff --git a/src/main/java/com/aventstack/extentreports/NullTestException.java b/src/main/java/com/aventstack/extentreports/NullTestException.java
new file mode 100644
index 0000000..6ad9fa4
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/NullTestException.java
@@ -0,0 +1,5 @@
+package com.aventstack.extentreports;
+
+public class NullTestException extends NullPointerException {
+ private static final long serialVersionUID = -2987170430890267069L;
+}
diff --git a/src/main/java/com/aventstack/extentreports/ProvidesSource.java b/src/main/java/com/aventstack/extentreports/ProvidesSource.java
new file mode 100644
index 0000000..f53ead7
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/ProvidesSource.java
@@ -0,0 +1,5 @@
+package com.aventstack.extentreports;
+
+public interface ProvidesSource {
+ String getSource();
+}
diff --git a/src/main/java/com/aventstack/extentreports/ReactiveSubject.java b/src/main/java/com/aventstack/extentreports/ReactiveSubject.java
new file mode 100644
index 0000000..ba3aa0b
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/ReactiveSubject.java
@@ -0,0 +1,83 @@
+package com.aventstack.extentreports;
+
+import java.util.List;
+
+import com.aventstack.extentreports.model.Log;
+import com.aventstack.extentreports.model.Media;
+import com.aventstack.extentreports.model.Report;
+import com.aventstack.extentreports.model.Test;
+import com.aventstack.extentreports.observer.ExtentObserver;
+import com.aventstack.extentreports.observer.LogObserver;
+import com.aventstack.extentreports.observer.MediaObserver;
+import com.aventstack.extentreports.observer.NodeObserver;
+import com.aventstack.extentreports.observer.ReportObserver;
+import com.aventstack.extentreports.observer.TestObserver;
+import com.aventstack.extentreports.observer.entity.LogEntity;
+import com.aventstack.extentreports.observer.entity.MediaEntity;
+import com.aventstack.extentreports.observer.entity.NodeEntity;
+import com.aventstack.extentreports.observer.entity.ReportEntity;
+import com.aventstack.extentreports.observer.entity.TestEntity;
+
+import io.reactivex.rxjava3.subjects.PublishSubject;
+import lombok.Getter;
+
+@Getter
+abstract class ReactiveSubject {
+ private final Report report = Report.builder().build();
+ private final PublishSubject reportSubject = PublishSubject.create();
+ private final PublishSubject testSubject = PublishSubject.create();
+ private final PublishSubject nodeSubject = PublishSubject.create();
+ private final PublishSubject logSubject = PublishSubject.create();
+ private final PublishSubject mediaSubject = PublishSubject.create();
+
+ protected ReactiveSubject() {
+ }
+
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ protected final void attachReporter(List observerList) {
+ for (ExtentObserver o : observerList) {
+ if (o instanceof ReportObserver)
+ reportSubject.subscribe(((ReportObserver) o).getReportObserver());
+ if (o instanceof TestObserver)
+ testSubject.subscribe(((TestObserver) o).getTestObserver());
+ if (o instanceof NodeObserver)
+ nodeSubject.subscribe(((NodeObserver) o).getNodeObserver());
+ if (o instanceof LogObserver)
+ logSubject.subscribe(((LogObserver) o).getLogObserver());
+ if (o instanceof MediaObserver)
+ mediaSubject.subscribe(((MediaObserver) o).getMediaObserver());
+ }
+ }
+
+ protected void onTestCreated(Test test) {
+ testSubject.onNext(TestEntity.builder().test(test).build());
+ }
+
+ protected void onNodeCreated(Test node, Test parent) {
+ nodeSubject.onNext(NodeEntity.builder().node(node).test(parent).build());
+ }
+
+ protected void onTestRemoved(Test test) {
+ testSubject.onNext(TestEntity.builder().test(test).removed(true).build());
+ }
+
+ protected void onNodeRemoved(Test node) {
+ nodeSubject.onNext(NodeEntity.builder().node(node).test(node.getParent()).removed(true).build());
+ }
+
+ protected void onLogCreated(Log log, Test test) {
+ logSubject.onNext(LogEntity.builder().log(log).test(test).build());
+ }
+
+ protected void onMediaAdded(Media m, Test test) {
+ mediaSubject.onNext(MediaEntity.builder().media(m).test(test).build());
+ }
+
+ protected void onMediaAdded(Media m, Log log) {
+ mediaSubject.onNext(MediaEntity.builder().media(m).log(log).build());
+ }
+
+ protected void onFlush() {
+ reportSubject.onNext(ReportEntity.builder().report(report).build());
+ }
+}
diff --git a/src/main/java/com/aventstack/extentreports/ReportAggregates.java b/src/main/java/com/aventstack/extentreports/ReportAggregates.java
deleted file mode 100644
index e1558f2..0000000
--- a/src/main/java/com/aventstack/extentreports/ReportAggregates.java
+++ /dev/null
@@ -1,125 +0,0 @@
-package com.aventstack.extentreports;
-
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-
-import com.aventstack.extentreports.model.Author;
-import com.aventstack.extentreports.model.Category;
-import com.aventstack.extentreports.model.Device;
-import com.aventstack.extentreports.model.Test;
-import com.aventstack.extentreports.model.context.ExceptionTestContextStore;
-import com.aventstack.extentreports.model.context.SystemAttributeContext;
-import com.aventstack.extentreports.model.context.TestAttributeTestContextStore;
-
-/**
- * Aggregator for report elements and collections
- *
- */
-public class ReportAggregates {
-
- private List testList;
- private List testRunnerLogs;
- private TestAttributeTestContextStore categoryContext;
- private TestAttributeTestContextStore authorContext;
- private TestAttributeTestContextStore deviceContext;
- private ExceptionTestContextStore exceptionContext;
- private SystemAttributeContext systemAttributeContext;
- private ReportStatusStats reportStatusStats;
- private Collection statusCollection;
- private Date startTime;
- private Date endTime;
-
- public Date getStartTime() {
- return startTime;
- }
-
- public void setStartTime(Date startTime) {
- this.startTime = startTime;
- }
-
- public Date getEndTime() {
- return endTime;
- }
-
- public void setEndTime(Date endTime) {
- this.endTime = endTime;
- }
-
- public Status getStatus() {
- return Status.getHighestStatus(getStatusCollection());
- }
-
- public List getTestList() {
- return testList;
- }
-
- public void setTestList(List testList) {
- this.testList = testList;
- }
-
- public List getTestRunnerLogs() {
- return testRunnerLogs;
- }
-
- public void setTestRunnerLogs(List testRunnerLogs) {
- this.testRunnerLogs = testRunnerLogs;
- }
-
- public TestAttributeTestContextStore getCategoryContext() {
- return categoryContext;
- }
-
- public void setCategoryContext(TestAttributeTestContextStore categoryContext) {
- this.categoryContext = categoryContext;
- }
-
- public TestAttributeTestContextStore getAuthorContext() {
- return authorContext;
- }
-
- public void setAuthorContext(TestAttributeTestContextStore authorContext) {
- this.authorContext = authorContext;
- }
-
- public TestAttributeTestContextStore getDeviceContext() {
- return deviceContext;
- }
-
- public void setDeviceContext(TestAttributeTestContextStore deviceContext) {
- this.deviceContext = deviceContext;
- }
-
- public ExceptionTestContextStore getExceptionContext() {
- return exceptionContext;
- }
-
- public void setExceptionContext(ExceptionTestContextStore exceptionContext) {
- this.exceptionContext = exceptionContext;
- }
-
- public SystemAttributeContext getSystemAttributeContext() {
- return systemAttributeContext;
- }
-
- public void setSystemAttributeContext(SystemAttributeContext systemAttributeContext) {
- this.systemAttributeContext = systemAttributeContext;
- }
-
- public ReportStatusStats getReportStatusStats() {
- return reportStatusStats;
- }
-
- public void setReportStatusStats(ReportStatusStats reportStatusStats) {
- this.reportStatusStats = reportStatusStats;
- }
-
- public Collection getStatusCollection() {
- return statusCollection;
- }
-
- public void setStatusCollection(Collection statusCollection) {
- this.statusCollection = statusCollection;
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/ReportAggregatesBuilder.java b/src/main/java/com/aventstack/extentreports/ReportAggregatesBuilder.java
deleted file mode 100644
index bea527a..0000000
--- a/src/main/java/com/aventstack/extentreports/ReportAggregatesBuilder.java
+++ /dev/null
@@ -1,104 +0,0 @@
-package com.aventstack.extentreports;
-
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-
-import com.aventstack.extentreports.model.Author;
-import com.aventstack.extentreports.model.Category;
-import com.aventstack.extentreports.model.Device;
-import com.aventstack.extentreports.model.Test;
-import com.aventstack.extentreports.model.context.ExceptionTestContextStore;
-import com.aventstack.extentreports.model.context.SystemAttributeContext;
-import com.aventstack.extentreports.model.context.TestAttributeTestContextStore;
-
-/**
- * Builds {@link ReportAggregates}
- *
- */
-public class ReportAggregatesBuilder {
-
- private List testList;
- private List testRunnerLogs;
- private TestAttributeTestContextStore categoryContext;
- private TestAttributeTestContextStore authorContext;
- private TestAttributeTestContextStore deviceContext;
- private ExceptionTestContextStore exceptionContext;
- private SystemAttributeContext systemAttributeContext;
- private ReportStatusStats reportStatusStats;
- private Collection statusCollection;
- private Date startTime;
- private Date endTime;
-
- public ReportAggregates build() {
- ReportAggregates aggregates = new ReportAggregates();
- aggregates.setTestList(testList);
- aggregates.setTestRunnerLogs(testRunnerLogs);
- aggregates.setCategoryContext(categoryContext);
- aggregates.setAuthorContext(authorContext);
- aggregates.setDeviceContext(deviceContext);
- aggregates.setExceptionContext(exceptionContext);
- aggregates.setSystemAttributeContext(systemAttributeContext);
- aggregates.setReportStatusStats(reportStatusStats);
- aggregates.setStatusCollection(statusCollection);
- aggregates.setStartTime(startTime);
- aggregates.setEndTime(endTime);
- return aggregates;
- }
-
- public ReportAggregatesBuilder setTestList(List testList) {
- this.testList = testList;
- return this;
- }
-
- public ReportAggregatesBuilder setTestRunnerLogs(List testRunnerLogs) {
- this.testRunnerLogs = testRunnerLogs;
- return this;
- }
-
- public ReportAggregatesBuilder setCategoryContext(TestAttributeTestContextStore categoryContext) {
- this.categoryContext = categoryContext;
- return this;
- }
-
- public ReportAggregatesBuilder setAuthorContext(TestAttributeTestContextStore authorContext) {
- this.authorContext = authorContext;
- return this;
- }
-
- public ReportAggregatesBuilder setDeviceContext(TestAttributeTestContextStore deviceContext) {
- this.deviceContext = deviceContext;
- return this;
- }
-
- public ReportAggregatesBuilder setExceptionContext(ExceptionTestContextStore exceptionContext) {
- this.exceptionContext = exceptionContext;
- return this;
- }
-
- public ReportAggregatesBuilder setSystemAttributeContext(SystemAttributeContext systemAttributeContext) {
- this.systemAttributeContext = systemAttributeContext;
- return this;
- }
-
- public ReportAggregatesBuilder setReportStatusStats(ReportStatusStats reportStatusStats) {
- this.reportStatusStats = reportStatusStats;
- return this;
- }
-
- public ReportAggregatesBuilder setStatusCollection(Collection statusCollection) {
- this.statusCollection = statusCollection;
- return this;
- }
-
- public ReportAggregatesBuilder setStartTime(Date startTime) {
- this.startTime = startTime;
- return this;
- }
-
- public ReportAggregatesBuilder setEndTime(Date endTime) {
- this.endTime = endTime;
- return this;
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/ReportAggregatesListener.java b/src/main/java/com/aventstack/extentreports/ReportAggregatesListener.java
deleted file mode 100644
index a49863c..0000000
--- a/src/main/java/com/aventstack/extentreports/ReportAggregatesListener.java
+++ /dev/null
@@ -1,102 +0,0 @@
-package com.aventstack.extentreports;
-
-import java.util.List;
-
-import com.aventstack.extentreports.model.Author;
-import com.aventstack.extentreports.model.Category;
-import com.aventstack.extentreports.model.Device;
-import com.aventstack.extentreports.model.Test;
-import com.aventstack.extentreports.model.context.ExceptionTestContextStore;
-import com.aventstack.extentreports.model.context.SystemAttributeContext;
-import com.aventstack.extentreports.model.context.TestAttributeTestContextStore;
-
-/**
- * Allows sharing of aggregates/collections to be shared with the started
- * reporter. A few examples of these collections include:
- *
- *
- * Category context - list of all categories and associated tests
- * Exception context - list of all exceptions and associated tests
- * Complete list of started tests
- * System information
- *
- */
-public interface ReportAggregatesListener {
-
- /**
- * Allows sharing the complete list of tests with the reporter
- *
- * @param testList list of all tests created by {@link ExtentReports}
- */
- void setTestList(List testList);
-
- /**
- * Passes the complete list of logs to the reporter
- *
- * @param logs testrunner logs
- */
- void setTestRunnerLogs(List logs);
-
- /**
- * Allows sharing the complete list of category and associated tests with the
- * reporter
- *
- * @param categoryContext collection containing categories and all associated
- * tests
- */
- void setCategoryContextInfo(TestAttributeTestContextStore categoryContext);
-
- /**
- * Allows sharing the complete list of author and associated tests with the
- * reporter
- *
- * @param authorContext collection containing author and all associated tests
- */
- void setAuthorContextInfo(TestAttributeTestContextStore authorContext);
-
- /**
- * Allows sharing the complete list of device and associated tests with the
- * reporter
- *
- * @param deviceContext collection containing devices and all associated tests
- */
- void setDeviceContextInfo(TestAttributeTestContextStore deviceContext);
-
- /**
- * Allows sharing the complete list of exceptions and associated tests with the
- * reporter
- *
- * @param exceptionContext collection containing exception and all associated
- * tests
- */
- void setExceptionContextInfo(ExceptionTestContextStore exceptionContext);
-
- /**
- * Passes all system information to the reporter
- *
- * @param systemAttributeContext system information
- */
- void setSystemAttributeContext(SystemAttributeContext systemAttributeContext);
-
- /**
- * Report Status stats of the run session for all possible levels:
- *
- *
- * Features/Tests
- * Scenarios/Logs
- * Steps
- *
- *
- * @param sc {@link ReportStatusStats} represents stats of each hierarchical
- * level of test/event
- */
- void setReportStatusStats(ReportStatusStats sc);
-
- /**
- * A distinct list of status assigned to tests
- *
- * @param statusList a distinct list of {@link Status}
- */
- void setStatusList(List statusList);
-
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/ReportConfigurator.java b/src/main/java/com/aventstack/extentreports/ReportConfigurator.java
deleted file mode 100644
index 3469eaf..0000000
--- a/src/main/java/com/aventstack/extentreports/ReportConfigurator.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.aventstack.extentreports;
-
-public class ReportConfigurator {
-
- private static class ReportConfiguratorInstance {
- static final ReportConfigurator INSTANCE = new ReportConfigurator();
-
- private ReportConfiguratorInstance() {
- }
- }
-
- private ReportConfigurator() {
- }
-
- public static ReportConfigurator getInstance() {
- return ReportConfiguratorInstance.INSTANCE;
- }
-
- public StatusConfigurator statusConfigurator() {
- return StatusConfigurator.getInstance();
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/ReportObservable.java b/src/main/java/com/aventstack/extentreports/ReportObservable.java
deleted file mode 100644
index 7e4ff66..0000000
--- a/src/main/java/com/aventstack/extentreports/ReportObservable.java
+++ /dev/null
@@ -1,597 +0,0 @@
-package com.aventstack.extentreports;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import com.aventstack.extentreports.model.Author;
-import com.aventstack.extentreports.model.Category;
-import com.aventstack.extentreports.model.Device;
-import com.aventstack.extentreports.model.Log;
-import com.aventstack.extentreports.model.ScreenCapture;
-import com.aventstack.extentreports.model.SystemAttribute;
-import com.aventstack.extentreports.model.Test;
-import com.aventstack.extentreports.model.context.ExceptionTestContextStore;
-import com.aventstack.extentreports.model.context.SystemAttributeContext;
-import com.aventstack.extentreports.model.context.TestAttributeTestContextStore;
-import com.aventstack.extentreports.model.context.helpers.TestRemover;
-import com.aventstack.extentreports.model.service.ScreenCaptureService;
-import com.aventstack.extentreports.model.service.TestService;
-import com.aventstack.extentreports.reporter.BasicFileReporter;
-import com.aventstack.extentreports.reporter.ExtentReporter;
-
-abstract class ReportObservable implements ReportService {
-
- /**
- * The current AnalysisStrategy for the run session. This decides the technique
- * used to count the test status at differing levels. For example, for a BDD
- * style report, the levels to be calculated are Feature, Scenario and Step (3
- * levels). For a generic, non-BDD style report, levels can be dynamic. For a
- * non-BDD style report, levels typically consist of:
- *
- *
- * 1 level: Test
- * Test
- * - Event
- *
- *
- * 2 levels: Test & node
- * Test
- * - Node
- * -- Event
- *
- *
- * 2 levels: Test, the leaf-node
- * Test
- * - Node
- * -- Leaf Node
- * --- Event
- *
- */
- private AnalysisStrategy strategy = AnalysisStrategy.TEST;
-
- /**
- * Use this setting when building post-execution reports, such as from TestNG
- * IReporter. This setting allows setting test with your own variables and
- * prevent update by Extent. As of today, with this enabled, Extent does not use
- * time-stamps for tests at the time they were created
- */
- private boolean usesManualConfiguration = false;
-
- /**
- * The status of the entire report or build
- */
- private Status reportStatus = Status.PASS;
-
- /**
- * Time the report or build was started
- */
- private Date reportStartDate = Calendar.getInstance().getTime();
-
- /**
- * Time the report or build ended. This value is updated everytime
- * flush is called
- */
- private Date reportEndDate;
-
- /**
- * A collection of tests arranged by category
- */
- private TestAttributeTestContextStore categoryContext = new TestAttributeTestContextStore<>();
-
- /**
- * A collection of tests arranged by author
- */
- private TestAttributeTestContextStore authorContext = new TestAttributeTestContextStore<>();
-
- /**
- * A collection of tests arranged by author
- */
- private TestAttributeTestContextStore deviceContext = new TestAttributeTestContextStore<>();
-
- /**
- * A collection of tests arranged by exception
- */
- private ExceptionTestContextStore exceptionContext = new ExceptionTestContextStore();
-
- /**
- * A context of all system or environment variables
- */
- private SystemAttributeContext systemAttributeContext = new SystemAttributeContext();
-
- /**
- * A list of all {@link ExtentReporter} reporters started by the
- * attachReporter method
- */
- private List reporterList = new ArrayList<>();
-
- /**
- * Any logs added by to the test runner can be added to Extent
- *
- *
- * TestNG Example:
- *
- *
- * Setting logs with TestNG:
- *
- *
- * Reporter.log("hello world")
- *
- *
- *
- * Informing Extent of any logs added:
- *
- *
- * for (String s : Reporter.getOutput()) {
- * extent.setTestRunnerOutput(s);
- * }
- *
- */
- private List testRunnerLogs = new ArrayList<>();
-
- /**
- * A list of all tests created
- */
- private List testList = new ArrayList<>();
-
- /**
- * Instance of {@link ReportStatusStats}
- */
- private ReportStatusStats stats = new ReportStatusStats(strategy);
-
- /**
- * A unique collection of statuses tests are marked with
- *
- *
- * Consider a report having 10 tests:
- *
- *
- * Test1: PASS
- * Test2: PASS
- * Test3: PASS
- * Test4: SKIP
- * Test5: SKIP
- * Test6: FAIL
- * Test7: PASS
- * Test8: PASS
- * Test9: FAIL
- * Test10: PASS
- *
- *
- *
- * Distinct list of contained status:
- *
- *
- * PASS
- * SKIP
- * FAIL
- *
- */
- private Set statusSet = new HashSet();
-
- /**
- * Path of dirs to resolve relative image path so there is a direct access
- */
- private String[] imagePathResolveDir;
-
- protected ReportObservable() {
- }
-
- /**
- * Subscribe the reporter to receive updates when making calls to the API
- *
- * @param reporter {@link ExtentReporter} reporter
- */
- protected void register(ExtentReporter reporter) {
- reporterList.add(reporter);
- reporter.start();
- }
-
- /**
- * Unsubscribe the reporter. Calling unsubscribe will call the stop
- * method and also remove the reporter from the list of started reporters
- *
- * @param reporter {@link ExtentReporter} reporter to unsubscribe
- */
- protected void deregister(ExtentReporter reporter) {
-
- if (reporterList.contains((Object) reporter)) {
- reporter.stop();
- reporterList.remove(reporter);
- }
- }
-
- /**
- * Retrieve a list of all started reporters
- *
- * @return a list of {@link ExtentReporter} objects
- */
- protected List getReporterCollection() {
- return reporterList;
- }
-
- /**
- * Saves the started test and notifies all started reporters
- *
- * @param test a {@link Test} object
- */
- protected synchronized void saveTest(Test test) {
- testList.add(test);
- reporterList.forEach(x -> x.onTestStarted(test));
- }
-
- /**
- * Removes the test and notifies all started reporters
- *
- * @param test a {@link Test} object
- */
- protected void removeTest(Test test) {
- removeTestTestList(test);
- removeTestTestAttributeContext(test);
- reporterList.forEach(x -> x.onTestRemoved(test));
- }
-
- /**
- * Removes a test from test list
- *
- * @param test a {@link Test} object
- */
- private void removeTestTestList(Test test) {
- TestRemover.remove(testList, test);
- refreshReportEntities();
- }
-
- /**
- * Removes test from test list of each context
- *
- * @param test a {@link Test} object
- */
- private void removeTestTestAttributeContext(Test test) {
- if (TestService.testHasCategory(test)) {
- categoryContext.removeTest(test);
- }
- if (TestService.testHasAuthor(test)) {
- authorContext.removeTest(test);
- }
- if (TestService.testHasDevice(test)) {
- deviceContext.removeTest(test);
- }
- }
-
- /**
- * Refreshes report entities such as {@link ReportStatusStats} and list of
- * distinct {@link Status}
- */
- private void refreshReportEntities() {
- refreshReportStats();
- refreshStatusList();
- }
-
- /**
- * Refresh and notify all reports of {@link ReportStatusStats}
- */
- private synchronized void refreshReportStats() {
- stats.refresh(testList);
- }
-
- /**
- * Refresh and notify all reports of distinct status assigned to tests
- */
- private synchronized void refreshStatusList() {
- statusSet.clear();
- refreshStatusList(testList);
- }
-
- /**
- * Refreshes distinct status list
- *
- * @param list a list of started {@link Test}
- */
- private synchronized void refreshStatusList(List list) {
- if (list == null || list.isEmpty()) {
- return;
- }
- list.forEach(x -> statusSet.add(x.getStatus()));
- list.forEach(x -> refreshStatusList(x.getNodeContext().getAll()));
- }
-
- /**
- * Notify reporters of the added node
- *
- * @param node a {@link Test} node
- */
- void addNode(Test node) {
- reporterList.forEach(x -> x.onNodeStarted(node));
- }
-
- /**
- * Notifies reporters with information of added {@link Log}
- *
- * @param test {@link Test} to which the event is added
- * @param log {@link Log}
- */
- void addLog(Test test, Log log) {
- reporterList.forEach(x -> x.onLogAdded(test, log));
- }
-
- /**
- * Notifies reporters with information of added {@link Category}
- *
- * @param test {@link Test} to which the Category is added
- * @param category {@link Category}
- */
- void assignCategory(Test test, Category category) {
- reporterList.forEach(x -> x.onCategoryAssigned(test, category));
- }
-
- /**
- * Notifies reporters with information of added {@link Author}
- *
- * @param test {@link Test} to which the Author is added
- * @param author {@link Author}
- */
- void assignAuthor(Test test, Author author) {
- reporterList.forEach(x -> x.onAuthorAssigned(test, author));
- }
-
- /**
- * Notifies reporters with information of added {@link Author}
- *
- * @param test {@link Test} to which the Device is added
- * @param device {@link Device}
- */
- void assignDevice(Test test, Device device) {
- reporterList.forEach(x -> x.onDeviceAssigned(test, device));
- }
-
- /**
- * Notifies reporters with information of added {@link ScreenCapture}
- *
- * @param test {@link Test} to which the ScreenCapture is added
- * @param screenCapture {@link ScreenCapture}
- *
- * @throws IOException thrown if the {@link ScreenCapture} is not found
- */
- void addScreenCapture(Test test, ScreenCapture screenCapture) throws IOException {
- ScreenCaptureService.resolvePath(screenCapture, imagePathResolveDir);
- for (ExtentReporter r : reporterList) {
- r.onScreenCaptureAdded(test, screenCapture);
- }
- }
-
- /**
- * Notifies reporters with information of added {@link ScreenCapture}
- *
- * @param test {@link Log} to which the ScreenCapture is added
- * @param screenCapture {@link ScreenCapture}
- *
- * @throws IOException thrown if the {@link ScreenCapture} is not found
- */
- void addScreenCapture(Log log, ScreenCapture screenCapture) throws IOException {
- ScreenCaptureService.resolvePath(screenCapture, imagePathResolveDir);
- for (ExtentReporter r : reporterList) {
- r.onScreenCaptureAdded(log, screenCapture);
- }
- }
-
- /**
- * Returns the context of author with the list of tests for each
- *
- * @return a {@link TestAttributeTestContextStore} object
- */
- protected TestAttributeTestContextStore getAuthorContextInfo() {
- return authorContext;
- }
-
- /**
- * Updates the status of the report or build
- *
- * @param status a {@link Status}
- */
- private void updateReportStatus(Status status) {
- int statusIndex = Status.getStatusHierarchy().indexOf(status);
- int reportStatusIndex = Status.getStatusHierarchy().indexOf(reportStatus);
-
- reportStatus = statusIndex < reportStatusIndex ? status : reportStatus;
- }
-
- /**
- * Ends the test
- *
- * @param test a {@link Test} object
- */
- private void endTest(Test test) {
- test.end();
- updateReportStatus(test.getStatus());
- }
-
- /**
- * Collects and updates all run information and notifies all reporters.
- * Depending upon the type of reporter, additional events can occur such as:
- *
- *
- * A file written to disk (eg. case of {@link BasicFileReporter}
- * A database being updated (eg. case of KlovReporter)
- *
- */
- protected synchronized void flush() {
- generateRecentStatus();
- notifyReporters();
- }
-
- /**
- * Collects run information from all tests for assigned {@link Category},
- * {@link Author}, Exception, Nodes. This also ends and updates all internal
- * test information and refreshes {@link ReportStatusStats} and the distinct
- * list of {@link Status}
- */
- public synchronized void generateRecentStatus() {
- if (testList == null || testList.isEmpty())
- return;
-
- reportEndDate = Calendar.getInstance().getTime();
-
- for (Test test : testList) {
- endTest(test);
- test.setUsesManualConfiguration(getAllowManualConfig());
- if (TestService.testHasCategory(test)) {
- test.getCategoryContext().getAll().forEach(x -> categoryContext.setAttributeContext((Category) x, test));
- }
- if (TestService.testHasAuthor(test)) {
- test.getAuthorContext().getAll().forEach(x -> authorContext.setAttributeContext((Author) x, test));
- }
- if (TestService.testHasDevice(test)) {
- test.getDeviceContext().getAll().forEach(x -> deviceContext.setAttributeContext((Device) x, test));
- }
- if (TestService.testHasException(test)) {
- test.getExceptionInfoContext().getAll().forEach(x -> exceptionContext.setExceptionContext(x, test));
- }
- if (TestService.testHasChildren(test)) {
- Iterator iter = test.getNodeContext().getIterator();
- while (iter.hasNext()) {
- Test node = iter.next();
- copyNodeAttributeAndRunTimeInfoToAttributeContexts(node);
- node.setUsesManualConfiguration(getAllowManualConfig());
- }
- }
- }
-
- refreshReportEntities();
- updateReportStartTimeForManualConfigurationSetting();
- }
-
- /**
- * In case where manual configuration is used, calculate the correct timestamps
- * based upon the timestamps assigned to tests
- */
- private void updateReportStartTimeForManualConfigurationSetting() {
- if (getAllowManualConfig() && !testList.isEmpty()) {
- Date minDate = testList.stream().map(t -> t.getStartTime()).min(Date::compareTo).get();
- Date maxDate = testList.stream().map(t -> t.getEndTime()).max(Date::compareTo).get();
- reportStartDate = reportStartDate.getTime() > minDate.getTime() ? minDate : reportStartDate;
- reportEndDate = reportEndDate.getTime() < maxDate.getTime() ? maxDate : reportEndDate;
- }
- }
-
- /**
- * Traverse all nodes and refresh {@link Category}, {@link Author}, Exception
- * and Node context information
- *
- * @param node a {@link Test} node
- */
- private void copyNodeAttributeAndRunTimeInfoToAttributeContexts(Test node) {
- if (TestService.testHasCategory(node)) {
- node.getCategoryContext().getAll().forEach(x -> categoryContext.setAttributeContext((Category) x, node));
- }
- if (TestService.testHasAuthor(node)) {
- node.getAuthorContext().getAll().forEach(x -> authorContext.setAttributeContext((Author) x, node));
- }
- if (TestService.testHasDevice(node)) {
- node.getDeviceContext().getAll().forEach(x -> deviceContext.setAttributeContext((Device) x, node));
- }
- if (TestService.testHasException(node)) {
- node.getExceptionInfoContext().getAll().forEach(x -> exceptionContext.setExceptionContext(x, node));
- }
- if (TestService.testHasChildren(node)) {
- node.getNodeContext().getAll().forEach(this::copyNodeAttributeAndRunTimeInfoToAttributeContexts);
- }
- }
-
- /**
- * Notify all reporters with complete run information
- */
- private synchronized void notifyReporters() {
- if (!testList.isEmpty() && TestService.isTestBehaviorDriven(testList.get(0))) {
- strategy = AnalysisStrategy.BDD;
- }
- ReportAggregates reportAggregates = new ReportAggregatesBuilder()
- .setAuthorContext(authorContext)
- .setCategoryContext(categoryContext)
- .setDeviceContext(deviceContext)
- .setExceptionContext(exceptionContext)
- .setReportStatusStats(stats)
- .setStatusCollection(statusSet)
- .setSystemAttributeContext(systemAttributeContext)
- .setTestList(testList)
- .setTestRunnerLogs(testRunnerLogs)
- .setStartTime(reportStartDate)
- .setEndTime(reportEndDate)
- .build();
- reporterList.forEach(x -> x.setAnalysisStrategy(strategy));
- reporterList.forEach(x -> x.flush(reportAggregates));
- }
-
- /**
- * Ends logging, stops and clears the list of reporters
- */
- protected void end() {
- flush();
- reporterList.forEach(ExtentReporter::stop);
- reporterList.clear();
- }
-
- /**
- * Add a system attribute
- *
- * @param sa a {@link SystemAttribute} object
- */
- protected void setSystemInfo(SystemAttribute sa) {
- systemAttributeContext.setSystemAttribute(sa);
- }
-
- /**
- * Add a test runner log
- *
- * @param log a log event
- */
- protected void setTestRunnerLogs(String log) {
- testRunnerLogs.add(log);
- }
-
- /**
- * Updates the {@link AnalysisStrategy}
- *
- * @param strategy a {@link AnalysisStrategy} object
- */
- protected void setAnalysisStrategy(AnalysisStrategy strategy) {
- this.strategy = strategy;
- stats = new ReportStatusStats(strategy);
- }
-
- protected void setMediaPathResolveDir(String[] imagePathResolveDir) {
- this.imagePathResolveDir = imagePathResolveDir;
- }
-
- /**
- * Setting to allow user driven configuration for test time-stamps
- *
- * @param useManualConfig setting for manual configuration
- */
- protected void setAllowManualConfig(boolean useManualConfig) {
- this.usesManualConfiguration = useManualConfig;
- }
-
- /**
- * Returns the current value of using manual configuration for test time-stamps
- *
- * @return setting for manual configuration
- */
- protected boolean getAllowManualConfig() {
- return usesManualConfiguration;
- }
-
- /**
- * Return the {@link ReportStatusStats} object
- *
- * @return a {@link ReportStatusStats} object
- */
- protected ReportStatusStats getStats() {
- generateRecentStatus();
- return stats;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/ReportService.java b/src/main/java/com/aventstack/extentreports/ReportService.java
deleted file mode 100644
index 2932d67..0000000
--- a/src/main/java/com/aventstack/extentreports/ReportService.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.aventstack.extentreports;
-
-import com.aventstack.extentreports.reporter.AbstractReporter;
-import com.aventstack.extentreports.reporter.ExtentReporter;
-
-/**
- * The main service for {@link ExtentReports} which allows attaching a reporter
- * of type {@link AbstractReporter}
- */
-public interface ReportService {
-
- void attachReporter(ExtentReporter... reporter);
-
- void generateRecentStatus();
-
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/ReportStatusStats.java b/src/main/java/com/aventstack/extentreports/ReportStatusStats.java
deleted file mode 100644
index 3de73be..0000000
--- a/src/main/java/com/aventstack/extentreports/ReportStatusStats.java
+++ /dev/null
@@ -1,602 +0,0 @@
-package com.aventstack.extentreports;
-
-import java.util.Iterator;
-import java.util.List;
-
-import com.aventstack.extentreports.gherkin.model.Scenario;
-import com.aventstack.extentreports.model.Log;
-import com.aventstack.extentreports.model.Test;
-
-/**
- *
- * This class maintains the total count of tests and its nodes along with their
- * statuses for a given run session
- */
-public class ReportStatusStats {
-
- private List testList;
- private AnalysisStrategy strategy = AnalysisStrategy.TEST;
-
- private int parentPass = 0;
- private int parentFail = 0;
- private int parentFatal = 0;
- private int parentError = 0;
- private int parentWarning = 0;
- private int parentSkip = 0;
- private int parentExceptions = 0;
-
- private int childPass = 0;
- private int childFail = 0;
- private int childFatal = 0;
- private int childError = 0;
- private int childWarning = 0;
- private int childSkip = 0;
- private int childInfo = 0;
- private int childDebug = 0;
- private int childExceptions = 0;
-
- private int grandChildPass = 0;
- private int grandChildFail = 0;
- private int grandChildFatal = 0;
- private int grandChildError = 0;
- private int grandChildWarning = 0;
- private int grandChildSkip = 0;
- private int grandChildInfo = 0;
- private int grandChildDebug = 0;
- private int grandChildExceptions = 0;
-
- private int eventsPass = 0;
- private int eventsFail = 0;
- private int eventsFatal = 0;
- private int eventsError = 0;
- private int eventsWarning = 0;
- private int eventsSkip = 0;
- private int eventsInfo = 0;
- private int eventsDebug = 0;
- private int eventsExceptions = 0;
-
- public ReportStatusStats(AnalysisStrategy strategy) {
- this.strategy = strategy;
- }
-
- public void refresh(List testList) {
- reset();
- this.testList = testList;
- refreshStats();
- }
-
- private void reset() {
- parentPass = 0;
- parentFail = 0;
- parentFatal = 0;
- parentError = 0;
- parentWarning = 0;
- parentSkip = 0;
- parentExceptions = 0;
-
- childPass = 0;
- childFail = 0;
- childFatal = 0;
- childError = 0;
- childWarning = 0;
- childSkip = 0;
- childInfo = 0;
- childExceptions = 0;
-
- grandChildPass = 0;
- grandChildFail = 0;
- grandChildFatal = 0;
- grandChildError = 0;
- grandChildWarning = 0;
- grandChildSkip = 0;
- grandChildInfo = 0;
- grandChildExceptions = 0;
-
- eventsPass = 0;
- eventsFail = 0;
- eventsFatal = 0;
- eventsError = 0;
- eventsWarning = 0;
- eventsSkip = 0;
- eventsInfo = 0;
- eventsDebug = 0;
- eventsExceptions = 0;
- }
-
- public int getParentCount() {
- return getParentCountPass() + getParentCountFail() + getParentCountFatal() + getParentCountError()
- + getParentCountWarning() + getParentCountSkip();
- }
-
- public int getParentCountPass() {
- return parentPass;
- }
-
- public int getParentCountFail() {
- return parentFail;
- }
-
- public int getParentCountFatal() {
- return parentFatal;
- }
-
- public int getParentCountError() {
- return parentError;
- }
-
- public int getParentCountWarning() {
- return parentWarning;
- }
-
- public int getParentCountSkip() {
- return parentSkip;
- }
-
- public int getParentCountExceptions() {
- return parentExceptions;
- }
-
- public float getParentPercentagePass() {
- float p = getParentCount() > 0 ? (float) getParentCountPass() / (float) getParentCount() : 0;
- return p * 100;
- }
-
- public float getParentPercentageFail() {
- float p = getParentCount() > 0
- ? ((float) getParentCountFail() + (float) getParentCountFatal()) / (float) getParentCount()
- : 0;
- return p * 100;
- }
-
- public float getParentPercentageOthers() {
- float p = getParentCount() > 0
- ? ((float) getParentCountWarning() + (float) getParentCountError()) / (float) getParentCount()
- : 0;
- return p * 100;
- }
-
- public float getParentPercentageSkip() {
- float p = getParentCount() > 0 ? (float) getParentCountSkip() / (float) getParentCount() : 0;
- return p * 100;
- }
-
- public int getChildCount() {
- return getChildCountPass() + getChildCountFail() + getChildCountFatal() + getChildCountError()
- + getChildCountWarning() + getChildCountSkip() + getChildCountInfo();
- }
-
- public int getChildCountPass() {
- return childPass;
- }
-
- public int getChildCountFail() {
- return childFail;
- }
-
- public int getChildCountFatal() {
- return childFatal;
- }
-
- public int getChildCountError() {
- return childError;
- }
-
- public int getChildCountWarning() {
- return childWarning;
- }
-
- public int getChildCountSkip() {
- return childSkip;
- }
-
- public int getChildCountInfo() {
- return childInfo;
- }
-
- public int getChildCountDebug() {
- return childDebug;
- }
-
- public int getChildCountExceptions() {
- return childExceptions;
- }
-
- public float getChildPercentagePass() {
- float p = getChildCount() > 0 ? (float) getChildCountPass() / (float) getChildCount() : 0;
- return p * 100;
- }
-
- public float getChildPercentageFail() {
- float p = getChildCount() > 0
- ? ((float) getChildCountFail() + (float) getChildCountFatal()) / (float) getChildCount()
- : 0;
- return p * 100;
- }
-
- public float getChildPercentageOthers() {
- float p = getChildCount() > 0
- ? (((float) getChildCountWarning() + (float) getChildCountError() + (float) getChildCountSkip()
- + (float) getChildCountInfo()) / (float) getChildCount())
- : 0;
- return p * 100;
- }
-
- public float getChildPercentageSkip() {
- float p = getChildCount() > 0 ? (float) getChildCountSkip() / (float) getChildCount() : 0;
- return p * 100;
- }
-
- public int getGrandChildCount() {
- return getGrandChildCountPass() + getGrandChildCountFail() + getGrandChildCountFatal()
- + getGrandChildCountError() + getGrandChildCountWarning() + getGrandChildCountSkip()
- + getGrandChildCountInfo();
- }
-
- public int getGrandChildCountPass() {
- return grandChildPass;
- }
-
- public int getGrandChildCountFail() {
- return grandChildFail;
- }
-
- public int getGrandChildCountFatal() {
- return grandChildFatal;
- }
-
- public int getGrandChildCountError() {
- return grandChildError;
- }
-
- public int getGrandChildCountWarning() {
- return grandChildWarning;
- }
-
- public int getGrandChildCountSkip() {
- return grandChildSkip;
- }
-
- public int getGrandChildCountInfo() {
- return grandChildInfo;
- }
-
- public int getGrandChildCountDebug() {
- return grandChildDebug;
- }
-
- public int getGrandChildCountExceptions() {
- return grandChildExceptions;
- }
-
- public float getGrandChildPercentagePass() {
- float p = getGrandChildCount() > 0 ? (float) getGrandChildCountPass() / (float) getGrandChildCount() : 0;
- return p * 100;
- }
-
- public float getGrandChildPercentageFail() {
- float p = getGrandChildCount() > 0
- ? ((float) getGrandChildCountFail() + (float) getGrandChildCountFatal()) / (float) getGrandChildCount()
- : 0;
- return p * 100;
- }
-
- public float getGrandChildPercentageOthers() {
- float p = getGrandChildCount() > 0
- ? (((float) getGrandChildCountWarning() + (float) getGrandChildCountError()
- + (float) getGrandChildCountSkip() + (float) getGrandChildCountInfo())
- / (float) getGrandChildCount())
- : 0;
- return p * 100;
- }
-
- public float getGrandChildPercentageSkip() {
- float p = getGrandChildCount() > 0 ? (float) getGrandChildCountSkip() / (float) getGrandChildCount() : 0;
- return p * 100;
- }
-
- public int getEventsCount() {
- return getEventsCountPass() + getEventsCountFail() + getEventsCountFatal()
- + getEventsCountError() + getEventsCountWarning() + getEventsCountSkip()
- + getEventsCountInfo();
- }
-
- public int getEventsCountPass() {
- return eventsPass;
- }
-
- public int getEventsCountFail() {
- return eventsFail;
- }
-
- public int getEventsCountFatal() {
- return eventsFatal;
- }
-
- public int getEventsCountError() {
- return eventsError;
- }
-
- public int getEventsCountWarning() {
- return eventsWarning;
- }
-
- public int getEventsCountSkip() {
- return eventsSkip;
- }
-
- public int getEventsCountInfo() {
- return eventsInfo;
- }
-
- public int getEventsCountDebug() {
- return eventsDebug;
- }
-
- public int getEventsCountExceptions() {
- return eventsExceptions;
- }
-
- public float getEventsPercentagePass() {
- float p = getEventsCount() > 0 ? (float) getEventsCountPass() / (float) getEventsCount() : 0;
- return p * 100;
- }
-
- public float getEventsPercentageFail() {
- float p = getEventsCount() > 0
- ? ((float) getEventsCountFail() + (float) getEventsCountFatal()) / (float) getEventsCount()
- : 0;
- return p * 100;
- }
-
- public float getEventsPercentageOthers() {
- float p = getEventsCount() > 0
- ? (((float) getEventsCountWarning() + (float) getEventsCountError()
- + (float) getEventsCountSkip() + (float) getEventsCountInfo())
- / (float) getEventsCount())
- : 0;
- return p * 100;
- }
-
- public float getEventsPercentageSkip() {
- float p = getEventsCount() > 0 ? (float) getEventsCountSkip() / (float) getEventsCount() : 0;
- return p * 100;
- }
-
- private void refreshStats() {
- testList.forEach(this::addTestForStatusStatsUpdate);
- }
-
- private void addTestForStatusStatsUpdate(Test test) {
- updateEventsCount(test);
-
- if (test.getBddType() != null
- || (!test.getNodeContext().isEmpty() && test.getNodeContext().get(0).getBddType() != null)) {
- updateGroupCountsBDD(test);
- return;
- }
-
- if (strategy == AnalysisStrategy.TEST || strategy == AnalysisStrategy.CLASS) {
- updateGroupCountsTestStrategy(test);
- return;
- }
-
- if (strategy == AnalysisStrategy.SUITE) {
- updateGroupCountsSuiteStrategy(test);
- return;
- }
-
- throw new InvalidAnalysisStrategyException("No such strategy found: " + strategy);
- }
-
- private synchronized void updateEventsCount(Test test) {
- test.getLogContext().getAll().stream()
- .map(Log::getStatus)
- .forEach(this::incrementEvent);
- Iterator iter = test.getNodeContext().getIterator();
- while (iter.hasNext()) {
- Test node = iter.next();
- updateEventsCount(node);
- }
- }
-
- private void updateGroupCountsSuiteStrategy(Test test) {
- incrementItemCountByStatus(ItemLevel.PARENT, test.getStatus());
-
- if (!test.getNodeContext().isEmpty()) {
- for (Test x : test.getNodeContext().getAll()) {
- incrementItemCountByStatus(ItemLevel.CHILD, x.getStatus());
- if (!x.getNodeContext().isEmpty()) {
- x.getNodeContext().getAll()
- .forEach(n -> incrementItemCountByStatus(ItemLevel.GRANDCHILD, n.getStatus()));
- }
- }
- }
- }
-
- private void updateGroupCountsBDD(Test test) {
- incrementItemCountByStatus(ItemLevel.PARENT, test.getStatus());
-
- if (!test.getNodeContext().isEmpty()) {
- for (Test x : test.getNodeContext().getAll()) {
- if (x.getBddType() == Scenario.class) {
- incrementItemCountByStatus(ItemLevel.CHILD, x.getStatus());
- }
- if (!x.getNodeContext().isEmpty()) {
- for (Test n : x.getNodeContext().getAll()) {
- if (n.getBddType() == Scenario.class) {
- incrementItemCountByStatus(ItemLevel.CHILD, n.getStatus());
- n.getNodeContext().getAll()
- .forEach(z -> incrementItemCountByStatus(ItemLevel.GRANDCHILD, z.getStatus()));
- } else {
- incrementItemCountByStatus(ItemLevel.GRANDCHILD, n.getStatus());
- }
- }
- }
- }
- }
- }
-
- private void updateGroupCountsTestStrategy(Test test) {
- incrementItemCountByStatus(ItemLevel.PARENT, test.getStatus());
-
- if (!test.getNodeContext().isEmpty()) {
- updateGroupCountsTestStrategyChildren(test);
- }
- }
-
- private void updateGroupCountsTestStrategyChildren(Test test) {
- test.getNodeContext().getAll().forEach(x -> {
- if (x.getNodeContext().isEmpty()) {
- incrementItemCountByStatus(ItemLevel.CHILD, x.getStatus());
- } else {
- updateGroupCountsTestStrategyChildren(x);
- }
- });
- }
-
- enum ItemLevel {
- PARENT, CHILD, GRANDCHILD
- }
-
- private void incrementItemCountByStatus(ItemLevel item, Status status) {
- switch (item) {
- case PARENT:
- incrementParent(status);
- break;
- case CHILD:
- incrementChild(status);
- break;
- case GRANDCHILD:
- incrementGrandChild(status);
- break;
- default:
- break;
- }
- }
-
- private void incrementParent(Status status) {
- switch (status) {
- case PASS:
- parentPass++;
- return;
- case FAIL:
- parentFail++;
- break;
- case FATAL:
- parentFatal++;
- break;
- case ERROR:
- parentError++;
- break;
- case WARNING:
- parentWarning++;
- break;
- case SKIP:
- parentSkip++;
- break;
- default:
- break;
- }
-
- parentExceptions++;
- }
-
- private void incrementChild(Status status) {
- switch (status) {
- case PASS:
- childPass++;
- break;
- case FAIL:
- childFail++;
- break;
- case FATAL:
- childFatal++;
- break;
- case ERROR:
- childError++;
- break;
- case WARNING:
- childWarning++;
- break;
- case SKIP:
- childSkip++;
- break;
- case INFO:
- childInfo++;
- break;
- case DEBUG:
- childDebug++;
- break;
- default:
- break;
- }
-
- if (status != Status.PASS && status != Status.INFO)
- childExceptions++;
- }
-
- private void incrementGrandChild(Status status) {
- switch (status) {
- case PASS:
- grandChildPass++;
- break;
- case FAIL:
- grandChildFail++;
- break;
- case FATAL:
- grandChildFatal++;
- break;
- case ERROR:
- grandChildError++;
- break;
- case WARNING:
- grandChildWarning++;
- break;
- case SKIP:
- grandChildSkip++;
- break;
- case INFO:
- grandChildInfo++;
- break;
- case DEBUG:
- grandChildDebug++;
- break;
- default:
- break;
- }
-
- if (status != Status.PASS && status != Status.INFO)
- grandChildExceptions++;
- }
-
- private void incrementEvent(Status status) {
- switch (status) {
- case PASS:
- eventsPass++;
- break;
- case FAIL:
- eventsFail++;
- break;
- case FATAL:
- eventsFatal++;
- break;
- case ERROR:
- eventsError++;
- break;
- case WARNING:
- eventsWarning++;
- break;
- case SKIP:
- eventsSkip++;
- break;
- case INFO:
- eventsInfo++;
- break;
- case DEBUG:
- eventsDebug++;
- break;
- default:
- break;
- }
- }
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/RunResult.java b/src/main/java/com/aventstack/extentreports/RunResult.java
deleted file mode 100644
index 426197f..0000000
--- a/src/main/java/com/aventstack/extentreports/RunResult.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.aventstack.extentreports;
-/**
- * Marker interface for the run result with a single getStatus() method
- *
- */
-public interface RunResult {
-
- Status getStatus();
-
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/SourceProvider.java b/src/main/java/com/aventstack/extentreports/SourceProvider.java
deleted file mode 100644
index eccc815..0000000
--- a/src/main/java/com/aventstack/extentreports/SourceProvider.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.aventstack.extentreports;
-
-/**
- * Some formatters can provide the source which is also written to file,
- * for example, Email formatters or reporters. Along with writing the contents
- * to a file, you can retrieve the source using which an email can be sent.
- */
-public interface SourceProvider {
-
- String getSource();
-
-}
diff --git a/src/main/java/com/aventstack/extentreports/Status.java b/src/main/java/com/aventstack/extentreports/Status.java
index f4ca613..5d9116d 100644
--- a/src/main/java/com/aventstack/extentreports/Status.java
+++ b/src/main/java/com/aventstack/extentreports/Status.java
@@ -1,97 +1,62 @@
package com.aventstack.extentreports;
-import java.io.Serializable;
-import java.util.Arrays;
+
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Comparator;
import java.util.List;
-/**
- * List of allowed status for {@link com.aventstack.extentreports.model.Log}
- */
-public enum Status implements Serializable {
- PASS,
- FAIL,
- FATAL,
- ERROR,
- WARNING,
- INFO,
- DEBUG,
- SKIP;
+import com.aventstack.extentreports.view.Ico;
+
+import lombok.Getter;
+
+@Getter
+public enum Status {
+ INFO("Info", 10), PASS("Pass", 20), SKIP("Skip", 30), WARNING("Warning", 40), FAIL("Fail", 50);
+
+ private final Integer level;
+ private final String name;
+
+ Status(String name, Integer level) {
+ this.name = name;
+ this.level = level;
+ }
+
+ private static void resolveHierarchy(List status) {
+ status.sort((Status s1, Status s2) -> s1.getLevel().compareTo(s2.getLevel()));
+ }
+
+ public static List getResolvedHierarchy(List status) {
+ List list = new ArrayList<>(status);
+ resolveHierarchy(list);
+ return list;
+ }
- private static List statusHierarchy = Arrays.asList(
- Status.FATAL,
- Status.FAIL,
- Status.ERROR,
- Status.WARNING,
- Status.SKIP,
- Status.PASS,
- Status.INFO,
- Status.DEBUG
- );
-
- /**
- * Returns the hierarchical list of status, in the below order:
- *
- *
- * FATAL
- * FAIL
- * ERROR
- * WARNING
- * SKIP
- * PASS
- * DEBUG
- * INFO
- *
- *
- * @return Hierarchical list of status
- */
- public static List getStatusHierarchy() {
- return statusHierarchy;
+ public static Status max(Collection status) {
+ return status.stream().max(Comparator.comparing(Status::getLevel)).orElse(PASS);
}
-
- public static Status getHighestStatus(Collection statusCollection) {
- Status highestStatus = Status.PASS;
- if (statusCollection == null || statusCollection.isEmpty()) {
- return highestStatus;
- }
- for (Status status : statusCollection) {
- highestStatus = Status.getStatusHierarchy().indexOf(status) < Status.getStatusHierarchy().indexOf(highestStatus)
- ? status
- : highestStatus;
- }
- return highestStatus;
+
+ public static Status min(Collection status) {
+ return status.stream().min(Comparator.comparing(Status::getLevel)).orElse(PASS);
}
-
- static void setStatusHierarchy(List statusHierarchy) {
- Status.statusHierarchy = statusHierarchy;
+
+ public static Status max(Status s1, Status s2) {
+ return s1.getLevel() > s2.getLevel() ? s1 : s2;
}
-
- static void resetStatusHierarchy() {
- List statusHierarchy = Arrays.asList(
- Status.FATAL,
- Status.FAIL,
- Status.ERROR,
- Status.WARNING,
- Status.SKIP,
- Status.PASS,
- Status.INFO,
- Status.DEBUG
- );
-
- setStatusHierarchy(statusHierarchy);
+
+ public static String i(String status) {
+ return Ico.ico(status).toString();
}
-
+
+ public static String i(Status status) {
+ return Ico.ico(status.toString()).toString();
+ }
+
+ public String toLower() {
+ return name.toLowerCase();
+ }
+
@Override
public String toString() {
- switch (this) {
- case PASS: return "pass";
- case FAIL: return "fail";
- case FATAL: return "fatal";
- case ERROR: return "error";
- case WARNING: return "warning";
- case INFO: return "info";
- case DEBUG: return "debug";
- case SKIP: return "skip";
- default: return "unknown";
- }
+ return name;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/com/aventstack/extentreports/StatusConfigurator.java b/src/main/java/com/aventstack/extentreports/StatusConfigurator.java
deleted file mode 100644
index 9e5cc6a..0000000
--- a/src/main/java/com/aventstack/extentreports/StatusConfigurator.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package com.aventstack.extentreports;
-
-import java.util.List;
-
-public class StatusConfigurator {
-
- private static class StatusConfiguratorInstance {
- static final StatusConfigurator INSTANCE = new StatusConfigurator();
-
- private StatusConfiguratorInstance() {
- }
- }
-
- private StatusConfigurator() {
- }
-
- public static StatusConfigurator getInstance() {
- return StatusConfiguratorInstance.INSTANCE;
- }
-
- public List getStatusHierarchy() {
- return Status.getStatusHierarchy();
- }
-
- public void setStatusHierarchy(List statusHierarchy) {
- Status.setStatusHierarchy(statusHierarchy);
- }
-
- public void resetStatusHierarchy() {
- Status.resetStatusHierarchy();
- }
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/TestListener.java b/src/main/java/com/aventstack/extentreports/TestListener.java
deleted file mode 100644
index 5201df4..0000000
--- a/src/main/java/com/aventstack/extentreports/TestListener.java
+++ /dev/null
@@ -1,96 +0,0 @@
-package com.aventstack.extentreports;
-
-import java.io.IOException;
-
-import com.aventstack.extentreports.model.Author;
-import com.aventstack.extentreports.model.Category;
-import com.aventstack.extentreports.model.Device;
-import com.aventstack.extentreports.model.Log;
-import com.aventstack.extentreports.model.ScreenCapture;
-import com.aventstack.extentreports.model.Test;
-
-/**
- * Listener methods invoked when an event occurs in the report:
- *
- *
- * A test or node is started
- * A category or author is added
- * A media object is added etc.
- *
- */
-public interface TestListener {
-
- /**
- * Invoked when a test is started using createTest()
- *
- * @param test {@link com.aventstack.extentreports.model.Test} object
- */
- void onTestStarted(Test test);
-
- /**
- * Invoked when a test is removed using removeTest()
- *
- * @param test {@link com.aventstack.extentreports.model.Test} object
- */
- void onTestRemoved(Test test);
-
- /**
- * Invoked when a node is started using createNode()
- *
- * @param node {@link com.aventstack.extentreports.model.Test} object
- */
- void onNodeStarted(Test node);
-
- /**
- * Invoked each time a log is added to any test/node
- *
- * @param test {@link com.aventstack.extentreports.model.Test} object
- * @param log {@link com.aventstack.extentreports.model.Log} object
- */
- void onLogAdded(Test test, Log log);
-
- /**
- * Invoked each time a category is assigned to any test/node
- *
- * @param test {@link com.aventstack.extentreports.model.Test} object
- * @param category {@link com.aventstack.extentreports.model.Category} object
- */
- void onCategoryAssigned(Test test, Category category);
-
- /**
- * Invoked each time an author is assigned to any test/node
- *
- * @param test {@link com.aventstack.extentreports.model.Test} object
- * @param author {@link com.aventstack.extentreports.model.Author} object
- */
- void onAuthorAssigned(Test test, Author author);
-
- /**
- * Invoked each time a device is assigned to any test/node
- *
- * @param test {@link com.aventstack.extentreports.model.Test} object
- * @param device {@link com.aventstack.extentreports.model.Device} object
- */
- void onDeviceAssigned(Test test, Device device);
-
- /**
- * Invoked each time a screencapture is added to test
- *
- * @param test {@link com.aventstack.extentreports.model.Test} object
- * @param screenCapture {@link com.aventstack.extentreports.model.ScreenCapture}
- * object
- * @throws IOException Exception thrown if the media object is not found
- */
- void onScreenCaptureAdded(Test test, ScreenCapture screenCapture) throws IOException;
-
- /**
- * Invoked each time a screencapture is added to log
- *
- * @param log {@link com.aventstack.extentreports.model.Log} object
- * @param screenCapture {@link com.aventstack.extentreports.model.ScreenCapture}
- * object
- * @throws IOException Exception thrown if the media object is not found
- */
- void onScreenCaptureAdded(Log log, ScreenCapture screenCapture) throws IOException;
-
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/Writable.java b/src/main/java/com/aventstack/extentreports/Writable.java
new file mode 100644
index 0000000..22e187a
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/Writable.java
@@ -0,0 +1,6 @@
+package com.aventstack.extentreports;
+
+@FunctionalInterface
+public interface Writable {
+ void flush();
+}
diff --git a/src/main/java/com/aventstack/extentreports/annotations/MarkupIgnore.java b/src/main/java/com/aventstack/extentreports/annotations/MarkupIgnore.java
new file mode 100644
index 0000000..1ead655
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/annotations/MarkupIgnore.java
@@ -0,0 +1,11 @@
+package com.aventstack.extentreports.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface MarkupIgnore {
+}
diff --git a/src/main/java/com/aventstack/extentreports/annotations/MarkupInclude.java b/src/main/java/com/aventstack/extentreports/annotations/MarkupInclude.java
new file mode 100644
index 0000000..ee510a0
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/annotations/MarkupInclude.java
@@ -0,0 +1,11 @@
+package com.aventstack.extentreports.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface MarkupInclude {
+}
diff --git a/src/main/java/com/aventstack/extentreports/config/ConfigStore.java b/src/main/java/com/aventstack/extentreports/config/ConfigStore.java
new file mode 100644
index 0000000..61f7614
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/config/ConfigStore.java
@@ -0,0 +1,41 @@
+package com.aventstack.extentreports.config;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class ConfigStore {
+ private Map store = new HashMap();
+
+ public void addConfig(String key, Object value) {
+ store.put(key, value);
+ }
+
+ public boolean containsConfig(String k) {
+ return store.containsKey(k);
+ }
+
+ public void removeConfig(String k) {
+ store.remove(k);
+ }
+
+ public Object getConfig(String k) {
+ return store.get(k);
+ }
+
+ public void extendConfig(Map map) {
+ map.forEach((key, value) -> this.addConfig(key, value));
+ }
+
+ public void extendConfig(ConfigStore configMap) {
+ this.extendConfig(configMap.getStore());
+ }
+
+ public boolean isEmpty() {
+ return store.isEmpty();
+ }
+}
diff --git a/src/main/java/com/aventstack/extentreports/config/external/JsonConfigLoader.java b/src/main/java/com/aventstack/extentreports/config/external/JsonConfigLoader.java
new file mode 100644
index 0000000..6991728
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/config/external/JsonConfigLoader.java
@@ -0,0 +1,56 @@
+package com.aventstack.extentreports.config.external;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.lang.reflect.Type;
+
+import org.testng.reporters.Files;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.InstanceCreator;
+
+public class JsonConfigLoader {
+ private File f;
+ private String json;
+ private T instance;
+ private InstanceCreator creator;
+
+ public JsonConfigLoader(T instance, File f) throws FileNotFoundException {
+ if (f == null)
+ throw new IllegalArgumentException("File cannot be null");
+ if (!f.exists())
+ throw new FileNotFoundException("File " + f.getAbsolutePath() + " could not be found");
+ init(instance);
+ this.f = f;
+ }
+
+ public JsonConfigLoader(T instance, String json) {
+ if (json == null || json.isEmpty())
+ throw new IllegalArgumentException("Json input cannot be null or empty");
+ init(instance);
+ this.json = json;
+ }
+
+ private void init(T instance) {
+ this.instance = instance;
+ creator = new InstanceCreator() {
+ @Override
+ public T createInstance(Type type) {
+ return instance;
+ }
+ };
+ }
+
+ @SuppressWarnings("unchecked")
+ public void apply() {
+ final Gson gson = new GsonBuilder().registerTypeAdapter(instance.getClass(), creator).create();
+ try {
+ String json = f != null ? Files.readFile(f) : this.json;
+ instance = (T) gson.fromJson(json, instance.getClass());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/com/aventstack/extentreports/config/external/XmlConfigLoader.java b/src/main/java/com/aventstack/extentreports/config/external/XmlConfigLoader.java
new file mode 100644
index 0000000..5bfd46a
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/config/external/XmlConfigLoader.java
@@ -0,0 +1,83 @@
+package com.aventstack.extentreports.config.external;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.CharacterData;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+import com.aventstack.extentreports.config.ConfigStore;
+
+public class XmlConfigLoader {
+ private static final Logger LOG = Logger.getLogger(XmlConfigLoader.class.getName());
+
+ private ConfigStore store = new ConfigStore();
+ private InputStream stream;
+
+ public XmlConfigLoader(URL url) {
+ try {
+ stream = url.openStream();
+ } catch (IOException e) {
+ LOG.log(Level.SEVERE, url.toString(), e);
+ }
+ }
+
+ public XmlConfigLoader(File file) {
+ try {
+ stream = new FileInputStream(file);
+ } catch (FileNotFoundException e) {
+ LOG.log(Level.SEVERE, file.getPath(), e);
+ }
+ }
+
+ public ConfigStore getConfigStore() {
+ if (stream == null)
+ return null;
+
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder documentBuilder;
+ String value;
+
+ try {
+ documentBuilder = documentBuilderFactory.newDocumentBuilder();
+
+ Document doc = documentBuilder.parse(stream);
+ doc.getDocumentElement().normalize();
+
+ NodeList nodeList = doc.getElementsByTagName("configuration").item(0).getChildNodes();
+
+ for (int ix = 0; ix < nodeList.getLength(); ix++) {
+ Node node = nodeList.item(ix);
+
+ Element el = node.getNodeType() == Node.ELEMENT_NODE ? (Element) node : null;
+
+ if (el != null) {
+ value = el.getTextContent();
+
+ value = el instanceof CharacterData ? ((CharacterData) el).getData() : value;
+ store.addConfig(el.getNodeName(), value);
+ }
+ }
+
+ return store;
+ } catch (IOException | SAXException | ParserConfigurationException e) {
+ LOG.log(Level.SEVERE, "Failed to load external configuration", e);
+ }
+
+ return null;
+ }
+}
diff --git a/src/main/java/com/aventstack/extentreports/configuration/ConfigurationBuilder.java b/src/main/java/com/aventstack/extentreports/configuration/ConfigurationBuilder.java
deleted file mode 100644
index c66ec17..0000000
--- a/src/main/java/com/aventstack/extentreports/configuration/ConfigurationBuilder.java
+++ /dev/null
@@ -1,84 +0,0 @@
-package com.aventstack.extentreports.configuration;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.w3c.dom.CharacterData;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
-
-public class ConfigurationBuilder {
-
- private static final Logger logger = Logger.getLogger(ConfigurationBuilder.class.getName());
-
- private ConfigurationStore store = new ConfigurationStore();
- private InputStream stream;
-
- public ConfigurationBuilder(URL url) {
- try {
- stream = url.openStream();
- } catch (IOException e) {
- logger.log(Level.SEVERE, url.toString(), e);
- }
- }
-
- public ConfigurationBuilder(File file, Boolean silent) {
- try {
- if (silent && !file.exists())
- return;
- stream = new FileInputStream(file);
- } catch (FileNotFoundException e) {
- logger.log(Level.SEVERE, file.getPath(), e);
- }
- }
-
- public ConfigurationStore getConfigurationStore() {
- if (stream == null)
- return null;
-
- DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder documentBuilder;
- String value;
-
- try {
- documentBuilder = documentBuilderFactory.newDocumentBuilder();
-
- Document doc = documentBuilder.parse(stream);
- doc.getDocumentElement().normalize();
-
- NodeList nodeList = doc.getElementsByTagName("configuration").item(0).getChildNodes();
-
- for (int ix = 0; ix < nodeList.getLength(); ix++) {
- Node node = nodeList.item(ix);
-
- Element el = node.getNodeType() == Node.ELEMENT_NODE ? (Element) node : null;
-
- if (el != null) {
- value = el.getTextContent();
-
- value = el instanceof CharacterData ? ((CharacterData) el).getData() : value;
- store.storeConfig(el.getNodeName(), value);
- }
- }
-
- return store;
- } catch (IOException | SAXException | ParserConfigurationException e) {
- logger.log(Level.SEVERE, "Failed to load external configuration", e);
- }
-
- return null;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/configuration/ConfigurationStore.java b/src/main/java/com/aventstack/extentreports/configuration/ConfigurationStore.java
deleted file mode 100644
index 51e2acb..0000000
--- a/src/main/java/com/aventstack/extentreports/configuration/ConfigurationStore.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.aventstack.extentreports.configuration;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class ConfigurationStore {
-
- private Map store = new HashMap();
-
- public Map getStore() {
- return store;
- }
-
- public void storeConfig(String key, Object value) {
- store.put(key, value);
- }
-
- public boolean containsConfig(String k) {
- return store.containsKey(k);
- }
-
- public void removeConfig(String k) {
- store.remove(k);
- }
-
- public Object getConfig(String k) {
- return store.containsKey(k) ? store.get(k) : null;
- }
-
- public void extendConfig(Map map) {
- map.forEach((key, value) -> this.storeConfig(key, value));
- }
-
- public void extendConfig(ConfigurationStore config) {
- Map map = config.store;
- this.extendConfig(map);
- }
-
- public boolean isEmpty() {
- return store.isEmpty();
- }
-
-}
diff --git a/src/main/java/com/aventstack/extentreports/convert/JsonDeserializer.java b/src/main/java/com/aventstack/extentreports/convert/JsonDeserializer.java
deleted file mode 100644
index 669f6d0..0000000
--- a/src/main/java/com/aventstack/extentreports/convert/JsonDeserializer.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.aventstack.extentreports.convert;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Type;
-import java.nio.file.Files;
-import java.util.ArrayList;
-import java.util.List;
-
-import com.aventstack.extentreports.model.Test;
-import com.google.gson.Gson;
-import com.google.gson.reflect.TypeToken;
-
-class JsonDeserializer {
-
- public static List deserialize(File f) throws IOException {
- Gson gson = new Gson();
- String json = new String(Files.readAllBytes(f.toPath()));
- Type t = new TypeToken>() {}.getType();
- List tests = gson.fromJson(json, t);
- return tests;
- }
-
-}
diff --git a/src/main/java/com/aventstack/extentreports/convert/TestModelReportBuilder.java b/src/main/java/com/aventstack/extentreports/convert/TestModelReportBuilder.java
deleted file mode 100644
index eeef8a9..0000000
--- a/src/main/java/com/aventstack/extentreports/convert/TestModelReportBuilder.java
+++ /dev/null
@@ -1,71 +0,0 @@
-package com.aventstack.extentreports.convert;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-
-import com.aventstack.extentreports.ExtentReports;
-import com.aventstack.extentreports.ExtentTest;
-import com.aventstack.extentreports.GherkinKeyword;
-import com.aventstack.extentreports.model.Log;
-import com.aventstack.extentreports.model.Test;
-
-public class TestModelReportBuilder {
-
- public void createDomainFromJsonArchive(ExtentReports extent, File jsonFile) throws IOException {
- if (!jsonFile.exists()) {
- return;
- }
- Boolean configChanged = extent.getReportUsesManualConfiguration() ? false : true;
- extent.setReportUsesManualConfiguration(true);
- List tests = JsonDeserializer.deserialize(jsonFile);
- for (Test test : tests) {
- try {
- if (test.getBehaviorDrivenTypeName() == null) {
- createDomain(test, extent.createTest(test.getName(), test.getDescription()));
- } else {
- createDomain(test, extent.createTest(new GherkinKeyword(test.getBehaviorDrivenTypeName()),
- test.getName(), test.getDescription()));
-
- }
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- }
- if (configChanged) {
- extent.setReportUsesManualConfiguration(false);
- }
- }
-
- public void createDomain(Test test, ExtentTest extentTest) throws ClassNotFoundException {
- extentTest.getModel().setStartTime(test.getStartTime());
- extentTest.getModel().setEndTime(test.getEndTime());
- extentTest.getModel().computeEndTimeFromChildren();
-
- // create events
- for (Log log : test.getLogContext().getAll()) {
- if (log.getDetails() != null)
- extentTest.log(log.getStatus(), log.getDetails());
- if (log.getExceptionInfo() != null)
- extentTest.log(log.getStatus(), log.getExceptionInfo());
- }
-
- // assign attributes
- test.getAuthorContext().getAll().forEach(x -> extentTest.assignAuthor(x.getName()));
- test.getCategoryContext().getAll().forEach(x -> extentTest.assignCategory(x.getName()));
- test.getDeviceContext().getAll().forEach(x -> extentTest.assignDevice(x.getName()));
-
- // handle nodes
- for (Test node : test.getNodeContext().getAll()) {
- ExtentTest extentNode = null;
- if (node.getBehaviorDrivenTypeName() == null) {
- extentNode = extentTest.createNode(node.getName(), node.getDescription());
- } else {
- extentNode = extentTest.createNode(new GherkinKeyword(node.getBehaviorDrivenTypeName()), node.getName(),
- node.getDescription());
- }
- createDomain(node, extentNode);
- }
- }
-
-}
diff --git a/src/main/java/com/aventstack/extentreports/gherkin/GherkinDialect.java b/src/main/java/com/aventstack/extentreports/gherkin/GherkinDialect.java
index 37b51a5..d209f79 100644
--- a/src/main/java/com/aventstack/extentreports/gherkin/GherkinDialect.java
+++ b/src/main/java/com/aventstack/extentreports/gherkin/GherkinDialect.java
@@ -3,6 +3,9 @@
import java.util.List;
import java.util.Map;
+import lombok.Getter;
+import lombok.ToString;
+
/**
*
* Modified version of GherkinKeyword.java from cucumber/gherkin. Source url:
@@ -12,24 +15,16 @@
* Gherkin source is licensed under the MIT License
*
*/
+@Getter
+@ToString
public class GherkinDialect {
-
- private final Map> keywords;
- private String language;
-
- public GherkinDialect(String language, Map> keywords) {
- keywords.remove("name");
- keywords.remove("native");
- this.language = language;
- this.keywords = keywords;
- }
-
- public Map> getKeywords() {
- return keywords;
- }
+ private final Map> keywords;
+ private String language;
- public String getLanguage() {
- return language;
- }
-
-}
\ No newline at end of file
+ public GherkinDialect(String language, Map> keywords) {
+ keywords.remove("name");
+ keywords.remove("native");
+ this.language = language;
+ this.keywords = keywords;
+ }
+}
diff --git a/src/main/java/com/aventstack/extentreports/gherkin/GherkinDialectManager.java b/src/main/java/com/aventstack/extentreports/gherkin/GherkinDialectManager.java
new file mode 100644
index 0000000..6ca1efb
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/gherkin/GherkinDialectManager.java
@@ -0,0 +1,78 @@
+package com.aventstack.extentreports.gherkin;
+
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import com.google.gson.Gson;
+
+/**
+ *
+ * Modified version of GherkinDialectProvider.java from cucumber/gherkin. Source
+ * url:
+ * https://github.com/cucumber/cucumber/blob/master/gherkin/java/src/main/java/gherkin/GherkinDialectProvider.java.
+ *
+ *
+ * Gherkin source is licensed under the MIT License
+ *
+ */
+@SuppressWarnings("unchecked")
+public class GherkinDialectManager {
+ private static final Logger LOG = Logger.getLogger(GherkinDialectManager.class.getName());
+ private static final String DEFAULT_LANGUAGE = "en";
+ private static final String GHERKIN_LANGUAGES_JSON_URL = "https://github.com/cucumber/cucumber/blob/master/gherkin/gherkin-languages.json";
+ private static final String GHERKIN_LANGUAGES_PATH = "gherkin-languages.json";
+
+ private static GherkinDialect currentDialect;
+ private static Map>> dialects;
+ private static String language;
+
+ static {
+ Gson gson = new Gson();
+ try {
+ Reader d = new InputStreamReader(GherkinDialectManager.class.getResourceAsStream(GHERKIN_LANGUAGES_PATH),
+ "UTF-8");
+ dialects = gson.fromJson(d, Map.class);
+ } catch (UnsupportedEncodingException e) {
+ LOG.log(Level.SEVERE, "Unable to parse Gherkin languages file. Either the file is missing or corrupted.", e);
+ }
+ }
+
+ public static GherkinDialect getDialect() {
+ return currentDialect;
+ }
+
+ public static String getDefaultLanguage() {
+ return DEFAULT_LANGUAGE;
+ }
+
+ public static String getLanguage() {
+ if (language == null || language.isEmpty())
+ language = DEFAULT_LANGUAGE;
+ return language;
+ }
+
+ /**
+ * Sets/changes the default language
+ *
+ * @param lang
+ * A valid dialect from
+ * https://github.com/cucumber/cucumber/blob/master/gherkin/gherkin-languages.json
+ *
+ * @throws UnsupportedEncodingException
+ * Thrown if the language is one of the supported language from
+ * https://github.com/cucumber/cucumber/blob/master/gherkin/gherkin-languages.json
+ */
+ public static void setLanguage(String lang) throws UnsupportedEncodingException {
+ language = lang;
+ Map> map = dialects.get(GherkinDialectManager.language);
+ if (map == null)
+ throw new UnsupportedEncodingException("Invalid language [" + language
+ + "]. See list of supported languages: " + GHERKIN_LANGUAGES_JSON_URL);
+ currentDialect = new GherkinDialect(language, map);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/gherkin/GherkinDialectProvider.java b/src/main/java/com/aventstack/extentreports/gherkin/GherkinDialectProvider.java
deleted file mode 100644
index 4cc01cc..0000000
--- a/src/main/java/com/aventstack/extentreports/gherkin/GherkinDialectProvider.java
+++ /dev/null
@@ -1,77 +0,0 @@
-package com.aventstack.extentreports.gherkin;
-
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.io.UnsupportedEncodingException;
-import java.util.List;
-import java.util.Map;
-
-import com.google.gson.Gson;
-
-/**
- *
- * Modified version of GherkinDialectProvider.java from cucumber/gherkin. Source
- * url:
- * https://github.com/cucumber/cucumber/blob/master/gherkin/java/src/main/java/gherkin/GherkinDialectProvider.java.
- *
- *
- * Gherkin source is licensed under the MIT License
- *
- */
-@SuppressWarnings("unchecked")
-public class GherkinDialectProvider {
-
- private static final String DEFAULT_LANGUAGE = "en";
- private static final String GHERKIN_LANGUAGES_JSON_URL = "https://github.com/cucumber/cucumber/blob/master/gherkin/gherkin-languages.json";
- private static final String GHERKIN_LANGUAGES_PATH = "gherkin-languages.json";
-
- private static GherkinDialect currentDialect;
- private static Map>> dialects;
- private static String language;
-
- static {
- Gson gson = new Gson();
- try {
- Reader d = new InputStreamReader(GherkinDialectProvider.class.getResourceAsStream(GHERKIN_LANGUAGES_PATH),
- "UTF-8");
- dialects = gson.fromJson(d, Map.class);
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
- }
-
- public static GherkinDialect getDialect() {
- return currentDialect;
- }
-
- public static String getDefaultLanguage() {
- return DEFAULT_LANGUAGE;
- }
-
- public static String getLanguage() {
- if (language == null || language.isEmpty()) {
- language = DEFAULT_LANGUAGE;
- }
- return language;
- }
-
- /**
- * Sets/changes the default language
- *
- * @param lang A valid dialect from
- * https://github.com/cucumber/cucumber/blob/master/gherkin/gherkin-languages.json
- *
- * @throws UnsupportedEncodingException Thrown if the language is one of the
- * supported language from
- * https://github.com/cucumber/cucumber/blob/master/gherkin/gherkin-languages.json
- */
- public static void setLanguage(String lang) throws UnsupportedEncodingException {
- language = lang;
- Map> map = dialects.get(GherkinDialectProvider.language);
- if (map == null) {
- throw new UnsupportedEncodingException("Invalid language [" + language + "]. See list of supported languages: " + GHERKIN_LANGUAGES_JSON_URL);
- }
- currentDialect = new GherkinDialect(language, map);
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/gherkin/entity/And.java b/src/main/java/com/aventstack/extentreports/gherkin/entity/And.java
new file mode 100644
index 0000000..de999b3
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/gherkin/entity/And.java
@@ -0,0 +1,17 @@
+package com.aventstack.extentreports.gherkin.entity;
+
+import java.io.Serializable;
+
+public class And implements IGherkinFormatterModel, Serializable {
+ private static final long serialVersionUID = 8543289653944756660L;
+ private static final String VALUE = "And";
+
+ public static String getGherkinName() {
+ return VALUE;
+ }
+
+ @Override
+ public String toString() {
+ return getGherkinName();
+ }
+}
diff --git a/src/main/java/com/aventstack/extentreports/gherkin/entity/Asterisk.java b/src/main/java/com/aventstack/extentreports/gherkin/entity/Asterisk.java
new file mode 100644
index 0000000..01bee00
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/gherkin/entity/Asterisk.java
@@ -0,0 +1,17 @@
+package com.aventstack.extentreports.gherkin.entity;
+
+import java.io.Serializable;
+
+public class Asterisk implements IGherkinFormatterModel, Serializable {
+ private static final long serialVersionUID = 7251419811428200133L;
+ private static final String VALUE = "*";
+
+ public static String getGherkinName() {
+ return VALUE;
+ }
+
+ @Override
+ public String toString() {
+ return getGherkinName();
+ }
+}
diff --git a/src/main/java/com/aventstack/extentreports/gherkin/entity/Background.java b/src/main/java/com/aventstack/extentreports/gherkin/entity/Background.java
new file mode 100644
index 0000000..bef271a
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/gherkin/entity/Background.java
@@ -0,0 +1,17 @@
+package com.aventstack.extentreports.gherkin.entity;
+
+import java.io.Serializable;
+
+public class Background implements IGherkinFormatterModel, Serializable {
+ private static final long serialVersionUID = -955371501488725151L;
+ private static final String VALUE = "Background";
+
+ public static String getGherkinName() {
+ return VALUE;
+ }
+
+ @Override
+ public String toString() {
+ return getGherkinName();
+ }
+}
diff --git a/src/main/java/com/aventstack/extentreports/gherkin/entity/But.java b/src/main/java/com/aventstack/extentreports/gherkin/entity/But.java
new file mode 100644
index 0000000..f074d65
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/gherkin/entity/But.java
@@ -0,0 +1,17 @@
+package com.aventstack.extentreports.gherkin.entity;
+
+import java.io.Serializable;
+
+public class But implements IGherkinFormatterModel, Serializable {
+ private static final long serialVersionUID = 3420514631996827220L;
+ private static final String VALUE = "But";
+
+ public static String getGherkinName() {
+ return VALUE;
+ }
+
+ @Override
+ public String toString() {
+ return getGherkinName();
+ }
+}
diff --git a/src/main/java/com/aventstack/extentreports/gherkin/entity/Feature.java b/src/main/java/com/aventstack/extentreports/gherkin/entity/Feature.java
new file mode 100644
index 0000000..adc1fe2
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/gherkin/entity/Feature.java
@@ -0,0 +1,17 @@
+package com.aventstack.extentreports.gherkin.entity;
+
+import java.io.Serializable;
+
+public class Feature implements IGherkinFormatterModel, Serializable {
+ private static final long serialVersionUID = -4719215211721789414L;
+ private static final String VALUE = "Feature";
+
+ public static String getGherkinName() {
+ return VALUE;
+ }
+
+ @Override
+ public String toString() {
+ return getGherkinName();
+ }
+}
diff --git a/src/main/java/com/aventstack/extentreports/gherkin/entity/GherkinEntity.java b/src/main/java/com/aventstack/extentreports/gherkin/entity/GherkinEntity.java
new file mode 100644
index 0000000..ab081b0
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/gherkin/entity/GherkinEntity.java
@@ -0,0 +1,7 @@
+package com.aventstack.extentreports.gherkin.entity;
+
+import java.io.Serializable;
+
+public abstract class GherkinEntity implements Serializable {
+ private static final long serialVersionUID = 725203884274843593L;
+}
diff --git a/src/main/java/com/aventstack/extentreports/gherkin/entity/Given.java b/src/main/java/com/aventstack/extentreports/gherkin/entity/Given.java
new file mode 100644
index 0000000..10364f7
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/gherkin/entity/Given.java
@@ -0,0 +1,17 @@
+package com.aventstack.extentreports.gherkin.entity;
+
+import java.io.Serializable;
+
+public class Given implements IGherkinFormatterModel, Serializable {
+ private static final long serialVersionUID = 939197985263690070L;
+ private static final String VALUE = "Given";
+
+ public static String getGherkinName() {
+ return VALUE;
+ }
+
+ @Override
+ public String toString() {
+ return getGherkinName();
+ }
+}
diff --git a/src/main/java/com/aventstack/extentreports/gherkin/model/IGherkinFormatterModel.java b/src/main/java/com/aventstack/extentreports/gherkin/entity/IGherkinFormatterModel.java
similarity index 64%
rename from src/main/java/com/aventstack/extentreports/gherkin/model/IGherkinFormatterModel.java
rename to src/main/java/com/aventstack/extentreports/gherkin/entity/IGherkinFormatterModel.java
index d150968..687533c 100644
--- a/src/main/java/com/aventstack/extentreports/gherkin/model/IGherkinFormatterModel.java
+++ b/src/main/java/com/aventstack/extentreports/gherkin/entity/IGherkinFormatterModel.java
@@ -1,4 +1,4 @@
-package com.aventstack.extentreports.gherkin.model;
+package com.aventstack.extentreports.gherkin.entity;
import java.io.Serializable;
diff --git a/src/main/java/com/aventstack/extentreports/gherkin/entity/Scenario.java b/src/main/java/com/aventstack/extentreports/gherkin/entity/Scenario.java
new file mode 100644
index 0000000..d2a8a83
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/gherkin/entity/Scenario.java
@@ -0,0 +1,17 @@
+package com.aventstack.extentreports.gherkin.entity;
+
+import java.io.Serializable;
+
+public class Scenario implements IGherkinFormatterModel, Serializable {
+ private static final long serialVersionUID = 7401124129196617280L;
+ private static final String VALUE = "Scenario";
+
+ public static String getGherkinName() {
+ return VALUE;
+ }
+
+ @Override
+ public String toString() {
+ return getGherkinName();
+ }
+}
diff --git a/src/main/java/com/aventstack/extentreports/gherkin/entity/ScenarioOutline.java b/src/main/java/com/aventstack/extentreports/gherkin/entity/ScenarioOutline.java
new file mode 100644
index 0000000..5a329f7
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/gherkin/entity/ScenarioOutline.java
@@ -0,0 +1,17 @@
+package com.aventstack.extentreports.gherkin.entity;
+
+import java.io.Serializable;
+
+public class ScenarioOutline implements IGherkinFormatterModel, Serializable {
+ private static final long serialVersionUID = -2058398543903906031L;
+ private static final String VALUE = "Scenario Outline";
+
+ public static String getGherkinName() {
+ return VALUE;
+ }
+
+ @Override
+ public String toString() {
+ return getGherkinName();
+ }
+}
diff --git a/src/main/java/com/aventstack/extentreports/gherkin/entity/Then.java b/src/main/java/com/aventstack/extentreports/gherkin/entity/Then.java
new file mode 100644
index 0000000..e0f2c15
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/gherkin/entity/Then.java
@@ -0,0 +1,17 @@
+package com.aventstack.extentreports.gherkin.entity;
+
+import java.io.Serializable;
+
+public class Then implements IGherkinFormatterModel, Serializable {
+ private static final long serialVersionUID = 2493591502473169772L;
+ private static final String VALUE = "Then";
+
+ public static String getGherkinName() {
+ return VALUE;
+ }
+
+ @Override
+ public String toString() {
+ return getGherkinName();
+ }
+}
diff --git a/src/main/java/com/aventstack/extentreports/gherkin/entity/When.java b/src/main/java/com/aventstack/extentreports/gherkin/entity/When.java
new file mode 100644
index 0000000..1e0b610
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/gherkin/entity/When.java
@@ -0,0 +1,17 @@
+package com.aventstack.extentreports.gherkin.entity;
+
+import java.io.Serializable;
+
+public class When implements IGherkinFormatterModel, Serializable {
+ private static final long serialVersionUID = 8337259741948416898L;
+ private static final String VALUE = "When";
+
+ public static String getGherkinName() {
+ return VALUE;
+ }
+
+ @Override
+ public String toString() {
+ return getGherkinName();
+ }
+}
diff --git a/src/main/java/com/aventstack/extentreports/gherkin/model/And.java b/src/main/java/com/aventstack/extentreports/gherkin/model/And.java
deleted file mode 100644
index c2a2bff..0000000
--- a/src/main/java/com/aventstack/extentreports/gherkin/model/And.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.aventstack.extentreports.gherkin.model;
-
-import java.io.Serializable;
-
-public class And implements IGherkinFormatterModel, Serializable {
-
- private static final long serialVersionUID = 8543289653944756660L;
- private static final String VALUE = "And";
-
- public static String getGherkinName() {
- return VALUE;
- }
-
- @Override
- public String toString() {
- return getGherkinName();
- }
-
-}
diff --git a/src/main/java/com/aventstack/extentreports/gherkin/model/Asterisk.java b/src/main/java/com/aventstack/extentreports/gherkin/model/Asterisk.java
deleted file mode 100644
index c6e10d7..0000000
--- a/src/main/java/com/aventstack/extentreports/gherkin/model/Asterisk.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.aventstack.extentreports.gherkin.model;
-
-import java.io.Serializable;
-
-public class Asterisk implements IGherkinFormatterModel, Serializable {
-
- private static final long serialVersionUID = 7251419811428200133L;
- private static final String VALUE = "*";
-
- public static String getGherkinName() {
- return VALUE;
- }
-
- @Override
- public String toString() {
- return getGherkinName();
- }
-
-}
diff --git a/src/main/java/com/aventstack/extentreports/gherkin/model/Background.java b/src/main/java/com/aventstack/extentreports/gherkin/model/Background.java
deleted file mode 100644
index 1e42713..0000000
--- a/src/main/java/com/aventstack/extentreports/gherkin/model/Background.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.aventstack.extentreports.gherkin.model;
-
-import java.io.Serializable;
-
-public class Background implements IGherkinFormatterModel, Serializable {
-
- private static final long serialVersionUID = -955371501488725151L;
- private static final String VALUE = "Background";
-
- public static String getGherkinName() {
- return VALUE;
- }
-
- @Override
- public String toString() {
- return getGherkinName();
- }
-
-}
diff --git a/src/main/java/com/aventstack/extentreports/gherkin/model/But.java b/src/main/java/com/aventstack/extentreports/gherkin/model/But.java
deleted file mode 100644
index 6d88158..0000000
--- a/src/main/java/com/aventstack/extentreports/gherkin/model/But.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.aventstack.extentreports.gherkin.model;
-
-import java.io.Serializable;
-
-public class But implements IGherkinFormatterModel, Serializable {
-
- private static final long serialVersionUID = 3420514631996827220L;
- private static final String VALUE = "But";
-
- public static String getGherkinName() {
- return VALUE;
- }
-
- @Override
- public String toString() {
- return getGherkinName();
- }
-
-}
diff --git a/src/main/java/com/aventstack/extentreports/gherkin/model/Feature.java b/src/main/java/com/aventstack/extentreports/gherkin/model/Feature.java
deleted file mode 100644
index 6475396..0000000
--- a/src/main/java/com/aventstack/extentreports/gherkin/model/Feature.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.aventstack.extentreports.gherkin.model;
-
-import java.io.Serializable;
-
-public class Feature implements IGherkinFormatterModel, Serializable {
-
- private static final long serialVersionUID = -4719215211721789414L;
- private static final String VALUE = "Feature";
-
- public static String getGherkinName() {
- return VALUE;
- }
-
- @Override
- public String toString() {
- return getGherkinName();
- }
-
-}
diff --git a/src/main/java/com/aventstack/extentreports/gherkin/model/GherkinModelSerializer.java b/src/main/java/com/aventstack/extentreports/gherkin/model/GherkinModelSerializer.java
deleted file mode 100644
index 242fefa..0000000
--- a/src/main/java/com/aventstack/extentreports/gherkin/model/GherkinModelSerializer.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.aventstack.extentreports.gherkin.model;
-
-import java.io.IOException;
-
-import com.google.gson.TypeAdapter;
-import com.google.gson.stream.JsonReader;
-import com.google.gson.stream.JsonWriter;
-
-public class GherkinModelSerializer extends TypeAdapter {
-
- @Override
- public void write(JsonWriter out, IGherkinFormatterModel value) throws IOException {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public IGherkinFormatterModel read(JsonReader in) throws IOException {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
diff --git a/src/main/java/com/aventstack/extentreports/gherkin/model/Given.java b/src/main/java/com/aventstack/extentreports/gherkin/model/Given.java
deleted file mode 100644
index 483b0d2..0000000
--- a/src/main/java/com/aventstack/extentreports/gherkin/model/Given.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.aventstack.extentreports.gherkin.model;
-
-import java.io.Serializable;
-
-public class Given implements IGherkinFormatterModel, Serializable {
-
- private static final long serialVersionUID = 939197985263690070L;
- private static final String VALUE = "Given";
-
- public static String getGherkinName() {
- return VALUE;
- }
-
- @Override
- public String toString() {
- return getGherkinName();
- }
-
-}
diff --git a/src/main/java/com/aventstack/extentreports/gherkin/model/Scenario.java b/src/main/java/com/aventstack/extentreports/gherkin/model/Scenario.java
deleted file mode 100644
index 683f4d1..0000000
--- a/src/main/java/com/aventstack/extentreports/gherkin/model/Scenario.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.aventstack.extentreports.gherkin.model;
-
-import java.io.Serializable;
-
-public class Scenario implements IGherkinFormatterModel, Serializable {
-
- private static final long serialVersionUID = 7401124129196617280L;
- private static final String VALUE = "Scenario";
-
- public static String getGherkinName() {
- return VALUE;
- }
-
- @Override
- public String toString() {
- return getGherkinName();
- }
-
-}
diff --git a/src/main/java/com/aventstack/extentreports/gherkin/model/ScenarioOutline.java b/src/main/java/com/aventstack/extentreports/gherkin/model/ScenarioOutline.java
deleted file mode 100644
index 6b84733..0000000
--- a/src/main/java/com/aventstack/extentreports/gherkin/model/ScenarioOutline.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.aventstack.extentreports.gherkin.model;
-
-import java.io.Serializable;
-
-public class ScenarioOutline implements IGherkinFormatterModel, Serializable {
-
- private static final long serialVersionUID = -2058398543903906031L;
- private static final String VALUE = "Scenario Outline";
-
- public static String getGherkinName() {
- return VALUE;
- }
-
- @Override
- public String toString() {
- return getGherkinName();
- }
-
-}
diff --git a/src/main/java/com/aventstack/extentreports/gherkin/model/Then.java b/src/main/java/com/aventstack/extentreports/gherkin/model/Then.java
deleted file mode 100644
index 2ad2bc7..0000000
--- a/src/main/java/com/aventstack/extentreports/gherkin/model/Then.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.aventstack.extentreports.gherkin.model;
-
-import java.io.Serializable;
-
-public class Then implements IGherkinFormatterModel, Serializable {
-
- private static final long serialVersionUID = 2493591502473169772L;
- private static final String VALUE = "Then";
-
- public static String getGherkinName() {
- return VALUE;
- }
-
- @Override
- public String toString() {
- return getGherkinName();
- }
-
-}
diff --git a/src/main/java/com/aventstack/extentreports/gherkin/model/When.java b/src/main/java/com/aventstack/extentreports/gherkin/model/When.java
deleted file mode 100644
index d9460db..0000000
--- a/src/main/java/com/aventstack/extentreports/gherkin/model/When.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.aventstack.extentreports.gherkin.model;
-
-import java.io.Serializable;
-
-public class When implements IGherkinFormatterModel, Serializable {
-
- private static final long serialVersionUID = 8337259741948416898L;
- private static final String VALUE = "When";
-
- public static String getGherkinName() {
- return VALUE;
- }
-
- @Override
- public String toString() {
- return getGherkinName();
- }
-
-}
diff --git a/src/main/java/com/aventstack/extentreports/io/BufferedWriterWriter.java b/src/main/java/com/aventstack/extentreports/io/BufferedWriterWriter.java
new file mode 100644
index 0000000..5661df3
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/io/BufferedWriterWriter.java
@@ -0,0 +1,35 @@
+package com.aventstack.extentreports.io;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class BufferedWriterWriter {
+
+ private static class WriterInstance {
+ static final BufferedWriterWriter INSTANCE = new BufferedWriterWriter();
+
+ private WriterInstance() {
+ }
+ }
+
+ static final Logger logger = Logger.getLogger(BufferedWriterWriter.class.getName());
+
+ private BufferedWriterWriter() {
+ }
+
+ public synchronized void write(final File f, String text) {
+ try (BufferedWriter writer = new BufferedWriter(new FileWriter(f))) {
+ writer.write(text);
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, f.getPath(), e);
+ }
+ }
+
+ public static BufferedWriterWriter getInstance() {
+ return WriterInstance.INSTANCE;
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/io/FileWriterBuffered.java b/src/main/java/com/aventstack/extentreports/io/FileWriterBuffered.java
deleted file mode 100644
index 76b1bcb..0000000
--- a/src/main/java/com/aventstack/extentreports/io/FileWriterBuffered.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.aventstack.extentreports.io;
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-public class FileWriterBuffered {
-
- private static class WriterInstance {
- static final FileWriterBuffered INSTANCE = new FileWriterBuffered();
-
- private WriterInstance() {
- }
- }
-
- static final Logger logger = Logger.getLogger(FileWriterBuffered.class.getName());
-
- private FileWriterBuffered() {
- }
-
- public synchronized void write(final File f, String text) {
- try (BufferedWriter writer = new BufferedWriter(new FileWriter(f))) {
- writer.write(text);
- } catch (Exception e) {
- logger.log(Level.SEVERE, f.getPath(), e);
- }
- }
-
- public static FileWriterBuffered getInstance() {
- return WriterInstance.INSTANCE;
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/io/ResourceUtil.java b/src/main/java/com/aventstack/extentreports/io/ResourceUtil.java
deleted file mode 100644
index 6069081..0000000
--- a/src/main/java/com/aventstack/extentreports/io/ResourceUtil.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package com.aventstack.extentreports.io;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.nio.file.StandardCopyOption;
-
-public class ResourceUtil {
-
- public static void moveResource(String resourcePath, String copyPath) {
- if (copyPath != null)
- copyPath = copyPath.replace("\\", "/");
- if (resourcePath != null)
- resourcePath = resourcePath.replace("\\", "/");
-
- try {
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- InputStream in = classLoader.getResourceAsStream(resourcePath);
-
- FileOutputStream out = new FileOutputStream(copyPath);
-
- byte[] b = new byte[1024];
- int noOfBytes = 0;
-
- while ((noOfBytes = in.read(b)) != -1) {
- out.write(b, 0, noOfBytes);
- }
-
- in.close();
- out.close();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- public static void moveBinaryFile(String resourcePath, String copyPath) {
- URI uri = new File(resourcePath).toURI();
- Path path = Paths.get(uri);
- try {
- Files.copy(path, new File(copyPath).toPath(), StandardCopyOption.REPLACE_EXISTING);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/json/JsonDeserializer.java b/src/main/java/com/aventstack/extentreports/json/JsonDeserializer.java
new file mode 100644
index 0000000..533e853
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/json/JsonDeserializer.java
@@ -0,0 +1,23 @@
+package com.aventstack.extentreports.json;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Type;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.aventstack.extentreports.model.Test;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+
+class JsonDeserializer {
+ public List deserialize(File f) throws IOException {
+ Gson gson = new Gson();
+ String json = new String(Files.readAllBytes(f.toPath()));
+ Type t = new TypeToken>() {
+ }.getType();
+ List tests = gson.fromJson(json, t);
+ return tests;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/markuputils/CodeBlock.java b/src/main/java/com/aventstack/extentreports/markuputils/CodeBlock.java
index d378816..a3529c5 100644
--- a/src/main/java/com/aventstack/extentreports/markuputils/CodeBlock.java
+++ b/src/main/java/com/aventstack/extentreports/markuputils/CodeBlock.java
@@ -5,61 +5,63 @@
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
+import com.google.gson.Gson;
+
import freemarker.template.Template;
import freemarker.template.TemplateException;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.ToString;
+@Getter
+@Builder
+@AllArgsConstructor
+@ToString
class CodeBlock extends MarkupTemplate implements Markup {
- private static final long serialVersionUID = -5532095355983830164L;
- private static final AtomicInteger id = new AtomicInteger(0);
- private static final String CODEBLOCK_TEMPLATE = "codeblock.ftl";
- private static final String CODEBLOCK_JSON_TEMPLATE = "codeblock.json.ftl";
- private static Template codeblock;
- private static Template codeblockJson;
- private String code;
- private CodeLanguage lang;
-
- static {
- try {
- codeblock = ft.createTemplate(CODEBLOCK_TEMPLATE);
- codeblockJson = ft.createTemplate(CODEBLOCK_JSON_TEMPLATE);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public void setCodeBlock(String code) {
- this.code = code;
- }
-
- public String getCodeBlock() {
- return code;
- }
+ private static final long serialVersionUID = -5532095355983830164L;
+ private static final AtomicInteger id = new AtomicInteger(0);
+ private static final String CODEBLOCK_TEMPLATE = "codeblock.ftl";
+ private static final String CODEBLOCK_JSON_TEMPLATE = "codeblock.json.ftl";
+ private static Template codeblock;
+ private static Template codeblockJson;
+ private String code;
+ private CodeLanguage lang;
+ private Object jsonObject;
- public void setCodeBlock(String code, CodeLanguage lang) {
- this.code = code;
- this.lang = lang;
- }
+ static {
+ try {
+ codeblock = ft.createTemplate(CODEBLOCK_TEMPLATE);
+ codeblockJson = ft.createTemplate(CODEBLOCK_JSON_TEMPLATE);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
- @Override
- public String getMarkup() {
- int index = 0;
- Template t = codeblock;
- if (lang == CodeLanguage.JSON) {
- index = id.getAndIncrement();
- t = codeblockJson;
- }
- Map map = new HashMap<>();
- map.put("code", code);
- map.put("index", index);
- try {
- return ft.getSource(t, map);
- } catch (TemplateException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
+ @Override
+ public String getMarkup() {
+ if (code == null && jsonObject == null)
+ return "";
+ if (jsonObject != null)
+ code = new Gson().toJson(jsonObject);
+ int index = 0;
+ Template t = codeblock;
+ if (lang == CodeLanguage.JSON) {
+ index = id.getAndIncrement();
+ t = codeblockJson;
+ }
+ Map map = new HashMap<>();
+ map.put("code", code);
+ map.put("index", index);
+ try {
+ return ft.getSource(t, map);
+ } catch (TemplateException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
}
diff --git a/src/main/java/com/aventstack/extentreports/markuputils/CodeLanguage.java b/src/main/java/com/aventstack/extentreports/markuputils/CodeLanguage.java
index 67f07ca..eb74eea 100644
--- a/src/main/java/com/aventstack/extentreports/markuputils/CodeLanguage.java
+++ b/src/main/java/com/aventstack/extentreports/markuputils/CodeLanguage.java
@@ -4,6 +4,5 @@
* List of supported languages that will be prettified on output
*/
public enum CodeLanguage {
- XML,
- JSON
+ XML, JSON
}
diff --git a/src/main/java/com/aventstack/extentreports/markuputils/HtmlList.java b/src/main/java/com/aventstack/extentreports/markuputils/HtmlList.java
new file mode 100644
index 0000000..1a0dfd3
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/markuputils/HtmlList.java
@@ -0,0 +1,38 @@
+package com.aventstack.extentreports.markuputils;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+abstract class HtmlList {
+ @SuppressWarnings("unchecked")
+ protected String getList(Object object, ListType listType) {
+ final StringBuilder sb = new StringBuilder();
+ sb.append("<" + listType.toString().toLowerCase() + ">");
+ if (object instanceof Map) {
+ for (Map.Entry entry : ((Map) object).entrySet()) {
+ sb.append("");
+ sb.append(entry.getKey());
+ sb.append(":");
+ sb.append(entry.getValue());
+ sb.append(" ");
+ }
+ } else if (object instanceof List || object instanceof Set || object.getClass().isArray()) {
+ if (object.getClass().isArray())
+ object = Arrays.asList((Object[])object);
+ for (Object o : (Collection) object) {
+ sb.append("");
+ sb.append(o.toString());
+ sb.append(" ");
+ }
+ } else {
+ sb.append("");
+ sb.append(object.toString());
+ sb.append(" ");
+ }
+ sb.append("" + listType.toString().toLowerCase() + ">");
+ return sb.toString();
+ }
+}
diff --git a/src/main/java/com/aventstack/extentreports/markuputils/Label.java b/src/main/java/com/aventstack/extentreports/markuputils/Label.java
index 698d1b4..b71a986 100644
--- a/src/main/java/com/aventstack/extentreports/markuputils/Label.java
+++ b/src/main/java/com/aventstack/extentreports/markuputils/Label.java
@@ -1,27 +1,33 @@
package com.aventstack.extentreports.markuputils;
-class Label implements Markup {
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+@Getter
+@Setter
+@Builder
+@AllArgsConstructor
+@ToString
+class Label implements Markup {
private static final long serialVersionUID = 548763908072445261L;
-
- private String text = "";
- private ExtentColor color = ExtentColor.TRANSPARENT;
-
- public void setText(String text) {
- this.text = text;
- }
- public String getText() { return text; }
-
- public void setColor(ExtentColor color) {
- this.color = color;
- }
- public ExtentColor getColor() { return color; }
+
+ private String text;
+ private ExtentColor color;
public String getMarkup() {
+ if (text == null || text.isEmpty())
+ return "";
String textColor = color != ExtentColor.WHITE ? "white-text" : "black-text";
String lhs = "";
String rhs = " ";
-
return lhs + text + rhs;
}
+
+ public static class LabelBuilder {
+ private String text = "";
+ private ExtentColor color = ExtentColor.TRANSPARENT;
+ }
}
diff --git a/src/main/java/com/aventstack/extentreports/markuputils/ListType.java b/src/main/java/com/aventstack/extentreports/markuputils/ListType.java
new file mode 100644
index 0000000..6bf7872
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/markuputils/ListType.java
@@ -0,0 +1,5 @@
+package com.aventstack.extentreports.markuputils;
+
+enum ListType {
+ OL, UL
+}
diff --git a/src/main/java/com/aventstack/extentreports/markuputils/Markup.java b/src/main/java/com/aventstack/extentreports/markuputils/Markup.java
index bd8856c..9dea7e7 100644
--- a/src/main/java/com/aventstack/extentreports/markuputils/Markup.java
+++ b/src/main/java/com/aventstack/extentreports/markuputils/Markup.java
@@ -4,5 +4,5 @@
@FunctionalInterface
public interface Markup extends Serializable {
- String getMarkup();
-}
+ String getMarkup();
+}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/markuputils/MarkupHelper.java b/src/main/java/com/aventstack/extentreports/markuputils/MarkupHelper.java
index 42ca33d..e347fb0 100644
--- a/src/main/java/com/aventstack/extentreports/markuputils/MarkupHelper.java
+++ b/src/main/java/com/aventstack/extentreports/markuputils/MarkupHelper.java
@@ -2,29 +2,79 @@
public class MarkupHelper {
- public static Markup createLabel(String text, ExtentColor color) {
- Label l = new Label();
- l.setText(text);
- l.setColor(color);
- return l;
- }
-
- public static Markup createCodeBlock(String code) {
- CodeBlock cb = new CodeBlock();
- cb.setCodeBlock(code);
- return cb;
- }
-
- public static Markup createCodeBlock(String code, CodeLanguage lang) {
- CodeBlock cb = new CodeBlock();
- cb.setCodeBlock(code, lang);
- return cb;
- }
-
- public static Markup createTable(String[][] data) {
- Table t = new Table();
- t.setData(data);
- return t;
- }
+ public static Markup createLabel(String text, ExtentColor color) {
+ return Label.builder().text(text).color(color).build();
+ }
+
+ public static Markup createCodeBlock(String code) {
+ return CodeBlock.builder().code(code).build();
+ }
+
+ public static Markup createCodeBlock(String code, CodeLanguage lang) {
+ return CodeBlock.builder().code(code).lang(lang).build();
+ }
+
+ public static Markup createCodeBlock(Object o) {
+ return CodeBlock.builder().jsonObject(o).lang(CodeLanguage.JSON).build();
+ }
+
+ /**
+ * Creates an ordered list from one of the following underlying collections
+ *
+ *
+ * List
+ * Map
+ * Set
+ *
+ *
+ * @param o
+ * An iterable collection
+ * @return {@link Markup}
+ */
+ public static Markup createOrderedList(Object o) {
+ return OrderedList.builder().object(o).build();
+ }
+
+ /**
+ * Creates an unordered list from one of the following underlying
+ * collections
+ *
+ *
+ * List
+ * Map
+ * Set
+ *
+ *
+ * @param o
+ * An iterable collection
+ * @return {@link Markup}
+ */
+ public static Markup createUnorderedList(Object o) {
+ return UnorderedList.builder().object(o).build();
+ }
+
+ public static Markup createTable(String[][] data, String[] cssClass) {
+ return Table.builder().data(data).cssClasses(cssClass).build();
+ }
+
+ public static Markup createTable(String[][] data, String cssClass) {
+ return Table.builder().data(data).cssClass(cssClass).build();
+ }
+
+ public static Markup createTable(String[][] data) {
+ return Table.builder().data(data).build();
+ }
+
+ public static Markup toTable(Object o, String[] cssClass) {
+ return Table.builder().object(o).cssClasses(cssClass).build();
+ }
+
+ public static Markup toTable(Object o, String cssClass) {
+ return Table.builder().object(o).cssClass(cssClass).build();
+ }
+
+ public static Markup toTable(Object o) {
+ return Table.builder().object(o).build();
+ }
}
diff --git a/src/main/java/com/aventstack/extentreports/markuputils/MarkupTemplate.java b/src/main/java/com/aventstack/extentreports/markuputils/MarkupTemplate.java
index f5db943..eb9780c 100644
--- a/src/main/java/com/aventstack/extentreports/markuputils/MarkupTemplate.java
+++ b/src/main/java/com/aventstack/extentreports/markuputils/MarkupTemplate.java
@@ -4,7 +4,5 @@
import com.aventstack.extentreports.templating.FreemarkerTemplate;
class MarkupTemplate {
-
- protected static final FreemarkerTemplate ft = new FreemarkerTemplate(ExtentReports.class, "markup/", "UTF-8");
-
+ protected static final FreemarkerTemplate ft = new FreemarkerTemplate(ExtentReports.class, "markup/", "UTF-8");
}
diff --git a/src/main/java/com/aventstack/extentreports/markuputils/OrderedList.java b/src/main/java/com/aventstack/extentreports/markuputils/OrderedList.java
new file mode 100644
index 0000000..f5aa004
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/markuputils/OrderedList.java
@@ -0,0 +1,21 @@
+package com.aventstack.extentreports.markuputils;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.ToString;
+
+@Getter
+@Builder
+@AllArgsConstructor
+@ToString
+public class OrderedList extends HtmlList implements Markup {
+ private static final long serialVersionUID = -1763712576872406878L;
+
+ private Object object;
+
+ @Override
+ public String getMarkup() {
+ return getList(object, ListType.OL);
+ }
+}
diff --git a/src/main/java/com/aventstack/extentreports/markuputils/Table.java b/src/main/java/com/aventstack/extentreports/markuputils/Table.java
index 5fcc4bc..15a272a 100644
--- a/src/main/java/com/aventstack/extentreports/markuputils/Table.java
+++ b/src/main/java/com/aventstack/extentreports/markuputils/Table.java
@@ -1,23 +1,55 @@
package com.aventstack.extentreports.markuputils;
-class Table implements Markup {
+import java.lang.reflect.Field;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import com.aventstack.extentreports.annotations.MarkupIgnore;
+import com.aventstack.extentreports.markuputils.util.ReflectionUtil;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.ToString;
+@Getter
+@Builder
+@AllArgsConstructor
+@ToString
+class Table implements Markup {
private static final long serialVersionUID = 7780527162407673294L;
-
+
private String[][] data;
-
- public void setData(String[][] data) {
- this.data = data;
- }
- public String[][] getData() { return data; }
-
+ private Object object;
+ @Builder.Default
+ private String cssClass = "";
+ private String[] cssClasses;
+
@Override
public String getMarkup() {
+ if (cssClasses != null && cssClasses.length > 0)
+ Arrays.asList(cssClasses).forEach(x -> cssClass += " " + x);
+ if (data != null)
+ return fromData();
+ try {
+ return fromObject();
+ } catch (IllegalArgumentException | IllegalAccessException e) {
+ e.printStackTrace();
+ return "";
+ }
+ }
+
+ private String fromData() {
StringBuilder sb = new StringBuilder();
- sb.append("");
- for(int row = 0; row < data.length; row++){
+ sb.append("");
+ for (int row = 0; row < data.length; row++) {
sb.append("");
- for(int col = 0; col < data[row].length; col++){
+ for (int col = 0; col < data[row].length; col++) {
sb.append("" + data[row][col] + " ");
}
sb.append(" ");
@@ -26,4 +58,90 @@ public String getMarkup() {
return sb.toString();
}
+ private String fromObject() throws IllegalArgumentException, IllegalAccessException {
+ if (object == null)
+ return "";
+ final List fieldList = ReflectionUtil.getFieldsIgnoringAnnotation(object.getClass(), MarkupIgnore.class);
+ final StringBuilder sb = new StringBuilder();
+ final StringBuilder sb2 = new StringBuilder();
+ sb.append("");
+ sb.append("");
+ final List list = Stream.of("").collect(Collectors.toList());
+ final List columnRowCount = Stream.of(0).collect(Collectors.toList());
+ if (object instanceof Map) {
+ appendMapItems(object, list, sb2, columnRowCount);
+ } else if (object instanceof List || object instanceof Set) {
+ appendListItems(object, list, sb2, columnRowCount);
+ } else if (object instanceof String) {
+ list.set(0, "" + object.toString() + " ");
+ } else if (object.getClass().isArray()) {
+ appendArrayItems(object, list, sb2, columnRowCount);
+ } else if (!fieldList.isEmpty()) {
+ sb.append("");
+ fieldList.forEach(x -> sb.append("" + x.getName() + " "));
+ sb.append(" ");
+ for (Field f : fieldList) {
+ if (f != null && !f.isAccessible()) {
+ f.setAccessible(true);
+ }
+ if (f.getType().isAssignableFrom(Map.class)) {
+ appendMapItems(f.get(object), list, sb2, columnRowCount);
+ } else if (f.getType().isAssignableFrom(List.class) || f.getType().isAssignableFrom(Set.class)) {
+ appendListItems(f.get(object), list, sb2, columnRowCount);
+ } else if (f.getType().isArray()) {
+ appendArrayItems(f.get(object), list, sb2, columnRowCount);
+ } else {
+ list.set(0, list.get(0) + "" + f.get(object).toString() + " ");
+ columnRowCount.set(columnRowCount.size() - 1, 1);
+ }
+ columnRowCount.add(0);
+ }
+ } else {
+ list.set(0, "" + object.toString() + " ");
+ }
+ list.forEach(x -> sb.append("" + x + " "));
+ sb.append(" ");
+ sb.append("
");
+ return sb.toString();
+ }
+
+ @SuppressWarnings("unchecked")
+ private void appendMapItems(Object object, List list, StringBuilder sb, List columnRowCount) {
+ Map map = (Map) object;
+ for (int ix = map.size(); ix >= list.size(); ix--)
+ list.add("");
+ columnRowCount.set(columnRowCount.size() - 1, map.size());
+ int row = 0;
+ for (Map.Entry entry : map.entrySet()) {
+ sb.setLength(0);
+ if (columnRowCount.size() > 1 && row + 1 > columnRowCount.get(columnRowCount.size() - 2))
+ sb.append(" ");
+ sb.append("" + entry.getKey() + ":" + entry.getValue() + " ");
+ list.set(row, list.get(row) + sb.toString());
+ row++;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private void appendListItems(Object object, List list, StringBuilder sb, List columnRowCount) {
+ int row = 0;
+ Collection obj = (Collection) object;
+ for (int ix = obj.size(); ix >= list.size(); ix--)
+ list.add("");
+ columnRowCount.set(columnRowCount.size() - 1, obj.size());
+ for (Object o : obj) {
+ sb.setLength(0);
+ if (columnRowCount.size() > 1 && row + 1 > columnRowCount.get(columnRowCount.size() - 2)) {
+ sb.append(" ");
+ }
+ sb.append("" + o.toString() + " ");
+ list.set(row, list.get(row) + sb.toString());
+ row++;
+ }
+ }
+
+ private void appendArrayItems(Object object, List list, StringBuilder sb, List columnRowCount) {
+ List obj = Arrays.asList(((Object[]) object));
+ appendListItems(obj, list, sb, columnRowCount);
+ }
}
diff --git a/src/main/java/com/aventstack/extentreports/markuputils/UnorderedList.java b/src/main/java/com/aventstack/extentreports/markuputils/UnorderedList.java
new file mode 100644
index 0000000..dac4bf2
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/markuputils/UnorderedList.java
@@ -0,0 +1,22 @@
+package com.aventstack.extentreports.markuputils;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.ToString;
+
+@Getter
+@Builder
+@AllArgsConstructor
+@ToString
+class UnorderedList extends HtmlList implements Markup {
+ private static final long serialVersionUID = 2056301782889894819L;
+
+ private Object object;
+
+ @Override
+ public String getMarkup() {
+ return getList(object, ListType.UL);
+ }
+
+}
diff --git a/src/main/java/com/aventstack/extentreports/markuputils/util/ReflectionUtil.java b/src/main/java/com/aventstack/extentreports/markuputils/util/ReflectionUtil.java
new file mode 100644
index 0000000..1c79b9d
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/markuputils/util/ReflectionUtil.java
@@ -0,0 +1,36 @@
+package com.aventstack.extentreports.markuputils.util;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class ReflectionUtil {
+ public static List getFieldsIgnoringAnnotation(Class> clazz,
+ Class extends Annotation> skippingAnnotationClazz) {
+ if (clazz == null)
+ return Collections.emptyList();
+ List fields = new ArrayList<>(
+ getFieldsIgnoringAnnotation(clazz.getSuperclass(), skippingAnnotationClazz));
+ List filteredList = Arrays.stream(clazz.getDeclaredFields())
+ .filter(x -> !x.isAnnotationPresent(skippingAnnotationClazz))
+ .collect(Collectors.toList());
+ fields.addAll(filteredList);
+ return fields;
+ }
+
+ public static List getAnnotatedFields(Class> clazz,
+ Class extends Annotation> annotationClazz) {
+ if (clazz == null)
+ return Collections.emptyList();
+ List fields = new ArrayList<>(getAnnotatedFields(clazz.getSuperclass(), annotationClazz));
+ List filteredList = Arrays.stream(clazz.getDeclaredFields())
+ .filter(x -> x.isAnnotationPresent(annotationClazz))
+ .collect(Collectors.toList());
+ fields.addAll(filteredList);
+ return fields;
+ }
+}
diff --git a/src/main/java/com/aventstack/extentreports/mediastorage/KlovMediaStorageHandler.java b/src/main/java/com/aventstack/extentreports/mediastorage/KlovMediaStorageHandler.java
deleted file mode 100644
index b233c44..0000000
--- a/src/main/java/com/aventstack/extentreports/mediastorage/KlovMediaStorageHandler.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.aventstack.extentreports.mediastorage;
-
-import java.io.IOException;
-
-import org.bson.Document;
-import org.bson.types.ObjectId;
-
-import com.aventstack.extentreports.mediastorage.impl.HttpMediaManagerImplKlov;
-import com.aventstack.extentreports.mediastorage.model.KlovMedia;
-import com.aventstack.extentreports.model.BasicMongoReportElement;
-import com.aventstack.extentreports.model.ScreenCapture;
-import com.aventstack.extentreports.model.Test;
-import com.aventstack.extentreports.utils.MongoUtil;
-
-public class KlovMediaStorageHandler {
-
- private MediaStorage mediaStorage;
- private KlovMedia klovMedia;
-
- public KlovMediaStorageHandler(String url, KlovMedia klovMedia) throws IOException {
- if (url == null || url.isEmpty()) {
- throw new IllegalArgumentException("Invalid URL or resource not found");
- }
- this.klovMedia = klovMedia;
- this.mediaStorage = new HttpMediaManagerImplKlov();
- mediaStorage.init(url);
- }
-
- public void saveScreenCapture(BasicMongoReportElement el, ScreenCapture media) throws IOException {
- Document doc = new Document("project", klovMedia.getProjectId())
- .append("report", klovMedia.getReportId())
- .append("sequence", media.getSequence())
- .append("test", media.getBsonId().get("testId"));
-
- if (media.isBase64()) {
- doc.append("base64String", media.getBase64String());
- }
- if (el.getClass() != Test.class) {
- doc.append("log", el.getObjectId());
- } else {
- doc.append("testName", ((Test)el).getName());
- }
-
- klovMedia.getMediaCollection().insertOne(doc);
- ObjectId mediaId = MongoUtil.getId(doc);
- media.getBsonId().put("id", mediaId);
- media.getBsonId().put("reportId", klovMedia.getReportId());
- mediaStorage.storeMedia((ScreenCapture)media);
- }
-
-}
diff --git a/src/main/java/com/aventstack/extentreports/mediastorage/LocalMediaStorageHandler.java b/src/main/java/com/aventstack/extentreports/mediastorage/LocalMediaStorageHandler.java
deleted file mode 100644
index ef2427b..0000000
--- a/src/main/java/com/aventstack/extentreports/mediastorage/LocalMediaStorageHandler.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package com.aventstack.extentreports.mediastorage;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.logging.Logger;
-
-import com.aventstack.extentreports.model.Media;
-import com.aventstack.extentreports.utils.FileUtil;
-
-public class LocalMediaStorageHandler
- implements MediaStorage {
-
- private static final Logger logger = Logger.getLogger(LocalMediaStorageHandler.class.getName());
-
- private String reporterGeneratedFilePath;
- private String targetPath;
- private String relativePath;
-
- public void init(String reporterGeneratedFilePath) {
- this.reporterGeneratedFilePath = reporterGeneratedFilePath;
- mkDirs();
- }
-
- public void storeMedia(Media screenCapture) throws IOException {
- storeMediaFileLocal(screenCapture);
- }
-
- private void mkDirs() {
- String ext = FileUtil.getExtension(reporterGeneratedFilePath);
- String archiveName = "";
- if (ext.equalsIgnoreCase("htm") || ext.equalsIgnoreCase("html")) {
- archiveName = FileUtil.getFileNameWithoutExtension(reporterGeneratedFilePath) + ".";
- }
- String absolutePath = new File(reporterGeneratedFilePath).getAbsolutePath().replace("\\", "/");
- String basePath = archiveName.isEmpty() ? absolutePath : new File(absolutePath).getParent().replace("\\", "/");
- archiveName = archiveName.isEmpty() ? archiveName = FileUtil.getFileNameWithoutExtension(reporterGeneratedFilePath) + "." : archiveName;
-
- mkDirs(basePath, archiveName, 0);
- }
-
- private void mkDirs(String basePath, String fileName, int cnt) {
- relativePath = fileName + cnt + "/";
- targetPath = basePath + "/" + relativePath;
-
- File f = new File(targetPath);
- if (!f.exists()) {
- f.mkdirs();
- }
- else {
- mkDirs(basePath, fileName, ++cnt);
- }
- }
-
- private void storeMediaFileLocal(Media media) throws IOException {
- File f = new File(media.getPath());
- if (!f.exists()) {
- logger.warning("Unable to locate media file: " + media.getPath());
- return;
- }
-
- String baseFileName = new File(media.getPath()).getName();
- String mediaFileName = baseFileName;
- String copyToPath = targetPath + baseFileName;
- File copyToFile = new File(copyToPath);
- int cnt = 0;
-
- while(copyToFile.exists()) {
- String name = FileUtil.getFileNameWithoutExtension(baseFileName) + "." + cnt;
- String ext = FileUtil.getExtension(baseFileName);
- mediaFileName = name + "." + ext;
-
- copyToPath = targetPath + mediaFileName + "/";
- copyToFile = new File(copyToPath);
-
- cnt ++;
- }
-
- Path p = Paths.get(copyToPath);
- Files.copy(new FileInputStream(f), p);
- media.setPath(relativePath + mediaFileName);
- }
-
-}
diff --git a/src/main/java/com/aventstack/extentreports/mediastorage/MediaStorage.java b/src/main/java/com/aventstack/extentreports/mediastorage/MediaStorage.java
deleted file mode 100644
index 835efe5..0000000
--- a/src/main/java/com/aventstack/extentreports/mediastorage/MediaStorage.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.aventstack.extentreports.mediastorage;
-
-import java.io.IOException;
-
-import com.aventstack.extentreports.model.Media;
-
-public interface MediaStorage {
-
- void init(String v) throws IOException;
-
- void storeMedia(Media m) throws IOException;
-
-}
diff --git a/src/main/java/com/aventstack/extentreports/mediastorage/impl/HttpMediaManagerImplKlov.java b/src/main/java/com/aventstack/extentreports/mediastorage/impl/HttpMediaManagerImplKlov.java
deleted file mode 100644
index a671248..0000000
--- a/src/main/java/com/aventstack/extentreports/mediastorage/impl/HttpMediaManagerImplKlov.java
+++ /dev/null
@@ -1,85 +0,0 @@
-package com.aventstack.extentreports.mediastorage.impl;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.logging.Logger;
-
-import org.apache.http.HttpResponse;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.ContentType;
-import org.apache.http.entity.mime.HttpMultipartMode;
-import org.apache.http.entity.mime.MultipartEntityBuilder;
-import org.apache.http.entity.mime.content.FileBody;
-import org.apache.http.entity.mime.content.StringBody;
-import org.apache.http.impl.client.HttpClientBuilder;
-
-import com.aventstack.extentreports.mediastorage.MediaStorage;
-import com.aventstack.extentreports.model.Media;
-import com.aventstack.extentreports.model.ScreenCapture;
-import com.aventstack.extentreports.utils.FileUtil;
-
-public class HttpMediaManagerImplKlov
- implements MediaStorage {
-
- private static final Logger logger = Logger.getLogger(HttpMediaManagerImplKlov.class.getName());
- private static final String ROUTE = "files/upload";
-
- private String host;
-
- @Override
- public void init(String host) throws IOException {
- this.host = host;
- if (host.lastIndexOf('/') != host.length() - 1) {
- this.host = host + "/";
- }
- }
-
- @Override
- public void storeMedia(Media m) throws IOException {
- if (m.getPath() == null) {
- return;
- }
- if (m instanceof ScreenCapture && ((ScreenCapture)m).getBase64String() != null) {
- return;
- }
- File f = new File(m.getResolvedPath());
- if (!f.exists()) {
- throw new IOException("The system cannot find the file specified " + m.getPath());
- }
-
- HttpPost post = new HttpPost(host + ROUTE);
- post.addHeader("Connection", "keep-alive");
- post.addHeader("User-Agent", "Mozilla/5.0");
- post.addHeader("Accept", "application/json");
-
- String ext = FileUtil.getExtension(m.getPath());
-
- MultipartEntityBuilder builder = MultipartEntityBuilder.create();
- builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
- builder.addPart("name",new StringBody(m.getSequence() + "." + ext, ContentType.TEXT_PLAIN));
- builder.addPart("id", new StringBody(m.getBsonId().get("id").toString(), ContentType.TEXT_PLAIN));
- builder.addPart("reportId", new StringBody(m.getBsonId().get("reportId").toString(), ContentType.TEXT_PLAIN));
- builder.addPart("testId", new StringBody(m.getBsonId().get("testId").toString(), ContentType.TEXT_PLAIN));
- builder.addPart("f", new FileBody(new File(m.getResolvedPath())));
- post.setEntity(builder.build());
-
- String logId = m.getBsonId().get("logId") == null ? "" : m.getBsonId().get("logId").toString();
- builder.addPart("logId", new StringBody(logId, ContentType.TEXT_PLAIN));
-
- HttpClient client = HttpClientBuilder.create().build();
- HttpResponse response = client.execute(post);
-
- int responseCode = response.getStatusLine().getStatusCode();
- boolean isValid = isResponseValid(responseCode);
-
- if (!isValid) {
- logger.warning("Unable to upload file to server " + m.getPath());
- }
- }
-
- private boolean isResponseValid(int responseCode) {
- return responseCode >= 200 && responseCode < 400;
- }
-
-}
diff --git a/src/main/java/com/aventstack/extentreports/mediastorage/model/KlovMedia.java b/src/main/java/com/aventstack/extentreports/mediastorage/model/KlovMedia.java
deleted file mode 100644
index 586b191..0000000
--- a/src/main/java/com/aventstack/extentreports/mediastorage/model/KlovMedia.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package com.aventstack.extentreports.mediastorage.model;
-
-import org.bson.Document;
-import org.bson.types.ObjectId;
-
-import com.mongodb.client.MongoCollection;
-
-public class KlovMedia {
-
- private ObjectId reportId;
- private ObjectId projectId;
- private MongoCollection mediaCollection;
-
- public KlovMedia() { }
-
- public KlovMedia(ObjectId projectId, ObjectId reportId, MongoCollection mediaCollection) {
- this.projectId = projectId;
- this.reportId = reportId;
- this.mediaCollection = mediaCollection;
- }
-
- public ObjectId getReportId() {
- return reportId;
- }
-
- public void setReportId(ObjectId reportId) {
- this.reportId = reportId;
- }
-
- public ObjectId getProjectId() {
- return projectId;
- }
-
- public void setProjectId(ObjectId projectId) {
- this.projectId = projectId;
- }
-
- public MongoCollection getMediaCollection() {
- return mediaCollection;
- }
-
- public void setMediaCollection(MongoCollection mediaCollection) {
- this.mediaCollection = mediaCollection;
- }
-
-}
diff --git a/src/main/java/com/aventstack/extentreports/model/AbstractStructure.java b/src/main/java/com/aventstack/extentreports/model/AbstractStructure.java
deleted file mode 100644
index 356fc13..0000000
--- a/src/main/java/com/aventstack/extentreports/model/AbstractStructure.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package com.aventstack.extentreports.model;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-
-public class AbstractStructure implements Serializable {
-
- private static final long serialVersionUID = -2630417398255980331L;
-
- private List list = Collections.synchronizedList(new ArrayList<>());
-
- public void add(T t) {
- list.add(t);
- }
-
- public T get(int x) {
- return list.get(x);
- }
-
- public T getFirst() {
- return list.isEmpty() ? null : list.get(0);
- }
-
- public T getLast() {
- return list.isEmpty() ? null : list.get(list.size()-1);
- }
-
- public List getAll() {
- return list;
- }
-
- public int size() {
- if (list == null) {
- return 0;
- }
- return list.size();
- }
-
- public boolean isEmpty() {
- return size() == 0;
- }
-
- public TIterator getIterator() { return new TIterator(); }
-
- private class TIterator implements Iterator {
- private int index;
-
- TIterator() {
- index = 0;
- }
-
- @Override
- public boolean hasNext() {
- return list != null && list.size() >= index + 1;
- }
-
- @Override
- public T next() {
- if (hasNext()) {
- return list.get(index++);
- }
-
- throw new NoSuchElementException();
- }
-
- @Override
- public void remove() {
- list.remove(index);
- }
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/model/Attribute.java b/src/main/java/com/aventstack/extentreports/model/Attribute.java
deleted file mode 100644
index 77494d7..0000000
--- a/src/main/java/com/aventstack/extentreports/model/Attribute.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.aventstack.extentreports.model;
-
-import java.io.Serializable;
-
-public class Attribute implements Serializable {
-
- private static final long serialVersionUID = 6491172989326625178L;
-
- private String k;
- private String v;
-
- public Attribute() {
- }
-
- public Attribute(String k, String v) {
- this.k = k;
- this.v = v;
- }
-
- public Attribute(String k) {
- this(k, null);
- }
-
- public String getName() {
- return k;
- }
-
- public void setName(String k) {
- this.k = k;
- }
-
- public String getValue() {
- return v;
- }
-
- public void setValue(String v) {
- this.v = v;
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/model/Author.java b/src/main/java/com/aventstack/extentreports/model/Author.java
index 2e3b6b1..2ca9d27 100644
--- a/src/main/java/com/aventstack/extentreports/model/Author.java
+++ b/src/main/java/com/aventstack/extentreports/model/Author.java
@@ -1,15 +1,18 @@
package com.aventstack.extentreports.model;
-public class Author extends Attribute {
+import java.io.Serializable;
- private static final long serialVersionUID = -6374771272610470521L;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
- public Author(String k) {
- super(k);
- }
-
- public Author(String k, String v) {
- super(k, v);
- }
+@Getter
+@Setter
+@ToString(callSuper = true, includeFieldNames = true)
+public final class Author extends NamedAttribute implements Serializable, BaseEntity {
+ private static final long serialVersionUID = -1589597649718748057L;
-}
\ No newline at end of file
+ public Author(String name) {
+ super(name);
+ }
+}
diff --git a/src/main/java/com/aventstack/extentreports/model/BaseEntity.java b/src/main/java/com/aventstack/extentreports/model/BaseEntity.java
new file mode 100644
index 0000000..f79726a
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/model/BaseEntity.java
@@ -0,0 +1,7 @@
+package com.aventstack.extentreports.model;
+
+/**
+ * Marker interface for entities
+ */
+public interface BaseEntity {
+}
diff --git a/src/main/java/com/aventstack/extentreports/model/BasicMongoReportElement.java b/src/main/java/com/aventstack/extentreports/model/BasicMongoReportElement.java
deleted file mode 100644
index a3f3cd6..0000000
--- a/src/main/java/com/aventstack/extentreports/model/BasicMongoReportElement.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.aventstack.extentreports.model;
-
-import org.bson.types.ObjectId;
-
-/**
- * Marker interface for MongoDB elements
- *
- */
-public interface BasicMongoReportElement {
-
- public ObjectId getObjectId();
-
- public void setObjectId(ObjectId id);
-
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/model/Category.java b/src/main/java/com/aventstack/extentreports/model/Category.java
index f9eb334..cee9c65 100644
--- a/src/main/java/com/aventstack/extentreports/model/Category.java
+++ b/src/main/java/com/aventstack/extentreports/model/Category.java
@@ -1,15 +1,18 @@
package com.aventstack.extentreports.model;
-public class Category extends Attribute {
+import java.io.Serializable;
- private static final long serialVersionUID = 2652701333761577144L;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
- public Category(String k) {
- super(k);
- }
-
- public Category(String k, String v) {
- super(k, v);
- }
+@Getter
+@Setter
+@ToString(callSuper = true, includeFieldNames = true)
+public final class Category extends NamedAttribute implements Serializable, BaseEntity {
+ private static final long serialVersionUID = 5282727628859917993L;
-}
\ No newline at end of file
+ public Category(String name) {
+ super(name);
+ }
+}
diff --git a/src/main/java/com/aventstack/extentreports/model/Device.java b/src/main/java/com/aventstack/extentreports/model/Device.java
index e148219..bba0dc4 100644
--- a/src/main/java/com/aventstack/extentreports/model/Device.java
+++ b/src/main/java/com/aventstack/extentreports/model/Device.java
@@ -1,15 +1,18 @@
package com.aventstack.extentreports.model;
-public class Device extends Attribute {
+import java.io.Serializable;
- private static final long serialVersionUID = -3675996041755598043L;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
- public Device(String k) {
- super(k);
- }
-
- public Device(String k, String v) {
- super(k, v);
- }
+@Getter
+@Setter
+@ToString(callSuper = true, includeFieldNames = true)
+public final class Device extends NamedAttribute implements Serializable {
+ private static final long serialVersionUID = -5585746447313067401L;
-}
\ No newline at end of file
+ public Device(String name) {
+ super(name);
+ }
+}
diff --git a/src/main/java/com/aventstack/extentreports/model/ExceptionInfo.java b/src/main/java/com/aventstack/extentreports/model/ExceptionInfo.java
index bbadc83..473be56 100644
--- a/src/main/java/com/aventstack/extentreports/model/ExceptionInfo.java
+++ b/src/main/java/com/aventstack/extentreports/model/ExceptionInfo.java
@@ -2,31 +2,23 @@
import java.io.Serializable;
-public class ExceptionInfo implements Serializable {
+import lombok.Builder;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
- private static final long serialVersionUID = 2672123037706464734L;
-
- private String exceptionName;
+@Getter
+@Setter
+@ToString
+public class ExceptionInfo extends NamedAttribute implements Serializable, BaseEntity {
+ private static final long serialVersionUID = -8152865623044194249L;
+ private Throwable exception;
private String stackTrace;
- private Throwable throwable;
- public String getExceptionName() {
- return exceptionName;
- }
- public void setExceptionName(String exceptionName) {
- this.exceptionName = exceptionName;
- }
- public String getStackTrace() {
- return stackTrace;
- }
- public void setStackTrace(String stackTrace) {
- this.stackTrace = stackTrace;
- }
- public Throwable getThrowable() {
- return throwable;
- }
- public void setThrowable(Throwable throwable) {
- this.throwable = throwable;
- }
-
-}
\ No newline at end of file
+ @Builder
+ public ExceptionInfo(Throwable exception, String name, String stackTrace) {
+ super(name);
+ this.exception = exception;
+ this.stackTrace = stackTrace;
+ }
+}
diff --git a/src/main/java/com/aventstack/extentreports/model/Log.java b/src/main/java/com/aventstack/extentreports/model/Log.java
index 3532094..07c91b8 100644
--- a/src/main/java/com/aventstack/extentreports/model/Log.java
+++ b/src/main/java/com/aventstack/extentreports/model/Log.java
@@ -1,98 +1,39 @@
package com.aventstack.extentreports.model;
import java.io.Serializable;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
+import java.util.List;
-import org.bson.types.ObjectId;
-
-import com.aventstack.extentreports.RunResult;
import com.aventstack.extentreports.Status;
-public class Log implements Serializable, RunResult, BasicMongoReportElement {
-
- private static final long serialVersionUID = 8072065800800347981L;
- private Date timestamp = Calendar.getInstance().getTime();
-
- private ExceptionInfo exceptionInfo;
- private AbstractStructure screenCaptureContext;
- private transient Test test;
- private Status status;
- private String details;
- private int sequence;
- private ObjectId objectId;
-
- public Log(Test test) {
- this.test = test;
- }
-
- public Date getTimestamp() {
- return timestamp;
- }
-
- public void setTimestamp(Date timestamp) {
- this.timestamp = timestamp;
- }
-
- public ExceptionInfo getExceptionInfo() {
- return exceptionInfo;
- }
-
- public void setExceptionInfo(ExceptionInfo exceptionInfo) {
- this.exceptionInfo = exceptionInfo;
- }
-
- public AbstractStructure getScreenCaptureContext() {
- if (screenCaptureContext == null) {
- screenCaptureContext = new AbstractStructure<>();
- }
- return screenCaptureContext;
- }
-
- public void setScreenCaptureContext(AbstractStructure screenCapture) {
- this.screenCaptureContext = screenCapture;
- }
-
- public Test getTest() {
- return test;
- }
-
- public void setTest(Test test) {
- this.test = test;
- }
-
- public Status getStatus() {
- return status;
- }
-
- public void setStatus(Status status) {
- this.status = status;
- }
-
- public String getDetails() {
- return details;
- }
-
- public void setDetails(String details) {
- this.details = details;
- }
-
- public int getSequence() {
- return sequence;
- }
-
- public void setSequence(int sequence) {
- this.sequence = sequence;
- }
-
- @Override
- public ObjectId getObjectId() {
- return objectId;
- }
-
- @Override
- public void setObjectId(ObjectId id) {
- this.objectId = id;
- }
-
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.ToString;
+
+@Getter
+@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+@ToString
+public class Log implements RunResult, Serializable, BaseEntity {
+ private static final long serialVersionUID = -3690764012141784427L;
+
+ private final Date timestamp = Calendar.getInstance().getTime();
+ @Builder.Default
+ private Status status = Status.PASS;
+ private String details;
+ @Builder.Default
+ private Integer seq = -1;
+ private final List exceptions = new ArrayList<>();
+ private final List media = new ArrayList<>();
+
+ public Log(Integer seq) {
+ this.seq = seq;
+ }
}
diff --git a/src/main/java/com/aventstack/extentreports/model/Media.java b/src/main/java/com/aventstack/extentreports/model/Media.java
index b5343c5..19b1b8a 100644
--- a/src/main/java/com/aventstack/extentreports/model/Media.java
+++ b/src/main/java/com/aventstack/extentreports/model/Media.java
@@ -1,79 +1,18 @@
package com.aventstack.extentreports.model;
import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-import org.bson.types.ObjectId;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
-public class Media implements Serializable {
-
- private static final long serialVersionUID = 2620739620884939951L;
- private String name = "";
- private String description;
- private String path;
- private int sequence;
- private long fileSize = 0;
- private Map bsonId;
- private String resolvedPath;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public String getPath() {
- return path;
- }
-
- public void setPath(String path) {
- this.path = path;
- }
-
- public int getSequence() {
- return sequence;
- }
-
- public void setSequence(int sequence) {
- this.sequence = sequence;
- }
-
- public long getFileSize() {
- return fileSize;
- }
-
- public void setFileSize(long fileSize) {
- this.fileSize = fileSize;
- }
-
- public Map getBsonId() {
- if (bsonId == null) {
- bsonId = new HashMap<>();
- }
- return bsonId;
- }
-
- public void setBsonId(Map bsonId) {
- this.bsonId = bsonId;
- }
-
- public String getResolvedPath() {
- return resolvedPath == null ? getPath() : resolvedPath;
- }
-
- public void setResolvedPath(String resolvedPath) {
- this.resolvedPath = resolvedPath;
- }
+@Getter
+@Setter
+@AllArgsConstructor
+public abstract class Media implements Serializable, BaseEntity {
+ private static final long serialVersionUID = 5428859443090457608L;
+ private String path;
+ private String title;
+ private String resolvedPath;
}
diff --git a/src/main/java/com/aventstack/extentreports/model/NameValuePair.java b/src/main/java/com/aventstack/extentreports/model/NameValuePair.java
new file mode 100644
index 0000000..0c17212
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/model/NameValuePair.java
@@ -0,0 +1,18 @@
+package com.aventstack.extentreports.model;
+
+import java.io.Serializable;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public abstract class NameValuePair extends NamedAttribute implements Serializable, BaseEntity {
+ private static final long serialVersionUID = 6613712676810614719L;
+ private String value;
+
+ public NameValuePair(String name, String value) {
+ super(name);
+ this.value = value;
+ }
+}
diff --git a/src/main/java/com/aventstack/extentreports/model/NamedAttribute.java b/src/main/java/com/aventstack/extentreports/model/NamedAttribute.java
new file mode 100644
index 0000000..0ef3c48
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/model/NamedAttribute.java
@@ -0,0 +1,19 @@
+package com.aventstack.extentreports.model;
+
+import java.io.Serializable;
+
+import lombok.AllArgsConstructor;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.experimental.SuperBuilder;
+
+@Getter
+@Setter
+@SuperBuilder
+@AllArgsConstructor
+@EqualsAndHashCode
+public abstract class NamedAttribute implements Serializable, BaseEntity {
+ private static final long serialVersionUID = -804568330360505098L;
+ private String name;
+}
diff --git a/src/main/java/com/aventstack/extentreports/model/Report.java b/src/main/java/com/aventstack/extentreports/model/Report.java
new file mode 100644
index 0000000..f91c11d
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/model/Report.java
@@ -0,0 +1,41 @@
+package com.aventstack.extentreports.model;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+
+import com.aventstack.extentreports.Status;
+import com.aventstack.extentreports.model.context.NamedAttributeContextManager;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+
+@Getter
+@Setter
+@AllArgsConstructor
+@Builder
+@ToString(includeFieldNames = true)
+public class Report implements Serializable, BaseEntity {
+ private static final long serialVersionUID = -8667496631392333349L;
+
+ @Builder.Default
+ private Date startTime = Calendar.getInstance().getTime();
+ @Builder.Default
+ private Date endTime = Calendar.getInstance().getTime();
+ @Builder.Default
+ private Status status = Status.PASS;
+ private final ReportStats stats = new ReportStats();
+ private final List testList = Collections.synchronizedList(new ArrayList<>());
+ private final NamedAttributeContextManager authorCtx = new NamedAttributeContextManager<>();
+ private final NamedAttributeContextManager categoryCtx = new NamedAttributeContextManager<>();
+ private final NamedAttributeContextManager deviceCtx = new NamedAttributeContextManager<>();
+ private final NamedAttributeContextManager exceptionInfoCtx = new NamedAttributeContextManager<>();
+ private final List logs = Collections.synchronizedList(new ArrayList<>());
+ private final List systemEnvInfo = new ArrayList<>();
+}
diff --git a/src/main/java/com/aventstack/extentreports/model/ReportStats.java b/src/main/java/com/aventstack/extentreports/model/ReportStats.java
new file mode 100644
index 0000000..69a0937
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/model/ReportStats.java
@@ -0,0 +1,29 @@
+package com.aventstack.extentreports.model;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import com.aventstack.extentreports.AnalysisStrategy;
+import com.aventstack.extentreports.Status;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+
+@Getter
+@Setter
+@ToString
+public class ReportStats implements Serializable {
+ private static final long serialVersionUID = 5424613250832948474L;
+
+ private AnalysisStrategy analysisStrategy = AnalysisStrategy.TEST;
+ private final Map parent = new ConcurrentHashMap<>();
+ private final Map child = new ConcurrentHashMap<>();
+ private final Map grandchild = new ConcurrentHashMap<>();
+ private final Map log = new ConcurrentHashMap<>();
+ private final Map parentPercentage = new ConcurrentHashMap<>();
+ private final Map childPercentage = new ConcurrentHashMap<>();
+ private final Map grandchildPercentage = new ConcurrentHashMap<>();
+ private final Map logPercentage = new ConcurrentHashMap<>();
+}
diff --git a/src/main/java/com/aventstack/extentreports/model/RunResult.java b/src/main/java/com/aventstack/extentreports/model/RunResult.java
new file mode 100644
index 0000000..897addf
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/model/RunResult.java
@@ -0,0 +1,8 @@
+package com.aventstack.extentreports.model;
+
+import com.aventstack.extentreports.Status;
+
+@FunctionalInterface
+public interface RunResult {
+ Status getStatus();
+}
diff --git a/src/main/java/com/aventstack/extentreports/model/ScreenCapture.java b/src/main/java/com/aventstack/extentreports/model/ScreenCapture.java
index 493d296..a59ef1f 100644
--- a/src/main/java/com/aventstack/extentreports/model/ScreenCapture.java
+++ b/src/main/java/com/aventstack/extentreports/model/ScreenCapture.java
@@ -1,31 +1,21 @@
package com.aventstack.extentreports.model;
-public class ScreenCapture extends Media {
+import java.io.Serializable;
- private static final long serialVersionUID = 3876935785138278521L;
- private String base64;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.Setter;
- public String getBase64String() {
- return base64;
- }
+@Getter
+@Setter
+public class ScreenCapture extends Media implements Serializable {
+ private static final long serialVersionUID = -3047762572007885369L;
- public void setBase64String(String base64) {
- base64 = base64.contains("data:") || base64.contains("image/") ? base64 : "data:image/png;base64," + base64;
- this.base64 = base64;
- }
+ private String base64;
- public String getScreenCapturePath() {
- return getPath() != null ? getPath() : getBase64String();
- }
-
- public Boolean isBase64() {
- return getBase64String() != null;
- }
-
- public String getSource() {
- if (getBase64String() != null)
- return "base64-img ";
- return " ";
+ @Builder
+ public ScreenCapture(String path, String title, String resolvedPath, String base64) {
+ super(path, title, resolvedPath);
+ this.base64 = base64;
}
-
}
diff --git a/src/main/java/com/aventstack/extentreports/model/SystemAttribute.java b/src/main/java/com/aventstack/extentreports/model/SystemAttribute.java
deleted file mode 100644
index 27ed149..0000000
--- a/src/main/java/com/aventstack/extentreports/model/SystemAttribute.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.aventstack.extentreports.model;
-
-public class SystemAttribute extends Attribute {
-
- private static final long serialVersionUID = -6374771272610470521L;
-
- public SystemAttribute(String k) {
- super(k);
- }
-
- public SystemAttribute(String k, String v) {
- super(k, v);
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/model/SystemEnvInfo.java b/src/main/java/com/aventstack/extentreports/model/SystemEnvInfo.java
new file mode 100644
index 0000000..8d7334b
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/model/SystemEnvInfo.java
@@ -0,0 +1,18 @@
+package com.aventstack.extentreports.model;
+
+import java.io.Serializable;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+
+@Getter
+@Setter
+@ToString(callSuper = true, includeFieldNames = true)
+public class SystemEnvInfo extends NameValuePair implements Serializable, BaseEntity {
+ private static final long serialVersionUID = 8643409194315531097L;
+
+ public SystemEnvInfo(String name, String value) {
+ super(name, value);
+ }
+}
diff --git a/src/main/java/com/aventstack/extentreports/model/Test.java b/src/main/java/com/aventstack/extentreports/model/Test.java
index 0df24fb..812efb4 100644
--- a/src/main/java/com/aventstack/extentreports/model/Test.java
+++ b/src/main/java/com/aventstack/extentreports/model/Test.java
@@ -1,384 +1,54 @@
package com.aventstack.extentreports.model;
import java.io.Serializable;
-import java.lang.reflect.Method;
+import java.util.ArrayList;
import java.util.Calendar;
+import java.util.Collections;
import java.util.Date;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
-import org.bson.types.ObjectId;
-
-import com.aventstack.extentreports.ExtentReports;
-import com.aventstack.extentreports.RunResult;
import com.aventstack.extentreports.Status;
-import com.aventstack.extentreports.gherkin.model.IGherkinFormatterModel;
-import com.google.gson.annotations.Expose;
-
-public class Test implements Serializable, RunResult, BasicMongoReportElement {
-
- private static final long serialVersionUID = -8681630689550647312L;
- private static final AtomicInteger atomicInt = new AtomicInteger(0);
-
- /**
- * An instance of {@link ExtentReports}
- */
- private transient ExtentReports extent;
-
- /**
- * Level describes the hierarchy of the test in the tree. A level 0 indicates a
- * parent test. Level 1 indicates an immediate child of the parent, level 2
- * indicates an immediate child of the Child and so on.. The bottom-most test in
- * the hierarchy is considered a leaf
- */
- private int level = 0;
-
- /**
- * A unique ID, generated by AtomicInteger
- */
- private transient int id = atomicInt.incrementAndGet();
-
- /**
- * An assigned {@link ObjectId}
- */
- private ObjectId objectId;
-
- /**
- * If this Test is at the top-most level, or in other words, has a level value
- * of 0, parent will be null. This field will only contain a value if the Test
- * is a child, or has a level 1 or greater.
- */
- private transient Test parent;
-
- /**
- * {@link Status} of this test, defaults to PASS
- */
- private Status status = Status.PASS;
-
- /**
- * A structure containing all nodes of this test
- */
- private AbstractStructure nodeContext;
-
- /**
- * A structure containing all logs/events of this test
- */
- private AbstractStructure logContext;
-
- /**
- * A structure containing all categories assigned to this test
- */
- private AbstractStructure categoryContext;
-
- /**
- * A structure containing all authors assigned to this test
- */
- private AbstractStructure authorContext;
-
- /**
- * A structure containing all devices assigned to this test
- */
- private AbstractStructure deviceContext;
-
- /**
- * Time the test was started
- */
- private Date startTime = Calendar.getInstance().getTime();
-
- /**
- * Time the test was ended
- */
- private Date endTime = Calendar.getInstance().getTime();
-
- /**
- * Type of BDD object represented by {@link IGherkinFormatterModel}. It can have
- * one of the following values:
- *
- *
- * {@link com.aventstack.extentreports.gherkin.model.Feature}
- * {@link com.aventstack.extentreports.gherkin.model.Background}
- * {@link com.aventstack.extentreports.gherkin.model.Scenario}
- * {@link com.aventstack.extentreports.gherkin.model.Given}
- * {@link com.aventstack.extentreports.gherkin.model.When}
- * {@link com.aventstack.extentreports.gherkin.model.Then}
- * {@link com.aventstack.extentreports.gherkin.model.And}
- * {@link com.aventstack.extentreports.gherkin.model.But}
- *
- */
- private transient Class extends IGherkinFormatterModel> bddType;
-
- @Expose
- private String bddTypeName;
-
- /**
- * A list of {@link ScreenCapture}
- */
- private transient AbstractStructure screenCaptureContext;
-
- /**
- * A list of {@link ExceptionInfo}
- */
- private transient AbstractStructure exceptionInfoContext;
-
- /**
- * Name of the test
- */
- private String name;
-
- /**
- * Description
- */
- private String description;
-
- /**
- * This setting allows setting test with your own time-stamps. With this
- * enabled, Extent does not use time-stamps for tests at the time they were
- * created
- */
- private boolean usesManualConfiguration = false;
-
- public ExtentReports getExtent() {
- return extent;
- }
-
- public void setExtent(ExtentReports extent) {
- this.extent = extent;
- }
-
- public int getLevel() {
- return level;
- }
-
- public void setLevel(int level) {
- this.level = level;
- }
-
- public int getId() {
- return id;
- }
-
- public void setId(int id) {
- this.id = id;
- }
-
- public Test getParent() {
- return parent;
- }
-
- public void setParent(Test parent) {
- this.parent = parent;
- }
-
- public Status getStatus() {
- return status;
- }
-
- public void setStatus(Status status) {
- this.status = status;
- }
-
- public AbstractStructure getNodeContext() {
- if (nodeContext == null) {
- nodeContext = new AbstractStructure<>();
- }
- return nodeContext;
- }
-
- public void setNodeContext(AbstractStructure node) {
- this.nodeContext = node;
- }
-
- public AbstractStructure getLogContext() {
- if (logContext == null) {
- logContext = new AbstractStructure<>();
- }
- return logContext;
- }
-
- public void setLogContext(AbstractStructure log) {
- this.logContext = log;
- }
-
- public AbstractStructure getCategoryContext() {
- if (categoryContext == null) {
- categoryContext = new AbstractStructure<>();
- }
- return categoryContext;
- }
-
- public void setCategoryContext(AbstractStructure category) {
- this.categoryContext = category;
- }
-
- public AbstractStructure getAuthorContext() {
- if (authorContext == null) {
- authorContext = new AbstractStructure<>();
- }
- return authorContext;
- }
-
- public void setAuthorContext(AbstractStructure author) {
- this.authorContext = author;
- }
-
- public AbstractStructure getDeviceContext() {
- if (deviceContext == null) {
- deviceContext = new AbstractStructure<>();
- }
- return deviceContext;
- }
-
- public void setDeviceContext(AbstractStructure device) {
- this.deviceContext = device;
- }
-
- public Date getStartTime() {
- return startTime;
- }
-
- public void setStartTime(Date startTime) {
- this.startTime = startTime;
- }
-
- public Date getEndTime() {
- return endTime;
- }
-
- public void setEndTime(Date endTime) {
- this.endTime = endTime;
- }
-
- public Class extends IGherkinFormatterModel> getBddType() {
- return bddType;
- }
-
- public void setBddType(Class extends IGherkinFormatterModel> bddType) {
- this.bddType = bddType;
- bddTypeName = getBehaviorDrivenTypeName();
- }
-
- public AbstractStructure getScreenCaptureContext() {
- if (screenCaptureContext == null) {
- screenCaptureContext = new AbstractStructure<>();
- }
- return screenCaptureContext;
- }
-
- public void setScreenCaptureContext(AbstractStructure screenCapture) {
- this.screenCaptureContext = screenCapture;
- }
-
- public AbstractStructure getExceptionInfoContext() {
- if (exceptionInfoContext == null) {
- exceptionInfoContext = new AbstractStructure<>();
- }
- return exceptionInfoContext;
- }
-
- public void setExceptionInfoContext(AbstractStructure exception) {
- this.exceptionInfoContext = exception;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public boolean isUsesManualConfiguration() {
- return usesManualConfiguration;
- }
-
- public void setUsesManualConfiguration(boolean usesManualConfiguration) {
- this.usesManualConfiguration = usesManualConfiguration;
- }
-
- private synchronized void updateStatus(Status logStatus) {
- int logStatusIndex = Status.getStatusHierarchy().indexOf(logStatus);
- int testStatusIndex = Status.getStatusHierarchy().indexOf(status);
- status = logStatusIndex < testStatusIndex ? logStatus : status;
- }
-
- public void end() {
- updateTestStatusRecursive(this);
- endChildrenRecursive(this);
- status = (status == Status.INFO || status == Status.DEBUG) ? Status.PASS : status;
- if (!usesManualConfiguration) {
- computeEndTimeFromChildren();
- }
- }
-
- private synchronized void updateTestStatusRecursive(Test test) {
- test.getLogContext().getAll().forEach(x -> updateStatus(x.getStatus()));
-
- if (!test.getNodeContext().isEmpty()) {
- test.getNodeContext().getAll().forEach(this::updateTestStatusRecursive);
- }
-
- // if not all children are marked SKIP, then:
- // ensure the parent has a status that is not SKIP
- if (test.bddType == null) {
- boolean hasNodeNotSkipped = test.getNodeContext().getAll().stream()
- .anyMatch(x -> x.getStatus() != Status.SKIP);
-
- if (status == Status.SKIP && hasNodeNotSkipped) {
- // reset status
- status = Status.PASS;
- // compute new status
- test.getNodeContext().getAll().stream().filter(x -> x.getStatus() != Status.SKIP)
- .forEach(this::updateTestStatusRecursive);
- }
- }
- }
-
- private void endChildrenRecursive(Test test) {
- test.getNodeContext().getAll().forEach(Test::end);
- }
-
- public void computeEndTimeFromChildren() {
- if (!getNodeContext().isEmpty()) {
- setStartTime(getNodeContext().getFirst().getStartTime());
- setEndTime(getNodeContext().getLast().getEndTime());
- } else if (!getLogContext().isEmpty()) {
- Date lastLogEndTime = getLogContext().getLast().getTimestamp();
- setEndTime(lastLogEndTime);
- }
- }
-
- public String getBehaviorDrivenTypeName() {
- if (bddTypeName != null) {
- return bddTypeName;
- }
- try {
- Method method = bddType.getMethod("getGherkinName");
- Object o = method.invoke(null, (Object[]) null);
- return o.toString();
- } catch (Exception e) {
- return null;
- }
- }
-
- public Boolean isBehaviorDrivenType() {
- return getBddType() != null;
- }
-
- @Override
- public ObjectId getObjectId() {
- return objectId;
- }
-
- @Override
- public void setObjectId(ObjectId id) {
- this.objectId = id;
- }
-
+import com.aventstack.extentreports.gherkin.entity.IGherkinFormatterModel;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+@Getter
+@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+public final class Test implements RunResult, Serializable, BaseEntity {
+ private static final long serialVersionUID = -4896520724677957845L;
+ private static final AtomicInteger atomicInt = new AtomicInteger(0);
+
+ private final Integer id = atomicInt.incrementAndGet();
+ @Builder.Default
+ private Date startTime = Calendar.getInstance().getTime();
+ @Builder.Default
+ private Date endTime = Calendar.getInstance().getTime();
+ @Builder.Default
+ private Status status = Status.PASS;
+ @Builder.Default
+ private Integer level = 0;
+ @Builder.Default
+ private boolean isLeaf = true;
+ private String name;
+ private String description;
+ private Test parent;
+ private Class extends IGherkinFormatterModel> bddType;
+ private final List children = Collections.synchronizedList(new ArrayList<>());
+ private final List logs = Collections.synchronizedList(new ArrayList<>());
+ private final List media = Collections.synchronizedList(new ArrayList<>());
+ private final List exceptions = new ArrayList<>();
+ private final Set authorSet = ConcurrentHashMap.newKeySet();
+ private final Set categorySet = ConcurrentHashMap.newKeySet();
+ private final Set deviceSet = ConcurrentHashMap.newKeySet();
+ private final List generatedLog = Collections.synchronizedList(new ArrayList<>());
}
diff --git a/src/main/java/com/aventstack/extentreports/model/context/ExceptionTestContext.java b/src/main/java/com/aventstack/extentreports/model/context/ExceptionTestContext.java
deleted file mode 100644
index 7080bd9..0000000
--- a/src/main/java/com/aventstack/extentreports/model/context/ExceptionTestContext.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package com.aventstack.extentreports.model.context;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-import com.aventstack.extentreports.model.ExceptionInfo;
-import com.aventstack.extentreports.model.Test;
-
-public class ExceptionTestContext implements Serializable {
-
- private static final long serialVersionUID = -2516200535748363722L;
-
- private ExceptionInfo exceptionInfo;
- private List tests = new ArrayList<>();
-
- public ExceptionTestContext(ExceptionInfo exceptionInfo) {
- this.exceptionInfo = exceptionInfo;
- }
-
- public void setTest(Test test) {
- tests.add(test);
- }
-
- public List getTests() {
- return tests;
- }
-
- public ExceptionInfo getExceptionInfo() {
- return exceptionInfo;
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/model/context/ExceptionTestContextStore.java b/src/main/java/com/aventstack/extentreports/model/context/ExceptionTestContextStore.java
deleted file mode 100644
index b15dea3..0000000
--- a/src/main/java/com/aventstack/extentreports/model/context/ExceptionTestContextStore.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package com.aventstack.extentreports.model.context;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-
-import com.aventstack.extentreports.model.ExceptionInfo;
-import com.aventstack.extentreports.model.Test;
-
-/**
- * Provides and tracks the collection of tests segregated by the type of
- * {@link Exception}
- *
- */
-public class ExceptionTestContextStore {
-
- private List exceptionTestContext = new ArrayList<>();
-
- public void setExceptionContext(ExceptionInfo ei, Test test) {
- Optional exOptionalTestContext = exceptionTestContext.stream()
- .filter(x -> x.getExceptionInfo().getExceptionName().equals(ei.getExceptionName())).findFirst();
-
- if (exOptionalTestContext.isPresent()) {
- List testList = exOptionalTestContext.get().getTests();
-
- boolean b = testList.stream().anyMatch(t -> t.getId() == test.getId());
-
- if (!b) {
- exOptionalTestContext.get().setTest(test);
- }
- } else {
- ExceptionTestContext exTestContext = new ExceptionTestContext(ei);
- exTestContext.setTest(test);
- exceptionTestContext.add(exTestContext);
- }
- }
-
- public List getExceptionTestContext() {
- return exceptionTestContext;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/model/context/NamedAttributeContext.java b/src/main/java/com/aventstack/extentreports/model/context/NamedAttributeContext.java
new file mode 100644
index 0000000..0844fb4
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/model/context/NamedAttributeContext.java
@@ -0,0 +1,55 @@
+package com.aventstack.extentreports.model.context;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import com.aventstack.extentreports.Status;
+import com.aventstack.extentreports.model.NamedAttribute;
+import com.aventstack.extentreports.model.Test;
+
+import lombok.Getter;
+import lombok.ToString;
+
+@Getter
+@ToString
+public class NamedAttributeContext implements Serializable {
+ private static final long serialVersionUID = -2671203343283101908L;
+
+ private final List testList = Collections.synchronizedList(new ArrayList<>());
+ private T attr;
+ private Integer passed = 0;
+ private Integer failed = 0;
+ private Integer skipped = 0;
+ private Integer others = 0;
+
+ public NamedAttributeContext(T attribute, Test test) {
+ this.attr = attribute;
+ addTest(test);
+ }
+
+ public void addTest(Test test) {
+ if (test == null)
+ throw new IllegalArgumentException("Test cannot be null");
+ testList.add(test);
+ refresh(test);
+ }
+
+ private synchronized void refresh(Test test) {
+ passed += test.getStatus() == Status.PASS ? 1 : 0;
+ failed += test.getStatus() == Status.FAIL ? 1 : 0;
+ skipped += test.getStatus() == Status.SKIP ? 1 : 0;
+ others += test.getStatus() != Status.PASS && test.getStatus() != Status.FAIL
+ && test.getStatus() != Status.SKIP ? 1 : 0;
+ }
+
+ public void refresh() {
+ passed = failed = skipped = others = 0;
+ testList.forEach(this::refresh);
+ }
+
+ public Integer size() {
+ return passed + failed + skipped + others;
+ }
+}
diff --git a/src/main/java/com/aventstack/extentreports/model/context/NamedAttributeContextManager.java b/src/main/java/com/aventstack/extentreports/model/context/NamedAttributeContextManager.java
new file mode 100644
index 0000000..caba555
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/model/context/NamedAttributeContextManager.java
@@ -0,0 +1,64 @@
+package com.aventstack.extentreports.model.context;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import com.aventstack.extentreports.model.NamedAttribute;
+import com.aventstack.extentreports.model.Test;
+import com.aventstack.extentreports.model.service.TestService;
+
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+
+@NoArgsConstructor
+@Getter
+public class NamedAttributeContextManager {
+ private Set> set = Collections
+ .newSetFromMap(new ConcurrentHashMap, Boolean>());
+
+ public void addContext(T attr, Test test) {
+ Optional> opt = set.stream()
+ .filter(x -> x.getAttr().getName().equals(attr.getName()))
+ .findAny();
+ if (opt.isPresent()) {
+ List list = opt.get().getTestList();
+ if (!list.stream().anyMatch(t -> t.getId() == test.getId()))
+ list.add(test);
+ } else {
+ set.add(new NamedAttributeContext<>(attr, test));
+ }
+ }
+
+ public void addContext(T attr, List testList) {
+ testList.forEach(x -> addContext(attr, x));
+ }
+
+ /**
+ * Remove a test from the context. This will also removed the context if
+ * there are no tests present after test removal
+ *
+ * @param test
+ * {@link Test}
+ */
+ public void removeTest(Test test) {
+ Iterator> iter = set.iterator();
+ while (iter.hasNext()) {
+ NamedAttributeContext context = iter.next();
+ TestService.deleteTest(context.getTestList(), test);
+ if (context.getTestList().isEmpty())
+ iter.remove();
+ }
+ }
+
+ public boolean hasItems() {
+ return !set.isEmpty();
+ }
+
+ public void resetAll() {
+ set.stream().forEach(x -> x.refresh());
+ }
+}
diff --git a/src/main/java/com/aventstack/extentreports/model/context/SystemAttributeContext.java b/src/main/java/com/aventstack/extentreports/model/context/SystemAttributeContext.java
deleted file mode 100644
index 5de8207..0000000
--- a/src/main/java/com/aventstack/extentreports/model/context/SystemAttributeContext.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.aventstack.extentreports.model.context;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.aventstack.extentreports.model.SystemAttribute;
-
-/**
- * A simple key-value pair collection to store System/Environment information
- *
- */
-public class SystemAttributeContext {
-
- private List list = new ArrayList<>();
-
- public void setSystemAttribute(SystemAttribute sa) {
- list.add(sa);
- }
-
- public String getSystemAttribute(String k) {
- return list.stream()
- .filter(x -> x.getName().equals(k))
- .map(SystemAttribute::getValue)
- .findFirst()
- .orElse(null);
- }
-
- public List getSystemAttributeList() {
- return list;
- }
-
- public void clear() {
- list.clear();
- }
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/model/context/TestAttributeTestContext.java b/src/main/java/com/aventstack/extentreports/model/context/TestAttributeTestContext.java
deleted file mode 100644
index 560bda6..0000000
--- a/src/main/java/com/aventstack/extentreports/model/context/TestAttributeTestContext.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package com.aventstack.extentreports.model.context;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-import com.aventstack.extentreports.Status;
-import com.aventstack.extentreports.model.Attribute;
-import com.aventstack.extentreports.model.Test;
-import com.aventstack.extentreports.model.context.filter.TestAttributeContextFilters;
-
-public class TestAttributeTestContext implements Serializable {
-
- private static final long serialVersionUID = 2595632998970711190L;
-
- private List tests = new ArrayList<>();
- private T attr;
- private int passed = 0;
- private int failed = 0;
- private int skipped = 0;
- private int others = 0;
-
- public TestAttributeTestContext(T attr) {
- this.attr = attr;
- }
-
- public void setTest(Test test) {
- updateTestStatusCounts(test);
- tests.add(test);
- }
-
- private void updateTestStatusCounts(Test test) {
- if (!TestAttributeContextFilters.testHasStatusIncrEligibility(test))
- return;
- if (test.getStatus() == Status.PASS) {
- passed++;
- } else if (test.getStatus() == Status.FAIL || test.getStatus() == Status.FATAL) {
- failed++;
- } else if (test.getStatus() == Status.SKIP) {
- skipped++;
- } else {
- others++;
- }
- }
-
- public void refreshTestStatusCounts() {
- passed = failed = skipped = others = 0;
- tests.forEach(this::updateTestStatusCounts);
- }
-
- public List getTests() {
- return tests;
- }
-
- public String getName() {
- return attr.getName();
- }
-
- public int getPassed() {
- return passed;
- }
-
- public int getFailed() {
- return failed;
- }
-
- public int getSkipped() {
- return skipped;
- }
-
- public int getOthers() {
- return others;
- }
-
- public int size() {
- return tests == null ? 0 : tests.size();
- }
-
- public boolean isEmpty() {
- return size() == 0;
- }
-
- public T getAttribute() {
- return attr;
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/model/context/TestAttributeTestContextStore.java b/src/main/java/com/aventstack/extentreports/model/context/TestAttributeTestContextStore.java
deleted file mode 100644
index 0926fdc..0000000
--- a/src/main/java/com/aventstack/extentreports/model/context/TestAttributeTestContextStore.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package com.aventstack.extentreports.model.context;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Optional;
-
-import com.aventstack.extentreports.model.Attribute;
-import com.aventstack.extentreports.model.Test;
-import com.aventstack.extentreports.model.context.helpers.TestRemover;
-
-/**
- * Uses an attribute context for {@link Attribute} (Category, Device, Author
- * etc.) and tracks the collection of tests segregated by the type
- * {@link Attribute}
- *
- * @param A {@link Attribute} type
- */
-public class TestAttributeTestContextStore {
-
- private List> testAttrTestContext;
-
- public TestAttributeTestContextStore() {
- testAttrTestContext = new ArrayList<>();
- }
-
- public void setAttributeContext(T attr, Test test) {
- Optional> optTestContext = testAttrTestContext.stream()
- .filter(x -> x.getName().equals(attr.getName())).findFirst();
-
- if (optTestContext.isPresent()) {
- List tests = optTestContext.get().getTests();
-
- boolean b = tests.stream().anyMatch(t -> t.getId() == test.getId());
-
- if (!b) {
- optTestContext.get().setTest(test);
- }
- optTestContext.get().refreshTestStatusCounts();
- } else {
- TestAttributeTestContext testAttrContext = new TestAttributeTestContext<>(attr);
- testAttrContext.setTest(test);
- testAttrTestContext.add(testAttrContext);
- }
- }
-
- public synchronized void removeTest(Test test) {
- Iterator> iter = testAttrTestContext.iterator();
- while (iter.hasNext()) {
- TestAttributeTestContext context = iter.next();
- TestRemover.remove(context.getTests(), test);
- if (context.isEmpty()) {
- iter.remove();
- }
- }
- }
-
- public List> getTestAttributeTestContext() {
- return testAttrTestContext;
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/com/aventstack/extentreports/model/context/filter/NamedAttributeTestContextFilter.java b/src/main/java/com/aventstack/extentreports/model/context/filter/NamedAttributeTestContextFilter.java
new file mode 100644
index 0000000..7899586
--- /dev/null
+++ b/src/main/java/com/aventstack/extentreports/model/context/filter/NamedAttributeTestContextFilter.java
@@ -0,0 +1,25 @@
+package com.aventstack.extentreports.model.context.filter;
+
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import com.aventstack.extentreports.Status;
+import com.aventstack.extentreports.model.NamedAttribute;
+import com.aventstack.extentreports.model.Test;
+import com.aventstack.extentreports.model.context.NamedAttributeContextManager;
+import com.aventstack.extentreports.model.context.NamedAttributeContext;
+
+public class NamedAttributeTestContextFilter {
+ public Set> filter(NamedAttributeContextManager mgr, Set status) {
+ NamedAttributeContextManager newmgr = new NamedAttributeContextManager