package org.apache.poi.xwpf;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
import org.apache.poi.xwpf.extractor.TestXWPFWordExtractor;
import org.apache.poi.xwpf.model.TestXWPFHeaderFooterPolicy;
import org.apache.poi.xwpf.usermodel.TestXWPFDocument;
import org.apache.poi.xwpf.usermodel.TestXWPFRun;
import org.apache.poi.xwpf.usermodel.TestXWPFStyles;
import org.apache.poi.xwpf.usermodel.TestXWPFTable;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
/**
* Collects all tests for <tt>org.apache.poi.xwpf</tt> and sub-packages.
- *
- * @author Josh Micich
*/
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ TestXWPFBugs.class,
+ TestXWPFDocument.class,
+ TestXWPFWordExtractor.class,
+ TestXWPFHeaderFooterPolicy.class,
+ TestXWPFHeader.class,
+ TestXWPFHeadings.class,
+ TestXWPFParagraph.class,
+ TestXWPFRun.class,
+ TestXWPFTable.class,
+ TestXWPFStyles.class,
+ TestXWPFPictureData.class,
+ TestXWPFNumbering.class,
+ TestAllExtendedProperties.class,
+ TestPackageCorePropertiesGetKeywords.class
+})
public final class AllXWPFTests {
-
- public static Test suite() {
- TestSuite result = new TestSuite(AllXWPFTests.class.getName());
- result.addTestSuite(TestXWPFBugs.class);
- result.addTestSuite(TestXWPFDocument.class);
- result.addTestSuite(TestXWPFWordExtractor.class);
- result.addTestSuite(TestXWPFHeaderFooterPolicy.class);
- result.addTestSuite(TestXWPFHeader.class);
- result.addTestSuite(TestXWPFHeadings.class);
- result.addTestSuite(TestXWPFParagraph.class);
- result.addTestSuite(TestXWPFRun.class);
- result.addTestSuite(TestXWPFTable.class);
- result.addTestSuite(TestXWPFStyles.class);
- result.addTestSuite(TestXWPFPictureData.class);
- result.addTestSuite(TestXWPFNumbering.class);
- result.addTestSuite(TestAllExtendedProperties.class);
- result.addTestSuite(TestPackageCorePropertiesGetKeywords.class);
- return result;
- }
-}
+}
\ No newline at end of file
package org.apache.poi.xwpf;\r
\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertNotNull;\r
+import static org.junit.Assert.assertTrue;\r
+\r
import java.io.File;\r
import java.io.InputStream;\r
\r
-import junit.framework.TestCase;\r
+import javax.crypto.Cipher;\r
\r
import org.apache.poi.POIDataSamples;\r
-import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;\r
import org.apache.poi.openxml4j.opc.OPCPackage;\r
import org.apache.poi.poifs.crypt.Decryptor;\r
import org.apache.poi.poifs.crypt.EncryptionHeader;\r
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;\r
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;\r
import org.apache.poi.xwpf.usermodel.XWPFDocument;\r
+import org.junit.Assume;\r
+import org.junit.Test;\r
\r
-public class TestXWPFBugs extends TestCase {\r
+public class TestXWPFBugs {\r
/**\r
* A word document that's encrypted with non-standard\r
* Encryption options, and no cspname section. See bug 53475\r
*/\r
- public void test53475NoCSPName() throws Exception {\r
- try {\r
- Biff8EncryptionKey.setCurrentUserPassword("solrcell");\r
- File file = POIDataSamples.getDocumentInstance().getFile("bug53475-password-is-solrcell.docx");\r
- NPOIFSFileSystem filesystem = new NPOIFSFileSystem(file, true);\r
+ @Test\r
+ public void bug53475NoCSPName() throws Exception {\r
+ File file = POIDataSamples.getDocumentInstance().getFile("bug53475-password-is-solrcell.docx");\r
+ NPOIFSFileSystem filesystem = new NPOIFSFileSystem(file, true);\r
\r
- // Check the encryption details\r
- EncryptionInfo info = new EncryptionInfo(filesystem);\r
- assertEquals(128, info.getHeader().getKeySize());\r
- assertEquals(EncryptionHeader.ALGORITHM_AES_128, info.getHeader().getAlgorithm());\r
- assertEquals(EncryptionHeader.HASH_SHA1, info.getHeader().getHashAlgorithm());\r
+ // Check the encryption details\r
+ EncryptionInfo info = new EncryptionInfo(filesystem);\r
+ assertEquals(128, info.getHeader().getKeySize());\r
+ assertEquals(EncryptionHeader.ALGORITHM_AES_128, info.getHeader().getAlgorithm());\r
+ assertEquals(EncryptionHeader.HASH_SHA1, info.getHeader().getHashAlgorithm());\r
\r
- // Check it can be decoded\r
- Decryptor d = Decryptor.getInstance(info); \r
- assertTrue("Unable to process: document is encrypted", d.verifyPassword("solrcell"));\r
+ // Check it can be decoded\r
+ Decryptor d = Decryptor.getInstance(info); \r
+ assertTrue("Unable to process: document is encrypted", d.verifyPassword("solrcell"));\r
\r
- // Check we can read the word document in that\r
- InputStream dataStream = d.getDataStream(filesystem);\r
- OPCPackage opc = OPCPackage.open(dataStream);\r
- XWPFDocument doc = new XWPFDocument(opc);\r
- XWPFWordExtractor ex = new XWPFWordExtractor(doc);\r
- String text = ex.getText();\r
- assertNotNull(text);\r
- assertEquals("This is password protected Word document.", text.trim());\r
- ex.close();\r
- } finally {\r
- Biff8EncryptionKey.setCurrentUserPassword(null);\r
- }\r
+ // Check we can read the word document in that\r
+ InputStream dataStream = d.getDataStream(filesystem);\r
+ OPCPackage opc = OPCPackage.open(dataStream);\r
+ XWPFDocument doc = new XWPFDocument(opc);\r
+ XWPFWordExtractor ex = new XWPFWordExtractor(doc);\r
+ String text = ex.getText();\r
+ assertNotNull(text);\r
+ assertEquals("This is password protected Word document.", text.trim());\r
+ ex.close();\r
}\r
\r
/**\r
* A word document with aes-256, i.e. aes is always 128 bit (= 128 bit block size),\r
* but the key can be 128/192/256 bits\r
*/\r
- public void test53475_aes256() throws Exception {\r
- try {\r
- Biff8EncryptionKey.setCurrentUserPassword("pass");\r
- File file = POIDataSamples.getDocumentInstance().getFile("bug53475-password-is-pass.docx");\r
- NPOIFSFileSystem filesystem = new NPOIFSFileSystem(file, true);\r
+ @Test\r
+ public void bug53475_aes256() throws Exception {\r
+ int maxKeyLen = Cipher.getMaxAllowedKeyLength("AES");\r
+ Assume.assumeTrue("Please install JCE Unlimited Strength Jurisdiction Policy files for AES 256", maxKeyLen == 2147483647);\r
+\r
+ File file = POIDataSamples.getDocumentInstance().getFile("bug53475-password-is-pass.docx");\r
+ NPOIFSFileSystem filesystem = new NPOIFSFileSystem(file, true);\r
\r
- // Check the encryption details\r
- EncryptionInfo info = new EncryptionInfo(filesystem);\r
- assertEquals(16, info.getHeader().getBlockSize());\r
- assertEquals(256, info.getHeader().getKeySize());\r
- assertEquals(EncryptionHeader.ALGORITHM_AES_256, info.getHeader().getAlgorithm());\r
- assertEquals(EncryptionHeader.HASH_SHA1, info.getHeader().getHashAlgorithm());\r
+ // Check the encryption details\r
+ EncryptionInfo info = new EncryptionInfo(filesystem);\r
+ assertEquals(16, info.getHeader().getBlockSize());\r
+ assertEquals(256, info.getHeader().getKeySize());\r
+ assertEquals(EncryptionHeader.ALGORITHM_AES_256, info.getHeader().getAlgorithm());\r
+ assertEquals(EncryptionHeader.HASH_SHA1, info.getHeader().getHashAlgorithm());\r
\r
- // Check it can be decoded\r
- Decryptor d = Decryptor.getInstance(info); \r
- assertTrue("Unable to process: document is encrypted", d.verifyPassword("pass"));\r
+ // Check it can be decoded\r
+ Decryptor d = Decryptor.getInstance(info); \r
+ assertTrue("Unable to process: document is encrypted", d.verifyPassword("pass"));\r
\r
- // Check we can read the word document in that\r
- InputStream dataStream = d.getDataStream(filesystem);\r
- OPCPackage opc = OPCPackage.open(dataStream);\r
- XWPFDocument doc = new XWPFDocument(opc);\r
- XWPFWordExtractor ex = new XWPFWordExtractor(doc);\r
- String text = ex.getText();\r
- assertNotNull(text);\r
- // I know ... a stupid typo, maybe next time ...\r
- assertEquals("The is a password protected document.", text.trim());\r
- ex.close();\r
- } finally {\r
- Biff8EncryptionKey.setCurrentUserPassword(null);\r
- }\r
+ // Check we can read the word document in that\r
+ InputStream dataStream = d.getDataStream(filesystem);\r
+ OPCPackage opc = OPCPackage.open(dataStream);\r
+ XWPFDocument doc = new XWPFDocument(opc);\r
+ XWPFWordExtractor ex = new XWPFWordExtractor(doc);\r
+ String text = ex.getText();\r
+ assertNotNull(text);\r
+ // I know ... a stupid typo, maybe next time ...\r
+ assertEquals("The is a password protected document.", text.trim());\r
+ ex.close();\r
}\r
}\r