directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fel...@apache.org
Subject svn commit: r592023 [9/25] - in /directory/sandbox/felixk/studio-dsml-parser: ./ META-INF/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/directory/ src/main/java/org/apache/directory/studio/ src/mai...
Date Mon, 05 Nov 2007 14:53:11 GMT
Added: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/authRequest/AuthRequestTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/authRequest/AuthRequestTest.java?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/authRequest/AuthRequestTest.java (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/authRequest/AuthRequestTest.java Mon Nov  5 06:52:22 2007
@@ -0,0 +1,264 @@
+/*
+ *  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.Control;
+import org.apache.directory.shared.ldap.codec.bind.BindRequest;
+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.setInputFile( AuthRequestTest.class.getResource( "request_with_principal_attribute.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindRequest bindRequest = ( BindRequest ) 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.setInputFile( AuthRequestTest.class.getResource( "request_with_requestID_attribute.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindRequest abandonRequest = ( BindRequest ) 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.setInputFile( AuthRequestTest.class.getResource( "request_with_1_control.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindRequest abandonRequest = ( BindRequest ) parser.getBatchRequest().getCurrentRequest();
+        Control 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.setInputFile( AuthRequestTest.class.getResource( "request_with_1_control_base64_value.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindRequest abandonRequest = ( BindRequest ) parser.getBatchRequest().getCurrentRequest();
+        Control 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.setInputFile( AuthRequestTest.class.getResource( "request_with_1_control_empty_value.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindRequest abandonRequest = ( BindRequest ) parser.getBatchRequest().getCurrentRequest();
+        Control 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.setInputFile( AuthRequestTest.class.getResource( "request_with_2_controls.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindRequest abandonRequest = ( BindRequest ) parser.getBatchRequest().getCurrentRequest();
+        Control 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.setInputFile( AuthRequestTest.class.getResource( "request_with_3_controls_without_value.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindRequest abandonRequest = ( BindRequest ) parser.getBatchRequest().getCurrentRequest();
+        Control 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" );
+    }
+}

Propchange: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/authRequest/AuthRequestTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/authResponse/AuthResponseTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/authResponse/AuthResponseTest.java?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/authResponse/AuthResponseTest.java (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/authResponse/AuthResponseTest.java Mon Nov  5 06:52:22 2007
@@ -0,0 +1,514 @@
+/*
+ *  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.Control;
+import org.apache.directory.shared.ldap.codec.LdapResult;
+import org.apache.directory.shared.ldap.codec.bind.BindResponse;
+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.setInputFile( AuthResponseTest.class.getResource( "response_with_requestID_attribute.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindResponse bindResponse = ( BindResponse ) 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.setInputFile( AuthResponseTest.class.getResource( "response_with_1_control.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindResponse bindResponse = ( BindResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 1, bindResponse.getControls().size() );
+
+        Control 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.setInputFile( AuthResponseTest.class.getResource( "response_with_1_control_empty_value.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindResponse bindResponse = ( BindResponse ) parser.getBatchResponse().getCurrentResponse();
+        Control 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.setInputFile( AuthResponseTest.class.getResource( "response_with_2_controls.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindResponse bindResponse = ( BindResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 2, bindResponse.getControls().size() );
+
+        Control 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.setInputFile( AuthResponseTest.class.getResource( "response_with_3_controls_without_value.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindResponse bindResponse = ( BindResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 3, bindResponse.getControls().size() );
+
+        Control 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.setInputFile( AuthResponseTest.class.getResource( "response_with_result_code.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindResponse bindResponse = ( BindResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult 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.setInputFile( AuthResponseTest.class.getResource( "response_with_error_message.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindResponse bindResponse = ( BindResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult 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.setInputFile( AuthResponseTest.class.getResource( "response_with_empty_error_message.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindResponse bindResponse = ( BindResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult 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.setInputFile( AuthResponseTest.class.getResource( "response_with_1_referral.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindResponse bindResponse = ( BindResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult 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.setInputFile( AuthResponseTest.class.getResource( "response_with_1_empty_referral.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindResponse bindResponse = ( BindResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult 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.setInputFile( AuthResponseTest.class.getResource( "response_with_2_referrals.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindResponse bindResponse = ( BindResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult 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.setInputFile( AuthResponseTest.class.getResource( "response_with_1_referral_and_error_message.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindResponse bindResponse = ( BindResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult 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.setInputFile( AuthResponseTest.class.getResource( "response_with_matchedDN_attribute.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BindResponse bindResponse = ( BindResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult 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" );
+    }
+}

Propchange: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/authResponse/AuthResponseTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/batchRequest/BatchRequestTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/batchRequest/BatchRequestTest.java?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/batchRequest/BatchRequestTest.java (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/batchRequest/BatchRequestTest.java Mon Nov  5 06:52:22 2007
@@ -0,0 +1,778 @@
+/*
+ *  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.LdapMessage;
+import org.apache.directory.shared.ldap.codec.abandon.AbandonRequest;
+import org.apache.directory.shared.ldap.codec.add.AddRequest;
+import org.apache.directory.shared.ldap.codec.bind.BindRequest;
+import org.apache.directory.shared.ldap.codec.compare.CompareRequest;
+import org.apache.directory.shared.ldap.codec.del.DelRequest;
+import org.apache.directory.shared.ldap.codec.extended.ExtendedRequest;
+import org.apache.directory.shared.ldap.codec.modify.ModifyRequest;
+import org.apache.directory.shared.ldap.codec.modifyDn.ModifyDNRequest;
+import org.apache.directory.shared.ldap.codec.search.SearchRequest;
+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
+                .setInputFile( BatchRequestTest.class.getResource( "request_with_requestID_attribute.xml" ).getFile() );
+
+            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
+                .setInputFile( BatchRequestTest.class.getResource( "request_with_requestID_attribute.xml" ).getFile() );
+
+            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.setInputFile( BatchRequestTest.class.getResource( "request_with_1_AuthRequest.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 1, batchRequest.getRequests().size() );
+
+        LdapMessage request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof BindRequest )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 1 AddRequest
+     */
+    public void testResponseWith1AddRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_AddRequest.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 1, batchRequest.getRequests().size() );
+
+        LdapMessage request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof AddRequest )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 1 CompareRequest
+     */
+    public void testResponseWith1CompareRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_CompareRequest.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 1, batchRequest.getRequests().size() );
+
+        LdapMessage request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof CompareRequest )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 1 AbandonRequest
+     */
+    public void testResponseWith1AbandonRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_AbandonRequest.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 1, batchRequest.getRequests().size() );
+
+        LdapMessage request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof AbandonRequest )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 1 DelRequest
+     */
+    public void testResponseWith1DelRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_DelRequest.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 1, batchRequest.getRequests().size() );
+
+        LdapMessage request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof DelRequest )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 1 ExtendedRequest
+     */
+    public void testResponseWith1ExtendedRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_ExtendedRequest.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 1, batchRequest.getRequests().size() );
+
+        LdapMessage request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof ExtendedRequest )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 1 ModDNRequest
+     */
+    public void testResponseWith1ModDNRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_ModDNRequest.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 1, batchRequest.getRequests().size() );
+
+        LdapMessage request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof ModifyDNRequest )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 1 ModifyRequest
+     */
+    public void testResponseWith1ModifyRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_ModifyRequest.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 1, batchRequest.getRequests().size() );
+
+        LdapMessage request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof ModifyRequest )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 1 SearchRequest
+     */
+    public void testResponseWith1SearchRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_1_SearchRequest.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 1, batchRequest.getRequests().size() );
+
+        LdapMessage request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof SearchRequest )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 2 AddRequest
+     */
+    public void testResponseWith2AddRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_2_AddRequest.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 2, batchRequest.getRequests().size() );
+
+        LdapMessage request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof AddRequest )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 2 CompareRequest
+     */
+    public void testResponseWith2CompareRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_2_CompareRequest.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 2, batchRequest.getRequests().size() );
+
+        LdapMessage request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof CompareRequest )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 2 AbandonRequest
+     */
+    public void testResponseWith2AbandonRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_2_AbandonRequest.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 2, batchRequest.getRequests().size() );
+
+        LdapMessage request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof AbandonRequest )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 2 DelRequest
+     */
+    public void testResponseWith2DelRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_2_DelRequest.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 2, batchRequest.getRequests().size() );
+
+        LdapMessage request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof DelRequest )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 2 ExtendedRequest
+     */
+    public void testResponseWith2ExtendedRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_2_ExtendedRequest.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 2, batchRequest.getRequests().size() );
+
+        LdapMessage request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof ExtendedRequest )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 2 ModDNRequest
+     */
+    public void testResponseWith2ModDNRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_2_ModDNRequest.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 2, batchRequest.getRequests().size() );
+
+        LdapMessage request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof ModifyDNRequest )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 2 ModifyRequest
+     */
+    public void testResponseWith2ModifyRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_2_ModifyRequest.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 2, batchRequest.getRequests().size() );
+
+        LdapMessage request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof ModifyRequest )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Request with 2 SearchRequest
+     */
+    public void testResponseWith2SearchRequest()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( BatchRequestTest.class.getResource( "request_with_2_SearchRequest.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        assertEquals( 2, batchRequest.getRequests().size() );
+
+        LdapMessage request = batchRequest.getCurrentRequest();
+
+        if ( request instanceof SearchRequest )
+        {
+            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.setInputFile( BatchRequestTest.class.getResource( "request_with_1_AuthRequest_1_AddRequest.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchRequest batchRequest = parser.getBatchRequest();
+
+        List requests = batchRequest.getRequests();
+
+        assertEquals( 2, requests.size() );
+
+        LdapMessage request = ( LdapMessage ) requests.get( 0 );
+
+        if ( request instanceof BindRequest )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+
+        request = ( LdapMessage ) requests.get( 1 );
+
+        if ( request instanceof AddRequest )
+        {
+            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" );
+    }
+}

Propchange: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/batchRequest/BatchRequestTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/batchResponse/BatchResponseTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/batchResponse/BatchResponseTest.java?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/batchResponse/BatchResponseTest.java (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/batchResponse/BatchResponseTest.java Mon Nov  5 06:52:22 2007
@@ -0,0 +1,757 @@
+/*
+ *  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.LdapResponse;
+import org.apache.directory.shared.ldap.codec.add.AddResponse;
+import org.apache.directory.shared.ldap.codec.bind.BindResponse;
+import org.apache.directory.shared.ldap.codec.compare.CompareResponse;
+import org.apache.directory.shared.ldap.codec.del.DelResponse;
+import org.apache.directory.shared.ldap.codec.extended.ExtendedResponse;
+import org.apache.directory.shared.ldap.codec.modify.ModifyResponse;
+import org.apache.directory.shared.ldap.codec.modifyDn.ModifyDNResponse;
+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.setInputFile( BatchResponseTest.class.getResource( "response_with_requestID_attribute.xml" )
+                .getFile() );
+
+            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.setInputFile( BatchResponseTest.class.getResource( "response_with_0_response.xml" ).getFile() );
+
+            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.setInputFile( BatchResponseTest.class.getResource( "response_with_1_AddResponse.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 1, batchResponse.getResponses().size() );
+
+        LdapResponse response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof AddResponse )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 1 AuthResponse
+     */
+    public void testResponseWith1AuthResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_1_AuthResponse.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 1, batchResponse.getResponses().size() );
+
+        LdapResponse response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof BindResponse )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 1 CompareResponse
+     */
+    public void testResponseWith1CompareResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser
+                .setInputFile( BatchResponseTest.class.getResource( "response_with_1_CompareResponse.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 1, batchResponse.getResponses().size() );
+
+        LdapResponse response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof CompareResponse )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 1 DelResponse
+     */
+    public void testResponseWith1DelResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_1_DelResponse.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 1, batchResponse.getResponses().size() );
+
+        LdapResponse response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof DelResponse )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 1 ErrorResponse
+     */
+    public void testResponseWith1ErrorResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_1_ErrorResponse.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 1, batchResponse.getResponses().size() );
+
+        LdapResponse 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.setInputFile( BatchResponseTest.class.getResource( "response_with_1_ExtendedResponse.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 1, batchResponse.getResponses().size() );
+
+        LdapResponse response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof ExtendedResponse )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 1 ModDNResponse
+     */
+    public void testResponseWith1ModDNResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_1_ModDNResponse.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 1, batchResponse.getResponses().size() );
+
+        LdapResponse response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof ModifyDNResponse )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 1 ModifyResponse
+     */
+    public void testResponseWith1ModifyResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_1_ModifyResponse.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 1, batchResponse.getResponses().size() );
+
+        LdapResponse response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof ModifyResponse )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 1 SearchResponse
+     */
+    public void testResponseWith1SearchResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_1_SearchResponse.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 1, batchResponse.getResponses().size() );
+
+        LdapResponse 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.setInputFile( BatchResponseTest.class.getResource( "response_with_2_AddResponse.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 2, batchResponse.getResponses().size() );
+
+        LdapResponse response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof AddResponse )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 2 AuthResponse
+     */
+    public void testResponseWith2AuthResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_2_AuthResponse.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 2, batchResponse.getResponses().size() );
+
+        LdapResponse response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof BindResponse )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 2 CompareResponse
+     */
+    public void testResponseWith2CompareResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser
+                .setInputFile( BatchResponseTest.class.getResource( "response_with_2_CompareResponse.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 2, batchResponse.getResponses().size() );
+
+        LdapResponse response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof CompareResponse )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 2 DelResponse
+     */
+    public void testResponseWith2DelResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_2_DelResponse.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 2, batchResponse.getResponses().size() );
+
+        LdapResponse response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof DelResponse )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 2 ErrorResponse
+     */
+    public void testResponseWith2ErrorResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_2_ErrorResponse.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 2, batchResponse.getResponses().size() );
+
+        LdapResponse 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.setInputFile( BatchResponseTest.class.getResource( "response_with_2_ExtendedResponse.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 2, batchResponse.getResponses().size() );
+
+        LdapResponse response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof ExtendedResponse )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 2 ModDNResponse
+     */
+    public void testResponseWith2ModDNResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_2_ModDNResponse.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 2, batchResponse.getResponses().size() );
+
+        LdapResponse response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof ModifyDNResponse )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 2 ModifyResponse
+     */
+    public void testResponseWith2ModifyResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_2_ModifyResponse.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 2, batchResponse.getResponses().size() );
+
+        LdapResponse response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof ModifyResponse )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a Response with the 2 SearchResponse
+     */
+    public void testResponseWith2SearchResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( BatchResponseTest.class.getResource( "response_with_2_SearchResponse.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        BatchResponse batchResponse = parser.getBatchResponse();
+
+        assertEquals( 2, batchResponse.getResponses().size() );
+
+        LdapResponse response = batchResponse.getCurrentResponse();
+
+        if ( response instanceof SearchResponse )
+        {
+            assertTrue( true );
+        }
+        else
+        {
+            fail();
+        }
+    }
+}

