open-test-reporting-r0.1.0-M1/000077500000000000000000000000001421732762500161035ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/.gitattributes000066400000000000000000000002321421732762500207730ustar00rootroot00000000000000# # https://help.github.com/articles/dealing-with-line-endings/ # # These are explicitly windows files and should use crlf *.bat text eol=crlf open-test-reporting-r0.1.0-M1/.gitignore000066400000000000000000000001741421732762500200750ustar00rootroot00000000000000# Ignore Gradle project-specific cache directory .gradle # Ignore Gradle build output directory build # SDKMAN! .sdkmanrc open-test-reporting-r0.1.0-M1/LICENSE.md000066400000000000000000000243771421732762500175240ustar00rootroot00000000000000Apache License ============== _Version 2.0, January 2004_ _<>_ ### Terms and Conditions for use, reproduction, and distribution #### 1. Definitions “License” shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. “Licensor” shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. “Legal Entity” shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, “control” means **(i)** the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or **(ii)** ownership of fifty percent (50%) or more of the outstanding shares, or **(iii)** beneficial ownership of such entity. “You” (or “Your”) shall mean an individual or Legal Entity exercising permissions granted by this License. “Source” form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. “Object” form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. “Work” shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). “Derivative Works” shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. “Contribution” shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, “submitted” means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as “Not a Contribution.” “Contributor” shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. #### 2. Grant of Copyright License Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. #### 3. Grant of Patent License Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. #### 4. Redistribution You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: * **(a)** You must give any other recipients of the Work or Derivative Works a copy of this License; and * **(b)** You must cause any modified files to carry prominent notices stating that You changed the files; and * **(c)** You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and * **(d)** If the Work includes a “NOTICE” text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. #### 5. Submission of Contributions Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. #### 6. Trademarks This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. #### 7. Disclaimer of Warranty Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. #### 8. Limitation of Liability In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. #### 9. Accepting Warranty or Additional Liability While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. _END OF TERMS AND CONDITIONS_ ### APPENDIX: How to apply the Apache License to your work To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets `[]` replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same “printed page” as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. open-test-reporting-r0.1.0-M1/README.adoc000066400000000000000000000257431421732762500177030ustar00rootroot00000000000000= Open Test Reporting New test reporting formats that are agnostic of testing framework and programming language. == Introduction This repository contains the definition of and tooling for two new XML-based test reporting formats that are agnostic of any testing framework and programming language yet concrete enough to be consumable by a wide range of downstream tools such as IDEs, build tools, and report generators. The first format is _event-based_ which is not only suitable for writing events to a file but also for streaming events over a local socket or network connection. Instead of having to collect all data for a test only to write it to the report after the test has completed, testing frameworks can emit events as they occur, for example when a test is started or finished. The second format is meant to be closer to existing _hierarchical_ representations of test results that users are familiar with. For example, when executing tests in IDEs, one is usually presented with a tree of tests and their results. This same structure can be found in files that use this format. Thus, instead of requiring humans or processing tools to piece together all relevant events for a test from the event-based format, this hierarchical format collects all relevant information in a single place for each test. Besides being human-readable, this format is easier to transform into an HTML report by a downstream reporting tool or CI server. The two formats are designed to complement each other such that the event-based format can be mechanically converted into the hierarchical one. This repository contains a reference implementation of such a converter as an executable and library. This way, testing frameworks can focus on writing the event-based format; build tools may use the converter to write the hierarchical format; and reporting tools can consume whichever format they prefer. == Prior art In the Java ecosystem, Ant originally defined an XML-based reporting format for tests. Other build tools like Maven and Gradle have adopted the format and, in the case of Maven Surefire, later made changes to add additional data. Many build servers know how to parse the XML-based format, and even non-Java tools sometimes support it. However, it’s based on the concept of test classes and methods, so using it for frameworks and tools where those elements are not present is awkward at best. Moreover, it does not support nested structures beyond a simple parent-child relationship. Finally, it is not extensible: no additional attributes can be added without the risk of breaking existing tools. For those reasons, many testing frameworks such as TestNG and Spock have defined their own reporting formats. This has given them the flexibility they need, but the number of tools that can parse, display, or transform their custom formats is very limited. To overcome the limitations described above, this document defines a new format for test reporting. Its goal is to be platform-agnostic so that as many testing frameworks as possible can benefit from it. Moreover, it is designed to be extensible so new data can be added as needed, without breaking consumers. However, all well-known attributes are properly defined so it’s consumable by downstream reporting tools. == Design goals human-readable:: The new format needs to be human-readable so it can be inspected without requiring another tool. A format that represents the test tree via nesting is easier to understand than a flat list of events that reference their parents via IDs. streamable:: Writing report files during test execution should not require keeping state about currently running tests, etc. in memory. Instead, the new format should allow tools to write events to a file as they occur. machine-readable:: At the same time, the format must be machine-readable so it can be easily parsed and transformed on a variety of platforms. schema-aware:: Implementors and tools should be able to validate a given document against a well-known schema. extensible:: Adding additional language- or framework-specific attributes to nodes must be possible without breaking backwards compatibility. === XML vs. JSON JSON is less verbose than XML, but the latter provides more expressive ways to define schemas. Moreover, XML has typed extensions built-in via the use of multiple schemas. Thus, the new formats use XML with accompanying XML schemas. == Format specification Both formats share a set of core elements that is defined in link:schema/src/main/resources/org/opentest4j/reporting/schema/core.xsd[core.xsd]. === Event-based format The event-based format is defined in link:schema/src/main/resources/org/opentest4j/reporting/schema/events.xsd[events.xsd]. The following example shows the result of a test run with a single top-level "container" and a "test" child. [source,xml] ---- wonderland alice ---- <1> attributes of the infrastructure the tests were run on <2> start event of "container" with timestamp <3> start event of "test" with timestamp and reference to its parent "container" <4> finished event of "test" with timestamp and result status <5> finished event of "container" with timestamp and result status This file contains 4 events: 2 started and 2 finished ones. The test framework reporting these events was able to write them as they occurred. In particular, it did not have to wait for all children of "container" to be finished. === Hierarchical format The event-based format is defined in link:schema/src/main/resources/org/opentest4j/reporting/schema/hierarchy.xsd[hierarchy.xsd]. The following example shows the result of converting the above event-based report into the hierarchical format. [source,xml] ---- wonderland alice ---- <1> attributes of the infrastructure the tests were run on (same as in the event-based format) <2> root node of "container" with timestamp, duration, and result status <3> child node of "test" with timestamp, duration, and result status === Java extensions All schema definitions mentioned so far are language-agnostic. In order to report Java-specific attributes, e.g. the class or method name of a test, an extension schema is defined in link:schema/src/main/resources/org/opentest4j/reporting/schema/java.xsd[java.xsd]. NOTE: Test frameworks are encouraged to define their own similar framework-specific extensions if they want to report additional information that is not suitable to be added to the core namespace. == Reference implementation While the reporting formats are language-agnostic, the reference implementation is written in Java due to being the language its authors are most familiar with. This repository contains the following subprojects: schema:: XML schema definitions of both formats events:: Java API for writing the event-based format without having to deal with Java's XML APIs cli:: Command-line interface for validating both fomats and converting from the event-based to the hierarchical format tooling:: Java API for validating both formats and converting from the event-based to the hierarchical format (suitable for inclusion in build tools and reporting tools) === API for writing event-based format Testing frameworks that run on the JVM can use the API provided by the _events_ subprojects as follows. [source,java] ---- import org.opentest4j.reporting.events.api.DocumentWriter; import org.opentest4j.reporting.events.api.NamespaceRegistry; import org.opentest4j.reporting.events.core.CoreFactory; import org.opentest4j.reporting.events.root.Events; import org.opentest4j.reporting.schema.Namespace; import java.nio.file.Paths; import java.time.Instant; import static org.opentest4j.reporting.events.core.CoreFactory.*; import static org.opentest4j.reporting.events.core.Result.Status.SUCCESSFUL; import static org.opentest4j.reporting.events.root.RootFactory.finished; import static org.opentest4j.reporting.events.root.RootFactory.started; public class DocumentWriterSample { public static void main(String[] args) throws Exception { NamespaceRegistry namespaceRegistry = NamespaceRegistry.builder(Namespace.REPORTING_CORE) // <1> .add("e", Namespace.REPORTING_EVENTS) // .add("java", Namespace.REPORTING_JAVA) // .build(); try (DocumentWriter writer = Events.createDocumentWriter(namespaceRegistry, Paths.get("events.xml"))) { writer.append(infrastructure(), infrastructure -> infrastructure // <2> .append(userName("alice")) // .append(hostName("wonderland"))); writer.append(started("1", Instant.now(), "container")); // <3> writer.append(started("2", Instant.now(), "test"), started -> started.withParentId("1")); // <4> writer.append(finished("2", Instant.now()), finished -> finished.append(CoreFactory.result(SUCCESSFUL))); // <5> writer.append(finished("1", Instant.now()), finished -> finished.append(CoreFactory.result(SUCCESSFUL))); // <6> } } } ---- <1> create a registry of all namespaces used in the document along with their prefixes <2> report infrastructure attributes <3> start event of "container" with timestamp <4> start event of "test" with timestamp and reference to its parent "container" <5> finished event of "test" with timestamp and result status <6> finished event of "container" with timestamp and result status === CLI tool for validation and format conversion The CLI tool provided by the _cli_ subprojects provides subcommands for validating both formats and converting from the event-based to the hierarchical format. [source,console] ---- $ ./open-test-reporting convert events.xml ℹ️ Converted events.xml to hierarchy.xml ---- NOTE: Please refer to the CLI tool's `--help` option for more information. open-test-reporting-r0.1.0-M1/build.gradle.kts000066400000000000000000000002641421732762500211640ustar00rootroot00000000000000plugins { id("io.github.gradle-nexus.publish-plugin") version "1.1.0" } nexusPublishing { packageGroup.set("org.opentest4j") repositories { sonatype() } } open-test-reporting-r0.1.0-M1/buildSrc/000077500000000000000000000000001421732762500176525ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/buildSrc/build.gradle.kts000066400000000000000000000004321421732762500227300ustar00rootroot00000000000000plugins { `kotlin-dsl` } repositories { mavenCentral() gradlePluginPortal() } dependencies { implementation("com.diffplug.spotless:spotless-plugin-gradle:6.1.2") } tasks { compileKotlin { kotlinOptions { jvmTarget = "17" } } } open-test-reporting-r0.1.0-M1/buildSrc/src/000077500000000000000000000000001421732762500204415ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/buildSrc/src/main/000077500000000000000000000000001421732762500213655ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/buildSrc/src/main/kotlin/000077500000000000000000000000001421732762500226655ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/buildSrc/src/main/kotlin/java-conventions.gradle.kts000066400000000000000000000030431421732762500301310ustar00rootroot00000000000000plugins { `java-library` id("com.diffplug.spotless") id("publishing-conventions") } base { archivesName.set("open-test-reporting-${project.name}") } java { toolchain.languageVersion.set(JavaLanguageVersion.of(17)) withSourcesJar() withJavadocJar() } spotless { val spotlessDir = rootProject.file("gradle/spotless") val licenseHeaderFile = File(spotlessDir, "apache-license-2.0.java") val javaFormatterConfigFile = File(spotlessDir, "eclipse-formatter-settings.xml") java { licenseHeaderFile(licenseHeaderFile, "(package|import|open|module) ") eclipse().configFile(javaFormatterConfigFile) trimTrailingWhitespace() endWithNewline() } } tasks { compileJava { options.release.convention(8) } compileTestJava { options.release.convention(17) } jar { manifest { attributes("Automatic-Module-Name" to "org.opentest4j.reporting.${project.name}") } } javadoc { (options as StandardJavadocDocletOptions).apply { addBooleanOption("Werror", true) addBooleanOption("Xdoclint:all", true) } } tasks.withType().configureEach { from(rootDir) { include("LICENSE.md") into("META-INF") } } test { useJUnitPlatform() } } configure { publications { named("maven") { from(components["java"]) artifactId = base.archivesName.get() } } } open-test-reporting-r0.1.0-M1/buildSrc/src/main/kotlin/publishing-conventions.gradle.kts000066400000000000000000000032511421732762500313550ustar00rootroot00000000000000import org.gradle.api.publish.maven.MavenPublication plugins { `maven-publish` signing } val isSnapshot = project.version.toString().contains("SNAPSHOT") val isContinuousIntegrationEnvironment = System.getenv("CI")?.toBoolean() ?: false signing { useGpgCmd() sign(publishing.publications) isRequired = !(isSnapshot || isContinuousIntegrationEnvironment) } tasks.withType().configureEach { onlyIf { !isSnapshot // Gradle Module Metadata currently does not support signing snapshots } } publishing { publications { create("maven") { pom { name.set(provider { artifactId }) description.set(provider { "Module \"${project.name}\" of open-test-reporting" }) url.set("https://github.com/ota4j-team/open-test-reporting") scm { connection.set("scm:git:git://github.com/ota4j-team/open-test-reporting.git") developerConnection.set("scm:git:git://github.com/ota4j-team/open-test-reporting.git") url.set("https://github.com/ota4j-team/open-test-reporting") } licenses { license { name.set("The Apache License, Version 2.0") url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") } } developers { developer { id.set("marcphilipp") name.set("Marc Philipp") email.set("marc@junit.org") } } } } } } open-test-reporting-r0.1.0-M1/cli/000077500000000000000000000000001421732762500166525ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/cli/build.gradle.kts000066400000000000000000000006701421732762500217340ustar00rootroot00000000000000plugins { `java-conventions` application } application { applicationName = "open-test-reporting" mainClass.set("org.opentest4j.reporting.cli.ReportingCli") } dependencies { implementation(projects.events) implementation(projects.tooling) implementation(libs.picocli) implementation(libs.slf4j.api) runtimeOnly(libs.log4j.slf4j.impl) } tasks { compileJava { options.release.set(11) } } open-test-reporting-r0.1.0-M1/cli/src/000077500000000000000000000000001421732762500174415ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/cli/src/main/000077500000000000000000000000001421732762500203655ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/cli/src/main/java/000077500000000000000000000000001421732762500213065ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/cli/src/main/java/org/000077500000000000000000000000001421732762500220755ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/cli/src/main/java/org/opentest4j/000077500000000000000000000000001421732762500241745ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/cli/src/main/java/org/opentest4j/reporting/000077500000000000000000000000001421732762500262055ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/cli/src/main/java/org/opentest4j/reporting/cli/000077500000000000000000000000001421732762500267545ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/cli/src/main/java/org/opentest4j/reporting/cli/ConvertCommand.java000066400000000000000000000030411421732762500325340ustar00rootroot00000000000000/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.cli; import org.opentest4j.reporting.tooling.converter.DefaultConverter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import picocli.CommandLine.Command; import picocli.CommandLine.Parameters; import java.nio.file.Path; import java.util.concurrent.Callable; /** * Converts from the event-based to the hierarchical XML format. */ @Command(name = "convert", description = "Converts from the event-based to the hierarchical XML format") public class ConvertCommand implements Callable { private static final Logger LOG = LoggerFactory.getLogger(ConvertCommand.class); @Parameters(arity = "1") Path eventsXml; @Override public Integer call() throws Exception { var targetFile = eventsXml.resolveSibling("hierarchy.xml"); var converter = new DefaultConverter(); converter.convert(eventsXml, targetFile); LOG.info("Converted {} to {}", eventsXml, targetFile); return 0; } } open-test-reporting-r0.1.0-M1/cli/src/main/java/org/opentest4j/reporting/cli/ReportingCli.java000066400000000000000000000024731421732762500322260ustar00rootroot00000000000000/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.cli; import picocli.CommandLine; import picocli.CommandLine.Command; import picocli.CommandLine.HelpCommand; /** * Main entrypoint into the reporting CLI * * @see ConvertCommand * @see ValidateCommand */ @Command(// name = "open-test-reporting", // mixinStandardHelpOptions = true, // subcommands = { HelpCommand.class, ConvertCommand.class, ValidateCommand.class } // ) public class ReportingCli { /** * Run the reporting CLI. * * @param args command-line arguments */ @SuppressWarnings("InstantiationOfUtilityClass") public static void main(String[] args) { int exitCode = new CommandLine(new ReportingCli()).execute(args); System.exit(exitCode); } } open-test-reporting-r0.1.0-M1/cli/src/main/java/org/opentest4j/reporting/cli/ValidateCommand.java000066400000000000000000000055001421732762500326470ustar00rootroot00000000000000/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.cli; import org.opentest4j.reporting.tooling.validator.DefaultValidator; import org.opentest4j.reporting.tooling.validator.ValidationResult; import org.opentest4j.reporting.tooling.validator.Validator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import picocli.CommandLine.Command; import picocli.CommandLine.Option; import picocli.CommandLine.Parameters; import java.net.URI; import java.nio.file.Path; import java.util.List; import java.util.concurrent.Callable; import static org.opentest4j.reporting.tooling.validator.Severity.ERROR; import static org.opentest4j.reporting.tooling.validator.Severity.WARNING; /** * Validates XML report files of both formats. */ @Command(name = "validate", description = "Validates XML report files of both formats") public class ValidateCommand implements Callable { private static final Logger LOG = LoggerFactory.getLogger(ValidateCommand.class); @Parameters(arity = "1..*") List xmlFiles; @Option(names = "--catalog") List catalogs = List.of(); @Override public Integer call() { return validateAll() ? 0 : 1; } private boolean validateAll() { var validator = new DefaultValidator(catalogs.stream().map(Path::toUri).toArray(URI[]::new)); boolean allValid = true; for (var xmlFile : xmlFiles) { allValid &= validate(validator, xmlFile); } return allValid; } private boolean validate(Validator validator, Path xmlFile) { try { var validationResult = validator.validate(xmlFile); logValidationMessages(validationResult); var errors = validationResult.count(ERROR); if (errors == 0) { LOG.info("Valid: {}", xmlFile); return true; } else { LOG.info("Invalid ({} {}): {}", errors, errors == 1 ? "error" : "errors", xmlFile); return false; } } catch (Exception e) { LOG.error("Failure during validation: {}", xmlFile, e); return false; } } private void logValidationMessages(ValidationResult validationResult) { validationResult.forEach(message -> { if (message.getSeverity() == WARNING) { LOG.warn("{}\n{}", message.getLocation(), message.getMessage()); } else { LOG.error("{}\n{}", message.getLocation(), message.getMessage()); } }); } } open-test-reporting-r0.1.0-M1/cli/src/main/resources/000077500000000000000000000000001421732762500223775ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/cli/src/main/resources/log4j2.xml000066400000000000000000000007351421732762500242270ustar00rootroot00000000000000 open-test-reporting-r0.1.0-M1/documentation/000077500000000000000000000000001421732762500207545ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/documentation/build.gradle.kts000066400000000000000000000006421421732762500240350ustar00rootroot00000000000000plugins { id("org.ajoberstar.git-publish") version "4.1.0" } val schemas by configurations.creating { isCanBeConsumed = false isCanBeResolved = true } dependencies { schemas(project(":schema", "schemas")) } gitPublish { repoUri.set("https://github.com/ota4j-team/open-test-reporting.git") branch.set("gh-pages") contents { from(schemas) into("schemas/snapshot") } } open-test-reporting-r0.1.0-M1/events/000077500000000000000000000000001421732762500174075ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/build.gradle.kts000066400000000000000000000003661421732762500224730ustar00rootroot00000000000000plugins { `java-conventions` } dependencies { api(projects.schema) testImplementation(libs.archunit) testImplementation(libs.assertj.core) testImplementation(libs.junit.jupiter) testImplementation(libs.xmlunit.assertj) } open-test-reporting-r0.1.0-M1/events/src/000077500000000000000000000000001421732762500201765ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/000077500000000000000000000000001421732762500211225ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/000077500000000000000000000000001421732762500220435ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/000077500000000000000000000000001421732762500226325ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/000077500000000000000000000000001421732762500247315ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/000077500000000000000000000000001421732762500267425ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/000077500000000000000000000000001421732762500302465ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/api/000077500000000000000000000000001421732762500310175ustar00rootroot00000000000000Appendable.java000066400000000000000000000032531421732762500336410ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/api/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.api; import java.util.function.Consumer; /** * Interface for objects that support appending child {@linkplain Element elements}. * * @param parent element type */ public interface Appendable> { /** * Append the child element created by the supplied {@linkplain Factory factory}. * * @param creator child element factory * @param child element type * @return self reference to allow method chaining */ default > Appendable append(Factory creator) { return append(creator, __ -> { }); } /** * Append the child element created by the supplied {@linkplain Factory factory} configured by the supplied {@linkplain Consumer consumer}. * * @param creator child element factory * @param configurer child element configurer * @param child element type * @return self reference to allow method chaining */ > Appendable append(Factory creator, Consumer configurer); } ChildElement.java000066400000000000000000000024471421732762500341470ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/api/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.api; import org.opentest4j.reporting.schema.QualifiedName; /** * Base class for child elements with well-known parent types. * * @param

