You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2009/07/21 19:04:29 UTC

svn commit: r796383 [9/23] - in /directory/shared/trunk: ./ dsml-parser/ dsml-parser/src/ dsml-parser/src/main/ dsml-parser/src/main/java/ dsml-parser/src/main/java/org/ dsml-parser/src/main/java/org/apache/ dsml-parser/src/main/java/org/apache/directo...

Added: directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/authRequest/AuthRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/authRequest/AuthRequestTest.java?rev=796383&view=auto
==============================================================================
--- directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/authRequest/AuthRequestTest.java (added)
+++ directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/authRequest/AuthRequestTest.java Tue Jul 21 17:04:13 2009
@@ -0,0 +1,266 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.dsmlv2.authRequest;
+
+
+import org.apache.directory.shared.ldap.codec.ControlCodec;
+import org.apache.directory.shared.ldap.codec.bind.BindRequestCodec;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.studio.dsmlv2.AbstractTest;
+import org.apache.directory.studio.dsmlv2.Dsmlv2Parser;
+
+
+/**
+ * Tests for the Auth Request parsing
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class AuthRequestTest extends AbstractTest
+{
+    /**
+     * Test parsing of a request without the principal attribute
+     */
+    public void testRequestWithoutPrincipal()
+    {
+        testParsingFail( AuthRequestTest.class, "request_without_principal_attribute.xml" );
+    }
+
+
+    /**
+     * Test parsing of a request with the principal attribute
+     */
+    public void testRequestWithPrincipal()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( AuthRequestTest.class.getResource( "request_with_principal_attribute.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindRequestCodec bindRequest = ( BindRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM", bindRequest.getName().toString() );
+    }
+
+
+    /**
+     * Test parsing of a request with the (optional) requestID attribute
+     */
+    public void testRequestWithRequestId()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( AuthRequestTest.class.getResource( "request_with_requestID_attribute.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindRequestCodec abandonRequest = ( BindRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( 456, abandonRequest.getMessageId() );
+    }
+
+
+    /**
+     * Test parsing of a request with the (optional) requestID attribute equals to 0
+     */
+    public void testRequestWithRequestIdEquals0()
+    {
+        testParsingFail( AuthRequestTest.class, "request_with_requestID_equals_0.xml" );
+    }
+
+
+    /**
+     * Test parsing of a request with a (optional) Control element
+     */
+    public void testRequestWith1Control()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( AuthRequestTest.class.getResource( "request_with_1_control.xml" ).openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindRequestCodec abandonRequest = ( BindRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+        ControlCodec control = abandonRequest.getCurrentControl();
+
+        assertEquals( 1, abandonRequest.getControls().size() );
+        assertTrue( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
+        assertEquals( "Some text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
+    }
+
+
+    /**
+     * Test parsing of a request with a (optional) Control element with Base64 value
+     */
+    public void testRequestWith1ControlBase64Value()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( AuthRequestTest.class.getResource( "request_with_1_control_base64_value.xml" )
+                .openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindRequestCodec abandonRequest = ( BindRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+        ControlCodec control = abandonRequest.getCurrentControl();
+
+        assertEquals( 1, abandonRequest.getControls().size() );
+        assertTrue( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
+        assertEquals( "DSMLv2.0 rocks!!", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
+    }
+
+
+    /**
+     * Test parsing of a request with a (optional) Control element with empty value
+     */
+    public void testRequestWith1ControlEmptyValue()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput(
+                AuthRequestTest.class.getResource( "request_with_1_control_empty_value.xml" ).openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindRequestCodec abandonRequest = ( BindRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+        ControlCodec control = abandonRequest.getCurrentControl();
+
+        assertEquals( 1, abandonRequest.getControls().size() );
+        assertTrue( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
+        assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() );
+    }
+
+
+    /**
+     * Test parsing of a request with 2 (optional) Control elements
+     */
+    public void testRequestWith2Controls()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( AuthRequestTest.class.getResource( "request_with_2_controls.xml" ).openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindRequestCodec abandonRequest = ( BindRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+        ControlCodec control = abandonRequest.getCurrentControl();
+
+        assertEquals( 2, abandonRequest.getControls().size() );
+        assertFalse( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.789", control.getControlType() );
+        assertEquals( "Some other text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
+    }
+
+
+    /**
+     * Test parsing of a request with 3 (optional) Control elements without value
+     */
+    public void testRequestWith3ControlsWithoutValue()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( AuthRequestTest.class.getResource( "request_with_3_controls_without_value.xml" )
+                .openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindRequestCodec abandonRequest = ( BindRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+        ControlCodec control = abandonRequest.getCurrentControl();
+
+        assertEquals( 3, abandonRequest.getControls().size() );
+        assertTrue( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.456", control.getControlType() );
+        assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() );
+    }
+
+
+    /**
+     * Test parsing of a request with a needed requestID attribute
+     * 
+     * DIRSTUDIO-1
+     */
+    public void testRequestWithNeededRequestId()
+    {
+        testParsingFail( AuthRequestTest.class, "request_with_needed_requestID.xml" );
+    }
+}

Added: directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/authResponse/AuthResponseTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/authResponse/AuthResponseTest.java?rev=796383&view=auto
==============================================================================
--- directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/authResponse/AuthResponseTest.java (added)
+++ directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/authResponse/AuthResponseTest.java Tue Jul 21 17:04:13 2009
@@ -0,0 +1,525 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.dsmlv2.authResponse;
+
+
+import java.util.List;
+
+import javax.naming.NamingException;
+
+import org.apache.directory.shared.ldap.codec.ControlCodec;
+import org.apache.directory.shared.ldap.codec.LdapResultCodec;
+import org.apache.directory.shared.ldap.codec.bind.BindResponseCodec;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.studio.dsmlv2.AbstractResponseTest;
+import org.apache.directory.studio.dsmlv2.Dsmlv2ResponseParser;
+
+import com.sun.jndi.ldap.LdapURL;
+
+
+/**
+ * Tests for the Auth Response parsing
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class AuthResponseTest extends AbstractResponseTest
+{
+
+    /**
+     * Test parsing of a Response with the (optional) requestID attribute
+     */
+    public void testResponseWithRequestId()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput(
+                AuthResponseTest.class.getResource( "response_with_requestID_attribute.xml" ).openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindResponseCodec bindResponse = ( BindResponseCodec ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 456, bindResponse.getMessageId() );
+    }
+
+
+    /**
+     * Test parsing of a Response with the (optional) requestID attribute equals 0
+     */
+    public void testResponseWithRequestIdEquals0()
+    {
+        testParsingFail( AuthResponseTest.class, "response_with_requestID_equals_0.xml" );
+    }
+
+
+    /**
+     * Test parsing of a response with a (optional) Control element
+     */
+    public void testResponseWith1Control()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( AuthResponseTest.class.getResource( "response_with_1_control.xml" ).openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindResponseCodec bindResponse = ( BindResponseCodec ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 1, bindResponse.getControls().size() );
+
+        ControlCodec control = bindResponse.getCurrentControl();
+
+        assertTrue( control.getCriticality() );
+
+        assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
+
+        assertEquals( "Some text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
+    }
+
+
+    /**
+     * Test parsing of a response with a (optional) Control element with empty value
+     */
+    public void testResponseWith1ControlEmptyValue()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( AuthResponseTest.class.getResource( "response_with_1_control_empty_value.xml" )
+                .openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindResponseCodec bindResponse = ( BindResponseCodec ) parser.getBatchResponse().getCurrentResponse();
+        ControlCodec control = bindResponse.getCurrentControl();
+
+        assertEquals( 1, bindResponse.getControls().size() );
+        assertTrue( control.getCriticality() );
+        assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
+        assertEquals( StringTools.EMPTY_BYTES, ( byte[] ) control.getControlValue() );
+    }
+
+
+    /**
+     * Test parsing of a response with 2 (optional) Control elements
+     */
+    public void testResponseWith2Controls()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser
+                .setInput( AuthResponseTest.class.getResource( "response_with_2_controls.xml" ).openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindResponseCodec bindResponse = ( BindResponseCodec ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 2, bindResponse.getControls().size() );
+
+        ControlCodec control = bindResponse.getCurrentControl();
+
+        assertFalse( control.getCriticality() );
+
+        assertEquals( "1.2.840.113556.1.4.789", control.getControlType() );
+
+        assertEquals( "Some other text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
+    }
+
+
+    /**
+     * Test parsing of a response with 3 (optional) Control elements without value
+     */
+    public void testResponseWith3ControlsWithoutValue()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( AuthResponseTest.class.getResource( "response_with_3_controls_without_value.xml" )
+                .openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindResponseCodec bindResponse = ( BindResponseCodec ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 3, bindResponse.getControls().size() );
+
+        ControlCodec control = bindResponse.getCurrentControl();
+
+        assertTrue( control.getCriticality() );
+
+        assertEquals( "1.2.840.113556.1.4.456", control.getControlType() );
+
+        assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() );
+    }
+
+
+    /**
+     * Test parsing of a response without Result Code element
+     */
+    public void testResponseWithoutResultCode()
+    {
+        testParsingFail( AuthResponseTest.class, "response_without_result_code.xml" );
+    }
+
+
+    /**
+     * Test parsing of a response with Result Code element but a not integer value
+     */
+    public void testResponseWithResultCodeNotInteger()
+    {
+        testParsingFail( AuthResponseTest.class, "response_with_result_code_not_integer.xml" );
+    }
+
+
+    /**
+     * Test parsing of a response with Result Code 
+     */
+    public void testResponseWithResultCode()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( AuthResponseTest.class.getResource( "response_with_result_code.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindResponseCodec bindResponse = ( BindResponseCodec ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResultCodec ldapResult = bindResponse.getLdapResult();
+
+        assertEquals( ResultCodeEnum.PROTOCOL_ERROR, ldapResult.getResultCode() );
+    }
+
+
+    /**
+     * Test parsing of a response with Error Message
+     */
+    public void testResponseWithErrorMessage()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( AuthResponseTest.class.getResource( "response_with_error_message.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindResponseCodec bindResponse = ( BindResponseCodec ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResultCodec ldapResult = bindResponse.getLdapResult();
+
+        assertEquals( "Unrecognized extended operation EXTENSION_OID: 1.2.6.1.4.1.18060.1.1.1.100.2", ldapResult
+            .getErrorMessage() );
+    }
+
+
+    /**
+     * Test parsing of a response with Empty Error Message
+     */
+    public void testResponseWithEmptyErrorMessage()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput(
+                AuthResponseTest.class.getResource( "response_with_empty_error_message.xml" ).openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindResponseCodec bindResponse = ( BindResponseCodec ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResultCodec ldapResult = bindResponse.getLdapResult();
+
+        assertNull( ldapResult.getErrorMessage() );
+    }
+
+
+    /**
+     * Test parsing of a response with a Referral
+     */
+    public void testResponseWith1Referral()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser
+                .setInput( AuthResponseTest.class.getResource( "response_with_1_referral.xml" ).openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindResponseCodec bindResponse = ( BindResponseCodec ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResultCodec ldapResult = bindResponse.getLdapResult();
+
+        List referrals = ldapResult.getReferrals();
+
+        assertEquals( 1, referrals.size() );
+
+        Object referral = referrals.get( 0 );
+
+        try
+        {
+            assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
+        }
+        catch ( NamingException e )
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a response with an empty Referral
+     */
+    public void testResponseWith1EmptyReferral()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( AuthResponseTest.class.getResource( "response_with_1_empty_referral.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindResponseCodec bindResponse = ( BindResponseCodec ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResultCodec ldapResult = bindResponse.getLdapResult();
+
+        List referrals = ldapResult.getReferrals();
+
+        assertEquals( 0, referrals.size() );
+    }
+
+
+    /**
+     * Test parsing of a response with 2 Referral elements
+     */
+    public void testResponseWith2Referrals()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( AuthResponseTest.class.getResource( "response_with_2_referrals.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindResponseCodec bindResponse = ( BindResponseCodec ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResultCodec ldapResult = bindResponse.getLdapResult();
+
+        List referrals = ldapResult.getReferrals();
+
+        assertEquals( 2, referrals.size() );
+
+        Object referral = referrals.get( 0 );
+
+        try
+        {
+            assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
+        }
+        catch ( NamingException e )
+        {
+            fail();
+        }
+
+        Object referral2 = referrals.get( 1 );
+
+        try
+        {
+            assertEquals( new LdapURL( "ldap://www.apple.com/" ).toString(), referral2.toString() );
+        }
+        catch ( NamingException e )
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a response with a Referral and an Error Message
+     */
+    public void testResponseWith1ReferralAndAnErrorMessage()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( AuthResponseTest.class.getResource( "response_with_1_referral_and_error_message.xml" )
+                .openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindResponseCodec bindResponse = ( BindResponseCodec ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResultCodec ldapResult = bindResponse.getLdapResult();
+
+        List referrals = ldapResult.getReferrals();
+
+        assertEquals( 1, referrals.size() );
+
+        Object referral = referrals.get( 0 );
+
+        try
+        {
+            assertEquals( new LdapURL( "ldap://www.apache.org/" ).toString(), referral.toString() );
+        }
+        catch ( NamingException e )
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a response with MatchedDN attribute
+     */
+    public void testResponseWithMatchedDNAttribute()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput(
+                AuthResponseTest.class.getResource( "response_with_matchedDN_attribute.xml" ).openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindResponseCodec bindResponse = ( BindResponseCodec ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResultCodec ldapResult = bindResponse.getLdapResult();
+
+        assertEquals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM", ldapResult.getMatchedDN() );
+    }
+
+
+    /**
+     * Test parsing of a response with wrong matched DN
+     */
+    public void testResponseWithWrongMatchedDN()
+    {
+        testParsingFail( AuthResponseTest.class, "response_with_wrong_matchedDN_attribute.xml" );
+    }
+
+
+    /**
+     * Test parsing of a response with wrong Descr attribute
+     */
+    public void testResponseWithWrongDescr()
+    {
+        testParsingFail( AuthResponseTest.class, "response_with_wrong_matchedDN_attribute.xml" );
+    }
+}

Added: directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/batchRequest/BatchRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/batchRequest/BatchRequestTest.java?rev=796383&view=auto
==============================================================================
--- directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/batchRequest/BatchRequestTest.java (added)
+++ directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/batchRequest/BatchRequestTest.java Tue Jul 21 17:04:13 2009
@@ -0,0 +1,796 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.dsmlv2.batchRequest;
+
+
+import java.util.List;
+
+import org.apache.directory.shared.ldap.codec.LdapMessageCodec;
+import org.apache.directory.shared.ldap.codec.abandon.AbandonRequestCodec;
+import org.apache.directory.shared.ldap.codec.add.AddRequestCodec;
+import org.apache.directory.shared.ldap.codec.bind.BindRequestCodec;
+import org.apache.directory.shared.ldap.codec.compare.CompareRequestCodec;
+import org.apache.directory.shared.ldap.codec.del.DelRequestCodec;
+import org.apache.directory.shared.ldap.codec.extended.ExtendedRequestCodec;
+import org.apache.directory.shared.ldap.codec.modify.ModifyRequestCodec;
+import org.apache.directory.shared.ldap.codec.modifyDn.ModifyDNRequestCodec;
+import org.apache.directory.shared.ldap.codec.search.SearchRequestCodec;
+import org.apache.directory.studio.dsmlv2.AbstractTest;
+import org.apache.directory.studio.dsmlv2.Dsmlv2Parser;
+import org.apache.directory.studio.dsmlv2.request.BatchRequest;
+
+
+/**
+ * Tests for the Compare Response parsing
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BatchRequestTest extends AbstractTest
+{
+    /**
+     * Test parsing of a Request with the (optional) requestID attribute
+     */
+    public void testResponseWithRequestId()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( BatchRequestTest.class.getResource( "request_with_requestID_attribute.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 1234567890, batchRequest.getRequestID() );
+    }
+
+
+    /**
+     * Test parsing of a request with the (optional) requestID attribute equals to 0
+     */
+    public void testRequestWithRequestIdEquals0()
+    {
+        testParsingFail( BatchRequestTest.class, "request_with_requestID_equals_0.xml" );
+    }
+
+
+    /**
+     * Test parsing of a Request with the (optional) requestID attribute
+     */
+    public void testResponseWith0Request()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( BatchRequestTest.class.getResource( "request_with_requestID_attribute.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 0, batchRequest.getRequests().size() );
+    }
+
+
+    /**
+     * Test parsing of a Request with 1 AuthRequest
+     */
+    public void testResponseWith1AuthRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( BatchRequestTest.class.getResource( "request_with_1_AuthRequest.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 1, batchRequest.getRequests().size() );
+
+        LdapMessageCodec request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof BindRequestCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 1 AddRequest
+     */
+    public void testResponseWith1AddRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( BatchRequestTest.class.getResource( "request_with_1_AddRequest.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 1, batchRequest.getRequests().size() );
+
+        LdapMessageCodec request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof AddRequestCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 1 CompareRequest
+     */
+    public void testResponseWith1CompareRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( BatchRequestTest.class.getResource( "request_with_1_CompareRequest.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 1, batchRequest.getRequests().size() );
+
+        LdapMessageCodec request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof CompareRequestCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 1 AbandonRequest
+     */
+    public void testResponseWith1AbandonRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( BatchRequestTest.class.getResource( "request_with_1_AbandonRequest.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 1, batchRequest.getRequests().size() );
+
+        LdapMessageCodec request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof AbandonRequestCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 1 DelRequest
+     */
+    public void testResponseWith1DelRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( BatchRequestTest.class.getResource( "request_with_1_DelRequest.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 1, batchRequest.getRequests().size() );
+
+        LdapMessageCodec request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof DelRequestCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 1 ExtendedRequest
+     */
+    public void testResponseWith1ExtendedRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( BatchRequestTest.class.getResource( "request_with_1_ExtendedRequest.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 1, batchRequest.getRequests().size() );
+
+        LdapMessageCodec request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof ExtendedRequestCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 1 ModDNRequest
+     */
+    public void testResponseWith1ModDNRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( BatchRequestTest.class.getResource( "request_with_1_ModDNRequest.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 1, batchRequest.getRequests().size() );
+
+        LdapMessageCodec request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof ModifyDNRequestCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 1 ModifyRequest
+     */
+    public void testResponseWith1ModifyRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( BatchRequestTest.class.getResource( "request_with_1_ModifyRequest.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 1, batchRequest.getRequests().size() );
+
+        LdapMessageCodec request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof ModifyRequestCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 1 SearchRequest
+     */
+    public void testResponseWith1SearchRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( BatchRequestTest.class.getResource( "request_with_1_SearchRequest.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 1, batchRequest.getRequests().size() );
+
+        LdapMessageCodec request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof SearchRequestCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 2 AddRequest
+     */
+    public void testResponseWith2AddRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( BatchRequestTest.class.getResource( "request_with_2_AddRequest.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 2, batchRequest.getRequests().size() );
+
+        LdapMessageCodec request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof AddRequestCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 2 CompareRequest
+     */
+    public void testResponseWith2CompareRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( BatchRequestTest.class.getResource( "request_with_2_CompareRequest.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 2, batchRequest.getRequests().size() );
+
+        LdapMessageCodec request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof CompareRequestCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 2 AbandonRequest
+     */
+    public void testResponseWith2AbandonRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( BatchRequestTest.class.getResource( "request_with_2_AbandonRequest.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 2, batchRequest.getRequests().size() );
+
+        LdapMessageCodec request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof AbandonRequestCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 2 DelRequest
+     */
+    public void testResponseWith2DelRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( BatchRequestTest.class.getResource( "request_with_2_DelRequest.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 2, batchRequest.getRequests().size() );
+
+        LdapMessageCodec request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof DelRequestCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 2 ExtendedRequest
+     */
+    public void testResponseWith2ExtendedRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( BatchRequestTest.class.getResource( "request_with_2_ExtendedRequest.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 2, batchRequest.getRequests().size() );
+
+        LdapMessageCodec request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof ExtendedRequestCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 2 ModDNRequest
+     */
+    public void testResponseWith2ModDNRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( BatchRequestTest.class.getResource( "request_with_2_ModDNRequest.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 2, batchRequest.getRequests().size() );
+
+        LdapMessageCodec request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof ModifyDNRequestCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 2 ModifyRequest
+     */
+    public void testResponseWith2ModifyRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( BatchRequestTest.class.getResource( "request_with_2_ModifyRequest.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 2, batchRequest.getRequests().size() );
+
+        LdapMessageCodec request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof ModifyRequestCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 2 SearchRequest
+     */
+    public void testResponseWith2SearchRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( BatchRequestTest.class.getResource( "request_with_2_SearchRequest.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 2, batchRequest.getRequests().size() );
+
+        LdapMessageCodec request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof SearchRequestCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 1 AuthRequest and 1 AddRequest
+     */
+    public void testResponseWith1AuthRequestAnd1AddRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( BatchRequestTest.class.getResource( "request_with_1_AuthRequest_1_AddRequest.xml" )
+                .openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        List requests = batchRequest.getRequests();
+
+        assertEquals( 2, requests.size() );
+
+        LdapMessageCodec request = ( LdapMessageCodec ) requests.get( 0 );
+
+        if ( request instanceof BindRequestCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+
+        request = ( LdapMessageCodec ) requests.get( 1 );
+
+        if ( request instanceof AddRequestCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a request with 1 wrong placed AuthRequest
+     */
+    public void testRequestWithWrongPlacedAuthRequest()
+    {
+        testParsingFail( BatchRequestTest.class, "request_with_wrong_placed_AuthRequest.xml" );
+    }
+}

Added: directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/batchResponse/BatchResponseTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/batchResponse/BatchResponseTest.java?rev=796383&view=auto
==============================================================================
--- directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/batchResponse/BatchResponseTest.java (added)
+++ directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/batchResponse/BatchResponseTest.java Tue Jul 21 17:04:13 2009
@@ -0,0 +1,772 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.dsmlv2.batchResponse;
+
+
+import org.apache.directory.shared.ldap.codec.LdapResponseCodec;
+import org.apache.directory.shared.ldap.codec.add.AddResponseCodec;
+import org.apache.directory.shared.ldap.codec.bind.BindResponseCodec;
+import org.apache.directory.shared.ldap.codec.compare.CompareResponseCodec;
+import org.apache.directory.shared.ldap.codec.del.DelResponseCodec;
+import org.apache.directory.shared.ldap.codec.extended.ExtendedResponseCodec;
+import org.apache.directory.shared.ldap.codec.modify.ModifyResponseCodec;
+import org.apache.directory.shared.ldap.codec.modifyDn.ModifyDNResponseCodec;
+import org.apache.directory.studio.dsmlv2.AbstractResponseTest;
+import org.apache.directory.studio.dsmlv2.Dsmlv2ResponseParser;
+import org.apache.directory.studio.dsmlv2.reponse.BatchResponse;
+import org.apache.directory.studio.dsmlv2.reponse.ErrorResponse;
+import org.apache.directory.studio.dsmlv2.reponse.SearchResponse;
+
+
+/**
+ * Tests for the Compare Response parsing
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BatchResponseTest extends AbstractResponseTest
+{
+    /**
+     * Test parsing of a Response with the (optional) requestID attribute
+     */
+    public void testResponseWithRequestId()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( BatchResponseTest.class.getResource( "response_with_requestID_attribute.xml" )
+                .openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 1234567890, batchResponse.getRequestID() );
+    }
+
+
+    /**
+     * Test parsing of a Response with the (optional) requestID attribute equals 0
+     */
+    public void testResponseWithRequestIdEquals0()
+    {
+        testParsingFail( BatchResponseTest.class, "response_with_requestID_equals_0.xml" );
+    }
+
+
+    /**
+     * Test parsing of a Response with 0 Response
+     */
+    public void testResponseWith0Reponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( BatchResponseTest.class.getResource( "response_with_0_response.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 0, batchResponse.getResponses().size() );
+    }
+
+
+    /**
+     * Test parsing of a Response with the 1 AddResponse
+     */
+    public void testResponseWith1AddResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( BatchResponseTest.class.getResource( "response_with_1_AddResponse.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 1, batchResponse.getResponses().size() );
+
+        LdapResponseCodec response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof AddResponseCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 1 AuthResponse
+     */
+    public void testResponseWith1AuthResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( BatchResponseTest.class.getResource( "response_with_1_AuthResponse.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 1, batchResponse.getResponses().size() );
+
+        LdapResponseCodec response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof BindResponseCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 1 CompareResponse
+     */
+    public void testResponseWith1CompareResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( BatchResponseTest.class.getResource( "response_with_1_CompareResponse.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 1, batchResponse.getResponses().size() );
+
+        LdapResponseCodec response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof CompareResponseCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 1 DelResponse
+     */
+    public void testResponseWith1DelResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( BatchResponseTest.class.getResource( "response_with_1_DelResponse.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 1, batchResponse.getResponses().size() );
+
+        LdapResponseCodec response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof DelResponseCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 1 ErrorResponse
+     */
+    public void testResponseWith1ErrorResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( BatchResponseTest.class.getResource( "response_with_1_ErrorResponse.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 1, batchResponse.getResponses().size() );
+
+        LdapResponseCodec response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof ErrorResponse )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 1 ExtendedResponse
+     */
+    public void testResponseWith1ExtendedResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput(
+                BatchResponseTest.class.getResource( "response_with_1_ExtendedResponse.xml" ).openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 1, batchResponse.getResponses().size() );
+
+        LdapResponseCodec response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof ExtendedResponseCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 1 ModDNResponse
+     */
+    public void testResponseWith1ModDNResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( BatchResponseTest.class.getResource( "response_with_1_ModDNResponse.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 1, batchResponse.getResponses().size() );
+
+        LdapResponseCodec response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof ModifyDNResponseCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 1 ModifyResponse
+     */
+    public void testResponseWith1ModifyResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( BatchResponseTest.class.getResource( "response_with_1_ModifyResponse.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 1, batchResponse.getResponses().size() );
+
+        LdapResponseCodec response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof ModifyResponseCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 1 SearchResponse
+     */
+    public void testResponseWith1SearchResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( BatchResponseTest.class.getResource( "response_with_1_SearchResponse.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 1, batchResponse.getResponses().size() );
+
+        LdapResponseCodec response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof SearchResponse )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 2 AddResponse
+     */
+    public void testResponseWith2AddResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( BatchResponseTest.class.getResource( "response_with_2_AddResponse.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 2, batchResponse.getResponses().size() );
+
+        LdapResponseCodec response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof AddResponseCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 2 AuthResponse
+     */
+    public void testResponseWith2AuthResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( BatchResponseTest.class.getResource( "response_with_2_AuthResponse.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 2, batchResponse.getResponses().size() );
+
+        LdapResponseCodec response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof BindResponseCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 2 CompareResponse
+     */
+    public void testResponseWith2CompareResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( BatchResponseTest.class.getResource( "response_with_2_CompareResponse.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 2, batchResponse.getResponses().size() );
+
+        LdapResponseCodec response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof CompareResponseCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 2 DelResponse
+     */
+    public void testResponseWith2DelResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( BatchResponseTest.class.getResource( "response_with_2_DelResponse.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 2, batchResponse.getResponses().size() );
+
+        LdapResponseCodec response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof DelResponseCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 2 ErrorResponse
+     */
+    public void testResponseWith2ErrorResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( BatchResponseTest.class.getResource( "response_with_2_ErrorResponse.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 2, batchResponse.getResponses().size() );
+
+        LdapResponseCodec response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof ErrorResponse )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 2 ExtendedResponse
+     */
+    public void testResponseWith2ExtendedResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput(
+                BatchResponseTest.class.getResource( "response_with_2_ExtendedResponse.xml" ).openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 2, batchResponse.getResponses().size() );
+
+        LdapResponseCodec response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof ExtendedResponseCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 2 ModDNResponse
+     */
+    public void testResponseWith2ModDNResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( BatchResponseTest.class.getResource( "response_with_2_ModDNResponse.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 2, batchResponse.getResponses().size() );
+
+        LdapResponseCodec response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof ModifyDNResponseCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 2 ModifyResponse
+     */
+    public void testResponseWith2ModifyResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( BatchResponseTest.class.getResource( "response_with_2_ModifyResponse.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 2, batchResponse.getResponses().size() );
+
+        LdapResponseCodec response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof ModifyResponseCodec )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 2 SearchResponse
+     */
+    public void testResponseWith2SearchResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInput( BatchResponseTest.class.getResource( "response_with_2_SearchResponse.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 2, batchResponse.getResponses().size() );
+
+        LdapResponseCodec response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof SearchResponse )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+}

Added: directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/compareRequest/CompareRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/compareRequest/CompareRequestTest.java?rev=796383&view=auto
==============================================================================
--- directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/compareRequest/CompareRequestTest.java (added)
+++ directory/shared/trunk/dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/compareRequest/CompareRequestTest.java Tue Jul 21 17:04:13 2009
@@ -0,0 +1,423 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.dsmlv2.compareRequest;
+
+
+import org.apache.directory.shared.ldap.codec.ControlCodec;
+import org.apache.directory.shared.ldap.codec.compare.CompareRequestCodec;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.directory.studio.dsmlv2.AbstractTest;
+import org.apache.directory.studio.dsmlv2.Dsmlv2Parser;
+
+
+/**
+ * Tests for the Compare Request parsing
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class CompareRequestTest extends AbstractTest
+{
+    /**
+     * Test parsing of a request without the dn attribute
+     */
+    public void testRequestWithoutDn()
+    {
+        testParsingFail( CompareRequestTest.class, "request_without_dn_attribute.xml" );
+    }
+
+
+    /**
+     * Test parsing of a request with the dn attribute
+     */
+    public void testRequestWithDn()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( CompareRequestTest.class.getResource( "request_with_dn_attribute.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareRequestCodec compareRequest = ( CompareRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM", compareRequest.getEntry().toString() );
+    }
+
+
+    /**
+     * Test parsing of a request with the (optional) requestID attribute
+     */
+    public void testRequestWithRequestId()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( CompareRequestTest.class.getResource( "request_with_requestID_attribute.xml" )
+                .openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareRequestCodec compareRequest = ( CompareRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( 456, compareRequest.getMessageId() );
+    }
+
+
+    /**
+     * Test parsing of a request with the (optional) requestID attribute equals to 0
+     */
+    public void testRequestWithRequestIdEquals0()
+    {
+        testParsingFail( CompareRequestTest.class, "request_with_requestID_equals_0.xml" );
+    }
+
+
+    /**
+     * Test parsing of a request with a (optional) Control element
+     */
+    public void testRequestWith1Control()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser
+                .setInput( CompareRequestTest.class.getResource( "request_with_1_control.xml" ).openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareRequestCodec compareRequest = ( CompareRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( 1, compareRequest.getControls().size() );
+
+        ControlCodec control = compareRequest.getCurrentControl();
+
+        assertTrue( control.getCriticality() );
+
+        assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
+
+        assertEquals( "Some text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
+    }
+
+
+    /**
+     * Test parsing of a request with a (optional) Control element with Base64 value
+     */
+    public void testRequestWith1ControlBase64Value()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser
+                .setInput( CompareRequestTest.class.getResource( "request_with_1_control.xml" ).openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareRequestCodec compareRequest = ( CompareRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( 1, compareRequest.getControls().size() );
+
+        ControlCodec control = compareRequest.getCurrentControl();
+
+        assertTrue( control.getCriticality() );
+
+        assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
+
+        assertEquals( "Some text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
+    }
+
+
+    /**
+     * Test parsing of a request with a (optional) Control element with empty value
+     */
+    public void testRequestWith1ControlEmptyValue()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( CompareRequestTest.class.getResource( "request_with_1_control_empty_value.xml" )
+                .openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareRequestCodec compareRequest = ( CompareRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( 1, compareRequest.getControls().size() );
+
+        ControlCodec control = compareRequest.getCurrentControl();
+
+        assertTrue( control.getCriticality() );
+
+        assertEquals( "1.2.840.113556.1.4.643", control.getControlType() );
+
+        assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() );
+    }
+
+
+    /**
+     * Test parsing of a request with 2 (optional) Control elements
+     */
+    public void testRequestWith2Controls()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( CompareRequestTest.class.getResource( "request_with_2_controls.xml" ).openStream(),
+                "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareRequestCodec compareRequest = ( CompareRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( 2, compareRequest.getControls().size() );
+
+        ControlCodec control = compareRequest.getCurrentControl();
+
+        assertFalse( control.getCriticality() );
+
+        assertEquals( "1.2.840.113556.1.4.789", control.getControlType() );
+
+        assertEquals( "Some other text", StringTools.utf8ToString( ( byte[] ) control.getControlValue() ) );
+    }
+
+
+    /**
+     * Test parsing of a request with 3 (optional) Control elements without value
+     */
+    public void testRequestWith3ControlsWithoutValue()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( CompareRequestTest.class.getResource( "request_with_3_controls_without_value.xml" )
+                .openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareRequestCodec compareRequest = ( CompareRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( 3, compareRequest.getControls().size() );
+
+        ControlCodec control = compareRequest.getCurrentControl();
+
+        assertTrue( control.getCriticality() );
+
+        assertEquals( "1.2.840.113556.1.4.456", control.getControlType() );
+
+        assertEquals( StringTools.EMPTY_BYTES, control.getControlValue() );
+    }
+
+
+    /**
+     * Test parsing of a request with an Attr elements with value
+     */
+    public void testRequestWith1CompleteAssertion()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( CompareRequestTest.class.getResource( "request_with_1_complete_assertion.xml" )
+                .openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareRequestCodec compareRequest = ( CompareRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM", ( String ) compareRequest.getEntry().toString() );
+
+        assertEquals( "sn", ( String ) compareRequest.getAttributeDesc() );
+
+        assertEquals( "Johnson", ( String ) compareRequest.getAssertionValue() );
+    }
+
+
+    /**
+     * Test parsing of a request with a complete assertion with base64 value
+     */
+    public void testRequestWith1CompleteAssertionBase64Value()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( CompareRequestTest.class
+                .getResource( "request_with_1_complete_assertion_base64_value.xml" ).openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareRequestCodec compareRequest = ( CompareRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM", ( String ) compareRequest.getEntry().toString() );
+
+        assertEquals( "sn", ( String ) compareRequest.getAttributeDesc() );
+
+        assertEquals( "DSMLv2.0 rocks!!", new String( ( byte[] ) compareRequest.getAssertionValue() ) );
+    }
+
+
+    /**
+     * Test parsing of a request with an Attr elements with empty value
+     */
+    public void testRequestWith1AssertionEmptyValue()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInput( CompareRequestTest.class.getResource( "request_with_1_assertion_empty_value.xml" )
+                .openStream(), "UTF-8" );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareRequestCodec compareRequest = ( CompareRequestCodec ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM", ( String ) compareRequest.getEntry().toString() );
+
+        assertEquals( "sn", ( String ) compareRequest.getAttributeDesc() );
+
+        assertNull( compareRequest.getAssertionValue() );
+    }
+
+
+    /**
+     * Test parsing of a request without the Assertion element
+     */
+    public void testRequestWithoutAssertion()
+    {
+        testParsingFail( CompareRequestTest.class, "request_without_assertion.xml" );
+    }
+
+
+    /**
+     * Test parsing of a request with 2 complete Assertion element
+     */
+    public void testRequestWith2CompleteAssertions()
+    {
+        testParsingFail( CompareRequestTest.class, "request_with_2_complete_assertions.xml" );
+    }
+
+
+    /**
+     * Test parsing of a request with 1 Assertion element without the name attribute
+     */
+    public void testRequestWith1AssertionWithoutNameAttribute()
+    {
+        testParsingFail( CompareRequestTest.class, "request_with_1_assertion_without_name_attribute.xml" );
+    }
+
+
+    /**
+     * Test parsing of a request with 1 Assertion element without the Value element
+     */
+    public void testRequestWith1AssertionWithoutValue()
+    {
+        testParsingFail( CompareRequestTest.class, "request_with_1_assertion_without_value.xml" );
+    }
+
+
+    /**
+     * Test parsing of a request with 1 Assertion element with 2 Value elements
+     */
+    public void testRequestWith1AssertionWith2Value()
+    {
+        testParsingFail( CompareRequestTest.class, "request_with_1_assertion_with_2_values.xml" );
+    }
+
+
+    /**
+     * Test parsing of a request with a needed requestID attribute
+     * 
+     * DIRSTUDIO-1
+     */
+    public void testRequestWithNeededRequestId()
+    {
+        testParsingFail( CompareRequestTest.class, "request_with_needed_requestID.xml" );
+    }
+}