Show
Ignore:
Timestamp:
08/19/08 07:43:27 PM (5 months ago)
Author:
octorian
Message:

Envelope tests

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/LogicMail-1.0/LogicMailTests/src/org/logicprobe/LogicMail/mail/imap/ImapProtocolTest.java

    r268 r273  
    132132    } 
    133133     
    134     public void testExecuteNamespace() { 
     134    public void testExecuteNamespace1() { 
    135135        try { 
    136136            // Normal namespace: 
     
    140140                    new String[] { "* NAMESPACE ((\"\" \"/\")) ((\"Other Users/\" \"/\")) NIL" }); 
    141141            ImapProtocol.NamespaceResponse result = instance.executeNamespace(); 
    142             assertNotNull(result); 
    143              
    144             assertNotNull(result.personal); 
     142            assertNotNull("Result", result); 
     143             
     144            assertNotNull("Personal", result.personal); 
    145145            assertEquals(1, result.personal.length); 
    146146            assertEquals("", result.personal[0].prefix); 
    147147            assertEquals("/", result.personal[0].delimiter); 
    148148             
    149             assertNotNull(result.other); 
     149            assertNotNull("Other", result.other); 
    150150            assertEquals(1, result.other.length); 
    151151            assertEquals("Other Users/", result.other[0].prefix); 
    152152            assertEquals("/", result.other[0].delimiter); 
    153153 
    154             assertNull(result.shared); 
    155              
     154            assertNull("Shared", result.shared); 
     155        } catch (Throwable t) { 
     156            fail("Exception thrown during test: "+t.toString()); 
     157            t.printStackTrace(); 
     158        } 
     159    } 
     160     
     161    public void testExecuteNamespace2() { 
     162        try { 
    156163            // Escaped delimiters: 
    157164            // NAMESPACE (("" "\\")) (("Other Users\\" "\\")) (("Public Folders\\" "\\")) 
     
    159166                    "NAMESPACE", null, 
    160167                    new String[] { "* NAMESPACE ((\"\" \"\\\\\")) ((\"Other Users\\\\\" \"\\\\\")) ((\"Public Folders\\\\\" \"\\\\\"))" }); 
    161             result = instance.executeNamespace(); 
    162             assertNotNull(result); 
    163              
    164             assertNotNull(result.personal); 
     168            ImapProtocol.NamespaceResponse result = instance.executeNamespace(); 
     169            assertNotNull("Result", result); 
     170             
     171            assertNotNull("Personal", result.personal); 
    165172            assertEquals(1, result.personal.length); 
    166173            assertEquals("", result.personal[0].prefix); 
    167174            assertEquals("\\", result.personal[0].delimiter); 
    168175             
    169             assertNotNull(result.other); 
     176            assertNotNull("Other", result.other); 
    170177            assertEquals(1, result.other.length); 
    171178            assertEquals("Other Users\\", result.other[0].prefix); 
    172179            assertEquals("\\", result.other[0].delimiter); 
    173180             
    174             assertNotNull(result.shared); 
     181            assertNotNull("Shared ", result.shared); 
    175182            assertEquals(1, result.shared.length); 
    176183            assertEquals("Public Folders\\", result.shared[0].prefix); 
     
    450457            assertEquals("<7b02460f0703121938sff23a05xd3c2a37dc6b9eb7d@mail.scratch.test>", env.messageId); 
    451458             
    452         } catch (MailException e) { 
    453             fail("MailException thrown during test: "+e.toString()); 
    454             e.printStackTrace(); 
    455         } catch (IOException e) { 
    456             fail("IOException thrown during test: "+e.toString()); 
    457             e.printStackTrace(); 
     459        } catch (Throwable t) { 
     460            fail("Exception thrown during test: "+t.toString()); 
     461            t.printStackTrace(); 
    458462        } 
    459463    } 
     
    528532            assertEquals("<4690A4EF.3070302@mail.scratch.test>", env.messageId); 
    529533             
    530         } catch (MailException e) { 
    531             fail("MailException thrown during test: "+e.toString()); 
    532             e.printStackTrace(); 
    533         } catch (IOException e) { 
    534             fail("IOException thrown during test: "+e.toString()); 
    535             e.printStackTrace(); 
    536         } 
    537     } 
    538  
     534        } catch (Throwable t) { 
     535            fail("Exception thrown during test: "+t.toString()); 
     536            t.printStackTrace(); 
     537        } 
     538    } 
     539 
     540    public void testExecuteFetchEnvelope3() { 
     541        try { 
     542            instance.addExecuteExpectation( 
     543                "FETCH", "1:1 (FLAGS ENVELOPE)", 
     544                new String[] { 
     545                    "* 1 FETCH (" + 
     546                    "FLAGS (\\Seen) " + 
     547                    "ENVELOPE (\"Wed, 06 Aug 2008 02:23:30 -0000\" " + 
     548                    "\"[LogicMail for BlackBerry] #93: Endless \\\"refresh folders\\\" loop when using qmail server\" " + 
     549                    "((\"LogicMail for BlackBerry\" NIL \"trac\" \"scratch.test\")) " + 
     550                    "((\"LogicMail for BlackBerry\" NIL \"trac\" \"scratch.test\")) " + 
     551                    "((NIL NIL \"trac\" \"scratch.test\")) "+ 
     552                    "((NIL NIL \"undisclosed-recipients\" NIL)) " + 
     553                    "NIL NIL NIL " + 
     554                    "\"<060.de38dad18d49d570300daa4869e9abed@scratch.test>\"))" 
     555                }); 
     556            ImapProtocol.FetchEnvelopeResponse[] result = instance.executeFetchEnvelope(1, 1); 
     557            assertNotNull(result); 
     558            assertEquals(1, result.length); 
     559            assertNotNull(result[0]); 
     560 
     561            assertEquals(1, result[0].index); 
     562            assertNotNull(result[0].flags); 
     563            assertTrue(result[0].flags.seen); 
     564            assertTrue(!result[0].flags.answered); 
     565            assertTrue(!result[0].flags.deleted); 
     566            assertTrue(!result[0].flags.draft); 
     567            assertTrue(!result[0].flags.flagged); 
     568            assertTrue(!result[0].flags.recent); 
     569             
     570            assertNotNull(result[0].envelope); 
     571            MessageEnvelope env = result[0].envelope; 
     572            Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); 
     573            cal.set(Calendar.YEAR, 2008); 
     574            cal.set(Calendar.MONTH, 7); 
     575            cal.set(Calendar.DAY_OF_MONTH, 6); 
     576            cal.set(Calendar.HOUR_OF_DAY, 2); 
     577            cal.set(Calendar.MINUTE, 23); 
     578            cal.set(Calendar.SECOND, 30); 
     579            assertEquals(StringParser.createDateString(cal.getTime()), StringParser.createDateString(env.date)); 
     580 
     581            assertEquals("[LogicMail for BlackBerry] #93: Endless \\\"refresh folders\\\" loop when using qmail server", env.subject); 
     582             
     583            assertNotNull(env.from); 
     584            assertEquals(1, env.from.length); 
     585            assertNotNull(env.from[0]); 
     586            assertEquals("LogicMail for BlackBerry <trac@scratch.test>", env.from[0]); 
     587             
     588            assertNotNull(env.sender); 
     589            assertEquals(1, env.sender.length); 
     590            assertNotNull(env.sender[0]); 
     591            assertEquals("LogicMail for BlackBerry <trac@scratch.test>", env.sender[0]); 
     592 
     593            assertNotNull(env.replyTo); 
     594            assertEquals(1, env.replyTo.length); 
     595            assertNotNull(env.replyTo[0]); 
     596            assertEquals("trac@scratch.test", env.replyTo[0]); 
     597 
     598            assertNotNull(env.to); 
     599            assertEquals(1, env.to.length); 
     600            assertNotNull(env.to[0]); 
     601            assertEquals("undisclosed-recipients", env.to[0]); 
     602 
     603            assertNull(env.cc); 
     604            assertNull(env.bcc); 
     605             
     606            assertEquals("", env.inReplyTo); 
     607            assertEquals("<060.de38dad18d49d570300daa4869e9abed@scratch.test>", env.messageId); 
     608        } catch (Throwable t) { 
     609            fail("Exception thrown during test: "+t.toString()); 
     610            t.printStackTrace(); 
     611        } 
     612    } 
     613 
     614    public void testExecuteFetchEnvelope4() { 
     615        try { 
     616            instance.addExecuteExpectation( 
     617                "FETCH", "1:1 (FLAGS ENVELOPE)", 
     618                new String[] { 
     619                    "* 1 FETCH (FLAGS (\\Seen) " + 
     620                    "ENVELOPE (\"Sun, 10 Aug 2008 14:47:16 -0000\" " + 
     621                    "\"Re: [LogicMail for BlackBerry] #94: Message \\\"\\\"This message does not contain any sections that could be displayed\\\"\" " + 
     622                    "((\"LogicMail for BlackBerry\" NIL \"trac\" \"scratch.test\")) " + 
     623                    "((\"LogicMail for BlackBerry\" NIL \"trac\" \"scratch.test\")) " + 
     624                    "((NIL NIL \"trac\" \"scratch.test\")) " + 
     625                    "((NIL NIL \"undisclosed-recipients\" NIL)) " + 
     626                    "NIL NIL " + 
     627                    "\"<060.dbfdcb41f7f58c1f764727b7af599d3a@scratch.test>\" " + 
     628                    "\"<069.001addbae7c31283d93b5f5d97756e65@scratch.test>\"))" 
     629                }); 
     630            ImapProtocol.FetchEnvelopeResponse[] result = instance.executeFetchEnvelope(1, 1); 
     631            assertNotNull(result); 
     632            assertEquals(1, result.length); 
     633            assertNotNull(result[0]); 
     634 
     635            assertEquals(1, result[0].index); 
     636            assertNotNull(result[0].flags); 
     637            assertTrue(result[0].flags.seen); 
     638            assertTrue(!result[0].flags.answered); 
     639            assertTrue(!result[0].flags.deleted); 
     640            assertTrue(!result[0].flags.draft); 
     641            assertTrue(!result[0].flags.flagged); 
     642            assertTrue(!result[0].flags.recent); 
     643            assertNotNull(result[0].envelope); 
     644 
     645            MessageEnvelope env = result[0].envelope; 
     646            Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); 
     647            cal.set(Calendar.YEAR, 2008); 
     648            cal.set(Calendar.MONTH, 7); 
     649            cal.set(Calendar.DAY_OF_MONTH, 10); 
     650            cal.set(Calendar.HOUR_OF_DAY, 14); 
     651            cal.set(Calendar.MINUTE, 47); 
     652            cal.set(Calendar.SECOND, 16); 
     653            assertEquals(StringParser.createDateString(cal.getTime()), StringParser.createDateString(env.date)); 
     654 
     655            assertEquals("Re: [LogicMail for BlackBerry] #94: Message \\\"\\\"This message does not contain any sections that could be displayed\\\"", env.subject); 
     656             
     657            assertNotNull(env.from); 
     658            assertEquals(1, env.from.length); 
     659            assertNotNull(env.from[0]); 
     660            assertEquals("LogicMail for BlackBerry <trac@scratch.test>", env.from[0]); 
     661             
     662            assertNotNull(env.sender); 
     663            assertEquals(1, env.sender.length); 
     664            assertNotNull(env.sender[0]); 
     665            assertEquals("LogicMail for BlackBerry <trac@scratch.test>", env.sender[0]); 
     666 
     667            assertNotNull(env.replyTo); 
     668            assertEquals(1, env.replyTo.length); 
     669            assertNotNull(env.replyTo[0]); 
     670            assertEquals("trac@scratch.test", env.replyTo[0]); 
     671 
     672            assertNotNull(env.to); 
     673            assertEquals(1, env.to.length); 
     674            assertNotNull(env.to[0]); 
     675            assertEquals("undisclosed-recipients", env.to[0]); 
     676 
     677            assertNull(env.cc); 
     678            assertNull(env.bcc); 
     679             
     680            assertEquals("<060.dbfdcb41f7f58c1f764727b7af599d3a@scratch.test>", env.inReplyTo); 
     681            assertEquals("<069.001addbae7c31283d93b5f5d97756e65@scratch.test>", env.messageId); 
     682        } catch (Throwable t) { 
     683            fail("Exception thrown during test: "+t.toString()); 
     684            t.printStackTrace(); 
     685        } 
     686    } 
     687     
    539688    public void testExecuteStore1() { 
    540689        try { 
     
    582731        suite.addTest(new ImapProtocolTest("executeCapability", new TestMethod() 
    583732        { public void run(TestCase tc) {((ImapProtocolTest)tc).testExecuteCapability(); } })); 
    584         suite.addTest(new ImapProtocolTest("executeNamespace", new TestMethod() 
    585         { public void run(TestCase tc) {((ImapProtocolTest)tc).testExecuteNamespace(); } })); 
     733        suite.addTest(new ImapProtocolTest("executeNamespace1", new TestMethod() 
     734        { public void run(TestCase tc) {((ImapProtocolTest)tc).testExecuteNamespace1(); } })); 
     735        suite.addTest(new ImapProtocolTest("executeNamespace2", new TestMethod() 
     736        { public void run(TestCase tc) {((ImapProtocolTest)tc).testExecuteNamespace2(); } })); 
    586737        suite.addTest(new ImapProtocolTest("executeList1", new TestMethod() 
    587738        { public void run(TestCase tc) {((ImapProtocolTest)tc).testExecuteList1(); } })); 
     
    600751        suite.addTest(new ImapProtocolTest("executeFetchEnvelope2", new TestMethod() 
    601752        { public void run(TestCase tc) {((ImapProtocolTest)tc).testExecuteFetchEnvelope2(); } })); 
     753        suite.addTest(new ImapProtocolTest("executeFetchEnvelope3", new TestMethod() 
     754        { public void run(TestCase tc) {((ImapProtocolTest)tc).testExecuteFetchEnvelope3(); } })); 
     755        suite.addTest(new ImapProtocolTest("executeFetchEnvelope4", new TestMethod() 
     756        { public void run(TestCase tc) {((ImapProtocolTest)tc).testExecuteFetchEnvelope4(); } })); 
    602757        suite.addTest(new ImapProtocolTest("executeStore1", new TestMethod() 
    603758        { public void run(TestCase tc) {((ImapProtocolTest)tc).testExecuteStore1(); } }));