incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From svanteschub...@apache.org
Subject svn commit: r1802473 - in /incubator/odf/trunk/validator: ./ src/main/java/org/odftoolkit/odfvalidator/ src/test/java/org/odftoolkit/odfvalidator/ src/test/java/org/odftoolkit/odfvalidator/jar/
Date Thu, 20 Jul 2017 11:20:54 GMT
Author: svanteschubert
Date: Thu Jul 20 11:20:54 2017
New Revision: 1802473

URL: http://svn.apache.org/viewvc?rev=1802473&view=rev
Log:
#ODFTOOLKIT-461# Patch by Michael Stahl - Fix for ODF valdiator command line handling with
integratioan tests based on the JAR

Added:
    incubator/odf/trunk/validator/src/test/java/org/odftoolkit/odfvalidator/jar/
    incubator/odf/trunk/validator/src/test/java/org/odftoolkit/odfvalidator/jar/ITJarTest.java
      - copied, changed from r1802424, incubator/odf/trunk/validator/src/test/java/org/odftoolkit/odfvalidator/InvalidPackageTest.java
Modified:
    incubator/odf/trunk/validator/pom.xml
    incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/Main.java
    incubator/odf/trunk/validator/src/test/java/org/odftoolkit/odfvalidator/InvalidPackageTest.java

Modified: incubator/odf/trunk/validator/pom.xml
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/pom.xml?rev=1802473&r1=1802472&r2=1802473&view=diff
==============================================================================
--- incubator/odf/trunk/validator/pom.xml (original)
+++ incubator/odf/trunk/validator/pom.xml Thu Jul 20 11:20:54 2017
@@ -282,18 +282,6 @@
 				<configuration>
 					<archive>
 						<index>true</index>
-						<!--  No custom manifest worked, neither the below..
-							<index>true</index>
-							<manifest>
-								<addClasspath>true</addClasspath>
-								<odfdomName>ODFDOM Validator</odfdomName>
-								<odfdomVersion>${project.version}</odfdomVersion>
-								<odfdomWebsite>http://incubator.apache.org/odftoolkit/conformance/ODFValidator.html</odfdomWebsite>
-								<odfdomBuiltDate>${build.timestamp}</odfdomBuiltDate>
-								<odfdomSupportedOdfVersion>1.2</odfdomSupportedOdfVersion>
-								<mainClass>org.odftoolkit.odfvalidator.Main</mainClass>
-							</manifest>
-						</archive>-->
 						<manifestEntries>
 							<version>${project.version}</version>
 						</manifestEntries>
@@ -322,15 +310,12 @@
 			</plugin>
 			<plugin>
 				<groupId>org.apache.maven.plugins</groupId>
-				<artifactId>maven-surefire-plugin</artifactId>
-				<!-- Explizit version required for fix on systemPropertyVariables -->
-				<version>2.15</version>
+				<artifactId>maven-surefire-plugin</artifactId>				
+				<version>2.20</version>
 				<configuration>
-					<systemPropertyVariables>
-						<odfdom.version>${project.version}</odfdom.version>
-						<odfdom.timestamp>${build.timestamp}</odfdom.timestamp>
-						<org.odftoolkit.odfdom.validation>org.odftoolkit.odfdom.pkg.DefaultErrorHandler</org.odftoolkit.odfdom.validation>
-					</systemPropertyVariables>
+                    <excludes>                                        
+                        <exclude>**/*.java</exclude>
+                    </excludes>
 				</configuration>
 			</plugin>
 			<plugin>
@@ -378,6 +363,29 @@
 					</excludes>
 				</configuration>
 			</plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-failsafe-plugin</artifactId>
+                <version>2.20</version>
+                <configuration>
+                    <includes>                                        
+                        <include>**/*.java</include>
+                    </includes> 
+					<systemPropertyVariables>
+						<odfvalidator.version>${project.version}</odfvalidator.version>
+						<org.odftoolkit.odfdom.validation>org.odftoolkit.odfdom.pkg.DefaultErrorHandler</org.odftoolkit.odfdom.validation>
+					</systemPropertyVariables>                                                   
   
