creator, Consumer super C> configurer);
}
ChildElement.java 0000664 0000000 0000000 00000002447 14217327625 0034147 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000006006 14217327625 0033310 0 ustar 00root root 0000000 0000000 /*
* 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.java 0000664 0000000 0000000 00000022704 14217327625 0036070 0 ustar 00root root 0000000 0000000 open-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 super C> 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.java 0000664 0000000 0000000 00000004416 14217327625 0034563 0 ustar 00root root 0000000 0000000 open-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 super C> 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.java 0000664 0000000 0000000 00000006246 14217327625 0033263 0 ustar 00root root 0000000 0000000 /*
* 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 super C> 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.java 0000664 0000000 0000000 00000002734 14217327625 0033277 0 ustar 00root root 0000000 0000000 /*
* 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 super T> configurer) {
T result = create(context);
configurer.accept(result);
return result;
}
}
NamespaceRegistry.java 0000664 0000000 0000000 00000012321 14217327625 0035227 0 ustar 00root root 0000000 0000000 open-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/ 0000775 0000000 0000000 00000000000 14217327625 0031176 5 ustar 00root root 0000000 0000000 Attachments.java 0000664 0000000 0000000 00000002330 14217327625 0034233 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000012062 14217327625 0034203 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000002320 14217327625 0033502 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000004165 14217327625 0032720 0 ustar 00root root 0000000 0000000 /*
* 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.java 0000664 0000000 0000000 00000002641 14217327625 0035112 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000002645 14217327625 0034375 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000003415 14217327625 0034025 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000002303 14217327625 0033476 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000002463 14217327625 0035007 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000002311 14217327625 0033477 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000002346 14217327625 0035124 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000002265 14217327625 0033275 0 ustar 00root root 0000000 0000000 /*
* 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.java 0000664 0000000 0000000 00000003303 14217327625 0033316 0 ustar 00root root 0000000 0000000 /*
* 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.java0000664 0000000 0000000 00000002304 14217327625 0033463 0 ustar 00root root 0000000 0000000 /*
* 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.java 0000664 0000000 0000000 00000002240 14217327625 0032552 0 ustar 00root root 0000000 0000000 /*
* 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.java 0000664 0000000 0000000 00000002205 14217327625 0032736 0 ustar 00root root 0000000 0000000 /*
* 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.java 0000664 0000000 0000000 00000002561 14217327625 0033706 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000002303 14217327625 0033477 0 ustar 00root root 0000000 0000000 open-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/ 0000775 0000000 0000000 00000000000 14217327625 0031167 5 ustar 00root root 0000000 0000000 ClassSource.java 0000664 0000000 0000000 00000003606 14217327625 0034206 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000003770 14217327625 0036575 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000002423 14217327625 0034302 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000003036 14217327625 0033465 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000006230 14217327625 0034165 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000002416 14217327625 0034205 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000004146 14217327625 0034361 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000002664 14217327625 0034477 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000003610 14217327625 0033702 0 ustar 00root root 0000000 0000000 open-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/ 0000775 0000000 0000000 00000000000 14217327625 0031231 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/events/src/main/java/org/opentest4j/reporting/events/root/Event.java 0000664 0000000 0000000 00000003145 14217327625 0033160 0 ustar 00root root 0000000 0000000 /*
* 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.java 0000664 0000000 0000000 00000003516 14217327625 0033345 0 ustar 00root root 0000000 0000000 /*
* 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.java 0000664 0000000 0000000 00000002520 14217327625 0033545 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000002520 14217327625 0033600 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000003702 14217327625 0034272 0 ustar 00root root 0000000 0000000 open-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.java0000664 0000000 0000000 00000004036 14217327625 0033505 0 ustar 00root root 0000000 0000000 /*
* 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/ 0000775 0000000 0000000 00000000000 14217327625 0021155 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/events/src/test/java/ 0000775 0000000 0000000 00000000000 14217327625 0022076 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/events/src/test/java/DocumentWriterSample.java 0000664 0000000 0000000 00000004255 14217327625 0027064 0 ustar 00root root 0000000 0000000
/*
* 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/ 0000775 0000000 0000000 00000000000 14217327625 0022665 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/events/src/test/java/org/opentest4j/ 0000775 0000000 0000000 00000000000 14217327625 0024764 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/events/src/test/java/org/opentest4j/reporting/ 0000775 0000000 0000000 00000000000 14217327625 0026775 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/events/src/test/java/org/opentest4j/reporting/ArchitectureTests.java 0000664 0000000 0000000 00000002123 14217327625 0033303 0 ustar 00root root 0000000 0000000 /*
* 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/ 0000775 0000000 0000000 00000000000 14217327625 0030301 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/events/src/test/java/org/opentest4j/reporting/events/api/ 0000775 0000000 0000000 00000000000 14217327625 0031052 5 ustar 00root root 0000000 0000000 DocumentWriterTest.java 0000664 0000000 0000000 00000005131 14217327625 0035451 0 ustar 00root root 0000000 0000000 open-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.properties 0000664 0000000 0000000 00000000064 14217327625 0021457 0 ustar 00root root 0000000 0000000 group = org.opentest4j.reporting
version = 0.1.0-M1
open-test-reporting-r0.1.0-M1/schema/ 0000775 0000000 0000000 00000000000 14217327625 0017343 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/schema/build.gradle.kts 0000664 0000000 0000000 00000000350 14217327625 0022420 0 ustar 00root root 0000000 0000000 plugins {
`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/ 0000775 0000000 0000000 00000000000 14217327625 0020132 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/schema/src/docs/ 0000775 0000000 0000000 00000000000 14217327625 0021062 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/schema/src/docs/asciidoc/ 0000775 0000000 0000000 00000000000 14217327625 0022640 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/schema/src/docs/asciidoc/includes/ 0000775 0000000 0000000 00000000000 14217327625 0024446 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/schema/src/docs/asciidoc/includes/events.xml 0000664 0000000 0000000 00000001343 14217327625 0026475 0 ustar 00root root 0000000 0000000
wonderland
alice
open-test-reporting-r0.1.0-M1/schema/src/docs/asciidoc/includes/hierarchy.xml 0000664 0000000 0000000 00000001224 14217327625 0027145 0 ustar 00root root 0000000 0000000
wonderland
alice
open-test-reporting-r0.1.0-M1/schema/src/main/ 0000775 0000000 0000000 00000000000 14217327625 0021056 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/schema/src/main/java/ 0000775 0000000 0000000 00000000000 14217327625 0021777 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/schema/src/main/java/org/ 0000775 0000000 0000000 00000000000 14217327625 0022566 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/schema/src/main/java/org/opentest4j/ 0000775 0000000 0000000 00000000000 14217327625 0024665 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/schema/src/main/java/org/opentest4j/reporting/ 0000775 0000000 0000000 00000000000 14217327625 0026676 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/schema/src/main/java/org/opentest4j/reporting/schema/ 0000775 0000000 0000000 00000000000 14217327625 0030136 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/schema/src/main/java/org/opentest4j/reporting/schema/Namespace.java 0000664 0000000 0000000 00000004765 14217327625 0032711 0 ustar 00root root 0000000 0000000 /*
* 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.java 0000664 0000000 0000000 00000003612 14217327625 0033430 0 ustar 00root root 0000000 0000000 open-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/ 0000775 0000000 0000000 00000000000 14217327625 0023070 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/schema/src/main/resources/org/ 0000775 0000000 0000000 00000000000 14217327625 0023657 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/schema/src/main/resources/org/opentest4j/ 0000775 0000000 0000000 00000000000 14217327625 0025756 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/schema/src/main/resources/org/opentest4j/reporting/ 0000775 0000000 0000000 00000000000 14217327625 0027767 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/schema/src/main/resources/org/opentest4j/reporting/schema/ 0000775 0000000 0000000 00000000000 14217327625 0031227 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/schema/src/main/resources/org/opentest4j/reporting/schema/core.xsd 0000664 0000000 0000000 00000010012 14217327625 0032671 0 ustar 00root root 0000000 0000000
open-test-reporting-r0.1.0-M1/schema/src/main/resources/org/opentest4j/reporting/schema/events.xsd 0000664 0000000 0000000 00000002677 14217327625 0033267 0 ustar 00root root 0000000 0000000
hierarchy.xsd 0000664 0000000 0000000 00000002314 14217327625 0033646 0 ustar 00root root 0000000 0000000 open-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.xsd 0000664 0000000 0000000 00000004463 14217327625 0032677 0 ustar 00root root 0000000 0000000
open-test-reporting-r0.1.0-M1/settings.gradle.kts 0000664 0000000 0000000 00000000472 14217327625 0021726 0 ustar 00root root 0000000 0000000 rootProject.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/ 0000775 0000000 0000000 00000000000 14217327625 0017556 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/tooling/build.gradle.kts 0000664 0000000 0000000 00000000547 14217327625 0022643 0 ustar 00root root 0000000 0000000 plugins {
`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/ 0000775 0000000 0000000 00000000000 14217327625 0020345 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/tooling/src/main/ 0000775 0000000 0000000 00000000000 14217327625 0021271 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/tooling/src/main/java/ 0000775 0000000 0000000 00000000000 14217327625 0022212 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/tooling/src/main/java/org/ 0000775 0000000 0000000 00000000000 14217327625 0023001 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/tooling/src/main/java/org/opentest4j/ 0000775 0000000 0000000 00000000000 14217327625 0025100 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/tooling/src/main/java/org/opentest4j/reporting/ 0000775 0000000 0000000 00000000000 14217327625 0027111 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/tooling/src/main/java/org/opentest4j/reporting/tooling/ 0000775 0000000 0000000 00000000000 14217327625 0030564 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/tooling/src/main/java/org/opentest4j/reporting/tooling/converter/ 0000775 0000000 0000000 00000000000 14217327625 0032573 5 ustar 00root root 0000000 0000000 Converter.java 0000664 0000000 0000000 00000002202 14217327625 0035322 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000022605 14217327625 0036640 0 ustar 00root root 0000000 0000000 open-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/ 0000775 0000000 0000000 00000000000 14217327625 0032551 5 ustar 00root root 0000000 0000000 DefaultValidator.java 0000664 0000000 0000000 00000015533 14217327625 0036576 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000003530 14217327625 0035106 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000001515 14217327625 0035151 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000003716 14217327625 0036743 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000003135 14217327625 0036630 0 ustar 00root root 0000000 0000000 open-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.java 0000664 0000000 0000000 00000001717 14217327625 0035270 0 ustar 00root root 0000000 0000000 open-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/ 0000775 0000000 0000000 00000000000 14217327625 0021324 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/tooling/src/test/java/ 0000775 0000000 0000000 00000000000 14217327625 0022245 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/tooling/src/test/java/org/ 0000775 0000000 0000000 00000000000 14217327625 0023034 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/tooling/src/test/java/org/opentest4j/ 0000775 0000000 0000000 00000000000 14217327625 0025133 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/tooling/src/test/java/org/opentest4j/reporting/ 0000775 0000000 0000000 00000000000 14217327625 0027144 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/tooling/src/test/java/org/opentest4j/reporting/tooling/ 0000775 0000000 0000000 00000000000 14217327625 0030617 5 ustar 00root root 0000000 0000000 open-test-reporting-r0.1.0-M1/tooling/src/test/java/org/opentest4j/reporting/tooling/converter/ 0000775 0000000 0000000 00000000000 14217327625 0032626 5 ustar 00root root 0000000 0000000 DefaultConverterTests.java 0000664 0000000 0000000 00000014754 14217327625 0037724 0 ustar 00root root 0000000 0000000 open-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/ 0000775 0000000 0000000 00000000000 14217327625 0032604 5 ustar 00root root 0000000 0000000 DefaultValidatorTests.java 0000664 0000000 0000000 00000006563 14217327625 0037657 0 ustar 00root root 0000000 0000000 open-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);
}
}
}