Added:
pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestInvalidDirectory.java
URL:
http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestInvalidDirectory.java?rev=1355309&view=auto
==============================================================================
---
pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestInvalidDirectory.java
(added)
+++
pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestInvalidDirectory.java
Fri Jun 29 10:25:22 2012
@@ -0,0 +1,92 @@
+/*****************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.preflight;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.activation.FileDataSource;
+
+import junit.framework.Assert;
+
+import org.apache.pdfbox.preflight.parser.PreflightParser;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class TestInvalidDirectory {
+
+
+ protected static File directory;
+
+ protected File target = null;
+
+
+ public TestInvalidDirectory (File file) {
+ this.target = file;
+ }
+
+ @Test
+ public void validate () throws Exception {
+ PreflightParser parser = new PreflightParser(new
FileDataSource(target));
+ parser.parse();
+ PreflightDocument document = (PreflightDocument)
parser.getPDDocument();
+ document.validate();
+ Assert.assertFalse(document.getResult().isValid());
+ document.close();
+ }
+
+ @Parameters
+ public static Collection<Object[]> initializeParameters() throws Exception {
+ // check directory
+ File directory = null;
+ String pdfPath = System.getProperty("pdfa.invalid", null);
+ if ("${user.pdfa.invalid}".equals(pdfPath)) {pdfPath=null;}
+ if (pdfPath!=null) {
+ directory = new File(pdfPath);
+ if (!directory.exists()) throw new Exception ("directory does not exists
: "+directory.getAbsolutePath());
+ if (!directory.isDirectory()) throw new Exception ("not a directory :
"+directory.getAbsolutePath());
+ } else {
+ System.err.println("System property 'pdfa.invalid' not defined, will not
run TestValidaDirectory");
+ }
+ // create list
+ if (directory==null) {
+ return new ArrayList<Object[]>(0);
+ } else {
+ File [] files = directory.listFiles();
+ List<Object[]> data = new ArrayList<Object[]>(files.length);
+ for (File file : files) {
+ if (file.isFile()) {
+ data.add(new Object [] {file});
+ }
+ }
+ return data;
+ }
+ }
+
+
+
+}
Propchange:
pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestInvalidDirectory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartorValidationFromClasspath.java
URL:
http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartorValidationFromClasspath.java?rev=1355309&view=auto
==============================================================================
---
pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartorValidationFromClasspath.java
(added)
+++
pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartorValidationFromClasspath.java
Fri Jun 29 10:25:22 2012
@@ -0,0 +1,170 @@
+/*****************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.preflight;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+import junit.framework.Assert;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.pdfbox.preflight.PreflightDocument;
+import org.apache.pdfbox.preflight.ValidationResult;
+import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
+import org.apache.pdfbox.preflight.exception.ValidationException;
+import org.apache.pdfbox.preflight.parser.PreflightParser;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class TestIsartorValidationFromClasspath {
+
+ protected static FileOutputStream isartorResultFile = null;
+
+ protected String expectedError;
+
+ protected String path;
+
+ public TestIsartorValidationFromClasspath(String path, String error) {
+ this.path = path;
+ this.expectedError = error;
+ }
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+
+ String irp = System.getProperty("isartor.results.path");
+ if (irp != null) {
+ File f = new File (irp);
+ if (f.exists() && f.isFile()) {
+ f.delete();
+ isartorResultFile = new FileOutputStream(f);
+ } else if (!f.exists()) {
+ isartorResultFile = new FileOutputStream(f);
+ } else {
+ throw new IllegalArgumentException("Invalid
result file : " + irp);
+ }
+ }
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
+ if (isartorResultFile != null) {
+ IOUtils.closeQuietly(isartorResultFile);
+ }
+ }
+
+ @Test()
+ public void validate() throws Exception {
+ PreflightDocument document = null;
+ try {
+ InputStream input =
this.getClass().getResourceAsStream(path);
+ PreflightParser parser = new PreflightParser(new
org.apache.pdfbox.preflight.utils.ByteArrayDataSource(input));
+ parser.parse();
+ document = (PreflightDocument)parser.getPDDocument();
+ document.validate();
+ ValidationResult result = document.getResult();
+ Assert.assertFalse(path + " : Isartor file should be
invalid (" + path + ")", result.isValid());
+ Assert.assertTrue(path + " : Should find at least one
error", result.getErrorsList().size() > 0);
+ // could contain more than one error
+ boolean found = false;
+ for (ValidationError error : result.getErrorsList()) {
+ if
(error.getErrorCode().equals(this.expectedError)) {
+ found = true;
+ }
+ if (isartorResultFile != null) {
+ String log = path.replace(".pdf", "") +
"#"
+
+error.getErrorCode()+"#"+error.getDetails()+"\n";
+ isartorResultFile.write(log.getBytes());
+ }
+ }
+
+ if (result.getErrorsList().size() > 1) {
+ if (!found) {
+ StringBuilder message = new
StringBuilder(100);
+ message.append(path).append(
+ " : Invalid error code
returned. Expected ");
+
message.append(this.expectedError).append(", found ");
+ for (ValidationError error :
result.getErrorsList()) {
+
message.append(error.getErrorCode()).append(" ");
+ }
+ Assert.fail(message.toString());
+ }
+ } else {
+ Assert.assertEquals(path + " : Invalid error
code returned.",
+ this.expectedError,
+
result.getErrorsList().get(0).getErrorCode());
+ }
+ } catch (ValidationException e) {
+ throw new Exception(path + " :" + e.getMessage(), e);
+ } finally {
+ if (document != null) document.close();
+ }
+ }
+
+ @Parameters
+ public static Collection<Object[]> initializeParameters() throws
Exception
+ {
+ // load expected errors
+ File f = new File("src/test/resources/expected_errors.txt");
+ System.out.println(f.exists());
+ InputStream expected = new FileInputStream(f);
+ Properties props = new Properties();
+ props.load(expected);
+ IOUtils.closeQuietly(expected);
+ // prepare config
+ List<Object[]> data = new ArrayList<Object[]>();
+ InputStream is = Class.class.getResourceAsStream("/Isartor
testsuite.list");
+ if (is != null)
+ {
+ BufferedReader reader = new BufferedReader(new
InputStreamReader(is));
+ String line = reader.readLine();
+ while (line!=null)
+ {
+ String fn = new File(line).getName();
+ String error = new
StringTokenizer(props.getProperty(fn), "//").nextToken().trim();
+ Object[] tmp = new Object[] { "/"+line, error };
+ data.add(tmp);
+ line = reader.readLine();
+ }
+ }
+ else
+ {
+
System.out.println("TestIsartorValidationFromClasspath2.initializeParameters():
No input files found");
+ }
+ return data;
+ }
+}
+
Propchange:
pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestIsartorValidationFromClasspath.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestPreflightPath.java
URL:
http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestPreflightPath.java?rev=1355309&view=auto
==============================================================================
---
pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestPreflightPath.java
(added)
+++
pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestPreflightPath.java
Fri Jun 29 10:25:22 2012
@@ -0,0 +1,89 @@
+/*****************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.preflight;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class TestPreflightPath {
+
+ @Test
+ public void test() {
+ PreflightPath path = new PreflightPath();
+
+ assertTrue(path.isEmpty());
+ assertEquals(0,path.size());
+
+ path.pushObject("a");
+ assertEquals(1,path.size());
+ assertFalse(path.isEmpty());
+
+ int position = path.getClosestTypePosition(String.class);
+ assertEquals(0,position);
+
+ path.pushObject(new Integer(6));
+ assertEquals(2,path.size());
+
+ position = path.getClosestTypePosition(String.class);
+ assertEquals(0,position);
+
+ position = path.getClosestTypePosition(Integer.class);
+ assertEquals(1,position);
+
+ path.pushObject("b");
+ assertEquals(3,path.size());
+
+ position = path.getClosestTypePosition(String.class);
+ assertEquals(2,position);
+ position = path.getClosestTypePosition(Integer.class);
+ assertEquals(1,position);
+
+ Integer i = path.getPathElement(position, Integer.class);
+ assertEquals(new Integer(6), i);
+
+ Object str = path.peek();
+ assertEquals(3,path.size());
+ assertEquals(String.class, str.getClass());
+ assertEquals("b", (String)str);
+
+ str = path.pop();
+ assertEquals(2,path.size());
+ assertEquals(String.class, str.getClass());
+ assertEquals("b", (String)str);
+
+ path.clear();
+ assertTrue(path.isEmpty());
+ assertEquals(0,path.size());
+ }
+
+ @Test
+ public void testPush() {
+ PreflightPath path = new PreflightPath();
+ assertTrue(path.pushObject("a"));
+ assertFalse(path.pushObject(null));
+ }
+
+}
+
Propchange:
pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestPreflightPath.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestValidDirectory.java
URL:
http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestValidDirectory.java?rev=1355309&view=auto
==============================================================================
---
pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestValidDirectory.java
(added)
+++
pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestValidDirectory.java
Fri Jun 29 10:25:22 2012
@@ -0,0 +1,99 @@
+/*****************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.preflight;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.activation.FileDataSource;
+
+import junit.framework.Assert;
+
+import org.apache.padaf.preflight.PdfAValidator;
+import org.apache.padaf.preflight.PdfAValidatorFactory;
+import org.apache.padaf.preflight.ValidationResult;
+import org.apache.pdfbox.preflight.parser.PreflightParser;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class TestValidDirectory {
+
+ protected File target = null;
+
+ public TestValidDirectory (File file) {
+ this.target = file;
+ }
+
+ @Test
+ public void validate () throws Exception {
+ ValidationResult result = null;
+ try {
+ System.out.println(target);
+ PreflightParser parser = new PreflightParser(new
FileDataSource(target));
+ parser.parse();
+ PreflightDocument document = (PreflightDocument)
parser.getPDDocument();
+ document.validate();
+ Assert.assertTrue("Validation of " + target
,document.getResult().isValid());
+ } finally {
+ if (result != null) {
+ result.closePdf();
+ }
+ }
+ }
+
+ @Parameters
+ public static Collection<Object[]> initializeParameters() throws Exception {
+ // check directory
+ File directory = null;
+ String pdfPath = System.getProperty("pdfa.valid", null);
+ if ("${user.pdfa.valid}".equals(pdfPath)) {pdfPath=null;}
+ if (pdfPath!=null) {
+ directory = new File(pdfPath);
+ if (!directory.exists()) throw new Exception ("directory does not exists
: "+directory.getAbsolutePath());
+ if (!directory.isDirectory()) throw new Exception ("not a directory :
"+directory.getAbsolutePath());
+ } else {
+ System.err.println("System property 'pdfa.valid' not defined, will not
run TestValidaDirectory");
+ }
+ // create list
+ if (directory==null) {
+ return new ArrayList<Object[]>(0);
+ } else {
+ File [] files = directory.listFiles();
+ List<Object[]> data = new ArrayList<Object[]>(files.length);
+ for (File file : files) {
+ if (file.isFile()) {
+ data.add(new Object [] {file});
+ }
+ }
+ return data;
+ }
+ }
+
+
+
+}
Propchange:
pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestValidDirectory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/parser/TestPreflightConfiguration.java
URL:
http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/parser/TestPreflightConfiguration.java?rev=1355309&view=auto
==============================================================================
---
pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/parser/TestPreflightConfiguration.java
(added)
+++
pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/parser/TestPreflightConfiguration.java
Fri Jun 29 10:25:22 2012
@@ -0,0 +1,69 @@
+/*****************************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.preflight.parser;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.pdfbox.preflight.PreflightConfiguration;
+import org.apache.pdfbox.preflight.PreflightContext;
+import org.apache.pdfbox.preflight.exception.MissingValidationProcessException;
+import org.apache.pdfbox.preflight.exception.ValidationException;
+import org.apache.pdfbox.preflight.process.ValidationProcess;
+import org.junit.Test;
+
+public class TestPreflightConfiguration {
+
+ @Test(expected=MissingValidationProcessException.class)
+ public void testGetValidationProcess_MissingProcess() throws Exception {
+ PreflightConfiguration configuration =
PreflightConfiguration.createPdfA1BConfiguration();
+ configuration.getInstanceOfProcess("unknownProcess");
+ }
+
+ @Test
+ public void testGetValidationProcess_MissingProcess_NoError() throws
Exception {
+ PreflightConfiguration configuration =
PreflightConfiguration.createPdfA1BConfiguration();
+ configuration.setErrorOnMissingProcess(false);
+ configuration.getInstanceOfProcess("unknownProcess");
+ }
+
+ @Test
+ public void testReplaceValidationProcess() throws Exception {
+ PreflightConfiguration configuration =
PreflightConfiguration.createPdfA1BConfiguration();
+
+ String processName = "mock-process";
+ configuration.replaceProcess(processName, MockProcess.class);
+ assertEquals(MockProcess.class,
configuration.getInstanceOfProcess(processName).getClass());
+
+ configuration.replaceProcess(processName, MockProcess2.class);
+ assertEquals(MockProcess2.class,
configuration.getInstanceOfProcess(processName).getClass());
+ }
+
+ public static class MockProcess implements ValidationProcess {
+ public void validate(PreflightContext ctx) throws
ValidationException {
+ }
+ }
+
+ public static class MockProcess2 extends MockProcess {
+ public void validate(PreflightContext ctx) throws
ValidationException {
+ }
+ }
+}
Propchange:
pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/parser/TestPreflightConfiguration.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: pdfbox/trunk/preflight/src/test/resources/expected_errors.txt
URL:
http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/resources/expected_errors.txt?rev=1355309&r1=1355308&r2=1355309&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/test/resources/expected_errors.txt (original)
+++ pdfbox/trunk/preflight/src/test/resources/expected_errors.txt Fri Jun 29
10:25:22 2012
@@ -111,7 +111,7 @@ isartor-6-3-4-t01-fail-c.pdf=3.1.3
isartor-6-3-4-t01-fail-d.pdf=3.1.3
isartor-6-3-4-t01-fail-e.pdf=3.1.3
isartor-6-3-4-t01-fail-f.pdf=3.1.3
-isartor-6-3-4-t01-fail-g.pdf=3.1.3 // -- Type3 invalide parce qu'il
référence une police Type1 non embarquée. ==> L'erreur retournée concerne
le Type1 et non le Type3
+isartor-6-3-4-t01-fail-g.pdf=3.2.4 // Type3 Damage because the Type1 used as
Resource isn't embedded
isartor-6-3-4-t01-fail-h.pdf=3.1.3
isartor-6-3-5-t01-fail-a.pdf=3.3.1
isartor-6-3-5-t01-fail-b.pdf=3.3.1
@@ -125,7 +125,7 @@ isartor-6-3-6-t01-fail-c.pdf=3.1.6
isartor-6-3-7-t01-fail-a.pdf=3.1.5
isartor-6-3-7-t02-fail-a.pdf=3.1.5
isartor-6-3-7-t03-fail-a.pdf=3.1.5
-isartor-6-4-t01-fail-a.pdf=2.2.1 // -- Il y a un XObj contenant S=Transparency
+isartor-6-4-t01-fail-a.pdf=4.1.1
isartor-6-4-t01-fail-b.pdf=2.2.2
isartor-6-4-t02-fail-a.pdf=2.2.1
isartor-6-4-t03-fail-a.pdf=4.1.3