KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > dsmlv2 > batchResponse > BatchResponseTest


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.batchResponse;
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.BatchResponse;
27 import org.apache.directory.ldapstudio.dsmlv2.reponse.ErrorResponse;
28 import org.apache.directory.ldapstudio.dsmlv2.reponse.SearchResponse;
29 import org.apache.directory.shared.ldap.codec.LdapResponse;
30 import org.apache.directory.shared.ldap.codec.add.AddResponse;
31 import org.apache.directory.shared.ldap.codec.bind.BindResponse;
32 import org.apache.directory.shared.ldap.codec.compare.CompareResponse;
33 import org.apache.directory.shared.ldap.codec.del.DelResponse;
34 import org.apache.directory.shared.ldap.codec.extended.ExtendedResponse;
35 import org.apache.directory.shared.ldap.codec.modify.ModifyResponse;
36 import org.apache.directory.shared.ldap.codec.modifyDn.ModifyDNResponse;
37
38
39 /**
40  * Tests for the Compare Response parsing
41  *
42  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
43  * @version $Rev$, $Date$
44  */

45 public class BatchResponseTest extends AbstractResponseTest
46 {
47     /**
48      * Test parsing of a Response with the (optional) requestID attribute
49      */

50     public void testResponseWithRequestId()
51     {
52         Dsmlv2ResponseParser parser = null;
53         try
54         {
55             parser = new Dsmlv2ResponseParser();
56
57             parser.setInputFile( BatchResponseTest.class.getResource( "response_with_requestID_attribute.xml" )
58                 .getFile() );
59
60             parser.parse();
61         }
62         catch ( Exception JavaDoc e )
63         {
64             fail( e.getMessage() );
65         }
66
67         BatchResponse batchResponse = parser.getBatchResponse();
68
69         assertEquals( 1234567890, batchResponse.getRequestID() );
70     }
71     
72     
73     /**
74      * Test parsing of a Response with the (optional) requestID attribute equals 0
75      */

76     public void testResponseWithRequestIdEquals0()
77     {
78         testParsingFail( BatchResponseTest.class, "response_with_requestID_equals_0.xml" );
79     }
80
81
82     /**
83      * Test parsing of a Response with 0 Response
84      */

85     public void testResponseWith0Reponse()
86     {
87         Dsmlv2ResponseParser parser = null;
88         try
89         {
90             parser = new Dsmlv2ResponseParser();
91
92             parser.setInputFile( BatchResponseTest.class.getResource( "response_with_0_response.xml" ).getFile() );
93
94             parser.parse();
95         }
96         catch ( Exception JavaDoc e )
97         {
98             fail( e.getMessage() );
99         }
100
101         BatchResponse batchResponse = parser.getBatchResponse();
102
103         assertEquals( 0, batchResponse.getResponses().size() );
104     }
105
106
107     /**
108      * Test parsing of a Response with the 1 AddResponse
109      */

110     public void testResponseWith1AddResponse()
111     {
112         Dsmlv2ResponseParser parser = null;
113         try
114         {
115             parser = new Dsmlv2ResponseParser();
116
117             parser.setInputFile( BatchResponseTest.class.getResource( "response_with_1_AddResponse.xml" ).getFile() );
118
119             parser.parse();
120         }
121         catch ( Exception JavaDoc e )
122         {
123             fail( e.getMessage() );
124         }
125
126         BatchResponse batchResponse = parser.getBatchResponse();
127
128         assertEquals( 1, batchResponse.getResponses().size() );
129
130         LdapResponse response = batchResponse.getCurrentResponse();
131
132         if ( response instanceof AddResponse )
133         {
134             assertTrue( true );
135         }
136         else
137         {
138             fail();
139         }
140     }
141
142
143     /**
144      * Test parsing of a Response with the 1 AuthResponse
145      */

146     public void testResponseWith1AuthResponse()
147     {
148         Dsmlv2ResponseParser parser = null;
149         try
150         {
151             parser = new Dsmlv2ResponseParser();
152
153             parser.setInputFile( BatchResponseTest.class.getResource( "response_with_1_AuthResponse.xml" ).getFile() );
154
155             parser.parse();
156         }
157         catch ( Exception JavaDoc e )
158         {
159             fail( e.getMessage() );
160         }
161
162         BatchResponse batchResponse = parser.getBatchResponse();
163
164         assertEquals( 1, batchResponse.getResponses().size() );
165
166         LdapResponse response = batchResponse.getCurrentResponse();
167
168         if ( response instanceof BindResponse )
169         {
170             assertTrue( true );
171         }
172         else
173         {
174             fail();
175         }
176     }
177
178
179     /**
180      * Test parsing of a Response with the 1 CompareResponse
181      */

182     public void testResponseWith1CompareResponse()
183     {
184         Dsmlv2ResponseParser parser = null;
185         try
186         {
187             parser = new Dsmlv2ResponseParser();
188
189             parser
190                 .setInputFile( BatchResponseTest.class.getResource( "response_with_1_CompareResponse.xml" ).getFile() );
191
192             parser.parse();
193         }
194         catch ( Exception JavaDoc e )
195         {
196             fail( e.getMessage() );
197         }
198
199         BatchResponse batchResponse = parser.getBatchResponse();
200
201         assertEquals( 1, batchResponse.getResponses().size() );
202
203         LdapResponse response = batchResponse.getCurrentResponse();
204
205         if ( response instanceof CompareResponse )
206         {
207             assertTrue( true );
208         }
209         else
210         {
211             fail();
212         }
213     }
214
215
216     /**
217      * Test parsing of a Response with the 1 DelResponse
218      */

219     public void testResponseWith1DelResponse()
220     {
221         Dsmlv2ResponseParser parser = null;
222         try
223         {
224             parser = new Dsmlv2ResponseParser();
225
226             parser.setInputFile( BatchResponseTest.class.getResource( "response_with_1_DelResponse.xml" ).getFile() );
227
228             parser.parse();
229         }
230         catch ( Exception JavaDoc e )
231         {
232             fail( e.getMessage() );
233         }
234
235         BatchResponse batchResponse = parser.getBatchResponse();
236
237         assertEquals( 1, batchResponse.getResponses().size() );
238
239         LdapResponse response = batchResponse.getCurrentResponse();
240
241         if ( response instanceof DelResponse )
242         {
243             assertTrue( true );
244         }
245         else
246         {
247             fail();
248         }
249     }
250
251
252     /**
253      * Test parsing of a Response with the 1 ErrorResponse
254      */

255     public void testResponseWith1ErrorResponse()
256     {
257         Dsmlv2ResponseParser parser = null;
258         try
259         {
260             parser = new Dsmlv2ResponseParser();
261
262             parser.setInputFile( BatchResponseTest.class.getResource( "response_with_1_ErrorResponse.xml" ).getFile() );
263
264             parser.parse();
265         }
266         catch ( Exception JavaDoc e )
267         {
268             fail( e.getMessage() );
269         }
270
271         BatchResponse batchResponse = parser.getBatchResponse();
272
273         assertEquals( 1, batchResponse.getResponses().size() );
274
275         LdapResponse response = batchResponse.getCurrentResponse();
276
277         if ( response instanceof ErrorResponse )
278         {
279             assertTrue( true );
280         }
281         else
282         {
283             fail();
284         }
285     }
286
287
288     /**
289      * Test parsing of a Response with the 1 ExtendedResponse
290      */

291     public void testResponseWith1ExtendedResponse()
292     {
293         Dsmlv2ResponseParser parser = null;
294         try
295         {
296             parser = new Dsmlv2ResponseParser();
297
298             parser.setInputFile( BatchResponseTest.class.getResource( "response_with_1_ExtendedResponse.xml" )
299                 .getFile() );
300
301             parser.parse();
302         }
303         catch ( Exception JavaDoc e )
304         {
305             fail( e.getMessage() );
306         }
307
308         BatchResponse batchResponse = parser.getBatchResponse();
309
310         assertEquals( 1, batchResponse.getResponses().size() );
311
312         LdapResponse response = batchResponse.getCurrentResponse();
313
314         if ( response instanceof ExtendedResponse )
315         {
316             assertTrue( true );
317         }
318         else
319         {
320             fail();
321         }
322     }
323
324
325     /**
326      * Test parsing of a Response with the 1 ModDNResponse
327      */

328     public void testResponseWith1ModDNResponse()
329     {
330         Dsmlv2ResponseParser parser = null;
331         try
332         {
333             parser = new Dsmlv2ResponseParser();
334
335             parser.setInputFile( BatchResponseTest.class.getResource( "response_with_1_ModDNResponse.xml" ).getFile() );
336
337             parser.parse();
338         }
339         catch ( Exception JavaDoc e )
340         {
341             fail( e.getMessage() );
342         }
343
344         BatchResponse batchResponse = parser.getBatchResponse();
345
346         assertEquals( 1, batchResponse.getResponses().size() );
347
348         LdapResponse response = batchResponse.getCurrentResponse();
349
350         if ( response instanceof ModifyDNResponse )
351         {
352             assertTrue( true );
353         }
354         else
355         {
356             fail();
357         }
358     }
359
360
361     /**
362      * Test parsing of a Response with the 1 ModifyResponse
363      */

364     public void testResponseWith1ModifyResponse()
365     {
366         Dsmlv2ResponseParser parser = null;
367         try
368         {
369             parser = new Dsmlv2ResponseParser();
370
371             parser.setInputFile( BatchResponseTest.class.getResource( "response_with_1_ModifyResponse.xml" ).getFile() );
372
373             parser.parse();
374         }
375         catch ( Exception JavaDoc e )
376         {
377             fail( e.getMessage() );
378         }
379
380         BatchResponse batchResponse = parser.getBatchResponse();
381
382         assertEquals( 1, batchResponse.getResponses().size() );
383
384         LdapResponse response = batchResponse.getCurrentResponse();
385
386         if ( response instanceof ModifyResponse )
387         {
388             assertTrue( true );
389         }
390         else
391         {
392             fail();
393         }
394     }
395
396
397     /**
398      * Test parsing of a Response with the 1 SearchResponse
399      */

400     public void testResponseWith1SearchResponse()
401     {
402         Dsmlv2ResponseParser parser = null;
403         try
404         {
405             parser = new Dsmlv2ResponseParser();
406
407             parser.setInputFile( BatchResponseTest.class.getResource( "response_with_1_SearchResponse.xml" ).getFile() );
408
409             parser.parse();
410         }
411         catch ( Exception JavaDoc e )
412         {
413             fail( e.getMessage() );
414         }
415
416         BatchResponse batchResponse = parser.getBatchResponse();
417
418         assertEquals( 1, batchResponse.getResponses().size() );
419
420         LdapResponse response = batchResponse.getCurrentResponse();
421
422         if ( response instanceof SearchResponse )
423         {
424             assertTrue( true );
425         }
426         else
427         {
428             fail();
429         }
430     }
431
432
433     /**
434      * Test parsing of a Response with the 2 AddResponse
435      */

436     public void testResponseWith2AddResponse()
437     {
438         Dsmlv2ResponseParser parser = null;
439         try
440         {
441             parser = new Dsmlv2ResponseParser();
442
443             parser.setInputFile( BatchResponseTest.class.getResource( "response_with_2_AddResponse.xml" ).getFile() );
444
445             parser.parse();
446         }
447         catch ( Exception JavaDoc e )
448         {
449             fail( e.getMessage() );
450         }
451
452         BatchResponse batchResponse = parser.getBatchResponse();
453
454         assertEquals( 2, batchResponse.getResponses().size() );
455
456         LdapResponse response = batchResponse.getCurrentResponse();
457
458         if ( response instanceof AddResponse )
459         {
460             assertTrue( true );
461         }
462         else
463         {
464             fail();
465         }
466     }
467
468
469     /**
470      * Test parsing of a Response with the 2 AuthResponse
471      */

472     public void testResponseWith2AuthResponse()
473     {
474         Dsmlv2ResponseParser parser = null;
475         try
476         {
477             parser = new Dsmlv2ResponseParser();
478
479             parser.setInputFile( BatchResponseTest.class.getResource( "response_with_2_AuthResponse.xml" ).getFile() );
480
481             parser.parse();
482         }
483         catch ( Exception JavaDoc e )
484         {
485             fail( e.getMessage() );
486         }
487
488         BatchResponse batchResponse = parser.getBatchResponse();
489
490         assertEquals( 2, batchResponse.getResponses().size() );
491
492         LdapResponse response = batchResponse.getCurrentResponse();
493
494         if ( response instanceof BindResponse )
495         {
496             assertTrue( true );
497         }
498         else
499         {
500             fail();
501         }
502     }
503
504
505     /**
506      * Test parsing of a Response with the 2 CompareResponse
507      */

508     public void testResponseWith2CompareResponse()
509     {
510         Dsmlv2ResponseParser parser = null;
511         try
512         {
513             parser = new Dsmlv2ResponseParser();
514
515             parser
516                 .setInputFile( BatchResponseTest.class.getResource( "response_with_2_CompareResponse.xml" ).getFile() );
517
518             parser.parse();
519         }
520         catch ( Exception JavaDoc e )
521         {
522             fail( e.getMessage() );
523         }
524
525         BatchResponse batchResponse = parser.getBatchResponse();
526
527         assertEquals( 2, batchResponse.getResponses().size() );
528
529         LdapResponse response = batchResponse.getCurrentResponse();
530
531         if ( response instanceof CompareResponse )
532         {
533             assertTrue( true );
534         }
535         else
536         {
537             fail();
538         }
539     }
540
541
542     /**
543      * Test parsing of a Response with the 2 DelResponse
544      */

545     public void testResponseWith2DelResponse()
546     {
547         Dsmlv2ResponseParser parser = null;
548         try
549         {
550             parser = new Dsmlv2ResponseParser();
551
552             parser.setInputFile( BatchResponseTest.class.getResource( "response_with_2_DelResponse.xml" ).getFile() );
553
554             parser.parse();
555         }
556         catch ( Exception JavaDoc e )
557         {
558             fail( e.getMessage() );
559         }
560
561         BatchResponse batchResponse = parser.getBatchResponse();
562
563         assertEquals( 2, batchResponse.getResponses().size() );
564
565         LdapResponse response = batchResponse.getCurrentResponse();
566
567         if ( response instanceof DelResponse )
568         {
569             assertTrue( true );
570         }
571         else
572         {
573             fail();
574         }
575     }
576
577
578     /**
579      * Test parsing of a Response with the 2 ErrorResponse
580      */

581     public void testResponseWith2ErrorResponse()
582     {
583         Dsmlv2ResponseParser parser = null;
584         try
585         {
586             parser = new Dsmlv2ResponseParser();
587
588             parser.setInputFile( BatchResponseTest.class.getResource( "response_with_2_ErrorResponse.xml" ).getFile() );
589
590             parser.parse();
591         }
592         catch ( Exception JavaDoc e )
593         {
594             fail( e.getMessage() );
595         }
596
597         BatchResponse batchResponse = parser.getBatchResponse();
598
599         assertEquals( 2, batchResponse.getResponses().size() );
600
601         LdapResponse response = batchResponse.getCurrentResponse();
602
603         if ( response instanceof ErrorResponse )
604         {
605             assertTrue( true );
606         }
607         else
608         {
609             fail();
610         }
611     }
612
613
614     /**
615      * Test parsing of a Response with the 2 ExtendedResponse
616      */

617     public void testResponseWith2ExtendedResponse()
618     {
619         Dsmlv2ResponseParser parser = null;
620         try
621         {
622             parser = new Dsmlv2ResponseParser();
623
624             parser.setInputFile( BatchResponseTest.class.getResource( "response_with_2_ExtendedResponse.xml" )
625                 .getFile() );
626
627             parser.parse();
628         }
629         catch ( Exception JavaDoc e )
630         {
631             fail( e.getMessage() );
632         }
633
634         BatchResponse batchResponse = parser.getBatchResponse();
635
636         assertEquals( 2, batchResponse.getResponses().size() );
637
638         LdapResponse response = batchResponse.getCurrentResponse();
639
640         if ( response instanceof ExtendedResponse )
641         {
642             assertTrue( true );
643         }
644         else
645         {
646             fail();
647         }
648     }
649
650
651     /**
652      * Test parsing of a Response with the 2 ModDNResponse
653      */

654     public void testResponseWith2ModDNResponse()
655     {
656         Dsmlv2ResponseParser parser = null;
657         try
658         {
659             parser = new Dsmlv2ResponseParser();
660
661             parser.setInputFile( BatchResponseTest.class.getResource( "response_with_2_ModDNResponse.xml" ).getFile() );
662
663             parser.parse();
664         }
665         catch ( Exception JavaDoc e )
666         {
667             fail( e.getMessage() );
668         }
669
670         BatchResponse batchResponse = parser.getBatchResponse();
671
672         assertEquals( 2, batchResponse.getResponses().size() );
673
674         LdapResponse response = batchResponse.getCurrentResponse();
675
676         if ( response instanceof ModifyDNResponse )
677         {
678             assertTrue( true );
679         }
680         else
681         {
682             fail();
683         }
684     }
685
686
687     /**
688      * Test parsing of a Response with the 2 ModifyResponse
689      */

690     public void testResponseWith2ModifyResponse()
691     {
692         Dsmlv2ResponseParser parser = null;
693         try
694         {
695             parser = new Dsmlv2ResponseParser();
696
697             parser.setInputFile( BatchResponseTest.class.getResource( "response_with_2_ModifyResponse.xml" ).getFile() );
698
699             parser.parse();
700         }
701         catch ( Exception JavaDoc e )
702         {
703             fail( e.getMessage() );
704         }
705
706         BatchResponse batchResponse = parser.getBatchResponse();
707
708         assertEquals( 2, batchResponse.getResponses().size() );
709
710         LdapResponse response = batchResponse.getCurrentResponse();
711
712         if ( response instanceof ModifyResponse )
713         {
714             assertTrue( true );
715         }
716         else
717         {
718             fail();
719         }
720     }
721
722
723     /**
724      * Test parsing of a Response with the 2 SearchResponse
725      */

726     public void testResponseWith2SearchResponse()
727     {
728         Dsmlv2ResponseParser parser = null;
729         try
730         {
731             parser = new Dsmlv2ResponseParser();
732
733             parser.setInputFile( BatchResponseTest.class.getResource( "response_with_2_SearchResponse.xml" ).getFile() );
734
735             parser.parse();
736         }
737         catch ( Exception JavaDoc e )
738         {
739             fail( e.getMessage() );
740         }
741
742         BatchResponse batchResponse = parser.getBatchResponse();
743
744         assertEquals( 2, batchResponse.getResponses().size() );
745
746         LdapResponse response = batchResponse.getCurrentResponse();
747
748         if ( response instanceof SearchResponse )
749         {
750             assertTrue( true );
751         }
752         else
753         {
754             fail();
755         }
756     }
757 }
758
Popular Tags