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

fix: re[prt the container creation date #1585

Merged
merged 2 commits into from
Dec 29, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,6 @@
<artifactId>json-path-assert</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>xmlunit</groupId>
<artifactId>xmlunit</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
Expand Down
21 changes: 8 additions & 13 deletions src/main/java/com/adobe/epubcheck/ocf/OCFChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,6 @@ private boolean checkContainerFile(OCFCheckerState state)
}
return false;
}
// FIXME 2022 - report container info
// long l = container.getTimeEntry(OCFData.containerEntry);
// if (l > 0)
// {
// Date d = new Date(l);
// String formattedDate = new
// SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(d);
// report.info(OCFData.containerEntry, FeatureEnum.CREATION_DATE,
// formattedDate);
// }

ValidationContext containerFileContext = state.context()
.url(OCFMetaFile.CONTAINER.asURL(container)).mimetype("application/xml").build();
Expand Down Expand Up @@ -559,9 +549,14 @@ private void reportFeatures(OCFResource resource)
{
for (FeatureEnum feature : resource.getProperties().keySet())
{
// report.info(context.path, feature,
// resource.getProperties().get(feature));
report.info(resource.getPath(), feature, resource.getProperties().get(feature));
if (feature == FeatureEnum.CREATION_DATE
&& !OCFMetaFile.CONTAINER.asPath().equals(resource.getPath()))
{
// we only report the creation date once
continue;
}
report.info(resource.getPath(), feature,
resource.getProperties().get(feature));
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/adobe/epubcheck/ocf/OCFZipResources.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
Expand Down Expand Up @@ -48,11 +50,14 @@ public OCFResource next()
throws NoSuchElementException
{
final ZipEntry entry = entries.nextElement();

final Map<FeatureEnum, String> properties = ImmutableMap.<FeatureEnum, String> builder()
.put(FeatureEnum.SIZE, String.valueOf(entry.getSize()))
.put(FeatureEnum.COMPRESSED_SIZE, String.valueOf(entry.getCompressedSize()))
.put(FeatureEnum.COMPRESSION_METHOD, getCompressionMethod(entry))
.put(FeatureEnum.SHA_256, getSHAHash(entry, zip))
.put(FeatureEnum.CREATION_DATE,
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(new Date(entry.getTime())))
.build();

return new OCFResource()
Expand Down Expand Up @@ -87,7 +92,7 @@ public String getPath()
{
return entry.getName();
}

@Override
public String toString()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class JSONReportAssertionSteps
{

private TestReport report;
final private TestReport report;

public JSONReportAssertionSteps(TestConfiguration configuration)
{
Expand Down
115 changes: 115 additions & 0 deletions src/test/java/org/w3c/epubcheck/test/XMLReportAssertionSteps.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package org.w3c.epubcheck.test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.emptyIterable;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.StringReader;
import java.util.function.Supplier;

import javax.xml.transform.stream.StreamSource;

import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import net.sf.saxon.s9api.DocumentBuilder;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.XPathCompiler;
import net.sf.saxon.s9api.XPathSelector;
import net.sf.saxon.s9api.XdmNode;

public class XMLReportAssertionSteps
{

private final TestReport report;
private final Processor processor;
private final XPathCompiler xpathCompiler;
Supplier<XdmNode> xml = new Supplier<XdmNode>()
{
XdmNode xml = null;

@Override
public XdmNode get()
{
if (xml == null)
{

// Parse the XML report
DocumentBuilder docBuilder = processor.newDocumentBuilder();
try
{
xml = docBuilder.build(new StreamSource(new StringReader(report.getOutput())));
} catch (SaxonApiException e)
{
assertThat(e.getMessage(), false);
}
}
return xml;
}
};

public XMLReportAssertionSteps(TestConfiguration configuration)
{
this.report = configuration.getReport();

// Configure Saxon
this.processor = new Processor(false);
processor.getUnderlyingConfiguration()
.setStandardErrorOutput(new PrintStream(new OutputStream()
{
// TODO when upgrading to Java 11, replace by
// OutputStream#nullOutputStream()
@Override
public void write(int b)
throws IOException
{
}
}));
xpathCompiler = processor.newXPathCompiler();
}

@Given("the default namespace is {string}")
public void setDefaultNamespace(String namespace)
{
xpathCompiler.declareNamespace("", namespace);
}

@Then("the XML report is well-formed")
public void xmlIsWellFormed()
{
// Parsing errors would be raised in the constructor already
}

@Then("(the )XPath (value of ){string} is true")
public void xpathIsTrue(String xpath)
throws SaxonApiException
{
assertThat(eval(xpath).effectiveBooleanValue(), is(true));
}

@Then("(the )XPath {string} exists")
public void xpathExists(String xpath)
throws SaxonApiException
{
assertThat(eval(xpath), is(not(emptyIterable())));

}

private XPathSelector eval(String xpath)
{
try
{
XPathSelector result = xpathCompiler.compile(xpath).load();
result.setContextItem(xml.get());
return result;
} catch (SaxonApiException e)
{
throw new IllegalArgumentException(e);
}
}

}
21 changes: 21 additions & 0 deletions src/test/resources/reporting/xml-report.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Feature: EPUBCheck - XML Report tests

Checks the XML (JHove) report format


Background:
Given EPUB test files located at '/reporting/files/'
And the reporting format is set to XML
And EPUBCheck with default settings
Given the default namespace is 'http://schema.openpreservation.org/ois/xml/ns/jhove'

Scenario: Basic well-formedness checks
When checking EPUB 'minimal'
Then the XML report is well-formed
And XPath '//repInfo' exists

Scenario: Creation date is set
When checking EPUB 'minimal'
And XPath '//repInfo/created' exists


Loading