You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2011/07/24 16:02:33 UTC
svn commit: r1150373 [11/12] - in /pdfbox/trunk/preflight: ./ src/ src/main/
src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/padaf/ src/main/java/org/apache/padaf/preflight/
src/main/java/org/apache/padaf/preflight/...
Added: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/IsartorTargetFileInformation.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/IsartorTargetFileInformation.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/IsartorTargetFileInformation.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/IsartorTargetFileInformation.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,96 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight;
+
+import java.io.File;
+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.log4j.Logger;
+
+public class IsartorTargetFileInformation {
+
+ protected File targetFile = null;
+
+ protected String expectedError = null;
+
+ public IsartorTargetFileInformation(File targetFile, String expectedError) {
+ this.targetFile = targetFile;
+ this.expectedError = expectedError;
+ }
+
+ public File getTargetFile() {
+ return targetFile;
+ }
+
+ public String getExpectedError() {
+ return expectedError;
+ }
+
+ public static List<IsartorTargetFileInformation> loadConfiguration(File root)
+ throws Exception {
+ // load config
+ InputStream expected = IsartorTargetFileInformation.class
+ .getResourceAsStream("/expected_errors.txt");
+ Properties props = new Properties();
+ props.load(expected);
+ // list files
+ List<IsartorTargetFileInformation> result = new ArrayList<IsartorTargetFileInformation>();
+ if (root.isDirectory()) {
+ Collection<?> col = FileUtils.listFiles(root, new String[] { "pdf" },
+ true);
+ for (Object o : col) {
+ File file = (File) o;
+ IsartorTargetFileInformation info = getInformation(file, props);
+ if (info == null) {
+ continue;
+ }
+ result.add(info);
+ }
+ } else if (root.isFile()) {
+ result.add(getInformation(root, props));
+ }
+ return result;
+ }
+
+ protected static IsartorTargetFileInformation getInformation(File file,
+ Properties props) {
+ Logger logger = Logger.getLogger("test.isartor");
+ String key = file.getName();
+ String line = props.getProperty(key);
+ if (line != null) {
+ // only one parameter for the moment
+ String error = new StringTokenizer(line, "//").nextToken().trim();
+ return new IsartorTargetFileInformation(file, error);
+ } else {
+ logger.error("There is no expected error for " + key);
+ return null;
+ }
+
+ }
+
+}
Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/IsartorTargetFileInformation.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/RetrieveMissingStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/RetrieveMissingStream.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/RetrieveMissingStream.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/RetrieveMissingStream.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,68 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight;
+
+import java.io.FileInputStream;
+import java.util.HashSet;
+import java.util.List;
+
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.cos.COSObject;
+import org.apache.pdfbox.cos.COSStream;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
+import org.apache.pdfbox.pdmodel.PDPage;
+import org.apache.pdfbox.pdmodel.common.PDStream;
+import org.apache.pdfbox.persistence.util.COSObjectKey;
+
+public class RetrieveMissingStream {
+ public static void main(String[] args) throws Exception {
+ if (args.length != 1) {
+ System.err.println("usage : RetrieveMissingStream file");
+ System.exit(233);
+ }
+
+ HashSet<COSObjectKey> listOfKeys = new HashSet<COSObjectKey>();
+
+ PDDocument document = PDDocument.load(new FileInputStream(args[0]));
+ List<COSObject> lCosObj = document.getDocument().getObjects();
+ for (COSObject cosObject : lCosObj) {
+
+ if (cosObject.getObject() instanceof COSStream) {
+ listOfKeys.add(new COSObjectKey(cosObject.getObjectNumber().intValue(),
+ cosObject.getGenerationNumber().intValue()));
+ }
+
+ }
+
+ PDDocumentCatalog catalog = document.getDocumentCatalog();
+ List<?> pages = catalog.getAllPages();
+ for (int i = 0; i < pages.size(); ++i) {
+ PDPage pdp = (PDPage) pages.get(i);
+ PDStream pdStream = pdp.getContents();
+
+ COSBase b = pdp.getCOSDictionary().getItem(COSName.getPDFName("Contents"));
+ System.out.println();
+ }
+ }
+}
Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/RetrieveMissingStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestInvalidDirectory.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestInvalidDirectory.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestInvalidDirectory.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestInvalidDirectory.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,106 @@
+/*****************************************************************************
+ *
+ * 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.padaf.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.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 TestInvalidDirectory {
+
+
+ protected static File directory;
+
+ protected static PdfAValidator validator = null;
+
+ protected File target = null;
+
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ // create validator
+ validator = new PdfAValidatorFactory().createValidatorInstance(PdfAValidatorFactory.PDF_A_1_b);
+ }
+
+ public TestInvalidDirectory (File file) {
+ this.target = file;
+ }
+
+ @Test
+ public void validate () throws Exception {
+ ValidationResult result = null;
+ try {
+ result = validator.validate(new FileDataSource(target));
+ Assert.assertFalse(result.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.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/padaf/preflight/TestInvalidDirectory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestIsartorValidationFromClasspath.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestIsartorValidationFromClasspath.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestIsartorValidationFromClasspath.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestIsartorValidationFromClasspath.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,168 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight;
+
+import java.io.BufferedReader;
+import java.io.File;
+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.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.apache.padaf.preflight.util.ByteArrayDataSource;
+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 static PdfAValidator validator = 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 {
+ validator = new
+PdfAValidatorFactory().createValidatorInstance(PdfAValidatorFactory.PDF_A_1_b);
+
+ 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 {
+ ValidationResult result = null;
+ try {
+ InputStream input = this.getClass().getResourceAsStream(path);
+ ByteArrayDataSource bds = new ByteArrayDataSource(input);
+ 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;
+ 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 (result!=null) {
+ result.closePdf();
+ }
+ }
+ }
+
+ @Parameters
+ public static Collection<Object[]> initializeParameters() throws
+Exception {
+ // load expected errors
+ InputStream expected = IsartorTargetFileInformation.class
+ .getResourceAsStream("/expected_errors.txt");
+ 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");
+ 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();
+ }
+ return data;
+ }
+}
+
Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestIsartorValidationFromClasspath.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestPDFA1bValidator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestPDFA1bValidator.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestPDFA1bValidator.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestPDFA1bValidator.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,95 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.activation.DataSource;
+import javax.activation.FileDataSource;
+
+
+import org.apache.padaf.preflight.PdfA1bValidator;
+import org.apache.padaf.preflight.PdfAValidatorFactory;
+import org.apache.padaf.preflight.ValidationException;
+import org.apache.padaf.preflight.ValidationResult;
+import org.junit.Test;
+
+public class TestPDFA1bValidator {
+
+ @Test(expected = ValidationException.class)
+ public void testIOExceptionOnJavaCCParser() throws ValidationException {
+ DummyPdfaValidator totest = new DummyPdfaValidator() {
+ public synchronized ValidationResult validate(DataSource source)
+ throws ValidationException {
+ return super.validate(new IODataSource());
+ };
+ };
+ totest.validate(new FileDataSource(""));
+ }
+
+ private class IODataSource implements DataSource {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.activation.DataSource#getContentType()
+ */
+ public String getContentType() {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.activation.DataSource#getInputStream()
+ */
+ public InputStream getInputStream() throws IOException {
+ throw new IOException("Exception fo code coverage");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.activation.DataSource#getName()
+ */
+ public String getName() {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.activation.DataSource#getOutputStream()
+ */
+ public OutputStream getOutputStream() throws IOException {
+ throw new IOException("Exception fo code coverage");
+ }
+ }
+
+ private class DummyPdfaValidator extends PdfA1bValidator {
+ public DummyPdfaValidator() throws ValidationException {
+ super(PdfAValidatorFactory.getStandardPDFA1BConfiguration());
+ }
+ }
+}
Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestPDFA1bValidator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestPdfaValidationFactory.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestPdfaValidationFactory.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestPdfaValidationFactory.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestPdfaValidationFactory.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,48 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight;
+
+import static org.junit.Assert.assertTrue;
+
+
+import org.apache.padaf.preflight.PdfA1bValidator;
+import org.apache.padaf.preflight.PdfAValidator;
+import org.apache.padaf.preflight.PdfAValidatorFactory;
+import org.apache.padaf.preflight.ValidationException;
+import org.junit.Test;
+
+public class TestPdfaValidationFactory {
+
+ @Test
+ public void createPDFA1bValidator() throws ValidationException {
+ PdfAValidatorFactory fact = new PdfAValidatorFactory();
+ PdfAValidator val = fact
+ .createValidatorInstance(PdfAValidatorFactory.PDF_A_1_b);
+ assertTrue(val instanceof PdfA1bValidator);
+ }
+
+ @Test(expected = ValidationException.class)
+ public void createUnknownValidator() throws ValidationException {
+ PdfAValidatorFactory fact = new PdfAValidatorFactory();
+ fact.createValidatorInstance("UnknownPDFFormat");
+ }
+}
Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestPdfaValidationFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestValidDirectory.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestValidDirectory.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestValidDirectory.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestValidDirectory.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,106 @@
+/*****************************************************************************
+ *
+ * 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.padaf.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.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 {
+
+ // TODO Validation CIDKeyed Type2 with Non Identity Map
+ // TODO Validation CIDKeyed Type0
+
+ protected static PdfAValidator validator = null;
+
+ protected File target = null;
+
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ // create validator
+ validator = new PdfAValidatorFactory().createValidatorInstance(PdfAValidatorFactory.PDF_A_1_b);
+ }
+
+ public TestValidDirectory (File file) {
+ this.target = file;
+ }
+
+ @Test
+ public void validate () throws Exception {
+ ValidationResult result = null;
+ try {
+ result = validator.validate(new FileDataSource(target));
+ Assert.assertTrue(result.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/padaf/preflight/TestValidDirectory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestVersionning.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestVersionning.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestVersionning.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestVersionning.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,39 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight;
+
+import org.apache.padaf.preflight.PdfAValidator;
+import org.apache.padaf.preflight.PdfAValidatorFactory;
+import org.junit.Test;
+
+public class TestVersionning {
+
+
+ @Test
+ public void testGetVersion () throws Exception {
+ PdfAValidatorFactory factory = new PdfAValidatorFactory();
+ PdfAValidator validator = factory.createValidatorInstance(PdfAValidatorFactory.PDF_A_1_b);
+
+ System.err.println(">> "+validator.getFullName());
+ }
+
+}
Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/TestVersionning.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/annotations/MyAnnotationFactory.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/annotations/MyAnnotationFactory.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/annotations/MyAnnotationFactory.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/annotations/MyAnnotationFactory.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,72 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.annotations;
+
+import java.util.List;
+
+import org.apache.padaf.preflight.DocumentHandler;
+import org.apache.padaf.preflight.ValidationException;
+import org.apache.padaf.preflight.ValidationResult.ValidationError;
+import org.apache.padaf.preflight.annotation.AnnotationValidator;
+import org.apache.padaf.preflight.annotation.PDFAbAnnotationFactory;
+import org.apache.pdfbox.cos.COSDictionary;
+
+
+public class MyAnnotationFactory extends PDFAbAnnotationFactory {
+
+ public MyAnnotationFactory() {
+ }
+
+ public AnnotationValidator instantiateAnnotationValidator(COSDictionary annotDic,
+ DocumentHandler handler, List<ValidationError> errors) {
+ System.out.println("AnnotationValidatorFactory is overrided");
+ return new MyAnnotationValidator(handler, annotDic);
+ }
+
+ public class MyAnnotationValidator extends AnnotationValidator {
+ public static final String ERROR = "MyAnnotationValidator";
+ public MyAnnotationValidator(DocumentHandler handler,
+ COSDictionary annotDictionary) {
+ super(handler, annotDictionary);
+ }
+
+ /* (non-Javadoc)
+ * @see net.padaf.preflight.annotation.AnnotationValidator#checkMandatoryFields(java.util.List)
+ */
+ @Override
+ protected boolean checkMandatoryFields(List<ValidationError> errors) {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see net.padaf.preflight.annotation.AnnotationValidator#validate(java.util.List)
+ */
+ @Override
+ public boolean validate(List<ValidationError> errors)
+ throws ValidationException {
+ System.out.println("A Custom AnnotationValidator ");
+ errors.add(new ValidationError(ERROR));
+ return false;
+ }
+
+ }
+}
Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/annotations/MyAnnotationFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/font/TestType1MetricHelper.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/font/TestType1MetricHelper.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/font/TestType1MetricHelper.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/font/TestType1MetricHelper.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,122 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.font;
+
+import static org.apache.padaf.preflight.ValidationConstants.FONT_DICTIONARY_VALUE_ENCODING_WIN;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.InputStream;
+
+
+import org.apache.padaf.preflight.ValidationException;
+import org.apache.padaf.preflight.font.Type1MetricHelper;
+import org.junit.Test;
+
+public class TestType1MetricHelper {
+
+ @Test
+ /**
+ * This test validates the Glyph Width extraction of a Valid Type 1 Font Program
+ */
+ public void testNominal() throws Exception {
+ int length1 = 926;
+ int length2 = 12270;
+
+ int first = 32;
+ int last = 160;
+
+ int[] widths = { 278, 0, 0, 0, 0, 0, 0, 191, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 556, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 611, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 556, 0, 556, 556, 278, 556, 556, 222, 0, 0, 222, 833, 556,
+ 556, 556, 0, 0, 500, 278, 0, 0, 722, 500, 500, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 278 };
+ InputStream font = this.getClass().getResourceAsStream(
+ "subset_type1_valid.font");
+
+ Type1MetricHelper helper = new Type1MetricHelper(font, length1, length2,
+ FONT_DICTIONARY_VALUE_ENCODING_WIN);
+ helper.parse();
+ for (int i = 0; i < (last - first + 1); ++i) {
+ if (widths[i] != 0) {
+ assertTrue(widths[i] == helper.getWidth(first + i));
+ }
+ }
+
+ }
+
+ @Test(expected = ValidationException.class)
+ /**
+ * A invalid Type1 Font program is parsed by the MetricHelper.
+ * A ValidationException is expected.
+ *
+ * (The Font Program is a TrueType Font.)
+ */
+ public void testInvalidFont() throws Exception {
+ int length1 = 926;
+ int length2 = 12270;
+
+ InputStream font = this.getClass().getResourceAsStream("true_type.ttf");
+ Type1MetricHelper helper = new Type1MetricHelper(font, length1, length2,
+ FONT_DICTIONARY_VALUE_ENCODING_WIN);
+
+ helper.parse();
+ fail();
+ }
+
+ @Test
+ /**
+ * A Missing character code shouldn't cause Exception but return a Width of 0.
+ */
+ public void testMissingGlyph() throws Exception {
+ int length1 = 926;
+ int length2 = 12270;
+
+ int first = 32;
+ int last = 160;
+
+ int[] widths = { 278, 0, 0, 0, 0, 0, 0, 191, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 556, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 611, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 556, 0, 556, 556, 278, 556, 556, 222, 0, 0, 222, 833, 556,
+ 556, 556, 0, 0, 500, 278, 0, 0, 722, 500, 500, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 278 };
+ InputStream font = this.getClass().getResourceAsStream(
+ "subset_type1_valid.font");
+
+ Type1MetricHelper helper = new Type1MetricHelper(font, length1, length2,
+ FONT_DICTIONARY_VALUE_ENCODING_WIN);
+ helper.parse();
+
+ for (int i = 0; i < (last - first + 1); ++i) {
+ if (widths[i] != 0) {
+ assertTrue(widths[i] == helper.getWidth(first + i));
+ }
+ }
+
+ // ---- Missing Glyph returns 0
+ assertTrue(helper.getWidth(200) == 0);
+ }
+}
Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/font/TestType1MetricHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/helpers/MyFontValidationHelper.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/helpers/MyFontValidationHelper.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/helpers/MyFontValidationHelper.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/helpers/MyFontValidationHelper.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,55 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.helpers;
+
+import java.util.List;
+
+import org.apache.padaf.preflight.DocumentHandler;
+import org.apache.padaf.preflight.ValidationException;
+import org.apache.padaf.preflight.ValidatorConfig;
+import org.apache.padaf.preflight.ValidationResult.ValidationError;
+import org.apache.padaf.preflight.font.FontValidator;
+import org.apache.padaf.preflight.helpers.FontValidationHelper;
+
+
+/**
+ * Class used by the TestConfiguredValidator class
+ */
+public class MyFontValidationHelper extends FontValidationHelper {
+
+ public MyFontValidationHelper(ValidatorConfig cfg)
+ throws ValidationException {
+ super(cfg);
+ }
+
+ protected void initFontValidatorFactory () {
+ super.initFontValidatorFactory();
+ System.out.println("Override the initFontValidatorFactory method");
+ }
+
+ public void validateFont(DocumentHandler handler, FontValidator fontVal,
+ List<ValidationError> result) throws ValidationException {
+ System.out.println("Override the validateFont method");
+ super.validateFont(handler, fontVal, result);
+ result.add(new ValidationError("UNCODEINCONNU"));
+ }
+}
Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/helpers/MyFontValidationHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/helpers/TestAbstractHelper.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/helpers/TestAbstractHelper.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/helpers/TestAbstractHelper.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/helpers/TestAbstractHelper.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,44 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.helpers;
+
+
+import org.apache.padaf.preflight.PdfAValidatorFactory;
+import org.apache.padaf.preflight.ValidationException;
+import org.apache.padaf.preflight.helpers.AcroFormValidationHelper;
+import org.apache.padaf.preflight.util.DocumentHandlerStub;
+import org.junit.Test;
+
+public class TestAbstractHelper {
+
+ @Test(expected = ValidationException.class)
+ public void testAbstractHelperCheckMethod() throws ValidationException {
+ AcroFormValidationHelper afvh = new AcroFormValidationHelper(PdfAValidatorFactory.getStandardPDFA1BConfiguration());
+ afvh.validate(new DocumentHandlerStub(null));
+ }
+
+ @Test(expected = ValidationException.class)
+ public void testAbstractHelperCheckMethod2() throws ValidationException {
+ AcroFormValidationHelper afvh = new AcroFormValidationHelper(PdfAValidatorFactory.getStandardPDFA1BConfiguration());
+ afvh.validate(null);
+ }
+}
Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/helpers/TestAbstractHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/helpers/TestBookmarkValidationHelper.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/helpers/TestBookmarkValidationHelper.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/helpers/TestBookmarkValidationHelper.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/helpers/TestBookmarkValidationHelper.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,45 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.helpers;
+
+
+import org.apache.padaf.preflight.PdfAValidatorFactory;
+import org.apache.padaf.preflight.ValidationException;
+import org.apache.padaf.preflight.helpers.BookmarkValidationHelper;
+import org.apache.padaf.preflight.util.DocumentHandlerStub;
+import org.apache.padaf.preflight.util.NOCatalogDocument;
+import org.apache.padaf.preflight.utils.COSUtils;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.junit.Test;
+
+public class TestBookmarkValidationHelper {
+
+ @Test(expected = ValidationException.class)
+ public void noCatalogEntry() throws Exception {
+ PDDocument pdoc = new NOCatalogDocument();
+ BookmarkValidationHelper helper = new BookmarkValidationHelper(PdfAValidatorFactory.getStandardPDFA1BConfiguration());
+ DocumentHandlerStub hdl = new DocumentHandlerStub(null);
+ hdl.setDocument(pdoc);
+ helper.innerValidate(hdl);
+ COSUtils.closeDocumentQuietly(pdoc);
+ }
+}
Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/helpers/TestBookmarkValidationHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/helpers/TestPageValidationHelper.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/helpers/TestPageValidationHelper.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/helpers/TestPageValidationHelper.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/helpers/TestPageValidationHelper.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,44 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.helpers;
+
+
+import org.apache.padaf.preflight.PdfAValidatorFactory;
+import org.apache.padaf.preflight.ValidationException;
+import org.apache.padaf.preflight.helpers.PagesValidationHelper;
+import org.apache.padaf.preflight.util.DocumentHandlerStub;
+import org.apache.padaf.preflight.util.NOCatalogDocument;
+import org.apache.padaf.preflight.utils.COSUtils;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.junit.Test;
+
+public class TestPageValidationHelper {
+ @Test(expected = ValidationException.class)
+ public void noCatalogEntry() throws Exception {
+ PDDocument pdoc = new NOCatalogDocument();
+ PagesValidationHelper helper = new PagesValidationHelper(PdfAValidatorFactory.getStandardPDFA1BConfiguration());
+ DocumentHandlerStub hdl = new DocumentHandlerStub(null);
+ hdl.setDocument(pdoc);
+ helper.innerValidate(hdl);
+ COSUtils.closeDocumentQuietly(pdoc);
+ }
+}
Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/helpers/TestPageValidationHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/util/ByteArrayDataSource.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/util/ByteArrayDataSource.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/util/ByteArrayDataSource.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/util/ByteArrayDataSource.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,77 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.activation.DataSource;
+
+import org.apache.commons.io.IOUtils;
+
+public class ByteArrayDataSource implements DataSource {
+ private ByteArrayOutputStream data;
+ private String type = null;
+ private String name = null;
+
+ public ByteArrayDataSource(InputStream is) throws IOException {
+ data = new ByteArrayOutputStream();
+ IOUtils.copyLarge(is, data);
+ IOUtils.closeQuietly(is);
+ }
+
+ public String getContentType() {
+ return this.type;
+ }
+
+ /**
+ * @param type
+ * the type to set
+ */
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ /**
+ * @param name
+ * the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public InputStream getInputStream() throws IOException {
+ return new ByteArrayInputStream(data.toByteArray());
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public OutputStream getOutputStream() throws IOException {
+ this.data = new ByteArrayOutputStream();
+ return data;
+ }
+}
Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/util/ByteArrayDataSource.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/util/DocumentHandlerStub.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/util/DocumentHandlerStub.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/util/DocumentHandlerStub.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/util/DocumentHandlerStub.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,39 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.util;
+
+import javax.activation.DataSource;
+
+
+import org.apache.padaf.preflight.DocumentHandler;
+import org.apache.pdfbox.pdmodel.PDDocument;
+
+public class DocumentHandlerStub extends DocumentHandler {
+
+ public DocumentHandlerStub(DataSource source) {
+ super(source);
+ }
+
+ public void setDocument(PDDocument doc) {
+ super.setDocument(doc);
+ }
+}
Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/util/DocumentHandlerStub.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/util/IsartorPdfProvider.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/util/IsartorPdfProvider.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/util/IsartorPdfProvider.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/util/IsartorPdfProvider.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,63 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.util;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.Iterator;
+
+import org.apache.commons.io.FileUtils;
+
+public class IsartorPdfProvider {
+// public static File path;
+// static {
+// String ip = System.getProperty("isartor.path", null);
+// if (ip != null) {
+// path = new File(ip);
+// if (!path.exists() || !path.isDirectory()) {
+// path = null;
+// }
+// }
+// }
+
+ public static InputStream getIsartorDocument(String name) {
+ return IsartorPdfProvider.class.getResourceAsStream(name);
+//
+// if (path == null) {
+// return null;
+// }
+//
+// String[] ext = { "pdf" };
+// Iterator<?> iter = FileUtils.iterateFiles(path, ext, true);
+// while (iter.hasNext()) {
+// Object o = iter.next();
+// if (o instanceof File) {
+// File isartorFile = (File) o;
+// if (isartorFile.isFile() && name.equals(isartorFile.getName())) {
+// return isartorFile;
+// }
+// }
+// }
+// return null;
+// }
+ }
+}
Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/util/IsartorPdfProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/util/NOCatalogDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/util/NOCatalogDocument.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/util/NOCatalogDocument.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/util/NOCatalogDocument.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,43 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.util;
+
+import java.io.IOException;
+
+import org.apache.pdfbox.cos.COSDocument;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
+
+public class NOCatalogDocument extends PDDocument {
+ public NOCatalogDocument() throws IOException {
+ super();
+ }
+
+ public NOCatalogDocument(COSDocument doc) {
+ super(doc);
+ }
+
+ @Override
+ public PDDocumentCatalog getDocumentCatalog() {
+ return null;
+ }
+}
Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/util/NOCatalogDocument.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/utils/TestCOSUtils.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/utils/TestCOSUtils.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/utils/TestCOSUtils.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/utils/TestCOSUtils.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,203 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.utils;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.IOException;
+
+
+import org.apache.padaf.preflight.utils.COSUtils;
+import org.apache.pdfbox.cos.COSArray;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSDocument;
+import org.apache.pdfbox.cos.COSFloat;
+import org.apache.pdfbox.cos.COSInteger;
+import org.apache.pdfbox.cos.COSObject;
+import org.apache.pdfbox.cos.COSStream;
+import org.apache.pdfbox.cos.COSString;
+import org.apache.pdfbox.io.RandomAccess;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.persistence.util.COSObjectKey;
+import org.junit.Test;
+
+public class TestCOSUtils {
+
+ @Test
+ public void testIsInteger() {
+ try {
+ COSObject co = new COSObject(new COSInteger(10));
+ co.setGenerationNumber(new COSInteger(0));
+ co.setObjectNumber(new COSInteger(10));
+
+ assertFalse(COSUtils.isInteger(co, new IOCOSDocument()));
+
+ COSDocument doc = new COSDocument();
+ doc.setXRef(new COSObjectKey(co), 1000);
+ COSUtils.isInteger(co, doc);
+ doc.close();
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testIsFloat() {
+ try {
+ COSObject co = new COSObject(new COSFloat(10.0f));
+ co.setGenerationNumber(new COSInteger(0));
+ co.setObjectNumber(new COSInteger(10));
+
+ assertFalse(COSUtils.isFloat(co, new IOCOSDocument()));
+
+ COSDocument doc = new COSDocument();
+ doc.setXRef(new COSObjectKey(co), 1000);
+ COSUtils.isFloat(co, doc);
+ doc.close();
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testIsString() {
+ try {
+ COSObject co = new COSObject(new COSString(""));
+ co.setGenerationNumber(new COSInteger(0));
+ co.setObjectNumber(new COSInteger(10));
+
+ assertFalse(COSUtils.isString(co, new IOCOSDocument()));
+
+ COSDocument doc = new COSDocument();
+ doc.setXRef(new COSObjectKey(co), 1000);
+ COSUtils.isString(co, doc);
+ doc.close();
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testIsStream() {
+ try {
+ COSObject co = new COSObject(new COSStream(null));
+ co.setGenerationNumber(new COSInteger(0));
+ co.setObjectNumber(new COSInteger(10));
+
+ assertFalse(COSUtils.isStream(co, new IOCOSDocument()));
+
+ COSDocument doc = new COSDocument();
+ doc.setXRef(new COSObjectKey(co), 1000);
+ COSUtils.isStream(co, doc);
+ doc.close();
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testIsDictionary() {
+ try {
+ COSObject co = new COSObject(new COSDictionary());
+ co.setGenerationNumber(new COSInteger(0));
+ co.setObjectNumber(new COSInteger(10));
+
+ assertFalse(COSUtils.isDictionary(co, new IOCOSDocument()));
+
+ COSDocument doc = new COSDocument();
+ doc.setXRef(new COSObjectKey(co), 1000);
+ COSUtils.isDictionary(co, doc);
+ doc.close();
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testIsArray() {
+ try {
+ COSObject co = new COSObject(new COSArray());
+ co.setGenerationNumber(new COSInteger(0));
+ co.setObjectNumber(new COSInteger(10));
+
+ assertFalse(COSUtils.isArray(co, new IOCOSDocument()));
+
+ COSDocument doc = new COSDocument();
+ doc.setXRef(new COSObjectKey(co), 1000);
+ COSUtils.isArray(co, doc);
+ doc.close();
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testCloseCOSDocumentNull() {
+ COSUtils.closeDocumentQuietly((COSDocument) null);
+ }
+
+ @Test
+ public void testClosePDDocumentNull() {
+ COSUtils.closeDocumentQuietly((PDDocument) null);
+ }
+
+ @Test
+ public void testCloseCOSDocumentIO() {
+ try {
+ COSUtils.closeDocumentQuietly(new IOCOSDocument());
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * Class used to check the catch block in COSUtils methods
+ */
+ private class IOCOSDocument extends COSDocument {
+
+ IOCOSDocument() throws IOException {
+ super();
+ }
+
+ IOCOSDocument(File scratchDir) throws IOException {
+ super(scratchDir);
+ }
+
+ IOCOSDocument(RandomAccess file) {
+ super(file);
+ }
+
+ @Override
+ public void close() throws IOException {
+ super.close();
+ throw new IOException("Exception for code coverage");
+ }
+
+ @Override
+ public COSObject getObjectFromPool(COSObjectKey key) throws IOException {
+ super.close();
+ throw new IOException("Exception for code coverage");
+ }
+ }
+}
Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/utils/TestCOSUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/xmp/TestSynchronizedMetadataValidation.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/xmp/TestSynchronizedMetadataValidation.java?rev=1150373&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/xmp/TestSynchronizedMetadataValidation.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/xmp/TestSynchronizedMetadataValidation.java Sun Jul 24 14:02:12 2011
@@ -0,0 +1,577 @@
+/*****************************************************************************
+ *
+ * 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.padaf.preflight.xmp;
+
+import java.io.IOException;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.apache.padaf.preflight.ValidationConstants;
+import org.apache.padaf.preflight.ValidationException;
+import org.apache.padaf.preflight.ValidationResult.ValidationError;
+import org.apache.padaf.preflight.xmp.SynchronizedMetaDataValidation;
+import org.apache.padaf.xmpbox.XMPMetadata;
+import org.apache.padaf.xmpbox.schema.AdobePDFSchema;
+import org.apache.padaf.xmpbox.schema.DublinCoreSchema;
+import org.apache.padaf.xmpbox.schema.XMPBasicSchema;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.PDDocumentInformation;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Test Class of SynchronizedMetaDataValidation (for 6-7-3 Isartor Tests)
+ *
+ * @author Germain Costenobel
+ *
+ */
+public class TestSynchronizedMetadataValidation {
+
+ protected PDDocument doc;
+ protected PDDocumentInformation dico;
+ protected XMPMetadata metadata;
+ protected String title, author, subject, keywords, creator, producer;
+ protected Calendar creationDate, modifyDate;
+ protected static SynchronizedMetaDataValidation sync;
+ protected List<ValidationError> ve;
+
+ @BeforeClass
+ public static void initSynchronizedMetadataValidation() {
+ sync = new SynchronizedMetaDataValidation();
+ }
+
+ @Before
+ public void initNewDocumentInformation() throws Exception {
+
+ try {
+ doc = new PDDocument();
+ dico = doc.getDocumentInformation();
+ metadata = new XMPMetadata();
+ } catch (IOException e) {
+ throw new Exception("Failed to create temporary test PDF/XMP Document");
+ }
+
+ }
+
+ /**
+ * Check detection of a null Document
+ *
+ * @throws ValidationException
+ */
+ @Test(expected = ValidationException.class)
+ public void TestNullDocument() throws ValidationException {
+ sync.validateMetadataSynchronization(null, metadata);
+ }
+
+ /**
+ * Check detection of null metadata
+ *
+ * @throws ValidationException
+ */
+ @Test(expected = ValidationException.class)
+ public void TestNullMetaData() throws ValidationException {
+ sync.validateMetadataSynchronization(doc, null);
+ }
+
+ /**
+ * Check the detection of a PDF document without any information
+ *
+ * @throws Exception
+ */
+ @Test
+ public void TestDocumentWithoutInformation() throws Exception {
+ try {
+ ve = sync.validateMetadataSynchronization(doc, metadata);
+ // Test without any information
+ Assert.assertEquals(0, ve.size());
+ } catch (ValidationException e) {
+ throw new Exception(e.getMessage());
+ }
+ }
+
+ /**
+ * Check the detection of a completely empty XMP document (without any
+ * schemas)
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testEmptyXMP() throws Exception {
+ title = "TITLE";
+ author = "AUTHOR(S)";
+ subject = "SUBJECTS";
+ keywords = "KEYWORD(S)";
+ creator = "CREATOR";
+ producer = "PRODUCER";
+ creationDate = Calendar.getInstance();
+ modifyDate = Calendar.getInstance();
+
+ // Writing info in Document Information dictionary
+ // TITLE
+ dico.setTitle(title);
+ // AUTHOR
+ dico.setAuthor(author);
+ // SUBJECT
+ dico.setSubject(subject);
+ // KEYWORDS
+ dico.setKeywords(keywords);
+ // CREATOR
+ dico.setCreator(creator);
+ // PRODUCER
+ dico.setProducer(producer);
+ // CREATION DATE
+ dico.setCreationDate(creationDate);
+ // MODIFY DATE
+ dico.setModificationDate(modifyDate);
+
+ try {
+ ve = sync.validateMetadataSynchronization(doc, metadata);
+ // Test Detection of an Empty XMP (without any schemas)
+ for (ValidationError valid : ve) {
+ Assert.assertEquals(ValidationConstants.ERROR_METADATA_MISMATCH, valid
+ .getErrorCode());
+ }
+ } catch (ValidationException e) {
+ throw new Exception(e.getMessage());
+ }
+ }
+
+ /**
+ * Check the detection of a XMP with empty common schemas
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testEmptyXMPSchemas() throws Exception {
+ title = "TITLE";
+ author = "AUTHOR(S)";
+ subject = "SUBJECTS";
+ keywords = "KEYWORD(S)";
+ creator = "CREATOR";
+ producer = "PRODUCER";
+ creationDate = Calendar.getInstance();
+ modifyDate = Calendar.getInstance();
+
+ // building temporary XMP metadata (but empty)
+ metadata.createAndAddDublinCoreSchema();
+ metadata.createAndAddAdobePDFSchema();
+ metadata.createAndAddXMPBasicSchema();
+
+ // Writing info in Document Information dictionary
+ // TITLE
+ dico.setTitle(title);
+ // AUTHOR
+ dico.setAuthor(author);
+ // SUBJECT
+ dico.setSubject(subject);
+ // KEYWORDS
+ dico.setKeywords(keywords);
+ // CREATOR
+ dico.setCreator(creator);
+ // PRODUCER
+ dico.setProducer(producer);
+ // CREATION DATE
+ dico.setCreationDate(creationDate);
+ // MODIFY DATE
+ dico.setModificationDate(modifyDate);
+
+ try {
+ ve = sync.validateMetadataSynchronization(doc, metadata);
+ // Test Detection of absent XMP values
+ Assert.assertEquals(8, ve.size());
+ } catch (ValidationException e) {
+ throw new Exception(e.getMessage());
+ }
+
+ }
+
+ /**
+ * Check detection of a null value in array (for Subject and author
+ * properties)
+ *
+ * @throws Exception
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testNullArrayValue() throws Exception {
+ // building temporary XMP metadata
+
+ DublinCoreSchema dc = metadata.createAndAddDublinCoreSchema();
+
+ // AUTHOR
+ dico.setAuthor("dicoAuthor");
+ dc.addToCreatorValue(null);
+
+ // SUBJECT
+ dico.setSubject("dicoSubj");
+ dc.addToSubjectValue(null);
+
+ // Launching synchronization test
+ try {
+ ve = sync.validateMetadataSynchronization(doc, metadata);
+ // Test unsychronized value
+ Assert.assertEquals(2, ve.size());
+
+ } catch (ValidationException e) {
+ throw new Exception(e.getMessage());
+ }
+ }
+
+ /**
+ * in XMP, Subject and Author must be embedded in a single entry text array
+ * This function check the detection of multiple entries for these properties
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testBadSizeOfArrays() throws Exception {
+ // building temporary XMP metadata
+
+ DublinCoreSchema dc = metadata.createAndAddDublinCoreSchema();
+ AdobePDFSchema pdf = metadata.createAndAddAdobePDFSchema();
+ XMPBasicSchema xmp = metadata.createAndAddXMPBasicSchema();
+
+ // Writing info in XMP and Document Information dictionary
+ // TITLE
+ dico.setTitle("dicoTitle");
+ dc.addToTitleValue("x-default", "XMPTitle");
+ // AUTHOR
+ dico.setAuthor("dicoAuthor");
+ dc.addToCreatorValue("XMPAuthor");
+ dc.addToCreatorValue("2ndCreator");
+ // SUBJECT
+ dico.setSubject("dicoSubj");
+ dc.addToSubjectValue("XMPSubj");
+ dc.addToSubjectValue("2ndSubj");
+ // KEYWORDS
+ dico.setKeywords("DicoKeywords");
+ pdf.setKeywordsValue("XMPkeywords");
+ // CREATOR
+ dico.setCreator("DicoCreator");
+ xmp.setCreatorToolValue("XMPCreator");
+ // PRODUCER
+ dico.setProducer("DicoProducer");
+ pdf.setProducerValue("XMPProducer");
+ // CREATION DATE
+ dico.setCreationDate(Calendar.getInstance());
+ GregorianCalendar XMPCreate = new GregorianCalendar(2008, 11, 05);
+ xmp.setCreateDateValue(XMPCreate);
+ // MODIFY DATE
+ dico.setModificationDate(Calendar.getInstance());
+ GregorianCalendar XMPModify = new GregorianCalendar(2009, 10, 15);
+ xmp.setModifyDateValue(XMPModify);
+
+ // Launching synchronization test
+ try {
+ ve = sync.validateMetadataSynchronization(doc, metadata);
+ // Test unsychronized value
+ Assert.assertEquals(8, ve.size());
+ } catch (ValidationException e) {
+ throw new Exception(e.getMessage());
+ }
+
+ }
+
+ /**
+ * Check the detection of unsynchronized information between Document
+ * Information dictionary and XMP
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testAllInfoUnsynchronized() throws Exception {
+ // building temporary XMP metadata
+
+ DublinCoreSchema dc = metadata.createAndAddDublinCoreSchema();
+ AdobePDFSchema pdf = metadata.createAndAddAdobePDFSchema();
+ XMPBasicSchema xmp = metadata.createAndAddXMPBasicSchema();
+
+ // Writing info in XMP and Document Information dictionary
+ // TITLE
+ dico.setTitle("dicoTitle");
+ dc.addToTitleValue("x-default", "XMPTitle");
+ // AUTHOR
+ dico.setAuthor("dicoAuthor");
+ dc.addToCreatorValue("XMPAuthor");
+ // SUBJECT
+ dico.setSubject("dicoSubj");
+ dc.addToSubjectValue("XMPSubj");
+ // KEYWORDS
+ dico.setKeywords("DicoKeywords");
+ pdf.setKeywordsValue("XMPkeywords");
+ // CREATOR
+ dico.setCreator("DicoCreator");
+ xmp.setCreatorToolValue("XMPCreator");
+ // PRODUCER
+ dico.setProducer("DicoProducer");
+ pdf.setProducerValue("XMPProducer");
+ // CREATION DATE
+ dico.setCreationDate(Calendar.getInstance());
+ GregorianCalendar XMPCreate = new GregorianCalendar(2008, 11, 05);
+ xmp.setCreateDateValue(XMPCreate);
+ // MODIFY DATE
+ dico.setModificationDate(Calendar.getInstance());
+ GregorianCalendar XMPModify = new GregorianCalendar(2009, 10, 15);
+ xmp.setModifyDateValue(XMPModify);
+
+ // Launching synchronization test
+ try {
+ ve = sync.validateMetadataSynchronization(doc, metadata);
+ // Test unsychronized value
+ Assert.assertEquals(8, ve.size());
+ } catch (ValidationException e) {
+ throw new Exception(e.getMessage());
+ }
+
+ }
+
+ /**
+ * Check reaction when metadata are well-formed
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testAllInfoSynhcronized() throws Exception {
+ title = "TITLE";
+ author = "AUTHOR(S)";
+ subject = "SUBJECTS";
+ keywords = "KEYWORD(S)";
+ creator = "CREATOR";
+ producer = "PRODUCER";
+ creationDate = Calendar.getInstance();
+ modifyDate = Calendar.getInstance();
+
+ // building temporary XMP metadata
+ DublinCoreSchema dc = metadata.createAndAddDublinCoreSchema();
+ XMPBasicSchema xmp = metadata.createAndAddXMPBasicSchema();
+ AdobePDFSchema pdf = metadata.createAndAddAdobePDFSchema();
+ // Writing info in XMP and Document Information dictionary
+ // TITLE
+ dico.setTitle(title);
+ dc.addToTitleValue("x-default", title);
+ // AUTHOR
+ dico.setAuthor(author);
+ dc.addToCreatorValue(author);
+ // SUBJECT
+ dico.setSubject(subject);
+ dc.addToDescriptionValue("x-default", subject);
+ // KEYWORDS
+ dico.setKeywords(keywords);
+ pdf.setKeywordsValue(keywords);
+ // CREATOR
+ dico.setCreator(creator);
+ xmp.setCreatorToolValue(creator);
+ // PRODUCER
+ dico.setProducer(producer);
+ pdf.setProducerValue(producer);
+ // CREATION DATE
+ dico.setCreationDate(creationDate);
+ xmp.setCreateDateValue(creationDate);
+ // MODIFY DATE
+ dico.setModificationDate(modifyDate);
+ xmp.setModifyDateValue(modifyDate);
+
+ // Launching synchronization test
+ try {
+ ve = sync.validateMetadataSynchronization(doc, metadata);
+ // Checking all is synchronized
+ Assert.assertEquals(0, ve.size());
+ } catch (ValidationException e) {
+ throw new Exception(e.getMessage());
+ }
+
+ }
+
+ /**
+ * Check if FormatAccessException Generator is ok
+ *
+ * @throws Exception
+ */
+ @Test
+ public void checkformatAccessException() throws Exception {
+ Throwable cause = new Throwable();
+ Assert.assertSame(cause, sync.formatAccessException("test", "test", cause)
+ .getCause());
+ }
+
+ /**
+ * Check if SchemaAccessException Generator is ok
+ *
+ * @throws Exception
+ */
+ @Test
+ public void checkSchemaAccessException() throws Exception {
+ Throwable cause = new Throwable();
+ Assert.assertSame(cause, sync.SchemaAccessException("test", cause)
+ .getCause());
+ }
+
+ /**
+ * Check reaction when metadata are well-formed
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testBadPrefixSchemas() throws Exception {
+ title = "TITLE";
+ author = "AUTHOR(S)";
+ subject = "SUBJECTS";
+ keywords = "KEYWORD(S)";
+ creator = "CREATOR";
+ producer = "PRODUCER";
+ creationDate = Calendar.getInstance();
+ modifyDate = Calendar.getInstance();
+
+ // building temporary XMP metadata
+ DublinCoreSchema dc = new DublinCoreSchema(metadata, "dctest");
+ metadata.addSchema(dc);
+ XMPBasicSchema xmp = new XMPBasicSchema(metadata, "xmptest");
+ metadata.addSchema(xmp);
+ AdobePDFSchema pdf = new AdobePDFSchema(metadata, "pdftest");
+ metadata.addSchema(pdf);
+
+ // Writing info in XMP and Document Information dictionary
+ // TITLE
+ dico.setTitle(title);
+ dc.addToTitleValue("x-default", title);
+ // AUTHOR
+ dico.setAuthor(author);
+ dc.addToCreatorValue(author);
+ // SUBJECT
+ dico.setSubject(subject);
+ dc.addToDescriptionValue("x-default", subject);
+ // KEYWORDS
+ dico.setKeywords(keywords);
+ pdf.setKeywordsValue(keywords);
+ // CREATOR
+ dico.setCreator(creator);
+ xmp.setCreatorToolValue(creator);
+ // PRODUCER
+ dico.setProducer(producer);
+ pdf.setProducerValue(producer);
+ // CREATION DATE
+ dico.setCreationDate(creationDate);
+ xmp.setCreateDateValue(creationDate);
+ // MODIFY DATE
+ dico.setModificationDate(modifyDate);
+ xmp.setModifyDateValue(modifyDate);
+
+ // Launching synchronization test
+ try {
+ ve = sync.validateMetadataSynchronization(doc, metadata);
+ for (ValidationError valid : ve) {
+ Assert.assertEquals(ValidationConstants.ERROR_METADATA_WRONG_NS_PREFIX,
+ valid.getErrorCode());
+ }
+ } catch (ValidationException e) {
+ throw new Exception(e.getMessage());
+ }
+
+ }
+
+ /**
+ * Check reaction when metadata are well-formed
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testdoublePrefixSchemas() throws Exception {
+ title = "TITLE";
+ author = "AUTHOR(S)";
+ subject = "SUBJECTS";
+ keywords = "KEYWORD(S)";
+ creator = "CREATOR";
+ producer = "PRODUCER";
+ creationDate = Calendar.getInstance();
+ modifyDate = Calendar.getInstance();
+
+ // building temporary XMP metadata
+ DublinCoreSchema dc = metadata.createAndAddDublinCoreSchema();
+ DublinCoreSchema dc2 = new DublinCoreSchema(metadata, "dctest");
+ metadata.addSchema(dc2);
+ XMPBasicSchema xmp = metadata.createAndAddXMPBasicSchema();
+ XMPBasicSchema xmp2 = new XMPBasicSchema(metadata, "xmptest");
+ metadata.addSchema(xmp2);
+ AdobePDFSchema pdf = metadata.createAndAddAdobePDFSchema();
+ AdobePDFSchema pdf2 = new AdobePDFSchema(metadata, "pdftest");
+ metadata.addSchema(pdf2);
+
+ // write some temp info in 'false' schemas
+ dc2.setCoverageValue("tmpcover");
+ xmp2.setCreatorToolValue("tmpcreator");
+ pdf2.setKeywordsValue("tmpkeys");
+
+ // Writing info in XMP and Document Information dictionary
+ // TITLE
+ dico.setTitle(title);
+ dc.addToTitleValue("x-default", title);
+ // AUTHOR
+ dico.setAuthor(author);
+ dc.addToCreatorValue(author);
+ // SUBJECT
+ dico.setSubject(subject);
+ dc.addToDescriptionValue("x-default", subject);
+ // KEYWORDS
+ dico.setKeywords(keywords);
+ pdf.setKeywordsValue(keywords);
+ // CREATOR
+ dico.setCreator(creator);
+ xmp.setCreatorToolValue(creator);
+ // PRODUCER
+ dico.setProducer(producer);
+ pdf.setProducerValue(producer);
+ // CREATION DATE
+ dico.setCreationDate(creationDate);
+ xmp.setCreateDateValue(creationDate);
+ // MODIFY DATE
+ dico.setModificationDate(modifyDate);
+ xmp.setModifyDateValue(modifyDate);
+
+ // Launching synchronization test
+ try {
+ ve = sync.validateMetadataSynchronization(doc, metadata);
+ Assert.assertTrue(ve.isEmpty());
+ } catch (ValidationException e) {
+ throw new Exception(e.getMessage());
+ }
+
+ }
+
+ @After
+ public void checkErrors() throws Exception {
+ try {
+ doc.close();
+ } catch (IOException e) {
+ throw new Exception("Error while closing PDF Document");
+ }
+ /*
+ * Iterator<ValidationError> it=ve.iterator(); while(it.hasNext()){
+ * ValidationError tmp=it.next(); System.out.println("Error:"+
+ * tmp.getDetails()+"\n code: "+tmp.getErrorCode()); }
+ */
+ }
+
+}
Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/padaf/preflight/xmp/TestSynchronizedMetadataValidation.java
------------------------------------------------------------------------------
svn:eol-style = native