You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by gb...@apache.org on 2011/08/31 10:00:43 UTC
svn commit: r1163518 - in /pdfbox/trunk/preflight: ./
src/test/java/org/apache/padaf/integration/
Author: gbailleul
Date: Wed Aug 31 08:00:42 2011
New Revision: 1163518
URL: http://svn.apache.org/viewvc?rev=1163518&view=rev
Log:
PDFBOX-1105 : adding integration tests add pom cleaning
Added:
pdfbox/trunk/preflight/src/test/java/org/apache/padaf/integration/
pdfbox/trunk/preflight/src/test/java/org/apache/padaf/integration/AbstractInvalidFileTester.java (with props)
pdfbox/trunk/preflight/src/test/java/org/apache/padaf/integration/TestInvalidFiles.java (with props)
pdfbox/trunk/preflight/src/test/java/org/apache/padaf/integration/TestIsartorValidation.java (with props)
pdfbox/trunk/preflight/src/test/java/org/apache/padaf/integration/TestValidFiles.java (with props)
Modified:
pdfbox/trunk/preflight/pom.xml
Modified: pdfbox/trunk/preflight/pom.xml
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/pom.xml?rev=1163518&r1=1163517&r2=1163518&view=diff
==============================================================================
--- pdfbox/trunk/preflight/pom.xml (original)
+++ pdfbox/trunk/preflight/pom.xml Wed Aug 31 08:00:42 2011
@@ -39,9 +39,6 @@
<properties>
<compileSource>1.5</compileSource>
- <javacPath>${user.javac5}</javacPath>
- <pdfa.valid>${user.pdfa.valid}</pdfa.valid>
- <pdfa.invalid>${user.pdfa.invalid}</pdfa.invalid>
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
</properties>
@@ -57,6 +54,62 @@
</resources>
<plugins>
<plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.9</version>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ <executions>
+ <execution>
+ <id>surefire-test</id>
+ <phase>test</phase>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <skip>false</skip>
+ <excludes>
+ <exclude>**/integration/**</exclude>
+ </excludes>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.9</version>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ <executions>
+ <execution>
+ <id>surefire-itest</id>
+ <phase>integration-test</phase>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <skip>${skipITs}</skip>
+ <includes>
+ <include>**/integration/*</include>
+ </includes>
+ <systemPropertyVariables>
+ <isartor.files>${isartor.files}</isartor.files>
+ <isartor.errors>${isartor.errors}</isartor.errors>
+ <invalid.files>${invalid.files}</invalid.files>
+ <invalid.errors>${invalid.errors}</invalid.errors>
+ <valid.files>${valid.files}</valid.files>
+ </systemPropertyVariables>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+
+ <plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.0.0</version>
Added: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/integration/AbstractInvalidFileTester.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/padaf/integration/AbstractInvalidFileTester.java?rev=1163518&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/padaf/integration/AbstractInvalidFileTester.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/padaf/integration/AbstractInvalidFileTester.java Wed Aug 31 08:00:42 2011
@@ -0,0 +1,164 @@
+package org.apache.padaf.integration;
+/*****************************************************************************
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+
+import javax.activation.FileDataSource;
+
+import junit.framework.Assert;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.log4j.Logger;
+import org.apache.padaf.preflight.PdfAValidator;
+import org.apache.padaf.preflight.PdfAValidatorFactory;
+import org.apache.padaf.preflight.ValidationException;
+import org.apache.padaf.preflight.ValidationResult;
+import org.apache.padaf.preflight.ValidationResult.ValidationError;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public abstract class AbstractInvalidFileTester {
+
+ /**
+ * where result information are pushed
+ */
+ protected OutputStream outputResult = null;
+
+ /**
+ * The instance of validator
+ */
+ protected PdfAValidator validator = null;
+
+ /**
+ * carry the expected error with the current test
+ */
+ protected final String expectedError;
+
+ /**
+ * carry the path of the file validated during current test
+ */
+ protected File path;
+
+ protected static Logger staticLogger = Logger.getLogger("Test");
+
+ protected Logger logger = null;
+
+ /**
+ * Prepare the test for one file
+ *
+ * @param path pdf/a file to test
+ * @param error expected error for this test
+ * @throws ValidationException
+ */
+ public AbstractInvalidFileTester(File path, String error) throws ValidationException {
+ this.path = path;
+ this.expectedError = error;
+ this.logger = Logger.getLogger(this.getClass());
+ PdfAValidatorFactory factory = new PdfAValidatorFactory();
+ validator = factory.createValidatorInstance(PdfAValidatorFactory.PDF_A_1_b);
+ }
+
+
+ @Test()
+ public final void validate() throws Exception {
+ if (path==null) {
+ logger.warn("This is an empty test");
+ return;
+ }
+ ValidationResult result = null;
+ try {
+ FileDataSource bds = new FileDataSource(path);
+ result = validator.validate(bds);
+ 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;
+ if (this.expectedError!=null) {
+ for (ValidationError error : result.getErrorsList()) {
+ if (error.getErrorCode().equals(this.expectedError)) {
+ found = true;
+ }
+ if (outputResult != null) {
+ String log = path.getName().replace(".pdf", "") + "#"
+ +error.getErrorCode()+"#"+error.getDetails()+"\n";
+ outputResult.write(log.getBytes());
+ }
+ }
+ }
+
+ if (result.getErrorsList().size() > 0) {
+ if (this.expectedError == null) {
+ logger.info("File invalid as expected (no expected code) :"+this.path.getAbsolutePath());
+ } else 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 (result!=null) {
+ result.closePdf();
+ }
+ }
+ }
+
+ protected abstract String getResultFileKey();
+
+ @Before
+ public void before() throws Exception {
+ String irp = System.getProperty(getResultFileKey());
+
+ if (irp==null) {
+ // no log file defined, use system.err
+ outputResult = System.err;
+ } else {
+ outputResult = new FileOutputStream(irp);
+ }
+ }
+
+ @After
+ public void after() throws Exception {
+ IOUtils.closeQuietly(outputResult);
+ }
+
+}
+
Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/integration/AbstractInvalidFileTester.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/integration/TestInvalidFiles.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/padaf/integration/TestInvalidFiles.java?rev=1163518&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/padaf/integration/TestInvalidFiles.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/padaf/integration/TestInvalidFiles.java Wed Aug 31 08:00:42 2011
@@ -0,0 +1,116 @@
+package org.apache.padaf.integration;
+/*****************************************************************************
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.log4j.Logger;
+import org.apache.padaf.preflight.ValidationException;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class TestInvalidFiles extends AbstractInvalidFileTester {
+
+ private static final String RESULTS_FILE = "results.file";
+
+ private static final String EXPECTED_ERRORS = "invalid.errors";
+
+ private static final String ISARTOR_FILES = "invalid.files";
+
+ protected static Logger staticLogger = Logger.getLogger("Test");
+
+ public TestInvalidFiles(File path, String error) throws ValidationException {
+ super(path,error);
+ }
+
+
+ protected static Collection<Object[]> stopIfExpected () throws Exception {
+ List<Object[]> ret = new ArrayList<Object[]>();
+ ret.add(new Object[]{null,null});
+ return ret;
+ }
+
+ @Parameters
+ public static Collection<Object[]> initializeParameters() throws Exception
+ {
+ // find isartor files
+ String isartor = System.getProperty(ISARTOR_FILES);
+ if (isartor==null) {
+ staticLogger.warn(ISARTOR_FILES+" (where are isartor pdf files) is not defined.");
+ return stopIfExpected();
+ }
+ File root = new File(isartor);
+ // load expected errors
+ Properties props = new Properties();
+ String expectedPath = System.getProperty(EXPECTED_ERRORS);
+ if (expectedPath==null) {
+ staticLogger.warn(EXPECTED_ERRORS+" not defined, only check if file is invalid");
+ } else {
+ File expectedFile = new File(expectedPath);
+ if (!expectedFile.exists() || !expectedFile.isFile()) {
+ staticLogger.warn("'expected.errors' does not reference valid file, so cannot execute tests : "+expectedFile.getAbsolutePath());
+ return stopIfExpected();
+ }
+ InputStream expected = new FileInputStream(expectedPath);
+ props.load(expected);
+ IOUtils.closeQuietly(expected);
+ }
+ // prepare config
+ List<Object[]> data = new ArrayList<Object[]>();
+ Collection<?> files= FileUtils.listFiles(root, new String [] {"pdf"}, true);
+
+ for (Object object : files) {
+ File file = (File)object;
+ String fn = file.getName();
+ if (props.getProperty(fn)!=null) {
+ String error = new StringTokenizer(props.getProperty(fn), "//").nextToken().trim();
+ Object[] tmp = new Object[] { file, error };
+ data.add(tmp);
+ } else {
+ // no expected error
+ Object[] tmp = new Object[] { file, null };
+ data.add(tmp);
+ }
+
+ }
+ return data;
+ }
+
+
+ @Override
+ protected String getResultFileKey() {
+ return RESULTS_FILE;
+ }
+
+}
+
Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/integration/TestInvalidFiles.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/integration/TestIsartorValidation.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/padaf/integration/TestIsartorValidation.java?rev=1163518&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/padaf/integration/TestIsartorValidation.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/padaf/integration/TestIsartorValidation.java Wed Aug 31 08:00:42 2011
@@ -0,0 +1,114 @@
+package org.apache.padaf.integration;
+/*****************************************************************************
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.log4j.Logger;
+import org.apache.padaf.preflight.ValidationException;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class TestIsartorValidation extends AbstractInvalidFileTester {
+
+ private static final String RESULTS_FILE = "results.file";
+
+ private static final String EXPECTED_ERRORS = "isartor.errors";
+
+ private static final String ISARTOR_FILES = "isartor.files";
+
+ protected static Logger staticLogger = Logger.getLogger("Test");
+
+
+ public TestIsartorValidation(File path, String error) throws ValidationException {
+ super(path,error);
+ }
+
+
+ protected static Collection<Object[]> stopIfExpected () throws Exception {
+ List<Object[]> ret = new ArrayList<Object[]>();
+ ret.add(new Object[]{null,null});
+ return ret;
+ }
+
+ @Parameters
+ public static Collection<Object[]> initializeParameters() throws Exception
+ {
+ // find isartor files
+ String isartor = System.getProperty(ISARTOR_FILES);
+ if (isartor==null) {
+ staticLogger.warn(ISARTOR_FILES+" (where are isartor pdf files) is not defined.");
+ return stopIfExpected();
+ }
+ File root = new File(isartor);
+ // load expected errors
+ String expectedPath = System.getProperty(EXPECTED_ERRORS);
+ if (expectedPath==null) {
+ staticLogger.warn("'expected.errors' not defined, so cannot execute tests");
+ return stopIfExpected();
+ }
+ File expectedFile = new File(expectedPath);
+ if (!expectedFile.exists() || !expectedFile.isFile()) {
+ staticLogger.warn("'expected.errors' does not reference valid file, so cannot execute tests : "+expectedFile.getAbsolutePath());
+ return stopIfExpected();
+ }
+ InputStream expected = new FileInputStream(expectedPath);
+ Properties props = new Properties();
+ props.load(expected);
+ IOUtils.closeQuietly(expected);
+ // prepare config
+ List<Object[]> data = new ArrayList<Object[]>();
+ Collection<?> files= FileUtils.listFiles(root, new String [] {"pdf"}, true);
+
+ for (Object object : files) {
+ File file = (File)object;
+ String fn = file.getName();
+ if (props.getProperty(fn)!=null) {
+ String error = new StringTokenizer(props.getProperty(fn), "//").nextToken().trim();
+ Object[] tmp = new Object[] { file, error };
+ data.add(tmp);
+ } else {
+ System.err.println("No expected result for this file, will not try to validate : "+file.getAbsolutePath());
+ }
+
+ }
+ return data;
+ }
+
+ @Override
+ protected String getResultFileKey() {
+ return RESULTS_FILE;
+ }
+
+}
+
Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/integration/TestIsartorValidation.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/integration/TestValidFiles.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/padaf/integration/TestValidFiles.java?rev=1163518&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/padaf/integration/TestValidFiles.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/padaf/integration/TestValidFiles.java Wed Aug 31 08:00:42 2011
@@ -0,0 +1,152 @@
+package org.apache.padaf.integration;
+/*****************************************************************************
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.activation.FileDataSource;
+
+import junit.framework.Assert;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.log4j.Logger;
+import org.apache.padaf.preflight.PdfAValidator;
+import org.apache.padaf.preflight.PdfAValidatorFactory;
+import org.apache.padaf.preflight.ValidationException;
+import org.apache.padaf.preflight.ValidationResult;
+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 TestValidFiles {
+
+ private static final String RESULTS_FILE = "results.file";
+
+ private static final String ISARTOR_FILES = "valid.files";
+
+ protected static OutputStream isartorResultFile = null;
+
+ protected static PdfAValidator validator = null;
+
+ protected File path;
+
+ protected static Logger staticLogger = Logger.getLogger("Test");
+
+ protected Logger logger = null;
+
+
+ public TestValidFiles(File path) {
+ this.path = path;
+ this.logger = Logger.getLogger(path!=null?path.getName():"dummy");
+ }
+
+
+ protected static Collection<Object[]> stopIfExpected () throws Exception {
+ // throw new Exception("Test badly configured");
+ List<Object[]> ret = new ArrayList<Object[]>();
+ ret.add(new Object[]{null});
+ return ret;
+ }
+
+ @Parameters
+ public static Collection<Object[]> initializeParameters() throws Exception
+ {
+ // find isartor files
+ String isartor = System.getProperty(ISARTOR_FILES);
+ if (isartor==null) {
+ staticLogger.warn(ISARTOR_FILES+" (where are isartor pdf files) is not defined.");
+ return stopIfExpected();
+ }
+ File root = new File(isartor);
+ // load expected errors
+ // prepare config
+ List<Object[]> data = new ArrayList<Object[]>();
+ Collection<?> files= FileUtils.listFiles(root, new String [] {"pdf"}, true);
+
+ for (Object object : files) {
+ File file = (File)object;
+ Object[] tmp = new Object[] { file };
+ data.add(tmp);
+ }
+ return data;
+ }
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ PdfAValidatorFactory factory = new PdfAValidatorFactory();
+ validator = factory.createValidatorInstance(PdfAValidatorFactory.PDF_A_1_b);
+
+ String irp = System.getProperty(RESULTS_FILE);
+
+ if (irp==null) {
+ // no log file defined, use system.err
+ System.err.println("No result file defined, will use standart error");
+ isartorResultFile = System.err;
+ } else {
+ isartorResultFile = new FileOutputStream(irp);
+ }
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
+ IOUtils.closeQuietly(isartorResultFile);
+ }
+
+ @Test()
+ public void validate() throws Exception {
+ if (path==null) {
+ logger.warn("This is an empty test");
+ return;
+ }
+ ValidationResult result = null;
+ try {
+ FileDataSource bds = new FileDataSource(path);
+ result = validator.validate(bds);
+ 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
+ if (result.getErrorsList().size() > 0) {
+ Assert.fail("File expected valid : "+path.getAbsolutePath());
+ }
+ } catch (ValidationException e) {
+ throw new Exception(path + " :" + e.getMessage(), e);
+ } finally {
+ if (result!=null) {
+ result.closePdf();
+ }
+ }
+ }
+
+}
+
Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/integration/TestValidFiles.java
------------------------------------------------------------------------------
svn:eol-style = native