KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > dsmlv2 > errorResponse > ErrorResponseTest


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.dsmlv2.errorResponse;
22
23
24 import org.apache.directory.ldapstudio.dsmlv2.AbstractResponseTest;
25 import org.apache.directory.ldapstudio.dsmlv2.Dsmlv2ResponseParser;
26 import org.apache.directory.ldapstudio.dsmlv2.reponse.ErrorResponse;
27 import org.apache.directory.ldapstudio.dsmlv2.reponse.ErrorResponse.ErrorResponseType;
28
29
30 /**
31  * Tests for the Error Response parsing
32  *
33  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
34  * @version $Rev$, $Date$
35  */

36 public class ErrorResponseTest extends AbstractResponseTest
37 {
38
39     /**
40      * Test parsing of a Response with the (optional) requestID attribute
41      */

42     public void testResponseWithRequestId()
43     {
44         Dsmlv2ResponseParser parser = null;
45         try
46         {
47             parser = new Dsmlv2ResponseParser();
48
49             parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_requestID_attribute.xml" )
50                 .getFile() );
51
52             parser.parse();
53         }
54         catch ( Exception JavaDoc e )
55         {
56             fail( e.getMessage() );
57         }
58
59         ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
60
61         assertEquals( 456, errorResponse.getMessageId() );
62     }
63     
64     
65     /**
66      * Test parsing of a Response with the (optional) requestID attribute equals 0
67      */

68     public void testResponseWithRequestIdEquals0()
69     {
70         testParsingFail( ErrorResponseTest.class, "response_with_requestID_equals_0.xml" );
71     }
72
73
74     /**
75      * Test parsing of a response without Type attribute
76      */

77     public void testResponseWithoutType()
78     {
79         testParsingFail( ErrorResponseTest.class, "response_without_type.xml" );
80     }
81
82
83     /**
84      * Test parsing of a response with type == notAttempted
85      */

86     public void testResponseWithTypeNotAttempted()
87     {
88         Dsmlv2ResponseParser parser = null;
89         try
90         {
91             parser = new Dsmlv2ResponseParser();
92
93             parser
94                 .setInputFile( ErrorResponseTest.class.getResource( "response_with_type_notAttempted.xml" ).getFile() );
95
96             parser.parse();
97         }
98         catch ( Exception JavaDoc e )
99         {
100             fail( e.getMessage() );
101         }
102
103         ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
104
105         assertEquals( ErrorResponseType.NOT_ATTEMPTED, errorResponse.getType() );
106     }
107
108
109     /**
110      * Test parsing of a response with type == couldNotConnect
111      */

112     public void testResponseWithTypeCouldNotConnect()
113     {
114         Dsmlv2ResponseParser parser = null;
115         try
116         {
117             parser = new Dsmlv2ResponseParser();
118
119             parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_type_couldNotConnect.xml" )
120                 .getFile() );
121
122             parser.parse();
123         }
124         catch ( Exception JavaDoc e )
125         {
126             fail( e.getMessage() );
127         }
128
129         ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
130
131         assertEquals( ErrorResponseType.COULD_NOT_CONNECT, errorResponse.getType() );
132     }
133
134
135     /**
136      * Test parsing of a response with type == connectionClosed
137      */

138     public void testResponseWithTypeConnectionClosed()
139     {
140         Dsmlv2ResponseParser parser = null;
141         try
142         {
143             parser = new Dsmlv2ResponseParser();
144
145             parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_type_connectionClosed.xml" )
146                 .getFile() );
147
148             parser.parse();
149         }
150         catch ( Exception JavaDoc e )
151         {
152             fail( e.getMessage() );
153         }
154
155         ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
156
157         assertEquals( ErrorResponseType.CONNECTION_CLOSED, errorResponse.getType() );
158     }
159
160
161     /**
162      * Test parsing of a response with type == malformedRequest
163      */