Propchange: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/batchResponse/BatchResponseTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/compareRequest/CompareRequestTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/compareRequest/CompareRequestTest.java?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/compareRequest/CompareRequestTest.java (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/compareRequest/CompareRequestTest.java Mon Nov  5 06:52:22 2007
@@ -0,0 +1,419 @@
+/*
+ *  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.Control;
+import org.apache.directory.shared.ldap.codec.compare.CompareRequest;
+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.setInputFile( CompareRequestTest.class.getResource( "request_with_dn_attribute.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareRequest compareRequest = ( CompareRequest ) 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.setInputFile( CompareRequestTest.class.getResource( "request_with_requestID_attribute.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareRequest compareRequest = ( CompareRequest ) 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.setInputFile( CompareRequestTest.class.getResource( "request_with_1_control.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareRequest compareRequest = ( CompareRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( 1, compareRequest.getControls().size() );
+
+        Control 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.setInputFile( CompareRequestTest.class.getResource( "request_with_1_control.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareRequest compareRequest = ( CompareRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( 1, compareRequest.getControls().size() );
+
+        Control 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.setInputFile( CompareRequestTest.class.getResource( "request_with_1_control_empty_value.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareRequest compareRequest = ( CompareRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( 1, compareRequest.getControls().size() );
+
+        Control 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.setInputFile( CompareRequestTest.class.getResource( "request_with_2_controls.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareRequest compareRequest = ( CompareRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( 2, compareRequest.getControls().size() );
+
+        Control 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.setInputFile( CompareRequestTest.class.getResource( "request_with_3_controls_without_value.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareRequest compareRequest = ( CompareRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( 3, compareRequest.getControls().size() );
+
+        Control 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.setInputFile( CompareRequestTest.class.getResource( "request_with_1_complete_assertion.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareRequest compareRequest = ( CompareRequest ) 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.setInputFile( CompareRequestTest.class.getResource(
+                "request_with_1_complete_assertion_base64_value.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareRequest compareRequest = ( CompareRequest ) 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.setInputFile( CompareRequestTest.class.getResource( "request_with_1_assertion_empty_value.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareRequest compareRequest = ( CompareRequest ) 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" );
+    }
+}

Propchange: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/compareRequest/CompareRequestTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message