parent element type * @param child element type */ public class ChildElement

, T extends ChildElement> extends Element { /** * Create an instance with the supplied {@linkplain Context context} and {@linkplain QualifiedName qualified name}. * * @param context the context of this instance * @param qualifiedName the qualified name of this instance */ public ChildElement(Context context, QualifiedName qualifiedName) { super(context, qualifiedName); } } open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/api/Context.java000066400000000000000000000060061421732762500333100ustar00rootroot00000000000000/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.api; import org.opentest4j.reporting.schema.QualifiedName; import org.w3c.dom.Document; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; /** * Context encapsulating a single XML document along with its namespace configuration. */ public class Context { static Context create(QualifiedName rootElement, NamespaceRegistry namespaceRegistry) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); try { DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.newDocument(); Context context = new Context(document, namespaceRegistry); document.appendChild(createRoot(rootElement, namespaceRegistry, context)); return context; } catch (Exception e) { throw new RuntimeException(e); } } private static org.w3c.dom.Element createRoot(QualifiedName rootElement, NamespaceRegistry namespaceRegistry, Context context) { org.w3c.dom.Element root = context.createElement(rootElement); namespaceRegistry.getAdditionalNamespaces() // .forEach(namespace -> { String prefix = namespaceRegistry.getPrefix(namespace).orElseThrow(IllegalStateException::new); root.setAttribute("xmlns:" + prefix, namespace.getUri()); }); return root; } private final ConcurrentMap prefixedNames = new ConcurrentHashMap<>(); private final Document document; private final NamespaceRegistry namespaceRegistry; private Context(Document document, NamespaceRegistry namespaceRegistry) { this.document = document; this.namespaceRegistry = namespaceRegistry; } Document getDocument() { return document; } org.w3c.dom.Element createElement(QualifiedName qualifiedName) { return namespaceRegistry.getPrefix(qualifiedName.getNamespace()).isPresent() ? document.createElementNS(qualifiedName.getNamespace().getUri(), prefixed(qualifiedName)) : document.createElement(qualifiedName.getSimpleName()); } String prefixed(QualifiedName qualifiedName) { Optional prefix = namespaceRegistry.getPrefix(qualifiedName.getNamespace()); return prefixedNames.computeIfAbsent(qualifiedName, __ -> prefix.map(it -> it + ":" + qualifiedName.getSimpleName()).orElse(qualifiedName.getSimpleName())); } } DefaultDocumentWriter.java000066400000000000000000000227041421732762500360700ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/api/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.api; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; import javax.xml.namespace.NamespaceContext; import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stax.StAXResult; import java.io.BufferedWriter; import java.io.IOException; import java.io.Writer; import java.util.Optional; import java.util.function.Consumer; import static java.util.stream.Collectors.joining; import static javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING; import static javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI; import static org.opentest4j.reporting.events.api.NamespaceRegistry.XSI_PREFIX; class DefaultDocumentWriter> implements DocumentWriter { private final BufferedWriter bufferedWriter; private final XMLStreamWriter xmlWriter; private final Context context; private final Transformer transformer; private final SingleElementStreamWriter elementXmlWriter; DefaultDocumentWriter(QualifiedName rootElementName, NamespaceRegistry namespaceRegistry, Writer writer) throws Exception { XMLOutputFactory factory = XMLOutputFactory.newInstance(); bufferedWriter = buffered(writer); xmlWriter = factory.createXMLStreamWriter(writer); xmlWriter.writeStartDocument(); bufferedWriter.newLine(); writeStartElement(rootElementName, namespaceRegistry); writeNamespaces(namespaceRegistry); writeSchemaLocations(namespaceRegistry); xmlWriter.writeCharacters(""); elementXmlWriter = new SingleElementStreamWriter(xmlWriter, namespaceRegistry); context = Context.create(rootElementName, namespaceRegistry); TransformerFactory transformerFactory = TransformerFactory.newInstance(); transformerFactory.setFeature(FEATURE_SECURE_PROCESSING, true); transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); } private void writeStartElement(QualifiedName rootElement, NamespaceRegistry namespaceRegistry) throws XMLStreamException { Optional prefix = namespaceRegistry.getPrefix(rootElement.getNamespace()); if (prefix.isPresent()) { xmlWriter.writeStartElement(prefix.get(), rootElement.getSimpleName(), rootElement.getNamespace().getUri()); } else { xmlWriter.writeStartElement(rootElement.getSimpleName()); } } private void writeNamespaces(NamespaceRegistry namespaceRegistry) throws XMLStreamException { xmlWriter.writeDefaultNamespace(namespaceRegistry.getDefaultNamespace().getUri()); for (Namespace namespace : namespaceRegistry.getAdditionalNamespaces()) { Optional prefix = namespaceRegistry.getPrefix(namespace); if (prefix.isPresent()) { xmlWriter.writeNamespace(prefix.get(), namespace.getUri()); } } } private void writeSchemaLocations(NamespaceRegistry namespaceRegistry) throws XMLStreamException { if (!namespaceRegistry.getSchemaLocations().isEmpty()) { String value = namespaceRegistry.getSchemaLocations().entrySet().stream() // .map(e -> e.getKey().getUri() + " " + e.getValue()) // .collect(joining(" ")); xmlWriter.writeAttribute(XSI_PREFIX, W3C_XML_SCHEMA_INSTANCE_NS_URI, "schemaLocation", value); } } private static BufferedWriter buffered(Writer writer) { return writer instanceof BufferedWriter // ? (BufferedWriter) writer // : new BufferedWriter(writer); } @Override public synchronized > DocumentWriter append(Factory creator, Consumer configurer) { C event = creator.createAndConfigure(context, configurer); try { bufferedWriter.newLine(); org.w3c.dom.Element domElement = event.getDomElement(); domElement.normalize(); transformer.transform(new DOMSource(domElement), new StAXResult(elementXmlWriter)); } catch (Exception e) { throw new RuntimeException("Failed to write event: " + event, e); } return this; } @Override public void close() throws IOException { try { bufferedWriter.newLine(); xmlWriter.writeEndDocument(); xmlWriter.close(); } catch (XMLStreamException e) { throw new IOException("Failed to write XML", e); } finally { bufferedWriter.close(); } } private static class SingleElementStreamWriter implements XMLStreamWriter { private final XMLStreamWriter delegate; private final NamespaceRegistry namespaceRegistry; public SingleElementStreamWriter(XMLStreamWriter delegate, NamespaceRegistry namespaceRegistry) { this.delegate = delegate; this.namespaceRegistry = namespaceRegistry; } @Override public void writeStartElement(String localName) throws XMLStreamException { delegate.writeStartElement(localName); } @Override public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException { delegate.writeStartElement(namespaceURI, localName); } @Override public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException { delegate.writeStartElement(prefix, localName, namespaceURI); } @Override public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException { delegate.writeEmptyElement(namespaceURI, localName); } @Override public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException { delegate.writeEmptyElement(prefix, localName, namespaceURI); } @Override public void writeEmptyElement(String localName) throws XMLStreamException { delegate.writeEmptyElement(localName); } @Override public void writeEndElement() throws XMLStreamException { delegate.writeEndElement(); } @Override public void writeEndDocument() { } @Override public void close() throws XMLStreamException { delegate.close(); } @Override public void flush() throws XMLStreamException { delegate.flush(); } @Override public void writeAttribute(String localName, String value) throws XMLStreamException { delegate.writeAttribute(localName, value); } @Override public void writeAttribute(String prefix, String namespaceURI, String localName, String value) throws XMLStreamException { delegate.writeAttribute(prefix, namespaceURI, localName, value); } @Override public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException { delegate.writeAttribute(namespaceURI, localName, value); } @Override public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException { if (!namespaceRegistry.containsUri(namespaceURI)) { delegate.writeNamespace(prefix, namespaceURI); } } @Override public void writeDefaultNamespace(String namespaceURI) { } @Override public void writeComment(String data) throws XMLStreamException { delegate.writeComment(data); } @Override public void writeProcessingInstruction(String target) throws XMLStreamException { delegate.writeProcessingInstruction(target); } @Override public void writeProcessingInstruction(String target, String data) throws XMLStreamException { delegate.writeProcessingInstruction(target, data); } @Override public void writeCData(String data) throws XMLStreamException { delegate.writeCData(data); } @Override public void writeDTD(String dtd) throws XMLStreamException { delegate.writeDTD(dtd); } @Override public void writeEntityRef(String name) throws XMLStreamException { delegate.writeEntityRef(name); } @Override public void writeStartDocument() { } @Override public void writeStartDocument(String version) { } @Override public void writeStartDocument(String encoding, String version) { } @Override public void writeCharacters(String text) throws XMLStreamException { delegate.writeCharacters(text); } @Override public void writeCharacters(char[] text, int start, int len) throws XMLStreamException { delegate.writeCharacters(text, start, len); } @Override public String getPrefix(String uri) throws XMLStreamException { return delegate.getPrefix(uri); } @Override public void setPrefix(String prefix, String uri) throws XMLStreamException { delegate.setPrefix(prefix, uri); } @Override public void setDefaultNamespace(String uri) throws XMLStreamException { delegate.setDefaultNamespace(uri); } @Override public void setNamespaceContext(NamespaceContext context) throws XMLStreamException { delegate.setNamespaceContext(context); } @Override public NamespaceContext getNamespaceContext() { return delegate.getNamespaceContext(); } @Override public Object getProperty(String name) throws IllegalArgumentException { return delegate.getProperty(name); } } } DocumentWriter.java000066400000000000000000000044161421732762500345630ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/api/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.api; import org.opentest4j.reporting.schema.QualifiedName; import java.io.Closeable; import java.nio.file.Files; import java.nio.file.Path; import java.util.function.Consumer; /** * Writer for documents with a certain root element type. * * @param root element type */ public interface DocumentWriter> extends Closeable, Appendable { /** * Create a no-op implementation of {@code DocumentWriter}. * * @param root element type * @return no-op DocumentWriter */ static > DocumentWriter noop() { return new DocumentWriter() { @Override public > Appendable append(Factory creator, Consumer configurer) { return this; } @Override public void close() { } }; } /** * Create a new document writer with the supplied root {@linkplain QualifiedName element name} and * {@linkplain NamespaceRegistry namespace registry} that will write to the supplied {@linkplain Path XML file}. * * @param rootElementName root element name * @param namespaceRegistry namespace registry * @param xmlFile target XML file * @param root element type * @return new document writer * @throws Exception in case there's an error opening the XML file or preparing the XML writing infrastructure */ static > DocumentWriter create(QualifiedName rootElementName, NamespaceRegistry namespaceRegistry, Path xmlFile) throws Exception { return new DefaultDocumentWriter<>(rootElementName, namespaceRegistry, Files.newBufferedWriter(xmlFile)); } } open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/api/Element.java000066400000000000000000000062461421732762500332630ustar00rootroot00000000000000/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.api; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; import org.w3c.dom.Attr; import org.w3c.dom.Document; import java.util.function.Consumer; /** * Base class for elements. * * @param element type */ public class Element> implements Appendable { private final Context context; private final Namespace namespace; final org.w3c.dom.Element domElement; /** * Create an instance with the supplied {@linkplain Context context} and {@linkplain QualifiedName qualified name}. * * @param context the context of this instance * @param qualifiedName the qualified name of this instance */ public Element(Context context, QualifiedName qualifiedName) { this.context = context; this.namespace = qualifiedName.getNamespace(); this.domElement = context.createElement(qualifiedName); } org.w3c.dom.Element getDomElement() { return domElement; } /** * Add text content to this element. * * @param value the text content * @return this element */ public Element withContent(String value) { domElement.setTextContent(value); return this; } /** * Add a CDATA section to this element. * * @param value the content of the CDATA section * @return this element */ @SuppressWarnings("UnusedReturnValue") public Element withCDataSection(String value) { domElement.appendChild(document().createCDATASection(value)); return this; } /** * Add an attribute to this element. * * @param qualifiedName the qualified name of the attribute * @param value the attribute value * @return this element */ public Element withAttribute(QualifiedName qualifiedName, String value) { Attr attr = createAttr(qualifiedName); attr.setValue(value); domElement.setAttributeNode(attr); return this; } private Attr createAttr(QualifiedName qualifiedName) { return namespace.equals(qualifiedName.getNamespace()) // ? document().createAttribute(qualifiedName.getSimpleName()) // : document().createAttributeNS(qualifiedName.getNamespace().getUri(), context.prefixed(qualifiedName)); } private Document document() { return context.getDocument(); } @Override public > Appendable append(Factory creator, Consumer configurer) { C child = creator.createAndConfigure(context, configurer); domElement.appendChild(child.domElement); return this; } @Override public String toString() { return "Element{domElement=" + domElement + '}'; } } open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/api/Factory.java000066400000000000000000000027341421732762500332770ustar00rootroot00000000000000/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.api; import java.util.function.Consumer; /** * Factory for creating elements of a certain type for a given {@linkplain Context context}. * * @param the type of element to create */ @FunctionalInterface public interface Factory { /** * Create an element using the supplied {@linkplain Context context}. * * @param context the context to use * @return the created element */ T create(Context context); /** * Create and configure an element using the supplied {@linkplain Context context} and {@link Consumer configurer}. * * @param context the context to use * @param configurer the configurer to use * @return the created element */ default T createAndConfigure(Context context, Consumer configurer) { T result = create(context); configurer.accept(result); return result; } } NamespaceRegistry.java000066400000000000000000000123211421732762500352270ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/api/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.api; import org.opentest4j.reporting.schema.Namespace; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; import java.util.Optional; import java.util.Set; /** * Registry of namespaces for writing a document. * * @see Namespace * @see DocumentWriter */ public class NamespaceRegistry { static final String XSI_PREFIX = "xsi"; /** * Create a new builder with the supplied default namespace. * * @param defaultNamespace the default namespace * @return a new builder */ public static Builder builder(Namespace defaultNamespace) { return new Builder(defaultNamespace, null); } /** * Create a new builder with the supplied default namespace and schema location. * * @param defaultNamespace the default namespace * @param schemaLocation the schema location of the default namespace * @return a new builder */ public static Builder builder(Namespace defaultNamespace, String schemaLocation) { return new Builder(defaultNamespace, schemaLocation); } private final Namespace defaultNamespace; private final Map schemaLocations; private final Map additionalNamespaces; private NamespaceRegistry(Namespace defaultNamespace, Map schemaLocations, Map additionalNamespaces) { this.defaultNamespace = defaultNamespace; this.schemaLocations = Collections.unmodifiableMap(new LinkedHashMap<>(schemaLocations)); this.additionalNamespaces = Collections.unmodifiableMap(new LinkedHashMap<>(additionalNamespaces)); } /** * Get the default namespace of this registry. * * @return the default namespace */ public Namespace getDefaultNamespace() { return defaultNamespace; } /** * Get additional namespaces registered with this registry. * * @return additional namespaces */ public Set getAdditionalNamespaces() { return additionalNamespaces.keySet(); } /** * Get the prefix for the supplied namespace registered with this registry. * * @param namespace the namespace to look up the prefix for * @return the prefix for the namespace or empty if the namespace is not as an additional namespace */ public Optional getPrefix(Namespace namespace) { return Optional.ofNullable(additionalNamespaces.get(namespace)); } /** * Get all schema locations registered with this registry. * * @return schema locations */ public Map getSchemaLocations() { return schemaLocations; } /** * Check whether a namespace with the supplied URI is registered with this registry. * * @param uri the namespace URI to look up * @return whether the namespace is registered */ public boolean containsUri(String uri) { return defaultNamespace.getUri().equals(uri) || additionalNamespaces.containsKey(Namespace.of(uri)); } /** * Builder for {@link NamespaceRegistry}. */ public static class Builder { private final Namespace defaultNamespace; private final Map schemaLocations = new LinkedHashMap<>(); private final Map additionalNamespaces = new LinkedHashMap<>(); private Builder(Namespace defaultNamespace, String schemaLocation) { this.defaultNamespace = defaultNamespace; if (schemaLocation != null) { schemaLocations.put(defaultNamespace, schemaLocation); } } /** * Add an additional namespace to this registry. * * @param prefix the prefix for the namespace * @param namespace the namespace * @return this builder */ public Builder add(String prefix, Namespace namespace) { return add(prefix, namespace, null); } /** * Add an additional namespace to this registry. * * @param prefix the prefix for the namespace * @param namespace the namespace * @param schemaLocation the schema location of the namespace * @return this builder */ public Builder add(String prefix, Namespace namespace, String schemaLocation) { if (additionalNamespaces.containsKey(namespace) || defaultNamespace.equals(namespace)) { throw new IllegalStateException("Namespace has already been added previously: " + namespace); } additionalNamespaces.put(namespace, prefix); if (schemaLocation != null) { schemaLocations.put(namespace, schemaLocation); } return this; } /** * Build the {@link NamespaceRegistry}. * * @return the namespace registry */ public NamespaceRegistry build() { if (!schemaLocations.isEmpty()) { add(XSI_PREFIX, Namespace.XML_SCHEMA_INSTANCE); } return new NamespaceRegistry(defaultNamespace, schemaLocations, additionalNamespaces); } } } open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/core/000077500000000000000000000000001421732762500311765ustar00rootroot00000000000000Attachments.java000066400000000000000000000023301421732762500342330ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/core/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.core; import org.opentest4j.reporting.events.api.ChildElement; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.events.root.Event; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; /** * The {@code attachments} element of the core namespace. */ public class Attachments extends ChildElement { private static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_CORE, "attachments"); Attachments(Context context) { super(context, ELEMENT); } } CoreFactory.java000066400000000000000000000120621421732762500342030ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/core/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.core; import org.opentest4j.reporting.events.api.Element; import org.opentest4j.reporting.events.api.Factory; import java.io.File; import java.net.URI; import java.util.Optional; /** * Factory for elements of the core namespace. */ public class CoreFactory { private CoreFactory() { } /** * Create a factory for {@link Infrastructure} elements. * * @return Infrastructure factory */ public static Factory infrastructure() { return Infrastructure::new; } /** * Create a factory for {@link HostName} elements. * * @param hostName the host name * @return HostName factory */ public static Factory hostName(String hostName) { return context -> new HostName(context, hostName); } /** * Create a factory for {@link UserName} elements. * * @param userName the user name * @return UserName factory */ public static Factory userName(String userName) { return context -> new UserName(context, userName); } /** * Create a factory for {@link OperatingSystem} elements. * * @param osName the name of the operating system * @return OperatingSystem factory */ public static Factory operatingSystem(String osName) { return context -> new OperatingSystem(context, osName); } /** * Create a factory for {@link CpuCores} elements. * * @param cpuCores the number of CPU cores * @return CpuCores factory */ public static Factory cpuCores(int cpuCores) { return context -> new CpuCores(context, cpuCores); } /** * Create a factory for {@link Sources} elements. * * @return Sources factory */ public static Factory sources() { return Sources::new; } /** * Create a factory for {@link Metadata} elements. * * @return Metadata factory */ public static Factory metadata() { return Metadata::new; } /** * Create a factory for {@link Tags} elements. * * @return Tags factory */ public static Factory tags() { return Tags::new; } /** * Create a factory for {@link Tag} elements. * * @param value the value of the tag * @return Tag factory */ public static Factory tag(String value) { return context -> new Tag(context, value); } /** * Create a factory for {@link Attachments} elements. * * @return Attachments factory */ public static Factory attachments() { return Attachments::new; } /** * Create a factory for {@link Data} elements. * * @return Data factory */ public static Factory data() { return Data::new; } /** * Create a factory for {@link Result} elements. * * @param status the status of the result * @return Result factory */ public static Factory result(Result.Status status) { return context -> new Result(context).withStatus(status); } /** * Create a factory for {@link Reason} elements. * * @param reason the reason * @return Reason factory */ public static Factory reason(String reason) { return context -> new Reason(context, reason); } /** * Create a factory for {@link FileSource} elements. * * @param file the source file * @return FileSource factory */ public static Factory fileSource(File file) { return context -> new FileSource(context).withPath(file); } /** * Create a factory for {@link DirectorySource} elements. * * @param dir the source directory * @return DirectorySource factory */ public static Factory directorySource(File dir) { return context -> new DirectorySource(context).withPath(dir); } /** * Create a factory for {@link UriSource} elements. * * @param uri the source URI * @return UriSource factory */ public static Factory uriSource(URI uri) { return context -> new UriSource(context).withUri(uri); } /** * Create a factory for {@link FilePosition} elements. * * @param line the line number * @param column the column number * @param

parent element type * @return FilePosition factory */ @SuppressWarnings("OptionalUsedAsFieldOrParameterType") public static

> Factory> filePosition(int line, Optional column) { return context -> { FilePosition

filePosition = new FilePosition<>(context); filePosition.withAttribute(FilePosition.LINE, String.valueOf(line)); column.ifPresent(value -> filePosition.withAttribute(FilePosition.COLUMN, value.toString())); return filePosition; }; } } CpuCores.java000066400000000000000000000023201421732762500335020ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/core/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.core; import org.opentest4j.reporting.events.api.ChildElement; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; /** * The {@code cpuCores} element of the core namespace. */ public class CpuCores extends ChildElement { private static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_CORE, "cpuCores"); CpuCores(Context context, int value) { super(context, ELEMENT); withContent(String.valueOf(value)); } } open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/core/Data.java000066400000000000000000000041651421732762500327200ustar00rootroot00000000000000/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.core; import org.opentest4j.reporting.events.api.ChildElement; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; import java.time.LocalDateTime; /** * The {@code data} element of the core namespace. */ public class Data extends ChildElement { private static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_CORE, "data"); private static final QualifiedName TIME = QualifiedName.of(Namespace.REPORTING_CORE, "time"); Data(Context context) { super(context, ELEMENT); } /** * Set the {@code time} attribute of this element. * * @param timestamp the timestamp to set * @return this element */ public Data withTime(LocalDateTime timestamp) { withAttribute(TIME, timestamp.toString()); return this; } /** * Add an {@code entry} child element to this element. * * @param key entry key * @param value entry value */ public void addEntry(String key, String value) { append(context -> new Entry(context, key, value)); } private static class Entry extends ChildElement { public static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_CORE, "entry"); public static final QualifiedName KEY = QualifiedName.of(Namespace.REPORTING_CORE, "key"); Entry(Context context, String key, String value) { super(context, ELEMENT); withAttribute(KEY, key); withContent(value); } } } DirectorySource.java000066400000000000000000000026411421732762500351120ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/core/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.core; import org.opentest4j.reporting.events.api.ChildElement; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; import java.io.File; /** * The {@code directorySource} element of the core namespace. */ public class DirectorySource extends ChildElement { private static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_CORE, "directorySource"); private static final QualifiedName PATH = QualifiedName.of(Namespace.REPORTING_CORE, "path"); DirectorySource(Context context) { super(context, DirectorySource.ELEMENT); } DirectorySource withPath(File file) { withAttribute(PATH, file.getPath()); return this; } } FilePosition.java000066400000000000000000000026451421732762500343750ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/core/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.core; import org.opentest4j.reporting.events.api.ChildElement; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.events.api.Element; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; /** * The {@code filePosition} element of the core namespace. */ public class FilePosition