164     public void testResponseWithTypeMalformedRequest()
165     {
166         Dsmlv2ResponseParser parser = null;
167         try
168         {
169             parser = new Dsmlv2ResponseParser();
170
171             parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_type_malformedRequest.xml" )
172                 .getFile() );
173
174             parser.parse();
175         }
176         catch ( Exception JavaDoc e )
177         {
178             fail( e.getMessage() );
179         }
180
181         ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
182
183         assertEquals( ErrorResponseType.MALFORMED_REQUEST, errorResponse.getType() );
184     }
185
186
187     /**
188      * Test parsing of a response with type == gatewayInternalError
189      */

190     public void testResponseWithTypeGatewayInternalError()
191     {
192         Dsmlv2ResponseParser parser = null;
193         try
194         {
195             parser = new Dsmlv2ResponseParser();
196
197             parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_type_gatewayInternalError.xml" )
198                 .getFile() );
199
200             parser.parse();
201         }
202         catch ( Exception JavaDoc e )
203         {
204             fail( e.getMessage() );
205         }
206
207         ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
208
209         assertEquals( ErrorResponseType.GATEWAY_INTERNAL_ERROR, errorResponse.getType() );
210     }
211
212
213     /**
214      * Test parsing of a response with type == authenticationFailed
215      */

216     public void testResponseWithTypeAuthenticationFailed()
217     {
218         Dsmlv2ResponseParser parser = null;
219         try
220         {
221             parser = new Dsmlv2ResponseParser();
222
223             parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_type_authenticationFailed.xml" )
224                 .getFile() );
225
226             parser.parse();
227         }
228         catch ( Exception JavaDoc e )
229         {
230             fail( e.getMessage() );
231         }
232
233         ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
234
235         assertEquals( ErrorResponseType.AUTHENTICATION_FAILED, errorResponse.getType() );
236     }
237
238
239     /**
240      * Test parsing of a response with type == unresolvableURI
241      */

242     public void testResponseWithTypeUnresolvableURI()
243     {
244         Dsmlv2ResponseParser parser = null;
245         try
246         {
247             parser = new Dsmlv2ResponseParser();
248
249             parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_type_unresolvableURI.xml" )
250                 .getFile() );
251
252             parser.parse();
253         }
254         catch ( Exception JavaDoc e )
255         {
256             fail( e.getMessage() );
257         }
258
259         ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
260
261         assertEquals( ErrorResponseType.UNRESOLVABLE_URI, errorResponse.getType() );
262     }
263
264
265     /**
266      * Test parsing of a response with type == other
267      */

268     public void testResponseWithTypeOther()
269     {
270         Dsmlv2ResponseParser parser = null;
271         try
272         {
273             parser = new Dsmlv2ResponseParser();
274
275             parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_type_other.xml" ).getFile() );
276
277             parser.parse();
278         }
279         catch ( Exception JavaDoc e )
280         {
281             fail( e.getMessage() );
282         }
283
284         ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
285
286         assertEquals( ErrorResponseType.OTHER, errorResponse.getType() );
287     }
288
289
290     /**
291      * Test parsing of a response with type in error
292      */

293     public void testResponseWithTypeError()
294     {
295         testParsingFail( ErrorResponseTest.class, "response_with_type_inError.xml" );
296     }
297
298
299     /**
300      * Test parsing of a response with Message
301      */

302     public void testResponseWithMessage()
303     {
304         Dsmlv2ResponseParser parser = null;
305         try
306         {
307             parser = new Dsmlv2ResponseParser();
308
309             parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_message.xml" ).getFile() );
310
311             parser.parse();
312         }
313         catch ( Exception JavaDoc e )
314         {
315             fail( e.getMessage() );
316         }
317
318         ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
319
320         assertEquals( "Connection refused", errorResponse.getMessage() );
321     }
322     
323     /**
324      * Test parsing of a response with empty Message
325      */

326     public void testResponseWithEmptyMessage()
327     {
328         Dsmlv2ResponseParser parser = null;
329         try
330         {
331             parser = new Dsmlv2ResponseParser();
332
333             parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_empty_message.xml" ).getFile() );
334
335             parser.parse();
336         }
337         catch ( Exception JavaDoc e )
338         {
339             fail( e.getMessage() );
340         }
341
342         ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
343
344         assertNull( errorResponse.getMessage() );
345     }
346 }
347
Popular Tags