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 2012/08/08 22:08:32 UTC

svn commit: r1370929 - in /pdfbox/trunk/preflight/src/test: java/org/apache/pdfbox/preflight/action/ java/org/apache/pdfbox/preflight/action/pdfa1b/ resources/

Author: leleueri
Date: Wed Aug  8 20:08:31 2012
New Revision: 1370929

URL: http://svn.apache.org/viewvc?rev=1370929&view=rev
Log:
[https://issues.apache.org/jira/browse/PDFBOX-1312] Addition of Unit Test for Action validation

Added:
    pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/
    pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/
    pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/AbstractTestAction.java   (with props)
    pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestForbiddenAction.java   (with props)
    pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestGotoAction.java   (with props)
    pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestGotoRemoteAction.java   (with props)
    pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestHideAction.java   (with props)
    pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestNamedAction.java   (with props)
    pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestSubmitAction.java   (with props)
    pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestThreadAction.java   (with props)
    pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestUriAction.java   (with props)
    pdfbox/trunk/preflight/src/test/resources/pdfa-with-annotations-square.pdf   (with props)

Added: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/AbstractTestAction.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/AbstractTestAction.java?rev=1370929&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/AbstractTestAction.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/AbstractTestAction.java Wed Aug  8 20:08:31 2012
@@ -0,0 +1,119 @@
+/*****************************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ ****************************************************************************/
+
+package org.apache.pdfbox.preflight.action.pdfa1b;
+
+import static org.junit.Assert.*;
+
+import java.util.List;
+
+import javax.activation.DataSource;
+import javax.activation.FileDataSource;
+
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.interactive.action.type.PDAction;
+import org.apache.pdfbox.preflight.Format;
+import org.apache.pdfbox.preflight.PreflightContext;
+import org.apache.pdfbox.preflight.PreflightDocument;
+import org.apache.pdfbox.preflight.ValidationResult.ValidationError;
+import org.apache.pdfbox.preflight.action.AbstractActionManager;
+import org.apache.pdfbox.preflight.action.ActionManagerFactory;
+
+public abstract class AbstractTestAction {
+
+	/**
+	 * Read a simple PDF/A to create a valid Context
+	 * 
+	 * @return
+	 * @throws Exception
+	 */
+	protected PreflightContext createContext() throws Exception {
+		DataSource ds = new FileDataSource("src/test/resources/pdfa-with-annotations-square.pdf");
+		PDDocument doc = PDDocument.load(ds.getInputStream());
+		PreflightDocument preflightDocument = new PreflightDocument(doc.getDocument(), Format.PDF_A1B);
+		PreflightContext ctx = new PreflightContext(ds);
+		ctx.setDocument(preflightDocument);
+		preflightDocument.setContext(ctx);
+		return ctx;
+	}
+	
+	/**
+	 * Run the Action validation and check the result.
+	 * 
+	 * @param action action to check
+	 * @param valid true if the Action must be valid, false if the action contains mistakes
+	 * @throws Exception
+	 */
+	protected void valid(PDAction action, boolean valid) throws Exception {
+		valid(action, valid, null);
+	}
+
+	protected void valid(COSDictionary action, boolean valid) throws Exception {
+		valid(action, valid, null);
+	}
+	
+	/**
+	 * Run the Action validation and check the result.
+	 * 
+	 * @param action action to check
+	 * @param valid true if the Action must be valid, false if the action contains mistakes
+	 * @param expectedCode the expected error code (can be null)
+	 * @throws Exception
+	 */
+	protected void valid(PDAction action, boolean valid, String expectedCode) throws Exception {
+		valid(action.getCOSDictionary(), valid, expectedCode);
+	}
+	
+	protected void valid(COSDictionary action, boolean valid, String expectedCode) throws Exception {
+		ActionManagerFactory fact = new ActionManagerFactory();
+		PreflightContext ctx = createContext();
+		COSDictionary dict = new COSDictionary();
+		dict.setItem(COSName.A, action);
+		
+		// process the action validation
+		List<AbstractActionManager> actions = fact.getActionManagers(ctx, dict);
+		for (AbstractActionManager abstractActionManager : actions) {
+			abstractActionManager.valid();
+		}
+
+		// check the result
+		if (!valid) {
+			List<ValidationError> errors = ctx.getDocument().getResult().getErrorsList();
+			assertFalse(errors.isEmpty());
+			if (expectedCode != null || !"".equals(expectedCode)) {
+				boolean found = false;
+				for (ValidationError err : errors) {
+					if (err.getErrorCode().equals(expectedCode)) {
+						found = true;
+					}
+				}
+				assertTrue(found);
+			}
+		} else {
+			if (ctx.getDocument().getResult() != null) {
+				List<ValidationError> errors = ctx.getDocument().getResult().getErrorsList();
+				assertTrue(errors.isEmpty());
+			}
+		}
+	}
+}

Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/AbstractTestAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestForbiddenAction.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestForbiddenAction.java?rev=1370929&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestForbiddenAction.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestForbiddenAction.java Wed Aug  8 20:08:31 2012
@@ -0,0 +1,73 @@
+/*****************************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ ****************************************************************************/
+
+package org.apache.pdfbox.preflight.action.pdfa1b;
+
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.preflight.PreflightConstants;
+import org.junit.Test;
+
+public class TestForbiddenAction extends AbstractTestAction {
+	
+	protected COSDictionary createAction(String type) {
+		COSDictionary action = new COSDictionary();
+		action.setItem(COSName.TYPE, COSName.getPDFName("Action"));
+		action.setItem(COSName.S, COSName.getPDFName(type));
+		return action;
+	}
+	
+	@Test
+	public void testLaunch() throws Exception {
+		COSDictionary action = createAction("Launch");
+		valid(action, false, PreflightConstants.ERROR_ACTION_FORBIDDEN_ACTIONS_EXPLICITLY_FORBIDDEN);
+	}
+
+	@Test
+	public void testSound() throws Exception {
+		COSDictionary action = createAction("Sound");
+		valid(action, false, PreflightConstants.ERROR_ACTION_FORBIDDEN_ACTIONS_EXPLICITLY_FORBIDDEN);
+	}
+
+	@Test
+	public void testMovie() throws Exception {
+		COSDictionary action = createAction("Movie");
+		valid(action, false, PreflightConstants.ERROR_ACTION_FORBIDDEN_ACTIONS_EXPLICITLY_FORBIDDEN);
+	}
+
+	@Test
+	public void testImportData() throws Exception {
+		COSDictionary action = createAction("ImportData");
+		valid(action, false, PreflightConstants.ERROR_ACTION_FORBIDDEN_ACTIONS_EXPLICITLY_FORBIDDEN);
+	}
+
+	@Test
+	public void testResetForm() throws Exception {
+		COSDictionary action = createAction("ResetForm");
+		valid(action, false, PreflightConstants.ERROR_ACTION_FORBIDDEN_ACTIONS_EXPLICITLY_FORBIDDEN);
+	}
+
+	@Test
+	public void testJS() throws Exception {
+		COSDictionary action = createAction("JavaScript");
+		valid(action, false, PreflightConstants.ERROR_ACTION_FORBIDDEN_ACTIONS_EXPLICITLY_FORBIDDEN);
+	}
+}

Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestForbiddenAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestGotoAction.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestGotoAction.java?rev=1370929&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestGotoAction.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestGotoAction.java Wed Aug  8 20:08:31 2012
@@ -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.pdfbox.preflight.action.pdfa1b;
+
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.interactive.action.type.PDActionGoTo;
+import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDDestination;
+import org.apache.pdfbox.preflight.PreflightConstants;
+import org.junit.Test;
+
+public class TestGotoAction extends AbstractTestAction {
+
+	@Test
+	public void testGoto_OK() throws Exception {
+		PDActionGoTo gotoAction = new PDActionGoTo();
+		gotoAction.setDestination(new PDDestination() {
+			public COSBase getCOSObject() {
+				return COSName.getPDFName("ADest");
+			}
+		});
+
+		valid(gotoAction, true);
+	}
+
+	@Test
+	public void testGoto_KO_invalidContent() throws Exception {
+		PDActionGoTo gotoAction = new PDActionGoTo();
+		gotoAction.setDestination(new PDDestination() {
+			public COSBase getCOSObject() {
+				return new COSDictionary();
+			}
+		});
+
+		valid(gotoAction, false, PreflightConstants.ERROR_ACTION_INVALID_TYPE);
+	}
+	
+	@Test
+	public void testGoto_KO_missingD() throws Exception {
+		PDActionGoTo gotoAction = new PDActionGoTo();
+		valid(gotoAction, false, PreflightConstants.ERROR_ACTION_MISING_KEY);
+	}
+}

Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestGotoAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestGotoRemoteAction.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestGotoRemoteAction.java?rev=1370929&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestGotoRemoteAction.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestGotoRemoteAction.java Wed Aug  8 20:08:31 2012
@@ -0,0 +1,98 @@
+/*****************************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ ****************************************************************************/
+
+package org.apache.pdfbox.preflight.action.pdfa1b;
+
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.common.filespecification.PDFileSpecification;
+import org.apache.pdfbox.pdmodel.interactive.action.type.PDActionGoTo;
+import org.apache.pdfbox.pdmodel.interactive.action.type.PDActionRemoteGoTo;
+import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDDestination;
+import org.apache.pdfbox.preflight.PreflightConstants;
+import org.junit.Test;
+
+public class TestGotoRemoteAction extends AbstractTestAction {
+
+	@Test
+	public void testGoto_OK() throws Exception {
+		PDActionRemoteGoTo gotoAction = new PDActionRemoteGoTo();
+		gotoAction.setD(COSName.getPDFName("ADest"));
+		gotoAction.setFile(new PDFileSpecification() {
+			public COSBase getCOSObject() {
+				return COSName.getPDFName("ADest");
+			}
+			@Override
+			public void setFile(String file) {
+			}
+			@Override
+			public String getFile() {
+				return "pouey";
+			}
+		});
+		valid(gotoAction, true);
+	}
+
+	@Test
+	public void testGoto_KO_InvalidContent() throws Exception {
+		PDActionRemoteGoTo gotoAction = new PDActionRemoteGoTo();
+		gotoAction.setD(new COSDictionary());
+		gotoAction.setFile(new PDFileSpecification() {
+			public COSBase getCOSObject() {
+				return COSName.getPDFName("ADest");
+			}
+			@Override
+			public void setFile(String file) {
+			}
+			@Override
+			public String getFile() {
+				return "pouey";
+			}
+		});
+		valid(gotoAction, false, PreflightConstants.ERROR_ACTION_INVALID_TYPE);
+	}
+
+	@Test
+	public void testGoto_KO_MissingD() throws Exception {
+		PDActionRemoteGoTo gotoAction = new PDActionRemoteGoTo();
+		gotoAction.setFile(new PDFileSpecification() {
+			public COSBase getCOSObject() {
+				return COSName.getPDFName("ADest");
+			}
+			@Override
+			public void setFile(String file) {
+			}
+			@Override
+			public String getFile() {
+				return "pouey";
+			}
+		});
+		valid(gotoAction, false, PreflightConstants.ERROR_ACTION_MISING_KEY);
+	}
+
+	@Test
+	public void testGoto_KO_MissingF() throws Exception {
+		PDActionRemoteGoTo gotoAction = new PDActionRemoteGoTo();
+		gotoAction.setD(COSName.getPDFName("ADest"));
+		valid(gotoAction, false, PreflightConstants.ERROR_ACTION_MISING_KEY);
+	}
+}

Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestGotoRemoteAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestHideAction.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestHideAction.java?rev=1370929&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestHideAction.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestHideAction.java Wed Aug  8 20:08:31 2012
@@ -0,0 +1,66 @@
+/*****************************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ ****************************************************************************/
+
+package org.apache.pdfbox.preflight.action.pdfa1b;
+
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.preflight.PreflightConstants;
+import org.junit.Test;
+
+public class TestHideAction extends AbstractTestAction {
+
+	protected COSDictionary createHideAction() {
+		COSDictionary hideAction = new COSDictionary();
+		hideAction.setItem(COSName.TYPE, COSName.getPDFName("Action"));
+		hideAction.setItem(COSName.S, COSName.getPDFName("Hide"));
+		hideAction.setBoolean(COSName.H, false);
+		hideAction.setString(COSName.T, "avalue");
+		return hideAction;
+	}
+	
+	@Test
+	public void testHideAction() throws Exception {
+		COSDictionary action = createHideAction();
+		valid(action, true);
+	}
+	
+	@Test
+	public void testHideAction_InvalideH() throws Exception {
+		COSDictionary action = createHideAction();
+		action.setBoolean(COSName.H, true);
+		valid(action, false, PreflightConstants.ERROR_ACTION_HIDE_H_INVALID);
+	}
+	
+	@Test
+	public void testHideAction_InvalideT() throws Exception {
+		COSDictionary action = createHideAction();
+		action.setBoolean(COSName.T, true);
+		valid(action, false, PreflightConstants.ERROR_ACTION_INVALID_TYPE);
+	}
+	
+	@Test
+	public void testHideAction_MissingT() throws Exception {
+		COSDictionary action = createHideAction();
+		action.removeItem(COSName.T);
+		valid(action, false, PreflightConstants.ERROR_ACTION_MISING_KEY);
+	}
+}

Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestHideAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestNamedAction.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestNamedAction.java?rev=1370929&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestNamedAction.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestNamedAction.java Wed Aug  8 20:08:31 2012
@@ -0,0 +1,78 @@
+/*****************************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ ****************************************************************************/
+
+package org.apache.pdfbox.preflight.action.pdfa1b;
+
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.preflight.PreflightConstants;
+import org.junit.Test;
+
+public class TestNamedAction extends AbstractTestAction {
+	protected COSDictionary createNamedAction() {
+		COSDictionary namedAction = new COSDictionary();
+		namedAction.setItem(COSName.TYPE, COSName.getPDFName("Action"));
+		namedAction.setItem(COSName.S, COSName.getPDFName("Named"));
+		
+		return namedAction;
+	}
+	
+	@Test
+	public void testFirstPage() throws Exception {
+		COSDictionary namedAction = createNamedAction();
+		namedAction.setItem(COSName.N, COSName.getPDFName(PreflightConstants.ACTION_DICTIONARY_VALUE_ATYPE_NAMED_FIRST));
+		valid(namedAction, true);
+	}
+
+	@Test
+	public void testLastPage() throws Exception {
+		COSDictionary namedAction = createNamedAction();
+		namedAction.setItem(COSName.N, COSName.getPDFName(PreflightConstants.ACTION_DICTIONARY_VALUE_ATYPE_NAMED_LAST));
+		valid(namedAction, true);
+	}
+
+	@Test
+	public void testNextPage() throws Exception {
+		COSDictionary namedAction = createNamedAction();
+		namedAction.setItem(COSName.N, COSName.getPDFName(PreflightConstants.ACTION_DICTIONARY_VALUE_ATYPE_NAMED_NEXT));
+		valid(namedAction, true);
+	}
+
+	@Test
+	public void testPrevPage() throws Exception {
+		COSDictionary namedAction = createNamedAction();
+		namedAction.setItem(COSName.N, COSName.getPDFName(PreflightConstants.ACTION_DICTIONARY_VALUE_ATYPE_NAMED_PREV));
+		valid(namedAction, true);
+	}
+
+	@Test
+	public void testMissingN() throws Exception {
+		COSDictionary namedAction = createNamedAction();
+		valid(namedAction, false, PreflightConstants.ERROR_ACTION_MISING_KEY);
+	}
+	
+	@Test
+	public void testForbiddenN() throws Exception {
+		COSDictionary namedAction = createNamedAction();
+		namedAction.setItem(COSName.N, COSName.getPDFName("unknown"));
+		valid(namedAction, false, PreflightConstants.ERROR_ACTION_FORBIDDEN_ACTIONS_NAMED);
+	}
+}

Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestNamedAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestSubmitAction.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestSubmitAction.java?rev=1370929&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestSubmitAction.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestSubmitAction.java Wed Aug  8 20:08:31 2012
@@ -0,0 +1,65 @@
+/*****************************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ ****************************************************************************/
+
+package org.apache.pdfbox.preflight.action.pdfa1b;
+
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.common.filespecification.PDFileSpecification;
+import org.apache.pdfbox.preflight.PreflightConstants;
+import org.junit.Test;
+
+public class TestSubmitAction extends AbstractTestAction {
+	
+	protected COSDictionary createSubmitAction() {
+		COSDictionary action = new COSDictionary();
+		action.setItem(COSName.TYPE, COSName.getPDFName("Action"));
+		action.setItem(COSName.S, COSName.getPDFName("SubmitForm"));
+		action.setItem(COSName.F, new PDFileSpecification() {
+			public COSBase getCOSObject() {
+				return COSName.getPDFName("value");
+			}
+			@Override
+			public void setFile(String file) {
+			}
+			@Override
+			public String getFile() {
+				return null;
+			}
+		});
+		return action;
+	}
+	
+	@Test
+	public void test() throws Exception {
+		COSDictionary action = createSubmitAction();
+		valid(action, true);
+	}
+	
+	@Test
+	public void testMissngF() throws Exception {
+		COSDictionary action = createSubmitAction();
+		action.removeItem(COSName.F);
+		valid(action, false, PreflightConstants.ERROR_ACTION_MISING_KEY);
+	}
+
+}

Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestSubmitAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestThreadAction.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestThreadAction.java?rev=1370929&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestThreadAction.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestThreadAction.java Wed Aug  8 20:08:31 2012
@@ -0,0 +1,58 @@
+/*****************************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ ****************************************************************************/
+
+package org.apache.pdfbox.preflight.action.pdfa1b;
+
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.preflight.PreflightConstants;
+import org.junit.Test;
+
+public class TestThreadAction extends AbstractTestAction {
+	
+	protected COSDictionary createSubmitAction() {
+		COSDictionary action = new COSDictionary();
+		action.setItem(COSName.TYPE, COSName.getPDFName("Action"));
+		action.setItem(COSName.S, COSName.getPDFName("Thread"));
+		action.setInt(COSName.D, 1);
+		return action;
+	}
+	
+	@Test
+	public void test() throws Exception {
+		COSDictionary action = createSubmitAction();
+		valid(action, true);
+	}
+	
+	@Test
+	public void testMissingD() throws Exception {
+		COSDictionary action = createSubmitAction();
+		action.removeItem(COSName.D);
+		valid(action, false, PreflightConstants.ERROR_ACTION_MISING_KEY);
+	}
+	
+	@Test
+	public void testInvalidD() throws Exception {
+		COSDictionary action = createSubmitAction();
+		action.setBoolean(COSName.D, false);
+		valid(action, false, PreflightConstants.ERROR_ACTION_INVALID_TYPE);
+	}
+}

Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestThreadAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestUriAction.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestUriAction.java?rev=1370929&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestUriAction.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestUriAction.java Wed Aug  8 20:08:31 2012
@@ -0,0 +1,73 @@
+/*****************************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ ****************************************************************************/
+
+package org.apache.pdfbox.preflight.action.pdfa1b;
+
+import java.util.Arrays;
+
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.interactive.action.type.PDAction;
+import org.apache.pdfbox.pdmodel.interactive.action.type.PDActionJavaScript;
+import org.apache.pdfbox.pdmodel.interactive.action.type.PDActionURI;
+import org.apache.pdfbox.preflight.PreflightConstants;
+import org.junit.Test;
+
+public class TestUriAction extends AbstractTestAction {
+	
+	protected PDActionURI createAction() {
+		PDActionURI action = new PDActionURI();
+		action.setURI("http://www.apache.org");
+		return action;
+	}
+	
+	@Test
+	public void test() throws Exception {
+		PDAction action = createAction();
+		valid(action, true);
+	}
+	
+	@Test
+	public void testMissingURI() throws Exception {
+		PDActionURI action = new PDActionURI();
+		valid(action, false, PreflightConstants.ERROR_ACTION_MISING_KEY);
+	}
+	
+	@Test
+	public void testInvalidURI() throws Exception {
+		PDActionURI action = new PDActionURI();
+		action.getCOSDictionary().setBoolean(COSName.URI, true);
+		valid(action, false, PreflightConstants.ERROR_ACTION_INVALID_TYPE);
+	}
+	
+	@Test
+	public void testNextValid() throws Exception {
+		PDActionURI action = createAction();
+		action.setNext(Arrays.asList(createAction()));
+		valid(action, true);
+	}
+
+	@Test
+	public void testNextInvalid() throws Exception {
+		PDActionURI action = createAction();
+		action.setNext(Arrays.asList(new PDActionJavaScript()));
+		valid(action, false, PreflightConstants.ERROR_ACTION_FORBIDDEN_ACTIONS_EXPLICITLY_FORBIDDEN);
+	}
+}

Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/action/pdfa1b/TestUriAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: pdfbox/trunk/preflight/src/test/resources/pdfa-with-annotations-square.pdf
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/resources/pdfa-with-annotations-square.pdf?rev=1370929&view=auto
==============================================================================
Binary file - no diff available.

Propchange: pdfbox/trunk/preflight/src/test/resources/pdfa-with-annotations-square.pdf
------------------------------------------------------------------------------
    svn:executable = *

Propchange: pdfbox/trunk/preflight/src/test/resources/pdfa-with-annotations-square.pdf
------------------------------------------------------------------------------
    svn:mime-type = application/pdf