You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ja...@apache.org on 2014/10/09 09:18:26 UTC
svn commit: r1630304 - in /pdfbox/trunk/preflight: ./
src/main/java/org/apache/pdfbox/preflight/
src/main/java/org/apache/pdfbox/preflight/process/
src/test/java/org/apache/pdfbox/preflight/
Author: jahewson
Date: Thu Oct 9 07:18:26 2014
New Revision: 1630304
URL: http://svn.apache.org/r1630304
Log:
PDFBOX-2299: Clean up Isartor tests and enable by default
Modified:
pdfbox/trunk/preflight/pom.xml
pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightDocument.java
pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/PageTreeValidationProcess.java
pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartor.java
Modified: pdfbox/trunk/preflight/pom.xml
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/pom.xml?rev=1630304&r1=1630303&r2=1630304&view=diff
==============================================================================
--- pdfbox/trunk/preflight/pom.xml (original)
+++ pdfbox/trunk/preflight/pom.xml Thu Oct 9 07:18:26 2014
@@ -23,11 +23,6 @@
<packaging>bundle</packaging>
- <properties>
- <skip.external.resources>true</skip.external.resources>
- </properties>
-
-
<parent>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox-parent</artifactId>
@@ -55,7 +50,7 @@
<excludes>
<exclude>**/integration/**</exclude>
</excludes>
- <argLine>-Xmx768m</argLine>
+ <argLine>-Xmx768m</argLine>
</configuration>
</execution>
<execution>
@@ -162,13 +157,11 @@
<url>http://www.pdfa.org/wp-content/uploads/2011/08/isartor-pdfa-2008-08-13.zip</url>
<unpack>true</unpack>
<outputDirectory>${project.build.directory}/pdfs</outputDirectory>
- <!--<md5></md5>-->
- <skip>${skip.external.resources}</skip>
+ <md5>9f129c834bc6f9f8dabad4491c4c10ec</md5>
</configuration>
</execution>
</executions>
</plugin>
-
</plugins>
</build>
Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightDocument.java?rev=1630304&r1=1630303&r2=1630304&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightDocument.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/PreflightDocument.java Thu Oct 9 07:18:26 2014
@@ -165,7 +165,7 @@ public class PreflightDocument extends P
Collection<String> processes = config.getProcessNames();
for (String name : processes)
{
- ContextHelper.validateElement(context, name);
+ ContextHelper.validateElement(context, name);
}
}
Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/PageTreeValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/PageTreeValidationProcess.java?rev=1630304&r1=1630303&r2=1630304&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/PageTreeValidationProcess.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/PageTreeValidationProcess.java Thu Oct 9 07:18:26 2014
@@ -24,8 +24,6 @@ package org.apache.pdfbox.preflight.proc
import static org.apache.pdfbox.preflight.PreflightConfiguration.PAGE_PROCESS;
import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_NOCATALOG;
-import java.util.List;
-
import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.preflight.PreflightContext;
@@ -41,10 +39,10 @@ public class PageTreeValidationProcess e
PDDocumentCatalog catalog = context.getDocument().getDocumentCatalog();
if (catalog != null)
{
- List<?> pages = catalog.getAllPages();
- for (int i = 0; i < pages.size(); ++i)
+ int numPages = context.getDocument().getNumberOfPages();
+ for (int i = 0; i < numPages; i++)
{
- validatePage(context, (PDPage) pages.get(i));
+ validatePage(context, context.getDocument().getPage(i));
}
}
else
Modified: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartor.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartor.java?rev=1630304&r1=1630303&r2=1630304&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartor.java (original)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartor.java Thu Oct 9 07:18:26 2014
@@ -36,8 +36,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
import org.apache.pdfbox.preflight.exception.SyntaxValidationException;
-import org.apache.pdfbox.preflight.exception.ValidationException;
import org.apache.pdfbox.preflight.parser.PreflightParser;
+import org.apache.pdfbox.preflight.utils.ByteArrayDataSource;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -52,27 +52,50 @@ import static org.junit.Assert.fail;
@RunWith(Parameterized.class)
public class TestIsartor
{
+ private static final String FILTER_FILE = "isartor.filter";
+ private static FileOutputStream isartorResultFile;
+ private static final Log logger = LogFactory.getLog(TestIsartor.class);
- public static final String FILTER_FILE = "isartor.filter";
-
- protected static FileOutputStream isartorResultFile = null;
-
- protected String expectedError;
+ @Parameters(name = "{0}")
+ public static Collection<Object[]> initializeParameters() throws Exception
+ {
+ String filter = System.getProperty(FILTER_FILE);
- protected File path;
+ // load expected errors
+ File f = new File("src/test/resources/expected_errors.txt");
+ InputStream expected = new FileInputStream(f);
+ Properties props = new Properties();
+ props.load(expected);
+ IOUtils.closeQuietly(expected);
- protected static final Log logger = LogFactory.getLog(TestIsartor.class);
+ // prepare config
+ List<Object[]> data = new ArrayList<Object[]>();
- public TestIsartor(File path, String error)
- {
- this.path = path;
- this.expectedError = error;
+ File isartor = new File("target/pdfs/Isartor testsuite/PDFA-1b");
+ if (isartor.isDirectory())
+ {
+ Collection<?> pdfFiles = FileUtils.listFiles(isartor, new String[] {"pdf","PDF"}, true);
+ for (Object pdfFile : pdfFiles)
+ {
+ String fn = ((File)pdfFile).getName();
+ if (filter == null || fn.contains(filter))
+ {
+ String path = props.getProperty(fn);
+ String error = new StringTokenizer(path, "//").nextToken().trim();
+ data.add(new Object[] { (File)pdfFile, error });
+ }
+ }
+ }
+ else
+ {
+ fail("Isartor data set has not been downloaded! Try running Maven?");
+ }
+ return data;
}
@BeforeClass
public static void beforeClass() throws Exception
{
-
String irp = System.getProperty("isartor.results.path");
if (irp != null)
{
@@ -102,30 +125,46 @@ public class TestIsartor
}
}
+ private final String expectedError;
+ private final File file;
+
+ public TestIsartor(File path, String error)
+ {
+ System.out.println(" " + path.getName());
+ this.file = path;
+ this.expectedError = error;
+ }
+
@Test()
public void validate() throws Exception
{
PreflightDocument document = null;
try
{
- InputStream input = new FileInputStream(path);
-
- ValidationResult result = null;
+ InputStream input = new FileInputStream(file);
+ ValidationResult result;
try
{
- PreflightParser parser = new PreflightParser(new org.apache.pdfbox.preflight.utils.ByteArrayDataSource(
- input));
+ PreflightParser parser = new PreflightParser(new ByteArrayDataSource(input));
parser.parse();
document = (PreflightDocument) parser.getPDDocument();
- document.validate();
+ // to speeds up tests, skip validation of page count is over the limit
+ if (document.getNumberOfPages() < 8191)
+ {
+ document.validate();
+ }
result = document.getResult();
}
catch (SyntaxValidationException e)
{
result = e.getResult();
}
- assertFalse(path.getName() + " : Isartor file should be invalid (expected " + this.expectedError + ")", result.isValid());
- assertTrue(path.getName() + " : Should find at least one error", result.getErrorsList().size() > 0);
+
+ assertFalse(file.getName() + " : Isartor file should be invalid (expected " +
+ this.expectedError + ")", result.isValid());
+
+ assertTrue(file.getName() + " : Should find at least one error",
+ result.getErrorsList().size() > 0);
// could contain more than one error
boolean found = false;
@@ -141,8 +180,8 @@ public class TestIsartor
}
if (isartorResultFile != null)
{
- String log = path.getName().replace(".pdf", "") + "#" + error.getErrorCode() + "#" + error.getDetails()
- + "\n";
+ String log = file.getName().replace(".pdf", "") + "#" + error.getErrorCode() +
+ "#" + error.getDetails() + "\n";
isartorResultFile.write(log.getBytes());
}
}
@@ -157,61 +196,27 @@ public class TestIsartor
message.append(error.getErrorCode()).append(" ");
}
fail(String.format("%s : Invalid error code returned. Expected %s, found [%s]",
- path.getName(),
- expectedError,
- message.toString().trim()
- ));
-
+ file.getName(), expectedError, message.toString().trim()));
}
// if one of the error code of the list is the expected one, we consider test valid
}
else
{
- assertEquals(path.getName() + " : Invalid error code returned.", this.expectedError, result
- .getErrorsList().get(0).getErrorCode());
+ assertEquals(file.getName() + " : Invalid error code returned.", this.expectedError,
+ result.getErrorsList().get(0).getErrorCode());
}
}
- catch (Exception e) {
- fail(String.format("%s : %s raised , message=%s",
- path.getName(),
- e.getClass().getSimpleName()
- , e.getMessage()
- ));
+ catch (Exception e)
+ {
+ fail(String.format("%s : %s raised , message=%s", file.getName(),
+ e.getClass().getSimpleName(), e.getMessage()));
}
finally
{
if (document != null)
+ {
document.close();
- }
- }
-
- @Parameters(name = "{0}")
- public static Collection<Object[]> initializeParameters() throws Exception
- {
- String filter = System.getProperty(FILTER_FILE);
- // load expected errors
- File f = new File("src/test/resources/expected_errors.txt");
- InputStream expected = new FileInputStream(f);
- Properties props = new Properties();
- props.load(expected);
- IOUtils.closeQuietly(expected);
- // prepare config
- List<Object[]> data = new ArrayList<Object[]>();
-
- File isartor = new File("target/pdfs/Isartor testsuite/PDFA-1b");
- if (isartor.isDirectory()) {
- Collection<?> pdfFiles = FileUtils.listFiles(isartor,new String[] {"pdf","PDF"},true);
- for (Object pdfFile : pdfFiles) {
- String fn = ((File)pdfFile).getName();
- if (filter==null || (filter!=null && fn.contains(filter))) {
- String error = new StringTokenizer(props.getProperty(fn), "//").nextToken().trim();
- Object[] tmp = new Object[]{(File) pdfFile, error};
- data.add(tmp);
- }
}
- } else {
- logger.warn("Isartor data set not present, skipping Isartor validation");
}
- return data;
}
}