> extends ChildElement> { private static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_CORE, "filePosition"); static final QualifiedName LINE = QualifiedName.of(Namespace.REPORTING_CORE, "line"); static final QualifiedName COLUMN = QualifiedName.of(Namespace.REPORTING_CORE, "column"); FilePosition(Context context) { super(context, ELEMENT); } } FileSource.java000066400000000000000000000034151421732762500340250ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/core/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.core; import org.opentest4j.reporting.events.api.Appendable; import org.opentest4j.reporting.events.api.ChildElement; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; import java.io.File; import java.util.Optional; /** * The {@code fileSource} element of the core namespace. */ public class FileSource extends ChildElement { private static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_CORE, "fileSource"); private static final QualifiedName PATH = QualifiedName.of(Namespace.REPORTING_CORE, "path"); FileSource(Context context) { super(context, FileSource.ELEMENT); } FileSource withPath(File file) { withAttribute(PATH, file.getPath()); return this; } /** * Add a {@code filePosition} child element to this element. * * @param line the line number * @param column the column number * @return this element */ public Appendable addFilePosition(int line, Optional column) { return append(CoreFactory.filePosition(line, column)); } } HostName.java000066400000000000000000000023031421732762500334760ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/core/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.core; import org.opentest4j.reporting.events.api.ChildElement; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; /** * The {@code hostName} element of the core namespace. */ public class HostName extends ChildElement { private static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_CORE, "hostName"); HostName(Context context, String value) { super(context, ELEMENT); withContent(value); } } Infrastructure.java000066400000000000000000000024631421732762500350070ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/core/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.core; import org.opentest4j.reporting.events.api.ChildElement; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.events.root.Events; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; /** * The {@code infrastructure} element of the core namespace. */ public final class Infrastructure extends ChildElement { /** * Qualified name of the {@code infrastructure} element. */ public static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_CORE, "infrastructure"); Infrastructure(Context context) { super(context, ELEMENT); } } Metadata.java000066400000000000000000000023111421732762500334770ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/core/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.core; import org.opentest4j.reporting.events.api.ChildElement; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.events.root.Event; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; /** * The {@code metadata} element of the core namespace. */ public class Metadata extends ChildElement { private static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_CORE, "metadata"); Metadata(Context context) { super(context, ELEMENT); } } OperatingSystem.java000066400000000000000000000023461421732762500351240ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/core/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.core; import org.opentest4j.reporting.events.api.ChildElement; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; /** * The {@code operatingSystem} element of the core namespace. */ public class OperatingSystem extends ChildElement { private static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_CORE, "operatingSystem"); OperatingSystem(Context context, String value) { super(context, ELEMENT); withContent(value); } } open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/core/Reason.java000066400000000000000000000022651421732762500332750ustar00rootroot00000000000000/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.core; import org.opentest4j.reporting.events.api.ChildElement; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; /** * The {@code reason} element of the core namespace. */ public class Reason extends ChildElement { private static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_CORE, "reason"); Reason(Context context, String content) { super(context, ELEMENT); withContent(content); } } open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/core/Result.java000066400000000000000000000033031421732762500333160ustar00rootroot00000000000000/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.core; import org.opentest4j.reporting.events.api.ChildElement; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.events.root.Event; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; /** * The {@code result} element of the core namespace. */ public class Result extends ChildElement { private static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_CORE, "result"); private static final QualifiedName STATUS = QualifiedName.of(Namespace.REPORTING_CORE, "status"); Result(Context context) { super(context, ELEMENT); } Result withStatus(Status status) { withAttribute(STATUS, status.name()); return this; } /** * Enum of values for the {@code status} attribute of the {@code result} element. */ public enum Status { /** * The test was skipped. */ SKIPPED, /** * The test was aborted. */ ABORTED, /** * The test was successful. */ SUCCESSFUL, /** * The test failed. */ FAILED } } open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/core/Sources.java000066400000000000000000000023041421732762500334630ustar00rootroot00000000000000/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.core; import org.opentest4j.reporting.events.api.ChildElement; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.events.root.Event; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; /** * The {@code sources} element of the core namespace. */ public class Sources extends ChildElement { private static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_CORE, "sources"); Sources(Context context) { super(context, ELEMENT); } } open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/core/Tag.java000066400000000000000000000022401421732762500325520ustar00rootroot00000000000000/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.core; import org.opentest4j.reporting.events.api.ChildElement; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; /** * The {@code tag} element of the core namespace. */ public class Tag extends ChildElement { private static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_CORE, "tag"); Tag(Context context, String value) { super(context, ELEMENT); withContent(value); } } open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/core/Tags.java000066400000000000000000000022051421732762500327360ustar00rootroot00000000000000/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.core; import org.opentest4j.reporting.events.api.ChildElement; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; /** * The {@code tags} element of the core namespace. */ public class Tags extends ChildElement { private static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_CORE, "tags"); Tags(Context context) { super(context, ELEMENT); } } UriSource.java000066400000000000000000000025611421732762500337060ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/core/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.core; import org.opentest4j.reporting.events.api.ChildElement; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; import java.net.URI; /** * The {@code uriSource} element of the core namespace. */ public class UriSource extends ChildElement { private static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_CORE, "uriSource"); private static final QualifiedName URI = QualifiedName.of(Namespace.REPORTING_CORE, "uri"); UriSource(Context context) { super(context, UriSource.ELEMENT); } UriSource withUri(URI uri) { withAttribute(URI, uri.toString()); return this; } } UserName.java000066400000000000000000000023031421732762500334770ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/core/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.core; import org.opentest4j.reporting.events.api.ChildElement; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; /** * The {@code userName} element of the core namespace. */ public class UserName extends ChildElement { private static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_CORE, "userName"); UserName(Context context, String value) { super(context, ELEMENT); withContent(value); } } open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/java/000077500000000000000000000000001421732762500311675ustar00rootroot00000000000000ClassSource.java000066400000000000000000000036061421732762500342060ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/java/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.java; import org.opentest4j.reporting.events.api.Appendable; import org.opentest4j.reporting.events.api.ChildElement; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.events.core.CoreFactory; import org.opentest4j.reporting.events.core.Sources; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; import java.util.Optional; /** * The {@code classSource} element of the Java namespace. */ public class ClassSource extends ChildElement { private static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_JAVA, "classSource"); private static final QualifiedName CLASS_NAME = QualifiedName.of(Namespace.REPORTING_JAVA, "className"); ClassSource(Context context) { super(context, ClassSource.ELEMENT); } ClassSource withClassName(String className) { withAttribute(CLASS_NAME, className); return this; } /** * Add a {@code filePosition} child element to this element. * * @param line the line number * @param column the column number * @return this element */ public Appendable addFilePosition(int line, Optional column) { return append(CoreFactory.filePosition(line, column)); } } ClasspathResourceSource.java000066400000000000000000000037701421732762500365750ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/java/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.java; import org.opentest4j.reporting.events.api.Appendable; import org.opentest4j.reporting.events.api.ChildElement; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.events.core.CoreFactory; import org.opentest4j.reporting.events.core.Sources; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; import java.util.Optional; /** * The {@code classpathResourceSource} element of the Java namespace. */ public class ClasspathResourceSource extends ChildElement { private static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_JAVA, "classpathResourceSource"); private static final QualifiedName RESOURCE_NAME = QualifiedName.of(Namespace.REPORTING_JAVA, "resourceName"); ClasspathResourceSource(Context context) { super(context, ClasspathResourceSource.ELEMENT); } ClasspathResourceSource withResourceName(String resourceName) { withAttribute(RESOURCE_NAME, resourceName); return this; } /** * Add a {@code filePosition} child element to this element. * * @param line the line number * @param column the column number * @return this element */ public Appendable addFilePosition(int line, Optional column) { return append(CoreFactory.filePosition(line, column)); } } FileEncoding.java000066400000000000000000000024231421732762500343020ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/java/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.java; import org.opentest4j.reporting.events.api.ChildElement; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.events.core.Infrastructure; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; /** * The {@code fileEncoding} element of the Java namespace. */ public class FileEncoding extends ChildElement { private static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_JAVA, "fileEncoding"); FileEncoding(Context context, String value) { super(context, ELEMENT); withContent(value); } } HeapSize.java000066400000000000000000000030361421732762500334650ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/java/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.java; import org.opentest4j.reporting.events.api.ChildElement; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.events.core.Infrastructure; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; /** * The {@code heapSize} element of the Java namespace. */ public class HeapSize extends ChildElement { private static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_JAVA, "heapSize"); private static final QualifiedName MAX = QualifiedName.of(Namespace.REPORTING_JAVA, "max"); HeapSize(Context context) { super(context, ELEMENT); } /** * Set the {@code max} attribute of this element. * * @param bytes the number of bytes * @return this element */ public HeapSize withMax(long bytes) { withAttribute(MAX, String.valueOf(bytes)); return this; } } JavaFactory.java000066400000000000000000000062301421732762500341650ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/java/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.java; import org.opentest4j.reporting.events.api.Factory; import org.opentest4j.reporting.events.core.Infrastructure; /** * Factory for elements of the Java namespace. */ public class JavaFactory { private JavaFactory() { } /** * Create a factory for {@link JavaVersion} elements. * * @param version the Java version * @return JavaVersion factory */ public static Factory javaVersion(String version) { return context -> new JavaVersion(context, version); } /** * Create a factory for {@link FileEncoding} elements. * * @param fileEncoding the file encoding * @return FileEncoding factory */ public static Factory fileEncoding(String fileEncoding) { return context -> new FileEncoding(context, fileEncoding); } /** * Create a factory for {@link HeapSize} elements. * * @return HeapSize factory */ public static Factory heapSize() { return HeapSize::new; } /** * Create a factory for {@link ClassSource} elements. * * @param className the source class name * @return ClassSource factory */ public static Factory classSource(String className) { return context -> new ClassSource(context).withClassName(className); } /** * Create a factory for {@link MethodSource} elements. * * @param className the source class name * @param methodName the source method name * @return MethodSource factory */ public static Factory methodSource(String className, String methodName) { return context -> new MethodSource(context).withClassName(className).withMethodName(methodName); } /** * Create a factory for {@link ClasspathResourceSource} elements. * * @param resourceName the source resource name * @return ClasspathResourceSource factory */ public static Factory classpathResourceSource(String resourceName) { return context -> new ClasspathResourceSource(context).withResourceName(resourceName); } /** * Create a factory for {@link PackageSource} elements. * * @param packageName the source package name * @return PackageSource factory */ public static Factory packageSource(String packageName) { return context -> new PackageSource(context).withName(packageName); } /** * Create a factory for {@link Throwable} elements. * * @param throwable the throwable * @return Throwable factory */ public static Factory throwable(java.lang.Throwable throwable) { return context -> new Throwable(context).withThrowable(throwable); } } JavaVersion.java000066400000000000000000000024161421732762500342050ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/java/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.java; import org.opentest4j.reporting.events.api.ChildElement; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.events.core.Infrastructure; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; /** * The {@code javaVersion} element of the Java namespace. */ public class JavaVersion extends ChildElement { private static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_JAVA, "javaVersion"); JavaVersion(Context context, String value) { super(context, ELEMENT); withContent(value); } } MethodSource.java000066400000000000000000000041461421732762500343610ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/java/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.java; import org.opentest4j.reporting.events.api.ChildElement; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.events.core.Sources; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; /** * The {@code methodSource} element of the Java namespace. */ public class MethodSource extends ChildElement { private static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_JAVA, "methodSource"); private static final QualifiedName CLASS_NAME = QualifiedName.of(Namespace.REPORTING_JAVA, "className"); private static final QualifiedName METHOD_NAME = QualifiedName.of(Namespace.REPORTING_JAVA, "methodName"); private static final QualifiedName METHOD_PARAMETER_TYPES = QualifiedName.of(Namespace.REPORTING_JAVA, "methodParameterTypes"); MethodSource(Context context) { super(context, MethodSource.ELEMENT); } MethodSource withClassName(String className) { withAttribute(CLASS_NAME, className); return this; } MethodSource withMethodName(String methodName) { withAttribute(METHOD_NAME, methodName); return this; } /** * Set the {@code methodParameterTypes} attribute of this element. * * @param methodParameterTypes the method parameter types * @return this element */ public MethodSource withMethodParameterTypes(String methodParameterTypes) { withAttribute(METHOD_PARAMETER_TYPES, methodParameterTypes); return this; } } PackageSource.java000066400000000000000000000026641421732762500344770ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/java/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.java; import org.opentest4j.reporting.events.api.ChildElement; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.events.core.Sources; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; /** * The {@code packageSource} element of the Java namespace. */ public class PackageSource extends ChildElement { private static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_JAVA, "packageSource"); private static final QualifiedName NAME = QualifiedName.of(Namespace.REPORTING_JAVA, "name"); PackageSource(Context context) { super(context, PackageSource.ELEMENT); } PackageSource withName(String className) { withAttribute(NAME, className); return this; } } Throwable.java000066400000000000000000000036101421732762500337020ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/java/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.java; import org.opentest4j.reporting.events.api.ChildElement; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.events.core.Result; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; import java.io.PrintWriter; import java.io.StringWriter; /** * The {@code throwable} element of the Java namespace. */ public class Throwable extends ChildElement { private static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_JAVA, "throwable"); private static final QualifiedName TYPE = QualifiedName.of(Namespace.REPORTING_JAVA, "type"); private static final QualifiedName ASSERTION_ERROR = QualifiedName.of(Namespace.REPORTING_JAVA, "assertionError"); Throwable(Context context) { super(context, Throwable.ELEMENT); } Throwable withThrowable(java.lang.Throwable throwable) { withAttribute(TYPE, throwable.getClass().getName()); withAttribute(ASSERTION_ERROR, String.valueOf(throwable instanceof AssertionError)); StringWriter stringWriter = new StringWriter(); try (PrintWriter writer = new PrintWriter(stringWriter)) { throwable.printStackTrace(writer); } withCDataSection(stringWriter.toString()); return this; } } open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/root/000077500000000000000000000000001421732762500312315ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/root/Event.java000066400000000000000000000031451421732762500331600ustar00rootroot00000000000000/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.root; import org.opentest4j.reporting.events.api.ChildElement; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; import java.time.Instant; /** * Abstract base class for all events in the events namespace. */ public abstract class Event extends ChildElement { /** * Qualified name of the {@code id} attribute of an event. */ public static final QualifiedName ID = QualifiedName.of(Namespace.REPORTING_EVENTS, "id"); /** * Qualified name of the {@code time} attribute of an event. */ public static final QualifiedName TIME = QualifiedName.of(Namespace.REPORTING_EVENTS, "time"); Event(Context context, QualifiedName qualifiedName) { super(context, qualifiedName); } Event withId(String id) { withAttribute(ID, id); return this; } Event withTime(Instant time) { withAttribute(TIME, time.toString()); return this; } } open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/root/Events.java000066400000000000000000000035161421732762500333450ustar00rootroot00000000000000/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.root; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.events.api.DocumentWriter; import org.opentest4j.reporting.events.api.Element; import org.opentest4j.reporting.events.api.NamespaceRegistry; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; import java.nio.file.Path; /** * The {@code events} element of the events namespace. */ public class Events extends Element { private static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_EVENTS, "events"); private Events(Context context) { super(context, ELEMENT); } /** * Create a new {@link DocumentWriter} for the event-based reporting format. * * @param namespaceRegistry the namespace registry to use * @param xmlFile the file to write to * @return the new {@link DocumentWriter} * @throws Exception if an error initializing the XML writing infrastructure or writing to the XML file occurs */ public static DocumentWriter createDocumentWriter(NamespaceRegistry namespaceRegistry, Path xmlFile) throws Exception { return DocumentWriter.create(ELEMENT, namespaceRegistry, xmlFile); } } Finished.java000066400000000000000000000025201421732762500335450ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/root/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.root; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; import java.time.Instant; /** * The {@code finished} element of the events namespace. */ public final class Finished extends Event { /** * Qualified name of the {@code finished} element. */ public static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_EVENTS, "finished"); Finished(Context context) { super(context, ELEMENT); } @Override Finished withId(String id) { super.withId(id); return this; } @Override Finished withTime(Instant time) { super.withTime(time); return this; } } Reported.java000066400000000000000000000025201421732762500336000ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/root/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.root; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; import java.time.Instant; /** * The {@code reported} element of the events namespace. */ public final class Reported extends Event { /** * Qualified name of the {@code reported} element. */ public static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_EVENTS, "reported"); Reported(Context context) { super(context, ELEMENT); } @Override Reported withId(String id) { super.withId(id); return this; } @Override Reported withTime(Instant time) { super.withTime(time); return this; } } RootFactory.java000066400000000000000000000037021421732762500342720ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/root/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.root; import org.opentest4j.reporting.events.api.Factory; import org.opentest4j.reporting.events.java.HeapSize; import java.time.Instant; /** * Factory for elements of the events namespace. */ public class RootFactory { private RootFactory() { } /** * Create a factory for {@link Started} elements. * * @param id test id (unique within the test run) * @param time time of the event * @param name test name * @return Started factory */ public static Factory started(String id, Instant time, String name) { return context -> new Started(context).withId(id).withTime(time).withName(name); } /** * Create a factory for {@link Reported} elements. * * @param id test id (must match id of previous {@link Started} element) * @param time time of the event * @return Reported factory */ public static Factory reported(String id, Instant time) { return context -> new Reported(context).withId(id).withTime(time); } /** * Create a factory for {@link Finished} elements. * * @param id test id (must match id of previous {@link Started} element) * @param time time of the event * @return Finished factory */ public static Factory finished(String id, Instant time) { return context -> new Finished(context).withId(id).withTime(time); } } open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/root/Started.java000066400000000000000000000040361421732762500335050ustar00rootroot00000000000000/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.root; import org.opentest4j.reporting.events.api.Context; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; import java.time.Instant; /** * The {@code started} element of the events namespace. */ public final class Started extends Event { /** * Qualified name of the {@code started} element. */ public static final QualifiedName ELEMENT = QualifiedName.of(Namespace.REPORTING_EVENTS, "started"); /** * Qualified name of the {@code name} attribute of a started event. */ private static final QualifiedName NAME = QualifiedName.of(Namespace.REPORTING_EVENTS, "name"); /** * Qualified name of the {@code parentId} attribute of a started event. */ public static final QualifiedName PARENT_ID = QualifiedName.of(Namespace.REPORTING_EVENTS, "parentId"); Started(Context context) { super(context, ELEMENT); } @Override Started withId(String id) { super.withId(id); return this; } @Override Started withTime(Instant time) { super.withTime(time); return this; } Started withName(String name) { withAttribute(NAME, name); return this; } /** * Set the {@code parentId} attribute of this started event. * * @param parentId the parent id * @return this event */ @SuppressWarnings("UnusedReturnValue") public Started withParentId(String parentId) { withAttribute(PARENT_ID, parentId); return this; } } open-test-reporting-r0.1.0-M1/events/src/test/000077500000000000000000000000001421732762500211555ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/test/java/000077500000000000000000000000001421732762500220765ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/test/java/DocumentWriterSample.java000066400000000000000000000042551421732762500270640ustar00rootroot00000000000000 /* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.opentest4j.reporting.events.api.DocumentWriter; import org.opentest4j.reporting.events.api.NamespaceRegistry; import org.opentest4j.reporting.events.core.CoreFactory; import org.opentest4j.reporting.events.root.Events; import org.opentest4j.reporting.schema.Namespace; import java.nio.file.Paths; import java.time.Instant; import static org.opentest4j.reporting.events.core.CoreFactory.*; import static org.opentest4j.reporting.events.core.Result.Status.SUCCESSFUL; import static org.opentest4j.reporting.events.root.RootFactory.finished; import static org.opentest4j.reporting.events.root.RootFactory.started; public class DocumentWriterSample { public static void main(String[] args) throws Exception { NamespaceRegistry namespaceRegistry = NamespaceRegistry.builder(Namespace.REPORTING_CORE) // <1> .add("e", Namespace.REPORTING_EVENTS) // .add("java", Namespace.REPORTING_JAVA) // .build(); try (DocumentWriter writer = Events.createDocumentWriter(namespaceRegistry, Paths.get("events.xml"))) { writer.append(infrastructure(), infrastructure -> infrastructure // <2> .append(userName("alice")) // .append(hostName("wonderland"))); writer.append(started("1", Instant.now(), "container")); // <3> writer.append(started("2", Instant.now(), "test"), started -> started.withParentId("1")); // <4> writer.append(finished("2", Instant.now()), finished -> finished.append(CoreFactory.result(SUCCESSFUL))); // <5> writer.append(finished("1", Instant.now()), finished -> finished.append(CoreFactory.result(SUCCESSFUL))); // <6> } } } open-test-reporting-r0.1.0-M1/events/src/test/java/org/000077500000000000000000000000001421732762500226655ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/test/java/org/opentest4j/000077500000000000000000000000001421732762500247645ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/test/java/org/opentest4j/reporting/000077500000000000000000000000001421732762500267755ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/test/java/org/opentest4j/reporting/ArchitectureTests.java000066400000000000000000000021231421732762500333030ustar00rootroot00000000000000/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting; import com.tngtech.archunit.junit.AnalyzeClasses; import com.tngtech.archunit.junit.ArchTest; import com.tngtech.archunit.lang.ArchRule; import static com.tngtech.archunit.library.dependencies.SlicesRuleDefinition.slices; @AnalyzeClasses(packages = "org.opentest4j.reporting.events") class ArchitectureTests { @ArchTest static final ArchRule noCycles = slices().matching( "org.opentest4j.reporting.events.(**)").should().beFreeOfCycles(); } open-test-reporting-r0.1.0-M1/events/src/test/java/org/opentest4j/reporting/events/000077500000000000000000000000001421732762500303015ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/test/java/org/opentest4j/reporting/events/api/000077500000000000000000000000001421732762500310525ustar00rootroot00000000000000DocumentWriterTest.java000066400000000000000000000051311421732762500354510ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/events/src/test/java/org/opentest4j/reporting/events/api/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.events.api; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; import java.nio.file.Path; import static org.xmlunit.assertj3.XmlAssert.assertThat; class DocumentWriterTest { static final Namespace NAMESPACE_A = Namespace.of("urn::a"); static final Namespace NAMESPACE_B = Namespace.of("urn::b"); static final NamespaceRegistry NAMESPACE_REGISTRY = NamespaceRegistry.builder(NAMESPACE_A) // .add("b", NAMESPACE_B, "https://example.org/b.xsd") // .build(); @TempDir Path tempDir; @Test void producesWellFormedNamespacedXml() throws Exception { var targetFile = tempDir.resolve("test.xml"); try (var writer = DocumentWriter. create(Root.ELEMENT, NAMESPACE_REGISTRY, targetFile)) { writer.append(Child::new, child -> child // .withAttribute(QualifiedName.of(NAMESPACE_A, "a"), "1") // .withAttribute(QualifiedName.of(NAMESPACE_B, "b"), "2") // .append(Extension::new, extension -> extension.withContent("conent"))); } var expected = """ con<t>ent """; assertThat(targetFile).and(expected).ignoreWhitespace().areIdentical(); } static class Root extends Element { static final QualifiedName ELEMENT = QualifiedName.of(NAMESPACE_A, "root"); Root(Context context) { super(context, ELEMENT); } } static class Child extends ChildElement { Child(Context context) { super(context, QualifiedName.of(NAMESPACE_A, "child")); } } static class Extension extends ChildElement { Extension(Context context) { super(context, QualifiedName.of(NAMESPACE_B, "extension")); } } } open-test-reporting-r0.1.0-M1/gradle.properties000066400000000000000000000000641421732762500214570ustar00rootroot00000000000000group = org.opentest4j.reporting version = 0.1.0-M1 open-test-reporting-r0.1.0-M1/schema/000077500000000000000000000000001421732762500173435ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/schema/build.gradle.kts000066400000000000000000000003501421732762500224200ustar00rootroot00000000000000plugins { `java-conventions` } val schemas by configurations.creating { isCanBeConsumed = true isCanBeResolved = false outgoing { artifact(file("src/main/resources/org/opentest4j/reporting/schema")) } } open-test-reporting-r0.1.0-M1/schema/src/000077500000000000000000000000001421732762500201325ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/schema/src/docs/000077500000000000000000000000001421732762500210625ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/schema/src/docs/asciidoc/000077500000000000000000000000001421732762500226405ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/schema/src/docs/asciidoc/includes/000077500000000000000000000000001421732762500244465ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/schema/src/docs/asciidoc/includes/events.xml000066400000000000000000000013431421732762500264750ustar00rootroot00000000000000 wonderland alice open-test-reporting-r0.1.0-M1/schema/src/docs/asciidoc/includes/hierarchy.xml000066400000000000000000000012241421732762500271450ustar00rootroot00000000000000 wonderland alice open-test-reporting-r0.1.0-M1/schema/src/main/000077500000000000000000000000001421732762500210565ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/schema/src/main/java/000077500000000000000000000000001421732762500217775ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/schema/src/main/java/org/000077500000000000000000000000001421732762500225665ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/schema/src/main/java/org/opentest4j/000077500000000000000000000000001421732762500246655ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/schema/src/main/java/org/opentest4j/reporting/000077500000000000000000000000001421732762500266765ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/schema/src/main/java/org/opentest4j/reporting/schema/000077500000000000000000000000001421732762500301365ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/schema/src/main/java/org/opentest4j/reporting/schema/Namespace.java000066400000000000000000000047651421732762500327110ustar00rootroot00000000000000/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.schema; import java.util.Objects; import static javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI; /** * An XML namespace identified by a URI. */ public class Namespace { /** * W3C XML Schema Instance namespace ({@value javax.xml.XMLConstants#W3C_XML_SCHEMA_INSTANCE_NS_URI}). */ public static final Namespace XML_SCHEMA_INSTANCE = Namespace.of(W3C_XML_SCHEMA_INSTANCE_NS_URI); /** * Open Test Reporting core namespace */ public static final Namespace REPORTING_CORE = Namespace.of("https://schemas.opentest4j.org/reporting/core/0.1.0"); /** * Open Test Reporting events namespace */ public static final Namespace REPORTING_EVENTS = Namespace.of( "https://schemas.opentest4j.org/reporting/events/0.1.0"); /** * Open Test Reporting Java namespace */ public static final Namespace REPORTING_JAVA = Namespace.of("https://schemas.opentest4j.org/reporting/java/0.1.0"); /** * Open Test Reporting hierarchical namespace */ public static final Namespace REPORTING_HIERARCHY = Namespace.of( "https://schemas.opentest4j.org/reporting/hierarchy/0.1.0"); /** * Create the namespace with the supplied URI. * * @param uri the namespace URI * @return namespace with the supplied URI */ public static Namespace of(String uri) { return new Namespace(uri); } private final String uri; private Namespace(String uri) { this.uri = uri; } /** * @return the URI that identifies this namespace */ public String getUri() { return uri; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Namespace namespace = (Namespace) o; return uri.equals(namespace.uri); } @Override public int hashCode() { return Objects.hash(uri); } @Override public String toString() { return String.format("Namespace{uri='%s'}", uri); } } QualifiedName.java000066400000000000000000000036121421732762500334300ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/schema/src/main/java/org/opentest4j/reporting/schema/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.schema; import java.util.Objects; /** * A qualified name consisting of a namespace and a simple name. */ public class QualifiedName { /** * Create the qualified name for the supplied namespace and name. * * @param namespace the namespace * @param simpleName the simple name * @return namespace with the supplied URI */ public static QualifiedName of(Namespace namespace, String simpleName) { return new QualifiedName(namespace, simpleName); } private final Namespace namespace; private final String simpleName; private QualifiedName(Namespace namespace, String simpleName) { this.namespace = namespace; this.simpleName = simpleName; } /** * @return the namespace of this qualified name */ public Namespace getNamespace() { return namespace; } /** * @return the simple name of this qualified name */ public String getSimpleName() { return simpleName; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } QualifiedName that = (QualifiedName) o; return namespace.equals(that.namespace) && simpleName.equals(that.simpleName); } @Override public int hashCode() { return Objects.hash(namespace, simpleName); } } open-test-reporting-r0.1.0-M1/schema/src/main/resources/000077500000000000000000000000001421732762500230705ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/schema/src/main/resources/org/000077500000000000000000000000001421732762500236575ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/schema/src/main/resources/org/opentest4j/000077500000000000000000000000001421732762500257565ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/schema/src/main/resources/org/opentest4j/reporting/000077500000000000000000000000001421732762500277675ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/schema/src/main/resources/org/opentest4j/reporting/schema/000077500000000000000000000000001421732762500312275ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/schema/src/main/resources/org/opentest4j/reporting/schema/core.xsd000066400000000000000000000100121421732762500326710ustar00rootroot00000000000000 open-test-reporting-r0.1.0-M1/schema/src/main/resources/org/opentest4j/reporting/schema/events.xsd000066400000000000000000000026771421732762500332670ustar00rootroot00000000000000 hierarchy.xsd000066400000000000000000000023141421732762500336460ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/schema/src/main/resources/org/opentest4j/reporting/schema open-test-reporting-r0.1.0-M1/schema/src/main/resources/org/opentest4j/reporting/schema/java.xsd000066400000000000000000000044631421732762500326770ustar00rootroot00000000000000 open-test-reporting-r0.1.0-M1/settings.gradle.kts000066400000000000000000000004721421732762500217260ustar00rootroot00000000000000rootProject.name = "open-test-reporting" dependencyResolutionManagement { repositories { mavenCentral() } } include("cli") include("documentation") include("events") include("schema") include("tooling") enableFeaturePreview("VERSION_CATALOGS") enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") open-test-reporting-r0.1.0-M1/tooling/000077500000000000000000000000001421732762500175565ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/tooling/build.gradle.kts000066400000000000000000000005471421732762500226430ustar00rootroot00000000000000plugins { `java-conventions` } dependencies { api(projects.schema) implementation(projects.events) testImplementation(libs.assertj.core) testImplementation(libs.junit.jupiter) testImplementation(libs.xmlunit.assertj) testCompileOnly(libs.jetbrains.annotations) } tasks { compileJava { options.release.set(11) } } open-test-reporting-r0.1.0-M1/tooling/src/000077500000000000000000000000001421732762500203455ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/tooling/src/main/000077500000000000000000000000001421732762500212715ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/tooling/src/main/java/000077500000000000000000000000001421732762500222125ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/tooling/src/main/java/org/000077500000000000000000000000001421732762500230015ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/tooling/src/main/java/org/opentest4j/000077500000000000000000000000001421732762500251005ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/tooling/src/main/java/org/opentest4j/reporting/000077500000000000000000000000001421732762500271115ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/tooling/src/main/java/org/opentest4j/reporting/tooling/000077500000000000000000000000001421732762500305645ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/tooling/src/main/java/org/opentest4j/reporting/tooling/converter/000077500000000000000000000000001421732762500325735ustar00rootroot00000000000000Converter.java000066400000000000000000000022021421732762500353220ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/tooling/src/main/java/org/opentest4j/reporting/tooling/converter/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.tooling.converter; import java.nio.file.Path; /** * Converter for event-based reports into the hierarchical format. */ public interface Converter { /** * Convert the supplied event-based report into the hierarchical format. * * @param eventsXmlFile the source file * @param hierarchicalXmlFile the target file * @throws Exception if an error occurs converting or writing to the target file */ void convert(Path eventsXmlFile, Path hierarchicalXmlFile) throws Exception; } DefaultConverter.java000066400000000000000000000226051421732762500366400ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/tooling/src/main/java/org/opentest4j/reporting/tooling/converter/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.tooling.converter; import org.opentest4j.reporting.events.core.Infrastructure; import org.opentest4j.reporting.events.root.Event; import org.opentest4j.reporting.events.root.Finished; import org.opentest4j.reporting.events.root.Reported; import org.opentest4j.reporting.events.root.Started; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.schema.QualifiedName; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import java.nio.file.Path; import java.time.Duration; import java.time.Instant; import java.util.HashMap; import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.function.BiPredicate; import java.util.function.IntFunction; import java.util.stream.IntStream; import java.util.stream.Stream; import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toUnmodifiableSet; import static javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING; import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE; import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI; /** * Default implementation of {@link Converter}. */ public class DefaultConverter implements Converter { private static final String HIERARCHY_PREFIX = "h"; private static final String EXECUTION_NODE_NAME = HIERARCHY_PREFIX + ":execution"; private static final String ROOT_NODE_NAME = HIERARCHY_PREFIX + ":root"; private static final String CHILD_NODE_NAME = HIERARCHY_PREFIX + ":child"; private static final String START_ATTRIBUTE_NAME = "start"; private static final String DURATION_ATTRIBUTE_NAME = "duration"; private static final Set EVENT_ONLY_ATTRIBUTES = Stream.of(Event.ID, Event.TIME, Started.PARENT_ID) // .map(QualifiedName::getSimpleName) // .collect(toUnmodifiableSet()); @Override public void convert(Path eventsXmlFile, Path hierarchicalXmlFile) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document sourceDocument = builder.parse(eventsXmlFile.toFile()); Node sourceRoot = sourceDocument.getDocumentElement(); Document targetDocument = builder.newDocument(); createRootElement(sourceRoot, targetDocument); Map nodeById = new HashMap<>(); for (Node child = sourceRoot.getFirstChild(); child != null; child = child.getNextSibling()) { if (child instanceof Element) { Element element = (Element) child; if (matches(Started.ELEMENT, element)) { started(targetDocument, nodeById, element); } else if (matches(Reported.ELEMENT, element)) { reported(nodeById, element); } else if (matches(Finished.ELEMENT, element)) { finished(nodeById, element); } else if (matches(Infrastructure.ELEMENT, element)) { infrastructure(targetDocument, element); } } } TransformerFactory transformerFactory = TransformerFactory.newInstance(); transformerFactory.setFeature(FEATURE_SECURE_PROCESSING, true); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); transformer.transform(new DOMSource(targetDocument), new StreamResult(hierarchicalXmlFile.toFile())); } private void createRootElement(Node sourceRoot, Document targetDocument) { Element targetRoot = targetDocument.createElement(EXECUTION_NODE_NAME); targetDocument.appendChild(targetRoot); copyAttributes(sourceRoot, targetRoot, (__, value) -> !Namespace.REPORTING_EVENTS.getUri().equals(value)); targetRoot.setAttributeNS(XMLNS_ATTRIBUTE_NS_URI, XMLNS_ATTRIBUTE + ":" + HIERARCHY_PREFIX, Namespace.REPORTING_HIERARCHY.getUri()); } private boolean matches(QualifiedName qualifiedName, Element element) { return qualifiedName.getNamespace().getUri().equals(element.getNamespaceURI()) && qualifiedName.getSimpleName().equals(element.getLocalName()); } private void infrastructure(Document targetDocument, Element sourceElement) { Node targetElement = sourceElement.cloneNode(true); targetDocument.adoptNode(targetElement); targetDocument.getDocumentElement().appendChild(targetElement); } private void started(Document targetDocument, Map nodeById, Element sourceElement) { Element targetElement; if (sourceElement.hasAttribute(Started.PARENT_ID.getSimpleName())) { targetElement = targetDocument.createElementNS(Namespace.REPORTING_HIERARCHY.getUri(), CHILD_NODE_NAME); nodeById.get(sourceElement.getAttribute(Started.PARENT_ID.getSimpleName())).appendChild(targetElement); } else { targetElement = targetDocument.createElementNS(Namespace.REPORTING_HIERARCHY.getUri(), ROOT_NODE_NAME); targetDocument.getDocumentElement().appendChild(targetElement); } String id = sourceElement.getAttribute(Event.ID.getSimpleName()); nodeById.put(id, targetElement); copyAttributes(sourceElement, targetElement, (name, __) -> !EVENT_ONLY_ATTRIBUTES.contains(name)); copyChildren(sourceElement, targetElement); if (sourceElement.hasAttribute(Event.TIME.getSimpleName())) { targetElement.setAttribute(START_ATTRIBUTE_NAME, sourceElement.getAttribute(Event.TIME.getSimpleName())); } } private void reported(Map nodeById, Element sourceElement) { Element targetElement = nodeById.get(sourceElement.getAttribute(Event.ID.getSimpleName())); copyAttributes(sourceElement, targetElement, (name, __) -> !EVENT_ONLY_ATTRIBUTES.contains(name)); mergeChildren(sourceElement, targetElement); } private void finished(Map nodeById, Element sourceElement) { Element targetElement = nodeById.get(sourceElement.getAttribute(Event.ID.getSimpleName())); copyAttributes(sourceElement, targetElement, (name, __) -> !EVENT_ONLY_ATTRIBUTES.contains(name)); mergeChildren(sourceElement, targetElement); if (targetElement.hasAttribute(START_ATTRIBUTE_NAME) && sourceElement.hasAttribute(Event.TIME.getSimpleName())) { Instant start = Instant.parse(targetElement.getAttribute(START_ATTRIBUTE_NAME)); Instant finish = Instant.parse(sourceElement.getAttribute(Event.TIME.getSimpleName())); targetElement.setAttribute(DURATION_ATTRIBUTE_NAME, Duration.between(start, finish).toString()); } moveChildrenToEnd(targetElement); } private void moveChildrenToEnd(Element targetElement) { stream(targetElement.getChildNodes()) // .filter(child -> CHILD_NODE_NAME.equals(child.getNodeName())) // .collect(toList()) // avoid concurrent modification .forEach(child -> { targetElement.removeChild(child); targetElement.appendChild(child); }); } private void copyAttributes(Node sourceNode, Node targetNode, BiPredicate filter) { stream(sourceNode.getAttributes()) // .filter(sourceItem -> filter.test(sourceItem.getNodeName(), sourceItem.getNodeValue())) // .map(sourceItem -> sourceItem.cloneNode(true)) // .forEach(targetItem -> { targetNode.getOwnerDocument().adoptNode(targetItem); targetNode.getAttributes().setNamedItem(targetItem); }); } private void mergeChildren(Node sourceElement, Node targetElement) { stream(sourceElement.getChildNodes()) // .forEach(sourceChild -> findNode(targetElement.getChildNodes(), sourceChild.getNodeName()) // .ifPresentOrElse( // existingNode -> copyChildren(sourceChild, existingNode), // () -> { Node targetChild = sourceChild.cloneNode(true); targetElement.getOwnerDocument().adoptNode(targetChild); targetElement.appendChild(targetChild); })); } private Optional findNode(NodeList nodes, String name) { return stream(nodes) // .filter(node -> node.getNodeName().equals(name)) // .findAny(); } private void copyChildren(Node sourceElement, Node targetElement) { stream(sourceElement.getChildNodes()) // .map(sourceChild -> sourceChild.cloneNode(true)) // .forEach(targetChild -> { targetElement.getOwnerDocument().adoptNode(targetChild); targetElement.appendChild(targetChild); }); } private static Stream stream(NodeList nodeList) { return stream(nodeList.getLength(), nodeList::item); } private static Stream stream(NamedNodeMap namedNodeMap) { return stream(namedNodeMap.getLength(), namedNodeMap::item); } private static Stream stream(int length, IntFunction item) { return IntStream.range(0, length).mapToObj(item); } } open-test-reporting-r0.1.0-M1/tooling/src/main/java/org/opentest4j/reporting/tooling/validator/000077500000000000000000000000001421732762500325515ustar00rootroot00000000000000DefaultValidator.java000066400000000000000000000155331421732762500365760ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/tooling/src/main/java/org/opentest4j/reporting/tooling/validator/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.tooling.validator; import org.opentest4j.reporting.schema.Namespace; import org.opentest4j.reporting.tooling.converter.Converter; import org.w3c.dom.ls.LSInput; import org.w3c.dom.ls.LSResourceResolver; import org.xml.sax.ErrorHandler; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import javax.xml.catalog.CatalogFeatures; import javax.xml.catalog.CatalogFeatures.Feature; import javax.xml.catalog.CatalogResolver; import javax.xml.transform.Source; import javax.xml.transform.stream.StreamSource; import javax.xml.validation.SchemaFactory; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Map; import static java.util.Objects.requireNonNull; import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI; import static javax.xml.catalog.CatalogManager.catalogResolver; import static org.opentest4j.reporting.tooling.validator.Severity.ERROR; import static org.opentest4j.reporting.tooling.validator.Severity.WARNING; /** * Default implementation of {@link Validator}. */ public class DefaultValidator implements Validator { private static final Map SCHEMAS = Map.of( // Namespace.REPORTING_EVENTS, "/org/opentest4j/reporting/schema/events.xsd", // Namespace.REPORTING_HIERARCHY, "/org/opentest4j/reporting/schema/hierarchy.xsd", // Namespace.REPORTING_CORE, "/org/opentest4j/reporting/schema/core.xsd", // Namespace.REPORTING_JAVA, "/org/opentest4j/reporting/schema/java.xsd"); private final SchemaFactory schemaFactory = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI); private final CatalogResolver catalogResolver; /** * Create a new instance. * * @param catalogs for resolving references to XML schemas */ public DefaultValidator(URI... catalogs) { var features = CatalogFeatures.builder().with(Feature.RESOLVE, "continue").build(); this.catalogResolver = catalogResolver(features, catalogs); } @Override public ValidationResult validate(Path xmlFile) { try (var in = Files.newInputStream(xmlFile)) { return validateSafely(xmlFile, new StreamSource(in)); } catch (Exception e) { throw new RuntimeException("Failure during validation: " + xmlFile, e); } } private ValidationResult validateSafely(Path xmlFile, Source source) throws SAXException, IOException { var errorHandler = new CollectingErrorHandler(xmlFile); validate(source, errorHandler); return errorHandler.toValidationResult(); } private void validate(Source source, ErrorHandler errorHandler) throws SAXException, IOException { var validator = schemaFactory.newSchema().newValidator(); validator.setResourceResolver(createResourceResolver()); validator.setErrorHandler(errorHandler); validator.validate(source); } private LSResourceResolver createResourceResolver() { return (type, namespaceURI, publicId, systemId, baseURI) -> { if (namespaceURI != null) { var namespace = Namespace.of(namespaceURI); if (SCHEMAS.containsKey(namespace)) { LSInputImpl input = new LSInputImpl(); input.setPublicId(publicId); var schema = SCHEMAS.get(namespace); input.setSystemId(requireNonNull(Namespace.class.getResource(schema)).toExternalForm()); input.setBaseURI(baseURI); var stream = Namespace.class.getResourceAsStream(schema); input.setCharacterStream(new InputStreamReader(requireNonNull(stream))); return input; } } if (systemId != null) { return catalogResolver.resolveResource(type, namespaceURI, publicId, systemId, baseURI); } return null; }; } static class LSInputImpl implements LSInput { private Reader characterStream; private InputStream byteStream; private String stringData; private String systemId; private String publicId; private String baseURI; private String encoding; private boolean certifiedText; @Override public Reader getCharacterStream() { return characterStream; } @Override public void setCharacterStream(Reader characterStream) { this.characterStream = characterStream; } @Override public InputStream getByteStream() { return byteStream; } @Override public void setByteStream(InputStream byteStream) { this.byteStream = byteStream; } @Override public String getStringData() { return stringData; } @Override public void setStringData(String stringData) { this.stringData = stringData; } @Override public String getSystemId() { return systemId; } @Override public void setSystemId(String systemId) { this.systemId = systemId; } @Override public String getPublicId() { return publicId; } @Override public void setPublicId(String publicId) { this.publicId = publicId; } @Override public String getBaseURI() { return baseURI; } @Override public void setBaseURI(String baseURI) { this.baseURI = baseURI; } @Override public String getEncoding() { return encoding; } @Override public void setEncoding(String encoding) { this.encoding = encoding; } @Override public boolean getCertifiedText() { return certifiedText; } @Override public void setCertifiedText(boolean certifiedText) { this.certifiedText = certifiedText; } } private static class CollectingErrorHandler implements ErrorHandler { private final Path xmlFile; private final List messages = new ArrayList<>(); public CollectingErrorHandler(Path xmlFile) { this.xmlFile = xmlFile; } @Override public void warning(SAXParseException e) { addValidationMessage(WARNING, e); } @Override public void error(SAXParseException e) { addValidationMessage(ERROR, e); } private void addValidationMessage(Severity severity, SAXParseException e) { var path = e.getSystemId() == null ? xmlFile.toString() : e.getSystemId(); var location = new Location(path, e.getLineNumber(), e.getColumnNumber()); messages.add(new ValidationMessage(severity, location, e.getMessage())); } @Override public void fatalError(SAXParseException e) throws SAXParseException { throw e; } public ValidationResult toValidationResult() { return new ValidationResult(messages); } } } Location.java000066400000000000000000000035301421732762500351060ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/tooling/src/main/java/org/opentest4j/reporting/tooling/validator/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.tooling.validator; import java.util.Objects; /** * Location of a {@linkplain ValidationMessage validation message}. */ public class Location { private final String path; private final int lineNumber; private final int column; Location(String path, int lineNumber, int column) { this.path = path; this.lineNumber = lineNumber; this.column = column; } /** * Get the path of the file. * * @return the path of the file */ public String getPath() { return path; } /** * Get the line number. * * @return the line number */ public int getLineNumber() { return lineNumber; } /** * Get the column number. * * @return the column number */ public int getColumn() { return column; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Location location = (Location) o; return lineNumber == location.lineNumber && column == location.column && path.equals(location.path); } @Override public int hashCode() { return Objects.hash(path, lineNumber, column); } @Override public String toString() { return String.format("%s:%d:%d", path, lineNumber, column); } } Severity.java000066400000000000000000000015151421732762500351510ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/tooling/src/main/java/org/opentest4j/reporting/tooling/validator/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.tooling.validator; /** * Severity of a {@linkplain ValidationMessage validation message}. */ public enum Severity { /** * A warning. */ WARNING, /** * An error. */ ERROR } ValidationMessage.java000066400000000000000000000037161421732762500367430ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/tooling/src/main/java/org/opentest4j/reporting/tooling/validator/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.tooling.validator; import java.util.Objects; /** * Validation message with severity and location. */ public class ValidationMessage { private final Severity severity; private final Location location; private final String message; ValidationMessage(Severity severity, Location location, String message) { this.severity = severity; this.location = location; this.message = message; } /** * Get the severity of this validation message. * * @return the severity */ public Severity getSeverity() { return severity; } /** * Get the location of this validation message. * * @return the location */ public Location getLocation() { return location; } /** * Get the message of this validation message. * * @return the message */ public String getMessage() { return message; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } ValidationMessage that = (ValidationMessage) o; return severity == that.severity && location.equals(that.location) && message.equals(that.message); } @Override public int hashCode() { return Objects.hash(severity, location, message); } @Override public String toString() { return String.format("[%s] %s - %s", severity, location, message); } } ValidationResult.java000066400000000000000000000031351421732762500366300ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/tooling/src/main/java/org/opentest4j/reporting/tooling/validator/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.tooling.validator; import java.util.Iterator; import java.util.List; import java.util.Objects; import static java.util.stream.Collectors.joining; /** * Result of validating an XML report file. */ public class ValidationResult implements Iterable { private final List messages; ValidationResult(List messages) { this.messages = List.copyOf(messages); } /** * Count the number of validation messages with the supplied severity. * * @param severity the severity to count * @return number of validation messages with the supplied severity */ public long count(Severity severity) { return messages.stream().filter(m -> severity.equals(m.getSeverity())).count(); } @Override public Iterator iterator() { return messages.iterator(); } @Override public String toString() { return messages.stream() // .map(Objects::toString) // .collect(joining("\n")); } } Validator.java000066400000000000000000000017171421732762500352700ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/tooling/src/main/java/org/opentest4j/reporting/tooling/validator/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.tooling.validator; import java.nio.file.Path; /** * Validator for event-based and hierarchical XML report files. */ public interface Validator { /** * Validate the supplied XML file. * * @param xmlFile the XML file to validate * @return validation result */ ValidationResult validate(Path xmlFile); } open-test-reporting-r0.1.0-M1/tooling/src/test/000077500000000000000000000000001421732762500213245ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/tooling/src/test/java/000077500000000000000000000000001421732762500222455ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/tooling/src/test/java/org/000077500000000000000000000000001421732762500230345ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/tooling/src/test/java/org/opentest4j/000077500000000000000000000000001421732762500251335ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/tooling/src/test/java/org/opentest4j/reporting/000077500000000000000000000000001421732762500271445ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/tooling/src/test/java/org/opentest4j/reporting/tooling/000077500000000000000000000000001421732762500306175ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/tooling/src/test/java/org/opentest4j/reporting/tooling/converter/000077500000000000000000000000001421732762500326265ustar00rootroot00000000000000DefaultConverterTests.java000066400000000000000000000147541421732762500377240ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/tooling/src/test/java/org/opentest4j/reporting/tooling/converter/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.tooling.converter; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import org.opentest4j.reporting.events.api.DocumentWriter; import org.opentest4j.reporting.events.api.NamespaceRegistry; import org.opentest4j.reporting.events.root.Events; import org.opentest4j.reporting.schema.Namespace; import org.xmlunit.assertj3.XmlAssert; import org.xmlunit.builder.Input; import org.xmlunit.util.Convert; import java.nio.file.Path; import java.time.Duration; import java.time.Instant; import java.util.Arrays; import java.util.Map; import java.util.function.Consumer; import static org.opentest4j.reporting.events.core.CoreFactory.attachments; import static org.opentest4j.reporting.events.core.CoreFactory.cpuCores; import static org.opentest4j.reporting.events.core.CoreFactory.data; import static org.opentest4j.reporting.events.core.CoreFactory.infrastructure; import static org.opentest4j.reporting.events.core.CoreFactory.metadata; import static org.opentest4j.reporting.events.core.CoreFactory.result; import static org.opentest4j.reporting.events.core.CoreFactory.tag; import static org.opentest4j.reporting.events.core.CoreFactory.tags; import static org.opentest4j.reporting.events.core.Result.Status.SUCCESSFUL; import static org.opentest4j.reporting.events.root.RootFactory.finished; import static org.opentest4j.reporting.events.root.RootFactory.reported; import static org.opentest4j.reporting.events.root.RootFactory.started; class DefaultConverterTests { static final NamespaceRegistry NAMESPACE_REGISTRY = NamespaceRegistry.builder(Namespace.REPORTING_CORE) // .add("e", Namespace.REPORTING_EVENTS) // .add("java", Namespace.REPORTING_JAVA) // .build(); Path sourceFile; Path targetFile; @BeforeEach void setUp(@TempDir Path tempDir) { sourceFile = tempDir.resolve("events.xml"); targetFile = tempDir.resolve("hierarchy.xml"); } @Test void convertsInfrastructureSection() throws Exception { writeXml(sourceFile, writer -> writer.append(infrastructure(), infrastructure -> infrastructure.append(cpuCores(42)))); new DefaultConverter().convert(sourceFile, targetFile); assertAll(targetFile, it -> it.valueByXPath("//*/c:infrastructure/c:cpuCores").isEqualTo(42)); } @Test void convertsStartedAndFinishedEvents() throws Exception { var duration = Duration.ofMillis(42); var startTime = Instant.now().minus(duration); writeXml(sourceFile, writer -> writer // .append(started("1", startTime, "container"), started -> started // .append(metadata(), metadata -> metadata // .append(tags(), tags -> tags // .append(tag("a"))))) // .append(started("2", startTime.plus(duration), "test"), started -> started.withParentId("1")) // .append(finished("2", startTime.plus(duration.multipliedBy(2)))) // .append(finished("1", startTime.plus(duration.multipliedBy(3))), finished -> finished // .append(result(SUCCESSFUL)))); new DefaultConverter().convert(sourceFile, targetFile); assertAll(targetFile, // it -> it.nodesByXPath("//*/h:root") // .hasSize(1) // .haveAttribute("name", "container") // .haveAttribute("start", startTime.toString()) // .haveAttribute("duration", duration.multipliedBy(3).toString()), // it -> it.valueByXPath("//*/h:root/c:metadata/c:tags/c:tag") // .isEqualTo("a"), // it -> it.valueByXPath("//*/h:root/c:result/@status") // .isEqualTo("SUCCESSFUL"), // it -> it.nodesByXPath("//*/h:root/h:child") // .hasSize(1) // .haveAttribute("name", "test") // .haveAttribute("start", startTime.plus(duration).toString()) // .haveAttribute("duration", duration.toString()) // ); } @Test void mergesReportEntries() throws Exception { writeXml(sourceFile, writer -> writer.append(started("1", Instant.now(), "test"), started -> started // .append(attachments(), attachments -> attachments // .append(data(), data -> data.addEntry("started", "1")))) // .append(reported("1", Instant.now()), reported -> reported // .append(attachments(), attachments -> attachments // .append(data(), data -> data.addEntry("reported", "2")))) // .append(finished("1", Instant.now()), finished -> finished // .append(attachments(), attachments -> attachments // .append(data(), data -> data.addEntry("finished", "3"))))); new DefaultConverter().convert(sourceFile, targetFile); assertAll(targetFile, // it -> it.nodesByXPath("//*/h:root/c:attachments").hasSize(1), // it -> it.nodesByXPath("//*/h:root/c:attachments/c:data").hasSize(3), // it -> it.valueByXPath("(//*/h:root/c:attachments/c:data/c:entry/@key)[1]").isEqualTo("started"), // it -> it.valueByXPath("(//*/h:root/c:attachments/c:data/c:entry/text())[1]").isEqualTo("1"), // it -> it.valueByXPath("(//*/h:root/c:attachments/c:data/c:entry/@key)[2]").isEqualTo("reported"), // it -> it.valueByXPath("(//*/h:root/c:attachments/c:data/c:entry/text())[2]").isEqualTo("2"), // it -> it.valueByXPath("(//*/h:root/c:attachments/c:data/c:entry/@key)[3]").isEqualTo("finished"), // it -> it.valueByXPath("(//*/h:root/c:attachments/c:data/c:entry/text())[3]").isEqualTo("3") // ); } private void writeXml(Path eventsXmlFile, Consumer> action) throws Exception { try (var writer = Events.createDocumentWriter(NAMESPACE_REGISTRY, eventsXmlFile)) { action.accept(writer); } } @SafeVarargs private static void assertAll(Path targetFile, Consumer... checks) { var document = Convert.toDocument(Input.from(targetFile).build()); var xmlAssert = XmlAssert.assertThat(document).withNamespaceContext(Map.of( // "h", Namespace.REPORTING_HIERARCHY.getUri(), // "c", Namespace.REPORTING_CORE.getUri() // )); Assertions.assertAll(targetFile.toUri().toString(), Arrays.stream(checks).map(it -> () -> it.accept(xmlAssert))); } } open-test-reporting-r0.1.0-M1/tooling/src/test/java/org/opentest4j/reporting/tooling/validator/000077500000000000000000000000001421732762500326045ustar00rootroot00000000000000DefaultValidatorTests.java000066400000000000000000000065631421732762500376570ustar00rootroot00000000000000open-test-reporting-r0.1.0-M1/tooling/src/test/java/org/opentest4j/reporting/tooling/validator/* * Copyright 2021-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.opentest4j.reporting.tooling.validator; import org.intellij.lang.annotations.Language; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import java.io.IOException; import java.io.UncheckedIOException; import java.nio.file.Files; import java.nio.file.Path; import static org.assertj.core.api.Assertions.assertThat; import static org.opentest4j.reporting.tooling.validator.Severity.ERROR; import static org.opentest4j.reporting.tooling.validator.Severity.WARNING; class DefaultValidatorTests { @TempDir Path tempDir; @Test void validatesEventsXmlFile() { var xmlFile = writeXml(tempDir.resolve("events.xml"), """ """); var validationResult = new DefaultValidator().validate(xmlFile); assertThat(validationResult).isEmpty(); } @Test void validatesHierarchicalXmlFile() { var xmlFile = writeXml(tempDir.resolve("hierarchy.xml"), """ """); var validationResult = new DefaultValidator().validate(xmlFile); assertThat(validationResult).isEmpty(); } @Test void resolvesThirdPartySchemasUsingCatalog() { writeXml(tempDir.resolve("schema.xsd"), """ """); var catalog = writeXml(tempDir.resolve("catalog.xml"), """ """); var xmlFile = writeXml(tempDir.resolve("test.xml"), """ Hello World! """); var validationResult = new DefaultValidator(catalog.toUri()).validate(xmlFile); assertThat(validationResult).isEmpty(); } @Test void generatesWarningsAndErrors() { var xmlFile = writeXml(tempDir.resolve("test.xml"), """ Hello World! """); var validationResult = new DefaultValidator().validate(xmlFile); assertThat(validationResult.count(WARNING)).isEqualTo(1); assertThat(validationResult.count(ERROR)).isEqualTo(1); } private Path writeXml(Path file, @Language("xml") String content) { try { return Files.writeString(file, content); } catch (IOException e) { throw new UncheckedIOException(e); } } }