Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make DDIExportTest XML validation non-flaky #9618

Merged
merged 1 commit into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,25 @@
import java.time.ZoneId;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonReader;
import javax.xml.transform.Source;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.xml.sax.SAXException;
import org.xmlunit.assertj3.XmlAssert;
import org.xmlunit.builder.Input;

public class DDIExporterTest {

Expand Down Expand Up @@ -88,7 +95,7 @@ public void testExportDataset() throws JsonParseException, IOException, ExportEx
// then
String xml = XmlPrinter.prettyPrintXml(byteArrayOutputStream.toString(StandardCharsets.UTF_8));
logger.fine(xml);
XmlAssert.assertThat(xml).isValid();
XmlAssert.assertThat(xml).isValidAgainst(Input.fromPath(Path.of("src/test/resources/xml/xsd/ddi-codebook-2.5/ddi_codebook_2_5.xsd")).build());
logger.severe("DDIExporterTest.testExportDataset() creates XML that should now be valid, since DDIExportUtil has been fixed.");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3.org/1999/xhtml"
xmlns="http://www.w3.org/1999/xhtml">

<xs:annotation>
<xs:documentation>
This is the XML Schema common attributes module for XHTML
$Id$
</xs:documentation>
<xs:documentation source="xhtml-copyright-1.xsd"/>
<xs:documentation
source="http://www.w3.org/TR/xhtml-modularization/abstract_modules.html#s_commonatts"/>
</xs:annotation>

<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="../xml.xsd">
<xs:annotation>
<xs:documentation>
This import brings in the XML namespace attributes
The module itself does not provide the schemaLocation
and expects the driver schema to provide the
actual SchemaLocation.
</xs:documentation>
</xs:annotation>
</xs:import>

<xs:attributeGroup name="id">
<xs:attribute name="id" type="xs:ID"/>
</xs:attributeGroup>

<xs:attributeGroup name="class">
<xs:attribute name="class" type="xs:NMTOKENS"/>
</xs:attributeGroup>

<xs:attributeGroup name="title">
<xs:attribute name="title" type="xs:string"/>
</xs:attributeGroup>

<xs:attributeGroup name="Core.attrib">
<xs:attributeGroup ref="id"/>
<xs:attributeGroup ref="class"/>
<xs:attributeGroup ref="title"/>
<xs:attributeGroup ref="Core.extra.attrib"/>
</xs:attributeGroup>

<xs:attributeGroup name="I18n.attrib">
<xs:attribute ref="xml:lang"/>
<xs:attributeGroup ref="I18n.extra.attrib"/>
</xs:attributeGroup>

<xs:attributeGroup name="Common.attrib">
<xs:attributeGroup ref="Core.attrib"/>
<xs:attributeGroup ref="I18n.attrib"/>
<xs:attributeGroup ref="Common.extra"/>
</xs:attributeGroup>


<!-- Global attributes -->
<xs:attribute name="id" type="xs:ID"/>
<xs:attribute name="class" type="xs:NMTOKENS"/>
<xs:attribute name="title" type="xs:string"/>

<xs:attributeGroup name="Global.core.attrib">
<xs:attribute ref="id"/>
<xs:attribute ref="class"/>
<xs:attribute ref="title"/>
<xs:attributeGroup ref="Global.core.extra.attrib"/>
</xs:attributeGroup>

<xs:attributeGroup name="Global.i18n.attrib">
<xs:attribute ref="xml:lang"/>
<xs:attributeGroup ref="Global.I18n.extra.attrib"/>
</xs:attributeGroup>

<xs:attributeGroup name="Global.common.attrib">
<xs:attributeGroup ref="Global.core.attrib"/>
<xs:attributeGroup ref="Global.i18n.attrib"/>
<xs:attributeGroup ref="Global.Common.extra"/>
</xs:attributeGroup>


</xs:schema>
85 changes: 85 additions & 0 deletions src/test/resources/xml/xsd/ddi-codebook-2.5/XHTML/xhtml-bdo-1.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.w3.org/1999/xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:annotation>
<xs:documentation>
Bidirectional Override (bdo) Element
This is the XML Schema BDO Element module for XHTML

This modules declares the element 'bdo' and 'dir' attributes,
Used to override the Unicode bidirectional algorithm for selected
fragments of text.
Bidirectional text support includes both the bdo element and
the 'dir' attribute.

$Id$
</xs:documentation>
<xs:documentation source="xhtml-copyright-1.xsd"/>
<xs:documentation
source="http://www.w3.org/TR/2001/REC-xhtml-modularization-20010410/abstract_modules.html#s_bdomodule"/>
</xs:annotation>

<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="../xml.xsd">
<xs:annotation>
<xs:documentation>
This import brings in the XML namespace attributes
The module itself does not provide the schemaLocation
and expects the driver schema to provide the
actual SchemaLocation.
</xs:documentation>
</xs:annotation>
</xs:import>

<xs:attributeGroup name="bdo.attlist">
<xs:attribute ref="xml:lang"/>
<xs:attributeGroup ref="Core.attrib"/>
<xs:attribute name="dir" use="required">
<xs:simpleType>
<xs:restriction base="xs:NMTOKEN">
<xs:enumeration value="ltr"/>
<xs:enumeration value="rtl"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:attributeGroup>

<xs:group name="bdo.content">
<xs:sequence>
<xs:group ref="Inline.mix" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:group>

<xs:complexType name="bdo.type" mixed="true">
<xs:group ref="bdo.content"/>
<xs:attributeGroup ref="bdo.attlist"/>
</xs:complexType>

<xs:element name="bdo" type="bdo.type"/>

<xs:attributeGroup name="dir.attrib">
<xs:attribute name="dir">
<xs:simpleType>
<xs:restriction base="xs:NMTOKEN">
<xs:enumeration value="ltr"/>
<xs:enumeration value="rtl"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:attributeGroup>

<!-- Global dir attribute -->
<xs:attribute name="dir">
<xs:simpleType>
<xs:restriction base="xs:NMTOKEN">
<xs:enumeration value="ltr"/>
<xs:enumeration value="rtl"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>

<xs:attributeGroup name="Global.bdo.attrib">
<xs:attribute ref="dir"/>
</xs:attributeGroup>

</xs:schema>