diff --git a/.gitignore b/.gitignore index 3f6fe75..1c3b157 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,6 @@ deploycmd.txt # Intellij .idea/ + +# +pom.nexus.xml diff --git a/.travis.yml b/.travis.yml index a165e66..9f1582c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ language: java jdk: - openjdk8 -services: - - mongodb after_success: - bash <(curl -s https://codecov.io/bash) \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 908caa2..3a1d3c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,32 @@ +## [5.0.0](https://github.com/extent-framework/extentreports-java/compare/v4.1.6...v5.0.0) + +#### New Features +- [#47](../issues/47) Anchors for each test +- [#150](../issues/150) Unused status from charts will not be displayed +- [#152](../issues/152) Spark: Author view +- [#153](../issues/153) Spark: Device view +- [#157](../issues/157) Spark: Add TestRunnerLogs view +- [#168](../issues/168) Spark: Navigation from attributes pages (tags, exception) to Tests View +- [#173](../issues/173) Spark: Allow configuration to select view order, Dashboard view as primary +- [#176](../issues/176) Apply Status filters to report +- [#177](../issues/177) Minified templates (> 10% reduction in file size) +- [#184](../issues/184) Reporter::loadExternalConfiguration with json file +- [#188](../issues/188) Display upto 4 `pre` blocks on a single row +- [#191](../issues/191) Navigation from Tags/Exception pages to nested steps +- [#213](../issues/213) Toggle theme from URI component using '#theme=' +- [#215](../issues/215) A test removed from the report will also be removed from MongoDB (Klov) + +#### Issues Resolved +- [#131](../issues/131) Merging two html extent Reports works but Category view gets overwritten +- [#161](../issues/161) Merging ExtentSpark 4.1.5 Reports causing the existing base64 image removed +- [#169](../issues/169) Fix SparkReporter shortcuts +- [#197](../issues/197) MarkupHelper::codeBlock has extra indentation on the first line +- [#208](../issues/208) Show title text for screencaptures + +## [4.1.7](https://github.com/extent-framework/extentreports-java/compare/v4.1.6...v4.1.7) +#### Fixes +* [#193] Unable to format the JSON code String in report + ## [4.1.6](https://github.com/extent-framework/extentreports-java/compare/v4.1.5...v4.1.6) #### Fixes * [#149] Skipped count is not displaying in authors tag and category tag diff --git a/LICENSE b/LICENSE index 261eeb9..d0de84b 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] + Copyright 2020 Anshoo Arora Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/Readme.md b/Readme.md index 2a8f2fe..b14ed08 100644 --- a/Readme.md +++ b/Readme.md @@ -1,14 +1,27 @@ -## Extent Framework 4 - Community Edition +## ExtentReports 5 [![Join the chat at https://gitter.im/anshooarora/extentreports](https://badges.gitter.im/anshooarora/extentreports.svg)](https://gitter.im/anshooarora/extentreports?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Maven Central](https://img.shields.io/maven-central/v/com.aventstack/extentreports.svg?maxAge=300)](http://search.maven.org/#search|ga|1|g:"com.aventstack") [![Build Status](https://travis-ci.com/extent-framework/extentreports-java.svg?branch=master)](https://travis-ci.com/extent-framework/extentreports-java) [![CodeFactor](https://www.codefactor.io/repository/github/extent-framework/extentreports-java/badge)](https://www.codefactor.io/repository/github/extent-framework/extentreports-java) [![codecov](https://codecov.io/gh/extent-framework/extentreports-java/branch/master/graph/badge.svg)](https://codecov.io/gh/extent-framework/extentreports-java) -[![Join the chat at https://gitter.im/anshooarora/extentreports](https://badges.gitter.im/anshooarora/extentreports.svg)](https://gitter.im/anshooarora/extentreports?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -[![Maven Central](https://img.shields.io/maven-central/v/com.aventstack/extentreports.svg?maxAge=300)](http://search.maven.org/#search|ga|1|g:"com.aventstack") -[![Build Status](https://travis-ci.com/extent-framework/extentreports-java.svg?branch=master)](https://travis-ci.com/extent-framework/extentreports-java) -[![Codacy Badge](https://api.codacy.com/project/badge/Grade/dbdc8c04b0f84489a738f064f28a82fa)](https://www.codacy.com/app/anshooarora/extentreports?utm_source=github.com&utm_medium=referral&utm_content=extent-framework/extentreports&utm_campaign=Badge_Grade) +### Documentation ### -#### Documentation +* Documentation for ExtentReports 5.x is hosted on GitHub at [ExtentReports Wiki](https://github.com/extent-framework/extentreports-java/wiki). +* For versions 4 and below, visit [extentreports.com](http://extentreports.com/). -View [extentreports.com](http://extentreports.com/docs/versions/4/java/) for complete documentation. +### Contributing ### -### License +For more information on contributing to the ExtentReports project, please see [CONTRIBUTING.md](https://github.com/extent-framework/extentreports-java/blob/master/Contributing.md). -Apache-2.0 +A complete list of contributors since ExtentReports migrated from [@anshooarora/extentreports-java](https://github.com/anshooarora/extentreports-java) can be [found here](https://github.com/extent-framework/extentreports-java/graphs/contributors). + +### Upcoming ### + +* See [v5.0.x milestones](https://github.com/extent-framework/extentreports-java/milestone/2) +* See [v5.1.x milestones](https://github.com/extent-framework/extentreports-java/milestone/3) +* Want to see a feature added? Let me know [here](https://github.com/extent-framework/extentreports-java/issues?q=is%3Aopen+is%3Aissue+milestone%3A5.0.x) + +### Versions ### + +* ExtentReports 4.x is available from the [4.x branch](https://github.com/extent-framework/extentreports-java/tree/4.1.x) +* ExtentReports 3.x is no longer maintained, and is available from [@anshooarora/extentreports-java](https://github.com/anshooarora/extentreports-java) + +### License ### + +ExtentReports is Open Source software and ExtentReports 5.0 is released under Apache-2.0. diff --git a/config/logger-config.xml b/config/logger-config.xml deleted file mode 100644 index a0094a6..0000000 --- a/config/logger-config.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - standard - - - - UTF-8 - - - true - - - - https - - - Extent Framework - - - Build 1 - - - MMM dd, yyyy HH:mm:ss - - - - - - - - - - - - diff --git a/config/spark-config.json b/config/spark-config.json new file mode 100644 index 0000000..26b0fb5 --- /dev/null +++ b/config/spark-config.json @@ -0,0 +1,12 @@ +{ + "theme": "STANDARD", + "encoding": "utf-8", + "protocol": "HTTPS", + "timelineEnabled": false, + "offlineMode": true, + "documentTitle": "ExtentReports", + "reportName": "ExtentReports", + "timeStampFormat": "MMM dd, yyyy HH:mm:ss a", + "js": "", + "css": "" +} diff --git a/config/spark-config.xml b/config/spark-config.xml index 0bb21fe..1c52508 100644 --- a/config/spark-config.xml +++ b/config/spark-config.xml @@ -1,52 +1,50 @@ - - - - - standard - - - - UTF-8 - - - - https - - - false - - - Extent Framework - - - Build 1 - - - MMM dd, yyyy HH:mm:ss - - - true - false - true - true - - - - - - - - - - - - + + + + + STANDARD + + + + UTF-8 + + + + + HTTPS + + + true + + + false + + + Extent Framework + + + Build 1 + + + MMM dd, yyyy HH:mm:ss + + + + + + + + + + + + \ No newline at end of file diff --git a/config/v3html-config.xml b/config/v3html-config.xml deleted file mode 100644 index 0bb21fe..0000000 --- a/config/v3html-config.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - standard - - - - UTF-8 - - - - https - - - false - - - Extent Framework - - - Build 1 - - - MMM dd, yyyy HH:mm:ss - - - true - false - true - true - - - - - - - - - - - - - \ No newline at end of file diff --git a/lombok.config b/lombok.config new file mode 100644 index 0000000..7a21e88 --- /dev/null +++ b/lombok.config @@ -0,0 +1 @@ +lombok.addLombokGeneratedAnnotation = true diff --git a/pom.xml b/pom.xml index a6d67d2..059f226 100644 --- a/pom.xml +++ b/pom.xml @@ -1,20 +1,20 @@ - 4.0.0 + 4.0.0 com.aventstack extentreports - 4.1.6 + 5.0.0 - extentreports + ExtentReports www.extentreports.com - Extent Framework + ExtentReports library - scm:git:https://github.com/extent-framework/extentreports.git - scm:git:https://github.com/extent-framework/extentreports.git - https://github.com/extent-framework/extentreports + scm:git:https://github.com/extent-framework/extentreports-java.git + scm:git:https://github.com/extent-framework/extentreports-java.git + https://github.com/extent-framework/extentreports-java @@ -37,46 +37,35 @@ UTF-8 - 3.12.0 - 4.5.2 - org.freemarker - freemarker - 2.3.29 + io.reactivex.rxjava3 + rxjava + 3.0.4 - org.apache.httpcomponents - httpclient - ${apache.httpcomponents.version} + org.freemarker + freemarker + 2.3.30 - org.apache.httpcomponents - httpmime - ${apache.httpcomponents.version} + org.projectlombok + lombok + 1.18.12 com.google.code.gson gson 2.8.6 - - org.mongodb - mongodb-driver - ${mongodb.version} - - - org.mongodb - bson - ${mongodb.version} - + + org.testng testng - 6.14.3 - test + 7.1.0 @@ -103,7 +92,7 @@ org.apache.maven.plugins maven-compiler-plugin - 2.3.2 + 3.6.1 1.8 1.8 @@ -112,26 +101,12 @@ org.apache.maven.plugins maven-resources-plugin - 2.7 - - - org.apache.maven.plugins - maven-gpg-plugin - 1.6 - - - sign-artifacts - verify - - sign - - - + 3.1.0 org.jacoco jacoco-maven-plugin - 0.7.9 + 0.8.5 @@ -152,27 +127,12 @@ - release-sign-artifacts - - - performRelease - true - - - - 41414BBD - - anshooarora - - - - org.apache.maven.plugins maven-source-plugin - 2.3 + 3.0.1 attach-sources @@ -185,7 +145,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.3 + 3.0.1 attach-javadocs @@ -210,5 +170,4 @@ https://oss.sonatype.org/service/local/staging/deploy/maven2 - - \ No newline at end of file + diff --git a/pom-nexus.xml b/reporters/klov/pom.xml similarity index 58% rename from pom-nexus.xml rename to reporters/klov/pom.xml index a6d67d2..59e2842 100644 --- a/pom-nexus.xml +++ b/reporters/klov/pom.xml @@ -4,17 +4,18 @@ 4.0.0 com.aventstack - extentreports - 4.1.6 + klovreporter + 5.0.0-SNAPSHOT - extentreports + klov-reporter www.extentreports.com - Extent Framework + Reporter for Klov Server + jar - scm:git:https://github.com/extent-framework/extentreports.git - scm:git:https://github.com/extent-framework/extentreports.git - https://github.com/extent-framework/extentreports + scm:git:https://github.com/extent-framework/extentreports-java.git + scm:git:https://github.com/extent-framework/extentreports-java.git + https://github.com/extent-framework/extentreports-java @@ -28,7 +29,7 @@ Anshoo Arora https://github.com/anshooarora - anshooarora + anshoo.arora Owner @@ -37,46 +38,33 @@ UTF-8 - 3.12.0 - 4.5.2 - org.freemarker - freemarker - 2.3.29 - - - org.apache.httpcomponents - httpclient - ${apache.httpcomponents.version} - - - org.apache.httpcomponents - httpmime - ${apache.httpcomponents.version} - - - com.google.code.gson - gson - 2.8.6 + com.aventstack + extentreports + 5.0.0-SNAPSHOT org.mongodb mongodb-driver - ${mongodb.version} + 3.3.0 org.mongodb bson - ${mongodb.version} + 3.3.0 + + + org.apache.httpcomponents + httpclient + 4.5.2 - org.testng - testng - 6.14.3 - test + org.apache.httpcomponents + httpmime + 4.5.2 @@ -103,7 +91,7 @@ org.apache.maven.plugins maven-compiler-plugin - 2.3.2 + 3.6.1 1.8 1.8 @@ -112,67 +100,19 @@ org.apache.maven.plugins maven-resources-plugin - 2.7 - - - org.apache.maven.plugins - maven-gpg-plugin - 1.6 - - - sign-artifacts - verify - - sign - - - - - - org.jacoco - jacoco-maven-plugin - 0.7.9 - - - - prepare-agent - - - - report - test - - report - - - + 3.1.0 - release-sign-artifacts - - - performRelease - true - - - - 41414BBD - - anshooarora - - - - org.apache.maven.plugins maven-source-plugin - 2.3 + 3.0.1 attach-sources @@ -185,7 +125,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.3 + 3.0.1 attach-javadocs @@ -210,5 +150,4 @@ https://oss.sonatype.org/service/local/staging/deploy/maven2 - \ No newline at end of file diff --git a/reporters/klov/src/main/java/com/aventstack/extentreports/reporter/ExtentKlovReporter.java b/reporters/klov/src/main/java/com/aventstack/extentreports/reporter/ExtentKlovReporter.java new file mode 100644 index 0000000..82ef7ae --- /dev/null +++ b/reporters/klov/src/main/java/com/aventstack/extentreports/reporter/ExtentKlovReporter.java @@ -0,0 +1,919 @@ +package com.aventstack.extentreports.reporter; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.Calendar; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.stream.Collectors; + +import org.bson.Document; +import org.bson.types.ObjectId; + +import com.aventstack.extentreports.Status; +import com.aventstack.extentreports.model.Author; +import com.aventstack.extentreports.model.Category; +import com.aventstack.extentreports.model.Device; +import com.aventstack.extentreports.model.ExceptionInfo; +import com.aventstack.extentreports.model.Log; +import com.aventstack.extentreports.model.Media; +import com.aventstack.extentreports.model.MetaDataStorable; +import com.aventstack.extentreports.model.NamedAttribute; +import com.aventstack.extentreports.model.Report; +import com.aventstack.extentreports.model.ReportStats; +import com.aventstack.extentreports.model.ScreenCapture; +import com.aventstack.extentreports.model.SystemEnvInfo; +import com.aventstack.extentreports.model.Test; +import com.aventstack.extentreports.model.context.NamedAttributeContext; +import com.aventstack.extentreports.model.context.NamedAttributeContextManager; +import com.aventstack.extentreports.observer.EntityObserver; +import com.aventstack.extentreports.observer.entity.AttributeEntity; +import com.aventstack.extentreports.observer.entity.LogEntity; +import com.aventstack.extentreports.observer.entity.MediaEntity; +import com.aventstack.extentreports.observer.entity.ObservedEntity; +import com.aventstack.extentreports.observer.entity.ReportEntity; +import com.aventstack.extentreports.observer.entity.TestEntity; +import com.mongodb.BasicDBObject; +import com.mongodb.MongoClient; +import com.mongodb.MongoClientOptions; +import com.mongodb.MongoClientURI; +import com.mongodb.MongoCredential; +import com.mongodb.ServerAddress; +import com.mongodb.client.FindIterable; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; + +import io.reactivex.rxjava3.core.Observer; +import io.reactivex.rxjava3.disposables.Disposable; + +/** + * ExtentKlovReporter is a NoSQL database reporter (MongoDB), which updates + * information in the database which is then used by the ExtentX server to + * display in-depth analysis. + * + * ExtentKlovReporter is a port from ExtentReports version 4. + */ +public class ExtentKlovReporter extends AbstractReporter + implements + EntityObserver { + public static final String ID_KEY = "KLOV_ID"; + public static final String REPORT_ID_KEY = "KLOV_REPORT_ID"; + public static final String LOG_ID_KEY = "KLOV_LOG_ID"; + public static final String TEST_ID_KEY = "KLOV_TEST_ID"; + + private static final String DEFAULT_PROJECT_NAME_PROP = "klov.project.name"; + private static final String DEFAULT_REPORT_NAME_PROP = "klov.report.name"; + private static final String DEFAULT_MONGODB_HOST_PROP = "mongodb.host"; + private static final String DEFAULT_MONGODB_PORT_PROP = "mongodb.port"; + private static final String DEFAULT_MONGODB_URI_PROP = "mongodb.uri"; + private static final String DEFAULT_KLOV_HOST_PROP = "klov.host"; + private static final String DEFAULT_KLOV_PORT_PROP = "klov.port"; + private static final String DB_NAME = "klov"; + private static final String DEFAULT_PROJECT_NAME = "Default"; + + private final AtomicBoolean initiated = new AtomicBoolean(); + + private String url; + private Boolean appendExisting = false; + + private NamedAttributeContextManager categoryContext; + private NamedAttributeContextManager authorContext; + private NamedAttributeContextManager deviceContext; + private Map categoryNameObjectIdCollection = new HashMap<>(); + private Map authorNameObjectIdCollection = new HashMap<>(); + private Map deviceNameObjectIdCollection = new HashMap<>(); + private Map exceptionNameObjectIdCollection = new HashMap<>(); + private KlovMediaStorageHandler mediaStorageHandler; + + private ObjectId reportId; + private String reportName; + private long reportSeq; + private ObjectId projectId; + private String projectName; + + private MongoClient mongoClient; + + private MongoCollection projectCollection; + private MongoCollection reportCollection; + private MongoCollection testCollection; + private MongoCollection logCollection; + private MongoCollection exceptionCollection; + private MongoCollection mediaCollection; + private MongoCollection categoryCollection; + private MongoCollection authorCollection; + private MongoCollection deviceCollection; + private MongoCollection environmentCollection; + + static { + /* use mongodb reporting for only critical/severe events */ + Logger mongoLogger = Logger.getLogger("org.mongodb.driver"); + mongoLogger.setLevel(Level.SEVERE); + } + + /** + * Initializes the KlovReporter + */ + public ExtentKlovReporter() { + } + + /** + * Initializes the KlovReporter with project and report names + * + * @param projectName + * Name of the project + * @param reportName + * Name of the report + */ + public ExtentKlovReporter(String projectName, String reportName) { + this(); + this.projectName = projectName; + this.reportName = reportName; + } + + public ExtentKlovReporter(String projectName) { + this(projectName, null); + } + + /** + * Sets the project name + * + * @param projectName + * Name of the project + */ + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + /** + * Sets the report name + * + * @param reportName + * Name of the report + */ + public void setReportName(String reportName) { + this.reportName = reportName; + } + + /** + * Initialize Mongo DB connection with host and default port: 27017 + * + * @param host + * host name + * @return a {@link ExtentKlovReporter} object + */ + public ExtentKlovReporter initMongoDbConnection(String host) { + mongoClient = new MongoClient(host, 27017); + return this; + } + + /** + * Initialize Mongo DB connection with host and {@link MongoClientOptions} + * + * @param host + * host name + * @param options + * {@link MongoClientOptions} options + * @return a {@link ExtentKlovReporter} object + */ + public ExtentKlovReporter initMongoDbConnection(String host, MongoClientOptions options) { + mongoClient = new MongoClient(host, options); + return this; + } + + /** + * Initialize Mongo DB connection with host and post + * + * @param host + * host name + * @param port + * port number + * @return a {@link ExtentKlovReporter} object + */ + public ExtentKlovReporter initMongoDbConnection(String host, int port) { + mongoClient = new MongoClient(host, port); + return this; + } + + /** + * Initialize Mongo DB connection with a {@link MongoClientURI} + * + * @param uri + * {@link MongoClientURI} uri + * @return a {@link ExtentKlovReporter} object + */ + public ExtentKlovReporter initMongoDbConnection(MongoClientURI uri) { + mongoClient = new MongoClient(uri); + return this; + } + + /** + * Initializes the Mongo DB connection with {@link ServerAddress} + * + * @param addr + * {@link ServerAddress} server address + * @return a {@link ExtentKlovReporter} object + */ + public ExtentKlovReporter initMongoDbConnection(ServerAddress addr) { + mongoClient = new MongoClient(addr); + return this; + } + + /** + * Initializes the Mongo DB connection with a list of {@link ServerAddress} + * addresses + * + * @param seeds + * A list of {@link ServerAddress} server addresses + * @return a {@link ExtentKlovReporter} object + */ + public ExtentKlovReporter initMongoDbConnection(List seeds) { + mongoClient = new MongoClient(seeds); + return this; + } + + /** + * Initializes the Mongo DB connection with a list of {@link ServerAddress} + * and {@link MongoCredential} + * + * @param seeds + * A list of {@link ServerAddress} server addresses + * @param credentialsList + * A list of {@link MongoCredential} credentials + * @return a {@link ExtentKlovReporter} object + */ + public ExtentKlovReporter initMongoDbConnection(List seeds, List credentialsList) { + mongoClient = new MongoClient(seeds, credentialsList); + return this; + } + + /** + * Initializes the Mongo DB connection with a list of {@link ServerAddress}, + * {@link MongoCredential} and {@link MongoClientOptions} + * + * @param seeds + * A list of {@link ServerAddress} server addresses + * @param credentialsList + * A list of {@link MongoCredential} credentials + * @param options + * {@link MongoClientOptions} options + * @return a {@link ExtentKlovReporter} object + */ + public ExtentKlovReporter initMongoDbConnection(List seeds, List credentialsList, + MongoClientOptions options) { + mongoClient = new MongoClient(seeds, credentialsList, options); + return this; + } + + /** + * Initializes the Mongo DB connection with a list of {@link ServerAddress} + * and {@link MongoClientOptions} + * + * @param seeds + * A list of {@link ServerAddress} server addresses + * @param options + * {@link MongoClientOptions} options + * @return a {@link ExtentKlovReporter} object + */ + public ExtentKlovReporter initMongoDbConnection(List seeds, MongoClientOptions options) { + mongoClient = new MongoClient(seeds, options); + return this; + } + + /** + * Initializes the Mongo DB connection with {@link ServerAddress} and a list + * of {@link MongoCredential} credentials + * + * @param addr + * {@link ServerAddress} server address + * @param credentialsList + * A list of {@link MongoCredential} credentials + * @return a {@link ExtentKlovReporter} object + */ + public ExtentKlovReporter initMongoDbConnection(ServerAddress addr, List credentialsList) { + mongoClient = new MongoClient(addr, credentialsList); + return this; + } + + /** + * Initializes the Mongo DB connection with a list of {@link ServerAddress}, + * {@link MongoCredential} and {@link MongoClientOptions} + * + * @param addr + * A list of {@link ServerAddress} server addresses + * @param credentialsList + * A list of {@link MongoCredential} credentials + * @param options + * {@link MongoClientOptions} options + * @return a {@link ExtentKlovReporter} object + */ + public ExtentKlovReporter initMongoDbConnection(ServerAddress addr, List credentialsList, + MongoClientOptions options) { + mongoClient = new MongoClient(addr, credentialsList, options); + return this; + } + + /** + * Initializes the Mongo DB connection with a {@link ServerAddress} and + * {@link MongoClientOptions} + * + * @param addr + * A list of {@link ServerAddress} server addresses + * @param options + * {@link MongoClientOptions} options + * @return a {@link ExtentKlovReporter} object + */ + public ExtentKlovReporter initMongoDbConnection(ServerAddress addr, MongoClientOptions options) { + mongoClient = new MongoClient(addr, options); + return this; + } + + /** + * Initializes the Mongo DB connection with a connection url + * + * @param url + * Url string + * @return a {@link ExtentKlovReporter} object + */ + public ExtentKlovReporter initKlovServerConnection(String url) { + this.url = url; + return this; + } + + /** + * Initializes KlovReporter with default Klov and MongoDB settings. This + * default the Klov server and MongoDB to LOCALHOST and also uses default + * ports 80 and 27017 respectively. + * + * @return A {@link ExtentKlovReporter} object + */ + public ExtentKlovReporter initWithDefaultSettings() { + return initMongoDbConnection("localhost", 27017) + .initKlovServerConnection("http://localhost"); + } + + public void loadInitializationParams(InputStream is) { + try { + Properties props = loadProperties(is); + loadInitializationParams(props); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private Properties loadProperties(InputStream is) throws IOException { + Properties properties = new Properties(); + properties.load(is); + return properties; + } + + private void loadInitializationParams(Properties props) { + String mongoUri = props.getProperty(DEFAULT_MONGODB_URI_PROP); + String mongoHost = props.getProperty(DEFAULT_MONGODB_HOST_PROP); + String mongoPort = props.getProperty(DEFAULT_MONGODB_PORT_PROP); + int mongoPortInt = IntUtil.tryParseInt(mongoPort) == true ? Integer.valueOf(mongoPort) : -1; + if (mongoHost != null && mongoPortInt != -1) { + initMongoDbConnection(mongoHost, mongoPortInt); + } else if (mongoHost != null) { + initMongoDbConnection(mongoHost); + } else if (mongoUri != null) { + initMongoDbConnection(new MongoClientURI(mongoUri)); + } else { + throw new IllegalStateException("Mongo connection params have not been supplied."); + } + + String projectName = props.getProperty(DEFAULT_PROJECT_NAME_PROP); + this.projectName = projectName == null || projectName.isEmpty() ? this.projectName : projectName; + + String reportName = props.getProperty(DEFAULT_REPORT_NAME_PROP); + reportName = reportName == null || reportName.isEmpty() ? this.reportName : reportName; + this.reportName = reportName; + + String klovHost = props.getProperty(DEFAULT_KLOV_HOST_PROP); + String klovPort = props.getProperty(DEFAULT_KLOV_PORT_PROP); + if (klovHost != null && klovPort != null) { + String uri = klovHost + ":" + klovPort; + initKlovServerConnection(uri); + } else if (klovHost != null) { + initKlovServerConnection(klovHost); + } + } + + private void initCollections(MongoDatabase db) { + projectCollection = db.getCollection("project"); + reportCollection = db.getCollection("report"); + testCollection = db.getCollection("test"); + logCollection = db.getCollection("log"); + exceptionCollection = db.getCollection("exception"); + mediaCollection = db.getCollection("media"); + categoryCollection = db.getCollection("category"); + authorCollection = db.getCollection("author"); + deviceCollection = db.getCollection("device"); + environmentCollection = db.getCollection("environment"); + } + + private void setupProject() { + String projectName = this.projectName == null || this.projectName.isEmpty() + ? DEFAULT_PROJECT_NAME + : this.projectName; + Document doc = new Document("name", projectName); + Document project = projectCollection.find(doc).first(); + if (project != null) { + projectId = project.getObjectId("_id"); + } else { + doc.append("createdAt", Calendar.getInstance().getTime()); + projectCollection.insertOne(doc); + projectId = MongoUtil.getId(doc); + } + setupReport(projectName); + } + + private void setupReport(String projectName) { + String reportName = this.reportName == null || this.reportName.isEmpty() + ? "Build " + Calendar.getInstance().getTimeInMillis() + : this.reportName; + this.reportName = reportName; + Document doc = new Document("name", reportName) + .append("project", projectId) + .append("projectName", projectName); + if (appendExisting) { + FindIterable iterable = reportCollection.find(doc); + Document report = iterable.first(); + if (report != null) { + reportId = report.getObjectId("_id"); + return; + } + } + reportSeq = reportCollection.count(new Document("project", projectId)) + 1; + doc.append("startTime", Calendar.getInstance().getTime()) + .append("seq", reportSeq); + reportCollection.insertOne(doc); + reportId = MongoUtil.getId(doc); + } + + public synchronized void flush(ReportEntity entity) { + Report report = entity.getReport(); + List testList = report.getTestList(); + + if (testList == null || testList.isEmpty()) + return; + + ReportStats stats = report.getStats(); + this.authorContext = report.getAuthorCtx(); + this.categoryContext = report.getCategoryCtx(); + this.deviceContext = report.getDeviceCtx(); + Set authorNameList = getCollectionKeys(authorNameObjectIdCollection); + Set categoryNameList = getCollectionKeys(categoryNameObjectIdCollection); + Set deviceNameList = getCollectionKeys(deviceNameObjectIdCollection); + Set exceptionNameList = getCollectionKeys(exceptionNameObjectIdCollection); + + Document doc = new Document("endTime", report.getEndTime()) + .append("duration", report.timeTaken()) + .append("status", report.getStatus().toLower()) + .append("parentLength", stats.sumStat(stats.getParent())) + .append("passParentLength", stats.getParent().get(Status.PASS)) + .append("failParentLength", stats.getParent().get(Status.FAIL)) + .append("warningParentLength", stats.getParent().get(Status.WARNING)) + .append("skipParentLength", stats.getParent().get(Status.SKIP)) + .append("childLength", stats.sumStat(stats.getChild())) + .append("passChildLength", stats.getChild().get(Status.PASS)) + .append("failChildLength", stats.getChild().get(Status.FAIL)) + .append("warningChildLength", stats.getChild().get(Status.WARNING)) + .append("skipChildLength", stats.getChild().get(Status.SKIP)) + .append("grandChildLength", stats.sumStat(stats.getGrandchild())) + .append("passGrandChildLength", stats.getGrandchild().get(Status.PASS)) + .append("failGrandChildLength", stats.getGrandchild().get(Status.FAIL)) + .append("warningGrandChildLength", stats.getGrandchild().get(Status.WARNING)) + .append("skipGrandChildLength", stats.getGrandchild().get(Status.SKIP)) + .append("analysisStrategy", stats.getAnalysisStrategy().toString()) + .append("bdd", testList.get(0).isBDD()); + + if (authorNameList != null && !authorNameList.isEmpty()) + doc.append("authorNameList", authorNameList); + if (categoryNameList != null && !categoryNameList.isEmpty()) + doc.append("categoryNameList", categoryNameList); + if (deviceNameList != null && !deviceNameList.isEmpty()) + doc.append("deviceNameList", deviceNameList); + if (exceptionNameList != null && !exceptionNameList.isEmpty()) + doc.append("exceptions", exceptionNameList); + + reportCollection.updateOne(new Document("_id", reportId), new Document("$set", doc)); + insertUpdateSystemAttribute(report); + } + + private void insertUpdateSystemAttribute(Report report) { + List sysEnvInfoList = report.getSystemEnvInfo(); + Document doc; + for (SystemEnvInfo attr : sysEnvInfoList) { + doc = new Document("project", projectId).append("report", reportId).append("name", attr.getName()); + Document envSingle = environmentCollection.find(doc).first(); + if (envSingle == null) { + doc.append("value", attr.getValue()); + environmentCollection.insertOne(doc); + } else { + ObjectId id = envSingle.getObjectId("_id"); + doc = new Document("_id", id).append("value", attr.getValue()); + environmentCollection.updateOne(new Document("_id", id), new Document("$set", doc)); + } + } + } + + private Set getCollectionKeys(Map collection) { + if (collection == null || collection.isEmpty()) + return null; + return collection.entrySet().stream().map(Map.Entry::getKey).collect(Collectors.toSet()); + } + + public Set getCollectionValues(Map collection) { + if (collection == null || collection.isEmpty()) + return null; + return collection.entrySet().stream().map(Map.Entry::getValue).collect(Collectors.toSet()); + } + + private void updateTestDesc(Test test) { + Document doc = new Document("description", test.getDescription()); + testCollection.updateOne(new Document("_id", test.getInfoMap().get(ID_KEY)), new Document("$set", doc)); + } + + private void updateTestChildrenCount(Test test) { + Document doc = new Document("childNodesLength", test.getChildren().size()); + testCollection.updateOne(new Document("_id", test.getInfoMap().get(ID_KEY)), new Document("$set", doc)); + } + + public Observer getAttributesObserver() { + return new Observer() { + @Override + public void onSubscribe(Disposable d) { + } + + @Override + public void onNext(AttributeEntity value) { + if (value.getAuthor() != null) + assignAttribute(value.getTest(), value.getAuthor(), authorNameObjectIdCollection, + authorCollection, + authorContext); + if (value.getCategory() != null) + assignAttribute(value.getTest(), value.getCategory(), categoryNameObjectIdCollection, + categoryCollection, + categoryContext); + if (value.getDevice() != null) + assignAttribute(value.getTest(), value.getDevice(), deviceNameObjectIdCollection, + deviceCollection, + deviceContext); + } + + @Override + public void onError(Throwable e) { + } + + @Override + public void onComplete() { + } + }; + } + + public void assignAttribute(Test test, NamedAttribute attribute, + Map attrObjectIdCollection, MongoCollection mongoCollection, + NamedAttributeContextManager attributeContext) { + Document doc; + if (!attrObjectIdCollection.containsKey(attribute.getName())) { + doc = new Document("report", reportId).append("project", projectId).append("name", attribute.getName()); + + FindIterable iterable = mongoCollection.find(doc); + Document docAttribute = iterable.first(); + + if (docAttribute != null) { + attrObjectIdCollection.put(attribute.getName(), docAttribute.getObjectId("_id")); + } else { + doc = new Document("testIdList", Arrays.asList(test.getInfoMap().get(ID_KEY))) + .append("testNameList", Arrays.asList(test.getName())) + .append("testLength", 1) + .append("project", projectId).append("report", reportId) + .append("name", attribute.getName()) + .append("timeTaken", Long.valueOf(0)); + mongoCollection.insertOne(doc); + ObjectId categoryId = MongoUtil.getId(doc); + attrObjectIdCollection.put(attribute.getName(), categoryId); + } + } else { + ObjectId id = attrObjectIdCollection.get(attribute.getName()); + // default length + int testLength = 1; + if (attributeContext != null) { + Optional> context = attributeContext.getSet() + .stream().filter(x -> x.getAttr().getName().equals(attribute.getName())).findFirst(); + if (context.isPresent()) + testLength = context.get().size() + 1; + } + mongoCollection.updateOne(new Document("_id", id), new Document("$push", + new Document("testIdList", test.getInfoMap().get(ID_KEY)) + .append("testNameList", test.getName()))); + mongoCollection.updateOne(new Document("_id", id), + new Document("$set", new Document("testLength", testLength))); + } + } + + public Observer getLogObserver() { + return new Observer() { + @Override + public void onSubscribe(Disposable d) { + } + + @Override + public void onNext(LogEntity value) { + onLogAdded(value.getTest(), value.getLog()); + } + + @Override + public void onError(Throwable e) { + } + + @Override + public void onComplete() { + } + }; + } + + public synchronized void onLogAdded(Test test, Log log) { + Document doc = new Document("test", test.getInfoMap().get(ID_KEY)) + .append("project", projectId).append("report", reportId) + .append("testName", test.getName()) + .append("sequence", log.getSeq()) + .append("status", log.getStatus().toLower()) + .append("timestamp", log.getTimestamp()) + .append("mediaCount", log.hasMedia() ? 1 : 0) + .append("details", log.getDetails()); + + if (log.hasException()) + doc.append("exception", log.getException().getName()) + .append("stacktrace", log.getException().getStackTrace()); + + if (log.hasMedia() && ((ScreenCapture) log.getMedia()).getBase64() != null) + doc.append("details", log.getDetails() + ((ScreenCapture) log.getMedia()).getBase64()); + + logCollection.insertOne(doc); + ObjectId logId = MongoUtil.getId(doc); + log.getInfoMap().put(ID_KEY, logId); + + // check for exceptions.. + for (ExceptionInfo ex : test.getExceptions()) { + ObjectId exceptionId; + doc = new Document("report", reportId) + .append("project", projectId) + .append("name", ex.getName()); + FindIterable iterable = exceptionCollection.find(doc); + Document docException = iterable.first(); + + // check if a matching exception name is available in 'Exception' + // collection + // (MongoDB) + // if a matching exception name is found, associate with this + // exception's + // ObjectId + if (!exceptionNameObjectIdCollection.containsKey(ex.getName())) { + if (docException != null) { + exceptionNameObjectIdCollection.put(ex.getName(), docException.getObjectId("_id")); + } else { + doc = new Document("project", projectId) + .append("report", reportId) + .append("name", ex.getName()) + .append("stacktrace", ex.getStackTrace()) + .append("testCount", 0); + exceptionCollection.insertOne(doc); + exceptionId = MongoUtil.getId(doc); + docException = exceptionCollection.find(new Document("_id", exceptionId)).first(); + exceptionNameObjectIdCollection.put(ex.getName(), exceptionId); + } + } + Integer testCount = ((Integer) (docException.get("testCount"))) + 1; + doc = new Document("testCount", testCount); + exceptionCollection.updateOne(new Document("_id", docException.getObjectId("_id")), + new Document("$set", doc)); + doc = new Document("exception", exceptionNameObjectIdCollection.get(ex.getName())); + testCollection.updateOne(new Document("_id", test.getInfoMap().get(ID_KEY)), new Document("$set", doc)); + updateTestDesc(test); + } + endTestRecursive(test); + } + + private void endTestRecursive(Test test) { + Document doc = new Document("status", test.getStatus().toLower()) + .append("endTime", test.getEndTime()) + .append("duration", test.timeTaken()) + .append("leaf", test.isLeaf()) + .append("mediaCount", !test.getMedia().isEmpty() ? test.getMedia().size() : 0) + .append("childNodesLength", test.hasChildren() ? test.getChildren().size() : 0) + .append("logCount", test.hasAnyLog() ? test.getLogs().size() + test.getGeneratedLog().size() : 0) + .append("categorized", test.hasAttributes()) + .append("description", test.getDescription()); + + if (test.hasCategory()) { + List categoryNameList = test.getCategorySet().stream().map(NamedAttribute::getName) + .collect(Collectors.toList()); + doc.append("categoryNameList", categoryNameList); + } + if (test.hasDevice()) { + List deviceNameList = test.getDeviceSet().stream().map(NamedAttribute::getName) + .collect(Collectors.toList()); + doc.append("deviceNameList", deviceNameList); + } + if (test.hasAuthor()) { + List authorNameList = test.getAuthorSet().stream().map(NamedAttribute::getName) + .collect(Collectors.toList()); + doc.append("authorNameList", authorNameList); + } + + testCollection.updateOne(new Document("_id", test.getInfoMap().get(ID_KEY)), new Document("$set", doc)); + if (test.getLevel() > 0) + endTestRecursive(test.getParent()); + } + + public Observer getMediaObserver() { + return new Observer() { + @Override + public void onSubscribe(Disposable d) { + } + + @Override + public void onNext(MediaEntity value) { + try { + if (value.getTest() != null) + onScreenCaptureAdded(value.getTest(), (ScreenCapture) value.getMedia()); + if (value.getLog() != null) + onScreenCaptureAdded(value.getLog(), (ScreenCapture) value.getMedia()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void onError(Throwable e) { + } + + @Override + public void onComplete() { + } + }; + } + + public void onScreenCaptureAdded(Test test, ScreenCapture screenCapture) throws IOException { + screenCapture.getInfoMap().put(TEST_ID_KEY, test.getInfoMap().get(ID_KEY)); + saveScreenCapture(test, screenCapture); + } + + public void onScreenCaptureAdded(Log log, ScreenCapture screenCapture) throws IOException { + screenCapture.getInfoMap().put(LOG_ID_KEY, log.getInfoMap().get(ID_KEY)); + saveScreenCapture(log, screenCapture); + } + + private void saveScreenCapture(MetaDataStorable store, ScreenCapture screenCapture) throws IOException { + if (mediaStorageHandler == null) { + KlovMedia klovMedia = new KlovMedia(projectId, reportId, mediaCollection); + mediaStorageHandler = new KlovMediaStorageHandler(url, klovMedia); + } + mediaStorageHandler.saveScreenCapture(store, screenCapture); + } + + public Observer getReportObserver() { + return new Observer() { + @Override + public void onSubscribe(Disposable d) { + } + + @Override + public void onNext(ReportEntity value) { + flush(value); + } + + // TODO: replace with DoFinally + @Override + public void onError(Throwable e) { + mongoClient.close(); + } + + @Override + public void onComplete() { + mongoClient.close(); + } + }; + } + + public Observer getTestObserver() { + return new Observer() { + @Override + public void onSubscribe(Disposable d) { + } + + @Override + public void onNext(TestEntity value) { + if (!initiated.get()) { + start(); + initiated.compareAndSet(false, true); + } + if (!value.getRemoved()) + onTestStarted(value.getTest()); + else + onTestRemoved(value.getTest()); + } + + @Override + public void onError(Throwable e) { + } + + @Override + public void onComplete() { + } + }; + } + + private final void start() { + MongoDatabase db = mongoClient.getDatabase(DB_NAME); + initCollections(db); + setupProject(); + } + + private void onTestStarted(Test test) { + Document doc = new Document("project", projectId) + .append("report", reportId) + .append("reportName", reportName) + .append("reportSeq", reportSeq) + .append("level", test.getLevel()) + .append("name", test.getName()) + .append("status", test.getStatus().toLower()) + .append("description", test.getDescription()) + .append("startTime", test.getStartTime()) + .append("endTime", test.getEndTime()) + .append("bdd", test.isBDD()) + .append("leaf", test.isLeaf()) + .append("childNodesLength", test.getChildren().size()) + .append("mediaCount", 0) + .append("childNodesLength", 0) + .append("logCount", 0); + + if (test.isBDD()) + doc.append("bddType", test.getBddType().getSimpleName()); + + if (test.getParent() != null) { + doc.append("parent", test.getParent().getInfoMap().get(ID_KEY)) + .append("parentName", test.getParent().getName()); + updateTestChildrenCount(test.getParent()); + updateTestDesc(test.getParent()); + } + + testCollection.insertOne(doc); + ObjectId testId = MongoUtil.getId(doc); + test.getInfoMap().put(ID_KEY, testId); + } + + private void onTestRemoved(Test test) { + Document doc = new Document("_id", test.getInfoMap().get(ID_KEY)); + testCollection.deleteOne(doc); + test.getLogs().forEach(this::removeLog); + if (test.hasAnyLog()) { + doc = new Document("test", test.getInfoMap().get(ID_KEY)); + logCollection.deleteMany(doc); + } + if (test.hasAttributes()) + removeFromAttributes(test); + if (test.hasChildren()) + test.getChildren().forEach(this::onTestRemoved); + } + + private void removeLog(Log log) { + Document doc = new Document("_id", log.getInfoMap().get(ID_KEY)); + logCollection.deleteOne(doc); + if (log.hasMedia()) + removeMedia(log.getMedia()); + } + + private void removeMedia(Media m) { + Document doc = new Document("_id", m.getInfoMap().get(ID_KEY)); + mediaCollection.deleteOne(doc); + } + + private void removeFromAttributes(Test t) { + Document match, update; + for (Author x : t.getAuthorSet()) { + match = new Document("_id", authorNameObjectIdCollection.get(x.getName())); + update = new Document("testIdList", t.getInfoMap().get(ID_KEY)); + authorCollection.updateOne(match, new BasicDBObject("$pull", update)); + } + for (Category x : t.getCategorySet()) { + match = new Document("_id", categoryNameObjectIdCollection.get(x.getName())); + update = new Document("testIdList", t.getInfoMap().get(ID_KEY)); + categoryCollection.updateOne(match, new BasicDBObject("$pull", update)); + } + for (Device x : t.getDeviceSet()) { + match = new Document("_id", deviceNameObjectIdCollection.get(x.getName())); + update = new Document("testIdList", t.getInfoMap().get(ID_KEY)); + deviceCollection.updateOne(match, new BasicDBObject("$pull", update)); + } + } +} diff --git a/reporters/klov/src/main/java/com/aventstack/extentreports/reporter/ExtentKlovReporterConfig.java b/reporters/klov/src/main/java/com/aventstack/extentreports/reporter/ExtentKlovReporterConfig.java new file mode 100644 index 0000000..59157dc --- /dev/null +++ b/reporters/klov/src/main/java/com/aventstack/extentreports/reporter/ExtentKlovReporterConfig.java @@ -0,0 +1,17 @@ +package com.aventstack.extentreports.reporter; + +import com.aventstack.extentreports.reporter.configuration.AbstractConfiguration; + +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.SuperBuilder; + +/** + * Defines configuration settings for the Klov reporter + */ +@Getter +@Setter +@SuperBuilder +public class ExtentKlovReporterConfig extends AbstractConfiguration { + +} diff --git a/reporters/klov/src/main/java/com/aventstack/extentreports/reporter/FileUtil.java b/reporters/klov/src/main/java/com/aventstack/extentreports/reporter/FileUtil.java new file mode 100644 index 0000000..3955831 --- /dev/null +++ b/reporters/klov/src/main/java/com/aventstack/extentreports/reporter/FileUtil.java @@ -0,0 +1,20 @@ +package com.aventstack.extentreports.reporter; + +import java.io.File; + +public class FileUtil { + private FileUtil() { + } + + public static String getExtension(File f) { + String name = f.getName(); + int i = name.lastIndexOf('.'); + if (i > 0) + return name.substring(i + 1); + return ""; + } + + public static String getExtension(String filePath) { + return getExtension(new File(filePath)); + } +} diff --git a/reporters/klov/src/main/java/com/aventstack/extentreports/reporter/HttpMediaManagerImplKlov.java b/reporters/klov/src/main/java/com/aventstack/extentreports/reporter/HttpMediaManagerImplKlov.java new file mode 100644 index 0000000..1425ff8 --- /dev/null +++ b/reporters/klov/src/main/java/com/aventstack/extentreports/reporter/HttpMediaManagerImplKlov.java @@ -0,0 +1,109 @@ +package com.aventstack.extentreports.reporter; + +import java.io.File; +import java.io.IOException; +import java.util.Calendar; +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.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.TrustSelfSignedStrategy; +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 org.apache.http.impl.client.HttpClients; +import org.apache.http.ssl.SSLContextBuilder; + +import com.aventstack.extentreports.model.Media; +import com.aventstack.extentreports.model.ScreenCapture; + +public class HttpMediaManagerImplKlov + implements + MediaStorage { + + private static final Logger logger = Logger.getLogger(HttpMediaManagerImplKlov.class.getName()); + private static final String ROUTE = "api/files"; + + 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).getBase64() != 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(Calendar.getInstance().getTime().getTime() + "." + ext, ContentType.TEXT_PLAIN)); + builder.addPart("id", + new StringBody(m.getInfoMap().get(ExtentKlovReporter.ID_KEY).toString(), ContentType.TEXT_PLAIN)); + builder.addPart("reportId", + new StringBody(m.getInfoMap().get(ExtentKlovReporter.REPORT_ID_KEY).toString(), + ContentType.TEXT_PLAIN)); + builder.addPart("testId", + new StringBody(m.getInfoMap().get(ExtentKlovReporter.TEST_ID_KEY).toString(), ContentType.TEXT_PLAIN)); + builder.addPart("f", new FileBody(new File(m.getResolvedPath()))); + post.setEntity(builder.build()); + + String logId = m.getInfoMap().get(ExtentKlovReporter.LOG_ID_KEY) == null + ? null + : m.getInfoMap().get(ExtentKlovReporter.LOG_ID_KEY).toString(); + builder.addPart("logId", new StringBody(logId, ContentType.TEXT_PLAIN)); + + HttpClient client = null; + if (host.toLowerCase().startsWith("https")) { + SSLContextBuilder sslContextBuilder = new SSLContextBuilder(); + try { + sslContextBuilder.loadTrustMaterial(new TrustSelfSignedStrategy()); + @SuppressWarnings("deprecation") + SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( + sslContextBuilder.build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); + client = HttpClients.custom().setSSLSocketFactory( + sslsf).build(); + } catch (Exception e) { + + } + } else { + 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 200 <= responseCode && responseCode <= 399; + } + +} diff --git a/src/main/java/com/aventstack/extentreports/utils/IntUtil.java b/reporters/klov/src/main/java/com/aventstack/extentreports/reporter/IntUtil.java similarity index 85% rename from src/main/java/com/aventstack/extentreports/utils/IntUtil.java rename to reporters/klov/src/main/java/com/aventstack/extentreports/reporter/IntUtil.java index 4ec796b..ed32eca 100644 --- a/src/main/java/com/aventstack/extentreports/utils/IntUtil.java +++ b/reporters/klov/src/main/java/com/aventstack/extentreports/reporter/IntUtil.java @@ -1,7 +1,6 @@ -package com.aventstack.extentreports.utils; +package com.aventstack.extentreports.reporter; public class IntUtil { - private IntUtil() { } @@ -13,5 +12,4 @@ public static boolean tryParseInt(String value) { return false; } } - } \ No newline at end of file diff --git a/reporters/klov/src/main/java/com/aventstack/extentreports/reporter/KlovMedia.java b/reporters/klov/src/main/java/com/aventstack/extentreports/reporter/KlovMedia.java new file mode 100644 index 0000000..5421417 --- /dev/null +++ b/reporters/klov/src/main/java/com/aventstack/extentreports/reporter/KlovMedia.java @@ -0,0 +1,21 @@ +package com.aventstack.extentreports.reporter; + +import org.bson.Document; +import org.bson.types.ObjectId; + +import com.mongodb.client.MongoCollection; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class KlovMedia { + private ObjectId reportId; + private ObjectId projectId; + private MongoCollection mediaCollection; +} diff --git a/reporters/klov/src/main/java/com/aventstack/extentreports/reporter/KlovMediaStorageHandler.java b/reporters/klov/src/main/java/com/aventstack/extentreports/reporter/KlovMediaStorageHandler.java new file mode 100644 index 0000000..66c07c1 --- /dev/null +++ b/reporters/klov/src/main/java/com/aventstack/extentreports/reporter/KlovMediaStorageHandler.java @@ -0,0 +1,49 @@ +package com.aventstack.extentreports.reporter; + +import java.io.IOException; + +import org.bson.Document; +import org.bson.types.ObjectId; + +import com.aventstack.extentreports.model.MetaDataStorable; +import com.aventstack.extentreports.model.ScreenCapture; +import com.aventstack.extentreports.model.Test; + +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(MetaDataStorable el, ScreenCapture media) throws IOException { + Document doc = new Document("project", klovMedia.getProjectId()) + .append("report", klovMedia.getReportId()) + .append("test", media.getInfoMap().get(ExtentKlovReporter.TEST_ID_KEY)); + + if (el.getClass() != Test.class) { + doc.append("log", media.getInfoMap().get(ExtentKlovReporter.LOG_ID_KEY)); + } else { + doc.append("testName", ((Test) el).getName()); + } + + if (media.getBase64() != null) + doc.append("base64String", media.getBase64()); + + klovMedia.getMediaCollection().insertOne(doc); + ObjectId mediaId = MongoUtil.getId(doc); + media.getInfoMap().put(ExtentKlovReporter.ID_KEY, mediaId); + media.getInfoMap().put(ExtentKlovReporter.REPORT_ID_KEY, klovMedia.getReportId()); + + if (media.getBase64() != null) + return; + + mediaStorage.storeMedia((ScreenCapture) media); + } + +} diff --git a/src/main/java/com/aventstack/extentreports/mediastorage/MediaStorage.java b/reporters/klov/src/main/java/com/aventstack/extentreports/reporter/MediaStorage.java similarity index 61% rename from src/main/java/com/aventstack/extentreports/mediastorage/MediaStorage.java rename to reporters/klov/src/main/java/com/aventstack/extentreports/reporter/MediaStorage.java index 835efe5..87c8639 100644 --- a/src/main/java/com/aventstack/extentreports/mediastorage/MediaStorage.java +++ b/reporters/klov/src/main/java/com/aventstack/extentreports/reporter/MediaStorage.java @@ -1,13 +1,10 @@ -package com.aventstack.extentreports.mediastorage; +package com.aventstack.extentreports.reporter; import java.io.IOException; import com.aventstack.extentreports.model.Media; public interface MediaStorage { - - void init(String v) throws IOException; - + void init(String v) throws IOException; void storeMedia(Media m) throws IOException; - } diff --git a/reporters/klov/src/main/java/com/aventstack/extentreports/reporter/MongoUtil.java b/reporters/klov/src/main/java/com/aventstack/extentreports/reporter/MongoUtil.java new file mode 100644 index 0000000..f34afa1 --- /dev/null +++ b/reporters/klov/src/main/java/com/aventstack/extentreports/reporter/MongoUtil.java @@ -0,0 +1,13 @@ +package com.aventstack.extentreports.reporter; + +import org.bson.Document; +import org.bson.types.ObjectId; + +public class MongoUtil { + private MongoUtil() { + } + + public static ObjectId getId(Document doc) { + return (ObjectId) doc.get("_id"); + } +} diff --git a/src/main/java/com/aventstack/extentreports/AbstractProcessor.java b/src/main/java/com/aventstack/extentreports/AbstractProcessor.java new file mode 100644 index 0000000..36a0d3d --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/AbstractProcessor.java @@ -0,0 +1,100 @@ +package com.aventstack.extentreports; + +import java.io.File; +import java.io.IOException; + +import com.aventstack.extentreports.append.RawEntityConverter; +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.Media; +import com.aventstack.extentreports.model.SystemEnvInfo; +import com.aventstack.extentreports.model.Test; +import com.aventstack.extentreports.model.service.MediaService; +import com.aventstack.extentreports.model.service.TestService; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public abstract class AbstractProcessor extends ReactiveSubject { + private String[] mediaResolverPath; + private boolean usingNaturalConf = true; + + @Override + protected void onTestCreated(Test test) { + getReport().getTestList().add(test); + super.onTestCreated(test); + } + + @Override + protected void onTestRemoved(Test test) { + TestService.deleteTest(getReport().getTestList(), test); + super.onTestRemoved(test); + } + + protected void onNodeCreated(Test node) { + super.onTestCreated(node); + } + + @Override + protected void onLogCreated(Log log, Test test) { + super.onLogCreated(log, test); + if (log.hasException()) + getReport().getExceptionInfoCtx().addContext(log.getException(), test); + } + + @Override + protected void onMediaAdded(Media m, Test test) { + tryResolvePath(m); + super.onMediaAdded(m, test); + } + + @Override + protected void onMediaAdded(Media m, Log log) { + tryResolvePath(m); + super.onMediaAdded(m, log); + } + + private void tryResolvePath(Media m) { + MediaService.tryResolveMediaPath(m, mediaResolverPath); + } + + protected void onAuthorAdded(Author x, Test test) { + getReport().getAuthorCtx().addContext(x, test); + super.onAuthorAssigned(x, test); + } + + protected void onCategoryAdded(Category x, Test test) { + getReport().getCategoryCtx().addContext(x, test); + super.onCategoryAssigned(x, test); + } + + protected void onDeviceAdded(Device x, Test test) { + getReport().getDeviceCtx().addContext(x, test); + super.onDeviceAssigned(x, test); + } + + @Override + protected void onFlush() { + getReport().refresh(); + if (!usingNaturalConf) + getReport().applyOverrideConf(); + super.onFlush(); + } + + protected void onReportLogAdded(String log) { + getReport().getLogs().add(log); + } + + protected void onSystemInfoAdded(SystemEnvInfo env) { + getReport().getSystemEnvInfo().add(env); + } + + protected void convertRawEntities(ExtentReports extent, File f) throws IOException { + RawEntityConverter converter = new RawEntityConverter(extent); + converter.convertAndApply(f); + } +} diff --git a/src/main/java/com/aventstack/extentreports/AnalysisStrategy.java b/src/main/java/com/aventstack/extentreports/AnalysisStrategy.java index fdfca02..e305a8c 100644 --- a/src/main/java/com/aventstack/extentreports/AnalysisStrategy.java +++ b/src/main/java/com/aventstack/extentreports/AnalysisStrategy.java @@ -1,16 +1,36 @@ package com.aventstack.extentreports; +import com.aventstack.extentreports.gherkin.model.IGherkinFormatterModel; +import com.aventstack.extentreports.model.ReportStats; + /** - * Strategy used to generate statistics for the current run - *

- * Available strategies are: - *

    - *
  • BDD: Strategy for BDD-style (Gherkin) tests
  • - *
  • CLASS: Used for 2 levels: Class, Test
  • - *
  • SUITE: Used for 3 levels: Suite, Class, Test
  • - *
  • TEST: Used for 1 level only: Test
  • - *
+ * Enumeration for various kinds of analysis strategies used by + * {@link ReportStats} */ public enum AnalysisStrategy { - BDD, CLASS, SUITE, TEST -} \ No newline at end of file + /** + * This is the efault strategy used by BDD tests. If any created test uses a + * {@link IGherkinFormatterModel} type, the strategy would default to BDD + * and {@link AnalysisStrategy} would be ignored. + */ + BDD, + + /** + * This strategy is useful when all tests in a suite are grouped together by + * their containing Class. This strategy would account for the number of + * Classes that passed or failed, and repeat the process for tests. + */ + CLASS, + + /** + * This strategy is useful if there are 3 levels in the hierarchy: Suite, + * Class and Test. + */ + SUITE, + + /** + * TEST is the default strategy and only tracks the leaf nodes to create + * {@link ReportStats} + */ + TEST +} diff --git a/src/main/java/com/aventstack/extentreports/AnalysisTypeConfigurable.java b/src/main/java/com/aventstack/extentreports/AnalysisTypeConfigurable.java new file mode 100644 index 0000000..58cc9c2 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/AnalysisTypeConfigurable.java @@ -0,0 +1,6 @@ +package com.aventstack.extentreports; + +@FunctionalInterface +public interface AnalysisTypeConfigurable { + void setAnalysisStrategy(AnalysisStrategy strategy); +} diff --git a/src/main/java/com/aventstack/extentreports/ExtentReports.java b/src/main/java/com/aventstack/extentreports/ExtentReports.java index e5f7a77..1e92e89 100644 --- a/src/main/java/com/aventstack/extentreports/ExtentReports.java +++ b/src/main/java/com/aventstack/extentreports/ExtentReports.java @@ -6,14 +6,13 @@ import java.util.Arrays; import java.util.List; -import com.aventstack.extentreports.convert.TestModelReportBuilder; -import com.aventstack.extentreports.gherkin.GherkinDialectProvider; +import com.aventstack.extentreports.gherkin.GherkinDialectManager; import com.aventstack.extentreports.gherkin.model.IGherkinFormatterModel; import com.aventstack.extentreports.model.Media; -import com.aventstack.extentreports.model.ScreenCapture; -import com.aventstack.extentreports.model.SystemAttribute; -import com.aventstack.extentreports.reporter.ExtentKlovReporter; -import com.aventstack.extentreports.reporter.ExtentReporter; +import com.aventstack.extentreports.model.ReportStats; +import com.aventstack.extentreports.model.SystemEnvInfo; +import com.aventstack.extentreports.model.service.TestService; +import com.aventstack.extentreports.observer.ExtentObserver; /** *

@@ -56,433 +55,411 @@ * @see IGherkinFormatterModel * @see Status */ -public class ExtentReports extends ReportObservable { - private static final String[] IMAGE_PATH_RESOLVER_DIR = new String[] { "target/", "test-output/" }; - - /** - * Attach a {@link ExtentReporter} reporter, allowing it to access all started - * tests, nodes and logs - * - *

- * Available reporter types are: - *

- * - *
    - *
  • ExtentHtmlReporter provided by artifactId "extent-html-formatter"
  • - *
  • ExtentEmailReporter (pro-only) provided by artifactId - * "extent-email-formatter"
  • - *
  • KlovReporter provided by artifactId "extent-klov-reporter"
  • - *
  • ConsoleLogger
  • - *
- * - * @param reporter {@link ExtentReporter} reporter - */ - public void attachReporter(ExtentReporter... reporter) { - Arrays.stream(reporter).forEach(this::register); - } +public class ExtentReports extends AbstractProcessor implements Writable, AnalysisTypeConfigurable { - /** - * Returns a list of started reporters - * - * @return A list of {@link ExtentReporter} - */ - public List getStartedReporters() { - return getReporterCollection(); - } + /** + * Attach a {@link ExtentObserver} reporter, allowing it to access all + * started tests, nodes and logs + * + * @param observer + * {@link ExtentObserver} reporter + */ + @SuppressWarnings("rawtypes") + public void attachReporter(ExtentObserver... observer) { + attachReporter(Arrays.asList(observer)); + } - /** - * Creates a BDD-style test with description 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}
  • - *
  • {@link com.aventstack.extentreports.gherkin.model.But}
  • - *
- * - *

- * Example: - *

- * - *
-	 * extent.createTest(Feature.class, "feature", "description");
-	 * extent.createTest(Scenario.class, "scenario", "description");
-	 * extent.createTest(Given.class, "given", "description");
-	 * 
- * - * @param type A {@link IGherkinFormatterModel} type - * @param testName Name of test - * @param description A short description of the test - * - * @return {@link ExtentTest} object - */ - public ExtentTest createTest(Class type, String testName, - String description) { - ExtentTest t = new ExtentTest(this, type, testName, description); - applyCommonTestSettings(t); - saveTest(t.getModel()); - return t; - } + /** + * Creates a BDD-style test with description 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}
  • + *
  • {@link com.aventstack.extentreports.gherkin.model.But}
  • + *
+ * + *

+ * Example: + *

+ * + *
+     * extent.createTest(Feature.class, "feature", "description");
+     * extent.createTest(Scenario.class, "scenario", "description");
+     * extent.createTest(Given.class, "given", "description");
+     * 
+ * + * @param type + * A {@link IGherkinFormatterModel} type + * @param name + * Name of test + * @param description + * A short description of the test + * + * @return {@link ExtentTest} object + */ + public ExtentTest createTest(Class type, String name, + String description) { + ExtentTest t = new ExtentTest(this, type, name, description); + onTestCreated(t.getModel()); + return t; + } - /** - * Creates a BDD-style test 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}
  • - *
  • {@link com.aventstack.extentreports.gherkin.model.But}
  • - *
- * - *

- * Example: - *

- * - *
-	 * extent.createTest(Feature.class, "feature");
-	 * extent.createTest(Scenario.class, "scenario");
-	 * extent.createTest(Given.class, "given");
-	 * 
- * - * @param type A {@link IGherkinFormatterModel} type - * @param testName Name of test - * - * @return {@link ExtentTest} object - */ - public ExtentTest createTest(Class type, String testName) { - return createTest(type, testName, null); - } + /** + * Creates a BDD-style test 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}
  • + *
  • {@link com.aventstack.extentreports.gherkin.model.But}
  • + *
+ * + *

+ * Example: + *

+ * + *
+     * extent.createTest(Feature.class, "feature");
+     * extent.createTest(Scenario.class, "scenario");
+     * extent.createTest(Given.class, "given");
+     * 
+ * + * @param type + * A {@link IGherkinFormatterModel} type + * @param name + * Name of test + * + * @return {@link ExtentTest} object + */ + public ExtentTest createTest(Class type, String name) { + return createTest(type, name, null); + } - /** - * Creates a BDD-style test 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}
  • - *
  • {@link com.aventstack.extentreports.gherkin.model.But}
  • - *
- * - *

- * Example: - *

- * - *
-	 * extent.createTest(new GherkinKeyword("Feature"), "feature", "description");
-	 * extent.createTest(new GherkinKeyword("Scenario"), "scenario", "description");
-	 * extent.createTest(new GherkinKeyword("Given"), "given", "description");
-	 * 
- * - * @param gherkinKeyword Name of the {@link GherkinKeyword} - * @param testName Name of test - * @param description A short description of the test - * - * @return {@link ExtentTest} object - */ - public ExtentTest createTest(GherkinKeyword gherkinKeyword, String testName, String description) { - Class clazz = gherkinKeyword.getKeyword().getClass(); - return createTest(clazz, testName, description); - } + /** + * Creates a BDD-style test 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}
  • + *
  • {@link com.aventstack.extentreports.gherkin.model.But}
  • + *
+ * + *

+ * Example: + *

+ * + *
+     * extent.createTest(new GherkinKeyword("Feature"), "feature", "description");
+     * extent.createTest(new GherkinKeyword("Scenario"), "scenario", "description");
+     * extent.createTest(new GherkinKeyword("Given"), "given", "description");
+     * 
+ * + * @param gherkinKeyword + * Name of the {@link GherkinKeyword} + * @param name + * Name of test + * @param description + * A short description of the test + * + * @return {@link ExtentTest} object + */ + public ExtentTest createTest(GherkinKeyword gherkinKeyword, String name, String description) { + Class clazz = gherkinKeyword.getKeyword().getClass(); + return createTest(clazz, name, description); + } - /** - * Creates a BDD-style test 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}
  • - *
  • {@link com.aventstack.extentreports.gherkin.model.But}
  • - *
- * - *

- * Example: - *

- * - *
-	 * extent.createTest(new GherkinKeyword("Feature"), "feature");
-	 * extent.createTest(new GherkinKeyword("Scenario"), "scenario");
-	 * extent.createTest(new GherkinKeyword("Given"), "given");
-	 * 
- * - * @param gherkinKeyword Name of the {@link GherkinKeyword} - * @param testName Name of test - * - * @return {@link ExtentTest} object - */ - public ExtentTest createTest(GherkinKeyword gherkinKeyword, String testName) { - return createTest(gherkinKeyword, testName, null); - } + /** + * Creates a BDD-style test 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}
  • + *
  • {@link com.aventstack.extentreports.gherkin.model.But}
  • + *
+ * + *

+ * Example: + *

+ * + *
+     * extent.createTest(new GherkinKeyword("Feature"), "feature");
+     * extent.createTest(new GherkinKeyword("Scenario"), "scenario");
+     * extent.createTest(new GherkinKeyword("Given"), "given");
+     * 
+ * + * @param gherkinKeyword + * Name of the {@link GherkinKeyword} + * @param testName + * Name of test + * + * @return {@link ExtentTest} object + */ + public ExtentTest createTest(GherkinKeyword gherkinKeyword, String testName) { + return createTest(gherkinKeyword, testName, null); + } - /** - * Creates a test with description - * - * @param testName Name of test - * @param description A short test description - * - * @return {@link ExtentTest} object - */ - public ExtentTest createTest(String testName, String description) { - ExtentTest t = new ExtentTest(this, testName, description); - applyCommonTestSettings(t); + /** + * Creates a test with description + * + * @param name + * Name of test + * @param description + * A short test description + * + * @return {@link ExtentTest} object + */ + public ExtentTest createTest(String name, String description) { + ExtentTest t = new ExtentTest(this, name, description); + onTestCreated(t.getModel()); + return t; + } - saveTest(t.getModel()); + /** + * Creates a test + * + * @param name + * Name of test + * + * @return {@link ExtentTest} object + */ + public ExtentTest createTest(String name) { + return createTest(name, null); + } - return t; - } + /** + * Removes a test + * + * @param test + * {@link ExtentTest} object + */ + public void removeTest(ExtentTest test) { + onTestRemoved(test.getModel()); + } - /** - * Creates a test - * - * @param testName Name of test - * - * @return {@link ExtentTest} object - */ - public ExtentTest createTest(String testName) { - return createTest(testName, null); - } + /** + * Removes a test by name + * + * @param name + * The test name + */ + public void removeTest(String name) { + TestService.findTest(getReport().getTestList(), name) + .ifPresent(this::onTestRemoved); + } - private void applyCommonTestSettings(ExtentTest extentTest) { - extentTest.setUseManualConfiguration(getAllowManualConfig()); - } + /** + * Writes test information from the started reporters to their output view + * + *
    + *
  • extent-html-formatter: flush output to HTML file
  • + *
  • extent-klov-reporter: updates MongoDB collections
  • + *
  • extent-email-formatter (pro-only): creates or appends to an HTML + * file
  • + *
  • ConsoleLogger: no action taken
  • + *
+ */ + @Override + public void flush() { + onFlush(); + } - /** - * Removes a test - * - * @param test {@link ExtentTest} object - */ - public void removeTest(ExtentTest test) { - super.removeTest(test.getModel()); - } + /** + * Adds any applicable system information to all started reporters + * + *

+ * Example: + *

+ * + *
+     * extent.setSystemInfo("HostName", "AventStack");
+     * 
+ * + * @param k + * Name of system variable + * @param v + * Value of system variable + */ + public void setSystemInfo(String k, String v) { + onSystemInfoAdded(new SystemEnvInfo(k, v)); + } - /** - * Writes test information from the started reporters to their output view - * - *
    - *
  • extent-html-formatter: flush output to HTML file
  • - *
  • extent-klov-reporter: updates MongoDB collections
  • - *
  • extent-email-formatter (pro-only): creates or appends to an HTML - * file
  • - *
  • ConsoleLogger: no action taken
  • - *
- */ - @Override - public void flush() { - super.flush(); - } + /** + * Adds logs from test framework tools to the test-runner logs view (if + * available in the reporter) + * + *

+ * TestNG usage example: + *

+ * + *
+     * extent.setTestRunnerOutput(Reporter.getOutput());
+     * 
+ * + * @param log + * Log string from the test runner frameworks such as TestNG or + * JUnit + */ + public void addTestRunnerOutput(List log) { + log.forEach(this::addTestRunnerOutput); + } - /** - * Adds any applicable system information to all started reporters - * - *

- * Example: - *

- * - *
-	 * extent.setSystemInfo("HostName", "AventStack-PC");
-	 * 
- * - * @param k Name of system variable - * @param v Value of system variable - */ - public void setSystemInfo(String k, String v) { - SystemAttribute sa = new SystemAttribute(k, v); - super.setSystemInfo(sa); - } + /** + * 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 addTestRunnerOutput(String log) { + onReportLogAdded(log); + } - /** - * Adds logs from test framework tools to the test-runner logs view (if - * available in the reporter) - * - *

- * TestNG usage example: - *

- * - *
-	 * extent.setTestRunnerOutput(Reporter.getOutput());
-	 * 
- * - * @param log Log string from the test runner frameworks such as TestNG or JUnit - */ - public void setTestRunnerOutput(List log) { - log.forEach(this::setTestRunnerLogs); - } + /** + * Tries to resolve a {@link Media} 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 path + * Dirs used to create absolute path of the {@link Media} object + * + * @return {@link ExtentReports} + */ + public ExtentReports tryResolveMediaPath(String[] path) { + setMediaResolverPath(path); + return this; + } - /** - * 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 jsonFile + * The JSON archive file + * @throws IOException + * Exception thrown if the jsonFile is not found + */ + public void createDomainFromJsonArchive(File jsonFile) throws IOException { + convertRawEntities(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 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(); - } + /** + * 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)); + } - /** - * 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); - } + /** + * 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) { + setUsingNaturalConf(!useManualConfig); + } - /** - * Provides common report configurations - * - * @return an instance of {@link ReportConfigurator} - */ - public ReportConfigurator config() { - return ReportConfigurator.getInstance(); - } + /** + * 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); + } - /** - * 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 ReportStats} with counts of tests executed + * by their status (pass, fail, skip etc) + * + * @return an instance of {@link ReportStats} + */ + 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..1d8a392 100644 --- a/src/main/java/com/aventstack/extentreports/ExtentTest.java +++ b/src/main/java/com/aventstack/extentreports/ExtentTest.java @@ -1,21 +1,23 @@ 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.markuputils.Markup; +import com.aventstack.extentreports.markuputils.MarkupHelper; import com.aventstack.extentreports.model.Author; import com.aventstack.extentreports.model.Category; import com.aventstack.extentreports.model.Device; 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 lombok.Getter; /** * Defines a test. You can add logs, snapshots, assign author and categories to @@ -42,1183 +44,1052 @@ * 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 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 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 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 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 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 type, String name, String description) { + if (name == null || name.isEmpty()) + throw new IllegalArgumentException("Test name cannot be null or empty"); + model = Test.builder() + .bddType(type) + .name(name) + .description(description) + .useNaturalConf(extent.isUsingNaturalConf()) + .build(); + 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 type, String name, + String description) { + ExtentTest t = new ExtentTest(extent, type, name, description); + model.addChild(t.getModel()); + extent.onNodeCreated(t.getModel()); + 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); + model.addChild(t.getModel()); + extent.onNodeCreated(t.getModel()); + 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 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); + } + + /** + * Create a non-standard log with details. This is unlike the + * log method, which creates a fixed table layout with the + * following columns: + * + *
    + *
  • Timestamp
  • + *
  • Status
  • + *
  • Details
  • + *
+ * + * @param status + * {@link Status} + * @param details + * Text details of the step + * @return an {@link ExtentTest} object + */ + public ExtentTest generateLog(Status status, String details) { + Log log = Log.builder().status(status).details(details).build(); + model.addGeneratedLog(log); + return this; + } + + /** + * Create a non-standard log with details. This is unlike the + * log method, which creates a fixed table layout with the + * following columns: + * + *
    + *
  • Timestamp
  • + *
  • Status
  • + *
  • Details
  • + *
+ * + * generateLog with {@link Markup} allows for a user-defined + * log with any type of markup supported by {@link MarkupHelper}. + * + * @param status + * {@link Status} + * @param markup + * A {@link Markup} created by {@link MarkupHelper} + * @return an {@link ExtentTest} object + */ + 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 t + * A {@link Throwable} exception to be logged, enabling the + * Exception view of certain HTML reporters + * @param media + * A {@link Media} object + * + * @return An {@link ExtentTest} object + */ + public ExtentTest log(Status status, String details, Throwable t, Media media) { + if (status == null) + throw new IllegalArgumentException("Status must not be null"); + Log log = Log.builder() + .status(status) + .details(details == null ? "" : details) + .build(); + ExceptionInfo exceptionInfo = ExceptionInfoService.createExceptionInfo(t); + log.setException(exceptionInfo); + log.addMedia(media); + model.addLog(log); + 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 media + * A {@link Media} object provided by {@link MediaEntityBuilder} + * + * @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 + * A {@link Throwable} exception to be logged, enabling the + * Exception view of certain HTML reporters + * @param media + * A {@link Media} object provided by {@link MediaEntityBuilder} + * + * @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 + * A {@link Throwable} exception to be logged, enabling the + * Exception view of certain HTML reporters + * + * @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 + * A {@link Media} object provided by {@link MediaEntityBuilder} + * + * @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 media + * A {@link Media} object provided by {@link MediaEntityBuilder} + * + * @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 media + * A {@link Media} object provided by {@link MediaEntityBuilder} + * + * @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 + * A {@link Media} object provided by {@link MediaEntityBuilder} + * + * @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 media + * A {@link Media} object provided by {@link MediaEntityBuilder} + * + * @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 media + * A {@link Media} object provided by {@link MediaEntityBuilder} + * + * @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 + * A {@link Media} object provided by {@link MediaEntityBuilder} + * + * @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 media + * A {@link Media} object provided by {@link MediaEntityBuilder} + * + * @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 media + * A {@link Media} object provided by {@link MediaEntityBuilder} + * + * @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 + * A {@link Media} object provided by {@link MediaEntityBuilder} + * + * @return {@link ExtentTest} object + */ + public ExtentTest warning(Media media) { + log(Status.WARNING, media); + return this; + } + + /** + * + * @param details + * Details + * @param media + * A {@link Media} object provided by {@link MediaEntityBuilder} + * + * @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 media + * A {@link Media} object provided by {@link MediaEntityBuilder} + * + * @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 + * A {@link Media} object provided by {@link MediaEntityBuilder} + * + * @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 model.getStatus(); + } + + 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(); + model.addMedia(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"); + if (!base64.startsWith("data:")) + base64 = "data:image/png;base64," + base64; + Media m = ScreenCapture.builder().base64(base64).title(title).build(); + model.addMedia(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..b1dd4d0 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.GherkinDialectManager; import com.aventstack.extentreports.gherkin.model.Asterisk; import com.aventstack.extentreports.gherkin.model.IGherkinFormatterModel; import freemarker.template.utility.StringUtil; +import lombok.Getter; /** * Allows {@link IGherkinFormatterModel} to be returned by using a name, from @@ -39,49 +40,47 @@ * * @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) { + apiKeyword = StringUtil.capitalize(key.getKey()); + break; + } + } + } + if (apiKeyword == null) + throw new GherkinKeywordNotFoundException("Keyword cannot be found. " + + "You supplied: " + gk + " for dialect " + dialect + " which couldn't be mapped."); + if (apiKeyword.toLowerCase().contains("scenario") && apiKeyword.toLowerCase().contains("outline")) + apiKeyword = "ScenarioOutline"; + 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..04c6b05 100644 --- a/src/main/java/com/aventstack/extentreports/MediaEntityBuilder.java +++ b/src/main/java/com/aventstack/extentreports/MediaEntityBuilder.java @@ -1,7 +1,5 @@ package com.aventstack.extentreports; -import java.io.IOException; - import com.aventstack.extentreports.model.Media; import com.aventstack.extentreports.model.ScreenCapture; @@ -10,61 +8,48 @@ * */ 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 final String BASE64_ENCODED = "data:image/png;base64,"; + 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) { + 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) { + return createScreenCaptureFromPath(path, null); + } + + public static MediaEntityBuilder createScreenCaptureFromBase64String(String base64, String title) { + if (base64 == null || base64.trim().equals("")) + throw new IllegalArgumentException("Base64 string cannot be null or empty"); + if (!base64.startsWith("data:")) + base64 = BASE64_ENCODED + base64; + media.set(ScreenCapture.builder().base64(base64).title(title).build()); + return getInstance(); + } + + public static MediaEntityBuilder createScreenCaptureFromBase64String(String base64) { + 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..de53bae --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/ReactiveSubject.java @@ -0,0 +1,90 @@ +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.Log; +import com.aventstack.extentreports.model.Media; +import com.aventstack.extentreports.model.Report; +import com.aventstack.extentreports.model.Test; +import com.aventstack.extentreports.observer.AttributesObserver; +import com.aventstack.extentreports.observer.ExtentObserver; +import com.aventstack.extentreports.observer.LogObserver; +import com.aventstack.extentreports.observer.MediaObserver; +import com.aventstack.extentreports.observer.ReportObserver; +import com.aventstack.extentreports.observer.TestObserver; +import com.aventstack.extentreports.observer.entity.AttributeEntity; +import com.aventstack.extentreports.observer.entity.LogEntity; +import com.aventstack.extentreports.observer.entity.MediaEntity; +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 logSubject = PublishSubject.create(); + private final PublishSubject mediaSubject = PublishSubject.create(); + private final PublishSubject attribSubject = 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 LogObserver) + logSubject.subscribe(((LogObserver) o).getLogObserver()); + if (o instanceof MediaObserver) + mediaSubject.subscribe(((MediaObserver) o).getMediaObserver()); + if (o instanceof AttributesObserver) + attribSubject.subscribe(((AttributesObserver) o).getAttributesObserver()); + } + } + + protected void onTestCreated(Test test) { + testSubject.onNext(TestEntity.builder().test(test).build()); + } + + protected void onTestRemoved(Test test) { + testSubject.onNext(TestEntity.builder().test(test).removed(true).build()); + } + + protected void onLogCreated(Log log, Test test) { + logSubject.onNext(LogEntity.builder().log(log).test(test).build()); + } + + protected void onAuthorAssigned(Author x, Test test) { + attribSubject.onNext(AttributeEntity.builder().author(x).test(test).build()); + } + + protected void onCategoryAssigned(Category x, Test test) { + attribSubject.onNext(AttributeEntity.builder().category(x).test(test).build()); + } + + protected void onDeviceAssigned(Device x, Test test) { + attribSubject.onNext(AttributeEntity.builder().device(x).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: - * - *

    - *
  1. Test1: PASS
  2. - *
  3. Test2: PASS
  4. - *
  5. Test3: PASS
  6. - *
  7. Test4: SKIP
  8. - *
  9. Test5: SKIP
  10. - *
  11. Test6: FAIL
  12. - *
  13. Test7: PASS
  14. - *
  15. Test8: PASS
  16. - *
  17. Test9: FAIL
  18. - *
  19. Test10: PASS
  20. - *
- * - *

- * Distinct list of contained status: - * - *

    - *
  1. PASS
  2. - *
  3. SKIP
  4. - *
  5. FAIL
  6. - *
- */ - 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..cf3e389 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 max(Status s1, Status s2) { + return s1.getLevel() > s2.getLevel() ? s1 : s2; } - - static void setStatusHierarchy(List statusHierarchy) { - Status.statusHierarchy = statusHierarchy; + + public static Status min(Collection status) { + return status.stream().min(Comparator.comparing(Status::getLevel)).orElse(PASS); } - - 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/append/JsonDeserializer.java b/src/main/java/com/aventstack/extentreports/append/JsonDeserializer.java new file mode 100644 index 0000000..71e1c4d --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/append/JsonDeserializer.java @@ -0,0 +1,33 @@ +package com.aventstack.extentreports.append; + +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.gson.GsonExtentTypeAdapterBuilder; +import com.aventstack.extentreports.model.Test; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + +public class JsonDeserializer { + private File f; + + public JsonDeserializer(File f) { + this.f = f; + } + + public List deserialize() throws IOException { + Gson gson = GsonExtentTypeAdapterBuilder.builder() + .withBddTypeAdapterFactory() + .withScreenCaptureTypeAdapter() + .build(); + 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/append/RawEntityConverter.java b/src/main/java/com/aventstack/extentreports/append/RawEntityConverter.java new file mode 100644 index 0000000..7598b90 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/append/RawEntityConverter.java @@ -0,0 +1,101 @@ +package com.aventstack.extentreports.append; + +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.MediaEntityBuilder; +import com.aventstack.extentreports.model.Log; +import com.aventstack.extentreports.model.Media; +import com.aventstack.extentreports.model.ScreenCapture; +import com.aventstack.extentreports.model.Test; + +public class RawEntityConverter { + private final ExtentReports extent; + + public RawEntityConverter(ExtentReports extent) { + this.extent = extent; + } + + public void convertAndApply(File jsonFile) throws IOException { + if (!jsonFile.exists()) + return; + extent.setReportUsesManualConfiguration(true); + List tests = new JsonDeserializer(jsonFile).deserialize(); + for (Test test : tests) { + try { + if (test.getBddType() == null) { + createDomain(test, extent.createTest(test.getName(), test.getDescription())); + } else { + ExtentTest extentTest = extent.createTest(new GherkinKeyword(test.getBddType().getSimpleName()), + test.getName(), test.getDescription()); + createDomain(test, extentTest); + } + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } + } + + public void createDomain(Test test, ExtentTest extentTest) throws ClassNotFoundException { + extentTest.getModel().setStartTime(test.getStartTime()); + extentTest.getModel().setEndTime(test.getEndTime()); + addMedia(test, extentTest); + + // create events + for (Log log : test.getLogs()) { + if (log.hasException() && log.hasMedia()) + addMedia(log, extentTest, log.getException().getException()); + else if (log.hasException()) + extentTest.log(log.getStatus(), log.getException().getException()); + else if (log.hasMedia()) + addMedia(log, extentTest, null); + else + extentTest.log(log.getStatus(), log.getDetails()); + } + + // assign attributes + test.getAuthorSet().stream().map(x -> x.getName()).forEach(extentTest::assignAuthor); + test.getCategorySet().stream().map(x -> x.getName()).forEach(extentTest::assignCategory); + test.getDeviceSet().stream().map(x -> x.getName()).forEach(extentTest::assignDevice); + + // handle nodes + for (Test node : test.getChildren()) { + ExtentTest extentNode = null; + if (node.getBddType() == null) + extentNode = extentTest.createNode(node.getName(), node.getDescription()); + else + extentNode = extentTest.createNode(new GherkinKeyword(node.getBddType().getSimpleName()), node.getName(), + node.getDescription()); + addMedia(node, extentNode); + createDomain(node, extentNode); + } + } + + private void addMedia(Log log, ExtentTest extentTest, Throwable ex) { + Media m = log.getMedia(); + if (m.getPath() != null) { + extentTest.log(log.getStatus(), ex, + MediaEntityBuilder.createScreenCaptureFromPath(m.getPath()).build()); + } else if (((ScreenCapture) m).getBase64() != null) { + extentTest.log(log.getStatus(), ex, + MediaEntityBuilder.createScreenCaptureFromBase64String(((ScreenCapture) m).getBase64()) + .build()); + } + } + + private void addMedia(Test test, ExtentTest extentTest) { + if (test.getMedia() != null) { + for (Media m : test.getMedia()) { + if (m.getPath() != null) { + extentTest.addScreenCaptureFromPath(m.getPath()); + } else if (m instanceof ScreenCapture) { + extentTest.addScreenCaptureFromBase64String(((ScreenCapture) m).getBase64()); + } + } + } + } +} diff --git a/src/main/java/com/aventstack/extentreports/append/ScreenCaptureTypeAdapter.java b/src/main/java/com/aventstack/extentreports/append/ScreenCaptureTypeAdapter.java new file mode 100644 index 0000000..55e6c1e --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/append/ScreenCaptureTypeAdapter.java @@ -0,0 +1,48 @@ +package com.aventstack.extentreports.append; + +import java.io.IOException; + +import com.aventstack.extentreports.model.Media; +import com.aventstack.extentreports.model.ScreenCapture; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonToken; +import com.google.gson.stream.JsonWriter; + +public class ScreenCaptureTypeAdapter extends TypeAdapter { + + @Override + public void write(JsonWriter out, Media value) throws IOException { + } + + @Override + public Media read(JsonReader reader) throws IOException { + ScreenCapture sc = ScreenCapture.builder().build(); + reader.beginObject(); + String fieldName = null; + int cycle = 0; + while (reader.hasNext()) { + JsonToken token = reader.peek(); + if (token.equals(JsonToken.NAME)) { + fieldName = reader.nextName(); + } + if ("string".equalsIgnoreCase(token.name()) && fieldName.equalsIgnoreCase("path")) { + token = reader.peek(); + sc.setPath(reader.nextString()); + } + if ("string".equalsIgnoreCase(token.name()) && fieldName.equalsIgnoreCase("resolvedPath")) { + token = reader.peek(); + sc.setResolvedPath(reader.nextString()); + } + if ("string".equalsIgnoreCase(token.name()) && fieldName.equalsIgnoreCase("base64")) { + token = reader.peek(); + sc.setBase64(reader.nextString()); + } + if (cycle++ > 10) + return sc; + } + reader.endObject(); + return sc; + } + +} 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/CaseInsensitiveEnumTypeAdapterFactory.java b/src/main/java/com/aventstack/extentreports/config/external/CaseInsensitiveEnumTypeAdapterFactory.java new file mode 100644 index 0000000..bc27424 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/config/external/CaseInsensitiveEnumTypeAdapterFactory.java @@ -0,0 +1,52 @@ +package com.aventstack.extentreports.config.external; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + +import com.google.gson.Gson; +import com.google.gson.TypeAdapter; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.reflect.TypeToken; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonToken; +import com.google.gson.stream.JsonWriter; + +public class CaseInsensitiveEnumTypeAdapterFactory implements TypeAdapterFactory { + @SuppressWarnings("unchecked") + public TypeAdapter create(Gson gson, TypeToken type) { + Class rawType = (Class) type.getRawType(); + if (!rawType.isEnum()) { + return null; + } + + final Map lowercaseToConstant = new HashMap(); + for (T constant : rawType.getEnumConstants()) { + lowercaseToConstant.put(toLowercase(constant), constant); + } + + return new TypeAdapter() { + public void write(JsonWriter out, T value) throws IOException { + if (value == null) { + out.nullValue(); + } else { + out.value(toLowercase(value)); + } + } + + public T read(JsonReader reader) throws IOException { + if (reader.peek() == JsonToken.NULL) { + reader.nextNull(); + return null; + } else { + return lowercaseToConstant.get(toLowercase(reader.nextString())); + } + } + }; + } + + private String toLowercase(Object o) { + return o.toString().toLowerCase(Locale.US); + } +} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/config/external/ConfigLoadable.java b/src/main/java/com/aventstack/extentreports/config/external/ConfigLoadable.java new file mode 100644 index 0000000..9c88256 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/config/external/ConfigLoadable.java @@ -0,0 +1,6 @@ +package com.aventstack.extentreports.config.external; + +@FunctionalInterface +public interface ConfigLoadable { + void apply(); +} 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..1275934 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/config/external/JsonConfigLoader.java @@ -0,0 +1,58 @@ +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 implements ConfigLoadable { + 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..60ec21d --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/config/external/XmlConfigLoader.java @@ -0,0 +1,86 @@ +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.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; +import com.google.gson.Gson; + +public class XmlConfigLoader implements ConfigLoadable { + private static final Logger LOG = Logger.getLogger(XmlConfigLoader.class.getName()); + + private ConfigStore store = new ConfigStore(); + private InputStream stream; + private T instance; + + public XmlConfigLoader(T instance, File f) throws FileNotFoundException { + createStream(f); + this.instance = instance; + } + + private void createStream(File file) { + try { + stream = new FileInputStream(file); + } catch (FileNotFoundException e) { + LOG.log(Level.SEVERE, file.getPath(), e); + } + } + + public void apply() { + ConfigStore store = getConfigStore(); + Gson gson = new Gson(); + String json = gson.toJson(store.getStore()); + JsonConfigLoader jsonLoader = new JsonConfigLoader(instance, json); + jsonLoader.apply(); + } + + public ConfigStore getConfigStore() { + 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/model/And.java b/src/main/java/com/aventstack/extentreports/gherkin/model/And.java index c2a2bff..c81d896 100644 --- a/src/main/java/com/aventstack/extentreports/gherkin/model/And.java +++ b/src/main/java/com/aventstack/extentreports/gherkin/model/And.java @@ -3,17 +3,15 @@ import java.io.Serializable; public class And implements IGherkinFormatterModel, Serializable { + private static final long serialVersionUID = 8543289653944756660L; + private static final String VALUE = "And"; - private static final long serialVersionUID = 8543289653944756660L; - private static final String VALUE = "And"; - - public static String getGherkinName() { - return VALUE; - } - - @Override - public String toString() { - return getGherkinName(); - } + 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 index c6e10d7..24402b4 100644 --- a/src/main/java/com/aventstack/extentreports/gherkin/model/Asterisk.java +++ b/src/main/java/com/aventstack/extentreports/gherkin/model/Asterisk.java @@ -3,17 +3,15 @@ import java.io.Serializable; public class Asterisk implements IGherkinFormatterModel, Serializable { + private static final long serialVersionUID = 7251419811428200133L; + private static final String VALUE = "*"; - private static final long serialVersionUID = 7251419811428200133L; - private static final String VALUE = "*"; - - public static String getGherkinName() { - return VALUE; - } - - @Override - public String toString() { - return getGherkinName(); - } + 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 index 1e42713..7d83736 100644 --- a/src/main/java/com/aventstack/extentreports/gherkin/model/Background.java +++ b/src/main/java/com/aventstack/extentreports/gherkin/model/Background.java @@ -3,17 +3,15 @@ import java.io.Serializable; public class Background implements IGherkinFormatterModel, Serializable { + private static final long serialVersionUID = -955371501488725151L; + private static final String VALUE = "Background"; - private static final long serialVersionUID = -955371501488725151L; - private static final String VALUE = "Background"; - - public static String getGherkinName() { - return VALUE; - } - - @Override - public String toString() { - return getGherkinName(); - } + 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 index 6d88158..acf42e5 100644 --- a/src/main/java/com/aventstack/extentreports/gherkin/model/But.java +++ b/src/main/java/com/aventstack/extentreports/gherkin/model/But.java @@ -3,17 +3,15 @@ import java.io.Serializable; public class But implements IGherkinFormatterModel, Serializable { + private static final long serialVersionUID = 3420514631996827220L; + private static final String VALUE = "But"; - private static final long serialVersionUID = 3420514631996827220L; - private static final String VALUE = "But"; - - public static String getGherkinName() { - return VALUE; - } - - @Override - public String toString() { - return getGherkinName(); - } + 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 index 6475396..63e435e 100644 --- a/src/main/java/com/aventstack/extentreports/gherkin/model/Feature.java +++ b/src/main/java/com/aventstack/extentreports/gherkin/model/Feature.java @@ -3,17 +3,15 @@ import java.io.Serializable; public class Feature implements IGherkinFormatterModel, Serializable { + private static final long serialVersionUID = -4719215211721789414L; + private static final String VALUE = "Feature"; - private static final long serialVersionUID = -4719215211721789414L; - private static final String VALUE = "Feature"; - - public static String getGherkinName() { - return VALUE; - } - - @Override - public String toString() { - return getGherkinName(); - } + public static String getGherkinName() { + return VALUE; + } + @Override + public String toString() { + return getGherkinName(); + } } diff --git a/src/main/java/com/aventstack/extentreports/gherkin/model/GherkinEntity.java b/src/main/java/com/aventstack/extentreports/gherkin/model/GherkinEntity.java new file mode 100644 index 0000000..ef59e65 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/gherkin/model/GherkinEntity.java @@ -0,0 +1,7 @@ +package com.aventstack.extentreports.gherkin.model; + +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/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 index 483b0d2..521f016 100644 --- a/src/main/java/com/aventstack/extentreports/gherkin/model/Given.java +++ b/src/main/java/com/aventstack/extentreports/gherkin/model/Given.java @@ -3,17 +3,15 @@ import java.io.Serializable; public class Given implements IGherkinFormatterModel, Serializable { + private static final long serialVersionUID = 939197985263690070L; + private static final String VALUE = "Given"; - private static final long serialVersionUID = 939197985263690070L; - private static final String VALUE = "Given"; - - public static String getGherkinName() { - return VALUE; - } - - @Override - public String toString() { - return getGherkinName(); - } + 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 index 683f4d1..6404ad3 100644 --- a/src/main/java/com/aventstack/extentreports/gherkin/model/Scenario.java +++ b/src/main/java/com/aventstack/extentreports/gherkin/model/Scenario.java @@ -3,17 +3,15 @@ import java.io.Serializable; public class Scenario implements IGherkinFormatterModel, Serializable { + private static final long serialVersionUID = 7401124129196617280L; + private static final String VALUE = "Scenario"; - private static final long serialVersionUID = 7401124129196617280L; - private static final String VALUE = "Scenario"; - - public static String getGherkinName() { - return VALUE; - } - - @Override - public String toString() { - return getGherkinName(); - } + 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 index 6b84733..9e7bca3 100644 --- a/src/main/java/com/aventstack/extentreports/gherkin/model/ScenarioOutline.java +++ b/src/main/java/com/aventstack/extentreports/gherkin/model/ScenarioOutline.java @@ -3,17 +3,15 @@ import java.io.Serializable; public class ScenarioOutline implements IGherkinFormatterModel, Serializable { + private static final long serialVersionUID = -2058398543903906031L; + private static final String VALUE = "Scenario Outline"; - 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(); - } + 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 index 2ad2bc7..5297125 100644 --- a/src/main/java/com/aventstack/extentreports/gherkin/model/Then.java +++ b/src/main/java/com/aventstack/extentreports/gherkin/model/Then.java @@ -3,17 +3,15 @@ import java.io.Serializable; public class Then implements IGherkinFormatterModel, Serializable { + private static final long serialVersionUID = 2493591502473169772L; + private static final String VALUE = "Then"; - private static final long serialVersionUID = 2493591502473169772L; - private static final String VALUE = "Then"; - - public static String getGherkinName() { - return VALUE; - } - - @Override - public String toString() { - return getGherkinName(); - } + 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 index d9460db..28934e4 100644 --- a/src/main/java/com/aventstack/extentreports/gherkin/model/When.java +++ b/src/main/java/com/aventstack/extentreports/gherkin/model/When.java @@ -3,17 +3,15 @@ import java.io.Serializable; public class When implements IGherkinFormatterModel, Serializable { + private static final long serialVersionUID = 8337259741948416898L; + private static final String VALUE = "When"; - private static final long serialVersionUID = 8337259741948416898L; - private static final String VALUE = "When"; - - public static String getGherkinName() { - return VALUE; - } - - @Override - public String toString() { - return getGherkinName(); - } + public static String getGherkinName() { + return VALUE; + } + @Override + public String toString() { + return getGherkinName(); + } } diff --git a/src/main/java/com/aventstack/extentreports/gson/BddTypeAdapter.java b/src/main/java/com/aventstack/extentreports/gson/BddTypeAdapter.java new file mode 100644 index 0000000..78e161f --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/gson/BddTypeAdapter.java @@ -0,0 +1,48 @@ +package com.aventstack.extentreports.gson; + +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; + +import com.aventstack.extentreports.gherkin.model.IGherkinFormatterModel; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonToken; +import com.google.gson.stream.JsonWriter; + +public class BddTypeAdapter extends TypeAdapter> { + private static final Logger LOG = Logger.getLogger(BddTypeAdapter.class.getName()); + + @SuppressWarnings("unchecked") + @Override + public Class read(final JsonReader reader) throws IOException { + int cycle = 0; + while (reader.hasNext()) { + JsonToken token = reader.peek(); + if ("string".equalsIgnoreCase(token.name())) { + token = reader.peek(); + String s = reader.nextString(); + if (s != null && !s.isEmpty()) { + try { + return (Class) Class.forName(s); + } catch (ClassNotFoundException e) { + LOG.log(Level.SEVERE, "Failed to convert Gherkin type", e); + } + } + } + if (cycle++ > 10) + return null; + } + return null; + } + + @Override + public void write(final JsonWriter out, final Class value) throws IOException { + if (value == null) { + out.nullValue(); + return; + } + out.value(value.getName()); + } + +} diff --git a/src/main/java/com/aventstack/extentreports/gson/BddTypeAdapterFactory.java b/src/main/java/com/aventstack/extentreports/gson/BddTypeAdapterFactory.java new file mode 100644 index 0000000..441ccc2 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/gson/BddTypeAdapterFactory.java @@ -0,0 +1,16 @@ +package com.aventstack.extentreports.gson; + +import com.google.gson.Gson; +import com.google.gson.TypeAdapter; +import com.google.gson.TypeAdapterFactory; +import com.google.gson.reflect.TypeToken; + +public class BddTypeAdapterFactory implements TypeAdapterFactory { + @SuppressWarnings("unchecked") + @Override + public TypeAdapter create(Gson gson, TypeToken type) { + if (!Class.class.isAssignableFrom(type.getRawType())) + return null; + return (TypeAdapter) new BddTypeAdapter(); + } +} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/gson/GsonExtentTypeAdapterBuilder.java b/src/main/java/com/aventstack/extentreports/gson/GsonExtentTypeAdapterBuilder.java new file mode 100644 index 0000000..5c873d3 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/gson/GsonExtentTypeAdapterBuilder.java @@ -0,0 +1,30 @@ +package com.aventstack.extentreports.gson; + +import com.aventstack.extentreports.append.ScreenCaptureTypeAdapter; +import com.aventstack.extentreports.model.Media; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +public class GsonExtentTypeAdapterBuilder { + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + GsonBuilder builder = new GsonBuilder(); + + public Builder withBddTypeAdapterFactory() { + builder.registerTypeAdapterFactory(new BddTypeAdapterFactory()); + return this; + } + + public Builder withScreenCaptureTypeAdapter() { + builder.registerTypeAdapter(Media.class, new ScreenCaptureTypeAdapter()); + return this; + } + + public Gson build() { + return builder.create(); + } + } +} 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/markuputils/CodeBlock.java b/src/main/java/com/aventstack/extentreports/markuputils/CodeBlock.java index d378816..c7d0787 100644 --- a/src/main/java/com/aventstack/extentreports/markuputils/CodeBlock.java +++ b/src/main/java/com/aventstack/extentreports/markuputils/CodeBlock.java @@ -5,61 +5,64 @@ 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[] codeArray; + 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 (jsonObject == null && codeArray == null) + return ""; + if (jsonObject != null) + codeArray = new String[]{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", codeArray); + 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(""); + 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..5cc1618 100644 --- a/src/main/java/com/aventstack/extentreports/markuputils/MarkupHelper.java +++ b/src/main/java/com/aventstack/extentreports/markuputils/MarkupHelper.java @@ -2,29 +2,96 @@ 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) { + String[] a = code == null ? null : new String[]{code}; + return CodeBlock.builder().codeArray(a).build(); + } + + public static Markup createCodeBlock(String code1, String code2) { + return CodeBlock.builder().codeArray(new String[]{code1, code2}).build(); + } + + public static Markup createCodeBlock(String code1, String code2, String code3) { + return CodeBlock.builder().codeArray(new String[]{code1, code2, code3}).build(); + } + + public static Markup createCodeBlock(String code1, String code2, String code3, String code4) { + return CodeBlock.builder().codeArray(new String[]{code1, code2, code3, code4}).build(); + } + + public static Markup createCodeBlock(String code, CodeLanguage lang) { + return CodeBlock.builder().codeArray(new String[]{code}).lang(lang).build(); + } + + public static Markup createCodeBlocks(String[] code) { + return CodeBlock.builder().codeArray(code).build(); + } + + public static Markup createJsonCodeBlock(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..83e3aac 100644 --- a/src/main/java/com/aventstack/extentreports/markuputils/Table.java +++ b/src/main/java/com/aventstack/extentreports/markuputils/Table.java @@ -1,23 +1,57 @@ package com.aventstack.extentreports.markuputils; -class Table implements Markup { +import java.lang.reflect.Array; +import java.lang.reflect.Field; +import java.util.ArrayList; +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(""); } sb.append(""); @@ -26,4 +60,104 @@ 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("
    " + data[row][col] + "
    "); + 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, ""); + } else if (object.getClass().isArray()) { + appendArrayItems(object, list, sb2, columnRowCount); + } else if (!fieldList.isEmpty()) { + sb.append(""); + fieldList.forEach(x -> sb.append("")); + 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) + ""); + columnRowCount.set(columnRowCount.size() - 1, 1); + } + columnRowCount.add(0); + } + } else { + list.set(0, ""); + } + list.forEach(x -> sb.append("" + x + "")); + sb.append(""); + sb.append("
    " + object.toString() + "
    " + x.getName() + "
    " + f.get(object).toString() + "" + object.toString() + "
    "); + 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) { + Object[] array = toArray(object); + List obj = Arrays.asList(array); + appendListItems(obj, list, sb, columnRowCount); + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + private Object[] toArray(Object array) { + Class clz = array.getClass().getComponentType(); + if (clz.isPrimitive()) { + int length = Array.getLength(array); + List list = new ArrayList(length); + for (int i = 0; i < length; i++) + list.add(Array.get(array, i)); + return list.toArray(); + } + return (Object[]) array; + } } 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 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 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/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..04e80d0 100644 --- a/src/main/java/com/aventstack/extentreports/model/Log.java +++ b/src/main/java/com/aventstack/extentreports/model/Log.java @@ -3,96 +3,49 @@ import java.io.Serializable; import java.util.Calendar; import java.util.Date; +import java.util.HashMap; +import java.util.Map; -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, MetaDataStorable { + private static final long serialVersionUID = -3690764012141784427L; + + @Builder.Default + private Date timestamp = Calendar.getInstance().getTime(); + @Builder.Default + private Status status = Status.PASS; + private String details; + @Builder.Default + private Integer seq = -1; + private final Map infoMap = new HashMap<>(); + private Media media; + private ExceptionInfo exception; + + public final boolean hasException() { + return exception != null; + } + + public final void addMedia(Media media) { + if (media != null && ((media.getPath() != null || media.getResolvedPath() != null) + || media instanceof ScreenCapture && ((ScreenCapture) media).getBase64() != null)) + this.media = media; + } + + public final boolean hasMedia() { + return media != null; + } } diff --git a/src/main/java/com/aventstack/extentreports/model/Media.java b/src/main/java/com/aventstack/extentreports/model/Media.java index b5343c5..1bdfeb8 100644 --- a/src/main/java/com/aventstack/extentreports/model/Media.java +++ b/src/main/java/com/aventstack/extentreports/model/Media.java @@ -1,79 +1,20 @@ 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 class Media implements Serializable, BaseEntity, MetaDataStorable { + private static final long serialVersionUID = 5428859443090457608L; + private String path; + private String title; + private String resolvedPath; + private transient Map infoMap; } diff --git a/src/main/java/com/aventstack/extentreports/model/MetaDataStorable.java b/src/main/java/com/aventstack/extentreports/model/MetaDataStorable.java new file mode 100644 index 0000000..1cbf064 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/model/MetaDataStorable.java @@ -0,0 +1,8 @@ +package com.aventstack.extentreports.model; + +import java.util.Map; + +@FunctionalInterface +public interface MetaDataStorable { + Map getInfoMap(); +} 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..dcb9ef4 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/model/Report.java @@ -0,0 +1,91 @@ +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 java.util.stream.Collectors; + +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 transient ReportStats stats = new ReportStats(); + private final List testList = Collections.synchronizedList(new ArrayList<>()); + private final transient NamedAttributeContextManager authorCtx = new NamedAttributeContextManager<>(); + private final transient NamedAttributeContextManager categoryCtx = new NamedAttributeContextManager<>(); + private final transient NamedAttributeContextManager deviceCtx = new NamedAttributeContextManager<>(); + private final transient NamedAttributeContextManager exceptionInfoCtx = new NamedAttributeContextManager<>(); + private final List logs = Collections.synchronizedList(new ArrayList<>()); + private final List systemEnvInfo = new ArrayList<>(); + + public final void refresh() { + authorCtx.getSet().forEach(x -> x.refresh()); + categoryCtx.getSet().forEach(x -> x.refresh()); + deviceCtx.getSet().forEach(x -> x.refresh()); + stats.update(testList); + synchronized (this) { + setEndTime(Calendar.getInstance().getTime()); + } + } + + public final void applyOverrideConf() { + Date min = testList.stream() + .map(t -> t.getStartTime()) + .min(Date::compareTo) + .get(); + Date max = testList.stream() + .map(t -> t.getEndTime()) + .max(Date::compareTo) + .get(); + synchronized (this) { + setStartTime(min); + setEndTime(max); + } + } + + public final boolean isBDD() { + return !testList.isEmpty() && testList.stream().allMatch(Test::isBDD); + } + + public final boolean anyTestHasStatus(Status status) { + return testList.stream() + .anyMatch(x -> x.getStatus() == status); + } + + public final long timeTaken() { + return endTime.getTime() - startTime.getTime(); + } + + public final Status getStatus() { + List list = testList + .stream() + .map(x -> x.getStatus()) + .collect(Collectors.toList()); + Status s = Status.max(list); + if (s == Status.SKIP && anyTestHasStatus(Status.PASS)) + s = Status.PASS; + return s; + } +} 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..521ce04 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/model/ReportStats.java @@ -0,0 +1,101 @@ +package com.aventstack.extentreports.model; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; + +import com.aventstack.extentreports.AnalysisStrategy; +import com.aventstack.extentreports.Status; +import com.aventstack.extentreports.gherkin.model.Scenario; +import com.aventstack.extentreports.gherkin.model.ScenarioOutline; + +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<>(); + + public final void update(final List testList) { + reset(); + if (testList == null || testList.isEmpty()) + return; + + update(testList, parent, parentPercentage); + + // level 1, for BDD, this would also include Scenario and excludes + // ScenarioOutline + List children = testList.stream() + .flatMap(x -> x.getChildren().stream()) + .filter(x -> x.getBddType() != ScenarioOutline.class) + .collect(Collectors.toList()); + List scenarios = testList.stream() + .flatMap(x -> x.getChildren().stream()) + .flatMap(x -> x.getChildren().stream()) + .filter(x -> x.getBddType() == Scenario.class) + .collect(Collectors.toList()); + children.addAll(scenarios); + update(children, child, childPercentage); + + // level 2, for BDD, this only includes Steps + List grandChildren = children.stream() + .flatMap(x -> x.getChildren().stream()) + .filter(x -> x.getBddType() != Scenario.class) + .collect(Collectors.toList()); + update(grandChildren, grandchild, grandchildPercentage); + + List logs = testList.stream().flatMap(x -> x.getLogs().stream()).collect(Collectors.toList()); + logs.addAll(children.stream().flatMap(x -> x.getLogs().stream()).collect(Collectors.toList())); + logs.addAll(grandChildren.stream().flatMap(x -> x.getLogs().stream()).collect(Collectors.toList())); + update(logs, log, logPercentage); + } + + private final void update(final List list, final Map countMap, + final Map percentageMap) { + if (list == null) + return; + Map map = list.stream().collect( + Collectors.groupingBy(RunResult::getStatus, Collectors.counting())); + Arrays.asList(Status.values()).forEach(x -> map.putIfAbsent(x, 0L)); + countMap.putAll(map); + if (list.isEmpty()) { + percentageMap.putAll( + map.entrySet().stream() + .collect(Collectors.toMap(e -> e.getKey(), e -> Float.valueOf(e.getValue())))); + return; + } + Map pctMap = map.entrySet().stream() + .collect(Collectors.toMap(e -> e.getKey(), + e -> Float.valueOf(e.getValue() * 100 / list.size()))); + percentageMap.putAll(pctMap); + } + + public final void reset() { + List list = new ArrayList<>(); + update(list, parent, parentPercentage); + update(list, child, childPercentage); + update(list, grandchild, grandchildPercentage); + update(list, log, logPercentage); + } + + public final long sumStat(final Map stat) { + return stat.values().stream().mapToLong(Long::longValue).sum(); + } +} 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..5f441f0 100644 --- a/src/main/java/com/aventstack/extentreports/model/ScreenCapture.java +++ b/src/main/java/com/aventstack/extentreports/model/ScreenCapture.java @@ -1,31 +1,22 @@ package com.aventstack.extentreports.model; -public class ScreenCapture extends Media { +import java.io.Serializable; +import java.util.HashMap; - 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, new HashMap()); + 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..d8d6146 100644 --- a/src/main/java/com/aventstack/extentreports/model/Test.java +++ b/src/main/java/com/aventstack/extentreports/model/Test.java @@ -1,384 +1,213 @@ 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.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +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 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 getBddType() { - return bddType; - } - - public void setBddType(Class 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.model.ScenarioOutline; + +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, MetaDataStorable { + private static final long serialVersionUID = -4896520724677957845L; + private static final AtomicInteger atomicInt = new AtomicInteger(0); + + private final transient int id = atomicInt.incrementAndGet(); + private final transient StatusDeterminator determinator = new StatusDeterminator(); + @Builder.Default + private boolean useNaturalConf = true; + @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 transient Test parent; + private Class bddType; + private final Map infoMap = new HashMap<>(); + 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<>()); + + public final void addChild(Test child) { + if (child == null) + throw new IllegalArgumentException("Node must not be null"); + child.setLevel(level + 1); + child.setParent(this); + child.setLeaf(true); + isLeaf = false; + end(child.getStatus()); + children.add(child); + } + + private void end(Status evtStatus) { + setStatus(Status.max(status, evtStatus)); + if (useNaturalConf) + propogateTime(); + } + + private void propogateTime() { + setEndTime(Calendar.getInstance().getTime()); + if (parent != null) + parent.propogateTime(); + } + + public final void addLog(Log log) { + addLog(log, logs); + } + + public final void addGeneratedLog(Log log) { + addLog(log, generatedLog); + } + + private final void addLog(Log log, List list) { + if (log == null) + throw new IllegalArgumentException("Log must not be null"); + log.setSeq(list.size()); + list.add(log); + end(log.getStatus()); + updateResult(); + } + + public final boolean isBDD() { + return getBddType() != null; + } + + public final boolean hasLog() { + return !logs.isEmpty(); + } + + public final boolean hasAnyLog() { + return !logs.isEmpty() || !generatedLog.isEmpty(); + } + + public final boolean hasChildren() { + return !children.isEmpty(); + } + + public final boolean hasAttributes() { + return hasAuthor() || hasCategory() || hasDevice(); + } + + public final boolean hasAuthor() { + return !authorSet.isEmpty(); + } + + public final boolean hasCategory() { + return !categorySet.isEmpty(); + } + + public final boolean hasDevice() { + return !deviceSet.isEmpty(); + } + + public final boolean hasException() { + return !exceptions.isEmpty(); + } + + public final String getFullName() { + Test test = this; + StringBuilder sb = new StringBuilder(test.getName()); + while (test.getParent() != null) { + test = test.getParent(); + if (test.getBddType() == null || test.getBddType() != ScenarioOutline.class) + sb.insert(0, test.getName() + "."); + } + return sb.toString(); + } + + public final void addMedia(Media m) { + if (m != null && (m.getPath() != null || m.getResolvedPath() != null + || ((ScreenCapture) m).getBase64() != null)) + media.add(m); + end(status); + } + + public final boolean hasScreenCapture() { + return !media.isEmpty() && media.stream().anyMatch(x -> x instanceof ScreenCapture); + } + + public final long timeTaken() { + return endTime.getTime() - startTime.getTime(); + } + + public final Test getAncestor() { + Test test = this; + while (test.getParent() != null) + test = test.getParent(); + return test; + } + + public final void updateResult() { + determinator.computeTestStatus(); + } + + private class StatusDeterminator { + public void computeTestStatus() { + List leafList = getLeafList(Test.this); + computeStatus(leafList); + } + + private List getLeafList(Test test) { + List testList = new ArrayList<>(); + if (test.isLeaf()) + testList.add(test); + else + for (Test t : test.getChildren()) + if (t.isLeaf()) + testList.add(t); + else + testList.addAll(getLeafList(t)); + return testList; + } + + private void computeStatus(List testList) { + testList.forEach(this::computeStatus); + } + + private void computeStatus(Test t) { + Set set = new HashSet<>(); + Iterator iter = new ArrayList<>(t.getLogs()).iterator(); + while (iter.hasNext()) + set.add(iter.next().getStatus()); + set.add(t.getStatus()); + t.setStatus(Status.max(set)); + if (t.getParent() != null) { + t.getParent().setStatus(Status.max(t.getStatus(), t.getParent().getStatus())); + computeStatus(t.getParent()); + } + } + } } 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..7cead19 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/model/context/NamedAttributeContext.java @@ -0,0 +1,58 @@ +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) { + if (test.getStatus() == Status.PASS) + passed++; + else if (test.getStatus() == Status.FAIL) + failed++; + else if (test.getStatus() == Status.SKIP) + skipped++; + else + others++; + } + + 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(); + mgr.getSet().stream() + .forEach(x -> newmgr.addContext(x.getAttr(), x.getTestList())); + List unwantedList = newmgr.getSet().stream() + .flatMap(x -> x.getTestList().stream()) + .filter(x -> !status.contains(x.getStatus())) + .collect(Collectors.toList()); + unwantedList.forEach(newmgr::removeTest); + return newmgr.getSet(); + } +} diff --git a/src/main/java/com/aventstack/extentreports/model/context/filter/TestAttributeContextFilters.java b/src/main/java/com/aventstack/extentreports/model/context/filter/TestAttributeContextFilters.java deleted file mode 100644 index 87d15a8..0000000 --- a/src/main/java/com/aventstack/extentreports/model/context/filter/TestAttributeContextFilters.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.aventstack.extentreports.model.context.filter; - -import com.aventstack.extentreports.model.Test; - -public class TestAttributeContextFilters { - - public static boolean testHasStatusIncrEligibility(Test test) { - return test.isBehaviorDrivenType() && test.getBehaviorDrivenTypeName().equalsIgnoreCase("feature") ? false - : true; - } - -} diff --git a/src/main/java/com/aventstack/extentreports/model/context/helpers/TestRemover.java b/src/main/java/com/aventstack/extentreports/model/context/helpers/TestRemover.java deleted file mode 100644 index b9837d1..0000000 --- a/src/main/java/com/aventstack/extentreports/model/context/helpers/TestRemover.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.aventstack.extentreports.model.context.helpers; - -import java.util.List; -import java.util.stream.Collectors; - -import com.aventstack.extentreports.model.Test; - -public class TestRemover { - - /** - * Helper for removing test recursively. This flag determines when to break out - * of recursion - */ - private static boolean removed = false; - - private TestRemover() { - } - - /** - * Remove a test using its unique ID from a list - * - * @param testList a list of {@link Test} - * @param test {@link Test} to be removed - */ - public static void remove(List testList, Test test) { - removed = false; - findAndRemoveTest(testList, test); - testList.forEach(Test::end); - } - - /** - * Recursively traverses all tests, nodes upto the last leaf to find and remove - * the specified test - * - * @param list a list of {@link Test} - * @param test {@link Test} to be removed - */ - private synchronized static void findAndRemoveTest(List list, Test test) { - List filteredTestList = list.stream().filter(x -> x.getId() == test.getId()).collect(Collectors.toList()); - - if (filteredTestList.size() == 1) { - removeTest(list, filteredTestList.get(0)); - removed = true; - return; - } - - for (Test t : list) { - if (removed) { - return; - } - findAndRemoveTest(t.getNodeContext().getAll(), test); - } - } - - /** - * Removes the test from a given list of tests - * - * @param list a list of {@link Test} - * @param test {@link Test} to be removed - */ - private static void removeTest(List list, Test test) { - list.remove(test); - } - -} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/model/service/EntityService.java b/src/main/java/com/aventstack/extentreports/model/service/EntityService.java new file mode 100644 index 0000000..a908c00 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/model/service/EntityService.java @@ -0,0 +1,4 @@ +package com.aventstack.extentreports.model.service; + +public interface EntityService { +} diff --git a/src/main/java/com/aventstack/extentreports/model/service/ExceptionInfoService.java b/src/main/java/com/aventstack/extentreports/model/service/ExceptionInfoService.java new file mode 100644 index 0000000..eb87b96 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/model/service/ExceptionInfoService.java @@ -0,0 +1,17 @@ +package com.aventstack.extentreports.model.service; + +import com.aventstack.extentreports.model.ExceptionInfo; +import com.aventstack.extentreports.model.service.util.ExceptionUtil; + +public class ExceptionInfoService { + public static ExceptionInfo createExceptionInfo(Throwable t) { + if (t == null) + return null; + ExceptionInfo exceptionInfo = ExceptionInfo.builder() + .exception(t) + .name(ExceptionUtil.getExceptionHeadline(t)) + .stackTrace(ExceptionUtil.getStackTrace(t)) + .build(); + return exceptionInfo; + } +} diff --git a/src/main/java/com/aventstack/extentreports/model/service/LogService.java b/src/main/java/com/aventstack/extentreports/model/service/LogService.java deleted file mode 100644 index daf9f53..0000000 --- a/src/main/java/com/aventstack/extentreports/model/service/LogService.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.aventstack.extentreports.model.service; - -import com.aventstack.extentreports.model.Log; - -public class LogService { - - public static Boolean logHasScreenCapture(Log log) { - return !log.getScreenCaptureContext().isEmpty(); - } - -} diff --git a/src/main/java/com/aventstack/extentreports/model/service/MediaService.java b/src/main/java/com/aventstack/extentreports/model/service/MediaService.java new file mode 100644 index 0000000..155a8b3 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/model/service/MediaService.java @@ -0,0 +1,41 @@ +package com.aventstack.extentreports.model.service; + +import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; + +import com.aventstack.extentreports.model.Media; +import com.aventstack.extentreports.model.ScreenCapture; + +public class MediaService { + public static void tryResolveMediaPath(Media media, String[] knownPath) { + if (knownPath == null || (media instanceof ScreenCapture && ((ScreenCapture) media).getBase64() != null)) + return; + String loc = media.getPath(); + File f = new File(loc); + if (!new File(loc).exists()) { + for (String p : knownPath) { + Path path = Paths.get(p, loc); + if (path.toFile().exists()) { + media.setResolvedPath(path.toFile().getAbsolutePath()); + break; + } + path = Paths.get(p, f.getName()); + if (path.toFile().exists()) { + media.setResolvedPath(path.toFile().getAbsolutePath()); + break; + } + } + } + } + + public static boolean isBase64(Media m) { + return m instanceof ScreenCapture && ((ScreenCapture) m).getBase64() != null; + } + + public static String getBase64(Media m) { + if (isBase64(m)) + return ((ScreenCapture) m).getBase64(); + return null; + } +} diff --git a/src/main/java/com/aventstack/extentreports/model/service/ReportFilterService.java b/src/main/java/com/aventstack/extentreports/model/service/ReportFilterService.java new file mode 100644 index 0000000..5e8bed4 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/model/service/ReportFilterService.java @@ -0,0 +1,40 @@ +package com.aventstack.extentreports.model.service; + +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import com.aventstack.extentreports.Status; +import com.aventstack.extentreports.model.Author; +import com.aventstack.extentreports.model.Category; +import com.aventstack.extentreports.model.Device; +import com.aventstack.extentreports.model.Report; +import com.aventstack.extentreports.model.Test; +import com.aventstack.extentreports.model.context.NamedAttributeContext; +import com.aventstack.extentreports.model.context.filter.NamedAttributeTestContextFilter; + +public class ReportFilterService { + public static Report filter(Report report, Set statusList) { + if (report.getTestList().isEmpty()) + return report; + Report filtered = Report.builder().build(); + filtered.getLogs().addAll(report.getLogs()); + filtered.setStartTime(report.getStartTime()); + filtered.setEndTime(report.getEndTime()); + List list = report.getTestList().stream() + .filter(x -> statusList.contains(x.getStatus())) + .collect(Collectors.toList()); + list.forEach(filtered.getTestList()::add); + filtered.getStats().update(list); + Set> authorCtx = new NamedAttributeTestContextFilter() + .filter(report.getAuthorCtx(), statusList); + authorCtx.stream().forEach(x -> filtered.getAuthorCtx().addContext(x.getAttr(), x.getTestList())); + Set> categoryCtx = new NamedAttributeTestContextFilter() + .filter(report.getCategoryCtx(), statusList); + categoryCtx.stream().forEach(x -> filtered.getCategoryCtx().addContext(x.getAttr(), x.getTestList())); + Set> deviceCtx = new NamedAttributeTestContextFilter() + .filter(report.getDeviceCtx(), statusList); + deviceCtx.stream().forEach(x -> filtered.getDeviceCtx().addContext(x.getAttr(), x.getTestList())); + return filtered; + } +} diff --git a/src/main/java/com/aventstack/extentreports/model/service/ScreenCaptureService.java b/src/main/java/com/aventstack/extentreports/model/service/ScreenCaptureService.java deleted file mode 100644 index bc3c0d3..0000000 --- a/src/main/java/com/aventstack/extentreports/model/service/ScreenCaptureService.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.aventstack.extentreports.model.service; - -import java.io.File; -import java.nio.file.Path; -import java.nio.file.Paths; - -import com.aventstack.extentreports.model.ScreenCapture; -import com.aventstack.extentreports.utils.FileUtil; - -public class ScreenCaptureService { - - public static void resolvePath(ScreenCapture capture, String[] paths) { - if (paths == null || capture.isBase64()) { - return; - } - String capturePath = capture.getPath(); - String captureFileName = new File(capturePath).getName(); - if (!FileUtil.fileExists(capturePath)) { - for (String p : paths) { - Path path = Paths.get(p, capturePath); - if (path.toFile().exists()) { - capturePath = path.toFile().getAbsolutePath(); - break; - } - path = Paths.get(p, captureFileName); - if (path.toFile().exists()) { - capturePath = path.toFile().getAbsolutePath(); - break; - } - } - } - capture.setResolvedPath(capturePath); - } - -} diff --git a/src/main/java/com/aventstack/extentreports/model/service/TestService.java b/src/main/java/com/aventstack/extentreports/model/service/TestService.java index 24a3abb..dd0c229 100644 --- a/src/main/java/com/aventstack/extentreports/model/service/TestService.java +++ b/src/main/java/com/aventstack/extentreports/model/service/TestService.java @@ -1,98 +1,75 @@ package com.aventstack.extentreports.model.service; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; import com.aventstack.extentreports.gherkin.model.IGherkinFormatterModel; -import com.aventstack.extentreports.gherkin.model.ScenarioOutline; +import com.aventstack.extentreports.model.ExceptionInfo; +import com.aventstack.extentreports.model.Log; import com.aventstack.extentreports.model.Test; public class TestService { - - public static Boolean testHasAttributes(Test test) { - return testHasAuthor(test) || testHasCategory(test) || testHasDevice(test); - } - - public static Boolean testHasAuthor(Test test) { - return test != null && !test.getAuthorContext().isEmpty(); - } - - public static Boolean testHasCategory(Test test) { - return test != null && !test.getCategoryContext().isEmpty(); - } - - public static Boolean testHasDevice(Test test) { - return test != null && !test.getDeviceContext().isEmpty(); - } - - public static Boolean testHasException(Test test) { - return test != null && !test.getExceptionInfoContext().isEmpty(); - } - - public static Boolean testHasChildren(Test test) { - return test != null && !test.getNodeContext().isEmpty(); - } - - public static Boolean testHasLog(Test test) { - return test != null && !test.getLogContext().isEmpty(); - } - - public static Boolean testHasScreenCapture(Test test) { - return test != null && !test.getScreenCaptureContext().isEmpty(); - } - - public static Boolean testHasScreenCapture(Test test, Boolean deep) { - if (deep) { - Boolean hasScreenCapture = !test.getScreenCaptureContext().isEmpty() - || test.getLogContext().getAll().stream().anyMatch(LogService::logHasScreenCapture); - if (!hasScreenCapture) { - hasScreenCapture = test.getNodeContext().getAll().stream().anyMatch(x -> testHasScreenCapture(x, deep)); - } - return hasScreenCapture; - } - return testHasScreenCapture(test); - } - - public static Boolean isTestBehaviorDriven(Test test) { - return test != null && test.getBddType() != null; - } - - public static String getBehaviorDrivenTypeName(Class bddType) - throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, - InvocationTargetException { - Method method = bddType.getMethod("getGherkinName"); - Object o = method.invoke(null, (Object[]) null); - return o.toString(); - } - - public static String getBehaviorDrivenTypeName(Test test) throws NoSuchMethodException, SecurityException, - IllegalAccessException, IllegalArgumentException, InvocationTargetException { - return getBehaviorDrivenTypeName(test.getBddType()); - } - - public static String getRunDuration(Test test) { - long diff = test.getEndTime().getTime() - test.getStartTime().getTime(); - long secs = diff / 1000; - long millis = diff % 1000; - long mins = secs / 60; - secs = secs % 60; - long hours = mins / 60; - mins = mins % 60; - return hours + "h " + mins + "m " + secs + "s+" + millis + "ms"; - } - - public static Long getRunDurationMillis(Test test) { - return test.getEndTime().getTime() - test.getStartTime().getTime(); - } - - public static String getHierarchicalName(Test test) { - StringBuilder sb = new StringBuilder(test.getName()); - while (test.getParent() != null) { - test = test.getParent(); - if (!test.isBehaviorDrivenType() || test.getBddType() != ScenarioOutline.class) - sb.insert(0, test.getName() + "."); - } - return sb.toString(); - } - + public static boolean deleteTest(List list, Test test) { + boolean removed = list.removeIf(x -> x.getId() == test.getId()); + if (!removed) + list.forEach(x -> deleteTest(x.getChildren(), test)); + return removed; + } + + public static Optional findTest(List list, String name) { + Optional test = list.stream().filter(x -> x.getName().equals(name)).findFirst(); + if (!test.isPresent()) + for (Test t : list) + return findTest(t.getChildren(), name); + return test; + } + + public static Boolean testHasScreenCapture(Test test, Boolean deep) { + if (deep) { + Boolean hasScreenCapture = !test.getMedia().isEmpty() + || test.getLogs().stream().anyMatch(Log::hasMedia); + if (!hasScreenCapture) + hasScreenCapture = test.getChildren().stream().anyMatch(x -> testHasScreenCapture(x, deep)); + return hasScreenCapture; + } + return test.hasScreenCapture(); + } + + public static List aggregateExceptions(List testList) { + List list = new ArrayList<>(); + for (Test test : testList) { + list.addAll(aggregateExceptions(test)); + if (!test.getChildren().isEmpty()) + aggregateExceptions(test.getChildren()); + } + return list; + } + + public static List aggregateExceptions(Test test) { + return test.getLogs().stream() + .filter(x -> x.getException() != null) + .map(x -> x.getException()) + .collect(Collectors.toList()); + } + + public static Test createTest(Class type, String name, String description) { + if (name == null || name.isEmpty()) + throw new IllegalArgumentException("Test name cannot be null or empty"); + return Test.builder() + .bddType(type) + .name(name) + .description(description) + .endTime(Calendar.getInstance().getTime()).build(); + } + + public static Test createTest(String name, String description) { + return createTest(null, name, description); + } + + public static Test createTest(String name) { + return createTest(name, null); + } } diff --git a/src/main/java/com/aventstack/extentreports/model/service/util/ExceptionUtil.java b/src/main/java/com/aventstack/extentreports/model/service/util/ExceptionUtil.java new file mode 100644 index 0000000..f698d24 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/model/service/util/ExceptionUtil.java @@ -0,0 +1,30 @@ +package com.aventstack.extentreports.model.service.util; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class ExceptionUtil { + + private ExceptionUtil() { + } + + public static String getStackTrace(Throwable t) { + if (t == null) + return null; + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + t.printStackTrace(pw); + return sw.toString(); + } + + public static String getExceptionHeadline(Throwable t) { + Pattern pattern = Pattern.compile("([\\w\\.]+)(:.*)?"); + String stackTrace = getStackTrace(t); + Matcher matcher = pattern.matcher(stackTrace); + if (matcher.find()) + return matcher.group(1); + return null; + } +} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/observable/ObservableList.java b/src/main/java/com/aventstack/extentreports/observable/ObservableList.java new file mode 100644 index 0000000..fa9fa6d --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/observable/ObservableList.java @@ -0,0 +1,35 @@ +package com.aventstack.extentreports.observable; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import com.aventstack.extentreports.model.BaseEntity; + +import io.reactivex.rxjava3.core.Observable; +import io.reactivex.rxjava3.core.Observer; +import io.reactivex.rxjava3.subjects.PublishSubject; +import lombok.Getter; + +@Getter +public class ObservableList { + private final List list = Collections.synchronizedList(new ArrayList<>()); + private final PublishSubject observable = PublishSubject.create(); + + public void subscribe(Observer observer) { + observable.subscribe(observer); + } + + public void add(T value) { + list.add(value); + observable.onNext(value); + } + + public void remove(T value) { + + } + + public Observable getObservable() { + return observable; + } +} diff --git a/src/main/java/com/aventstack/extentreports/observer/AttributesObserver.java b/src/main/java/com/aventstack/extentreports/observer/AttributesObserver.java new file mode 100644 index 0000000..7dd8846 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/observer/AttributesObserver.java @@ -0,0 +1,10 @@ +package com.aventstack.extentreports.observer; + +import com.aventstack.extentreports.observer.entity.AttributeEntity; +import com.aventstack.extentreports.observer.entity.ObservedEntity; + +import io.reactivex.rxjava3.core.Observer; + +public interface AttributesObserver extends ExtentObserver { + Observer getAttributesObserver(); +} diff --git a/src/main/java/com/aventstack/extentreports/observer/EntityObserver.java b/src/main/java/com/aventstack/extentreports/observer/EntityObserver.java new file mode 100644 index 0000000..69830bc --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/observer/EntityObserver.java @@ -0,0 +1,12 @@ +package com.aventstack.extentreports.observer; + +import com.aventstack.extentreports.observer.entity.ObservedEntity; + +public interface EntityObserver + extends + AttributesObserver, + LogObserver, + MediaObserver, + ReportObserver, + TestObserver { +} diff --git a/src/main/java/com/aventstack/extentreports/observer/ExtentObserver.java b/src/main/java/com/aventstack/extentreports/observer/ExtentObserver.java new file mode 100644 index 0000000..dacb0e4 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/observer/ExtentObserver.java @@ -0,0 +1,6 @@ +package com.aventstack.extentreports.observer; + +import com.aventstack.extentreports.observer.entity.ObservedEntity; + +public interface ExtentObserver { +} diff --git a/src/main/java/com/aventstack/extentreports/observer/LogObserver.java b/src/main/java/com/aventstack/extentreports/observer/LogObserver.java new file mode 100644 index 0000000..33058f7 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/observer/LogObserver.java @@ -0,0 +1,10 @@ +package com.aventstack.extentreports.observer; + +import com.aventstack.extentreports.observer.entity.LogEntity; +import com.aventstack.extentreports.observer.entity.ObservedEntity; + +import io.reactivex.rxjava3.core.Observer; + +public interface LogObserver extends ExtentObserver { + Observer getLogObserver(); +} diff --git a/src/main/java/com/aventstack/extentreports/observer/MediaObserver.java b/src/main/java/com/aventstack/extentreports/observer/MediaObserver.java new file mode 100644 index 0000000..6ef3aea --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/observer/MediaObserver.java @@ -0,0 +1,10 @@ +package com.aventstack.extentreports.observer; + +import com.aventstack.extentreports.observer.entity.MediaEntity; +import com.aventstack.extentreports.observer.entity.ObservedEntity; + +import io.reactivex.rxjava3.core.Observer; + +public interface MediaObserver extends ExtentObserver { + Observer getMediaObserver(); +} diff --git a/src/main/java/com/aventstack/extentreports/observer/ReportObserver.java b/src/main/java/com/aventstack/extentreports/observer/ReportObserver.java new file mode 100644 index 0000000..5931ed5 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/observer/ReportObserver.java @@ -0,0 +1,10 @@ +package com.aventstack.extentreports.observer; + +import com.aventstack.extentreports.observer.entity.ObservedEntity; +import com.aventstack.extentreports.observer.entity.ReportEntity; + +import io.reactivex.rxjava3.core.Observer; + +public interface ReportObserver extends ExtentObserver { + Observer getReportObserver(); +} diff --git a/src/main/java/com/aventstack/extentreports/observer/TestObserver.java b/src/main/java/com/aventstack/extentreports/observer/TestObserver.java new file mode 100644 index 0000000..e57bbed --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/observer/TestObserver.java @@ -0,0 +1,10 @@ +package com.aventstack.extentreports.observer; + +import com.aventstack.extentreports.observer.entity.ObservedEntity; +import com.aventstack.extentreports.observer.entity.TestEntity; + +import io.reactivex.rxjava3.core.Observer; + +public interface TestObserver extends ExtentObserver { + Observer getTestObserver(); +} diff --git a/src/main/java/com/aventstack/extentreports/observer/entity/AttributeEntity.java b/src/main/java/com/aventstack/extentreports/observer/entity/AttributeEntity.java new file mode 100644 index 0000000..b860698 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/observer/entity/AttributeEntity.java @@ -0,0 +1,22 @@ +package com.aventstack.extentreports.observer.entity; + +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 lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +@AllArgsConstructor +@Getter +@Setter +@Builder +public class AttributeEntity implements ObservedEntity { + private Test test; + private Author author; + private Category category; + private Device device; +} diff --git a/src/main/java/com/aventstack/extentreports/observer/entity/LogEntity.java b/src/main/java/com/aventstack/extentreports/observer/entity/LogEntity.java new file mode 100644 index 0000000..e4e1415 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/observer/entity/LogEntity.java @@ -0,0 +1,18 @@ +package com.aventstack.extentreports.observer.entity; + +import com.aventstack.extentreports.model.Log; +import com.aventstack.extentreports.model.Test; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +@AllArgsConstructor +@Getter +@Setter +@Builder +public class LogEntity implements ObservedEntity { + private Log log; + private Test test; +} diff --git a/src/main/java/com/aventstack/extentreports/observer/entity/MediaEntity.java b/src/main/java/com/aventstack/extentreports/observer/entity/MediaEntity.java new file mode 100644 index 0000000..2392361 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/observer/entity/MediaEntity.java @@ -0,0 +1,20 @@ +package com.aventstack.extentreports.observer.entity; + +import com.aventstack.extentreports.model.Log; +import com.aventstack.extentreports.model.Media; +import com.aventstack.extentreports.model.Test; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +@AllArgsConstructor +@Getter +@Setter +@Builder +public class MediaEntity implements ObservedEntity { + private Media media; + private Test test; + private Log log; +} diff --git a/src/main/java/com/aventstack/extentreports/observer/entity/NamedAttributeTestEntity.java b/src/main/java/com/aventstack/extentreports/observer/entity/NamedAttributeTestEntity.java new file mode 100644 index 0000000..e939873 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/observer/entity/NamedAttributeTestEntity.java @@ -0,0 +1,18 @@ +package com.aventstack.extentreports.observer.entity; + +import com.aventstack.extentreports.model.NamedAttribute; +import com.aventstack.extentreports.model.Test; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +@Builder +public class NamedAttributeTestEntity implements ObservedEntity { + private NamedAttribute attribute; + private Test test; +} diff --git a/src/main/java/com/aventstack/extentreports/observer/entity/ObservedEntity.java b/src/main/java/com/aventstack/extentreports/observer/entity/ObservedEntity.java new file mode 100644 index 0000000..bc80b19 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/observer/entity/ObservedEntity.java @@ -0,0 +1,4 @@ +package com.aventstack.extentreports.observer.entity; + +public interface ObservedEntity { +} diff --git a/src/main/java/com/aventstack/extentreports/observer/entity/ReportEntity.java b/src/main/java/com/aventstack/extentreports/observer/entity/ReportEntity.java new file mode 100644 index 0000000..904bea4 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/observer/entity/ReportEntity.java @@ -0,0 +1,16 @@ +package com.aventstack.extentreports.observer.entity; + +import com.aventstack.extentreports.model.Report; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +@AllArgsConstructor +@Getter +@Setter +@Builder +public class ReportEntity implements ObservedEntity { + private Report report; +} diff --git a/src/main/java/com/aventstack/extentreports/observer/entity/TestEntity.java b/src/main/java/com/aventstack/extentreports/observer/entity/TestEntity.java new file mode 100644 index 0000000..cadea7f --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/observer/entity/TestEntity.java @@ -0,0 +1,18 @@ +package com.aventstack.extentreports.observer.entity; + +import com.aventstack.extentreports.model.Test; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +@AllArgsConstructor +@Getter +@Setter +@Builder +public class TestEntity implements ObservedEntity { + private Test test; + @Builder.Default + private Boolean removed = false; +} diff --git a/src/main/java/com/aventstack/extentreports/offline/OfflineResxDelegate.java b/src/main/java/com/aventstack/extentreports/offline/OfflineResxDelegate.java deleted file mode 100644 index d4d043e..0000000 --- a/src/main/java/com/aventstack/extentreports/offline/OfflineResxDelegate.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.aventstack.extentreports.offline; - -import java.io.File; -import java.nio.file.Path; -import java.nio.file.Paths; - -import com.aventstack.extentreports.io.ResourceUtil; -import com.aventstack.extentreports.utils.FileUtil; - -public class OfflineResxDelegate { - - public static void saveOfflineResources(String baseResourceDirectory, String[] resx, String toPath) { - FileUtil.createDirectory(toPath); - for (String f : resx) { - Path path = Paths.get(baseResourceDirectory, f); - String fromPath = path.toString(); - String toPathComplete = Paths.get(toPath, new File(f).getName()).toString(); - ResourceUtil.moveResource(fromPath, toPathComplete); - } - } - - public static void saveOfflineResources(String[] resx, String toPath) { - for (String f : resx) { - ResourceUtil.moveResource(f, toPath); - } - } - -} diff --git a/src/main/java/com/aventstack/extentreports/reporter/AbstractFileReporter.java b/src/main/java/com/aventstack/extentreports/reporter/AbstractFileReporter.java new file mode 100644 index 0000000..13f7a58 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/reporter/AbstractFileReporter.java @@ -0,0 +1,101 @@ +package com.aventstack.extentreports.reporter; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +import com.aventstack.extentreports.ExtentReports; +import com.aventstack.extentreports.Status; +import com.aventstack.extentreports.model.service.TestService; +import com.aventstack.extentreports.templating.FreemarkerTemplate; +import com.aventstack.extentreports.templating.TemplateConfig; +import com.aventstack.extentreports.view.Ico; + +import freemarker.ext.beans.BeansWrapper; +import freemarker.ext.beans.BeansWrapperBuilder; +import freemarker.template.Configuration; +import freemarker.template.Template; +import freemarker.template.TemplateException; +import freemarker.template.TemplateHashModel; +import freemarker.template.TemplateModelException; +import lombok.Getter; + +@Getter +public abstract class AbstractFileReporter extends AbstractFilterableReporter { + private static final Logger LOG = Logger.getLogger(AbstractFileReporter.class.getName()); + protected static final String PATH_SEP = "/"; + + private File file; + private Map templateModel; + private Configuration freemarkerConfig; + + protected AbstractFileReporter(File f) { + this.file = f; + File parentFile; + if (Files.isDirectory(f.toPath())) { + parentFile = f; + } else { + parentFile = f.getParentFile(); + } + if (!parentFile.exists()) + parentFile.mkdirs(); + } + + protected void loadTemplateModel() { + if (templateModel != null) + return; + + templateModel = new HashMap<>(); + BeansWrapperBuilder builder = new BeansWrapperBuilder(Configuration.VERSION_2_3_30); + BeansWrapper beansWrapper = builder.build(); + + try { + TemplateHashModel fieldTypeModel = (TemplateHashModel) beansWrapper.getEnumModels() + .get(Status.class.getName()); + templateModel.put("Status", fieldTypeModel); + fieldTypeModel = (TemplateHashModel) beansWrapper.getStaticModels() + .get(Ico.class.getName()); + templateModel.put("Ico", fieldTypeModel); + fieldTypeModel = (TemplateHashModel) beansWrapper.getStaticModels() + .get(TestService.class.getName()); + templateModel.put("TestService", fieldTypeModel); + } catch (TemplateModelException e) { + LOG.log(Level.SEVERE, "", e); + } + } + + protected void processTemplate(Template template, File outputFile) throws TemplateException, IOException { + FreemarkerTemplate freemarkerTemplate = new FreemarkerTemplate(getFreemarkerConfig()); + freemarkerTemplate.writeTemplate(template, templateModel, outputFile); + } + + protected Configuration createFreemarkerConfig(String templatePath, String encoding) { + if (freemarkerConfig == null) { + TemplateConfig freemarkerConfig = new TemplateConfig(); + this.freemarkerConfig = freemarkerConfig.getFreemarkerConfig(ExtentReports.class, templatePath, + encoding); + } + return freemarkerConfig; + } + + protected String getFileNameAsExt(String fileName, String[] checkExt) { + if (checkExt.length == 0) + return fileName; + String path = getFile().getPath(); + final String filePath = (getFile().isDirectory() + || path.indexOf(".") == -1) + && !Arrays.stream(checkExt).anyMatch(x -> path.endsWith(x)) + ? getFile().getAbsolutePath() + + PATH_SEP + fileName + : getFile().getAbsolutePath(); + boolean b = Arrays.stream(checkExt).anyMatch(x -> filePath.endsWith(x)); + String resolved = b ? filePath : filePath + checkExt[0]; + new File(resolved).getParentFile().mkdirs(); + return resolved; + } +} diff --git a/src/main/java/com/aventstack/extentreports/reporter/AbstractFilterableReporter.java b/src/main/java/com/aventstack/extentreports/reporter/AbstractFilterableReporter.java new file mode 100644 index 0000000..cc7dd13 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/reporter/AbstractFilterableReporter.java @@ -0,0 +1,22 @@ +package com.aventstack.extentreports.reporter; + +import java.util.Set; + +import com.aventstack.extentreports.Status; +import com.aventstack.extentreports.model.Report; +import com.aventstack.extentreports.model.service.ReportFilterService; +import com.aventstack.extentreports.reporter.filter.StatusFilterable; + +import lombok.Getter; + +@Getter +public class AbstractFilterableReporter extends AbstractReporter implements StatusFilterable { + @Override + public Report filterAndGet(Report report, Set set) { + if (report == null || report.getTestList().isEmpty()) + return report; + if (set != null) + return ReportFilterService.filter(report, set); + return report; + } +} diff --git a/src/main/java/com/aventstack/extentreports/reporter/AbstractReporter.java b/src/main/java/com/aventstack/extentreports/reporter/AbstractReporter.java index 1dedb56..32f1734 100644 --- a/src/main/java/com/aventstack/extentreports/reporter/AbstractReporter.java +++ b/src/main/java/com/aventstack/extentreports/reporter/AbstractReporter.java @@ -1,189 +1,4 @@ package com.aventstack.extentreports.reporter; -import java.io.IOException; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.List; - -import com.aventstack.extentreports.AnalysisStrategy; -import com.aventstack.extentreports.ReportAggregates; -import com.aventstack.extentreports.ReportStatusStats; -import com.aventstack.extentreports.Status; -import com.aventstack.extentreports.mediastorage.LocalMediaStorageHandler; -import com.aventstack.extentreports.mediastorage.MediaStorage; -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; -import com.aventstack.extentreports.model.context.ExceptionTestContextStore; -import com.aventstack.extentreports.model.context.SystemAttributeContext; -import com.aventstack.extentreports.model.context.TestAttributeTestContextStore; - public abstract class AbstractReporter implements ExtentReporter { - - private Date startTime = Calendar.getInstance().getTime(); - private Date endTime = startTime; - private AnalysisStrategy strategy = AnalysisStrategy.TEST; - - private MediaStorage media; - private List testList; - private List testRunnerLogs; - private ExceptionTestContextStore exceptionContext; - private TestAttributeTestContextStore categoryContext; - private TestAttributeTestContextStore authorContext; - private TestAttributeTestContextStore deviceContext; - private SystemAttributeContext systemAttributeContext; - private ReportStatusStats stats; - private Collection statusCollection; - - public void flush(ReportAggregates reportAggregates) { - startTime = reportAggregates.getStartTime(); - endTime = reportAggregates.getEndTime(); - this.authorContext = reportAggregates.getAuthorContext(); - this.categoryContext = reportAggregates.getCategoryContext(); - this.deviceContext = reportAggregates.getDeviceContext(); - this.exceptionContext = reportAggregates.getExceptionContext(); - this.stats = reportAggregates.getReportStatusStats(); - this.systemAttributeContext = reportAggregates.getSystemAttributeContext(); - this.testList = reportAggregates.getTestList(); - this.testRunnerLogs = reportAggregates.getTestRunnerLogs(); - this.statusCollection = reportAggregates.getStatusCollection(); - } - - public Date getStartTime() { - return startTime; - } - - public void setStartTime(Date startTime) { - this.startTime = startTime; - } - - public void setEndTime(Date endTime) { - this.endTime = endTime; - } - - public Date getEndTime() { - return endTime; - } - - public void setAnalysisStrategy(AnalysisStrategy strategy) { - this.strategy = strategy; - } - - public AnalysisStrategy getAnalysisStrategy() { - return strategy; - } - - public long getRunDuration() { - return endTime.getTime() - startTime.getTime(); - } - - public String getLongRunDuration() { - long millis = getRunDuration(); - - long secs = millis / 1000; - long ms = millis % 1000; - long mins = secs / 60; - secs = (secs % 60); - long hours = mins / 60; - mins = mins % 60; - - return hours + "h " + mins + "m " + secs + "s+" + ms + "ms"; - } - - public List getTestList() { - return testList; - } - - public List getTestRunnerLogs() { - return testRunnerLogs; - } - - public TestAttributeTestContextStore getCategoryContextInfo() { - return categoryContext; - } - - public TestAttributeTestContextStore getAuthorContextInfo() { - return authorContext; - } - - public TestAttributeTestContextStore getDeviceContextInfo() { - return deviceContext; - } - - public ExceptionTestContextStore getExceptionContextInfo() { - return exceptionContext; - } - - public SystemAttributeContext getSystemAttributeContext() { - return systemAttributeContext; - } - - public ReportStatusStats getReportStatusStats() { - return stats; - } - - public Collection getStatusCollection() { - return statusCollection; - } - - @Override - public void onTestStarted(Test test) { - } - - @Override - public void onTestRemoved(Test test) { - } - - @Override - public void onNodeStarted(Test node) { - } - - @Override - public void onLogAdded(Test test, Log log) { - } - - @Override - public void onCategoryAssigned(Test test, Category category) { - } - - @Override - public void onAuthorAssigned(Test test, Author author) { - } - - @Override - public void onDeviceAssigned(Test test, Device device) { - } - - @Override - public void onScreenCaptureAdded(Test test, ScreenCapture screenCapture) throws IOException { - } - - @Override - public void onScreenCaptureAdded(Log log, ScreenCapture screenCapture) throws IOException { - } - - protected void autoCreateRelativePathMedia(ScreenCapture screenCapture, Boolean autoCreateRelativePath, - String destination) throws IOException { - // if user has not specific a configuration, exit - if (screenCapture.isBase64()) { - return; - } - // check always so user has the option to disable this setting at anytime - if (autoCreateRelativePath) { - if (media == null) { - media = new LocalMediaStorageHandler(); - media.init(destination); - } - media.storeMedia(screenCapture); - } - } - - @Override - public void stop() { - } - } diff --git a/src/main/java/com/aventstack/extentreports/reporter/BasicFileReporter.java b/src/main/java/com/aventstack/extentreports/reporter/BasicFileReporter.java deleted file mode 100644 index 9caf04a..0000000 --- a/src/main/java/com/aventstack/extentreports/reporter/BasicFileReporter.java +++ /dev/null @@ -1,178 +0,0 @@ -package com.aventstack.extentreports.reporter; - -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; - -import com.aventstack.extentreports.ExtentReports; -import com.aventstack.extentreports.ReportAggregates; -import com.aventstack.extentreports.Status; -import com.aventstack.extentreports.model.Log; -import com.aventstack.extentreports.model.ScreenCapture; -import com.aventstack.extentreports.model.Test; -import com.aventstack.extentreports.model.service.LogService; -import com.aventstack.extentreports.model.service.TestService; -import com.aventstack.extentreports.templating.FreemarkerTemplate; -import com.aventstack.extentreports.templating.TemplateConfig; -import com.aventstack.extentreports.utils.FileUtil; -import com.aventstack.extentreports.viewdefs.Icon; -import com.aventstack.extentreports.viewdefs.MaterialIcon; -import com.aventstack.extentreports.viewdefs.TWBSColor; - -import freemarker.ext.beans.BeansWrapper; -import freemarker.ext.beans.BeansWrapperBuilder; -import freemarker.template.Configuration; -import freemarker.template.Template; -import freemarker.template.TemplateException; -import freemarker.template.TemplateHashModel; -import freemarker.template.TemplateModelException; - -/** - * A base class for all reporter types that generate an output file - * - */ -public abstract class BasicFileReporter extends ConfigurableReporter { - - private static final Logger logger = Logger.getLogger(BasicFileReporter.class.getName()); - private static final String DEFAULT_MEDIA_SAVE_PROPERTY_NAME = "autoCreateRelativePathMedia"; - private static final String TEMPLATE_LOCATION = "view/"; - - private static String encoding = "UTF-8"; - - private String filePath; - private String destination; - private Map templateModel; - private String source; - private Configuration freemarkerConfig; - - protected BasicFileReporter(File f) { - this.filePath = f.getAbsolutePath(); - File parentFile; - if (f.isDirectory() || FileUtil.getExtension(f).isEmpty()) { - parentFile = f; - } else { - parentFile = f.getParentFile(); - } - destination = parentFile == null ? "" : parentFile.getAbsolutePath() + "/"; - File destinationFile = new File(destination); - if (!destinationFile.exists()) { - destinationFile.mkdirs(); - } - } - - protected BasicFileReporter(String path) { - this(new File(path)); - } - - protected void setFilePath(String filePath) { - this.filePath = filePath; - } - - public String getFilePath() { - return filePath; - } - - public File getFileFile() { - return new File(filePath); - } - - public String getDestinationPath() { - return destination; - } - - @Override - public void start() { - if (templateModel != null) { - return; - } - - templateModel = new HashMap<>(); - templateModel.put("report", this); - templateModel.put("MaterialIcon", new MaterialIcon()); - templateModel.put("Icon", new Icon()); - templateModel.put("TWBSColor", new TWBSColor()); - - BeansWrapperBuilder builder = new BeansWrapperBuilder(Configuration.VERSION_2_3_29); - BeansWrapper beansWrapper = builder.build(); - - try { - TemplateHashModel fieldTypeModel = (TemplateHashModel) beansWrapper.getEnumModels() - .get(Status.class.getName()); - templateModel.put("Status", fieldTypeModel); - fieldTypeModel = (TemplateHashModel) beansWrapper.getStaticModels() - .get(TestService.class.getName()); - templateModel.put("TestService", fieldTypeModel); - fieldTypeModel = (TemplateHashModel) beansWrapper.getStaticModels() - .get(LogService.class.getName()); - templateModel.put("LogService", fieldTypeModel); - } catch (TemplateModelException e) { - logger.log(Level.SEVERE, "", e); - } - } - - @Override - public synchronized void flush(ReportAggregates reportAggregates) { - super.flush(reportAggregates); - } - - @Override - public void onScreenCaptureAdded(Test test, ScreenCapture screenCapture) throws IOException { - onScreenCaptureAdded(screenCapture); - } - - @Override - public void onScreenCaptureAdded(Log log, ScreenCapture screenCapture) throws IOException { - onScreenCaptureAdded(screenCapture); - } - - private void onScreenCaptureAdded(ScreenCapture screenCapture) throws IOException { - if (getConfigurationStore() == null) - return; - String autoCreateRelativePathMedia = (String) getConfigurationStore() - .getConfig(DEFAULT_MEDIA_SAVE_PROPERTY_NAME); - if (autoCreateRelativePathMedia != null && Boolean.valueOf(autoCreateRelativePathMedia)) { - autoCreateRelativePathMedia(screenCapture, Boolean.valueOf(autoCreateRelativePathMedia), destination); - } - } - - public boolean containsStatus(String status) { - Status s = Status.valueOf(status.toUpperCase()); - return containsStatus(s); - } - - public boolean containsStatus(Status status) { - return getStatusCollection() != null && getStatusCollection().contains(status); - } - - protected void processTemplate(Template template, File outputFile) throws TemplateException, IOException { - FreemarkerTemplate freemarkerTemplate = new FreemarkerTemplate(getFreemarkerConfig()); - freemarkerTemplate.writeTemplate(template, templateModel, outputFile); - } - - protected String getSource() { - return source; - } - - protected Configuration getFreemarkerConfig() { - if (freemarkerConfig == null) { - TemplateConfig freemarkerConfig = new TemplateConfig(); - this.freemarkerConfig = freemarkerConfig.getFreemarkerConfig(ExtentReports.class, TEMPLATE_LOCATION, - encoding); - } - return freemarkerConfig; - } - - protected Boolean enforceOfflineMode() { - if (getConfigurationStore().containsConfig("enableOfflineMode")) { - String offlineMode = String.valueOf(getConfigurationStore().getConfig("enableOfflineMode")); - if (!getConfigurationStore().containsConfig("offlineDirectory") && Boolean.parseBoolean(offlineMode)) { - return true; - } - } - return false; - } - -} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/reporter/ConfigurableReporter.java b/src/main/java/com/aventstack/extentreports/reporter/ConfigurableReporter.java deleted file mode 100644 index f696599..0000000 --- a/src/main/java/com/aventstack/extentreports/reporter/ConfigurableReporter.java +++ /dev/null @@ -1,144 +0,0 @@ -package com.aventstack.extentreports.reporter; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.util.Arrays; -import java.util.Map; -import java.util.Properties; -import java.util.logging.Level; -import java.util.logging.Logger; - -import com.aventstack.extentreports.configuration.ConfigurationBuilder; -import com.aventstack.extentreports.configuration.ConfigurationStore; -import com.aventstack.extentreports.reporter.configuration.BasicConfiguration; - -public abstract class ConfigurableReporter extends AbstractReporter { - - private static final Logger logger = Logger.getLogger(ConfigurableReporter.class.getName()); - - private BasicConfiguration basicConfiguration; - - /** - * Loads configuration from an XML file - * - * @param filePath Configuration file path - * @param silent Load configuration silently, no errors are thrown if the - * configuration file is not present - */ - public void loadXMLConfig(String filePath, Boolean silent) { - loadXMLConfig(new File(filePath), silent); - } - - /** - * Loads configuration from an XML file - * - * @param filePath configuration file path - */ - public void loadXMLConfig(String filePath) { - loadXMLConfig(filePath, false); - } - - /** - * Loads configuration from an XML file - * - * @param file configuration {@link File} - */ - public void loadXMLConfig(File file) { - loadXMLConfig(file, false); - } - - /** - * Loads configuration from an XML file - * - * @param file configuration {@link File} - * @param silent If silent, no errors will be thrown - */ - public void loadXMLConfig(File file, Boolean silent) { - ConfigurationBuilder builder = new ConfigurationBuilder(file, silent); - ConfigurationStore store = builder.getConfigurationStore(); - basicConfiguration.getConfigurationStore().extendConfig(store); - } - - /** - * Loads configuration from a Properties file - * - * @param properties a {@link Properties} object - */ - public void loadConfig(Properties properties) { - properties.entrySet().forEach(o -> { - if (o.getKey() != null) { - basicConfiguration.getConfigurationStore().storeConfig(o.getKey().toString(), o.getValue()); - } - }); - } - - /** - * Loads configuration from an {@link InputStream} which is a {@link Properties} - * file - * - * @param stream an {@link InputStream} - */ - public void loadConfig(InputStream stream) { - Properties properties = new Properties(); - - try { - properties.load(stream); - loadConfig(properties); - } catch (FileNotFoundException e) { - logger.log(Level.SEVERE, "Default Properties file not found", e); - } catch (IOException e) { - logger.log(Level.SEVERE, "Unable to load properties file", e); - } - } - - /** - * Loads configuration from an path which is a {@link Properties} file - * - * @param filePath Properties file path - */ - public void loadConfig(String filePath) { - try { - InputStream is = new FileInputStream(filePath); - loadConfig(is); - } catch (FileNotFoundException e) { - logger.log(Level.SEVERE, "Default Properties file not found", e); - } - } - - protected void loadUserConfig() { - for (Map.Entry entry : getConfigurationStore().getStore().entrySet()) { - getConfigurationStore().storeConfig(entry.getKey(), entry.getValue()); - } - } - - protected void init(String[] configFilePath, BasicConfiguration userConfig) { - basicConfiguration = userConfig; - loadInternalReporterConfiguration(configFilePath); - } - - protected void loadInternalReporterConfiguration(String[] configFilePath) { - if (configFilePath == null || configFilePath.length == 0) - return; - - ClassLoader loader = getClass().getClassLoader(); - Arrays.stream(configFilePath) - .map(x -> loader.getResourceAsStream(x)) - .filter(x -> x != null) - .findFirst() - .ifPresent(x -> loadConfig(x)); - } - - /** - * Returns the current configuration (default and user-defined) - * - * @return a {@link ConfigurationStore} containing key-value pairs of config - * entries - */ - public ConfigurationStore getConfigurationStore() { - return basicConfiguration == null ? null : basicConfiguration.getConfigurationStore(); - } - -} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/reporter/ConsoleLogger.java b/src/main/java/com/aventstack/extentreports/reporter/ConsoleLogger.java deleted file mode 100644 index 72f954f..0000000 --- a/src/main/java/com/aventstack/extentreports/reporter/ConsoleLogger.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.aventstack.extentreports.reporter; - -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - -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; - -public class ConsoleLogger - extends AbstractReporter { - - private static final Logger LOGGER = Logger.getAnonymousLogger(); - private static final String REPORTER_NAME = "consolelogger"; - - @Override - public void start() { - LOGGER.log(Level.INFO, getClass().getName() + " was registered"); - } - - @Override - public void stop() { - LOGGER.log(Level.INFO, getClass().getName() + " stopping.."); - } - - public void onTestStarted(Test test) { - LOGGER.log(Level.INFO, "Starting test " + test.getName()); - } - - @Override - public void onTestRemoved(Test test) { - LOGGER.log(Level.INFO, "Test with name " + test.getName() + " was removed"); - } - - public void onNodeStarted(Test node) { - LOGGER.log(Level.INFO, "A new node " + node.getName() + " for test " + node.getParent().getName() + " created"); - } - - public void onLogAdded(Test test, Log log) { - LOGGER.log(Level.INFO, "A new log event with details " + log.getDetails() + " for test " + test.getName() + " created"); - } - - @Override - public void onCategoryAssigned(Test test, Category category) { - LOGGER.log(Level.INFO, "A new category " + category.getName() + " for test " + test.getName() + " assigned"); - } - - @Override - public void onAuthorAssigned(Test test, Author author) { - LOGGER.log(Level.INFO, "A new author " + author.getName() + " for test " + test.getName() + " assigned"); - } - - @Override - public void onDeviceAssigned(Test test, Device device) { - LOGGER.log(Level.INFO, "A new device " + device.getName() + " for test " + test.getName() + " assigned"); - } - - @Override - public void onScreenCaptureAdded(Test test, ScreenCapture screenCapture) throws IOException { - LOGGER.log(Level.INFO, "A new screencapture for test " + test.getName() + " created"); - } - - @Override - public void onScreenCaptureAdded(Log log, ScreenCapture screenCapture) { - LOGGER.log(Level.INFO, "A new screencapture for log " + log.getDetails() + " created"); - } - - @Override - public String getReporterName() { - return REPORTER_NAME; - } - -} diff --git a/src/main/java/com/aventstack/extentreports/reporter/ExtentAventReporter.java b/src/main/java/com/aventstack/extentreports/reporter/ExtentAventReporter.java deleted file mode 100644 index cfa4b39..0000000 --- a/src/main/java/com/aventstack/extentreports/reporter/ExtentAventReporter.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.aventstack.extentreports.reporter; - -import java.io.File; - -import com.aventstack.extentreports.ReportAggregates; - -/** - * The ExtentHtmlReporter creates a rich standalone HTML file. It allows several configuration options - * via the config() method. - */ -public class ExtentAventReporter - extends BasicFileReporter { - - private static final String REPORTER_NAME = "avent"; - - public ExtentAventReporter(String path) { - super(path); - } - - public ExtentAventReporter(File file) { - super(file); - } - - @Override - public synchronized void flush(ReportAggregates reportAggregates) { - } - - @Override - public String getReporterName() { - return REPORTER_NAME; - } - -} diff --git a/src/main/java/com/aventstack/extentreports/reporter/ExtentBDDReporter.java b/src/main/java/com/aventstack/extentreports/reporter/ExtentBDDReporter.java deleted file mode 100644 index 0a609b7..0000000 --- a/src/main/java/com/aventstack/extentreports/reporter/ExtentBDDReporter.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.aventstack.extentreports.reporter; - -import java.io.File; - -import com.aventstack.extentreports.ReportAggregates; - -/** - * The ExtentHtmlReporter creates a rich standalone HTML file. It allows several configuration options - * via the config() method. - */ -public class ExtentBDDReporter - extends BasicFileReporter { - - private static final String REPORTER_NAME = "bdd"; - - public ExtentBDDReporter(String path) { - super(path); - } - - public ExtentBDDReporter(File file) { - super(file); - } - - @Override - public synchronized void flush(ReportAggregates reportAggregates) { - } - - @Override - public String getReporterName() { - return REPORTER_NAME; - } - -} diff --git a/src/main/java/com/aventstack/extentreports/reporter/ExtentCardsReporter.java b/src/main/java/com/aventstack/extentreports/reporter/ExtentCardsReporter.java deleted file mode 100644 index a3dbee1..0000000 --- a/src/main/java/com/aventstack/extentreports/reporter/ExtentCardsReporter.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.aventstack.extentreports.reporter; - -import java.io.File; - -import com.aventstack.extentreports.ReportAggregates; - -/** - * The ExtentHtmlReporter creates a rich standalone HTML file. It allows several configuration options - * via the config() method. - */ -public class ExtentCardsReporter - extends BasicFileReporter { - - private static final String REPORTER_NAME = "cards"; - - public ExtentCardsReporter(String path) { - super(path); - } - - public ExtentCardsReporter(File file) { - super(file); - } - - @Override - public synchronized void flush(ReportAggregates reportAggregates) { - } - - @Override - public String getReporterName() { - return REPORTER_NAME; - } - -} diff --git a/src/main/java/com/aventstack/extentreports/reporter/ExtentEmailReporter.java b/src/main/java/com/aventstack/extentreports/reporter/ExtentEmailReporter.java deleted file mode 100644 index c785a06..0000000 --- a/src/main/java/com/aventstack/extentreports/reporter/ExtentEmailReporter.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.aventstack.extentreports.reporter; - -import java.io.File; - -import com.aventstack.extentreports.ReportAggregates; -import com.aventstack.extentreports.SourceProvider; - -/** - * The ExtentHtmlReporter creates a rich standalone HTML file. It allows several - * configuration options via the config() method. - */ -public class ExtentEmailReporter extends BasicFileReporter implements SourceProvider { - - private static final String REPORTER_NAME = "email"; - - public ExtentEmailReporter(String path) { - super(path); - } - - public ExtentEmailReporter(File file) { - super(file); - } - - @Override - public synchronized void flush(ReportAggregates reportAggregates) { - } - - @Override - public String getReporterName() { - return REPORTER_NAME; - } - - @Override - public String getSource() { - return super.getSource(); - } - -} diff --git a/src/main/java/com/aventstack/extentreports/reporter/ExtentHtmlReporter.java b/src/main/java/com/aventstack/extentreports/reporter/ExtentHtmlReporter.java deleted file mode 100644 index 93ec7da..0000000 --- a/src/main/java/com/aventstack/extentreports/reporter/ExtentHtmlReporter.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.aventstack.extentreports.reporter; - -import java.io.File; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - -import com.aventstack.extentreports.ReportAggregates; -import com.aventstack.extentreports.reporter.configuration.ExtentHtmlReporterConfiguration; - -import freemarker.template.Template; -import freemarker.template.TemplateException; - -/** - * The ExtentSparkReporter creates a rich standalone spark file. It allows - * several configuration options via the config() method. - */ -@Deprecated -public class ExtentHtmlReporter extends BasicFileReporter { - - private static final Logger logger = Logger.getLogger(ExtentHtmlReporter.class.getName()); - private static final String REPORTER_NAME = "html"; - private static final String TEMPLATE_NAME = "v3html/v3-html-index.ftl"; - private static final String[] DEFAULT_CONFIG_FILE_PATH = new String[] { "html.properties", - "src/main/resources/html.properties" }; - - private ExtentHtmlReporterConfiguration externalUserConfiguration = new ExtentHtmlReporterConfiguration(this); - - public ExtentHtmlReporter(String path) { - super(path); - init(DEFAULT_CONFIG_FILE_PATH, config()); - } - - public ExtentHtmlReporter(File file) { - super(file); - init(DEFAULT_CONFIG_FILE_PATH, config()); - } - - public ExtentHtmlReporterConfiguration config() { - return externalUserConfiguration; - } - - @Override - public synchronized void flush(ReportAggregates reportAggregates) { - super.flush(reportAggregates); - if (getTestList().isEmpty()) { - return; - } - if (enforceOfflineMode()) { - externalUserConfiguration.enableOfflineMode(true); - } - - loadUserConfig(); - - try { - Template template = getFreemarkerConfig().getTemplate(TEMPLATE_NAME); - processTemplate(template, new File(getFilePath())); - } catch (IOException | TemplateException e) { - logger.log(Level.SEVERE, "An exception occurred", e); - } - } - - @Override - public String getReporterName() { - return REPORTER_NAME; - } - -} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/reporter/ExtentKlovReporter.java b/src/main/java/com/aventstack/extentreports/reporter/ExtentKlovReporter.java deleted file mode 100644 index fc20f39..0000000 --- a/src/main/java/com/aventstack/extentreports/reporter/ExtentKlovReporter.java +++ /dev/null @@ -1,659 +0,0 @@ -package com.aventstack.extentreports.reporter; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.util.Calendar; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.stream.Collectors; - -import org.bson.Document; -import org.bson.types.ObjectId; - -import com.aventstack.extentreports.ReportAggregates; -import com.aventstack.extentreports.ReportStatusStats; -import com.aventstack.extentreports.Status; -import com.aventstack.extentreports.mediastorage.KlovMediaStorageHandler; -import com.aventstack.extentreports.mediastorage.model.KlovMedia; -import com.aventstack.extentreports.model.Attribute; -import com.aventstack.extentreports.model.Author; -import com.aventstack.extentreports.model.BasicMongoReportElement; -import com.aventstack.extentreports.model.Category; -import com.aventstack.extentreports.model.Device; -import com.aventstack.extentreports.model.ExceptionInfo; -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.SystemAttributeContext; -import com.aventstack.extentreports.model.context.TestAttributeTestContextStore; -import com.aventstack.extentreports.model.service.LogService; -import com.aventstack.extentreports.model.service.TestService; -import com.aventstack.extentreports.reporter.configuration.ExtentKlovReporterConfiguration; -import com.aventstack.extentreports.utils.IntUtil; -import com.aventstack.extentreports.utils.MongoUtil; -import com.mongodb.MongoClient; -import com.mongodb.MongoClientOptions; -import com.mongodb.MongoClientURI; -import com.mongodb.ServerAddress; -import com.mongodb.client.FindIterable; -import com.mongodb.client.MongoCollection; -import com.mongodb.client.MongoDatabase; - -/** - * ExtentKlovReporter is a NoSQL database reporter (MongoDB), which updates - * information in the database which is then used by the ExtentX server to - * display in-depth analysis. - */ -public class ExtentKlovReporter extends ConfigurableReporter { - - private static final String DEFAULT_PROJECT_NAME_PROP = "klov.project.name"; - private static final String DEFAULT_REPORT_NAME_PROP = "klov.report.name"; - private static final String DEFAULT_MONGODB_HOST_PROP = "mongodb.host"; - private static final String DEFAULT_MONGODB_PORT_PROP = "mongodb.port"; - private static final String DEFAULT_MONGODB_URI_PROP = "mongodb.uri"; - private static final String DEFAULT_KLOV_HOST_PROP = "klov.host"; - private static final String DEFAULT_KLOV_PORT_PROP = "klov.port"; - private static final String REPORTER_NAME = "klov"; - private static final String DB_NAME = "klov"; - private static final String DEFAULT_PROJECT_NAME = "Default"; - - private ExtentKlovReporterConfiguration config = new ExtentKlovReporterConfiguration(this); - - private String url; - private List testList; - private ReportStatusStats stats; - private SystemAttributeContext systemAttributeContext; - private TestAttributeTestContextStore categoryContext; - private TestAttributeTestContextStore authorContext; - private TestAttributeTestContextStore deviceContext; - private Map categoryNameObjectIdCollection = new HashMap<>(); - private Map authorNameObjectIdCollection = new HashMap<>(); - private Map deviceNameObjectIdCollection = new HashMap<>(); - private Map exceptionNameObjectIdCollection = new HashMap<>(); - private ObjectId reportId; - private String reportName; - private ObjectId projectId; - private String projectName; - private MongoClient mongoClient; - private MongoCollection projectCollection; - private MongoCollection reportCollection; - private MongoCollection testCollection; - private MongoCollection logCollection; - private MongoCollection exceptionCollection; - private MongoCollection mediaCollection; - private MongoCollection categoryCollection; - private MongoCollection authorCollection; - private MongoCollection deviceCollection; - private MongoCollection environmentCollection; - private KlovMediaStorageHandler mediaStorageHandler; - - static { - /* use mongodb reporting for only critical/severe events */ - Logger mongoLogger = Logger.getLogger("org.mongodb.driver"); - mongoLogger.setLevel(Level.SEVERE); - } - - /** - * Initializes the KlovReporter with the project name and default report name - * - *

    - * The reportName will be created using the current timestamp - * - * @param projectName Name of the project - * - */ - public ExtentKlovReporter(String projectName) { - this.projectName = projectName; - } - - /** - * Initializes the KlovReporter with project and report names - * - * @param projectName Name of the project - * @param reportName Name of the report - */ - public ExtentKlovReporter(String projectName, String reportName) { - this.projectName = projectName; - this.reportName = reportName; - } - - /** - * Sets the project name - * - * @param projectName Name of the project - * @return a {@link ExtentKlovReporter} object - */ - public ExtentKlovReporter setProjectName(String projectName) { - this.projectName = projectName; - return this; - } - - /** - * Sets the report name - * - * @param reportName Name of the report - * @return a {@link ExtentKlovReporter} object - */ - public ExtentKlovReporter setReportName(String reportName) { - this.reportName = reportName; - return this; - } - - /** - * Initialize Mongo DB connection with host and default port: 27017 - * - * @param host host name - * @return a {@link ExtentKlovReporter} object - */ - public ExtentKlovReporter initMongoDbConnection(String host) { - mongoClient = new MongoClient(host, 27017); - return this; - } - - /** - * Initialize Mongo DB connection with host and {@link MongoClientOptions} - * - * @param host host name - * @param options {@link MongoClientOptions} options - * @return a {@link ExtentKlovReporter} object - */ - public ExtentKlovReporter initMongoDbConnection(String host, MongoClientOptions options) { - mongoClient = new MongoClient(host, options); - return this; - } - - /** - * Initialize Mongo DB connection with host and post - * - * @param host host name - * @param port port number - * @return a {@link ExtentKlovReporter} object - */ - public ExtentKlovReporter initMongoDbConnection(String host, int port) { - mongoClient = new MongoClient(host, port); - return this; - } - - /** - * Initialize Mongo DB connection with a {@link MongoClientURI} - * - * @param uri {@link MongoClientURI} uri - * @return a {@link ExtentKlovReporter} object - */ - public ExtentKlovReporter initMongoDbConnection(MongoClientURI uri) { - mongoClient = new MongoClient(uri); - return this; - } - - /** - * Initializes the Mongo DB connection with {@link ServerAddress} - * - * @param addr {@link ServerAddress} server address - * @return a {@link ExtentKlovReporter} object - */ - public ExtentKlovReporter initMongoDbConnection(ServerAddress addr) { - mongoClient = new MongoClient(addr); - return this; - } - - /** - * Initializes the Mongo DB connection with a list of {@link ServerAddress} - * addresses - * - * @param seeds A list of {@link ServerAddress} server addresses - * @return a {@link ExtentKlovReporter} object - */ - public ExtentKlovReporter initMongoDbConnection(List seeds) { - mongoClient = new MongoClient(seeds); - return this; - } - - /** - * Initializes the Mongo DB connection with a list of {@link ServerAddress} and - * {@link MongoClientOptions} - * - * @param seeds A list of {@link ServerAddress} server addresses - * @param options {@link MongoClientOptions} options - * @return a {@link ExtentKlovReporter} object - */ - public ExtentKlovReporter initMongoDbConnection(List seeds, MongoClientOptions options) { - mongoClient = new MongoClient(seeds, options); - return this; - } - - /** - * Initializes the Mongo DB connection with a {@link ServerAddress} and - * {@link MongoClientOptions} - * - * @param addr A list of {@link ServerAddress} server addresses - * @param options {@link MongoClientOptions} options - * @return a {@link ExtentKlovReporter} object - */ - public ExtentKlovReporter initMongoDbConnection(ServerAddress addr, MongoClientOptions options) { - mongoClient = new MongoClient(addr, options); - return this; - } - - /** - * Initializes the Mongo DB connection with a connection url - * - * @param url Url string - * @return a {@link ExtentKlovReporter} object - */ - public ExtentKlovReporter initKlovServerConnection(String url) { - this.url = url; - return this; - } - - public void loadInitializationParams(InputStream is) { - init(null, config); - loadConfig(is); - loadInitializationParams(); - } - - public void loadInitializationParams(String propertiesPath) throws FileNotFoundException { - init(null, config); - File f = new File(propertiesPath); - if (f.exists()) { - InputStream stream = new FileInputStream(f); - loadInitializationParams(stream); - } - } - - public void loadInitializationParams(Properties props) { - init(null, config); - loadConfig(props); - loadInitializationParams(); - } - - private void loadInitializationParams() { - String mongoUri = getConfigValue(DEFAULT_MONGODB_URI_PROP); - if (mongoUri == null || mongoUri.isEmpty()) { - String mongoHost = getConfigValue(DEFAULT_MONGODB_HOST_PROP); - String mongoPort = getConfigValue(DEFAULT_MONGODB_PORT_PROP); - int mongoPortInt = IntUtil.tryParseInt(mongoPort) == true ? Integer.valueOf(mongoPort) : -1; - if (mongoHost != null && mongoPortInt != -1) { - initMongoDbConnection(mongoHost, mongoPortInt); - } else if (mongoHost != null) { - initMongoDbConnection(mongoHost); - } - } else { - initMongoDbConnection(new MongoClientURI(mongoUri)); - } - - String projectName = System.getProperty(DEFAULT_PROJECT_NAME_PROP); - projectName = projectName == null || projectName.isEmpty() ? getConfigValue(DEFAULT_PROJECT_NAME_PROP) - : projectName; - this.projectName = projectName == null || projectName.isEmpty() ? this.projectName : projectName; - - String reportName = System.getProperty(DEFAULT_REPORT_NAME_PROP); - reportName = reportName == null || reportName.isEmpty() ? getConfigValue(DEFAULT_REPORT_NAME_PROP) : reportName; - reportName = reportName == null || reportName.isEmpty() ? this.reportName : reportName; - this.reportName = reportName; - - String klovHost = getConfigValue(DEFAULT_KLOV_HOST_PROP); - String klovPort = getConfigValue(DEFAULT_KLOV_PORT_PROP); - - if (klovHost != null && klovPort != null) { - String uri = klovHost + ":" + klovPort; - initKlovServerConnection(uri); - } else if (klovHost != null) { - initKlovServerConnection(klovHost); - } - } - - private String getConfigValue(String key) { - return String.valueOf(getConfigurationStore().getConfig(key)); - } - - @Override - public void start() { - MongoDatabase db = mongoClient.getDatabase(DB_NAME); - initCollections(db); - setupProject(); - } - - private void initCollections(MongoDatabase db) { - projectCollection = db.getCollection("project"); - reportCollection = db.getCollection("report"); - testCollection = db.getCollection("test"); - logCollection = db.getCollection("log"); - exceptionCollection = db.getCollection("exception"); - mediaCollection = db.getCollection("media"); - categoryCollection = db.getCollection("category"); - authorCollection = db.getCollection("author"); - deviceCollection = db.getCollection("device"); - environmentCollection = db.getCollection("environment"); - } - - private void setupProject() { - String projectName = this.projectName == null || this.projectName.isEmpty() ? DEFAULT_PROJECT_NAME - : this.projectName; - - Document doc = new Document("name", projectName); - Document project = projectCollection.find(doc).first(); - - if (project != null) { - projectId = project.getObjectId("_id"); - } else { - doc.append("createdAt", Calendar.getInstance().getTime()); - projectCollection.insertOne(doc); - projectId = MongoUtil.getId(doc); - } - - setupReport(projectName); - } - - private void setupReport(String projectName) { - String reportName = this.reportName == null || this.reportName.isEmpty() - ? "Build " + Calendar.getInstance().getTimeInMillis() - : this.reportName; - this.reportName = reportName; - - Document doc = new Document("name", reportName).append("startTime", getStartTime()).append("project", projectId) - .append("projectName", projectName); - - reportCollection.insertOne(doc); - reportId = MongoUtil.getId(doc); - } - - @Override - public void stop() { - mongoClient.close(); - } - - @Override - public synchronized void flush(ReportAggregates reportAggregates) { - setEndTime(Calendar.getInstance().getTime()); - this.testList = reportAggregates.getTestList(); - - if (testList == null || testList.isEmpty()) { - return; - } - - this.authorContext = reportAggregates.getAuthorContext(); - this.categoryContext = reportAggregates.getCategoryContext(); - this.deviceContext = reportAggregates.getDeviceContext(); - this.stats = reportAggregates.getReportStatusStats(); - this.systemAttributeContext = reportAggregates.getSystemAttributeContext(); - - Status buildStatus = reportAggregates.getStatus(); - - Document doc = new Document("endTime", getEndTime()).append("duration", getRunDuration()) - .append("status", String.valueOf(buildStatus)).append("parentLength", stats.getParentCount()) - .append("passParentLength", stats.getParentCountPass()) - .append("failParentLength", stats.getParentCountFail()) - .append("fatalParentLength", stats.getParentCountFatal()) - .append("errorParentLength", stats.getParentCountError()) - .append("warningParentLength", stats.getParentCountWarning()) - .append("skipParentLength", stats.getParentCountSkip()) - .append("exceptionsParentLength", stats.getParentCountExceptions()) - .append("childLength", stats.getChildCount()).append("passChildLength", stats.getChildCountPass()) - .append("failChildLength", stats.getChildCountFail()) - .append("fatalChildLength", stats.getChildCountFatal()) - .append("errorChildLength", stats.getChildCountError()) - .append("warningChildLength", stats.getChildCountWarning()) - .append("skipChildLength", stats.getChildCountSkip()) - .append("infoChildLength", stats.getChildCountInfo()) - .append("exceptionsChildLength", stats.getChildCountExceptions()) - .append("grandChildLength", stats.getGrandChildCount()) - .append("passGrandChildLength", stats.getGrandChildCountPass()) - .append("failGrandChildLength", stats.getGrandChildCountFail()) - .append("fatalGrandChildLength", stats.getGrandChildCountFatal()) - .append("errorGrandChildLength", stats.getGrandChildCountError()) - .append("warningGrandChildLength", stats.getGrandChildCountWarning()) - .append("skipGrandChildLength", stats.getGrandChildCountSkip()) - .append("exceptionsGrandChildLength", stats.getGrandChildCountExceptions()) - .append("analysisStrategy", String.valueOf(getAnalysisStrategy())); - - reportCollection.updateOne(new Document("_id", reportId), new Document("$set", doc)); - - insertUpdateSystemAttribute(); - } - - public List getCollectionValues(Map collection) { - if (collection == null || collection.isEmpty()) - return null; - return collection.entrySet().stream().map(Map.Entry::getValue).collect(Collectors.toList()); - } - - private void insertUpdateSystemAttribute() { - List systemAttrList = systemAttributeContext.getSystemAttributeList(); - Document doc; - - for (SystemAttribute attr : systemAttrList) { - doc = new Document("project", projectId) - .append("report", reportId) - .append("name", attr.getName()); - - Document envSingle = environmentCollection.find(doc).first(); - - if (envSingle == null) { - doc.append("value", attr.getValue()); - environmentCollection.insertOne(doc); - } else { - ObjectId id = envSingle.getObjectId("_id"); - doc = new Document("_id", id).append("value", attr.getValue()); - environmentCollection.updateOne(new Document("_id", id), new Document("$set", doc)); - } - } - } - - @Override - public void onTestStarted(Test test) { - onTestStartedHelper(test); - } - - @Override - public synchronized void onNodeStarted(Test node) { - onTestStartedHelper(node); - } - - private void onTestStartedHelper(Test test) { - Document doc = new Document("project", projectId) - .append("report", reportId) - .append("reportName", reportName) - .append("level", test.getLevel()) - .append("name", test.getName()) - .append("status", test.getStatus().toString()) - .append("description", test.getDescription()) - .append("startTime", test.getStartTime()) - .append("endTime", test.getEndTime()) - .append("bdd", test.isBehaviorDrivenType()) - .append("leaf", test.getNodeContext().isEmpty()) - .append("childNodesLength", test.getNodeContext().size()); - - if (test.isBehaviorDrivenType()) { - doc.append("bddType", test.getBehaviorDrivenTypeName()); - } - - if (test.getParent() != null) { - doc.append("parent", test.getParent().getObjectId()) - .append("parentName", test.getParent().getName()); - updateTestChildrenCount(test.getParent()); - updateTestDesc(test.getParent()); - } - - testCollection.insertOne(doc); - ObjectId testId = MongoUtil.getId(doc); - test.setObjectId(testId); - } - - private void updateTestDesc(Test test) { - Document doc = new Document("description", test.getDescription()); - testCollection.updateOne(new Document("_id", test.getObjectId()), new Document("$set", doc)); - } - - private void updateTestChildrenCount(Test test) { - Document doc = new Document("childNodesLength", test.getNodeContext().size()); - testCollection.updateOne(new Document("_id", test.getObjectId()), new Document("$set", doc)); - } - - @Override - public synchronized void onLogAdded(Test test, Log log) { - Document doc = new Document("test", test.getObjectId()) - .append("project", projectId) - .append("report", reportId) - .append("testName", test.getName()) - .append("sequence", log.getSequence()) - .append("status", log.getStatus().toString()) - .append("timestamp", log.getTimestamp()) - .append("details", log.getDetails()); - - if (log.getExceptionInfo() != null) { - doc.append("exception", log.getExceptionInfo().getExceptionName()).append("stacktrace", - log.getExceptionInfo().getStackTrace()); - } - - if (LogService.logHasScreenCapture(log) && log.getScreenCaptureContext().getFirst().isBase64()) { - doc.append("details", log.getDetails() + log.getScreenCaptureContext().getFirst().getSource()); - } - - logCollection.insertOne(doc); - - ObjectId logId = MongoUtil.getId(doc); - log.setObjectId(logId); - - // check for exceptions.. - if (TestService.testHasException(test)) { - if (exceptionNameObjectIdCollection == null) - exceptionNameObjectIdCollection = new HashMap<>(); - - ExceptionInfo ex = test.getExceptionInfoContext().get(0); - - ObjectId exceptionId; - doc = new Document("report", reportId).append("project", projectId).append("name", ex.getExceptionName()); - - FindIterable iterable = exceptionCollection.find(doc); - Document docException = iterable.first(); - - // check if a matching exception name is available in 'Exception' collection - // (MongoDB) - // if a matching exception name is found, associate with this exception's - // ObjectId - if (!exceptionNameObjectIdCollection.containsKey(ex.getExceptionName())) { - if (docException != null) { - exceptionNameObjectIdCollection.put(ex.getExceptionName(), docException.getObjectId("_id")); - } else { - doc = new Document("project", projectId) - .append("report", reportId) - .append("name", ex.getExceptionName()) - .append("stacktrace", ex.getStackTrace()) - .append("testCount", 0); - - exceptionCollection.insertOne(doc); - - exceptionId = MongoUtil.getId(doc); - docException = exceptionCollection.find(new Document("_id", exceptionId)).first(); - - exceptionNameObjectIdCollection.put(ex.getExceptionName(), exceptionId); - } - } - - Integer testCount = ((Integer) (docException.get("testCount"))) + 1; - doc = new Document("testCount", testCount); - - exceptionCollection.updateOne(new Document("_id", docException.getObjectId("_id")), - new Document("$set", doc)); - - doc = new Document("exception", exceptionNameObjectIdCollection.get(ex.getExceptionName())); - - testCollection.updateOne(new Document("_id", test.getObjectId()), new Document("$set", doc)); - updateTestDesc(test); - } - - endTestRecursive(test); - } - - private void endTestRecursive(Test test) { - Document doc = new Document("status", test.getStatus().toString()).append("endTime", test.getEndTime()) - .append("duration", TestService.getRunDurationMillis(test)) - .append("leaf", test.getNodeContext().isEmpty()) - .append("childNodesLength", test.getNodeContext().size()) - .append("categorized", TestService.testHasCategory(test)) - .append("description", test.getDescription()); - - testCollection.updateOne(new Document("_id", test.getObjectId()), new Document("$set", doc)); - - if (test.getLevel() > 0) { - endTestRecursive(test.getParent()); - } - } - - public void assignAttribute(Test test, Attribute attribute, - Map nameObjectIdCollection, MongoCollection mongoCollection, - TestAttributeTestContextStore attributeContext) { - } - - @Override - public void onCategoryAssigned(Test test, Category category) { - assignAttribute(test, category, categoryNameObjectIdCollection, categoryCollection, categoryContext); - } - - @Override - public void onAuthorAssigned(Test test, Author author) { - assignAttribute(test, author, authorNameObjectIdCollection, authorCollection, authorContext); - } - - @Override - public void onScreenCaptureAdded(Test test, ScreenCapture screenCapture) throws IOException { - screenCapture.getBsonId().put("testId", test.getObjectId()); - saveScreenCapture(test, screenCapture); - } - - @Override - public void onScreenCaptureAdded(Log log, ScreenCapture screenCapture) throws IOException { - screenCapture.getBsonId().put("logId", log.getObjectId()); - screenCapture.getBsonId().put("testId", log.getTest().getObjectId()); - saveScreenCapture(log, screenCapture); - } - - private void saveScreenCapture(BasicMongoReportElement el, ScreenCapture screenCapture) throws IOException { - if (mediaStorageHandler == null) { - KlovMedia klovMedia = new KlovMedia(projectId, reportId, mediaCollection); - mediaStorageHandler = new KlovMediaStorageHandler(url, klovMedia); - } - mediaStorageHandler.saveScreenCapture(el, screenCapture); - } - - /** - * Returns the active Project ID - * - * @return A {@link ObjectId} object - */ - public ObjectId getProjectId() { - return projectId; - } - - /** - * Returns the active Report ID - * - * @return A {@link ObjectId} object - */ - public ObjectId getReportId() { - return reportId; - } - - @Override - public void onTestRemoved(Test test) { - } - - @Override - public void onDeviceAssigned(Test test, Device device) { - assignAttribute(test, device, deviceNameObjectIdCollection, deviceCollection, deviceContext); - } - - @Override - public String getReporterName() { - return REPORTER_NAME; - } - -} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/reporter/ExtentLoggerReporter.java b/src/main/java/com/aventstack/extentreports/reporter/ExtentLoggerReporter.java deleted file mode 100644 index 27accad..0000000 --- a/src/main/java/com/aventstack/extentreports/reporter/ExtentLoggerReporter.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.aventstack.extentreports.reporter; - -import java.io.File; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - -import com.aventstack.extentreports.ReportAggregates; -import com.aventstack.extentreports.reporter.configuration.ExtentLoggerReporterConfiguration; - -import freemarker.template.Template; -import freemarker.template.TemplateException; - -/** - * The ExtentHtmlReporter creates a rich standalone HTML file. It allows several - * configuration options via the config() method. - */ -public class ExtentLoggerReporter extends BasicFileReporter { - - private static final Logger logger = Logger.getLogger(ExtentLoggerReporter.class.getName()); - private static final String REPORTER_NAME = "logger"; - private static final String TEMPLATE_NAME = "logger/logger-test.ftl"; - private static final String DASHBOARD_TEMPLATE_NAME = "logger/logger-dashboard.ftl"; - private static final String CATEGORY_TEMPLATE_NAME = "logger/logger-tag.ftl"; - private static final String EXCEPTION_TEMPLATE_NAME = "logger/logger-exception.ftl"; - private static final String[] DEFAULT_CONFIG_FILE_PATH = new String[] { "logger.properties", - "src/main/resources/logger.properties" }; - - private ExtentLoggerReporterConfiguration userConfig = new ExtentLoggerReporterConfiguration(this); - - public ExtentLoggerReporter(String path) { - super(path); - init(DEFAULT_CONFIG_FILE_PATH, config()); - } - - public ExtentLoggerReporter(File file) { - super(file); - init(DEFAULT_CONFIG_FILE_PATH, config()); - } - - public ExtentLoggerReporterConfiguration config() { - return userConfig; - } - - @Override - public synchronized void flush(ReportAggregates reportAggregates) { - super.flush(reportAggregates); - - if (getTestList().isEmpty()) - return; - - if (enforceOfflineMode()) - userConfig.enableOfflineMode(true); - - loadUserConfig(); - - try { - Template template = getFreemarkerConfig().getTemplate(TEMPLATE_NAME); - processTemplate(template, new File(getDestinationPath() + "index.html")); - if (String.valueOf(getConfigurationStore().getConfig("enableDashboard")).equalsIgnoreCase("true")) { - template = getFreemarkerConfig().getTemplate(DASHBOARD_TEMPLATE_NAME); - processTemplate(template, new File(getDestinationPath() + "dashboard.html")); - } - if (!getCategoryContextInfo().getTestAttributeTestContext().isEmpty()) { - template = getFreemarkerConfig().getTemplate(CATEGORY_TEMPLATE_NAME); - processTemplate(template, new File(getDestinationPath() + "tag.html")); - } - if (!getExceptionContextInfo().getExceptionTestContext().isEmpty()) { - template = getFreemarkerConfig().getTemplate(EXCEPTION_TEMPLATE_NAME); - processTemplate(template, new File(getDestinationPath() + "exception.html")); - } - } catch (IOException | TemplateException e) { - logger.log(Level.SEVERE, "An exception occurred", e); - } - } - - @Override - public String getReporterName() { - return REPORTER_NAME; - } - -} diff --git a/src/main/java/com/aventstack/extentreports/reporter/ExtentReporter.java b/src/main/java/com/aventstack/extentreports/reporter/ExtentReporter.java index c867d04..571d5f7 100644 --- a/src/main/java/com/aventstack/extentreports/reporter/ExtentReporter.java +++ b/src/main/java/com/aventstack/extentreports/reporter/ExtentReporter.java @@ -1,38 +1,7 @@ package com.aventstack.extentreports.reporter; -import com.aventstack.extentreports.IAnalysisStrategyMethod; -import com.aventstack.extentreports.ReportAggregates; -import com.aventstack.extentreports.ReportAggregatesListener; -import com.aventstack.extentreports.TestListener; - /** - * Primary interface implemented by each reporter. This interface implements - * {@link TestListener} and {@link ReportAggregatesListener} interface to - * provide additional functionality to each reporter. + * Mark interface */ -public interface ExtentReporter extends TestListener, IAnalysisStrategyMethod { - - /** - * Starts passing run information to the reporter - */ - void start(); - - /** - * Stops the reporter. Ensures no information is passed to the reporter. - */ - void stop(); - - /** - * Write to or update the target source (file, database) - * - * @param reportAggregates a {@link ReportAggregates} object - */ - void flush(ReportAggregates reportAggregates); - - /** - * Get the reporter name - * - * @return reporter name - */ - String getReporterName(); -} \ No newline at end of file +public interface ExtentReporter { +} diff --git a/src/main/java/com/aventstack/extentreports/reporter/ExtentSparkReporter.java b/src/main/java/com/aventstack/extentreports/reporter/ExtentSparkReporter.java index 0ea22ea..8f60dba 100644 --- a/src/main/java/com/aventstack/extentreports/reporter/ExtentSparkReporter.java +++ b/src/main/java/com/aventstack/extentreports/reporter/ExtentSparkReporter.java @@ -2,102 +2,155 @@ import java.io.File; import java.io.IOException; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; import java.util.logging.Logger; -import com.aventstack.extentreports.ReportAggregates; -import com.aventstack.extentreports.reporter.configuration.ExtentSparkReporterConfiguration; -import com.aventstack.extentreports.reporter.configuration.ViewStyle; +import com.aventstack.extentreports.config.external.JsonConfigLoader; +import com.aventstack.extentreports.config.external.XmlConfigLoader; +import com.aventstack.extentreports.model.Report; +import com.aventstack.extentreports.observer.ReportObserver; +import com.aventstack.extentreports.observer.entity.ReportEntity; +import com.aventstack.extentreports.reporter.configuration.EntityFilters; +import com.aventstack.extentreports.reporter.configuration.ExtentSparkReporterConfig; +import com.aventstack.extentreports.reporter.configuration.ViewConfigurer; +import com.aventstack.extentreports.reporter.configuration.ViewsConfigurable; import freemarker.template.Template; import freemarker.template.TemplateException; - -/** - * The ExtentSparkReporter creates a rich standalone spark file. It allows - * several configuration options via the config() method. - */ -public class ExtentSparkReporter extends BasicFileReporter { - - private static final Logger logger = Logger.getLogger(ExtentSparkReporter.class.getName()); - private static final String REPORTER_NAME = "spark"; - private static final String SPA_TEMPLATE_NAME = REPORTER_NAME + "/spark.spa.ftl"; - private static final String TEST_TEMPLATE_NAME = REPORTER_NAME + "/test.ftl"; - private static final String TAG_TEMPLATE_NAME = REPORTER_NAME + "/tag.ftl"; - private static final String EXCEPTION_TEMPLATE_NAME = REPORTER_NAME + "/exception.ftl"; - private static final String DASHBOARD_TEMPLATE_NAME = REPORTER_NAME + "/dashboard.ftl"; - private static final String[] DEFAULT_CONFIG_FILE_PATH = new String[] { "spark.properties", - "src/main/resources/spark.properties" }; - - private ExtentSparkReporterConfiguration externalUserConfiguration = new ExtentSparkReporterConfiguration(this); - private ViewStyle viewStyle = ViewStyle.SPA; - - public ExtentSparkReporter(String path) { - super(path); - init(DEFAULT_CONFIG_FILE_PATH, config()); - } - - public ExtentSparkReporter(File file) { - super(file); - init(DEFAULT_CONFIG_FILE_PATH, config()); - } - - public ExtentSparkReporter(String path, ViewStyle viewStyle) { - this(path); - setViewStyle(viewStyle); - } - - public ExtentSparkReporter(File file, ViewStyle viewStyle) { - this(file); - setViewStyle(viewStyle); - } - - public ExtentSparkReporterConfiguration config() { - return externalUserConfiguration; - } - - private void setViewStyle(ViewStyle viewStyle) { - this.viewStyle = viewStyle; - } - - @Override - public synchronized void flush(ReportAggregates reportAggregates) { - super.flush(reportAggregates); - if (getTestList().isEmpty()) { - return; - } - if (enforceOfflineMode()) { - externalUserConfiguration.enableOfflineMode(true); - } - - loadUserConfig(); - - try { - if (viewStyle == ViewStyle.SPA) { - String fileName = getFileFile().isDirectory() ? getDestinationPath() + "Index.html" : getFilePath(); - Template template = getFreemarkerConfig().getTemplate(SPA_TEMPLATE_NAME); - processTemplate(template, new File(fileName)); - return; - } - Template template = getFreemarkerConfig().getTemplate(TEST_TEMPLATE_NAME); - processTemplate(template, new File(getDestinationPath() + "index.html")); - if (!getCategoryContextInfo().getTestAttributeTestContext().isEmpty()) { - template = getFreemarkerConfig().getTemplate(TAG_TEMPLATE_NAME); - processTemplate(template, new File(getDestinationPath() + "tag.html")); - } - if (!getExceptionContextInfo().getExceptionTestContext().isEmpty()) { - template = getFreemarkerConfig().getTemplate(EXCEPTION_TEMPLATE_NAME); - processTemplate(template, new File(getDestinationPath() + "exception.html")); - } - template = getFreemarkerConfig().getTemplate(DASHBOARD_TEMPLATE_NAME); - processTemplate(template, new File(getDestinationPath() + "dashboard.html")); - } catch (IOException | TemplateException e) { - logger.log(Level.SEVERE, "An exception occurred", e); - } - } - - @Override - public String getReporterName() { - return REPORTER_NAME; - } - -} \ No newline at end of file +import io.reactivex.rxjava3.core.Observer; +import io.reactivex.rxjava3.disposables.Disposable; +import lombok.AccessLevel; +import lombok.Getter; + +@Getter +public class ExtentSparkReporter extends AbstractFileReporter + implements + ReportObserver, + ReporterConfigurable, + ViewsConfigurable, + ReporterFilterable { + private static final Logger logger = Logger.getLogger(ExtentSparkReporter.class.getName()); + private static final String TEMPLATE_LOCATION = "templates/"; + private static final String ENCODING = "UTF-8"; + private static final String REPORTER_NAME = "spark"; + private static final String SPA_TEMPLATE_NAME = REPORTER_NAME + "/spark.spa.ftl"; + private static final String FILE_NAME = "Index.html"; + + private final AtomicBoolean executed = new AtomicBoolean(); + @Getter(value = AccessLevel.NONE) + private final ViewConfigurer viewConfigurer = new ViewConfigurer<>(this); + @Getter(value = AccessLevel.NONE) + private final EntityFilters filter = new EntityFilters<>(this); + + private ExtentSparkReporterConfig conf = ExtentSparkReporterConfig.builder().reporter(this).build(); + private Disposable disposable; + private Report report; + + public ExtentSparkReporter(String path) { + super(new File(path)); + } + + public ExtentSparkReporter(File f) { + super(f); + } + + @Override + public EntityFilters filter() { + return filter; + } + + @Override + public ViewConfigurer viewConfigurer() { + return viewConfigurer; + } + + public ExtentSparkReporterConfig config() { + return conf; + } + + public ExtentSparkReporter config(ExtentSparkReporterConfig conf) { + conf.setReporter(this); + this.conf = conf; + return this; + } + + @Override + public void loadJSONConfig(File jsonFile) throws IOException { + final JsonConfigLoader loader = new JsonConfigLoader(conf, + jsonFile); + loader.apply(); + } + + @Override + public void loadJSONConfig(String jsonString) throws IOException { + final JsonConfigLoader loader = new JsonConfigLoader(conf, + jsonString); + loader.apply(); + } + + @Override + public void loadXMLConfig(File xmlFile) throws IOException { + final XmlConfigLoader loader = new XmlConfigLoader(conf, + xmlFile); + loader.apply(); + } + + @Override + public void loadXMLConfig(String xmlFile) throws IOException { + loadXMLConfig(new File(xmlFile)); + } + + private void executeActions() { + if (!executed.get()) { + conf.enableOfflineMode(conf.getOfflineMode()); + executed.compareAndSet(false, true); + } + } + + @Override + public Observer getReportObserver() { + return new Observer() { + @Override + public void onSubscribe(Disposable d) { + start(d); + } + + @Override + public void onNext(ReportEntity value) { + flush(value); + } + + @Override + public void onError(Throwable e) { + } + + @Override + public void onComplete() { + } + }; + } + + private void start(Disposable d) { + disposable = d; + loadTemplateModel(); + } + + private void flush(ReportEntity value) { + executeActions(); + report = filterAndGet(value.getReport(), filter.statusFilter().getStatus()); + try { + getTemplateModel().put("this", this); + getTemplateModel().put("viewOrder", viewConfigurer.viewOrder().getViewOrder()); + getTemplateModel().put("report", report); + createFreemarkerConfig(TEMPLATE_LOCATION, ENCODING); + final String filePath = getFileNameAsExt(FILE_NAME, new String[]{".html", ".htm"}); + final Template template = getFreemarkerConfig().getTemplate(SPA_TEMPLATE_NAME); + processTemplate(template, new File(filePath)); + return; + } catch (IOException | TemplateException e) { + disposable.dispose(); + logger.log(Level.SEVERE, "An exception occurred", e); + } + } +} diff --git a/src/main/java/com/aventstack/extentreports/reporter/ExtentTabularReporter.java b/src/main/java/com/aventstack/extentreports/reporter/ExtentTabularReporter.java deleted file mode 100644 index ac73203..0000000 --- a/src/main/java/com/aventstack/extentreports/reporter/ExtentTabularReporter.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.aventstack.extentreports.reporter; - -import java.io.File; - -import com.aventstack.extentreports.ReportAggregates; - -/** - * The ExtentHtmlReporter creates a rich standalone HTML file. It allows several configuration options - * via the config() method. - */ -public class ExtentTabularReporter - extends BasicFileReporter { - - private static final String REPORTER_NAME = "tabular"; - - public ExtentTabularReporter(String path) { - super(path); - } - - public ExtentTabularReporter(File file) { - super(file); - } - - @Override - public synchronized void flush(ReportAggregates reportAggregates) { - } - - @Override - public String getReporterName() { - return REPORTER_NAME; - } - -} diff --git a/src/main/java/com/aventstack/extentreports/reporter/JsonFormatter.java b/src/main/java/com/aventstack/extentreports/reporter/JsonFormatter.java index 1e4b062..ca6a4bb 100644 --- a/src/main/java/com/aventstack/extentreports/reporter/JsonFormatter.java +++ b/src/main/java/com/aventstack/extentreports/reporter/JsonFormatter.java @@ -5,42 +5,75 @@ import java.io.IOException; import java.util.List; -import com.aventstack.extentreports.ReportAggregates; +import com.aventstack.extentreports.gson.GsonExtentTypeAdapterBuilder; import com.aventstack.extentreports.model.Test; +import com.aventstack.extentreports.observer.ReportObserver; +import com.aventstack.extentreports.observer.entity.ReportEntity; import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - -public class JsonFormatter extends BasicFileReporter { - - public JsonFormatter(String path) { - super(path); - } - - public JsonFormatter(File file) { - super(file); - } - - @Override - public void start() { - - } - - @Override - public synchronized void flush(ReportAggregates reportAggregates) { - super.flush(reportAggregates); - GsonBuilder builder = new GsonBuilder(); - Gson gson = builder.create(); - try (FileWriter writer = new FileWriter(getFilePath())) { - List list = reportAggregates.getTestList(); - gson.toJson(list, writer); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public String getReporterName() { - return "JSON"; - } +import io.reactivex.rxjava3.core.Observer; +import io.reactivex.rxjava3.disposables.Disposable; + +public class JsonFormatter extends AbstractFileReporter implements ReporterConfigurable, ReportObserver { + private static final String FILE_NAME = "extent.json"; + + public JsonFormatter(File file) { + super(file); + } + + public JsonFormatter(String filePath) { + super(new File(filePath)); + } + + @Override + public Observer getReportObserver() { + return new Observer() { + @Override + public void onSubscribe(Disposable d) { + } + + @Override + public void onNext(ReportEntity value) { + flush(value); + } + + @Override + public void onError(Throwable e) { + } + + @Override + public void onComplete() { + } + }; + } + + private void flush(ReportEntity value) { + Gson gson = GsonExtentTypeAdapterBuilder.builder() + .withBddTypeAdapterFactory() + .build(); + final String filePath = getFileNameAsExt(FILE_NAME, new String[]{".json"}); + try (FileWriter writer = new FileWriter(new File(filePath))) { + List list = value.getReport().getTestList(); + gson.toJson(list, writer); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void loadJSONConfig(File jsonFile) throws IOException { + } + + @Override + public void loadJSONConfig(String jsonString) throws IOException { + + } + + @Override + public void loadXMLConfig(File xmlFile) throws IOException { + } + + @Override + public void loadXMLConfig(String xmlFile) throws IOException { + } } diff --git a/src/main/java/com/aventstack/extentreports/reporter/ReportAppendable.java b/src/main/java/com/aventstack/extentreports/reporter/ReportAppendable.java deleted file mode 100644 index ecb10da..0000000 --- a/src/main/java/com/aventstack/extentreports/reporter/ReportAppendable.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.aventstack.extentreports.reporter; - -public interface ReportAppendable { - - void setAppendExisting(Boolean b); - -} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/reporter/ReporterConfigurable.java b/src/main/java/com/aventstack/extentreports/reporter/ReporterConfigurable.java new file mode 100644 index 0000000..0341c1e --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/reporter/ReporterConfigurable.java @@ -0,0 +1,11 @@ +package com.aventstack.extentreports.reporter; + +import java.io.File; +import java.io.IOException; + +public interface ReporterConfigurable { + void loadJSONConfig(File jsonFile) throws IOException; + void loadJSONConfig(String jsonString) throws IOException; + void loadXMLConfig(File xmlFile) throws IOException; + void loadXMLConfig(String xmlFile) throws IOException; +} diff --git a/src/main/java/com/aventstack/extentreports/reporter/ReporterFilterable.java b/src/main/java/com/aventstack/extentreports/reporter/ReporterFilterable.java new file mode 100644 index 0000000..eaac16f --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/reporter/ReporterFilterable.java @@ -0,0 +1,8 @@ +package com.aventstack.extentreports.reporter; + +import com.aventstack.extentreports.reporter.configuration.EntityFilters; + +@FunctionalInterface +public interface ReporterFilterable { + EntityFilters filter(); +} diff --git a/src/main/java/com/aventstack/extentreports/reporter/TestListener.java b/src/main/java/com/aventstack/extentreports/reporter/TestListener.java deleted file mode 100644 index 6916f46..0000000 --- a/src/main/java/com/aventstack/extentreports/reporter/TestListener.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.aventstack.extentreports.reporter; - -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 onLogCreated(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 onScreenCaptureCreated(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 onScreenCaptureCreated(Log log, ScreenCapture screenCapture) throws IOException; - -} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/reporter/configuration/AbstractConfiguration.java b/src/main/java/com/aventstack/extentreports/reporter/configuration/AbstractConfiguration.java new file mode 100644 index 0000000..2bc8f03 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/reporter/configuration/AbstractConfiguration.java @@ -0,0 +1,22 @@ +package com.aventstack.extentreports.reporter.configuration; + +import com.aventstack.extentreports.config.ConfigStore; +import com.aventstack.extentreports.reporter.AbstractReporter; + +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.SuperBuilder; + +@Getter +@Setter +@SuperBuilder +public abstract class AbstractConfiguration { + protected AbstractReporter reporter; + private final ConfigStore store = new ConfigStore(); + + @Builder.Default + private String timeStampFormat = "MMM d, yyyy hh:mm:ss a"; + @Builder.Default + private String reportName = ""; +} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/reporter/configuration/BasicConfiguration.java b/src/main/java/com/aventstack/extentreports/reporter/configuration/BasicConfiguration.java deleted file mode 100644 index cd1a10a..0000000 --- a/src/main/java/com/aventstack/extentreports/reporter/configuration/BasicConfiguration.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.aventstack.extentreports.reporter.configuration; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Optional; - -import com.aventstack.extentreports.Status; -import com.aventstack.extentreports.configuration.ConfigurationStore; -import com.aventstack.extentreports.reporter.AbstractReporter; - -public abstract class BasicConfiguration { - - private ConfigurationStore store = new ConfigurationStore(); - private AbstractReporter reporter; - private List levels; - - protected BasicConfiguration(AbstractReporter reporter) { - this.reporter = reporter; - } - - protected AbstractReporter getReporter() { - return reporter; - } - - public ConfigurationStore getConfigurationStore() { - return store; - } - - public void setLevel(Status... level) { - if (levels == null) { - levels = new ArrayList<>(); - } - Arrays.stream(level).forEach(levels::add); - } - - public List getLevel() { - return levels; - } - - public String getReportName() { - return (String) Optional.ofNullable(getConfigurationStore().getConfig("reportName")).orElse(null); - } - - public void setReportName(String reportName) { - store.storeConfig("reportName", reportName); - } - -} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/reporter/configuration/BasicFileConfiguration.java b/src/main/java/com/aventstack/extentreports/reporter/configuration/BasicFileConfiguration.java deleted file mode 100644 index 75432b2..0000000 --- a/src/main/java/com/aventstack/extentreports/reporter/configuration/BasicFileConfiguration.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.aventstack.extentreports.reporter.configuration; - -import java.util.Optional; - -import com.aventstack.extentreports.reporter.AbstractReporter; - -/** - * Common configuration for file based reporters - * - */ -public abstract class BasicFileConfiguration extends BasicConfiguration { - - protected BasicFileConfiguration(AbstractReporter reporter) { - super(reporter); - } - - /** - * Gets the timestamp format - * - * @return The time stamp format - */ - public String getTimeStampFormat() { - return (String) Optional.ofNullable(getConfigurationStore().getConfig("timeStampFormat")).orElse(null); - } - - /** - * Sets the timestamp format - * - * @param timeStampFormat The desired time stamp format See - * http://freemarker.org/docs/ref_builtins_date.html#ref_builtin_string_for_date - */ - public void setTimeStampFormat(String timeStampFormat) { - getConfigurationStore().storeConfig("timeStampFormat", timeStampFormat); - } - - /** - * Sets file encoding, eg: UTF-8 - * - * @param encoding Encoding - */ - public void setEncoding(String encoding) { - getConfigurationStore().storeConfig("encoding", encoding); - } - - public String getEncoding() { - return (String) Optional.ofNullable(getConfigurationStore().getConfig("encoding")).orElse(null); - } - - /** - * Sets the document title denoted by the title tag - * - * @param documentTitle Title - */ - public void setDocumentTitle(String documentTitle) { - getConfigurationStore().storeConfig("documentTitle", documentTitle); - } - - public String getDocumentTitle() { - return (String) Optional.ofNullable(getConfigurationStore().getConfig("documentTitle")).orElse(null); - } - - /** - * Sets CSS to be used to customize the look and feel of your report - * - * @param css CSS - */ - public void setCSS(String css) { - getConfigurationStore().storeConfig("css", css); - } - - public String getCSS() { - return (String) Optional.ofNullable(getConfigurationStore().getConfig("css")).orElse(null); - } - - /** - * Adds custom JavaScript - * - * @param js JavaScript - */ - public void setJS(String js) { - getConfigurationStore().storeConfig("js", js); - } - - public String getJS() { - return (String) Optional.ofNullable(getConfigurationStore().getConfig("js")).orElse(null); - } - -} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/reporter/configuration/EntityFilters.java b/src/main/java/com/aventstack/extentreports/reporter/configuration/EntityFilters.java new file mode 100644 index 0000000..3267dd4 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/reporter/configuration/EntityFilters.java @@ -0,0 +1,22 @@ +package com.aventstack.extentreports.reporter.configuration; + +import com.aventstack.extentreports.reporter.AbstractReporter; + +import lombok.Getter; +import lombok.experimental.Accessors; + +@Getter +@Accessors(fluent = true) +public class EntityFilters { + private final T reporter; + private final StatusFilter statusFilter; + + public EntityFilters(T reporter) { + this.reporter = reporter; + statusFilter = new StatusFilter(this); + } + + public T apply() { + return reporter; + } +} diff --git a/src/main/java/com/aventstack/extentreports/reporter/configuration/ExtentHtmlReporterConfiguration.java b/src/main/java/com/aventstack/extentreports/reporter/configuration/ExtentHtmlReporterConfiguration.java deleted file mode 100644 index 578b62b..0000000 --- a/src/main/java/com/aventstack/extentreports/reporter/configuration/ExtentHtmlReporterConfiguration.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.aventstack.extentreports.reporter.configuration; - -import java.io.File; -import java.util.stream.Stream; - -import com.aventstack.extentreports.ExtentReports; -import com.aventstack.extentreports.offline.OfflineResxDelegate; -import com.aventstack.extentreports.reporter.BasicFileReporter; -import com.aventstack.extentreports.utils.FileUtil; - -/** - * Defines configuration settings for the Spark reporter - */ -public class ExtentHtmlReporterConfiguration extends RichViewReporterConfiguration { - - @SuppressWarnings("deprecation") - public ExtentHtmlReporterConfiguration(com.aventstack.extentreports.reporter.ExtentHtmlReporter reporter) { - super(reporter); - } - - /** - * Creates the HTML report, saving all resources (css, js, fonts) in the same - * location, so the report can be viewed without an internet connection - * - * @param offline Setting to enable an offline accessible report - */ - public void enableOfflineMode(Boolean offline) { - getConfigurationStore().storeConfig("enableOfflineMode", String.valueOf(offline)); - getConfigurationStore().storeConfig("offlineDirectory", getReporter().getReporterName() + "/"); - if (offline) { - File f = getTargetDirectory(((BasicFileReporter) getReporter()).getFileFile()); - String s = "/"; - String resourcePackagePath = ExtentReports.class.getPackage().getName().replace(".", s); - resourcePackagePath += s + "offline" + s; - String[] resx = combine(getJSFiles(), getCSSFiles(), getIconFiles(), getImgFiles()); - OfflineResxDelegate.saveOfflineResources(resourcePackagePath, resx, f.getAbsolutePath()); - } - } - - private File getTargetDirectory(File f) { - String dir; - if (FileUtil.isDirectory(f)) { - dir = f.getAbsolutePath().replace("\\", "/"); - } else { - dir = f.getAbsolutePath().replace("\\", "/"); - dir = new File(dir).getParent(); - } - dir += "/" + getReporter().getReporterName(); - return new File(dir); - } - - private String[] combine(String[]... array) { - String[] result = new String[] {}; - for (String[] arr : array) { - result = Stream.of(result, arr).flatMap(Stream::of).toArray(String[]::new); - } - return result; - } - - private String[] getJSFiles() { - String commonsPath = "commons/js/"; - String reporterPath = getReporter().getReporterName() + "/js/"; - String[] files = { reporterPath + "spark-script.js", commonsPath + "jsontree.js" }; - return files; - } - - private String[] getCSSFiles() { - String stylesPath = "css/"; - String reporterPath = getReporter().getReporterName() + "/" + stylesPath; - String[] files = { reporterPath + "spark-style.css" }; - return files; - } - - private String[] getIconFiles() { - String path = "commons/css/icons/"; - String iconDirPath = "fontawesome/"; - String[] files = { path + "font-awesome.min.css", path + iconDirPath + "fontawesome-webfont.eot", - path + iconDirPath + "fontawesome-webfont.svg", path + iconDirPath + "fontawesome-webfont.ttf", - path + iconDirPath + "fontawesome-webfont.woff", path + iconDirPath + "fontawesome-webfont.woff2", - path + iconDirPath + "FontAwesome.otf" }; - return files; - } - - private String[] getImgFiles() { - String path = "commons/img/"; - String[] files = { path + "logo.png" }; - return files; - } - -} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/reporter/configuration/ExtentKlovReporterConfiguration.java b/src/main/java/com/aventstack/extentreports/reporter/configuration/ExtentKlovReporterConfiguration.java deleted file mode 100644 index c222c0a..0000000 --- a/src/main/java/com/aventstack/extentreports/reporter/configuration/ExtentKlovReporterConfiguration.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.aventstack.extentreports.reporter.configuration; - -import com.aventstack.extentreports.reporter.AbstractReporter; - -public class ExtentKlovReporterConfiguration extends RichViewReporterConfiguration { - - public ExtentKlovReporterConfiguration(AbstractReporter reporter) { - super(reporter); - } - -} diff --git a/src/main/java/com/aventstack/extentreports/reporter/configuration/ExtentLoggerReporterConfiguration.java b/src/main/java/com/aventstack/extentreports/reporter/configuration/ExtentLoggerReporterConfiguration.java deleted file mode 100644 index 781bcca..0000000 --- a/src/main/java/com/aventstack/extentreports/reporter/configuration/ExtentLoggerReporterConfiguration.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.aventstack.extentreports.reporter.configuration; - -import java.io.File; -import java.util.stream.Stream; - -import com.aventstack.extentreports.ExtentReports; -import com.aventstack.extentreports.offline.OfflineResxDelegate; -import com.aventstack.extentreports.reporter.AbstractReporter; -import com.aventstack.extentreports.reporter.ExtentLoggerReporter; -import com.aventstack.extentreports.utils.FileUtil; - -/** - * Defines configuration settings for the HTML reporter - */ -public class ExtentLoggerReporterConfiguration extends RichViewReporterConfiguration { - - public ExtentLoggerReporterConfiguration(AbstractReporter reporter) { - super(reporter); - } - - /** - * Creates the HTML report, saving all resources (css, js, fonts) in the same - * location, so the report can be viewed without an internet connection - * - * @param offline Setting to enable an offline accessible report - */ - public void enableOfflineMode(Boolean offline) { - getConfigurationStore().storeConfig("enableOfflineMode", String.valueOf(offline)); - getConfigurationStore().storeConfig("offlineDirectory", getReporter().getReporterName() + "/"); - if (offline) { - File f = getTargetDirectory(((ExtentLoggerReporter) getReporter()).getFileFile()); - String s = "/"; - String resourcePackagePath = ExtentReports.class.getPackage().getName().replace(".", s); - resourcePackagePath += s + "offline" + s; - String[] resx = combine(getJSFiles(), getCSSFiles(), getIconFiles(), getImgFiles()); - OfflineResxDelegate.saveOfflineResources(resourcePackagePath, resx, f.getAbsolutePath()); - } - } - - private File getTargetDirectory(File f) { - String dir; - if (FileUtil.isDirectory(f)) { - dir = f.getAbsolutePath().replace("\\", "/"); - } else { - dir = f.getAbsolutePath().replace("\\", "/"); - dir = new File(dir).getParent(); - } - dir += "/" + getReporter().getReporterName(); - return new File(dir); - } - - private String[] combine(String[]... array) { - String[] result = new String[] {}; - for (String[] arr : array) { - result = Stream.of(result, arr).flatMap(Stream::of).toArray(String[]::new); - } - return result; - } - - private String[] getJSFiles() { - String commonsPath = "commons/js/"; - String reporterPath = getReporter().getReporterName() + "/js/"; - String[] files = { commonsPath + "attr.js", commonsPath + "dashboard.js", reporterPath + "logger-scripts.js" }; - return files; - } - - private String[] getCSSFiles() { - String stylesPath = "css/"; - String reporterPath = getReporter().getReporterName() + "/" + stylesPath + "/"; - String[] files = { reporterPath + "logger-style.css", }; - return files; - } - - private String[] getIconFiles() { - String path = "commons/css/icons/"; - String iconDirPath = "fontawesome/"; - String[] files = { path + "font-awesome.min.css", path + iconDirPath + "fontawesome-webfont.eot", - path + iconDirPath + "fontawesome-webfont.svg", path + iconDirPath + "fontawesome-webfont.ttf", - path + iconDirPath + "fontawesome-webfont.woff", path + iconDirPath + "fontawesome-webfont.woff2", - path + iconDirPath + "FontAwesome.otf", }; - return files; - } - - private String[] getImgFiles() { - String path = "commons/img/"; - String[] files = { path + "logo.png" }; - return files; - } - -} diff --git a/src/main/java/com/aventstack/extentreports/reporter/configuration/ExtentSparkReporterConfig.java b/src/main/java/com/aventstack/extentreports/reporter/configuration/ExtentSparkReporterConfig.java new file mode 100644 index 0000000..a719521 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/reporter/configuration/ExtentSparkReporterConfig.java @@ -0,0 +1,102 @@ +package com.aventstack.extentreports.reporter.configuration; + +import java.io.File; +import java.util.stream.Stream; + +import com.aventstack.extentreports.ExtentReports; +import com.aventstack.extentreports.reporter.ExtentSparkReporter; +import com.aventstack.extentreports.reporter.configuration.util.ResourceHelper; + +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.SuperBuilder; + +/** + * Defines configuration settings for the Spark reporter + */ +@Getter +@Setter +@SuperBuilder +public class ExtentSparkReporterConfig extends InteractiveReporterConfig { + private static final String REPORTER_NAME = "spark"; + private static final String SEP = "/"; + private static final String COMMONS = "commons" + SEP; + private static final String CSS = "css" + SEP; + private static final String JS = "js" + SEP; + private static final String ICONS = "icons" + SEP; + private static final String IMG = "img" + SEP; + + @Builder.Default + private Boolean offlineMode = false; + @Builder.Default + private String resourceCDN = "github"; + + /** + * Creates the HTML report, saving all resources (css, js, fonts) in the + * same location, so the report can be viewed without an internet connection + * + * @param offlineMode + * Setting to enable an offline accessible report + */ + public void enableOfflineMode(Boolean offlineMode) { + this.offlineMode = offlineMode; + if (offlineMode && reporter != null) { + File f = Offline.getTargetDirectory(((ExtentSparkReporter) reporter).getFile()); + String resPackage = ExtentReports.class.getPackage().getName().replace(".", SEP); + resPackage += SEP + "offline" + SEP; + String[] resx = Offline.combineAll(); + ResourceHelper.saveOfflineResources(resPackage, resx, f.getAbsolutePath()); + } + } + + private static class Offline { + private static File getTargetDirectory(File f) { + String dir = f.getAbsolutePath().replace("\\", SEP); + if (!f.isDirectory()) + dir = new File(dir).getParent(); + dir += "/" + REPORTER_NAME; + return new File(dir); + } + + private static String[] combineAll() { + return combine(getJSFiles(), getCSSFiles(), getIconFiles(), getImgFiles()); + } + + private static String[] combine(String[]... array) { + String[] result = new String[]{}; + for (String[] arr : array) + result = Stream.of(result, arr).flatMap(Stream::of).toArray(String[]::new); + return result; + } + + private static String[] getJSFiles() { + final String commonsPath = COMMONS + JS; + final String reporterPath = REPORTER_NAME + SEP + JS; + final String[] files = {reporterPath + "spark-script.js", commonsPath + "jsontree.js"}; + return files; + } + + private static String[] getCSSFiles() { + final String reporterPath = REPORTER_NAME + SEP + CSS; + final String[] files = {reporterPath + "spark-style.css"}; + return files; + } + + private static String[] getIconFiles() { + final String path = COMMONS + CSS + ICONS; + final String iconDirPath = "fontawesome" + SEP; + final String[] files = {path + "font-awesome.min.css", path + iconDirPath + "fontawesome-webfont.eot", + path + iconDirPath + "fontawesome-webfont.svg", path + iconDirPath + "fontawesome-webfont.ttf", + path + iconDirPath + "fontawesome-webfont.woff", path + iconDirPath + "fontawesome-webfont.woff2", + path + iconDirPath + "FontAwesome.otf"}; + return files; + } + + private static String[] getImgFiles() { + final String path = COMMONS + IMG; + final String[] files = {path + "logo.png"}; + return files; + } + } +} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/reporter/configuration/ExtentSparkReporterConfiguration.java b/src/main/java/com/aventstack/extentreports/reporter/configuration/ExtentSparkReporterConfiguration.java deleted file mode 100644 index 2ba9185..0000000 --- a/src/main/java/com/aventstack/extentreports/reporter/configuration/ExtentSparkReporterConfiguration.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.aventstack.extentreports.reporter.configuration; - -import java.io.File; -import java.util.stream.Stream; - -import com.aventstack.extentreports.ExtentReports; -import com.aventstack.extentreports.offline.OfflineResxDelegate; -import com.aventstack.extentreports.reporter.ExtentSparkReporter; -import com.aventstack.extentreports.utils.FileUtil; - -/** - * Defines configuration settings for the Spark reporter - */ -public class ExtentSparkReporterConfiguration extends RichViewReporterConfiguration { - - public ExtentSparkReporterConfiguration(ExtentSparkReporter reporter) { - super(reporter); - } - - /** - * Creates the HTML report, saving all resources (css, js, fonts) in the same - * location, so the report can be viewed without an internet connection - * - * @param offline Setting to enable an offline accessible report - */ - public void enableOfflineMode(Boolean offline) { - getConfigurationStore().storeConfig("enableOfflineMode", String.valueOf(offline)); - getConfigurationStore().storeConfig("offlineDirectory", getReporter().getReporterName() + "/"); - if (offline) { - File f = getTargetDirectory(((ExtentSparkReporter) getReporter()).getFileFile()); - String s = "/"; - String resourcePackagePath = ExtentReports.class.getPackage().getName().replace(".", s); - resourcePackagePath += s + "offline" + s; - String[] resx = combine(getJSFiles(), getCSSFiles(), getIconFiles(), getImgFiles()); - OfflineResxDelegate.saveOfflineResources(resourcePackagePath, resx, f.getAbsolutePath()); - } - } - - private File getTargetDirectory(File f) { - String dir; - if (FileUtil.isDirectory(f)) { - dir = f.getAbsolutePath().replace("\\", "/"); - } else { - dir = f.getAbsolutePath().replace("\\", "/"); - dir = new File(dir).getParent(); - } - dir += "/" + getReporter().getReporterName(); - return new File(dir); - } - - private String[] combine(String[]... array) { - String[] result = new String[] {}; - for (String[] arr : array) { - result = Stream.of(result, arr).flatMap(Stream::of).toArray(String[]::new); - } - return result; - } - - private String[] getJSFiles() { - String commonsPath = "commons/js/"; - String reporterPath = getReporter().getReporterName() + "/js/"; - String[] files = { reporterPath + "spark-script.js", commonsPath + "jsontree.js" }; - return files; - } - - private String[] getCSSFiles() { - String stylesPath = "css/"; - String reporterPath = getReporter().getReporterName() + "/" + stylesPath; - String[] files = { reporterPath + "spark-style.css" }; - return files; - } - - private String[] getIconFiles() { - String path = "commons/css/icons/"; - String iconDirPath = "fontawesome/"; - String[] files = { path + "font-awesome.min.css", path + iconDirPath + "fontawesome-webfont.eot", - path + iconDirPath + "fontawesome-webfont.svg", path + iconDirPath + "fontawesome-webfont.ttf", - path + iconDirPath + "fontawesome-webfont.woff", path + iconDirPath + "fontawesome-webfont.woff2", - path + iconDirPath + "FontAwesome.otf" }; - return files; - } - - private String[] getImgFiles() { - String path = "commons/img/"; - String[] files = { path + "logo.png" }; - return files; - } - -} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/reporter/configuration/FileReporterConfig.java b/src/main/java/com/aventstack/extentreports/reporter/configuration/FileReporterConfig.java new file mode 100644 index 0000000..6c8c53e --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/reporter/configuration/FileReporterConfig.java @@ -0,0 +1,16 @@ +package com.aventstack.extentreports.reporter.configuration; + +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.SuperBuilder; + +@Getter +@Setter +@SuperBuilder(builderMethodName = "with") +public abstract class FileReporterConfig extends AbstractConfiguration { + @Builder.Default + private String encoding = "UTF-8"; + @Builder.Default + private String documentTitle = ""; +} diff --git a/src/main/java/com/aventstack/extentreports/reporter/configuration/IReporterConfiguration.java b/src/main/java/com/aventstack/extentreports/reporter/configuration/IReporterConfiguration.java deleted file mode 100644 index 9cac8d2..0000000 --- a/src/main/java/com/aventstack/extentreports/reporter/configuration/IReporterConfiguration.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.aventstack.extentreports.reporter.configuration; - -public interface IReporterConfiguration { - -} diff --git a/src/main/java/com/aventstack/extentreports/reporter/configuration/InteractiveReporterConfig.java b/src/main/java/com/aventstack/extentreports/reporter/configuration/InteractiveReporterConfig.java new file mode 100644 index 0000000..09cb070 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/reporter/configuration/InteractiveReporterConfig.java @@ -0,0 +1,22 @@ +package com.aventstack.extentreports.reporter.configuration; + +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.SuperBuilder; + +@Getter +@Setter +@SuperBuilder +public class InteractiveReporterConfig extends FileReporterConfig { + @Builder.Default + private Protocol protocol = Protocol.HTTP; + @Builder.Default + private Theme theme = Theme.STANDARD; + @Builder.Default + private boolean timelineEnabled = true; + @Builder.Default + private String css = ""; + @Builder.Default + private String js = ""; +} diff --git a/src/main/java/com/aventstack/extentreports/reporter/configuration/Protocol.java b/src/main/java/com/aventstack/extentreports/reporter/configuration/Protocol.java index 6818afa..135b80e 100644 --- a/src/main/java/com/aventstack/extentreports/reporter/configuration/Protocol.java +++ b/src/main/java/com/aventstack/extentreports/reporter/configuration/Protocol.java @@ -1,8 +1,13 @@ package com.aventstack.extentreports.reporter.configuration; +import com.google.gson.annotations.SerializedName; + /** * Protocol used to download CDN css/js resources for HTML reports */ public enum Protocol { - HTTP, HTTPS + @SerializedName(value = "http", alternate = {"HTTP"}) + HTTP, + @SerializedName(value = "https", alternate = {"HTTPS"}) + HTTPS } \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/reporter/configuration/RichViewReporterConfiguration.java b/src/main/java/com/aventstack/extentreports/reporter/configuration/RichViewReporterConfiguration.java deleted file mode 100644 index f1c468b..0000000 --- a/src/main/java/com/aventstack/extentreports/reporter/configuration/RichViewReporterConfiguration.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.aventstack.extentreports.reporter.configuration; - -import com.aventstack.extentreports.reporter.AbstractReporter; - -/** - * Contains configuration for rich reporters such as Avent, Tabular, Cards etc. - * - */ -public abstract class RichViewReporterConfiguration extends BasicFileConfiguration implements IReporterConfiguration { - - protected RichViewReporterConfiguration(AbstractReporter reporter) { - super(reporter); - } - - /** - * Sets the protocol of accessing CSS/JS resources from CDN - * - *

    - * Default protocol value: HTTPS - *

    - * - * @param protocol Protocol, HTTPS or HTTP - */ - public void setProtocol(Protocol protocol) { - getConfigurationStore().storeConfig("protocol", String.valueOf(protocol).toLowerCase()); - } - - public Protocol getProtocol() { - if (getConfigurationStore().containsConfig("protocol")) { - return (Protocol) getConfigurationStore().getConfig("protocol"); - } - return null; - } - - /** - * Sets the {@link Theme} of the report - * - * @param theme {@link Theme} - */ - public void setTheme(Theme theme) { - getConfigurationStore().storeConfig("theme", String.valueOf(theme).toLowerCase()); - } - - public Theme getTheme() { - if (getConfigurationStore().containsConfig("theme")) { - return Theme.valueOf(getConfigurationStore().getConfig("theme").toString()); - } - return null; - } - - /** - * Enable or disable the Timeline section in the Dashboard view - * - * @param v Setting to enable or disable the Timeline section in the Dashboard - * view - */ - public void enableTimeline(boolean v) { - getConfigurationStore().storeConfig("enableTimeline", String.valueOf(v).toLowerCase()); - } - -} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/reporter/configuration/StatusFilter.java b/src/main/java/com/aventstack/extentreports/reporter/configuration/StatusFilter.java new file mode 100644 index 0000000..890b285 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/reporter/configuration/StatusFilter.java @@ -0,0 +1,35 @@ +package com.aventstack.extentreports.reporter.configuration; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import com.aventstack.extentreports.Status; +import com.aventstack.extentreports.reporter.AbstractReporter; + +import lombok.Getter; + +@Getter +public class StatusFilter { + private Set status; + private EntityFilters configurer; + + public StatusFilter(EntityFilters configurer) { + this.configurer = configurer; + } + + @SuppressWarnings("unchecked") + public EntityFilters as(Set status) { + this.status = status; + return (EntityFilters) configurer; + } + + public EntityFilters as(List status) { + return as(new HashSet<>(status)); + } + + public EntityFilters as(Status[] status) { + return as(Arrays.asList(status)); + } +} diff --git a/src/main/java/com/aventstack/extentreports/reporter/configuration/Theme.java b/src/main/java/com/aventstack/extentreports/reporter/configuration/Theme.java index 7f0a8dc..124f420 100644 --- a/src/main/java/com/aventstack/extentreports/reporter/configuration/Theme.java +++ b/src/main/java/com/aventstack/extentreports/reporter/configuration/Theme.java @@ -1,8 +1,27 @@ package com.aventstack.extentreports.reporter.configuration; +import com.google.gson.annotations.SerializedName; + +import lombok.Getter; + /** * Available themes for the HTML reporter */ +@Getter public enum Theme { - STANDARD, DARK + @SerializedName(value = "standard", alternate = {"STANDARD"}) + STANDARD("standard"), + @SerializedName(value = "dark", alternate = {"DARK"}) + DARK("dark"); + + private final String name; + + Theme(String name) { + this.name = name.toLowerCase(); + } + + @Override + public String toString() { + return name; + } } \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/reporter/configuration/ViewConfigurer.java b/src/main/java/com/aventstack/extentreports/reporter/configuration/ViewConfigurer.java new file mode 100644 index 0000000..8187db0 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/reporter/configuration/ViewConfigurer.java @@ -0,0 +1,20 @@ +package com.aventstack.extentreports.reporter.configuration; + +import lombok.Getter; +import lombok.experimental.Accessors; + +@Getter +@Accessors(fluent = true) +public class ViewConfigurer> { + private final T reporter; + private final ViewOrder viewOrder; + + public ViewConfigurer(T reporter) { + this.reporter = reporter; + viewOrder = new ViewOrder(this); + } + + public T apply() { + return reporter; + } +} diff --git a/src/main/java/com/aventstack/extentreports/reporter/configuration/ViewName.java b/src/main/java/com/aventstack/extentreports/reporter/configuration/ViewName.java new file mode 100644 index 0000000..9e502ea --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/reporter/configuration/ViewName.java @@ -0,0 +1,10 @@ +package com.aventstack.extentreports.reporter.configuration; + +public enum ViewName { + AUTHOR, CATEGORY, DASHBOARD, DEVICE, EXCEPTION, LOG, TEST; + + @Override + public String toString() { + return this.name().toLowerCase(); + } +} diff --git a/src/main/java/com/aventstack/extentreports/reporter/configuration/ViewOrder.java b/src/main/java/com/aventstack/extentreports/reporter/configuration/ViewOrder.java new file mode 100644 index 0000000..94608a7 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/reporter/configuration/ViewOrder.java @@ -0,0 +1,38 @@ +package com.aventstack.extentreports.reporter.configuration; + +import java.util.Arrays; +import java.util.List; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class ViewOrder> { + private static final List DEFAULT_ORDER = Arrays.asList(new ViewName[]{ + ViewName.TEST, + ViewName.EXCEPTION, + ViewName.CATEGORY, + ViewName.DEVICE, + ViewName.AUTHOR, + ViewName.LOG, + ViewName.DASHBOARD + }); + + private List viewOrder = DEFAULT_ORDER; + private ViewConfigurer configurer; + + public ViewOrder(ViewConfigurer configurer) { + this.configurer = configurer; + } + + @SuppressWarnings("unchecked") + public ViewConfigurer as(List order) { + this.viewOrder = order; + return (ViewConfigurer) configurer; + } + + public ViewConfigurer as(ViewName[] viewOrder) { + return as(Arrays.asList(viewOrder)); + } +} diff --git a/src/main/java/com/aventstack/extentreports/reporter/configuration/ViewStyle.java b/src/main/java/com/aventstack/extentreports/reporter/configuration/ViewStyle.java index 914608e..c0ee7bf 100644 --- a/src/main/java/com/aventstack/extentreports/reporter/configuration/ViewStyle.java +++ b/src/main/java/com/aventstack/extentreports/reporter/configuration/ViewStyle.java @@ -1,5 +1,5 @@ package com.aventstack.extentreports.reporter.configuration; public enum ViewStyle { - DEFAULT, SPA -} + DEFAULT, SPA +} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/reporter/configuration/ViewsConfigurable.java b/src/main/java/com/aventstack/extentreports/reporter/configuration/ViewsConfigurable.java new file mode 100644 index 0000000..4b36b89 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/reporter/configuration/ViewsConfigurable.java @@ -0,0 +1,6 @@ +package com.aventstack.extentreports.reporter.configuration; + +@FunctionalInterface +public interface ViewsConfigurable { + ViewConfigurer viewConfigurer(); +} diff --git a/src/main/java/com/aventstack/extentreports/reporter/configuration/util/IOUtil.java b/src/main/java/com/aventstack/extentreports/reporter/configuration/util/IOUtil.java new file mode 100644 index 0000000..b114b1f --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/reporter/configuration/util/IOUtil.java @@ -0,0 +1,60 @@ +package com.aventstack.extentreports.reporter.configuration.util; + +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; +import java.util.Arrays; + +public class IOUtil { + private static final String SEP = "/"; + + private IOUtil() { + } + + public static void createDirectory(String path) { + new File(path).mkdirs(); + } + + public static void createDirectory(String[] path) { + Arrays.asList(path).forEach(IOUtil::createDirectory); + } + + public static void moveResource(String resourcePath, String copyPath) { + if (copyPath != null) + copyPath = copyPath.replace("\\", SEP); + if (resourcePath != null) + resourcePath = resourcePath.replace("\\", SEP); + 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 moveBinary(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(); + } + } +} diff --git a/src/main/java/com/aventstack/extentreports/reporter/configuration/util/ResourceHelper.java b/src/main/java/com/aventstack/extentreports/reporter/configuration/util/ResourceHelper.java new file mode 100644 index 0000000..d46cb03 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/reporter/configuration/util/ResourceHelper.java @@ -0,0 +1,26 @@ +package com.aventstack.extentreports.reporter.configuration.util; + +import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; + +public class ResourceHelper { + private ResourceHelper() { + + } + + public static void saveOfflineResources(String baseDir, String[] resx, String toPath) { + IOUtil.createDirectory(toPath); + for (String f : resx) { + Path path = Paths.get(baseDir, f); + String fromPath = path.toString(); + String toPathComplete = Paths.get(toPath, new File(f).getName()).toString(); + IOUtil.moveResource(fromPath, toPathComplete); + } + } + + public static void saveOfflineResources(String[] resx, String toPath) { + Arrays.stream(resx).forEach(x -> IOUtil.moveResource(x, toPath)); + } +} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/reporter/filter/ContextFilter.java b/src/main/java/com/aventstack/extentreports/reporter/filter/ContextFilter.java new file mode 100644 index 0000000..d706afd --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/reporter/filter/ContextFilter.java @@ -0,0 +1,93 @@ +package com.aventstack.extentreports.reporter.filter; + +import java.util.Arrays; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import com.aventstack.extentreports.Status; + +import lombok.Getter; + +@Getter +public class ContextFilter { + private static final Builder BUILDER = new Builder(); + private Set status; + private Set author; + private Set category; + private Set device; + + public ContextFilter(Set status, Set author, Set category, Set device) { + this.status = status; + this.author = author; + this.category = category; + this.device = device; + } + + public static Builder builder() { + return BUILDER; + } + + public static class Builder { + private Set statusSet; + private Set authorSet; + private Set categorySet; + private Set deviceSet; + + public Builder status(Set status) { + this.statusSet = status; + return this; + } + + public Builder status(Status[] status) { + return status(Arrays.stream(status).collect(Collectors.toSet())); + } + + public Builder status(Status status) { + return status(Stream.of(status).collect(Collectors.toSet())); + } + + public Builder author(Set author) { + this.authorSet = author; + return this; + } + + public Builder author(String[] author) { + return author(Arrays.stream(author).collect(Collectors.toSet())); + } + + public Builder author(String author) { + return author(Stream.of(author).collect(Collectors.toSet())); + } + + public Builder category(Set category) { + this.categorySet = category; + return this; + } + + public Builder category(String[] category) { + return category(Arrays.stream(category).collect(Collectors.toSet())); + } + + public Builder category(String category) { + return category(Stream.of(category).collect(Collectors.toSet())); + } + + public Builder device(Set device) { + this.deviceSet = device; + return this; + } + + public Builder device(String[] device) { + return author(Arrays.stream(device).collect(Collectors.toSet())); + } + + public Builder device(String device) { + return author(Stream.of(device).collect(Collectors.toSet())); + } + + public ContextFilter build() { + return new ContextFilter(statusSet, authorSet, categorySet, deviceSet); + } + } +} diff --git a/src/main/java/com/aventstack/extentreports/reporter/filter/StatusFilterable.java b/src/main/java/com/aventstack/extentreports/reporter/filter/StatusFilterable.java new file mode 100644 index 0000000..76c8d8f --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/reporter/filter/StatusFilterable.java @@ -0,0 +1,11 @@ +package com.aventstack.extentreports.reporter.filter; + +import java.util.Set; + +import com.aventstack.extentreports.Status; +import com.aventstack.extentreports.model.Report; + +@FunctionalInterface +public interface StatusFilterable { + Report filterAndGet(Report report, Set set); +} diff --git a/src/main/java/com/aventstack/extentreports/templating/FreemarkerTemplate.java b/src/main/java/com/aventstack/extentreports/templating/FreemarkerTemplate.java index 7ce39e2..218fb83 100644 --- a/src/main/java/com/aventstack/extentreports/templating/FreemarkerTemplate.java +++ b/src/main/java/com/aventstack/extentreports/templating/FreemarkerTemplate.java @@ -5,7 +5,7 @@ import java.io.StringWriter; import java.util.Map; -import com.aventstack.extentreports.io.FileWriterBuffered; +import com.aventstack.extentreports.io.BufferedWriterWriter; import freemarker.core.ParseException; import freemarker.template.Configuration; @@ -15,45 +15,43 @@ import freemarker.template.TemplateNotFoundException; public class FreemarkerTemplate { - - private TemplateConfig config = new TemplateConfig(); - private Configuration freemarkerConfiguration; - - public FreemarkerTemplate(Configuration freemarkerConfiguration) { - this.freemarkerConfiguration = freemarkerConfiguration; - } - - public FreemarkerTemplate(Class clazz, String encoding) { - freemarkerConfiguration = config.getFreemarkerConfig(clazz, encoding); - } - - public FreemarkerTemplate(Class clazz, String basePackagePath, String encoding) { - freemarkerConfiguration = config.getFreemarkerConfig(clazz, basePackagePath, encoding); - } - - public Template createTemplate(String templatePath) - throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException { - return freemarkerConfiguration.getTemplate(templatePath); - } - - public String getSource(Template template, Map templateMap) throws TemplateException, IOException { - String source = processTemplate(template, templateMap); - return source; - } - - public void writeTemplate(Template template, Map templateMap, File outputFile) - throws TemplateException, IOException { - String source = getSource(template, templateMap); - FileWriterBuffered.getInstance().write(outputFile, source); - } - - private String processTemplate(Template template, Map templateMap) - throws TemplateException, IOException { - StringWriter out = new StringWriter(); - template.process(templateMap, out); - String source = out.toString(); - out.close(); - return source; - } - -} + private final TemplateConfig templateConfig = new TemplateConfig(); + private final Configuration freemarkerConfig; + + public FreemarkerTemplate(Configuration freemarkerConfiguration) { + this.freemarkerConfig = freemarkerConfiguration; + } + + public FreemarkerTemplate(Class clazz, String encoding) { + freemarkerConfig = templateConfig.getFreemarkerConfig(clazz, encoding); + } + + public FreemarkerTemplate(Class clazz, String basePackagePath, String encoding) { + freemarkerConfig = templateConfig.getFreemarkerConfig(clazz, basePackagePath, encoding); + } + + public Template createTemplate(String templatePath) + throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException { + return freemarkerConfig.getTemplate(templatePath); + } + + public String getSource(Template template, Map templateMap) throws TemplateException, IOException { + String source = processTemplate(template, templateMap); + return source; + } + + public void writeTemplate(Template template, Map templateMap, File outputFile) + throws TemplateException, IOException { + String source = getSource(template, templateMap); + BufferedWriterWriter.getInstance().write(outputFile, source); + } + + private String processTemplate(Template template, Map templateMap) + throws TemplateException, IOException { + StringWriter out = new StringWriter(); + template.process(templateMap, out); + String source = out.toString(); + out.close(); + return source; + } +} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/templating/TemplateConfig.java b/src/main/java/com/aventstack/extentreports/templating/TemplateConfig.java index 508bc00..fbe9f5e 100644 --- a/src/main/java/com/aventstack/extentreports/templating/TemplateConfig.java +++ b/src/main/java/com/aventstack/extentreports/templating/TemplateConfig.java @@ -3,16 +3,15 @@ import freemarker.template.Configuration; public class TemplateConfig { - - public Configuration getFreemarkerConfig(Class clazz, String basePackagePath, String encoding) { - Configuration cfg = new Configuration(Configuration.VERSION_2_3_29); - cfg.setClassForTemplateLoading(clazz, basePackagePath); - cfg.setDefaultEncoding(encoding); - return cfg; - } - - public Configuration getFreemarkerConfig(Class clazz, String encoding) { - return getFreemarkerConfig(clazz, "/", encoding); - } - -} + public Configuration getFreemarkerConfig(Class clazz, String basePackagePath, String encoding) { + Configuration cfg = new Configuration(Configuration.VERSION_2_3_30); + cfg.setClassForTemplateLoading(clazz, basePackagePath); + cfg.setDefaultEncoding(encoding); + cfg.setAPIBuiltinEnabled(true); + return cfg; + } + + public Configuration getFreemarkerConfig(Class clazz, String encoding) { + return getFreemarkerConfig(clazz, "/", encoding); + } +} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/utils/ExceptionUtil.java b/src/main/java/com/aventstack/extentreports/utils/ExceptionUtil.java deleted file mode 100644 index 81c03eb..0000000 --- a/src/main/java/com/aventstack/extentreports/utils/ExceptionUtil.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.aventstack.extentreports.utils; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class ExceptionUtil { - - private ExceptionUtil() { - } - - public static String getStackTrace(Throwable t) { - if (t == null) - return null; - - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - t.printStackTrace(pw); - return sw.toString(); - } - - public static String getExceptionHeadline(Throwable t) { - Pattern pattern = Pattern.compile("([\\w\\.]+)(:.*)?"); - String stackTrace = getStackTrace(t); - Matcher matcher = pattern.matcher(stackTrace); - - if (matcher.find()) - return matcher.group(1); - - return null; - } -} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/utils/FileUtil.java b/src/main/java/com/aventstack/extentreports/utils/FileUtil.java deleted file mode 100644 index 32a1a62..0000000 --- a/src/main/java/com/aventstack/extentreports/utils/FileUtil.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.aventstack.extentreports.utils; - -import java.io.File; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Arrays; - -public class FileUtil { - - private FileUtil() { - } - - public static String getFileName(File f) { - if (f == null || !f.exists()) - return ""; - return f.getName(); - } - - public static String getFileName(String path) { - return getFileName(new File(path)); - } - - public static String getFileNameWithoutExtension(File f) { - String name = f.getName(); - int i = name.lastIndexOf('.'); - if (i > 0) - return name.substring(0, i); - - return name; - } - - public static String getFileNameWithoutExtension(String filePath) { - return getFileNameWithoutExtension(new File(filePath)); - } - - public static String getExtension(File f) { - String name = f.getName(); - int i = name.lastIndexOf('.'); - if (i > 0) - return name.substring(i + 1); - return ""; - } - - public static String getExtension(String filePath) { - return getExtension(new File(filePath)); - } - - public static Boolean isDirectory(String filePath) { - return isDirectory(new File(filePath)); - } - - public static Boolean isDirectory(File file) { - Path path = file.toPath(); - return Files.isDirectory(path); - } - - public static void createDirectory(String path) { - new File(path).mkdirs(); - } - - public static void createDirectory(String[] path) { - Arrays.asList(path).forEach(FileUtil::createDirectory); - } - - public static Boolean fileExists(String path) { - File f = new File(path); - return f.exists() && !f.isDirectory(); - } - - public static long getFileSize(String path) { - if (path == null) - return 0; - File f = new File(path); - return f.exists() ? f.length() : 0; - } - -} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/utils/MongoUtil.java b/src/main/java/com/aventstack/extentreports/utils/MongoUtil.java deleted file mode 100644 index 085b7dc..0000000 --- a/src/main/java/com/aventstack/extentreports/utils/MongoUtil.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.aventstack.extentreports.utils; - -import org.bson.Document; -import org.bson.types.ObjectId; - -public class MongoUtil { - - private MongoUtil() { - } - - public static ObjectId getId(Document doc) { - return (ObjectId) doc.get("_id"); - } - -} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/utils/StringUtil.java b/src/main/java/com/aventstack/extentreports/utils/StringUtil.java deleted file mode 100644 index 8edf83b..0000000 --- a/src/main/java/com/aventstack/extentreports/utils/StringUtil.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.aventstack.extentreports.utils; - -public class StringUtil { - - private StringUtil() { - } - - public static String capitalize(String s) { - return Character.toLowerCase(s.charAt(0)) + s.substring(1); - } - - public static boolean isNotNullOrEmpty(String str) { - return str != null && !str.trim().isEmpty(); - } -} \ No newline at end of file diff --git a/src/main/java/com/aventstack/extentreports/view/Ico.java b/src/main/java/com/aventstack/extentreports/view/Ico.java new file mode 100644 index 0000000..ea948f5 --- /dev/null +++ b/src/main/java/com/aventstack/extentreports/view/Ico.java @@ -0,0 +1,36 @@ +package com.aventstack.extentreports.view; + +import java.util.Arrays; + +public enum Ico { + INFO("Info", "info"), PASS("Pass", "check"), SKIP("Skip", "long-arrow-right"), WARNING("Warning", + "warning"), FAIL("Fail", "times"), RETRY("Retry", "reset"); + + private final String name; + private final String ico; + + Ico(String name, String ico) { + this.name = name; + this.ico = ico; + } + + public String getName() { + return name; + } + + public String getIco() { + return ico; + } + + public static Ico ico(String name) { + return Arrays.stream(values()) + .filter(x -> x.name.equalsIgnoreCase(name)) + .findAny() + .orElse(null); + } + + @Override + public String toString() { + return ico; + } +} diff --git a/src/main/java/com/aventstack/extentreports/viewdefs/Icon.java b/src/main/java/com/aventstack/extentreports/viewdefs/Icon.java deleted file mode 100644 index 2913f6b..0000000 --- a/src/main/java/com/aventstack/extentreports/viewdefs/Icon.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.aventstack.extentreports.viewdefs; - -import java.util.EnumMap; -import java.util.Map; - -import com.aventstack.extentreports.Status; - -public class Icon { - - private static Map map = new EnumMap<>(Status.class); - - public void override(Status status, String icon) { - map.put(status, icon); - } - - public String getIcon(Status status) { - if (map.containsKey(status)) - return map.get(status); - - String s = status.toString().toLowerCase(); - - switch (s) { - case "fail": - case "fatal": - return "times"; - case "error": - return "exclamation"; - case "warning": - return "warning"; - case "skip": - return "long-arrow-right"; - case "pass": - return "check"; - case "debug": - return "low_priority"; - case "info": - return "info"; - default: - return "help"; - } - } - -} diff --git a/src/main/java/com/aventstack/extentreports/viewdefs/MaterialIcon.java b/src/main/java/com/aventstack/extentreports/viewdefs/MaterialIcon.java deleted file mode 100644 index 6a1a7db..0000000 --- a/src/main/java/com/aventstack/extentreports/viewdefs/MaterialIcon.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.aventstack.extentreports.viewdefs; - -import java.util.EnumMap; -import java.util.Map; - -import com.aventstack.extentreports.Status; - -public class MaterialIcon { - - private static Map map = new EnumMap<>(Status.class); - - public void override(Status status, String icon) { - map.put(status, icon); - } - - public String getIcon(Status status) { - if (map.containsKey(status)) - return map.get(status); - - String s = status.toString().toLowerCase(); - - switch (s) { - case "fail": - return "cancel"; - case "fatal": - return "cancel"; - case "error": - return "error"; - case "warning": - return "warning"; - case "skip": - return "redo"; - case "pass": - return "check_circle"; - case "debug": - return "low_priority"; - case "info": - return "info_outline"; - default: - return "help"; - } - } - -} diff --git a/src/main/java/com/aventstack/extentreports/viewdefs/TWBSColor.java b/src/main/java/com/aventstack/extentreports/viewdefs/TWBSColor.java deleted file mode 100644 index 2b5afa0..0000000 --- a/src/main/java/com/aventstack/extentreports/viewdefs/TWBSColor.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.aventstack.extentreports.viewdefs; - -import java.util.EnumMap; -import java.util.Map; - -import com.aventstack.extentreports.Status; - -public class TWBSColor { - -private static Map map = new EnumMap<>(Status.class); - - public void override(Status status, String color) { - map.put(status, color); - } - - public String getColor(Status status) { - if (map.containsKey(status)) - return map.get(status); - - String s = status.toString().toLowerCase(); - - switch (s) { - case "fail": - case "fatal": - return "b-danger"; - case "error": - case "warning": - return "b-warning"; - case "skip": - return "b-skip"; - case "pass": - return "b-success"; - case "info": - return "b-primary"; - case "debug": - default: - return ""; - } - } - - public String getBgColor(Status status) { - if (map.containsKey(status)) - return map.get(status); - - String s = status.toString().toLowerCase(); - - switch (s) { - case "fail": - case "fatal": - return "danger"; - case "error": - case "warning": - return "warning"; - case "skip": - return "skip"; - case "pass": - return "success"; - case "info": - return "primary"; - case "debug": - default: - return ""; - } - } -} diff --git a/src/main/resources/com/aventstack/extentreports/markup/codeblock.ftl b/src/main/resources/com/aventstack/extentreports/markup/codeblock.ftl index a0e209c..52eac80 100644 --- a/src/main/resources/com/aventstack/extentreports/markup/codeblock.ftl +++ b/src/main/resources/com/aventstack/extentreports/markup/codeblock.ftl @@ -1,3 +1,8 @@ - \ No newline at end of file +<#assign col = code?size> +
    +<#list code as c> +
    + +
    + +
    diff --git a/src/main/resources/com/aventstack/extentreports/markup/codeblock.json.ftl b/src/main/resources/com/aventstack/extentreports/markup/codeblock.json.ftl index 36074fa..aa86990 100644 --- a/src/main/resources/com/aventstack/extentreports/markup/codeblock.json.ftl +++ b/src/main/resources/com/aventstack/extentreports/markup/codeblock.json.ftl @@ -1,9 +1,9 @@ - \ No newline at end of file +<#list code as c> +
    + + \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/offline/commons/css/icons/material-icons.css b/src/main/resources/com/aventstack/extentreports/offline/commons/css/icons/material-icons.css deleted file mode 100644 index fd963f7..0000000 --- a/src/main/resources/com/aventstack/extentreports/offline/commons/css/icons/material-icons.css +++ /dev/null @@ -1,36 +0,0 @@ -@font-face { - font-family: 'Material Icons'; - font-style: normal; - font-weight: 400; - src: url(MaterialIcons-Regular.eot); /* For IE6-8 */ - src: local('Material Icons'), - local('MaterialIcons-Regular'), - url(MaterialIcons-Regular.woff2) format('woff2'), - url(MaterialIcons-Regular.woff) format('woff'), - url(MaterialIcons-Regular.ttf) format('truetype'); -} - -.material-icons { - font-family: 'Material Icons'; - font-weight: normal; - font-style: normal; - font-size: 24px; /* Preferred icon size */ - display: inline-block; - line-height: 1; - text-transform: none; - letter-spacing: normal; - word-wrap: normal; - white-space: nowrap; - direction: ltr; - - /* Support for all WebKit browsers. */ - -webkit-font-smoothing: antialiased; - /* Support for Safari and Chrome. */ - text-rendering: optimizeLegibility; - - /* Support for Firefox. */ - -moz-osx-font-smoothing: grayscale; - - /* Support for IE. */ - font-feature-settings: 'liga'; -} \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/offline/commons/css/icons/material/MaterialIcons-Regular.eot b/src/main/resources/com/aventstack/extentreports/offline/commons/css/icons/material/MaterialIcons-Regular.eot deleted file mode 100644 index 70508eb..0000000 Binary files a/src/main/resources/com/aventstack/extentreports/offline/commons/css/icons/material/MaterialIcons-Regular.eot and /dev/null differ diff --git a/src/main/resources/com/aventstack/extentreports/offline/commons/css/icons/material/MaterialIcons-Regular.ijmap b/src/main/resources/com/aventstack/extentreports/offline/commons/css/icons/material/MaterialIcons-Regular.ijmap deleted file mode 100644 index d9f1d25..0000000 --- a/src/main/resources/com/aventstack/extentreports/offline/commons/css/icons/material/MaterialIcons-Regular.ijmap +++ /dev/null @@ -1 +0,0 @@ -{"icons":{"e84d":{"name":"3d Rotation"},"eb3b":{"name":"Ac Unit"},"e190":{"name":"Access Alarm"},"e191":{"name":"Access Alarms"},"e192":{"name":"Access Time"},"e84e":{"name":"Accessibility"},"e914":{"name":"Accessible"},"e84f":{"name":"Account Balance"},"e850":{"name":"Account Balance Wallet"},"e851":{"name":"Account Box"},"e853":{"name":"Account Circle"},"e60e":{"name":"Adb"},"e145":{"name":"Add"},"e439":{"name":"Add A Photo"},"e193":{"name":"Add Alarm"},"e003":{"name":"Add Alert"},"e146":{"name":"Add Box"},"e147":{"name":"Add Circle"},"e148":{"name":"Add Circle Outline"},"e567":{"name":"Add Location"},"e854":{"name":"Add Shopping Cart"},"e39d":{"name":"Add To Photos"},"e05c":{"name":"Add To Queue"},"e39e":{"name":"Adjust"},"e630":{"name":"Airline Seat Flat"},"e631":{"name":"Airline Seat Flat Angled"},"e632":{"name":"Airline Seat Individual Suite"},"e633":{"name":"Airline Seat Legroom Extra"},"e634":{"name":"Airline Seat Legroom Normal"},"e635":{"name":"Airline Seat Legroom Reduced"},"e636":{"name":"Airline Seat Recline Extra"},"e637":{"name":"Airline Seat Recline Normal"},"e195":{"name":"Airplanemode Active"},"e194":{"name":"Airplanemode Inactive"},"e055":{"name":"Airplay"},"eb3c":{"name":"Airport Shuttle"},"e855":{"name":"Alarm"},"e856":{"name":"Alarm Add"},"e857":{"name":"Alarm Off"},"e858":{"name":"Alarm On"},"e019":{"name":"Album"},"eb3d":{"name":"All Inclusive"},"e90b":{"name":"All Out"},"e859":{"name":"Android"},"e85a":{"name":"Announcement"},"e5c3":{"name":"Apps"},"e149":{"name":"Archive"},"e5c4":{"name":"Arrow Back"},"e5db":{"name":"Arrow Downward"},"e5c5":{"name":"Arrow Drop Down"},"e5c6":{"name":"Arrow Drop Down Circle"},"e5c7":{"name":"Arrow Drop Up"},"e5c8":{"name":"Arrow Forward"},"e5d8":{"name":"Arrow Upward"},"e060":{"name":"Art Track"},"e85b":{"name":"Aspect Ratio"},"e85c":{"name":"Assessment"},"e85d":{"name":"Assignment"},"e85e":{"name":"Assignment Ind"},"e85f":{"name":"Assignment Late"},"e860":{"name":"Assignment Return"},"e861":{"name":"Assignment Returned"},"e862":{"name":"Assignment Turned In"},"e39f":{"name":"Assistant"},"e3a0":{"name":"Assistant Photo"},"e226":{"name":"Attach File"},"e227":{"name":"Attach Money"},"e2bc":{"name":"Attachment"},"e3a1":{"name":"Audiotrack"},"e863":{"name":"Autorenew"},"e01b":{"name":"Av Timer"},"e14a":{"name":"Backspace"},"e864":{"name":"Backup"},"e19c":{"name":"Battery Alert"},"e1a3":{"name":"Battery Charging Full"},"e1a4":{"name":"Battery Full"},"e1a5":{"name":"Battery Std"},"e1a6":{"name":"Battery Unknown"},"eb3e":{"name":"Beach Access"},"e52d":{"name":"Beenhere"},"e14b":{"name":"Block"},"e1a7":{"name":"Bluetooth"},"e60f":{"name":"Bluetooth Audio"},"e1a8":{"name":"Bluetooth Connected"},"e1a9":{"name":"Bluetooth Disabled"},"e1aa":{"name":"Bluetooth Searching"},"e3a2":{"name":"Blur Circular"},"e3a3":{"name":"Blur Linear"},"e3a4":{"name":"Blur Off"},"e3a5":{"name":"Blur On"},"e865":{"name":"Book"},"e866":{"name":"Bookmark"},"e867":{"name":"Bookmark Border"},"e228":{"name":"Border All"},"e229":{"name":"Border Bottom"},"e22a":{"name":"Border Clear"},"e22b":{"name":"Border Color"},"e22c":{"name":"Border Horizontal"},"e22d":{"name":"Border Inner"},"e22e":{"name":"Border Left"},"e22f":{"name":"Border Outer"},"e230":{"name":"Border Right"},"e231":{"name":"Border Style"},"e232":{"name":"Border Top"},"e233":{"name":"Border Vertical"},"e06b":{"name":"Branding Watermark"},"e3a6":{"name":"Brightness 1"},"e3a7":{"name":"Brightness 2"},"e3a8":{"name":"Brightness 3"},"e3a9":{"name":"Brightness 4"},"e3aa":{"name":"Brightness 5"},"e3ab":{"name":"Brightness 6"},"e3ac":{"name":"Brightness 7"},"e1ab":{"name":"Brightness Auto"},"e1ac":{"name":"Brightness High"},"e1ad":{"name":"Brightness Low"},"e1ae":{"name":"Brightness Medium"},"e3ad":{"name":"Broken Image"},"e3ae":{"name":"Brush"},"e6dd":{"name":"Bubble Chart"},"e868":{"name":"Bug Report"},"e869":{"name":"Build"},"e43c":{"name":"Burst Mode"},"e0af":{"name":"Business"},"eb3f":{"name":"Business Center"},"e86a":{"name":"Cached"},"e7e9":{"name":"Cake"},"e0b0":{"name":"Call"},"e0b1":{"name":"Call End"},"e0b2":{"name":"Call Made"},"e0b3":{"name":"Call Merge"},"e0b4":{"name":"Call Missed"},"e0e4":{"name":"Call Missed Outgoing"},"e0b5":{"name":"Call Received"},"e0b6":{"name":"Call Split"},"e06c":{"name":"Call To Action"},"e3af":{"name":"Camera"},"e3b0":{"name":"Camera Alt"},"e8fc":{"name":"Camera Enhance"},"e3b1":{"name":"Camera Front"},"e3b2":{"name":"Camera Rear"},"e3b3":{"name":"Camera Roll"},"e5c9":{"name":"Cancel"},"e8f6":{"name":"Card Giftcard"},"e8f7":{"name":"Card Membership"},"e8f8":{"name":"Card Travel"},"eb40":{"name":"Casino"},"e307":{"name":"Cast"},"e308":{"name":"Cast Connected"},"e3b4":{"name":"Center Focus Strong"},"e3b5":{"name":"Center Focus Weak"},"e86b":{"name":"Change History"},"e0b7":{"name":"Chat"},"e0ca":{"name":"Chat Bubble"},"e0cb":{"name":"Chat Bubble Outline"},"e5ca":{"name":"Check"},"e834":{"name":"Check Box"},"e835":{"name":"Check Box Outline Blank"},"e86c":{"name":"Check Circle"},"e5cb":{"name":"Chevron Left"},"e5cc":{"name":"Chevron Right"},"eb41":{"name":"Child Care"},"eb42":{"name":"Child Friendly"},"e86d":{"name":"Chrome Reader Mode"},"e86e":{"name":"Class"},"e14c":{"name":"Clear"},"e0b8":{"name":"Clear All"},"e5cd":{"name":"Close"},"e01c":{"name":"Closed Caption"},"e2bd":{"name":"Cloud"},"e2be":{"name":"Cloud Circle"},"e2bf":{"name":"Cloud Done"},"e2c0":{"name":"Cloud Download"},"e2c1":{"name":"Cloud Off"},"e2c2":{"name":"Cloud Queue"},"e2c3":{"name":"Cloud Upload"},"e86f":{"name":"Code"},"e3b6":{"name":"Collections"},"e431":{"name":"Collections Bookmark"},"e3b7":{"name":"Color Lens"},"e3b8":{"name":"Colorize"},"e0b9":{"name":"Comment"},"e3b9":{"name":"Compare"},"e915":{"name":"Compare Arrows"},"e30a":{"name":"Computer"},"e638":{"name":"Confirmation Number"},"e0d0":{"name":"Contact Mail"},"e0cf":{"name":"Contact Phone"},"e0ba":{"name":"Contacts"},"e14d":{"name":"Content Copy"},"e14e":{"name":"Content Cut"},"e14f":{"name":"Content Paste"},"e3ba":{"name":"Control Point"},"e3bb":{"name":"Control Point Duplicate"},"e90c":{"name":"Copyright"},"e150":{"name":"Create"},"e2cc":{"name":"Create New Folder"},"e870":{"name":"Credit Card"},"e3be":{"name":"Crop"},"e3bc":{"name":"Crop 16 9"},"e3bd":{"name":"Crop 3 2"},"e3bf":{"name":"Crop 5 4"},"e3c0":{"name":"Crop 7 5"},"e3c1":{"name":"Crop Din"},"e3c2":{"name":"Crop Free"},"e3c3":{"name":"Crop Landscape"},"e3c4":{"name":"Crop Original"},"e3c5":{"name":"Crop Portrait"},"e437":{"name":"Crop Rotate"},"e3c6":{"name":"Crop Square"},"e871":{"name":"Dashboard"},"e1af":{"name":"Data Usage"},"e916":{"name":"Date Range"},"e3c7":{"name":"Dehaze"},"e872":{"name":"Delete"},"e92b":{"name":"Delete Forever"},"e16c":{"name":"Delete Sweep"},"e873":{"name":"Description"},"e30b":{"name":"Desktop Mac"},"e30c":{"name":"Desktop Windows"},"e3c8":{"name":"Details"},"e30d":{"name":"Developer Board"},"e1b0":{"name":"Developer Mode"},"e335":{"name":"Device Hub"},"e1b1":{"name":"Devices"},"e337":{"name":"Devices Other"},"e0bb":{"name":"Dialer Sip"},"e0bc":{"name":"Dialpad"},"e52e":{"name":"Directions"},"e52f":{"name":"Directions Bike"},"e532":{"name":"Directions Boat"},"e530":{"name":"Directions Bus"},"e531":{"name":"Directions Car"},"e534":{"name":"Directions Railway"},"e566":{"name":"Directions Run"},"e533":{"name":"Directions Subway"},"e535":{"name":"Directions Transit"},"e536":{"name":"Directions Walk"},"e610":{"name":"Disc Full"},"e875":{"name":"Dns"},"e612":{"name":"Do Not Disturb"},"e611":{"name":"Do Not Disturb Alt"},"e643":{"name":"Do Not Disturb Off"},"e644":{"name":"Do Not Disturb On"},"e30e":{"name":"Dock"},"e7ee":{"name":"Domain"},"e876":{"name":"Done"},"e877":{"name":"Done All"},"e917":{"name":"Donut Large"},"e918":{"name":"Donut Small"},"e151":{"name":"Drafts"},"e25d":{"name":"Drag Handle"},"e613":{"name":"Drive Eta"},"e1b2":{"name":"Dvr"},"e3c9":{"name":"Edit"},"e568":{"name":"Edit Location"},"e8fb":{"name":"Eject"},"e0be":{"name":"Email"},"e63f":{"name":"Enhanced Encryption"},"e01d":{"name":"Equalizer"},"e000":{"name":"Error"},"e001":{"name":"Error Outline"},"e926":{"name":"Euro Symbol"},"e56d":{"name":"Ev Station"},"e878":{"name":"Event"},"e614":{"name":"Event Available"},"e615":{"name":"Event Busy"},"e616":{"name":"Event Note"},"e903":{"name":"Event Seat"},"e879":{"name":"Exit To App"},"e5ce":{"name":"Expand Less"},"e5cf":{"name":"Expand More"},"e01e":{"name":"Explicit"},"e87a":{"name":"Explore"},"e3ca":{"name":"Exposure"},"e3cb":{"name":"Exposure Neg 1"},"e3cc":{"name":"Exposure Neg 2"},"e3cd":{"name":"Exposure Plus 1"},"e3ce":{"name":"Exposure Plus 2"},"e3cf":{"name":"Exposure Zero"},"e87b":{"name":"Extension"},"e87c":{"name":"Face"},"e01f":{"name":"Fast Forward"},"e020":{"name":"Fast Rewind"},"e87d":{"name":"Favorite"},"e87e":{"name":"Favorite Border"},"e06d":{"name":"Featured Play List"},"e06e":{"name":"Featured Video"},"e87f":{"name":"Feedback"},"e05d":{"name":"Fiber Dvr"},"e061":{"name":"Fiber Manual Record"},"e05e":{"name":"Fiber New"},"e06a":{"name":"Fiber Pin"},"e062":{"name":"Fiber Smart Record"},"e2c4":{"name":"File Download"},"e2c6":{"name":"File Upload"},"e3d3":{"name":"Filter"},"e3d0":{"name":"Filter 1"},"e3d1":{"name":"Filter 2"},"e3d2":{"name":"Filter 3"},"e3d4":{"name":"Filter 4"},"e3d5":{"name":"Filter 5"},"e3d6":{"name":"Filter 6"},"e3d7":{"name":"Filter 7"},"e3d8":{"name":"Filter 8"},"e3d9":{"name":"Filter 9"},"e3da":{"name":"Filter 9 Plus"},"e3db":{"name":"Filter B And W"},"e3dc":{"name":"Filter Center Focus"},"e3dd":{"name":"Filter Drama"},"e3de":{"name":"Filter Frames"},"e3df":{"name":"Filter Hdr"},"e152":{"name":"Filter List"},"e3e0":{"name":"Filter None"},"e3e2":{"name":"Filter Tilt Shift"},"e3e3":{"name":"Filter Vintage"},"e880":{"name":"Find In Page"},"e881":{"name":"Find Replace"},"e90d":{"name":"Fingerprint"},"e5dc":{"name":"First Page"},"eb43":{"name":"Fitness Center"},"e153":{"name":"Flag"},"e3e4":{"name":"Flare"},"e3e5":{"name":"Flash Auto"},"e3e6":{"name":"Flash Off"},"e3e7":{"name":"Flash On"},"e539":{"name":"Flight"},"e904":{"name":"Flight Land"},"e905":{"name":"Flight Takeoff"},"e3e8":{"name":"Flip"},"e882":{"name":"Flip To Back"},"e883":{"name":"Flip To Front"},"e2c7":{"name":"Folder"},"e2c8":{"name":"Folder Open"},"e2c9":{"name":"Folder Shared"},"e617":{"name":"Folder Special"},"e167":{"name":"Font Download"},"e234":{"name":"Format Align Center"},"e235":{"name":"Format Align Justify"},"e236":{"name":"Format Align Left"},"e237":{"name":"Format Align Right"},"e238":{"name":"Format Bold"},"e239":{"name":"Format Clear"},"e23a":{"name":"Format Color Fill"},"e23b":{"name":"Format Color Reset"},"e23c":{"name":"Format Color Text"},"e23d":{"name":"Format Indent Decrease"},"e23e":{"name":"Format Indent Increase"},"e23f":{"name":"Format Italic"},"e240":{"name":"Format Line Spacing"},"e241":{"name":"Format List Bulleted"},"e242":{"name":"Format List Numbered"},"e243":{"name":"Format Paint"},"e244":{"name":"Format Quote"},"e25e":{"name":"Format Shapes"},"e245":{"name":"Format Size"},"e246":{"name":"Format Strikethrough"},"e247":{"name":"Format Textdirection L To R"},"e248":{"name":"Format Textdirection R To L"},"e249":{"name":"Format Underlined"},"e0bf":{"name":"Forum"},"e154":{"name":"Forward"},"e056":{"name":"Forward 10"},"e057":{"name":"Forward 30"},"e058":{"name":"Forward 5"},"eb44":{"name":"Free Breakfast"},"e5d0":{"name":"Fullscreen"},"e5d1":{"name":"Fullscreen Exit"},"e24a":{"name":"Functions"},"e927":{"name":"G Translate"},"e30f":{"name":"Gamepad"},"e021":{"name":"Games"},"e90e":{"name":"Gavel"},"e155":{"name":"Gesture"},"e884":{"name":"Get App"},"e908":{"name":"Gif"},"eb45":{"name":"Golf Course"},"e1b3":{"name":"Gps Fixed"},"e1b4":{"name":"Gps Not Fixed"},"e1b5":{"name":"Gps Off"},"e885":{"name":"Grade"},"e3e9":{"name":"Gradient"},"e3ea":{"name":"Grain"},"e1b8":{"name":"Graphic Eq"},"e3eb":{"name":"Grid Off"},"e3ec":{"name":"Grid On"},"e7ef":{"name":"Group"},"e7f0":{"name":"Group Add"},"e886":{"name":"Group Work"},"e052":{"name":"Hd"},"e3ed":{"name":"Hdr Off"},"e3ee":{"name":"Hdr On"},"e3f1":{"name":"Hdr Strong"},"e3f2":{"name":"Hdr Weak"},"e310":{"name":"Headset"},"e311":{"name":"Headset Mic"},"e3f3":{"name":"Healing"},"e023":{"name":"Hearing"},"e887":{"name":"Help"},"e8fd":{"name":"Help Outline"},"e024":{"name":"High Quality"},"e25f":{"name":"Highlight"},"e888":{"name":"Highlight Off"},"e889":{"name":"History"},"e88a":{"name":"Home"},"eb46":{"name":"Hot Tub"},"e53a":{"name":"Hotel"},"e88b":{"name":"Hourglass Empty"},"e88c":{"name":"Hourglass Full"},"e902":{"name":"Http"},"e88d":{"name":"Https"},"e3f4":{"name":"Image"},"e3f5":{"name":"Image Aspect Ratio"},"e0e0":{"name":"Import Contacts"},"e0c3":{"name":"Import Export"},"e912":{"name":"Important Devices"},"e156":{"name":"Inbox"},"e909":{"name":"Indeterminate Check Box"},"e88e":{"name":"Info"},"e88f":{"name":"Info Outline"},"e890":{"name":"Input"},"e24b":{"name":"Insert Chart"},"e24c":{"name":"Insert Comment"},"e24d":{"name":"Insert Drive File"},"e24e":{"name":"Insert Emoticon"},"e24f":{"name":"Insert Invitation"},"e250":{"name":"Insert Link"},"e251":{"name":"Insert Photo"},"e891":{"name":"Invert Colors"},"e0c4":{"name":"Invert Colors Off"},"e3f6":{"name":"Iso"},"e312":{"name":"Keyboard"},"e313":{"name":"Keyboard Arrow Down"},"e314":{"name":"Keyboard Arrow Left"},"e315":{"name":"Keyboard Arrow Right"},"e316":{"name":"Keyboard Arrow Up"},"e317":{"name":"Keyboard Backspace"},"e318":{"name":"Keyboard Capslock"},"e31a":{"name":"Keyboard Hide"},"e31b":{"name":"Keyboard Return"},"e31c":{"name":"Keyboard Tab"},"e31d":{"name":"Keyboard Voice"},"eb47":{"name":"Kitchen"},"e892":{"name":"Label"},"e893":{"name":"Label Outline"},"e3f7":{"name":"Landscape"},"e894":{"name":"Language"},"e31e":{"name":"Laptop"},"e31f":{"name":"Laptop Chromebook"},"e320":{"name":"Laptop Mac"},"e321":{"name":"Laptop Windows"},"e5dd":{"name":"Last Page"},"e895":{"name":"Launch"},"e53b":{"name":"Layers"},"e53c":{"name":"Layers Clear"},"e3f8":{"name":"Leak Add"},"e3f9":{"name":"Leak Remove"},"e3fa":{"name":"Lens"},"e02e":{"name":"Library Add"},"e02f":{"name":"Library Books"},"e030":{"name":"Library Music"},"e90f":{"name":"Lightbulb Outline"},"e919":{"name":"Line Style"},"e91a":{"name":"Line Weight"},"e260":{"name":"Linear Scale"},"e157":{"name":"Link"},"e438":{"name":"Linked Camera"},"e896":{"name":"List"},"e0c6":{"name":"Live Help"},"e639":{"name":"Live Tv"},"e53f":{"name":"Local Activity"},"e53d":{"name":"Local Airport"},"e53e":{"name":"Local Atm"},"e540":{"name":"Local Bar"},"e541":{"name":"Local Cafe"},"e542":{"name":"Local Car Wash"},"e543":{"name":"Local Convenience Store"},"e556":{"name":"Local Dining"},"e544":{"name":"Local Drink"},"e545":{"name":"Local Florist"},"e546":{"name":"Local Gas Station"},"e547":{"name":"Local Grocery Store"},"e548":{"name":"Local Hospital"},"e549":{"name":"Local Hotel"},"e54a":{"name":"Local Laundry Service"},"e54b":{"name":"Local Library"},"e54c":{"name":"Local Mall"},"e54d":{"name":"Local Movies"},"e54e":{"name":"Local Offer"},"e54f":{"name":"Local Parking"},"e550":{"name":"Local Pharmacy"},"e551":{"name":"Local Phone"},"e552":{"name":"Local Pizza"},"e553":{"name":"Local Play"},"e554":{"name":"Local Post Office"},"e555":{"name":"Local Printshop"},"e557":{"name":"Local See"},"e558":{"name":"Local Shipping"},"e559":{"name":"Local Taxi"},"e7f1":{"name":"Location City"},"e1b6":{"name":"Location Disabled"},"e0c7":{"name":"Location Off"},"e0c8":{"name":"Location On"},"e1b7":{"name":"Location Searching"},"e897":{"name":"Lock"},"e898":{"name":"Lock Open"},"e899":{"name":"Lock Outline"},"e3fc":{"name":"Looks"},"e3fb":{"name":"Looks 3"},"e3fd":{"name":"Looks 4"},"e3fe":{"name":"Looks 5"},"e3ff":{"name":"Looks 6"},"e400":{"name":"Looks One"},"e401":{"name":"Looks Two"},"e028":{"name":"Loop"},"e402":{"name":"Loupe"},"e16d":{"name":"Low Priority"},"e89a":{"name":"Loyalty"},"e158":{"name":"Mail"},"e0e1":{"name":"Mail Outline"},"e55b":{"name":"Map"},"e159":{"name":"Markunread"},"e89b":{"name":"Markunread Mailbox"},"e322":{"name":"Memory"},"e5d2":{"name":"Menu"},"e252":{"name":"Merge Type"},"e0c9":{"name":"Message"},"e029":{"name":"Mic"},"e02a":{"name":"Mic None"},"e02b":{"name":"Mic Off"},"e618":{"name":"Mms"},"e253":{"name":"Mode Comment"},"e254":{"name":"Mode Edit"},"e263":{"name":"Monetization On"},"e25c":{"name":"Money Off"},"e403":{"name":"Monochrome Photos"},"e7f2":{"name":"Mood"},"e7f3":{"name":"Mood Bad"},"e619":{"name":"More"},"e5d3":{"name":"More Horiz"},"e5d4":{"name":"More Vert"},"e91b":{"name":"Motorcycle"},"e323":{"name":"Mouse"},"e168":{"name":"Move To Inbox"},"e02c":{"name":"Movie"},"e404":{"name":"Movie Creation"},"e43a":{"name":"Movie Filter"},"e6df":{"name":"Multiline Chart"},"e405":{"name":"Music Note"},"e063":{"name":"Music Video"},"e55c":{"name":"My Location"},"e406":{"name":"Nature"},"e407":{"name":"Nature People"},"e408":{"name":"Navigate Before"},"e409":{"name":"Navigate Next"},"e55d":{"name":"Navigation"},"e569":{"name":"Near Me"},"e1b9":{"name":"Network Cell"},"e640":{"name":"Network Check"},"e61a":{"name":"Network Locked"},"e1ba":{"name":"Network Wifi"},"e031":{"name":"New Releases"},"e16a":{"name":"Next Week"},"e1bb":{"name":"Nfc"},"e641":{"name":"No Encryption"},"e0cc":{"name":"No Sim"},"e033":{"name":"Not Interested"},"e06f":{"name":"Note"},"e89c":{"name":"Note Add"},"e7f4":{"name":"Notifications"},"e7f7":{"name":"Notifications Active"},"e7f5":{"name":"Notifications None"},"e7f6":{"name":"Notifications Off"},"e7f8":{"name":"Notifications Paused"},"e90a":{"name":"Offline Pin"},"e63a":{"name":"Ondemand Video"},"e91c":{"name":"Opacity"},"e89d":{"name":"Open In Browser"},"e89e":{"name":"Open In New"},"e89f":{"name":"Open With"},"e7f9":{"name":"Pages"},"e8a0":{"name":"Pageview"},"e40a":{"name":"Palette"},"e925":{"name":"Pan Tool"},"e40b":{"name":"Panorama"},"e40c":{"name":"Panorama Fish Eye"},"e40d":{"name":"Panorama Horizontal"},"e40e":{"name":"Panorama Vertical"},"e40f":{"name":"Panorama Wide Angle"},"e7fa":{"name":"Party Mode"},"e034":{"name":"Pause"},"e035":{"name":"Pause Circle Filled"},"e036":{"name":"Pause Circle Outline"},"e8a1":{"name":"Payment"},"e7fb":{"name":"People"},"e7fc":{"name":"People Outline"},"e8a2":{"name":"Perm Camera Mic"},"e8a3":{"name":"Perm Contact Calendar"},"e8a4":{"name":"Perm Data Setting"},"e8a5":{"name":"Perm Device Information"},"e8a6":{"name":"Perm Identity"},"e8a7":{"name":"Perm Media"},"e8a8":{"name":"Perm Phone Msg"},"e8a9":{"name":"Perm Scan Wifi"},"e7fd":{"name":"Person"},"e7fe":{"name":"Person Add"},"e7ff":{"name":"Person Outline"},"e55a":{"name":"Person Pin"},"e56a":{"name":"Person Pin Circle"},"e63b":{"name":"Personal Video"},"e91d":{"name":"Pets"},"e0cd":{"name":"Phone"},"e324":{"name":"Phone Android"},"e61b":{"name":"Phone Bluetooth Speaker"},"e61c":{"name":"Phone Forwarded"},"e61d":{"name":"Phone In Talk"},"e325":{"name":"Phone Iphone"},"e61e":{"name":"Phone Locked"},"e61f":{"name":"Phone Missed"},"e620":{"name":"Phone Paused"},"e326":{"name":"Phonelink"},"e0db":{"name":"Phonelink Erase"},"e0dc":{"name":"Phonelink Lock"},"e327":{"name":"Phonelink Off"},"e0dd":{"name":"Phonelink Ring"},"e0de":{"name":"Phonelink Setup"},"e410":{"name":"Photo"},"e411":{"name":"Photo Album"},"e412":{"name":"Photo Camera"},"e43b":{"name":"Photo Filter"},"e413":{"name":"Photo Library"},"e432":{"name":"Photo Size Select Actual"},"e433":{"name":"Photo Size Select Large"},"e434":{"name":"Photo Size Select Small"},"e415":{"name":"Picture As Pdf"},"e8aa":{"name":"Picture In Picture"},"e911":{"name":"Picture In Picture Alt"},"e6c4":{"name":"Pie Chart"},"e6c5":{"name":"Pie Chart Outlined"},"e55e":{"name":"Pin Drop"},"e55f":{"name":"Place"},"e037":{"name":"Play Arrow"},"e038":{"name":"Play Circle Filled"},"e039":{"name":"Play Circle Outline"},"e906":{"name":"Play For Work"},"e03b":{"name":"Playlist Add"},"e065":{"name":"Playlist Add Check"},"e05f":{"name":"Playlist Play"},"e800":{"name":"Plus One"},"e801":{"name":"Poll"},"e8ab":{"name":"Polymer"},"eb48":{"name":"Pool"},"e0ce":{"name":"Portable Wifi Off"},"e416":{"name":"Portrait"},"e63c":{"name":"Power"},"e336":{"name":"Power Input"},"e8ac":{"name":"Power Settings New"},"e91e":{"name":"Pregnant Woman"},"e0df":{"name":"Present To All"},"e8ad":{"name":"Print"},"e645":{"name":"Priority High"},"e80b":{"name":"Public"},"e255":{"name":"Publish"},"e8ae":{"name":"Query Builder"},"e8af":{"name":"Question Answer"},"e03c":{"name":"Queue"},"e03d":{"name":"Queue Music"},"e066":{"name":"Queue Play Next"},"e03e":{"name":"Radio"},"e837":{"name":"Radio Button Checked"},"e836":{"name":"Radio Button Unchecked"},"e560":{"name":"Rate Review"},"e8b0":{"name":"Receipt"},"e03f":{"name":"Recent Actors"},"e91f":{"name":"Record Voice Over"},"e8b1":{"name":"Redeem"},"e15a":{"name":"Redo"},"e5d5":{"name":"Refresh"},"e15b":{"name":"Remove"},"e15c":{"name":"Remove Circle"},"e15d":{"name":"Remove Circle Outline"},"e067":{"name":"Remove From Queue"},"e417":{"name":"Remove Red Eye"},"e928":{"name":"Remove Shopping Cart"},"e8fe":{"name":"Reorder"},"e040":{"name":"Repeat"},"e041":{"name":"Repeat One"},"e042":{"name":"Replay"},"e059":{"name":"Replay 10"},"e05a":{"name":"Replay 30"},"e05b":{"name":"Replay 5"},"e15e":{"name":"Reply"},"e15f":{"name":"Reply All"},"e160":{"name":"Report"},"e8b2":{"name":"Report Problem"},"e56c":{"name":"Restaurant"},"e561":{"name":"Restaurant Menu"},"e8b3":{"name":"Restore"},"e929":{"name":"Restore Page"},"e0d1":{"name":"Ring Volume"},"e8b4":{"name":"Room"},"eb49":{"name":"Room Service"},"e418":{"name":"Rotate 90 Degrees Ccw"},"e419":{"name":"Rotate Left"},"e41a":{"name":"Rotate Right"},"e920":{"name":"Rounded Corner"},"e328":{"name":"Router"},"e921":{"name":"Rowing"},"e0e5":{"name":"Rss Feed"},"e642":{"name":"Rv Hookup"},"e562":{"name":"Satellite"},"e161":{"name":"Save"},"e329":{"name":"Scanner"},"e8b5":{"name":"Schedule"},"e80c":{"name":"School"},"e1be":{"name":"Screen Lock Landscape"},"e1bf":{"name":"Screen Lock Portrait"},"e1c0":{"name":"Screen Lock Rotation"},"e1c1":{"name":"Screen Rotation"},"e0e2":{"name":"Screen Share"},"e623":{"name":"Sd Card"},"e1c2":{"name":"Sd Storage"},"e8b6":{"name":"Search"},"e32a":{"name":"Security"},"e162":{"name":"Select All"},"e163":{"name":"Send"},"e811":{"name":"Sentiment Dissatisfied"},"e812":{"name":"Sentiment Neutral"},"e813":{"name":"Sentiment Satisfied"},"e814":{"name":"Sentiment Very Dissatisfied"},"e815":{"name":"Sentiment Very Satisfied"},"e8b8":{"name":"Settings"},"e8b9":{"name":"Settings Applications"},"e8ba":{"name":"Settings Backup Restore"},"e8bb":{"name":"Settings Bluetooth"},"e8bd":{"name":"Settings Brightness"},"e8bc":{"name":"Settings Cell"},"e8be":{"name":"Settings Ethernet"},"e8bf":{"name":"Settings Input Antenna"},"e8c0":{"name":"Settings Input Component"},"e8c1":{"name":"Settings Input Composite"},"e8c2":{"name":"Settings Input Hdmi"},"e8c3":{"name":"Settings Input Svideo"},"e8c4":{"name":"Settings Overscan"},"e8c5":{"name":"Settings Phone"},"e8c6":{"name":"Settings Power"},"e8c7":{"name":"Settings Remote"},"e1c3":{"name":"Settings System Daydream"},"e8c8":{"name":"Settings Voice"},"e80d":{"name":"Share"},"e8c9":{"name":"Shop"},"e8ca":{"name":"Shop Two"},"e8cb":{"name":"Shopping Basket"},"e8cc":{"name":"Shopping Cart"},"e261":{"name":"Short Text"},"e6e1":{"name":"Show Chart"},"e043":{"name":"Shuffle"},"e1c8":{"name":"Signal Cellular 4 Bar"},"e1cd":{"name":"Signal Cellular Connected No Internet 4 Bar"},"e1ce":{"name":"Signal Cellular No Sim"},"e1cf":{"name":"Signal Cellular Null"},"e1d0":{"name":"Signal Cellular Off"},"e1d8":{"name":"Signal Wifi 4 Bar"},"e1d9":{"name":"Signal Wifi 4 Bar Lock"},"e1da":{"name":"Signal Wifi Off"},"e32b":{"name":"Sim Card"},"e624":{"name":"Sim Card Alert"},"e044":{"name":"Skip Next"},"e045":{"name":"Skip Previous"},"e41b":{"name":"Slideshow"},"e068":{"name":"Slow Motion Video"},"e32c":{"name":"Smartphone"},"eb4a":{"name":"Smoke Free"},"eb4b":{"name":"Smoking Rooms"},"e625":{"name":"Sms"},"e626":{"name":"Sms Failed"},"e046":{"name":"Snooze"},"e164":{"name":"Sort"},"e053":{"name":"Sort By Alpha"},"eb4c":{"name":"Spa"},"e256":{"name":"Space Bar"},"e32d":{"name":"Speaker"},"e32e":{"name":"Speaker Group"},"e8cd":{"name":"Speaker Notes"},"e92a":{"name":"Speaker Notes Off"},"e0d2":{"name":"Speaker Phone"},"e8ce":{"name":"Spellcheck"},"e838":{"name":"Star"},"e83a":{"name":"Star Border"},"e839":{"name":"Star Half"},"e8d0":{"name":"Stars"},"e0d3":{"name":"Stay Current Landscape"},"e0d4":{"name":"Stay Current Portrait"},"e0d5":{"name":"Stay Primary Landscape"},"e0d6":{"name":"Stay Primary Portrait"},"e047":{"name":"Stop"},"e0e3":{"name":"Stop Screen Share"},"e1db":{"name":"Storage"},"e8d1":{"name":"Store"},"e563":{"name":"Store Mall Directory"},"e41c":{"name":"Straighten"},"e56e":{"name":"Streetview"},"e257":{"name":"Strikethrough S"},"e41d":{"name":"Style"},"e5d9":{"name":"Subdirectory Arrow Left"},"e5da":{"name":"Subdirectory Arrow Right"},"e8d2":{"name":"Subject"},"e064":{"name":"Subscriptions"},"e048":{"name":"Subtitles"},"e56f":{"name":"Subway"},"e8d3":{"name":"Supervisor Account"},"e049":{"name":"Surround Sound"},"e0d7":{"name":"Swap Calls"},"e8d4":{"name":"Swap Horiz"},"e8d5":{"name":"Swap Vert"},"e8d6":{"name":"Swap Vertical Circle"},"e41e":{"name":"Switch Camera"},"e41f":{"name":"Switch Video"},"e627":{"name":"Sync"},"e628":{"name":"Sync Disabled"},"e629":{"name":"Sync Problem"},"e62a":{"name":"System Update"},"e8d7":{"name":"System Update Alt"},"e8d8":{"name":"Tab"},"e8d9":{"name":"Tab Unselected"},"e32f":{"name":"Tablet"},"e330":{"name":"Tablet Android"},"e331":{"name":"Tablet Mac"},"e420":{"name":"Tag Faces"},"e62b":{"name":"Tap And Play"},"e564":{"name":"Terrain"},"e262":{"name":"Text Fields"},"e165":{"name":"Text Format"},"e0d8":{"name":"Textsms"},"e421":{"name":"Texture"},"e8da":{"name":"Theaters"},"e8db":{"name":"Thumb Down"},"e8dc":{"name":"Thumb Up"},"e8dd":{"name":"Thumbs Up Down"},"e62c":{"name":"Time To Leave"},"e422":{"name":"Timelapse"},"e922":{"name":"Timeline"},"e425":{"name":"Timer"},"e423":{"name":"Timer 10"},"e424":{"name":"Timer 3"},"e426":{"name":"Timer Off"},"e264":{"name":"Title"},"e8de":{"name":"Toc"},"e8df":{"name":"Today"},"e8e0":{"name":"Toll"},"e427":{"name":"Tonality"},"e913":{"name":"Touch App"},"e332":{"name":"Toys"},"e8e1":{"name":"Track Changes"},"e565":{"name":"Traffic"},"e570":{"name":"Train"},"e571":{"name":"Tram"},"e572":{"name":"Transfer Within A Station"},"e428":{"name":"Transform"},"e8e2":{"name":"Translate"},"e8e3":{"name":"Trending Down"},"e8e4":{"name":"Trending Flat"},"e8e5":{"name":"Trending Up"},"e429":{"name":"Tune"},"e8e6":{"name":"Turned In"},"e8e7":{"name":"Turned In Not"},"e333":{"name":"Tv"},"e169":{"name":"Unarchive"},"e166":{"name":"Undo"},"e5d6":{"name":"Unfold Less"},"e5d7":{"name":"Unfold More"},"e923":{"name":"Update"},"e1e0":{"name":"Usb"},"e8e8":{"name":"Verified User"},"e258":{"name":"Vertical Align Bottom"},"e259":{"name":"Vertical Align Center"},"e25a":{"name":"Vertical Align Top"},"e62d":{"name":"Vibration"},"e070":{"name":"Video Call"},"e071":{"name":"Video Label"},"e04a":{"name":"Video Library"},"e04b":{"name":"Videocam"},"e04c":{"name":"Videocam Off"},"e338":{"name":"Videogame Asset"},"e8e9":{"name":"View Agenda"},"e8ea":{"name":"View Array"},"e8eb":{"name":"View Carousel"},"e8ec":{"name":"View Column"},"e42a":{"name":"View Comfy"},"e42b":{"name":"View Compact"},"e8ed":{"name":"View Day"},"e8ee":{"name":"View Headline"},"e8ef":{"name":"View List"},"e8f0":{"name":"View Module"},"e8f1":{"name":"View Quilt"},"e8f2":{"name":"View Stream"},"e8f3":{"name":"View Week"},"e435":{"name":"Vignette"},"e8f4":{"name":"Visibility"},"e8f5":{"name":"Visibility Off"},"e62e":{"name":"Voice Chat"},"e0d9":{"name":"Voicemail"},"e04d":{"name":"Volume Down"},"e04e":{"name":"Volume Mute"},"e04f":{"name":"Volume Off"},"e050":{"name":"Volume Up"},"e0da":{"name":"Vpn Key"},"e62f":{"name":"Vpn Lock"},"e1bc":{"name":"Wallpaper"},"e002":{"name":"Warning"},"e334":{"name":"Watch"},"e924":{"name":"Watch Later"},"e42c":{"name":"Wb Auto"},"e42d":{"name":"Wb Cloudy"},"e42e":{"name":"Wb Incandescent"},"e436":{"name":"Wb Iridescent"},"e430":{"name":"Wb Sunny"},"e63d":{"name":"Wc"},"e051":{"name":"Web"},"e069":{"name":"Web Asset"},"e16b":{"name":"Weekend"},"e80e":{"name":"Whatshot"},"e1bd":{"name":"Widgets"},"e63e":{"name":"Wifi"},"e1e1":{"name":"Wifi Lock"},"e1e2":{"name":"Wifi Tethering"},"e8f9":{"name":"Work"},"e25b":{"name":"Wrap Text"},"e8fa":{"name":"Youtube Searched For"},"e8ff":{"name":"Zoom In"},"e900":{"name":"Zoom Out"},"e56b":{"name":"Zoom Out Map"}}} \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/offline/commons/css/icons/material/MaterialIcons-Regular.svg b/src/main/resources/com/aventstack/extentreports/offline/commons/css/icons/material/MaterialIcons-Regular.svg deleted file mode 100644 index a449327..0000000 --- a/src/main/resources/com/aventstack/extentreports/offline/commons/css/icons/material/MaterialIcons-Regular.svg +++ /dev/null @@ -1,2373 +0,0 @@ - - - - - -Created by FontForge 20151118 at Mon Feb 8 11:58:02 2016 - By shyndman -Copyright 2015 Google, Inc. All Rights Reserved. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/resources/com/aventstack/extentreports/offline/commons/css/icons/material/MaterialIcons-Regular.ttf b/src/main/resources/com/aventstack/extentreports/offline/commons/css/icons/material/MaterialIcons-Regular.ttf deleted file mode 100644 index 7015564..0000000 Binary files a/src/main/resources/com/aventstack/extentreports/offline/commons/css/icons/material/MaterialIcons-Regular.ttf and /dev/null differ diff --git a/src/main/resources/com/aventstack/extentreports/offline/commons/css/icons/material/MaterialIcons-Regular.woff b/src/main/resources/com/aventstack/extentreports/offline/commons/css/icons/material/MaterialIcons-Regular.woff deleted file mode 100644 index b648a3e..0000000 Binary files a/src/main/resources/com/aventstack/extentreports/offline/commons/css/icons/material/MaterialIcons-Regular.woff and /dev/null differ diff --git a/src/main/resources/com/aventstack/extentreports/offline/commons/css/icons/material/MaterialIcons-Regular.woff2 b/src/main/resources/com/aventstack/extentreports/offline/commons/css/icons/material/MaterialIcons-Regular.woff2 deleted file mode 100644 index 9fa2112..0000000 Binary files a/src/main/resources/com/aventstack/extentreports/offline/commons/css/icons/material/MaterialIcons-Regular.woff2 and /dev/null differ diff --git a/src/main/resources/com/aventstack/extentreports/offline/commons/js/attr.js b/src/main/resources/com/aventstack/extentreports/offline/commons/js/attr.js deleted file mode 100644 index 08ed890..0000000 --- a/src/main/resources/com/aventstack/extentreports/offline/commons/js/attr.js +++ /dev/null @@ -1,115 +0,0 @@ -/*! jQuery v3.2.1 | (c) JS Foundation and other contributors | jquery.org/license */ -!function(a,b){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){"use strict";var c=[],d=a.document,e=Object.getPrototypeOf,f=c.slice,g=c.concat,h=c.push,i=c.indexOf,j={},k=j.toString,l=j.hasOwnProperty,m=l.toString,n=m.call(Object),o={};function p(a,b){b=b||d;var c=b.createElement("script");c.text=a,b.head.appendChild(c).parentNode.removeChild(c)}var q="3.2.1",r=function(a,b){return new r.fn.init(a,b)},s=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,t=/^-ms-/,u=/-([a-z])/g,v=function(a,b){return b.toUpperCase()};r.fn=r.prototype={jquery:q,constructor:r,length:0,toArray:function(){return f.call(this)},get:function(a){return null==a?f.call(this):a<0?this[a+this.length]:this[a]},pushStack:function(a){var b=r.merge(this.constructor(),a);return b.prevObject=this,b},each:function(a){return r.each(this,a)},map:function(a){return this.pushStack(r.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return this.pushStack(f.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(a){var b=this.length,c=+a+(a<0?b:0);return this.pushStack(c>=0&&c0&&b-1 in a)}var x=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u="sizzle"+1*new Date,v=a.document,w=0,x=0,y=ha(),z=ha(),A=ha(),B=function(a,b){return a===b&&(l=!0),0},C={}.hasOwnProperty,D=[],E=D.pop,F=D.push,G=D.push,H=D.slice,I=function(a,b){for(var c=0,d=a.length;c+~]|"+K+")"+K+"*"),S=new RegExp("="+K+"*([^\\]'\"]*?)"+K+"*\\]","g"),T=new RegExp(N),U=new RegExp("^"+L+"$"),V={ID:new RegExp("^#("+L+")"),CLASS:new RegExp("^\\.("+L+")"),TAG:new RegExp("^("+L+"|[*])"),ATTR:new RegExp("^"+M),PSEUDO:new RegExp("^"+N),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+K+"*(even|odd|(([+-]|)(\\d*)n|)"+K+"*(?:([+-]|)"+K+"*(\\d+)|))"+K+"*\\)|)","i"),bool:new RegExp("^(?:"+J+")$","i"),needsContext:new RegExp("^"+K+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+K+"*((?:-\\d)?\\d*)"+K+"*\\)|)(?=[^-]|$)","i")},W=/^(?:input|select|textarea|button)$/i,X=/^h\d$/i,Y=/^[^{]+\{\s*\[native \w/,Z=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,$=/[+~]/,_=new RegExp("\\\\([\\da-f]{1,6}"+K+"?|("+K+")|.)","ig"),aa=function(a,b,c){var d="0x"+b-65536;return d!==d||c?b:d<0?String.fromCharCode(d+65536):String.fromCharCode(d>>10|55296,1023&d|56320)},ba=/([\0-\x1f\x7f]|^-?\d)|^-$|[^\0-\x1f\x7f-\uFFFF\w-]/g,ca=function(a,b){return b?"\0"===a?"\ufffd":a.slice(0,-1)+"\\"+a.charCodeAt(a.length-1).toString(16)+" ":"\\"+a},da=function(){m()},ea=ta(function(a){return a.disabled===!0&&("form"in a||"label"in a)},{dir:"parentNode",next:"legend"});try{G.apply(D=H.call(v.childNodes),v.childNodes),D[v.childNodes.length].nodeType}catch(fa){G={apply:D.length?function(a,b){F.apply(a,H.call(b))}:function(a,b){var c=a.length,d=0;while(a[c++]=b[d++]);a.length=c-1}}}function ga(a,b,d,e){var f,h,j,k,l,o,r,s=b&&b.ownerDocument,w=b?b.nodeType:9;if(d=d||[],"string"!=typeof a||!a||1!==w&&9!==w&&11!==w)return d;if(!e&&((b?b.ownerDocument||b:v)!==n&&m(b),b=b||n,p)){if(11!==w&&(l=Z.exec(a)))if(f=l[1]){if(9===w){if(!(j=b.getElementById(f)))return d;if(j.id===f)return d.push(j),d}else if(s&&(j=s.getElementById(f))&&t(b,j)&&j.id===f)return d.push(j),d}else{if(l[2])return G.apply(d,b.getElementsByTagName(a)),d;if((f=l[3])&&c.getElementsByClassName&&b.getElementsByClassName)return G.apply(d,b.getElementsByClassName(f)),d}if(c.qsa&&!A[a+" "]&&(!q||!q.test(a))){if(1!==w)s=b,r=a;else if("object"!==b.nodeName.toLowerCase()){(k=b.getAttribute("id"))?k=k.replace(ba,ca):b.setAttribute("id",k=u),o=g(a),h=o.length;while(h--)o[h]="#"+k+" "+sa(o[h]);r=o.join(","),s=$.test(a)&&qa(b.parentNode)||b}if(r)try{return G.apply(d,s.querySelectorAll(r)),d}catch(x){}finally{k===u&&b.removeAttribute("id")}}}return i(a.replace(P,"$1"),b,d,e)}function ha(){var a=[];function b(c,e){return a.push(c+" ")>d.cacheLength&&delete b[a.shift()],b[c+" "]=e}return b}function ia(a){return a[u]=!0,a}function ja(a){var b=n.createElement("fieldset");try{return!!a(b)}catch(c){return!1}finally{b.parentNode&&b.parentNode.removeChild(b),b=null}}function ka(a,b){var c=a.split("|"),e=c.length;while(e--)d.attrHandle[c[e]]=b}function la(a,b){var c=b&&a,d=c&&1===a.nodeType&&1===b.nodeType&&a.sourceIndex-b.sourceIndex;if(d)return d;if(c)while(c=c.nextSibling)if(c===b)return-1;return a?1:-1}function ma(a){return function(b){var c=b.nodeName.toLowerCase();return"input"===c&&b.type===a}}function na(a){return function(b){var c=b.nodeName.toLowerCase();return("input"===c||"button"===c)&&b.type===a}}function oa(a){return function(b){return"form"in b?b.parentNode&&b.disabled===!1?"label"in b?"label"in b.parentNode?b.parentNode.disabled===a:b.disabled===a:b.isDisabled===a||b.isDisabled!==!a&&ea(b)===a:b.disabled===a:"label"in b&&b.disabled===a}}function pa(a){return ia(function(b){return b=+b,ia(function(c,d){var e,f=a([],c.length,b),g=f.length;while(g--)c[e=f[g]]&&(c[e]=!(d[e]=c[e]))})})}function qa(a){return a&&"undefined"!=typeof a.getElementsByTagName&&a}c=ga.support={},f=ga.isXML=function(a){var b=a&&(a.ownerDocument||a).documentElement;return!!b&&"HTML"!==b.nodeName},m=ga.setDocument=function(a){var b,e,g=a?a.ownerDocument||a:v;return g!==n&&9===g.nodeType&&g.documentElement?(n=g,o=n.documentElement,p=!f(n),v!==n&&(e=n.defaultView)&&e.top!==e&&(e.addEventListener?e.addEventListener("unload",da,!1):e.attachEvent&&e.attachEvent("onunload",da)),c.attributes=ja(function(a){return a.className="i",!a.getAttribute("className")}),c.getElementsByTagName=ja(function(a){return a.appendChild(n.createComment("")),!a.getElementsByTagName("*").length}),c.getElementsByClassName=Y.test(n.getElementsByClassName),c.getById=ja(function(a){return o.appendChild(a).id=u,!n.getElementsByName||!n.getElementsByName(u).length}),c.getById?(d.filter.ID=function(a){var b=a.replace(_,aa);return function(a){return a.getAttribute("id")===b}},d.find.ID=function(a,b){if("undefined"!=typeof b.getElementById&&p){var c=b.getElementById(a);return c?[c]:[]}}):(d.filter.ID=function(a){var b=a.replace(_,aa);return function(a){var c="undefined"!=typeof a.getAttributeNode&&a.getAttributeNode("id");return c&&c.value===b}},d.find.ID=function(a,b){if("undefined"!=typeof b.getElementById&&p){var c,d,e,f=b.getElementById(a);if(f){if(c=f.getAttributeNode("id"),c&&c.value===a)return[f];e=b.getElementsByName(a),d=0;while(f=e[d++])if(c=f.getAttributeNode("id"),c&&c.value===a)return[f]}return[]}}),d.find.TAG=c.getElementsByTagName?function(a,b){return"undefined"!=typeof b.getElementsByTagName?b.getElementsByTagName(a):c.qsa?b.querySelectorAll(a):void 0}:function(a,b){var c,d=[],e=0,f=b.getElementsByTagName(a);if("*"===a){while(c=f[e++])1===c.nodeType&&d.push(c);return d}return f},d.find.CLASS=c.getElementsByClassName&&function(a,b){if("undefined"!=typeof b.getElementsByClassName&&p)return b.getElementsByClassName(a)},r=[],q=[],(c.qsa=Y.test(n.querySelectorAll))&&(ja(function(a){o.appendChild(a).innerHTML="",a.querySelectorAll("[msallowcapture^='']").length&&q.push("[*^$]="+K+"*(?:''|\"\")"),a.querySelectorAll("[selected]").length||q.push("\\["+K+"*(?:value|"+J+")"),a.querySelectorAll("[id~="+u+"-]").length||q.push("~="),a.querySelectorAll(":checked").length||q.push(":checked"),a.querySelectorAll("a#"+u+"+*").length||q.push(".#.+[+~]")}),ja(function(a){a.innerHTML="";var b=n.createElement("input");b.setAttribute("type","hidden"),a.appendChild(b).setAttribute("name","D"),a.querySelectorAll("[name=d]").length&&q.push("name"+K+"*[*^$|!~]?="),2!==a.querySelectorAll(":enabled").length&&q.push(":enabled",":disabled"),o.appendChild(a).disabled=!0,2!==a.querySelectorAll(":disabled").length&&q.push(":enabled",":disabled"),a.querySelectorAll("*,:x"),q.push(",.*:")})),(c.matchesSelector=Y.test(s=o.matches||o.webkitMatchesSelector||o.mozMatchesSelector||o.oMatchesSelector||o.msMatchesSelector))&&ja(function(a){c.disconnectedMatch=s.call(a,"*"),s.call(a,"[s!='']:x"),r.push("!=",N)}),q=q.length&&new RegExp(q.join("|")),r=r.length&&new RegExp(r.join("|")),b=Y.test(o.compareDocumentPosition),t=b||Y.test(o.contains)?function(a,b){var c=9===a.nodeType?a.documentElement:a,d=b&&b.parentNode;return a===d||!(!d||1!==d.nodeType||!(c.contains?c.contains(d):a.compareDocumentPosition&&16&a.compareDocumentPosition(d)))}:function(a,b){if(b)while(b=b.parentNode)if(b===a)return!0;return!1},B=b?function(a,b){if(a===b)return l=!0,0;var d=!a.compareDocumentPosition-!b.compareDocumentPosition;return d?d:(d=(a.ownerDocument||a)===(b.ownerDocument||b)?a.compareDocumentPosition(b):1,1&d||!c.sortDetached&&b.compareDocumentPosition(a)===d?a===n||a.ownerDocument===v&&t(v,a)?-1:b===n||b.ownerDocument===v&&t(v,b)?1:k?I(k,a)-I(k,b):0:4&d?-1:1)}:function(a,b){if(a===b)return l=!0,0;var c,d=0,e=a.parentNode,f=b.parentNode,g=[a],h=[b];if(!e||!f)return a===n?-1:b===n?1:e?-1:f?1:k?I(k,a)-I(k,b):0;if(e===f)return la(a,b);c=a;while(c=c.parentNode)g.unshift(c);c=b;while(c=c.parentNode)h.unshift(c);while(g[d]===h[d])d++;return d?la(g[d],h[d]):g[d]===v?-1:h[d]===v?1:0},n):n},ga.matches=function(a,b){return ga(a,null,null,b)},ga.matchesSelector=function(a,b){if((a.ownerDocument||a)!==n&&m(a),b=b.replace(S,"='$1']"),c.matchesSelector&&p&&!A[b+" "]&&(!r||!r.test(b))&&(!q||!q.test(b)))try{var d=s.call(a,b);if(d||c.disconnectedMatch||a.document&&11!==a.document.nodeType)return d}catch(e){}return ga(b,n,null,[a]).length>0},ga.contains=function(a,b){return(a.ownerDocument||a)!==n&&m(a),t(a,b)},ga.attr=function(a,b){(a.ownerDocument||a)!==n&&m(a);var e=d.attrHandle[b.toLowerCase()],f=e&&C.call(d.attrHandle,b.toLowerCase())?e(a,b,!p):void 0;return void 0!==f?f:c.attributes||!p?a.getAttribute(b):(f=a.getAttributeNode(b))&&f.specified?f.value:null},ga.escape=function(a){return(a+"").replace(ba,ca)},ga.error=function(a){throw new Error("Syntax error, unrecognized expression: "+a)},ga.uniqueSort=function(a){var b,d=[],e=0,f=0;if(l=!c.detectDuplicates,k=!c.sortStable&&a.slice(0),a.sort(B),l){while(b=a[f++])b===a[f]&&(e=d.push(f));while(e--)a.splice(d[e],1)}return k=null,a},e=ga.getText=function(a){var b,c="",d=0,f=a.nodeType;if(f){if(1===f||9===f||11===f){if("string"==typeof a.textContent)return a.textContent;for(a=a.firstChild;a;a=a.nextSibling)c+=e(a)}else if(3===f||4===f)return a.nodeValue}else while(b=a[d++])c+=e(b);return c},d=ga.selectors={cacheLength:50,createPseudo:ia,match:V,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(a){return a[1]=a[1].replace(_,aa),a[3]=(a[3]||a[4]||a[5]||"").replace(_,aa),"~="===a[2]&&(a[3]=" "+a[3]+" "),a.slice(0,4)},CHILD:function(a){return a[1]=a[1].toLowerCase(),"nth"===a[1].slice(0,3)?(a[3]||ga.error(a[0]),a[4]=+(a[4]?a[5]+(a[6]||1):2*("even"===a[3]||"odd"===a[3])),a[5]=+(a[7]+a[8]||"odd"===a[3])):a[3]&&ga.error(a[0]),a},PSEUDO:function(a){var b,c=!a[6]&&a[2];return V.CHILD.test(a[0])?null:(a[3]?a[2]=a[4]||a[5]||"":c&&T.test(c)&&(b=g(c,!0))&&(b=c.indexOf(")",c.length-b)-c.length)&&(a[0]=a[0].slice(0,b),a[2]=c.slice(0,b)),a.slice(0,3))}},filter:{TAG:function(a){var b=a.replace(_,aa).toLowerCase();return"*"===a?function(){return!0}:function(a){return a.nodeName&&a.nodeName.toLowerCase()===b}},CLASS:function(a){var b=y[a+" "];return b||(b=new RegExp("(^|"+K+")"+a+"("+K+"|$)"))&&y(a,function(a){return b.test("string"==typeof a.className&&a.className||"undefined"!=typeof a.getAttribute&&a.getAttribute("class")||"")})},ATTR:function(a,b,c){return function(d){var e=ga.attr(d,a);return null==e?"!="===b:!b||(e+="","="===b?e===c:"!="===b?e!==c:"^="===b?c&&0===e.indexOf(c):"*="===b?c&&e.indexOf(c)>-1:"$="===b?c&&e.slice(-c.length)===c:"~="===b?(" "+e.replace(O," ")+" ").indexOf(c)>-1:"|="===b&&(e===c||e.slice(0,c.length+1)===c+"-"))}},CHILD:function(a,b,c,d,e){var f="nth"!==a.slice(0,3),g="last"!==a.slice(-4),h="of-type"===b;return 1===d&&0===e?function(a){return!!a.parentNode}:function(b,c,i){var j,k,l,m,n,o,p=f!==g?"nextSibling":"previousSibling",q=b.parentNode,r=h&&b.nodeName.toLowerCase(),s=!i&&!h,t=!1;if(q){if(f){while(p){m=b;while(m=m[p])if(h?m.nodeName.toLowerCase()===r:1===m.nodeType)return!1;o=p="only"===a&&!o&&"nextSibling"}return!0}if(o=[g?q.firstChild:q.lastChild],g&&s){m=q,l=m[u]||(m[u]={}),k=l[m.uniqueID]||(l[m.uniqueID]={}),j=k[a]||[],n=j[0]===w&&j[1],t=n&&j[2],m=n&&q.childNodes[n];while(m=++n&&m&&m[p]||(t=n=0)||o.pop())if(1===m.nodeType&&++t&&m===b){k[a]=[w,n,t];break}}else if(s&&(m=b,l=m[u]||(m[u]={}),k=l[m.uniqueID]||(l[m.uniqueID]={}),j=k[a]||[],n=j[0]===w&&j[1],t=n),t===!1)while(m=++n&&m&&m[p]||(t=n=0)||o.pop())if((h?m.nodeName.toLowerCase()===r:1===m.nodeType)&&++t&&(s&&(l=m[u]||(m[u]={}),k=l[m.uniqueID]||(l[m.uniqueID]={}),k[a]=[w,t]),m===b))break;return t-=e,t===d||t%d===0&&t/d>=0}}},PSEUDO:function(a,b){var c,e=d.pseudos[a]||d.setFilters[a.toLowerCase()]||ga.error("unsupported pseudo: "+a);return e[u]?e(b):e.length>1?(c=[a,a,"",b],d.setFilters.hasOwnProperty(a.toLowerCase())?ia(function(a,c){var d,f=e(a,b),g=f.length;while(g--)d=I(a,f[g]),a[d]=!(c[d]=f[g])}):function(a){return e(a,0,c)}):e}},pseudos:{not:ia(function(a){var b=[],c=[],d=h(a.replace(P,"$1"));return d[u]?ia(function(a,b,c,e){var f,g=d(a,null,e,[]),h=a.length;while(h--)(f=g[h])&&(a[h]=!(b[h]=f))}):function(a,e,f){return b[0]=a,d(b,null,f,c),b[0]=null,!c.pop()}}),has:ia(function(a){return function(b){return ga(a,b).length>0}}),contains:ia(function(a){return a=a.replace(_,aa),function(b){return(b.textContent||b.innerText||e(b)).indexOf(a)>-1}}),lang:ia(function(a){return U.test(a||"")||ga.error("unsupported lang: "+a),a=a.replace(_,aa).toLowerCase(),function(b){var c;do if(c=p?b.lang:b.getAttribute("xml:lang")||b.getAttribute("lang"))return c=c.toLowerCase(),c===a||0===c.indexOf(a+"-");while((b=b.parentNode)&&1===b.nodeType);return!1}}),target:function(b){var c=a.location&&a.location.hash;return c&&c.slice(1)===b.id},root:function(a){return a===o},focus:function(a){return a===n.activeElement&&(!n.hasFocus||n.hasFocus())&&!!(a.type||a.href||~a.tabIndex)},enabled:oa(!1),disabled:oa(!0),checked:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&!!a.checked||"option"===b&&!!a.selected},selected:function(a){return a.parentNode&&a.parentNode.selectedIndex,a.selected===!0},empty:function(a){for(a=a.firstChild;a;a=a.nextSibling)if(a.nodeType<6)return!1;return!0},parent:function(a){return!d.pseudos.empty(a)},header:function(a){return X.test(a.nodeName)},input:function(a){return W.test(a.nodeName)},button:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&"button"===a.type||"button"===b},text:function(a){var b;return"input"===a.nodeName.toLowerCase()&&"text"===a.type&&(null==(b=a.getAttribute("type"))||"text"===b.toLowerCase())},first:pa(function(){return[0]}),last:pa(function(a,b){return[b-1]}),eq:pa(function(a,b,c){return[c<0?c+b:c]}),even:pa(function(a,b){for(var c=0;c=0;)a.push(d);return a}),gt:pa(function(a,b,c){for(var d=c<0?c+b:c;++d1?function(b,c,d){var e=a.length;while(e--)if(!a[e](b,c,d))return!1;return!0}:a[0]}function va(a,b,c){for(var d=0,e=b.length;d-1&&(f[j]=!(g[j]=l))}}else r=wa(r===g?r.splice(o,r.length):r),e?e(null,g,r,i):G.apply(g,r)})}function ya(a){for(var b,c,e,f=a.length,g=d.relative[a[0].type],h=g||d.relative[" "],i=g?1:0,k=ta(function(a){return a===b},h,!0),l=ta(function(a){return I(b,a)>-1},h,!0),m=[function(a,c,d){var e=!g&&(d||c!==j)||((b=c).nodeType?k(a,c,d):l(a,c,d));return b=null,e}];i1&&ua(m),i>1&&sa(a.slice(0,i-1).concat({value:" "===a[i-2].type?"*":""})).replace(P,"$1"),c,i0,e=a.length>0,f=function(f,g,h,i,k){var l,o,q,r=0,s="0",t=f&&[],u=[],v=j,x=f||e&&d.find.TAG("*",k),y=w+=null==v?1:Math.random()||.1,z=x.length;for(k&&(j=g===n||g||k);s!==z&&null!=(l=x[s]);s++){if(e&&l){o=0,g||l.ownerDocument===n||(m(l),h=!p);while(q=a[o++])if(q(l,g||n,h)){i.push(l);break}k&&(w=y)}c&&((l=!q&&l)&&r--,f&&t.push(l))}if(r+=s,c&&s!==r){o=0;while(q=b[o++])q(t,u,g,h);if(f){if(r>0)while(s--)t[s]||u[s]||(u[s]=E.call(i));u=wa(u)}G.apply(i,u),k&&!f&&u.length>0&&r+b.length>1&&ga.uniqueSort(i)}return k&&(w=y,j=v),t};return c?ia(f):f}return h=ga.compile=function(a,b){var c,d=[],e=[],f=A[a+" "];if(!f){b||(b=g(a)),c=b.length;while(c--)f=ya(b[c]),f[u]?d.push(f):e.push(f);f=A(a,za(e,d)),f.selector=a}return f},i=ga.select=function(a,b,c,e){var f,i,j,k,l,m="function"==typeof a&&a,n=!e&&g(a=m.selector||a);if(c=c||[],1===n.length){if(i=n[0]=n[0].slice(0),i.length>2&&"ID"===(j=i[0]).type&&9===b.nodeType&&p&&d.relative[i[1].type]){if(b=(d.find.ID(j.matches[0].replace(_,aa),b)||[])[0],!b)return c;m&&(b=b.parentNode),a=a.slice(i.shift().value.length)}f=V.needsContext.test(a)?0:i.length;while(f--){if(j=i[f],d.relative[k=j.type])break;if((l=d.find[k])&&(e=l(j.matches[0].replace(_,aa),$.test(i[0].type)&&qa(b.parentNode)||b))){if(i.splice(f,1),a=e.length&&sa(i),!a)return G.apply(c,e),c;break}}}return(m||h(a,n))(e,b,!p,c,!b||$.test(a)&&qa(b.parentNode)||b),c},c.sortStable=u.split("").sort(B).join("")===u,c.detectDuplicates=!!l,m(),c.sortDetached=ja(function(a){return 1&a.compareDocumentPosition(n.createElement("fieldset"))}),ja(function(a){return a.innerHTML="","#"===a.firstChild.getAttribute("href")})||ka("type|href|height|width",function(a,b,c){if(!c)return a.getAttribute(b,"type"===b.toLowerCase()?1:2)}),c.attributes&&ja(function(a){return a.innerHTML="",a.firstChild.setAttribute("value",""),""===a.firstChild.getAttribute("value")})||ka("value",function(a,b,c){if(!c&&"input"===a.nodeName.toLowerCase())return a.defaultValue}),ja(function(a){return null==a.getAttribute("disabled")})||ka(J,function(a,b,c){var d;if(!c)return a[b]===!0?b.toLowerCase():(d=a.getAttributeNode(b))&&d.specified?d.value:null}),ga}(a);r.find=x,r.expr=x.selectors,r.expr[":"]=r.expr.pseudos,r.uniqueSort=r.unique=x.uniqueSort,r.text=x.getText,r.isXMLDoc=x.isXML,r.contains=x.contains,r.escapeSelector=x.escape;var y=function(a,b,c){var d=[],e=void 0!==c;while((a=a[b])&&9!==a.nodeType)if(1===a.nodeType){if(e&&r(a).is(c))break;d.push(a)}return d},z=function(a,b){for(var c=[];a;a=a.nextSibling)1===a.nodeType&&a!==b&&c.push(a);return c},A=r.expr.match.needsContext;function B(a,b){return a.nodeName&&a.nodeName.toLowerCase()===b.toLowerCase()}var C=/^<([a-z][^\/\0>:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i,D=/^.[^:#\[\.,]*$/;function E(a,b,c){return r.isFunction(b)?r.grep(a,function(a,d){return!!b.call(a,d,a)!==c}):b.nodeType?r.grep(a,function(a){return a===b!==c}):"string"!=typeof b?r.grep(a,function(a){return i.call(b,a)>-1!==c}):D.test(b)?r.filter(b,a,c):(b=r.filter(b,a),r.grep(a,function(a){return i.call(b,a)>-1!==c&&1===a.nodeType}))}r.filter=function(a,b,c){var d=b[0];return c&&(a=":not("+a+")"),1===b.length&&1===d.nodeType?r.find.matchesSelector(d,a)?[d]:[]:r.find.matches(a,r.grep(b,function(a){return 1===a.nodeType}))},r.fn.extend({find:function(a){var b,c,d=this.length,e=this;if("string"!=typeof a)return this.pushStack(r(a).filter(function(){for(b=0;b1?r.uniqueSort(c):c},filter:function(a){return this.pushStack(E(this,a||[],!1))},not:function(a){return this.pushStack(E(this,a||[],!0))},is:function(a){return!!E(this,"string"==typeof a&&A.test(a)?r(a):a||[],!1).length}});var F,G=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]+))$/,H=r.fn.init=function(a,b,c){var e,f;if(!a)return this;if(c=c||F,"string"==typeof a){if(e="<"===a[0]&&">"===a[a.length-1]&&a.length>=3?[null,a,null]:G.exec(a),!e||!e[1]&&b)return!b||b.jquery?(b||c).find(a):this.constructor(b).find(a);if(e[1]){if(b=b instanceof r?b[0]:b,r.merge(this,r.parseHTML(e[1],b&&b.nodeType?b.ownerDocument||b:d,!0)),C.test(e[1])&&r.isPlainObject(b))for(e in b)r.isFunction(this[e])?this[e](b[e]):this.attr(e,b[e]);return this}return f=d.getElementById(e[2]),f&&(this[0]=f,this.length=1),this}return a.nodeType?(this[0]=a,this.length=1,this):r.isFunction(a)?void 0!==c.ready?c.ready(a):a(r):r.makeArray(a,this)};H.prototype=r.fn,F=r(d);var I=/^(?:parents|prev(?:Until|All))/,J={children:!0,contents:!0,next:!0,prev:!0};r.fn.extend({has:function(a){var b=r(a,this),c=b.length;return this.filter(function(){for(var a=0;a-1:1===c.nodeType&&r.find.matchesSelector(c,a))){f.push(c);break}return this.pushStack(f.length>1?r.uniqueSort(f):f)},index:function(a){return a?"string"==typeof a?i.call(r(a),this[0]):i.call(this,a.jquery?a[0]:a):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(a,b){return this.pushStack(r.uniqueSort(r.merge(this.get(),r(a,b))))},addBack:function(a){return this.add(null==a?this.prevObject:this.prevObject.filter(a))}});function K(a,b){while((a=a[b])&&1!==a.nodeType);return a}r.each({parent:function(a){var b=a.parentNode;return b&&11!==b.nodeType?b:null},parents:function(a){return y(a,"parentNode")},parentsUntil:function(a,b,c){return y(a,"parentNode",c)},next:function(a){return K(a,"nextSibling")},prev:function(a){return K(a,"previousSibling")},nextAll:function(a){return y(a,"nextSibling")},prevAll:function(a){return y(a,"previousSibling")},nextUntil:function(a,b,c){return y(a,"nextSibling",c)},prevUntil:function(a,b,c){return y(a,"previousSibling",c)},siblings:function(a){return z((a.parentNode||{}).firstChild,a)},children:function(a){return z(a.firstChild)},contents:function(a){return B(a,"iframe")?a.contentDocument:(B(a,"template")&&(a=a.content||a),r.merge([],a.childNodes))}},function(a,b){r.fn[a]=function(c,d){var e=r.map(this,b,c);return"Until"!==a.slice(-5)&&(d=c),d&&"string"==typeof d&&(e=r.filter(d,e)),this.length>1&&(J[a]||r.uniqueSort(e),I.test(a)&&e.reverse()),this.pushStack(e)}});var L=/[^\x20\t\r\n\f]+/g;function M(a){var b={};return r.each(a.match(L)||[],function(a,c){b[c]=!0}),b}r.Callbacks=function(a){a="string"==typeof a?M(a):r.extend({},a);var b,c,d,e,f=[],g=[],h=-1,i=function(){for(e=e||a.once,d=b=!0;g.length;h=-1){c=g.shift();while(++h-1)f.splice(c,1),c<=h&&h--}),this},has:function(a){return a?r.inArray(a,f)>-1:f.length>0},empty:function(){return f&&(f=[]),this},disable:function(){return e=g=[],f=c="",this},disabled:function(){return!f},lock:function(){return e=g=[],c||b||(f=c=""),this},locked:function(){return!!e},fireWith:function(a,c){return e||(c=c||[],c=[a,c.slice?c.slice():c],g.push(c),b||i()),this},fire:function(){return j.fireWith(this,arguments),this},fired:function(){return!!d}};return j};function N(a){return a}function O(a){throw a}function P(a,b,c,d){var e;try{a&&r.isFunction(e=a.promise)?e.call(a).done(b).fail(c):a&&r.isFunction(e=a.then)?e.call(a,b,c):b.apply(void 0,[a].slice(d))}catch(a){c.apply(void 0,[a])}}r.extend({Deferred:function(b){var c=[["notify","progress",r.Callbacks("memory"),r.Callbacks("memory"),2],["resolve","done",r.Callbacks("once memory"),r.Callbacks("once memory"),0,"resolved"],["reject","fail",r.Callbacks("once memory"),r.Callbacks("once memory"),1,"rejected"]],d="pending",e={state:function(){return d},always:function(){return f.done(arguments).fail(arguments),this},"catch":function(a){return e.then(null,a)},pipe:function(){var a=arguments;return r.Deferred(function(b){r.each(c,function(c,d){var e=r.isFunction(a[d[4]])&&a[d[4]];f[d[1]](function(){var a=e&&e.apply(this,arguments);a&&r.isFunction(a.promise)?a.promise().progress(b.notify).done(b.resolve).fail(b.reject):b[d[0]+"With"](this,e?[a]:arguments)})}),a=null}).promise()},then:function(b,d,e){var f=0;function g(b,c,d,e){return function(){var h=this,i=arguments,j=function(){var a,j;if(!(b=f&&(d!==O&&(h=void 0,i=[a]),c.rejectWith(h,i))}};b?k():(r.Deferred.getStackHook&&(k.stackTrace=r.Deferred.getStackHook()),a.setTimeout(k))}}return r.Deferred(function(a){c[0][3].add(g(0,a,r.isFunction(e)?e:N,a.notifyWith)),c[1][3].add(g(0,a,r.isFunction(b)?b:N)),c[2][3].add(g(0,a,r.isFunction(d)?d:O))}).promise()},promise:function(a){return null!=a?r.extend(a,e):e}},f={};return r.each(c,function(a,b){var g=b[2],h=b[5];e[b[1]]=g.add,h&&g.add(function(){d=h},c[3-a][2].disable,c[0][2].lock),g.add(b[3].fire),f[b[0]]=function(){return f[b[0]+"With"](this===f?void 0:this,arguments),this},f[b[0]+"With"]=g.fireWith}),e.promise(f),b&&b.call(f,f),f},when:function(a){var b=arguments.length,c=b,d=Array(c),e=f.call(arguments),g=r.Deferred(),h=function(a){return function(c){d[a]=this,e[a]=arguments.length>1?f.call(arguments):c,--b||g.resolveWith(d,e)}};if(b<=1&&(P(a,g.done(h(c)).resolve,g.reject,!b),"pending"===g.state()||r.isFunction(e[c]&&e[c].then)))return g.then();while(c--)P(e[c],h(c),g.reject);return g.promise()}});var Q=/^(Eval|Internal|Range|Reference|Syntax|Type|URI)Error$/;r.Deferred.exceptionHook=function(b,c){a.console&&a.console.warn&&b&&Q.test(b.name)&&a.console.warn("jQuery.Deferred exception: "+b.message,b.stack,c)},r.readyException=function(b){a.setTimeout(function(){throw b})};var R=r.Deferred();r.fn.ready=function(a){return R.then(a)["catch"](function(a){r.readyException(a)}),this},r.extend({isReady:!1,readyWait:1,ready:function(a){(a===!0?--r.readyWait:r.isReady)||(r.isReady=!0,a!==!0&&--r.readyWait>0||R.resolveWith(d,[r]))}}),r.ready.then=R.then;function S(){d.removeEventListener("DOMContentLoaded",S), -a.removeEventListener("load",S),r.ready()}"complete"===d.readyState||"loading"!==d.readyState&&!d.documentElement.doScroll?a.setTimeout(r.ready):(d.addEventListener("DOMContentLoaded",S),a.addEventListener("load",S));var T=function(a,b,c,d,e,f,g){var h=0,i=a.length,j=null==c;if("object"===r.type(c)){e=!0;for(h in c)T(a,b,h,c[h],!0,f,g)}else if(void 0!==d&&(e=!0,r.isFunction(d)||(g=!0),j&&(g?(b.call(a,d),b=null):(j=b,b=function(a,b,c){return j.call(r(a),c)})),b))for(;h1,null,!0)},removeData:function(a){return this.each(function(){X.remove(this,a)})}}),r.extend({queue:function(a,b,c){var d;if(a)return b=(b||"fx")+"queue",d=W.get(a,b),c&&(!d||Array.isArray(c)?d=W.access(a,b,r.makeArray(c)):d.push(c)),d||[]},dequeue:function(a,b){b=b||"fx";var c=r.queue(a,b),d=c.length,e=c.shift(),f=r._queueHooks(a,b),g=function(){r.dequeue(a,b)};"inprogress"===e&&(e=c.shift(),d--),e&&("fx"===b&&c.unshift("inprogress"),delete f.stop,e.call(a,g,f)),!d&&f&&f.empty.fire()},_queueHooks:function(a,b){var c=b+"queueHooks";return W.get(a,c)||W.access(a,c,{empty:r.Callbacks("once memory").add(function(){W.remove(a,[b+"queue",c])})})}}),r.fn.extend({queue:function(a,b){var c=2;return"string"!=typeof a&&(b=a,a="fx",c--),arguments.length\x20\t\r\n\f]+)/i,la=/^$|\/(?:java|ecma)script/i,ma={option:[1,""],thead:[1,"","
    "],col:[2,"","
    "],tr:[2,"","
    "],td:[3,"","
    "],_default:[0,"",""]};ma.optgroup=ma.option,ma.tbody=ma.tfoot=ma.colgroup=ma.caption=ma.thead,ma.th=ma.td;function na(a,b){var c;return c="undefined"!=typeof a.getElementsByTagName?a.getElementsByTagName(b||"*"):"undefined"!=typeof a.querySelectorAll?a.querySelectorAll(b||"*"):[],void 0===b||b&&B(a,b)?r.merge([a],c):c}function oa(a,b){for(var c=0,d=a.length;c-1)e&&e.push(f);else if(j=r.contains(f.ownerDocument,f),g=na(l.appendChild(f),"script"),j&&oa(g),c){k=0;while(f=g[k++])la.test(f.type||"")&&c.push(f)}return l}!function(){var a=d.createDocumentFragment(),b=a.appendChild(d.createElement("div")),c=d.createElement("input");c.setAttribute("type","radio"),c.setAttribute("checked","checked"),c.setAttribute("name","t"),b.appendChild(c),o.checkClone=b.cloneNode(!0).cloneNode(!0).lastChild.checked,b.innerHTML="",o.noCloneChecked=!!b.cloneNode(!0).lastChild.defaultValue}();var ra=d.documentElement,sa=/^key/,ta=/^(?:mouse|pointer|contextmenu|drag|drop)|click/,ua=/^([^.]*)(?:\.(.+)|)/;function va(){return!0}function wa(){return!1}function xa(){try{return d.activeElement}catch(a){}}function ya(a,b,c,d,e,f){var g,h;if("object"==typeof b){"string"!=typeof c&&(d=d||c,c=void 0);for(h in b)ya(a,h,c,d,b[h],f);return a}if(null==d&&null==e?(e=c,d=c=void 0):null==e&&("string"==typeof c?(e=d,d=void 0):(e=d,d=c,c=void 0)),e===!1)e=wa;else if(!e)return a;return 1===f&&(g=e,e=function(a){return r().off(a),g.apply(this,arguments)},e.guid=g.guid||(g.guid=r.guid++)),a.each(function(){r.event.add(this,b,e,d,c)})}r.event={global:{},add:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,n,o,p,q=W.get(a);if(q){c.handler&&(f=c,c=f.handler,e=f.selector),e&&r.find.matchesSelector(ra,e),c.guid||(c.guid=r.guid++),(i=q.events)||(i=q.events={}),(g=q.handle)||(g=q.handle=function(b){return"undefined"!=typeof r&&r.event.triggered!==b.type?r.event.dispatch.apply(a,arguments):void 0}),b=(b||"").match(L)||[""],j=b.length;while(j--)h=ua.exec(b[j])||[],n=p=h[1],o=(h[2]||"").split(".").sort(),n&&(l=r.event.special[n]||{},n=(e?l.delegateType:l.bindType)||n,l=r.event.special[n]||{},k=r.extend({type:n,origType:p,data:d,handler:c,guid:c.guid,selector:e,needsContext:e&&r.expr.match.needsContext.test(e),namespace:o.join(".")},f),(m=i[n])||(m=i[n]=[],m.delegateCount=0,l.setup&&l.setup.call(a,d,o,g)!==!1||a.addEventListener&&a.addEventListener(n,g)),l.add&&(l.add.call(a,k),k.handler.guid||(k.handler.guid=c.guid)),e?m.splice(m.delegateCount++,0,k):m.push(k),r.event.global[n]=!0)}},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,n,o,p,q=W.hasData(a)&&W.get(a);if(q&&(i=q.events)){b=(b||"").match(L)||[""],j=b.length;while(j--)if(h=ua.exec(b[j])||[],n=p=h[1],o=(h[2]||"").split(".").sort(),n){l=r.event.special[n]||{},n=(d?l.delegateType:l.bindType)||n,m=i[n]||[],h=h[2]&&new RegExp("(^|\\.)"+o.join("\\.(?:.*\\.|)")+"(\\.|$)"),g=f=m.length;while(f--)k=m[f],!e&&p!==k.origType||c&&c.guid!==k.guid||h&&!h.test(k.namespace)||d&&d!==k.selector&&("**"!==d||!k.selector)||(m.splice(f,1),k.selector&&m.delegateCount--,l.remove&&l.remove.call(a,k));g&&!m.length&&(l.teardown&&l.teardown.call(a,o,q.handle)!==!1||r.removeEvent(a,n,q.handle),delete i[n])}else for(n in i)r.event.remove(a,n+b[j],c,d,!0);r.isEmptyObject(i)&&W.remove(a,"handle events")}},dispatch:function(a){var b=r.event.fix(a),c,d,e,f,g,h,i=new Array(arguments.length),j=(W.get(this,"events")||{})[b.type]||[],k=r.event.special[b.type]||{};for(i[0]=b,c=1;c=1))for(;j!==this;j=j.parentNode||this)if(1===j.nodeType&&("click"!==a.type||j.disabled!==!0)){for(f=[],g={},c=0;c-1:r.find(e,this,null,[j]).length),g[e]&&f.push(d);f.length&&h.push({elem:j,handlers:f})}return j=this,i\x20\t\r\n\f]*)[^>]*)\/>/gi,Aa=/\s*$/g;function Ea(a,b){return B(a,"table")&&B(11!==b.nodeType?b:b.firstChild,"tr")?r(">tbody",a)[0]||a:a}function Fa(a){return a.type=(null!==a.getAttribute("type"))+"/"+a.type,a}function Ga(a){var b=Ca.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function Ha(a,b){var c,d,e,f,g,h,i,j;if(1===b.nodeType){if(W.hasData(a)&&(f=W.access(a),g=W.set(b,f),j=f.events)){delete g.handle,g.events={};for(e in j)for(c=0,d=j[e].length;c1&&"string"==typeof q&&!o.checkClone&&Ba.test(q))return a.each(function(e){var f=a.eq(e);s&&(b[0]=q.call(this,e,f.html())),Ja(f,b,c,d)});if(m&&(e=qa(b,a[0].ownerDocument,!1,a,d),f=e.firstChild,1===e.childNodes.length&&(e=f),f||d)){for(h=r.map(na(e,"script"),Fa),i=h.length;l")},clone:function(a,b,c){var d,e,f,g,h=a.cloneNode(!0),i=r.contains(a.ownerDocument,a);if(!(o.noCloneChecked||1!==a.nodeType&&11!==a.nodeType||r.isXMLDoc(a)))for(g=na(h),f=na(a),d=0,e=f.length;d0&&oa(g,!i&&na(a,"script")),h},cleanData:function(a){for(var b,c,d,e=r.event.special,f=0;void 0!==(c=a[f]);f++)if(U(c)){if(b=c[W.expando]){if(b.events)for(d in b.events)e[d]?r.event.remove(c,d):r.removeEvent(c,d,b.handle);c[W.expando]=void 0}c[X.expando]&&(c[X.expando]=void 0)}}}),r.fn.extend({detach:function(a){return Ka(this,a,!0)},remove:function(a){return Ka(this,a)},text:function(a){return T(this,function(a){return void 0===a?r.text(this):this.empty().each(function(){1!==this.nodeType&&11!==this.nodeType&&9!==this.nodeType||(this.textContent=a)})},null,a,arguments.length)},append:function(){return Ja(this,arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=Ea(this,a);b.appendChild(a)}})},prepend:function(){return Ja(this,arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=Ea(this,a);b.insertBefore(a,b.firstChild)}})},before:function(){return Ja(this,arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this)})},after:function(){return Ja(this,arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this.nextSibling)})},empty:function(){for(var a,b=0;null!=(a=this[b]);b++)1===a.nodeType&&(r.cleanData(na(a,!1)),a.textContent="");return this},clone:function(a,b){return a=null!=a&&a,b=null==b?a:b,this.map(function(){return r.clone(this,a,b)})},html:function(a){return T(this,function(a){var b=this[0]||{},c=0,d=this.length;if(void 0===a&&1===b.nodeType)return b.innerHTML;if("string"==typeof a&&!Aa.test(a)&&!ma[(ka.exec(a)||["",""])[1].toLowerCase()]){a=r.htmlPrefilter(a);try{for(;c1)}});function _a(a,b,c,d,e){return new _a.prototype.init(a,b,c,d,e)}r.Tween=_a,_a.prototype={constructor:_a,init:function(a,b,c,d,e,f){this.elem=a,this.prop=c,this.easing=e||r.easing._default,this.options=b,this.start=this.now=this.cur(),this.end=d,this.unit=f||(r.cssNumber[c]?"":"px")},cur:function(){var a=_a.propHooks[this.prop];return a&&a.get?a.get(this):_a.propHooks._default.get(this)},run:function(a){var b,c=_a.propHooks[this.prop];return this.options.duration?this.pos=b=r.easing[this.easing](a,this.options.duration*a,0,1,this.options.duration):this.pos=b=a,this.now=(this.end-this.start)*b+this.start,this.options.step&&this.options.step.call(this.elem,this.now,this),c&&c.set?c.set(this):_a.propHooks._default.set(this),this}},_a.prototype.init.prototype=_a.prototype,_a.propHooks={_default:{get:function(a){var b;return 1!==a.elem.nodeType||null!=a.elem[a.prop]&&null==a.elem.style[a.prop]?a.elem[a.prop]:(b=r.css(a.elem,a.prop,""),b&&"auto"!==b?b:0)},set:function(a){r.fx.step[a.prop]?r.fx.step[a.prop](a):1!==a.elem.nodeType||null==a.elem.style[r.cssProps[a.prop]]&&!r.cssHooks[a.prop]?a.elem[a.prop]=a.now:r.style(a.elem,a.prop,a.now+a.unit)}}},_a.propHooks.scrollTop=_a.propHooks.scrollLeft={set:function(a){a.elem.nodeType&&a.elem.parentNode&&(a.elem[a.prop]=a.now)}},r.easing={linear:function(a){return a},swing:function(a){return.5-Math.cos(a*Math.PI)/2},_default:"swing"},r.fx=_a.prototype.init,r.fx.step={};var ab,bb,cb=/^(?:toggle|show|hide)$/,db=/queueHooks$/;function eb(){bb&&(d.hidden===!1&&a.requestAnimationFrame?a.requestAnimationFrame(eb):a.setTimeout(eb,r.fx.interval),r.fx.tick())}function fb(){return a.setTimeout(function(){ab=void 0}),ab=r.now()}function gb(a,b){var c,d=0,e={height:a};for(b=b?1:0;d<4;d+=2-b)c=ca[d],e["margin"+c]=e["padding"+c]=a;return b&&(e.opacity=e.width=a),e}function hb(a,b,c){for(var d,e=(kb.tweeners[b]||[]).concat(kb.tweeners["*"]),f=0,g=e.length;f1)},removeAttr:function(a){return this.each(function(){r.removeAttr(this,a)})}}),r.extend({attr:function(a,b,c){var d,e,f=a.nodeType;if(3!==f&&8!==f&&2!==f)return"undefined"==typeof a.getAttribute?r.prop(a,b,c):(1===f&&r.isXMLDoc(a)||(e=r.attrHooks[b.toLowerCase()]||(r.expr.match.bool.test(b)?lb:void 0)),void 0!==c?null===c?void r.removeAttr(a,b):e&&"set"in e&&void 0!==(d=e.set(a,c,b))?d:(a.setAttribute(b,c+""),c):e&&"get"in e&&null!==(d=e.get(a,b))?d:(d=r.find.attr(a,b), -null==d?void 0:d))},attrHooks:{type:{set:function(a,b){if(!o.radioValue&&"radio"===b&&B(a,"input")){var c=a.value;return a.setAttribute("type",b),c&&(a.value=c),b}}}},removeAttr:function(a,b){var c,d=0,e=b&&b.match(L);if(e&&1===a.nodeType)while(c=e[d++])a.removeAttribute(c)}}),lb={set:function(a,b,c){return b===!1?r.removeAttr(a,c):a.setAttribute(c,c),c}},r.each(r.expr.match.bool.source.match(/\w+/g),function(a,b){var c=mb[b]||r.find.attr;mb[b]=function(a,b,d){var e,f,g=b.toLowerCase();return d||(f=mb[g],mb[g]=e,e=null!=c(a,b,d)?g:null,mb[g]=f),e}});var nb=/^(?:input|select|textarea|button)$/i,ob=/^(?:a|area)$/i;r.fn.extend({prop:function(a,b){return T(this,r.prop,a,b,arguments.length>1)},removeProp:function(a){return this.each(function(){delete this[r.propFix[a]||a]})}}),r.extend({prop:function(a,b,c){var d,e,f=a.nodeType;if(3!==f&&8!==f&&2!==f)return 1===f&&r.isXMLDoc(a)||(b=r.propFix[b]||b,e=r.propHooks[b]),void 0!==c?e&&"set"in e&&void 0!==(d=e.set(a,c,b))?d:a[b]=c:e&&"get"in e&&null!==(d=e.get(a,b))?d:a[b]},propHooks:{tabIndex:{get:function(a){var b=r.find.attr(a,"tabindex");return b?parseInt(b,10):nb.test(a.nodeName)||ob.test(a.nodeName)&&a.href?0:-1}}},propFix:{"for":"htmlFor","class":"className"}}),o.optSelected||(r.propHooks.selected={get:function(a){var b=a.parentNode;return b&&b.parentNode&&b.parentNode.selectedIndex,null},set:function(a){var b=a.parentNode;b&&(b.selectedIndex,b.parentNode&&b.parentNode.selectedIndex)}}),r.each(["tabIndex","readOnly","maxLength","cellSpacing","cellPadding","rowSpan","colSpan","useMap","frameBorder","contentEditable"],function(){r.propFix[this.toLowerCase()]=this});function pb(a){var b=a.match(L)||[];return b.join(" ")}function qb(a){return a.getAttribute&&a.getAttribute("class")||""}r.fn.extend({addClass:function(a){var b,c,d,e,f,g,h,i=0;if(r.isFunction(a))return this.each(function(b){r(this).addClass(a.call(this,b,qb(this)))});if("string"==typeof a&&a){b=a.match(L)||[];while(c=this[i++])if(e=qb(c),d=1===c.nodeType&&" "+pb(e)+" "){g=0;while(f=b[g++])d.indexOf(" "+f+" ")<0&&(d+=f+" ");h=pb(d),e!==h&&c.setAttribute("class",h)}}return this},removeClass:function(a){var b,c,d,e,f,g,h,i=0;if(r.isFunction(a))return this.each(function(b){r(this).removeClass(a.call(this,b,qb(this)))});if(!arguments.length)return this.attr("class","");if("string"==typeof a&&a){b=a.match(L)||[];while(c=this[i++])if(e=qb(c),d=1===c.nodeType&&" "+pb(e)+" "){g=0;while(f=b[g++])while(d.indexOf(" "+f+" ")>-1)d=d.replace(" "+f+" "," ");h=pb(d),e!==h&&c.setAttribute("class",h)}}return this},toggleClass:function(a,b){var c=typeof a;return"boolean"==typeof b&&"string"===c?b?this.addClass(a):this.removeClass(a):r.isFunction(a)?this.each(function(c){r(this).toggleClass(a.call(this,c,qb(this),b),b)}):this.each(function(){var b,d,e,f;if("string"===c){d=0,e=r(this),f=a.match(L)||[];while(b=f[d++])e.hasClass(b)?e.removeClass(b):e.addClass(b)}else void 0!==a&&"boolean"!==c||(b=qb(this),b&&W.set(this,"__className__",b),this.setAttribute&&this.setAttribute("class",b||a===!1?"":W.get(this,"__className__")||""))})},hasClass:function(a){var b,c,d=0;b=" "+a+" ";while(c=this[d++])if(1===c.nodeType&&(" "+pb(qb(c))+" ").indexOf(b)>-1)return!0;return!1}});var rb=/\r/g;r.fn.extend({val:function(a){var b,c,d,e=this[0];{if(arguments.length)return d=r.isFunction(a),this.each(function(c){var e;1===this.nodeType&&(e=d?a.call(this,c,r(this).val()):a,null==e?e="":"number"==typeof e?e+="":Array.isArray(e)&&(e=r.map(e,function(a){return null==a?"":a+""})),b=r.valHooks[this.type]||r.valHooks[this.nodeName.toLowerCase()],b&&"set"in b&&void 0!==b.set(this,e,"value")||(this.value=e))});if(e)return b=r.valHooks[e.type]||r.valHooks[e.nodeName.toLowerCase()],b&&"get"in b&&void 0!==(c=b.get(e,"value"))?c:(c=e.value,"string"==typeof c?c.replace(rb,""):null==c?"":c)}}}),r.extend({valHooks:{option:{get:function(a){var b=r.find.attr(a,"value");return null!=b?b:pb(r.text(a))}},select:{get:function(a){var b,c,d,e=a.options,f=a.selectedIndex,g="select-one"===a.type,h=g?null:[],i=g?f+1:e.length;for(d=f<0?i:g?f:0;d-1)&&(c=!0);return c||(a.selectedIndex=-1),f}}}}),r.each(["radio","checkbox"],function(){r.valHooks[this]={set:function(a,b){if(Array.isArray(b))return a.checked=r.inArray(r(a).val(),b)>-1}},o.checkOn||(r.valHooks[this].get=function(a){return null===a.getAttribute("value")?"on":a.value})});var sb=/^(?:focusinfocus|focusoutblur)$/;r.extend(r.event,{trigger:function(b,c,e,f){var g,h,i,j,k,m,n,o=[e||d],p=l.call(b,"type")?b.type:b,q=l.call(b,"namespace")?b.namespace.split("."):[];if(h=i=e=e||d,3!==e.nodeType&&8!==e.nodeType&&!sb.test(p+r.event.triggered)&&(p.indexOf(".")>-1&&(q=p.split("."),p=q.shift(),q.sort()),k=p.indexOf(":")<0&&"on"+p,b=b[r.expando]?b:new r.Event(p,"object"==typeof b&&b),b.isTrigger=f?2:3,b.namespace=q.join("."),b.rnamespace=b.namespace?new RegExp("(^|\\.)"+q.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,b.result=void 0,b.target||(b.target=e),c=null==c?[b]:r.makeArray(c,[b]),n=r.event.special[p]||{},f||!n.trigger||n.trigger.apply(e,c)!==!1)){if(!f&&!n.noBubble&&!r.isWindow(e)){for(j=n.delegateType||p,sb.test(j+p)||(h=h.parentNode);h;h=h.parentNode)o.push(h),i=h;i===(e.ownerDocument||d)&&o.push(i.defaultView||i.parentWindow||a)}g=0;while((h=o[g++])&&!b.isPropagationStopped())b.type=g>1?j:n.bindType||p,m=(W.get(h,"events")||{})[b.type]&&W.get(h,"handle"),m&&m.apply(h,c),m=k&&h[k],m&&m.apply&&U(h)&&(b.result=m.apply(h,c),b.result===!1&&b.preventDefault());return b.type=p,f||b.isDefaultPrevented()||n._default&&n._default.apply(o.pop(),c)!==!1||!U(e)||k&&r.isFunction(e[p])&&!r.isWindow(e)&&(i=e[k],i&&(e[k]=null),r.event.triggered=p,e[p](),r.event.triggered=void 0,i&&(e[k]=i)),b.result}},simulate:function(a,b,c){var d=r.extend(new r.Event,c,{type:a,isSimulated:!0});r.event.trigger(d,null,b)}}),r.fn.extend({trigger:function(a,b){return this.each(function(){r.event.trigger(a,b,this)})},triggerHandler:function(a,b){var c=this[0];if(c)return r.event.trigger(a,b,c,!0)}}),r.each("blur focus focusin focusout resize scroll click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup contextmenu".split(" "),function(a,b){r.fn[b]=function(a,c){return arguments.length>0?this.on(b,null,a,c):this.trigger(b)}}),r.fn.extend({hover:function(a,b){return this.mouseenter(a).mouseleave(b||a)}}),o.focusin="onfocusin"in a,o.focusin||r.each({focus:"focusin",blur:"focusout"},function(a,b){var c=function(a){r.event.simulate(b,a.target,r.event.fix(a))};r.event.special[b]={setup:function(){var d=this.ownerDocument||this,e=W.access(d,b);e||d.addEventListener(a,c,!0),W.access(d,b,(e||0)+1)},teardown:function(){var d=this.ownerDocument||this,e=W.access(d,b)-1;e?W.access(d,b,e):(d.removeEventListener(a,c,!0),W.remove(d,b))}}});var tb=a.location,ub=r.now(),vb=/\?/;r.parseXML=function(b){var c;if(!b||"string"!=typeof b)return null;try{c=(new a.DOMParser).parseFromString(b,"text/xml")}catch(d){c=void 0}return c&&!c.getElementsByTagName("parsererror").length||r.error("Invalid XML: "+b),c};var wb=/\[\]$/,xb=/\r?\n/g,yb=/^(?:submit|button|image|reset|file)$/i,zb=/^(?:input|select|textarea|keygen)/i;function Ab(a,b,c,d){var e;if(Array.isArray(b))r.each(b,function(b,e){c||wb.test(a)?d(a,e):Ab(a+"["+("object"==typeof e&&null!=e?b:"")+"]",e,c,d)});else if(c||"object"!==r.type(b))d(a,b);else for(e in b)Ab(a+"["+e+"]",b[e],c,d)}r.param=function(a,b){var c,d=[],e=function(a,b){var c=r.isFunction(b)?b():b;d[d.length]=encodeURIComponent(a)+"="+encodeURIComponent(null==c?"":c)};if(Array.isArray(a)||a.jquery&&!r.isPlainObject(a))r.each(a,function(){e(this.name,this.value)});else for(c in a)Ab(c,a[c],b,e);return d.join("&")},r.fn.extend({serialize:function(){return r.param(this.serializeArray())},serializeArray:function(){return this.map(function(){var a=r.prop(this,"elements");return a?r.makeArray(a):this}).filter(function(){var a=this.type;return this.name&&!r(this).is(":disabled")&&zb.test(this.nodeName)&&!yb.test(a)&&(this.checked||!ja.test(a))}).map(function(a,b){var c=r(this).val();return null==c?null:Array.isArray(c)?r.map(c,function(a){return{name:b.name,value:a.replace(xb,"\r\n")}}):{name:b.name,value:c.replace(xb,"\r\n")}}).get()}});var Bb=/%20/g,Cb=/#.*$/,Db=/([?&])_=[^&]*/,Eb=/^(.*?):[ \t]*([^\r\n]*)$/gm,Fb=/^(?:about|app|app-storage|.+-extension|file|res|widget):$/,Gb=/^(?:GET|HEAD)$/,Hb=/^\/\//,Ib={},Jb={},Kb="*/".concat("*"),Lb=d.createElement("a");Lb.href=tb.href;function Mb(a){return function(b,c){"string"!=typeof b&&(c=b,b="*");var d,e=0,f=b.toLowerCase().match(L)||[];if(r.isFunction(c))while(d=f[e++])"+"===d[0]?(d=d.slice(1)||"*",(a[d]=a[d]||[]).unshift(c)):(a[d]=a[d]||[]).push(c)}}function Nb(a,b,c,d){var e={},f=a===Jb;function g(h){var i;return e[h]=!0,r.each(a[h]||[],function(a,h){var j=h(b,c,d);return"string"!=typeof j||f||e[j]?f?!(i=j):void 0:(b.dataTypes.unshift(j),g(j),!1)}),i}return g(b.dataTypes[0])||!e["*"]&&g("*")}function Ob(a,b){var c,d,e=r.ajaxSettings.flatOptions||{};for(c in b)void 0!==b[c]&&((e[c]?a:d||(d={}))[c]=b[c]);return d&&r.extend(!0,a,d),a}function Pb(a,b,c){var d,e,f,g,h=a.contents,i=a.dataTypes;while("*"===i[0])i.shift(),void 0===d&&(d=a.mimeType||b.getResponseHeader("Content-Type"));if(d)for(e in h)if(h[e]&&h[e].test(d)){i.unshift(e);break}if(i[0]in c)f=i[0];else{for(e in c){if(!i[0]||a.converters[e+" "+i[0]]){f=e;break}g||(g=e)}f=f||g}if(f)return f!==i[0]&&i.unshift(f),c[f]}function Qb(a,b,c,d){var e,f,g,h,i,j={},k=a.dataTypes.slice();if(k[1])for(g in a.converters)j[g.toLowerCase()]=a.converters[g];f=k.shift();while(f)if(a.responseFields[f]&&(c[a.responseFields[f]]=b),!i&&d&&a.dataFilter&&(b=a.dataFilter(b,a.dataType)),i=f,f=k.shift())if("*"===f)f=i;else if("*"!==i&&i!==f){if(g=j[i+" "+f]||j["* "+f],!g)for(e in j)if(h=e.split(" "),h[1]===f&&(g=j[i+" "+h[0]]||j["* "+h[0]])){g===!0?g=j[e]:j[e]!==!0&&(f=h[0],k.unshift(h[1]));break}if(g!==!0)if(g&&a["throws"])b=g(b);else try{b=g(b)}catch(l){return{state:"parsererror",error:g?l:"No conversion from "+i+" to "+f}}}return{state:"success",data:b}}r.extend({active:0,lastModified:{},etag:{},ajaxSettings:{url:tb.href,type:"GET",isLocal:Fb.test(tb.protocol),global:!0,processData:!0,async:!0,contentType:"application/x-www-form-urlencoded; charset=UTF-8",accepts:{"*":Kb,text:"text/plain",html:"text/html",xml:"application/xml, text/xml",json:"application/json, text/javascript"},contents:{xml:/\bxml\b/,html:/\bhtml/,json:/\bjson\b/},responseFields:{xml:"responseXML",text:"responseText",json:"responseJSON"},converters:{"* text":String,"text html":!0,"text json":JSON.parse,"text xml":r.parseXML},flatOptions:{url:!0,context:!0}},ajaxSetup:function(a,b){return b?Ob(Ob(a,r.ajaxSettings),b):Ob(r.ajaxSettings,a)},ajaxPrefilter:Mb(Ib),ajaxTransport:Mb(Jb),ajax:function(b,c){"object"==typeof b&&(c=b,b=void 0),c=c||{};var e,f,g,h,i,j,k,l,m,n,o=r.ajaxSetup({},c),p=o.context||o,q=o.context&&(p.nodeType||p.jquery)?r(p):r.event,s=r.Deferred(),t=r.Callbacks("once memory"),u=o.statusCode||{},v={},w={},x="canceled",y={readyState:0,getResponseHeader:function(a){var b;if(k){if(!h){h={};while(b=Eb.exec(g))h[b[1].toLowerCase()]=b[2]}b=h[a.toLowerCase()]}return null==b?null:b},getAllResponseHeaders:function(){return k?g:null},setRequestHeader:function(a,b){return null==k&&(a=w[a.toLowerCase()]=w[a.toLowerCase()]||a,v[a]=b),this},overrideMimeType:function(a){return null==k&&(o.mimeType=a),this},statusCode:function(a){var b;if(a)if(k)y.always(a[y.status]);else for(b in a)u[b]=[u[b],a[b]];return this},abort:function(a){var b=a||x;return e&&e.abort(b),A(0,b),this}};if(s.promise(y),o.url=((b||o.url||tb.href)+"").replace(Hb,tb.protocol+"//"),o.type=c.method||c.type||o.method||o.type,o.dataTypes=(o.dataType||"*").toLowerCase().match(L)||[""],null==o.crossDomain){j=d.createElement("a");try{j.href=o.url,j.href=j.href,o.crossDomain=Lb.protocol+"//"+Lb.host!=j.protocol+"//"+j.host}catch(z){o.crossDomain=!0}}if(o.data&&o.processData&&"string"!=typeof o.data&&(o.data=r.param(o.data,o.traditional)),Nb(Ib,o,c,y),k)return y;l=r.event&&o.global,l&&0===r.active++&&r.event.trigger("ajaxStart"),o.type=o.type.toUpperCase(),o.hasContent=!Gb.test(o.type),f=o.url.replace(Cb,""),o.hasContent?o.data&&o.processData&&0===(o.contentType||"").indexOf("application/x-www-form-urlencoded")&&(o.data=o.data.replace(Bb,"+")):(n=o.url.slice(f.length),o.data&&(f+=(vb.test(f)?"&":"?")+o.data,delete o.data),o.cache===!1&&(f=f.replace(Db,"$1"),n=(vb.test(f)?"&":"?")+"_="+ub++ +n),o.url=f+n),o.ifModified&&(r.lastModified[f]&&y.setRequestHeader("If-Modified-Since",r.lastModified[f]),r.etag[f]&&y.setRequestHeader("If-None-Match",r.etag[f])),(o.data&&o.hasContent&&o.contentType!==!1||c.contentType)&&y.setRequestHeader("Content-Type",o.contentType),y.setRequestHeader("Accept",o.dataTypes[0]&&o.accepts[o.dataTypes[0]]?o.accepts[o.dataTypes[0]]+("*"!==o.dataTypes[0]?", "+Kb+"; q=0.01":""):o.accepts["*"]);for(m in o.headers)y.setRequestHeader(m,o.headers[m]);if(o.beforeSend&&(o.beforeSend.call(p,y,o)===!1||k))return y.abort();if(x="abort",t.add(o.complete),y.done(o.success),y.fail(o.error),e=Nb(Jb,o,c,y)){if(y.readyState=1,l&&q.trigger("ajaxSend",[y,o]),k)return y;o.async&&o.timeout>0&&(i=a.setTimeout(function(){y.abort("timeout")},o.timeout));try{k=!1,e.send(v,A)}catch(z){if(k)throw z;A(-1,z)}}else A(-1,"No Transport");function A(b,c,d,h){var j,m,n,v,w,x=c;k||(k=!0,i&&a.clearTimeout(i),e=void 0,g=h||"",y.readyState=b>0?4:0,j=b>=200&&b<300||304===b,d&&(v=Pb(o,y,d)),v=Qb(o,v,y,j),j?(o.ifModified&&(w=y.getResponseHeader("Last-Modified"),w&&(r.lastModified[f]=w),w=y.getResponseHeader("etag"),w&&(r.etag[f]=w)),204===b||"HEAD"===o.type?x="nocontent":304===b?x="notmodified":(x=v.state,m=v.data,n=v.error,j=!n)):(n=x,!b&&x||(x="error",b<0&&(b=0))),y.status=b,y.statusText=(c||x)+"",j?s.resolveWith(p,[m,x,y]):s.rejectWith(p,[y,x,n]),y.statusCode(u),u=void 0,l&&q.trigger(j?"ajaxSuccess":"ajaxError",[y,o,j?m:n]),t.fireWith(p,[y,x]),l&&(q.trigger("ajaxComplete",[y,o]),--r.active||r.event.trigger("ajaxStop")))}return y},getJSON:function(a,b,c){return r.get(a,b,c,"json")},getScript:function(a,b){return r.get(a,void 0,b,"script")}}),r.each(["get","post"],function(a,b){r[b]=function(a,c,d,e){return r.isFunction(c)&&(e=e||d,d=c,c=void 0),r.ajax(r.extend({url:a,type:b,dataType:e,data:c,success:d},r.isPlainObject(a)&&a))}}),r._evalUrl=function(a){return r.ajax({url:a,type:"GET",dataType:"script",cache:!0,async:!1,global:!1,"throws":!0})},r.fn.extend({wrapAll:function(a){var b;return this[0]&&(r.isFunction(a)&&(a=a.call(this[0])),b=r(a,this[0].ownerDocument).eq(0).clone(!0),this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstElementChild)a=a.firstElementChild;return a}).append(this)),this},wrapInner:function(a){return r.isFunction(a)?this.each(function(b){r(this).wrapInner(a.call(this,b))}):this.each(function(){var b=r(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){var b=r.isFunction(a);return this.each(function(c){r(this).wrapAll(b?a.call(this,c):a)})},unwrap:function(a){return this.parent(a).not("body").each(function(){r(this).replaceWith(this.childNodes)}),this}}),r.expr.pseudos.hidden=function(a){return!r.expr.pseudos.visible(a)},r.expr.pseudos.visible=function(a){return!!(a.offsetWidth||a.offsetHeight||a.getClientRects().length)},r.ajaxSettings.xhr=function(){try{return new a.XMLHttpRequest}catch(b){}};var Rb={0:200,1223:204},Sb=r.ajaxSettings.xhr();o.cors=!!Sb&&"withCredentials"in Sb,o.ajax=Sb=!!Sb,r.ajaxTransport(function(b){var c,d;if(o.cors||Sb&&!b.crossDomain)return{send:function(e,f){var g,h=b.xhr();if(h.open(b.type,b.url,b.async,b.username,b.password),b.xhrFields)for(g in b.xhrFields)h[g]=b.xhrFields[g];b.mimeType&&h.overrideMimeType&&h.overrideMimeType(b.mimeType),b.crossDomain||e["X-Requested-With"]||(e["X-Requested-With"]="XMLHttpRequest");for(g in e)h.setRequestHeader(g,e[g]);c=function(a){return function(){c&&(c=d=h.onload=h.onerror=h.onabort=h.onreadystatechange=null,"abort"===a?h.abort():"error"===a?"number"!=typeof h.status?f(0,"error"):f(h.status,h.statusText):f(Rb[h.status]||h.status,h.statusText,"text"!==(h.responseType||"text")||"string"!=typeof h.responseText?{binary:h.response}:{text:h.responseText},h.getAllResponseHeaders()))}},h.onload=c(),d=h.onerror=c("error"),void 0!==h.onabort?h.onabort=d:h.onreadystatechange=function(){4===h.readyState&&a.setTimeout(function(){c&&d()})},c=c("abort");try{h.send(b.hasContent&&b.data||null)}catch(i){if(c)throw i}},abort:function(){c&&c()}}}),r.ajaxPrefilter(function(a){a.crossDomain&&(a.contents.script=!1)}),r.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/\b(?:java|ecma)script\b/},converters:{"text script":function(a){return r.globalEval(a),a}}}),r.ajaxPrefilter("script",function(a){void 0===a.cache&&(a.cache=!1),a.crossDomain&&(a.type="GET")}),r.ajaxTransport("script",function(a){if(a.crossDomain){var b,c;return{send:function(e,f){b=r(" \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/templates/commons/commons-macros.ftl b/src/main/resources/com/aventstack/extentreports/templates/commons/commons-macros.ftl new file mode 100644 index 0000000..d07c959 --- /dev/null +++ b/src/main/resources/com/aventstack/extentreports/templates/commons/commons-macros.ftl @@ -0,0 +1,41 @@ +<#macro attributes test> + <#if test.hasCategory()> + + <#list test.categoryContext.all as category> + ${category.name} + + + + <#if test.hasAuthor()> + + <#list test.authorContext.all as author> + ${author.name} + + + + <#if test.hasDevice()> + + <#list test.deviceContext.all as device> + ${device.name} + + + + + +<#macro media media> + <#if media?? && media?is_enumerable><#list media as m><@mediaSingle m /> + <#else><@mediaSingle media /> + + + +<#macro mediaSingle m> + <#if m??> +
    + <#if m.base64??> + <#elseif m.resolvedPath??> + <#elseif m.path??> + + <#if m.title??>
    ${m.title}
    +
    + + diff --git a/src/main/resources/com/aventstack/extentreports/view/commons/commons-tag.ftl b/src/main/resources/com/aventstack/extentreports/templates/commons/commons-tag.ftl similarity index 100% rename from src/main/resources/com/aventstack/extentreports/view/commons/commons-tag.ftl rename to src/main/resources/com/aventstack/extentreports/templates/commons/commons-tag.ftl diff --git a/src/main/resources/com/aventstack/extentreports/templates/commons/commons-variables.ftl b/src/main/resources/com/aventstack/extentreports/templates/commons/commons-variables.ftl new file mode 100644 index 0000000..3911a18 --- /dev/null +++ b/src/main/resources/com/aventstack/extentreports/templates/commons/commons-variables.ftl @@ -0,0 +1,40 @@ +<#assign + config=this.config() + theme=config.theme?lower_case + timeStampFormat=config.timeStampFormat + offline=config.offlineMode + reportType="" + parentHeading="Tests" + childHeading="Steps" + grandChildHeading="" + displayEvents=true + chartWidth="115" + chartHeight="90" + chartBoxHeight="94" + displayEvents=true> +<#if report.stats.analysisStrategy=="SUITE"> + <#assign + parentHeading="Suite" + childHeading="Class" + grandChildHeading="Test"> + +<#if report.stats.analysisStrategy=="CLASS"> + <#assign + parentHeading="Class" + childHeading="Methods" + grandChildHeading=""> + +<#assign chartCount=2> +<#if report.stats.sumStat(report.stats.child) != 0><#assign chartCount=3> +<#if report.stats.sumStat(report.stats.grandchild) != 0><#assign chartCount=4> +<#if report.isBDD()> + <#assign + reportType="bdd" + parentHeading="Features" + childHeading="Scenarios" + grandChildHeading="Steps" + chartCount=3 + displayEvents=false> + +<#assign + boxsize="col-md-"+(12/chartCount)> \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/templates/spark/dashboard.ftl b/src/main/resources/com/aventstack/extentreports/templates/spark/dashboard.ftl new file mode 100644 index 0000000..0e7fabd --- /dev/null +++ b/src/main/resources/com/aventstack/extentreports/templates/spark/dashboard.ftl @@ -0,0 +1,20 @@ +<#include "../commons/commons-variables.ftl"> + + + + <#include "partials/head.ftl"> + +
    +
    + <#include "partials/navbar.ftl"> + <#include "partials/sidenav.ftl"> +
    +
    + <#include "partials/dashboard.ftl"> +
    +
    +
    +
    + <#include "partials/scripts.ftl"> + + \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/templates/spark/exception.ftl b/src/main/resources/com/aventstack/extentreports/templates/spark/exception.ftl new file mode 100644 index 0000000..c0675d8 --- /dev/null +++ b/src/main/resources/com/aventstack/extentreports/templates/spark/exception.ftl @@ -0,0 +1,20 @@ +<#include "../commons/commons-variables.ftl"> + + + +<#include "partials/head.ftl"> + +
    +
    + <#include "partials/navbar.ftl"> + <#include "partials/sidenav.ftl"> +
    +
    + <#include "partials/exception.ftl"> +
    +
    +
    +
    + <#include "partials/scripts.ftl"> + + \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/templates/spark/macros/attributes.ftl b/src/main/resources/com/aventstack/extentreports/templates/spark/macros/attributes.ftl new file mode 100644 index 0000000..2972108 --- /dev/null +++ b/src/main/resources/com/aventstack/extentreports/templates/spark/macros/attributes.ftl @@ -0,0 +1,19 @@ +<#macro attributes test> +<#compress> + <#if test.hasAuthor()> + <#list test.authorSet as author> + ${author.name} + + + <#if test.hasCategory()> + <#list test.categorySet as category> + ${category.name} + + + <#if test.hasDevice()> + <#list test.deviceSet as device> + ${device.name} + + + + \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/templates/spark/macros/log.ftl b/src/main/resources/com/aventstack/extentreports/templates/spark/macros/log.ftl new file mode 100644 index 0000000..bd38625 --- /dev/null +++ b/src/main/resources/com/aventstack/extentreports/templates/spark/macros/log.ftl @@ -0,0 +1,18 @@ +<#macro log test> + + + + <#list test.logs as log> + + + + + + + +
    StatusTimestampDetails
    ${log.status?string}${log.timestamp?time?string} + <#if log.exception??> + <#else>${log.details} + <#if log.media??><@mediaSingle log.media /> +
    + \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/templates/spark/macros/recurse_nodes.ftl b/src/main/resources/com/aventstack/extentreports/templates/spark/macros/recurse_nodes.ftl new file mode 100644 index 0000000..0fe770c --- /dev/null +++ b/src/main/resources/com/aventstack/extentreports/templates/spark/macros/recurse_nodes.ftl @@ -0,0 +1,33 @@ +<#include "log.ftl"> +<#macro recurse_nodes test> +<#if test.hasChildren()> +
    + <#list test.children as node> +
    +
    +
    +
    ${node.name}
    +
    + +
    + <#if TestService.testHasScreenCapture(node, true)> +
    + +
    +
    + <#if node.hasLog()> +
    +
    + <@log test=node /> + <@media node.media /> +
    +
    + + <#if test.hasChildren()> + <@recurse_nodes test=node /> + +
    + +
    + + \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/templates/spark/partials/author.ftl b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/author.ftl new file mode 100644 index 0000000..e66eb55 --- /dev/null +++ b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/author.ftl @@ -0,0 +1,80 @@ +<#if report.authorCtx.set?size != 0> +<#assign + authorCtx=report.authorCtx.set> +<#compress> +
    +
    + +
    +
      + <#list authorCtx as ctx> +
    • +
      + + <#if ctx.passed!=0>${ctx.passed} + <#if ctx.failed!=0>${ctx.failed} + <#if ctx.skipped!=0>${ctx.skipped} + <#if ctx.others!=0>${ctx.others} + +

      ${ctx.attr.name}

      +

      ${ctx.size()} tests

      +
      +
      +
      +

      ${ctx.attr.name}

      + <#if ctx.passed!=0>${ctx.passed} passed + <#if ctx.failed!=0>${ctx.failed} failed + <#if ctx.skipped!=0>${ctx.skipped} skipped + <#if ctx.others!=0>${ctx.others} others +
      + + + + + + + + + + <#list ctx.testList as test> + + + + + + + +
      StatusTimestampTestName
      ${test.status?string}${test.startTime?string[("HH:mm:ss a")]} + ${test.name} + <#if test.parent??> +
      + ${test.getFullName()} +
      + +
      +
      +
    • + +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    + + \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/templates/spark/partials/bdd-content.ftl b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/bdd-content.ftl new file mode 100644 index 0000000..e234346 --- /dev/null +++ b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/bdd-content.ftl @@ -0,0 +1,68 @@ +<#macro stepdetails test> + <#if test.hasLog()> + <#list test.logs as log> +
    <#if log.exception??> + + <#else>${log.details} + <#if log.media??><@mediaSingle log.media />
    + + + + +<#if test.hasChildren()> +
    + <#list test.children as node> +
    + + <#if test.hasChildren()> + <#if node.bddType?? && node.bddType.simpleName=="ScenarioOutline"> +
    + <#list node.children as child> +
    +
    +
    +
    ${child.status?string}${child.name}
    + <#if TestService.testHasScreenCapture(child, true)> +
    + +
    + +
    +
    +
    + <#list child.children as step> +
    + ${step.name} + <@stepdetails test=step /> +
    + +
    +
    + +
    + <#else> +
    +
    + <#list node.children as child> +
    title="${child.description}"> + ${child.name} + <@stepdetails test=child /> +
    + +
    +
    + + +
    + +
    + \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/templates/spark/partials/category.ftl b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/category.ftl new file mode 100644 index 0000000..a5e606a --- /dev/null +++ b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/category.ftl @@ -0,0 +1,80 @@ +<#if report.categoryCtx.set?size != 0> +<#assign + categoryCtx=report.categoryCtx.set> +<#compress> +
    +
    + +
    +
      + <#list categoryCtx as ctx> +
    • +
      + + <#if ctx.passed!=0>${ctx.passed} + <#if ctx.failed!=0>${ctx.failed} + <#if ctx.skipped!=0>${ctx.skipped} + <#if ctx.others!=0>${ctx.others} + +

      ${ctx.attr.name}

      +

      ${ctx.size()} tests

      +
      +
      +
      +

      ${ctx.attr.name}

      + <#if ctx.passed!=0>${ctx.passed} passed + <#if ctx.failed!=0>${ctx.failed} failed + <#if ctx.skipped!=0>${ctx.skipped} skipped + <#if ctx.others!=0>${ctx.others} others +
      + + + + + + + + + + <#list ctx.testList as test> + + + + + + + +
      StatusTimestampTestName
      ${test.status?string}${test.startTime?string[("HH:mm:ss a")]} + ${test.name} + <#if test.parent??> +
      + ${test.getFullName()} +
      + +
      +
      +
    • + +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    + + \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/templates/spark/partials/dashboard.ftl b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/dashboard.ftl new file mode 100644 index 0000000..718a72f --- /dev/null +++ b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/dashboard.ftl @@ -0,0 +1,241 @@ +<#compress> +
    +
    +
    +
    +

    Started

    +

    ${report.startTime?datetime?string["${timeStampFormat}"]}

    +
    +
    +
    +
    +

    Ended

    +

    ${report.endTime?datetime?string["${timeStampFormat}"]}

    +
    +
    +
    +
    +

    ${parentHeading} Passed

    +

    ${report.stats.parent?api.get(Status.PASS)?c}

    +
    +
    +
    +
    +

    ${parentHeading} Failed

    +

    ${report.stats.parent?api.get(Status.FAIL)?c}

    +
    +
    +
    +
    +
    +
    +
    +
    ${parentHeading}
    +
    +
    +
    + +
    +
    + +
    +
    + <#if report.stats.sumStat(report.stats.child) != 0> +
    +
    +
    +
    ${childHeading}
    +
    +
    +
    + +
    +
    + +
    +
    + + <#if report.stats.sumStat(report.stats.grandchild) != 0> +
    +
    +
    +
    ${grandChildHeading}
    +
    +
    +
    + +
    +
    + +
    +
    + + <#if report.stats.sumStat(report.stats.log) != 0 && displayEvents> +
    +
    +
    +
    Log events
    +
    +
    +
    + +
    +
    + +
    +
    + +
    +
    + <#if report.authorCtx.set?size != 0> +
    +
    +

    Author

    +
    + + + <#list report.authorCtx.set as author> + + + + + + + + + + +
    NamePassedFailedSkippedOthersPassed %
    ${author.attr.name}${author.passed}${author.failed}${author.skipped}${author.others}<#if author.size()!=0>${(author.passed/author.size())*100}%<#else>0%
    +
    +
    + + <#if report.categoryCtx.set?size != 0> +
    +
    +

    Tags

    +
    + + <#list report.categoryCtx.set as category> + + + + + + + + + + +
    NamePassedFailedSkippedOthersPassed %
    ${category.attr.name}${category.passed}${category.failed}${category.skipped}${category.others}<#if category.size()!=0>${(category.passed/category.size())*100}%<#else>0%
    +
    +
    + + <#if report.deviceCtx.set?size != 0> +
    +
    +

    Device

    +
    + + + <#list report.deviceCtx.set as device> + + + + + + + + + + +
    NamePassedFailedSkippedOthersPassed %
    ${device.attr.name}${device.passed}${device.failed}${device.skipped}${device.others}<#if device.size()!=0>${(device.passed/device.size())*100}%<#else>0%
    +
    +
    + + <#if report.systemEnvInfo?size != 0> +
    +
    +

    System/Environment

    +
    + + + <#list report.systemEnvInfo as info> + + + + + + +
    NameValue
    ${info.name}${info.value}
    +
    +
    + +
    +
    + + \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/templates/spark/partials/device.ftl b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/device.ftl new file mode 100644 index 0000000..b39015a --- /dev/null +++ b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/device.ftl @@ -0,0 +1,80 @@ +<#if report.deviceCtx.set?size != 0> +<#assign + deviceCtx=report.deviceCtx.set> +<#compress> +
    +
    + +
    +
      + <#list deviceCtx as ctx> +
    • +
      + + <#if ctx.passed!=0>${ctx.passed} + <#if ctx.failed!=0>${ctx.failed} + <#if ctx.skipped!=0>${ctx.skipped} + <#if ctx.others!=0>${ctx.others} + +

      ${ctx.attr.name}

      +

      ${ctx.size()} tests

      +
      +
      +
      +

      ${ctx.attr.name}

      + <#if ctx.passed!=0>${ctx.passed} passed + <#if ctx.failed!=0>${ctx.failed} failed + <#if ctx.skipped!=0>${ctx.skipped} skipped + <#if ctx.others!=0>${ctx.others} others +
      + + + + + + + + + + <#list ctx.testList as test> + + + + + + + +
      StatusTimestampTestName
      ${test.status?string}${test.startTime?string[("HH:mm:ss a")]} + ${test.name} + <#if test.parent??> +
      + ${test.getFullName()} +
      + +
      +
      +
    • + +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    + + \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/templates/spark/partials/exception.ftl b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/exception.ftl new file mode 100644 index 0000000..2c2c214 --- /dev/null +++ b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/exception.ftl @@ -0,0 +1,84 @@ +<#if report.exceptionInfoCtx.set?size != 0> +<#assign + exceptionInfoCtx=report.exceptionInfoCtx.set> +<#compress> +
    +
    + +
    +
      + <#list exceptionInfoCtx as context> +
    • +
      +
      +

      ${context.attr.name}

      +

      ${context.testList?size} tests

      +
      +
      +
      +
      +

      ${context.attr.name}

      +
      + + + + + + + + + + <#list context.testList as test> + + + + + + + +
      StatusTimestampTestName
      ${test.status?string}${test.startTime?string[("HH:mm:ss a")]} + ${test.name} + <#if test.parent??> +
      + ${test.parent.name} +
      + +
      +
      +
    • + +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    + + \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/templates/spark/partials/head.ftl b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/head.ftl new file mode 100644 index 0000000..1f8d737 --- /dev/null +++ b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/head.ftl @@ -0,0 +1,35 @@ +<#compress> +<#assign + resourceCDN=config.resourceCDN + cdnURI="cdn.jsdelivr.net/gh/extent-framework/extent-github-cdn@" + csscommit="83e4e8776725a49f9e738b19d1e718e7404d6c19" + jscommit="5cf22a596531402644b8523470526952516f345f" + iconcommit="b00a2d0486596e73dd7326beacf352c639623a0e"> +<#if resourceCDN=="extentreports"> + <#assign + cdnURI="extentreports.com/resx" + csscommit="" + jscommit="" + iconcommit=""> + + + + + + ${config.documentTitle} + <#if offline> + + + + + + <#else> + + + + + + + <#include "../../commons/commons-inject-css.ftl"> + + \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/templates/spark/partials/log.ftl b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/log.ftl new file mode 100644 index 0000000..834fba4 --- /dev/null +++ b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/log.ftl @@ -0,0 +1,9 @@ +<#if report.logs?size != 0> +
    +
    +
    + <#list report.logs as log>${ log } +
    +
    +
    + \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/templates/spark/partials/logs.ftl b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/logs.ftl new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/com/aventstack/extentreports/templates/spark/partials/navbar.ftl b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/navbar.ftl new file mode 100644 index 0000000..110c040 --- /dev/null +++ b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/navbar.ftl @@ -0,0 +1,30 @@ +<#compress> + + \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/templates/spark/partials/scripts.ftl b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/scripts.ftl new file mode 100644 index 0000000..56a806f --- /dev/null +++ b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/scripts.ftl @@ -0,0 +1,4 @@ +<#if offline> +<#else> + +<#include "../../commons/commons-inject-js.ftl"> diff --git a/src/main/resources/com/aventstack/extentreports/templates/spark/partials/sidenav.ftl b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/sidenav.ftl new file mode 100644 index 0000000..beb1c33 --- /dev/null +++ b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/sidenav.ftl @@ -0,0 +1,33 @@ +<#compress> +
    +
    +
      + <#list viewOrder as order> + <#if order.toString()!="logs"> + <#if + order.toString()=="exception" && report.exceptionInfoCtx.hasItems() + || order.toString()=="category" && report.categoryCtx.hasItems() + || order.toString()=="device" && report.deviceCtx.hasItems() + || order.toString()=="author" && report.authorCtx.hasItems() + || order.toString()=="log" && report.logs?size != 0 + || order.toString()=="test" || order.toString()=="dashboard"> + <#assign ico="list"> + <#if order.toString()=="category"><#assign ico="tag"> + <#elseif order.toString()=="exception"><#assign ico="bug"> + <#elseif order.toString()=="device"><#assign ico="tablet"> + <#elseif order.toString()=="author"><#assign ico="user"> + <#elseif order.toString()=="dashboard"><#assign ico="bar-chart"> + <#elseif order.toString()=="log"><#assign ico="clipboard"> + + + + + +
    +
    +
    + \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/templates/spark/partials/standard-content.ftl b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/standard-content.ftl new file mode 100644 index 0000000..e6a2895 --- /dev/null +++ b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/standard-content.ftl @@ -0,0 +1,15 @@ +<@media test.media /> +<#if test.hasAnyLog()> +
    + <#list test.generatedLog as l> +
    +
    ${l.status?string}
    +
    ${l.details}
    +
    + + <#if test.hasLog()><@log test=test /> +
    + +<#if test.hasChildren()> +
    <@recurse_nodes test=test />
    + \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/templates/spark/partials/test.ftl b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/test.ftl new file mode 100644 index 0000000..0d36d69 --- /dev/null +++ b/src/main/resources/com/aventstack/extentreports/templates/spark/partials/test.ftl @@ -0,0 +1,101 @@ +
    +
    + <#compress> +
    + +
      + + <#if report.authorCtx.hasItems()> + + + <#if report.categoryCtx.hasItems()> + + + <#if report.deviceCtx.hasItems()> + + +
    +
    + +
    +
      + <#list report.testList as test> +
    • +
      + +
      +
      + +

      ${test.name}

      +

      ${test.startTime?string("HH:mm:ss a")} / ${test.timeTaken()/1000} secs

      +
      +
      + <#compress> +
      +
      +
      +
      #test-id=${test.getId()}
      +
      ${test.name}
      + ${test.startTime?string("MM.dd.yyyy HH:mm:ss")} + ${test.endTime?string("MM.dd.yyyy HH:mm:ss")} + ${test.timeTaken()/1000} secs +
      + <#if test.hasAttributes()> +
      <@attributes test=test />
      + + <#if test.description??> +
      ${test.description}
      + +
      +
      + + <#if isbdd><#include "bdd-content.ftl"> + <#else><#include "standard-content.ftl"> + +
      +
    • + +
    +
    +
    + <#compress> +
    +
    +
    +
    +
    +
    + +
    diff --git a/src/main/resources/com/aventstack/extentreports/templates/spark/spark.spa.ftl b/src/main/resources/com/aventstack/extentreports/templates/spark/spark.spa.ftl new file mode 100644 index 0000000..b240ff0 --- /dev/null +++ b/src/main/resources/com/aventstack/extentreports/templates/spark/spark.spa.ftl @@ -0,0 +1,33 @@ +<#include "../commons/commons-variables.ftl"> +<#include "../commons/commons-macros.ftl"> +<#include "macros/attributes.ftl"> +<#include "macros/log.ftl"> +<#include "macros/recurse_nodes.ftl"> + +<#assign + isbdd=false + pageClass=""> +<#if report.isBDD()> + <#assign + pageClass="bdd" + isbdd=true> + + + + +<#include "partials/head.ftl"> + +
    +
    + <#include "partials/navbar.ftl"> + <#include "partials/sidenav.ftl"> +
    +
    + <#list viewOrder as view><#include "partials/${view.toString()}.ftl"> +
    +
    +
    +
    + <#include "partials/scripts.ftl"> + + \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/templates/spark/tag.ftl b/src/main/resources/com/aventstack/extentreports/templates/spark/tag.ftl new file mode 100644 index 0000000..d92751c --- /dev/null +++ b/src/main/resources/com/aventstack/extentreports/templates/spark/tag.ftl @@ -0,0 +1,20 @@ +<#include "../commons/commons-variables.ftl"> + + + +<#include "partials/head.ftl"> + +
    +
    + <#include "partials/navbar.ftl"> + <#include "partials/sidenav.ftl"> +
    +
    + <#include "partials/tag.ftl"> +
    +
    +
    +
    + <#include "partials/scripts.ftl"> + + \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/templates/spark/test.ftl b/src/main/resources/com/aventstack/extentreports/templates/spark/test.ftl new file mode 100644 index 0000000..580b7e0 --- /dev/null +++ b/src/main/resources/com/aventstack/extentreports/templates/spark/test.ftl @@ -0,0 +1,36 @@ +<#include "../commons/commons-variables.ftl"> +<#include "../commons/commons-macros.ftl"> +<#include "macros/attributes.ftl"> +<#include "macros/log.ftl"> +<#include "macros/recurse_nodes.ftl"> + +<#assign + isbdd=false + pageClass=""> +<#if report.isBDD()> + <#assign + pageClass="bdd" + isbdd=true> + + + + +<#include "partials/head.ftl"> +<#if offline> +<#else> + + +
    +
    + <#include "partials/navbar.ftl"> + <#include "partials/sidenav.ftl"> +
    +
    + <#include "partials/test.ftl"> +
    +
    +
    +
    + <#include "partials/scripts.ftl"> + + \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/commons/commons-inject-css.ftl b/src/main/resources/com/aventstack/extentreports/view/commons/commons-inject-css.ftl deleted file mode 100644 index 00d17c4..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/commons/commons-inject-css.ftl +++ /dev/null @@ -1,3 +0,0 @@ - \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/commons/commons-inject-js.ftl b/src/main/resources/com/aventstack/extentreports/view/commons/commons-inject-js.ftl deleted file mode 100644 index dcf035d..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/commons/commons-inject-js.ftl +++ /dev/null @@ -1,4 +0,0 @@ - \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/commons/commons-macros.ftl b/src/main/resources/com/aventstack/extentreports/view/commons/commons-macros.ftl deleted file mode 100644 index 6967e19..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/commons/commons-macros.ftl +++ /dev/null @@ -1,58 +0,0 @@ -<#macro attributes test> - <#if TestService.testHasCategory(test)> - - <#list test.categoryContext.all as category> - ${category.name} - - - - <#if TestService.testHasAuthor(test)> - - <#list test.authorContext.all as author> - ${author.name} - - - - <#if TestService.testHasDevice(test)> - - <#list test.deviceContext.all as device> - ${device.name} - - - - - -<#macro media el> - <#if el.screenCaptureContext?? && !el.screenCaptureContext.isEmpty()> - ${el.screenCaptureContext.last.source} - - - -<#macro row test level> -<#assign n=test level=n.level> -<#if level!=0><#assign n=test.parent><#if n.level!=0><#assign n=n.parent><#if n.level!=0><#assign n=n.parent> - - - ${test.status} - ${test.name} <#if level!=0>
    ${test.parent.name} - ${TestService.getRunDuration(test)}c - <@attributes test=test /> - - <@media el=test /> - <#list test.logContext.all as log> - <@media el=log /> - - - - -<#if test.status==Status.FAIL || test.status==Status.SKIP> - - - <#list test.logContext.all as log> - <#if log.details??> - <#if log.exceptionInfo??> - - - - - \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/commons/commons-variables.ftl b/src/main/resources/com/aventstack/extentreports/view/commons/commons-variables.ftl deleted file mode 100644 index c0ffa55..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/commons/commons-variables.ftl +++ /dev/null @@ -1,50 +0,0 @@ -<#assign config=report.configurationStore> -<#assign offline="false"> -<#if config.getConfig("enableOfflineMode")??><#assign offline=config.getConfig("enableOfflineMode")> - -<#assign theme=config.containsConfig('theme')?then(config.getConfig('theme')?lower_case, '')> -<#assign systemAttributeContext=report.getSystemAttributeContext().getSystemAttributeList()> -<#assign categoryContext=report.getCategoryContextInfo().getTestAttributeTestContext()> -<#assign authorContext=report.getAuthorContextInfo().getTestAttributeTestContext()> -<#assign deviceContext=report.getDeviceContextInfo().getTestAttributeTestContext()> -<#assign exceptionContext=report.exceptionContextInfo.exceptionTestContext> - -<#assign reportType="" parentHeading="Tests" childHeading="Steps" grandChildHeading="" size=2> -<#if report.analysisStrategy=="SUITE"> - <#assign parentHeading="Suite" childHeading="Tests" grandChildHeading="Tests" size=2> - <#if report.reportStatusStats.grandChildCount!=0> - <#assign childHeading="Classes" grandChildHeading="Tests" size=3> - - -<#if report.analysisStrategy=="BDD"> - <#assign reportType="bdd" parentHeading="Features" childHeading="Scenarios" grandChildHeading="Steps" size=3> - -<#if report.analysisStrategy=="CLASS"> - <#assign parentHeading="Class" childHeading="Methods" grandChildHeading="" size=2> - - -<#assign timeStampFormat=config.getConfig('timeStampFormat')> - -<#assign boxsize='col-md-6' displayEvents=true> -<#if report.reportStatusStats.childCount!=0> - <#assign boxsize='col-sm-12 col-md-4'> - -<#if (report.analysisStrategy=="BDD") || (report.reportStatusStats.childCount != 0 && report.reportStatusStats.grandChildCount != 0)> - <#assign boxsize='col-sm-12 col-md-4' displayEvents=false> - - -<#assign chartWidth="115" chartHeight="90" chartBoxHeight="94"> - -<#assign reportType="" parentHeading="Tests" childHeading="Steps" grandChildHeading="" size=2> -<#if report.analysisStrategy=="SUITE"> - <#assign parentHeading="Suite" childHeading="Tests" grandChildHeading="Tests" size=2> - <#if report.reportStatusStats.grandChildCount!=0> - <#assign childHeading="Classes" grandChildHeading="Tests" size=3> - - -<#if report.analysisStrategy=="BDD"> - <#assign reportType="bdd" parentHeading="Features" childHeading="Scenarios" grandChildHeading="Steps" size=3> - -<#if report.analysisStrategy=="CLASS"> - <#assign parentHeading="Class" childHeading="Methods" grandChildHeading="" size=2> - \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/logger/logger-dashboard.ftl b/src/main/resources/com/aventstack/extentreports/view/logger/logger-dashboard.ftl deleted file mode 100644 index c6e22cb..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/logger/logger-dashboard.ftl +++ /dev/null @@ -1,36 +0,0 @@ -<#include "../commons/commons-variables.ftl"> - - - - <#include "partials/logger-head.ftl"> - -
    - <#include "partials/logger-nav.ftl"> -
    -
    -
    - -
    - <#include "../commons/commons-dashboard.ftl"> -
    -
    -
    - <#assign p="https://cdn.jsdelivr.net/gh/extent-framework/extent-github-cdn@832f979664f9d68bf618db3ac87498ac6c1a6390/commons/js/"> - <#if offline=="true"><#assign p=config.getConfig("offlineDirectory")> - - <#if config.containsConfig("scripts") && config.getConfig("scripts")?has_content> - <#include "../commons/commons-inject-js.ftl"> - - <#include "../commons/commons-dashboard-scripts.ftl"> - - \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/logger/logger-exception.ftl b/src/main/resources/com/aventstack/extentreports/view/logger/logger-exception.ftl deleted file mode 100644 index 223fc26..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/logger/logger-exception.ftl +++ /dev/null @@ -1,58 +0,0 @@ -<#include "../commons/commons-variables.ftl"> - - - - <#include "partials/logger-head.ftl"> - -
    - <#include "partials/logger-nav.ftl"> -
    -
    - -
    -
    -
    - <#include "../commons/commons-exception.ftl"> -
    -
    - -
    -
    -
    -
    -
    -
    -
    -
    -
    - <#assign p="https://cdn.jsdelivr.net/gh/extent-framework/extent-github-cdn@832f979664f9d68bf618db3ac87498ac6c1a6390/commons/js/"> - <#if offline=="true"><#assign p=config.getConfig("offlineDirectory")> - - <#if config.containsConfig("scripts") && config.getConfig("scripts")?has_content> - <#include "../commons/commons-inject-js.ftl"> - - - - diff --git a/src/main/resources/com/aventstack/extentreports/view/logger/logger-tag.ftl b/src/main/resources/com/aventstack/extentreports/view/logger/logger-tag.ftl deleted file mode 100644 index ce25a77..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/logger/logger-tag.ftl +++ /dev/null @@ -1,65 +0,0 @@ -<#include "../commons/commons-variables.ftl"> - - - - <#include "partials/logger-head.ftl"> - -
    - <#include "partials/logger-nav.ftl"> -
    -
    - -
    -
    -
    - <#include "../commons/commons-tag.ftl"> -
    -
    - -
    -
    -
    -
    -
    -
    -
    -
    -
    - <#assign p="https://cdn.jsdelivr.net/gh/extent-framework/extent-github-cdn@832f979664f9d68bf618db3ac87498ac6c1a6390/commons/js/"> - <#if offline=="true"><#assign p=config.getConfig("offlineDirectory")> - - <#if config.containsConfig("scripts") && config.getConfig("scripts")?has_content> - <#include "../commons/commons-inject-js.ftl"> - - - diff --git a/src/main/resources/com/aventstack/extentreports/view/logger/logger-test.ftl b/src/main/resources/com/aventstack/extentreports/view/logger/logger-test.ftl deleted file mode 100644 index fde08aa..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/logger/logger-test.ftl +++ /dev/null @@ -1,169 +0,0 @@ -<#include "../commons/commons-variables.ftl"> - - - - <#include "partials/logger-head.ftl"> - - -
    - <#include "partials/logger-nav.ftl"> -
    -
    -
    - -
    -
    -
    -
    -
    -
    -
    Test Logs
    - <#macro content test> - <#assign spacer="" level=test.level> - <#if level!=0> - <#if level!=1> - <#list 2..level as l> - <#assign spacer+="    "> - - - <#assign spacer+="|---"> - -
    - ${test.startTime?string("MM.dd.yyyy HH:mm:ss")}  - ${test.status?replace("ing","")}<#list test.status.toString()?replace("ing","")?length..5 as x>  - ${spacer}[${test.name}] started - <@attributes test=test /> - - <#list test.logContext.all as log> -
    - ${log.timestamp?string("MM.dd.yyyy HH:mm:ss")}  - ${log.status?replace("ing","")}<#list log.status.toString()?replace("ing","")?length..5 as x>  - ${spacer}[${test.name}] - <#if LogService.logHasScreenCapture(log)>${log.screenCaptureContext.last.source} - <#if log.details??>${log.details}<#if log.exceptionInfo??>threw an exception
    -
    - -
    - - <#macro attributes test> - <#if TestService.testHasCategory(test)> - - <#list test.categoryContext.all as category> - ${category.name} - - - - <#if TestService.testHasCategory(test)> - - <#list test.authorContext.all as author> - ${author.name} - - - - <#if TestService.testHasCategory(test)> - - <#list test.deviceContext.all as device> - ${device.name} - - - - - <#list report.testList as test> -
    - <@content test=test /> - <#list test.nodeContext.all as node> - <@content test=node /> - <#list node.nodeContext.all as c> - <@content test=c /> - <#list c.nodeContext.all as gc> - <@content test=gc /> - - - -
    - -
    -
    -
    -
    -
    -
    -
    -
    - <#assign p="https://cdn.jsdelivr.net/gh/extent-framework/extent-github-cdn@832f979664f9d68bf618db3ac87498ac6c1a6390/logger/js/"> - <#if offline=="true"><#assign p=config.getConfig("offlineDirectory")> - - <#if config.containsConfig("scripts") && config.getConfig("scripts")?has_content> - <#include "../commons/commons-inject-js.ftl"> - - - diff --git a/src/main/resources/com/aventstack/extentreports/view/logger/partials/logger-head.ftl b/src/main/resources/com/aventstack/extentreports/view/logger/partials/logger-head.ftl deleted file mode 100644 index 84ae5e0..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/logger/partials/logger-head.ftl +++ /dev/null @@ -1,21 +0,0 @@ - - - ${config.getConfig("documentTitle")} - - - - - - - - <#if offline=="true"> - - - <#else> - - - - <#if config.containsConfig("styles")> - <#include "../../commons/commons-inject-css.ftl"> - - diff --git a/src/main/resources/com/aventstack/extentreports/view/logger/partials/logger-nav-right-items.ftl b/src/main/resources/com/aventstack/extentreports/view/logger/partials/logger-nav-right-items.ftl deleted file mode 100644 index 7e0a331..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/logger/partials/logger-nav-right-items.ftl +++ /dev/null @@ -1,3 +0,0 @@ -
  • ${config.getConfig("reportName")}
  • -
  • ${report.startTime?datetime?string["${timeStampFormat}"]}
  • -
  • 4.0
  • diff --git a/src/main/resources/com/aventstack/extentreports/view/logger/partials/logger-nav.ftl b/src/main/resources/com/aventstack/extentreports/view/logger/partials/logger-nav.ftl deleted file mode 100644 index dc1619f..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/logger/partials/logger-nav.ftl +++ /dev/null @@ -1,67 +0,0 @@ -
    - -
    \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/spark/dashboard.ftl b/src/main/resources/com/aventstack/extentreports/view/spark/dashboard.ftl deleted file mode 100644 index 48f9a32..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/spark/dashboard.ftl +++ /dev/null @@ -1,20 +0,0 @@ -<#include "../commons/commons-variables.ftl"> - - - - <#include "partials/head.ftl"> - -
    -
    - <#include "partials/navbar.ftl"> - <#include "partials/sidenav.ftl"> -
    -
    - <#include "partials/dashboard.ftl"> -
    -
    -
    -
    - <#include "partials/scripts.ftl"> - - \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/spark/exception.ftl b/src/main/resources/com/aventstack/extentreports/view/spark/exception.ftl deleted file mode 100644 index 7d5fb5c..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/spark/exception.ftl +++ /dev/null @@ -1,20 +0,0 @@ -<#include "../commons/commons-variables.ftl"> - - - -<#include "partials/head.ftl"> - -
    -
    - <#include "partials/navbar.ftl"> - <#include "partials/sidenav.ftl"> -
    -
    - <#include "partials/exception.ftl"> -
    -
    -
    -
    - <#include "partials/scripts.ftl"> - - \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/spark/macros/attributes.ftl b/src/main/resources/com/aventstack/extentreports/view/spark/macros/attributes.ftl deleted file mode 100644 index cd59bf0..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/spark/macros/attributes.ftl +++ /dev/null @@ -1,17 +0,0 @@ -<#macro attributes test> - <#if TestService.testHasAuthor(test)> - <#list test.authorContext.all as author> - ${author.name} - - - <#if TestService.testHasCategory(test)> - <#list test.categoryContext.all as category> - ${category.name} - - - <#if TestService.testHasDevice(test)> - <#list test.deviceContext.all as device> - ${device.name} - - - \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/spark/macros/log.ftl b/src/main/resources/com/aventstack/extentreports/view/spark/macros/log.ftl deleted file mode 100644 index 3b7e1e9..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/spark/macros/log.ftl +++ /dev/null @@ -1,27 +0,0 @@ -<#macro log test> - - - - - - - - <#list test.logContext.all as log> - - - - - - - -
    StatusTimestampDetails
    ${log.timestamp?time?string} - <#if log.exceptionInfo??> - - <#else> - ${log.details} - - <#if LogService.logHasScreenCapture(log)> - ${log.screenCaptureContext.last.source} - -
    - \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/spark/macros/recurse_nodes.ftl b/src/main/resources/com/aventstack/extentreports/view/spark/macros/recurse_nodes.ftl deleted file mode 100644 index edf43a8..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/spark/macros/recurse_nodes.ftl +++ /dev/null @@ -1,38 +0,0 @@ -<#include "log.ftl"> - -<#macro recurse_nodes test> -<#if TestService.testHasChildren(test)> -
    - <#list test.nodeContext.all as node> -
    - -
    -
    - <#if TestService.testHasLog(node)> - <@log test=node /> - - <#list node.screenCaptureContext.all as sc> - ${sc.source} - -
    -
    - <#if TestService.testHasChildren(node)> - <@recurse_nodes test=node /> - -
    - -
    - - \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/spark/partials/bdd-content.ftl b/src/main/resources/com/aventstack/extentreports/view/spark/partials/bdd-content.ftl deleted file mode 100644 index 9747f4e..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/spark/partials/bdd-content.ftl +++ /dev/null @@ -1,84 +0,0 @@ -<#macro stepdetails test> - <#if TestService.testHasLog(test)> - <#list test.logContext.all as log> - <#if log.exceptionInfo??> - - <#else> -
    ${log.details}
    - - <#if LogService.logHasScreenCapture(log)> -
    ${log.screenCaptureContext.last.source}
    - - - - - -<#if TestService.testHasChildren(test)> -
    - <#list test.nodeContext.all as node> -
    - - <#if TestService.testHasChildren(node)> - <#if node.bddType?? && node.behaviorDrivenTypeName=="Scenario Outline"> -
    - <#list node.nodeContext.all as child> -
    - -
    - <#list child.nodeContext.all as step> -
    - - - - ${step.name} -
    - <@stepdetails test=step /> - -
    -
    - -
    - <#else> -
    -
    - <#list node.nodeContext.all as child> -
    - - - - ${child.name} -
    - <@stepdetails test=child /> - -
    -
    - - -
    - -
    - \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/spark/partials/dashboard.ftl b/src/main/resources/com/aventstack/extentreports/view/spark/partials/dashboard.ftl deleted file mode 100644 index e2a6ff0..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/spark/partials/dashboard.ftl +++ /dev/null @@ -1,391 +0,0 @@ -
    -
    -
    -
    -
    -
    ${parentHeading}
    -
    -
    -
    - -
    -
    - -
    -
    - <#if report.reportStatusStats.childCount != 0> -
    -
    -
    -
    ${childHeading}
    -
    -
    -
    - -
    -
    - -
    -
    - - <#if report.reportStatusStats.grandChildCount != 0> -
    -
    -
    -
    ${grandChildHeading}
    -
    -
    -
    - -
    -
    - -
    -
    - - <#if report.reportStatusStats.eventsCount != 0 && displayEvents> -
    -
    -
    -
    Log events
    -
    -
    -
    - -
    -
    - -
    -
    - -
    -
    -
    -
    -
    -
    -
    -
    ${parentHeading}
    -

    ${report.reportStatusStats.parentCount}

    - - - ${report.reportStatusStats.parentPercentagePass?string("#.00")}% - -
    -
    - -
    -
    -
    -
    -
    - <#if report.reportStatusStats.childCount != 0> -
    -
    -
    -
    -
    -
    ${childHeading}
    -

    ${report.reportStatusStats.childCount}

    - - - ${report.reportStatusStats.childPercentagePass?string("#.00")}% - -
    -
    - -
    -
    -
    -
    -
    - -
    -
    -
    -
    -
    -
    Start
    -

    ${report.startTime?datetime?string["${timeStampFormat}"]}

    - -
    -
    - -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    Duration
    -

    ${report.longRunDuration}

    - -
    -
    - -
    -
    -
    -
    -
    -
    - <#if config.getConfig("enableTimeline")=='true'> -
    -
    -
    -
    -
    Timeline
    -
    -
    -
    - -
    -
    -
    -
    -
    - -
    - <#if (authorContext?? && authorContext?size != 0)> -
    -
    -
    -
    Author
    -
    -
    - - - - - - - - - - - - - <#list authorContext as author> - - - - - - - - - - -
    NamePassedFailedSkippedOthersPassed %
    ${author.name}${author.passed}${author.failed}${author.skipped}${author.others} - <#if author.size()!=0> - ${(author.passed/author.size())*100}% - <#else> - 0% - -
    -
    -
    -
    - - <#if (categoryContext?? && categoryContext?size != 0)> -
    -
    -
    -
    Tags
    -
    -
    - - - - - - - - - - - - - <#list categoryContext as category> - - - - - - - - - - -
    NamePassedFailedSkippedOthersPassed %
    ${category.name}${category.passed}${category.failed}${category.skipped}${category.others} - <#if category.size()!=0> - ${(category.passed/category.size())*100}% - <#else> - 0% - -
    -
    -
    -
    - - <#if (deviceContext?? && deviceContext?size != 0)> -
    -
    -
    -
    Device
    -
    -
    - - - - - - - - - - - - - <#list deviceContext as device> - - - - - - - - - - -
    NamePassedFailedSkippedOthersPassed %
    ${device.name}${device.passed}${device.failed}${device.skipped}${device.others} - <#if device.size()!=0> - ${(device.passed/device.size())*100}% - <#else> - 0% - -
    -
    -
    -
    - - <#if systemAttributeContext?size != 0> -
    -
    -
    -
    Environment
    -
    -
    - - - - - - - - - <#list report.systemAttributeContext.systemAttributeList as sa> - <#if sa?? && sa.name?? && sa.value??> - - - - - - - -
    NameValue
    ${ sa.name }${ sa.value }
    -
    -
    -
    - -
    -
    - -<#if config.getConfig("enableTimeline")=='true'> - - \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/spark/partials/exception.ftl b/src/main/resources/com/aventstack/extentreports/view/spark/partials/exception.ftl deleted file mode 100644 index 3936249..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/spark/partials/exception.ftl +++ /dev/null @@ -1,82 +0,0 @@ -
    -
    - -
    -
      - <#list exceptionContext as context> -
    • -
      -
      -

      ${context.exceptionInfo.exceptionName}

      -

      ${context.tests?size} tests

      -
      -
      -
      -
      -

      ${context.exceptionInfo.exceptionName}

      -
      - - - - - - - - - - <#list context.tests as test> - - - - - - - -
      StatusTimestampTestName
      -
      - -
      -
      ${test.startTime?string[("HH:mm:ss a")]} - ${test.name} - <#if test.parent??> -
      - ${test.parent.name} -
      - -
      -
      -
    • - -
    -
    -
    -
    -
    - -
    -
    -
    -
    -
    -
    \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/spark/partials/head.ftl b/src/main/resources/com/aventstack/extentreports/view/spark/partials/head.ftl deleted file mode 100644 index 24834f3..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/spark/partials/head.ftl +++ /dev/null @@ -1,22 +0,0 @@ -<#assign resourceCDN=config.getConfig('resourceCDN') cdnURI="cdn.jsdelivr.net/gh/extent-framework/extent-github-cdn@" csscommit="6fbbd1c32fbc2463d026da5c6ce2e9eef0d29512" jscommit="ac7abbc71b4bb073da00153a5a3fdbcfe0c95e2a" iconcommit="b00a2d0486596e73dd7326beacf352c639623a0e"> -<#if resourceCDN=="extentreports"> - <#assign cdnURI="extentreports.com/resx" csscommit="" jscommit="" iconcommit=""> - - - - - - ${config.getConfig("documentTitle")} - <#if offline=="true"> - - - - - <#else> - - - - - - <#include "../../commons/commons-inject-css.ftl"> - \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/spark/partials/navbar.ftl b/src/main/resources/com/aventstack/extentreports/view/spark/partials/navbar.ftl deleted file mode 100644 index cdee98a..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/spark/partials/navbar.ftl +++ /dev/null @@ -1,33 +0,0 @@ - \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/spark/partials/scripts.ftl b/src/main/resources/com/aventstack/extentreports/view/spark/partials/scripts.ftl deleted file mode 100644 index 8703fa7..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/spark/partials/scripts.ftl +++ /dev/null @@ -1,6 +0,0 @@ -<#if offline=="true"> - -<#else> - - -<#include "../../commons/commons-inject-js.ftl"> diff --git a/src/main/resources/com/aventstack/extentreports/view/spark/partials/sidenav.ftl b/src/main/resources/com/aventstack/extentreports/view/spark/partials/sidenav.ftl deleted file mode 100644 index 0f8bad5..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/spark/partials/sidenav.ftl +++ /dev/null @@ -1,42 +0,0 @@ -
    -
    - -
    -
    \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/spark/partials/standard-content.ftl b/src/main/resources/com/aventstack/extentreports/view/spark/partials/standard-content.ftl deleted file mode 100644 index e50b374..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/spark/partials/standard-content.ftl +++ /dev/null @@ -1,19 +0,0 @@ -<#if TestService.testHasLog(test)> -
    - <@log test=test /> -
    - -<#if TestService.testHasScreenCapture(test)> -
    -
      - <#list test.screenCaptureContext.all as sc> - ${sc.source} - -
    -
    - -<#if TestService.testHasChildren(test)> -
    - <@recurse_nodes test=test /> -
    - \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/spark/partials/tag.ftl b/src/main/resources/com/aventstack/extentreports/view/spark/partials/tag.ftl deleted file mode 100644 index 4bfbf91..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/spark/partials/tag.ftl +++ /dev/null @@ -1,92 +0,0 @@ -
    -
    - -
    -
      - <#list categoryContext as context> -
    • -
      -
      -

      ${context.name}

      -

      ${context.size()} tests

      - - <#if context.passed!=0>${context.passed} - <#if context.failed!=0>${context.failed} - <#if context.skipped!=0>${context.skipped} - <#if context.others!=0>${context.others} - -
      -
      -
      -
      -

      ${context.name}

      - <#if context.passed!=0>${context.passed} passed - <#if context.failed!=0>${context.failed} failed - <#if context.skipped!=0>${context.skipped} skipped - <#if context.others!=0>${context.others} others -
      - - - - - - - - - - <#list context.tests as test> - - - - - - - -
      StatusTimestampTestName
      -
      - -
      -
      ${test.startTime?string[("HH:mm:ss a")]} - ${test.name} - <#if test.parent??> -
      - ${TestService.getHierarchicalName(test)} -
      - -
      -
      -
    • - -
    -
    -
    -
    -
    - -
    -
    -
    -
    -
    -
    \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/spark/partials/test.ftl b/src/main/resources/com/aventstack/extentreports/view/spark/partials/test.ftl deleted file mode 100644 index 2a543c2..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/spark/partials/test.ftl +++ /dev/null @@ -1,128 +0,0 @@ -
    -
    -
    - -
      - - <#if authorContext?? && authorContext?size != 0> - - - <#if categoryContext?? && categoryContext?size != 0> - - - <#if deviceContext?? && deviceContext?size != 0> - - -
    -
    -
    -
      - <#list report.testList as test> -
    • -
      - -
      -
      -
      -

      ${test.name}

      -

      ${TestService.getRunDuration(test)}

      - ${test.startTime?string("HH:mm:ss a")} -
      -
      -
      -
      -
      -
      -
      ${test.name}
      - ${test.startTime?string("MM.dd.yyyy HH:mm:ss")} - ${test.endTime?string("MM.dd.yyyy HH:mm:ss")} - ${TestService.getRunDuration(test)} -
      - <#if TestService.testHasAttributes(test)> -
      - <@attributes test=test /> -
      - - <#if test.description??> -
      - ${test.description} -
      - -
      -
      - <#if !isbdd> - <#include "standard-content.ftl"> - <#else> - <#include "bdd-content.ftl"> - -
      -
    • - -
    -
    -
    -
    -
    - -
    -
    -
    -
    -
    -
    \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/spark/spark.spa.ftl b/src/main/resources/com/aventstack/extentreports/view/spark/spark.spa.ftl deleted file mode 100644 index c4b5fc2..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/spark/spark.spa.ftl +++ /dev/null @@ -1,42 +0,0 @@ -<#include "../commons/commons-variables.ftl"> -<#include "../commons/commons-macros.ftl"> -<#include "macros/attributes.ftl"> -<#include "macros/log.ftl"> -<#include "macros/recurse_nodes.ftl"> - -<#assign isbdd=false pageClass=""> -<#if report.testList?? && report.testList?has_content && report.testList[0].isBehaviorDrivenType()> - <#assign pageClass="bdd-report" isbdd=true> - - - - -<#include "partials/head.ftl"> -<#if offline=="true"> - -<#else> - - - -
    -
    - <#include "partials/navbar.ftl"> - <#include "partials/sidenav.ftl"> -
    -
    - <#include "partials/test.ftl"> - <#if categoryContext?? && categoryContext?size != 0> - <#include "partials/tag.ftl"> - - <#if exceptionContext?? && exceptionContext?size != 0> - <#include "partials/exception.ftl"> - - - <#include "partials/dashboard.ftl"> -
    -
    -
    -
    - <#include "partials/scripts.ftl"> - - \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/spark/tag.ftl b/src/main/resources/com/aventstack/extentreports/view/spark/tag.ftl deleted file mode 100644 index f2b8812..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/spark/tag.ftl +++ /dev/null @@ -1,20 +0,0 @@ -<#include "../commons/commons-variables.ftl"> - - - -<#include "partials/head.ftl"> - -
    -
    - <#include "partials/navbar.ftl"> - <#include "partials/sidenav.ftl"> -
    -
    - <#include "partials/tag.ftl"> -
    -
    -
    -
    - <#include "partials/scripts.ftl"> - - \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/spark/test.ftl b/src/main/resources/com/aventstack/extentreports/view/spark/test.ftl deleted file mode 100644 index 6380060..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/spark/test.ftl +++ /dev/null @@ -1,34 +0,0 @@ -<#include "../commons/commons-variables.ftl"> -<#include "../commons/commons-macros.ftl"> -<#include "macros/attributes.ftl"> -<#include "macros/log.ftl"> -<#include "macros/recurse_nodes.ftl"> - -<#assign isbdd=false pageClass=""> -<#if report.testList?? && report.testList?has_content && report.testList[0].isBehaviorDrivenType()> - <#assign pageClass="bdd-report" isbdd=true> - - - - -<#include "partials/head.ftl"> -<#if offline=="true"> - -<#else> - - - -
    -
    - <#include "partials/navbar.ftl"> - <#include "partials/sidenav.ftl"> -
    -
    - <#include "partials/test.ftl"> -
    -
    -
    -
    - <#include "partials/scripts.ftl"> - - \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/v3html/author-view/v3-html-author-view.ftl b/src/main/resources/com/aventstack/extentreports/view/v3html/author-view/v3-html-author-view.ftl deleted file mode 100644 index 386671c..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/v3html/author-view/v3-html-author-view.ftl +++ /dev/null @@ -1,74 +0,0 @@ -<#if authorContext?? && authorContext?size != 0> -
    -
    -
    - - - -
    -
    -
    -
    -
      - <#list authorContext as author> -
    • -
      - ${ author.name } - - <#if author.passed != 0> - ${ author.passed } - - <#if author.failed != 0> - ${ author.failed } - - <#if author.others != 0> - ${ author.others } - - -
      -
      -
      - <#if author.passed != 0>Passed: ${ author.passed } - <#if author.failed != 0>Failed: ${ author.failed } - <#if author.others != 0>Others: ${ author.others } -
      -
      - - - - - - - - - - <#list author.tests as test> - - - - - - - -
      TimestampTestNameStatus
      ${ test.startTime?datetime?string["${timeStampFormat}"] }${ test.name }${ test.status }
      -
      -
      -
    • - -
    -
    -
    -
    -
    -
    -
    -
    -
    - \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/v3html/category-view/v3-html-category-view.ftl b/src/main/resources/com/aventstack/extentreports/view/v3html/category-view/v3-html-category-view.ftl deleted file mode 100644 index cb3a62c..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/v3html/category-view/v3-html-category-view.ftl +++ /dev/null @@ -1,75 +0,0 @@ -<#if categoryContext?? && categoryContext?size != 0> -
    -
    -
    - - - -
    -
    -
    -
    -
      - <#list categoryContext as category> -
    • -
      - ${ category.name } - - <#if category.passed != 0> - ${ category.passed } - - <#if category.failed != 0> - ${ category.failed } - - <#if category.skipped != 0> - ${ category.skipped } - - -
      -
      -
      - <#if category.passed != 0>Passed: ${ category.passed } - <#if category.failed != 0>Failed: ${ category.failed } - <#if category.skipped != 0>Skipped: ${ category.skipped } -
      -
      - - - - - - - - - - <#list category.tests as test> - - - - - - - -
      TimestampTestNameStatus
      ${ test.startTime?datetime?string["${timeStampFormat}"] }${ test.name }${ test.status }
      -
      -
      -
    • - -
    -
    -
    -
    -
    -
    -
    -
    -
    - - \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/v3html/dashboard-view/v3-html-dashboard-view.ftl b/src/main/resources/com/aventstack/extentreports/view/v3html/dashboard-view/v3-html-dashboard-view.ftl deleted file mode 100644 index f995b83..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/v3html/dashboard-view/v3-html-dashboard-view.ftl +++ /dev/null @@ -1,101 +0,0 @@ -
    -
    -
    Dashboard
    - -
    -
    -
    - ${ parentViewChartsHeading } -
    ${ parentCount }
    -
    -
    -
    -
    - ${ childViewChartsHeading } -
    ${ childCount }
    -
    -
    - <#if grandChildViewChartsHeading != ''> -
    -
    - ${ grandChildViewChartsHeading } -
    ${ grandChildCount }
    -
    -
    - -
    -
    - Start -
    ${ report.startTime?datetime?string["${timeStampFormat}"] }
    -
    -
    -
    -
    - End -
    ${ report.endTime?datetime?string["${timeStampFormat}"] }
    -
    -
    -
    -
    - Time Taken -
    ${ report.longRunDuration }
    -
    -
    - <#if systemAttributeContext?size != 0> -
    -
    - Environment

     

    - - - - - - - <#list systemAttributeContext as sa> - <#if sa?? && sa.name?? && sa.value??> - - - - - - -
    NameValue
    ${ sa.name }${ sa.value }
    -
    -
    - - <#if categoryContext?? && categoryContext?size != 0> -
    -
    - Categories

     

    - - - - - - - - - - <#list categoryContext as category> - - - - - - - - -
    NamePassedFailedSkippedPassed %
    ${category.name}${category.passed}${category.failed}${category.skipped} - <#if category.size()!=0> - ${(category.passed/category.size())*100}% - <#else> - 0% - -
    -
    -
    - -
    -
    -
    - diff --git a/src/main/resources/com/aventstack/extentreports/view/v3html/exception-view/v3-html-exception-view.ftl b/src/main/resources/com/aventstack/extentreports/view/v3html/exception-view/v3-html-exception-view.ftl deleted file mode 100644 index 29b985d..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/v3html/exception-view/v3-html-exception-view.ftl +++ /dev/null @@ -1,66 +0,0 @@ -<#if exceptionContext?? && exceptionContext?size != 0> -
    -
    -
    - - - -
    -
    -
    -
    -
      - <#list exceptionContext as exception> -
    • -
      - ${ exception.exceptionInfo.getExceptionName() } - ${ exception.tests?size } -
      -
      -
      - - - - - - - - - - <#list exception.tests as test> - <#list test.exceptionInfoContext.all as testException> - <#if testException.getExceptionName() == exception.exceptionInfo.getExceptionName()> - - - - - - - - - -
      TimestampTestNameStatus
      ${ test.startTime?datetime?string["${timeStampFormat}"] }${ test.name } - -
      -
      -
      -
    • - -
    -
    -
    -
    -
    -
    -
    -
    -
    - - \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/v3html/logs-view/v3-html-testrunner-logs-view.ftl b/src/main/resources/com/aventstack/extentreports/view/v3html/logs-view/v3-html-testrunner-logs-view.ftl deleted file mode 100644 index 1eb8075..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/v3html/logs-view/v3-html-testrunner-logs-view.ftl +++ /dev/null @@ -1,14 +0,0 @@ -<#if report.testRunnerLogs?? && report.testRunnerLogs?size != 0> -
    -
    -
    TestRunner Logs
    - -
    - <#list report.testRunnerLogs as log> - ${ log } - -
    -
    -
    - - \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/v3html/test-view/v3-html-bdd.ftl b/src/main/resources/com/aventstack/extentreports/view/v3html/test-view/v3-html-bdd.ftl deleted file mode 100644 index 1b33f2e..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/v3html/test-view/v3-html-bdd.ftl +++ /dev/null @@ -1,92 +0,0 @@ - -<#if test.description?? && test.description?has_content> -
    ${test.description}
    - -<#list test.nodeContext.all as node> -
    - <#if TestService.testHasCategory(node)> -
    - <#list node.categoryContext.all as category> - ${category.name} - -
    - - ${TestService.getRunDuration(node)} -
    -
    ${MaterialIcon.getIcon(node.status)} ${node.behaviorDrivenTypeName}: ${node.name}
    - <#if TestService.testHasScreenCapture(node)> -
      - <#list node.screenCaptureContext.all as sc> - <#if sc.path??> -
    • panorama
    • - <#elseif sc.isBase64()> -
    • panorama
    • - - -
    - - <#if node.description?? && node.description?has_content> - ${node.description} - -
    - <#if TestService.testHasChildren(node)> -
      - <#list node.nodeContext.all as child> -
    • -
      ${MaterialIcon.getIcon(child.status)}${child.name}
      - <#if TestService.testHasScreenCapture(child)> -
        - <#list child.screenCaptureContext.all as sc> - <#if sc.path??> -
      • panorama
      • - <#elseif sc.isBase64()> -
      • panorama
      • - - -
      - - <#list child.logContext.all as log> - <#if log.exceptionInfo??> - - <#else> -
      ${log.details}
      - - - <#if TestService.testHasChildren(child)> -
        - <#list child.nodeContext.all as gc> -
      • -
        ${MaterialIcon.getIcon(gc.status)}${gc.name}
        - <#if TestService.testHasScreenCapture(gc)> -
          - <#list gc.screenCaptureContext.all as sc> - <#if sc.path??> -
        • panorama
        • - <#elseif sc.isBase64> -
        • panorama
        • - - -
        - - <#list gc.logContext.all as log> - <#if log.exceptionInfo??> - - <#else> -
        ${log.details}
        - - -
      • - -
      - -
    • - -
    - -
    - \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/v3html/test-view/v3-html-standard.ftl b/src/main/resources/com/aventstack/extentreports/view/v3html/test-view/v3-html-standard.ftl deleted file mode 100644 index 7aa8bfd..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/v3html/test-view/v3-html-standard.ftl +++ /dev/null @@ -1,158 +0,0 @@ -
    - ${ test.startTime?datetime?string["${timeStampFormat}"] } - ${ test.endTime?datetime?string["${timeStampFormat}"] } - ${ TestService.getRunDuration(test)?string } -
    -<#if test.description?? && test.description?has_content> -
    ${ test.description}
    - -<#if TestService.testHasAttributes(test)> -
    - <#if TestService.testHasCategory(test)> -
    - <#list test.categoryContext.all as category> - ${ category.name } - -
    - - <#if TestService.testHasAuthor(test)> -
    - <#list test.authorContext.all as author> - ${ author.name } - -
    - - <#if TestService.testHasDevice(test)> -
    - <#list test.deviceContext.all as device> - ${ device.name } - -
    - -
    - -<#if TestService.testHasLog(test)> -
    - - - - - - <#if test.getLogContext().get(0).stepName??> - - - - - - - <#list test.getLogContext().getAll() as log> - - - - <#if log.stepName??> - - - - - - -
    StatusTimestampStepNameDetails
    ${ MaterialIcon.getIcon(log.status) }${ log.timestamp?time?string }${ log.stepName } - <#if log.exceptionInfo??> - - <#else> - ${log.details} - - <#if LogService.logHasScreenCapture(log)>${log.screenCaptureContext.last.source} -
    -
    - -<#if TestService.testHasChildren(test)> -
      - <#macro recurse_nodes nodeList> - <#list nodeList as node> - <#assign leaf=(TestService.testHasChildren(node))?then('','leaf')> -
    • -
      -
      ${ node.name }
      - ${ node.startTime?datetime?string["${timeStampFormat}"] } - · ${ TestService.getRunDuration(node) } - ${ node.status } - <#if TestService.testHasCategory(node)> -
      - <#list node.categoryContext.all as category> - ${ category.name } - -
      - -
      - <#assign displayContent=true> - <#if node.getStatus()=='pass' && disableToggleActionForPassedNode=='true'> - <#assign displayContent=false> - - <#if TestService.testHasLog(node) && displayContent> -
      - <#if TestService.testHasLog(node)> - <#if node.description?? && node.description?has_content> -
      ${ node.description}
      - - <#if TestService.testHasAuthor(node)> -
      - <#list node.authorContext.all as author> - ${ author.name } - -
      - -
      - - - - - - <#if node.getLogContext().get(0).stepName??> - - - - - - - <#list node.getLogContext().getAll() as log> - - - - <#if log.stepName??> - - - - - - -
      StatusTimestampStepNameDetails
      ${ MaterialIcon.getIcon(log.status) }${ log.timestamp?time?string }${ log.stepName } - <#if log.exceptionInfo??> - - <#else> - ${log.details} - - <#if LogService.logHasScreenCapture(log)>${log.screenCaptureContext.last.source} -
      - <#if TestService.testHasScreenCapture(node)> -
        - <#list node.screenCaptureContext.all as sc> -
      • ${ sc.source }
      • - -
      - -
      - -
      - - <#if TestService.testHasChildren(node)> -
        - <@recurse_nodes nodeList=node.nodeContext.all /> -
      - -
    • - - - <@recurse_nodes nodeList=test.nodeContext.all /> -
    - \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/v3html/test-view/v3-html-test-view-charts.ftl b/src/main/resources/com/aventstack/extentreports/view/v3html/test-view/v3-html-test-view-charts.ftl deleted file mode 100644 index 1b1fbed..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/v3html/test-view/v3-html-test-view-charts.ftl +++ /dev/null @@ -1,74 +0,0 @@ -<#assign sizeLarge='s12 m12 l12'> -<#if report.reportStatusStats.childCount!=0> - <#assign sizeLarge='s12 m6 l6'> - -<#if bddReport || (report.reportStatusStats.childCount != 0 && report.reportStatusStats.grandChildCount != 0)> - <#assign sizeLarge='s12 m4 l4'> - -<#assign chartWidth="90" chartHeight="70" chartBoxHeight="94"> -
    -
    -
    -
    -
    ${ parentViewChartsHeading }
    -
    - -
    -
    - ${ report.reportStatusStats.parentCountPass } ${parentLabel} passed -
    -
    - ${ report.reportStatusStats.parentCountFail + report.reportStatusStats.parentCountFatal } ${parentLabel} failed, ${ report.reportStatusStats.parentCountSkip } skipped -
    -
    -
    - <#if report.reportStatusStats.childCount != 0> -
    -
    -
    ${ childViewChartsHeading }
    -
    - -
    -
    - ${ report.reportStatusStats.childCountPass } ${childLabel} passed -
    -
    - ${ report.reportStatusStats.childCountFail + report.reportStatusStats.childCountFatal } ${childLabel} failed, - ${report.reportStatusStats.childCountSkip} skipped, - ${ report.reportStatusStats.childCountError + report.reportStatusStats.childCountWarning + report.reportStatusStats.childCountInfo } others -
    -
    -
    - - <#if report.reportStatusStats.grandChildCount != 0> -
    -
    -
    ${ grandChildViewChartsHeading }
    -
    - -
    -
    - ${ report.reportStatusStats.grandChildCountPass } ${grandChildLabel} passed -
    -
    - ${ report.reportStatusStats.grandChildCountFail + report.reportStatusStats.grandChildCountFatal } ${childLabel} failed, - ${report.reportStatusStats.grandChildCountSkip} skipped, - ${ report.reportStatusStats.grandChildCountError + report.reportStatusStats.grandChildCountWarning + report.reportStatusStats.grandChildCountInfo } others -
    -
    -
    - -
    - <#if enableTimeline=='true'> -
    -
    -
    -
    Timeline (seconds)
    -
    - -
    -
    -
    -
    - -
    \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/v3html/test-view/v3-html-test-view.ftl b/src/main/resources/com/aventstack/extentreports/view/v3html/test-view/v3-html-test-view.ftl deleted file mode 100644 index f3b7e3a..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/v3html/test-view/v3-html-test-view.ftl +++ /dev/null @@ -1,133 +0,0 @@ -
    -
    -
    - -
    - - warning Status - - -
    - - - <#if categoryContext?? && categoryContext?size != 0> -
    - - local_offer Category - - -
    - - - - - - -
    - <#assign btnEnabledClass=(chartVisibleOnOpen=='true')?then('pink-text','')> - - track_changes Dashboard - -
    - - - - -
    -
    - <#if testViewChartLocation=='top'> - <#include 'v3-html-test-view-charts.ftl'> - -
    -
    -
      - <#list report.testList as test> - <#assign isBdd = (TestService.testHasChildren(test) && test.nodeContext.get(0).isBehaviorDrivenType())> - <#assign hasChildrenClass = ''> - <#if test.nodeContext?? && test.nodeContext.all?size != 0> - <#assign hasChildrenClass = 'has-leaf'> - -
    • -
      - ${ test.name } - ${ test.startTime?datetime?string["${timeStampFormat}"] } - ${ test.status } -
      -
      - <#if isBdd> - <#include 'v3-html-bdd.ftl'> - <#else> - <#include 'v3-html-standard.ftl'> - - <#if test.screenCaptureList?? && test.screenCaptureList?size != 0> -
        - <#list test.screenCaptureList as sc> -
      • ${ sc.source }
      • - -
      - -
      -
    • - -
    -
    -
    - -
    -
    - -
    -
    -
    - - <#if testViewChartLocation=='bottom'> - <#include 'v3-html-test-view-charts.ftl'> - -
    - \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/v3html/v3-html-head.ftl b/src/main/resources/com/aventstack/extentreports/view/v3html/v3-html-head.ftl deleted file mode 100644 index 8fcfd77..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/v3html/v3-html-head.ftl +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - <#if offline=="true"> - - - <#else> - - - - - - ${ config.getConfig('documentTitle') } - - - - - diff --git a/src/main/resources/com/aventstack/extentreports/view/v3html/v3-html-index.ftl b/src/main/resources/com/aventstack/extentreports/view/v3html/v3-html-index.ftl deleted file mode 100644 index 2848730..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/v3html/v3-html-index.ftl +++ /dev/null @@ -1,136 +0,0 @@ -<#include "../commons/commons-variables.ftl"> - -<#assign parentCount=report.reportStatusStats.parentCount> -<#assign childCount=report.reportStatusStats.childCount> -<#assign grandChildCount=report.reportStatusStats.grandChildCount> -<#assign theme=config.containsConfig('theme')?then(config.getConfig('theme')?lower_case, 'standard')> -<#assign testViewChartLocation=config.containsConfig('chartLocation')?then(config.getConfig('chartLocation')?lower_case, 'top')> -<#assign chartVisibleOnOpen=config.containsConfig('chartVisibilityOnOpen')?then(config.getConfig('chartVisibilityOnOpen'), 'false')> -<#assign klovUrl=config.containsConfig('klov-url')?then(config.getConfig('klov-url'), '')> -<#assign disableToggleActionForPassedNode=config.containsConfig('disableToggleActionForPassedNode')?then(config.getConfig('disableToggleActionForPassedNode'), '')> -<#assign enableTimeline=config.containsConfig('enableTimeline')?then(config.getConfig('enableTimeline'), 'true')> -<#assign bddReport=false> -<#assign bddClass=''> -<#if report.testList?? && report.testList?size != 0> -<#assign firstTest=report.testList[0]> -<#assign bddReport = (TestService.testHasChildren(firstTest) && firstTest.nodeContext.get(0).isBehaviorDrivenType())?then(true, false)> - -<#assign parentViewChartsHeading='Classes' childViewChartsHeading='Tests' grandChildViewChartsHeading='Steps'> -<#assign parentLabel='class(es)' childLabel='test(s)' grandChildLabel='log(s)'> -<#if bddReport> -<#assign parentViewChartsHeading='Features' childViewChartsHeading='Scenarios' grandChildViewChartsHeading='Steps'> -<#assign parentLabel='feature(s)' childLabel='scenario(s)' grandChildLabel='step(s)'> -<#assign bddClass='bdd-report'> -<#else> -<#if (childCount == 0 || grandChildCount == 0)> -<#assign parentViewChartsHeading='Tests' childViewChartsHeading='Steps' grandChildViewChartsHeading=''> -<#assign parentLabel='test(s)' childLabel='step(s)' grandChildLabel=''> - -<#if report.analysisStrategy?string == 'SUITE'> -<#assign parentViewChartsHeading='Suites' childViewChartsHeading='Tests' grandChildViewChartsHeading='Test Methods'> -<#assign parentLabel='suite(s)' childLabel='test(s)' grandChildLabel='method(s)'> - - - -<#assign timeStampFormat = config.getConfig('timeStampFormat')> -<#assign resourceCDN=config.getConfig('resourceCDN') cdnURI="cdn.jsdelivr.net/gh/extent-framework/extent-github-cdn@" csscommit="ff53917fbbdb5ef820abbbe4d199a6942dc771ff" jscommit="ff53917fbbdb5ef820abbbe4d199a6942dc771ff"> -<#if resourceCDN=="extentreports"> - <#assign cdnURI="extentreports.com/resx" csscommit="" jscommit=""> - - -<#include "../commons/commons-variables.ftl"> - - - - <#include 'v3-html-head.ftl'> - -
    - desktop_windows -
    - <#include 'v3-html-nav.ftl'> - -
    - <#include 'test-view/v3-html-test-view.ftl'> - <#if config.getConfig('enableCategoryView')?? && config.getConfig('enableCategoryView') == 'true'> - <#include 'category-view/v3-html-category-view.ftl'> - - <#if config.getConfig('enableExceptionView')?? && config.getConfig('enableExceptionView') == 'true'> - <#include 'exception-view/v3-html-exception-view.ftl'> - - <#if config.getConfig('enableAuthorView')?? && config.getConfig('enableAuthorView') == 'true'> - <#include 'author-view/v3-html-author-view.ftl'> - - <#include 'dashboard-view/v3-html-dashboard-view.ftl'> - <#if config.getConfig('enableTestRunnerLogsView')?? && config.getConfig('enableTestRunnerLogsView') == 'true'> - <#include 'logs-view/v3-html-testrunner-logs-view.ftl'> - -
    - - - <#if enableTimeline=='true'> - - - - <#if offline=="true"> - - <#else> - - - <#assign hide=(chartVisibleOnOpen=='true')?then(false, true)> - <#if hide> - - - - - \ No newline at end of file diff --git a/src/main/resources/com/aventstack/extentreports/view/v3html/v3-html-nav.ftl b/src/main/resources/com/aventstack/extentreports/view/v3html/v3-html-nav.ftl deleted file mode 100644 index cf63f3f..0000000 --- a/src/main/resources/com/aventstack/extentreports/view/v3html/v3-html-nav.ftl +++ /dev/null @@ -1,37 +0,0 @@ - \ No newline at end of file diff --git a/src/main/resources/html.properties b/src/main/resources/html.properties deleted file mode 100644 index 55caf1f..0000000 --- a/src/main/resources/html.properties +++ /dev/null @@ -1,15 +0,0 @@ -encoding=utf-8 -protocol=https -theme=standard -chartLocation=top -chartVisibilityOnOpen=true -documentTitle=ExtentReports -reportName=ExtentReports -offline=false -resourceCDN=github -timeStampFormat=MMM d, yyyy hh:mm:ss a -enableCategoryView=true -enableExceptionView=true -enableAuthorView=true -enableTestRunnerLogsView=true -enableTimeline=true diff --git a/src/main/resources/klov.properties b/src/main/resources/klov.properties deleted file mode 100644 index bd422ba..0000000 --- a/src/main/resources/klov.properties +++ /dev/null @@ -1,6 +0,0 @@ -project.name=Default1 -report.name=Default1 -mongodb.host=localhost -mongodb.port=27017 -klov.host=http://localhost -klov.port=80 diff --git a/src/main/resources/logger.properties b/src/main/resources/logger.properties deleted file mode 100644 index fbedad5..0000000 --- a/src/main/resources/logger.properties +++ /dev/null @@ -1,10 +0,0 @@ -encoding=utf-8 -protocol=https -theme=standard -documentTitle=ExtentReports -reportName=ExtentReports -timeStampFormat=MMM d, yyyy hh:mm:ss a -enableTimeline=true -autoCreateRelativePathMedia=false -enableDashboard=true -enableOfflineMode=false diff --git a/src/main/resources/spark.properties b/src/main/resources/spark.properties deleted file mode 100644 index 55caf1f..0000000 --- a/src/main/resources/spark.properties +++ /dev/null @@ -1,15 +0,0 @@ -encoding=utf-8 -protocol=https -theme=standard -chartLocation=top -chartVisibilityOnOpen=true -documentTitle=ExtentReports -reportName=ExtentReports -offline=false -resourceCDN=github -timeStampFormat=MMM d, yyyy hh:mm:ss a -enableCategoryView=true -enableExceptionView=true -enableAuthorView=true -enableTestRunnerLogsView=true -enableTimeline=true diff --git a/src/test/java/com/aventstack/extentreports/AppenderTest.java b/src/test/java/com/aventstack/extentreports/AppenderTest.java new file mode 100644 index 0000000..55a4989 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/AppenderTest.java @@ -0,0 +1,166 @@ +package com.aventstack.extentreports; + +import java.io.IOException; +import java.util.List; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.aventstack.extentreports.model.ScreenCapture; +import com.aventstack.extentreports.reporter.JsonFormatter; + +public class AppenderTest { + private static final String JSON_ARCHIVE = "target/json/jsonArchive.json"; + + @Test + public void testWithLogs() throws IOException { + // initial, create archive: + ExtentReports extent = new ExtentReports(); + JsonFormatter json = new JsonFormatter(JSON_ARCHIVE); + extent.attachReporter(json); + ExtentTest test1 = extent.createTest("Testname1", "description1") + .pass("Pass") + .skip("Skip") + .fail("Fail"); + ExtentTest test2 = extent.createTest("Testname2", "description2") + .warning("Warn") + .info("Info"); + extent.flush(); + + // post, check archive + extent = new ExtentReports(); + extent.createDomainFromJsonArchive(JSON_ARCHIVE); + List list = extent.getReport().getTestList(); + Assert.assertEquals(list.size(), 2); + Assert.assertEquals(list.get(0).getStatus(), test1.getStatus()); + Assert.assertEquals(list.get(1).getStatus(), test2.getStatus()); + Assert.assertEquals(list.get(0).getName(), test1.getModel().getName()); + Assert.assertEquals(list.get(1).getName(), test2.getModel().getName()); + Assert.assertEquals(list.get(0).getDescription(), test1.getModel().getDescription()); + Assert.assertEquals(list.get(1).getDescription(), test2.getModel().getDescription()); + Assert.assertEquals(list.get(0).getLogs().size(), test1.getModel().getLogs().size()); + Assert.assertEquals(list.get(1).getLogs().size(), test2.getModel().getLogs().size()); + } + + @Test + public void testWithChildren() throws IOException { + // initial, create archive: + ExtentReports extent = new ExtentReports(); + JsonFormatter json = new JsonFormatter(JSON_ARCHIVE); + extent.attachReporter(json); + ExtentTest test1 = extent.createTest("Testname1", "description1"); + test1.createNode("Child1") + .pass("Pass") + .skip("Skip") + .fail("Fail"); + ExtentTest test2 = extent.createTest("Testname2", "description2"); + test2.createNode("Child2") + .warning("Warn") + .info("Info"); + test2.createNode("Child3") + .pass("Pass"); + extent.flush(); + + // post, check archive + extent = new ExtentReports(); + extent.createDomainFromJsonArchive(JSON_ARCHIVE); + List list = extent.getReport().getTestList(); + + // parent checks + Assert.assertEquals(list.size(), 2); + Assert.assertEquals(list.get(0).getChildren().size(), 1); + Assert.assertEquals(list.get(1).getChildren().size(), 2); + Assert.assertEquals(list.get(0).getStatus(), test1.getStatus()); + Assert.assertEquals(list.get(1).getStatus(), test2.getStatus()); + Assert.assertEquals(list.get(0).getName(), test1.getModel().getName()); + Assert.assertEquals(list.get(1).getName(), test2.getModel().getName()); + Assert.assertEquals(list.get(0).getDescription(), test1.getModel().getDescription()); + Assert.assertEquals(list.get(1).getDescription(), test2.getModel().getDescription()); + Assert.assertEquals(list.get(0).getLogs().size(), test1.getModel().getLogs().size()); + Assert.assertEquals(list.get(1).getLogs().size(), test2.getModel().getLogs().size()); + } + + @Test + public void children() throws IOException { + // initial, create archive: + ExtentReports extent = new ExtentReports(); + JsonFormatter json = new JsonFormatter(JSON_ARCHIVE); + extent.attachReporter(json); + ExtentTest test1 = extent.createTest("Testname1", "description1"); + ExtentTest child1 = test1.createNode("Child1") + .pass("Pass") + .skip("Skip") + .fail("Fail"); + ExtentTest test2 = extent.createTest("Testname2", "description2"); + ExtentTest child2 = test2.createNode("Child2") + .warning("Warn") + .info("Info"); + ExtentTest child3 = test2.createNode("Child3") + .pass("Pass"); + extent.flush(); + + // post, check archive + extent = new ExtentReports(); + extent.createDomainFromJsonArchive(JSON_ARCHIVE); + List list = extent.getReport().getTestList(); + + // children checks + Assert.assertEquals(list.get(0).getChildren().get(0).getName(), child1.getModel().getName()); + Assert.assertEquals(list.get(1).getChildren().get(0).getName(), child2.getModel().getName()); + Assert.assertEquals(list.get(1).getChildren().get(1).getName(), child3.getModel().getName()); + Assert.assertEquals(list.get(0).getChildren().get(0).getLogs().size(), child1.getModel().getLogs().size()); + Assert.assertEquals(list.get(1).getChildren().get(0).getLogs().size(), child2.getModel().getLogs().size()); + Assert.assertEquals(list.get(1).getChildren().get(1).getLogs().size(), child3.getModel().getLogs().size()); + } + + @Test + public void testWithMedia() throws IOException { + // initial, create archive: + ExtentReports extent = new ExtentReports(); + JsonFormatter json = new JsonFormatter(JSON_ARCHIVE); + extent.attachReporter(json); + ExtentTest test1 = extent.createTest("Testname1") + .addScreenCaptureFromPath("img.png") + .fail("Fail", MediaEntityBuilder.createScreenCaptureFromPath("img.png").build()); + extent.flush(); + + // post, check archive + extent = new ExtentReports(); + extent.createDomainFromJsonArchive(JSON_ARCHIVE); + List list = extent.getReport().getTestList(); + + // parent checks + Assert.assertEquals(list.size(), 1); + Assert.assertEquals(list.get(0).getMedia().size(), 1); + Assert.assertNotNull(list.get(0).getLogs().get(0).getMedia()); + Assert.assertEquals(list.get(0).getMedia().get(0).getPath(), test1.getModel().getMedia().get(0).getPath()); + Assert.assertEquals(list.get(0).getLogs().get(0).getMedia().getPath(), + test1.getModel().getLogs().get(0).getMedia().getPath()); + } + + @Test + public void testWithMediaBase64() throws IOException { + // initial, create archive: + ExtentReports extent = new ExtentReports(); + JsonFormatter json = new JsonFormatter(JSON_ARCHIVE); + extent.attachReporter(json); + ExtentTest test1 = extent.createTest("Testname1") + .addScreenCaptureFromBase64String("base64string") + .fail("Fail", MediaEntityBuilder.createScreenCaptureFromBase64String("base64string").build()); + extent.flush(); + + // post, check archive + extent = new ExtentReports(); + extent.createDomainFromJsonArchive(JSON_ARCHIVE); + List list = extent.getReport().getTestList(); + + // parent checks + Assert.assertEquals(list.size(), 1); + Assert.assertEquals(list.get(0).getMedia().size(), 1); + Assert.assertNotNull(list.get(0).getLogs().get(0).getMedia()); + Assert.assertEquals(((ScreenCapture) list.get(0).getMedia().get(0)).getBase64(), + ((ScreenCapture) test1.getModel().getMedia().get(0)).getBase64()); + Assert.assertEquals(((ScreenCapture) list.get(0).getLogs().get(0).getMedia()).getBase64(), + ((ScreenCapture) test1.getModel().getLogs().get(0).getMedia()).getBase64()); + } +} diff --git a/src/test/java/com/aventstack/extentreports/Base.java b/src/test/java/com/aventstack/extentreports/Base.java deleted file mode 100644 index 138d3d5..0000000 --- a/src/test/java/com/aventstack/extentreports/Base.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.aventstack.extentreports; - -import java.io.File; - -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; - -import com.aventstack.extentreports.reporter.ConsoleLogger; - -public abstract class Base { - - protected final String fileName = getClass().getSimpleName(); - protected final String htmlFilePath = getOutputFolder() + fileName + ".html"; - protected final String emailFilePath = getOutputFolder() + "email-" + fileName + ".html"; - protected ExtentReports extent; - - @BeforeClass - public void setup() { - ConsoleLogger logger = new ConsoleLogger(); - extent = new ExtentReports(); - extent.attachReporter(logger); - } - - @AfterClass - public void tearDown() { - extent.flush(); - } - - protected String getOutputFolder() { - return "test-output/"; - } - - public Base() { - File folder = new File(getOutputFolder()); - folder.mkdirs(); - } -} diff --git a/src/test/java/com/aventstack/extentreports/api/BddAttributesTest.java b/src/test/java/com/aventstack/extentreports/BddTypeTest.java similarity index 64% rename from src/test/java/com/aventstack/extentreports/api/BddAttributesTest.java rename to src/test/java/com/aventstack/extentreports/BddTypeTest.java index d16bdae..9786f7d 100644 --- a/src/test/java/com/aventstack/extentreports/api/BddAttributesTest.java +++ b/src/test/java/com/aventstack/extentreports/BddTypeTest.java @@ -1,12 +1,10 @@ -package com.aventstack.extentreports.api; +package com.aventstack.extentreports; import java.lang.reflect.Method; import org.testng.Assert; import org.testng.annotations.Test; -import com.aventstack.extentreports.Base; -import com.aventstack.extentreports.ExtentTest; import com.aventstack.extentreports.gherkin.model.And; import com.aventstack.extentreports.gherkin.model.Asterisk; import com.aventstack.extentreports.gherkin.model.Background; @@ -17,94 +15,95 @@ import com.aventstack.extentreports.gherkin.model.ScenarioOutline; import com.aventstack.extentreports.gherkin.model.Then; import com.aventstack.extentreports.gherkin.model.When; -import com.aventstack.extentreports.model.service.TestService; -public class BddAttributesTest extends Base { +public class BddTypeTest { + private ExtentReports extent() { + return new ExtentReports(); + } @Test public void featureIsOfBddType(Method method) { - ExtentTest feature = extent.createTest(Feature.class, method.getName()); - Assert.assertTrue(TestService.isTestBehaviorDriven(feature.getModel())); + ExtentTest feature = extent().createTest(Feature.class, method.getName()); + Assert.assertTrue(feature.getModel().isBDD()); Assert.assertEquals(feature.getModel().getBddType(), Feature.class); } - + @Test public void scenarioIsOfBddTypeWithBddChild(Method method) { - ExtentTest feature = extent.createTest(Feature.class, method.getName()); + ExtentTest feature = extent().createTest(Feature.class, method.getName()); ExtentTest scenario = feature.createNode(Scenario.class, "Scenario"); - Assert.assertTrue(TestService.isTestBehaviorDriven(scenario.getModel())); + Assert.assertTrue(scenario.getModel().isBDD()); Assert.assertEquals(scenario.getModel().getBddType(), Scenario.class); } - + @Test public void scenarioOutlineIsOfBddTypeWithBddChild(Method method) { - ExtentTest feature = extent.createTest(Feature.class, method.getName()); + ExtentTest feature = extent().createTest(Feature.class, method.getName()); ExtentTest scenarioOutline = feature.createNode(ScenarioOutline.class, "ScenarioOutline"); - Assert.assertTrue(TestService.isTestBehaviorDriven(scenarioOutline.getModel())); + Assert.assertTrue(scenarioOutline.getModel().isBDD()); Assert.assertEquals(scenarioOutline.getModel().getBddType(), ScenarioOutline.class); } - + @Test public void andIsOfBddTypeWithBddChild(Method method) { - ExtentTest feature = extent.createTest(Feature.class, method.getName()); + ExtentTest feature = extent().createTest(Feature.class, method.getName()); ExtentTest scenario = feature.createNode(Scenario.class, "Scenario"); ExtentTest and = scenario.createNode(And.class, "And"); - Assert.assertTrue(TestService.isTestBehaviorDriven(and.getModel())); + Assert.assertTrue(and.getModel().isBDD()); Assert.assertEquals(and.getModel().getBddType(), And.class); } - + @Test public void asteriskIsOfBddTypeWithBddChild(Method method) { - ExtentTest feature = extent.createTest(Feature.class, method.getName()); + ExtentTest feature = extent().createTest(Feature.class, method.getName()); ExtentTest scenario = feature.createNode(Scenario.class, "Scenario"); ExtentTest asterisk = scenario.createNode(Asterisk.class, "Asterisk"); - Assert.assertTrue(TestService.isTestBehaviorDriven(asterisk.getModel())); + Assert.assertTrue(asterisk.getModel().isBDD()); Assert.assertEquals(asterisk.getModel().getBddType(), Asterisk.class); } - + @Test public void backgroundIsOfBddTypeWithBddChild(Method method) { - ExtentTest feature = extent.createTest(Feature.class, method.getName()); + ExtentTest feature = extent().createTest(Feature.class, method.getName()); ExtentTest scenario = feature.createNode(Scenario.class, "Scenario"); ExtentTest background = scenario.createNode(Background.class, "Background"); - Assert.assertTrue(TestService.isTestBehaviorDriven(background.getModel())); + Assert.assertTrue(background.getModel().isBDD()); Assert.assertEquals(background.getModel().getBddType(), Background.class); } - + @Test public void butIsOfBddTypeWithBddChild(Method method) { - ExtentTest feature = extent.createTest(Feature.class, method.getName()); + ExtentTest feature = extent().createTest(Feature.class, method.getName()); ExtentTest scenario = feature.createNode(Scenario.class, "Scenario"); ExtentTest but = scenario.createNode(But.class, "But"); - Assert.assertTrue(TestService.isTestBehaviorDriven(but.getModel())); + Assert.assertTrue(but.getModel().isBDD()); Assert.assertEquals(but.getModel().getBddType(), But.class); } - + @Test public void givenIsOfBddTypeWithBddChild(Method method) { - ExtentTest feature = extent.createTest(Feature.class, method.getName()); + ExtentTest feature = extent().createTest(Feature.class, method.getName()); ExtentTest scenario = feature.createNode(Scenario.class, "Scenario"); ExtentTest given = scenario.createNode(Given.class, "Given"); - Assert.assertTrue(TestService.isTestBehaviorDriven(given.getModel())); + Assert.assertTrue(given.getModel().isBDD()); Assert.assertEquals(given.getModel().getBddType(), Given.class); } - + @Test public void thenIsOfBddTypeWithBddChild(Method method) { - ExtentTest feature = extent.createTest(Feature.class, method.getName()); + ExtentTest feature = extent().createTest(Feature.class, method.getName()); ExtentTest scenario = feature.createNode(Scenario.class, "Scenario"); ExtentTest then = scenario.createNode(Then.class, "Then"); - Assert.assertTrue(TestService.isTestBehaviorDriven(then.getModel())); + Assert.assertTrue(then.getModel().isBDD()); Assert.assertEquals(then.getModel().getBddType(), Then.class); } - + @Test public void whenIsOfBddTypeWithBddChild(Method method) { - ExtentTest feature = extent.createTest(Feature.class, method.getName()); + ExtentTest feature = extent().createTest(Feature.class, method.getName()); ExtentTest scenario = feature.createNode(Scenario.class, "Scenario"); ExtentTest when = scenario.createNode(When.class, "When"); - Assert.assertTrue(TestService.isTestBehaviorDriven(when.getModel())); + Assert.assertTrue(when.getModel().isBDD()); Assert.assertEquals(when.getModel().getBddType(), When.class); } - } diff --git a/src/test/java/com/aventstack/extentreports/ExtentReportsRemoveTest.java b/src/test/java/com/aventstack/extentreports/ExtentReportsRemoveTest.java new file mode 100644 index 0000000..6878769 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/ExtentReportsRemoveTest.java @@ -0,0 +1,53 @@ +package com.aventstack.extentreports; + +import org.testng.Assert; + +public class ExtentReportsRemoveTest { + private static final String TEST_NAME = "TEST"; + + private ExtentReports extent() { + return new ExtentReports(); + } + + @org.testng.annotations.Test + public void removeTest() { + ExtentReports extent = extent(); + ExtentTest test = extent.createTest(TEST_NAME); + Assert.assertEquals(extent.getReport().getTestList().size(), 1); + extent.removeTest(test); + Assert.assertEquals(extent.getReport().getTestList().size(), 0); + } + + @org.testng.annotations.Test + public void removeTestByName() { + ExtentReports extent = extent(); + extent.createTest(TEST_NAME); + Assert.assertEquals(extent.getReport().getTestList().size(), 1); + extent.removeTest(TEST_NAME); + Assert.assertEquals(extent.getReport().getTestList().size(), 0); + } + + @org.testng.annotations.Test + public void removeNode() { + ExtentReports extent = extent(); + ExtentTest test = extent.createTest(TEST_NAME); + ExtentTest node = test.createNode(TEST_NAME); + Assert.assertEquals(extent.getReport().getTestList().size(), 1); + Assert.assertEquals(extent.getReport().getTestList().get(0).getChildren().size(), 1); + extent.removeTest(node); + Assert.assertEquals(extent.getReport().getTestList().size(), 1); + Assert.assertEquals(extent.getReport().getTestList().get(0).getChildren().size(), 0); + } + + @org.testng.annotations.Test + public void removeNodeByName() { + ExtentReports extent = extent(); + ExtentTest test = extent.createTest(TEST_NAME + "Parent"); + test.createNode(TEST_NAME); + Assert.assertEquals(extent.getReport().getTestList().size(), 1); + Assert.assertEquals(extent.getReport().getTestList().get(0).getChildren().size(), 1); + extent.removeTest(TEST_NAME); + Assert.assertEquals(extent.getReport().getTestList().size(), 1); + Assert.assertEquals(extent.getReport().getTestList().get(0).getChildren().size(), 0); + } +} diff --git a/src/test/java/com/aventstack/extentreports/ExtentReportsSystemEnvTest.java b/src/test/java/com/aventstack/extentreports/ExtentReportsSystemEnvTest.java new file mode 100644 index 0000000..72ee77c --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/ExtentReportsSystemEnvTest.java @@ -0,0 +1,38 @@ +package com.aventstack.extentreports; + +import org.testng.Assert; +import org.testng.annotations.Test; + +public class ExtentReportsSystemEnvTest { + + private ExtentReports extent() { + return new ExtentReports(); + } + + @Test + public void systemInfo() { + ExtentReports extent = extent(); + extent.setSystemInfo("a", "b"); + Assert.assertEquals(extent.getReport().getSystemEnvInfo().size(), 1); + Assert.assertEquals(extent.getReport().getSystemEnvInfo().get(0).getName(), "a"); + Assert.assertEquals(extent.getReport().getSystemEnvInfo().get(0).getValue(), "b"); + } + + @Test + public void nullSystemInfo() { + ExtentReports extent = extent(); + extent.setSystemInfo(null, null); + Assert.assertEquals(extent.getReport().getSystemEnvInfo().size(), 1); + Assert.assertEquals(extent.getReport().getSystemEnvInfo().get(0).getName(), null); + Assert.assertEquals(extent.getReport().getSystemEnvInfo().get(0).getValue(), null); + } + + @Test + public void emptySystemInfo() { + ExtentReports extent = extent(); + extent.setSystemInfo("", ""); + Assert.assertEquals(extent.getReport().getSystemEnvInfo().size(), 1); + Assert.assertEquals(extent.getReport().getSystemEnvInfo().get(0).getName(), ""); + Assert.assertEquals(extent.getReport().getSystemEnvInfo().get(0).getValue(), ""); + } +} diff --git a/src/test/java/com/aventstack/extentreports/ExtentReportsTest.java b/src/test/java/com/aventstack/extentreports/ExtentReportsTest.java new file mode 100644 index 0000000..071c53d --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/ExtentReportsTest.java @@ -0,0 +1,109 @@ +package com.aventstack.extentreports; + +import java.io.UnsupportedEncodingException; +import java.util.Arrays; + +import org.testng.Assert; + +import com.aventstack.extentreports.gherkin.GherkinDialectManager; +import com.aventstack.extentreports.gherkin.model.Feature; +import com.aventstack.extentreports.model.Test; + +public class ExtentReportsTest { + private static final String TEST_NAME = "TEST"; + + private ExtentReports extent() { + return new ExtentReports(); + } + + @org.testng.annotations.Test + public void createTestOverloadTypeNameDesc() { + ExtentTest test = extent().createTest(Feature.class, TEST_NAME, "Description"); + Test model = test.getModel(); + Assert.assertTrue(model.isBDD()); + Assert.assertEquals(model.getName(), TEST_NAME); + Assert.assertEquals(model.getDescription(), "Description"); + Assert.assertEquals(model.getBddType(), Feature.class); + Assert.assertTrue(model.isLeaf()); + } + + @org.testng.annotations.Test + public void createTestOverloadTypeName() { + ExtentTest test = extent().createTest(Feature.class, TEST_NAME); + Test model = test.getModel(); + Assert.assertTrue(model.isBDD()); + Assert.assertEquals(model.getName(), TEST_NAME); + Assert.assertNull(model.getDescription()); + Assert.assertEquals(model.getBddType(), Feature.class); + Assert.assertTrue(model.isLeaf()); + } + + @org.testng.annotations.Test + public void createTestOverloadKeywordNameDesc() throws ClassNotFoundException { + ExtentTest test = extent().createTest(new GherkinKeyword("Feature"), TEST_NAME, "Description"); + Test model = test.getModel(); + Assert.assertTrue(model.isBDD()); + Assert.assertEquals(model.getName(), TEST_NAME); + Assert.assertEquals(model.getDescription(), "Description"); + Assert.assertEquals(model.getBddType(), Feature.class); + Assert.assertTrue(model.isLeaf()); + } + + @org.testng.annotations.Test + public void createTestOverloadKeywordName() throws ClassNotFoundException { + ExtentTest test = extent().createTest(new GherkinKeyword("Feature"), TEST_NAME); + Test model = test.getModel(); + Assert.assertTrue(model.isBDD()); + Assert.assertEquals(model.getName(), TEST_NAME); + Assert.assertNull(model.getDescription()); + Assert.assertEquals(model.getBddType(), Feature.class); + Assert.assertTrue(model.isLeaf()); + } + + @org.testng.annotations.Test + public void createTestOverloadNameDesc() { + ExtentTest test = extent().createTest(TEST_NAME, "Description"); + Test model = test.getModel(); + Assert.assertFalse(model.isBDD()); + Assert.assertEquals(model.getName(), TEST_NAME); + Assert.assertEquals(model.getDescription(), "Description"); + Assert.assertNull(model.getBddType()); + Assert.assertTrue(model.isLeaf()); + } + + @org.testng.annotations.Test + public void createTestOverloadName() { + ExtentTest test = extent().createTest(TEST_NAME); + Test model = test.getModel(); + Assert.assertFalse(model.isBDD()); + Assert.assertEquals(model.getName(), TEST_NAME); + Assert.assertNull(model.getDescription()); + Assert.assertNull(model.getBddType()); + Assert.assertTrue(model.isLeaf()); + } + + @org.testng.annotations.Test + public void gherkinDialect() throws UnsupportedEncodingException { + ExtentReports extent = extent(); + extent.setGherkinDialect("de"); + Assert.assertEquals(GherkinDialectManager.getLanguage(), "de"); + } + + @org.testng.annotations.Test + public void addTestRunnerOutputSingle() { + String[] logs = new String[]{"Log1", "Log2"}; + ExtentReports extent = extent(); + Arrays.stream(logs).forEach(extent::addTestRunnerOutput); + Assert.assertEquals(extent.getReport().getLogs().size(), 2); + Arrays.stream(logs).forEach(x -> Assert.assertTrue(extent.getReport().getLogs().contains(x))); + } + + @org.testng.annotations.Test + public void addTestRunnerOutputList() { + String[] logs = new String[]{"Log1", "Log2"}; + ExtentReports extent = extent(); + extent.addTestRunnerOutput(Arrays.asList(logs)); + Assert.assertEquals(extent.getReport().getLogs().size(), 2); + Arrays.stream(logs).forEach(x -> Assert.assertTrue(extent.getReport().getLogs().contains(x))); + } +} diff --git a/src/test/java/com/aventstack/extentreports/ExtentTestAttributesTest.java b/src/test/java/com/aventstack/extentreports/ExtentTestAttributesTest.java new file mode 100644 index 0000000..3745bb4 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/ExtentTestAttributesTest.java @@ -0,0 +1,68 @@ +package com.aventstack.extentreports; + +import org.testng.Assert; +import org.testng.annotations.Test; + +public class ExtentTestAttributesTest { + + private ExtentReports extent() { + return new ExtentReports(); + } + + @Test + public void extentTestWithNoAuthor() { + Assert.assertTrue( + extent().createTest("Test") + .assignAuthor() + .getModel() + .getAuthorSet().isEmpty()); + } + + @Test + public void extentTestWithAuthor() { + Assert.assertTrue( + extent().createTest("Test") + .assignAuthor("Author") + .getModel() + .getAuthorSet().stream() + .anyMatch(x -> x.getName().equals("Author"))); + } + + @Test + public void extentTestWithNoDevice() { + Assert.assertTrue( + extent().createTest("Test") + .assignDevice() + .getModel() + .getAuthorSet().isEmpty()); + } + + @Test + public void extentTestWithDevice() { + Assert.assertTrue( + extent().createTest("Test") + .assignDevice("Device") + .getModel() + .getDeviceSet().stream() + .anyMatch(x -> x.getName().equals("Device"))); + } + + @Test + public void extentTestWithNoCategory() { + Assert.assertTrue( + extent().createTest("Test") + .assignCategory() + .getModel() + .getAuthorSet().isEmpty()); + } + + @Test + public void extentTestWithCategory() { + Assert.assertTrue( + extent().createTest("Test") + .assignCategory("Tag") + .getModel() + .getCategorySet().stream() + .anyMatch(x -> x.getName().equals("Tag"))); + } +} diff --git a/src/test/java/com/aventstack/extentreports/ExtentTestGeneratedLogTest.java b/src/test/java/com/aventstack/extentreports/ExtentTestGeneratedLogTest.java new file mode 100644 index 0000000..70efa64 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/ExtentTestGeneratedLogTest.java @@ -0,0 +1,47 @@ +package com.aventstack.extentreports; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.aventstack.extentreports.markuputils.CodeLanguage; +import com.aventstack.extentreports.markuputils.Markup; +import com.aventstack.extentreports.markuputils.MarkupHelper; + +public class ExtentTestGeneratedLogTest { + + private ExtentReports extent() { + return new ExtentReports(); + } + + @Test + public void generatedLogEmpty() { + ExtentTest t = extent().createTest("Test") + .generateLog(Status.PASS, ""); + Assert.assertTrue(t.getModel().hasAnyLog()); + Assert.assertTrue(!t.getModel().getGeneratedLog().isEmpty()); + Assert.assertEquals(t.getModel().getGeneratedLog().get(0).getDetails(), ""); + } + + @Test + public void generatedLogDetails() { + ExtentTest t = extent().createTest("Test") + .generateLog(Status.PASS, "Details"); + Assert.assertTrue(t.getModel().hasAnyLog()); + Assert.assertTrue(!t.getModel().getGeneratedLog().isEmpty()); + Assert.assertEquals(t.getModel().getGeneratedLog().get(0).getDetails(), "Details"); + } + + @Test + public void generatedLogMarkup() { + String json = "{ 'key': 'value' }"; + Markup m = MarkupHelper.createCodeBlock(json, CodeLanguage.JSON); + ExtentTest t = extent().createTest("Test") + .generateLog(Status.PASS, m); + Assert.assertTrue(t.getModel().hasAnyLog()); + Assert.assertTrue(!t.getModel().getGeneratedLog().isEmpty()); + Assert.assertTrue(t.getModel().getGeneratedLog().get(0).getDetails().contains("jsonTree")); + Assert.assertTrue(t.getModel().getGeneratedLog().get(0).getDetails().contains("")); + Assert.assertTrue(t.getModel().getGeneratedLog().get(0).getDetails().contains("{ 'key': 'value' }")); + } +} diff --git a/src/test/java/com/aventstack/extentreports/ExtentTestInvalidArgTest.java b/src/test/java/com/aventstack/extentreports/ExtentTestInvalidArgTest.java new file mode 100644 index 0000000..dcdd5b8 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/ExtentTestInvalidArgTest.java @@ -0,0 +1,18 @@ +package com.aventstack.extentreports; + +import org.testng.annotations.Test; + +public class ExtentTestInvalidArgTest { + + private final ExtentReports extent = new ExtentReports(); + + @Test(expectedExceptions = IllegalArgumentException.class) + public void extentTestWithEmptyName() { + extent.createTest(""); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void extentTestWithNullName() { + extent.createTest(null); + } +} diff --git a/src/test/java/com/aventstack/extentreports/ExtentTestLogHierarchyTest.java b/src/test/java/com/aventstack/extentreports/ExtentTestLogHierarchyTest.java new file mode 100644 index 0000000..daecfd0 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/ExtentTestLogHierarchyTest.java @@ -0,0 +1,55 @@ +package com.aventstack.extentreports; + +import org.testng.Assert; +import org.testng.annotations.Test; + +public class ExtentTestLogHierarchyTest { + private ExtentTest test() { + return new ExtentReports().createTest("Test"); + } + + @Test + public void overall() { + ExtentTest test = test(); + test.pass("Pass"); + test.fail("Fail"); + test.info("Info"); + test.skip("Skip"); + test.warning("Warning"); + Assert.assertEquals(test.getStatus(), Status.FAIL); + } + + @Test + public void info() { + ExtentTest test = test(); + test.info("Info"); + Assert.assertEquals(test.getStatus(), Status.PASS); + } + + @Test + public void passed() { + ExtentTest test = test(); + test.pass("Pass"); + test.info("Info"); + Assert.assertEquals(test.getStatus(), Status.PASS); + } + + @Test + public void skipped() { + ExtentTest test = test(); + test.pass("Pass"); + test.info("Info"); + test.skip("Skip"); + Assert.assertEquals(test.getStatus(), Status.SKIP); + } + + @Test + public void warning() { + ExtentTest test = test(); + test.pass("Pass"); + test.info("Info"); + test.skip("Skip"); + test.warning("Warning"); + Assert.assertEquals(test.getStatus(), Status.WARNING); + } +} diff --git a/src/test/java/com/aventstack/extentreports/ExtentTestLogTest.java b/src/test/java/com/aventstack/extentreports/ExtentTestLogTest.java new file mode 100644 index 0000000..d08215d --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/ExtentTestLogTest.java @@ -0,0 +1,317 @@ +package com.aventstack.extentreports; + +import java.io.IOException; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.aventstack.extentreports.markuputils.Markup; +import com.aventstack.extentreports.markuputils.MarkupHelper; + +public class ExtentTestLogTest { + private static final String DETAILS = "details"; + private static final String ATTACHMENT = "img.png"; + + private ExtentTest test() { + return new ExtentReports().createTest("Test"); + } + + private Exception ex() { + return new RuntimeException(); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void logWithStatusNull() { + test().log(null, null, null, null); + } + + @Test + public void logDetails() { + ExtentTest test = test().log(Status.SKIP, DETAILS + "1"); + Assert.assertEquals(test.getModel().getStatus(), Status.SKIP); + Assert.assertEquals(test.getModel().getLogs().get(0).getDetails(), DETAILS + "1"); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.SKIP); + test.log(Status.FAIL, DETAILS); + Assert.assertEquals(test.getModel().getLogs().get(1).getDetails(), DETAILS); + Assert.assertEquals(test.getModel().getLogs().get(1).getStatus(), Status.FAIL); + } + + @Test + public void logDetailsMedia() throws IOException { + ExtentTest test = test().log(Status.SKIP, DETAILS, + MediaEntityBuilder.createScreenCaptureFromPath(ATTACHMENT).build()); + Assert.assertEquals(test.getModel().getStatus(), Status.SKIP); + Assert.assertEquals(test.getModel().getLogs().get(0).getDetails(), DETAILS); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.SKIP); + Assert.assertEquals(test.getModel().getLogs().get(0).getMedia().getPath(), ATTACHMENT); + test.log(Status.FAIL, DETAILS, MediaEntityBuilder.createScreenCaptureFromPath(ATTACHMENT).build()); + Assert.assertEquals(test.getModel().getLogs().get(1).getDetails(), DETAILS); + Assert.assertEquals(test.getModel().getLogs().get(1).getStatus(), Status.FAIL); + Assert.assertEquals(test.getModel().getLogs().get(1).getMedia().getPath(), ATTACHMENT); + } + + @Test + public void logMedia() throws IOException { + ExtentTest test = test().log(Status.SKIP, + MediaEntityBuilder.createScreenCaptureFromPath(ATTACHMENT).build()); + Assert.assertEquals(test.getModel().getStatus(), Status.SKIP); + Assert.assertEquals(test.getModel().getLogs().get(0).getDetails(), ""); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.SKIP); + Assert.assertEquals(test.getModel().getLogs().get(0).getMedia().getPath(), ATTACHMENT); + test.log(Status.FAIL, MediaEntityBuilder.createScreenCaptureFromPath(ATTACHMENT).build()); + Assert.assertEquals(test.getModel().getLogs().get(1).getDetails(), ""); + Assert.assertEquals(test.getModel().getLogs().get(1).getStatus(), Status.FAIL); + Assert.assertEquals(test.getModel().getLogs().get(1).getMedia().getPath(), ATTACHMENT); + } + + @Test + public void logMarkup() throws IOException { + Markup m = MarkupHelper.createCodeBlock("code"); + ExtentTest test = test().log(Status.SKIP, m); + Assert.assertEquals(test.getModel().getStatus(), Status.SKIP); + Assert.assertTrue(test.getModel().getLogs().get(0).getDetails().contains("code")); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.SKIP); + } + + @Test + public void logThrowable() { + Exception ex = ex(); + ExtentTest test = test().log(Status.SKIP, ex); + Assert.assertEquals(test.getModel().getStatus(), Status.SKIP); + Assert.assertEquals(test.getModel().getLogs().get(0).getException().getException(), ex); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.SKIP); + test.log(Status.FAIL, ex); + Assert.assertEquals(test.getModel().getLogs().get(1).getException().getException(), ex); + Assert.assertEquals(test.getModel().getLogs().get(1).getStatus(), Status.FAIL); + } + + @Test + public void logThrowableMedia() throws IOException { + Exception ex = ex(); + ExtentTest test = test().log(Status.SKIP, ex, + MediaEntityBuilder.createScreenCaptureFromPath(ATTACHMENT).build()); + Assert.assertEquals(test.getModel().getStatus(), Status.SKIP); + Assert.assertEquals(test.getModel().getLogs().get(0).getException().getException(), ex); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.SKIP); + Assert.assertEquals(test.getModel().getLogs().get(0).getMedia().getPath(), ATTACHMENT); + test.log(Status.FAIL, ex, MediaEntityBuilder.createScreenCaptureFromPath(ATTACHMENT).build()); + Assert.assertEquals(test.getModel().getLogs().get(1).getException().getException(), ex); + Assert.assertEquals(test.getModel().getLogs().get(1).getStatus(), Status.FAIL); + Assert.assertEquals(test.getModel().getLogs().get(1).getMedia().getPath(), ATTACHMENT); + } + + @Test + public void failDetails() { + ExtentTest test = test().fail(DETAILS); + Assert.assertEquals(test.getModel().getLogs().get(0).getDetails(), DETAILS); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.FAIL); + } + + @Test + public void failMedia() throws IOException { + ExtentTest test = test().fail( + MediaEntityBuilder.createScreenCaptureFromPath(ATTACHMENT).build()); + test.log(Status.FAIL, DETAILS, MediaEntityBuilder.createScreenCaptureFromPath(ATTACHMENT).build()); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.FAIL); + Assert.assertEquals(test.getModel().getLogs().get(0).getMedia().getPath(), ATTACHMENT); + } + + @Test + public void failThrowable() { + Exception ex = ex(); + ExtentTest test = test().fail(ex); + Assert.assertEquals(test.getModel().getLogs().get(0).getException().getException(), ex); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.FAIL); + } + + @Test + public void failThrowableMedia() throws IOException { + Exception ex = ex(); + ExtentTest test = test().fail(ex, + MediaEntityBuilder.createScreenCaptureFromPath(ATTACHMENT).build()); + Assert.assertEquals(test.getModel().getLogs().get(0).getException().getException(), ex); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.FAIL); + Assert.assertEquals(test.getModel().getLogs().get(0).getMedia().getPath(), ATTACHMENT); + } + + @Test + public void failMarkup() throws IOException { + Markup m = MarkupHelper.createCodeBlock("code"); + ExtentTest test = test().fail(m); + Assert.assertEquals(test.getModel().getStatus(), Status.FAIL); + Assert.assertTrue(test.getModel().getLogs().get(0).getDetails().contains("code")); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.FAIL); + } + + @Test + public void skipDetails() { + ExtentTest test = test().skip(DETAILS); + Assert.assertEquals(test.getModel().getLogs().get(0).getDetails(), DETAILS); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.SKIP); + } + + @Test + public void skipMedia() throws IOException { + ExtentTest test = test().skip( + MediaEntityBuilder.createScreenCaptureFromPath(ATTACHMENT).build()); + test.log(Status.FAIL, DETAILS, MediaEntityBuilder.createScreenCaptureFromPath(ATTACHMENT).build()); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.SKIP); + Assert.assertEquals(test.getModel().getLogs().get(0).getMedia().getPath(), ATTACHMENT); + } + + @Test + public void skipThrowable() { + Exception ex = ex(); + ExtentTest test = test().skip(ex); + Assert.assertEquals(test.getModel().getLogs().get(0).getException().getException(), ex); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.SKIP); + } + + @Test + public void skipThrowableMedia() throws IOException { + Exception ex = ex(); + ExtentTest test = test().skip(ex, + MediaEntityBuilder.createScreenCaptureFromPath(ATTACHMENT).build()); + Assert.assertEquals(test.getModel().getLogs().get(0).getException().getException(), ex); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.SKIP); + Assert.assertEquals(test.getModel().getLogs().get(0).getMedia().getPath(), ATTACHMENT); + } + + @Test + public void skipMarkup() throws IOException { + Markup m = MarkupHelper.createCodeBlock("code"); + ExtentTest test = test().log(Status.SKIP, m); + Assert.assertEquals(test.getModel().getStatus(), Status.SKIP); + Assert.assertTrue(test.getModel().getLogs().get(0).getDetails().contains("code")); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.SKIP); + } + + @Test + public void warnDetails() { + ExtentTest test = test().warning(DETAILS); + Assert.assertEquals(test.getModel().getLogs().get(0).getDetails(), DETAILS); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.WARNING); + } + + @Test + public void warnMedia() throws IOException { + ExtentTest test = test().warning( + MediaEntityBuilder.createScreenCaptureFromPath(ATTACHMENT).build()); + test.log(Status.WARNING, DETAILS, MediaEntityBuilder.createScreenCaptureFromPath(ATTACHMENT).build()); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.WARNING); + Assert.assertEquals(test.getModel().getLogs().get(0).getMedia().getPath(), ATTACHMENT); + } + + @Test + public void warnThrowable() { + Exception ex = ex(); + ExtentTest test = test().warning(ex); + Assert.assertEquals(test.getModel().getLogs().get(0).getException().getException(), ex); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.WARNING); + } + + @Test + public void warnThrowableMedia() throws IOException { + Exception ex = ex(); + ExtentTest test = test().log(Status.WARNING, ex, + MediaEntityBuilder.createScreenCaptureFromPath(ATTACHMENT).build()); + Assert.assertEquals(test.getModel().getLogs().get(0).getException().getException(), ex); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.WARNING); + Assert.assertEquals(test.getModel().getLogs().get(0).getMedia().getPath(), ATTACHMENT); + } + + @Test + public void warnMarkup() throws IOException { + Markup m = MarkupHelper.createCodeBlock("code"); + ExtentTest test = test().log(Status.WARNING, m); + Assert.assertEquals(test.getModel().getStatus(), Status.WARNING); + Assert.assertTrue(test.getModel().getLogs().get(0).getDetails().contains("code")); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.WARNING); + } + + @Test + public void passDetails() { + ExtentTest test = test().pass(DETAILS); + Assert.assertEquals(test.getModel().getLogs().get(0).getDetails(), DETAILS); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.PASS); + } + + @Test + public void passMedia() throws IOException { + ExtentTest test = test().pass( + MediaEntityBuilder.createScreenCaptureFromPath(ATTACHMENT).build()); + test.log(Status.PASS, DETAILS, MediaEntityBuilder.createScreenCaptureFromPath(ATTACHMENT).build()); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.PASS); + Assert.assertEquals(test.getModel().getLogs().get(0).getMedia().getPath(), ATTACHMENT); + } + + @Test + public void passThrowable() { + Exception ex = ex(); + ExtentTest test = test().pass(ex); + Assert.assertEquals(test.getModel().getLogs().get(0).getException().getException(), ex); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.PASS); + } + + @Test + public void passThrowableMedia() throws IOException { + Exception ex = ex(); + ExtentTest test = test().pass(ex, + MediaEntityBuilder.createScreenCaptureFromPath(ATTACHMENT).build()); + Assert.assertEquals(test.getModel().getLogs().get(0).getException().getException(), ex); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.PASS); + Assert.assertEquals(test.getModel().getLogs().get(0).getMedia().getPath(), ATTACHMENT); + } + + @Test + public void passMarkup() throws IOException { + Markup m = MarkupHelper.createCodeBlock("code"); + ExtentTest test = test().log(Status.PASS, m); + Assert.assertEquals(test.getModel().getStatus(), Status.PASS); + Assert.assertTrue(test.getModel().getLogs().get(0).getDetails().contains("code")); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.PASS); + } + + @Test + public void infoDetails() { + ExtentTest test = test().info(DETAILS); + Assert.assertEquals(test.getModel().getLogs().get(0).getDetails(), DETAILS); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.INFO); + } + + @Test + public void infoMedia() throws IOException { + ExtentTest test = test().info( + MediaEntityBuilder.createScreenCaptureFromPath(ATTACHMENT).build()); + test.log(Status.INFO, DETAILS, MediaEntityBuilder.createScreenCaptureFromPath(ATTACHMENT).build()); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.INFO); + Assert.assertEquals(test.getModel().getLogs().get(0).getMedia().getPath(), ATTACHMENT); + } + + @Test + public void infoThrowable() { + Exception ex = ex(); + ExtentTest test = test().info(ex); + Assert.assertEquals(test.getModel().getLogs().get(0).getException().getException(), ex); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.INFO); + } + + @Test + public void infoThrowableMedia() throws IOException { + Exception ex = ex(); + ExtentTest test = test().info(ex, + MediaEntityBuilder.createScreenCaptureFromPath(ATTACHMENT).build()); + Assert.assertEquals(test.getModel().getLogs().get(0).getException().getException(), ex); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.INFO); + Assert.assertEquals(test.getModel().getLogs().get(0).getMedia().getPath(), ATTACHMENT); + } + + @Test + public void infoMarkup() throws IOException { + Markup m = MarkupHelper.createCodeBlock("code"); + ExtentTest test = test().log(Status.INFO, m); + Assert.assertEquals(test.getModel().getStatus(), Status.PASS); + Assert.assertTrue(test.getModel().getLogs().get(0).getDetails().contains("code")); + Assert.assertEquals(test.getModel().getLogs().get(0).getStatus(), Status.INFO); + } +} diff --git a/src/test/java/com/aventstack/extentreports/ExtentTestMediaTest.java b/src/test/java/com/aventstack/extentreports/ExtentTestMediaTest.java new file mode 100644 index 0000000..3d15515 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/ExtentTestMediaTest.java @@ -0,0 +1,192 @@ +package com.aventstack.extentreports; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.aventstack.extentreports.model.ScreenCapture; + +public class ExtentTestMediaTest { + private static final String BASE64_ENCODED = "data:image/png;base64,"; + private static final String BASE64 = "iVBORw0KGgoAAAANSUhEUgAAAY4AAABbCAYAAABkgGJUAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAABIMSURBVHhe7Z3" + + + "daxRXH8effyZ3gVwIXgiFemXwookXkUIINFQQGrx4clV9LpILadCLEOzjWm0U00ZMQ7SQUEuKbSw1BoKkEdnqI1tss3lZ1rh1a9JsTMLvOWfmnJmzu/NyzuyLO/H7gUObcWfmzMzu7zPn/V8EAAAA" + + + "GABxAAAAMALiAAAAYATEAQAAwAiIAwAAgBEQBwAAACMgDgAAAEZAHAAAAIyAOAAAABgBcQAAADAC4gAAAGAExAEAAMAIiAMAAIAREAcAAAAjIA4AAABGQBwAAACMgDgAAAAYAXEAAAAwAuIAAABgB"; + private static final String PATH = "src/test/resources/img.png"; + private static final String TITLE = "MediaTitle"; + + private ExtentReports extent() { + return new ExtentReports(); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void addScreenCaptureFromEmptyPathTest() { + extent().createTest("Test") + .addScreenCaptureFromPath(""); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void addScreenCaptureFromNullPathTest() { + extent().createTest("Test") + .addScreenCaptureFromPath(null); + } + + @Test + public void addScreenCaptureFromPathTest() { + ExtentTest test = extent().createTest("Test") + .addScreenCaptureFromPath(PATH, TITLE) + .pass("Pass"); + Assert.assertEquals(test.getModel().getMedia().size(), 1); + Assert.assertEquals(test.getModel().getMedia().get(0).getPath(), PATH); + Assert.assertEquals(test.getModel().getMedia().get(0).getTitle(), TITLE); + } + + @Test + public void addScreenCaptureFromPathTestOverloads() { + ExtentTest test = extent().createTest("Test") + .addScreenCaptureFromPath(PATH) + .pass("Pass"); + Assert.assertEquals(test.getModel().getMedia().size(), 1); + Assert.assertEquals(test.getModel().getMedia().get(0).getPath(), PATH); + } + + @Test + public void addScreenCaptureFromPathNode() { + ExtentTest test = extent().createTest("Test"); + ExtentTest node = test + .createNode("Node") + .addScreenCaptureFromPath(PATH, TITLE) + .pass("Pass"); + Assert.assertEquals(test.getModel().getMedia().size(), 0); + Assert.assertEquals(node.getModel().getMedia().size(), 1); + Assert.assertEquals(node.getModel().getMedia().get(0).getPath(), PATH); + Assert.assertEquals(node.getModel().getMedia().get(0).getTitle(), TITLE); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void addScreenCaptureEmptyPathTestLog() { + extent().createTest("Test") + .pass("Pass", MediaEntityBuilder.createScreenCaptureFromPath("").build()); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void addScreenCaptureNullPathTestLog() { + extent().createTest("Test") + .pass("Pass", MediaEntityBuilder.createScreenCaptureFromPath(null).build()); + } + + @Test + public void addScreenCaptureFromPathTestLog() { + ExtentTest test = extent().createTest("Test") + .pass("Pass", MediaEntityBuilder.createScreenCaptureFromPath(PATH, TITLE).build()); + Assert.assertEquals(test.getModel().getMedia().size(), 0); + Assert.assertNotNull(test.getModel().getLogs().get(0).getMedia()); + Assert.assertEquals(test.getModel().getLogs().get(0).getMedia().getPath(), PATH); + Assert.assertEquals(test.getModel().getLogs().get(0).getMedia().getTitle(), TITLE); + } + + @Test + public void addScreenCaptureFromPathTestLogOverloads() { + ExtentTest test = extent().createTest("Test") + .pass("Pass", MediaEntityBuilder.createScreenCaptureFromPath(PATH).build()); + Assert.assertEquals(test.getModel().getMedia().size(), 0); + Assert.assertNotNull(test.getModel().getLogs().get(0).getMedia()); + Assert.assertEquals(test.getModel().getLogs().get(0).getMedia().getPath(), PATH); + } + + @Test + public void addScreenCaptureFromPathNodeLog() { + ExtentTest test = extent().createTest("Test"); + ExtentTest node = test + .createNode("Node") + .pass("Pass", MediaEntityBuilder.createScreenCaptureFromPath(PATH, TITLE).build()); + Assert.assertEquals(node.getModel().getMedia().size(), 0); + Assert.assertNotNull(node.getModel().getLogs().get(0).getMedia()); + Assert.assertEquals(node.getModel().getLogs().get(0).getMedia().getPath(), PATH); + Assert.assertEquals(node.getModel().getLogs().get(0).getMedia().getTitle(), TITLE); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void addScreenCaptureFromEmptyBase64Test() { + extent().createTest("Test") + .addScreenCaptureFromBase64String(""); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void addScreenCaptureFromNullBase64Test() { + extent().createTest("Test") + .addScreenCaptureFromBase64String(null); + } + + @Test + public void addScreenCaptureFromBase64Test() { + ExtentReports extent = new ExtentReports(); + ExtentTest test = extent.createTest("Test") + .addScreenCaptureFromBase64String(BASE64, TITLE) + .pass("Pass"); + Assert.assertEquals(test.getModel().getMedia().size(), 1); + Assert.assertEquals(((ScreenCapture) test.getModel().getMedia().get(0)).getBase64(), BASE64_ENCODED + BASE64); + Assert.assertEquals(test.getModel().getMedia().get(0).getTitle(), TITLE); + } + + @Test + public void addScreenCaptureFromBase64Node() { + ExtentTest test = extent().createTest("Test"); + ExtentTest node = test + .createNode("Node") + .addScreenCaptureFromBase64String(BASE64, TITLE) + .pass("Pass"); + Assert.assertEquals(test.getModel().getMedia().size(), 0); + Assert.assertEquals(node.getModel().getMedia().size(), 1); + Assert.assertEquals(((ScreenCapture) node.getModel().getMedia().get(0)).getBase64(), BASE64_ENCODED + BASE64); + Assert.assertEquals(node.getModel().getMedia().get(0).getTitle(), TITLE); + } + + @Test + public void addScreenCaptureFromBase64NodeOverloads() { + ExtentTest test = extent().createTest("Test"); + ExtentTest node = test + .createNode("Node") + .addScreenCaptureFromBase64String(BASE64) + .pass("Pass"); + Assert.assertEquals(test.getModel().getMedia().size(), 0); + Assert.assertEquals(node.getModel().getMedia().size(), 1); + Assert.assertEquals(((ScreenCapture) node.getModel().getMedia().get(0)).getBase64(), BASE64_ENCODED + BASE64); + } + + @Test + public void addScreenCaptureFromBase64TestLog() { + ExtentTest test = extent().createTest("Test") + .pass("Pass", MediaEntityBuilder.createScreenCaptureFromBase64String(BASE64, TITLE).build()); + Assert.assertEquals(test.getModel().getMedia().size(), 0); + Assert.assertNotNull(test.getModel().getLogs().get(0).getMedia()); + Assert.assertEquals(((ScreenCapture) test.getModel().getLogs().get(0).getMedia()).getBase64(), + BASE64_ENCODED + BASE64); + Assert.assertEquals(test.getModel().getLogs().get(0).getMedia().getTitle(), TITLE); + } + + @Test + public void addScreenCaptureFromBase64NodeLog() { + ExtentTest test = extent().createTest("Test"); + ExtentTest node = test + .createNode("Node") + .pass("Pass", MediaEntityBuilder.createScreenCaptureFromBase64String(BASE64, TITLE).build()); + Assert.assertEquals(node.getModel().getMedia().size(), 0); + Assert.assertNotNull(node.getModel().getLogs().get(0).getMedia()); + Assert.assertEquals(((ScreenCapture) node.getModel().getLogs().get(0).getMedia()).getBase64(), + BASE64_ENCODED + BASE64); + Assert.assertEquals(node.getModel().getLogs().get(0).getMedia().getTitle(), TITLE); + } + + @Test + public void addScreenCaptureFromBase64NodeLogOverloads() { + ExtentTest test = extent().createTest("Test"); + ExtentTest node = test + .createNode("Node") + .pass("Pass", MediaEntityBuilder.createScreenCaptureFromBase64String(BASE64).build()); + Assert.assertEquals(node.getModel().getMedia().size(), 0); + Assert.assertNotNull(node.getModel().getLogs().get(0).getMedia()); + Assert.assertEquals(((ScreenCapture) node.getModel().getLogs().get(0).getMedia()).getBase64(), + BASE64_ENCODED + BASE64); + } +} diff --git a/src/test/java/com/aventstack/extentreports/ExtentTestNodeTest.java b/src/test/java/com/aventstack/extentreports/ExtentTestNodeTest.java new file mode 100644 index 0000000..ea328f1 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/ExtentTestNodeTest.java @@ -0,0 +1,126 @@ +package com.aventstack.extentreports; + +import java.io.UnsupportedEncodingException; + +import org.testng.Assert; + +import com.aventstack.extentreports.gherkin.GherkinDialectManager; +import com.aventstack.extentreports.gherkin.model.Feature; +import com.aventstack.extentreports.gherkin.model.Scenario; +import com.aventstack.extentreports.model.Test; + +public class ExtentTestNodeTest { + private static final String TEST_NAME = "TEST"; + + private ExtentReports extent() { + try { + GherkinDialectManager.setLanguage(GherkinDialectManager.getDefaultLanguage()); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return new ExtentReports(); + } + + @org.testng.annotations.Test + public void createNodeOverloadTypeNameDesc() { + ExtentTest test = extent().createTest(Feature.class, TEST_NAME, "Description"); + ExtentTest node = test.createNode(Scenario.class, TEST_NAME, "Description"); + Test model = test.getModel(); + Assert.assertTrue(model.isBDD()); + Assert.assertEquals(model.getName(), TEST_NAME); + Assert.assertEquals(model.getDescription(), "Description"); + Assert.assertEquals(model.getBddType(), Feature.class); + Assert.assertFalse(model.isLeaf()); + + model = node.getModel(); + Assert.assertTrue(model.isBDD()); + Assert.assertEquals(model.getName(), TEST_NAME); + Assert.assertEquals(model.getDescription(), "Description"); + Assert.assertEquals(model.getBddType(), Scenario.class); + Assert.assertTrue(model.isLeaf()); + Assert.assertEquals(model.getLevel().intValue(), 1); + } + + @org.testng.annotations.Test + public void createNodeOverloadTypeName() { + ExtentTest node = extent().createTest(Feature.class, TEST_NAME) + .createNode(Scenario.class, TEST_NAME); + Test model = node.getModel(); + Assert.assertTrue(model.isBDD()); + Assert.assertEquals(model.getName(), TEST_NAME); + Assert.assertNull(model.getDescription()); + Assert.assertEquals(model.getBddType(), Scenario.class); + Assert.assertTrue(model.isLeaf()); + } + + @org.testng.annotations.Test + public void createNodeOverloadKeywordNameDesc() throws ClassNotFoundException { + ExtentTest test = extent().createTest(new GherkinKeyword("Feature"), TEST_NAME, "Description"); + ExtentTest node = test.createNode(new GherkinKeyword("Scenario"), TEST_NAME, "Description"); + Test model = test.getModel(); + Assert.assertTrue(model.isBDD()); + Assert.assertEquals(model.getName(), TEST_NAME); + Assert.assertEquals(model.getDescription(), "Description"); + Assert.assertEquals(model.getBddType(), Feature.class); + Assert.assertFalse(model.isLeaf()); + + model = node.getModel(); + Assert.assertTrue(model.isBDD()); + Assert.assertEquals(model.getName(), TEST_NAME); + Assert.assertEquals(model.getDescription(), "Description"); + Assert.assertEquals(model.getBddType(), Scenario.class); + Assert.assertTrue(model.isLeaf()); + Assert.assertEquals(model.getLevel().intValue(), 1); + } + + @org.testng.annotations.Test + public void createNodeOverloadKeywordName() throws ClassNotFoundException { + ExtentTest test = extent().createTest(new GherkinKeyword("Feature"), TEST_NAME); + ExtentTest node = test.createNode(new GherkinKeyword("Scenario"), TEST_NAME); + Test model = node.getModel(); + Assert.assertTrue(model.isBDD()); + Assert.assertEquals(model.getName(), TEST_NAME); + Assert.assertNull(model.getDescription()); + Assert.assertEquals(model.getBddType(), Scenario.class); + Assert.assertTrue(model.isLeaf()); + } + + @org.testng.annotations.Test + public void createNodeOverloadNameDesc() throws ClassNotFoundException { + ExtentTest test = extent().createTest(TEST_NAME, "Description"); + ExtentTest node = test.createNode(TEST_NAME, "Description"); + Test model = test.getModel(); + Assert.assertFalse(model.isBDD()); + Assert.assertEquals(model.getName(), TEST_NAME); + Assert.assertEquals(model.getDescription(), "Description"); + Assert.assertFalse(model.isLeaf()); + + model = node.getModel(); + Assert.assertFalse(model.isBDD()); + Assert.assertEquals(model.getName(), TEST_NAME); + Assert.assertEquals(model.getDescription(), "Description"); + Assert.assertTrue(model.isLeaf()); + Assert.assertEquals(model.getLevel().intValue(), 1); + } + + @org.testng.annotations.Test + public void createNodeOverloadName() throws ClassNotFoundException { + ExtentTest test = extent().createTest(TEST_NAME); + ExtentTest node = test.createNode(TEST_NAME); + Test model = node.getModel(); + Assert.assertFalse(model.isBDD()); + Assert.assertEquals(model.getName(), TEST_NAME); + Assert.assertNull(model.getDescription()); + Assert.assertTrue(model.isLeaf()); + } + + @org.testng.annotations.Test + public void timeCalcNodes() throws ClassNotFoundException, InterruptedException { + ExtentTest test = extent().createTest(TEST_NAME); + ExtentTest node = test.createNode(TEST_NAME).pass("init"); + Thread.sleep(100); + node.pass("complete"); + Assert.assertTrue(test.getModel().timeTaken() >= 100); + Assert.assertTrue(node.getModel().timeTaken() >= 100); + } +} diff --git a/src/test/java/com/aventstack/extentreports/NaturalConfTest.java b/src/test/java/com/aventstack/extentreports/NaturalConfTest.java new file mode 100644 index 0000000..4b3574b --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/NaturalConfTest.java @@ -0,0 +1,65 @@ +package com.aventstack.extentreports; + +import java.util.Calendar; +import java.util.Date; + +import org.testng.Assert; +import org.testng.annotations.Test; + +public class NaturalConfTest { + @Test + public void useNaturalConfReport() throws InterruptedException { + ExtentReports extent = new ExtentReports(); + extent.setReportUsesManualConfiguration(true); + ExtentTest test = extent.createTest("Test").pass("init"); + Thread.sleep(500); + test.pass("complete"); + // must flush to determine time for report + extent.flush(); + Assert.assertTrue(extent.getReport().timeTaken() < 5); + } + + @Test + public void useNaturalConfReportWithTimeChanged() throws InterruptedException { + ExtentReports extent = new ExtentReports(); + extent.setReportUsesManualConfiguration(true); + ExtentTest test = extent.createTest("Test").pass("init"); + test.getModel().setEndTime(new Date(Calendar.getInstance().getTime().getTime() + 5000)); + test.pass("complete"); + // must flush to determine time for report + extent.flush(); + Assert.assertTrue(extent.getReport().timeTaken() >= 5000); + } + + @Test + public void useNaturalConfTest() throws InterruptedException { + ExtentReports extent = new ExtentReports(); + extent.setReportUsesManualConfiguration(true); + ExtentTest test = extent.createTest("Test").pass("init"); + Thread.sleep(500); + test.pass("complete"); + Assert.assertTrue(test.getModel().timeTaken() < 5); + } + + @Test + public void useNaturalConfTestWithTimeChanged() throws InterruptedException { + ExtentReports extent = new ExtentReports(); + extent.setReportUsesManualConfiguration(true); + ExtentTest test = extent.createTest("Test").pass("init"); + test.getModel().setEndTime(new Date(Calendar.getInstance().getTime().getTime() + 5000)); + test.pass("complete"); + Assert.assertTrue(test.getModel().timeTaken() >= 5000); + } + + @Test + public void useNaturalConfTestWithNodes() throws InterruptedException { + ExtentReports extent = new ExtentReports(); + extent.setReportUsesManualConfiguration(true); + ExtentTest test = extent.createTest("Test"); + ExtentTest child = test.createNode("Node").pass("init"); + Thread.sleep(500); + child.pass("complete"); + Assert.assertTrue(test.getModel().timeTaken() < 5); + Assert.assertTrue(child.getModel().timeTaken() < 5); + } +} diff --git a/src/test/java/com/aventstack/extentreports/ObserverTest.java b/src/test/java/com/aventstack/extentreports/ObserverTest.java new file mode 100644 index 0000000..87dd1d6 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/ObserverTest.java @@ -0,0 +1,5 @@ +package com.aventstack.extentreports; + +public class ObserverTest { + +} diff --git a/src/test/java/com/aventstack/extentreports/ParallelClass1.java b/src/test/java/com/aventstack/extentreports/ParallelClass1.java deleted file mode 100644 index 74d6261..0000000 --- a/src/test/java/com/aventstack/extentreports/ParallelClass1.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.aventstack.extentreports; - -import java.lang.reflect.Method; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Status; -import com.aventstack.extentreports.common.ExtentTestManager; - -public class ParallelClass1 extends ParallelClassesBase { - - @Test - public void parallelClass1TestResultMustEqualPass(Method method) { - ExtentTestManager.createTest(method.getName()).info("Log from threadId: " + Thread.currentThread().getId()); - ExtentTestManager.getTest().pass("Log from threadId: " + Thread.currentThread().getId()); - - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.PASS); - } - - @Test - public void parallelClass1TestResultMustEqualFail(Method method) { - ExtentTestManager.createTest(method.getName()).error("Log from threadId: " + Thread.currentThread().getId()); - ExtentTestManager.getTest().fail("Log from threadId: " + Thread.currentThread().getId()); - - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.FAIL); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/ParallelClass2.java b/src/test/java/com/aventstack/extentreports/ParallelClass2.java deleted file mode 100644 index 52a31ff..0000000 --- a/src/test/java/com/aventstack/extentreports/ParallelClass2.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.aventstack.extentreports; - -import java.lang.reflect.Method; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Status; -import com.aventstack.extentreports.common.ExtentManager; -import com.aventstack.extentreports.common.ExtentTestManager; - -public class ParallelClass2 extends ParallelClassesBase { - - @Test - public void parallelClass1TestResultMustEqualWarning(Method method) { - ExtentTestManager.createTest(method.getName()).info("Log from threadId: " + Thread.currentThread().getId()); - ExtentTestManager.getTest().warning("Log from threadId: " + Thread.currentThread().getId()); - ExtentManager.getInstance().flush(); - - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.WARNING); - } - - @Test - public void parallelClass1TestResultMustEqualSkip(Method method) { - ExtentTestManager.createTest(method.getName()).skip("Log from threadId: " + Thread.currentThread().getId()); - ExtentTestManager.getTest().pass("Log from threadId: " + Thread.currentThread().getId()); - ExtentManager.getInstance().flush(); - - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.SKIP); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/ParallelClass3.java b/src/test/java/com/aventstack/extentreports/ParallelClass3.java deleted file mode 100644 index 9b13b0d..0000000 --- a/src/test/java/com/aventstack/extentreports/ParallelClass3.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.aventstack.extentreports; - -import java.lang.reflect.Method; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Status; -import com.aventstack.extentreports.common.ExtentManager; -import com.aventstack.extentreports.common.ExtentTestManager; - -public class ParallelClass3 extends ParallelClassesBase { - - @Test - public void parallelClass1TestResultMustEqualWarning(Method method) { - ExtentTestManager.createTest(method.getName()).info("Log from threadId: " + Thread.currentThread().getId()); - ExtentTestManager.getTest().warning("Log from threadId: " + Thread.currentThread().getId()); - ExtentManager.getInstance().flush(); - - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.WARNING); - } - - @Test - public void parallelClass1TestResultMustEqualSkip(Method method) { - ExtentTestManager.createTest(method.getName()).skip("Log from threadId: " + Thread.currentThread().getId()); - ExtentTestManager.getTest().pass("Log from threadId: " + Thread.currentThread().getId()); - ExtentManager.getInstance().flush(); - - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.SKIP); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/ParallelClass4.java b/src/test/java/com/aventstack/extentreports/ParallelClass4.java deleted file mode 100644 index 7692d9e..0000000 --- a/src/test/java/com/aventstack/extentreports/ParallelClass4.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.aventstack.extentreports; - -import java.lang.reflect.Method; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Status; -import com.aventstack.extentreports.common.ExtentManager; -import com.aventstack.extentreports.common.ExtentTestManager; - -public class ParallelClass4 extends ParallelClassesBase { - - @Test - public void parallelClass1TestResultMustEqualWarning(Method method) { - ExtentTestManager.createTest(method.getName()).info("Log from threadId: " + Thread.currentThread().getId()); - ExtentTestManager.getTest().warning("Log from threadId: " + Thread.currentThread().getId()); - ExtentManager.getInstance().flush(); - - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.WARNING); - } - - @Test - public void parallelClass1TestResultMustEqualSkip(Method method) { - ExtentTestManager.createTest(method.getName()).skip("Log from threadId: " + Thread.currentThread().getId()); - ExtentTestManager.getTest().pass("Log from threadId: " + Thread.currentThread().getId()); - ExtentManager.getInstance().flush(); - - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.SKIP); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/ParallelClassesBase.java b/src/test/java/com/aventstack/extentreports/ParallelClassesBase.java deleted file mode 100644 index 494dd9a..0000000 --- a/src/test/java/com/aventstack/extentreports/ParallelClassesBase.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.aventstack.extentreports; - -import org.testng.annotations.AfterSuite; -import org.testng.annotations.BeforeSuite; - -import com.aventstack.extentreports.common.ExtentManager; -import com.aventstack.extentreports.common.ExtentTestManager; - -public abstract class ParallelClassesBase extends Base { - - final String fileName = getOutputFolder() + getClass().getPackage().getName() + ".ParallelClasses.html"; - - @BeforeSuite - public void setup() { - ExtentManager.createInstance(); - ExtentTestManager.setReporter(ExtentManager.getInstance()); - } - - @AfterSuite - public void tearDown() { - ExtentManager.getInstance().flush(); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/ParallelMethods.java b/src/test/java/com/aventstack/extentreports/ParallelMethods.java deleted file mode 100644 index 4726506..0000000 --- a/src/test/java/com/aventstack/extentreports/ParallelMethods.java +++ /dev/null @@ -1,345 +0,0 @@ -package com.aventstack.extentreports; - -import java.lang.reflect.Method; - -import org.testng.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Status; -import com.aventstack.extentreports.common.ExtentManager; -import com.aventstack.extentreports.common.ExtentTestManager; - -public class ParallelMethods { - - @BeforeClass - public void beforeClass() { - ExtentManager.createInstance(); - ExtentTestManager.setReporter(ExtentManager.getInstance()); - } - - @AfterClass - public void afterClass() { - ExtentTestManager.getReporter().flush(); - } - - @Test - public void method1(Method method) { - ExtentTestManager.createTest(method.getName()).createNode(method.getName()).pass("pass"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.PASS); - } - - @Test - public void method2(Method method) { - ExtentTestManager.createTest(method.getName()).createNode(method.getName()).fail("fail"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.FAIL); - } - - @Test - public void method3(Method method) { - ExtentTestManager.createTest(method.getName()).createNode(method.getName()).error("error"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.ERROR); - } - - @Test - public void method4(Method method) { - ExtentTestManager.createTest(method.getName()).createNode(method.getName()).warning("warning"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.WARNING); - } - - @Test - public void method5(Method method) { - ExtentTestManager.createTest(method.getName()).createNode(method.getName()).info("info"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.PASS); - } - - @Test - public void method6(Method method) { - ExtentTestManager.createTest(method.getName()).createNode(method.getName()).fatal("fatal"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.FATAL); - } - - @Test - public void method7(Method method) { - ExtentTestManager.createTest(method.getName()).createNode(method.getName()).pass(""); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.PASS); - } - - @Test - public void method17(Method method) { - ExtentTestManager.createTest(method.getName()).pass("pass"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.PASS); - } - - @Test - public void method27(Method method) { - ExtentTestManager.createTest(method.getName()).createNode(method.getName()).fail("fail"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.FAIL); - } - - @Test - public void method37(Method method) { - ExtentTestManager.createTest(method.getName()).createNode(method.getName()).error("error"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.ERROR); - } - - @Test - public void method47(Method method) { - ExtentTestManager.createTest(method.getName()).createNode(method.getName()).warning("warning"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.WARNING); - } - - @Test - public void method57(Method method) { - ExtentTestManager.createTest(method.getName()).info("info"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.PASS); - } - - @Test - public void method67(Method method) { - ExtentTestManager.createTest(method.getName()).fatal("fatal"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.FATAL); - } - - @Test - public void method77(Method method) { - ExtentTestManager.createTest(method.getName()); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.PASS); - } - - @Test - public void method1x(Method method) { - ExtentTestManager.createTest(method.getName()).createNode(method.getName()).pass("pass"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.PASS); - } - - @Test - public void method2x(Method method) { - ExtentTestManager.createTest(method.getName()).createNode(method.getName()).fail("fail"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.FAIL); - } - - @Test - public void method3x(Method method) { - ExtentTestManager.createTest(method.getName()).error("error"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.ERROR); - } - - @Test - public void method4x(Method method) { - ExtentTestManager.createTest(method.getName()).warning("warning"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.WARNING); - } - - @Test - public void method5x(Method method) { - ExtentTestManager.createTest(method.getName()).createNode(method.getName()).info("info"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.PASS); - } - - @Test - public void method6x(Method method) { - ExtentTestManager.createTest(method.getName()).fatal("fatal"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.FATAL); - } - - @Test - public void method7x(Method method) { - ExtentTestManager.createTest(method.getName()); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.PASS); - } - - @Test - public void method17y(Method method) { - ExtentTestManager.createTest(method.getName()).createNode(method.getName()).pass("pass"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.PASS); - } - - @Test - public void method27y(Method method) { - ExtentTestManager.createTest(method.getName()).fail("fail"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.FAIL); - } - - @Test - public void method37y(Method method) { - ExtentTestManager.createTest(method.getName()).createNode(method.getName()).error("error"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.ERROR); - } - - @Test - public void method47y(Method method) { - ExtentTestManager.createTest(method.getName()).warning("warning"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.WARNING); - } - - @Test - public void method57y(Method method) { - ExtentTestManager.createTest(method.getName()).info("info"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.PASS); - } - - @Test - public void method67y(Method method) { - ExtentTestManager.createTest(method.getName()).fatal("fatal"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.FATAL); - } - - @Test - public void method77y(Method method) { - ExtentTestManager.createTest(method.getName()); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.PASS); - } - - @Test - public void method1v(Method method) { - ExtentTestManager.createTest(method.getName()).createNode(method.getName()).pass("pass"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.PASS); - } - - @Test - public void method2v(Method method) { - ExtentTestManager.createTest(method.getName()).createNode(method.getName()).fail("fail"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.FAIL); - } - - @Test - public void method3v(Method method) { - ExtentTestManager.createTest(method.getName()).error("error"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.ERROR); - } - - @Test - public void method4v(Method method) { - ExtentTestManager.createTest(method.getName()).warning("warning"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.WARNING); - } - - @Test - public void method5v(Method method) { - ExtentTestManager.createTest(method.getName()).info("info"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.PASS); - } - - @Test - public void method6v(Method method) { - ExtentTestManager.createTest(method.getName()).fatal("fatal"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.FATAL); - } - - @Test - public void method7v(Method method) { - ExtentTestManager.createTest(method.getName()); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.PASS); - } - - @Test - public void method17b(Method method) { - ExtentTestManager.createTest(method.getName()).pass("pass"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.PASS); - } - - @Test - public void method27b(Method method) { - ExtentTestManager.createTest(method.getName()).fail("fail"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.FAIL); - } - - @Test - public void method37b(Method method) { - ExtentTestManager.createTest(method.getName()).createNode(method.getName()).error("error"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.ERROR); - } - - @Test - public void method47b(Method method) { - ExtentTestManager.createTest(method.getName()).createNode(method.getName()).warning("warning"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.WARNING); - } - - @Test - public void method57b(Method method) { - ExtentTestManager.createTest(method.getName()).createNode(method.getName()).info("info"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.PASS); - } - - @Test - public void method67b(Method method) { - ExtentTestManager.createTest(method.getName()).createNode(method.getName()).fatal("fatal"); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.FATAL); - } - - @Test - public void method77g(Method method) { - ExtentTestManager.createTest(method.getName()).pass("").createNode(method.getName()).info(""); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.PASS); - } - - @Test - public void method47g(Method method) { - ExtentTestManager.createTest(method.getName()).pass("").createNode(method.getName()).info(""); - ExtentTestManager.getReporter().flush(); - } - - @Test - public void method57g(Method method) { - ExtentTestManager.createTest(method.getName()).pass("").createNode(method.getName()).info(""); - ExtentTestManager.getReporter().flush(); - Assert.assertEquals(ExtentTestManager.getTest().getStatus(), Status.PASS); - } - - @Test - public void method67g(Method method) { - ExtentTestManager.createTest(method.getName()).pass("").createNode(method.getName()).info(""); - ExtentTestManager.getReporter().flush(); - } - - @Test - public void method77u(Method method) { - ExtentTestManager.createTest(method.getName()).pass("").createNode(method.getName()).info(""); - ExtentTestManager.getReporter().flush(); - } -} diff --git a/src/test/java/com/aventstack/extentreports/ParallelTest.java b/src/test/java/com/aventstack/extentreports/ParallelTest.java new file mode 100644 index 0000000..aa419e4 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/ParallelTest.java @@ -0,0 +1,29 @@ +package com.aventstack.extentreports; + +import java.util.stream.IntStream; + +import org.testng.annotations.Test; + +import com.aventstack.extentreports.reporter.ExtentSparkReporter; + +public class ParallelTest { + @Test + public void parallelTests() { + ExtentReports extent = new ExtentReports(); + IntStream.range(0, 10000).parallel().forEach(x -> extent.createTest("Test").info(String.valueOf(x))); + } + + @Test + public void parallelTestsWithReporter() { + ExtentReports extent = new ExtentReports(); + extent.attachReporter(new ExtentSparkReporter("")); + IntStream.range(0, 10000).parallel().forEach(x -> extent.createTest("Test").info(String.valueOf(x))); + } + + @Test + public void parallelLogs() { + ExtentReports extent = new ExtentReports(); + ExtentTest test = extent.createTest("Test"); + IntStream.range(0, 10000).parallel().forEach(x -> test.info(String.valueOf(x))); + } +} diff --git a/src/test/java/com/aventstack/extentreports/TestIdsTest.java b/src/test/java/com/aventstack/extentreports/TestIdsTest.java new file mode 100644 index 0000000..04cd137 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/TestIdsTest.java @@ -0,0 +1,23 @@ +package com.aventstack.extentreports; + +import java.lang.reflect.Method; +import java.util.HashSet; +import java.util.Set; +import java.util.stream.IntStream; + +import org.testng.Assert; +import org.testng.annotations.Test; + +public class TestIdsTest { + private final int ATTEMPTS = 100; + + @Test + public void verifyAllStartedTestsHaveUniqueIds(Method method) { + ExtentReports extent = new ExtentReports(); + Set set = new HashSet<>(); + // create [times] tests to ensure test-id is not duplicate + IntStream.range(0, ATTEMPTS) + .forEach(x -> set.add(extent.createTest("" + x).info("" + x).getModel().getId())); + Assert.assertEquals(set.size(), ATTEMPTS); + } +} diff --git a/src/test/java/com/aventstack/extentreports/api/BddLevelsTest.java b/src/test/java/com/aventstack/extentreports/api/BddLevelsTest.java deleted file mode 100644 index 6f99dd0..0000000 --- a/src/test/java/com/aventstack/extentreports/api/BddLevelsTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.aventstack.extentreports.api; - -import java.io.UnsupportedEncodingException; -import java.lang.reflect.Method; - -import com.aventstack.extentreports.gherkin.model.And; -import com.aventstack.extentreports.gherkin.model.But; -import com.aventstack.extentreports.gherkin.model.Given; -import com.aventstack.extentreports.gherkin.model.Scenario; -import com.aventstack.extentreports.gherkin.model.Then; -import com.aventstack.extentreports.gherkin.model.When; -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; -import com.aventstack.extentreports.ExtentTest; -import com.aventstack.extentreports.GherkinKeyword; - -public class BddLevelsTest extends Base { - - @Test - public void verifyLevelsUsingGherkinKeyword(Method method) throws ClassNotFoundException, UnsupportedEncodingException { - extent.setGherkinDialect("en"); - ExtentTest feature = extent.createTest(method.getName()); - ExtentTest scenario = feature.createNode(new GherkinKeyword("Scenario"), "Child"); - ExtentTest given = scenario.createNode(new GherkinKeyword("Given"), "Given").info("info"); - ExtentTest and = scenario.createNode(new GherkinKeyword("And"), "And").info("info"); - ExtentTest when = scenario.createNode(new GherkinKeyword("When"), "When").info("info"); - ExtentTest then = scenario.createNode(new GherkinKeyword("Then"), "Then").pass("pass"); - ExtentTest but = scenario.createNode(new GherkinKeyword("But"), "But").pass("pass"); - - Assert.assertEquals(feature.getModel().getLevel(), 0); - Assert.assertEquals(scenario.getModel().getLevel(), 1); - Assert.assertEquals(given.getModel().getLevel(), 2); - Assert.assertEquals(and.getModel().getLevel(), 2); - Assert.assertEquals(when.getModel().getLevel(), 2); - Assert.assertEquals(then.getModel().getLevel(), 2); - Assert.assertEquals(but.getModel().getLevel(), 2); - } - - @Test - public void verifyLevelsUsingClass(Method method) { - ExtentTest feature = extent.createTest(method.getName()); - ExtentTest scenario = feature.createNode(Scenario.class, "Child"); - ExtentTest given = scenario.createNode(Given.class, "Given").info("info"); - ExtentTest and = scenario.createNode(And.class, "And").info("info"); - ExtentTest when = scenario.createNode(When.class, "When").info("info"); - ExtentTest then = scenario.createNode(Then.class, "Then").pass("pass"); - ExtentTest but = scenario.createNode(But.class, "But").pass("pass"); - - Assert.assertEquals(feature.getModel().getLevel(), 0); - Assert.assertEquals(scenario.getModel().getLevel(), 1); - Assert.assertEquals(given.getModel().getLevel(), 2); - Assert.assertEquals(and.getModel().getLevel(), 2); - Assert.assertEquals(when.getModel().getLevel(), 2); - Assert.assertEquals(then.getModel().getLevel(), 2); - Assert.assertEquals(but.getModel().getLevel(), 2); - } -} diff --git a/src/test/java/com/aventstack/extentreports/api/BddWithStepStatusHierarchyTest.java b/src/test/java/com/aventstack/extentreports/api/BddWithStepStatusHierarchyTest.java deleted file mode 100644 index d42c327..0000000 --- a/src/test/java/com/aventstack/extentreports/api/BddWithStepStatusHierarchyTest.java +++ /dev/null @@ -1,295 +0,0 @@ -package com.aventstack.extentreports.api; - -import java.io.UnsupportedEncodingException; -import java.lang.reflect.Method; - -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; -import com.aventstack.extentreports.ExtentTest; -import com.aventstack.extentreports.GherkinKeyword; -import com.aventstack.extentreports.Status; -import com.aventstack.extentreports.gherkin.GherkinDialectProvider; -import com.aventstack.extentreports.gherkin.model.And; -import com.aventstack.extentreports.gherkin.model.But; -import com.aventstack.extentreports.gherkin.model.Given; -import com.aventstack.extentreports.gherkin.model.Scenario; -import com.aventstack.extentreports.gherkin.model.Then; -import com.aventstack.extentreports.gherkin.model.When; - -public class BddWithStepStatusHierarchyTest extends Base { - - @BeforeClass - public void beforeClass() throws UnsupportedEncodingException { - GherkinDialectProvider.setLanguage("en"); - } - - @Test(expectedExceptions = ClassNotFoundException.class) - public void throwClassNotFoundExceptionWithInvalidKeyword(Method method) throws ClassNotFoundException { - ExtentTest feature = extent.createTest(method.getName()); - feature.createNode(new GherkinKeyword("Invalid"), "Child"); - - Assert.assertEquals(feature.getStatus(), Status.PASS); - } - - @Test(expectedExceptions = ClassNotFoundException.class) - public void throwClassNotFoundExceptionWithEmptyKeyword(Method method) throws ClassNotFoundException { - ExtentTest feature = extent.createTest(method.getName()); - feature.createNode(new GherkinKeyword(""), "Child"); - - Assert.assertEquals(feature.getStatus(), Status.PASS); - } - - @Test - public void verifyValidKeywordFoundWithInvalidCaseFirstCharacter(Method method) throws ClassNotFoundException { - ExtentTest feature = extent.createTest(method.getName()); - feature.createNode(new GherkinKeyword("given"), "Child").pass("pass"); - - Assert.assertEquals(feature.getStatus(), Status.PASS); - } - - @Test - public void verifyValidKeywordFounWithInvalidCase(Method method) throws ClassNotFoundException { - ExtentTest feature = extent.createTest(method.getName()); - feature.createNode(new GherkinKeyword("giVen"), "Child").pass("pass"); - - Assert.assertEquals(feature.getStatus(), Status.PASS); - } - - @Test - public void verifyPassHasHigherPriorityThanInfoUsingGherkinKeyword(Method method) throws ClassNotFoundException { - ExtentTest feature = extent.createTest(method.getName()); - ExtentTest scenario = feature.createNode(new GherkinKeyword("Scenario"), "Child"); - ExtentTest given = scenario.createNode(new GherkinKeyword("Given"), "Given").info("info"); - ExtentTest and = scenario.createNode(new GherkinKeyword("And"), "And").info("info"); - ExtentTest but = scenario.createNode(new GherkinKeyword("But"), "But").info("info"); - ExtentTest when = scenario.createNode(new GherkinKeyword("When"), "When").info("info"); - ExtentTest then = scenario.createNode(new GherkinKeyword("Then"), "Then").pass("pass"); - - Assert.assertEquals(feature.getModel().getLevel(), 0); - Assert.assertEquals(scenario.getModel().getLevel(), 1); - Assert.assertEquals(given.getModel().getLevel(), 2); - Assert.assertEquals(and.getModel().getLevel(), 2); - Assert.assertEquals(but.getModel().getLevel(), 2); - Assert.assertEquals(when.getModel().getLevel(), 2); - Assert.assertEquals(then.getModel().getLevel(), 2); - Assert.assertEquals(given.getStatus(), Status.PASS); - Assert.assertEquals(and.getStatus(), Status.PASS); - Assert.assertEquals(but.getStatus(), Status.PASS); - Assert.assertEquals(when.getStatus(), Status.PASS); - Assert.assertEquals(then.getStatus(), Status.PASS); - Assert.assertEquals(scenario.getStatus(), Status.PASS); - Assert.assertEquals(feature.getStatus(), Status.PASS); - } - - @Test - public void verifyPassHasHigherPriorityThanInfoUsingClass(Method method) { - ExtentTest feature = extent.createTest(method.getName()); - ExtentTest scenario = feature.createNode(Scenario.class, "Scenario"); - ExtentTest given = scenario.createNode(Given.class, "Given").info("info"); - ExtentTest and = scenario.createNode(And.class, "And").info("info"); - ExtentTest when = scenario.createNode(When.class, "When").info("info"); - ExtentTest then = scenario.createNode(Then.class, "Then").pass("pass"); - ExtentTest but = scenario.createNode(But.class, "But").pass("pass"); - - Assert.assertEquals(given.getStatus(), Status.PASS); - Assert.assertEquals(and.getStatus(), Status.PASS); - Assert.assertEquals(when.getStatus(), Status.PASS); - Assert.assertEquals(then.getStatus(), Status.PASS); - Assert.assertEquals(but.getStatus(), Status.PASS); - Assert.assertEquals(scenario.getStatus(), Status.PASS); - Assert.assertEquals(feature.getStatus(), Status.PASS); - } - - @Test - public void verifySkipHasHigherPriorityThanPassUsingGherkinKeyword(Method method) throws ClassNotFoundException { - ExtentTest feature = extent.createTest(method.getName()); - ExtentTest scenario = feature.createNode(new GherkinKeyword("Scenario"), "Child"); - ExtentTest given = scenario.createNode(new GherkinKeyword("Given"), "Given").pass("pass"); - ExtentTest and = scenario.createNode(new GherkinKeyword("And"), "And").pass("pass"); - ExtentTest when = scenario.createNode(new GherkinKeyword("When"), "When").pass("pass"); - ExtentTest then = scenario.createNode(new GherkinKeyword("Then"), "Then").skip("skip"); - ExtentTest but = scenario.createNode(new GherkinKeyword("But"), "But").skip("skip"); - - Assert.assertEquals(given.getStatus(), Status.PASS); - Assert.assertEquals(and.getStatus(), Status.PASS); - Assert.assertEquals(when.getStatus(), Status.PASS); - Assert.assertEquals(then.getStatus(), Status.SKIP); - Assert.assertEquals(but.getStatus(), Status.SKIP); - Assert.assertEquals(scenario.getStatus(), Status.SKIP); - Assert.assertEquals(feature.getStatus(), Status.SKIP); - } - - @Test - public void verifySkipHasHigherPriorityThanPassUsingClass(Method method) { - ExtentTest feature = extent.createTest(method.getName()); - ExtentTest scenario = feature.createNode(Scenario.class, "Scenario"); - ExtentTest given = scenario.createNode(Given.class, "Given").pass("pass"); - ExtentTest and = scenario.createNode(And.class, "And").pass("pass"); - ExtentTest when = scenario.createNode(When.class, "When").pass("pass"); - ExtentTest then = scenario.createNode(Then.class, "Then").skip("skip"); - ExtentTest but = scenario.createNode(But.class, "But").skip("skip"); - - Assert.assertEquals(given.getStatus(), Status.PASS); - Assert.assertEquals(and.getStatus(), Status.PASS); - Assert.assertEquals(when.getStatus(), Status.PASS); - Assert.assertEquals(then.getStatus(), Status.SKIP); - Assert.assertEquals(but.getStatus(), Status.SKIP); - Assert.assertEquals(scenario.getStatus(), Status.SKIP); - Assert.assertEquals(feature.getStatus(), Status.SKIP); - } - - @Test - public void verifyWarningHasHigherPriorityThanSkipUsingGherkinKeyword(Method method) throws ClassNotFoundException { - ExtentTest feature = extent.createTest(method.getName()); - ExtentTest scenario = feature.createNode(new GherkinKeyword("Scenario"), "Child"); - ExtentTest given = scenario.createNode(new GherkinKeyword("Given"), "Given").skip("skip"); - ExtentTest and = scenario.createNode(new GherkinKeyword("And"), "And").skip("skip"); - ExtentTest when = scenario.createNode(new GherkinKeyword("When"), "When").skip("skip"); - ExtentTest then = scenario.createNode(new GherkinKeyword("Then"), "Then").warning("warning"); - ExtentTest but = scenario.createNode(new GherkinKeyword("But"), "But").warning("warning"); - - Assert.assertEquals(given.getStatus(), Status.SKIP); - Assert.assertEquals(and.getStatus(), Status.SKIP); - Assert.assertEquals(when.getStatus(), Status.SKIP); - Assert.assertEquals(then.getStatus(), Status.WARNING); - Assert.assertEquals(but.getStatus(), Status.WARNING); - Assert.assertEquals(scenario.getStatus(), Status.WARNING); - Assert.assertEquals(feature.getStatus(), Status.WARNING); - } - - @Test - public void verifyWarningHasHigherPriorityThanSkipUsingClass(Method method) { - ExtentTest feature = extent.createTest(method.getName()); - ExtentTest scenario = feature.createNode(Scenario.class, "Scenario"); - ExtentTest given = scenario.createNode(Given.class, "Given").skip("skip"); - ExtentTest and = scenario.createNode(And.class, "And").skip("skip"); - ExtentTest when = scenario.createNode(When.class, "When").skip("skip"); - ExtentTest then = scenario.createNode(Then.class, "Then").warning("warning"); - ExtentTest but = scenario.createNode(But.class, "But").warning("warning"); - - Assert.assertEquals(given.getStatus(), Status.SKIP); - Assert.assertEquals(and.getStatus(), Status.SKIP); - Assert.assertEquals(when.getStatus(), Status.SKIP); - Assert.assertEquals(then.getStatus(), Status.WARNING); - Assert.assertEquals(but.getStatus(), Status.WARNING); - Assert.assertEquals(scenario.getStatus(), Status.WARNING); - Assert.assertEquals(feature.getStatus(), Status.WARNING); - } - - @Test - public void verifyErrorHasHigherPriorityThanWarningUsingGherkinKeyword(Method method) throws ClassNotFoundException { - ExtentTest feature = extent.createTest(method.getName()); - ExtentTest scenario = feature.createNode(new GherkinKeyword("Scenario"), "Child"); - ExtentTest given = scenario.createNode(new GherkinKeyword("Given"), "Given").warning("warning"); - ExtentTest and = scenario.createNode(new GherkinKeyword("And"), "And").warning("warning"); - ExtentTest when = scenario.createNode(new GherkinKeyword("When"), "When").warning("warning"); - ExtentTest then = scenario.createNode(new GherkinKeyword("Then"), "Then").error("error"); - ExtentTest but = scenario.createNode(new GherkinKeyword("But"), "But").error("error"); - - Assert.assertEquals(given.getStatus(), Status.WARNING); - Assert.assertEquals(and.getStatus(), Status.WARNING); - Assert.assertEquals(when.getStatus(), Status.WARNING); - Assert.assertEquals(then.getStatus(), Status.ERROR); - Assert.assertEquals(but.getStatus(), Status.ERROR); - Assert.assertEquals(scenario.getStatus(), Status.ERROR); - Assert.assertEquals(feature.getStatus(), Status.ERROR); - } - - @Test - public void verifyErrorHasHigherPriorityThanWarningUsingClass(Method method) { - ExtentTest feature = extent.createTest(method.getName()); - ExtentTest scenario = feature.createNode(Scenario.class, "Scenario"); - ExtentTest given = scenario.createNode(Given.class, "Given").warning("warning"); - ExtentTest and = scenario.createNode(And.class, "And").warning("warning"); - ExtentTest when = scenario.createNode(When.class, "When").warning("warning"); - ExtentTest then = scenario.createNode(Then.class, "Then").error("error"); - ExtentTest but = scenario.createNode(But.class, "But").error("error"); - - Assert.assertEquals(given.getStatus(), Status.WARNING); - Assert.assertEquals(and.getStatus(), Status.WARNING); - Assert.assertEquals(when.getStatus(), Status.WARNING); - Assert.assertEquals(then.getStatus(), Status.ERROR); - Assert.assertEquals(but.getStatus(), Status.ERROR); - Assert.assertEquals(scenario.getStatus(), Status.ERROR); - Assert.assertEquals(feature.getStatus(), Status.ERROR); - } - - @Test - public void verifyFailHasHigherPriorityThanErrorUsingGherkinKeyword(Method method) throws ClassNotFoundException { - ExtentTest feature = extent.createTest(method.getName()); - ExtentTest scenario = feature.createNode(new GherkinKeyword("Scenario"), "Child"); - ExtentTest given = scenario.createNode(new GherkinKeyword("Given"), "Given").error("error"); - ExtentTest and = scenario.createNode(new GherkinKeyword("And"), "And").error("error"); - ExtentTest when = scenario.createNode(new GherkinKeyword("When"), "When").error("error"); - ExtentTest then = scenario.createNode(new GherkinKeyword("Then"), "Then").fail("fail"); - ExtentTest but = scenario.createNode(new GherkinKeyword("But"), "But").fail("fail"); - - Assert.assertEquals(given.getStatus(), Status.ERROR); - Assert.assertEquals(and.getStatus(), Status.ERROR); - Assert.assertEquals(when.getStatus(), Status.ERROR); - Assert.assertEquals(then.getStatus(), Status.FAIL); - Assert.assertEquals(but.getStatus(), Status.FAIL); - Assert.assertEquals(scenario.getStatus(), Status.FAIL); - Assert.assertEquals(feature.getStatus(), Status.FAIL); - } - - @Test - public void verifyFailHasHigherPriorityThanErrorUsingClass(Method method) { - ExtentTest feature = extent.createTest(method.getName()); - ExtentTest scenario = feature.createNode(Scenario.class, "Scenario"); - ExtentTest given = scenario.createNode(Given.class, "Given").error("error"); - ExtentTest and = scenario.createNode(And.class, "And").error("error"); - ExtentTest when = scenario.createNode(When.class, "When").error("error"); - ExtentTest then = scenario.createNode(Then.class, "Then").fail("fail"); - ExtentTest but = scenario.createNode(But.class, "But").fail("fail"); - - Assert.assertEquals(given.getStatus(), Status.ERROR); - Assert.assertEquals(and.getStatus(), Status.ERROR); - Assert.assertEquals(when.getStatus(), Status.ERROR); - Assert.assertEquals(then.getStatus(), Status.FAIL); - Assert.assertEquals(but.getStatus(), Status.FAIL); - Assert.assertEquals(scenario.getStatus(), Status.FAIL); - Assert.assertEquals(feature.getStatus(), Status.FAIL); - } - - @Test - public void verifyFatalHasHigherPriorityThanFailUsingGherkinKeyword(Method method) throws ClassNotFoundException { - ExtentTest feature = extent.createTest(method.getName()); - ExtentTest scenario = feature.createNode(new GherkinKeyword("Scenario"), "Child"); - ExtentTest given = scenario.createNode(new GherkinKeyword("Given"), "Given").fail("fail"); - ExtentTest and = scenario.createNode(new GherkinKeyword("And"), "And").fail("fail"); - ExtentTest when = scenario.createNode(new GherkinKeyword("When"), "When").fail("fail"); - ExtentTest then = scenario.createNode(new GherkinKeyword("Then"), "Then").fatal("fatal"); - ExtentTest but = scenario.createNode(new GherkinKeyword("But"), "But").fatal("fatal"); - - Assert.assertEquals(given.getStatus(), Status.FAIL); - Assert.assertEquals(and.getStatus(), Status.FAIL); - Assert.assertEquals(when.getStatus(), Status.FAIL); - Assert.assertEquals(then.getStatus(), Status.FATAL); - Assert.assertEquals(but.getStatus(), Status.FATAL); - Assert.assertEquals(scenario.getStatus(), Status.FATAL); - Assert.assertEquals(feature.getStatus(), Status.FATAL); - } - - @Test - public void verifyFatalHasHigherPriorityThanFailUsingClass(Method method) { - ExtentTest feature = extent.createTest(method.getName()); - ExtentTest scenario = feature.createNode(Scenario.class, "Scenario"); - ExtentTest given = scenario.createNode(Given.class, "Given").fail("fail"); - ExtentTest and = scenario.createNode(And.class, "And").fail("fail"); - ExtentTest when = scenario.createNode(When.class, "When").fail("fail"); - ExtentTest then = scenario.createNode(Then.class, "Then").fatal("fatal"); - ExtentTest but = scenario.createNode(But.class, "But").fatal("fatal"); - - Assert.assertEquals(given.getStatus(), Status.FAIL); - Assert.assertEquals(and.getStatus(), Status.FAIL); - Assert.assertEquals(when.getStatus(), Status.FAIL); - Assert.assertEquals(then.getStatus(), Status.FATAL); - Assert.assertEquals(but.getStatus(), Status.FATAL); - Assert.assertEquals(scenario.getStatus(), Status.FATAL); - Assert.assertEquals(feature.getStatus(), Status.FATAL); - } -} diff --git a/src/test/java/com/aventstack/extentreports/api/BuildReportWithoutAttachedReportersTest.java b/src/test/java/com/aventstack/extentreports/api/BuildReportWithoutAttachedReportersTest.java deleted file mode 100644 index 796ad47..0000000 --- a/src/test/java/com/aventstack/extentreports/api/BuildReportWithoutAttachedReportersTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.aventstack.extentreports.api; - -import java.lang.reflect.Method; - -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.ExtentReports; - -public class BuildReportWithoutAttachedReportersTest { - - private ExtentReports extent; - - @BeforeClass - public void setup() { - extent = new ExtentReports(); - } - - @Test//(expectedExceptions=IllegalStateException.class) - public void createTestWithoutAttachedReporter(Method method) { - extent.createTest(method.getName()).pass("pass"); - } - - @Test//(expectedExceptions=IllegalStateException.class) - public void flushWithoutAttachedReporter() { - extent.flush(); - } -} diff --git a/src/test/java/com/aventstack/extentreports/api/GherkinDialectTests.java b/src/test/java/com/aventstack/extentreports/api/GherkinDialectTests.java deleted file mode 100644 index 3c2b7f4..0000000 --- a/src/test/java/com/aventstack/extentreports/api/GherkinDialectTests.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.aventstack.extentreports.api; - -import java.io.UnsupportedEncodingException; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.gherkin.GherkinDialectProvider; - -public class GherkinDialectTests { - - private static final String DEFAULT_LANGUAGE = "en"; - - @Test - public void defaultDialectTest() { - Assert.assertTrue(GherkinDialectProvider.getDefaultLanguage().equals(DEFAULT_LANGUAGE)); - } - - @Test - public void defaultLanguageTest() { - Assert.assertTrue(GherkinDialectProvider.getLanguage().equals(DEFAULT_LANGUAGE)); - } - - @Test(expectedExceptions=UnsupportedEncodingException.class) - public void invalidLanguageTest() throws UnsupportedEncodingException { - GherkinDialectProvider.setLanguage("invalid"); - } - - @Test - public void testLanguageSettingTest() throws UnsupportedEncodingException { - GherkinDialectProvider.setLanguage("de"); - Assert.assertTrue(GherkinDialectProvider.getLanguage().equals("de")); - } -} diff --git a/src/test/java/com/aventstack/extentreports/api/MediaEntityBuilderTest.java b/src/test/java/com/aventstack/extentreports/api/MediaEntityBuilderTest.java deleted file mode 100644 index 7cd929f..0000000 --- a/src/test/java/com/aventstack/extentreports/api/MediaEntityBuilderTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.aventstack.extentreports.api; - -import java.io.IOException; -import java.lang.reflect.Method; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; -import com.aventstack.extentreports.ExtentTest; -import com.aventstack.extentreports.MediaEntityBuilder; -import com.aventstack.extentreports.model.service.LogService; - -public class MediaEntityBuilderTest extends Base { - - private static final String IMG_PATH = "src/test/resources/logo.png"; - - @Test - public void testLogMediaEntity(Method method) throws IOException { - ExtentTest t = extent.createTest(method.getName()).pass("details", MediaEntityBuilder.createScreenCaptureFromPath(IMG_PATH).build()); - Assert.assertTrue(LogService.logHasScreenCapture(t.getModel().getLogContext().getFirst())); - } - - @Test - public void testLogMediaEntityWithTitle(Method method) throws IOException { - ExtentTest t = extent.createTest(method.getName()).pass("details", MediaEntityBuilder.createScreenCaptureFromPath(IMG_PATH, "title").build()); - Assert.assertTrue(LogService.logHasScreenCapture(t.getModel().getLogContext().getFirst())); - } - - @Test - public void testLogMediaEntityBase64(Method method) throws IOException { - ExtentTest t = extent.createTest(method.getName()).pass("details", MediaEntityBuilder.createScreenCaptureFromBase64String("base64").build()); - Assert.assertTrue(LogService.logHasScreenCapture(t.getModel().getLogContext().getFirst())); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/api/NodeAttributesTest.java b/src/test/java/com/aventstack/extentreports/api/NodeAttributesTest.java deleted file mode 100644 index 0ad6634..0000000 --- a/src/test/java/com/aventstack/extentreports/api/NodeAttributesTest.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.aventstack.extentreports.api; - -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.List; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; -import com.aventstack.extentreports.ExtentTest; -import com.aventstack.extentreports.model.Attribute; -import com.aventstack.extentreports.model.Category; - -public class NodeAttributesTest extends Base { - - private final String[] categories = { - "extent", - "git", - "tests", - "heroku" - }; - private final String[] authors = { - "anshoo", - "viren", - "maxi", - "vimal" - }; - - @Test - public void verifyIfNodeHasAddedCategory(Method method) { - ExtentTest node = extent - .createTest(method.getName()) - .createNode("Child") - .assignCategory(categories[0]) - .pass("pass"); - - Assert.assertEquals(node.getModel().getCategoryContext().size(), 1); - Category c = (Category) node.getModel().getCategoryContext().get(0); - Assert.assertEquals(c.getName(), categories[0]); - } - - @Test - public void verifyIfTestHasAddedCategories(Method method) { - ExtentTest node = extent.createTest(method.getName()).createNode("Child").pass("pass"); - Arrays.stream(categories).forEach(c -> node.assignCategory(c)); - - Assert.assertEquals(node.getModel().getCategoryContext().size(), categories.length); - - List categoryCollection = node.getModel().getCategoryContext().getAll(); - Arrays.stream(categories).forEach(c -> { - Boolean result = categoryCollection.stream().anyMatch(x -> x.getName() == c); - Assert.assertTrue(result); - }); - } - - @Test - public void verifyIfTestHasAddedAuthor(Method method) { - ExtentTest node = extent - .createTest(method.getName()) - .createNode("Child") - .assignAuthor(authors[0]) - .pass("pass"); - - Assert.assertEquals(node.getModel().getAuthorContext().size(), 1); - Assert.assertEquals(node.getModel().getAuthorContext().get(0).getName(), authors[0]); - } - - @Test - public void verifyIfTestHasAddedAuthors(Method method) { - ExtentTest node = extent - .createTest(method.getName()) - .createNode("Child") - .pass("pass"); - Arrays.stream(authors).forEach(a -> node.assignAuthor(a)); - - Assert.assertEquals(node.getModel().getAuthorContext().size(), authors.length); - - List authorCollection = node.getModel().getAuthorContext().getAll(); - Arrays.stream(authors).forEach(a -> { - Boolean result = authorCollection.stream().anyMatch(x -> x.getName() == a); - Assert.assertTrue(result); - }); - } -} diff --git a/src/test/java/com/aventstack/extentreports/api/NodeMediaTest.java b/src/test/java/com/aventstack/extentreports/api/NodeMediaTest.java deleted file mode 100644 index 6743963..0000000 --- a/src/test/java/com/aventstack/extentreports/api/NodeMediaTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.aventstack.extentreports.api; - -import java.io.IOException; -import java.lang.reflect.Method; -import java.net.URL; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; -import com.aventstack.extentreports.ExtentTest; - -public class NodeMediaTest extends Base { - - private final String imgName = "img"; - private URL url = getClass().getClassLoader().getResource("1.png"); - private String imgPath = url.getPath(); - - @Test - public void verifyIfScreenCaptureAdded(Method method) throws IOException { - ExtentTest node = extent - .createTest(method.getName()) - .createNode("Child") - .addScreenCaptureFromPath(imgPath) - .fail("fail"); - - Assert.assertEquals(node.getModel().getScreenCaptureContext().size(), 1); - } - - @Test - public void verifyScreenCaptureTitle(Method method) throws IOException { - ExtentTest node = extent - .createTest(method.getName()) - .createNode("Child") - .addScreenCaptureFromPath(imgPath, imgName) - .fail("fail"); - - Assert.assertEquals(node.getModel().getScreenCaptureContext().size(), 1); - Assert.assertEquals(node.getModel().getScreenCaptureContext().get(0).getName(), imgName); - } - - @Test - public void verifyMultipleScreenCaptures(Method method) throws IOException { - int times = 4; - - ExtentTest node = extent - .createTest(method.getName()) - .createNode("Child") - .fail("fail"); - - for (int ix = 0; ix < times; ix++) { - node.addScreenCaptureFromPath(imgPath, imgName); - } - - Assert.assertEquals(node.getModel().getScreenCaptureContext().size(), times); - for (int ix = 0; ix < times; ix++) { - Assert.assertEquals(node.getModel().getScreenCaptureContext().get(ix).getName(), imgName); - } - } - -} diff --git a/src/test/java/com/aventstack/extentreports/api/NodeSingleLogsStatusTest.java b/src/test/java/com/aventstack/extentreports/api/NodeSingleLogsStatusTest.java deleted file mode 100644 index c549a8c..0000000 --- a/src/test/java/com/aventstack/extentreports/api/NodeSingleLogsStatusTest.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.aventstack.extentreports.api; - -import java.lang.reflect.Method; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; -import com.aventstack.extentreports.ExtentTest; -import com.aventstack.extentreports.Status; - -public class NodeSingleLogsStatusTest extends Base { - - @Test - public void verifyIfTestHasStatusPass(Method method) { - ExtentTest test = extent.createTest(method.getName()); - ExtentTest node = test.createNode("Child").pass("pass"); - - Assert.assertEquals(node.getModel().getLevel(), 1); - Assert.assertEquals(node.getModel().getLogContext().size(), 1); - Assert.assertEquals(node.getStatus(), Status.PASS); - Assert.assertEquals(test.getStatus(), Status.PASS); - } - - @Test - public void verifyIfTestHasStatusSkip(Method method) { - ExtentTest test = extent.createTest(method.getName()); - ExtentTest node = test.createNode("Child").skip("skip"); - - Assert.assertEquals(node.getModel().getLevel(), 1); - Assert.assertEquals(node.getModel().getLogContext().size(), 1); - Assert.assertEquals(node.getStatus(), Status.SKIP); - Assert.assertEquals(test.getStatus(), Status.SKIP); - } - - @Test - public void verifyIfTestHasStatusWarning(Method method) { - ExtentTest test = extent.createTest(method.getName()); - ExtentTest node = test.createNode("Child").warning("warning"); - - Assert.assertEquals(node.getModel().getLevel(), 1); - Assert.assertEquals(node.getModel().getLogContext().size(), 1); - Assert.assertEquals(node.getStatus(), Status.WARNING); - Assert.assertEquals(test.getStatus(), Status.WARNING); - } - - @Test - public void verifyIfTestHasStatusError(Method method) { - ExtentTest test = extent.createTest(method.getName()); - ExtentTest node = test.createNode("Child").error("error"); - - Assert.assertEquals(node.getModel().getLevel(), 1); - Assert.assertEquals(node.getModel().getLogContext().size(), 1); - Assert.assertEquals(node.getStatus(), Status.ERROR); - Assert.assertEquals(test.getStatus(), Status.ERROR); - } - - @Test - public void verifyIfTestHasStatusFail(Method method) { - ExtentTest test = extent.createTest(method.getName()); - ExtentTest node = test.createNode("Child").fail("fail"); - - Assert.assertEquals(node.getModel().getLevel(), 1); - Assert.assertEquals(node.getModel().getLogContext().size(), 1); - Assert.assertEquals(node.getStatus(), Status.FAIL); - Assert.assertEquals(test.getStatus(), Status.FAIL); - } - - @Test - public void verifyIfTestHasStatusFatal(Method method) { - ExtentTest test = extent.createTest(method.getName()); - ExtentTest node = test.createNode("Child").fatal("fatal"); - - Assert.assertEquals(node.getModel().getLevel(), 1); - Assert.assertEquals(node.getModel().getLogContext().size(), 1); - Assert.assertEquals(node.getStatus(), Status.FATAL); - Assert.assertEquals(test.getStatus(), Status.FATAL); - } - - @Test - public void verifyIfTestHasStatusPassWithOnlyInfoSingle(Method method) { - ExtentTest test = extent.createTest(method.getName()); - ExtentTest node = test.createNode("Child").info("info"); - - Assert.assertEquals(node.getModel().getLevel(), 1); - Assert.assertEquals(node.getModel().getLogContext().size(), 1); - Assert.assertEquals(node.getStatus(), Status.PASS); - Assert.assertEquals(test.getStatus(), Status.PASS); - } -} diff --git a/src/test/java/com/aventstack/extentreports/api/NodeWithoutLogs.java b/src/test/java/com/aventstack/extentreports/api/NodeWithoutLogs.java deleted file mode 100644 index d31d287..0000000 --- a/src/test/java/com/aventstack/extentreports/api/NodeWithoutLogs.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.aventstack.extentreports.api; - -import java.lang.reflect.Method; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; -import com.aventstack.extentreports.ExtentTest; -import com.aventstack.extentreports.Status; - -public class NodeWithoutLogs extends Base { - - @Test - public void verifyNodeAndParentHasPassStatusIfNoLogsAdded(Method method) { - ExtentTest test = extent.createTest(method.getName()); - ExtentTest node = test.createNode("Child"); - - Assert.assertEquals(node.getModel().getLevel(), 1); - Assert.assertEquals(test.getModel().getLogContext().size(), 0); - Assert.assertEquals(test.getStatus(), Status.PASS); - Assert.assertEquals(node.getModel().getLogContext().size(), 0); - Assert.assertEquals(node.getStatus(), Status.PASS); - } -} diff --git a/src/test/java/com/aventstack/extentreports/api/NodeWithoutLogsTest.java b/src/test/java/com/aventstack/extentreports/api/NodeWithoutLogsTest.java deleted file mode 100644 index c476ab6..0000000 --- a/src/test/java/com/aventstack/extentreports/api/NodeWithoutLogsTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.aventstack.extentreports.api; - -import java.lang.reflect.Method; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; -import com.aventstack.extentreports.ExtentTest; -import com.aventstack.extentreports.Status; - -public class NodeWithoutLogsTest extends Base { - - @Test - public void verifyNodeAndParentHasPassStatusIfNoLogsAdded(Method method) { - ExtentTest test = extent.createTest(method.getName()); - ExtentTest node = test.createNode("Child"); - - Assert.assertEquals(node.getModel().getLevel(), 1); - Assert.assertEquals(test.getModel().getLogContext().size(), 0); - Assert.assertEquals(test.getStatus(), Status.PASS); - Assert.assertEquals(node.getModel().getLogContext().size(), 0); - Assert.assertEquals(node.getStatus(), Status.PASS); - } -} diff --git a/src/test/java/com/aventstack/extentreports/api/NodesStatusHierarchyTest.java b/src/test/java/com/aventstack/extentreports/api/NodesStatusHierarchyTest.java deleted file mode 100644 index 4b82354..0000000 --- a/src/test/java/com/aventstack/extentreports/api/NodesStatusHierarchyTest.java +++ /dev/null @@ -1,175 +0,0 @@ -package com.aventstack.extentreports.api; - -import java.lang.reflect.Method; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; -import com.aventstack.extentreports.ExtentTest; -import com.aventstack.extentreports.Status; - -public class NodesStatusHierarchyTest extends Base { - - @Test - public void verifyPassHasHigherPriorityThanInfoLevelsShallow(Method method) { - ExtentTest parent = extent.createTest(method.getName()); - ExtentTest child = parent.createNode("Child"); - child.info("info"); - child.pass("pass"); - - Assert.assertEquals(child.getModel().getLevel(), 1); - Assert.assertEquals(parent.getStatus(), Status.PASS); - Assert.assertEquals(child.getStatus(), Status.PASS); - } - - @Test - public void verifyPassHasHigherPriorityThanInfoLevelsDeep(Method method) { - ExtentTest parent = extent.createTest(method.getName()); - ExtentTest child = parent.createNode("Child"); - ExtentTest grandchild = child.createNode("GrandChild"); - grandchild.info("info"); - grandchild.pass("pass"); - - Assert.assertEquals(child.getModel().getLevel(), 1); - Assert.assertEquals(grandchild.getModel().getLevel(), 2); - Assert.assertEquals(parent.getStatus(), Status.PASS); - Assert.assertEquals(child.getStatus(), Status.PASS); - Assert.assertEquals(grandchild.getStatus(), Status.PASS); - } - - @Test - public void verifySkipHasHigherPriorityThanPassLevelsShallow(Method method) { - ExtentTest parent = extent.createTest(method.getName()); - ExtentTest child = parent.createNode("Child"); - child.pass("pass"); - child.skip("skip"); - - Assert.assertEquals(child.getModel().getLevel(), 1); - Assert.assertEquals(parent.getStatus(), Status.SKIP); - Assert.assertEquals(child.getStatus(), Status.SKIP); - } - - @Test - public void verifySkipHasHigherPriorityThanPassLevelsDeep(Method method) { - ExtentTest parent = extent.createTest(method.getName()); - ExtentTest child = parent.createNode("Child"); - ExtentTest grandchild = child.createNode("GrandChild"); - grandchild.pass("pass"); - grandchild.skip("skip"); - - Assert.assertEquals(child.getModel().getLevel(), 1); - Assert.assertEquals(grandchild.getModel().getLevel(), 2); - Assert.assertEquals(parent.getStatus(), Status.SKIP); - Assert.assertEquals(child.getStatus(), Status.SKIP); - Assert.assertEquals(grandchild.getStatus(), Status.SKIP); - } - - @Test - public void verifyWarningHasHigherPriorityThanSkipLevelsShallow(Method method) { - ExtentTest parent = extent.createTest(method.getName()); - ExtentTest child = parent.createNode("Child"); - child.skip("skip"); - child.warning("warning"); - - Assert.assertEquals(child.getModel().getLevel(), 1); - Assert.assertEquals(parent.getStatus(), Status.WARNING); - Assert.assertEquals(child.getStatus(), Status.WARNING); - } - - @Test - public void verifyWarningHasHigherPriorityThanSkipLevelsDeep(Method method) { - ExtentTest parent = extent.createTest(method.getName()); - ExtentTest child = parent.createNode("Child"); - ExtentTest grandchild = child.createNode("GrandChild"); - grandchild.skip("skip"); - grandchild.warning("warning"); - - Assert.assertEquals(child.getModel().getLevel(), 1); - Assert.assertEquals(grandchild.getModel().getLevel(), 2); - Assert.assertEquals(parent.getStatus(), Status.WARNING); - Assert.assertEquals(child.getStatus(), Status.WARNING); - Assert.assertEquals(grandchild.getStatus(), Status.WARNING); - } - - @Test - public void verifyErrorHasHigherPriorityThanWarningLevelsShallow(Method method) { - ExtentTest parent = extent.createTest(method.getName()); - ExtentTest child = parent.createNode("Child"); - child.warning("warning"); - child.error("error"); - - Assert.assertEquals(child.getModel().getLevel(), 1); - Assert.assertEquals(parent.getStatus(), Status.ERROR); - Assert.assertEquals(child.getStatus(), Status.ERROR); - } - - @Test - public void verifyErrorHasHigherPriorityThanWarningLevelsDeep(Method method) { - ExtentTest parent = extent.createTest(method.getName()); - ExtentTest child = parent.createNode("Child"); - ExtentTest grandchild = child.createNode("GrandChild"); - grandchild.warning("warning"); - grandchild.error("error"); - - Assert.assertEquals(child.getModel().getLevel(), 1); - Assert.assertEquals(grandchild.getModel().getLevel(), 2); - Assert.assertEquals(parent.getStatus(), Status.ERROR); - Assert.assertEquals(child.getStatus(), Status.ERROR); - Assert.assertEquals(grandchild.getStatus(), Status.ERROR); - } - - @Test - public void verifFailHasHigherPriorityThanErrorLevelsShallow(Method method) { - ExtentTest parent = extent.createTest(method.getName()); - ExtentTest child = parent.createNode("Child"); - child.error("error"); - child.fail("fail"); - - Assert.assertEquals(child.getModel().getLevel(), 1); - Assert.assertEquals(parent.getStatus(), Status.FAIL); - Assert.assertEquals(child.getStatus(), Status.FAIL); - } - - @Test - public void verifFailHasHigherPriorityThanErrorLevelsDeep(Method method) { - ExtentTest parent = extent.createTest(method.getName()); - ExtentTest child = parent.createNode("Child"); - ExtentTest grandchild = child.createNode("GrandChild"); - grandchild.error("error"); - grandchild.fail("fail"); - - Assert.assertEquals(child.getModel().getLevel(), 1); - Assert.assertEquals(grandchild.getModel().getLevel(), 2); - Assert.assertEquals(parent.getStatus(), Status.FAIL); - Assert.assertEquals(child.getStatus(), Status.FAIL); - Assert.assertEquals(grandchild.getStatus(), Status.FAIL); - } - - @Test - public void verifFatalHasHigherPriorityThanFailLevelsShallow(Method method) { - ExtentTest parent = extent.createTest(method.getName()); - ExtentTest child = parent.createNode("Child"); - child.fail("fail"); - child.fatal("fatal"); - - Assert.assertEquals(child.getModel().getLevel(), 1); - Assert.assertEquals(parent.getStatus(), Status.FATAL); - Assert.assertEquals(child.getStatus(), Status.FATAL); - } - - @Test - public void verifFatalHasHigherPriorityThanFailLevelsDeep(Method method) { - ExtentTest parent = extent.createTest(method.getName()); - ExtentTest child = parent.createNode("Child"); - ExtentTest grandchild = child.createNode("GrandChild"); - grandchild.fail("fail"); - grandchild.fatal("fatal"); - - Assert.assertEquals(child.getModel().getLevel(), 1); - Assert.assertEquals(grandchild.getModel().getLevel(), 2); - Assert.assertEquals(parent.getStatus(), Status.FATAL); - Assert.assertEquals(child.getStatus(), Status.FATAL); - Assert.assertEquals(grandchild.getStatus(), Status.FATAL); - } -} diff --git a/src/test/java/com/aventstack/extentreports/api/RemoveStartedTestsFromExtentTest.java b/src/test/java/com/aventstack/extentreports/api/RemoveStartedTestsFromExtentTest.java deleted file mode 100644 index 5dfbbdf..0000000 --- a/src/test/java/com/aventstack/extentreports/api/RemoveStartedTestsFromExtentTest.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.aventstack.extentreports.api; - -import java.lang.reflect.Method; -import java.util.Optional; - -import org.testng.Assert; -import org.testng.SkipException; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; -import com.aventstack.extentreports.ExtentTest; -import com.aventstack.extentreports.Status; -import com.aventstack.extentreports.reporter.AbstractReporter; - -public class RemoveStartedTestsFromExtentTest extends Base { - - private AbstractReporter reporter; - - @BeforeMethod - public void beforeMethod() { - setup(); - - Optional reporter = extent - .getStartedReporters() - .stream() - .filter(x -> x instanceof AbstractReporter) - .map(x -> (AbstractReporter)x) - .findFirst(); - if (reporter.get() != null) - this.reporter = reporter.get(); - } - - @Test - public void removeAnErroredTest(Method method) { - if (reporter == null) - throw new SkipException("No Reporters were started."); - - extent.createTest("Pass").pass("Hello"); - ExtentTest test = extent.createTest("Error").error("Hello"); - extent.removeTest(test); - extent.flush(); - - boolean b = reporter.getStatusCollection().contains(Status.ERROR); - Assert.assertFalse(b, "Error status was removed, collection still contains it"); - - b = reporter.getStatusCollection().contains(Status.PASS); - Assert.assertTrue(b, "Pass status was not removed, collection does not contain it"); - } - - @Test - public void removeAPassedTest(Method method) { - if (reporter == null) - throw new SkipException("No Reporters were started."); - - ExtentTest test = extent.createTest("Pass").pass("Hello"); - extent.createTest("Error").error("Hello"); - extent.removeTest(test); - extent.flush(); - - boolean b = reporter.getStatusCollection().contains(Status.PASS); - Assert.assertFalse(b, "Pass status was removed, collection still contains it"); - - b = reporter.getStatusCollection().contains(Status.ERROR); - Assert.assertTrue(b, "Error status was not removed, collection does not contain it"); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/api/StatusHierarchyConfiguratorTest.java b/src/test/java/com/aventstack/extentreports/api/StatusHierarchyConfiguratorTest.java deleted file mode 100644 index 0e021df..0000000 --- a/src/test/java/com/aventstack/extentreports/api/StatusHierarchyConfiguratorTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.aventstack.extentreports.api; - -import java.util.Arrays; -import java.util.List; - -import org.testng.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; -import com.aventstack.extentreports.Status; - -public class StatusHierarchyConfiguratorTest extends Base { - - @Test - public void skipHasHigherPriorityThanPass() { - int skipIndex = Status.getStatusHierarchy().indexOf(Status.SKIP); - int passIndex = Status.getStatusHierarchy().indexOf(Status.PASS); - - Assert.assertTrue(skipIndex < passIndex); - } - - @Test - public void withConfigurationSkipHasLowerPriorityThanPass() { - List statusHierarchy = Arrays.asList( - Status.FATAL, - Status.FAIL, - Status.ERROR, - Status.WARNING, - Status.PASS, - Status.SKIP, - Status.INFO - ); - - extent.config().statusConfigurator().setStatusHierarchy(statusHierarchy); - - int skipIndex = Status.getStatusHierarchy().indexOf(Status.SKIP); - int passIndex = Status.getStatusHierarchy().indexOf(Status.PASS); - - Assert.assertTrue(skipIndex > passIndex); - } - - @Test - public void fatalHasHigherPriorityThanFAIL() { - int fatalIndex = Status.getStatusHierarchy().indexOf(Status.FATAL); - int failIndex = Status.getStatusHierarchy().indexOf(Status.FAIL); - - Assert.assertTrue(fatalIndex < failIndex); - } - - @Test - public void withConfigurationFatalHasLowerPriorityThanFail() { - List statusHierarchy = Arrays.asList( - Status.FAIL, - Status.FATAL, - Status.ERROR, - Status.WARNING, - Status.PASS, - Status.SKIP, - Status.INFO - ); - - extent.config().statusConfigurator().setStatusHierarchy(statusHierarchy); - - int fatalIndex = Status.getStatusHierarchy().indexOf(Status.FATAL); - int failIndex = Status.getStatusHierarchy().indexOf(Status.FAIL); - - Assert.assertTrue(fatalIndex > failIndex); - } - - @AfterClass - public void afterThisClass() { - extent.config().statusConfigurator().resetStatusHierarchy(); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/api/TestAttributesTest.java b/src/test/java/com/aventstack/extentreports/api/TestAttributesTest.java deleted file mode 100644 index 8576f11..0000000 --- a/src/test/java/com/aventstack/extentreports/api/TestAttributesTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.aventstack.extentreports.api; - -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.List; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; -import com.aventstack.extentreports.ExtentTest; -import com.aventstack.extentreports.model.Attribute; - -public class TestAttributesTest extends Base { - - private final String[] categories = { - "extent", - "git", - "tests", - "heroku" - }; - private final String[] authors = { - "anshoo", - "viren", - "maxi", - "vimal" - }; - - @Test - public void verifyIfTestHasAddedCategory(Method method) { - ExtentTest test = extent.createTest(method.getName()).assignCategory(categories[0]); - test.pass("pass"); - - Assert.assertEquals(test.getModel().getCategoryContext().size(), 1); - Assert.assertEquals(test.getModel().getCategoryContext().get(0).getName(), categories[0]); - } - - @Test - public void verifyIfTestHasAddedCategories(Method method) { - ExtentTest test = extent.createTest(method.getName()); - Arrays.stream(categories).forEach(c -> test.assignCategory(c)); - test.pass("pass"); - - Assert.assertEquals(test.getModel().getCategoryContext().size(), categories.length); - - List categoryCollection = test.getModel().getCategoryContext().getAll(); - Arrays.stream(categories).forEach(c -> { - Boolean result = categoryCollection.stream().anyMatch(x -> x.getName() == c); - Assert.assertTrue(result); - }); - } - - @Test - public void verifyIfTestHasAddedAuthor(Method method) { - ExtentTest test = extent.createTest(method.getName()).assignAuthor(authors[0]); - test.pass("pass"); - - Assert.assertEquals(test.getModel().getAuthorContext().size(), 1); - Assert.assertEquals(test.getModel().getAuthorContext().get(0).getName(), authors[0]); - } - - @Test - public void verifyIfTestHasAddedAuthors(Method method) { - ExtentTest test = extent.createTest(method.getName()); - Arrays.stream(authors).forEach(a -> test.assignAuthor(a)); - test.pass("pass"); - - Assert.assertEquals(test.getModel().getAuthorContext().size(), authors.length); - - List authorCollection = test.getModel().getAuthorContext().getAll(); - Arrays.stream(authors).forEach(a -> { - Boolean result = authorCollection.stream().anyMatch(x -> x.getName() == a); - Assert.assertTrue(result); - }); - } -} diff --git a/src/test/java/com/aventstack/extentreports/api/TestIdsTest.java b/src/test/java/com/aventstack/extentreports/api/TestIdsTest.java deleted file mode 100644 index 2607340..0000000 --- a/src/test/java/com/aventstack/extentreports/api/TestIdsTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.aventstack.extentreports.api; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; - -public class TestIdsTest extends Base { - - private final int times = 100; - - @Test - public void verifyAllStartedTestsHaveUniqueIds(Method method) { - List idCollection = new ArrayList<>(); - - // create [times] tests to ensure test-id is not duplicate - for (int ix = 0; ix < times; ix++) { - int testId = extent.createTest(method.getName() + "." + ix).info("test # " + ix).getModel().getId(); - - Assert.assertFalse(idCollection.contains(testId)); - - idCollection.add(testId); - } - } -} diff --git a/src/test/java/com/aventstack/extentreports/api/TestInitializeNullValuesTest.java b/src/test/java/com/aventstack/extentreports/api/TestInitializeNullValuesTest.java deleted file mode 100644 index 590d7a0..0000000 --- a/src/test/java/com/aventstack/extentreports/api/TestInitializeNullValuesTest.java +++ /dev/null @@ -1,117 +0,0 @@ -package com.aventstack.extentreports.api; - -import java.io.UnsupportedEncodingException; -import java.lang.reflect.Method; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; -import com.aventstack.extentreports.ExtentTest; -import com.aventstack.extentreports.GherkinKeyword; -import com.aventstack.extentreports.gherkin.model.Given; -import com.aventstack.extentreports.gherkin.model.Scenario; - -public class TestInitializeNullValuesTest extends Base { - - @Test(priority=1) - public void resetDialect() throws UnsupportedEncodingException { - extent.setGherkinDialect("en"); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testNameNull() { - extent.createTest(null).pass("pass"); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void bddTestScenarioNameNull(Method method) { - ExtentTest feature = extent.createTest(method.getName()); - feature.createNode(Scenario.class, null); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void bddTestScenarioNameEmpty(Method method) { - ExtentTest feature = extent.createTest(method.getName()); - feature.createNode(Scenario.class, ""); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void bddTestStepNameNull(Method method) { - ExtentTest feature = extent.createTest(method.getName()); - ExtentTest scenario = feature.createNode(Scenario.class, "Scenario"); - scenario.createNode(Given.class, null); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void bddTestStepNameEmpty(Method method) { - ExtentTest feature = extent.createTest(method.getName()); - ExtentTest scenario = feature.createNode(Scenario.class, "Scenario"); - scenario.createNode(Given.class, ""); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void bddTestScenarioNameNullGherkinKeyword(Method method) throws ClassNotFoundException { - ExtentTest feature = extent.createTest(method.getName()); - feature.createNode(new GherkinKeyword("Scenario"), null); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void bddTestScenarioNameEmptyGherkinKeyword(Method method) throws ClassNotFoundException, UnsupportedEncodingException { - resetDialect(); - ExtentTest feature = extent.createTest(method.getName()); - feature.createNode(new GherkinKeyword("Scenario"), ""); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void bddTestStepNameNullGherkinKeyword(Method method) throws ClassNotFoundException { - ExtentTest feature = extent.createTest(method.getName()); - ExtentTest scenario = feature.createNode(Scenario.class, "Scenario"); - scenario.createNode(new GherkinKeyword("Given"), null); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void bddTestStepNameEmptyGherkinKeyword(Method method) throws ClassNotFoundException { - ExtentTest feature = extent.createTest(method.getName()); - ExtentTest scenario = feature.createNode(Scenario.class, "Scenario"); - scenario.createNode(new GherkinKeyword("Given"), ""); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testNameEmpty() { - extent.createTest("").pass("pass"); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void nodeNameNull(Method method) { - ExtentTest test = extent.createTest(method.getName()).fail("fail"); - ExtentTest node = test.createNode(null); - - Assert.assertEquals(test.getModel().getNodeContext().size(), 0); - Assert.assertNull(node); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void nodeNameEmpty(Method method) { - ExtentTest test = extent.createTest(method.getName()).fail("fail"); - ExtentTest node = test.createNode(""); - - Assert.assertEquals(test.getModel().getNodeContext().size(), 0); - Assert.assertNull(node); - } - - @Test - public void testDescriptionNull(Method method) { - ExtentTest test = extent.createTest(method.getName(), null).pass("pass"); - - Assert.assertTrue(test.getModel().getDescription().isEmpty()); - } - - @Test - public void nodeDescriptionNull(Method method) { - ExtentTest node = extent.createTest(method.getName()).createNode("Child", null).pass("pass"); - - Assert.assertTrue(node.getModel().getDescription().isEmpty()); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/api/TestMediaTest.java b/src/test/java/com/aventstack/extentreports/api/TestMediaTest.java deleted file mode 100644 index b2c9ec5..0000000 --- a/src/test/java/com/aventstack/extentreports/api/TestMediaTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.aventstack.extentreports.api; - -import java.io.IOException; -import java.lang.reflect.Method; -import java.net.URL; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; -import com.aventstack.extentreports.ExtentTest; - -public class TestMediaTest extends Base { - - private final String imgName = "img"; - private URL url = getClass().getClassLoader().getResource("1.png"); - private String imgPath = url.getPath(); - - @Test - public void verifyIfScreenCaptureAdded(Method method) throws IOException { - ExtentTest test = extent - .createTest(method.getName()) - .addScreenCaptureFromPath(imgPath) - .fail("fail"); - - Assert.assertEquals(test.getModel().getScreenCaptureContext().size(), 1); - } - - @Test - public void verifyScreenCaptureTitle(Method method) throws IOException { - ExtentTest test = extent - .createTest(method.getName()) - .addScreenCaptureFromPath(imgPath, imgName) - .fail("fail"); - - Assert.assertEquals(test.getModel().getScreenCaptureContext().size(), 1); - Assert.assertEquals(test.getModel().getScreenCaptureContext().get(0).getName(), imgName); - } - - @Test - public void verifyMultipleScreenCaptures(Method method) throws IOException { - int times = 4; - - ExtentTest test = extent - .createTest(method.getName()) - .fail("fail"); - - for (int ix = 0; ix < times; ix++) { - test.addScreenCaptureFromPath(imgPath, imgName); - } - - Assert.assertEquals(test.getModel().getScreenCaptureContext().size(), times); - for (int ix = 0; ix < times; ix++) { - Assert.assertEquals(test.getModel().getScreenCaptureContext().get(ix).getName(), imgName); - } - } - -} diff --git a/src/test/java/com/aventstack/extentreports/api/TestSingleLogsStatusTest.java b/src/test/java/com/aventstack/extentreports/api/TestSingleLogsStatusTest.java deleted file mode 100644 index 5d31206..0000000 --- a/src/test/java/com/aventstack/extentreports/api/TestSingleLogsStatusTest.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.aventstack.extentreports.api; - -import java.lang.reflect.Method; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; -import com.aventstack.extentreports.ExtentTest; -import com.aventstack.extentreports.Status; - -public class TestSingleLogsStatusTest extends Base { - - @Test - public void verifyIfTestHasStatusPass(Method method) { - ExtentTest test = extent.createTest(method.getName()).pass("pass"); - - Assert.assertEquals(test.getModel().getLogContext().size(), 1); - Assert.assertEquals(test.getStatus(), Status.PASS); - } - - @Test - public void verifyIfTestHasStatusSkip(Method method) { - ExtentTest test = extent.createTest(method.getName()).skip("skip"); - - Assert.assertEquals(test.getModel().getLogContext().size(), 1); - Assert.assertEquals(test.getStatus(), Status.SKIP); - } - - @Test - public void verifyIfTestHasStatusWarning(Method method) { - ExtentTest test = extent.createTest(method.getName()).warning("warning"); - - Assert.assertEquals(test.getModel().getLogContext().size(), 1); - Assert.assertEquals(test.getStatus(), Status.WARNING); - } - - @Test - public void verifyIfTestHasStatusError(Method method) { - ExtentTest test = extent.createTest(method.getName()).error("error"); - - Assert.assertEquals(test.getModel().getLogContext().size(), 1); - Assert.assertEquals(test.getStatus(), Status.ERROR); - } - - @Test - public void verifyIfTestHasStatusFail(Method method) { - ExtentTest test = extent.createTest(method.getName()).fail("fail"); - - Assert.assertEquals(test.getModel().getLogContext().size(), 1); - Assert.assertEquals(test.getStatus(), Status.FAIL); - } - - @Test - public void verifyIfTestHasStatusFatal(Method method) { - ExtentTest test = extent.createTest(method.getName()).fatal("fatal"); - - Assert.assertEquals(test.getModel().getLogContext().size(), 1); - Assert.assertEquals(test.getStatus(), Status.FATAL); - } - - @Test - public void verifyIfTestHasStatusPassWithOnlyInfoSingle(Method method) { - ExtentTest test = extent.createTest(method.getName()).info("info"); - - Assert.assertEquals(test.getModel().getLogContext().size(), 1); - Assert.assertEquals(test.getStatus(), Status.PASS); - } -} diff --git a/src/test/java/com/aventstack/extentreports/api/TestStartEndDateTimeTest.java b/src/test/java/com/aventstack/extentreports/api/TestStartEndDateTimeTest.java deleted file mode 100644 index fa86916..0000000 --- a/src/test/java/com/aventstack/extentreports/api/TestStartEndDateTimeTest.java +++ /dev/null @@ -1,154 +0,0 @@ -package com.aventstack.extentreports.api; - -import java.lang.reflect.Method; -import java.util.Calendar; -import java.util.Date; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; -import com.aventstack.extentreports.ExtentTest; - -public class TestStartEndDateTimeTest extends Base { - - @Test - public void testStartTimeBoundary(Method method) { - Date init = Calendar.getInstance().getTime(); - ExtentTest test = extent.createTest(method.getName()).pass("pass"); - Date end = Calendar.getInstance().getTime(); - - Assert.assertTrue(test.getModel().getStartTime().getTime() >= init.getTime()); - Assert.assertTrue(test.getModel().getStartTime().getTime() <= end.getTime()); - } - - @Test - public void testEndTimeBoundary(Method method) { - Date init = Calendar.getInstance().getTime(); - ExtentTest test = extent.createTest(method.getName()).pass("pass"); - Date end = Calendar.getInstance().getTime(); - - Assert.assertTrue(test.getModel().getEndTime().getTime() >= init.getTime()); - Assert.assertTrue(test.getModel().getEndTime().getTime() <= end.getTime()); - } - - @Test - public void testEndTimeLogTimeTaken(Method method) throws InterruptedException { - int wait = 200; - Date init = Calendar.getInstance().getTime(); - ExtentTest test = extent.createTest(method.getName()); - Thread.sleep(wait); - test.pass("pass"); - - Assert.assertTrue(test.getModel().getEndTime().getTime() >= (init.getTime() + wait)); - } - - @Test - public void testEndTimeNodeTimeTaken(Method method) throws InterruptedException { - int wait = 200; - Date init = Calendar.getInstance().getTime(); - ExtentTest test = extent.createTest(method.getName()); - ExtentTest node = test.createNode(method.getName()); - Thread.sleep(wait); - node.pass("pass"); - extent.flush(); - Assert.assertTrue(node.getModel().getEndTime().getTime() >= (init.getTime() + wait)); - Assert.assertTrue(test.getModel().getEndTime().getTime() >= (init.getTime() + wait)); - } - - @Test - public void testTimeWithManualSettingBoundary(Method method) { - extent.setReportUsesManualConfiguration(true); - - Date init = Calendar.getInstance().getTime(); - ExtentTest test = extent.createTest(method.getName()).pass("pass"); - Date end = Calendar.getInstance().getTime(); - - Assert.assertTrue(test.getModel().getEndTime().getTime() >= init.getTime()); - Assert.assertTrue(test.getModel().getEndTime().getTime() <= end.getTime()); - } - - @Test - public void testEndTimeWithManualSettingBoundary(Method method) { - extent.setReportUsesManualConfiguration(true); - - Date init = Calendar.getInstance().getTime(); - ExtentTest test = extent.createTest(method.getName()).pass("pass"); - Date end = Calendar.getInstance().getTime(); - - Assert.assertTrue(test.getModel().getEndTime().getTime() >= init.getTime()); - Assert.assertTrue(test.getModel().getEndTime().getTime() <= end.getTime()); - } - - @Test - public void testEndTimeWithManualSettingLog(Method method) throws InterruptedException { - int wait = 200; - extent.setReportUsesManualConfiguration(true); - - Date init = Calendar.getInstance().getTime(); - ExtentTest test = extent.createTest(method.getName()); - Thread.sleep(wait); - test.pass("pass"); - - Assert.assertFalse(test.getModel().getEndTime().getTime() >= (init.getTime() + wait)); - } - - @Test - public void testStartTimeWithManualSettingLogSetter(Method method) throws InterruptedException { - int wait = 200; - extent.setReportUsesManualConfiguration(true); - - Date init = Calendar.getInstance().getTime(); - ExtentTest test = extent.createTest(method.getName()); - Thread.sleep(wait); - test.pass("pass"); - test.getModel().setStartTime(test.getModel().getLogContext().getLast().getTimestamp()); - - Assert.assertTrue(test.getModel().getStartTime().getTime() >= (init.getTime() + wait)); - } - - @Test - public void testStartTimeWithManualSettingNodeLogSetter(Method method) throws InterruptedException { - int wait = 200; - extent.setReportUsesManualConfiguration(true); - - Date init = Calendar.getInstance().getTime(); - ExtentTest test = extent.createTest(method.getName()); - ExtentTest node = test.createNode(method.getName()); - Thread.sleep(wait); - node.pass("pass"); - test.getModel().setStartTime(test.getModel().getNodeContext().getLast().getEndTime()); - - Assert.assertTrue(test.getModel().getStartTime().getTime() >= (init.getTime() + wait)); - } - - @Test - public void testEndTimeWithManualSettingLogSetter(Method method) throws InterruptedException { - int wait = 200; - extent.setReportUsesManualConfiguration(true); - - Date init = Calendar.getInstance().getTime(); - ExtentTest test = extent.createTest(method.getName()); - Thread.sleep(wait); - test.pass("pass"); - test.getModel().setEndTime(test.getModel().getLogContext().getLast().getTimestamp()); - - Assert.assertTrue(test.getModel().getEndTime().getTime() >= (init.getTime() + wait)); - } - - @Test - public void testEndTimeWithManualSettingNodeLogSetter(Method method) throws InterruptedException { - int wait = 200; - extent.setReportUsesManualConfiguration(true); - - Date init = Calendar.getInstance().getTime(); - ExtentTest test = extent.createTest(method.getName()); - ExtentTest node = test.createNode(method.getName()); - Thread.sleep(wait); - node.pass("pass"); - test.getModel().setEndTime(test.getModel().getNodeContext().getLast().getEndTime()); - - Assert.assertTrue(test.getModel().getEndTime().getTime() >= (init.getTime() + wait)); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/api/TestStatusHierarchyTest.java b/src/test/java/com/aventstack/extentreports/api/TestStatusHierarchyTest.java deleted file mode 100644 index d671a8e..0000000 --- a/src/test/java/com/aventstack/extentreports/api/TestStatusHierarchyTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.aventstack.extentreports.api; - -import java.lang.reflect.Method; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; -import com.aventstack.extentreports.ExtentTest; -import com.aventstack.extentreports.Status; - -public class TestStatusHierarchyTest extends Base { - - @Test - public void verifyPassHasHigherPriorityThanInfo(Method method) { - ExtentTest test = extent.createTest(method.getName()); - test.info("info"); - test.pass("pass"); - - Assert.assertEquals(test.getStatus(), Status.PASS); - } - - @Test - public void verifySkipHasHigherPriorityThanPass(Method method) { - ExtentTest test = extent.createTest(method.getName()); - test.pass("pass"); - test.skip("skip"); - - Assert.assertEquals(test.getStatus(), Status.SKIP); - } - - @Test - public void verifyWarningHasHigherPriorityThanSkip(Method method) { - ExtentTest test = extent.createTest(method.getName()); - test.skip("skip"); - test.warning("warning"); - - Assert.assertEquals(test.getStatus(), Status.WARNING); - } - - @Test - public void verifyErrorHasHigherPriorityThanWarning(Method method) { - ExtentTest test = extent.createTest(method.getName()); - test.warning("warning"); - test.error("error"); - - Assert.assertEquals(test.getStatus(), Status.ERROR); - } - - @Test - public void verifFailHasHigherPriorityThanError(Method method) { - ExtentTest test = extent.createTest(method.getName()); - test.error("error"); - test.fail("fail"); - - Assert.assertEquals(test.getStatus(), Status.FAIL); - } - - @Test - public void verifFatalHasHigherPriorityThanFail(Method method) { - ExtentTest test = extent.createTest(method.getName()); - test.fail("fail"); - test.fatal("fatal"); - - Assert.assertEquals(test.getStatus(), Status.FATAL); - } -} diff --git a/src/test/java/com/aventstack/extentreports/api/TestWithoutLogsTest.java b/src/test/java/com/aventstack/extentreports/api/TestWithoutLogsTest.java deleted file mode 100644 index 84f3979..0000000 --- a/src/test/java/com/aventstack/extentreports/api/TestWithoutLogsTest.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.aventstack.extentreports.api; - -import java.lang.reflect.Method; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; -import com.aventstack.extentreports.ExtentTest; -import com.aventstack.extentreports.Status; - -public class TestWithoutLogsTest extends Base { - - @Test - public void verifyTestHasPassStatusIfNoLogsAdded(Method method) { - ExtentTest test = extent.createTest(method.getName()); - - Assert.assertEquals(test.getModel().getLogContext().size(), 0); - Assert.assertEquals(test.getStatus(), Status.PASS); - } -} diff --git a/src/test/java/com/aventstack/extentreports/common/ExtentManager.java b/src/test/java/com/aventstack/extentreports/common/ExtentManager.java deleted file mode 100644 index 1759652..0000000 --- a/src/test/java/com/aventstack/extentreports/common/ExtentManager.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.aventstack.extentreports.common; - -import com.aventstack.extentreports.ExtentReports; -import com.aventstack.extentreports.reporter.ConsoleLogger; - -public class ExtentManager { - - static ExtentReports extent; - - public static ExtentReports getInstance() { - return extent; - } - - public static ExtentReports createInstance() { - ConsoleLogger logger = new ConsoleLogger(); - extent = new ExtentReports(); - extent.attachReporter(logger); - - return extent; - } - -} diff --git a/src/test/java/com/aventstack/extentreports/common/ExtentTestManager.java b/src/test/java/com/aventstack/extentreports/common/ExtentTestManager.java deleted file mode 100644 index b514b8b..0000000 --- a/src/test/java/com/aventstack/extentreports/common/ExtentTestManager.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.aventstack.extentreports.common; - -import java.util.HashMap; -import java.util.Map; - -import com.aventstack.extentreports.ExtentReports; -import com.aventstack.extentreports.ExtentTest; - -public class ExtentTestManager { - - static Map extentTestMap = new HashMap(); - private static ExtentReports extent; - - public static void setReporter(ExtentReports extent) { - ExtentTestManager.extent = extent; - } - - public static ExtentReports getReporter() { - return extent; - } - - public static synchronized ExtentTest getTest() { - return extentTestMap.get((int) (long) (Thread.currentThread().getId())); - } - - public static ExtentTest createTest(String testName) { - return createTest(testName, ""); - } - - public static ExtentTest createTest(String testName, String desc) { - ExtentTest test = extent.createTest(testName, desc); - extentTestMap.put((int) (long) (Thread.currentThread().getId()), test); - - return test; - } - -} diff --git a/src/test/java/com/aventstack/extentreports/common/ExtentTestNGIReporterListener.java b/src/test/java/com/aventstack/extentreports/common/ExtentTestNGIReporterListener.java deleted file mode 100644 index 3a1edcf..0000000 --- a/src/test/java/com/aventstack/extentreports/common/ExtentTestNGIReporterListener.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.aventstack.extentreports.common; - -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import org.testng.IReporter; -import org.testng.IResultMap; -import org.testng.ISuite; -import org.testng.ISuiteResult; -import org.testng.ITestContext; -import org.testng.ITestResult; -import org.testng.Reporter; -import org.testng.xml.XmlSuite; - -import com.aventstack.extentreports.ExtentReports; -import com.aventstack.extentreports.ExtentTest; -import com.aventstack.extentreports.Status; -import com.aventstack.extentreports.reporter.ConsoleLogger; - -public class ExtentTestNGIReporterListener implements IReporter { - - private ExtentReports extent; - - @Override - public void generateReport(List xmlSuites, List suites, String outputDirectory) { - init(); - - for (ISuite suite : suites) { - Map result = suite.getResults(); - - for (ISuiteResult r : result.values()) { - ITestContext context = r.getTestContext(); - - buildTestNodes(context.getFailedTests(), Status.FAIL); - buildTestNodes(context.getSkippedTests(), Status.SKIP); - buildTestNodes(context.getPassedTests(), Status.PASS); - - } - } - - for (String s : Reporter.getOutput()) { - extent.setTestRunnerOutput(s); - } - - extent.flush(); - } - - private void init() { - ConsoleLogger logger = new ConsoleLogger(); - extent = new ExtentReports(); - extent.attachReporter(logger); - extent.setReportUsesManualConfiguration(true); - } - - private void buildTestNodes(IResultMap tests, Status status) { - ExtentTest test; - - if (tests.size() > 0) { - for (ITestResult result : tests.getAllResults()) { - test = extent.createTest(result.getMethod().getMethodName()); - - for (String group : result.getMethod().getGroups()) - test.assignCategory(group); - - if (result.getThrowable() != null) { - test.log(status, result.getThrowable()); - } - else { - test.log(status, "Test " + status.toString().toLowerCase() + "ed"); - } - - test.getModel().setStartTime(getTime(result.getStartMillis())); - test.getModel().setEndTime(getTime(result.getEndMillis())); - } - } - } - - private Date getTime(long millis) { - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(millis); - return calendar.getTime(); - } -} \ No newline at end of file diff --git a/src/test/java/com/aventstack/extentreports/common/ExtentTestNGITestListener.java b/src/test/java/com/aventstack/extentreports/common/ExtentTestNGITestListener.java deleted file mode 100644 index 0c1cea4..0000000 --- a/src/test/java/com/aventstack/extentreports/common/ExtentTestNGITestListener.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.aventstack.extentreports.common; - -import org.testng.ITestContext; -import org.testng.ITestListener; -import org.testng.ITestResult; - -import com.aventstack.extentreports.ExtentReports; -import com.aventstack.extentreports.ExtentTest; - -public class ExtentTestNGITestListener implements ITestListener { - - private static ExtentReports extent = ExtentManager.createInstance(); - private static ThreadLocal parentTest = new ThreadLocal(); - private static ThreadLocal test = new ThreadLocal(); - - @Override - public synchronized void onStart(ITestContext context) { - ExtentTest parent = extent.createTest(getClass().getName()); - parentTest.set(parent); - } - - @Override - public synchronized void onFinish(ITestContext context) { - extent.flush(); - } - - @Override - public synchronized void onTestStart(ITestResult result) { - ExtentTest child = parentTest.get().createNode(result.getMethod().getMethodName()); - test.set(child); - } - - @Override - public synchronized void onTestSuccess(ITestResult result) { - test.get().pass("Test passed"); - } - - @Override - public synchronized void onTestFailure(ITestResult result) { - test.get().fail(result.getThrowable()); - } - - @Override - public synchronized void onTestSkipped(ITestResult result) { - test.get().skip(result.getThrowable()); - } - - @Override - public synchronized void onTestFailedButWithinSuccessPercentage(ITestResult result) { - - } - -} diff --git a/src/test/java/com/aventstack/extentreports/common/ExtentTestNGListener.java b/src/test/java/com/aventstack/extentreports/common/ExtentTestNGListener.java deleted file mode 100644 index 90db98f..0000000 --- a/src/test/java/com/aventstack/extentreports/common/ExtentTestNGListener.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.aventstack.extentreports.common; - -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import org.testng.IReporter; -import org.testng.IResultMap; -import org.testng.ISuite; -import org.testng.ISuiteResult; -import org.testng.ITestContext; -import org.testng.ITestResult; -import org.testng.Reporter; -import org.testng.xml.XmlSuite; - -import com.aventstack.extentreports.ExtentReports; -import com.aventstack.extentreports.ExtentTest; -import com.aventstack.extentreports.Status; -import com.aventstack.extentreports.reporter.ConsoleLogger; - -public class ExtentTestNGListener implements IReporter { - - private ExtentReports extent; - - @Override - public void generateReport(List xmlSuites, List suites, String outputDirectory) { - init(); - - for (ISuite suite : suites) { - Map result = suite.getResults(); - - for (ISuiteResult r : result.values()) { - ITestContext context = r.getTestContext(); - - buildTestNodes(context.getFailedTests(), Status.FAIL); - buildTestNodes(context.getSkippedTests(), Status.SKIP); - buildTestNodes(context.getPassedTests(), Status.PASS); - - } - } - - for (String s : Reporter.getOutput()) { - extent.setTestRunnerOutput(s); - } - - extent.flush(); - } - - private void init() { - ConsoleLogger logger = new ConsoleLogger(); - extent = new ExtentReports(); - extent.attachReporter(logger); - extent.setReportUsesManualConfiguration(true); - } - - private void buildTestNodes(IResultMap tests, Status status) { - ExtentTest test; - - if (tests.size() > 0) { - for (ITestResult result : tests.getAllResults()) { - test = extent.createTest(result.getMethod().getMethodName()); - - for (String group : result.getMethod().getGroups()) - test.assignCategory(group); - - if (result.getThrowable() != null) { - test.log(status, result.getThrowable()); - } - else { - test.log(status, "Test " + status.toString().toLowerCase() + "ed"); - } - - test.getModel().setStartTime(getTime(result.getStartMillis())); - test.getModel().setEndTime(getTime(result.getEndMillis())); - } - } - } - - private Date getTime(long millis) { - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(millis); - return calendar.getTime(); - } -} \ No newline at end of file diff --git a/src/test/java/com/aventstack/extentreports/config/ConfigStoreTest.java b/src/test/java/com/aventstack/extentreports/config/ConfigStoreTest.java new file mode 100644 index 0000000..530a51b --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/config/ConfigStoreTest.java @@ -0,0 +1,73 @@ +package com.aventstack.extentreports.config; + +import org.testng.Assert; +import org.testng.annotations.Test; + +public class ConfigStoreTest { + private ConfigStore store = new ConfigStore(); + + @Test + public void duplicateConfig() { + store.addConfig("config", "value1"); + Assert.assertEquals(store.getConfig("config"), "value1"); + store.addConfig("config", "value2"); + Assert.assertEquals(store.getConfig("config"), "value2"); + } + + @Test + public void containsConfig() { + store.addConfig("config", "value1"); + Assert.assertTrue(store.containsConfig("config")); + Assert.assertFalse(store.containsConfig("config2")); + } + + @Test + public void removeConfig() { + store.addConfig("config", "value1"); + Assert.assertTrue(store.containsConfig("config")); + store.removeConfig("config"); + Assert.assertFalse(store.containsConfig("config")); + } + + @Test + public void configValueTest() { + store.addConfig("c", "v"); + store.addConfig("k", "z"); + Assert.assertTrue(store.getConfig("c").equals("v")); + Assert.assertTrue(store.getConfig("k").equals("z")); + } + + @Test + public void extendConfigWithStore() { + ConfigStore store1 = new ConfigStore(); + store1.addConfig("config1", "value1"); + ConfigStore store2 = new ConfigStore(); + store2.addConfig("config2", "value2"); + store1.extendConfig(store2); + Assert.assertTrue(store1.containsConfig("config1")); + Assert.assertTrue(store1.containsConfig("config2")); + Assert.assertTrue(store2.containsConfig("config2")); + Assert.assertFalse(store2.containsConfig("config1")); + } + + @Test + public void extendConfigWithMap() { + ConfigStore store1 = new ConfigStore(); + store1.addConfig("config1", "value1"); + ConfigStore store2 = new ConfigStore(); + store2.addConfig("config2", "value2"); + store1.extendConfig(store2.getStore()); + Assert.assertTrue(store1.containsConfig("config1")); + Assert.assertTrue(store1.containsConfig("config2")); + Assert.assertTrue(store2.containsConfig("config2")); + Assert.assertFalse(store2.containsConfig("config1")); + } + + @Test + public void configEmpty() { + ConfigStore store = new ConfigStore(); + Assert.assertTrue(store.isEmpty()); + store.addConfig("config1", "value1"); + Assert.assertFalse(store.isEmpty()); + } +} diff --git a/src/test/java/com/aventstack/extentreports/config/external/JsonConfigLoaderTest.java b/src/test/java/com/aventstack/extentreports/config/external/JsonConfigLoaderTest.java new file mode 100644 index 0000000..e17bcac --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/config/external/JsonConfigLoaderTest.java @@ -0,0 +1,42 @@ +package com.aventstack.extentreports.config.external; + +import java.io.File; +import java.io.FileNotFoundException; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.aventstack.extentreports.reporter.configuration.ExtentSparkReporterConfig; +import com.aventstack.extentreports.reporter.configuration.Protocol; +import com.aventstack.extentreports.reporter.configuration.Theme; + +public class JsonConfigLoaderTest { + private static final String JSON_FILE = "src/test/resources/config/spark-config.json"; + private static final String JSON_FILE_ENUM = "src/test/resources/config/spark-config_lowercase_enum.json"; + + @Test + public void jsonConfigTest() throws FileNotFoundException { + ExtentSparkReporterConfig conf = ExtentSparkReporterConfig.builder().build(); + JsonConfigLoader loader = new JsonConfigLoader(conf, + new File(JSON_FILE)); + loader.apply(); + Assert.assertEquals(conf.getCss(), "css1"); + Assert.assertEquals(conf.getDocumentTitle(), "Test1"); + Assert.assertEquals(conf.getEncoding(), "utf-16"); + Assert.assertEquals(conf.getReportName(), "Test2"); + Assert.assertEquals(conf.getTimeStampFormat(), "MMM dd, yyyy HH:mm:ss a"); + Assert.assertEquals(conf.getOfflineMode().booleanValue(), true); + Assert.assertEquals(conf.getProtocol(), Protocol.HTTP); + Assert.assertEquals(conf.getTheme(), Theme.DARK); + } + + @Test + public void jsonConfigLowerCaseEnumTest() throws FileNotFoundException { + ExtentSparkReporterConfig conf = ExtentSparkReporterConfig.builder().build(); + JsonConfigLoader loader = new JsonConfigLoader(conf, + new File(JSON_FILE_ENUM)); + loader.apply(); + Assert.assertEquals(conf.getProtocol(), Protocol.HTTP); + Assert.assertEquals(conf.getTheme(), Theme.DARK); + } +} diff --git a/src/test/java/com/aventstack/extentreports/config/external/XmlConfigLoaderTest.java b/src/test/java/com/aventstack/extentreports/config/external/XmlConfigLoaderTest.java new file mode 100644 index 0000000..477d42a --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/config/external/XmlConfigLoaderTest.java @@ -0,0 +1,42 @@ +package com.aventstack.extentreports.config.external; + +import java.io.File; +import java.io.FileNotFoundException; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.aventstack.extentreports.reporter.configuration.ExtentSparkReporterConfig; +import com.aventstack.extentreports.reporter.configuration.Protocol; +import com.aventstack.extentreports.reporter.configuration.Theme; + +public class XmlConfigLoaderTest { + private static final String XML_FILE = "src/test/resources/config/spark-config.xml"; + private static final String XML_FILE_ENUM = "src/test/resources/config/spark-config.xml"; + + @Test + public void xmlConfigTest() throws FileNotFoundException { + ExtentSparkReporterConfig conf = ExtentSparkReporterConfig.builder().build(); + XmlConfigLoader loader = new XmlConfigLoader(conf, + new File(XML_FILE)); + loader.apply(); + Assert.assertEquals(conf.getCss(), "css1"); + Assert.assertEquals(conf.getDocumentTitle(), "Test1"); + Assert.assertEquals(conf.getEncoding(), "utf-16"); + Assert.assertEquals(conf.getReportName(), "Test2"); + Assert.assertEquals(conf.getTimeStampFormat(), "MMM dd, yyyy HH:mm:ss a"); + Assert.assertEquals(conf.getOfflineMode().booleanValue(), true); + Assert.assertEquals(conf.getProtocol(), Protocol.HTTP); + Assert.assertEquals(conf.getTheme(), Theme.DARK); + } + + @Test + public void xmlConfigLowerCaseEnumTest() throws FileNotFoundException { + ExtentSparkReporterConfig conf = ExtentSparkReporterConfig.builder().build(); + XmlConfigLoader loader = new XmlConfigLoader(conf, + new File(XML_FILE_ENUM)); + loader.apply(); + Assert.assertEquals(conf.getProtocol(), Protocol.HTTP); + Assert.assertEquals(conf.getTheme(), Theme.DARK); + } +} diff --git a/src/test/java/com/aventstack/extentreports/entity/AuthorEntityTest.java b/src/test/java/com/aventstack/extentreports/entity/AuthorEntityTest.java new file mode 100644 index 0000000..e045bfc --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/entity/AuthorEntityTest.java @@ -0,0 +1,17 @@ +package com.aventstack.extentreports.entity; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.aventstack.extentreports.model.Author; + +public class AuthorEntityTest { + + @Test + public void authorName() { + final String name = "Anshoo"; + Author author = new Author(name); + Assert.assertEquals(author.getName(), name); + } + +} diff --git a/src/test/java/com/aventstack/extentreports/entity/CategoryEntityTest.java b/src/test/java/com/aventstack/extentreports/entity/CategoryEntityTest.java new file mode 100644 index 0000000..e0203c1 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/entity/CategoryEntityTest.java @@ -0,0 +1,17 @@ +package com.aventstack.extentreports.entity; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.aventstack.extentreports.model.Category; + +public class CategoryEntityTest { + + @Test + public void tagName() { + final String name = "TagName"; + Category tag = new Category(name); + Assert.assertEquals(tag.getName(), name); + } + +} diff --git a/src/test/java/com/aventstack/extentreports/entity/DeviceEntityTest.java b/src/test/java/com/aventstack/extentreports/entity/DeviceEntityTest.java new file mode 100644 index 0000000..7787e42 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/entity/DeviceEntityTest.java @@ -0,0 +1,17 @@ +package com.aventstack.extentreports.entity; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.aventstack.extentreports.model.Device; + +public class DeviceEntityTest { + + @Test + public void deviceName() { + final String name = "DeviceName"; + Device author = new Device(name); + Assert.assertEquals(author.getName(), name); + } + +} diff --git a/src/test/java/com/aventstack/extentreports/entity/LogEntityTest.java b/src/test/java/com/aventstack/extentreports/entity/LogEntityTest.java new file mode 100644 index 0000000..5f62572 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/entity/LogEntityTest.java @@ -0,0 +1,87 @@ +package com.aventstack.extentreports.entity; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.aventstack.extentreports.Status; +import com.aventstack.extentreports.model.Log; +import com.aventstack.extentreports.model.Media; +import com.aventstack.extentreports.model.ScreenCapture; + +public class LogEntityTest { + + @Test + public void defaultStatusBuilder() { + Log log = Log.builder().build(); + Assert.assertEquals(log.getStatus(), Status.PASS); + } + + /* + * Lombok @Builder.Default bug causing not setting fields on instantiating + * via new + */ + // @Test + // public void defaultStatusInstantiate() { + // Log log = new Log(); + // Assert.assertEquals(log.getStatus(), Status.PASS); + // } + + @Test + public void changedStatus() { + Log log = new Log(); + log.setStatus(Status.FAIL); + Assert.assertEquals(log.getStatus(), Status.FAIL); + log.setStatus(Status.PASS); + Assert.assertEquals(log.getStatus(), Status.PASS); + } + + @Test + public void timestampNonNullOnInit() { + Log log = Log.builder().build(); + Assert.assertNotNull(log.getTimestamp()); + } + + @Test + public void detailsNullOnInit() { + Log log = Log.builder().build(); + Assert.assertNull(log.getDetails()); + } + + @Test + public void seqNegOnInit() { + Log log = Log.builder().build(); + Assert.assertEquals(log.getSeq().intValue(), -1); + } + + @Test + public void mediaEmptyOnInit() { + Log log = Log.builder().build(); + Assert.assertEquals(log.getMedia(), null); + } + + @Test + public void exceptionsEmptyOnInit() { + Log log = Log.builder().build(); + Assert.assertEquals(log.getException(), null); + } + + @Test + public void addMediaDefault() { + Log log = Log.builder().build(); + Assert.assertFalse(log.hasMedia()); + } + + @Test + public void addMediaWithPathToLog() { + Media m = ScreenCapture.builder().path("./img.png").build(); + Log log = Log.builder().media(m).build(); + Assert.assertTrue(log.hasMedia()); + } + + @Test + public void addMediaWithResolvedPathToLog() { + Media m = ScreenCapture.builder().resolvedPath("./img.png").build(); + Log log = Log.builder().media(m).build(); + Assert.assertTrue(log.hasMedia()); + } +} diff --git a/src/test/java/com/aventstack/extentreports/entity/ReportEntityTest.java b/src/test/java/com/aventstack/extentreports/entity/ReportEntityTest.java new file mode 100644 index 0000000..619f5a8 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/entity/ReportEntityTest.java @@ -0,0 +1,171 @@ +package com.aventstack.extentreports.entity; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.testng.Assert; + +import com.aventstack.extentreports.ExtentReports; +import com.aventstack.extentreports.ExtentTest; +import com.aventstack.extentreports.Status; +import com.aventstack.extentreports.gherkin.model.Scenario; +import com.aventstack.extentreports.model.Author; +import com.aventstack.extentreports.model.Category; +import com.aventstack.extentreports.model.Device; +import com.aventstack.extentreports.model.ExceptionInfo; +import com.aventstack.extentreports.model.Log; +import com.aventstack.extentreports.model.Report; +import com.aventstack.extentreports.model.Test; +import com.aventstack.extentreports.model.context.NamedAttributeContextManager; +import com.aventstack.extentreports.model.service.TestService; + +public class ReportEntityTest { + private ExtentReports extent() { + return new ExtentReports(); + } + + @org.testng.annotations.Test + public void startAndEndTimesNonNullAtInit() { + Report report = Report.builder().build(); + Assert.assertNotNull(report.getStartTime()); + Assert.assertNotNull(report.getEndTime()); + } + + @org.testng.annotations.Test + public void startIsPassOnInit() { + Report report = Report.builder().build(); + Assert.assertEquals(report.getStatus(), Status.PASS); + } + + @org.testng.annotations.Test + public void testsEmptyOnInit() { + Report report = Report.builder().build(); + Assert.assertEquals(report.getTestList(), Collections.EMPTY_LIST); + } + + @org.testng.annotations.Test + public void statsNonNullAtInit() { + Report report = Report.builder().build(); + Assert.assertNotNull(report.getStats()); + } + + @org.testng.annotations.Test + public void reportTestListSize() { + Test test = TestService.createTest("Test"); + Report report = Report.builder().build(); + Assert.assertEquals(report.getTestList().size(), 0); + report.getTestList().add(test); + Assert.assertEquals(report.getTestList().size(), 1); + } + + @org.testng.annotations.Test + public void reportIsBDD() { + Test test = TestService.createTest("Test"); + Report report = Report.builder().build(); + Assert.assertFalse(report.isBDD()); + report.getTestList().add(test); + Assert.assertFalse(report.isBDD()); + test.setBddType(Scenario.class); + Assert.assertTrue(report.isBDD()); + } + + @org.testng.annotations.Test + public void reportTestHasStatus() { + Test test = TestService.createTest("Test"); + Log skip = Log.builder().status(Status.SKIP).build(); + Log pass = Log.builder().status(Status.PASS).build(); + Report report = Report.builder().build(); + report.getTestList().add(test); + Assert.assertTrue(report.anyTestHasStatus(Status.PASS)); + Assert.assertFalse(report.anyTestHasStatus(Status.SKIP)); + test.addLog(skip); + Assert.assertFalse(report.anyTestHasStatus(Status.PASS)); + Assert.assertTrue(report.anyTestHasStatus(Status.SKIP)); + test.addLog(pass); + Assert.assertFalse(report.anyTestHasStatus(Status.PASS)); + Assert.assertTrue(report.anyTestHasStatus(Status.SKIP)); + } + + @org.testng.annotations.Test + public void authorCtx() { + ExtentReports extent = extent(); + ExtentTest test = extent.createTest("Test"); + NamedAttributeContextManager context = extent.getReport().getAuthorCtx(); + Assert.assertFalse(context.hasItems()); + test.assignAuthor("x"); + Assert.assertTrue(context.hasItems()); + Assert.assertTrue(context.getSet().stream().anyMatch(x -> x.getAttr().getName().equals("x"))); + Assert.assertTrue(context.getSet().stream().anyMatch(x -> x.getTestList().size() == 1)); + Assert.assertTrue(context.getSet().stream() + .flatMap(x -> x.getTestList().stream()) + .anyMatch(x -> x.getName().equals("Test"))); + } + + @org.testng.annotations.Test + public void categoryCtx() { + ExtentReports extent = extent(); + ExtentTest test = extent.createTest("Test"); + NamedAttributeContextManager context = extent.getReport().getCategoryCtx(); + Assert.assertFalse(context.hasItems()); + test.assignCategory("x"); + Assert.assertTrue(context.hasItems()); + Assert.assertTrue(context.getSet().stream().anyMatch(x -> x.getAttr().getName().equals("x"))); + Assert.assertTrue(context.getSet().stream().anyMatch(x -> x.getTestList().size() == 1)); + Assert.assertTrue(context.getSet().stream() + .flatMap(x -> x.getTestList().stream()) + .anyMatch(x -> x.getName().equals("Test"))); + } + + @org.testng.annotations.Test + public void deviceCtx() { + ExtentReports extent = extent(); + ExtentTest test = extent.createTest("Test"); + NamedAttributeContextManager context = extent.getReport().getDeviceCtx(); + Assert.assertFalse(context.hasItems()); + test.assignDevice("x"); + Assert.assertTrue(context.hasItems()); + Assert.assertTrue(context.getSet().stream().anyMatch(x -> x.getAttr().getName().equals("x"))); + Assert.assertTrue(context.getSet().stream().anyMatch(x -> x.getTestList().size() == 1)); + Assert.assertTrue(context.getSet().stream() + .flatMap(x -> x.getTestList().stream()) + .anyMatch(x -> x.getName().equals("Test"))); + } + + @org.testng.annotations.Test + public void exceptionContext() { + String msg = "An exception has occurred."; + RuntimeException ex = new RuntimeException(msg); + ExtentReports extent = extent(); + ExtentTest test = extent.createTest("Test"); + NamedAttributeContextManager context = extent.getReport().getExceptionInfoCtx(); + Assert.assertFalse(context.hasItems()); + test.fail(ex); + test.assignDevice("x"); + Assert.assertTrue(context.hasItems()); + Assert.assertTrue( + context.getSet().stream().anyMatch(x -> x.getAttr().getName().equals("java.lang.RuntimeException"))); + Assert.assertTrue(context.getSet().stream().anyMatch(x -> x.getTestList().size() == 1)); + Assert.assertTrue(context.getSet().stream() + .flatMap(x -> x.getTestList().stream()) + .anyMatch(x -> x.getName().equals("Test"))); + } + + @org.testng.annotations.Test + public void testRunnerLogs() { + String[] s = new String[]{"Log 1", "Log 2", "Log 3"}; + ExtentReports extent = extent(); + List logs = extent.getReport().getLogs(); + Assert.assertTrue(logs.isEmpty()); + Arrays.stream(s).forEach(x -> extent.addTestRunnerOutput(x)); + Assert.assertFalse(logs.isEmpty()); + Arrays.stream(s).forEach(x -> Assert.assertTrue(logs.contains(x))); + } + + @org.testng.annotations.Test + public void timeTaken() { + Report report = Report.builder().build(); + long duration = report.timeTaken(); + Assert.assertTrue(duration < 5); + } +} diff --git a/src/test/java/com/aventstack/extentreports/entity/ReportStatsTest.java b/src/test/java/com/aventstack/extentreports/entity/ReportStatsTest.java new file mode 100644 index 0000000..b76055f --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/entity/ReportStatsTest.java @@ -0,0 +1,131 @@ +package com.aventstack.extentreports.entity; + +import java.util.Arrays; + +import org.testng.Assert; + +import com.aventstack.extentreports.AnalysisStrategy; +import com.aventstack.extentreports.Status; +import com.aventstack.extentreports.model.Report; +import com.aventstack.extentreports.model.ReportStats; +import com.aventstack.extentreports.model.Test; +import com.aventstack.extentreports.model.service.TestService; + +public class ReportStatsTest { + @org.testng.annotations.Test + public void analysisStrategyDefault() { + ReportStats stats = new ReportStats(); + Assert.assertNotNull(stats.getAnalysisStrategy()); + Assert.assertEquals(stats.getAnalysisStrategy(), AnalysisStrategy.TEST); + } + + @org.testng.annotations.Test + public void allLevelMapsNonNull() { + ReportStats stats = new ReportStats(); + Assert.assertNotNull(stats.getChild()); + Assert.assertNotNull(stats.getChildPercentage()); + Assert.assertNotNull(stats.getGrandchild()); + Assert.assertNotNull(stats.getGrandchildPercentage()); + Assert.assertNotNull(stats.getLog()); + Assert.assertNotNull(stats.getLogPercentage()); + Assert.assertNotNull(stats.getParent()); + Assert.assertNotNull(stats.getParentPercentage()); + } + + @org.testng.annotations.Test + public void statsSize() { + Test test = TestService.createTest("Test"); + Report report = Report.builder().build(); + report.getTestList().add(test); + Assert.assertEquals(report.getStats().getParent().size(), 0); + report.getStats().update(report.getTestList()); + Assert.assertEquals(report.getStats().getParent().size(), Status.values().length); + } + + @org.testng.annotations.Test + public void statsAll() { + Report report = Report.builder().build(); + report.getStats().update(report.getTestList()); + // check if all Status fields are present + Arrays.asList(Status.values()).forEach(x -> Assert.assertTrue(report.getStats().getParent().containsKey(x))); + Arrays.asList(Status.values()).forEach(x -> Assert.assertTrue(report.getStats().getChild().containsKey(x))); + Arrays.asList(Status.values()) + .forEach(x -> Assert.assertTrue(report.getStats().getGrandchild().containsKey(x))); + Assert.assertEquals(report.getStats().getParent().get(Status.PASS).longValue(), 0); + Assert.assertEquals(report.getStats().getParent().get(Status.FAIL).longValue(), 0); + Assert.assertEquals(report.getStats().getParent().get(Status.SKIP).longValue(), 0); + Assert.assertEquals(report.getStats().getParent().get(Status.WARNING).longValue(), 0); + Assert.assertEquals(report.getStats().getParent().get(Status.INFO).longValue(), 0); + Assert.assertEquals(report.getStats().getChild().get(Status.PASS).longValue(), 0); + Assert.assertEquals(report.getStats().getChild().get(Status.FAIL).longValue(), 0); + Assert.assertEquals(report.getStats().getChild().get(Status.SKIP).longValue(), 0); + Assert.assertEquals(report.getStats().getChild().get(Status.WARNING).longValue(), 0); + Assert.assertEquals(report.getStats().getChild().get(Status.INFO).longValue(), 0); + Assert.assertEquals(report.getStats().getGrandchild().get(Status.PASS).longValue(), 0); + Assert.assertEquals(report.getStats().getGrandchild().get(Status.FAIL).longValue(), 0); + Assert.assertEquals(report.getStats().getGrandchild().get(Status.SKIP).longValue(), 0); + Assert.assertEquals(report.getStats().getGrandchild().get(Status.WARNING).longValue(), 0); + Assert.assertEquals(report.getStats().getGrandchild().get(Status.INFO).longValue(), 0); + } + + @org.testng.annotations.Test + public void statsTestStatus() { + Test test = TestService.createTest("Test"); + Report report = Report.builder().build(); + report.getTestList().add(test); + report.getStats().update(report.getTestList()); + // check if all Status fields are present + Arrays.asList(Status.values()).forEach(x -> Assert.assertTrue(report.getStats().getParent().containsKey(x))); + Arrays.asList(Status.values()).forEach(x -> Assert.assertTrue(report.getStats().getChild().containsKey(x))); + Arrays.asList(Status.values()) + .forEach(x -> Assert.assertTrue(report.getStats().getGrandchild().containsKey(x))); + test.setStatus(Status.FAIL); + report.getStats().update(report.getTestList()); + Assert.assertEquals(report.getStats().getParent().get(Status.PASS).longValue(), 0); + Assert.assertEquals(report.getStats().getParent().get(Status.FAIL).longValue(), 1); + } + + @org.testng.annotations.Test + public void statsChildStatus() { + Test test = TestService.createTest("Test"); + Test node = TestService.createTest("Node"); + node.setStatus(Status.SKIP); + test.addChild(node); + Report report = Report.builder().build(); + report.getTestList().add(test); + report.getStats().update(report.getTestList()); + // check if all Status fields are present + Arrays.asList(Status.values()).forEach(x -> Assert.assertTrue(report.getStats().getParent().containsKey(x))); + Arrays.asList(Status.values()).forEach(x -> Assert.assertTrue(report.getStats().getChild().containsKey(x))); + Arrays.asList(Status.values()) + .forEach(x -> Assert.assertTrue(report.getStats().getGrandchild().containsKey(x))); + Assert.assertEquals(report.getStats().getParent().get(Status.PASS).longValue(), 0); + Assert.assertEquals(report.getStats().getParent().get(Status.SKIP).longValue(), 1); + Assert.assertEquals(report.getStats().getChild().get(Status.PASS).longValue(), 0); + Assert.assertEquals(report.getStats().getChild().get(Status.SKIP).longValue(), 1); + } + + @org.testng.annotations.Test + public void statsGrandchildStatus() { + Test test = TestService.createTest("Test"); + Test node = TestService.createTest("Node"); + Test grandchild = TestService.createTest("Grandchild"); + grandchild.setStatus(Status.FAIL); + node.addChild(grandchild); + test.addChild(node); + Report report = Report.builder().build(); + report.getTestList().add(test); + report.getStats().update(report.getTestList()); + // check if all Status fields are present + Arrays.asList(Status.values()).forEach(x -> Assert.assertTrue(report.getStats().getParent().containsKey(x))); + Arrays.asList(Status.values()).forEach(x -> Assert.assertTrue(report.getStats().getChild().containsKey(x))); + Arrays.asList(Status.values()) + .forEach(x -> Assert.assertTrue(report.getStats().getGrandchild().containsKey(x))); + Assert.assertEquals(report.getStats().getParent().get(Status.PASS).longValue(), 0); + Assert.assertEquals(report.getStats().getParent().get(Status.FAIL).longValue(), 1); + Assert.assertEquals(report.getStats().getChild().get(Status.PASS).longValue(), 0); + Assert.assertEquals(report.getStats().getChild().get(Status.FAIL).longValue(), 1); + Assert.assertEquals(report.getStats().getGrandchild().get(Status.PASS).longValue(), 0); + Assert.assertEquals(report.getStats().getGrandchild().get(Status.FAIL).longValue(), 1); + } +} diff --git a/src/test/java/com/aventstack/extentreports/entity/ScreenCaptureTest.java b/src/test/java/com/aventstack/extentreports/entity/ScreenCaptureTest.java new file mode 100644 index 0000000..72693e6 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/entity/ScreenCaptureTest.java @@ -0,0 +1,18 @@ +package com.aventstack.extentreports.entity; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.aventstack.extentreports.model.ScreenCapture; + +public class ScreenCaptureTest { + + @Test + public void initWithAllEntitiesNull() { + ScreenCapture capture = ScreenCapture.builder().build(); + Assert.assertNull(capture.getBase64()); + Assert.assertNull(capture.getPath()); + Assert.assertNull(capture.getResolvedPath()); + Assert.assertNull(capture.getTitle()); + } +} diff --git a/src/test/java/com/aventstack/extentreports/entity/StatusEntityTest.java b/src/test/java/com/aventstack/extentreports/entity/StatusEntityTest.java new file mode 100644 index 0000000..3ef9225 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/entity/StatusEntityTest.java @@ -0,0 +1,37 @@ +package com.aventstack.extentreports.entity; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.aventstack.extentreports.Status; + +public class StatusEntityTest { + + private List randomHierarchy() { + List list = Arrays.asList(Status.values()); + Collections.shuffle(list); + return list; + } + + @Test + public void statusMax() { + Assert.assertEquals(Status.max(randomHierarchy()), Status.FAIL); + } + + @Test + public void statusMin() { + Assert.assertEquals(Status.min(randomHierarchy()), Status.INFO); + } + + @Test + public void statusHierarchy() { + List list = Status.getResolvedHierarchy(randomHierarchy()); + Assert.assertTrue(list.get(0).equals(Status.INFO)); + Assert.assertTrue(list.get(Status.values().length - 1).equals(Status.FAIL)); + } + +} diff --git a/src/test/java/com/aventstack/extentreports/entity/TestEntityInitTest.java b/src/test/java/com/aventstack/extentreports/entity/TestEntityInitTest.java new file mode 100644 index 0000000..6bf09d2 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/entity/TestEntityInitTest.java @@ -0,0 +1,84 @@ +package com.aventstack.extentreports.entity; + +import java.util.Collections; + +import org.testng.Assert; + +import com.aventstack.extentreports.Status; +import com.aventstack.extentreports.model.Test; + +public class TestEntityInitTest { + + @org.testng.annotations.Test + public void startAndEndTimesNonNullAtInit() { + Test test = Test.builder().build(); + Assert.assertNotNull(test.getStartTime()); + Assert.assertNotNull(test.getEndTime()); + } + + @org.testng.annotations.Test + public void startIsPassOnInit() { + Test test = Test.builder().build(); + Assert.assertEquals(test.getStatus(), Status.PASS); + } + + @org.testng.annotations.Test + public void levelIs0OnInit() { + Test test = Test.builder().build(); + Assert.assertEquals(test.getLevel().intValue(), 0); + } + + @org.testng.annotations.Test + public void testIsLeafOnInit() { + Test test = Test.builder().build(); + Assert.assertEquals(test.isLeaf(), true); + } + + @org.testng.annotations.Test + public void childrenEmptyOnInit() { + Test test = Test.builder().build(); + Assert.assertEquals(test.getChildren(), Collections.EMPTY_LIST); + } + + @org.testng.annotations.Test + public void logsEmptyOnInit() { + Test test = Test.builder().build(); + Assert.assertEquals(test.getLogs(), Collections.EMPTY_LIST); + } + + @org.testng.annotations.Test + public void authorsEmptyOnInit() { + Test test = Test.builder().build(); + Assert.assertEquals(test.getAuthorSet(), Collections.EMPTY_SET); + } + + @org.testng.annotations.Test + public void devicesEmptyOnInit() { + Test test = Test.builder().build(); + Assert.assertEquals(test.getDeviceSet(), Collections.EMPTY_SET); + } + + @org.testng.annotations.Test + public void tagEmptyOnInit() { + Test test = Test.builder().build(); + Assert.assertEquals(test.getCategorySet(), Collections.EMPTY_SET); + } + + @org.testng.annotations.Test + public void testId1OrGreaterOnInit() { + Test test = Test.builder().build(); + Assert.assertNotEquals(test.getId(), 0); + } + + @org.testng.annotations.Test + public void descriptionNullOnInit() { + Test test = Test.builder().build(); + Assert.assertNull(test.getDescription()); + } + + @org.testng.annotations.Test + public void parentNullOnInit() { + Test test = Test.builder().build(); + Assert.assertNull(test.getParent()); + } +} diff --git a/src/test/java/com/aventstack/extentreports/entity/TestEntityTest.java b/src/test/java/com/aventstack/extentreports/entity/TestEntityTest.java new file mode 100644 index 0000000..e7d1643 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/entity/TestEntityTest.java @@ -0,0 +1,321 @@ +package com.aventstack.extentreports.entity; + +import java.lang.reflect.Method; + +import org.testng.Assert; + +import com.aventstack.extentreports.Status; +import com.aventstack.extentreports.gherkin.model.Scenario; +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; +import com.aventstack.extentreports.model.service.TestService; + +public class TestEntityTest { + private static final String DESCRIPTION = "test.description"; + + private Test getTest() { + return TestService.createTest("Test"); + } + + @org.testng.annotations.Test + public void logSeqIncrements(Method method) { + Test test = TestService.createTest(method.getName()); + Log log = Log.builder().build(); + test.addLog(log); + Assert.assertEquals(log.getSeq().intValue(), 0); + test.addLog(log); + Assert.assertEquals(log.getSeq().intValue(), 1); + test.addLog(log); + Assert.assertEquals(log.getSeq().intValue(), 2); + } + + @org.testng.annotations.Test + public void testEntities(Method method) { + Test test = TestService.createTest(method.getName()); + Assert.assertEquals(test.getAuthorSet().size(), 0); + Assert.assertEquals(test.getDeviceSet().size(), 0); + Assert.assertEquals(test.getCategorySet().size(), 0); + Assert.assertEquals(test.getChildren().size(), 0); + Assert.assertTrue(test.isLeaf()); + Assert.assertEquals(test.getLevel().intValue(), 0); + Assert.assertEquals(test.getStatus(), Status.PASS); + Assert.assertNull(test.getDescription()); + } + + @org.testng.annotations.Test(expectedExceptions = IllegalArgumentException.class) + public void addChildToNullTest() { + Test test = TestService.createTest("Test", DESCRIPTION); + test.addChild(null); + } + + @org.testng.annotations.Test + public void addChildToTest() { + Test test = getTest(); + Test node = TestService.createTest("Node", ""); + test.addChild(node); + Assert.assertEquals(test.getChildren().size(), 1); + test.addChild(node); + Assert.assertEquals(test.getChildren().size(), 2); + } + + @org.testng.annotations.Test + public void addChildToTestLevel() { + Test test = getTest(); + Test node = TestService.createTest("Node", ""); + test.addChild(node); + Assert.assertEquals(test.getLevel().intValue(), 0); + Assert.assertEquals(node.getLevel().intValue(), 1); + } + + @org.testng.annotations.Test + public void addChildToTestLeaf() { + Test test = getTest(); + Test node = TestService.createTest("Node", ""); + test.addChild(node); + Assert.assertFalse(test.isLeaf()); + Assert.assertTrue(node.isLeaf()); + } + + @org.testng.annotations.Test(expectedExceptions = IllegalArgumentException.class) + public void addNullLogToTest() { + Test test = getTest(); + test.addLog(null); + } + + @org.testng.annotations.Test + public void addLogToTest() { + Test test = getTest(); + Log log = Log.builder().build(); + test.addLog(log); + Assert.assertEquals(log.getSeq().intValue(), 0); + Assert.assertEquals(test.getLogs().size(), 1); + Assert.assertEquals(test.getStatus(), Status.PASS); + Assert.assertEquals(log.getStatus(), Status.PASS); + } + + @org.testng.annotations.Test + public void addSkipLogToTest() { + Test test = getTest(); + Log log = Log.builder().status(Status.SKIP).build(); + test.addLog(log); + Assert.assertEquals(test.getStatus(), Status.SKIP); + Assert.assertEquals(log.getStatus(), Status.SKIP); + } + + @org.testng.annotations.Test + public void addFailLogToTest() { + Test test = getTest(); + Log log = Log.builder().status(Status.FAIL).build(); + test.addLog(log); + Assert.assertEquals(test.getStatus(), Status.FAIL); + Assert.assertEquals(log.getStatus(), Status.FAIL); + } + + @org.testng.annotations.Test + public void testHasLog() { + Test test = getTest(); + Assert.assertFalse(test.hasLog()); + Log log = Log.builder().status(Status.FAIL).build(); + test.addLog(log); + Assert.assertTrue(test.hasLog()); + } + + @org.testng.annotations.Test + public void isTestBDD() { + Test test = getTest(); + Assert.assertFalse(test.isBDD()); + test.setBddType(Scenario.class); + Assert.assertTrue(test.isBDD()); + } + + @org.testng.annotations.Test + public void testHasChildren() { + Test test = getTest(); + Assert.assertFalse(test.hasChildren()); + test.addChild(TestService.createTest("Node", "")); + Assert.assertTrue(test.hasChildren()); + } + + @org.testng.annotations.Test + public void testStatusWithoutLog() { + Test test = getTest(); + Assert.assertEquals(test.getStatus(), Status.PASS); + } + + @org.testng.annotations.Test + public void testStatusWithLog() { + Test test = getTest(); + Assert.assertEquals(test.getStatus(), Status.PASS); + Log log = Log.builder().status(Status.FAIL).build(); + test.addLog(log); + Assert.assertEquals(test.getStatus(), Status.FAIL); + } + + @org.testng.annotations.Test + public void testStatusWithLogStatusChanged() { + Test test = getTest(); + Assert.assertEquals(test.getStatus(), Status.PASS); + Log log = Log.builder().status(Status.SKIP).build(); + test.addLog(log); + Assert.assertEquals(test.getStatus(), Status.SKIP); + log.setStatus(Status.FAIL); + test.updateResult(); + Assert.assertEquals(test.getStatus(), Status.FAIL); + } + + @org.testng.annotations.Test + public void hasAuthor() { + Test test = getTest(); + Assert.assertFalse(test.hasAuthor()); + test.getAuthorSet().add(new Author("x")); + Assert.assertTrue(test.hasAuthor()); + } + + @org.testng.annotations.Test + public void hasCategory() { + Test test = getTest(); + Assert.assertFalse(test.hasDevice()); + test.getCategorySet().add(new Category("x")); + Assert.assertTrue(test.hasCategory()); + } + + @org.testng.annotations.Test + public void hasDevice() { + Test test = getTest(); + Assert.assertFalse(test.hasDevice()); + test.getDeviceSet().add(new Device("x")); + Assert.assertTrue(test.hasDevice()); + } + + @org.testng.annotations.Test + public void hasAttributes() { + Test test = getTest(); + Assert.assertFalse(test.hasAttributes()); + test.getAuthorSet().add(new Author("x")); + Assert.assertTrue(test.hasAttributes()); + test = TestService.createTest("Test", ""); + test.getDeviceSet().add(new Device("x")); + Assert.assertTrue(test.hasAttributes()); + test = TestService.createTest("Test", ""); + test.getCategorySet().add(new Category("x")); + Assert.assertTrue(test.hasAttributes()); + } + + @org.testng.annotations.Test + public void testFullName() { + String[] name = new String[]{"Test", "Child", "Grandchild"}; + Test test = TestService.createTest(name[0], ""); + Test child = TestService.createTest(name[1], ""); + test.addChild(child); + Test grandchild = TestService.createTest(name[2], ""); + child.addChild(grandchild); + Assert.assertEquals(test.getFullName(), name[0]); + Assert.assertEquals(child.getFullName(), name[0] + "." + name[1]); + Assert.assertEquals(grandchild.getFullName(), + name[0] + "." + name[1] + "." + name[2]); + } + + @org.testng.annotations.Test + public void hasScreenCapture() { + Test test = getTest(); + Assert.assertFalse(test.hasScreenCapture()); + test.addMedia(ScreenCapture.builder().build()); + Assert.assertFalse(test.hasScreenCapture()); + test.addMedia(ScreenCapture.builder().path("/img.png").build()); + Assert.assertTrue(test.hasScreenCapture()); + } + + @org.testng.annotations.Test + public void computeTestStatusNoLog() { + Test test = getTest(); + test.updateResult(); + Assert.assertEquals(test.getStatus(), Status.PASS); + } + + @org.testng.annotations.Test + public void computeTestStatusSkipLog() { + Test test = getTest(); + test.getLogs().add(Log.builder().status(Status.SKIP).build()); + test.updateResult(); + Assert.assertEquals(test.getStatus(), Status.SKIP); + } + + @org.testng.annotations.Test + public void computeTestStatusSkipAndFailLog() { + Test test = getTest(); + test.getLogs().add(Log.builder().status(Status.SKIP).build()); + test.getLogs().add(Log.builder().status(Status.FAIL).build()); + test.updateResult(); + Assert.assertEquals(test.getStatus(), Status.FAIL); + } + + @org.testng.annotations.Test + public void computeTestStatusNode() { + Test parent = getTest(); + Test node = getTest(); + parent.addChild(node); + node.getLogs().add(Log.builder().status(Status.SKIP).build()); + parent.updateResult(); + Assert.assertEquals(parent.getStatus(), Status.SKIP); + Assert.assertEquals(node.getStatus(), Status.SKIP); + node.getLogs().add(Log.builder().status(Status.FAIL).build()); + parent.updateResult(); + Assert.assertEquals(parent.getStatus(), Status.FAIL); + Assert.assertEquals(node.getStatus(), Status.FAIL); + } + + @org.testng.annotations.Test + public void ancestor() { + Test parent = TestService.createTest("Ancestor"); + Test node = TestService.createTest("Node"); + Test child = TestService.createTest("Child"); + parent.addChild(node); + node.addChild(child); + Assert.assertEquals(parent.getAncestor(), parent); + Assert.assertEquals(node.getAncestor(), parent); + Assert.assertEquals(child.getAncestor(), parent); + } + + @org.testng.annotations.Test + public void generatedLog() { + Test test = getTest(); + Log log = Log.builder().status(Status.SKIP).details("details").build(); + test.addGeneratedLog(log); + Assert.assertEquals(test.getGeneratedLog().size(), 1); + Assert.assertEquals(test.getLogs().size(), 0); + Assert.assertEquals(test.getStatus(), Status.SKIP); + } + + @org.testng.annotations.Test + public void testHasAngLogWithNoLogs() { + Test test = getTest(); + Assert.assertFalse(test.hasAnyLog()); + } + + @org.testng.annotations.Test + public void testHasAngLogWithLog() { + Test test = getTest(); + Log log = Log.builder().status(Status.SKIP).details("details").build(); + test.addLog(log); + Assert.assertTrue(test.hasAnyLog()); + } + + @org.testng.annotations.Test + public void testHasAngLogWithGeneratedLog() { + Test test = getTest(); + Log log = Log.builder().status(Status.SKIP).details("details").build(); + test.addGeneratedLog(log); + Assert.assertTrue(test.hasAnyLog()); + } + + @org.testng.annotations.Test + public void timeTaken() { + Test test = getTest(); + long duration = test.timeTaken(); + Assert.assertTrue(duration < 5); + } +} diff --git a/src/test/java/com/aventstack/extentreports/entity/service/ExceptionInfoServiceTest.java b/src/test/java/com/aventstack/extentreports/entity/service/ExceptionInfoServiceTest.java new file mode 100644 index 0000000..91d4571 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/entity/service/ExceptionInfoServiceTest.java @@ -0,0 +1,16 @@ +package com.aventstack.extentreports.entity.service; + +import org.testng.Assert; + +import com.aventstack.extentreports.model.ExceptionInfo; +import com.aventstack.extentreports.model.service.ExceptionInfoService; + +public class ExceptionInfoServiceTest { + @org.testng.annotations.Test + public void exceptionInfo() { + RuntimeException ex = new RuntimeException("ERROR"); + ExceptionInfo info = ExceptionInfoService.createExceptionInfo(ex); + Assert.assertEquals(info.getException(), ex); + Assert.assertEquals(info.getName(), "java.lang.RuntimeException"); + } +} diff --git a/src/test/java/com/aventstack/extentreports/entity/service/TestServiceTest.java b/src/test/java/com/aventstack/extentreports/entity/service/TestServiceTest.java new file mode 100644 index 0000000..bd8ebe5 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/entity/service/TestServiceTest.java @@ -0,0 +1,143 @@ +package com.aventstack.extentreports.entity.service; + +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.List; + +import org.testng.Assert; + +import com.aventstack.extentreports.GherkinKeyword; +import com.aventstack.extentreports.Status; +import com.aventstack.extentreports.gherkin.GherkinDialectManager; +import com.aventstack.extentreports.gherkin.model.Scenario; +import com.aventstack.extentreports.model.Log; +import com.aventstack.extentreports.model.ScreenCapture; +import com.aventstack.extentreports.model.Test; +import com.aventstack.extentreports.model.service.TestService; + +public class TestServiceTest { + private static final String DESCRIPTION = "test.description"; + + private Test getTest() { + return TestService.createTest("Test"); + } + + @org.testng.annotations.Test(expectedExceptions = IllegalArgumentException.class) + public void testWithNullName() { + TestService.createTest(null); + } + + @org.testng.annotations.Test(expectedExceptions = IllegalArgumentException.class) + public void testWithEmptyName() { + TestService.createTest(""); + } + + @org.testng.annotations.Test(expectedExceptions = IllegalArgumentException.class) + public void testWithNullName2() { + TestService.createTest(null, DESCRIPTION); + } + + @org.testng.annotations.Test(expectedExceptions = IllegalArgumentException.class) + public void testWithEmptyName2() { + TestService.createTest("", DESCRIPTION); + } + + @org.testng.annotations.Test + public void testWithNullDescription() { + Test test = TestService.createTest("Test", null); + Assert.assertNull(test.getDescription()); + } + + @org.testng.annotations.Test + public void testWithEmptyDescription() { + Test test = TestService.createTest("Test", ""); + Assert.assertEquals(test.getDescription(), ""); + } + + @org.testng.annotations.Test + public void testWithDescription() { + Test test = TestService.createTest("Test", DESCRIPTION); + Assert.assertEquals(test.getDescription(), DESCRIPTION); + } + + @org.testng.annotations.Test + public void testWithNullBddType() { + Test test = TestService.createTest(null, "Test", DESCRIPTION); + Assert.assertEquals(test.getBddType(), null); + } + + @org.testng.annotations.Test + public void testWithBddType() { + Test test = TestService.createTest(Scenario.class, "Test", DESCRIPTION); + Assert.assertEquals(test.getBddType(), Scenario.class); + } + + @org.testng.annotations.Test + public void testWithBddTypeGherkinKeyword() throws ClassNotFoundException, UnsupportedEncodingException { + GherkinDialectManager.setLanguage("en"); + GherkinKeyword keyword = new GherkinKeyword("Scenario"); + Test test = TestService.createTest(keyword.getClazz(), "Test", DESCRIPTION); + Assert.assertEquals(test.getBddType(), keyword.getClazz()); + } + + @org.testng.annotations.Test + public void deleteTest() { + Test test1 = TestService.createTest("Test1", ""); + Test test2 = TestService.createTest("Test2", ""); + List list = new ArrayList<>(); + list.add(test1); + list.add(test2); + Assert.assertEquals(list.size(), 2); + TestService.deleteTest(list, test1); + Assert.assertEquals(list.size(), 1); + Assert.assertEquals(list.get(0).getName(), "Test2"); + } + + @org.testng.annotations.Test + public void deleteNode() { + Test test1 = TestService.createTest("Test1", ""); + Test test2 = TestService.createTest("Test2", ""); + Test child = TestService.createTest("Child", ""); + test1.addChild(child); + List list = new ArrayList<>(); + list.add(test1); + list.add(test2); + Assert.assertEquals(list.size(), 2); + Assert.assertEquals(list.get(0).getChildren().size(), 1); + TestService.deleteTest(list, child); + Assert.assertEquals(list.size(), 2); + Assert.assertEquals(list.get(0).getChildren().size(), 0); + } + + @org.testng.annotations.Test + public void testHasScreenCaptureDeepLog() { + Test test = getTest(); + Log log = Log.builder().status(Status.PASS).details("").build(); + log.addMedia(ScreenCapture.builder().path("/img.png").build()); + test.addLog(log); + Assert.assertFalse(test.hasScreenCapture()); + Assert.assertTrue(TestService.testHasScreenCapture(test, true)); + } + + @org.testng.annotations.Test + public void testHasScreenCaptureDeepNode() { + Test test = getTest(); + Test node = getTest(); + test.getChildren().add(node); + node.addMedia(ScreenCapture.builder().path("/img.png").build()); + Assert.assertFalse(test.hasScreenCapture()); + Assert.assertTrue(TestService.testHasScreenCapture(test, true)); + } + + @org.testng.annotations.Test + public void testHasScreenCaptureDeepNodeLog() { + Test test = getTest(); + Test node = getTest(); + test.getChildren().add(node); + Log log = Log.builder().status(Status.PASS).details("").build(); + log.addMedia(ScreenCapture.builder().path("/img.png").build()); + node.addLog(log); + Assert.assertFalse(test.hasScreenCapture()); + Assert.assertTrue(TestService.testHasScreenCapture(test, true)); + } +} diff --git a/src/test/java/com/aventstack/extentreports/api/GherkinKeywordTest.java b/src/test/java/com/aventstack/extentreports/gherkin/GherkinKeywordTest.java similarity index 90% rename from src/test/java/com/aventstack/extentreports/api/GherkinKeywordTest.java rename to src/test/java/com/aventstack/extentreports/gherkin/GherkinKeywordTest.java index bc5f96a..659507e 100644 --- a/src/test/java/com/aventstack/extentreports/api/GherkinKeywordTest.java +++ b/src/test/java/com/aventstack/extentreports/gherkin/GherkinKeywordTest.java @@ -1,11 +1,11 @@ -package com.aventstack.extentreports.api; +package com.aventstack.extentreports.gherkin; import java.io.UnsupportedEncodingException; import org.testng.Assert; import org.testng.annotations.Test; -import com.aventstack.extentreports.Base; +import com.aventstack.extentreports.ExtentReports; import com.aventstack.extentreports.ExtentTest; import com.aventstack.extentreports.GherkinKeyword; import com.aventstack.extentreports.gherkin.model.And; @@ -15,10 +15,14 @@ import com.aventstack.extentreports.gherkin.model.Then; import com.aventstack.extentreports.gherkin.model.When; -public class GherkinKeywordTest extends Base { - +public class GherkinKeywordTest { + private ExtentReports extent() { + return new ExtentReports(); + } + @Test public void testEnglishGherkinKeywords() throws ClassNotFoundException, UnsupportedEncodingException { + ExtentReports extent = extent(); extent.setGherkinDialect("en"); ExtentTest feature = extent.createTest(new GherkinKeyword("Feature"), "Refund item VM"); @@ -26,7 +30,7 @@ public void testEnglishGherkinKeywords() throws ClassNotFoundException, Unsuppor ExtentTest given = scenario.createNode(new GherkinKeyword("Given"), "Jeff has bought a microwave for $100").skip("skip"); ExtentTest and = scenario.createNode(new GherkinKeyword("And"), "he has a receipt").pass("pass"); ExtentTest when = scenario.createNode(new GherkinKeyword("When"), "he returns the microwave").pass("pass"); - ExtentTest then = scenario.createNode(new GherkinKeyword("Then"), "Jeff should be refunded $100").error("error"); + ExtentTest then = scenario.createNode(new GherkinKeyword("Then"), "Jeff should be refunded $100").skip("skip"); Assert.assertEquals(feature.getModel().getBddType(), Feature.class); Assert.assertEquals(scenario.getModel().getBddType(), Scenario.class); @@ -38,6 +42,7 @@ public void testEnglishGherkinKeywords() throws ClassNotFoundException, Unsuppor @Test public void testGermanGherkinKeywords() throws ClassNotFoundException, UnsupportedEncodingException { + ExtentReports extent = extent(); extent.setGherkinDialect("de"); ExtentTest feature = extent.createTest(new GherkinKeyword("Funktionalität"), "Refund item VM"); @@ -45,7 +50,7 @@ public void testGermanGherkinKeywords() throws ClassNotFoundException, Unsupport ExtentTest given = scenario.createNode(new GherkinKeyword("Angenommen"), "Jeff has bought a microwave for $100").skip("skip"); ExtentTest and = scenario.createNode(new GherkinKeyword("Und"), "he has a receipt").pass("pass"); ExtentTest when = scenario.createNode(new GherkinKeyword("Wenn"), "he returns the microwave").pass("pass"); - ExtentTest then = scenario.createNode(new GherkinKeyword("Dann"), "Jeff should be refunded $100").error("error"); + ExtentTest then = scenario.createNode(new GherkinKeyword("Dann"), "Jeff should be refunded $100").skip("skip"); Assert.assertEquals(feature.getModel().getBddType(), Feature.class); Assert.assertEquals(scenario.getModel().getBddType(), Scenario.class); @@ -59,7 +64,7 @@ public void testGermanGherkinKeywords() throws ClassNotFoundException, Unsupport public void testMixedGherkinKeywords() throws UnsupportedEncodingException, ClassNotFoundException { ExtentTest and = null, when = null, then = null; - // set German dialect + ExtentReports extent = extent(); extent.setGherkinDialect("de"); // the below tests should pass since GherkinKeywords are valid German words @@ -82,11 +87,11 @@ public void testMixedGherkinKeywords() throws UnsupportedEncodingException, Clas } catch (ClassNotFoundException e) { } try { - then = scenario.createNode(new GherkinKeyword("Then"), "Jeff should be refunded $100").error("error"); + then = scenario.createNode(new GherkinKeyword("Then"), "Jeff should be refunded $100").skip("skip"); } catch (ClassNotFoundException e) { } Assert.assertEquals(and, null); Assert.assertEquals(when, null); Assert.assertEquals(then, null); } -} +} \ No newline at end of file diff --git a/src/test/java/com/aventstack/extentreports/api/GherkinNameTest.java b/src/test/java/com/aventstack/extentreports/gherkin/GherkinNameTest.java similarity index 96% rename from src/test/java/com/aventstack/extentreports/api/GherkinNameTest.java rename to src/test/java/com/aventstack/extentreports/gherkin/GherkinNameTest.java index 2ab6317..b3a9162 100644 --- a/src/test/java/com/aventstack/extentreports/api/GherkinNameTest.java +++ b/src/test/java/com/aventstack/extentreports/gherkin/GherkinNameTest.java @@ -1,4 +1,4 @@ -package com.aventstack.extentreports.api; +package com.aventstack.extentreports.gherkin; import org.testng.Assert; import org.testng.annotations.Test; @@ -15,7 +15,6 @@ import com.aventstack.extentreports.gherkin.model.When; public class GherkinNameTest { - private static final String AND = "And"; private static final String ASTERISK = "*"; private static final String BACKGROUND = "Background"; @@ -26,105 +25,104 @@ public class GherkinNameTest { private static final String SCENARIO_OUTLINE = "Scenario Outline"; private static final String THEN = "Then"; private static final String WHEN = "When"; - + @Test public void testAndGherkinName() { Assert.assertTrue(And.getGherkinName().equals(AND)); } - + @Test public void testAndToString() { Assert.assertTrue(new And().toString().equals(AND)); } - + @Test public void testAsteriskGherkinName() { Assert.assertTrue(Asterisk.getGherkinName().equals(ASTERISK)); } - + @Test public void testAsteriskToString() { Assert.assertTrue(new Asterisk().toString().equals(ASTERISK)); } - + @Test public void testBackgroundGherkinName() { Assert.assertTrue(Background.getGherkinName().equals(BACKGROUND)); } - + @Test public void testBackgroundToString() { Assert.assertTrue(new Background().toString().equals(BACKGROUND)); } - + @Test public void testButGherkinName() { Assert.assertTrue(But.getGherkinName().equals(BUT)); } - + @Test public void testButToString() { Assert.assertTrue(new But().toString().equals(BUT)); } - + @Test public void testFeatureGherkinName() { Assert.assertTrue(Feature.getGherkinName().equals(FEATURE)); } - + @Test public void testFeatureToString() { Assert.assertTrue(new Feature().toString().equals(FEATURE)); } - + @Test public void testGivenGherkinName() { Assert.assertTrue(Given.getGherkinName().equals(GIVEN)); } - + @Test public void testGivenToString() { Assert.assertTrue(new Given().toString().equals(GIVEN)); } - + @Test public void testScenarioGherkinName() { Assert.assertTrue(Scenario.getGherkinName().equals(SCENARIO)); } - + @Test public void testScenarioToString() { Assert.assertTrue(new Scenario().toString().equals(SCENARIO)); } - + @Test public void testScenarioOutlineGherkinName() { Assert.assertTrue(ScenarioOutline.getGherkinName().equals(SCENARIO_OUTLINE)); } - + @Test public void testScenarioOutlineToString() { Assert.assertTrue(new ScenarioOutline().toString().equals(SCENARIO_OUTLINE)); } - + @Test public void testThenGherkinName() { Assert.assertTrue(Then.getGherkinName().equals(THEN)); } - + @Test public void testThenToString() { Assert.assertTrue(new Then().toString().equals(THEN)); } - + @Test public void testWhenGherkinName() { Assert.assertTrue(When.getGherkinName().equals(WHEN)); } - + @Test public void testWhenToString() { Assert.assertTrue(new When().toString().equals(WHEN)); } - -} +} \ No newline at end of file diff --git a/src/test/java/com/aventstack/extentreports/listenertests/ListenerTest.java b/src/test/java/com/aventstack/extentreports/listenertests/ListenerTest.java deleted file mode 100644 index b03f9c9..0000000 --- a/src/test/java/com/aventstack/extentreports/listenertests/ListenerTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.aventstack.extentreports.listenertests; - -import org.testng.Assert; -import org.testng.Reporter; -import org.testng.SkipException; -import org.testng.annotations.Listeners; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Status; -import com.aventstack.extentreports.common.ExtentTestNGListener; - -@Listeners(ExtentTestNGListener.class) -public class ListenerTest { - - @Test(groups = "pass") - public void passTest() { - Reporter.log("Started passTest"); - try { Thread.sleep(20); } catch(Exception e) { } - Assert.assertEquals(Status.PASS, Status.PASS); - } - - @Test(expectedExceptions = SkipException.class, groups = "skip") - public void skipTest() { - try { Thread.sleep(20); } catch(Exception e) { } - throw new SkipException("Intentionally skipped test."); - } - - @Test(expectedExceptions = RuntimeException.class, groups = "fail") - public void failTest() { - try { Thread.sleep(20); } catch(Exception e) { } - throw new RuntimeException("Intentionally failed test."); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/listenertests/ListenerTestsIReporterTest.java b/src/test/java/com/aventstack/extentreports/listenertests/ListenerTestsIReporterTest.java deleted file mode 100644 index b4edd2e..0000000 --- a/src/test/java/com/aventstack/extentreports/listenertests/ListenerTestsIReporterTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.aventstack.extentreports.listenertests; - -import org.testng.Assert; -import org.testng.Reporter; -import org.testng.SkipException; -import org.testng.annotations.Listeners; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Status; -import com.aventstack.extentreports.common.ExtentTestNGIReporterListener; - -@Listeners(ExtentTestNGIReporterListener.class) -public class ListenerTestsIReporterTest { - - @Test(groups = "pass") - public void passTest() { - Reporter.log("Started passTest"); - try { Thread.sleep(20); } catch(Exception e) { } - Assert.assertEquals(Status.PASS, Status.PASS); - } - - @Test(expectedExceptions = SkipException.class, groups = "skip") - public void skipTest() { - try { Thread.sleep(20); } catch(Exception e) { } - throw new SkipException("Intentionally skipped test."); - } - - @Test(expectedExceptions = RuntimeException.class, groups = "fail") - public void failTest() { - try { Thread.sleep(20); } catch(Exception e) { } - throw new RuntimeException("Intentionally failed test."); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/listenertests/ListenerTestsITestListenerTest.java b/src/test/java/com/aventstack/extentreports/listenertests/ListenerTestsITestListenerTest.java deleted file mode 100644 index 04975f5..0000000 --- a/src/test/java/com/aventstack/extentreports/listenertests/ListenerTestsITestListenerTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.aventstack.extentreports.listenertests; - -import org.testng.Assert; -import org.testng.Reporter; -import org.testng.SkipException; -import org.testng.annotations.Listeners; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Status; -import com.aventstack.extentreports.common.ExtentTestNGITestListener; - -@Listeners(ExtentTestNGITestListener.class) -public class ListenerTestsITestListenerTest { - - @Test(groups = "pass") - public void passTest() { - Reporter.log("Started passTest"); - try { Thread.sleep(20); } catch(Exception e) { } - Assert.assertEquals(Status.PASS, Status.PASS); - } - - @Test(expectedExceptions = SkipException.class, groups = "skip") - public void skipTest() { - try { Thread.sleep(20); } catch(Exception e) { } - throw new SkipException("Intentionally skipped test."); - } - - @Test(expectedExceptions = RuntimeException.class, groups = "fail") - public void failTest() { - try { Thread.sleep(20); } catch(Exception e) { } - throw new RuntimeException("Intentionally failed test."); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/markuputils/CodeBlockMarkupTest.java b/src/test/java/com/aventstack/extentreports/markuputils/CodeBlockMarkupTest.java new file mode 100644 index 0000000..bbd3aac --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/markuputils/CodeBlockMarkupTest.java @@ -0,0 +1,91 @@ +package com.aventstack.extentreports.markuputils; + +import org.testng.Assert; +import org.testng.annotations.Test; + +public class CodeBlockMarkupTest { + + @Test + public void nullCodeBlockContent() { + Markup m = MarkupHelper.createCodeBlock(null); + Assert.assertEquals(m.getMarkup(), ""); + } + + @Test + public void xmlCodeBlock() { + String xml = "value"; + Markup m = MarkupHelper.createCodeBlock(xml); + Assert.assertTrue(m.getMarkup().contains(xml)); + } + + @Test + public void xmlCodeBlockWithLang() { + String xml = "value"; + Markup m = MarkupHelper.createCodeBlock(xml, CodeLanguage.XML); + Assert.assertTrue(m.getMarkup().contains(xml)); + } + + @Test + public void jsonCodeBlock() { + String json = "{ 'key': 'value' }"; + Markup m = MarkupHelper.createCodeBlock(json); + Assert.assertTrue(m.getMarkup().contains(json)); + } + + @Test(priority = 1) + public void jsonCodeBlockWithLang() { + String json = "{ 'key': 'value' }"; + Markup m = MarkupHelper.createCodeBlock(json, CodeLanguage.JSON); + Assert.assertTrue(m.getMarkup().contains(json)); + Assert.assertTrue(m.getMarkup().contains("jsonTreeCreate")); + Assert.assertTrue(m.getMarkup().contains("")); + } + + @Test(priority = 2) + public void jsonCodeBlockWithLangMultiple() { + String json = "{ 'key': 'value' }"; + Markup m = MarkupHelper.createCodeBlock(json, CodeLanguage.JSON); + Assert.assertTrue(m.getMarkup().contains(json)); + Assert.assertTrue(m.getMarkup().contains("jsonTreeCreate")); + Assert.assertTrue(m.getMarkup().contains("")); + m = MarkupHelper.createCodeBlock(json, CodeLanguage.JSON); + Assert.assertTrue(m.getMarkup().contains(json)); + Assert.assertTrue(m.getMarkup().contains("jsonTreeCreate")); + Assert.assertTrue(m.getMarkup().contains("")); + } + + @Test + public void multipleCodeBlocks1() { + String xml = "value"; + Markup m = MarkupHelper.createCodeBlocks(new String[]{xml}); + String s = m.getMarkup(); + Assert.assertTrue(s.contains("col-md-12")); + } + + @Test + public void multipleCodeBlocks2() { + String xml = "value"; + Markup m = MarkupHelper.createCodeBlocks(new String[]{xml, xml}); + String s = m.getMarkup(); + Assert.assertTrue(s.contains("col-md-6")); + } + + @Test + public void multipleCodeBlocks3() { + String xml = "value"; + Markup m = MarkupHelper.createCodeBlocks(new String[]{xml, xml, xml}); + String s = m.getMarkup(); + Assert.assertTrue(s.contains("col-md-4")); + } + + @Test + public void multipleCodeBlocks4() { + String xml = "value"; + Markup m = MarkupHelper.createCodeBlocks(new String[]{xml, xml, xml, xml}); + String s = m.getMarkup(); + Assert.assertTrue(s.contains("col-md-3")); + } +} diff --git a/src/test/java/com/aventstack/extentreports/markuputils/Foo.java b/src/test/java/com/aventstack/extentreports/markuputils/Foo.java new file mode 100644 index 0000000..97e77e2 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/markuputils/Foo.java @@ -0,0 +1,24 @@ +package com.aventstack.extentreports.markuputils; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.aventstack.extentreports.annotations.MarkupIgnore; + +public class Foo { + public List names = Arrays.asList("Anshoo", "Extent", "Klov"); + @SuppressWarnings("unused") + private Object[] stack1 = new Object[]{"Java", "C#", "Angular"}; + @MarkupIgnore + private List ignored = Arrays.asList("Anshoo/Ignore", "Extent/Ignore", "Klov/Ignore"); + @SuppressWarnings({"serial", "unused"}) + private Map items = new HashMap() { + { + put("Item1", "Value1"); + put("Item2", "Value2"); + put("Item3", "Value3"); + } + }; +} \ No newline at end of file diff --git a/src/test/java/com/aventstack/extentreports/markuputils/LabelMarkupTest.java b/src/test/java/com/aventstack/extentreports/markuputils/LabelMarkupTest.java new file mode 100644 index 0000000..5639850 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/markuputils/LabelMarkupTest.java @@ -0,0 +1,26 @@ +package com.aventstack.extentreports.markuputils; + +import org.testng.Assert; +import org.testng.annotations.Test; + +public class LabelMarkupTest { + + @Test + public void labelWithNullText() { + Markup m = MarkupHelper.createLabel(null, ExtentColor.TRANSPARENT); + Assert.assertEquals(m.getMarkup(), ""); + } + + @Test + public void labelWithEmptyText() { + Markup m = MarkupHelper.createLabel("", ExtentColor.TRANSPARENT); + Assert.assertEquals(m.getMarkup(), ""); + } + + @Test + public void labelWithText() { + String text = "Extent"; + Markup m = MarkupHelper.createLabel(text, ExtentColor.TRANSPARENT); + Assert.assertTrue(m.getMarkup().contains(text)); + } +} diff --git a/src/test/java/com/aventstack/extentreports/markuputils/ListTest.java b/src/test/java/com/aventstack/extentreports/markuputils/ListTest.java new file mode 100644 index 0000000..42922a2 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/markuputils/ListTest.java @@ -0,0 +1,143 @@ +package com.aventstack.extentreports.markuputils; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.testng.Assert; +import org.testng.annotations.Test; + +public class ListTest { + @Test + public void unorderedListFromString() { + String items = "Item"; + Markup m = MarkupHelper.createUnorderedList(items); + String s = m.getMarkup(); + Assert.assertTrue(s.contains("
      ")); + Assert.assertTrue(s.contains("
    ")); + Assert.assertTrue(s.contains("
  • Item
  • ")); + } + + @Test + public void unorderedListFromArray() { + String[] items = new String[]{"Item1", "Item2", "Item3"}; + Markup m = MarkupHelper.createUnorderedList(items); + String s = m.getMarkup(); + Assert.assertTrue(s.contains("
      ")); + Assert.assertTrue(s.contains("
    ")); + Assert.assertTrue(s.contains("
  • Item1
  • ")); + Assert.assertTrue(s.contains("
  • Item2
  • ")); + Assert.assertTrue(s.contains("
  • Item3
  • ")); + } + + @Test + public void unorderedListFromSet() { + Set items = new HashSet<>(Arrays.asList("Item1", "Item2", "Item3")); + Markup m = MarkupHelper.createUnorderedList(items); + String s = m.getMarkup(); + Assert.assertTrue(s.contains("
      ")); + Assert.assertTrue(s.contains("
    ")); + Assert.assertTrue(s.contains("
  • Item1
  • ")); + Assert.assertTrue(s.contains("
  • Item2
  • ")); + Assert.assertTrue(s.contains("
  • Item3
  • ")); + } + + @Test + public void unorderedListFromList() { + List items = Arrays.asList(new Object[]{"Item1", "Item2", "Item3"}); + Markup m = MarkupHelper.createUnorderedList(items); + String s = m.getMarkup(); + Assert.assertTrue(s.contains("
      ")); + Assert.assertTrue(s.contains("
    ")); + Assert.assertTrue(s.contains("
  • Item1
  • ")); + Assert.assertTrue(s.contains("
  • Item2
  • ")); + Assert.assertTrue(s.contains("
  • Item3
  • ")); + } + + @SuppressWarnings("serial") + @Test + public void unorderedListFromMap() { + Map items = new HashMap() { + { + put("Item1", "Value1"); + put("Item2", "Value2"); + put("Item3", "Value3"); + } + }; + Markup m = MarkupHelper.createUnorderedList(items); + String s = m.getMarkup(); + Assert.assertTrue(s.contains("
      ")); + Assert.assertTrue(s.contains("
    ")); + Assert.assertTrue(s.contains("
  • Item1:Value1
  • ")); + Assert.assertTrue(s.contains("
  • Item2:Value2
  • ")); + Assert.assertTrue(s.contains("
  • Item3:Value3
  • ")); + } + + @Test + public void orderedListFromString() { + String items = "Item1"; + Markup m = MarkupHelper.createOrderedList(items); + String s = m.getMarkup(); + Assert.assertTrue(s.contains("
      ")); + Assert.assertTrue(s.contains("
    ")); + Assert.assertTrue(s.contains("
  • Item1
  • ")); + } + + @Test + public void orderedListFromArray() { + String[] items = new String[]{"Item1", "Item2", "Item3"}; + Markup m = MarkupHelper.createOrderedList(items); + String s = m.getMarkup(); + Assert.assertTrue(s.contains("
      ")); + Assert.assertTrue(s.contains("
    ")); + Assert.assertTrue(s.contains("
  • Item1
  • ")); + Assert.assertTrue(s.contains("
  • Item2
  • ")); + Assert.assertTrue(s.contains("
  • Item3
  • ")); + } + + @Test + public void orderedListFromSet() { + Set items = new HashSet<>(Arrays.asList("Item1", "Item2", "Item3")); + Markup m = MarkupHelper.createOrderedList(items); + String s = m.getMarkup(); + Assert.assertTrue(s.contains("
      ")); + Assert.assertTrue(s.contains("
    ")); + Assert.assertTrue(s.contains("
  • Item1
  • ")); + Assert.assertTrue(s.contains("
  • Item2
  • ")); + Assert.assertTrue(s.contains("
  • Item3
  • ")); + } + + @Test + public void orderedListFromList() { + List items = Arrays.asList(new Object[]{"Item1", "Item2", "Item3"}); + Markup m = MarkupHelper.createOrderedList(items); + String s = m.getMarkup(); + Assert.assertTrue(s.contains("
      ")); + Assert.assertTrue(s.contains("
    ")); + Assert.assertTrue(s.contains("
  • Item1
  • ")); + Assert.assertTrue(s.contains("
  • Item2
  • ")); + Assert.assertTrue(s.contains("
  • Item3
  • ")); + } + + @SuppressWarnings("serial") + @Test + public void orderedListFromMap() { + Map items = new HashMap() { + { + put("Item1", "Value1"); + put("Item2", "Value2"); + put("Item3", "Value3"); + } + }; + Markup m = MarkupHelper.createOrderedList(items); + String s = m.getMarkup(); + Assert.assertTrue(s.contains("
      ")); + Assert.assertTrue(s.contains("
    ")); + Assert.assertTrue(s.contains("
  • Item1:Value1
  • ")); + Assert.assertTrue(s.contains("
  • Item2:Value2
  • ")); + Assert.assertTrue(s.contains("
  • Item3:Value3
  • ")); + } +} diff --git a/src/test/java/com/aventstack/extentreports/markuputils/TableMarkupTest.java b/src/test/java/com/aventstack/extentreports/markuputils/TableMarkupTest.java new file mode 100644 index 0000000..4a29fd5 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/markuputils/TableMarkupTest.java @@ -0,0 +1,101 @@ +package com.aventstack.extentreports.markuputils; + +import java.util.Arrays; +import java.util.stream.Collectors; + +import org.testng.Assert; +import org.testng.annotations.Test; + +public class TableMarkupTest { + + @Test + public void tableWithNullText() { + Markup m = MarkupHelper.createTable(null); + Assert.assertEquals(m.getMarkup(), ""); + } + + @Test + public void tableWithData() { + String[][] data = new String[][]{{"h1", "h2"}, {"c1", "c2"}}; + Markup m = MarkupHelper.createTable(data); + String s = m.getMarkup(); + Assert.assertTrue(s.contains("h1")); + Assert.assertTrue(s.contains("h2")); + Assert.assertTrue(s.contains("c1")); + Assert.assertTrue(s.contains("c2")); + Assert.assertTrue(s.contains("")); + } + + @Test + public void tableWithSingleStringField() { + Markup m = MarkupHelper.toTable("String"); + String s = m.getMarkup(); + Assert.assertTrue(s.contains("String")); + Assert.assertFalse(s.contains("String")); + } + + @Test + public void tableWithSingleList() { + Markup m = MarkupHelper.toTable(Arrays.asList("Anshoo", "Extent", "Klov")); + String s = m.getMarkup(); + Assert.assertTrue(s.contains("Anshoo")); + Assert.assertTrue(s.contains("Extent")); + Assert.assertTrue(s.contains("Klov")); + } + + @Test + public void tableWithSingleSet() { + Markup m = MarkupHelper.toTable(Arrays.asList("Anshoo", "Extent", "Klov") + .stream().collect(Collectors.toSet())); + String s = m.getMarkup(); + Assert.assertTrue(s.contains("Anshoo")); + Assert.assertTrue(s.contains("Extent")); + Assert.assertTrue(s.contains("Klov")); + } + + @Test + public void tableWithSingleArray() { + Markup m = MarkupHelper.toTable(new String[]{"Anshoo", "Extent", "Klov"}); + String s = m.getMarkup(); + Assert.assertTrue(s.contains("Anshoo")); + Assert.assertTrue(s.contains("Extent")); + Assert.assertTrue(s.contains("Klov")); + } + + @Test + public void tableWithPojoBeginningEndingTags() { + Markup m = MarkupHelper.toTable(new Foo()); + String s = m.getMarkup(); + Assert.assertTrue(s.contains("")); + } + + @Test + public void tableWithPojoHeaders() { + Markup m = MarkupHelper.toTable(new Foo()); + String s = m.getMarkup(); + Assert.assertTrue(s.contains("names")); + Assert.assertTrue(s.contains("stack1")); + Assert.assertTrue(s.contains("items")); + Assert.assertFalse(s.contains("ignored")); + } + + @Test + public void tableWithPojoCells() { + Markup m = MarkupHelper.toTable(new Foo()); + String s = m.getMarkup(); + Assert.assertTrue(s.contains("Anshoo")); + Assert.assertTrue(s.contains("Extent")); + Assert.assertTrue(s.contains("Klov")); + Assert.assertTrue(s.contains("Java")); + Assert.assertTrue(s.contains("C#")); + Assert.assertTrue(s.contains("Angular")); + Assert.assertTrue(s.contains("Item1:Value1")); + Assert.assertTrue(s.contains("Item2:Value2")); + Assert.assertTrue(s.contains("Item3:Value3")); + Assert.assertFalse(s.contains("Anshoo/Ignore")); + Assert.assertFalse(s.contains("Extent/Ignore")); + Assert.assertFalse(s.contains("Klov/Ignore")); + } +} diff --git a/src/test/java/com/aventstack/extentreports/mediastorage/LocalMediaStorageTest.java b/src/test/java/com/aventstack/extentreports/mediastorage/LocalMediaStorageTest.java deleted file mode 100644 index f2b592a..0000000 --- a/src/test/java/com/aventstack/extentreports/mediastorage/LocalMediaStorageTest.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.aventstack.extentreports.mediastorage; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.List; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; -import com.aventstack.extentreports.ExtentReports; -import com.aventstack.extentreports.reporter.ExtentHtmlReporter; - -public class LocalMediaStorageTest extends Base { - - private static final String IMG_PATH = "src/test/resources/logo.png"; - private static final String OUTPUT_PATH = "target/"; -/* - @Test(priority=1) - public void testLocalFolderCreationOrder(Method method) throws IOException { - ExtentHtmlReporter html = new ExtentHtmlReporter("target/Extent.html"); - html.config().setAutoCreateRelativePathMedia(true); - extent.attachReporter(html); - extent.createTest(method.getName()).pass("pass").addScreenCaptureFromPath(IMG_PATH); - extent.flush(); - Assert.assertTrue(getDirsByName(OUTPUT_PATH).contains("target.0")); - } - - private List getDirsByName(String path) { - File file = new File(path); - String[] names = file.list(); - return Arrays.asList(names); - } - - @Test(priority=2) - public void testLocalFolderCreationOrderMultipleTries(Method method) throws IOException { - ExtentHtmlReporter html; - for (int ix = 0; ix < 2; ix++) { - extent = new ExtentReports(); - html = new ExtentHtmlReporter("target/Extent.html"); - html.config().setAutoCreateRelativePathMedia(true); - extent.attachReporter(html); - extent.createTest(method.getName()).pass("pass").addScreenCaptureFromPath(IMG_PATH); - extent.flush(); - } - Assert.assertTrue(getDirsByName(OUTPUT_PATH).contains("target.2")); - Assert.assertTrue(new File(OUTPUT_PATH + "target.2/logo.png").exists()); - } -*/ -} diff --git a/src/test/java/com/aventstack/extentreports/model/BddLevelsTest.java b/src/test/java/com/aventstack/extentreports/model/BddLevelsTest.java deleted file mode 100644 index 2d4b317..0000000 --- a/src/test/java/com/aventstack/extentreports/model/BddLevelsTest.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.aventstack.extentreports.model; - -import java.io.UnsupportedEncodingException; -import java.lang.reflect.Method; - -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; -import com.aventstack.extentreports.ExtentTest; -import com.aventstack.extentreports.GherkinKeyword; -import com.aventstack.extentreports.gherkin.GherkinDialectProvider; -import com.aventstack.extentreports.gherkin.model.And; -import com.aventstack.extentreports.gherkin.model.But; -import com.aventstack.extentreports.gherkin.model.Feature; -import com.aventstack.extentreports.gherkin.model.Given; -import com.aventstack.extentreports.gherkin.model.Scenario; -import com.aventstack.extentreports.gherkin.model.Then; -import com.aventstack.extentreports.gherkin.model.When; - -public class BddLevelsTest extends Base { - - @BeforeClass - public void beforeClass() throws UnsupportedEncodingException { - GherkinDialectProvider.setLanguage("en"); - } - - @Test - public void verifyFeatureLevelUsingGherkinKeyword(Method method) throws ClassNotFoundException { - ExtentTest feature = extent.createTest(new GherkinKeyword("Feature"), method.getName()); - Assert.assertEquals(feature.getModel().getLevel(), 0); - } - - @Test - public void verifyScenarioLevelUsingGherkinKeyword(Method method) throws ClassNotFoundException { - ExtentTest feature = extent.createTest(new GherkinKeyword("Feature"), method.getName()); - ExtentTest scenario = feature.createNode(new GherkinKeyword("Scenario"), "Child"); - Assert.assertEquals(scenario.getModel().getLevel(), 1); - } - - @Test - public void verifyGivenLevesUsingGherkinKeyword(Method method) throws ClassNotFoundException { - ExtentTest feature = extent.createTest(new GherkinKeyword("Feature"), method.getName()); - ExtentTest scenario = feature.createNode(new GherkinKeyword("Scenario"), "Child"); - ExtentTest given = scenario.createNode(new GherkinKeyword("Given"), "Given").info("info"); - Assert.assertEquals(given.getModel().getLevel(), 2); - } - - @Test - public void verifyAndLevelUsingGherkinKeyword(Method method) throws ClassNotFoundException { - ExtentTest feature = extent.createTest(new GherkinKeyword("Feature"), method.getName()); - ExtentTest scenario = feature.createNode(new GherkinKeyword("Scenario"), "Child"); - ExtentTest and = scenario.createNode(new GherkinKeyword("And"), "And").info("info"); - Assert.assertEquals(and.getModel().getLevel(), 2); - } - - @Test - public void verifyWhenLevelUsingGherkinKeyword(Method method) throws ClassNotFoundException { - ExtentTest feature = extent.createTest(new GherkinKeyword("Feature"), method.getName()); - ExtentTest scenario = feature.createNode(new GherkinKeyword("Scenario"), "Child"); - ExtentTest when = scenario.createNode(new GherkinKeyword("When"), "When").info("info"); - Assert.assertEquals(when.getModel().getLevel(), 2); - } - - @Test - public void verifyThenLevelUsingGherkinKeyword(Method method) throws ClassNotFoundException { - ExtentTest feature = extent.createTest(new GherkinKeyword("Feature"), method.getName()); - ExtentTest scenario = feature.createNode(new GherkinKeyword("Scenario"), "Child"); - ExtentTest then = scenario.createNode(new GherkinKeyword("Then"), "Then").pass("pass"); - Assert.assertEquals(then.getModel().getLevel(), 2); - } - - @Test - public void verifyButLevelUsingGherkinKeyword(Method method) throws ClassNotFoundException { - ExtentTest feature = extent.createTest(new GherkinKeyword("Feature"), method.getName()); - ExtentTest scenario = feature.createNode(new GherkinKeyword("Scenario"), "Child"); - ExtentTest but = scenario.createNode(new GherkinKeyword("But"), "But").pass("pass"); - Assert.assertEquals(but.getModel().getLevel(), 2); - } - - @Test - public void verifyFeatureLevelUsingClass(Method method) { - ExtentTest feature = extent.createTest(Feature.class, method.getName()); - Assert.assertEquals(feature.getModel().getLevel(), 0); - } - - @Test - public void verifyScenarioLevelUsingClass(Method method) { - ExtentTest feature = extent.createTest(Feature.class, method.getName()); - ExtentTest scenario = feature.createNode(Scenario.class, "Child"); - Assert.assertEquals(scenario.getModel().getLevel(), 1); - } - - @Test - public void verifyGivenLevelUsingClass(Method method) { - ExtentTest feature = extent.createTest(Feature.class, method.getName()); - ExtentTest scenario = feature.createNode(Scenario.class, "Child"); - ExtentTest given = scenario.createNode(Given.class, "Given").info("info"); - Assert.assertEquals(given.getModel().getLevel(), 2); - } - - @Test - public void verifyAndLevelUsingClass(Method method) { - ExtentTest feature = extent.createTest(Feature.class, method.getName()); - ExtentTest scenario = feature.createNode(Scenario.class, "Child"); - ExtentTest and = scenario.createNode(And.class, "And").info("info"); - Assert.assertEquals(and.getModel().getLevel(), 2); - } - - @Test - public void verifyWhenLevelUsingClass(Method method) { - ExtentTest feature = extent.createTest(Feature.class, method.getName()); - ExtentTest scenario = feature.createNode(Scenario.class, "Child"); - ExtentTest when = scenario.createNode(When.class, "When").info("info"); - Assert.assertEquals(when.getModel().getLevel(), 2); - } - - @Test - public void verifyThenLevelUsingClass(Method method) { - ExtentTest feature = extent.createTest(Feature.class, method.getName()); - ExtentTest scenario = feature.createNode(Scenario.class, "Child"); - ExtentTest then = scenario.createNode(Then.class, "Then").pass("pass"); - Assert.assertEquals(then.getModel().getLevel(), 2); - } - - @Test - public void verifyButLevelUsingClass(Method method) { - ExtentTest feature = extent.createTest(Feature.class, method.getName()); - ExtentTest scenario = feature.createNode(Scenario.class, "Child"); - ExtentTest but = scenario.createNode(But.class, "But").pass("pass"); - Assert.assertEquals(but.getModel().getLevel(), 2); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/model/LogModelTest.java b/src/test/java/com/aventstack/extentreports/model/LogModelTest.java deleted file mode 100644 index 9380713..0000000 --- a/src/test/java/com/aventstack/extentreports/model/LogModelTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.aventstack.extentreports.model; - -import java.lang.reflect.Method; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; -import com.aventstack.extentreports.ExtentTest; -import com.aventstack.extentreports.Status; - - -public class LogModelTest extends Base { - - @Test - public void testLogStatusPass(Method method) { - ExtentTest t = extent.createTest(method.getName()).pass("pass"); - Assert.assertEquals(t.getModel().getLogContext().getFirst().getStatus(), Status.PASS); - } - - @Test - public void testLogStatusFail(Method method) { - ExtentTest t = extent.createTest(method.getName()).fail("fail"); - Assert.assertEquals(t.getModel().getLogContext().getFirst().getStatus(), Status.FAIL); - } - - @Test - public void testLogStatusSkip(Method method) { - ExtentTest t = extent.createTest(method.getName()).skip("skip"); - Assert.assertEquals(t.getModel().getLogContext().getFirst().getStatus(), Status.SKIP); - } - - @Test - public void testLogStatusPassMultiple(Method method) { - ExtentTest t = extent.createTest(method.getName()).fail("fail").pass("pass").skip("skip"); - Assert.assertEquals(t.getModel().getLogContext().getFirst().getStatus(), Status.FAIL); - } - - @Test - public void testLogStatusFailMultiple(Method method) { - ExtentTest t = extent.createTest(method.getName()).fail("fail").pass("pass").skip("skip"); - Assert.assertEquals(t.getModel().getLogContext().get(1).getStatus(), Status.PASS); - } - - @Test - public void testLogStatusSkipMultiple(Method method) { - ExtentTest t = extent.createTest(method.getName()).fail("fail").pass("pass").skip("skip"); - Assert.assertEquals(t.getModel().getLogContext().getLast().getStatus(), Status.SKIP); - } - - @Test - public void testLogDetailsContent(Method method) { - String content = "fail"; - ExtentTest t = extent.createTest(method.getName()).fail(content); - Assert.assertEquals(t.getModel().getLogContext().getFirst().getDetails(), content); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/model/MarkupHelperTest.java b/src/test/java/com/aventstack/extentreports/model/MarkupHelperTest.java deleted file mode 100644 index be55165..0000000 --- a/src/test/java/com/aventstack/extentreports/model/MarkupHelperTest.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.aventstack.extentreports.model; - -import java.lang.reflect.Method; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; -import com.aventstack.extentreports.ExtentTest; -import com.aventstack.extentreports.markuputils.CodeLanguage; -import com.aventstack.extentreports.markuputils.ExtentColor; -import com.aventstack.extentreports.markuputils.Markup; -import com.aventstack.extentreports.markuputils.MarkupHelper; - -public class MarkupHelperTest extends Base { - - private static final String TEXTAREA_START = " idCollection = new ArrayList<>(); - - // create [times] tests to ensure test-id is not duplicate - for (int ix = 0; ix < times; ix++) { - int testId = extent.createTest(method.getName() + "." + ix).info("test # " + ix).getModel().getId(); - - Assert.assertFalse(idCollection.contains(testId)); - - idCollection.add(testId); - } - } -} diff --git a/src/test/java/com/aventstack/extentreports/model/TestMediaTest.java b/src/test/java/com/aventstack/extentreports/model/TestMediaTest.java deleted file mode 100644 index f354eba..0000000 --- a/src/test/java/com/aventstack/extentreports/model/TestMediaTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.aventstack.extentreports.model; - -import java.io.IOException; -import java.lang.reflect.Method; -import java.net.URL; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; -import com.aventstack.extentreports.ExtentTest; - -public class TestMediaTest extends Base { - - private final String imgName = "img"; - private URL url = getClass().getClassLoader().getResource("1.png"); - private String imgPath = url.getPath(); - - @Test - public void verifyIfScreenCaptureAdded(Method method) throws IOException { - ExtentTest test = extent - .createTest(method.getName()) - .addScreenCaptureFromPath(imgPath) - .fail("fail"); - - Assert.assertEquals(test.getModel().getScreenCaptureContext().size(), 1); - } - - @Test - public void verifyScreenCaptureTitle(Method method) throws IOException { - ExtentTest test = extent - .createTest(method.getName()) - .addScreenCaptureFromPath(imgPath, imgName) - .fail("fail"); - - Assert.assertEquals(test.getModel().getScreenCaptureContext().size(), 1); - Assert.assertEquals(test.getModel().getScreenCaptureContext().get(0).getName(), imgName); - } - - @Test - public void verifyMultipleScreenCaptures(Method method) throws IOException { - int times = 4; - - ExtentTest test = extent - .createTest(method.getName()) - .fail("fail"); - - for (int ix = 0; ix < times; ix++) { - test.addScreenCaptureFromPath(imgPath, imgName); - } - - Assert.assertEquals(test.getModel().getScreenCaptureContext().size(), times); - for (int ix = 0; ix < times; ix++) { - Assert.assertEquals(test.getModel().getScreenCaptureContext().get(ix).getName(), imgName); - } - } - -} diff --git a/src/test/java/com/aventstack/extentreports/model/TestModelTest.java b/src/test/java/com/aventstack/extentreports/model/TestModelTest.java deleted file mode 100644 index 6865c80..0000000 --- a/src/test/java/com/aventstack/extentreports/model/TestModelTest.java +++ /dev/null @@ -1,273 +0,0 @@ -package com.aventstack.extentreports.model; - -import java.lang.reflect.Method; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; -import com.aventstack.extentreports.ExtentTest; - -public class TestModelTest extends Base { - - @Test - public void testTestId(Method method) { - ExtentTest t = extent.createTest(method.getName()); - Assert.assertTrue(t.getModel().getId()>=0); - } - - @Test - public void testHasNoChildrenViaModel(Method method) { - ExtentTest t = extent.createTest(method.getName()); - Assert.assertTrue(t.getModel().getNodeContext().isEmpty()); - } - - @Test - public void testHasChildrenViaModel(Method method) { - ExtentTest t = extent.createTest(method.getName()); - t.createNode(method.getName()); - Assert.assertFalse(t.getModel().getNodeContext().isEmpty()); - } - - @Test - public void testNodeIsChildNode(Method method) { - ExtentTest t = extent.createTest(method.getName()).createNode(method.getName()); - Assert.assertTrue(t.getModel().getLevel()>0); - } - - @Test - public void testNodeContextIsEmpty(Method method) { - ExtentTest t = extent.createTest(method.getName()); - Assert.assertTrue(t.getModel().getNodeContext().isEmpty()); - } - - @Test - public void testNodeContextIsNotEmpty(Method method) { - ExtentTest t = extent.createTest(method.getName()); - t.createNode(method.getName()); - Assert.assertFalse(t.getModel().getNodeContext().isEmpty()); - } - - @Test - public void testNodeContextFirstNotNull(Method method) { - ExtentTest t = extent.createTest(method.getName()); - t.createNode(method.getName()); - Assert.assertTrue(t.getModel().getNodeContext().getFirst()!=null); - } - - @Test - public void testNodeContextFirstContent(Method method) { - ExtentTest t = extent.createTest(method.getName()); - String name = method.getName() + "x"; - t.createNode(name); - Assert.assertTrue(t.getModel().getNodeContext().getFirst().getName().equals(name)); - } - - @Test - public void testNodeContextLastContent(Method method) { - ExtentTest t = extent.createTest(method.getName()); - String name = method.getName() + "x"; - t.createNode(name); - Assert.assertTrue(t.getModel().getNodeContext().getLast().getName().equals(name)); - } - - @Test - public void testNodeContextFirstLastContent(Method method) { - ExtentTest t = extent.createTest(method.getName()); - String name1 = method.getName() + "x1"; - t.createNode(name1); - String name2 = method.getName() + "x2"; - t.createNode(name2); - Assert.assertTrue(t.getModel().getNodeContext().getFirst().getName().equals(name1)); - Assert.assertTrue(t.getModel().getNodeContext().getLast().getName().equals(name2)); - } - - @Test - public void testNodeContextIndexContent(Method method) { - ExtentTest t = extent.createTest(method.getName()); - String name1 = method.getName() + "x1"; - t.createNode(name1); - String name2 = method.getName() + "x2"; - t.createNode(name2); - Assert.assertTrue(t.getModel().getNodeContext().get(0).getName().equals(name1)); - Assert.assertTrue(t.getModel().getNodeContext().get(1).getName().equals(name2)); - } - - @Test - public void testHasNoEventsViaModel(Method method) { - ExtentTest t = extent.createTest(method.getName()); - Assert.assertTrue(t.getModel().getLogContext().isEmpty()); - } - - @Test - public void testHasEventsViaModel(Method method) { - ExtentTest t = extent.createTest(method.getName()).pass("pass"); - Assert.assertFalse(t.getModel().getLogContext().isEmpty()); - } - - @Test - public void testLogContextIsEmpty(Method method) { - ExtentTest t = extent.createTest(method.getName()); - Assert.assertTrue(t.getModel().getLogContext().isEmpty()); - } - - @Test - public void testLogContextIsNotEmpty(Method method) { - ExtentTest t = extent.createTest(method.getName()).pass("pass"); - Assert.assertFalse(t.getModel().getLogContext().isEmpty()); - } - - @Test - public void testLogContextFirstNotNull(Method method) { - ExtentTest t = extent.createTest(method.getName()).pass("pass"); - Assert.assertTrue(t.getModel().getLogContext().getFirst()!=null); - } - - @Test - public void testLogContextFirstContent(Method method) { - String name = method.getName() + "x"; - ExtentTest t = extent.createTest(method.getName()).pass(name); - Assert.assertTrue(t.getModel().getLogContext().getFirst().getDetails().equals(name)); - } - - @Test - public void testLogContextLastContent(Method method) { - String name = method.getName() + "x"; - ExtentTest t = extent.createTest(method.getName()).pass(name); - Assert.assertTrue(t.getModel().getLogContext().getLast().getDetails().equals(name)); - } - - @Test - public void testLogContextFirstLastContent(Method method) { - ExtentTest t = extent.createTest(method.getName()); - String name1 = method.getName() + "x1"; - t.pass(name1); - String name2 = method.getName() + "x2"; - t.pass(name2); - Assert.assertTrue(t.getModel().getLogContext().getFirst().getDetails().equals(name1)); - Assert.assertTrue(t.getModel().getLogContext().getLast().getDetails().equals(name2)); - } - - @Test - public void testLogContextIndexContent(Method method) { - ExtentTest t = extent.createTest(method.getName()); - String name1 = method.getName() + "x1"; - t.pass(name1); - String name2 = method.getName() + "x2"; - t.pass(name2); - Assert.assertTrue(t.getModel().getLogContext().get(0).getDetails().equals(name1)); - Assert.assertTrue(t.getModel().getLogContext().get(1).getDetails().equals(name2)); - } - - @Test - public void testHasCategory(Method method) { - ExtentTest t = extent.createTest(method.getName()).assignCategory("category"); - Assert.assertFalse(t.getModel().getCategoryContext().isEmpty()); - } - - @Test - public void testHasNoCategoryWhenCategoryNull(Method method) { - ExtentTest t = extent.createTest(method.getName()).assignCategory(new String[] { null }); - Assert.assertTrue(t.getModel().getCategoryContext().isEmpty()); - } - - @Test - public void testHasNoCategoryWhenCategoryEmpty(Method method) { - ExtentTest t = extent.createTest(method.getName()).assignCategory(""); - Assert.assertTrue(t.getModel().getCategoryContext().isEmpty()); - } - - @Test - public void testHasNoCategoryWhenCategorySpaces(Method method) { - ExtentTest t = extent.createTest(method.getName()).assignCategory(" "); - Assert.assertTrue(t.getModel().getCategoryContext().isEmpty()); - } - - @Test - public void testCategorySingleNameMatch(Method method) { - ExtentTest t = extent.createTest(method.getName()).assignCategory(method.getName()); - Assert.assertTrue(t.getModel().getCategoryContext().getFirst().getName().equals(method.getName())); - } - - @Test - public void testCategoryMultipleOrderedNameMatch(Method method) { - ExtentTest t = extent.createTest(method.getName()).assignCategory(method.getName(), "tag"); - Assert.assertTrue(t.getModel().getCategoryContext().getFirst().getName().equals(method.getName())); - Assert.assertTrue(t.getModel().getCategoryContext().getLast().getName().equals("tag")); - } - - @Test - public void testHasAuthor(Method method) { - ExtentTest t = extent.createTest(method.getName()).assignAuthor("Author"); - Assert.assertFalse(t.getModel().getAuthorContext().isEmpty()); - } - - @Test - public void testHasNoAuthorWhenAuthorNull(Method method) { - ExtentTest t = extent.createTest(method.getName()).assignAuthor(new String[] { null }); - Assert.assertTrue(t.getModel().getAuthorContext().isEmpty()); - } - - @Test - public void testHasNoAuthorWhenAuthorEmpty(Method method) { - ExtentTest t = extent.createTest(method.getName()).assignAuthor(""); - Assert.assertTrue(t.getModel().getAuthorContext().isEmpty()); - } - - @Test - public void testHasNoAuthorWhenAuthorSpaces(Method method) { - ExtentTest t = extent.createTest(method.getName()).assignAuthor(" "); - Assert.assertTrue(t.getModel().getAuthorContext().isEmpty()); - } - - @Test - public void testAuthorSingleNameMatch(Method method) { - ExtentTest t = extent.createTest(method.getName()).assignAuthor(method.getName()); - Assert.assertTrue(t.getModel().getAuthorContext().getFirst().getName().equals(method.getName())); - } - - @Test - public void testAuthorMultipleOrderedNameMatch(Method method) { - ExtentTest t = extent.createTest(method.getName()).assignAuthor(method.getName(), "author"); - Assert.assertTrue(t.getModel().getAuthorContext().getFirst().getName().equals(method.getName())); - Assert.assertTrue(t.getModel().getAuthorContext().getLast().getName().equals("author")); - } - - @Test - public void testHasDevice(Method method) { - ExtentTest t = extent.createTest(method.getName()).assignDevice("Device"); - Assert.assertFalse(t.getModel().getDeviceContext().isEmpty()); - } - - @Test - public void testHasNoDeviceWhenDeviceNull(Method method) { - ExtentTest t = extent.createTest(method.getName()).assignDevice(new String[] { null }); - Assert.assertTrue(t.getModel().getDeviceContext().isEmpty()); - } - - @Test - public void testHasNoDeviceWhenDeviceEmpty(Method method) { - ExtentTest t = extent.createTest(method.getName()).assignDevice(""); - Assert.assertTrue(t.getModel().getDeviceContext().isEmpty()); - } - - @Test - public void testHasNoDeviceWhenDeviceSpaces(Method method) { - ExtentTest t = extent.createTest(method.getName()).assignDevice(" "); - Assert.assertTrue(t.getModel().getDeviceContext().isEmpty()); - } - - @Test - public void testDeviceSingleNameMatch(Method method) { - ExtentTest t = extent.createTest(method.getName()).assignDevice(method.getName()); - Assert.assertTrue(t.getModel().getDeviceContext().getFirst().getName().equals(method.getName())); - } - - @Test - public void testDeviceMultipleOrderedNameMatch(Method method) { - ExtentTest t = extent.createTest(method.getName()).assignDevice(method.getName(), "Device"); - Assert.assertTrue(t.getModel().getDeviceContext().getFirst().getName().equals(method.getName())); - Assert.assertTrue(t.getModel().getDeviceContext().getLast().getName().equals("Device")); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/observer/ReportEntityObserverTest.java b/src/test/java/com/aventstack/extentreports/observer/ReportEntityObserverTest.java new file mode 100644 index 0000000..43e96f2 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/observer/ReportEntityObserverTest.java @@ -0,0 +1,54 @@ +package com.aventstack.extentreports.observer; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.aventstack.extentreports.ExtentReports; +import com.aventstack.extentreports.observer.entity.ReportEntity; + +import io.reactivex.rxjava3.core.Observer; +import io.reactivex.rxjava3.disposables.Disposable; + +public class ReportEntityObserverTest { + private Disposable disp; + private ReportEntity entity; + + @Test + public void disposableNonNull() { + ExtentReports extent = new ExtentReports(); + Assert.assertNull(disp); + Assert.assertNull(entity); + extent.attachReporter(new TestReporter()); + Assert.assertNotNull(disp); + Assert.assertNull(entity); + extent.flush(); + Assert.assertNotNull(disp); + Assert.assertNotNull(entity); + } + + @SuppressWarnings("rawtypes") + private class TestReporter implements ReportObserver { + @Override + public Observer getReportObserver() { + return new Observer() { + @Override + public void onSubscribe(Disposable d) { + disp = d; + } + + @Override + public void onNext(ReportEntity value) { + entity = value; + } + + @Override + public void onError(Throwable e) { + } + + @Override + public void onComplete() { + } + }; + } + } +} diff --git a/src/test/java/com/aventstack/extentreports/reporter/Base64Tests.java b/src/test/java/com/aventstack/extentreports/reporter/Base64Tests.java deleted file mode 100644 index c86fa3f..0000000 --- a/src/test/java/com/aventstack/extentreports/reporter/Base64Tests.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.aventstack.extentreports.reporter; - -import org.testng.annotations.Test; - -import com.aventstack.extentreports.ExtentReports; -import com.aventstack.extentreports.gherkin.model.Feature; -import com.aventstack.extentreports.gherkin.model.Given; -import com.aventstack.extentreports.gherkin.model.Scenario; - -public class Base64Tests { - - private final static String BASE64 = ""; - - @Test - public void testBase64BDDAtFeature() { - ExtentReports extent = new ExtentReports(); - ExtentHtmlReporter html = new ExtentHtmlReporter("html/index.html"); - ExtentSparkReporter spark = new ExtentSparkReporter("spark/index.html"); - extent.attachReporter(html, spark); - extent.createTest(Feature.class, "Feature") - .addScreenCaptureFromBase64String(BASE64); - extent.flush(); - } - - @Test - public void testBase64BDDAtScenario() { - ExtentReports extent = new ExtentReports(); - ExtentHtmlReporter html = new ExtentHtmlReporter("html/index.html"); - ExtentSparkReporter spark = new ExtentSparkReporter("spark/index.html"); - extent.attachReporter(html, spark); - extent.createTest(Feature.class, "Feature") - .createNode(Scenario.class, "Scenario") - .addScreenCaptureFromBase64String(BASE64); - extent.flush(); - } - - @Test - public void testBase64BDDAtStep() { - ExtentReports extent = new ExtentReports(); - ExtentHtmlReporter html = new ExtentHtmlReporter("html/index.html"); - ExtentSparkReporter spark = new ExtentSparkReporter("spark/index.html"); - extent.attachReporter(html, spark); - extent.createTest(Feature.class, "Feature") - .createNode(Scenario.class, "Scenario") - .createNode(Given.class, "Given") - .addScreenCaptureFromBase64String(BASE64); - extent.flush(); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/reporter/FileReporterPathsTest.java b/src/test/java/com/aventstack/extentreports/reporter/FileReporterPathsTest.java new file mode 100644 index 0000000..2f0c6e3 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/reporter/FileReporterPathsTest.java @@ -0,0 +1,60 @@ +package com.aventstack.extentreports.reporter; + +import java.io.File; +import java.util.Calendar; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.aventstack.extentreports.ExtentReports; + +public class FileReporterPathsTest { + + private ExtentReports getExtent(String r, String f) { + ExtentReports extent = new ExtentReports(); + if (r == "spark") + extent.attachReporter(new ExtentSparkReporter(f)); + else + extent.attachReporter(new JsonFormatter(f)); + extent.createTest("Test").pass("Pass"); + extent.flush(); + return extent; + } + + private String getFileName(String ext) { + final String basePath = "target/"; + long t = Calendar.getInstance().getTimeInMillis(); + String fileName = basePath + t + ext; + return fileName; + } + + @Test + public void sparkPathAsFile() { + String f = getFileName(".html"); + getExtent("spark", f); + Assert.assertTrue(new File(f).exists()); + } + + @Test + public void sparkPathAsDirectory() { + String f = getFileName(""); + getExtent("spark", f); + Assert.assertTrue(new File(f).exists()); + Assert.assertTrue(new File(f + "/Index.html").exists()); + } + + @Test + public void jsonPathAsFile() { + String f = getFileName(".json"); + getExtent("json", f); + Assert.assertTrue(new File(f).exists()); + } + + @Test + public void jsonPathAsDirectory() { + String f = getFileName(""); + getExtent("json", f); + Assert.assertTrue(new File(f).exists()); + Assert.assertTrue(new File(f + "/extent.json").exists()); + } +} diff --git a/src/test/java/com/aventstack/extentreports/reporter/HtmlBasicFileReporterConfigurationTest.java b/src/test/java/com/aventstack/extentreports/reporter/HtmlBasicFileReporterConfigurationTest.java deleted file mode 100644 index 9d9b6a7..0000000 --- a/src/test/java/com/aventstack/extentreports/reporter/HtmlBasicFileReporterConfigurationTest.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.aventstack.extentreports.reporter; - -import java.lang.reflect.Method; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; - -public class HtmlBasicFileReporterConfigurationTest extends Base { - - @Test - public void htmlReporterHasInitialConfig(Method method) { - ExtentSparkReporter html = new ExtentSparkReporter(method.getName() + ".html"); - Assert.assertFalse(html.getConfigurationStore().isEmpty()); - } - - @Test - public void testHtmlReporterUserConfigInitialCSSNull(Method method) { - ExtentSparkReporter html = new ExtentSparkReporter(method.getName() + ".html"); - String v = (String) html.getConfigurationStore().getConfig("css"); - Assert.assertNull(v); - } - - @Test - public void testHtmlReporterUserConfigCSSHasValue(Method method) { - ExtentSparkReporter html = new ExtentSparkReporter(method.getName() + ".html"); - String css = ".dark{background:black;}"; - html.config().setCSS(css); - String v = (String) html.getConfigurationStore().getConfig("css"); - Assert.assertFalse(v.isEmpty()); - } - - @Test - public void testHtmlReporterUserConfigCSSValue(Method method) { - ExtentSparkReporter html = new ExtentSparkReporter(method.getName() + ".html"); - String css = ".dark{background:black;}"; - html.config().setCSS(css); - String v = (String) html.getConfigurationStore().getConfig("css"); - Assert.assertEquals(v, css); - } - - @Test - public void testHtmlReporterUserConfigInitialJSNull(Method method) { - ExtentSparkReporter html = new ExtentSparkReporter(method.getName() + ".html"); - String v = (String) html.getConfigurationStore().getConfig("js"); - Assert.assertNull(v); - } - - @Test - public void testHtmlReporterUserConfigJSHasValue(Method method) { - ExtentSparkReporter html = new ExtentSparkReporter(method.getName() + ".html"); - html.config().setJS("alert('');"); - String v = (String) html.getConfigurationStore().getConfig("js"); - Assert.assertFalse(v.isEmpty()); - } - - @Test - public void testHtmlReporterUserConfigJSValue(Method method) { - ExtentSparkReporter html = new ExtentSparkReporter(method.getName() + ".html"); - String js = "alert('');"; - html.config().setJS(js); - String v = (String) html.getConfigurationStore().getConfig("js"); - Assert.assertEquals(v, js); - } - - @Test - public void documentTitleInitialValueTest(Method method) { - ExtentSparkReporter html = new ExtentSparkReporter(method.getName() + ".html"); - Assert.assertFalse(html.getConfigurationStore().getConfig("documentTitle").toString().isEmpty()); - } - - @Test - public void documentTitleInitialUserValueTest(Method method) { - ExtentSparkReporter html = new ExtentSparkReporter(method.getName() + ".html"); - String v = (String) html.getConfigurationStore().getConfig("documentTitle"); - Assert.assertNotNull(v); - } - - @Test - public void documentTitleUserValueTest(Method method) { - ExtentSparkReporter html = new ExtentSparkReporter(method.getName() + ".html"); - String docTitle = "test"; - html.config().setDocumentTitle(docTitle); - String v = (String) html.getConfigurationStore().getConfig("documentTitle"); - Assert.assertEquals(v, docTitle); - } - - @Test - public void encodingInitialValueTest(Method method) { - ExtentSparkReporter html = new ExtentSparkReporter(method.getName() + ".html"); - Assert.assertTrue(html.getConfigurationStore().getConfig("encoding").toString().equalsIgnoreCase("utf-8")); - } - - @Test - public void encodingInitialUserValueTest(Method method) { - ExtentSparkReporter html = new ExtentSparkReporter(method.getName() + ".html"); - String v = (String) html.getConfigurationStore().getConfig("encoding"); - Assert.assertNotNull(v); - } - - @Test - public void encodingUserValueTest(Method method) { - ExtentSparkReporter html = new ExtentSparkReporter(method.getName() + ".html"); - String encoding = "utf-16"; - html.config().setEncoding(encoding); - String v = (String) html.getConfigurationStore().getConfig("encoding"); - Assert.assertEquals(v, encoding); - } -} diff --git a/src/test/java/com/aventstack/extentreports/reporter/HtmlConfigurableReporterTest.java b/src/test/java/com/aventstack/extentreports/reporter/HtmlConfigurableReporterTest.java deleted file mode 100644 index 73c6aa7..0000000 --- a/src/test/java/com/aventstack/extentreports/reporter/HtmlConfigurableReporterTest.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.aventstack.extentreports.reporter; - -import java.lang.reflect.Method; - -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; - -public class HtmlConfigurableReporterTest extends Base { - - private static final String CONFIG_PATH = "src/test/resources/html-config.xml"; - private static final String THEME = "dark"; - private static final String ENCODING = "utf-8"; - private static final String DOCUMENT_TITLE = "Extent Framework"; - private static final String REPORT_NAME = "Build 1"; - private static final String TIMESTAMP_FORMAT = "MMM dd, yyyy HH:mm:ss"; - private static final String CSS = ".test.active { border: 1px solid #ccc; }"; - private static final String JS = "$('.test').click(function() { console.log('test'); });"; - - private ExtentSparkReporter spark; - - @BeforeClass - public void beforeClass() { - spark = new ExtentSparkReporter("Extent.html"); - spark.loadXMLConfig(CONFIG_PATH); - } - - @Test - public void testTheme(Method method) { - Assert.assertEquals(spark.getConfigurationStore().getConfig("theme"), THEME); - } - - @Test - public void testEncoding(Method method) { - Assert.assertTrue(String.valueOf(spark.getConfigurationStore().getConfig("encoding")).equalsIgnoreCase(ENCODING)); - } - - @Test - public void testDocumentTitle(Method method) { - Assert.assertEquals(spark.getConfigurationStore().getConfig("documentTitle"), DOCUMENT_TITLE); - } - - @Test - public void testReportName(Method method) { - Assert.assertEquals(spark.getConfigurationStore().getConfig("reportName"), REPORT_NAME); - } - - @Test - public void testTimestampFormat(Method method) { - Assert.assertEquals(spark.getConfigurationStore().getConfig("timeStampFormat"), TIMESTAMP_FORMAT); - } - - @Test - public void testCSS(Method method) { - Assert.assertTrue(spark.getConfigurationStore().getConfig("styles").toString().contains(CSS)); - } - - @Test - public void testJS(Method method) { - Assert.assertTrue(spark.getConfigurationStore().getConfig("scripts").toString().contains(JS)); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/reporter/HtmlRichViewReporterConfigurationTest.java b/src/test/java/com/aventstack/extentreports/reporter/HtmlRichViewReporterConfigurationTest.java deleted file mode 100644 index 6ddbde5..0000000 --- a/src/test/java/com/aventstack/extentreports/reporter/HtmlRichViewReporterConfigurationTest.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.aventstack.extentreports.reporter; - -import java.lang.reflect.Method; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.reporter.configuration.Protocol; -import com.aventstack.extentreports.reporter.configuration.Theme; - -public class HtmlRichViewReporterConfigurationTest { - - @Test - public void testHtmlReporterUserConfigEnableTimelineEnabled(Method method) { - ExtentSparkReporter spark = new ExtentSparkReporter(method.getName() + ".html"); - spark.config().enableTimeline(true); - String v = (String) spark.getConfigurationStore().getConfig("enableTimeline"); - Assert.assertEquals(v, String.valueOf(true)); - } - - @Test - public void testHtmlReporterUserConfigEnableTimelineDisabled(Method method) { - ExtentSparkReporter spark = new ExtentSparkReporter(method.getName() + ".html"); - spark.config().enableTimeline(false); - String v = (String) spark.getConfigurationStore().getConfig("enableTimeline"); - Assert.assertEquals(v, String.valueOf(false)); - } - - @Test - public void testHtmlReporterUserConfigDetaultProtocol(Method method) { - ExtentSparkReporter spark = new ExtentSparkReporter(method.getName() + ".html"); - String v = (String) spark.getConfigurationStore().getConfig("protocol"); - Assert.assertEquals(Enum.valueOf(Protocol.class, v.toUpperCase()), Protocol.HTTPS); - } - - @Test - public void testHtmlReporterUserConfigProtocolSetting(Method method) { - ExtentSparkReporter spark = new ExtentSparkReporter(method.getName() + ".html"); - spark.config().setProtocol(Protocol.HTTP); - Object p = spark.getConfigurationStore().getConfig("protocol"); - Protocol v = Protocol.valueOf(String.valueOf(p).toUpperCase()); - Assert.assertEquals(v, Protocol.HTTP); - } - - @Test - public void testHtmlReporterUserConfigDetaultTheme(Method method) { - ExtentSparkReporter spark = new ExtentSparkReporter(method.getName() + ".html"); - Object t = spark.getConfigurationStore().getConfig("theme"); - Theme theme = Theme.valueOf(String.valueOf(t).toUpperCase()); - Assert.assertEquals(theme, Theme.STANDARD); - } - - @Test - public void testHtmlReporterUserConfigThemeSetting(Method method) { - ExtentSparkReporter spark = new ExtentSparkReporter(method.getName() + ".html"); - spark.config().setTheme(Theme.DARK); - Object t = spark.config().getConfigurationStore().getConfig("theme"); - Theme theme = Theme.valueOf(String.valueOf(t).toUpperCase()); - Assert.assertEquals(theme, Theme.DARK); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/reporter/JsonFormatterBDDTest.java b/src/test/java/com/aventstack/extentreports/reporter/JsonFormatterBDDTest.java new file mode 100644 index 0000000..d9bda48 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/reporter/JsonFormatterBDDTest.java @@ -0,0 +1,32 @@ +package com.aventstack.extentreports.reporter; + +import java.io.IOException; + +import org.testng.annotations.Test; + +import com.aventstack.extentreports.ExtentReports; +import com.aventstack.extentreports.gherkin.model.Feature; +import com.aventstack.extentreports.gherkin.model.Given; +import com.aventstack.extentreports.gherkin.model.Scenario; + +public class JsonFormatterBDDTest { + private static final String JSON_PATH = "target/extent.json"; + + @Test + public void writeBdd() { + ExtentReports extent = new ExtentReports(); + JsonFormatter json = new JsonFormatter(JSON_PATH); + extent.attachReporter(json); + extent.createTest(Feature.class, "FeatureName") + .createNode(Scenario.class, "ScenarioName") + .createNode(Given.class, "Given ..") + .pass("Pass"); + extent.flush(); + } + + @Test(dependsOnMethods = "writeBdd") + public void readBdd() throws IOException { + ExtentReports extent = new ExtentReports(); + extent.createDomainFromJsonArchive(JSON_PATH); + } +} diff --git a/src/test/java/com/aventstack/extentreports/reporter/JsonFormatterStandardTest.java b/src/test/java/com/aventstack/extentreports/reporter/JsonFormatterStandardTest.java new file mode 100644 index 0000000..95b9f7d --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/reporter/JsonFormatterStandardTest.java @@ -0,0 +1,26 @@ +package com.aventstack.extentreports.reporter; + +import java.io.IOException; + +import org.testng.annotations.Test; + +import com.aventstack.extentreports.ExtentReports; + +public class JsonFormatterStandardTest { + private static final String JSON_PATH = "target/extent.json"; + + @Test + public void writeStandard() { + ExtentReports extent = new ExtentReports(); + JsonFormatter json = new JsonFormatter(JSON_PATH); + extent.attachReporter(json); + extent.createTest("Test"); + extent.flush(); + } + + @Test(dependsOnMethods = "writeStandard") + public void readStandard() throws IOException { + ExtentReports extent = new ExtentReports(); + extent.createDomainFromJsonArchive(JSON_PATH); + } +} diff --git a/src/test/java/com/aventstack/extentreports/reporter/LoggerBasicFileReporterConfigurationTest2.java b/src/test/java/com/aventstack/extentreports/reporter/LoggerBasicFileReporterConfigurationTest2.java deleted file mode 100644 index 469e20a..0000000 --- a/src/test/java/com/aventstack/extentreports/reporter/LoggerBasicFileReporterConfigurationTest2.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.aventstack.extentreports.reporter; - -import java.lang.reflect.Method; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; - -public class LoggerBasicFileReporterConfigurationTest2 extends Base { - - @Test - public void htmlReporterHasInitialConfig(Method method) { - ExtentLoggerReporter logger = new ExtentLoggerReporter(method.getName() + ".html"); - Assert.assertFalse(logger.getConfigurationStore().isEmpty()); - } - - @Test - public void testHtmlReporterUserConfigInitialCSSNull(Method method) { - ExtentLoggerReporter logger = new ExtentLoggerReporter(method.getName() + ".html"); - String v = (String) logger.getConfigurationStore().getConfig("css"); - Assert.assertNull(v); - } - - @Test - public void testHtmlReporterUserConfigCSSHasValue(Method method) { - ExtentLoggerReporter logger = new ExtentLoggerReporter(method.getName() + ".html"); - String css = ".dark{background:black;}"; - logger.config().setCSS(css); - String v = (String) logger.getConfigurationStore().getConfig("css"); - Assert.assertFalse(v.isEmpty()); - } - - @Test - public void testHtmlReporterUserConfigCSSValue(Method method) { - ExtentLoggerReporter logger = new ExtentLoggerReporter(method.getName() + ".html"); - String css = ".dark{background:black;}"; - logger.config().setCSS(css); - String v = (String) logger.getConfigurationStore().getConfig("css"); - Assert.assertEquals(v, css); - } - - @Test - public void testHtmlReporterUserConfigInitialJSNull(Method method) { - ExtentLoggerReporter logger = new ExtentLoggerReporter(method.getName() + ".html"); - String v = (String) logger.getConfigurationStore().getConfig("js"); - Assert.assertNull(v); - } - - @Test - public void testHtmlReporterUserConfigJSHasValue(Method method) { - ExtentLoggerReporter logger = new ExtentLoggerReporter(method.getName() + ".html"); - logger.config().setJS("alert('');"); - String v = (String) logger.getConfigurationStore().getConfig("js"); - Assert.assertFalse(v.isEmpty()); - } - - @Test - public void testHtmlReporterUserConfigJSValue(Method method) { - ExtentLoggerReporter logger = new ExtentLoggerReporter(method.getName() + ".html"); - String js = "alert('');"; - logger.config().setJS(js); - String v = (String) logger.getConfigurationStore().getConfig("js"); - Assert.assertEquals(v, js); - } - - @Test - public void documentTitleInitialValueTest(Method method) { - ExtentLoggerReporter logger = new ExtentLoggerReporter(method.getName() + ".html"); - Assert.assertFalse(logger.getConfigurationStore().getConfig("documentTitle").toString().isEmpty()); - } - - @Test - public void documentTitleInitialUserValueTest(Method method) { - ExtentLoggerReporter logger = new ExtentLoggerReporter(method.getName() + ".html"); - String v = (String) logger.getConfigurationStore().getConfig("documentTitle"); - Assert.assertNotNull(v); - } - - @Test - public void documentTitleUserValueTest(Method method) { - ExtentLoggerReporter logger = new ExtentLoggerReporter(method.getName() + ".html"); - String docTitle = "test"; - logger.config().setDocumentTitle(docTitle); - String v = (String) logger.getConfigurationStore().getConfig("documentTitle"); - Assert.assertEquals(v, docTitle); - } - - @Test - public void encodingInitialValueTest(Method method) { - ExtentLoggerReporter logger = new ExtentLoggerReporter(method.getName() + ".html"); - Assert.assertTrue(logger.getConfigurationStore().getConfig("encoding").toString().equalsIgnoreCase("utf-8")); - } - - @Test - public void encodingInitialUserValueTest(Method method) { - ExtentLoggerReporter logger = new ExtentLoggerReporter(method.getName() + ".html"); - String v = (String) logger.getConfigurationStore().getConfig("encoding"); - Assert.assertNotNull(v); - } - - @Test - public void encodingUserValueTest(Method method) { - ExtentLoggerReporter logger = new ExtentLoggerReporter(method.getName() + ".html"); - String encoding = "utf-16"; - logger.config().setEncoding(encoding); - String v = (String) logger.getConfigurationStore().getConfig("encoding"); - Assert.assertEquals(v, encoding); - } -} diff --git a/src/test/java/com/aventstack/extentreports/reporter/LoggerConfigurableReporterTest.java b/src/test/java/com/aventstack/extentreports/reporter/LoggerConfigurableReporterTest.java deleted file mode 100644 index 8a71a02..0000000 --- a/src/test/java/com/aventstack/extentreports/reporter/LoggerConfigurableReporterTest.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.aventstack.extentreports.reporter; - -import java.lang.reflect.Method; - -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; - -public class LoggerConfigurableReporterTest extends Base { - - private static final String CONFIG_PATH = "src/test/resources/html-config.xml"; - private static final String THEME = "dark"; - private static final String ENCODING = "utf-8"; - private static final String DOCUMENT_TITLE = "Extent Framework"; - private static final String REPORT_NAME = "Build 1"; - private static final String TIMESTAMP_FORMAT = "MMM dd, yyyy HH:mm:ss"; - private static final String CSS = ".test.active { border: 1px solid #ccc; }"; - private static final String JS = "$('.test').click(function() { console.log('test'); });"; - - private ExtentLoggerReporter logger; - - @BeforeClass - public void beforeClass() { - logger = new ExtentLoggerReporter("Extent.html"); - logger.loadXMLConfig(CONFIG_PATH); - } - - @Test - public void testTheme(Method method) { - Assert.assertEquals(logger.getConfigurationStore().getConfig("theme"), THEME); - } - - @Test - public void testEncoding(Method method) { - Assert.assertTrue(String.valueOf(logger.getConfigurationStore().getConfig("encoding")).equalsIgnoreCase(ENCODING)); - } - - @Test - public void testDocumentTitle(Method method) { - Assert.assertEquals(logger.getConfigurationStore().getConfig("documentTitle"), DOCUMENT_TITLE); - } - - @Test - public void testReportName(Method method) { - Assert.assertEquals(logger.getConfigurationStore().getConfig("reportName"), REPORT_NAME); - } - - @Test - public void testTimestampFormat(Method method) { - Assert.assertEquals(logger.getConfigurationStore().getConfig("timeStampFormat"), TIMESTAMP_FORMAT); - } - - @Test - public void testCSS(Method method) { - Assert.assertTrue(logger.getConfigurationStore().getConfig("styles").toString().contains(CSS)); - } - - @Test - public void testJS(Method method) { - Assert.assertTrue(logger.getConfigurationStore().getConfig("scripts").toString().contains(JS)); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/reporter/LoggerRichViewReporterConfigurationTest.java b/src/test/java/com/aventstack/extentreports/reporter/LoggerRichViewReporterConfigurationTest.java deleted file mode 100644 index b49530e..0000000 --- a/src/test/java/com/aventstack/extentreports/reporter/LoggerRichViewReporterConfigurationTest.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.aventstack.extentreports.reporter; - -import java.lang.reflect.Method; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.reporter.configuration.Protocol; -import com.aventstack.extentreports.reporter.configuration.Theme; - -public class LoggerRichViewReporterConfigurationTest { - - @Test - public void testHtmlReporterUserConfigEnableTimelineEnabled(Method method) { - ExtentLoggerReporter logger = new ExtentLoggerReporter(method.getName() + ".html"); - logger.config().enableTimeline(true); - String v = (String) logger.getConfigurationStore().getConfig("enableTimeline"); - Assert.assertEquals(v, String.valueOf(true)); - } - - @Test - public void testHtmlReporterUserConfigEnableTimelineDisabled(Method method) { - ExtentLoggerReporter logger = new ExtentLoggerReporter(method.getName() + ".html"); - logger.config().enableTimeline(false); - String v = (String) logger.getConfigurationStore().getConfig("enableTimeline"); - Assert.assertEquals(v, String.valueOf(false)); - } -/* - @Test - public void testHtmlReporterUserConfigAutoConfigMediaEnabled(Method method) { - ExtentLoggerReporter logger = new ExtentLoggerReporter(method.getName() + ".html"); - logger.config().setAutoCreateRelativePathMedia(true); - String v = (String) logger.getConfigurationStore().getConfig("autoCreateRelativePathMedia"); - Assert.assertEquals(v, String.valueOf(true)); - } - - @Test - public void testHtmlReporterUserConfigAutoConfigMediaDisabled(Method method) { - ExtentLoggerReporter logger = new ExtentLoggerReporter(method.getName() + ".html"); - logger.config().setAutoCreateRelativePathMedia(false); - String v = (String) logger.getConfigurationStore().getConfig("autoCreateRelativePathMedia"); - Assert.assertEquals(v, String.valueOf(false)); - } -*/ - @Test - public void testHtmlReporterUserConfigDetaultProtocol(Method method) { - ExtentLoggerReporter logger = new ExtentLoggerReporter(method.getName() + ".html"); - String v = (String) logger.getConfigurationStore().getConfig("protocol"); - Assert.assertEquals(Enum.valueOf(Protocol.class, v.toUpperCase()), Protocol.HTTPS); - } - - @Test - public void testHtmlReporterUserConfigProtocolSetting(Method method) { - ExtentLoggerReporter logger = new ExtentLoggerReporter(method.getName() + ".html"); - logger.config().setProtocol(Protocol.HTTP); - String v = (String) logger.getConfigurationStore().getConfig("protocol"); - Assert.assertEquals(Enum.valueOf(Protocol.class, v.toUpperCase()), Protocol.HTTP); - } - - @Test - public void testHtmlReporterUserConfigDetaultTheme(Method method) { - ExtentLoggerReporter logger = new ExtentLoggerReporter(method.getName() + ".html"); - String v = (String) logger.getConfigurationStore().getConfig("theme"); - Assert.assertEquals(Enum.valueOf(Theme.class, v.toUpperCase()), Theme.STANDARD); - } - - @Test - public void testHtmlReporterUserConfigThemeSetting(Method method) { - ExtentLoggerReporter logger = new ExtentLoggerReporter(method.getName() + ".html"); - logger.config().setTheme(Theme.DARK); - String v = (String) logger.getConfigurationStore().getConfig("theme"); - Assert.assertEquals(Enum.valueOf(Theme.class, v.toUpperCase()), Theme.DARK); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/reporter/OfflineReportTest.java b/src/test/java/com/aventstack/extentreports/reporter/OfflineReportTest.java deleted file mode 100644 index 310a829..0000000 --- a/src/test/java/com/aventstack/extentreports/reporter/OfflineReportTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.aventstack.extentreports.reporter; - -import java.io.File; -import java.lang.reflect.Method; - -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Base; - -public class OfflineReportTest extends Base { - - private static final String OUTPUT_PATH = "target/spark/"; - private static final String LOGGER_SCRIPTS_JS = OUTPUT_PATH + "spark-script.js"; - private static final String LOGGER_STYLES_CSS = OUTPUT_PATH + "spark-style.css"; - - @BeforeClass - public void createOfflineResx() { - ExtentSparkReporter spark = new ExtentSparkReporter("target/"); - spark.config().enableOfflineMode(true); - extent.attachReporter(spark); - } - - @Test - public void verifyScriptsExists(Method method) { - Assert.assertTrue(new File(LOGGER_SCRIPTS_JS).exists()); - } - - @Test - public void verifyStylesExists(Method method) { - Assert.assertTrue(new File(LOGGER_STYLES_CSS).exists()); - } -} diff --git a/src/test/java/com/aventstack/extentreports/reporter/SparkReporterConfigTest.java b/src/test/java/com/aventstack/extentreports/reporter/SparkReporterConfigTest.java new file mode 100644 index 0000000..7cd86d0 --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/reporter/SparkReporterConfigTest.java @@ -0,0 +1,61 @@ +package com.aventstack.extentreports.reporter; + +import java.io.File; +import java.io.IOException; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.aventstack.extentreports.reporter.configuration.ExtentSparkReporterConfig; +import com.aventstack.extentreports.reporter.configuration.Theme; + +public class SparkReporterConfigTest { + @Test + public void configTest() { + ExtentSparkReporter spark = new ExtentSparkReporter("target/spark.html"); + spark.config( + ExtentSparkReporterConfig.builder() + .theme(Theme.DARK) + .documentTitle("MyReport") + .build()); + Assert.assertEquals(spark.getConf().getTheme(), Theme.DARK); + Assert.assertEquals(spark.getConf().getDocumentTitle(), "MyReport"); + } + + @Test + public void loadJSONConfigFileTest() throws IOException { + ExtentSparkReporter spark = new ExtentSparkReporter("target/spark.html"); + spark.loadJSONConfig(new File("config/spark-config.json")); + Assert.assertEquals(spark.getConf().getTheme(), Theme.STANDARD); + Assert.assertEquals(spark.getConf().getDocumentTitle(), "ExtentReports"); + Assert.assertEquals(spark.getConf().getEncoding(), "utf-8"); + } + + @Test + public void loadJSONConfigStringTest() throws IOException { + String json = "{ 'theme': 'DARK', 'documentTitle': 'Extent', 'encoding': 'utf-8' }"; + ExtentSparkReporter spark = new ExtentSparkReporter("target/spark.html"); + spark.loadJSONConfig(json); + Assert.assertEquals(spark.getConf().getTheme(), Theme.DARK); + Assert.assertEquals(spark.getConf().getDocumentTitle(), "Extent"); + Assert.assertEquals(spark.getConf().getEncoding(), "utf-8"); + } + + @Test + public void loadXMLConfigFileTest() throws IOException { + ExtentSparkReporter spark = new ExtentSparkReporter("target/spark.html"); + spark.loadXMLConfig(new File("config/spark-config.xml")); + Assert.assertEquals(spark.getConf().getReportName(), "Build 1"); + Assert.assertEquals(spark.getConf().getDocumentTitle(), "Extent Framework"); + Assert.assertEquals(spark.getConf().getEncoding(), "UTF-8"); + } + + @Test + public void loadXMLConfigPathTest() throws IOException { + ExtentSparkReporter spark = new ExtentSparkReporter("target/spark.html"); + spark.loadXMLConfig("config/spark-config.xml"); + Assert.assertEquals(spark.getConf().getReportName(), "Build 1"); + Assert.assertEquals(spark.getConf().getDocumentTitle(), "Extent Framework"); + Assert.assertEquals(spark.getConf().getEncoding(), "UTF-8"); + } +} diff --git a/src/test/java/com/aventstack/extentreports/reporter/SparkReporterFilterTest.java b/src/test/java/com/aventstack/extentreports/reporter/SparkReporterFilterTest.java new file mode 100644 index 0000000..caee90e --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/reporter/SparkReporterFilterTest.java @@ -0,0 +1,58 @@ +package com.aventstack.extentreports.reporter; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.aventstack.extentreports.ExtentReports; +import com.aventstack.extentreports.Status; + +public class SparkReporterFilterTest { + + @Test + public void singleStatusFilterTestAllFiltered() { + ExtentReports extent = new ExtentReports(); + ExtentSparkReporter spark = new ExtentSparkReporter("target/spark.html"); + spark.filter() + .statusFilter() + .as(new Status[]{Status.FAIL}) + .apply(); + extent.attachReporter(spark); + extent.createTest("Test").pass("Pass"); + extent.flush(); + Assert.assertEquals(spark.getReport().getTestList().size(), 0); + } + + @Test + public void singleStatusFilterTestOneFiltered() { + ExtentReports extent = new ExtentReports(); + ExtentSparkReporter spark = new ExtentSparkReporter("target/spark.html"); + spark.filter() + .statusFilter() + .as(new Status[]{Status.FAIL}) + .apply(); + extent.attachReporter(spark); + extent.createTest("Test1").pass("Pass"); + extent.createTest("Test2").fail("Fail"); + extent.flush(); + Assert.assertEquals(spark.getReport().getTestList().size(), 1); + Assert.assertEquals(spark.getReport().getTestList().get(0).getName(), "Test2"); + } + + @Test + public void singleStatusFilterTestSomeFiltered() { + ExtentReports extent = new ExtentReports(); + ExtentSparkReporter spark = new ExtentSparkReporter("target/spark.html"); + spark.filter() + .statusFilter() + .as(new Status[]{Status.FAIL, Status.SKIP}) + .apply(); + extent.attachReporter(spark); + extent.createTest("Test1").pass("Pass"); + extent.createTest("Test2").fail("Fail"); + extent.createTest("Test3").skip("Skip"); + extent.flush(); + Assert.assertEquals(spark.getReport().getTestList().size(), 2); + Assert.assertEquals(spark.getReport().getTestList().get(0).getName(), "Test2"); + Assert.assertEquals(spark.getReport().getTestList().get(1).getName(), "Test3"); + } +} diff --git a/src/test/java/com/aventstack/extentreports/reporter/SparkReporterTest.java b/src/test/java/com/aventstack/extentreports/reporter/SparkReporterTest.java new file mode 100644 index 0000000..64490ab --- /dev/null +++ b/src/test/java/com/aventstack/extentreports/reporter/SparkReporterTest.java @@ -0,0 +1,181 @@ +package com.aventstack.extentreports.reporter; + +import java.io.File; +import java.util.Calendar; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import com.aventstack.extentreports.ExtentReports; +import com.aventstack.extentreports.Status; + +public class SparkReporterTest { + private static final String FILE_PATH = "target/spark/"; + private static final String FILE_NAME = "spark.html"; + private static final String PARENT = "Parent"; + private static final String CHILD = "Child"; + private static final String GRANDCHILD = "Grandchild"; + private static final String SCRIPTS = "spark-script.js"; + private static final String STYLESHEET = "spark-style.css"; + + private final String path() { + return FILE_PATH + Calendar.getInstance().getTimeInMillis() + FILE_NAME; + } + + private void assertFileExists(String path) { + File f = new File(path); + Assert.assertTrue(f.exists()); + f.delete(); + } + + @Test + public void createsReportWithNoTestsInitPath() { + ExtentReports extent = new ExtentReports(); + String path = path(); + ExtentSparkReporter spark = new ExtentSparkReporter(path); + extent.attachReporter(spark); + extent.flush(); + assertFileExists(path); + } + + @Test + public void createsReportWithNoTestsInitFile() { + ExtentReports extent = new ExtentReports(); + String path = path(); + ExtentSparkReporter spark = new ExtentSparkReporter(new File(path)); + extent.attachReporter(spark); + extent.flush(); + assertFileExists(path); + } + + @Test + public void reportContainsTestsAndNodes() { + ExtentReports extent = new ExtentReports(); + String path = path(); + ExtentSparkReporter spark = new ExtentSparkReporter(path); + extent.attachReporter(spark); + extent.createTest(PARENT) + .createNode(CHILD) + .createNode(GRANDCHILD) + .pass("Pass"); + extent.flush(); + assertFileExists(path); + Assert.assertEquals(spark.getReport().getTestList().size(), 1); + Assert.assertEquals(spark.getReport().getTestList().get(0).getName(), PARENT); + Assert.assertEquals(spark.getReport().getTestList().get(0).getChildren().size(), 1); + Assert.assertEquals(spark.getReport().getTestList().get(0).getChildren().get(0).getName(), CHILD); + Assert.assertEquals(spark.getReport().getTestList().get(0).getChildren().get(0).getChildren().size(), 1); + Assert.assertEquals(spark.getReport().getTestList().get(0).getChildren().get(0).getChildren().get(0).getName(), + GRANDCHILD); + } + + @Test + public void reportContainsTestsAndNodesTags() { + ExtentReports extent = new ExtentReports(); + String path = path(); + ExtentSparkReporter spark = new ExtentSparkReporter(path); + extent.attachReporter(spark); + extent.createTest(PARENT).assignCategory("Tag1") + .createNode(CHILD).assignCategory("Tag2") + .createNode(GRANDCHILD).assignCategory("Tag3") + .pass("Pass"); + extent.flush(); + assertFileExists(path); + com.aventstack.extentreports.model.Test t = spark.getReport().getTestList().get(0); + Assert.assertTrue(t.getCategorySet().stream().anyMatch(x -> x.getName().equals("Tag1"))); + Assert.assertTrue(t.getChildren().get(0).getCategorySet().stream().anyMatch(x -> x.getName().equals("Tag2"))); + Assert.assertTrue(t.getChildren().get(0).getChildren().get(0).getCategorySet().stream() + .anyMatch(x -> x.getName().equals("Tag3"))); + } + + @Test + public void reportContainsTestsAndNodesUsers() { + ExtentReports extent = new ExtentReports(); + String path = path(); + ExtentSparkReporter spark = new ExtentSparkReporter(path); + extent.attachReporter(spark); + extent.createTest(PARENT).assignAuthor("Tag1") + .createNode(CHILD).assignAuthor("Tag2") + .createNode(GRANDCHILD).assignAuthor("Tag3") + .pass("Pass"); + extent.flush(); + assertFileExists(path); + com.aventstack.extentreports.model.Test t = spark.getReport().getTestList().get(0); + Assert.assertTrue(t.getAuthorSet().stream().anyMatch(x -> x.getName().equals("Tag1"))); + Assert.assertTrue(t.getChildren().get(0).getAuthorSet().stream().anyMatch(x -> x.getName().equals("Tag2"))); + Assert.assertTrue(t.getChildren().get(0).getChildren().get(0).getAuthorSet().stream() + .anyMatch(x -> x.getName().equals("Tag3"))); + } + + @Test + public void reportContainsTestsAndNodesDevices() { + ExtentReports extent = new ExtentReports(); + String path = path(); + ExtentSparkReporter spark = new ExtentSparkReporter(path); + extent.attachReporter(spark); + extent.createTest(PARENT).assignDevice("Tag1") + .createNode(CHILD).assignDevice("Tag2") + .createNode(GRANDCHILD).assignDevice("Tag3") + .pass("Pass"); + extent.flush(); + assertFileExists(path); + com.aventstack.extentreports.model.Test t = spark.getReport().getTestList().get(0); + Assert.assertTrue(t.getDeviceSet().stream().anyMatch(x -> x.getName().equals("Tag1"))); + Assert.assertTrue(t.getChildren().get(0).getDeviceSet().stream().anyMatch(x -> x.getName().equals("Tag2"))); + Assert.assertTrue(t.getChildren().get(0).getChildren().get(0).getDeviceSet().stream() + .anyMatch(x -> x.getName().equals("Tag3"))); + } + + @Test + public void statusFilterable() { + ExtentReports extent = new ExtentReports(); + String path = path(); + ExtentSparkReporter spark = new ExtentSparkReporter(path) + .filter() + .statusFilter() + .as(new Status[]{Status.FAIL}) + .apply(); + extent.attachReporter(spark); + extent.createTest(PARENT).pass("Pass"); + extent.createTest(CHILD).fail("Fail"); + extent.flush(); + assertFileExists(path); + Assert.assertEquals(spark.getReport().getTestList().size(), 1); + Assert.assertEquals(spark.getReport().getTestList().get(0).getName(), CHILD); + } + + @Test + public void statusFilterableNode() { + ExtentReports extent = new ExtentReports(); + String path = path(); + ExtentSparkReporter spark = new ExtentSparkReporter(path) + .filter() + .statusFilter() + .as(new Status[]{Status.FAIL}) + .apply(); + extent.attachReporter(spark); + extent.createTest(PARENT).pass("Pass"); + extent.createTest(CHILD).pass("Pass") + .createNode(GRANDCHILD).fail("Fail"); + extent.flush(); + assertFileExists(path); + Assert.assertEquals(spark.getReport().getTestList().size(), 1); + Assert.assertEquals(spark.getReport().getTestList().get(0).getName(), CHILD); + Assert.assertEquals(spark.getReport().getTestList().get(0).getChildren().size(), 1); + Assert.assertEquals(spark.getReport().getTestList().get(0).getChildren().get(0).getName(), GRANDCHILD); + } + + @Test + public void sparkOffline() { + ExtentReports extent = new ExtentReports(); + String path = path(); + ExtentSparkReporter spark = new ExtentSparkReporter(path); + spark.config().enableOfflineMode(true); + extent.attachReporter(spark); + extent.createTest(PARENT).pass("Pass"); + extent.flush(); + assertFileExists(path); + Assert.assertTrue(new File(FILE_PATH + "spark/" + SCRIPTS).exists()); + Assert.assertTrue(new File(FILE_PATH + "spark/" + STYLESHEET).exists()); + } +} diff --git a/src/test/java/com/aventstack/extentreports/testng/components/ExtentTestNGReportBuilder.java b/src/test/java/com/aventstack/extentreports/testng/components/ExtentTestNGReportBuilder.java deleted file mode 100644 index 9b8cda9..0000000 --- a/src/test/java/com/aventstack/extentreports/testng/components/ExtentTestNGReportBuilder.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.aventstack.extentreports.testng.components; - -import java.lang.reflect.Method; - -import org.testng.ITestResult; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.BeforeSuite; - -import com.aventstack.extentreports.ExtentReports; -import com.aventstack.extentreports.ExtentTest; -import com.aventstack.extentreports.common.ExtentManager; -import com.aventstack.extentreports.reporter.ConsoleLogger; - -public class ExtentTestNGReportBuilder { - - private static ExtentReports extent; - private static ThreadLocal parentTest = new ThreadLocal(); - private static ThreadLocal test = new ThreadLocal(); - - @BeforeSuite - public void beforeSuite() { - extent = ExtentManager.createInstance(); - ConsoleLogger logger = new ConsoleLogger(); - extent.attachReporter(logger); - } - - @BeforeClass - public synchronized void beforeClass() { - ExtentTest parent = extent.createTest(getClass().getName()); - parentTest.set(parent); - } - - @BeforeMethod - public synchronized void beforeMethod(Method method) { - ExtentTest child = parentTest.get().createNode(method.getName()); - test.set(child); - } - - @AfterMethod - public synchronized void afterMethod(ITestResult result) { - if (result.getStatus() == ITestResult.FAILURE) - test.get().fail(result.getThrowable()); - else if (result.getStatus() == ITestResult.SKIP) - test.get().skip(result.getThrowable()); - else - test.get().pass("Test passed"); - - extent.flush(); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/testng/components/ParallelTest1.java b/src/test/java/com/aventstack/extentreports/testng/components/ParallelTest1.java deleted file mode 100644 index 46aa49f..0000000 --- a/src/test/java/com/aventstack/extentreports/testng/components/ParallelTest1.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.aventstack.extentreports.testng.components; - -import org.testng.Assert; -import org.testng.Reporter; -import org.testng.SkipException; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Status; - -public class ParallelTest1 extends ExtentTestNGReportBuilder { - - @Test(groups = "pass") - public void passTest1() { - Reporter.log("Started passTest"); - try { Thread.sleep(100); } catch(Exception e) { } - Assert.assertEquals(Status.PASS, Status.PASS); - } - - @Test(expectedExceptions = SkipException.class, groups = "skip") - public void skipTest1() { - try { Thread.sleep(100); } catch(Exception e) { } - throw new SkipException("Intentionally skipped test."); - } - - @Test(expectedExceptions = RuntimeException.class, groups = "fail") - public void failTest1() { - try { Thread.sleep(100); } catch(Exception e) { } - throw new RuntimeException("Intentionally failed test."); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/testng/components/ParallelTest2.java b/src/test/java/com/aventstack/extentreports/testng/components/ParallelTest2.java deleted file mode 100644 index 11c77cc..0000000 --- a/src/test/java/com/aventstack/extentreports/testng/components/ParallelTest2.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.aventstack.extentreports.testng.components; - -import org.testng.Assert; -import org.testng.Reporter; -import org.testng.SkipException; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Status; - -public class ParallelTest2 extends ExtentTestNGReportBuilder { - - @Test(groups = "pass") - public void passTest2() { - Reporter.log("Started passTest"); - try { Thread.sleep(100); } catch(Exception e) { } - Assert.assertEquals(Status.PASS, Status.PASS); - } - - @Test(expectedExceptions = SkipException.class, groups = "skip") - public void skipTest2() { - try { Thread.sleep(100); } catch(Exception e) { } - throw new SkipException("Intentionally skipped test."); - } - - @Test(expectedExceptions = RuntimeException.class, groups = "fail") - public void failTest2() { - try { Thread.sleep(100); } catch(Exception e) { } - throw new RuntimeException("Intentionally failed test."); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/testng/components/ParallelTest3.java b/src/test/java/com/aventstack/extentreports/testng/components/ParallelTest3.java deleted file mode 100644 index f225a4e..0000000 --- a/src/test/java/com/aventstack/extentreports/testng/components/ParallelTest3.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.aventstack.extentreports.testng.components; - -import org.testng.Assert; -import org.testng.Reporter; -import org.testng.SkipException; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Status; - -public class ParallelTest3 extends ExtentTestNGReportBuilder { - - @Test(groups = "pass") - public void passTest2() { - Reporter.log("Started passTest"); - try { Thread.sleep(100); } catch(Exception e) { } - Assert.assertEquals(Status.PASS, Status.PASS); - } - - @Test(expectedExceptions = SkipException.class, groups = "skip") - public void skipTest2() { - try { Thread.sleep(100); } catch(Exception e) { } - throw new SkipException("Intentionally skipped test."); - } - - @Test(expectedExceptions = RuntimeException.class, groups = "fail") - public void failTest2() { - try { Thread.sleep(100); } catch(Exception e) { } - throw new RuntimeException("Intentionally failed test."); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/testng/components/ParallelTest4.java b/src/test/java/com/aventstack/extentreports/testng/components/ParallelTest4.java deleted file mode 100644 index 314ebe8..0000000 --- a/src/test/java/com/aventstack/extentreports/testng/components/ParallelTest4.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.aventstack.extentreports.testng.components; - -import org.testng.Assert; -import org.testng.Reporter; -import org.testng.SkipException; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Status; - -public class ParallelTest4 extends ExtentTestNGReportBuilder { - - @Test(groups = "pass") - public void passTest2() { - Reporter.log("Started passTest"); - try { Thread.sleep(100); } catch(Exception e) { } - Assert.assertEquals(Status.PASS, Status.PASS); - } - - @Test(expectedExceptions = SkipException.class, groups = "skip") - public void skipTest2() { - try { Thread.sleep(100); } catch(Exception e) { } - throw new SkipException("Intentionally skipped test."); - } - - @Test(expectedExceptions = RuntimeException.class, groups = "fail") - public void failTest2() { - try { Thread.sleep(100); } catch(Exception e) { } - throw new RuntimeException("Intentionally failed test."); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/viewdefs/ViewDefsIconOverrideTest.java b/src/test/java/com/aventstack/extentreports/viewdefs/ViewDefsIconOverrideTest.java deleted file mode 100644 index c48063d..0000000 --- a/src/test/java/com/aventstack/extentreports/viewdefs/ViewDefsIconOverrideTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.aventstack.extentreports.viewdefs; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Status; - -public class ViewDefsIconOverrideTest { - - @Test - public void testTWBSColorPassReturnsValue() { - Icon icon = new Icon(); - String ico = "close"; - icon.override(Status.PASS, ico); - Assert.assertTrue(icon.getIcon(Status.PASS).equals(ico)); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/viewdefs/ViewDefsIconTest.java b/src/test/java/com/aventstack/extentreports/viewdefs/ViewDefsIconTest.java deleted file mode 100644 index bd509c0..0000000 --- a/src/test/java/com/aventstack/extentreports/viewdefs/ViewDefsIconTest.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.aventstack.extentreports.viewdefs; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Status; - -public class ViewDefsIconTest { - - private Icon icon = new Icon(); - - @Test - public void testiconColorPassReturnsValue() { - Assert.assertTrue(icon.getIcon(Status.PASS) != null && !icon.getIcon(Status.PASS).isEmpty()); - } - - @Test - public void testiconColorFailReturnsValue() { - Assert.assertTrue(icon.getIcon(Status.FAIL) != null && !icon.getIcon(Status.FAIL).isEmpty()); - } - - @Test - public void testiconColorFatalReturnsValue() { - Assert.assertTrue(icon.getIcon(Status.FATAL) != null && !icon.getIcon(Status.FATAL).isEmpty()); - } - - @Test - public void testiconColorErrorReturnsValue() { - Assert.assertTrue(icon.getIcon(Status.ERROR) != null && !icon.getIcon(Status.ERROR).isEmpty()); - } - - @Test - public void testiconColorSkipReturnsValue() { - Assert.assertTrue(icon.getIcon(Status.SKIP) != null && !icon.getIcon(Status.SKIP).isEmpty()); - } - - @Test - public void testiconColorInfoReturnsValue() { - Assert.assertTrue(icon.getIcon(Status.INFO) != null && !icon.getIcon(Status.INFO).isEmpty()); - } - - @Test - public void testiconColorDebugReturnsValue() { - Assert.assertTrue(icon.getIcon(Status.DEBUG) != null && !icon.getIcon(Status.DEBUG).isEmpty()); - } - - @Test - public void testiconColorWarningReturnsValue() { - Assert.assertTrue(icon.getIcon(Status.WARNING) != null && !icon.getIcon(Status.WARNING).isEmpty()); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/viewdefs/ViewDefsTWBSColorOverrideTest.java b/src/test/java/com/aventstack/extentreports/viewdefs/ViewDefsTWBSColorOverrideTest.java deleted file mode 100644 index 8e9107c..0000000 --- a/src/test/java/com/aventstack/extentreports/viewdefs/ViewDefsTWBSColorOverrideTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.aventstack.extentreports.viewdefs; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Status; - -public class ViewDefsTWBSColorOverrideTest { - - @Test - public void testTWBSColorPassReturnsValue() { - TWBSColor twbs = new TWBSColor(); - String color = "green"; - twbs.override(Status.PASS, color); - Assert.assertTrue(twbs.getColor(Status.PASS).equals(color)); - } - -} diff --git a/src/test/java/com/aventstack/extentreports/viewdefs/ViewDefsTWBSColorTest.java b/src/test/java/com/aventstack/extentreports/viewdefs/ViewDefsTWBSColorTest.java deleted file mode 100644 index 9922f9e..0000000 --- a/src/test/java/com/aventstack/extentreports/viewdefs/ViewDefsTWBSColorTest.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.aventstack.extentreports.viewdefs; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.aventstack.extentreports.Status; - -public class ViewDefsTWBSColorTest { - - private TWBSColor twbs = new TWBSColor(); - - @Test - public void testTWBSColorPassReturnsValue() { - Assert.assertTrue(twbs.getColor(Status.PASS) != null && !twbs.getColor(Status.PASS).isEmpty()); - } - - @Test - public void testTWBSColorFailReturnsValue() { - Assert.assertTrue(twbs.getColor(Status.FAIL) != null && !twbs.getColor(Status.FAIL).isEmpty()); - } - - @Test - public void testTWBSColorFatalReturnsValue() { - Assert.assertTrue(twbs.getColor(Status.FATAL) != null && !twbs.getColor(Status.FATAL).isEmpty()); - } - - @Test - public void testTWBSColorErrorReturnsValue() { - Assert.assertTrue(twbs.getColor(Status.ERROR) != null && !twbs.getColor(Status.ERROR).isEmpty()); - } - - @Test - public void testTWBSColorSkipReturnsValue() { - Assert.assertTrue(twbs.getColor(Status.SKIP) != null && !twbs.getColor(Status.SKIP).isEmpty()); - } - - @Test - public void testTWBSColorInfoReturnsValue() { - Assert.assertTrue(twbs.getColor(Status.INFO) != null && !twbs.getColor(Status.INFO).isEmpty()); - } - - @Test - public void testTWBSColorDebugReturnsEmpty() { - Assert.assertTrue(twbs.getColor(Status.DEBUG) != null && twbs.getColor(Status.DEBUG).isEmpty()); - } - - @Test - public void testTWBSColorWarningReturnsValue() { - Assert.assertTrue(twbs.getColor(Status.WARNING) != null && !twbs.getColor(Status.WARNING).isEmpty()); - } - - @Test - public void testTWBSBgColorPassReturnsValue() { - Assert.assertTrue(twbs.getBgColor(Status.PASS) != null && !twbs.getBgColor(Status.PASS).isEmpty()); - } - - @Test - public void testTWBSBgColorFailReturnsValue() { - Assert.assertTrue(twbs.getBgColor(Status.FAIL) != null && !twbs.getBgColor(Status.FAIL).isEmpty()); - } - - @Test - public void testTWBSBgColorFatalReturnsValue() { - Assert.assertTrue(twbs.getBgColor(Status.FATAL) != null && !twbs.getBgColor(Status.FATAL).isEmpty()); - } - - @Test - public void testTWBSBgColorErrorReturnsValue() { - Assert.assertTrue(twbs.getBgColor(Status.ERROR) != null && !twbs.getBgColor(Status.ERROR).isEmpty()); - } - - @Test - public void testTWBSBgColorSkipReturnsValue() { - Assert.assertTrue(twbs.getBgColor(Status.SKIP) != null && !twbs.getBgColor(Status.SKIP).isEmpty()); - } - - @Test - public void testTWBSBgColorInfoReturnsValue() { - Assert.assertTrue(twbs.getBgColor(Status.INFO) != null && !twbs.getBgColor(Status.INFO).isEmpty()); - } - - @Test - public void testTWBSBgColorDebugReturnsEmpty() { - Assert.assertTrue(twbs.getBgColor(Status.DEBUG) != null && twbs.getBgColor(Status.DEBUG).isEmpty()); - } - - @Test - public void testTWBSBgColorWarningReturnsValue() { - Assert.assertTrue(twbs.getBgColor(Status.WARNING) != null && !twbs.getBgColor(Status.WARNING).isEmpty()); - } - -} diff --git a/src/test/resources/1.png b/src/test/resources/1.png deleted file mode 100644 index fc16a13..0000000 Binary files a/src/test/resources/1.png and /dev/null differ diff --git a/src/test/resources/com/aventstack/extentreports/testng/parallel/parallel-classes-api-tests.xml b/src/test/resources/com/aventstack/extentreports/testng/parallel/parallel-classes-api-tests.xml deleted file mode 100644 index 71e23c7..0000000 --- a/src/test/resources/com/aventstack/extentreports/testng/parallel/parallel-classes-api-tests.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/test/resources/com/aventstack/extentreports/testng/parallel/parallel-classes-testng-components.xml b/src/test/resources/com/aventstack/extentreports/testng/parallel/parallel-classes-testng-components.xml deleted file mode 100644 index a524d9d..0000000 --- a/src/test/resources/com/aventstack/extentreports/testng/parallel/parallel-classes-testng-components.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/src/test/resources/com/aventstack/extentreports/testng/parallel/parallel-classes.xml b/src/test/resources/com/aventstack/extentreports/testng/parallel/parallel-classes.xml deleted file mode 100644 index 2a68c14..0000000 --- a/src/test/resources/com/aventstack/extentreports/testng/parallel/parallel-classes.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/src/test/resources/com/aventstack/extentreports/testng/parallel/parallel-methods.xml b/src/test/resources/com/aventstack/extentreports/testng/parallel/parallel-methods.xml deleted file mode 100644 index 6f177d3..0000000 --- a/src/test/resources/com/aventstack/extentreports/testng/parallel/parallel-methods.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/src/test/resources/com/aventstack/extentreports/testng/parallel/suite.xml b/src/test/resources/com/aventstack/extentreports/testng/parallel/suite.xml deleted file mode 100644 index b6a27eb..0000000 --- a/src/test/resources/com/aventstack/extentreports/testng/parallel/suite.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/src/test/resources/config/spark-config.json b/src/test/resources/config/spark-config.json new file mode 100644 index 0000000..c66c995 --- /dev/null +++ b/src/test/resources/config/spark-config.json @@ -0,0 +1,12 @@ +{ + "theme": "DARK", + "encoding": "utf-16", + "protocol": "HTTP", + "timelineEnabled": true, + "offlineMode": true, + "documentTitle": "Test1", + "reportName": "Test2", + "timeStampFormat": "MMM dd, yyyy HH:mm:ss a", + "js": "js1", + "css": "css1" +} diff --git a/src/test/resources/config/spark-config.xml b/src/test/resources/config/spark-config.xml new file mode 100644 index 0000000..d629023 --- /dev/null +++ b/src/test/resources/config/spark-config.xml @@ -0,0 +1,40 @@ + + + + + + + DARK + + + + utf-16 + + + + + HTTP + + + true + + + true + + + Test1 + + + Test2 + + + MMM dd, yyyy HH:mm:ss a + + + js1 + + + css1 + + + \ No newline at end of file diff --git a/src/test/resources/config/spark-config_lowercase_enum.json b/src/test/resources/config/spark-config_lowercase_enum.json new file mode 100644 index 0000000..f2a0880 --- /dev/null +++ b/src/test/resources/config/spark-config_lowercase_enum.json @@ -0,0 +1,12 @@ +{ + "theme": "dark", + "encoding": "utf-16", + "protocol": "http", + "timelineEnabled": true, + "offlineMode": true, + "documentTitle": "Test1", + "reportName": "Test2", + "timeStampFormat": "MMM dd, yyyy HH:mm:ss a", + "js": "js1", + "css": "css1" +} diff --git a/src/test/resources/config/spark-config_lowercase_enum.xml b/src/test/resources/config/spark-config_lowercase_enum.xml new file mode 100644 index 0000000..4193a3d --- /dev/null +++ b/src/test/resources/config/spark-config_lowercase_enum.xml @@ -0,0 +1,40 @@ + + + + + + + dark + + + + utf-16 + + + + + http + + + true + + + true + + + Test1 + + + Test2 + + + MMM dd, yyyy HH:mm:ss a + + + js1 + + + css1 + + + \ No newline at end of file diff --git a/src/test/resources/html-config.xml b/src/test/resources/html-config.xml deleted file mode 100644 index 0ad8c8d..0000000 --- a/src/test/resources/html-config.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - dark - - - - UTF-8 - - - - https - - - Extent Framework - - - Build 1 - - - MMM dd, yyyy HH:mm:ss - - - true - false - true - true - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/test/resources/img.png b/src/test/resources/img.png new file mode 100644 index 0000000..ffe2c29 Binary files /dev/null and b/src/test/resources/img.png differ diff --git a/src/test/resources/logger-config.xml b/src/test/resources/logger-config.xml deleted file mode 100644 index 0ad8c8d..0000000 --- a/src/test/resources/logger-config.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - dark - - - - UTF-8 - - - - https - - - Extent Framework - - - Build 1 - - - MMM dd, yyyy HH:mm:ss - - - true - false - true - true - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/test/resources/logo.png b/src/test/resources/logo.png deleted file mode 100644 index fc16a13..0000000 Binary files a/src/test/resources/logo.png and /dev/null differ