+                </configuration>                
+                <executions>
+                    <execution>
+                        <id>failsafe-it</id>
+                        <goals>
+                            <goal>integration-test</goal>
+                            <goal>verify</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>		            
 		</plugins>
 	</build>
 	<reporting>
@@ -413,7 +421,7 @@
 			<plugin>
 				<groupId>org.apache.maven.plugins</groupId>
 				<artifactId>maven-failsafe-plugin</artifactId>
-				<version>2.19.1</version>
+				<version>2.20</version>
 				<reportSets>
 					<reportSet>
 						<id>integration-tests</id>
@@ -452,56 +460,6 @@
 		<url>http://svn.apache.org/viewvc/incubator/odf/trunk/validator</url>
 	</scm>
 	<profiles>
-		<profile>
-			<id>integration-test</id>
-			<activation>
-				<property>
-					<name>integration-test</name>
-				</property>
-			</activation>
-			<build>
-				<defaultGoal>verify</defaultGoal>
-				<plugins>
-					<plugin>
-						<groupId>org.apache.maven.plugins</groupId>
-						<artifactId>maven-failsafe-plugin</artifactId>
-						<version>2.5</version>
-						<executions>
-							<execution>
-								<id>failsafe-it</id>
-								<phase>integration-test</phase>
-								<goals>
-									<goal>integration-test</goal>
-									<goal>verify</goal>
-								</goals>
-								<configuration>
-									<classesDirectory>${basedir}/target/odfdom.jar</classesDirectory>
-									<systemPropertyVariables>
-										<testresourcefolder>performance</testresourcefolder>
-										<executetimes>1</executetimes>
-										<testflag>test</testflag>
-									</systemPropertyVariables>
-								</configuration>
-							</execution>
-						</executions>
-					</plugin>
-					<plugin>
-						<groupId>org.apache.maven.plugins</groupId>
-						<artifactId>maven-surefire-plugin</artifactId>
-						<!-- Explizit version required for fix on systemPropertyVariables -->
-						<version>2.19.1</version>
-						<configuration>
-							<systemPropertyVariables>
-								<odfdom.version>${project.version}</odfdom.version>
-								<odfdom.timestamp>${build.timestamp}</odfdom.timestamp>
-								<org.odftoolkit.odfdom.validation>true</org.odftoolkit.odfdom.validation>
-							</systemPropertyVariables>
-							<skip>true</skip>
-						</configuration>
-					</plugin>
-				</plugins>
-			</build>
-		</profile>
 		<!-- Profile for deploying to the Sonatype repository, which
   requires GPG signatures 
   see

Modified: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/Main.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/Main.java?rev=1802473&r1=1802472&r2=1802473&view=diff
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/Main.java (original)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/Main.java Thu
Jul 20 11:20:54 2017
@@ -1,20 +1,20 @@
 /************************************************************************
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
- * 
+ *
  * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
- * 
+ *
  * Use is subject to license terms.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy
  * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
  * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
- * 
+ *
  * 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.
  *
@@ -39,16 +39,16 @@ import java.util.Vector;
 public class Main {
 
     private static final String VERSION="1.1.4";
-    
+
     /** Creates a new instance of Main */
     public Main() {
     }
