directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fel...@apache.org
Subject svn commit: r592023 [10/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/ma...
Date Mon, 05 Nov 2007 14:53:11 GMT
Added: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/compareResponse/CompareResponseTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/compareResponse/CompareResponseTest.java?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/compareResponse/CompareResponseTest.java (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/compareResponse/CompareResponseTest.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.compareResponse;
+
+
+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.compare.CompareResponse;
+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 Compare Response parsing
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class CompareResponseTest extends AbstractResponseTest
+{
+
+    /**
+     * Test parsing of a Response with the (optional) requestID attribute
+     */
+    public void testResponseWithRequestId()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( CompareResponseTest.class.getResource( "response_with_requestID_attribute.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 456, compareResponse.getMessageId() );
+    }
+    
+    
+    /**
+     * Test parsing of a Response with the (optional) requestID attribute equals 0
+     */
+    public void testResponseWithRequestIdEquals0()
+    {
+        testParsingFail( CompareResponseTest.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( CompareResponseTest.class.getResource( "response_with_1_control.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 1, compareResponse.getControls().size() );
+
+        Control control = compareResponse.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( CompareResponseTest.class.getResource( "response_with_1_control_empty_value.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
+        Control control = compareResponse.getCurrentControl();
+        
+        assertEquals( 1, compareResponse.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( CompareResponseTest.class.getResource( "response_with_2_controls.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 2, compareResponse.getControls().size() );
+
+        Control control = compareResponse.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( CompareResponseTest.class.getResource( "response_with_3_controls_without_value.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 3, compareResponse.getControls().size() );
+
+        Control control = compareResponse.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( CompareResponseTest.class, "response_without_result_code.xml" );
+    }
+
+
+    /**
+     * Test parsing of a response with Result Code element but a not integer value
+     */
+    public void testResponseWithResultCodeNotInteger()
+    {
+        testParsingFail( CompareResponseTest.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( CompareResponseTest.class.getResource( "response_with_result_code.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = compareResponse.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( CompareResponseTest.class.getResource( "response_with_error_message.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = compareResponse.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( CompareResponseTest.class.getResource( "response_with_empty_error_message.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = compareResponse.getLdapResult();
+
+        assertNull( ldapResult.getErrorMessage() );
+    }
+
+
+    /**
+     * Test parsing of a response with a Referral
+     */
+    public void testResponseWith1Referral()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( CompareResponseTest.class.getResource( "response_with_1_referral.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = compareResponse.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( CompareResponseTest.class.getResource( "response_with_1_empty_referral.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = compareResponse.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( CompareResponseTest.class.getResource( "response_with_2_referrals.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = compareResponse.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( CompareResponseTest.class.getResource(
+                "response_with_1_referral_and_error_message.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = compareResponse.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( CompareResponseTest.class.getResource( "response_with_matchedDN_attribute.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        CompareResponse compareResponse = ( CompareResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = compareResponse.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( CompareResponseTest.class, "response_with_wrong_matchedDN_attribute.xml" );
+    }
+
+
+    /**
+     * Test parsing of a response with wrong Descr attribute
+     */
+    public void testResponseWithWrongDescr()
+    {
+        testParsingFail( CompareResponseTest.class, "response_with_wrong_descr.xml" );
+    }
+}

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

Added: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/delRequest/DelRequestTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/delRequest/DelRequestTest.java?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/delRequest/DelRequestTest.java (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/delRequest/DelRequestTest.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.delRequest;
+
+
+import org.apache.directory.shared.ldap.codec.Control;
+import org.apache.directory.shared.ldap.codec.del.DelRequest;
+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 Del Request parsing
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class DelRequestTest extends AbstractTest
+{
+    /**
+     * Test parsing of a request without the dn attribute
+     */
+    public void testRequestWithoutDn()
+    {
+        testParsingFail( DelRequestTest.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( DelRequestTest.class.getResource( "request_with_dn_attribute.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelRequest delRequest = ( DelRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( "cn=Bob Rush,ou=Dev,dc=Example,dc=COM", delRequest.getEntry().toString() );
+    }
+
+
+    /**
+     * Test parsing of a request with the (optional) requestID attribute
+     */
+    public void testRequestWithRequestId()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( DelRequestTest.class.getResource( "request_with_requestID_attribute.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelRequest delRequest = ( DelRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( 456, delRequest.getMessageId() );
+    }
+
+
+    /**
+     * Test parsing of a request with the (optional) requestID attribute equals to 0
+     */
+    public void testRequestWithRequestIdEquals0()
+    {
+        testParsingFail( DelRequestTest.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( DelRequestTest.class.getResource( "request_with_1_control.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelRequest delRequest = ( DelRequest ) parser.getBatchRequest().getCurrentRequest();
+        Control control = delRequest.getCurrentControl();
+
+        assertEquals( 1, delRequest.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
+     */
+    public void testRequestWith1ControlBase64Value()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( DelRequestTest.class.getResource( "request_with_1_control_base64_value.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelRequest delRequest = ( DelRequest ) parser.getBatchRequest().getCurrentRequest();
+        Control control = delRequest.getCurrentControl();
+
+        assertEquals( 1, delRequest.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( DelRequestTest.class.getResource( "request_with_1_control_empty_value.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelRequest delRequest = ( DelRequest ) parser.getBatchRequest().getCurrentRequest();
+        Control control = delRequest.getCurrentControl();
+
+        assertEquals( 1, delRequest.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( DelRequestTest.class.getResource( "request_with_2_controls.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelRequest delRequest = ( DelRequest ) parser.getBatchRequest().getCurrentRequest();
+        Control control = delRequest.getCurrentControl();
+
+        assertEquals( 2, delRequest.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( DelRequestTest.class.getResource( "request_with_3_controls_without_value.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelRequest delRequest = ( DelRequest ) parser.getBatchRequest().getCurrentRequest();
+        Control control = delRequest.getCurrentControl();
+
+        assertEquals( 3, delRequest.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( DelRequestTest.class, "request_with_needed_requestID.xml" );
+    }
+}

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

Added: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/delResponse/DelResponseTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/delResponse/DelResponseTest.java?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/delResponse/DelResponseTest.java (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/delResponse/DelResponseTest.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.delResponse;
+
+
+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.del.DelResponse;
+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 Del Response parsing
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class DelResponseTest extends AbstractResponseTest
+{
+
+    /**
+     * Test parsing of a Response with the (optional) requestID attribute
+     */
+    public void testResponseWithRequestId()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser
+                .setInputFile( DelResponseTest.class.getResource( "response_with_requestID_attribute.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelResponse delResponse = ( DelResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 456, delResponse.getMessageId() );
+    }
+    
+    
+    /**
+     * Test parsing of a Response with the (optional) requestID attribute equals 0
+     */
+    public void testResponseWithRequestIdEquals0()
+    {
+        testParsingFail( DelResponseTest.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( DelResponseTest.class.getResource( "response_with_1_control.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelResponse delResponse = ( DelResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 1, delResponse.getControls().size() );
+
+        Control control = delResponse.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( DelResponseTest.class.getResource( "response_with_1_control_empty_value.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelResponse delResponse = ( DelResponse ) parser.getBatchResponse().getCurrentResponse();
+        Control control = delResponse.getCurrentControl();
+        
+        assertEquals( 1, delResponse.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( DelResponseTest.class.getResource( "response_with_2_controls.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelResponse delResponse = ( DelResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 2, delResponse.getControls().size() );
+
+        Control control = delResponse.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( DelResponseTest.class.getResource( "response_with_3_controls_without_value.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelResponse delResponse = ( DelResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 3, delResponse.getControls().size() );
+
+        Control control = delResponse.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( DelResponseTest.class, "response_without_result_code.xml" );
+    }
+
+
+    /**
+     * Test parsing of a response with Result Code element but a not integer value
+     */
+    public void testResponseWithResultCodeNotInteger()
+    {
+        testParsingFail( DelResponseTest.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( DelResponseTest.class.getResource( "response_with_result_code.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelResponse delResponse = ( DelResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = delResponse.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( DelResponseTest.class.getResource( "response_with_error_message.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelResponse delResponse = ( DelResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = delResponse.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( DelResponseTest.class.getResource( "response_with_empty_error_message.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelResponse delResponse = ( DelResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = delResponse.getLdapResult();
+
+        assertNull( ldapResult.getErrorMessage() );
+    }
+
+
+    /**
+     * Test parsing of a response with a Referral
+     */
+    public void testResponseWith1Referral()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( DelResponseTest.class.getResource( "response_with_1_referral.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelResponse delResponse = ( DelResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = delResponse.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( DelResponseTest.class.getResource( "response_with_1_empty_referral.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelResponse delResponse = ( DelResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = delResponse.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( DelResponseTest.class.getResource( "response_with_2_referrals.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelResponse delResponse = ( DelResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = delResponse.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( DelResponseTest.class.getResource( "response_with_1_referral_and_error_message.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelResponse delResponse = ( DelResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = delResponse.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( DelResponseTest.class.getResource( "response_with_matchedDN_attribute.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        DelResponse delResponse = ( DelResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = delResponse.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( DelResponseTest.class, "response_with_wrong_matchedDN_attribute.xml" );
+    }
+
+
+    /**
+     * Test parsing of a response with wrong Descr attribute
+     */
+    public void testResponseWithWrongDescr()
+    {
+        testParsingFail( DelResponseTest.class, "response_with_wrong_descr.xml" );
+    }
+}

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

Added: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/errorResponse/ErrorResponseTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/errorResponse/ErrorResponseTest.java?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/errorResponse/ErrorResponseTest.java (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/errorResponse/ErrorResponseTest.java Mon Nov  5 06:52:22 2007
@@ -0,0 +1,346 @@
+/*
+ *  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.errorResponse;
+
+
+import org.apache.directory.studio.dsmlv2.AbstractResponseTest;
+import org.apache.directory.studio.dsmlv2.Dsmlv2ResponseParser;
+import org.apache.directory.studio.dsmlv2.reponse.ErrorResponse;
+import org.apache.directory.studio.dsmlv2.reponse.ErrorResponse.ErrorResponseType;
+
+
+/**
+ * Tests for the Error Response parsing
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ErrorResponseTest extends AbstractResponseTest
+{
+
+    /**
+     * Test parsing of a Response with the (optional) requestID attribute
+     */
+    public void testResponseWithRequestId()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_requestID_attribute.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 456, errorResponse.getMessageId() );
+    }
+    
+    
+    /**
+     * Test parsing of a Response with the (optional) requestID attribute equals 0
+     */
+    public void testResponseWithRequestIdEquals0()
+    {
+        testParsingFail( ErrorResponseTest.class, "response_with_requestID_equals_0.xml" );
+    }
+
+
+    /**
+     * Test parsing of a response without Type attribute
+     */
+    public void testResponseWithoutType()
+    {
+        testParsingFail( ErrorResponseTest.class, "response_without_type.xml" );
+    }
+
+
+    /**
+     * Test parsing of a response with type == notAttempted
+     */
+    public void testResponseWithTypeNotAttempted()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser
+                .setInputFile( ErrorResponseTest.class.getResource( "response_with_type_notAttempted.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( ErrorResponseType.NOT_ATTEMPTED, errorResponse.getType() );
+    }
+
+
+    /**
+     * Test parsing of a response with type == couldNotConnect
+     */
+    public void testResponseWithTypeCouldNotConnect()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_type_couldNotConnect.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( ErrorResponseType.COULD_NOT_CONNECT, errorResponse.getType() );
+    }
+
+
+    /**
+     * Test parsing of a response with type == connectionClosed
+     */
+    public void testResponseWithTypeConnectionClosed()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_type_connectionClosed.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( ErrorResponseType.CONNECTION_CLOSED, errorResponse.getType() );
+    }
+
+
+    /**
+     * Test parsing of a response with type == malformedRequest
+     */
+    public void testResponseWithTypeMalformedRequest()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_type_malformedRequest.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( ErrorResponseType.MALFORMED_REQUEST, errorResponse.getType() );
+    }
+
+
+    /**
+     * Test parsing of a response with type == gatewayInternalError
+     */
+    public void testResponseWithTypeGatewayInternalError()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_type_gatewayInternalError.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( ErrorResponseType.GATEWAY_INTERNAL_ERROR, errorResponse.getType() );
+    }
+
+
+    /**
+     * Test parsing of a response with type == authenticationFailed
+     */
+    public void testResponseWithTypeAuthenticationFailed()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_type_authenticationFailed.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( ErrorResponseType.AUTHENTICATION_FAILED, errorResponse.getType() );
+    }
+
+
+    /**
+     * Test parsing of a response with type == unresolvableURI
+     */
+    public void testResponseWithTypeUnresolvableURI()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_type_unresolvableURI.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( ErrorResponseType.UNRESOLVABLE_URI, errorResponse.getType() );
+    }
+
+
+    /**
+     * Test parsing of a response with type == other
+     */
+    public void testResponseWithTypeOther()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_type_other.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( ErrorResponseType.OTHER, errorResponse.getType() );
+    }
+
+
+    /**
+     * Test parsing of a response with type in error
+     */
+    public void testResponseWithTypeError()
+    {
+        testParsingFail( ErrorResponseTest.class, "response_with_type_inError.xml" );
+    }
+
+
+    /**
+     * Test parsing of a response with Message
+     */
+    public void testResponseWithMessage()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_message.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( "Connection refused", errorResponse.getMessage() );
+    }
+    
+    /**
+     * Test parsing of a response with empty Message
+     */
+    public void testResponseWithEmptyMessage()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ErrorResponseTest.class.getResource( "response_with_empty_message.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ErrorResponse errorResponse = ( ErrorResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertNull( errorResponse.getMessage() );
+    }
+}

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

Added: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/extendedRequest/ExtendedRequestTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/extendedRequest/ExtendedRequestTest.java?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/extendedRequest/ExtendedRequestTest.java (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/extendedRequest/ExtendedRequestTest.java Mon Nov  5 06:52:22 2007
@@ -0,0 +1,334 @@
+/*
+ *  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.extendedRequest;
+
+
+import org.apache.directory.shared.ldap.codec.Control;
+import org.apache.directory.shared.ldap.codec.extended.ExtendedRequest;
+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 Extended Request parsing
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ExtendedRequestTest extends AbstractTest
+{
+    /**
+     * Test parsing of a request with the (optional) requestID attribute
+     */
+    public void testRequestWithRequestId()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ExtendedRequestTest.class.getResource( "request_with_requestID_attribute.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedRequest extendedRequest = ( ExtendedRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( 456, extendedRequest.getMessageId() );
+    }
+
+
+    /**
+     * Test parsing of a request with the (optional) requestID attribute equals to 0
+     */
+    public void testRequestWithRequestIdEquals0()
+    {
+        testParsingFail( ExtendedRequestTest.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( ExtendedRequestTest.class.getResource( "request_with_1_control.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedRequest extendedRequest = ( ExtendedRequest ) parser.getBatchRequest().getCurrentRequest();
+        Control control = extendedRequest.getCurrentControl();
+
+        assertEquals( 1, extendedRequest.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( ExtendedRequestTest.class.getResource( "request_with_1_control_base64_value.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedRequest extendedRequest = ( ExtendedRequest ) parser.getBatchRequest().getCurrentRequest();
+        Control control = extendedRequest.getCurrentControl();
+
+        assertEquals( 1, extendedRequest.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( ExtendedRequestTest.class.getResource( "request_with_1_control_empty_value.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedRequest extendedRequest = ( ExtendedRequest ) parser.getBatchRequest().getCurrentRequest();
+        Control control = extendedRequest.getCurrentControl();
+
+        assertEquals( 1, extendedRequest.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( ExtendedRequestTest.class.getResource( "request_with_2_controls.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedRequest extendedRequest = ( ExtendedRequest ) parser.getBatchRequest().getCurrentRequest();
+        Control control = extendedRequest.getCurrentControl();
+
+        assertEquals( 2, extendedRequest.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( ExtendedRequestTest.class.getResource( "request_with_3_controls_without_value.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedRequest extendedRequest = ( ExtendedRequest ) parser.getBatchRequest().getCurrentRequest();
+        Control control = extendedRequest.getCurrentControl();
+
+        assertEquals( 3, extendedRequest.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 RequestValue element
+     */
+    public void testRequestWithRequestValue()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ExtendedRequestTest.class.getResource( "request_with_requestValue.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedRequest extendedRequest = ( ExtendedRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( "foobar", new String( extendedRequest.getRequestValue() ) );
+    }
+
+
+    /**
+     * Test parsing of a request with a RequestValue element with Base64 value
+     */
+    public void testRequestWithBase64RequestValue()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ExtendedRequestTest.class.getResource( "request_with_base64_requestValue.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedRequest extendedRequest = ( ExtendedRequest ) parser.getBatchRequest().getCurrentRequest();
+
+        assertEquals( "DSMLv2.0 rocks!!", new String( extendedRequest.getRequestValue() ) );
+    }
+
+
+    /**
+     * Test parsing of a request with 2 requestValue Elements
+     */
+    public void testRequestWith2RequestValue()
+    {
+        testParsingFail( ExtendedRequestTest.class, "request_with_2_requestValue.xml" );
+    }
+
+
+    /**
+     * Test parsing of a request with 2 requestName Elements
+     */
+    public void testRequestWith2RequestName()
+    {
+        testParsingFail( ExtendedRequestTest.class, "request_with_2_requestName.xml" );
+    }
+
+
+    /**
+     * Test parsing of a request with an empty requestName
+     */
+    public void testRequestWithEmptyRequestName()
+    {
+        testParsingFail( ExtendedRequestTest.class, "request_with_empty_requestName.xml" );
+    }
+
+
+    /**
+     * Test parsing of a request with an empty RequestValue
+     */
+    public void testRequestWithEmptyRequestValue()
+    {
+        Dsmlv2Parser parser = null;
+        try
+        {
+            parser = new Dsmlv2Parser();
+
+            parser.setInputFile( ExtendedRequestTest.class.getResource( "request_with_empty_requestValue.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedRequest extendedRequest = ( ExtendedRequest ) parser.getBatchRequest().getCurrentRequest();
+        assertNull( extendedRequest.getRequestValue() );
+    }
+
+
+    /**
+     * Test parsing of a request with a needed requestID attribute
+     * 
+     * DIRSTUDIO-1
+     */
+    public void testRequestWithNeededRequestId()
+    {
+        testParsingFail( ExtendedRequestTest.class, "request_with_needed_requestID.xml" );
+    }
+}

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

Added: directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/extendedResponse/ExtendedResponseTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/extendedResponse/ExtendedResponseTest.java?rev=592023&view=auto
==============================================================================
--- directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/extendedResponse/ExtendedResponseTest.java (added)
+++ directory/sandbox/felixk/studio-dsml-parser/src/test/java/org/apache/directory/studio/dsmlv2/extendedResponse/ExtendedResponseTest.java Mon Nov  5 06:52:22 2007
@@ -0,0 +1,689 @@
+/*
+ *  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.extendedResponse;
+
+
+import java.util.List;
+
+import javax.naming.NamingException;
+
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.asn1.primitives.OID;
+import org.apache.directory.shared.ldap.codec.Control;
+import org.apache.directory.shared.ldap.codec.LdapResult;
+import org.apache.directory.shared.ldap.codec.extended.ExtendedResponse;
+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 Extended Response parsing
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ExtendedResponseTest extends AbstractResponseTest
+{
+
+    /**
+     * Test parsing of a Response with the (optional) requestID attribute
+     */
+    public void testResponseWithRequestId()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_requestID_attribute.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 456, extendedResponse.getMessageId() );
+    }
+    
+    
+    /**
+     * Test parsing of a Response with the (optional) requestID attribute equals 0
+     */
+    public void testResponseWithRequestIdEquals0()
+    {
+        testParsingFail( ExtendedResponseTest.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( ExtendedResponseTest.class.getResource( "response_with_1_control.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 1, extendedResponse.getControls().size() );
+
+        Control control = extendedResponse.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( ExtendedResponseTest.class.getResource( "response_with_1_control_empty_value.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+        Control control = extendedResponse.getCurrentControl();
+        
+        assertEquals( 1, extendedResponse.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( ExtendedResponseTest.class.getResource( "response_with_2_controls.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 2, extendedResponse.getControls().size() );
+
+        Control control = extendedResponse.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( ExtendedResponseTest.class.getResource( "response_with_3_controls_without_value.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( 3, extendedResponse.getControls().size() );
+
+        Control control = extendedResponse.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( ExtendedResponseTest.class, "response_without_result_code.xml" );
+    }
+
+
+    /**
+     * Test parsing of a response with Result Code element but a not integer value
+     */
+    public void testResponseWithResultCodeNotInteger()
+    {
+        testParsingFail( ExtendedResponseTest.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( ExtendedResponseTest.class.getResource( "response_with_result_code.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = extendedResponse.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( ExtendedResponseTest.class.getResource( "response_with_error_message.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = extendedResponse.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( ExtendedResponseTest.class.getResource( "response_with_empty_error_message.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = extendedResponse.getLdapResult();
+
+        assertNull( ldapResult.getErrorMessage() );
+    }
+
+
+    /**
+     * Test parsing of a response with a Referral
+     */
+    public void testResponseWith1Referral()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_1_referral.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = extendedResponse.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 a empty Referral
+     */
+    public void testResponseWith1EmptyReferral()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_1_empty_referral.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = extendedResponse.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( ExtendedResponseTest.class.getResource( "response_with_2_referrals.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = extendedResponse.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( ExtendedResponseTest.class.getResource(
+                "response_with_1_referral_and_error_message.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = extendedResponse.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( ExtendedResponseTest.class.getResource( "response_with_matchedDN_attribute.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        LdapResult ldapResult = extendedResponse.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( ExtendedResponseTest.class, "response_with_wrong_matchedDN_attribute.xml" );
+    }
+
+
+    /**
+     * Test parsing of a response with Response Name
+     */
+    public void testResponseWithResponseName()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_responseName.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        try
+        {
+            assertEquals( new OID( "1.2.3.4.5.6.7.8.9.0" ).toString(), extendedResponse.getResponseName().toString() );
+        }
+        catch ( DecoderException e )
+        {
+            fail();
+        }
+    }
+    
+    /**
+     * Test parsing of a response with empty Response Name
+     */
+    public void testResponseWithEmptyResponseName()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_empty_responseName.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( "", extendedResponse.getResponseName().toString() );
+    }
+
+
+    /**
+     * Test parsing of a response with wrong Response Name
+     */
+    public void testResponseWithWrongResponseName()
+    {
+        testParsingFail( ExtendedResponseTest.class, "response_with_wrong_responseName.xml" );
+    }
+
+
+    /**
+     * Test parsing of a response with Response
+     */
+    public void testResponseWithResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_response.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( "This is a response", extendedResponse.getResponse() );
+    }
+    
+    /**
+     * Test parsing of a response with Base64 Response
+     */
+    public void testResponseWithBase64Response()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_base64_response.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( "DSMLv2.0 rocks!!", new String( (byte[]) extendedResponse.getResponse() ) );
+    }
+    
+    /**
+     * Test parsing of a response with empty Response
+     */
+    public void testResponseWithEmptyResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_empty_response.xml" ).getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( "", extendedResponse.getResponse() );
+    }
+
+
+    /**
+     * Test parsing of a response with Response Name and Response
+     */
+    public void testResponseWithResponseNameAndResponse()
+    {
+        Dsmlv2ResponseParser parser = null;
+        try
+        {
+            parser = new Dsmlv2ResponseParser();
+
+            parser.setInputFile( ExtendedResponseTest.class.getResource( "response_with_responseName_and_response.xml" )
+                .getFile() );
+
+            parser.parse();
+        }
+        catch ( Exception e )
+        {
+            fail( e.getMessage() );
+        }
+
+        ExtendedResponse extendedResponse = ( ExtendedResponse ) parser.getBatchResponse().getCurrentResponse();
+
+        assertEquals( "This is a response", extendedResponse.getResponse() );
+
+        try
+        {
+            assertEquals( new OID( "1.2.3.4.5.6.7.8.9.0" ).toString(), extendedResponse.getResponseName().toString() );
+        }
+        catch ( DecoderException e )
+        {
+            fail();
+        }
+    }
+
+
+    /**
+     * Test parsing of a response with wrong Descr attribute
+     */
+    public void testResponseWithWrongDescr()
+    {
+        testParsingFail( ExtendedResponseTest.class, "response_with_wrong_descr.xml" );
+    }
+}

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



Mime
View raw message