Author: tilman Date: Fri Jan 23 08:05:08 2015 New Revision: 1654133 URL: http://svn.apache.org/r1654133 Log: PDFBOX-2621: created test for CreatePDFA that uses preflight to check for PDF/A-1b validity
Added: pdfbox/branches/1.8/examples/src/test/ pdfbox/branches/1.8/examples/src/test/java/ pdfbox/branches/1.8/examples/src/test/java/org/ pdfbox/branches/1.8/examples/src/test/java/org/apache/ pdfbox/branches/1.8/examples/src/test/java/org/apache/pdfbox/ pdfbox/branches/1.8/examples/src/test/java/org/apache/pdfbox/examples/ pdfbox/branches/1.8/examples/src/test/java/org/apache/pdfbox/examples/pdfa/ pdfbox/branches/1.8/examples/src/test/java/org/apache/pdfbox/examples/pdfa/CreatePDFATest.java (with props) Modified: pdfbox/branches/1.8/examples/pom.xml Modified: pdfbox/branches/1.8/examples/pom.xml URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/examples/pom.xml?rev=1654133&r1=1654132&r2=1654133&view=diff ============================================================================== --- pdfbox/branches/1.8/examples/pom.xml (original) +++ pdfbox/branches/1.8/examples/pom.xml Fri Jan 23 08:05:08 2015 @@ -49,11 +49,22 @@ <version>${project.version}</version> </dependency> <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>preflight</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> <groupId>org.bouncycastle</groupId> <artifactId>bcmail-jdk15</artifactId> <version>1.44</version> <optional>true</optional> </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + <scope>test</scope> + </dependency> </dependencies> <build> Added: pdfbox/branches/1.8/examples/src/test/java/org/apache/pdfbox/examples/pdfa/CreatePDFATest.java URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/examples/src/test/java/org/apache/pdfbox/examples/pdfa/CreatePDFATest.java?rev=1654133&view=auto ============================================================================== --- pdfbox/branches/1.8/examples/src/test/java/org/apache/pdfbox/examples/pdfa/CreatePDFATest.java (added) +++ pdfbox/branches/1.8/examples/src/test/java/org/apache/pdfbox/examples/pdfa/CreatePDFATest.java Fri Jan 23 08:05:08 2015 @@ -0,0 +1,66 @@ +/* + * Copyright 2015 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.pdfbox.examples.pdfa; + +import junit.framework.TestCase; + +import java.io.File; +import org.apache.pdfbox.preflight.PreflightDocument; +import org.apache.pdfbox.preflight.ValidationResult; +import org.apache.pdfbox.preflight.ValidationResult.ValidationError; +import org.apache.pdfbox.preflight.parser.PreflightParser; + +/** + * + * @author Tilman Hausherr + */ +public class CreatePDFATest extends TestCase +{ + private final String outDir = "target/test-output/"; + + @Override + protected void setUp() throws Exception + { + super.setUp(); + new File(outDir).mkdirs(); + } + + /** + * Test of doIt method of class CreatePDFA. + */ + public void testCreatePDFA() throws Exception + { + System.out.println("testCreatePDFA"); + String pdfaFilename = outDir + "/PDFA.pdf"; + String message = "The quick brown fox jumps over the lazy dog äöüÄÖÜß @°^²³ {[]}"; + CreatePDFA instance = new CreatePDFA(); + instance.doIt(pdfaFilename, message); + + PreflightParser preflightParser = new PreflightParser(new File(pdfaFilename)); + preflightParser.parse(); + PreflightDocument preflightDocument = preflightParser.getPreflightDocument(); + preflightDocument.validate(); + ValidationResult result = preflightDocument.getResult(); + for (ValidationError ve : result.getErrorsList()) + { + System.err.println(ve.getErrorCode() + ": " + ve.getDetails()); + } + assertTrue("PDF file created with CreatePDFA is not valid PDF/A-1b", result.isValid()); + preflightDocument.close(); + preflightParser.clearResources(); + } + +} Propchange: pdfbox/branches/1.8/examples/src/test/java/org/apache/pdfbox/examples/pdfa/CreatePDFATest.java ------------------------------------------------------------------------------ svn:eol-style = native