KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > dsmlv2 > abandonRequest > AbandonRequestTest


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.abandonRequest;
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.abandon.AbandonRequest;
28 import org.apache.directory.shared.ldap.util.StringTools;
29
30
31 /**
32  * Tests for the Abandon Request parsing
33  *
34  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
35  * @version $Rev$, $Date$
36  */

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

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

51     public void testRequestWithAbandonId()
52     {
53         Dsmlv2Parser parser = null;
54         try
55         {
56             parser = new Dsmlv2Parser();
57
58             parser.setInputFile( AbandonRequestTest.class.getResource( "request_with_abandonID_attribute.xml" )
59                 .getFile() );
60
61             parser.parse();
62         }
63         catch ( Exception JavaDoc e )
64         {
65             fail( e.getMessage() );
66         }
67
68         AbandonRequest abandonRequest = ( AbandonRequest ) parser.getBatchRequest().getCurrentRequest();
69
70         assertEquals( 123, abandonRequest.getAbandonedMessageId() );
71     }
72
73
74     /**
75      * Test parsing of a request with the (optional) requestID attribute equals to 0
76      */

77     public void testRequestWithRequestIdEquals0()
78     {
79         testParsingFail( AbandonRequestTest.class, "request_with_requestID_equals_0.xml" );
80     }
81     
82     /**
83      * Test parsing of a request with the (optional) requestID attribute
84      */

85     public void testRequestWithRequestId()
86     {
87         Dsmlv2Parser parser = null;
88         try
89         {
90             parser = new Dsmlv2Parser();
91
92             parser.setInputFile( AbandonRequestTest.class.getResource( "request_with_requestID_attribute.xml" )
93                 .getFile() );
94
95             parser.parse();
96         }
97         catch ( Exception JavaDoc e )
98         {
99             fail( e.getMessage() );
100         }
101
102         AbandonRequest abandonRequest = ( AbandonRequest ) parser.getBatchRequest().getCurrentRequest();
103
104         assertEquals( 456, abandonRequest.getMessageId() );
105     }
106
107
108     /**
109      * Test parsing of a request with a (optional) Control element
110      */

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

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

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

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

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

264     public void testRequestWithNeededRequestId()
265     {
266         testParsingFail( AbandonRequestTest.class, "request_with_needed_requestID.xml" );
267     }
268 }
269
Popular Tags