KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > dsmlv2 > authRequest > AuthRequestTest


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.authRequest;
22
23
24 import org.apache.directory.ldapstudio.dsmlv2.AbstractTest;
25 import org.apache.directory.ldapstudio.dsmlv2.Dsmlv2Parser;
26 import org.apache.directory.shared.ldap.codec.Control;
27 import org.apache.directory.shared.ldap.codec.bind.BindRequest;
28 import org.apache.directory.shared.ldap.util.StringTools;
29
30
31 /**
32  * Tests for the Auth Request parsing
33  *
34  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
35  * @version $Rev$, $Date$
36  */

37 public class AuthRequestTest extends AbstractTest
38 {
39     /**
40      * Test parsing of a request without the principal attribute
41      */

42     public void testRequestWithoutPrincipal()
43     {
44         testParsingFail( AuthRequestTest.class, "request_without_principal_attribute.xml" );
45     }
46
47
48     /**
49      * Test parsing of a request with the principal attribute
50      */

51     public void testRequestWithPrincipal()
52     {
53         Dsmlv2Parser parser = null;
54         try
55         {
56             parser = new Dsmlv2Parser();
57
58             parser.setInputFile( AuthRequestTest.class.getResource( "request_with_principal_attribute.xml" ).getFile() );
59
60             parser.parse();
61         }
62         catch ( Exception JavaDoc e )
63         {
64             fail( e.getMessage() );
65         }
66
67         BindRequest bindRequest = ( BindRequest ) parser.getBatchRequest().getCurrentRequest();
68
69         assertEquals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM", bindRequest.getName().toString() );
70     }
71
72
73     /**
74      * Test parsing of a request with the (optional) requestID attribute
75      */

76     public void testRequestWithRequestId()
77     {
78         Dsmlv2Parser parser = null;
79         try
80         {
81             parser = new Dsmlv2Parser();
82
83             parser.setInputFile( AuthRequestTest.class.getResource( "request_with_requestID_attribute.xml" ).getFile() );
84
85             parser.parse();
86         }
87         catch ( Exception JavaDoc e )
88         {
89             fail( e.getMessage() );
90         }
91
92         BindRequest abandonRequest = ( BindRequest ) parser.getBatchRequest().getCurrentRequest();
93
94         assertEquals( 456, abandonRequest.getMessageId() );
95     }
96
97
98     /**
99      * Test parsing of a request with the (optional) requestID attribute equals to 0
100      */

101     public void testRequestWithRequestIdEquals0()
102     {
103         testParsingFail( AuthRequestTest.class, "request_with_requestID_equals_0.xml" );
104     }
105
106
107     /**
108      * Test parsing of a request with a (optional) Control element
109      */

110     public void testRequestWith1Control()
111     {
112         Dsmlv2Parser parser = null;
113         try
114         {
115             parser = new Dsmlv2Parser();
116
117             parser.setInputFile( AuthRequestTest.class.getResource( "request_with_1_control.xml" ).getFile() );
118
119             parser.parse();
120         }
121         catch ( Exception JavaDoc e )
122         {
123             fail( e.getMessage() );
124         }
125
126         BindRequest abandonRequest = ( BindRequest ) parser.getBatchRequest().getCurrentRequest();
127         Control control = abandonRequest.getCurrentControl();
128
129         assertEquals( 1, abandonRequest.getControls().size() );
130         assertTrue( control.getCriticality() );
131         assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
132         assertEquals( "Some text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
133     }
134
135
136     /**
137      * Test parsing of a request with a (optional) Control element with Base64 value
138      */

139     public void testRequestWith1ControlBase64Value()
140     {
141         Dsmlv2Parser parser = null;
142         try
143         {
144             parser = new Dsmlv2Parser();
145
146             parser.setInputFile( AuthRequestTest.class.getResource( "request_with_1_control_base64_value.xml" )
147                 .getFile() );
148
149             parser.parse();
150         }
151         catch ( Exception JavaDoc e )
152         {
153             fail( e.getMessage() );
154         }
155
156         BindRequest abandonRequest = ( BindRequest ) parser.getBatchRequest().getCurrentRequest();
157         Control control = abandonRequest.getCurrentControl();
158
159         assertEquals( 1, abandonRequest.getControls().size() );
160         assertTrue( control.getCriticality() );
161         assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
162         assertEquals( "DSMLv2.0 rocks!!", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
163     }
164
165
166     /**
167      * Test parsing of a request with a (optional) Control element with empty value
168      */

169     public void testRequestWith1ControlEmptyValue()
170     {
171         Dsmlv2Parser parser = null;
172         try
173         {
174             parser = new Dsmlv2Parser();
175
176             parser.setInputFile( AuthRequestTest.class.getResource( "request_with_1_control_empty_value.xml" )
177                 .getFile() );
178
179             parser.parse();
180         }
181         catch ( Exception JavaDoc e )
182         {
183             fail( e.getMessage() );
184         }
185
186         BindRequest abandonRequest = ( BindRequest ) parser.getBatchRequest().getCurrentRequest();
187         Control control = abandonRequest.getCurrentControl();
188
189         assertEquals( 1, abandonRequest.getControls().size() );
190         assertTrue( control.getCriticality() );
191         assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
192         assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() );
193     }
194
195
196     /**
197      * Test parsing of a request with 2 (optional) Control elements
198      */

199     public void testRequestWith2Controls()
200     {
201         Dsmlv2Parser parser = null;
202         try
203         {
204             parser = new Dsmlv2Parser();
205
206             parser.setInputFile( AuthRequestTest.class.getResource( "request_with_2_controls.xml" ).getFile() );
207
208             parser.parse();
209         }
210         catch ( Exception JavaDoc e )
211         {
212             fail( e.getMessage() );
213         }
214
215         BindRequest abandonRequest = ( BindRequest ) parser.getBatchRequest().getCurrentRequest();
216         Control control = abandonRequest.getCurrentControl();
217
218         assertEquals( 2, abandonRequest.getControls().size() );
219         assertFalse( control.getCriticality() );
220         assertEquals( "1.2.840.113556.1.4.789", control.getControlType() );
221         assertEquals( "Some other text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
222     }
223
224
225     /**
226      * Test parsing of a request with 3 (optional) Control elements without value
227      */

228     public void testRequestWith3ControlsWithoutValue()
229     {
230         Dsmlv2Parser parser = null;
231         try
232         {
233             parser = new Dsmlv2Parser();
234
235             parser.setInputFile( AuthRequestTest.class.getResource( "request_with_3_controls_without_value.xml" )
236                 .getFile() );
237
238             parser.parse();
239         }
240         catch ( Exception JavaDoc e )
241         {
242             fail( e.getMessage() );
243         }
244
245         BindRequest abandonRequest = ( BindRequest ) parser.getBatchRequest().getCurrentRequest();
246         Control control = abandonRequest.getCurrentControl();
247
248         assertEquals( 3, abandonRequest.getControls().size() );
249         assertTrue( control.getCriticality() );
250         assertEquals( "1.2.840.113556.1.4.456", control.getControlType() );
251         assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() );
252     }
253
254
255     /**
256      * Test parsing of a request with a needed requestID attribute
257      *
258      * DIRSTUDIO-1
259      */

260     public void testRequestWithNeededRequestId()
261     {
262         testParsingFail( AuthRequestTest.class, "request_with_needed_requestID.xml" );
263     }
264 }
265
Popular Tags