KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > dsmlv2 > searchResponse > SearchResponseTest


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.searchResponse;
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.SearchResponse;
27
28
29 /**
30  * Tests for the Search Result Done Response parsing
31  *
32  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
33  * @version $Rev$, $Date$
34  */

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

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

66     public void testResponseWithRequestIdEquals0()
67     {
68         testParsingFail( SearchResponseTest.class, "response_with_requestID_equals_0.xml" );
69     }
70
71
72     /**
73      * Test parsing of a Response with a Search Result Done
74      */

75     public void testResponseWithSRD()
76     {
77         Dsmlv2ResponseParser parser = null;
78         try
79         {
80             parser = new Dsmlv2ResponseParser();
81
82             parser.setInputFile( SearchResponseTest.class.getResource( "response_with_1_SRD.xml" ).getFile() );
83
84             parser.parse();
85         }
86         catch ( Exception JavaDoc e )
87         {
88             fail( e.getMessage() );
89         }
90
91         SearchResponse searchResponse = ( SearchResponse ) parser.getBatchResponse().getCurrentResponse();
92
93         assertNotNull( searchResponse.getSearchResultDone() );
94     }
95
96
97     /**
98      * Test parsing of a Response with 1 Search Result Entry and a Search Result Done
99      */

100     public void testResponseWith1SRE1SRD()
101     {
102         Dsmlv2ResponseParser parser = null;
103         try
104         {
105             parser = new Dsmlv2ResponseParser();
106
107             parser.setInputFile( SearchResponseTest.class.getResource( "response_with_1_SRE_1_SRD.xml" ).getFile() );
108
109             parser.parse();
110         }
111         catch ( Exception JavaDoc e )
112         {
113             fail( e.getMessage() );
114         }
115
116         SearchResponse searchResponse = ( SearchResponse ) parser.getBatchResponse().getCurrentResponse();
117
118         assertEquals( 1, searchResponse.getSearchResultEntryList().size() );
119
120         assertNotNull( searchResponse.getSearchResultDone() );
121     }
122
123
124     /**
125      * Test parsing of a Response with 1 Search Result Reference and a Search Result Done
126      */

127     public void testResponseWith1SRR1SRD()
128     {
129         Dsmlv2ResponseParser parser = null;
130         try
131         {
132             parser = new Dsmlv2ResponseParser();
133
134             parser.setInputFile( SearchResponseTest.class.getResource( "response_with_1_SRR_1_SRD.xml" ).getFile() );
135
136             parser.parse();
137         }
138         catch ( Exception JavaDoc e )
139         {
140             fail( e.getMessage() );
141         }
142
143         SearchResponse searchResponse = ( SearchResponse ) parser.getBatchResponse().getCurrentResponse();
144
145         assertEquals( 1, searchResponse.getSearchResultReferenceList().size() );
146
147         assertNotNull( searchResponse.getSearchResultDone() );
148     }
149
150
151     /**
152      * Test parsing of a Response with 1 Search Result Entry, 1 Search Result Reference and a Search Result Done
153      */

154     public void testResponseWith1SRE1SRR1SRD()
155     {
156         Dsmlv2ResponseParser parser = null;
157         try
158         {
159             parser = new Dsmlv2ResponseParser();
160
161             parser.setInputFile( SearchResponseTest.class.getResource( "response_with_1_SRE_1_SRR_1_SRD.xml" )
162                 .getFile() );
163
164             parser.parse();
165         }
166         catch ( Exception JavaDoc e )
167         {
168             fail( e.getMessage() );
169         }
170
171         SearchResponse searchResponse = ( SearchResponse ) parser.getBatchResponse().getCurrentResponse();
172
173         assertEquals( 1, searchResponse.getSearchResultEntryList().size() );
174
175         assertEquals( 1, searchResponse.getSearchResultReferenceList().size() );
176
177         assertNotNull( searchResponse.getSearchResultDone() );
178     }
179
180
181     /**
182      * Test parsing of a Response with 2 Search Result Entry and a Search Result Done
183      */

184     public void testResponseWith2SRE1SRD()
185     {
186         Dsmlv2ResponseParser parser = null;
187         try
188         {
189             parser = new Dsmlv2ResponseParser();
190
191             parser.setInputFile( SearchResponseTest.class.getResource( "response_with_2_SRE_1_SRD.xml" ).getFile() );
192
193             parser.parse();
194         }
195         catch ( Exception JavaDoc e )
196         {
197             fail( e.getMessage() );
198         }
199
200         SearchResponse searchResponse = ( SearchResponse ) parser.getBatchResponse().getCurrentResponse();
201
202         assertEquals( 2, searchResponse.getSearchResultEntryList().size() );
203
204         assertNotNull( searchResponse.getSearchResultDone() );
205     }
206
207
208     /**
209      * Test parsing of a Response with 2 Search Result Reference and a Search Result Done
210      */

211     public void testResponseWith2SRR1SRD()
212     {
213         Dsmlv2ResponseParser parser = null;
214         try
215         {
216             parser = new Dsmlv2ResponseParser();
217
218             parser.setInputFile( SearchResponseTest.class.getResource( "response_with_2_SRR_1_SRD.xml" ).getFile() );
219
220             parser.parse();
221         }
222         catch ( Exception JavaDoc e )
223         {
224             fail( e.getMessage() );
225         }
226
227         SearchResponse searchResponse = ( SearchResponse ) parser.getBatchResponse().getCurrentResponse();
228
229         assertEquals( 2, searchResponse.getSearchResultReferenceList().size() );
230
231         assertNotNull( searchResponse.getSearchResultDone() );
232     }
233
234
235     /**
236      * Test parsing of a Response with 2 Search Result Entry, 2 Search Result Reference and a Search Result Done
237      */

238     public void testResponseWith2SRE2SRR1SRD()
239     {
240         Dsmlv2ResponseParser parser = null;
241         try
242         {
243             parser = new Dsmlv2ResponseParser();
244
245             parser.setInputFile( SearchResponseTest.class.getResource( "response_with_2_SRE_2_SRR_1_SRD.xml" )
246                 .getFile() );
247
248             parser.parse();
249         }
250         catch ( Exception JavaDoc e )
251         {
252             fail( e.getMessage() );
253         }
254
255         SearchResponse searchResponse = ( SearchResponse ) parser.getBatchResponse().getCurrentResponse();
256
257         assertEquals( 2, searchResponse.getSearchResultEntryList().size() );
258
259         assertEquals( 2, searchResponse.getSearchResultReferenceList().size() );
260
261         assertNotNull( searchResponse.getSearchResultDone() );
262     }
263
264
265     /**
266      * Test parsing of a response with no Search Result Done
267      */

268     public void testResponseWith0SRD()
269     {
270         testParsingFail( SearchResponseTest.class, "response_with_0_SRD.xml" );
271     }
272
273
274     /**
275      * Test parsing of a response with 1 Search Result Entry but no Search Result Done
276      */

277     public void testResponseWith1SRE0SRD()
278     {
279         testParsingFail( SearchResponseTest.class, "response_with_1_SRE_0_SRD.xml" );
280     }
281
282
283     /**
284      * Test parsing of a response with 1 Search Result Reference but no Search Result Done
285      */

286     public void testResponseWith1SRR0SRD()
287     {
288         testParsingFail( SearchResponseTest.class, "response_with_1_SRR_0_SRD.xml" );
289     }
290 }
291
Popular Tags