-    
+
     /**
      * @param aArgs the command line arguments
      */
     public static void main(String[] aArgs) {
-        
+
         String aConfigFileName = null;
         String aFilterFileName = null;
         String aStrictSchemaFileName = null;
@@ -215,11 +215,11 @@ public class Main {
             System.out.println( VERSION );
             return;
         }
-        
+
         try
         {
             // Print generator (does not require config file)
-            if( bPrintGenerator ) 
+            if( bPrintGenerator )
             {
                 MetaInformation aMetaInformation = new MetaInformation( System.out );
                 Iterator<String> aIter = aFileNames.iterator();
@@ -227,8 +227,10 @@ public class Main {
                     aMetaInformation.getInformation(aIter.next());
                 return;
             }
-            
-            // Read configuration
+
+            // Read configuration - by default aConfig is null, so the version
+            // will be read from the input file in
+            // ODFPackageValidator.getVersion() and config created based on that
             Configuration aConfig = null;
             if( aConfigFileName != null )
             {
@@ -260,7 +262,12 @@ public class Main {
                 }
             }
 
-            if( aConfig == null )
+            // if schema files specified, only use exactly those schema files
+            if (aConfig == null
+                && (   aStrictSchemaFileName != null
+                    || aSchemaFileName != null
+                    || aManifestSchemaFileName != null
+                    || aDSigSchemaFileName != null))
             {
                 aConfig = new Configuration();
             }
@@ -305,7 +312,7 @@ public class Main {
             System.out.println( "Validation aborted." );
         }
     }
-    
+
     private static void printUsage()
     {
         System.out.println( "usage: odfvalidator -g <odffiles>");

Modified: incubator/odf/trunk/validator/src/test/java/org/odftoolkit/odfvalidator/InvalidPackageTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/test/java/org/odftoolkit/odfvalidator/InvalidPackageTest.java?rev=1802473&r1=1802472&r2=1802473&view=diff
==============================================================================
--- incubator/odf/trunk/validator/src/test/java/org/odftoolkit/odfvalidator/InvalidPackageTest.java
(original)
+++ incubator/odf/trunk/validator/src/test/java/org/odftoolkit/odfvalidator/InvalidPackageTest.java
Thu Jul 20 11:20:54 2017
@@ -1,4 +1,4 @@
-/************************************************************************
+/** **********************************************************************
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
  *
@@ -18,111 +18,113 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
- ************************************************************************/
+ *********************************************************************** */
 package org.odftoolkit.odfvalidator;
 
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.util.logging.Level;
 import org.junit.Assert;
 import org.junit.Test;
 
-/** Test some invalid packages.
+/**
+ * Test some invalid packages.
  */
 public class InvalidPackageTest extends OdfValidatorTestBase {
 
-	@Test
-	public void validatePackage1() {
-		String output = "";
-		try {
-			String name = "testInvalidPkg1.odt";
-			output = doValidation(name, null);
-		} catch (Throwable t) {
-			t.printStackTrace();
-			Assert.fail(t.toString());
-		}
-		Assert.assertTrue(output.contains("testInvalidPkg1.odt/mimetype:  Error: The file 'mimetype'
is not the first file in the ODF package"));
-		Assert.assertTrue(output.contains("testInvalidPkg1.odt/mimetype:  Error: The file 'mimetype'
shall not be compressed"));
-		Assert.assertTrue(output.contains("testInvalidPkg1.odt/mimetype:  Error: There shall be
no extra field for the 'mimetype' file"));
-		Assert.assertTrue(output.contains("testInvalidPkg1.odt/META-INF/manifest.xml:  Error: The
file 'Configurations2/accelerator/current.xml' shall not be listed in the 'META-INF/manifest.xml'
file as it does not exist in the ODF package"));
-		Assert.assertTrue(output.contains("testInvalidPkg1.odt:  Info: 7 errors, 10 warnings"));
-	}
-
-	@Test
-	public void validatePackage1_V1_1() {
-		String output = "";
-		try {
-			String name = "testInvalidPkg1.odt";
-			output = doValidation(name, OdfVersion.V1_1);
-		} catch (Throwable t) {
-			t.printStackTrace();
-			Assert.fail(t.toString());
-		}
-		Assert.assertTrue(output.contains("testInvalidPkg1.odt/mimetype:  Warning: The file 'mimetype'
is not the first file in the ODF package"));
-		Assert.assertTrue(output.contains("testInvalidPkg1.odt/mimetype:  Error: The file 'mimetype'
shall not be compressed"));
-		Assert.assertTrue(output.contains("testInvalidPkg1.odt/mimetype:  Error: There shall be
no extra field for the 'mimetype' file"));
-		Assert.assertTrue(output.contains("testInvalidPkg1.odt/META-INF/manifest.xml:  Error: The
file 'Configurations2/accelerator/current.xml' shall not be listed in the 'META-INF/manifest.xml'
file as it does not exist in the ODF package"));
-		Assert.assertTrue(output.contains("testInvalidPkg1.odt:  Info: 10 errors, 11 warnings"));
-	}
-
-	@Test
-	public void validatePackage2() {
-		String output = "";
-		try {
-			String name = "testInvalidPkg2.odt";
-			output = doValidation(name, null);
-		} catch (Throwable t) {
-			t.printStackTrace();
-			Assert.fail(t.toString());
-		}
-		Assert.assertTrue(output.contains("testInvalidPkg2.odt/mimetype:  Error: The ODF package
'testInvalidPkg2.odt' contains no 'mimetype' file"));
-		Assert.assertTrue(output.contains("testInvalidPkg2.odt/META-INF/manifest.xml:  Error: The
file 'Configurations2/accelerator/current.xml' shall not be listed in the 'META-INF/manifest.xml'
file as it does not exist in the ODF package"));
-		Assert.assertTrue(output.contains("testInvalidPkg2.odt/META-INF/manifest.xml:  Error: The
file 'not_in_manifest' shall be listed in the 'META-INF/manifest.xml' file as it exists in
the ODF package"));
-		Assert.assertTrue(output.contains("testInvalidPkg2.odt:  Info: 5 errors, 10 warnings"));
-	}
-
-	@Test
-	public void validatePackage2_V1_1() {
-		String output = "";
-		try {
-			String name = "testInvalidPkg2.odt";
-			output = doValidation(name, OdfVersion.V1_1);
-		} catch (Throwable t) {
-			t.printStackTrace();
-			Assert.fail(t.toString());
-		}
-		Assert.assertTrue(output.contains("testInvalidPkg2.odt/mimetype:  Warning: The ODF package
'testInvalidPkg2.odt' contains no 'mimetype' file"));
-		Assert.assertTrue(output.contains("testInvalidPkg2.odt/META-INF/manifest.xml:  Error: The
file 'Configurations2/accelerator/current.xml' shall not be listed in the 'META-INF/manifest.xml'
file as it does not exist in the ODF package"));
-		Assert.assertTrue(output.contains("testInvalidPkg2.odt/META-INF/manifest.xml:  Warning:
The file 'not_in_manifest' shall be listed in the 'META-INF/manifest.xml' file as it exists
in the ODF package"));
-		Assert.assertTrue(output.contains("testInvalidPkg2.odt:  Info: 7 errors, 12 warnings"));
-	}
-
-	@Test
-	public void validatePackage3() {
-		String output = "";
-		try {
-			String name = "testInvalidPkg3.odt";
-			output = doValidation(name, null);
-		} catch (Throwable t) {
-			t.printStackTrace();
-			Assert.fail(t.toString());
-		}
-		Assert.assertTrue("Output of validatePackage3(): " + output, output.contains("Error: The
ODF package 'testInvalidPkg3.odt' shall contain the 'META-INF/manifest.xml' file"));
-		Assert.assertTrue("Output of validatePackage3(): " + output, output.contains("testInvalidPkg3.odt:
 Info: 3 errors, no warnings"));
-	}
-
-	@Test
-	public void validateEncryptedODT() {
-		String output = "";
-		try {
+    @Test
+    public void validatePackage1() {
+        String output = "";
+        try {
+            String name = "testInvalidPkg1.odt";
+            output = doValidation(name, null);
+        } catch (Throwable t) {
+            t.printStackTrace();
+            Assert.fail(t.toString());
+        }
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt/mimetype:  Error: The file
'mimetype' is not the first file in the ODF package"));
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt/mimetype:  Error: The file
'mimetype' shall not be compressed"));
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt/mimetype:  Error: There shall
be no extra field for the 'mimetype' file"));
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt/META-INF/manifest.xml:  Error:
The file 'Configurations2/accelerator/current.xml' shall not be listed in the 'META-INF/manifest.xml'
file as it does not exist in the ODF package"));
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt:  Info: 7 errors, 10 warnings"));
+    }
+
+    @Test
+    public void validatePackage1_V1_1() {
+        String output = "";
+        try {
+            String name = "testInvalidPkg1.odt";
+            output = doValidation(name, OdfVersion.V1_1);
+        } catch (Throwable t) {
+            t.printStackTrace();
+            Assert.fail(t.toString());
+        }
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt/mimetype:  Warning: The file
'mimetype' is not the first file in the ODF package"));
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt/mimetype:  Error: The file
'mimetype' shall not be compressed"));
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt/mimetype:  Error: There shall
be no extra field for the 'mimetype' file"));
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt/META-INF/manifest.xml:  Error:
The file 'Configurations2/accelerator/current.xml' shall not be listed in the 'META-INF/manifest.xml'
file as it does not exist in the ODF package"));
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt:  Info: 10 errors, 11 warnings"));
+    }
+
+    @Test
+    public void validatePackage2() {
+        String output = "";
+        try {
+            String name = "testInvalidPkg2.odt";
+            output = doValidation(name, null);
+        } catch (Throwable t) {
+            t.printStackTrace();
+            Assert.fail(t.toString());
+        }
+        Assert.assertTrue(output.contains("testInvalidPkg2.odt/mimetype:  Error: The ODF
package 'testInvalidPkg2.odt' contains no 'mimetype' file"));
+        Assert.assertTrue(output.contains("testInvalidPkg2.odt/META-INF/manifest.xml:  Error:
The file 'Configurations2/accelerator/current.xml' shall not be listed in the 'META-INF/manifest.xml'
file as it does not exist in the ODF package"));
+        Assert.assertTrue(output.contains("testInvalidPkg2.odt/META-INF/manifest.xml:  Error:
The file 'not_in_manifest' shall be listed in the 'META-INF/manifest.xml' file as it exists
in the ODF package"));
+        Assert.assertTrue(output.contains("testInvalidPkg2.odt:  Info: 5 errors, 10 warnings"));
+    }
+
+    @Test
+    public void validatePackage2_V1_1() {
+        String output = "";
+        try {
+            String name = "testInvalidPkg2.odt";
+            output = doValidation(name, OdfVersion.V1_1);
+        } catch (Throwable t) {
+            t.printStackTrace();
+            Assert.fail(t.toString());
+        }
+        Assert.assertTrue(output.contains("testInvalidPkg2.odt/mimetype:  Warning: The ODF
package 'testInvalidPkg2.odt' contains no 'mimetype' file"));
+        Assert.assertTrue(output.contains("testInvalidPkg2.odt/META-INF/manifest.xml:  Error:
The file 'Configurations2/accelerator/current.xml' shall not be listed in the 'META-INF/manifest.xml'
file as it does not exist in the ODF package"));
+        Assert.assertTrue(output.contains("testInvalidPkg2.odt/META-INF/manifest.xml:  Warning:
The file 'not_in_manifest' shall be listed in the 'META-INF/manifest.xml' file as it exists
in the ODF package"));
+        Assert.assertTrue(output.contains("testInvalidPkg2.odt:  Info: 7 errors, 12 warnings"));
+    }
+
+    @Test
+    public void validatePackage3() {
+        String output = "";
+        try {
+            String name = "testInvalidPkg3.odt";
+            output = doValidation(name, null);
+        } catch (Throwable t) {
+            t.printStackTrace();
+            Assert.fail(t.toString());
+        }
+        Assert.assertTrue("Output of validatePackage3(): " + output, output.contains("Error:
The ODF package 'testInvalidPkg3.odt' shall contain the 'META-INF/manifest.xml' file"));
+        Assert.assertTrue("Output of validatePackage3(): " + output, output.contains("testInvalidPkg3.odt:
 Info: 3 errors, no warnings"));
+    }
+
+    @Test
+    public void validateEncryptedODT() {
+        String output = "";
+        try {
             // password: hello
             String name = "encrypted-with-pwd_hello.odt";
-			output = doValidation(name, null);
-		} catch (Throwable t) {
-                StringWriter errors = new StringWriter();
-                t.printStackTrace(new PrintWriter(errors));
-			Assert.fail(t.toString() + "\n" + errors.toString());
-		}
-		Assert.assertTrue(output.contains("Fatal: ZIP entry 'mimetype': only DEFLATED entries can
have EXT descriptor"));
-        java.util.logging.Logger.getLogger(getClass().getName()).info("Test result:\n"+ output);
-	}
+            output = doValidation(name, null);
+        } catch (Exception t) {
+            StringWriter errors = new StringWriter();
+            t.printStackTrace(new PrintWriter(errors));
+            Assert.fail(t.toString() + "\n" + errors.toString());
+        }
+        Assert.assertTrue(output.contains("Fatal: ZIP entry 'mimetype': only DEFLATED entries
can have EXT descriptor"));
+        java.util.logging.Logger.getLogger(getClass().getName()).log(Level.INFO, "Test result:\n{0}",
output);
+    }
 }

Copied: incubator/odf/trunk/validator/src/test/java/org/odftoolkit/odfvalidator/jar/ITJarTest.java
(from r1802424, incubator/odf/trunk/validator/src/test/java/org/odftoolkit/odfvalidator/InvalidPackageTest.java)
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/test/java/org/odftoolkit/odfvalidator/jar/ITJarTest.java?p2=incubator/odf/trunk/validator/src/test/java/org/odftoolkit/odfvalidator/jar/ITJarTest.java&p1=incubator/odf/trunk/validator/src/test/java/org/odftoolkit/odfvalidator/InvalidPackageTest.java&r1=1802424&r2=1802473&rev=1802473&view=diff
==============================================================================
--- incubator/odf/trunk/validator/src/test/java/org/odftoolkit/odfvalidator/InvalidPackageTest.java
(original)
+++ incubator/odf/trunk/validator/src/test/java/org/odftoolkit/odfvalidator/jar/ITJarTest.java
Thu Jul 20 11:20:54 2017
@@ -1,4 +1,4 @@
-/************************************************************************
+/** **********************************************************************
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
  *
@@ -18,111 +18,61 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
- ************************************************************************/
-package org.odftoolkit.odfvalidator;
+ *********************************************************************** */
+package org.odftoolkit.odfvalidator.jar;
 
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.util.logging.Level;
 import org.junit.Assert;
 import org.junit.Test;
 
-/** Test some invalid packages.
+/**
+ * Integration test to validate via JAR testing command line parameters on
+ * (an invalid) ODF package.
  */
-public class InvalidPackageTest extends OdfValidatorTestBase {
-
-	@Test
-	public void validatePackage1() {
-		String output = "";
-		try {
-			String name = "testInvalidPkg1.odt";
-			output = doValidation(name, null);
-		} catch (Throwable t) {
-			t.printStackTrace();
-			Assert.fail(t.toString());
-		}
-		Assert.assertTrue(output.contains("testInvalidPkg1.odt/mimetype:  Error: The file 'mimetype'
is not the first file in the ODF package"));
-		Assert.assertTrue(output.contains("testInvalidPkg1.odt/mimetype:  Error: The file 'mimetype'
shall not be compressed"));
-		Assert.assertTrue(output.contains("testInvalidPkg1.odt/mimetype:  Error: There shall be
no extra field for the 'mimetype' file"));
-		Assert.assertTrue(output.contains("testInvalidPkg1.odt/META-INF/manifest.xml:  Error: The
file 'Configurations2/accelerator/current.xml' shall not be listed in the 'META-INF/manifest.xml'
file as it does not exist in the ODF package"));
-		Assert.assertTrue(output.contains("testInvalidPkg1.odt:  Info: 7 errors, 10 warnings"));
-	}
-
-	@Test
-	public void validatePackage1_V1_1() {
-		String output = "";
-		try {
-			String name = "testInvalidPkg1.odt";
-			output = doValidation(name, OdfVersion.V1_1);
-		} catch (Throwable t) {
-			t.printStackTrace();
-			Assert.fail(t.toString());
-		}
-		Assert.assertTrue(output.contains("testInvalidPkg1.odt/mimetype:  Warning: The file 'mimetype'
is not the first file in the ODF package"));
-		Assert.assertTrue(output.contains("testInvalidPkg1.odt/mimetype:  Error: The file 'mimetype'
shall not be compressed"));
-		Assert.assertTrue(output.contains("testInvalidPkg1.odt/mimetype:  Error: There shall be
no extra field for the 'mimetype' file"));
-		Assert.assertTrue(output.contains("testInvalidPkg1.odt/META-INF/manifest.xml:  Error: The
file 'Configurations2/accelerator/current.xml' shall not be listed in the 'META-INF/manifest.xml'
file as it does not exist in the ODF package"));
-		Assert.assertTrue(output.contains("testInvalidPkg1.odt:  Info: 10 errors, 11 warnings"));
-	}
-
-	@Test
-	public void validatePackage2() {
-		String output = "";
-		try {
-			String name = "testInvalidPkg2.odt";
-			output = doValidation(name, null);
-		} catch (Throwable t) {
-			t.printStackTrace();
-			Assert.fail(t.toString());
-		}
-		Assert.assertTrue(output.contains("testInvalidPkg2.odt/mimetype:  Error: The ODF package
'testInvalidPkg2.odt' contains no 'mimetype' file"));
-		Assert.assertTrue(output.contains("testInvalidPkg2.odt/META-INF/manifest.xml:  Error: The
file 'Configurations2/accelerator/current.xml' shall not be listed in the 'META-INF/manifest.xml'
file as it does not exist in the ODF package"));
-		Assert.assertTrue(output.contains("testInvalidPkg2.odt/META-INF/manifest.xml:  Error: The
file 'not_in_manifest' shall be listed in the 'META-INF/manifest.xml' file as it exists in
the ODF package"));
-		Assert.assertTrue(output.contains("testInvalidPkg2.odt:  Info: 5 errors, 10 warnings"));
-	}
-
-	@Test
-	public void validatePackage2_V1_1() {
-		String output = "";
-		try {
-			String name = "testInvalidPkg2.odt";
-			output = doValidation(name, OdfVersion.V1_1);
-		} catch (Throwable t) {
-			t.printStackTrace();
-			Assert.fail(t.toString());
-		}
-		Assert.assertTrue(output.contains("testInvalidPkg2.odt/mimetype:  Warning: The ODF package
'testInvalidPkg2.odt' contains no 'mimetype' file"));
-		Assert.assertTrue(output.contains("testInvalidPkg2.odt/META-INF/manifest.xml:  Error: The
file 'Configurations2/accelerator/current.xml' shall not be listed in the 'META-INF/manifest.xml'
file as it does not exist in the ODF package"));
-		Assert.assertTrue(output.contains("testInvalidPkg2.odt/META-INF/manifest.xml:  Warning:
The file 'not_in_manifest' shall be listed in the 'META-INF/manifest.xml' file as it exists
in the ODF package"));
-		Assert.assertTrue(output.contains("testInvalidPkg2.odt:  Info: 7 errors, 12 warnings"));
-	}
-
-	@Test
-	public void validatePackage3() {
-		String output = "";
-		try {
-			String name = "testInvalidPkg3.odt";
-			output = doValidation(name, null);
-		} catch (Throwable t) {
-			t.printStackTrace();
-			Assert.fail(t.toString());
-		}
-		Assert.assertTrue("Output of validatePackage3(): " + output, output.contains("Error: The
ODF package 'testInvalidPkg3.odt' shall contain the 'META-INF/manifest.xml' file"));
-		Assert.assertTrue("Output of validatePackage3(): " + output, output.contains("testInvalidPkg3.odt:
 Info: 3 errors, no warnings"));
-	}
-
-	@Test
-	public void validateEncryptedODT() {
-		String output = "";
-		try {
-            // password: hello
-            String name = "encrypted-with-pwd_hello.odt";
-			output = doValidation(name, null);
-		} catch (Throwable t) {
-                StringWriter errors = new StringWriter();
-                t.printStackTrace(new PrintWriter(errors));
-			Assert.fail(t.toString() + "\n" + errors.toString());
-		}
-		Assert.assertTrue(output.contains("Fatal: ZIP entry 'mimetype': only DEFLATED entries can
have EXT descriptor"));
-        java.util.logging.Logger.getLogger(getClass().getName()).info("Test result:\n"+ output);
-	}
+public class ITJarTest {
+    private static final String JAR_NAME_SUFFIX = "-jar-with-dependencies.jar";
+    private static final String JAR_NAME_PREFIX = "odfvalidator-";
+    private static final String ODT_NAME = "testInvalidPkg2.odt"; // password: hello
+    private static final String FATAL_PREFIX = "Fatal: ";
+
+    @Test
+    public void validateOdtViaCommandline() {
+        String output = "";
+        try {
+            // Command line call might be:
+            // java -jar .m2/repository/org/apache/odftoolkit/odfvalidator/1.2.0-incubating-SNAPSHOT/odfvalidator-1.2.0-incubating-SNAPSHOT-jar-with-dependencies.jar
foo.odt
+            String odfvalidatorVersion = System.getProperty("odfvalidator.version");
+            ProcessBuilder builder = new ProcessBuilder(
+                "java", "-jar", "target" + File.separatorChar + JAR_NAME_PREFIX + odfvalidatorVersion
+ JAR_NAME_SUFFIX,
+                "target" + File.separatorChar + "test-classes" + File.separatorChar + ODT_NAME);
+            builder.redirectErrorStream(true);
+            Process p = builder.start();
+            BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
+            String line;
+            while (true) {
+                line = r.readLine();
+                if (line == null) {
+                    break;
+                }
+                output = output.concat(line + "\n");
+                if (output.contains(FATAL_PREFIX) || output.contains("Exception")) {
+                    throw new IOException(output);
+                }
+            }
+        } catch (IOException t) {
+            StringWriter errors = new StringWriter();
+            t.printStackTrace(new PrintWriter(errors));
+            Assert.fail(t.toString() + "\n" + errors.toString());
+        }
+        java.util.logging.Logger.getLogger(getClass().getName()).log(Level.INFO, "Test result:\n{0}",
output);
+        Assert.assertTrue(output.contains("contains no 'mimetype' file"));
+        Assert.assertTrue(output.contains("testInvalidPkg2.odt/META-INF/manifest.xml:  Error:
The file 'Configurations2/accelerator/current.xml' shall not be listed in the 'META-INF/manifest.xml'
file as it does not exist in the ODF package"));
+        Assert.assertTrue(output.contains("testInvalidPkg2.odt/META-INF/manifest.xml:  Error:
The file 'not_in_manifest' shall be listed in the 'META-INF/manifest.xml' file as it exists
in the ODF package"));
+    }
 }



Mime
View raw message