1 36 package org.columba.ristretto.imap.parser; 37 38 import junit.framework.TestCase; 39 40 import org.columba.ristretto.imap.IMAPResponse; 41 import org.columba.ristretto.imap.ResponseTextCode; 42 import org.columba.ristretto.parser.ParserException; 43 44 public class IMAPResponseParserTest extends TestCase { 45 46 public void testUntaggedStatus1() { 47 String responseString = "* OK Alles klar!\r\n"; 48 try { 49 IMAPResponse response = IMAPResponseParser.parse(responseString); 50 51 assertTrue(!response.isTagged()); 52 assertTrue(response.getResponseSubType().equals("OK")); 53 assertTrue(response.getResponseMessage().equals("Alles klar!")); 54 } catch (ParserException e) { 55 e.printStackTrace(); 56 } 57 } 58 59 public void testUntaggedStatus2() { 60 String responseString = "* OK [UNSEEN 12] Alles klar!\r\n"; 61 try { 62 IMAPResponse response = IMAPResponseParser.parse(responseString); 63 64 assertTrue(!response.isTagged()); 65 assertTrue(response.getResponseSubType().equals("OK")); 66 assertEquals(response.getResponseTextCode().getType(), ResponseTextCode.UNSEEN); 67 assertEquals(response.getResponseTextCode().getIntValue(), 12); 68 assertTrue(response.getResponseMessage().equals("Alles klar!")); 69 } catch (ParserException e) { 70 e.printStackTrace(); 71 } 72 } 73 74 public void testUntaggedMailbox1() { 75 String responseString = "* LIST mailboxlist\r\n"; 76 try { 77 IMAPResponse response = IMAPResponseParser.parse(responseString); 78 79 assertTrue(!response.isTagged()); 80 assertTrue(response.getResponseSubType().equals("LIST")); 81 assertTrue(response.getResponseMessage().equals("mailboxlist")); 82 assertTrue(response.getResponseType() == IMAPResponse.RESPONSE_MAILBOX_DATA); 83 } catch (ParserException e) { 84 e.printStackTrace(); 85 } 86 } 87 88 public void testUntaggedMailbox2() { 89 String responseString = "* 512 EXISTS\r\n"; 90 try { 91 IMAPResponse response = IMAPResponseParser.parse(responseString); 92 93 assertTrue(!response.isTagged()); 94 assertTrue(response.getResponseSubType().equals("EXISTS")); 95 assertTrue(response.getPreNumber() == 512); 96 } catch (ParserException e) { 97 e.printStackTrace(); 98 } 99 } 100 101 public void testUntaggedMessage1() { 102 String responseString = "* 12 FETCH fetchblabla\r\n"; 103 try { 104 IMAPResponse response = IMAPResponseParser.parse(responseString); 105 106 assertTrue(!response.isTagged()); 107 assertTrue(response.getPreNumber() == 12); 108 assertTrue(response.getResponseSubType().equals("FETCH")); 109 assertTrue(response.getResponseMessage().equals("fetchblabla")); 110 } catch (ParserException e) { 111 e.printStackTrace(); 112 } 113 } 114 115 public void testUntaggedMessage2() { 116 String responseString = "* 124 EXPUNGE\r\n"; 117 try { 118 IMAPResponse response = IMAPResponseParser.parse(responseString); 119 120 assertTrue(!response.isTagged()); 121 assertTrue(response.getPreNumber() == 124); 122 assertTrue(response.getResponseSubType().equals("EXPUNGE")); 123 } catch (ParserException e) { 124 e.printStackTrace(); 125 } 126 } 127 128 public void testTaggedStatus1() { 129 String responseString = "A01 OK Alles klar!\r\n"; 130 try { 131 IMAPResponse response = IMAPResponseParser.parse(responseString); 132 133 assertTrue(response.isTagged()); 134 assertTrue(response.getTag().equals("A01")); 135 assertTrue(response.getResponseSubType().equals("OK")); 136 assertTrue(response.getResponseMessage().equals("Alles klar!")); 137 } catch (ParserException e) { 138 e.printStackTrace(); 139 } 140 } 141 142 public void testTaggedStatus2() { 143 String responseString = "A142 OK [READ-WRITE] SELECT completed"; 144 try { 145 IMAPResponse response = IMAPResponseParser.parse(responseString); 146 147 assertTrue(response.isTagged()); 148 assertTrue(response.getTag().equals("A142")); 149 assertTrue(response.getResponseSubType().equals("OK")); 150 assertEquals(response.getResponseTextCode().getType(), ResponseTextCode.READ_WRITE); 151 assertTrue(response.getResponseMessage().equals("SELECT completed")); 152 } catch (ParserException e) { 153 e.printStackTrace(); 154 } 155 } 156 157 public void testContinuation1() { 158 String responseString = "+ give me more\r\n"; 159 try { 160 IMAPResponse response = IMAPResponseParser.parse(responseString); 161 162 assertTrue(response.getResponseType() == IMAPResponse.RESPONSE_CONTINUATION); 163 assertTrue(response.getResponseMessage().equals("give me more")); 164 } catch (ParserException e) { 165 e.printStackTrace(); 166 } 167 } 168 169 public void testContinuation2() { 170 String responseString = "+ [UIDVALIDITY 385752904] give me more\r\n"; 171 try { 172 IMAPResponse response = IMAPResponseParser.parse(responseString); 173 174 assertTrue(response.getResponseType() == IMAPResponse.RESPONSE_CONTINUATION); 175 assertEquals(response.getResponseTextCode().getType(), ResponseTextCode.UIDVALIDITY ); 176 assertEquals(response.getResponseTextCode().getIntValue(), 385752904); 177 assertTrue(response.getResponseMessage().equals("give me more")); 178 } catch (ParserException e) { 179 e.printStackTrace(); 180 } 181 } 182 183 public void testCapabilities() { 184 String responseString = "* CAPABILITY IMAP4REV1 IDLE NAMESPACE MAILBOX-REFERRALS SCAN SORT THREAD=REFERENCES THREAD=ORDEREDSUBJECT MULTIAPPEND\r\n"; 185 try { 186 IMAPResponse response = IMAPResponseParser.parse(responseString); 187 188 assertTrue(!response.isTagged()); 189 assertTrue( response.getResponseSubType().equals("CAPABILITY")); 190 } catch (ParserException e) { 191 e.printStackTrace(); 192 } 193 } 194 195 public void testResponseTextCode1() { 196 String responseString = "* OK [PERMANENTFLAGS (\\Answered \\Flagged \\Draft \\Deleted \\Seen)]\r\n"; 197 try { 198 IMAPResponse response = IMAPResponseParser.parse(responseString); 199 200 assertTrue(!response.isTagged()); 201 assertEquals( ResponseTextCode.PERMANENTFLAGS, response.getResponseTextCode().getType()); 202 } catch (ParserException e) { 203 e.printStackTrace(); 204 } 205 } 206 207 public void testResponseTextCode2() { 208 String responseString = "3 OK [READ_WRITE] completed\r\n"; 209 try { 210 IMAPResponse response = IMAPResponseParser.parse(responseString); 211 212 assertTrue(response.isTagged()); 213 assertEquals( ResponseTextCode.READ_WRITE, response.getResponseTextCode().getType()); 214 } catch (ParserException e) { 215 e.printStackTrace(); 216 } 217 } 218 219 } 220 | Popular Tags |