KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > ristretto > imap > parser > IMAPResponseParserTest


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is Ristretto Mail API.
15  *
16  * The Initial Developers of the Original Code are
17  * Timo Stich and Frederik Dietz.
18  * Portions created by the Initial Developers are Copyright (C) 2004
19  * All Rights Reserved.
20  *
21  * Contributor(s):
22  *
23  * Alternatively, the contents of this file may be used under the terms of
24  * either the GNU General Public License Version 2 or later (the "GPL"), or
25  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26  * in which case the provisions of the GPL or the LGPL are applicable instead
27  * of those above. If you wish to allow use of your version of this file only
28  * under the terms of either the GPL or the LGPL, and not to allow others to
29  * use your version of this file under the terms of the MPL, indicate your
30  * decision by deleting the provisions above and replace them with the notice
31  * and other provisions required by the GPL or the LGPL. If you do not delete
32  * the provisions above, a recipient may use your version of this file under
33  * the terms of any one of the MPL, the GPL or the LGPL.
34  *
35  * ***** END LICENSE BLOCK ***** */

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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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