add unit tests for MAPIMessage.get*Body()
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1777463 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
25db24d2d6
commit
42c5a08dfb
@ -17,6 +17,9 @@
|
|||||||
|
|
||||||
package org.apache.poi.hsmf;
|
package org.apache.poi.hsmf;
|
||||||
|
|
||||||
|
import static org.apache.poi.POITestCase.assertContains;
|
||||||
|
import static org.apache.poi.POITestCase.assertStartsWith;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
@ -89,9 +92,9 @@ public final class TestBasics extends TestCase {
|
|||||||
public void testHeaders() throws Exception {
|
public void testHeaders() throws Exception {
|
||||||
// Simple email first
|
// Simple email first
|
||||||
assertEquals(26, simple.getHeaders().length);
|
assertEquals(26, simple.getHeaders().length);
|
||||||
assertTrue(simple.getHeaders()[0].startsWith("Return-path:"));
|
assertStartsWith(simple.getHeaders()[0], "Return-path:");
|
||||||
assertTrue(simple.getHeaders()[1].equals("Envelope-to: travis@overwrittenstack.com"));
|
assertEquals("Envelope-to: travis@overwrittenstack.com", simple.getHeaders()[1]);
|
||||||
assertTrue(simple.getHeaders()[25].startsWith("X-Antivirus-Scanner: Clean"));
|
assertStartsWith(simple.getHeaders()[25], "X-Antivirus-Scanner: Clean");
|
||||||
|
|
||||||
// Quick doesn't have them
|
// Quick doesn't have them
|
||||||
try {
|
try {
|
||||||
@ -107,9 +110,32 @@ public final class TestBasics extends TestCase {
|
|||||||
|
|
||||||
// Outlook30 has some
|
// Outlook30 has some
|
||||||
assertEquals(33, outlook30.getHeaders().length);
|
assertEquals(33, outlook30.getHeaders().length);
|
||||||
assertTrue(outlook30.getHeaders()[0].startsWith("Microsoft Mail Internet Headers"));
|
assertStartsWith(outlook30.getHeaders()[0], "Microsoft Mail Internet Headers");
|
||||||
assertTrue(outlook30.getHeaders()[1].startsWith("x-mimeole:"));
|
assertStartsWith(outlook30.getHeaders()[1], "x-mimeole:");
|
||||||
assertTrue(outlook30.getHeaders()[32].startsWith("\t\"Williams")); // May need better parsing in future
|
assertStartsWith(outlook30.getHeaders()[32], "\t\"Williams"); // May need better parsing in future
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBody() throws Exception {
|
||||||
|
// Messages may have their bodies saved as plain text, html, and/or rtf.
|
||||||
|
assertEquals("This is a test message.", simple.getTextBody());
|
||||||
|
assertEquals("The quick brown fox jumps over the lazy dog\r\n", quick.getTextBody());
|
||||||
|
assertStartsWith(outlook30.getTextBody(), "I am shutting down the IN-SPIRE servers now for 30ish minutes.\r\n\r\n");
|
||||||
|
assertStartsWith(attachments.getTextBody(), "contenu\r\n\r\n");
|
||||||
|
assertStartsWith(unicode.getTextBody(), "..less you are Nick.....");
|
||||||
|
|
||||||
|
// outlook30 has chunks for all 3 body formats
|
||||||
|
// Examine one of the paragraphs is present in all 3 formats, surrounded by markup tags
|
||||||
|
String text = "I am shutting down the IN-SPIRE servers now for 30ish minutes.";
|
||||||
|
assertStartsWith(outlook30.getTextBody(), text + "\r\n\r\n");
|
||||||
|
assertEquals(850494485, outlook30.getTextBody().hashCode());
|
||||||
|
|
||||||
|
assertStartsWith(outlook30.getHtmlBody(), "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\r\n<HTML>\r\n<HEAD>");
|
||||||
|
assertContains(outlook30.getHtmlBody(), "<P DIR=LTR><SPAN LANG=\"en-us\"><FONT FACE=\"Calibri\">" + text + "</FONT></SPAN></P>");
|
||||||
|
assertEquals(-654938715, outlook30.getHtmlBody().hashCode());
|
||||||
|
|
||||||
|
assertStartsWith(outlook30.getRtfBody(), "{\\rtf1\\adeflang1025\\ansi\\ansicpg1252\\uc1\\adeff3150");
|
||||||
|
assertContains(outlook30.getRtfBody(), "{\\rtlch\\fcs1 \\af31507 \\ltrch\\fcs0 \\cf0\\insrsid5003910 " + text + "\r\n\\par \r\n\\par");
|
||||||
|
assertEquals(891652290, outlook30.getRtfBody().hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,6 +44,14 @@ import org.apache.poi.util.Internal;
|
|||||||
*/
|
*/
|
||||||
@Internal
|
@Internal
|
||||||
public final class POITestCase {
|
public final class POITestCase {
|
||||||
|
public static void assertStartsWith(String string, String prefix) {
|
||||||
|
assertNotNull(string);
|
||||||
|
assertNotNull(prefix);
|
||||||
|
|
||||||
|
final int len = Math.min(string.length(), prefix.length());
|
||||||
|
assertEquals("string does not start with prefix", prefix, string.substring(0, len));
|
||||||
|
}
|
||||||
|
|
||||||
public static void assertContains(String haystack, String needle) {
|
public static void assertContains(String haystack, String needle) {
|
||||||
assertNotNull(haystack);
|
assertNotNull(haystack);
|
||||||
assertTrue(
|
assertTrue(
|
||||||
|
@ -33,6 +33,13 @@ import org.junit.Test;
|
|||||||
* A class for testing the POI Junit TestCase utility class
|
* A class for testing the POI Junit TestCase utility class
|
||||||
*/
|
*/
|
||||||
public final class TestPOITestCase {
|
public final class TestPOITestCase {
|
||||||
|
@Test
|
||||||
|
public void assertStartsWith() {
|
||||||
|
POITestCase.assertStartsWith("Apache POI", "");
|
||||||
|
POITestCase.assertStartsWith("Apache POI", "Apache");
|
||||||
|
POITestCase.assertStartsWith("Apache POI", "Apache POI");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void assertContains() {
|
public void assertContains() {
|
||||||
POITestCase.assertContains("There is a needle in this haystack", "needle");
|
POITestCase.assertContains("There is a needle in this haystack", "needle");
|
||||||
|
Loading…
Reference in New Issue
Block a user