diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java b/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java index 4567b12c6..c250c0e41 100644 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/TestBasics.java @@ -38,26 +38,26 @@ public final class TestBasics extends TestCase { private MAPIMessage cyrillic; private MAPIMessage chinese; - /** - * Initialize this test, load up the blank.msg mapi message. - * @throws Exception - */ - public TestBasics() throws IOException { - POIDataSamples samples = POIDataSamples.getHSMFInstance(); - simple = new MAPIMessage(samples.openResourceAsStream("simple_test_msg.msg")); - quick = new MAPIMessage(samples.openResourceAsStream("quick.msg")); - outlook30 = new MAPIMessage(samples.openResourceAsStream("outlook_30_msg.msg")); - attachments = new MAPIMessage(samples.openResourceAsStream("attachment_test_msg.msg")); - noRecipientAddress = new MAPIMessage(samples.openResourceAsStream("no_recipient_address.msg")); - unicode = new MAPIMessage(samples.openResourceAsStream("example_received_unicode.msg")); - cyrillic = new MAPIMessage(samples.openResourceAsStream("cyrillic_message.msg")); - chinese = new MAPIMessage(samples.openResourceAsStream("chinese-traditional.msg")); - } - - /** - * Can we always get the recipient's email? - */ - public void testRecipientEmail() throws Exception { + /** + * Initialize this test, load up the blank.msg mapi message. + * @throws Exception + */ + public TestBasics() throws IOException { + POIDataSamples samples = POIDataSamples.getHSMFInstance(); + simple = new MAPIMessage(samples.openResourceAsStream("simple_test_msg.msg")); + quick = new MAPIMessage(samples.openResourceAsStream("quick.msg")); + outlook30 = new MAPIMessage(samples.openResourceAsStream("outlook_30_msg.msg")); + attachments = new MAPIMessage(samples.openResourceAsStream("attachment_test_msg.msg")); + noRecipientAddress = new MAPIMessage(samples.openResourceAsStream("no_recipient_address.msg")); + unicode = new MAPIMessage(samples.openResourceAsStream("example_received_unicode.msg")); + cyrillic = new MAPIMessage(samples.openResourceAsStream("cyrillic_message.msg")); + chinese = new MAPIMessage(samples.openResourceAsStream("chinese-traditional.msg")); + } + + /** + * Can we always get the recipient's email? + */ + public void testRecipientEmail() throws Exception { assertEquals("travis@overwrittenstack.com", simple.getRecipientEmailAddress()); assertEquals("kevin.roast@alfresco.org", quick.getRecipientEmailAddress()); assertEquals("nicolas1.23456@free.fr", attachments.getRecipientEmailAddress()); @@ -71,25 +71,25 @@ public final class TestBasics extends TestCase { "debbie.payne@pnl.gov; stuart.rose@pnl.gov; randall.scarberry@pnl.gov; Leigh.Williams@pnl.gov", outlook30.getRecipientEmailAddress() ); - } - - /** - * Test subject - */ - public void testSubject() throws Exception { + } + + /** + * Test subject + */ + public void testSubject() throws Exception { assertEquals("test message", simple.getSubject()); assertEquals("Test the content transformer", quick.getSubject()); assertEquals("IN-SPIRE servers going down for a bit, back up around 8am", outlook30.getSubject()); assertEquals("test pi\u00e8ce jointe 1", attachments.getSubject()); - } - - /** - * Test message headers - */ - public void testHeaders() throws Exception { - // Simple email first - assertEquals(26, simple.getHeaders().length); - assertTrue(simple.getHeaders()[0].startsWith("Return-path:")); + } + + /** + * Test message headers + */ + public void testHeaders() throws Exception { + // Simple email first + assertEquals(26, simple.getHeaders().length); + assertTrue(simple.getHeaders()[0].startsWith("Return-path:")); assertTrue(simple.getHeaders()[1].equals("Envelope-to: travis@overwrittenstack.com")); assertTrue(simple.getHeaders()[25].startsWith("X-Antivirus-Scanner: Clean")); @@ -110,35 +110,35 @@ public final class TestBasics extends TestCase { assertTrue(outlook30.getHeaders()[0].startsWith("Microsoft Mail Internet Headers")); assertTrue(outlook30.getHeaders()[1].startsWith("x-mimeole:")); assertTrue(outlook30.getHeaders()[32].startsWith("\t\"Williams")); // May need better parsing in future - } - - /** - * Test attachments - */ - public void testAttachments() throws Exception { + } + + /** + * Test attachments + */ + public void testAttachments() throws Exception { assertEquals(0, simple.getAttachmentFiles().length); assertEquals(0, quick.getAttachmentFiles().length); assertEquals(0, outlook30.getAttachmentFiles().length); assertEquals(2, attachments.getAttachmentFiles().length); - } - - /** - * Test missing chunks. - * Use a file with no HTML body - */ - public void testMissingChunks() throws Exception { - assertEquals(false, attachments.isReturnNullOnMissingChunk()); + } - try { - attachments.getHtmlBody(); - fail(); - } catch(ChunkNotFoundException e) { - // Good - } - - attachments.setReturnNullOnMissingChunk(true); - - assertEquals(null, attachments.getHtmlBody()); + /** + * Test missing chunks. + * Use a file with no HTML body + */ + public void testMissingChunks() throws Exception { + assertEquals(false, attachments.isReturnNullOnMissingChunk()); + + try { + attachments.getHtmlBody(); + fail(); + } catch(ChunkNotFoundException e) { + // Good + } + + attachments.setReturnNullOnMissingChunk(true); + + assertEquals(null, attachments.getHtmlBody()); attachments.setReturnNullOnMissingChunk(false); @@ -148,13 +148,13 @@ public final class TestBasics extends TestCase { } catch(ChunkNotFoundException e) { // Good } - } - - /** - * More missing chunk testing, this time for - * missing recipient email address - */ - public void testMissingAddressChunk() throws Exception { + } + + /** + * More missing chunk testing, this time for + * missing recipient email address + */ + public void testMissingAddressChunk() throws Exception { assertEquals(false, noRecipientAddress.isReturnNullOnMissingChunk()); try { @@ -183,17 +183,17 @@ public final class TestBasics extends TestCase { assertEquals("New Outlook User", noRecipientAddress.getDisplayTo()); noRecipientAddress.setReturnNullOnMissingChunk(false); - } - - /** - * Test the 7 bit detection - */ - public void test7BitDetection() throws Exception { - assertEquals(false, unicode.has7BitEncodingStrings()); + } + + /** + * Test the 7 bit detection + */ + public void test7BitDetection() throws Exception { + assertEquals(false, unicode.has7BitEncodingStrings()); assertEquals(true, simple.has7BitEncodingStrings()); assertEquals(true, chinese.has7BitEncodingStrings()); assertEquals(true, cyrillic.has7BitEncodingStrings()); - } + } /** * We default to CP1252, but can sometimes do better diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/TestBlankFileRead.java b/src/scratchpad/testcases/org/apache/poi/hsmf/TestBlankFileRead.java index 430c1b8e7..79fe7ebd9 100644 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/TestBlankFileRead.java +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/TestBlankFileRead.java @@ -28,99 +28,94 @@ import junit.framework.TestCase; /** * Tests to verify that the library can read blank msg files. - * - * @author Travis Ferguson - * */ public final class TestBlankFileRead extends TestCase { - private MAPIMessage mapiMessage; + private MAPIMessage mapiMessage; - /** - * Initialize this test, load up the blank.msg mapi message. - */ - public TestBlankFileRead() throws IOException { + /** + * Initialize this test, load up the blank.msg mapi message. + */ + public TestBlankFileRead() throws IOException { POIDataSamples samples = POIDataSamples.getHSMFInstance(); - this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("blank.msg")); - } + this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("blank.msg")); + } - /** - * Check if we can read the body of the blank message, we expect "". - */ - public void testReadBody() { - try { - mapiMessage.getTextBody(); - } catch(ChunkNotFoundException exp) { - return; - } + /** + * Check if we can read the body of the blank message, we expect "". + */ + public void testReadBody() { + try { + mapiMessage.getTextBody(); + } catch(ChunkNotFoundException exp) { + return; + } - TestCase.fail("Should have thrown a ChunkNotFoundException but didn't"); - } + TestCase.fail("Should have thrown a ChunkNotFoundException but didn't"); + } - /** - * Test to see if we can read the CC Chunk. - */ - public void testReadDisplayCC() throws ChunkNotFoundException { - String obtained = mapiMessage.getDisplayCC(); - String expected = ""; + /** + * Test to see if we can read the CC Chunk. + */ + public void testReadDisplayCC() throws ChunkNotFoundException { + String obtained = mapiMessage.getDisplayCC(); + String expected = ""; - TestCase.assertEquals(expected, obtained); - } + TestCase.assertEquals(expected, obtained); + } - /** - * Test to see if we can read the CC Chunk. - */ - public void testReadDisplayTo() throws ChunkNotFoundException { - String obtained = mapiMessage.getDisplayTo(); - String expected = ""; + /** + * Test to see if we can read the CC Chunk. + */ + public void testReadDisplayTo() throws ChunkNotFoundException { + String obtained = mapiMessage.getDisplayTo(); + String expected = ""; - TestCase.assertEquals(expected, obtained); - } + TestCase.assertEquals(expected, obtained); + } - /** - * Test to see if we can read the FROM Chunk. - */ - public void testReadDisplayFrom() { - try { - mapiMessage.getDisplayFrom(); - } catch(ChunkNotFoundException exp) { - return; - } + /** + * Test to see if we can read the FROM Chunk. + */ + public void testReadDisplayFrom() { + try { + mapiMessage.getDisplayFrom(); + } catch(ChunkNotFoundException exp) { + return; + } - TestCase.fail("Should have thrown a ChunkNotFoundException but didn't"); - } + TestCase.fail("Should have thrown a ChunkNotFoundException but didn't"); + } - /** - * Test to see if we can read the CC Chunk. - */ - public void testReadDisplayBCC() throws ChunkNotFoundException { - String obtained = mapiMessage.getDisplayBCC(); - String expected = ""; + /** + * Test to see if we can read the CC Chunk. + */ + public void testReadDisplayBCC() throws ChunkNotFoundException { + String obtained = mapiMessage.getDisplayBCC(); + String expected = ""; - TestCase.assertEquals(expected, obtained); - } + TestCase.assertEquals(expected, obtained); + } - /** - * Check if we can read the subject line of the blank message, we expect "" - */ - public void testReadSubject() throws Exception { - String obtained = mapiMessage.getSubject(); - TestCase.assertEquals("", obtained); - } - - - /** - * Check if we can read the subject line of the blank message, we expect "" - */ - public void testReadConversationTopic() { - try { - mapiMessage.getConversationTopic(); - } catch(ChunkNotFoundException exp) { - return; - } - TestCase.fail("We shouldn't have a ConversationTopic node on the blank.msg file."); - } + /** + * Check if we can read the subject line of the blank message, we expect "" + */ + public void testReadSubject() throws Exception { + String obtained = mapiMessage.getSubject(); + TestCase.assertEquals("", obtained); + } + /** + * Check if we can read the subject line of the blank message, we expect "" + */ + public void testReadConversationTopic() { + try { + mapiMessage.getConversationTopic(); + } catch(ChunkNotFoundException exp) { + return; + } + TestCase.fail("We shouldn't have a ConversationTopic node on the blank.msg file."); + } } diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/TestFixedSizedProperties.java b/src/scratchpad/testcases/org/apache/poi/hsmf/TestFixedSizedProperties.java index 49a04793c..1809b6f57 100644 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/TestFixedSizedProperties.java +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/TestFixedSizedProperties.java @@ -36,70 +36,68 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem; * ones, for example Submission Dates */ public final class TestFixedSizedProperties extends POITestCase { - protected static final String messageSucceeds = "53784_succeeds.msg"; - protected static final String messageFails = "53784_fails.msg"; - private MAPIMessage mapiMessageSucceeds; - private MAPIMessage mapiMessageFails; - private POIFSFileSystem fsMessageSucceeds; - private POIFSFileSystem fsMessageFails; + protected static final String messageSucceeds = "53784_succeeds.msg"; + protected static final String messageFails = "53784_fails.msg"; + private MAPIMessage mapiMessageSucceeds; + private MAPIMessage mapiMessageFails; + private POIFSFileSystem fsMessageSucceeds; + private POIFSFileSystem fsMessageFails; - /** - * Initialize this test, load up the messages. - * - * @throws Exception - */ - public TestFixedSizedProperties() throws Exception { - POIDataSamples samples = POIDataSamples.getHSMFInstance(); - this.mapiMessageSucceeds = new MAPIMessage( - samples.openResourceAsStream(messageSucceeds)); - this.mapiMessageFails = new MAPIMessage( - samples.openResourceAsStream(messageFails)); - this.fsMessageSucceeds = new POIFSFileSystem(new FileInputStream(samples.getFile(messageSucceeds))); - this.fsMessageFails = new POIFSFileSystem(new FileInputStream(samples.getFile(messageFails))); - } + /** + * Initialize this test, load up the messages. + */ + public TestFixedSizedProperties() throws Exception { + POIDataSamples samples = POIDataSamples.getHSMFInstance(); + this.mapiMessageSucceeds = new MAPIMessage( + samples.openResourceAsStream(messageSucceeds)); + this.mapiMessageFails = new MAPIMessage( + samples.openResourceAsStream(messageFails)); + this.fsMessageSucceeds = new POIFSFileSystem(new FileInputStream(samples.getFile(messageSucceeds))); + this.fsMessageFails = new POIFSFileSystem(new FileInputStream(samples.getFile(messageFails))); + } - /** - * Test to see if we can read the Date Chunk with OutlookTextExtractor. - * TODO Work out why the Fri 22nd vs Monday 25th problem is occurring and fix - */ - public void DISABLEDtestReadMessageDateSucceedsWithOutlookTextExtractor() { - OutlookTextExtactor ext = new OutlookTextExtactor(mapiMessageSucceeds); - String text = ext.getText(); + /** + * Test to see if we can read the Date Chunk with OutlookTextExtractor. + * TODO Work out why the Fri 22nd vs Monday 25th problem is occurring and fix + */ + public void DISABLEDtestReadMessageDateSucceedsWithOutlookTextExtractor() { + OutlookTextExtactor ext = new OutlookTextExtactor(mapiMessageSucceeds); + String text = ext.getText(); - assertContains(text, "Date: Fri, 22 Jun 2012 21:32:54\n"); - } + assertContains(text, "Date: Fri, 22 Jun 2012 21:32:54\n"); + } - /** - * Test to see if we can read the Date Chunk with OutlookTextExtractor. + /** + * Test to see if we can read the Date Chunk with OutlookTextExtractor. * TODO Work out why the Thu 21st vs Monday 25th problem is occurring and fix - */ - public void DISABLEDtestReadMessageDateFailsWithOutlookTextExtractor() { - OutlookTextExtactor ext = new OutlookTextExtactor(mapiMessageFails); - String text = ext.getText(); + */ + public void DISABLEDtestReadMessageDateFailsWithOutlookTextExtractor() { + OutlookTextExtactor ext = new OutlookTextExtactor(mapiMessageFails); + String text = ext.getText(); + + assertContains(text, "Date: Thu, 21 Jun 2012 17:14:04\n"); + } - assertContains(text, "Date: Thu, 21 Jun 2012 17:14:04\n"); - } - /** * Test to see if we can read the Date Chunk with HSMFDump. * @throws IOException */ public void testReadMessageDateSucceedsWithHSMFDump() throws IOException { - PrintStream stream = new PrintStream(new ByteArrayOutputStream()); - HSMFDump dump = new HSMFDump(fsMessageSucceeds); - dump.dump(stream); + PrintStream stream = new PrintStream(new ByteArrayOutputStream()); + HSMFDump dump = new HSMFDump(fsMessageSucceeds); + dump.dump(stream); } - + /** * Test to see if we can read the Date Chunk with HSMFDump. * @throws Exception */ public void testReadMessageDateFailsWithHSMFDump() throws Exception { - PrintStream stream = new PrintStream(new ByteArrayOutputStream()); - HSMFDump dump = new HSMFDump(fsMessageFails); - dump.dump(stream); + PrintStream stream = new PrintStream(new ByteArrayOutputStream()); + HSMFDump dump = new HSMFDump(fsMessageFails); + dump.dump(stream); } - + /** * TODO Work out why the Fri 22nd vs Monday 25th problem is occurring and fix */ diff --git a/src/scratchpad/testcases/org/apache/poi/hsmf/TestOutlook30FileRead.java b/src/scratchpad/testcases/org/apache/poi/hsmf/TestOutlook30FileRead.java index 435f9bcf0..a791874ce 100644 --- a/src/scratchpad/testcases/org/apache/poi/hsmf/TestOutlook30FileRead.java +++ b/src/scratchpad/testcases/org/apache/poi/hsmf/TestOutlook30FileRead.java @@ -29,117 +29,117 @@ import junit.framework.TestCase; * Tests to verify that we can still work on the newer Outlook 3.0 files. */ public final class TestOutlook30FileRead extends TestCase { -private MAPIMessage mapiMessage; + private MAPIMessage mapiMessage; - /** - * Initialize this test, load up the blank.msg mapi message. - * @throws Exception - */ - public TestOutlook30FileRead() throws IOException { + /** + * Initialize this test, load up the blank.msg mapi message. + * @throws Exception + */ + public TestOutlook30FileRead() throws IOException { POIDataSamples samples = POIDataSamples.getHSMFInstance(); - this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("outlook_30_msg.msg")); - } + this.mapiMessage = new MAPIMessage(samples.openResourceAsStream("outlook_30_msg.msg")); + } - /** - * Test to see if we can read the CC Chunk. - * @throws ChunkNotFoundException - * - */ - public void testReadDisplayCC() throws ChunkNotFoundException { - String obtained = mapiMessage.getDisplayCC(); - String expected = ""; + /** + * Test to see if we can read the CC Chunk. + * @throws ChunkNotFoundException + * + */ + public void testReadDisplayCC() throws ChunkNotFoundException { + String obtained = mapiMessage.getDisplayCC(); + String expected = ""; - TestCase.assertEquals(obtained, expected); - } + TestCase.assertEquals(obtained, expected); + } - /** - * Test to see if we can read the CC Chunk. - * @throws ChunkNotFoundException - * - */ - public void testReadDisplayTo() throws ChunkNotFoundException { - String obtained = mapiMessage.getDisplayTo(); + /** + * Test to see if we can read the CC Chunk. + * @throws ChunkNotFoundException + * + */ + public void testReadDisplayTo() throws ChunkNotFoundException { + String obtained = mapiMessage.getDisplayTo(); - assertTrue(obtained.startsWith("Bohn, Shawn")); - } + assertTrue(obtained.startsWith("Bohn, Shawn")); + } - /** - * Test to see if we can read the From Chunk. - * @throws ChunkNotFoundException - * - */ - public void testReadDisplayFrom() throws ChunkNotFoundException { - String obtained = mapiMessage.getDisplayFrom(); - String expected = "Cramer, Nick"; + /** + * Test to see if we can read the From Chunk. + * @throws ChunkNotFoundException + * + */ + public void testReadDisplayFrom() throws ChunkNotFoundException { + String obtained = mapiMessage.getDisplayFrom(); + String expected = "Cramer, Nick"; - TestCase.assertEquals(obtained, expected); - } + TestCase.assertEquals(obtained, expected); + } - /** - * Test to see if we can read the CC Chunk. - * @throws ChunkNotFoundException - * - */ - public void testReadDisplayBCC() throws ChunkNotFoundException { - String obtained = mapiMessage.getDisplayBCC(); - String expected = ""; + /** + * Test to see if we can read the CC Chunk. + * @throws ChunkNotFoundException + * + */ + public void testReadDisplayBCC() throws ChunkNotFoundException { + String obtained = mapiMessage.getDisplayBCC(); + String expected = ""; - TestCase.assertEquals(obtained, expected); - } + TestCase.assertEquals(obtained, expected); + } - /** - * Check if we can read the body of the blank message, we expect "". - * - * @throws Exception - */ - public void testReadBody() throws Exception { - String obtained = mapiMessage.getTextBody(); - assertTrue(obtained.startsWith("I am shutting down")); - } + /** + * Check if we can read the body of the blank message, we expect "". + * + * @throws Exception + */ + public void testReadBody() throws Exception { + String obtained = mapiMessage.getTextBody(); + assertTrue(obtained.startsWith("I am shutting down")); + } - /** - * Check if we can read the subject line of the blank message, we expect "" - * - * @throws Exception - */ - public void testReadSubject() throws Exception { - String obtained = mapiMessage.getSubject(); - String expected = "IN-SPIRE servers going down for a bit, back up around 8am"; + /** + * Check if we can read the subject line of the blank message, we expect "" + * + * @throws Exception + */ + public void testReadSubject() throws Exception { + String obtained = mapiMessage.getSubject(); + String expected = "IN-SPIRE servers going down for a bit, back up around 8am"; - TestCase.assertEquals(expected, obtained); - } + TestCase.assertEquals(expected, obtained); + } - /** - * Check if we can read the subject line of the blank message, we expect "" - * - * @throws Exception - */ - public void testReadConversationTopic() throws Exception { - String obtained = mapiMessage.getConversationTopic(); - TestCase.assertEquals("IN-SPIRE servers going down for a bit, back up around 8am", obtained); - } + /** + * Check if we can read the subject line of the blank message, we expect "" + * + * @throws Exception + */ + public void testReadConversationTopic() throws Exception { + String obtained = mapiMessage.getConversationTopic(); + TestCase.assertEquals("IN-SPIRE servers going down for a bit, back up around 8am", obtained); + } - /** - * Check if we can read the subject line of the blank message, we expect "" - * - * @throws Exception - */ - public void testReadMessageClass() throws Exception { - String obtained = mapiMessage.getMessageClass(); - TestCase.assertEquals("IPM.Note", obtained); - } - - /** - * Ensure we can get the HTML and RTF versions - */ - public void testReadBodyContents() throws Exception { - String html = mapiMessage.getHtmlBody(); - String rtf = mapiMessage.getRtfBody(); - assertNotNull(html); - assertNotNull(rtf); - - assertTrue("Wrong text:\n" + html, html.startsWith("