001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hsmf.model;
019:
020: import java.io.IOException;
021:
022: import org.apache.poi.hsmf.MAPIMessage;
023: import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
024:
025: import junit.framework.TestCase;
026:
027: /**
028: * Tests to verify that the library can read blank msg files.
029: *
030: * @author Travis Ferguson
031: *
032: */
033: public class TestBlankFileRead extends TestCase {
034: private MAPIMessage mapiMessage;
035:
036: /**
037: * Initialize this test, load up the blank.msg mapi message.
038: * @throws IOException
039: */
040: public TestBlankFileRead() throws IOException {
041: String dirname = System.getProperty("HSMF.testdata.path");
042: this .mapiMessage = new MAPIMessage(dirname + "/blank.msg");
043: }
044:
045: /**
046: * Check if we can read the body of the blank message, we expect "".
047: *
048: * @throws Exception
049: */
050: public void testReadBody() throws Exception {
051: try {
052: mapiMessage.getTextBody();
053: } catch (ChunkNotFoundException exp) {
054: return;
055: }
056:
057: TestCase
058: .fail("Should have thrown a ChunkNotFoundException but didn't");
059: }
060:
061: /**
062: * Test to see if we can read the CC Chunk.
063: * @throws ChunkNotFoundException
064: *
065: */
066: public void testReadDisplayCC() throws ChunkNotFoundException {
067: String obtained = mapiMessage.getDisplayCC();
068: String expected = "";
069:
070: TestCase.assertEquals(obtained, expected);
071: }
072:
073: /**
074: * Test to see if we can read the CC Chunk.
075: * @throws ChunkNotFoundException
076: *
077: */
078: public void testReadDisplayTo() throws ChunkNotFoundException {
079: String obtained = mapiMessage.getDisplayTo();
080: String expected = "";
081:
082: TestCase.assertEquals(obtained, expected);
083: }
084:
085: /**
086: * Test to see if we can read the FROM Chunk.
087: * @throws ChunkNotFoundException
088: *
089: */
090: public void testReadDisplayFrom() throws ChunkNotFoundException {
091: try {
092: mapiMessage.getDisplayFrom();
093: } catch (ChunkNotFoundException exp) {
094: return;
095: }
096:
097: TestCase
098: .fail("Should have thrown a ChunkNotFoundException but didn't");
099: }
100:
101: /**
102: * Test to see if we can read the CC Chunk.
103: * @throws ChunkNotFoundException
104: *
105: */
106: public void testReadDisplayBCC() throws ChunkNotFoundException {
107: String obtained = mapiMessage.getDisplayBCC();
108: String expected = "";
109:
110: TestCase.assertEquals(obtained, expected);
111: }
112:
113: /**
114: * Check if we can read the subject line of the blank message, we expect ""
115: *
116: * @throws Exception
117: */
118: public void testReadSubject() throws Exception {
119: String obtained = mapiMessage.getSubject();
120: TestCase.assertEquals("", obtained);
121: }
122:
123: /**
124: * Check if we can read the subject line of the blank message, we expect ""
125: *
126: * @throws Exception
127: */
128: public void testReadConversationTopic() throws Exception {
129: try {
130: mapiMessage.getConversationTopic();
131: } catch (ChunkNotFoundException exp) {
132: return;
133: }
134: TestCase
135: .fail("We shouldn't have a ConversationTopic node on the blank.msg file.");
136: }
137:
138: }
|